consumer.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  58. * iio_read_channel_raw() - read from a given channel
  59. * @chan: The channel being queried.
  60. * @val: Value read back.
  61. *
  62. * Note raw reads from iio channels are in adc counts and hence
  63. * scale will need to be applied if standard units required.
  64. */
  65. int iio_read_channel_raw(struct iio_channel *chan,
  66. int *val);
  67. /**
  68. * iio_read_channel_processed() - read processed value from a given channel
  69. * @chan: The channel being queried.
  70. * @val: Value read back.
  71. *
  72. * Returns an error code or 0.
  73. *
  74. * This function will read a processed value from a channel. A processed value
  75. * means that this value will have the correct unit and not some device internal
  76. * representation. If the device does not support reporting a processed value
  77. * the function will query the raw value and the channels scale and offset and
  78. * do the appropriate transformation.
  79. */
  80. int iio_read_channel_processed(struct iio_channel *chan, int *val);
  81. /**
  82. * iio_get_channel_type() - get the type of a channel
  83. * @channel: The channel being queried.
  84. * @type: The type of the channel.
  85. *
  86. * returns the enum iio_chan_type of the channel
  87. */
  88. int iio_get_channel_type(struct iio_channel *channel,
  89. enum iio_chan_type *type);
  90. /**
  91. * iio_read_channel_scale() - read the scale value for a channel
  92. * @chan: The channel being queried.
  93. * @val: First part of value read back.
  94. * @val2: Second part of value read back.
  95. *
  96. * Note returns a description of what is in val and val2, such
  97. * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
  98. * + val2/1e6
  99. */
  100. int iio_read_channel_scale(struct iio_channel *chan, int *val,
  101. int *val2);
  102. /**
  103. * iio_convert_raw_to_processed() - Converts a raw value to a processed value
  104. * @chan: The channel being queried
  105. * @raw: The raw IIO to convert
  106. * @processed: The result of the conversion
  107. * @scale: Scale factor to apply during the conversion
  108. *
  109. * Returns an error code or 0.
  110. *
  111. * This function converts a raw value to processed value for a specific channel.
  112. * A raw value is the device internal representation of a sample and the value
  113. * returned by iio_read_channel_raw, so the unit of that value is device
  114. * depended. A processed value on the other hand is value has a normed unit
  115. * according with the IIO specification.
  116. *
  117. * The scale factor allows to increase the precession of the returned value. For
  118. * a scale factor of 1 the function will return the result in the normal IIO
  119. * unit for the channel type. E.g. millivolt for voltage channels, if you want
  120. * nanovolts instead pass 1000 as the scale factor.
  121. */
  122. int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
  123. int *processed, unsigned int scale);
  124. #endif