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