xref: /linux/drivers/input/mouse/alps.h (revision 04aae283ba6a8cd4851d937bf9c6d6ef0361d794)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * ALPS touchpad PS/2 mouse driver
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
51da177e4SLinus Torvalds  * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify it
81da177e4SLinus Torvalds  * under the terms of the GNU General Public License version 2 as published by
91da177e4SLinus Torvalds  * the Free Software Foundation.
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #ifndef _ALPS_H
131da177e4SLinus Torvalds #define _ALPS_H
141da177e4SLinus Torvalds 
1502d04254SHans de Goede #include <linux/input/mt.h>
1602d04254SHans de Goede 
17d7c13d34SDmitry Torokhov #define ALPS_PROTO_V1		0x100
18d7c13d34SDmitry Torokhov #define ALPS_PROTO_V2		0x200
19d7c13d34SDmitry Torokhov #define ALPS_PROTO_V3		0x300
20fb2dd7a6SDmitry Torokhov #define ALPS_PROTO_V3_RUSHMORE	0x310
21d7c13d34SDmitry Torokhov #define ALPS_PROTO_V4		0x400
22d7c13d34SDmitry Torokhov #define ALPS_PROTO_V5		0x500
23d7c13d34SDmitry Torokhov #define ALPS_PROTO_V6		0x600
24d7c13d34SDmitry Torokhov #define ALPS_PROTO_V7		0x700	/* t3btl t4s */
25fa629ef5SSeth Forshee 
2602d04254SHans de Goede #define MAX_TOUCHES	2
2702d04254SHans de Goede 
28ee65d4b3SYunkang Tang #define DOLPHIN_COUNT_PER_ELECTRODE	64
29ee65d4b3SYunkang Tang #define DOLPHIN_PROFILE_XOFFSET		8	/* x-electrode offset */
30ee65d4b3SYunkang Tang #define DOLPHIN_PROFILE_YOFFSET		1	/* y-electrode offset */
31ee65d4b3SYunkang Tang 
323808843cSYunkang Tang /*
333808843cSYunkang Tang  * enum V7_PACKET_ID - defines the packet type for V7
343808843cSYunkang Tang  * V7_PACKET_ID_IDLE: There's no finger and no button activity.
353808843cSYunkang Tang  * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
363808843cSYunkang Tang  *  or there's button activities.
373808843cSYunkang Tang  * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
383808843cSYunkang Tang  * V7_PACKET_ID_NEW: The finger position in slot is not continues from
393808843cSYunkang Tang  *  previous packet.
403808843cSYunkang Tang */
413808843cSYunkang Tang enum V7_PACKET_ID {
423808843cSYunkang Tang 	 V7_PACKET_ID_IDLE,
433808843cSYunkang Tang 	 V7_PACKET_ID_TWO,
443808843cSYunkang Tang 	 V7_PACKET_ID_MULTI,
453808843cSYunkang Tang 	 V7_PACKET_ID_NEW,
463808843cSYunkang Tang 	 V7_PACKET_ID_UNKNOWN,
473808843cSYunkang Tang };
483808843cSYunkang Tang 
4988a80348SKevin Cernekee /**
508326bb57SDmitry Torokhov  * struct alps_protocol_info - information about protocol used by a device
518326bb57SDmitry Torokhov  * @version: Indicates V1/V2/V3/...
528326bb57SDmitry Torokhov  * @byte0: Helps figure out whether a position report packet matches the
538326bb57SDmitry Torokhov  *   known format for this model.  The first byte of the report, ANDed with
548326bb57SDmitry Torokhov  *   mask0, should match byte0.
558326bb57SDmitry Torokhov  * @mask0: The mask used to check the first byte of the report.
568326bb57SDmitry Torokhov  * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
578326bb57SDmitry Torokhov  */
588326bb57SDmitry Torokhov struct alps_protocol_info {
598326bb57SDmitry Torokhov 	u16 version;
608326bb57SDmitry Torokhov 	u8 byte0, mask0;
618326bb57SDmitry Torokhov 	unsigned int flags;
628326bb57SDmitry Torokhov };
638326bb57SDmitry Torokhov 
648326bb57SDmitry Torokhov /**
6588a80348SKevin Cernekee  * struct alps_model_info - touchpad ID table
6688a80348SKevin Cernekee  * @signature: E7 response string to match.
6788a80348SKevin Cernekee  * @command_mode_resp: For V3/V4 touchpads, the final byte of the EC response
6888a80348SKevin Cernekee  *   (aka command mode response) identifies the firmware minor version.  This
6988a80348SKevin Cernekee  *   can be used to distinguish different hardware models which are not
7088a80348SKevin Cernekee  *   uniquely identifiable through their E7 responses.
718326bb57SDmitry Torokhov  * @protocol_info: information about protcol used by the device.
7288a80348SKevin Cernekee  *
7388a80348SKevin Cernekee  * Many (but not all) ALPS touchpads can be identified by looking at the
7488a80348SKevin Cernekee  * values returned in the "E7 report" and/or the "EC report."  This table
7588a80348SKevin Cernekee  * lists a number of such touchpads.
7688a80348SKevin Cernekee  */
771da177e4SLinus Torvalds struct alps_model_info {
78d7c13d34SDmitry Torokhov 	u8 signature[3];
79d7c13d34SDmitry Torokhov 	u8 command_mode_resp;
808326bb57SDmitry Torokhov 	struct alps_protocol_info protocol_info;
811da177e4SLinus Torvalds };
821da177e4SLinus Torvalds 
8388a80348SKevin Cernekee /**
8488a80348SKevin Cernekee  * struct alps_nibble_commands - encodings for register accesses
8588a80348SKevin Cernekee  * @command: PS/2 command used for the nibble
8688a80348SKevin Cernekee  * @data: Data supplied as an argument to the PS/2 command, if applicable
8788a80348SKevin Cernekee  *
8888a80348SKevin Cernekee  * The ALPS protocol uses magic sequences to transmit binary data to the
8988a80348SKevin Cernekee  * touchpad, as it is generally not OK to send arbitrary bytes out the
9088a80348SKevin Cernekee  * PS/2 port.  Each of the sequences in this table sends one nibble of the
9188a80348SKevin Cernekee  * register address or (write) data.  Different versions of the ALPS protocol
9288a80348SKevin Cernekee  * use slightly different encodings.
9388a80348SKevin Cernekee  */
9425bded7cSSeth Forshee struct alps_nibble_commands {
9525bded7cSSeth Forshee 	int command;
9625bded7cSSeth Forshee 	unsigned char data;
9725bded7cSSeth Forshee };
9825bded7cSSeth Forshee 
99036e6c7bSHans de Goede struct alps_bitmap_point {
100036e6c7bSHans de Goede 	int start_bit;
101036e6c7bSHans de Goede 	int num_bits;
102036e6c7bSHans de Goede };
103036e6c7bSHans de Goede 
10488a80348SKevin Cernekee /**
105f85e5001SKevin Cernekee  * struct alps_fields - decoded version of the report packet
106f85e5001SKevin Cernekee  * @x_map: Bitmap of active X positions for MT.
107f85e5001SKevin Cernekee  * @y_map: Bitmap of active Y positions for MT.
108f85e5001SKevin Cernekee  * @fingers: Number of fingers for MT.
10902d04254SHans de Goede  * @pressure: Pressure.
11002d04254SHans de Goede  * @st: position for ST.
11102d04254SHans de Goede  * @mt: position for MT.
112f85e5001SKevin Cernekee  * @first_mp: Packet is the first of a multi-packet report.
113f85e5001SKevin Cernekee  * @is_mp: Packet is part of a multi-packet report.
114f85e5001SKevin Cernekee  * @left: Left touchpad button is active.
115f85e5001SKevin Cernekee  * @right: Right touchpad button is active.
116f85e5001SKevin Cernekee  * @middle: Middle touchpad button is active.
117f85e5001SKevin Cernekee  * @ts_left: Left trackstick button is active.
118f85e5001SKevin Cernekee  * @ts_right: Right trackstick button is active.
119f85e5001SKevin Cernekee  * @ts_middle: Middle trackstick button is active.
120f85e5001SKevin Cernekee  */
121f85e5001SKevin Cernekee struct alps_fields {
122f85e5001SKevin Cernekee 	unsigned int x_map;
123f85e5001SKevin Cernekee 	unsigned int y_map;
124f85e5001SKevin Cernekee 	unsigned int fingers;
12502d04254SHans de Goede 
12602d04254SHans de Goede 	int pressure;
12702d04254SHans de Goede 	struct input_mt_pos st;
12802d04254SHans de Goede 	struct input_mt_pos mt[MAX_TOUCHES];
12902d04254SHans de Goede 
130f85e5001SKevin Cernekee 	unsigned int first_mp:1;
131f85e5001SKevin Cernekee 	unsigned int is_mp:1;
132f85e5001SKevin Cernekee 
133f85e5001SKevin Cernekee 	unsigned int left:1;
134f85e5001SKevin Cernekee 	unsigned int right:1;
135f85e5001SKevin Cernekee 	unsigned int middle:1;
136f85e5001SKevin Cernekee 
137f85e5001SKevin Cernekee 	unsigned int ts_left:1;
138f85e5001SKevin Cernekee 	unsigned int ts_right:1;
139f85e5001SKevin Cernekee 	unsigned int ts_middle:1;
140f85e5001SKevin Cernekee };
141f85e5001SKevin Cernekee 
142f85e5001SKevin Cernekee /**
14388a80348SKevin Cernekee  * struct alps_data - private data structure for the ALPS driver
144*04aae283SPali Rohár  * @psmouse: Pointer to parent psmouse device
145*04aae283SPali Rohár  * @dev2: Trackstick device (can be NULL).
146*04aae283SPali Rohár  * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
147*04aae283SPali Rohár  * @phys2: Physical path for the trackstick device.
148*04aae283SPali Rohár  * @phys3: Physical path for the generic PS/2 mouse.
149*04aae283SPali Rohár  * @dev3_register_work: Delayed work for registering PS/2 mouse.
15088a80348SKevin Cernekee  * @nibble_commands: Command mapping used for touchpad register accesses.
15188a80348SKevin Cernekee  * @addr_command: Command used to tell the touchpad that a register address
15288a80348SKevin Cernekee  *   follows.
15399df65e7SKevin Cernekee  * @proto_version: Indicates V1/V2/V3/...
15499df65e7SKevin Cernekee  * @byte0: Helps figure out whether a position report packet matches the
15599df65e7SKevin Cernekee  *   known format for this model.  The first byte of the report, ANDed with
15699df65e7SKevin Cernekee  *   mask0, should match byte0.
15799df65e7SKevin Cernekee  * @mask0: The mask used to check the first byte of the report.
158c0cd17f6SHans de Goede  * @fw_ver: cached copy of firmware version (EC report)
15999df65e7SKevin Cernekee  * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
1607a9f73e7SKevin Cernekee  * @x_max: Largest possible X position value.
1617a9f73e7SKevin Cernekee  * @y_max: Largest possible Y position value.
1627a9f73e7SKevin Cernekee  * @x_bits: Number of X bits in the MT bitmap.
1637a9f73e7SKevin Cernekee  * @y_bits: Number of Y bits in the MT bitmap.
16424af5cb9SKevin Cernekee  * @hw_init: Protocol-specific hardware init function.
16524af5cb9SKevin Cernekee  * @process_packet: Protocol-specific function to process a report packet.
166f85e5001SKevin Cernekee  * @decode_fields: Protocol-specific function to read packet bitfields.
16724af5cb9SKevin Cernekee  * @set_abs_params: Protocol-specific function to configure the input_dev.
16888a80348SKevin Cernekee  * @prev_fin: Finger bit from previous packet.
16988a80348SKevin Cernekee  * @multi_packet: Multi-packet data in progress.
17088a80348SKevin Cernekee  * @multi_data: Saved multi-packet data.
17102d04254SHans de Goede  * @f: Decoded packet data fields.
17288a80348SKevin Cernekee  * @quirks: Bitmap of ALPS_QUIRK_*.
17388a80348SKevin Cernekee  * @timer: Timer for flushing out the final report packet in the stream.
17488a80348SKevin Cernekee  */
1751da177e4SLinus Torvalds struct alps_data {
176*04aae283SPali Rohár 	struct psmouse *psmouse;
17788a80348SKevin Cernekee 	struct input_dev *dev2;
178*04aae283SPali Rohár 	struct input_dev *dev3;
179*04aae283SPali Rohár 	char phys2[32];
180*04aae283SPali Rohár 	char phys3[32];
181*04aae283SPali Rohár 	struct delayed_work dev3_register_work;
18299df65e7SKevin Cernekee 
18399df65e7SKevin Cernekee 	/* these are autodetected when the device is identified */
18425bded7cSSeth Forshee 	const struct alps_nibble_commands *nibble_commands;
18588a80348SKevin Cernekee 	int addr_command;
186d7c13d34SDmitry Torokhov 	u16 proto_version;
187d7c13d34SDmitry Torokhov 	u8 byte0, mask0;
188d7c13d34SDmitry Torokhov 	u8 fw_ver[3];
18940e8f53bSHans de Goede 	int flags;
1907a9f73e7SKevin Cernekee 	int x_max;
1917a9f73e7SKevin Cernekee 	int y_max;
1927a9f73e7SKevin Cernekee 	int x_bits;
1937a9f73e7SKevin Cernekee 	int y_bits;
194f3f33c67SHans de Goede 	unsigned int x_res;
195f3f33c67SHans de Goede 	unsigned int y_res;
19699df65e7SKevin Cernekee 
19724af5cb9SKevin Cernekee 	int (*hw_init)(struct psmouse *psmouse);
19824af5cb9SKevin Cernekee 	void (*process_packet)(struct psmouse *psmouse);
19938c11eaaSHans de Goede 	int (*decode_fields)(struct alps_fields *f, unsigned char *p,
200ee65d4b3SYunkang Tang 			      struct psmouse *psmouse);
20124af5cb9SKevin Cernekee 	void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
20224af5cb9SKevin Cernekee 
20388a80348SKevin Cernekee 	int prev_fin;
20488a80348SKevin Cernekee 	int multi_packet;
20588a80348SKevin Cernekee 	unsigned char multi_data[6];
20602d04254SHans de Goede 	struct alps_fields f;
20725bded7cSSeth Forshee 	u8 quirks;
2081d9f2626SSebastian Kapfer 	struct timer_list timer;
2091da177e4SLinus Torvalds };
2101da177e4SLinus Torvalds 
21125bded7cSSeth Forshee #define ALPS_QUIRK_TRACKSTICK_BUTTONS	1 /* trakcstick buttons in trackstick packet */
21225bded7cSSeth Forshee 
21355e3d922SAndres Salomon #ifdef CONFIG_MOUSE_PS2_ALPS
214b7802c5cSDmitry Torokhov int alps_detect(struct psmouse *psmouse, bool set_properties);
21555e3d922SAndres Salomon int alps_init(struct psmouse *psmouse);
21655e3d922SAndres Salomon #else
217b7802c5cSDmitry Torokhov inline int alps_detect(struct psmouse *psmouse, bool set_properties)
21855e3d922SAndres Salomon {
21955e3d922SAndres Salomon 	return -ENOSYS;
22055e3d922SAndres Salomon }
22155e3d922SAndres Salomon inline int alps_init(struct psmouse *psmouse)
22255e3d922SAndres Salomon {
22355e3d922SAndres Salomon 	return -ENOSYS;
22455e3d922SAndres Salomon }
22555e3d922SAndres Salomon #endif /* CONFIG_MOUSE_PS2_ALPS */
22655e3d922SAndres Salomon 
2271da177e4SLinus Torvalds #endif
228