xref: /openbmc/linux/drivers/input/mouse/alps.h (revision f7c35abe)
1 /*
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 
15 #include <linux/input/mt.h>
16 
17 #define ALPS_PROTO_V1		0x100
18 #define ALPS_PROTO_V2		0x200
19 #define ALPS_PROTO_V3		0x300
20 #define ALPS_PROTO_V3_RUSHMORE	0x310
21 #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 */
25 #define ALPS_PROTO_V8		0x800	/* SS4btl SS4s */
26 
27 #define MAX_TOUCHES	4
28 
29 #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 
33 /*
34  * 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
40  * SS4_PACKET_ID_STICK: A stick pointer packet
41 */
42 enum SS4_PACKET_ID {
43 	SS4_PACKET_ID_IDLE = 0,
44 	SS4_PACKET_ID_ONE,
45 	SS4_PACKET_ID_TWO,
46 	SS4_PACKET_ID_MULTI,
47 	SS4_PACKET_ID_STICK,
48 };
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 
57 #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 
67 #define SS4_IS_IDLE_V2(_b)	(((_b[0]) == 0x18) &&		\
68 				 ((_b[1]) == 0x10) &&		\
69 				 ((_b[2]) == 0x00) &&		\
70 				 ((_b[3] & 0x88) == 0x08) &&	\
71 				 ((_b[4]) == 0x10) &&		\
72 				 ((_b[5]) == 0x00)		\
73 				)
74 
75 #define SS4_1F_X_V2(_b)		(((_b[0]) & 0x0007) |		\
76 				 ((_b[1] << 3) & 0x0078) |	\
77 				 ((_b[1] << 2) & 0x0380) |	\
78 				 ((_b[2] << 5) & 0x1C00)	\
79 				)
80 
81 #define SS4_1F_Y_V2(_b)		(((_b[2]) & 0x000F) |		\
82 				 ((_b[3] >> 2) & 0x0030) |	\
83 				 ((_b[4] << 6) & 0x03C0) |	\
84 				 ((_b[4] << 5) & 0x0C00)	\
85 				)
86 
87 #define SS4_1F_Z_V2(_b)		(((_b[5]) & 0x0F) |		\
88 				 ((_b[5] >> 1) & 0x70) |	\
89 				 ((_b[4]) & 0x80)		\
90 				)
91 
92 #define SS4_1F_LFB_V2(_b)	(((_b[2] >> 4) & 0x01) == 0x01)
93 
94 #define SS4_MF_LF_V2(_b, _i)	((_b[1 + (_i) * 3] & 0x0004) == 0x0004)
95 
96 #define SS4_BTN_V2(_b)		((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS)
97 
98 #define SS4_STD_MF_X_V2(_b, _i)	(((_b[0 + (_i) * 3] << 5) & 0x00E0) |	\
99 				 ((_b[1 + _i * 3]  << 5) & 0x1F00)	\
100 				)
101 
102 #define SS4_STD_MF_Y_V2(_b, _i)	(((_b[1 + (_i) * 3] << 3) & 0x0010) |	\
103 				 ((_b[2 + (_i) * 3] << 5) & 0x01E0) |	\
104 				 ((_b[2 + (_i) * 3] << 4) & 0x0E00)	\
105 				)
106 
107 #define SS4_BTL_MF_X_V2(_b, _i)	(SS4_STD_MF_X_V2(_b, _i) |		\
108 				 ((_b[0 + (_i) * 3] >> 3) & 0x0010)	\
109 				)
110 
111 #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 #define SS4_TS_X_V2(_b)		(s8)(				\
123 				 ((_b[0] & 0x01) << 7) |	\
124 				 (_b[1] & 0x7F)		\
125 				)
126 
127 #define SS4_TS_Y_V2(_b)		-(s8)(				\
128 				 ((_b[3] & 0x01) << 7) |	\
129 				 (_b[2] & 0x7F)		\
130 				)
131 
132 #define SS4_TS_Z_V2(_b)		(s8)(_b[4] & 0x7F)
133 
134 
135 #define SS4_MFPACKET_NO_AX	8160	/* X-Coordinate value */
136 #define SS4_MFPACKET_NO_AY	4080	/* Y-Coordinate value */
137 #define SS4_MFPACKET_NO_AX_BL	8176	/* Buttonless X-Coordinate value */
138 #define SS4_MFPACKET_NO_AY_BL	4088	/* Buttonless Y-Coordinate value */
139 
140 /*
141  * enum V7_PACKET_ID - defines the packet type for V7
142  * V7_PACKET_ID_IDLE: There's no finger and no button activity.
143  * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
144  *  or there's button activities.
145  * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
146  * V7_PACKET_ID_NEW: The finger position in slot is not continues from
147  *  previous packet.
148 */
149 enum V7_PACKET_ID {
150 	 V7_PACKET_ID_IDLE,
151 	 V7_PACKET_ID_TWO,
152 	 V7_PACKET_ID_MULTI,
153 	 V7_PACKET_ID_NEW,
154 	 V7_PACKET_ID_UNKNOWN,
155 };
156 
157 /**
158  * struct alps_protocol_info - information about protocol used by a device
159  * @version: Indicates V1/V2/V3/...
160  * @byte0: Helps figure out whether a position report packet matches the
161  *   known format for this model.  The first byte of the report, ANDed with
162  *   mask0, should match byte0.
163  * @mask0: The mask used to check the first byte of the report.
164  * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
165  */
166 struct alps_protocol_info {
167 	u16 version;
168 	u8 byte0, mask0;
169 	unsigned int flags;
170 };
171 
172 /**
173  * struct alps_model_info - touchpad ID table
174  * @signature: E7 response string to match.
175  * @command_mode_resp: For V3/V4 touchpads, the final byte of the EC response
176  *   (aka command mode response) identifies the firmware minor version.  This
177  *   can be used to distinguish different hardware models which are not
178  *   uniquely identifiable through their E7 responses.
179  * @protocol_info: information about protocol used by the device.
180  *
181  * Many (but not all) ALPS touchpads can be identified by looking at the
182  * values returned in the "E7 report" and/or the "EC report."  This table
183  * lists a number of such touchpads.
184  */
185 struct alps_model_info {
186 	u8 signature[3];
187 	u8 command_mode_resp;
188 	struct alps_protocol_info protocol_info;
189 };
190 
191 /**
192  * struct alps_nibble_commands - encodings for register accesses
193  * @command: PS/2 command used for the nibble
194  * @data: Data supplied as an argument to the PS/2 command, if applicable
195  *
196  * The ALPS protocol uses magic sequences to transmit binary data to the
197  * touchpad, as it is generally not OK to send arbitrary bytes out the
198  * PS/2 port.  Each of the sequences in this table sends one nibble of the
199  * register address or (write) data.  Different versions of the ALPS protocol
200  * use slightly different encodings.
201  */
202 struct alps_nibble_commands {
203 	int command;
204 	unsigned char data;
205 };
206 
207 struct alps_bitmap_point {
208 	int start_bit;
209 	int num_bits;
210 };
211 
212 /**
213  * struct alps_fields - decoded version of the report packet
214  * @x_map: Bitmap of active X positions for MT.
215  * @y_map: Bitmap of active Y positions for MT.
216  * @fingers: Number of fingers for MT.
217  * @pressure: Pressure.
218  * @st: position for ST.
219  * @mt: position for MT.
220  * @first_mp: Packet is the first of a multi-packet report.
221  * @is_mp: Packet is part of a multi-packet report.
222  * @left: Left touchpad button is active.
223  * @right: Right touchpad button is active.
224  * @middle: Middle touchpad button is active.
225  * @ts_left: Left trackstick button is active.
226  * @ts_right: Right trackstick button is active.
227  * @ts_middle: Middle trackstick button is active.
228  */
229 struct alps_fields {
230 	unsigned int x_map;
231 	unsigned int y_map;
232 	unsigned int fingers;
233 
234 	int pressure;
235 	struct input_mt_pos st;
236 	struct input_mt_pos mt[MAX_TOUCHES];
237 
238 	unsigned int first_mp:1;
239 	unsigned int is_mp:1;
240 
241 	unsigned int left:1;
242 	unsigned int right:1;
243 	unsigned int middle:1;
244 
245 	unsigned int ts_left:1;
246 	unsigned int ts_right:1;
247 	unsigned int ts_middle:1;
248 };
249 
250 /**
251  * struct alps_data - private data structure for the ALPS driver
252  * @psmouse: Pointer to parent psmouse device
253  * @dev2: Trackstick device (can be NULL).
254  * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
255  * @phys2: Physical path for the trackstick device.
256  * @phys3: Physical path for the generic PS/2 mouse.
257  * @dev3_register_work: Delayed work for registering PS/2 mouse.
258  * @nibble_commands: Command mapping used for touchpad register accesses.
259  * @addr_command: Command used to tell the touchpad that a register address
260  *   follows.
261  * @proto_version: Indicates V1/V2/V3/...
262  * @byte0: Helps figure out whether a position report packet matches the
263  *   known format for this model.  The first byte of the report, ANDed with
264  *   mask0, should match byte0.
265  * @mask0: The mask used to check the first byte of the report.
266  * @fw_ver: cached copy of firmware version (EC report)
267  * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
268  * @x_max: Largest possible X position value.
269  * @y_max: Largest possible Y position value.
270  * @x_bits: Number of X bits in the MT bitmap.
271  * @y_bits: Number of Y bits in the MT bitmap.
272  * @hw_init: Protocol-specific hardware init function.
273  * @process_packet: Protocol-specific function to process a report packet.
274  * @decode_fields: Protocol-specific function to read packet bitfields.
275  * @set_abs_params: Protocol-specific function to configure the input_dev.
276  * @prev_fin: Finger bit from previous packet.
277  * @multi_packet: Multi-packet data in progress.
278  * @multi_data: Saved multi-packet data.
279  * @f: Decoded packet data fields.
280  * @quirks: Bitmap of ALPS_QUIRK_*.
281  * @timer: Timer for flushing out the final report packet in the stream.
282  */
283 struct alps_data {
284 	struct psmouse *psmouse;
285 	struct input_dev *dev2;
286 	struct input_dev *dev3;
287 	char phys2[32];
288 	char phys3[32];
289 	struct delayed_work dev3_register_work;
290 
291 	/* these are autodetected when the device is identified */
292 	const struct alps_nibble_commands *nibble_commands;
293 	int addr_command;
294 	u16 proto_version;
295 	u8 byte0, mask0;
296 	u8 dev_id[3];
297 	u8 fw_ver[3];
298 	int flags;
299 	int x_max;
300 	int y_max;
301 	int x_bits;
302 	int y_bits;
303 	unsigned int x_res;
304 	unsigned int y_res;
305 
306 	int (*hw_init)(struct psmouse *psmouse);
307 	void (*process_packet)(struct psmouse *psmouse);
308 	int (*decode_fields)(struct alps_fields *f, unsigned char *p,
309 			      struct psmouse *psmouse);
310 	void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
311 
312 	int prev_fin;
313 	int multi_packet;
314 	int second_touch;
315 	unsigned char multi_data[6];
316 	struct alps_fields f;
317 	u8 quirks;
318 	struct timer_list timer;
319 };
320 
321 #define ALPS_QUIRK_TRACKSTICK_BUTTONS	1 /* trakcstick buttons in trackstick packet */
322 
323 #ifdef CONFIG_MOUSE_PS2_ALPS
324 int alps_detect(struct psmouse *psmouse, bool set_properties);
325 int alps_init(struct psmouse *psmouse);
326 #else
327 inline int alps_detect(struct psmouse *psmouse, bool set_properties)
328 {
329 	return -ENOSYS;
330 }
331 inline int alps_init(struct psmouse *psmouse)
332 {
333 	return -ENOSYS;
334 }
335 #endif /* CONFIG_MOUSE_PS2_ALPS */
336 
337 #endif
338