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