blob: 02513c0502fc1309a9f8285ea2f4e3237fd7464a [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 */
Seth Forsheefa629ef2011-11-07 19:53:24 -080025
Hans de Goede02d04252014-07-25 22:43:35 -070026#define MAX_TOUCHES 2
27
Yunkang Tangee65d4b2013-12-26 14:54:19 -080028#define DOLPHIN_COUNT_PER_ELECTRODE 64
29#define DOLPHIN_PROFILE_XOFFSET 8 /* x-electrode offset */
30#define DOLPHIN_PROFILE_YOFFSET 1 /* y-electrode offset */
31
Yunkang Tang38088432014-07-26 13:51:41 -070032/*
33 * enum V7_PACKET_ID - defines the packet type for V7
34 * V7_PACKET_ID_IDLE: There's no finger and no button activity.
35 * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
36 * or there's button activities.
37 * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
38 * V7_PACKET_ID_NEW: The finger position in slot is not continues from
39 * previous packet.
40*/
41enum V7_PACKET_ID {
42 V7_PACKET_ID_IDLE,
43 V7_PACKET_ID_TWO,
44 V7_PACKET_ID_MULTI,
45 V7_PACKET_ID_NEW,
46 V7_PACKET_ID_UNKNOWN,
47};
48
Kevin Cernekee88a80342013-02-13 20:55:19 -080049/**
Dmitry Torokhov8326bb52015-01-13 21:08:00 -080050 * struct alps_protocol_info - information about protocol used by a device
51 * @version: Indicates V1/V2/V3/...
52 * @byte0: Helps figure out whether a position report packet matches the
53 * known format for this model. The first byte of the report, ANDed with
54 * mask0, should match byte0.
55 * @mask0: The mask used to check the first byte of the report.
56 * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
57 */
58struct alps_protocol_info {
59 u16 version;
60 u8 byte0, mask0;
61 unsigned int flags;
62};
63
64/**
Kevin Cernekee88a80342013-02-13 20:55:19 -080065 * struct alps_model_info - touchpad ID table
66 * @signature: E7 response string to match.
67 * @command_mode_resp: For V3/V4 touchpads, the final byte of the EC response
68 * (aka command mode response) identifies the firmware minor version. This
69 * can be used to distinguish different hardware models which are not
70 * uniquely identifiable through their E7 responses.
Dmitry Torokhov8326bb52015-01-13 21:08:00 -080071 * @protocol_info: information about protcol used by the device.
Kevin Cernekee88a80342013-02-13 20:55:19 -080072 *
73 * Many (but not all) ALPS touchpads can be identified by looking at the
74 * values returned in the "E7 report" and/or the "EC report." This table
75 * lists a number of such touchpads.
76 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077struct alps_model_info {
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -080078 u8 signature[3];
79 u8 command_mode_resp;
Dmitry Torokhov8326bb52015-01-13 21:08:00 -080080 struct alps_protocol_info protocol_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
Kevin Cernekee88a80342013-02-13 20:55:19 -080083/**
84 * struct alps_nibble_commands - encodings for register accesses
85 * @command: PS/2 command used for the nibble
86 * @data: Data supplied as an argument to the PS/2 command, if applicable
87 *
88 * The ALPS protocol uses magic sequences to transmit binary data to the
89 * touchpad, as it is generally not OK to send arbitrary bytes out the
90 * PS/2 port. Each of the sequences in this table sends one nibble of the
91 * register address or (write) data. Different versions of the ALPS protocol
92 * use slightly different encodings.
93 */
Seth Forshee25bded72011-11-07 19:53:36 -080094struct alps_nibble_commands {
95 int command;
96 unsigned char data;
97};
98
Hans de Goede036e6c72014-07-25 22:38:51 -070099struct alps_bitmap_point {
100 int start_bit;
101 int num_bits;
102};
103
Kevin Cernekee88a80342013-02-13 20:55:19 -0800104/**
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800105 * struct alps_fields - decoded version of the report packet
106 * @x_map: Bitmap of active X positions for MT.
107 * @y_map: Bitmap of active Y positions for MT.
108 * @fingers: Number of fingers for MT.
Hans de Goede02d04252014-07-25 22:43:35 -0700109 * @pressure: Pressure.
110 * @st: position for ST.
111 * @mt: position for MT.
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800112 * @first_mp: Packet is the first of a multi-packet report.
113 * @is_mp: Packet is part of a multi-packet report.
114 * @left: Left touchpad button is active.
115 * @right: Right touchpad button is active.
116 * @middle: Middle touchpad button is active.
117 * @ts_left: Left trackstick button is active.
118 * @ts_right: Right trackstick button is active.
119 * @ts_middle: Middle trackstick button is active.
120 */
121struct alps_fields {
122 unsigned int x_map;
123 unsigned int y_map;
124 unsigned int fingers;
Hans de Goede02d04252014-07-25 22:43:35 -0700125
126 int pressure;
127 struct input_mt_pos st;
128 struct input_mt_pos mt[MAX_TOUCHES];
129
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800130 unsigned int first_mp:1;
131 unsigned int is_mp:1;
132
133 unsigned int left:1;
134 unsigned int right:1;
135 unsigned int middle:1;
136
137 unsigned int ts_left:1;
138 unsigned int ts_right:1;
139 unsigned int ts_middle:1;
140};
141
142/**
Kevin Cernekee88a80342013-02-13 20:55:19 -0800143 * struct alps_data - private data structure for the ALPS driver
Pali Rohár04aae282015-01-14 13:18:30 -0800144 * @psmouse: Pointer to parent psmouse device
145 * @dev2: Trackstick device (can be NULL).
146 * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
147 * @phys2: Physical path for the trackstick device.
148 * @phys3: Physical path for the generic PS/2 mouse.
149 * @dev3_register_work: Delayed work for registering PS/2 mouse.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800150 * @nibble_commands: Command mapping used for touchpad register accesses.
151 * @addr_command: Command used to tell the touchpad that a register address
152 * follows.
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800153 * @proto_version: Indicates V1/V2/V3/...
154 * @byte0: Helps figure out whether a position report packet matches the
155 * known format for this model. The first byte of the report, ANDed with
156 * mask0, should match byte0.
157 * @mask0: The mask used to check the first byte of the report.
Hans de Goedec0cd17f2014-07-25 22:49:14 -0700158 * @fw_ver: cached copy of firmware version (EC report)
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800159 * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800160 * @x_max: Largest possible X position value.
161 * @y_max: Largest possible Y position value.
162 * @x_bits: Number of X bits in the MT bitmap.
163 * @y_bits: Number of Y bits in the MT bitmap.
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800164 * @hw_init: Protocol-specific hardware init function.
165 * @process_packet: Protocol-specific function to process a report packet.
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800166 * @decode_fields: Protocol-specific function to read packet bitfields.
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800167 * @set_abs_params: Protocol-specific function to configure the input_dev.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800168 * @prev_fin: Finger bit from previous packet.
169 * @multi_packet: Multi-packet data in progress.
170 * @multi_data: Saved multi-packet data.
Hans de Goede02d04252014-07-25 22:43:35 -0700171 * @f: Decoded packet data fields.
Kevin Cernekee88a80342013-02-13 20:55:19 -0800172 * @quirks: Bitmap of ALPS_QUIRK_*.
173 * @timer: Timer for flushing out the final report packet in the stream.
174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175struct alps_data {
Pali Rohár04aae282015-01-14 13:18:30 -0800176 struct psmouse *psmouse;
Kevin Cernekee88a80342013-02-13 20:55:19 -0800177 struct input_dev *dev2;
Pali Rohár04aae282015-01-14 13:18:30 -0800178 struct input_dev *dev3;
179 char phys2[32];
180 char phys3[32];
181 struct delayed_work dev3_register_work;
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800182
183 /* these are autodetected when the device is identified */
Seth Forshee25bded72011-11-07 19:53:36 -0800184 const struct alps_nibble_commands *nibble_commands;
Kevin Cernekee88a80342013-02-13 20:55:19 -0800185 int addr_command;
Dmitry Torokhovd7c13d32015-01-13 20:53:22 -0800186 u16 proto_version;
187 u8 byte0, mask0;
188 u8 fw_ver[3];
Hans de Goede40e8f532014-07-25 22:37:15 -0700189 int flags;
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800190 int x_max;
191 int y_max;
192 int x_bits;
193 int y_bits;
Hans de Goedef3f33c62014-07-29 11:22:07 -0700194 unsigned int x_res;
195 unsigned int y_res;
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800196
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800197 int (*hw_init)(struct psmouse *psmouse);
198 void (*process_packet)(struct psmouse *psmouse);
Hans de Goede38c11eaa2014-07-25 22:48:44 -0700199 int (*decode_fields)(struct alps_fields *f, unsigned char *p,
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800200 struct psmouse *psmouse);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800201 void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
202
Kevin Cernekee88a80342013-02-13 20:55:19 -0800203 int prev_fin;
204 int multi_packet;
205 unsigned char multi_data[6];
Hans de Goede02d04252014-07-25 22:43:35 -0700206 struct alps_fields f;
Seth Forshee25bded72011-11-07 19:53:36 -0800207 u8 quirks;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800208 struct timer_list timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
Seth Forshee25bded72011-11-07 19:53:36 -0800211#define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */
212
Andres Salomon55e3d922007-03-10 01:39:54 -0500213#ifdef CONFIG_MOUSE_PS2_ALPS
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700214int alps_detect(struct psmouse *psmouse, bool set_properties);
Andres Salomon55e3d922007-03-10 01:39:54 -0500215int alps_init(struct psmouse *psmouse);
216#else
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700217inline int alps_detect(struct psmouse *psmouse, bool set_properties)
Andres Salomon55e3d922007-03-10 01:39:54 -0500218{
219 return -ENOSYS;
220}
221inline int alps_init(struct psmouse *psmouse)
222{
223 return -ENOSYS;
224}
225#endif /* CONFIG_MOUSE_PS2_ALPS */
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#endif