Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 2 | /* |
Arjan Opmeer | 3f8c0df | 2009-04-18 19:05:40 -0700 | [diff] [blame] | 3 | * Elantech Touchpad driver (v6) |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 4 | * |
Arjan Opmeer | 3f8c0df | 2009-04-18 19:05:40 -0700 | [diff] [blame] | 5 | * Copyright (C) 2007-2009 Arjan Opmeer <arjan@opmeer.net> |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 6 | * |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 7 | * Trademarks are the property of their respective owners. |
| 8 | */ |
| 9 | |
| 10 | #ifndef _ELANTECH_H |
| 11 | #define _ELANTECH_H |
| 12 | |
| 13 | /* |
| 14 | * Command values for Synaptics style queries |
| 15 | */ |
JJ Ding | 28f4961 | 2011-09-09 10:30:31 -0700 | [diff] [blame] | 16 | #define ETP_FW_ID_QUERY 0x00 |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 17 | #define ETP_FW_VERSION_QUERY 0x01 |
| 18 | #define ETP_CAPABILITIES_QUERY 0x02 |
JJ Ding | 84a90b6 | 2011-09-20 22:42:51 -0700 | [diff] [blame] | 19 | #define ETP_SAMPLE_QUERY 0x03 |
JJ Ding | 3d95fd6 | 2011-11-20 22:26:56 -0800 | [diff] [blame] | 20 | #define ETP_RESOLUTION_QUERY 0x04 |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * Command values for register reading or writing |
| 24 | */ |
| 25 | #define ETP_REGISTER_READ 0x10 |
| 26 | #define ETP_REGISTER_WRITE 0x11 |
JJ Ding | 28f4961 | 2011-09-09 10:30:31 -0700 | [diff] [blame] | 27 | #define ETP_REGISTER_READWRITE 0x00 |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Hardware version 2 custom PS/2 command value |
| 31 | */ |
| 32 | #define ETP_PS2_CUSTOM_COMMAND 0xf8 |
| 33 | |
| 34 | /* |
| 35 | * Times to retry a ps2_command and millisecond delay between tries |
| 36 | */ |
| 37 | #define ETP_PS2_COMMAND_TRIES 3 |
| 38 | #define ETP_PS2_COMMAND_DELAY 500 |
| 39 | |
| 40 | /* |
| 41 | * Times to try to read back a register and millisecond delay between tries |
| 42 | */ |
| 43 | #define ETP_READ_BACK_TRIES 5 |
| 44 | #define ETP_READ_BACK_DELAY 2000 |
| 45 | |
| 46 | /* |
| 47 | * Register bitmasks for hardware version 1 |
| 48 | */ |
| 49 | #define ETP_R10_ABSOLUTE_MODE 0x04 |
| 50 | #define ETP_R11_4_BYTE_MODE 0x02 |
| 51 | |
| 52 | /* |
| 53 | * Capability bitmasks |
| 54 | */ |
| 55 | #define ETP_CAP_HAS_ROCKER 0x04 |
| 56 | |
| 57 | /* |
| 58 | * One hard to find application note states that X axis range is 0 to 576 |
| 59 | * and Y axis range is 0 to 384 for harware version 1. |
| 60 | * Edge fuzz might be necessary because of bezel around the touchpad |
| 61 | */ |
| 62 | #define ETP_EDGE_FUZZ_V1 32 |
| 63 | |
| 64 | #define ETP_XMIN_V1 ( 0 + ETP_EDGE_FUZZ_V1) |
| 65 | #define ETP_XMAX_V1 (576 - ETP_EDGE_FUZZ_V1) |
| 66 | #define ETP_YMIN_V1 ( 0 + ETP_EDGE_FUZZ_V1) |
| 67 | #define ETP_YMAX_V1 (384 - ETP_EDGE_FUZZ_V1) |
| 68 | |
| 69 | /* |
JJ Ding | 8a360d0 | 2011-09-09 10:27:42 -0700 | [diff] [blame] | 70 | * The resolution for older v2 hardware doubled. |
| 71 | * (newer v2's firmware provides command so we can query) |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 72 | */ |
JJ Ding | 8a360d0 | 2011-09-09 10:27:42 -0700 | [diff] [blame] | 73 | #define ETP_XMIN_V2 0 |
| 74 | #define ETP_XMAX_V2 1152 |
| 75 | #define ETP_YMIN_V2 0 |
| 76 | #define ETP_YMAX_V2 768 |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 77 | |
Éric Piel | f941c70 | 2011-05-16 22:45:54 -0700 | [diff] [blame] | 78 | #define ETP_PMIN_V2 0 |
| 79 | #define ETP_PMAX_V2 255 |
| 80 | #define ETP_WMIN_V2 0 |
| 81 | #define ETP_WMAX_V2 15 |
| 82 | |
JJ Ding | 28f4961 | 2011-09-09 10:30:31 -0700 | [diff] [blame] | 83 | /* |
JJ Ding | 1dc6ede | 2011-09-09 10:31:58 -0700 | [diff] [blame] | 84 | * v3 hardware has 2 kinds of packet types, |
| 85 | * v4 hardware has 3. |
JJ Ding | 28f4961 | 2011-09-09 10:30:31 -0700 | [diff] [blame] | 86 | */ |
| 87 | #define PACKET_UNKNOWN 0x01 |
| 88 | #define PACKET_DEBOUNCE 0x02 |
| 89 | #define PACKET_V3_HEAD 0x03 |
| 90 | #define PACKET_V3_TAIL 0x04 |
JJ Ding | 1dc6ede | 2011-09-09 10:31:58 -0700 | [diff] [blame] | 91 | #define PACKET_V4_HEAD 0x05 |
| 92 | #define PACKET_V4_MOTION 0x06 |
| 93 | #define PACKET_V4_STATUS 0x07 |
Ulrik De Bie | a2418fc | 2014-08-22 17:06:00 -0700 | [diff] [blame] | 94 | #define PACKET_TRACKPOINT 0x08 |
JJ Ding | 1dc6ede | 2011-09-09 10:31:58 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * track up to 5 fingers for v4 hardware |
| 98 | */ |
| 99 | #define ETP_MAX_FINGERS 5 |
| 100 | |
| 101 | /* |
| 102 | * weight value for v4 hardware |
| 103 | */ |
| 104 | #define ETP_WEIGHT_VALUE 5 |
| 105 | |
| 106 | /* |
Benjamin Tissoires | 21c48db | 2018-05-22 17:28:23 -0700 | [diff] [blame] | 107 | * Bus information on 3rd byte of query ETP_RESOLUTION_QUERY(0x04) |
| 108 | */ |
| 109 | #define ETP_BUS_PS2_ONLY 0 |
| 110 | #define ETP_BUS_SMB_ALERT_ONLY 1 |
| 111 | #define ETP_BUS_SMB_HST_NTFY_ONLY 2 |
| 112 | #define ETP_BUS_PS2_SMB_ALERT 3 |
| 113 | #define ETP_BUS_PS2_SMB_HST_NTFY 4 |
| 114 | |
| 115 | /* |
Benjamin Tissoires | df07723 | 2018-05-22 17:30:07 -0700 | [diff] [blame] | 116 | * New ICs are either using SMBus Host Notify or just plain PS2. |
| 117 | * |
| 118 | * ETP_FW_VERSION_QUERY is: |
| 119 | * Byte 1: |
| 120 | * - bit 0..3: IC BODY |
| 121 | * Byte 2: |
| 122 | * - bit 4: HiddenButton |
| 123 | * - bit 5: PS2_SMBUS_NOTIFY |
| 124 | * - bit 6: PS2CRCCheck |
| 125 | */ |
| 126 | #define ETP_NEW_IC_SMBUS_HOST_NOTIFY(fw_version) \ |
| 127 | ((((fw_version) & 0x0f2000) == 0x0f2000) && \ |
| 128 | ((fw_version) & 0x0000ff) > 0) |
| 129 | |
| 130 | /* |
JJ Ding | 1dc6ede | 2011-09-09 10:31:58 -0700 | [diff] [blame] | 131 | * The base position for one finger, v4 hardware |
| 132 | */ |
| 133 | struct finger_pos { |
| 134 | unsigned int x; |
| 135 | unsigned int y; |
| 136 | }; |
JJ Ding | 28f4961 | 2011-09-09 10:30:31 -0700 | [diff] [blame] | 137 | |
Benjamin Tissoires | f078759 | 2018-05-22 17:26:24 -0700 | [diff] [blame] | 138 | struct elantech_device_info { |
| 139 | unsigned char capabilities[3]; |
| 140 | unsigned char samples[3]; |
| 141 | unsigned char debug; |
| 142 | unsigned char hw_version; |
| 143 | unsigned int fw_version; |
Benjamin Tissoires | 3754865 | 2019-05-27 18:24:28 -0700 | [diff] [blame] | 144 | unsigned int x_min; |
| 145 | unsigned int y_min; |
| 146 | unsigned int x_max; |
| 147 | unsigned int y_max; |
Benjamin Tissoires | 80212ed | 2018-05-22 17:27:43 -0700 | [diff] [blame] | 148 | unsigned int x_res; |
| 149 | unsigned int y_res; |
Benjamin Tissoires | 3abcc53 | 2019-05-27 18:43:49 -0700 | [diff] [blame] | 150 | unsigned int x_traces; |
| 151 | unsigned int y_traces; |
Benjamin Tissoires | 3754865 | 2019-05-27 18:24:28 -0700 | [diff] [blame] | 152 | unsigned int width; |
Benjamin Tissoires | 21c48db | 2018-05-22 17:28:23 -0700 | [diff] [blame] | 153 | unsigned int bus; |
Benjamin Tissoires | f078759 | 2018-05-22 17:26:24 -0700 | [diff] [blame] | 154 | bool paritycheck; |
| 155 | bool jumpy_cursor; |
| 156 | bool reports_pressure; |
| 157 | bool crc_enabled; |
| 158 | bool set_hw_resolution; |
| 159 | bool has_trackpoint; |
Benjamin Tissoires | fd1cf11 | 2019-05-27 18:33:33 -0700 | [diff] [blame] | 160 | bool has_middle_button; |
Benjamin Tissoires | f078759 | 2018-05-22 17:26:24 -0700 | [diff] [blame] | 161 | int (*send_cmd)(struct psmouse *psmouse, unsigned char c, |
| 162 | unsigned char *param); |
| 163 | }; |
| 164 | |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 165 | struct elantech_data { |
Ulrik De Bie | a2418fc | 2014-08-22 17:06:00 -0700 | [diff] [blame] | 166 | struct input_dev *tp_dev; /* Relative device for trackpoint */ |
| 167 | char tp_phys[32]; |
JJ Ding | 1dc6ede | 2011-09-09 10:31:58 -0700 | [diff] [blame] | 168 | unsigned char reg_07; |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 169 | unsigned char reg_10; |
| 170 | unsigned char reg_11; |
| 171 | unsigned char reg_20; |
| 172 | unsigned char reg_21; |
| 173 | unsigned char reg_22; |
| 174 | unsigned char reg_23; |
| 175 | unsigned char reg_24; |
| 176 | unsigned char reg_25; |
| 177 | unsigned char reg_26; |
Éric Piel | 7f29f17 | 2010-08-05 23:51:49 -0700 | [diff] [blame] | 178 | unsigned int single_finger_reports; |
JJ Ding | 230282a | 2011-09-09 10:26:16 -0700 | [diff] [blame] | 179 | unsigned int y_max; |
JJ Ding | 1dc6ede | 2011-09-09 10:31:58 -0700 | [diff] [blame] | 180 | unsigned int width; |
| 181 | struct finger_pos mt[ETP_MAX_FINGERS]; |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 182 | unsigned char parity[256]; |
Benjamin Tissoires | f078759 | 2018-05-22 17:26:24 -0700 | [diff] [blame] | 183 | struct elantech_device_info info; |
Ulrik De Bie | bd88414 | 2015-04-06 15:35:38 -0700 | [diff] [blame] | 184 | void (*original_set_rate)(struct psmouse *psmouse, unsigned int rate); |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 185 | }; |
| 186 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 187 | int elantech_detect(struct psmouse *psmouse, bool set_properties); |
Benjamin Tissoires | 21c48db | 2018-05-22 17:28:23 -0700 | [diff] [blame] | 188 | int elantech_init_ps2(struct psmouse *psmouse); |
Hui Wang | cfd8579 | 2019-08-20 12:07:01 -0700 | [diff] [blame] | 189 | |
| 190 | #ifdef CONFIG_MOUSE_PS2_ELANTECH |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 191 | int elantech_init(struct psmouse *psmouse); |
| 192 | #else |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 193 | static inline int elantech_init(struct psmouse *psmouse) |
| 194 | { |
| 195 | return -ENOSYS; |
| 196 | } |
| 197 | #endif /* CONFIG_MOUSE_PS2_ELANTECH */ |
| 198 | |
Benjamin Tissoires | 21c48db | 2018-05-22 17:28:23 -0700 | [diff] [blame] | 199 | int elantech_init_smbus(struct psmouse *psmouse); |
Benjamin Tissoires | 21c48db | 2018-05-22 17:28:23 -0700 | [diff] [blame] | 200 | |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 201 | #endif |