Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Elantech Touchpad driver (v6)
0004  *
0005  * Copyright (C) 2007-2009 Arjan Opmeer <arjan@opmeer.net>
0006  *
0007  * Trademarks are the property of their respective owners.
0008  */
0009 
0010 #ifndef _ELANTECH_H
0011 #define _ELANTECH_H
0012 
0013 /*
0014  * Command values for Synaptics style queries
0015  */
0016 #define ETP_FW_ID_QUERY         0x00
0017 #define ETP_FW_VERSION_QUERY        0x01
0018 #define ETP_CAPABILITIES_QUERY      0x02
0019 #define ETP_SAMPLE_QUERY        0x03
0020 #define ETP_RESOLUTION_QUERY        0x04
0021 #define ETP_ICBODY_QUERY        0x05
0022 
0023 /*
0024  * Command values for register reading or writing
0025  */
0026 #define ETP_REGISTER_READ       0x10
0027 #define ETP_REGISTER_WRITE      0x11
0028 #define ETP_REGISTER_READWRITE      0x00
0029 
0030 /*
0031  * Hardware version 2 custom PS/2 command value
0032  */
0033 #define ETP_PS2_CUSTOM_COMMAND      0xf8
0034 
0035 /*
0036  * Times to retry a ps2_command and millisecond delay between tries
0037  */
0038 #define ETP_PS2_COMMAND_TRIES       3
0039 #define ETP_PS2_COMMAND_DELAY       500
0040 
0041 /*
0042  * Times to try to read back a register and millisecond delay between tries
0043  */
0044 #define ETP_READ_BACK_TRIES     5
0045 #define ETP_READ_BACK_DELAY     2000
0046 
0047 /*
0048  * Register bitmasks for hardware version 1
0049  */
0050 #define ETP_R10_ABSOLUTE_MODE       0x04
0051 #define ETP_R11_4_BYTE_MODE     0x02
0052 
0053 /*
0054  * Capability bitmasks
0055  */
0056 #define ETP_CAP_HAS_ROCKER      0x04
0057 
0058 /*
0059  * One hard to find application note states that X axis range is 0 to 576
0060  * and Y axis range is 0 to 384 for harware version 1.
0061  * Edge fuzz might be necessary because of bezel around the touchpad
0062  */
0063 #define ETP_EDGE_FUZZ_V1        32
0064 
0065 #define ETP_XMIN_V1         (  0 + ETP_EDGE_FUZZ_V1)
0066 #define ETP_XMAX_V1         (576 - ETP_EDGE_FUZZ_V1)
0067 #define ETP_YMIN_V1         (  0 + ETP_EDGE_FUZZ_V1)
0068 #define ETP_YMAX_V1         (384 - ETP_EDGE_FUZZ_V1)
0069 
0070 /*
0071  * The resolution for older v2 hardware doubled.
0072  * (newer v2's firmware provides command so we can query)
0073  */
0074 #define ETP_XMIN_V2         0
0075 #define ETP_XMAX_V2         1152
0076 #define ETP_YMIN_V2         0
0077 #define ETP_YMAX_V2         768
0078 
0079 #define ETP_PMIN_V2         0
0080 #define ETP_PMAX_V2         255
0081 #define ETP_WMIN_V2         0
0082 #define ETP_WMAX_V2         15
0083 
0084 /*
0085  * v3 hardware has 2 kinds of packet types,
0086  * v4 hardware has 3.
0087  */
0088 #define PACKET_UNKNOWN          0x01
0089 #define PACKET_DEBOUNCE         0x02
0090 #define PACKET_V3_HEAD          0x03
0091 #define PACKET_V3_TAIL          0x04
0092 #define PACKET_V4_HEAD          0x05
0093 #define PACKET_V4_MOTION        0x06
0094 #define PACKET_V4_STATUS        0x07
0095 #define PACKET_TRACKPOINT       0x08
0096 
0097 /*
0098  * track up to 5 fingers for v4 hardware
0099  */
0100 #define ETP_MAX_FINGERS         5
0101 
0102 /*
0103  * weight value for v4 hardware
0104  */
0105 #define ETP_WEIGHT_VALUE        5
0106 
0107 /*
0108  * Bus information on 3rd byte of query ETP_RESOLUTION_QUERY(0x04)
0109  */
0110 #define ETP_BUS_PS2_ONLY        0
0111 #define ETP_BUS_SMB_ALERT_ONLY      1
0112 #define ETP_BUS_SMB_HST_NTFY_ONLY   2
0113 #define ETP_BUS_PS2_SMB_ALERT       3
0114 #define ETP_BUS_PS2_SMB_HST_NTFY    4
0115 
0116 /*
0117  * New ICs are either using SMBus Host Notify or just plain PS2.
0118  *
0119  * ETP_FW_VERSION_QUERY is:
0120  * Byte 1:
0121  *  - bit 0..3: IC BODY
0122  * Byte 2:
0123  *  - bit 4: HiddenButton
0124  *  - bit 5: PS2_SMBUS_NOTIFY
0125  *  - bit 6: PS2CRCCheck
0126  */
0127 #define ETP_NEW_IC_SMBUS_HOST_NOTIFY(fw_version)    \
0128         ((((fw_version) & 0x0f2000) == 0x0f2000) && \
0129          ((fw_version) & 0x0000ff) > 0)
0130 
0131 /*
0132  * The base position for one finger, v4 hardware
0133  */
0134 struct finger_pos {
0135     unsigned int x;
0136     unsigned int y;
0137 };
0138 
0139 struct elantech_device_info {
0140     unsigned char capabilities[3];
0141     unsigned char samples[3];
0142     unsigned char debug;
0143     unsigned char hw_version;
0144     unsigned char pattern;
0145     unsigned int fw_version;
0146     unsigned int ic_version;
0147     unsigned int product_id;
0148     unsigned int x_min;
0149     unsigned int y_min;
0150     unsigned int x_max;
0151     unsigned int y_max;
0152     unsigned int x_res;
0153     unsigned int y_res;
0154     unsigned int x_traces;
0155     unsigned int y_traces;
0156     unsigned int width;
0157     unsigned int bus;
0158     bool paritycheck;
0159     bool jumpy_cursor;
0160     bool reports_pressure;
0161     bool crc_enabled;
0162     bool set_hw_resolution;
0163     bool has_trackpoint;
0164     bool has_middle_button;
0165     int (*send_cmd)(struct psmouse *psmouse, unsigned char c,
0166             unsigned char *param);
0167 };
0168 
0169 struct elantech_data {
0170     struct input_dev *tp_dev;   /* Relative device for trackpoint */
0171     char tp_phys[32];
0172     unsigned char reg_07;
0173     unsigned char reg_10;
0174     unsigned char reg_11;
0175     unsigned char reg_20;
0176     unsigned char reg_21;
0177     unsigned char reg_22;
0178     unsigned char reg_23;
0179     unsigned char reg_24;
0180     unsigned char reg_25;
0181     unsigned char reg_26;
0182     unsigned int single_finger_reports;
0183     unsigned int y_max;
0184     unsigned int width;
0185     struct finger_pos mt[ETP_MAX_FINGERS];
0186     unsigned char parity[256];
0187     struct elantech_device_info info;
0188     void (*original_set_rate)(struct psmouse *psmouse, unsigned int rate);
0189 };
0190 
0191 int elantech_detect(struct psmouse *psmouse, bool set_properties);
0192 int elantech_init_ps2(struct psmouse *psmouse);
0193 
0194 #ifdef CONFIG_MOUSE_PS2_ELANTECH
0195 int elantech_init(struct psmouse *psmouse);
0196 #else
0197 static inline int elantech_init(struct psmouse *psmouse)
0198 {
0199     return -ENOSYS;
0200 }
0201 #endif /* CONFIG_MOUSE_PS2_ELANTECH */
0202 
0203 int elantech_init_smbus(struct psmouse *psmouse);
0204 
0205 #endif