consumer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Industrial I/O in kernel consumer interface
  3. *
  4. * Copyright (c) 2011 Jonathan Cameron
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #ifndef _IIO_INKERN_CONSUMER_H_
  11. #define _IIO_INKERN_CONSUMER_H
  12. #include <linux/iio/types.h>
  13. struct iio_dev;
  14. struct iio_chan_spec;
  15. /**
  16. * struct iio_channel - everything needed for a consumer to use a channel
  17. * @indio_dev: Device on which the channel exists.
  18. * @channel: Full description of the channel.
  19. */
  20. struct iio_channel {
  21. struct iio_dev *indio_dev;
  22. const struct iio_chan_spec *channel;
  23. };
  24. /**
  25. * iio_channel_get() - get description of all that is needed to access channel.
  26. * @name: Unique name of the device as provided in the iio_map
  27. * with which the desired provider to consumer mapping
  28. * was registered.
  29. * @consumer_channel: Unique name to identify the channel on the consumer
  30. * side. This typically describes the channels use within
  31. * the consumer. E.g. 'battery_voltage'
  32. */
  33. struct iio_channel *iio_channel_get(const char *name,
  34. const char *consumer_channel);
  35. /**
  36. * iio_channel_release() - release channels obtained via iio_channel_get
  37. * @chan: The channel to be released.
  38. */
  39. void iio_channel_release(struct iio_channel *chan);
  40. /**
  41. * iio_channel_get_all() - get all channels associated with a client
  42. * @name: name of consumer device.
  43. *
  44. * Returns an array of iio_channel structures terminated with one with
  45. * null iio_dev pointer.
  46. * This function is used by fairly generic consumers to get all the
  47. * channels registered as having this consumer.
  48. */
  49. struct iio_channel *iio_channel_get_all(const char *name);
  50. /**
  51. * iio_channel_release_all() - reverse iio_channel_get_all
  52. * @chan: Array of channels to be released.
  53. */
  54. void iio_channel_release_all(struct iio_channel *chan);
  55. /**
  56. * iio_read_channel_raw() - read from a given channel
  57. * @channel: The channel being queried.
  58. * @val: Value read back.
  59. *
  60. * Note raw reads from iio channels are in adc counts and hence
  61. * scale will need to be applied if standard units required.
  62. */
  63. int iio_read_channel_raw(struct iio_channel *chan,
  64. int *val);
  65. /**
  66. * iio_get_channel_type() - get the type of a channel
  67. * @channel: The channel being queried.
  68. * @type: The type of the channel.
  69. *
  70. * returns the enum iio_chan_type of the channel
  71. */
  72. int iio_get_channel_type(struct iio_channel *channel,
  73. enum iio_chan_type *type);
  74. /**
  75. * iio_read_channel_scale() - read the scale value for a channel
  76. * @channel: The channel being queried.
  77. * @val: First part of value read back.
  78. * @val2: Second part of value read back.
  79. *
  80. * Note returns a description of what is in val and val2, such
  81. * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
  82. * + val2/1e6
  83. */
  84. int iio_read_channel_scale(struct iio_channel *chan, int *val,
  85. int *val2);
  86. #endif