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

iio: inkern: api for manipulating ext_info of iio channels

Extend the inkern api with functions for reading and writing ext_info
of iio channels.

Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Peter Rosin and committed by
Greg Kroah-Hartman
8a848e75 2c089f08

+97
+60
drivers/iio/inkern.c
··· 869 869 return ret; 870 870 } 871 871 EXPORT_SYMBOL_GPL(iio_write_channel_raw); 872 + 873 + unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan) 874 + { 875 + const struct iio_chan_spec_ext_info *ext_info; 876 + unsigned int i = 0; 877 + 878 + if (!chan->channel->ext_info) 879 + return i; 880 + 881 + for (ext_info = chan->channel->ext_info; ext_info->name; ext_info++) 882 + ++i; 883 + 884 + return i; 885 + } 886 + EXPORT_SYMBOL_GPL(iio_get_channel_ext_info_count); 887 + 888 + static const struct iio_chan_spec_ext_info *iio_lookup_ext_info( 889 + const struct iio_channel *chan, 890 + const char *attr) 891 + { 892 + const struct iio_chan_spec_ext_info *ext_info; 893 + 894 + if (!chan->channel->ext_info) 895 + return NULL; 896 + 897 + for (ext_info = chan->channel->ext_info; ext_info->name; ++ext_info) { 898 + if (!strcmp(attr, ext_info->name)) 899 + return ext_info; 900 + } 901 + 902 + return NULL; 903 + } 904 + 905 + ssize_t iio_read_channel_ext_info(struct iio_channel *chan, 906 + const char *attr, char *buf) 907 + { 908 + const struct iio_chan_spec_ext_info *ext_info; 909 + 910 + ext_info = iio_lookup_ext_info(chan, attr); 911 + if (!ext_info) 912 + return -EINVAL; 913 + 914 + return ext_info->read(chan->indio_dev, ext_info->private, 915 + chan->channel, buf); 916 + } 917 + EXPORT_SYMBOL_GPL(iio_read_channel_ext_info); 918 + 919 + ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, 920 + const char *buf, size_t len) 921 + { 922 + const struct iio_chan_spec_ext_info *ext_info; 923 + 924 + ext_info = iio_lookup_ext_info(chan, attr); 925 + if (!ext_info) 926 + return -EINVAL; 927 + 928 + return ext_info->write(chan->indio_dev, ext_info->private, 929 + chan->channel, buf, len); 930 + } 931 + EXPORT_SYMBOL_GPL(iio_write_channel_ext_info);
+37
include/linux/iio/consumer.h
··· 312 312 int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, 313 313 int *processed, unsigned int scale); 314 314 315 + /** 316 + * iio_get_channel_ext_info_count() - get number of ext_info attributes 317 + * connected to the channel. 318 + * @chan: The channel being queried 319 + * 320 + * Returns the number of ext_info attributes 321 + */ 322 + unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan); 323 + 324 + /** 325 + * iio_read_channel_ext_info() - read ext_info attribute from a given channel 326 + * @chan: The channel being queried. 327 + * @attr: The ext_info attribute to read. 328 + * @buf: Where to store the attribute value. Assumed to hold 329 + * at least PAGE_SIZE bytes. 330 + * 331 + * Returns the number of bytes written to buf (perhaps w/o zero termination; 332 + * it need not even be a string), or an error code. 333 + */ 334 + ssize_t iio_read_channel_ext_info(struct iio_channel *chan, 335 + const char *attr, char *buf); 336 + 337 + /** 338 + * iio_write_channel_ext_info() - write ext_info attribute from a given channel 339 + * @chan: The channel being queried. 340 + * @attr: The ext_info attribute to read. 341 + * @buf: The new attribute value. Strings needs to be zero- 342 + * terminated, but the terminator should not be included 343 + * in the below len. 344 + * @len: The size of the new attribute value. 345 + * 346 + * Returns the number of accepted bytes, which should be the same as len. 347 + * An error code can also be returned. 348 + */ 349 + ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, 350 + const char *buf, size_t len); 351 + 315 352 #endif