hid-sensor-hub.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * HID Sensors Driver
  3. * Copyright (c) 2012, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef _HID_SENSORS_HUB_H
  20. #define _HID_SENSORS_HUB_H
  21. #include <linux/hid.h>
  22. #include <linux/hid-sensor-ids.h>
  23. /**
  24. * struct hid_sensor_hub_attribute_info - Attribute info
  25. * @usage_id: Parent usage id of a physical device.
  26. * @attrib_id: Attribute id for this attribute.
  27. * @report_id: Report id in which this information resides.
  28. * @index: Field index in the report.
  29. * @units: Measurment unit for this attribute.
  30. * @unit_expo: Exponent used in the data.
  31. * @size: Size in bytes for data size.
  32. */
  33. struct hid_sensor_hub_attribute_info {
  34. u32 usage_id;
  35. u32 attrib_id;
  36. s32 report_id;
  37. s32 index;
  38. s32 units;
  39. s32 unit_expo;
  40. s32 size;
  41. };
  42. /**
  43. * struct hid_sensor_hub_device - Stores the hub instance data
  44. * @hdev: Stores the hid instance.
  45. * @vendor_id: Vendor id of hub device.
  46. * @product_id: Product id of hub device.
  47. */
  48. struct hid_sensor_hub_device {
  49. struct hid_device *hdev;
  50. u32 vendor_id;
  51. u32 product_id;
  52. };
  53. /**
  54. * struct hid_sensor_hub_callbacks - Client callback functions
  55. * @pdev: Platform device instance of the client driver.
  56. * @suspend: Suspend callback.
  57. * @resume: Resume callback.
  58. * @capture_sample: Callback to get a sample.
  59. * @send_event: Send notification to indicate all samples are
  60. * captured, process and send event
  61. */
  62. struct hid_sensor_hub_callbacks {
  63. struct platform_device *pdev;
  64. int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
  65. int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
  66. int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
  67. u32 usage_id, size_t raw_len, char *raw_data,
  68. void *priv);
  69. int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
  70. void *priv);
  71. };
  72. /* Registration functions */
  73. /**
  74. * sensor_hub_register_callback() - Register client callbacks
  75. * @hsdev: Hub device instance.
  76. * @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
  77. * @usage_callback: Callback function storage
  78. *
  79. * Used to register callbacks by client processing drivers. Sensor
  80. * hub core driver will call these callbacks to offload processing
  81. * of data streams and notifications.
  82. */
  83. int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
  84. u32 usage_id,
  85. struct hid_sensor_hub_callbacks *usage_callback);
  86. /**
  87. * sensor_hub_remove_callback() - Remove client callbacks
  88. * @hsdev: Hub device instance.
  89. * @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
  90. *
  91. * If there is a callback registred, this call will remove that
  92. * callbacks, so that it will stop data and event notifications.
  93. */
  94. int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
  95. u32 usage_id);
  96. /* Hid sensor hub core interfaces */
  97. /**
  98. * sensor_hub_input_get_attribute_info() - Get an attribute information
  99. * @hsdev: Hub device instance.
  100. * @type: Type of this attribute, input/output/feature
  101. * @usage_id: Attribute usage id of parent physical device as per spec
  102. * @attr_usage_id: Attribute usage id as per spec
  103. * @info: return information about attribute after parsing report
  104. *
  105. * Parses report and returns the attribute information such as report id,
  106. * field index, units and exponet etc.
  107. */
  108. int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
  109. u8 type,
  110. u32 usage_id, u32 attr_usage_id,
  111. struct hid_sensor_hub_attribute_info *info);
  112. /**
  113. * sensor_hub_input_attr_get_raw_value() - Synchronous read request
  114. * @usage_id: Attribute usage id of parent physical device as per spec
  115. * @attr_usage_id: Attribute usage id as per spec
  116. * @report_id: Report id to look for
  117. *
  118. * Issues a synchronous read request for an input attribute. Returns
  119. * data upto 32 bits. Since client can get events, so this call should
  120. * not be used for data paths, this will impact performance.
  121. */
  122. int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
  123. u32 usage_id,
  124. u32 attr_usage_id, u32 report_id);
  125. /**
  126. * sensor_hub_set_feature() - Feature set request
  127. * @report_id: Report id to look for
  128. * @field_index: Field index inside a report
  129. * @value: Value to set
  130. *
  131. * Used to set a field in feature report. For example this can set polling
  132. * interval, sensitivity, activate/deactivate state.
  133. */
  134. int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
  135. u32 field_index, s32 value);
  136. /**
  137. * sensor_hub_get_feature() - Feature get request
  138. * @report_id: Report id to look for
  139. * @field_index: Field index inside a report
  140. * @value: Place holder for return value
  141. *
  142. * Used to get a field in feature report. For example this can get polling
  143. * interval, sensitivity, activate/deactivate state.
  144. */
  145. int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
  146. u32 field_index, s32 *value);
  147. /* hid-sensor-attributes */
  148. /* Common hid sensor iio structure */
  149. struct hid_sensor_common {
  150. struct hid_sensor_hub_device *hsdev;
  151. struct platform_device *pdev;
  152. unsigned usage_id;
  153. bool data_ready;
  154. struct hid_sensor_hub_attribute_info poll;
  155. struct hid_sensor_hub_attribute_info report_state;
  156. struct hid_sensor_hub_attribute_info power_state;
  157. struct hid_sensor_hub_attribute_info sensitivity;
  158. };
  159. /* Convert from hid unit expo to regular exponent */
  160. static inline int hid_sensor_convert_exponent(int unit_expo)
  161. {
  162. if (unit_expo < 0x08)
  163. return unit_expo;
  164. else if (unit_expo <= 0x0f)
  165. return -(0x0f-unit_expo+1);
  166. else
  167. return 0;
  168. }
  169. int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
  170. u32 usage_id,
  171. struct hid_sensor_common *st);
  172. int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
  173. int val1, int val2);
  174. int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
  175. int *val1, int *val2);
  176. int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
  177. int val1, int val2);
  178. int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
  179. int *val1, int *val2);
  180. #endif