18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Elantech Touchpad driver (v6) 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2007-2009 Arjan Opmeer <arjan@opmeer.net> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Trademarks are the property of their respective owners. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _ELANTECH_H 118c2ecf20Sopenharmony_ci#define _ELANTECH_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* 148c2ecf20Sopenharmony_ci * Command values for Synaptics style queries 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci#define ETP_FW_ID_QUERY 0x00 178c2ecf20Sopenharmony_ci#define ETP_FW_VERSION_QUERY 0x01 188c2ecf20Sopenharmony_ci#define ETP_CAPABILITIES_QUERY 0x02 198c2ecf20Sopenharmony_ci#define ETP_SAMPLE_QUERY 0x03 208c2ecf20Sopenharmony_ci#define ETP_RESOLUTION_QUERY 0x04 218c2ecf20Sopenharmony_ci#define ETP_ICBODY_QUERY 0x05 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/* 248c2ecf20Sopenharmony_ci * Command values for register reading or writing 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci#define ETP_REGISTER_READ 0x10 278c2ecf20Sopenharmony_ci#define ETP_REGISTER_WRITE 0x11 288c2ecf20Sopenharmony_ci#define ETP_REGISTER_READWRITE 0x00 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Hardware version 2 custom PS/2 command value 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci#define ETP_PS2_CUSTOM_COMMAND 0xf8 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * Times to retry a ps2_command and millisecond delay between tries 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci#define ETP_PS2_COMMAND_TRIES 3 398c2ecf20Sopenharmony_ci#define ETP_PS2_COMMAND_DELAY 500 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * Times to try to read back a register and millisecond delay between tries 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ci#define ETP_READ_BACK_TRIES 5 458c2ecf20Sopenharmony_ci#define ETP_READ_BACK_DELAY 2000 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* 488c2ecf20Sopenharmony_ci * Register bitmasks for hardware version 1 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_ci#define ETP_R10_ABSOLUTE_MODE 0x04 518c2ecf20Sopenharmony_ci#define ETP_R11_4_BYTE_MODE 0x02 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* 548c2ecf20Sopenharmony_ci * Capability bitmasks 558c2ecf20Sopenharmony_ci */ 568c2ecf20Sopenharmony_ci#define ETP_CAP_HAS_ROCKER 0x04 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * One hard to find application note states that X axis range is 0 to 576 608c2ecf20Sopenharmony_ci * and Y axis range is 0 to 384 for harware version 1. 618c2ecf20Sopenharmony_ci * Edge fuzz might be necessary because of bezel around the touchpad 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_ci#define ETP_EDGE_FUZZ_V1 32 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define ETP_XMIN_V1 ( 0 + ETP_EDGE_FUZZ_V1) 668c2ecf20Sopenharmony_ci#define ETP_XMAX_V1 (576 - ETP_EDGE_FUZZ_V1) 678c2ecf20Sopenharmony_ci#define ETP_YMIN_V1 ( 0 + ETP_EDGE_FUZZ_V1) 688c2ecf20Sopenharmony_ci#define ETP_YMAX_V1 (384 - ETP_EDGE_FUZZ_V1) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* 718c2ecf20Sopenharmony_ci * The resolution for older v2 hardware doubled. 728c2ecf20Sopenharmony_ci * (newer v2's firmware provides command so we can query) 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci#define ETP_XMIN_V2 0 758c2ecf20Sopenharmony_ci#define ETP_XMAX_V2 1152 768c2ecf20Sopenharmony_ci#define ETP_YMIN_V2 0 778c2ecf20Sopenharmony_ci#define ETP_YMAX_V2 768 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define ETP_PMIN_V2 0 808c2ecf20Sopenharmony_ci#define ETP_PMAX_V2 255 818c2ecf20Sopenharmony_ci#define ETP_WMIN_V2 0 828c2ecf20Sopenharmony_ci#define ETP_WMAX_V2 15 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* 858c2ecf20Sopenharmony_ci * v3 hardware has 2 kinds of packet types, 868c2ecf20Sopenharmony_ci * v4 hardware has 3. 878c2ecf20Sopenharmony_ci */ 888c2ecf20Sopenharmony_ci#define PACKET_UNKNOWN 0x01 898c2ecf20Sopenharmony_ci#define PACKET_DEBOUNCE 0x02 908c2ecf20Sopenharmony_ci#define PACKET_V3_HEAD 0x03 918c2ecf20Sopenharmony_ci#define PACKET_V3_TAIL 0x04 928c2ecf20Sopenharmony_ci#define PACKET_V4_HEAD 0x05 938c2ecf20Sopenharmony_ci#define PACKET_V4_MOTION 0x06 948c2ecf20Sopenharmony_ci#define PACKET_V4_STATUS 0x07 958c2ecf20Sopenharmony_ci#define PACKET_TRACKPOINT 0x08 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* 988c2ecf20Sopenharmony_ci * track up to 5 fingers for v4 hardware 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ci#define ETP_MAX_FINGERS 5 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* 1038c2ecf20Sopenharmony_ci * weight value for v4 hardware 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_ci#define ETP_WEIGHT_VALUE 5 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* 1088c2ecf20Sopenharmony_ci * Bus information on 3rd byte of query ETP_RESOLUTION_QUERY(0x04) 1098c2ecf20Sopenharmony_ci */ 1108c2ecf20Sopenharmony_ci#define ETP_BUS_PS2_ONLY 0 1118c2ecf20Sopenharmony_ci#define ETP_BUS_SMB_ALERT_ONLY 1 1128c2ecf20Sopenharmony_ci#define ETP_BUS_SMB_HST_NTFY_ONLY 2 1138c2ecf20Sopenharmony_ci#define ETP_BUS_PS2_SMB_ALERT 3 1148c2ecf20Sopenharmony_ci#define ETP_BUS_PS2_SMB_HST_NTFY 4 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci/* 1178c2ecf20Sopenharmony_ci * New ICs are either using SMBus Host Notify or just plain PS2. 1188c2ecf20Sopenharmony_ci * 1198c2ecf20Sopenharmony_ci * ETP_FW_VERSION_QUERY is: 1208c2ecf20Sopenharmony_ci * Byte 1: 1218c2ecf20Sopenharmony_ci * - bit 0..3: IC BODY 1228c2ecf20Sopenharmony_ci * Byte 2: 1238c2ecf20Sopenharmony_ci * - bit 4: HiddenButton 1248c2ecf20Sopenharmony_ci * - bit 5: PS2_SMBUS_NOTIFY 1258c2ecf20Sopenharmony_ci * - bit 6: PS2CRCCheck 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_ci#define ETP_NEW_IC_SMBUS_HOST_NOTIFY(fw_version) \ 1288c2ecf20Sopenharmony_ci ((((fw_version) & 0x0f2000) == 0x0f2000) && \ 1298c2ecf20Sopenharmony_ci ((fw_version) & 0x0000ff) > 0) 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* 1328c2ecf20Sopenharmony_ci * The base position for one finger, v4 hardware 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistruct finger_pos { 1358c2ecf20Sopenharmony_ci unsigned int x; 1368c2ecf20Sopenharmony_ci unsigned int y; 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistruct elantech_device_info { 1408c2ecf20Sopenharmony_ci unsigned char capabilities[3]; 1418c2ecf20Sopenharmony_ci unsigned char samples[3]; 1428c2ecf20Sopenharmony_ci unsigned char debug; 1438c2ecf20Sopenharmony_ci unsigned char hw_version; 1448c2ecf20Sopenharmony_ci unsigned char pattern; 1458c2ecf20Sopenharmony_ci unsigned int fw_version; 1468c2ecf20Sopenharmony_ci unsigned int ic_version; 1478c2ecf20Sopenharmony_ci unsigned int product_id; 1488c2ecf20Sopenharmony_ci unsigned int x_min; 1498c2ecf20Sopenharmony_ci unsigned int y_min; 1508c2ecf20Sopenharmony_ci unsigned int x_max; 1518c2ecf20Sopenharmony_ci unsigned int y_max; 1528c2ecf20Sopenharmony_ci unsigned int x_res; 1538c2ecf20Sopenharmony_ci unsigned int y_res; 1548c2ecf20Sopenharmony_ci unsigned int x_traces; 1558c2ecf20Sopenharmony_ci unsigned int y_traces; 1568c2ecf20Sopenharmony_ci unsigned int width; 1578c2ecf20Sopenharmony_ci unsigned int bus; 1588c2ecf20Sopenharmony_ci bool paritycheck; 1598c2ecf20Sopenharmony_ci bool jumpy_cursor; 1608c2ecf20Sopenharmony_ci bool reports_pressure; 1618c2ecf20Sopenharmony_ci bool crc_enabled; 1628c2ecf20Sopenharmony_ci bool set_hw_resolution; 1638c2ecf20Sopenharmony_ci bool has_trackpoint; 1648c2ecf20Sopenharmony_ci bool has_middle_button; 1658c2ecf20Sopenharmony_ci int (*send_cmd)(struct psmouse *psmouse, unsigned char c, 1668c2ecf20Sopenharmony_ci unsigned char *param); 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistruct elantech_data { 1708c2ecf20Sopenharmony_ci struct input_dev *tp_dev; /* Relative device for trackpoint */ 1718c2ecf20Sopenharmony_ci char tp_phys[32]; 1728c2ecf20Sopenharmony_ci unsigned char reg_07; 1738c2ecf20Sopenharmony_ci unsigned char reg_10; 1748c2ecf20Sopenharmony_ci unsigned char reg_11; 1758c2ecf20Sopenharmony_ci unsigned char reg_20; 1768c2ecf20Sopenharmony_ci unsigned char reg_21; 1778c2ecf20Sopenharmony_ci unsigned char reg_22; 1788c2ecf20Sopenharmony_ci unsigned char reg_23; 1798c2ecf20Sopenharmony_ci unsigned char reg_24; 1808c2ecf20Sopenharmony_ci unsigned char reg_25; 1818c2ecf20Sopenharmony_ci unsigned char reg_26; 1828c2ecf20Sopenharmony_ci unsigned int single_finger_reports; 1838c2ecf20Sopenharmony_ci unsigned int y_max; 1848c2ecf20Sopenharmony_ci unsigned int width; 1858c2ecf20Sopenharmony_ci struct finger_pos mt[ETP_MAX_FINGERS]; 1868c2ecf20Sopenharmony_ci unsigned char parity[256]; 1878c2ecf20Sopenharmony_ci struct elantech_device_info info; 1888c2ecf20Sopenharmony_ci void (*original_set_rate)(struct psmouse *psmouse, unsigned int rate); 1898c2ecf20Sopenharmony_ci}; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ciint elantech_detect(struct psmouse *psmouse, bool set_properties); 1928c2ecf20Sopenharmony_ciint elantech_init_ps2(struct psmouse *psmouse); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#ifdef CONFIG_MOUSE_PS2_ELANTECH 1958c2ecf20Sopenharmony_ciint elantech_init(struct psmouse *psmouse); 1968c2ecf20Sopenharmony_ci#else 1978c2ecf20Sopenharmony_cistatic inline int elantech_init(struct psmouse *psmouse) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci return -ENOSYS; 2008c2ecf20Sopenharmony_ci} 2018c2ecf20Sopenharmony_ci#endif /* CONFIG_MOUSE_PS2_ELANTECH */ 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ciint elantech_init_smbus(struct psmouse *psmouse); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#endif 206