mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
iio: Add iio_read_channel_label to inkern API
It can be convenient for other in-kernel drivers to reuse IIO channel labels. Export the iio_read_channel_label function to allow this. The signature is different depending on where we are calling it from, so the meat is moved to do_iio_read_channel_label. Signed-off-by: Sean Anderson <sean.anderson@linux.dev> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://patch.msgid.link/20240624174601.1527244-2-sean.anderson@linux.dev Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
9641972917
commit
0214b27fc9
@ -34,6 +34,10 @@ void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
|
|||||||
struct iio_ioctl_handler *h);
|
struct iio_ioctl_handler *h);
|
||||||
void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
|
void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
|
||||||
|
|
||||||
|
ssize_t do_iio_read_channel_label(struct iio_dev *indio_dev,
|
||||||
|
const struct iio_chan_spec *c,
|
||||||
|
char *buf);
|
||||||
|
|
||||||
int __iio_add_chan_devattr(const char *postfix,
|
int __iio_add_chan_devattr(const char *postfix,
|
||||||
struct iio_chan_spec const *chan,
|
struct iio_chan_spec const *chan,
|
||||||
ssize_t (*func)(struct device *dev,
|
ssize_t (*func)(struct device *dev,
|
||||||
|
@ -727,20 +727,25 @@ ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(iio_format_value);
|
EXPORT_SYMBOL_GPL(iio_format_value);
|
||||||
|
|
||||||
|
ssize_t do_iio_read_channel_label(struct iio_dev *indio_dev,
|
||||||
|
const struct iio_chan_spec *c,
|
||||||
|
char *buf)
|
||||||
|
{
|
||||||
|
if (indio_dev->info->read_label)
|
||||||
|
return indio_dev->info->read_label(indio_dev, c, buf);
|
||||||
|
|
||||||
|
if (c->extend_name)
|
||||||
|
return sysfs_emit(buf, "%s\n", c->extend_name);
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t iio_read_channel_label(struct device *dev,
|
static ssize_t iio_read_channel_label(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
return do_iio_read_channel_label(dev_to_iio_dev(dev),
|
||||||
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
to_iio_dev_attr(attr)->c, buf);
|
||||||
|
|
||||||
if (indio_dev->info->read_label)
|
|
||||||
return indio_dev->info->read_label(indio_dev, this_attr->c, buf);
|
|
||||||
|
|
||||||
if (this_attr->c->extend_name)
|
|
||||||
return sysfs_emit(buf, "%s\n", this_attr->c->extend_name);
|
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t iio_read_channel_info(struct device *dev,
|
static ssize_t iio_read_channel_info(struct device *dev,
|
||||||
|
@ -1010,3 +1010,9 @@ ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr,
|
|||||||
chan->channel, buf, len);
|
chan->channel, buf, len);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(iio_write_channel_ext_info);
|
EXPORT_SYMBOL_GPL(iio_write_channel_ext_info);
|
||||||
|
|
||||||
|
ssize_t iio_read_channel_label(struct iio_channel *chan, char *buf)
|
||||||
|
{
|
||||||
|
return do_iio_read_channel_label(chan->indio_dev, chan->channel, buf);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(iio_read_channel_label);
|
||||||
|
@ -441,4 +441,14 @@ ssize_t iio_read_channel_ext_info(struct iio_channel *chan,
|
|||||||
ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr,
|
ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr,
|
||||||
const char *buf, size_t len);
|
const char *buf, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iio_read_channel_label() - read label for a given channel
|
||||||
|
* @chan: The channel being queried.
|
||||||
|
* @buf: Where to store the attribute value. Assumed to hold
|
||||||
|
* at least PAGE_SIZE bytes.
|
||||||
|
*
|
||||||
|
* Returns the number of bytes written to buf, or an error code.
|
||||||
|
*/
|
||||||
|
ssize_t iio_read_channel_label(struct iio_channel *chan, char *buf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user