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 15*02d04254SHans de Goede #include <linux/input/mt.h> 16*02d04254SHans de Goede 17b5d6b851SKevin Cernekee #define ALPS_PROTO_V1 1 18b5d6b851SKevin Cernekee #define ALPS_PROTO_V2 2 19b5d6b851SKevin Cernekee #define ALPS_PROTO_V3 3 20b5d6b851SKevin Cernekee #define ALPS_PROTO_V4 4 2175af9e56SDave Turvene #define ALPS_PROTO_V5 5 2295f75e91SYunkang Tang #define ALPS_PROTO_V6 6 23fa629ef5SSeth Forshee 24*02d04254SHans de Goede #define MAX_TOUCHES 2 25*02d04254SHans de Goede 26ee65d4b3SYunkang Tang #define DOLPHIN_COUNT_PER_ELECTRODE 64 27ee65d4b3SYunkang Tang #define DOLPHIN_PROFILE_XOFFSET 8 /* x-electrode offset */ 28ee65d4b3SYunkang Tang #define DOLPHIN_PROFILE_YOFFSET 1 /* y-electrode offset */ 29ee65d4b3SYunkang Tang 3088a80348SKevin Cernekee /** 3188a80348SKevin Cernekee * struct alps_model_info - touchpad ID table 3288a80348SKevin Cernekee * @signature: E7 response string to match. 3388a80348SKevin Cernekee * @command_mode_resp: For V3/V4 touchpads, the final byte of the EC response 3488a80348SKevin Cernekee * (aka command mode response) identifies the firmware minor version. This 3588a80348SKevin Cernekee * can be used to distinguish different hardware models which are not 3688a80348SKevin Cernekee * uniquely identifiable through their E7 responses. 3788a80348SKevin Cernekee * @proto_version: Indicates V1/V2/V3/... 3888a80348SKevin Cernekee * @byte0: Helps figure out whether a position report packet matches the 3988a80348SKevin Cernekee * known format for this model. The first byte of the report, ANDed with 4088a80348SKevin Cernekee * mask0, should match byte0. 4188a80348SKevin Cernekee * @mask0: The mask used to check the first byte of the report. 4288a80348SKevin Cernekee * @flags: Additional device capabilities (passthrough port, trackstick, etc.). 4388a80348SKevin Cernekee * 4488a80348SKevin Cernekee * Many (but not all) ALPS touchpads can be identified by looking at the 4588a80348SKevin Cernekee * values returned in the "E7 report" and/or the "EC report." This table 4688a80348SKevin Cernekee * lists a number of such touchpads. 4788a80348SKevin Cernekee */ 481da177e4SLinus Torvalds struct alps_model_info { 491da177e4SLinus Torvalds unsigned char signature[3]; 5088a80348SKevin Cernekee unsigned char command_mode_resp; 51fa629ef5SSeth Forshee unsigned char proto_version; 521da177e4SLinus Torvalds unsigned char byte0, mask0; 5340e8f53bSHans de Goede int flags; 541da177e4SLinus Torvalds }; 551da177e4SLinus Torvalds 5688a80348SKevin Cernekee /** 5788a80348SKevin Cernekee * struct alps_nibble_commands - encodings for register accesses 5888a80348SKevin Cernekee * @command: PS/2 command used for the nibble 5988a80348SKevin Cernekee * @data: Data supplied as an argument to the PS/2 command, if applicable 6088a80348SKevin Cernekee * 6188a80348SKevin Cernekee * The ALPS protocol uses magic sequences to transmit binary data to the 6288a80348SKevin Cernekee * touchpad, as it is generally not OK to send arbitrary bytes out the 6388a80348SKevin Cernekee * PS/2 port. Each of the sequences in this table sends one nibble of the 6488a80348SKevin Cernekee * register address or (write) data. Different versions of the ALPS protocol 6588a80348SKevin Cernekee * use slightly different encodings. 6688a80348SKevin Cernekee */ 6725bded7cSSeth Forshee struct alps_nibble_commands { 6825bded7cSSeth Forshee int command; 6925bded7cSSeth Forshee unsigned char data; 7025bded7cSSeth Forshee }; 7125bded7cSSeth Forshee 72036e6c7bSHans de Goede struct alps_bitmap_point { 73036e6c7bSHans de Goede int start_bit; 74036e6c7bSHans de Goede int num_bits; 75036e6c7bSHans de Goede }; 76036e6c7bSHans de Goede 7788a80348SKevin Cernekee /** 78f85e5001SKevin Cernekee * struct alps_fields - decoded version of the report packet 79f85e5001SKevin Cernekee * @x_map: Bitmap of active X positions for MT. 80f85e5001SKevin Cernekee * @y_map: Bitmap of active Y positions for MT. 81f85e5001SKevin Cernekee * @fingers: Number of fingers for MT. 82*02d04254SHans de Goede * @pressure: Pressure. 83*02d04254SHans de Goede * @st: position for ST. 84*02d04254SHans de Goede * @mt: position for MT. 85f85e5001SKevin Cernekee * @first_mp: Packet is the first of a multi-packet report. 86f85e5001SKevin Cernekee * @is_mp: Packet is part of a multi-packet report. 87f85e5001SKevin Cernekee * @left: Left touchpad button is active. 88f85e5001SKevin Cernekee * @right: Right touchpad button is active. 89f85e5001SKevin Cernekee * @middle: Middle touchpad button is active. 90f85e5001SKevin Cernekee * @ts_left: Left trackstick button is active. 91f85e5001SKevin Cernekee * @ts_right: Right trackstick button is active. 92f85e5001SKevin Cernekee * @ts_middle: Middle trackstick button is active. 93f85e5001SKevin Cernekee */ 94f85e5001SKevin Cernekee struct alps_fields { 95f85e5001SKevin Cernekee unsigned int x_map; 96f85e5001SKevin Cernekee unsigned int y_map; 97f85e5001SKevin Cernekee unsigned int fingers; 98*02d04254SHans de Goede 99*02d04254SHans de Goede int pressure; 100*02d04254SHans de Goede struct input_mt_pos st; 101*02d04254SHans de Goede struct input_mt_pos mt[MAX_TOUCHES]; 102*02d04254SHans de Goede 103f85e5001SKevin Cernekee unsigned int first_mp:1; 104f85e5001SKevin Cernekee unsigned int is_mp:1; 105f85e5001SKevin Cernekee 106f85e5001SKevin Cernekee unsigned int left:1; 107f85e5001SKevin Cernekee unsigned int right:1; 108f85e5001SKevin Cernekee unsigned int middle:1; 109f85e5001SKevin Cernekee 110f85e5001SKevin Cernekee unsigned int ts_left:1; 111f85e5001SKevin Cernekee unsigned int ts_right:1; 112f85e5001SKevin Cernekee unsigned int ts_middle:1; 113f85e5001SKevin Cernekee }; 114f85e5001SKevin Cernekee 115f85e5001SKevin Cernekee /** 11688a80348SKevin Cernekee * struct alps_data - private data structure for the ALPS driver 11788a80348SKevin Cernekee * @dev2: "Relative" device used to report trackstick or mouse activity. 11888a80348SKevin Cernekee * @phys: Physical path for the relative device. 11988a80348SKevin Cernekee * @nibble_commands: Command mapping used for touchpad register accesses. 12088a80348SKevin Cernekee * @addr_command: Command used to tell the touchpad that a register address 12188a80348SKevin Cernekee * follows. 12299df65e7SKevin Cernekee * @proto_version: Indicates V1/V2/V3/... 12399df65e7SKevin Cernekee * @byte0: Helps figure out whether a position report packet matches the 12499df65e7SKevin Cernekee * known format for this model. The first byte of the report, ANDed with 12599df65e7SKevin Cernekee * mask0, should match byte0. 12699df65e7SKevin Cernekee * @mask0: The mask used to check the first byte of the report. 12799df65e7SKevin Cernekee * @flags: Additional device capabilities (passthrough port, trackstick, etc.). 1287a9f73e7SKevin Cernekee * @x_max: Largest possible X position value. 1297a9f73e7SKevin Cernekee * @y_max: Largest possible Y position value. 1307a9f73e7SKevin Cernekee * @x_bits: Number of X bits in the MT bitmap. 1317a9f73e7SKevin Cernekee * @y_bits: Number of Y bits in the MT bitmap. 13224af5cb9SKevin Cernekee * @hw_init: Protocol-specific hardware init function. 13324af5cb9SKevin Cernekee * @process_packet: Protocol-specific function to process a report packet. 134f85e5001SKevin Cernekee * @decode_fields: Protocol-specific function to read packet bitfields. 13524af5cb9SKevin Cernekee * @set_abs_params: Protocol-specific function to configure the input_dev. 13688a80348SKevin Cernekee * @prev_fin: Finger bit from previous packet. 13788a80348SKevin Cernekee * @multi_packet: Multi-packet data in progress. 13888a80348SKevin Cernekee * @multi_data: Saved multi-packet data. 139*02d04254SHans de Goede * @f: Decoded packet data fields. 14088a80348SKevin Cernekee * @quirks: Bitmap of ALPS_QUIRK_*. 14188a80348SKevin Cernekee * @timer: Timer for flushing out the final report packet in the stream. 14288a80348SKevin Cernekee */ 1431da177e4SLinus Torvalds struct alps_data { 14488a80348SKevin Cernekee struct input_dev *dev2; 14588a80348SKevin Cernekee char phys[32]; 14699df65e7SKevin Cernekee 14799df65e7SKevin Cernekee /* these are autodetected when the device is identified */ 14825bded7cSSeth Forshee const struct alps_nibble_commands *nibble_commands; 14988a80348SKevin Cernekee int addr_command; 15099df65e7SKevin Cernekee unsigned char proto_version; 15199df65e7SKevin Cernekee unsigned char byte0, mask0; 15240e8f53bSHans de Goede int flags; 1537a9f73e7SKevin Cernekee int x_max; 1547a9f73e7SKevin Cernekee int y_max; 1557a9f73e7SKevin Cernekee int x_bits; 1567a9f73e7SKevin Cernekee int y_bits; 15799df65e7SKevin Cernekee 15824af5cb9SKevin Cernekee int (*hw_init)(struct psmouse *psmouse); 15924af5cb9SKevin Cernekee void (*process_packet)(struct psmouse *psmouse); 160ee65d4b3SYunkang Tang void (*decode_fields)(struct alps_fields *f, unsigned char *p, 161ee65d4b3SYunkang Tang struct psmouse *psmouse); 16224af5cb9SKevin Cernekee void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1); 16324af5cb9SKevin Cernekee 16488a80348SKevin Cernekee int prev_fin; 16588a80348SKevin Cernekee int multi_packet; 16688a80348SKevin Cernekee unsigned char multi_data[6]; 167*02d04254SHans de Goede struct alps_fields f; 16825bded7cSSeth Forshee u8 quirks; 1691d9f2626SSebastian Kapfer struct timer_list timer; 1701da177e4SLinus Torvalds }; 1711da177e4SLinus Torvalds 17225bded7cSSeth Forshee #define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */ 17325bded7cSSeth Forshee 17455e3d922SAndres Salomon #ifdef CONFIG_MOUSE_PS2_ALPS 175b7802c5cSDmitry Torokhov int alps_detect(struct psmouse *psmouse, bool set_properties); 17655e3d922SAndres Salomon int alps_init(struct psmouse *psmouse); 17755e3d922SAndres Salomon #else 178b7802c5cSDmitry Torokhov inline int alps_detect(struct psmouse *psmouse, bool set_properties) 17955e3d922SAndres Salomon { 18055e3d922SAndres Salomon return -ENOSYS; 18155e3d922SAndres Salomon } 18255e3d922SAndres Salomon inline int alps_init(struct psmouse *psmouse) 18355e3d922SAndres Salomon { 18455e3d922SAndres Salomon return -ENOSYS; 18555e3d922SAndres Salomon } 18655e3d922SAndres Salomon #endif /* CONFIG_MOUSE_PS2_ALPS */ 18755e3d922SAndres Salomon 1881da177e4SLinus Torvalds #endif 189