blob: 7931237171451c1a729458589f62a43d5526a78d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALPS touchpad PS/2 mouse driver
3 *
4 * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
5 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11
12#ifndef _ALPS_H
13#define _ALPS_H
14
Hans de Goede02d04252014-07-25 22:43:35 -070015#include <linux/input/mt.h>
16
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -080017#define ALPS_PROTO_V1 0x100
18#define ALPS_PROTO_V2 0x200
19#define ALPS_PROTO_V3 0x300
Dmitry Torokhovfb2dd7a2015-01-14 10:39:52 -080020#define ALPS_PROTO_V3_RUSHMORE 0x310
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -080021#define ALPS_PROTO_V4 0x400
22#define ALPS_PROTO_V5 0x500
23#define ALPS_PROTO_V6 0x600
24#define ALPS_PROTO_V7 0x700 /* t3btl t4s */
Masaki Ota3db5b9f2015-03-27 20:57:52 -070025#define ALPS_PROTO_V8 0x800 /* SS4btl SS4s */
Seth Forsheefa629ef2011-11-07 19:53:24 -080026
Masaki Ota3db5b9f2015-03-27 20:57:52 -070027#define MAX_TOUCHES 4
Hans de Goede02d04252014-07-25 22:43:35 -070028
Yunkang Tangee65d4b2013-12-26 14:54:19 -080029#define DOLPHIN_COUNT_PER_ELECTRODE 64
30#define DOLPHIN_PROFILE_XOFFSET 8 /* x-electrode offset */
31#define DOLPHIN_PROFILE_YOFFSET 1 /* y-electrode offset */
32
Yunkang Tang38088432014-07-26 13:51:41 -070033/*
Masaki Ota3db5b9f2015-03-27 20:57:52 -070034 * enum SS4_PACKET_ID - defines the packet type for V8
35 * SS4_PACKET_ID_IDLE: There's no finger and no button activity.
36 * SS4_PACKET_ID_ONE: There's one finger on touchpad
37 * or there's button activities.
38 * SS4_PACKET_ID_TWO: There's two or more fingers on touchpad
39 * SS4_PACKET_ID_MULTI: There's three or more fingers on touchpad
Ben Gamari4777ac22016-10-04 11:33:25 -070040 * SS4_PACKET_ID_STICK: A stick pointer packet
Masaki Ota3db5b9f2015-03-27 20:57:52 -070041*/
42enum SS4_PACKET_ID {
43 SS4_PACKET_ID_IDLE = 0,
44 SS4_PACKET_ID_ONE,
45 SS4_PACKET_ID_TWO,
46 SS4_PACKET_ID_MULTI,
Ben Gamari4777ac22016-10-04 11:33:25 -070047 SS4_PACKET_ID_STICK,
Masaki Ota3db5b9f2015-03-27 20:57:52 -070048};
49
50#define SS4_COUNT_PER_ELECTRODE 256
51#define SS4_NUMSENSOR_XOFFSET 7
52#define SS4_NUMSENSOR_YOFFSET 7
53#define SS4_MIN_PITCH_MM 50
54
55#define SS4_MASK_NORMAL_BUTTONS 0x07
56
Masaki Ota81643d02017-03-17 14:10:57 -070057#define SS4PLUS_COUNT_PER_ELECTRODE 128
58#define SS4PLUS_NUMSENSOR_XOFFSET 16
59#define SS4PLUS_NUMSENSOR_YOFFSET 5
60#define SS4PLUS_MIN_PITCH_MM 37
61
62#define IS_SS4PLUS_DEV(_b) (((_b[0]) == 0x73) && \
63 ((_b[1]) == 0x03) && \
64 ((_b[2]) == 0x28) \
65 )
66
Masaki Ota3db5b9f2015-03-27 20:57:52 -070067#define SS4_1F_X_V2(_b) ((_b[0] & 0x0007) | \
68 ((_b[1] << 3) & 0x0078) | \
69 ((_b[1] << 2) & 0x0380) | \
70 ((_b[2] << 5) & 0x1C00) \
71 )
72
73#define SS4_1F_Y_V2(_b) (((_b[2]) & 0x000F) | \
74 ((_b[3] >> 2) & 0x0030) | \
75 ((_b[4] << 6) & 0x03C0) | \
76 ((_b[4] << 5) & 0x0C00) \
77 )
78
79#define SS4_1F_Z_V2(_b) (((_b[5]) & 0x0F) | \
80 ((_b[5] >> 1) & 0x70) | \
81 ((_b[4]) & 0x80) \
82 )
83
84#define SS4_1F_LFB_V2(_b) (((_b[2] >> 4) & 0x01) == 0x01)
85
86#define SS4_MF_LF_V2(_b, _i) ((_b[1 + (_i) * 3] & 0x0004) == 0x0004)
87
88#define SS4_BTN_V2(_b) ((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS)
89
90#define SS4_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 5) & 0x00E0) | \
91 ((_b[1 + _i * 3] << 5) & 0x1F00) \
92 )
93
Masaki Ota963068b2017-08-24 15:44:36 -070094#define SS4_PLUS_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 4) & 0x0070) | \
95 ((_b[1 + (_i) * 3] << 4) & 0x0F80) \
96 )
97
Masaki Ota3db5b9f2015-03-27 20:57:52 -070098#define SS4_STD_MF_Y_V2(_b, _i) (((_b[1 + (_i) * 3] << 3) & 0x0010) | \
99 ((_b[2 + (_i) * 3] << 5) & 0x01E0) | \
100 ((_b[2 + (_i) * 3] << 4) & 0x0E00) \
101 )
102
103#define SS4_BTL_MF_X_V2(_b, _i) (SS4_STD_MF_X_V2(_b, _i) | \
104 ((_b[0 + (_i) * 3] >> 3) & 0x0010) \
105 )
106
Masaki Ota963068b2017-08-24 15:44:36 -0700107#define SS4_PLUS_BTL_MF_X_V2(_b, _i) (SS4_PLUS_STD_MF_X_V2(_b, _i) | \
108 ((_b[0 + (_i) * 3] >> 4) & 0x0008) \
109 )
110
Masaki Ota3db5b9f2015-03-27 20:57:52 -0700111#define SS4_BTL_MF_Y_V2(_b, _i) (SS4_STD_MF_Y_V2(_b, _i) | \
112 ((_b[0 + (_i) * 3] >> 3) & 0x0008) \
113 )
114
115#define SS4_MF_Z_V2(_b, _i) (((_b[1 + (_i) * 3]) & 0x0001) | \
116 ((_b[1 + (_i) * 3] >> 1) & 0x0002) \
117 )
118
119#define SS4_IS_MF_CONTINUE(_b) ((_b[2] & 0x10) == 0x10)
120#define SS4_IS_5F_DETECTED(_b) ((_b[2] & 0x10) == 0x10)
121
122
123#define SS4_MFPACKET_NO_AX 8160 /* X-Coordinate value */
124#define SS4_MFPACKET_NO_AY 4080 /* Y-Coordinate value */
125#define SS4_MFPACKET_NO_AX_BL 8176 /* Buttonless X-Coordinate value */
126#define SS4_MFPACKET_NO_AY_BL 4088 /* Buttonless Y-Coordinate value */
127
128/*
Yunkang Tang38088432014-07-26 13:51:41 -0700129 * enum V7_PACKET_ID - defines the packet type for V7
130 * V7_PACKET_ID_IDLE: There's no finger and no button activity.
131 * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
132 * or there's button activities.
133 * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
134 * V7_PACKET_ID_NEW: The finger position in slot is not continues from
135 * previous packet.
136*/
137enum V7_PACKET_ID {
138 V7_PACKET_ID_IDLE,
139 V7_PACKET_ID_TWO,
140 V7_PACKET_ID_MULTI,
141 V7_PACKET_ID_NEW,
142 V7_PACKET_ID_UNKNOWN,
143};
144
Kevin Cernekee88a80342013-02-13 20:55:19 -0800145/**
Dmitry Torokhov8326bb52015-01-13 21:08:00 -0800146 * struct alps_protocol_info - information about protocol used by a device
147 * @version: Indicates V1/V2/V3/...
148 * @byte0: Helps figure out whether a position report packet matches the
149 * known format for this model. The first byte of the report, ANDed with
150 * mask0, should match byte0.
151 * @mask0: The mask used to check the first byte of the report.
152 * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
153 */
154struct alps_protocol_info {
155 u16 version;
156 u8 byte0, mask0;
157 unsigned int flags;
158};
159
160/**
Kevin Cernekee88a80342013-02-13 20:55:19 -0800161 * struct alps_model_info - touchpad ID table
162 * @signature: E7 response string to match.
163 * @command_mode_resp: For V3/V4 touchpads, the final byte of the EC response
164 * (aka command mode response) identifies the firmware minor version. This
165 * can be used to distinguish different hardware models which are not
166 * uniquely identifiable through their E7 responses.
Dmitry Torokhov8326bb52015-01-13 21:08:00 -0800167 * @protocol_info: information about protcol used by the device.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800168 *
169 * Many (but not all) ALPS touchpads can be identified by looking at the
170 * values returned in the "E7 report" and/or the "EC report." This table
171 * lists a number of such touchpads.
172 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173struct alps_model_info {
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -0800174 u8 signature[3];
175 u8 command_mode_resp;
Dmitry Torokhov8326bb52015-01-13 21:08:00 -0800176 struct alps_protocol_info protocol_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177};
178
Kevin Cernekee88a80342013-02-13 20:55:19 -0800179/**
180 * struct alps_nibble_commands - encodings for register accesses
181 * @command: PS/2 command used for the nibble
182 * @data: Data supplied as an argument to the PS/2 command, if applicable
183 *
184 * The ALPS protocol uses magic sequences to transmit binary data to the
185 * touchpad, as it is generally not OK to send arbitrary bytes out the
186 * PS/2 port. Each of the sequences in this table sends one nibble of the
187 * register address or (write) data. Different versions of the ALPS protocol
188 * use slightly different encodings.
189 */
Seth Forshee25bded72011-11-07 19:53:36 -0800190struct alps_nibble_commands {
191 int command;
192 unsigned char data;
193};
194
Hans de Goede036e6c72014-07-25 22:38:51 -0700195struct alps_bitmap_point {
196 int start_bit;
197 int num_bits;
198};
199
Kevin Cernekee88a80342013-02-13 20:55:19 -0800200/**
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800201 * struct alps_fields - decoded version of the report packet
202 * @x_map: Bitmap of active X positions for MT.
203 * @y_map: Bitmap of active Y positions for MT.
204 * @fingers: Number of fingers for MT.
Hans de Goede02d04252014-07-25 22:43:35 -0700205 * @pressure: Pressure.
206 * @st: position for ST.
207 * @mt: position for MT.
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800208 * @first_mp: Packet is the first of a multi-packet report.
209 * @is_mp: Packet is part of a multi-packet report.
210 * @left: Left touchpad button is active.
211 * @right: Right touchpad button is active.
212 * @middle: Middle touchpad button is active.
213 * @ts_left: Left trackstick button is active.
214 * @ts_right: Right trackstick button is active.
215 * @ts_middle: Middle trackstick button is active.
216 */
217struct alps_fields {
218 unsigned int x_map;
219 unsigned int y_map;
220 unsigned int fingers;
Hans de Goede02d04252014-07-25 22:43:35 -0700221
222 int pressure;
223 struct input_mt_pos st;
224 struct input_mt_pos mt[MAX_TOUCHES];
225
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800226 unsigned int first_mp:1;
227 unsigned int is_mp:1;
228
229 unsigned int left:1;
230 unsigned int right:1;
231 unsigned int middle:1;
232
233 unsigned int ts_left:1;
234 unsigned int ts_right:1;
235 unsigned int ts_middle:1;
236};
237
238/**
Kevin Cernekee88a80342013-02-13 20:55:19 -0800239 * struct alps_data - private data structure for the ALPS driver
Pali Rohár04aae282015-01-14 13:18:30 -0800240 * @psmouse: Pointer to parent psmouse device
241 * @dev2: Trackstick device (can be NULL).
242 * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
243 * @phys2: Physical path for the trackstick device.
244 * @phys3: Physical path for the generic PS/2 mouse.
245 * @dev3_register_work: Delayed work for registering PS/2 mouse.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800246 * @nibble_commands: Command mapping used for touchpad register accesses.
247 * @addr_command: Command used to tell the touchpad that a register address
248 * follows.
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800249 * @proto_version: Indicates V1/V2/V3/...
250 * @byte0: Helps figure out whether a position report packet matches the
251 * known format for this model. The first byte of the report, ANDed with
252 * mask0, should match byte0.
253 * @mask0: The mask used to check the first byte of the report.
Hans de Goedec0cd17f2014-07-25 22:49:14 -0700254 * @fw_ver: cached copy of firmware version (EC report)
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800255 * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800256 * @x_max: Largest possible X position value.
257 * @y_max: Largest possible Y position value.
258 * @x_bits: Number of X bits in the MT bitmap.
259 * @y_bits: Number of Y bits in the MT bitmap.
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800260 * @hw_init: Protocol-specific hardware init function.
261 * @process_packet: Protocol-specific function to process a report packet.
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800262 * @decode_fields: Protocol-specific function to read packet bitfields.
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800263 * @set_abs_params: Protocol-specific function to configure the input_dev.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800264 * @prev_fin: Finger bit from previous packet.
265 * @multi_packet: Multi-packet data in progress.
266 * @multi_data: Saved multi-packet data.
Hans de Goede02d04252014-07-25 22:43:35 -0700267 * @f: Decoded packet data fields.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800268 * @quirks: Bitmap of ALPS_QUIRK_*.
269 * @timer: Timer for flushing out the final report packet in the stream.
270 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271struct alps_data {
Pali Rohár04aae282015-01-14 13:18:30 -0800272 struct psmouse *psmouse;
Kevin Cernekee88a80342013-02-13 20:55:19 -0800273 struct input_dev *dev2;
Pali Rohár04aae282015-01-14 13:18:30 -0800274 struct input_dev *dev3;
275 char phys2[32];
276 char phys3[32];
277 struct delayed_work dev3_register_work;
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800278
279 /* these are autodetected when the device is identified */
Seth Forshee25bded72011-11-07 19:53:36 -0800280 const struct alps_nibble_commands *nibble_commands;
Kevin Cernekee88a80342013-02-13 20:55:19 -0800281 int addr_command;
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -0800282 u16 proto_version;
283 u8 byte0, mask0;
Masaki Ota81643d02017-03-17 14:10:57 -0700284 u8 dev_id[3];
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -0800285 u8 fw_ver[3];
Hans de Goede40e8f532014-07-25 22:37:15 -0700286 int flags;
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800287 int x_max;
288 int y_max;
289 int x_bits;
290 int y_bits;
Hans de Goedef3f33c62014-07-29 11:22:07 -0700291 unsigned int x_res;
292 unsigned int y_res;
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800293
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800294 int (*hw_init)(struct psmouse *psmouse);
295 void (*process_packet)(struct psmouse *psmouse);
Hans de Goede38c11eaa2014-07-25 22:48:44 -0700296 int (*decode_fields)(struct alps_fields *f, unsigned char *p,
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800297 struct psmouse *psmouse);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800298 void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
299
Kevin Cernekee88a80342013-02-13 20:55:19 -0800300 int prev_fin;
301 int multi_packet;
Hans de Goede4dd26572015-05-20 14:41:10 -0700302 int second_touch;
Kevin Cernekee88a80342013-02-13 20:55:19 -0800303 unsigned char multi_data[6];
Hans de Goede02d04252014-07-25 22:43:35 -0700304 struct alps_fields f;
Seth Forshee25bded72011-11-07 19:53:36 -0800305 u8 quirks;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800306 struct timer_list timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};
308
Seth Forshee25bded72011-11-07 19:53:36 -0800309#define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */
310
Andres Salomon55e3d922007-03-10 01:39:54 -0500311#ifdef CONFIG_MOUSE_PS2_ALPS
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700312int alps_detect(struct psmouse *psmouse, bool set_properties);
Andres Salomon55e3d922007-03-10 01:39:54 -0500313int alps_init(struct psmouse *psmouse);
314#else
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700315inline int alps_detect(struct psmouse *psmouse, bool set_properties)
Andres Salomon55e3d922007-03-10 01:39:54 -0500316{
317 return -ENOSYS;
318}
319inline int alps_init(struct psmouse *psmouse)
320{
321 return -ENOSYS;
322}
323#endif /* CONFIG_MOUSE_PS2_ALPS */
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#endif