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