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