rmi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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_f30_data - overrides defaults for a single F30 GPIOs/LED chip.
  99. * @buttonpad - the touchpad is a buttonpad, so enable only the first actual
  100. * button that is found.
  101. * @trackstick_buttons - Set when the function 30 is handling the physical
  102. * buttons of the trackstick (as a PD/2 passthrough device.
  103. * @disable - the touchpad incorrectly reports F30 and it should be ignored.
  104. * This is a special case which is due to misconfigured firmware.
  105. */
  106. struct rmi_f30_data {
  107. bool buttonpad;
  108. bool trackstick_buttons;
  109. bool disable;
  110. };
  111. /**
  112. * struct rmi_f01_power - override default power management settings.
  113. *
  114. */
  115. enum rmi_f01_nosleep {
  116. RMI_F01_NOSLEEP_DEFAULT = 0,
  117. RMI_F01_NOSLEEP_OFF = 1,
  118. RMI_F01_NOSLEEP_ON = 2
  119. };
  120. /**
  121. * struct rmi_f01_power_management -When non-zero, these values will be written
  122. * to the touch sensor to override the default firmware settigns. For a
  123. * detailed explanation of what each field does, see the corresponding
  124. * documention in the RMI4 specification.
  125. *
  126. * @nosleep - specifies whether the device is permitted to sleep or doze (that
  127. * is, enter a temporary low power state) when no fingers are touching the
  128. * sensor.
  129. * @wakeup_threshold - controls the capacitance threshold at which the touch
  130. * sensor will decide to wake up from that low power state.
  131. * @doze_holdoff - controls how long the touch sensor waits after the last
  132. * finger lifts before entering the doze state, in units of 100ms.
  133. * @doze_interval - controls the interval between checks for finger presence
  134. * when the touch sensor is in doze mode, in units of 10ms.
  135. */
  136. struct rmi_f01_power_management {
  137. enum rmi_f01_nosleep nosleep;
  138. u8 wakeup_threshold;
  139. u8 doze_holdoff;
  140. u8 doze_interval;
  141. };
  142. /**
  143. * struct rmi_device_platform_data_spi - provides parameters used in SPI
  144. * communications. All Synaptics SPI products support a standard SPI
  145. * interface; some also support what is called SPI V2 mode, depending on
  146. * firmware and/or ASIC limitations. In V2 mode, the touch sensor can
  147. * support shorter delays during certain operations, and these are specified
  148. * separately from the standard mode delays.
  149. *
  150. * @block_delay - for standard SPI transactions consisting of both a read and
  151. * write operation, the delay (in microseconds) between the read and write
  152. * operations.
  153. * @split_read_block_delay_us - for V2 SPI transactions consisting of both a
  154. * read and write operation, the delay (in microseconds) between the read and
  155. * write operations.
  156. * @read_delay_us - the delay between each byte of a read operation in normal
  157. * SPI mode.
  158. * @write_delay_us - the delay between each byte of a write operation in normal
  159. * SPI mode.
  160. * @split_read_byte_delay_us - the delay between each byte of a read operation
  161. * in V2 mode.
  162. * @pre_delay_us - the delay before the start of a SPI transaction. This is
  163. * typically useful in conjunction with custom chip select assertions (see
  164. * below).
  165. * @post_delay_us - the delay after the completion of an SPI transaction. This
  166. * is typically useful in conjunction with custom chip select assertions (see
  167. * below).
  168. * @cs_assert - For systems where the SPI subsystem does not control the CS/SSB
  169. * line, or where such control is broken, you can provide a custom routine to
  170. * handle a GPIO as CS/SSB. This routine will be called at the beginning and
  171. * end of each SPI transaction. The RMI SPI implementation will wait
  172. * pre_delay_us after this routine returns before starting the SPI transfer;
  173. * and post_delay_us after completion of the SPI transfer(s) before calling it
  174. * with assert==FALSE.
  175. */
  176. struct rmi_device_platform_data_spi {
  177. u32 block_delay_us;
  178. u32 split_read_block_delay_us;
  179. u32 read_delay_us;
  180. u32 write_delay_us;
  181. u32 split_read_byte_delay_us;
  182. u32 pre_delay_us;
  183. u32 post_delay_us;
  184. u8 bits_per_word;
  185. u16 mode;
  186. void *cs_assert_data;
  187. int (*cs_assert)(const void *cs_assert_data, const bool assert);
  188. };
  189. /**
  190. * struct rmi_device_platform_data - system specific configuration info.
  191. *
  192. * @reset_delay_ms - after issuing a reset command to the touch sensor, the
  193. * driver waits a few milliseconds to give the firmware a chance to
  194. * to re-initialize. You can override the default wait period here.
  195. */
  196. struct rmi_device_platform_data {
  197. int reset_delay_ms;
  198. struct rmi_device_platform_data_spi spi_data;
  199. /* function handler pdata */
  200. struct rmi_2d_sensor_platform_data *sensor_pdata;
  201. struct rmi_f01_power_management power_management;
  202. struct rmi_f30_data *f30_data;
  203. };
  204. /**
  205. * struct rmi_function_descriptor - RMI function base addresses
  206. *
  207. * @query_base_addr: The RMI Query base address
  208. * @command_base_addr: The RMI Command base address
  209. * @control_base_addr: The RMI Control base address
  210. * @data_base_addr: The RMI Data base address
  211. * @interrupt_source_count: The number of irqs this RMI function needs
  212. * @function_number: The RMI function number
  213. *
  214. * This struct is used when iterating the Page Description Table. The addresses
  215. * are 16-bit values to include the current page address.
  216. *
  217. */
  218. struct rmi_function_descriptor {
  219. u16 query_base_addr;
  220. u16 command_base_addr;
  221. u16 control_base_addr;
  222. u16 data_base_addr;
  223. u8 interrupt_source_count;
  224. u8 function_number;
  225. u8 function_version;
  226. };
  227. struct rmi_device;
  228. /**
  229. * struct rmi_transport_dev - represent an RMI transport device
  230. *
  231. * @dev: Pointer to the communication device, e.g. i2c or spi
  232. * @rmi_dev: Pointer to the RMI device
  233. * @proto_name: name of the transport protocol (SPI, i2c, etc)
  234. * @ops: pointer to transport operations implementation
  235. *
  236. * The RMI transport device implements the glue between different communication
  237. * buses such as I2C and SPI.
  238. *
  239. */
  240. struct rmi_transport_dev {
  241. struct device *dev;
  242. struct rmi_device *rmi_dev;
  243. const char *proto_name;
  244. const struct rmi_transport_ops *ops;
  245. struct rmi_device_platform_data pdata;
  246. struct input_dev *input;
  247. void *attn_data;
  248. int attn_size;
  249. };
  250. /**
  251. * struct rmi_transport_ops - defines transport protocol operations.
  252. *
  253. * @write_block: Writing a block of data to the specified address
  254. * @read_block: Read a block of data from the specified address.
  255. */
  256. struct rmi_transport_ops {
  257. int (*write_block)(struct rmi_transport_dev *xport, u16 addr,
  258. const void *buf, size_t len);
  259. int (*read_block)(struct rmi_transport_dev *xport, u16 addr,
  260. void *buf, size_t len);
  261. int (*reset)(struct rmi_transport_dev *xport, u16 reset_addr);
  262. };
  263. /**
  264. * struct rmi_driver - driver for an RMI4 sensor on the RMI bus.
  265. *
  266. * @driver: Device driver model driver
  267. * @reset_handler: Called when a reset is detected.
  268. * @clear_irq_bits: Clear the specified bits in the current interrupt mask.
  269. * @set_irq_bist: Set the specified bits in the current interrupt mask.
  270. * @store_productid: Callback for cache product id from function 01
  271. * @data: Private data pointer
  272. *
  273. */
  274. struct rmi_driver {
  275. struct device_driver driver;
  276. int (*reset_handler)(struct rmi_device *rmi_dev);
  277. int (*clear_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
  278. int (*set_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
  279. int (*store_productid)(struct rmi_device *rmi_dev);
  280. int (*set_input_params)(struct rmi_device *rmi_dev,
  281. struct input_dev *input);
  282. void *data;
  283. };
  284. /**
  285. * struct rmi_device - represents an RMI4 sensor device on the RMI bus.
  286. *
  287. * @dev: The device created for the RMI bus
  288. * @number: Unique number for the device on the bus.
  289. * @driver: Pointer to associated driver
  290. * @xport: Pointer to the transport interface
  291. *
  292. */
  293. struct rmi_device {
  294. struct device dev;
  295. int number;
  296. struct rmi_driver *driver;
  297. struct rmi_transport_dev *xport;
  298. };
  299. struct rmi_driver_data {
  300. struct list_head function_list;
  301. struct rmi_device *rmi_dev;
  302. struct rmi_function *f01_container;
  303. bool f01_bootloader_mode;
  304. u32 attn_count;
  305. int num_of_irq_regs;
  306. int irq_count;
  307. unsigned long *irq_status;
  308. unsigned long *fn_irq_bits;
  309. unsigned long *current_irq_mask;
  310. unsigned long *new_irq_mask;
  311. struct mutex irq_mutex;
  312. struct input_dev *input;
  313. u8 pdt_props;
  314. u8 bsr;
  315. bool enabled;
  316. void *data;
  317. };
  318. int rmi_register_transport_device(struct rmi_transport_dev *xport);
  319. void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
  320. int rmi_process_interrupt_requests(struct rmi_device *rmi_dev);
  321. int rmi_driver_suspend(struct rmi_device *rmi_dev);
  322. int rmi_driver_resume(struct rmi_device *rmi_dev);
  323. #endif