Commit 0737158a authored by Olivier Moysan's avatar Olivier Moysan Committed by Jonathan Cameron

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: default avatarOlivier Moysan <olivier.moysan@foss.st.com>
Reviewed-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240730084640.1307938-2-olivier.moysan@foss.st.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c7668ac6
...@@ -502,6 +502,25 @@ int devm_iio_backend_request_buffer(struct device *dev, ...@@ -502,6 +502,25 @@ int devm_iio_backend_request_buffer(struct device *dev,
} }
EXPORT_SYMBOL_NS_GPL(devm_iio_backend_request_buffer, IIO_BACKEND); EXPORT_SYMBOL_NS_GPL(devm_iio_backend_request_buffer, IIO_BACKEND);
/**
* iio_backend_read_raw - Read a channel attribute from a backend device.
* @back: Backend device
* @chan: IIO channel reference
* @val: First returned value
* @val2: Second returned value
* @mask: Specify the attribute to return
*
* RETURNS:
* 0 on success, negative error number on failure.
*/
int iio_backend_read_raw(struct iio_backend *back,
struct iio_chan_spec const *chan, int *val, int *val2,
long mask)
{
return iio_backend_op_call(back, read_raw, chan, val, val2, mask);
}
EXPORT_SYMBOL_NS_GPL(iio_backend_read_raw, IIO_BACKEND);
static struct iio_backend *iio_backend_from_indio_dev_parent(const struct device *dev) static struct iio_backend *iio_backend_from_indio_dev_parent(const struct device *dev)
{ {
struct iio_backend *back = ERR_PTR(-ENODEV), *iter; struct iio_backend *back = ERR_PTR(-ENODEV), *iter;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#define _IIO_BACKEND_H_ #define _IIO_BACKEND_H_
#include <linux/types.h> #include <linux/types.h>
#include <linux/iio/iio.h>
struct iio_chan_spec; struct iio_chan_spec;
struct fwnode_handle; struct fwnode_handle;
...@@ -85,6 +86,7 @@ enum iio_backend_sample_trigger { ...@@ -85,6 +86,7 @@ enum iio_backend_sample_trigger {
* @extend_chan_spec: Extend an IIO channel. * @extend_chan_spec: Extend an IIO channel.
* @ext_info_set: Extended info setter. * @ext_info_set: Extended info setter.
* @ext_info_get: Extended info getter. * @ext_info_get: Extended info getter.
* @read_raw: Read a channel attribute from a backend device
* @debugfs_print_chan_status: Print channel status into a buffer. * @debugfs_print_chan_status: Print channel status into a buffer.
* @debugfs_reg_access: Read or write register value of backend. * @debugfs_reg_access: Read or write register value of backend.
**/ **/
...@@ -119,6 +121,9 @@ struct iio_backend_ops { ...@@ -119,6 +121,9 @@ struct iio_backend_ops {
const char *buf, size_t len); const char *buf, size_t len);
int (*ext_info_get)(struct iio_backend *back, uintptr_t private, int (*ext_info_get)(struct iio_backend *back, uintptr_t private,
const struct iio_chan_spec *chan, char *buf); const struct iio_chan_spec *chan, char *buf);
int (*read_raw)(struct iio_backend *back,
struct iio_chan_spec const *chan, int *val, int *val2,
long mask);
int (*debugfs_print_chan_status)(struct iio_backend *back, int (*debugfs_print_chan_status)(struct iio_backend *back,
unsigned int chan, char *buf, unsigned int chan, char *buf,
size_t len); size_t len);
...@@ -162,7 +167,9 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private, ...@@ -162,7 +167,9 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private,
const char *buf, size_t len); const char *buf, size_t len);
ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private, ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,
const struct iio_chan_spec *chan, char *buf); const struct iio_chan_spec *chan, char *buf);
int iio_backend_read_raw(struct iio_backend *back,
struct iio_chan_spec const *chan, int *val, int *val2,
long mask);
int iio_backend_extend_chan_spec(struct iio_backend *back, int iio_backend_extend_chan_spec(struct iio_backend *back,
struct iio_chan_spec *chan); struct iio_chan_spec *chan);
void *iio_backend_get_priv(const struct iio_backend *conv); void *iio_backend_get_priv(const struct iio_backend *conv);
...@@ -174,6 +181,21 @@ __devm_iio_backend_get_from_fwnode_lookup(struct device *dev, ...@@ -174,6 +181,21 @@ __devm_iio_backend_get_from_fwnode_lookup(struct device *dev,
int devm_iio_backend_register(struct device *dev, int devm_iio_backend_register(struct device *dev,
const struct iio_backend_info *info, void *priv); const struct iio_backend_info *info, void *priv);
static inline int iio_backend_read_scale(struct iio_backend *back,
struct iio_chan_spec const *chan,
int *val, int *val2)
{
return iio_backend_read_raw(back, chan, val, val2, IIO_CHAN_INFO_SCALE);
}
static inline int iio_backend_read_offset(struct iio_backend *back,
struct iio_chan_spec const *chan,
int *val, int *val2)
{
return iio_backend_read_raw(back, chan, val, val2,
IIO_CHAN_INFO_OFFSET);
}
ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back, ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back,
unsigned int chan, char *buf, unsigned int chan, char *buf,
size_t len); size_t len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment