rmi.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright (c) 2011-2016 Synaptics Incorporated
  3. * Copyright (c) 2011 Unixphere
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. */
  9. #ifndef _RMI_H
  10. #define _RMI_H
  11. #include <linux/kernel.h>
  12. #include <linux/device.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/input.h>
  15. #include <linux/list.h>
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #define NAME_BUFFER_SIZE 256
  19. /**
  20. * struct rmi_2d_axis_alignment - target axis alignment
  21. * @swap_axes: set to TRUE if desired to swap x- and y-axis
  22. * @flip_x: set to TRUE if desired to flip direction on x-axis
  23. * @flip_y: set to TRUE if desired to flip direction on y-axis
  24. * @clip_x_low - reported X coordinates below this setting will be clipped to
  25. * the specified value
  26. * @clip_x_high - reported X coordinates above this setting will be clipped to
  27. * the specified value
  28. * @clip_y_low - reported Y coordinates below this setting will be clipped to
  29. * the specified value
  30. * @clip_y_high - reported Y coordinates above this setting will be clipped to
  31. * the specified value
  32. * @offset_x - this value will be added to all reported X coordinates
  33. * @offset_y - this value will be added to all reported Y coordinates
  34. * @rel_report_enabled - if set to true, the relative reporting will be
  35. * automatically enabled for this sensor.
  36. */
  37. struct rmi_2d_axis_alignment {
  38. bool swap_axes;
  39. bool flip_x;
  40. bool flip_y;
  41. u16 clip_x_low;
  42. u16 clip_y_low;
  43. u16 clip_x_high;
  44. u16 clip_y_high;
  45. u16 offset_x;
  46. u16 offset_y;
  47. u8 delta_x_threshold;
  48. u8 delta_y_threshold;
  49. };
  50. /** This is used to override any hints an F11 2D sensor might have provided
  51. * as to what type of sensor it is.
  52. *
  53. * @rmi_f11_sensor_default - do not override, determine from F11_2D_QUERY14 if
  54. * available.
  55. * @rmi_f11_sensor_touchscreen - treat the sensor as a touchscreen (direct
  56. * pointing).
  57. * @rmi_f11_sensor_touchpad - thread the sensor as a touchpad (indirect
  58. * pointing).
  59. */
  60. enum rmi_sensor_type {
  61. rmi_sensor_default = 0,
  62. rmi_sensor_touchscreen,
  63. rmi_sensor_touchpad
  64. };
  65. #define RMI_F11_DISABLE_ABS_REPORT BIT(0)
  66. /**
  67. * struct rmi_2d_sensor_data - overrides defaults for a 2D sensor.
  68. * @axis_align - provides axis alignment overrides (see above).
  69. * @sensor_type - Forces the driver to treat the sensor as an indirect
  70. * pointing device (touchpad) rather than a direct pointing device
  71. * (touchscreen). This is useful when F11_2D_QUERY14 register is not
  72. * available.
  73. * @disable_report_mask - Force data to not be reported even if it is supported
  74. * by the firware.
  75. * @topbuttonpad - Used with the "5 buttons touchpads" found on the Lenovo 40
  76. * series
  77. * @kernel_tracking - most moderns RMI f11 firmwares implement Multifinger
  78. * Type B protocol. However, there are some corner cases where the user
  79. * triggers some jumps by tapping with two fingers on the touchpad.
  80. * Use this setting and dmax to filter out these jumps.
  81. * Also, when using an old sensor using MF Type A behavior, set to true to
  82. * report an actual MT protocol B.
  83. * @dmax - the maximum distance (in sensor units) the kernel tracking allows two
  84. * distincts fingers to be considered the same.
  85. */
  86. struct rmi_2d_sensor_platform_data {
  87. struct rmi_2d_axis_alignment axis_align;
  88. enum rmi_sensor_type sensor_type;
  89. int x_mm;
  90. int y_mm;
  91. int disable_report_mask;
  92. u16 rezero_wait;
  93. bool topbuttonpad;
  94. bool kernel_tracking;
  95. int dmax;
  96. };
  97. /**
  98. * struct rmi_f01_power - override default power management settings.
  99. *
  100. */
  101. enum rmi_f01_nosleep {
  102. RMI_F01_NOSLEEP_DEFAULT = 0,
  103. RMI_F01_NOSLEEP_OFF = 1,
  104. RMI_F01_NOSLEEP_ON = 2
  105. };
  106. /**
  107. * struct rmi_f01_power_management -When non-zero, these values will be written
  108. * to the touch sensor to override the default firmware settigns. For a
  109. * detailed explanation of what each field does, see the corresponding
  110. * documention in the RMI4 specification.
  111. *
  112. * @nosleep - specifies whether the device is permitted to sleep or doze (that
  113. * is, enter a temporary low power state) when no fingers are touching the
  114. * sensor.
  115. * @wakeup_threshold - controls the capacitance threshold at which the touch
  116. * sensor will decide to wake up from that low power state.
  117. * @doze_holdoff - controls how long the touch sensor waits after the last
  118. * finger lifts before entering the doze state, in units of 100ms.
  119. * @doze_interval - controls the interval between checks for finger presence
  120. * when the touch sensor is in doze mode, in units of 10ms.
  121. */
  122. struct rmi_f01_power_management {
  123. enum rmi_f01_nosleep nosleep;
  124. u8 wakeup_threshold;
  125. u8 doze_holdoff;
  126. u8 doze_interval;
  127. };
  128. /**
  129. * struct rmi_device_platform_data - system specific configuration info.
  130. *
  131. * @reset_delay_ms - after issuing a reset command to the touch sensor, the
  132. * driver waits a few milliseconds to give the firmware a chance to
  133. * to re-initialize. You can override the default wait period here.
  134. */
  135. struct rmi_device_platform_data {
  136. int reset_delay_ms;
  137. /* function handler pdata */
  138. struct rmi_2d_sensor_platform_data *sensor_pdata;
  139. struct rmi_f01_power_management power_management;
  140. };
  141. /**
  142. * struct rmi_function_descriptor - RMI function base addresses
  143. *
  144. * @query_base_addr: The RMI Query base address
  145. * @command_base_addr: The RMI Command base address
  146. * @control_base_addr: The RMI Control base address
  147. * @data_base_addr: The RMI Data base address
  148. * @interrupt_source_count: The number of irqs this RMI function needs
  149. * @function_number: The RMI function number
  150. *
  151. * This struct is used when iterating the Page Description Table. The addresses
  152. * are 16-bit values to include the current page address.
  153. *
  154. */
  155. struct rmi_function_descriptor {
  156. u16 query_base_addr;
  157. u16 command_base_addr;
  158. u16 control_base_addr;
  159. u16 data_base_addr;
  160. u8 interrupt_source_count;
  161. u8 function_number;
  162. u8 function_version;
  163. };
  164. struct rmi_device;
  165. /**
  166. * struct rmi_transport_dev - represent an RMI transport device
  167. *
  168. * @dev: Pointer to the communication device, e.g. i2c or spi
  169. * @rmi_dev: Pointer to the RMI device
  170. * @proto_name: name of the transport protocol (SPI, i2c, etc)
  171. * @ops: pointer to transport operations implementation
  172. *
  173. * The RMI transport device implements the glue between different communication
  174. * buses such as I2C and SPI.
  175. *
  176. */
  177. struct rmi_transport_dev {
  178. struct device *dev;
  179. struct rmi_device *rmi_dev;
  180. const char *proto_name;
  181. const struct rmi_transport_ops *ops;
  182. struct rmi_device_platform_data pdata;
  183. struct input_dev *input;
  184. void *attn_data;
  185. int attn_size;
  186. };
  187. /**
  188. * struct rmi_transport_ops - defines transport protocol operations.
  189. *
  190. * @write_block: Writing a block of data to the specified address
  191. * @read_block: Read a block of data from the specified address.
  192. */
  193. struct rmi_transport_ops {
  194. int (*write_block)(struct rmi_transport_dev *xport, u16 addr,
  195. const void *buf, size_t len);
  196. int (*read_block)(struct rmi_transport_dev *xport, u16 addr,
  197. void *buf, size_t len);
  198. int (*reset)(struct rmi_transport_dev *xport, u16 reset_addr);
  199. };
  200. /**
  201. * struct rmi_driver - driver for an RMI4 sensor on the RMI bus.
  202. *
  203. * @driver: Device driver model driver
  204. * @reset_handler: Called when a reset is detected.
  205. * @clear_irq_bits: Clear the specified bits in the current interrupt mask.
  206. * @set_irq_bist: Set the specified bits in the current interrupt mask.
  207. * @store_productid: Callback for cache product id from function 01
  208. * @data: Private data pointer
  209. *
  210. */
  211. struct rmi_driver {
  212. struct device_driver driver;
  213. int (*reset_handler)(struct rmi_device *rmi_dev);
  214. int (*clear_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
  215. int (*set_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
  216. int (*store_productid)(struct rmi_device *rmi_dev);
  217. int (*set_input_params)(struct rmi_device *rmi_dev,
  218. struct input_dev *input);
  219. void *data;
  220. };
  221. /**
  222. * struct rmi_device - represents an RMI4 sensor device on the RMI bus.
  223. *
  224. * @dev: The device created for the RMI bus
  225. * @number: Unique number for the device on the bus.
  226. * @driver: Pointer to associated driver
  227. * @xport: Pointer to the transport interface
  228. *
  229. */
  230. struct rmi_device {
  231. struct device dev;
  232. int number;
  233. struct rmi_driver *driver;
  234. struct rmi_transport_dev *xport;
  235. };
  236. struct rmi_driver_data {
  237. struct list_head function_list;
  238. struct rmi_device *rmi_dev;
  239. struct rmi_function *f01_container;
  240. bool f01_bootloader_mode;
  241. u32 attn_count;
  242. int num_of_irq_regs;
  243. int irq_count;
  244. unsigned long *irq_status;
  245. unsigned long *fn_irq_bits;
  246. unsigned long *current_irq_mask;
  247. unsigned long *new_irq_mask;
  248. struct mutex irq_mutex;
  249. struct input_dev *input;
  250. u8 pdt_props;
  251. u8 bsr;
  252. bool enabled;
  253. void *data;
  254. };
  255. int rmi_register_transport_device(struct rmi_transport_dev *xport);
  256. void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
  257. int rmi_process_interrupt_requests(struct rmi_device *rmi_dev);
  258. int rmi_driver_suspend(struct rmi_device *rmi_dev);
  259. int rmi_driver_resume(struct rmi_device *rmi_dev);
  260. #endif