Skip to content

Commit 8a848e7

Browse files
peda-rgregkh
authored andcommitted
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>
1 parent 2c089f0 commit 8a848e7

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎drivers/iio/inkern.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,3 +869,63 @@ int iio_write_channel_raw(struct iio_channel *chan, int val)
869869
return ret;
870870
}
871871
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);

‎include/linux/iio/consumer.h‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,41 @@ int iio_read_channel_scale(struct iio_channel *chan, int *val,
312312
int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
313313
int *processed, unsigned int scale);
314314

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+
315352
#endif

0 commit comments

Comments
 (0)