consumer.h 6.2 KB

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