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

iio: buffer-callback: allow getting underlying iio_dev

Add iio_channel_cb_get_iio_dev function to allow getting the
underlying iio_dev. This is useful for setting the trigger of the
consumer ADC device.

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Matt Ranostay and committed by
Jonathan Cameron
adca058b a4fa6509

+26 -10
+14 -10
drivers/iio/buffer/industrialio-buffer-cb.c
··· 18 18 int (*cb)(const void *data, void *private); 19 19 void *private; 20 20 struct iio_channel *channels; 21 + struct iio_dev *indio_dev; 21 22 }; 22 23 23 24 static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer) ··· 53 52 { 54 53 int ret; 55 54 struct iio_cb_buffer *cb_buff; 56 - struct iio_dev *indio_dev; 57 55 struct iio_channel *chan; 58 56 59 57 cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL); ··· 72 72 goto error_free_cb_buff; 73 73 } 74 74 75 - indio_dev = cb_buff->channels[0].indio_dev; 75 + cb_buff->indio_dev = cb_buff->channels[0].indio_dev; 76 76 cb_buff->buffer.scan_mask 77 - = kcalloc(BITS_TO_LONGS(indio_dev->masklength), sizeof(long), 78 - GFP_KERNEL); 77 + = kcalloc(BITS_TO_LONGS(cb_buff->indio_dev->masklength), 78 + sizeof(long), GFP_KERNEL); 79 79 if (cb_buff->buffer.scan_mask == NULL) { 80 80 ret = -ENOMEM; 81 81 goto error_release_channels; 82 82 } 83 83 chan = &cb_buff->channels[0]; 84 84 while (chan->indio_dev) { 85 - if (chan->indio_dev != indio_dev) { 85 + if (chan->indio_dev != cb_buff->indio_dev) { 86 86 ret = -EINVAL; 87 87 goto error_free_scan_mask; 88 88 } ··· 105 105 106 106 int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff) 107 107 { 108 - return iio_update_buffers(cb_buff->channels[0].indio_dev, 109 - &cb_buff->buffer, 108 + return iio_update_buffers(cb_buff->indio_dev, &cb_buff->buffer, 110 109 NULL); 111 110 } 112 111 EXPORT_SYMBOL_GPL(iio_channel_start_all_cb); 113 112 114 113 void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff) 115 114 { 116 - iio_update_buffers(cb_buff->channels[0].indio_dev, 117 - NULL, 118 - &cb_buff->buffer); 115 + iio_update_buffers(cb_buff->indio_dev, NULL, &cb_buff->buffer); 119 116 } 120 117 EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb); 121 118 ··· 129 132 return cb_buffer->channels; 130 133 } 131 134 EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels); 135 + 136 + struct iio_dev 137 + *iio_channel_cb_get_iio_dev(const struct iio_cb_buffer *cb_buffer) 138 + { 139 + return cb_buffer->indio_dev; 140 + } 141 + EXPORT_SYMBOL_GPL(iio_channel_cb_get_iio_dev); 132 142 133 143 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 134 144 MODULE_DESCRIPTION("Industrial I/O callback buffer");
+12
include/linux/iio/consumer.h
··· 165 165 *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer); 166 166 167 167 /** 168 + * iio_channel_cb_get_iio_dev() - get access to the underlying device. 169 + * @cb_buffer: The callback buffer from whom we want the device 170 + * information. 171 + * 172 + * This function allows one to obtain information about the device. 173 + * The primary aim is to allow drivers that are consuming a device to query 174 + * things like current trigger. 175 + */ 176 + struct iio_dev 177 + *iio_channel_cb_get_iio_dev(const struct iio_cb_buffer *cb_buffer); 178 + 179 + /** 168 180 * iio_read_channel_raw() - read from a given channel 169 181 * @chan: The channel being queried. 170 182 * @val: Value read back.