rmi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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/kfifo.h>
  16. #include <linux/list.h>
  17. #include <linux/module.h>
  18. #include <linux/types.h>
  19. #define NAME_BUFFER_SIZE 256
  20. /**
  21. * struct rmi_2d_axis_alignment - target axis alignment
  22. * @swap_axes: set to TRUE if desired to swap x- and y-axis
  23. * @flip_x: set to TRUE if desired to flip direction on x-axis
  24. * @flip_y: set to TRUE if desired to flip direction on y-axis
  25. * @clip_x_low - reported X coordinates below this setting will be clipped to
  26. * the specified value
  27. * @clip_x_high - reported X coordinates above this setting will be clipped to
  28. * the specified value
  29. * @clip_y_low - reported Y coordinates below this setting will be clipped to
  30. * the specified value
  31. * @clip_y_high - reported Y coordinates above this setting will be clipped to
  32. * the specified value
  33. * @offset_x - this value will be added to all reported X coordinates
  34. * @offset_y - this value will be added to all reported Y coordinates
  35. * @rel_report_enabled - if set to true, the relative reporting will be
  36. * automatically enabled for this sensor.
  37. */
  38. struct rmi_2d_axis_alignment {
  39. bool swap_axes;
  40. bool flip_x;
  41. bool flip_y;
  42. u16 clip_x_low;
  43. u16 clip_y_low;
  44. u16 clip_x_high;
  45. u16 clip_y_high;
  46. u16 offset_x;
  47. u16 offset_y;
  48. u8 delta_x_threshold;
  49. u8 delta_y_threshold;
  50. };
  51. /** This is used to override any hints an F11 2D sensor might have provided
  52. * as to what type of sensor it is.
  53. *
  54. * @rmi_f11_sensor_default - do not override, determine from F11_2D_QUERY14 if
  55. * available.
  56. * @rmi_f11_sensor_touchscreen - treat the sensor as a touchscreen (direct
  57. * pointing).
  58. * @rmi_f11_sensor_touchpad - thread the sensor as a touchpad (indirect
  59. * pointing).
  60. */
  61. enum rmi_sensor_type {
  62. rmi_sensor_default = 0,
  63. rmi_sensor_touchscreen,
  64. rmi_sensor_touchpad
  65. };
  66. #define RMI_F11_DISABLE_ABS_REPORT BIT(0)
  67. /**
  68. * struct rmi_2d_sensor_data - overrides defaults for a 2D sensor.
  69. * @axis_align - provides axis alignment overrides (see above).
  70. * @sensor_type - Forces the driver to treat the sensor as an indirect
  71. * pointing device (touchpad) rather than a direct pointing device
  72. * (touchscreen). This is useful when F11_2D_QUERY14 register is not
  73. * available.
  74. * @disable_report_mask - Force data to not be reported even if it is supported
  75. * by the firware.
  76. * @topbuttonpad - Used with the "5 buttons touchpads" found on the Lenovo 40
  77. * series
  78. * @kernel_tracking - most moderns RMI f11 firmwares implement Multifinger
  79. * Type B protocol. However, there are some corner cases where the user
  80. * triggers some jumps by tapping with two fingers on the touchpad.
  81. * Use this setting and dmax to filter out these jumps.
  82. * Also, when using an old sensor using MF Type A behavior, set to true to
  83. * report an actual MT protocol B.
  84. * @dmax - the maximum distance (in sensor units) the kernel tracking allows two
  85. * distincts fingers to be considered the same.
  86. */
  87. struct rmi_2d_sensor_platform_data {
  88. struct rmi_2d_axis_alignment axis_align;
  89. enum rmi_sensor_type sensor_type;
  90. int x_mm;
  91. int y_mm;
  92. int disable_report_mask;
  93. u16 rezero_wait;
  94. bool topbuttonpad;
  95. bool kernel_tracking;
  96. int dmax;
  97. int dribble;
  98. int palm_detect;
  99. };
  100. /**
  101. * struct rmi_f30_data - overrides defaults for a single F30 GPIOs/LED chip.
  102. * @buttonpad - the touchpad is a buttonpad, so enable only the first actual
  103. * button that is found.
  104. * @trackstick_buttons - Set when the function 30 is handling the physical
  105. * buttons of the trackstick (as a PS/2 passthrough device).
  106. * @disable - the touchpad incorrectly reports F30 and it should be ignored.
  107. * This is a special case which is due to misconfigured firmware.
  108. */
  109. struct rmi_f30_data {
  110. bool buttonpad;
  111. bool trackstick_buttons;
  112. bool disable;
  113. };
  114. /*
  115. * Set the state of a register
  116. * DEFAULT - use the default value set by the firmware config
  117. * OFF - explicitly disable the register
  118. * ON - explicitly enable the register
  119. */
  120. enum rmi_reg_state {
  121. RMI_REG_STATE_DEFAULT = 0,
  122. RMI_REG_STATE_OFF = 1,
  123. RMI_REG_STATE_ON = 2
  124. };
  125. /**
  126. * struct rmi_f01_power_management -When non-zero, these values will be written
  127. * to the touch sensor to override the default firmware settigns. For a
  128. * detailed explanation of what each field does, see the corresponding
  129. * documention in the RMI4 specification.
  130. *
  131. * @nosleep - specifies whether the device is permitted to sleep or doze (that
  132. * is, enter a temporary low power state) when no fingers are touching the
  133. * sensor.
  134. * @wakeup_threshold - controls the capacitance threshold at which the touch
  135. * sensor will decide to wake up from that low power state.
  136. * @doze_holdoff - controls how long the touch sensor waits after the last
  137. * finger lifts before entering the doze state, in units of 100ms.
  138. * @doze_interval - controls the interval between checks for finger presence
  139. * when the touch sensor is in doze mode, in units of 10ms.
  140. */
  141. struct rmi_f01_power_management {
  142. enum rmi_reg_state nosleep;
  143. u8 wakeup_threshold;
  144. u8 doze_holdoff;
  145. u8 doze_interval;
  146. };
  147. /**
  148. * struct rmi_device_platform_data_spi - provides parameters used in SPI
  149. * communications. All Synaptics SPI products support a standard SPI
  150. * interface; some also support what is called SPI V2 mode, depending on
  151. * firmware and/or ASIC limitations. In V2 mode, the touch sensor can
  152. * support shorter delays during certain operations, and these are specified
  153. * separately from the standard mode delays.
  154. *
  155. * @block_delay - for standard SPI transactions consisting of both a read and
  156. * write operation, the delay (in microseconds) between the read and write
  157. * operations.
  158. * @split_read_block_delay_us - for V2 SPI transactions consisting of both a
  159. * read and write operation, the delay (in microseconds) between the read and
  160. * write operations.
  161. * @read_delay_us - the delay between each byte of a read operation in normal
  162. * SPI mode.
  163. * @write_delay_us - the delay between each byte of a write operation in normal
  164. * SPI mode.
  165. * @split_read_byte_delay_us - the delay between each byte of a read operation
  166. * in V2 mode.
  167. * @pre_delay_us - the delay before the start of a SPI transaction. This is
  168. * typically useful in conjunction with custom chip select assertions (see
  169. * below).
  170. * @post_delay_us - the delay after the completion of an SPI transaction. This
  171. * is typically useful in conjunction with custom chip select assertions (see
  172. * below).
  173. * @cs_assert - For systems where the SPI subsystem does not control the CS/SSB
  174. * line, or where such control is broken, you can provide a custom routine to
  175. * handle a GPIO as CS/SSB. This routine will be called at the beginning and
  176. * end of each SPI transaction. The RMI SPI implementation will wait
  177. * pre_delay_us after this routine returns before starting the SPI transfer;
  178. * and post_delay_us after completion of the SPI transfer(s) before calling it
  179. * with assert==FALSE.
  180. */
  181. struct rmi_device_platform_data_spi {
  182. u32 block_delay_us;
  183. u32 split_read_block_delay_us;
  184. u32 read_delay_us;
  185. u32 write_delay_us;
  186. u32 split_read_byte_delay_us;
  187. u32 pre_delay_us;
  188. u32 post_delay_us;
  189. u8 bits_per_word;
  190. u16 mode;
  191. void *cs_assert_data;
  192. int (*cs_assert)(const void *cs_assert_data, const bool assert);
  193. };
  194. /**
  195. * struct rmi_device_platform_data - system specific configuration info.
  196. *
  197. * @reset_delay_ms - after issuing a reset command to the touch sensor, the
  198. * driver waits a few milliseconds to give the firmware a chance to
  199. * to re-initialize. You can override the default wait period here.
  200. * @irq: irq associated with the attn gpio line, or negative
  201. */
  202. struct rmi_device_platform_data {
  203. int reset_delay_ms;
  204. int irq;
  205. struct rmi_device_platform_data_spi spi_data;
  206. /* function handler pdata */
  207. struct rmi_2d_sensor_platform_data sensor_pdata;
  208. struct rmi_f01_power_management power_management;
  209. struct rmi_f30_data f30_data;
  210. };
  211. /**
  212. * struct rmi_function_descriptor - RMI function base addresses
  213. *
  214. * @query_base_addr: The RMI Query base address
  215. * @command_base_addr: The RMI Command base address
  216. * @control_base_addr: The RMI Control base address
  217. * @data_base_addr: The RMI Data base address
  218. * @interrupt_source_count: The number of irqs this RMI function needs
  219. * @function_number: The RMI function number
  220. *
  221. * This struct is used when iterating the Page Description Table. The addresses
  222. * are 16-bit values to include the current page address.
  223. *
  224. */
  225. struct rmi_function_descriptor {
  226. u16 query_base_addr;
  227. u16 command_base_addr;
  228. u16 control_base_addr;
  229. u16 data_base_addr;
  230. u8 interrupt_source_count;
  231. u8 function_number;
  232. u8 function_version;
  233. };
  234. struct rmi_device;
  235. /**
  236. * struct rmi_transport_dev - represent an RMI transport device
  237. *
  238. * @dev: Pointer to the communication device, e.g. i2c or spi
  239. * @rmi_dev: Pointer to the RMI device
  240. * @proto_name: name of the transport protocol (SPI, i2c, etc)
  241. * @ops: pointer to transport operations implementation
  242. *
  243. * The RMI transport device implements the glue between different communication
  244. * buses such as I2C and SPI.
  245. *
  246. */
  247. struct rmi_transport_dev {
  248. struct device *dev;
  249. struct rmi_device *rmi_dev;
  250. const char *proto_name;
  251. const struct rmi_transport_ops *ops;
  252. struct rmi_device_platform_data pdata;
  253. struct input_dev *input;
  254. };
  255. /**
  256. * struct rmi_transport_ops - defines transport protocol operations.
  257. *
  258. * @write_block: Writing a block of data to the specified address
  259. * @read_block: Read a block of data from the specified address.
  260. */
  261. struct rmi_transport_ops {
  262. int (*write_block)(struct rmi_transport_dev *xport, u16 addr,
  263. const void *buf, size_t len);
  264. int (*read_block)(struct rmi_transport_dev *xport, u16 addr,
  265. void *buf, size_t len);
  266. int (*reset)(struct rmi_transport_dev *xport, u16 reset_addr);
  267. };
  268. /**
  269. * struct rmi_driver - driver for an RMI4 sensor on the RMI bus.
  270. *
  271. * @driver: Device driver model driver
  272. * @reset_handler: Called when a reset is detected.
  273. * @clear_irq_bits: Clear the specified bits in the current interrupt mask.
  274. * @set_irq_bist: Set the specified bits in the current interrupt mask.
  275. * @store_productid: Callback for cache product id from function 01
  276. * @data: Private data pointer
  277. *
  278. */
  279. struct rmi_driver {
  280. struct device_driver driver;
  281. int (*reset_handler)(struct rmi_device *rmi_dev);
  282. int (*clear_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
  283. int (*set_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
  284. int (*store_productid)(struct rmi_device *rmi_dev);
  285. int (*set_input_params)(struct rmi_device *rmi_dev,
  286. struct input_dev *input);
  287. void *data;
  288. };
  289. /**
  290. * struct rmi_device - represents an RMI4 sensor device on the RMI bus.
  291. *
  292. * @dev: The device created for the RMI bus
  293. * @number: Unique number for the device on the bus.
  294. * @driver: Pointer to associated driver
  295. * @xport: Pointer to the transport interface
  296. *
  297. */
  298. struct rmi_device {
  299. struct device dev;
  300. int number;
  301. struct rmi_driver *driver;
  302. struct rmi_transport_dev *xport;
  303. };
  304. struct rmi4_attn_data {
  305. unsigned long irq_status;
  306. size_t size;
  307. void *data;
  308. };
  309. struct rmi_driver_data {
  310. struct list_head function_list;
  311. struct rmi_device *rmi_dev;
  312. struct rmi_function *f01_container;
  313. struct rmi_function *f34_container;
  314. bool bootloader_mode;
  315. int num_of_irq_regs;
  316. int irq_count;
  317. void *irq_memory;
  318. unsigned long *irq_status;
  319. unsigned long *fn_irq_bits;
  320. unsigned long *current_irq_mask;
  321. unsigned long *new_irq_mask;
  322. struct mutex irq_mutex;
  323. struct input_dev *input;
  324. u8 pdt_props;
  325. u8 num_rx_electrodes;
  326. u8 num_tx_electrodes;
  327. bool enabled;
  328. struct mutex enabled_mutex;
  329. struct rmi4_attn_data attn_data;
  330. DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
  331. };
  332. int rmi_register_transport_device(struct rmi_transport_dev *xport);
  333. void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
  334. void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
  335. void *data, size_t size);
  336. int rmi_driver_suspend(struct rmi_device *rmi_dev, bool enable_wake);
  337. int rmi_driver_resume(struct rmi_device *rmi_dev, bool clear_wake);
  338. #endif