Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 15 | #include <linux/input/mt.h> |
| 16 | |
Dmitry Torokhov | d7c13d3 | 2015-01-13 20:53:22 -0800 | [diff] [blame] | 17 | #define ALPS_PROTO_V1 0x100 |
| 18 | #define ALPS_PROTO_V2 0x200 |
| 19 | #define ALPS_PROTO_V3 0x300 |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 20 | #define ALPS_PROTO_V3_RUSHMORE 0x310 |
Dmitry Torokhov | d7c13d3 | 2015-01-13 20:53:22 -0800 | [diff] [blame] | 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 */ |
Masaki Ota | 3db5b9f | 2015-03-27 20:57:52 -0700 | [diff] [blame] | 25 | #define ALPS_PROTO_V8 0x800 /* SS4btl SS4s */ |
Seth Forshee | fa629ef | 2011-11-07 19:53:24 -0800 | [diff] [blame] | 26 | |
Masaki Ota | 3db5b9f | 2015-03-27 20:57:52 -0700 | [diff] [blame] | 27 | #define MAX_TOUCHES 4 |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 28 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 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 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 33 | /* |
Masaki Ota | 3db5b9f | 2015-03-27 20:57:52 -0700 | [diff] [blame] | 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 | */ |
| 41 | enum SS4_PACKET_ID { |
| 42 | SS4_PACKET_ID_IDLE = 0, |
| 43 | SS4_PACKET_ID_ONE, |
| 44 | SS4_PACKET_ID_TWO, |
| 45 | SS4_PACKET_ID_MULTI, |
| 46 | }; |
| 47 | |
| 48 | #define SS4_COUNT_PER_ELECTRODE 256 |
| 49 | #define SS4_NUMSENSOR_XOFFSET 7 |
| 50 | #define SS4_NUMSENSOR_YOFFSET 7 |
| 51 | #define SS4_MIN_PITCH_MM 50 |
| 52 | |
| 53 | #define SS4_MASK_NORMAL_BUTTONS 0x07 |
| 54 | |
| 55 | #define SS4_1F_X_V2(_b) ((_b[0] & 0x0007) | \ |
| 56 | ((_b[1] << 3) & 0x0078) | \ |
| 57 | ((_b[1] << 2) & 0x0380) | \ |
| 58 | ((_b[2] << 5) & 0x1C00) \ |
| 59 | ) |
| 60 | |
| 61 | #define SS4_1F_Y_V2(_b) (((_b[2]) & 0x000F) | \ |
| 62 | ((_b[3] >> 2) & 0x0030) | \ |
| 63 | ((_b[4] << 6) & 0x03C0) | \ |
| 64 | ((_b[4] << 5) & 0x0C00) \ |
| 65 | ) |
| 66 | |
| 67 | #define SS4_1F_Z_V2(_b) (((_b[5]) & 0x0F) | \ |
| 68 | ((_b[5] >> 1) & 0x70) | \ |
| 69 | ((_b[4]) & 0x80) \ |
| 70 | ) |
| 71 | |
| 72 | #define SS4_1F_LFB_V2(_b) (((_b[2] >> 4) & 0x01) == 0x01) |
| 73 | |
| 74 | #define SS4_MF_LF_V2(_b, _i) ((_b[1 + (_i) * 3] & 0x0004) == 0x0004) |
| 75 | |
| 76 | #define SS4_BTN_V2(_b) ((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS) |
| 77 | |
| 78 | #define SS4_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 5) & 0x00E0) | \ |
| 79 | ((_b[1 + _i * 3] << 5) & 0x1F00) \ |
| 80 | ) |
| 81 | |
| 82 | #define SS4_STD_MF_Y_V2(_b, _i) (((_b[1 + (_i) * 3] << 3) & 0x0010) | \ |
| 83 | ((_b[2 + (_i) * 3] << 5) & 0x01E0) | \ |
| 84 | ((_b[2 + (_i) * 3] << 4) & 0x0E00) \ |
| 85 | ) |
| 86 | |
| 87 | #define SS4_BTL_MF_X_V2(_b, _i) (SS4_STD_MF_X_V2(_b, _i) | \ |
| 88 | ((_b[0 + (_i) * 3] >> 3) & 0x0010) \ |
| 89 | ) |
| 90 | |
| 91 | #define SS4_BTL_MF_Y_V2(_b, _i) (SS4_STD_MF_Y_V2(_b, _i) | \ |
| 92 | ((_b[0 + (_i) * 3] >> 3) & 0x0008) \ |
| 93 | ) |
| 94 | |
| 95 | #define SS4_MF_Z_V2(_b, _i) (((_b[1 + (_i) * 3]) & 0x0001) | \ |
| 96 | ((_b[1 + (_i) * 3] >> 1) & 0x0002) \ |
| 97 | ) |
| 98 | |
| 99 | #define SS4_IS_MF_CONTINUE(_b) ((_b[2] & 0x10) == 0x10) |
| 100 | #define SS4_IS_5F_DETECTED(_b) ((_b[2] & 0x10) == 0x10) |
| 101 | |
| 102 | |
| 103 | #define SS4_MFPACKET_NO_AX 8160 /* X-Coordinate value */ |
| 104 | #define SS4_MFPACKET_NO_AY 4080 /* Y-Coordinate value */ |
| 105 | #define SS4_MFPACKET_NO_AX_BL 8176 /* Buttonless X-Coordinate value */ |
| 106 | #define SS4_MFPACKET_NO_AY_BL 4088 /* Buttonless Y-Coordinate value */ |
| 107 | |
| 108 | /* |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 109 | * enum V7_PACKET_ID - defines the packet type for V7 |
| 110 | * V7_PACKET_ID_IDLE: There's no finger and no button activity. |
| 111 | * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad |
| 112 | * or there's button activities. |
| 113 | * V7_PACKET_ID_MULTI: There are at least three non-resting fingers. |
| 114 | * V7_PACKET_ID_NEW: The finger position in slot is not continues from |
| 115 | * previous packet. |
| 116 | */ |
| 117 | enum V7_PACKET_ID { |
| 118 | V7_PACKET_ID_IDLE, |
| 119 | V7_PACKET_ID_TWO, |
| 120 | V7_PACKET_ID_MULTI, |
| 121 | V7_PACKET_ID_NEW, |
| 122 | V7_PACKET_ID_UNKNOWN, |
| 123 | }; |
| 124 | |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 125 | /** |
Dmitry Torokhov | 8326bb5 | 2015-01-13 21:08:00 -0800 | [diff] [blame] | 126 | * struct alps_protocol_info - information about protocol used by a device |
| 127 | * @version: Indicates V1/V2/V3/... |
| 128 | * @byte0: Helps figure out whether a position report packet matches the |
| 129 | * known format for this model. The first byte of the report, ANDed with |
| 130 | * mask0, should match byte0. |
| 131 | * @mask0: The mask used to check the first byte of the report. |
| 132 | * @flags: Additional device capabilities (passthrough port, trackstick, etc.). |
| 133 | */ |
| 134 | struct alps_protocol_info { |
| 135 | u16 version; |
| 136 | u8 byte0, mask0; |
| 137 | unsigned int flags; |
| 138 | }; |
| 139 | |
| 140 | /** |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 141 | * struct alps_model_info - touchpad ID table |
| 142 | * @signature: E7 response string to match. |
| 143 | * @command_mode_resp: For V3/V4 touchpads, the final byte of the EC response |
| 144 | * (aka command mode response) identifies the firmware minor version. This |
| 145 | * can be used to distinguish different hardware models which are not |
| 146 | * uniquely identifiable through their E7 responses. |
Dmitry Torokhov | 8326bb5 | 2015-01-13 21:08:00 -0800 | [diff] [blame] | 147 | * @protocol_info: information about protcol used by the device. |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 148 | * |
| 149 | * Many (but not all) ALPS touchpads can be identified by looking at the |
| 150 | * values returned in the "E7 report" and/or the "EC report." This table |
| 151 | * lists a number of such touchpads. |
| 152 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct alps_model_info { |
Dmitry Torokhov | d7c13d3 | 2015-01-13 20:53:22 -0800 | [diff] [blame] | 154 | u8 signature[3]; |
| 155 | u8 command_mode_resp; |
Dmitry Torokhov | 8326bb5 | 2015-01-13 21:08:00 -0800 | [diff] [blame] | 156 | struct alps_protocol_info protocol_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 159 | /** |
| 160 | * struct alps_nibble_commands - encodings for register accesses |
| 161 | * @command: PS/2 command used for the nibble |
| 162 | * @data: Data supplied as an argument to the PS/2 command, if applicable |
| 163 | * |
| 164 | * The ALPS protocol uses magic sequences to transmit binary data to the |
| 165 | * touchpad, as it is generally not OK to send arbitrary bytes out the |
| 166 | * PS/2 port. Each of the sequences in this table sends one nibble of the |
| 167 | * register address or (write) data. Different versions of the ALPS protocol |
| 168 | * use slightly different encodings. |
| 169 | */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 170 | struct alps_nibble_commands { |
| 171 | int command; |
| 172 | unsigned char data; |
| 173 | }; |
| 174 | |
Hans de Goede | 036e6c7 | 2014-07-25 22:38:51 -0700 | [diff] [blame] | 175 | struct alps_bitmap_point { |
| 176 | int start_bit; |
| 177 | int num_bits; |
| 178 | }; |
| 179 | |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 180 | /** |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 181 | * struct alps_fields - decoded version of the report packet |
| 182 | * @x_map: Bitmap of active X positions for MT. |
| 183 | * @y_map: Bitmap of active Y positions for MT. |
| 184 | * @fingers: Number of fingers for MT. |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 185 | * @pressure: Pressure. |
| 186 | * @st: position for ST. |
| 187 | * @mt: position for MT. |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 188 | * @first_mp: Packet is the first of a multi-packet report. |
| 189 | * @is_mp: Packet is part of a multi-packet report. |
| 190 | * @left: Left touchpad button is active. |
| 191 | * @right: Right touchpad button is active. |
| 192 | * @middle: Middle touchpad button is active. |
| 193 | * @ts_left: Left trackstick button is active. |
| 194 | * @ts_right: Right trackstick button is active. |
| 195 | * @ts_middle: Middle trackstick button is active. |
| 196 | */ |
| 197 | struct alps_fields { |
| 198 | unsigned int x_map; |
| 199 | unsigned int y_map; |
| 200 | unsigned int fingers; |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 201 | |
| 202 | int pressure; |
| 203 | struct input_mt_pos st; |
| 204 | struct input_mt_pos mt[MAX_TOUCHES]; |
| 205 | |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 206 | unsigned int first_mp:1; |
| 207 | unsigned int is_mp:1; |
| 208 | |
| 209 | unsigned int left:1; |
| 210 | unsigned int right:1; |
| 211 | unsigned int middle:1; |
| 212 | |
| 213 | unsigned int ts_left:1; |
| 214 | unsigned int ts_right:1; |
| 215 | unsigned int ts_middle:1; |
| 216 | }; |
| 217 | |
| 218 | /** |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 219 | * struct alps_data - private data structure for the ALPS driver |
Pali Rohár | 04aae28 | 2015-01-14 13:18:30 -0800 | [diff] [blame] | 220 | * @psmouse: Pointer to parent psmouse device |
| 221 | * @dev2: Trackstick device (can be NULL). |
| 222 | * @dev3: Generic PS/2 mouse (can be NULL, delayed registering). |
| 223 | * @phys2: Physical path for the trackstick device. |
| 224 | * @phys3: Physical path for the generic PS/2 mouse. |
| 225 | * @dev3_register_work: Delayed work for registering PS/2 mouse. |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 226 | * @nibble_commands: Command mapping used for touchpad register accesses. |
| 227 | * @addr_command: Command used to tell the touchpad that a register address |
| 228 | * follows. |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 229 | * @proto_version: Indicates V1/V2/V3/... |
| 230 | * @byte0: Helps figure out whether a position report packet matches the |
| 231 | * known format for this model. The first byte of the report, ANDed with |
| 232 | * mask0, should match byte0. |
| 233 | * @mask0: The mask used to check the first byte of the report. |
Hans de Goede | c0cd17f | 2014-07-25 22:49:14 -0700 | [diff] [blame] | 234 | * @fw_ver: cached copy of firmware version (EC report) |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 235 | * @flags: Additional device capabilities (passthrough port, trackstick, etc.). |
Kevin Cernekee | 7a9f73e | 2013-02-13 22:24:55 -0800 | [diff] [blame] | 236 | * @x_max: Largest possible X position value. |
| 237 | * @y_max: Largest possible Y position value. |
| 238 | * @x_bits: Number of X bits in the MT bitmap. |
| 239 | * @y_bits: Number of Y bits in the MT bitmap. |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 240 | * @hw_init: Protocol-specific hardware init function. |
| 241 | * @process_packet: Protocol-specific function to process a report packet. |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 242 | * @decode_fields: Protocol-specific function to read packet bitfields. |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 243 | * @set_abs_params: Protocol-specific function to configure the input_dev. |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 244 | * @prev_fin: Finger bit from previous packet. |
| 245 | * @multi_packet: Multi-packet data in progress. |
| 246 | * @multi_data: Saved multi-packet data. |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 247 | * @f: Decoded packet data fields. |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 248 | * @quirks: Bitmap of ALPS_QUIRK_*. |
| 249 | * @timer: Timer for flushing out the final report packet in the stream. |
| 250 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | struct alps_data { |
Pali Rohár | 04aae28 | 2015-01-14 13:18:30 -0800 | [diff] [blame] | 252 | struct psmouse *psmouse; |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 253 | struct input_dev *dev2; |
Pali Rohár | 04aae28 | 2015-01-14 13:18:30 -0800 | [diff] [blame] | 254 | struct input_dev *dev3; |
| 255 | char phys2[32]; |
| 256 | char phys3[32]; |
| 257 | struct delayed_work dev3_register_work; |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 258 | |
| 259 | /* these are autodetected when the device is identified */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 260 | const struct alps_nibble_commands *nibble_commands; |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 261 | int addr_command; |
Dmitry Torokhov | d7c13d3 | 2015-01-13 20:53:22 -0800 | [diff] [blame] | 262 | u16 proto_version; |
| 263 | u8 byte0, mask0; |
| 264 | u8 fw_ver[3]; |
Hans de Goede | 40e8f53 | 2014-07-25 22:37:15 -0700 | [diff] [blame] | 265 | int flags; |
Kevin Cernekee | 7a9f73e | 2013-02-13 22:24:55 -0800 | [diff] [blame] | 266 | int x_max; |
| 267 | int y_max; |
| 268 | int x_bits; |
| 269 | int y_bits; |
Hans de Goede | f3f33c6 | 2014-07-29 11:22:07 -0700 | [diff] [blame] | 270 | unsigned int x_res; |
| 271 | unsigned int y_res; |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 272 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 273 | int (*hw_init)(struct psmouse *psmouse); |
| 274 | void (*process_packet)(struct psmouse *psmouse); |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 275 | int (*decode_fields)(struct alps_fields *f, unsigned char *p, |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 276 | struct psmouse *psmouse); |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 277 | void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1); |
| 278 | |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 279 | int prev_fin; |
| 280 | int multi_packet; |
Hans de Goede | 4dd2657 | 2015-05-20 14:41:10 -0700 | [diff] [blame] | 281 | int second_touch; |
Kevin Cernekee | 88a8034 | 2013-02-13 20:55:19 -0800 | [diff] [blame] | 282 | unsigned char multi_data[6]; |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 283 | struct alps_fields f; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 284 | u8 quirks; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 285 | struct timer_list timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 288 | #define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */ |
| 289 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 290 | #ifdef CONFIG_MOUSE_PS2_ALPS |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 291 | int alps_detect(struct psmouse *psmouse, bool set_properties); |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 292 | int alps_init(struct psmouse *psmouse); |
| 293 | #else |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 294 | inline int alps_detect(struct psmouse *psmouse, bool set_properties) |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 295 | { |
| 296 | return -ENOSYS; |
| 297 | } |
| 298 | inline int alps_init(struct psmouse *psmouse) |
| 299 | { |
| 300 | return -ENOSYS; |
| 301 | } |
| 302 | #endif /* CONFIG_MOUSE_PS2_ALPS */ |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | #endif |