1 // SPDX-License-Identifier: GPL-2.0-only
2 /* The industrial I/O core in kernel channel mapping
4 * Copyright (c) 2011 Jonathan Cameron
7 #include <linux/export.h>
8 #include <linux/minmax.h>
9 #include <linux/mutex.h>
10 #include <linux/property.h>
11 #include <linux/slab.h>
13 #include <linux/iio/iio.h>
14 #include <linux/iio/iio-opaque.h>
16 #include <linux/iio/machine.h>
17 #include <linux/iio/driver.h>
18 #include <linux/iio/consumer.h>
20 struct iio_map_internal {
21 struct iio_dev *indio_dev;
26 static LIST_HEAD(iio_map_list);
27 static DEFINE_MUTEX(iio_map_list_lock);
29 static int iio_map_array_unregister_locked(struct iio_dev *indio_dev)
32 struct iio_map_internal *mapi, *next;
34 list_for_each_entry_safe(mapi, next, &iio_map_list, l) {
35 if (indio_dev == mapi->indio_dev) {
44 int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
47 struct iio_map_internal *mapi;
52 mutex_lock(&iio_map_list_lock);
53 while (maps[i].consumer_dev_name) {
54 mapi = kzalloc(sizeof(*mapi), GFP_KERNEL);
60 mapi->indio_dev = indio_dev;
61 list_add_tail(&mapi->l, &iio_map_list);
66 iio_map_array_unregister_locked(indio_dev);
67 mutex_unlock(&iio_map_list_lock);
71 EXPORT_SYMBOL_GPL(iio_map_array_register);
74 * Remove all map entries associated with the given iio device
76 int iio_map_array_unregister(struct iio_dev *indio_dev)
80 mutex_lock(&iio_map_list_lock);
81 ret = iio_map_array_unregister_locked(indio_dev);
82 mutex_unlock(&iio_map_list_lock);
86 EXPORT_SYMBOL_GPL(iio_map_array_unregister);
88 static void iio_map_array_unregister_cb(void *indio_dev)
90 iio_map_array_unregister(indio_dev);
93 int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, struct iio_map *maps)
97 ret = iio_map_array_register(indio_dev, maps);
101 return devm_add_action_or_reset(dev, iio_map_array_unregister_cb, indio_dev);
103 EXPORT_SYMBOL_GPL(devm_iio_map_array_register);
105 static const struct iio_chan_spec
106 *iio_chan_spec_from_name(const struct iio_dev *indio_dev, const char *name)
109 const struct iio_chan_spec *chan = NULL;
111 for (i = 0; i < indio_dev->num_channels; i++)
112 if (indio_dev->channels[i].datasheet_name &&
113 strcmp(name, indio_dev->channels[i].datasheet_name) == 0) {
114 chan = &indio_dev->channels[i];
121 * __fwnode_iio_simple_xlate - translate iiospec to the IIO channel index
122 * @indio_dev: pointer to the iio_dev structure
123 * @iiospec: IIO specifier as found in the device tree
125 * This is simple translation function, suitable for the most 1:1 mapped
126 * channels in IIO chips. This function performs only one sanity check:
127 * whether IIO index is less than num_channels (that is specified in the
130 static int __fwnode_iio_simple_xlate(struct iio_dev *indio_dev,
131 const struct fwnode_reference_args *iiospec)
136 if (iiospec->args[0] >= indio_dev->num_channels) {
137 dev_err(&indio_dev->dev, "invalid channel index %llu\n",
142 return iiospec->args[0];
145 static int __fwnode_iio_channel_get(struct iio_channel *channel,
146 struct fwnode_handle *fwnode, int index)
148 struct fwnode_reference_args iiospec;
150 struct iio_dev *indio_dev;
153 err = fwnode_property_get_reference_args(fwnode, "io-channels",
154 "#io-channel-cells", 0,
159 idev = bus_find_device_by_fwnode(&iio_bus_type, iiospec.fwnode);
161 fwnode_handle_put(iiospec.fwnode);
162 return -EPROBE_DEFER;
165 indio_dev = dev_to_iio_dev(idev);
166 channel->indio_dev = indio_dev;
167 if (indio_dev->info->fwnode_xlate)
168 index = indio_dev->info->fwnode_xlate(indio_dev, &iiospec);
170 index = __fwnode_iio_simple_xlate(indio_dev, &iiospec);
171 fwnode_handle_put(iiospec.fwnode);
174 channel->channel = &indio_dev->channels[index];
179 iio_device_put(indio_dev);
183 static struct iio_channel *fwnode_iio_channel_get(struct fwnode_handle *fwnode,
186 struct iio_channel *channel;
190 return ERR_PTR(-EINVAL);
192 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
194 return ERR_PTR(-ENOMEM);
196 err = __fwnode_iio_channel_get(channel, fwnode, index);
198 goto err_free_channel;
207 static struct iio_channel *
208 __fwnode_iio_channel_get_by_name(struct fwnode_handle *fwnode, const char *name)
210 struct iio_channel *chan;
214 * For named iio channels, first look up the name in the
215 * "io-channel-names" property. If it cannot be found, the
216 * index will be an error code, and fwnode_iio_channel_get()
220 index = fwnode_property_match_string(fwnode, "io-channel-names",
223 chan = fwnode_iio_channel_get(fwnode, index);
224 if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
228 pr_err("ERROR: could not get IIO channel %pfw:%s(%i)\n",
229 fwnode, name, index);
231 * In this case, we found 'name' in 'io-channel-names'
232 * but somehow we still fail so that we should not proceed
233 * with any other lookup. Hence, explicitly return -EINVAL
234 * (maybe not the better error code) so that the caller
235 * won't do a system lookup.
237 return ERR_PTR(-EINVAL);
240 * If index < 0, then fwnode_property_get_reference_args() fails
241 * with -EINVAL or -ENOENT (ACPI case) which is expected. We
242 * should not proceed if we get any other error.
244 if (PTR_ERR(chan) != -EINVAL && PTR_ERR(chan) != -ENOENT)
246 } else if (PTR_ERR(chan) != -ENOENT) {
248 * if !name, then we should only proceed the lookup if
249 * fwnode_property_get_reference_args() returns -ENOENT.
254 /* so we continue the lookup */
255 return ERR_PTR(-ENODEV);
258 struct iio_channel *fwnode_iio_channel_get_by_name(struct fwnode_handle *fwnode,
261 struct fwnode_handle *parent;
262 struct iio_channel *chan;
264 /* Walk up the tree of devices looking for a matching iio channel */
265 chan = __fwnode_iio_channel_get_by_name(fwnode, name);
266 if (!IS_ERR(chan) || PTR_ERR(chan) != -ENODEV)
270 * No matching IIO channel found on this node.
271 * If the parent node has a "io-channel-ranges" property,
272 * then we can try one of its channels.
274 fwnode_for_each_parent_node(fwnode, parent) {
275 if (!fwnode_property_present(parent, "io-channel-ranges")) {
276 fwnode_handle_put(parent);
277 return ERR_PTR(-ENODEV);
280 chan = __fwnode_iio_channel_get_by_name(fwnode, name);
281 if (!IS_ERR(chan) || PTR_ERR(chan) != -ENODEV) {
282 fwnode_handle_put(parent);
287 return ERR_PTR(-ENODEV);
289 EXPORT_SYMBOL_GPL(fwnode_iio_channel_get_by_name);
291 static struct iio_channel *fwnode_iio_channel_get_all(struct device *dev)
293 struct fwnode_handle *fwnode = dev_fwnode(dev);
294 struct iio_channel *chans;
295 int i, mapind, nummaps = 0;
299 ret = fwnode_property_get_reference_args(fwnode, "io-channels",
300 "#io-channel-cells", 0,
307 return ERR_PTR(-ENODEV);
309 /* NULL terminated array to save passing size */
310 chans = kcalloc(nummaps + 1, sizeof(*chans), GFP_KERNEL);
312 return ERR_PTR(-ENOMEM);
314 /* Search for FW matches */
315 for (mapind = 0; mapind < nummaps; mapind++) {
316 ret = __fwnode_iio_channel_get(&chans[mapind], fwnode, mapind);
318 goto error_free_chans;
323 for (i = 0; i < mapind; i++)
324 iio_device_put(chans[i].indio_dev);
329 static struct iio_channel *iio_channel_get_sys(const char *name,
330 const char *channel_name)
332 struct iio_map_internal *c_i = NULL, *c = NULL;
333 struct iio_channel *channel;
336 if (!(name || channel_name))
337 return ERR_PTR(-ENODEV);
339 /* first find matching entry the channel map */
340 mutex_lock(&iio_map_list_lock);
341 list_for_each_entry(c_i, &iio_map_list, l) {
342 if ((name && strcmp(name, c_i->map->consumer_dev_name) != 0) ||
344 strcmp(channel_name, c_i->map->consumer_channel) != 0))
347 iio_device_get(c->indio_dev);
350 mutex_unlock(&iio_map_list_lock);
352 return ERR_PTR(-ENODEV);
354 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
360 channel->indio_dev = c->indio_dev;
362 if (c->map->adc_channel_label) {
364 iio_chan_spec_from_name(channel->indio_dev,
365 c->map->adc_channel_label);
367 if (!channel->channel) {
378 iio_device_put(c->indio_dev);
382 struct iio_channel *iio_channel_get(struct device *dev,
383 const char *channel_name)
385 const char *name = dev ? dev_name(dev) : NULL;
386 struct iio_channel *channel;
389 channel = fwnode_iio_channel_get_by_name(dev_fwnode(dev),
391 if (!IS_ERR(channel) || PTR_ERR(channel) != -ENODEV)
395 return iio_channel_get_sys(name, channel_name);
397 EXPORT_SYMBOL_GPL(iio_channel_get);
399 void iio_channel_release(struct iio_channel *channel)
403 iio_device_put(channel->indio_dev);
406 EXPORT_SYMBOL_GPL(iio_channel_release);
408 static void devm_iio_channel_free(void *iio_channel)
410 iio_channel_release(iio_channel);
413 struct iio_channel *devm_iio_channel_get(struct device *dev,
414 const char *channel_name)
416 struct iio_channel *channel;
419 channel = iio_channel_get(dev, channel_name);
423 ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
429 EXPORT_SYMBOL_GPL(devm_iio_channel_get);
431 struct iio_channel *devm_fwnode_iio_channel_get_by_name(struct device *dev,
432 struct fwnode_handle *fwnode,
433 const char *channel_name)
435 struct iio_channel *channel;
438 channel = fwnode_iio_channel_get_by_name(fwnode, channel_name);
442 ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
448 EXPORT_SYMBOL_GPL(devm_fwnode_iio_channel_get_by_name);
450 struct iio_channel *iio_channel_get_all(struct device *dev)
453 struct iio_channel *chans;
454 struct iio_map_internal *c = NULL;
460 return ERR_PTR(-EINVAL);
462 chans = fwnode_iio_channel_get_all(dev);
464 * We only want to carry on if the error is -ENODEV. Anything else
465 * should be reported up the stack.
467 if (!IS_ERR(chans) || PTR_ERR(chans) != -ENODEV)
470 name = dev_name(dev);
472 mutex_lock(&iio_map_list_lock);
473 /* first count the matching maps */
474 list_for_each_entry(c, &iio_map_list, l)
475 if (name && strcmp(name, c->map->consumer_dev_name) != 0)
485 /* NULL terminated array to save passing size */
486 chans = kcalloc(nummaps + 1, sizeof(*chans), GFP_KERNEL);
492 /* for each map fill in the chans element */
493 list_for_each_entry(c, &iio_map_list, l) {
494 if (name && strcmp(name, c->map->consumer_dev_name) != 0)
496 chans[mapind].indio_dev = c->indio_dev;
497 chans[mapind].data = c->map->consumer_data;
498 chans[mapind].channel =
499 iio_chan_spec_from_name(chans[mapind].indio_dev,
500 c->map->adc_channel_label);
501 if (!chans[mapind].channel) {
503 goto error_free_chans;
505 iio_device_get(chans[mapind].indio_dev);
510 goto error_free_chans;
512 mutex_unlock(&iio_map_list_lock);
517 for (i = 0; i < nummaps; i++)
518 iio_device_put(chans[i].indio_dev);
521 mutex_unlock(&iio_map_list_lock);
525 EXPORT_SYMBOL_GPL(iio_channel_get_all);
527 void iio_channel_release_all(struct iio_channel *channels)
529 struct iio_channel *chan = &channels[0];
531 while (chan->indio_dev) {
532 iio_device_put(chan->indio_dev);
537 EXPORT_SYMBOL_GPL(iio_channel_release_all);
539 static void devm_iio_channel_free_all(void *iio_channels)
541 iio_channel_release_all(iio_channels);
544 struct iio_channel *devm_iio_channel_get_all(struct device *dev)
546 struct iio_channel *channels;
549 channels = iio_channel_get_all(dev);
550 if (IS_ERR(channels))
553 ret = devm_add_action_or_reset(dev, devm_iio_channel_free_all,
560 EXPORT_SYMBOL_GPL(devm_iio_channel_get_all);
562 static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
563 enum iio_chan_info_enum info)
566 int vals[INDIO_MAX_RAW_ELEMENTS];
573 if (!iio_channel_has_info(chan->channel, info))
576 if (chan->indio_dev->info->read_raw_multi) {
577 ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
578 chan->channel, INDIO_MAX_RAW_ELEMENTS,
579 vals, &val_len, info);
583 ret = chan->indio_dev->info->read_raw(chan->indio_dev,
584 chan->channel, val, val2, info);
590 int iio_read_channel_raw(struct iio_channel *chan, int *val)
592 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
595 mutex_lock(&iio_dev_opaque->info_exist_lock);
596 if (!chan->indio_dev->info) {
601 ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
603 mutex_unlock(&iio_dev_opaque->info_exist_lock);
607 EXPORT_SYMBOL_GPL(iio_read_channel_raw);
609 int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
611 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
614 mutex_lock(&iio_dev_opaque->info_exist_lock);
615 if (!chan->indio_dev->info) {
620 ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW);
622 mutex_unlock(&iio_dev_opaque->info_exist_lock);
626 EXPORT_SYMBOL_GPL(iio_read_channel_average_raw);
628 static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
629 int raw, int *processed,
632 int scale_type, scale_val, scale_val2;
633 int offset_type, offset_val, offset_val2;
636 offset_type = iio_channel_read(chan, &offset_val, &offset_val2,
637 IIO_CHAN_INFO_OFFSET);
638 if (offset_type >= 0) {
639 switch (offset_type) {
642 case IIO_VAL_INT_PLUS_MICRO:
643 case IIO_VAL_INT_PLUS_NANO:
645 * Both IIO_VAL_INT_PLUS_MICRO and IIO_VAL_INT_PLUS_NANO
646 * implicitely truncate the offset to it's integer form.
649 case IIO_VAL_FRACTIONAL:
650 offset_val /= offset_val2;
652 case IIO_VAL_FRACTIONAL_LOG2:
653 offset_val >>= offset_val2;
662 scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
663 IIO_CHAN_INFO_SCALE);
664 if (scale_type < 0) {
666 * If no channel scaling is available apply consumer scale to
667 * raw value and return.
669 *processed = raw * scale;
673 switch (scale_type) {
675 *processed = raw64 * scale_val * scale;
677 case IIO_VAL_INT_PLUS_MICRO:
679 *processed = -raw64 * scale_val;
681 *processed = raw64 * scale_val;
682 *processed += div_s64(raw64 * (s64)scale_val2 * scale,
685 case IIO_VAL_INT_PLUS_NANO:
687 *processed = -raw64 * scale_val;
689 *processed = raw64 * scale_val;
690 *processed += div_s64(raw64 * (s64)scale_val2 * scale,
693 case IIO_VAL_FRACTIONAL:
694 *processed = div_s64(raw64 * (s64)scale_val * scale,
697 case IIO_VAL_FRACTIONAL_LOG2:
698 *processed = (raw64 * (s64)scale_val * scale) >> scale_val2;
707 int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
708 int *processed, unsigned int scale)
710 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
713 mutex_lock(&iio_dev_opaque->info_exist_lock);
714 if (!chan->indio_dev->info) {
719 ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed,
722 mutex_unlock(&iio_dev_opaque->info_exist_lock);
726 EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);
728 int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
729 enum iio_chan_info_enum attribute)
731 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
734 mutex_lock(&iio_dev_opaque->info_exist_lock);
735 if (!chan->indio_dev->info) {
740 ret = iio_channel_read(chan, val, val2, attribute);
742 mutex_unlock(&iio_dev_opaque->info_exist_lock);
746 EXPORT_SYMBOL_GPL(iio_read_channel_attribute);
748 int iio_read_channel_offset(struct iio_channel *chan, int *val, int *val2)
750 return iio_read_channel_attribute(chan, val, val2, IIO_CHAN_INFO_OFFSET);
752 EXPORT_SYMBOL_GPL(iio_read_channel_offset);
754 int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
757 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
760 mutex_lock(&iio_dev_opaque->info_exist_lock);
761 if (!chan->indio_dev->info) {
766 if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)) {
767 ret = iio_channel_read(chan, val, NULL,
768 IIO_CHAN_INFO_PROCESSED);
773 ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
776 ret = iio_convert_raw_to_processed_unlocked(chan, *val, val,
781 mutex_unlock(&iio_dev_opaque->info_exist_lock);
785 EXPORT_SYMBOL_GPL(iio_read_channel_processed_scale);
787 int iio_read_channel_processed(struct iio_channel *chan, int *val)
789 /* This is just a special case with scale factor 1 */
790 return iio_read_channel_processed_scale(chan, val, 1);
792 EXPORT_SYMBOL_GPL(iio_read_channel_processed);
794 int iio_read_channel_scale(struct iio_channel *chan, int *val, int *val2)
796 return iio_read_channel_attribute(chan, val, val2, IIO_CHAN_INFO_SCALE);
798 EXPORT_SYMBOL_GPL(iio_read_channel_scale);
800 static int iio_channel_read_avail(struct iio_channel *chan,
801 const int **vals, int *type, int *length,
802 enum iio_chan_info_enum info)
804 if (!iio_channel_has_available(chan->channel, info))
807 return chan->indio_dev->info->read_avail(chan->indio_dev, chan->channel,
808 vals, type, length, info);
811 int iio_read_avail_channel_attribute(struct iio_channel *chan,
812 const int **vals, int *type, int *length,
813 enum iio_chan_info_enum attribute)
815 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
818 mutex_lock(&iio_dev_opaque->info_exist_lock);
819 if (!chan->indio_dev->info) {
824 ret = iio_channel_read_avail(chan, vals, type, length, attribute);
826 mutex_unlock(&iio_dev_opaque->info_exist_lock);
830 EXPORT_SYMBOL_GPL(iio_read_avail_channel_attribute);
832 int iio_read_avail_channel_raw(struct iio_channel *chan,
833 const int **vals, int *length)
838 ret = iio_read_avail_channel_attribute(chan, vals, &type, length,
841 if (ret >= 0 && type != IIO_VAL_INT)
842 /* raw values are assumed to be IIO_VAL_INT */
847 EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw);
849 static int iio_channel_read_max(struct iio_channel *chan,
850 int *val, int *val2, int *type,
851 enum iio_chan_info_enum info)
857 ret = iio_channel_read_avail(chan, &vals, type, &length, info);
862 case IIO_AVAIL_RANGE:
879 *val = max_array(vals, length);
882 /* TODO: learn about max for other iio values */
892 int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
894 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
898 mutex_lock(&iio_dev_opaque->info_exist_lock);
899 if (!chan->indio_dev->info) {
904 ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
906 mutex_unlock(&iio_dev_opaque->info_exist_lock);
910 EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);
912 static int iio_channel_read_min(struct iio_channel *chan,
913 int *val, int *val2, int *type,
914 enum iio_chan_info_enum info)
920 ret = iio_channel_read_avail(chan, &vals, type, &length, info);
925 case IIO_AVAIL_RANGE:
942 *val = min_array(vals, length);
945 /* TODO: learn about min for other iio values */
955 int iio_read_min_channel_raw(struct iio_channel *chan, int *val)
957 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
961 mutex_lock(&iio_dev_opaque->info_exist_lock);
962 if (!chan->indio_dev->info) {
967 ret = iio_channel_read_min(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
969 mutex_unlock(&iio_dev_opaque->info_exist_lock);
973 EXPORT_SYMBOL_GPL(iio_read_min_channel_raw);
975 int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
977 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
979 /* Need to verify underlying driver has not gone away */
981 mutex_lock(&iio_dev_opaque->info_exist_lock);
982 if (!chan->indio_dev->info) {
987 *type = chan->channel->type;
989 mutex_unlock(&iio_dev_opaque->info_exist_lock);
993 EXPORT_SYMBOL_GPL(iio_get_channel_type);
995 static int iio_channel_write(struct iio_channel *chan, int val, int val2,
996 enum iio_chan_info_enum info)
998 return chan->indio_dev->info->write_raw(chan->indio_dev,
999 chan->channel, val, val2, info);
1002 int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
1003 enum iio_chan_info_enum attribute)
1005 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
1008 mutex_lock(&iio_dev_opaque->info_exist_lock);
1009 if (!chan->indio_dev->info) {
1014 ret = iio_channel_write(chan, val, val2, attribute);
1016 mutex_unlock(&iio_dev_opaque->info_exist_lock);
1020 EXPORT_SYMBOL_GPL(iio_write_channel_attribute);
1022 int iio_write_channel_raw(struct iio_channel *chan, int val)
1024 return iio_write_channel_attribute(chan, val, 0, IIO_CHAN_INFO_RAW);
1026 EXPORT_SYMBOL_GPL(iio_write_channel_raw);
1028 unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan)
1030 const struct iio_chan_spec_ext_info *ext_info;
1033 if (!chan->channel->ext_info)
1036 for (ext_info = chan->channel->ext_info; ext_info->name; ext_info++)
1041 EXPORT_SYMBOL_GPL(iio_get_channel_ext_info_count);
1043 static const struct iio_chan_spec_ext_info *
1044 iio_lookup_ext_info(const struct iio_channel *chan, const char *attr)
1046 const struct iio_chan_spec_ext_info *ext_info;
1048 if (!chan->channel->ext_info)
1051 for (ext_info = chan->channel->ext_info; ext_info->name; ++ext_info) {
1052 if (!strcmp(attr, ext_info->name))
1059 ssize_t iio_read_channel_ext_info(struct iio_channel *chan,
1060 const char *attr, char *buf)
1062 const struct iio_chan_spec_ext_info *ext_info;
1064 ext_info = iio_lookup_ext_info(chan, attr);
1068 return ext_info->read(chan->indio_dev, ext_info->private,
1069 chan->channel, buf);
1071 EXPORT_SYMBOL_GPL(iio_read_channel_ext_info);
1073 ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr,
1074 const char *buf, size_t len)
1076 const struct iio_chan_spec_ext_info *ext_info;
1078 ext_info = iio_lookup_ext_info(chan, attr);
1082 return ext_info->write(chan->indio_dev, ext_info->private,
1083 chan->channel, buf, len);
1085 EXPORT_SYMBOL_GPL(iio_write_channel_ext_info);