hid-sensor-hub.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. * @ref_cnt: Number of MFD clients have opened this device
  48. */
  49. struct hid_sensor_hub_device {
  50. struct hid_device *hdev;
  51. u32 vendor_id;
  52. u32 product_id;
  53. int ref_cnt;
  54. };
  55. /**
  56. * struct hid_sensor_hub_callbacks - Client callback functions
  57. * @pdev: Platform device instance of the client driver.
  58. * @suspend: Suspend callback.
  59. * @resume: Resume callback.
  60. * @capture_sample: Callback to get a sample.
  61. * @send_event: Send notification to indicate all samples are
  62. * captured, process and send event
  63. */
  64. struct hid_sensor_hub_callbacks {
  65. struct platform_device *pdev;
  66. int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
  67. int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
  68. int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
  69. u32 usage_id, size_t raw_len, char *raw_data,
  70. void *priv);
  71. int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
  72. void *priv);
  73. };
  74. /**
  75. * sensor_hub_device_open() - Open hub device
  76. * @hsdev: Hub device instance.
  77. *
  78. * Used to open hid device for sensor hub.
  79. */
  80. int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
  81. /**
  82. * sensor_hub_device_clode() - Close hub device
  83. * @hsdev: Hub device instance.
  84. *
  85. * Used to clode hid device for sensor hub.
  86. */
  87. void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
  88. /* Registration functions */
  89. /**
  90. * sensor_hub_register_callback() - Register client callbacks
  91. * @hsdev: Hub device instance.
  92. * @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
  93. * @usage_callback: Callback function storage
  94. *
  95. * Used to register callbacks by client processing drivers. Sensor
  96. * hub core driver will call these callbacks to offload processing
  97. * of data streams and notifications.
  98. */
  99. int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
  100. u32 usage_id,
  101. struct hid_sensor_hub_callbacks *usage_callback);
  102. /**
  103. * sensor_hub_remove_callback() - Remove client callbacks
  104. * @hsdev: Hub device instance.
  105. * @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
  106. *
  107. * If there is a callback registred, this call will remove that
  108. * callbacks, so that it will stop data and event notifications.
  109. */
  110. int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
  111. u32 usage_id);
  112. /* Hid sensor hub core interfaces */
  113. /**
  114. * sensor_hub_input_get_attribute_info() - Get an attribute information
  115. * @hsdev: Hub device instance.
  116. * @type: Type of this attribute, input/output/feature
  117. * @usage_id: Attribute usage id of parent physical device as per spec
  118. * @attr_usage_id: Attribute usage id as per spec
  119. * @info: return information about attribute after parsing report
  120. *
  121. * Parses report and returns the attribute information such as report id,
  122. * field index, units and exponet etc.
  123. */
  124. int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
  125. u8 type,
  126. u32 usage_id, u32 attr_usage_id,
  127. struct hid_sensor_hub_attribute_info *info);
  128. /**
  129. * sensor_hub_input_attr_get_raw_value() - Synchronous read request
  130. * @usage_id: Attribute usage id of parent physical device as per spec
  131. * @attr_usage_id: Attribute usage id as per spec
  132. * @report_id: Report id to look for
  133. *
  134. * Issues a synchronous read request for an input attribute. Returns
  135. * data upto 32 bits. Since client can get events, so this call should
  136. * not be used for data paths, this will impact performance.
  137. */
  138. int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
  139. u32 usage_id,
  140. u32 attr_usage_id, u32 report_id);
  141. /**
  142. * sensor_hub_set_feature() - Feature set request
  143. * @report_id: Report id to look for
  144. * @field_index: Field index inside a report
  145. * @value: Value to set
  146. *
  147. * Used to set a field in feature report. For example this can set polling
  148. * interval, sensitivity, activate/deactivate state.
  149. */
  150. int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
  151. u32 field_index, s32 value);
  152. /**
  153. * sensor_hub_get_feature() - Feature get request
  154. * @report_id: Report id to look for
  155. * @field_index: Field index inside a report
  156. * @value: Place holder for return value
  157. *
  158. * Used to get a field in feature report. For example this can get polling
  159. * interval, sensitivity, activate/deactivate state.
  160. */
  161. int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
  162. u32 field_index, s32 *value);
  163. /* hid-sensor-attributes */
  164. /* Common hid sensor iio structure */
  165. struct hid_sensor_common {
  166. struct hid_sensor_hub_device *hsdev;
  167. struct platform_device *pdev;
  168. unsigned usage_id;
  169. bool data_ready;
  170. struct hid_sensor_hub_attribute_info poll;
  171. struct hid_sensor_hub_attribute_info report_state;
  172. struct hid_sensor_hub_attribute_info power_state;
  173. struct hid_sensor_hub_attribute_info sensitivity;
  174. };
  175. /* Convert from hid unit expo to regular exponent */
  176. static inline int hid_sensor_convert_exponent(int unit_expo)
  177. {
  178. if (unit_expo < 0x08)
  179. return unit_expo;
  180. else if (unit_expo <= 0x0f)
  181. return -(0x0f-unit_expo+1);
  182. else
  183. return 0;
  184. }
  185. int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
  186. u32 usage_id,
  187. struct hid_sensor_common *st);
  188. int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
  189. int val1, int val2);
  190. int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
  191. int *val1, int *val2);
  192. int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
  193. int val1, int val2);
  194. int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
  195. int *val1, int *val2);
  196. #endif