]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - include/linux/rmi.h
Input: synaptics-rmi4 - add support for F12
[mirror_ubuntu-eoan-kernel.git] / include / linux / rmi.h
CommitLineData
2b6a321d
AD
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>
16#include <linux/list.h>
17#include <linux/module.h>
18#include <linux/types.h>
19
20#define NAME_BUFFER_SIZE 256
21
ff8f8370
AD
22/**
23 * 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;
102};
103
2b6a321d
AD
104/**
105 * struct rmi_f01_power - override default power management settings.
106 *
107 */
108enum rmi_f01_nosleep {
109 RMI_F01_NOSLEEP_DEFAULT = 0,
110 RMI_F01_NOSLEEP_OFF = 1,
111 RMI_F01_NOSLEEP_ON = 2
112};
113
114/**
115 * struct rmi_f01_power_management -When non-zero, these values will be written
116 * to the touch sensor to override the default firmware settigns. For a
117 * detailed explanation of what each field does, see the corresponding
118 * documention in the RMI4 specification.
119 *
120 * @nosleep - specifies whether the device is permitted to sleep or doze (that
121 * is, enter a temporary low power state) when no fingers are touching the
122 * sensor.
123 * @wakeup_threshold - controls the capacitance threshold at which the touch
124 * sensor will decide to wake up from that low power state.
125 * @doze_holdoff - controls how long the touch sensor waits after the last
126 * finger lifts before entering the doze state, in units of 100ms.
127 * @doze_interval - controls the interval between checks for finger presence
128 * when the touch sensor is in doze mode, in units of 10ms.
129 */
130struct rmi_f01_power_management {
131 enum rmi_f01_nosleep nosleep;
132 u8 wakeup_threshold;
133 u8 doze_holdoff;
134 u8 doze_interval;
135};
136
137/**
138 * struct rmi_device_platform_data - system specific configuration info.
139 *
140 * @reset_delay_ms - after issuing a reset command to the touch sensor, the
141 * driver waits a few milliseconds to give the firmware a chance to
142 * to re-initialize. You can override the default wait period here.
143 */
144struct rmi_device_platform_data {
145 int reset_delay_ms;
146
147 /* function handler pdata */
ff8f8370 148 struct rmi_2d_sensor_platform_data *sensor_pdata;
2b6a321d
AD
149 struct rmi_f01_power_management power_management;
150};
151
152/**
153 * struct rmi_function_descriptor - RMI function base addresses
154 *
155 * @query_base_addr: The RMI Query base address
156 * @command_base_addr: The RMI Command base address
157 * @control_base_addr: The RMI Control base address
158 * @data_base_addr: The RMI Data base address
159 * @interrupt_source_count: The number of irqs this RMI function needs
160 * @function_number: The RMI function number
161 *
162 * This struct is used when iterating the Page Description Table. The addresses
163 * are 16-bit values to include the current page address.
164 *
165 */
166struct rmi_function_descriptor {
167 u16 query_base_addr;
168 u16 command_base_addr;
169 u16 control_base_addr;
170 u16 data_base_addr;
171 u8 interrupt_source_count;
172 u8 function_number;
173 u8 function_version;
174};
175
176struct rmi_device;
177
178/**
179 * struct rmi_transport_dev - represent an RMI transport device
180 *
181 * @dev: Pointer to the communication device, e.g. i2c or spi
182 * @rmi_dev: Pointer to the RMI device
183 * @proto_name: name of the transport protocol (SPI, i2c, etc)
184 * @ops: pointer to transport operations implementation
185 *
186 * The RMI transport device implements the glue between different communication
187 * buses such as I2C and SPI.
188 *
189 */
190struct rmi_transport_dev {
191 struct device *dev;
192 struct rmi_device *rmi_dev;
193
194 const char *proto_name;
195 const struct rmi_transport_ops *ops;
196
197 struct rmi_device_platform_data pdata;
198
199 struct input_dev *input;
200
201 void *attn_data;
202 int attn_size;
203};
204
205/**
206 * struct rmi_transport_ops - defines transport protocol operations.
207 *
208 * @write_block: Writing a block of data to the specified address
209 * @read_block: Read a block of data from the specified address.
210 */
211struct rmi_transport_ops {
212 int (*write_block)(struct rmi_transport_dev *xport, u16 addr,
213 const void *buf, size_t len);
214 int (*read_block)(struct rmi_transport_dev *xport, u16 addr,
215 void *buf, size_t len);
216 int (*reset)(struct rmi_transport_dev *xport, u16 reset_addr);
217};
218
219/**
220 * struct rmi_driver - driver for an RMI4 sensor on the RMI bus.
221 *
222 * @driver: Device driver model driver
223 * @reset_handler: Called when a reset is detected.
224 * @clear_irq_bits: Clear the specified bits in the current interrupt mask.
225 * @set_irq_bist: Set the specified bits in the current interrupt mask.
226 * @store_productid: Callback for cache product id from function 01
227 * @data: Private data pointer
228 *
229 */
230struct rmi_driver {
231 struct device_driver driver;
232
233 int (*reset_handler)(struct rmi_device *rmi_dev);
234 int (*clear_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
235 int (*set_irq_bits)(struct rmi_device *rmi_dev, unsigned long *mask);
236 int (*store_productid)(struct rmi_device *rmi_dev);
237 int (*set_input_params)(struct rmi_device *rmi_dev,
238 struct input_dev *input);
239 void *data;
240};
241
242/**
243 * struct rmi_device - represents an RMI4 sensor device on the RMI bus.
244 *
245 * @dev: The device created for the RMI bus
246 * @number: Unique number for the device on the bus.
247 * @driver: Pointer to associated driver
248 * @xport: Pointer to the transport interface
249 *
250 */
251struct rmi_device {
252 struct device dev;
253 int number;
254
255 struct rmi_driver *driver;
256 struct rmi_transport_dev *xport;
257
258};
259
260struct rmi_driver_data {
261 struct list_head function_list;
262
263 struct rmi_device *rmi_dev;
264
265 struct rmi_function *f01_container;
266 bool f01_bootloader_mode;
267
268 u32 attn_count;
269 int num_of_irq_regs;
270 int irq_count;
271 unsigned long *irq_status;
272 unsigned long *fn_irq_bits;
273 unsigned long *current_irq_mask;
274 unsigned long *new_irq_mask;
275 struct mutex irq_mutex;
276 struct input_dev *input;
277
278 u8 pdt_props;
279 u8 bsr;
280
281 bool enabled;
282
283 void *data;
284};
285
286int rmi_register_transport_device(struct rmi_transport_dev *xport);
287void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
288int rmi_process_interrupt_requests(struct rmi_device *rmi_dev);
289
290int rmi_driver_suspend(struct rmi_device *rmi_dev);
291int rmi_driver_resume(struct rmi_device *rmi_dev);
292#endif