Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: add read scale and offset services to iio backend framework

Add iio_backend_read_scale() and iio_backend_read_offset() services
to read channel scale and offset from an IIO backbend device.

Also add a read_raw callback which replicates the read_raw callback of
the IIO framework, and is intended to request miscellaneous channel
attributes from the backend device.
Both scale and offset helpers use this callback.

Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240730084640.1307938-2-olivier.moysan@foss.st.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Olivier Moysan and committed by
Jonathan Cameron
0737158a c7668ac6

+42 -1
+19
drivers/iio/industrialio-backend.c
··· 502 502 } 503 503 EXPORT_SYMBOL_NS_GPL(devm_iio_backend_request_buffer, IIO_BACKEND); 504 504 505 + /** 506 + * iio_backend_read_raw - Read a channel attribute from a backend device. 507 + * @back: Backend device 508 + * @chan: IIO channel reference 509 + * @val: First returned value 510 + * @val2: Second returned value 511 + * @mask: Specify the attribute to return 512 + * 513 + * RETURNS: 514 + * 0 on success, negative error number on failure. 515 + */ 516 + int iio_backend_read_raw(struct iio_backend *back, 517 + struct iio_chan_spec const *chan, int *val, int *val2, 518 + long mask) 519 + { 520 + return iio_backend_op_call(back, read_raw, chan, val, val2, mask); 521 + } 522 + EXPORT_SYMBOL_NS_GPL(iio_backend_read_raw, IIO_BACKEND); 523 + 505 524 static struct iio_backend *iio_backend_from_indio_dev_parent(const struct device *dev) 506 525 { 507 526 struct iio_backend *back = ERR_PTR(-ENODEV), *iter;
+23 -1
include/linux/iio/backend.h
··· 3 3 #define _IIO_BACKEND_H_ 4 4 5 5 #include <linux/types.h> 6 + #include <linux/iio/iio.h> 6 7 7 8 struct iio_chan_spec; 8 9 struct fwnode_handle; ··· 86 85 * @extend_chan_spec: Extend an IIO channel. 87 86 * @ext_info_set: Extended info setter. 88 87 * @ext_info_get: Extended info getter. 88 + * @read_raw: Read a channel attribute from a backend device 89 89 * @debugfs_print_chan_status: Print channel status into a buffer. 90 90 * @debugfs_reg_access: Read or write register value of backend. 91 91 **/ ··· 121 119 const char *buf, size_t len); 122 120 int (*ext_info_get)(struct iio_backend *back, uintptr_t private, 123 121 const struct iio_chan_spec *chan, char *buf); 122 + int (*read_raw)(struct iio_backend *back, 123 + struct iio_chan_spec const *chan, int *val, int *val2, 124 + long mask); 124 125 int (*debugfs_print_chan_status)(struct iio_backend *back, 125 126 unsigned int chan, char *buf, 126 127 size_t len); ··· 167 162 const char *buf, size_t len); 168 163 ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private, 169 164 const struct iio_chan_spec *chan, char *buf); 170 - 165 + int iio_backend_read_raw(struct iio_backend *back, 166 + struct iio_chan_spec const *chan, int *val, int *val2, 167 + long mask); 171 168 int iio_backend_extend_chan_spec(struct iio_backend *back, 172 169 struct iio_chan_spec *chan); 173 170 void *iio_backend_get_priv(const struct iio_backend *conv); ··· 180 173 181 174 int devm_iio_backend_register(struct device *dev, 182 175 const struct iio_backend_info *info, void *priv); 176 + 177 + static inline int iio_backend_read_scale(struct iio_backend *back, 178 + struct iio_chan_spec const *chan, 179 + int *val, int *val2) 180 + { 181 + return iio_backend_read_raw(back, chan, val, val2, IIO_CHAN_INFO_SCALE); 182 + } 183 + 184 + static inline int iio_backend_read_offset(struct iio_backend *back, 185 + struct iio_chan_spec const *chan, 186 + int *val, int *val2) 187 + { 188 + return iio_backend_read_raw(back, chan, val, val2, 189 + IIO_CHAN_INFO_OFFSET); 190 + } 183 191 184 192 ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back, 185 193 unsigned int chan, char *buf,