rmi.h 12 KB

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