consumer.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. * @data: Data about the channel used by consumer.
  20. */
  21. struct iio_channel {
  22. struct iio_dev *indio_dev;
  23. const struct iio_chan_spec *channel;
  24. void *data;
  25. };
  26. /**
  27. * iio_channel_get() - get description of all that is needed to access channel.
  28. * @name: Unique name of the device as provided in the iio_map
  29. * with which the desired provider to consumer mapping
  30. * was registered.
  31. * @consumer_channel: Unique name to identify the channel on the consumer
  32. * side. This typically describes the channels use within
  33. * the consumer. E.g. 'battery_voltage'
  34. */
  35. struct iio_channel *iio_channel_get(const char *name,
  36. const char *consumer_channel);
  37. /**
  38. * iio_channel_release() - release channels obtained via iio_channel_get
  39. * @chan: The channel to be released.
  40. */
  41. void iio_channel_release(struct iio_channel *chan);
  42. /**
  43. * iio_channel_get_all() - get all channels associated with a client
  44. * @name: name of consumer device.
  45. *
  46. * Returns an array of iio_channel structures terminated with one with
  47. * null iio_dev pointer.
  48. * This function is used by fairly generic consumers to get all the
  49. * channels registered as having this consumer.
  50. */
  51. struct iio_channel *iio_channel_get_all(const char *name);
  52. /**
  53. * iio_channel_release_all() - reverse iio_channel_get_all
  54. * @chan: Array of channels to be released.
  55. */
  56. void iio_channel_release_all(struct iio_channel *chan);
  57. struct iio_cb_buffer;
  58. /**
  59. * iio_channel_get_all_cb() - register callback for triggered capture
  60. * @name: Name of client device.
  61. * @cb: Callback function.
  62. * @private: Private data passed to callback.
  63. *
  64. * NB right now we have no ability to mux data from multiple devices.
  65. * So if the channels requested come from different devices this will
  66. * fail.
  67. */
  68. struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
  69. int (*cb)(u8 *data,
  70. void *private),
  71. void *private);
  72. /**
  73. * iio_channel_release_all_cb() - release and unregister the callback.
  74. * @cb_buffer: The callback buffer that was allocated.
  75. */
  76. void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
  77. /**
  78. * iio_channel_start_all_cb() - start the flow of data through callback.
  79. * @cb_buff: The callback buffer we are starting.
  80. */
  81. int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
  82. /**
  83. * iio_channel_stop_all_cb() - stop the flow of data through the callback.
  84. * @cb_buff: The callback buffer we are stopping.
  85. */
  86. void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
  87. /**
  88. * iio_channel_cb_get_channels() - get access to the underlying channels.
  89. * @cb_buff: The callback buffer from whom we want the channel
  90. * information.
  91. *
  92. * This function allows one to obtain information about the channels.
  93. * Whilst this may allow direct reading if all buffers are disabled, the
  94. * primary aim is to allow drivers that are consuming a channel to query
  95. * things like scaling of the channel.
  96. */
  97. struct iio_channel
  98. *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
  99. /**
  100. * iio_read_channel_raw() - read from a given channel
  101. * @chan: The channel being queried.
  102. * @val: Value read back.
  103. *
  104. * Note raw reads from iio channels are in adc counts and hence
  105. * scale will need to be applied if standard units required.
  106. */
  107. int iio_read_channel_raw(struct iio_channel *chan,
  108. int *val);
  109. /**
  110. * iio_read_channel_processed() - read processed value from a given channel
  111. * @chan: The channel being queried.
  112. * @val: Value read back.
  113. *
  114. * Returns an error code or 0.
  115. *
  116. * This function will read a processed value from a channel. A processed value
  117. * means that this value will have the correct unit and not some device internal
  118. * representation. If the device does not support reporting a processed value
  119. * the function will query the raw value and the channels scale and offset and
  120. * do the appropriate transformation.
  121. */
  122. int iio_read_channel_processed(struct iio_channel *chan, int *val);
  123. /**
  124. * iio_get_channel_type() - get the type of a channel
  125. * @channel: The channel being queried.
  126. * @type: The type of the channel.
  127. *
  128. * returns the enum iio_chan_type of the channel
  129. */
  130. int iio_get_channel_type(struct iio_channel *channel,
  131. enum iio_chan_type *type);
  132. /**
  133. * iio_read_channel_scale() - read the scale value for a channel
  134. * @chan: The channel being queried.
  135. * @val: First part of value read back.
  136. * @val2: Second part of value read back.
  137. *
  138. * Note returns a description of what is in val and val2, such
  139. * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
  140. * + val2/1e6
  141. */
  142. int iio_read_channel_scale(struct iio_channel *chan, int *val,
  143. int *val2);
  144. /**
  145. * iio_convert_raw_to_processed() - Converts a raw value to a processed value
  146. * @chan: The channel being queried
  147. * @raw: The raw IIO to convert
  148. * @processed: The result of the conversion
  149. * @scale: Scale factor to apply during the conversion
  150. *
  151. * Returns an error code or 0.
  152. *
  153. * This function converts a raw value to processed value for a specific channel.
  154. * A raw value is the device internal representation of a sample and the value
  155. * returned by iio_read_channel_raw, so the unit of that value is device
  156. * depended. A processed value on the other hand is value has a normed unit
  157. * according with the IIO specification.
  158. *
  159. * The scale factor allows to increase the precession of the returned value. For
  160. * a scale factor of 1 the function will return the result in the normal IIO
  161. * unit for the channel type. E.g. millivolt for voltage channels, if you want
  162. * nanovolts instead pass 1000 as the scale factor.
  163. */
  164. int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
  165. int *processed, unsigned int scale);
  166. #endif