Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _CYPRESS_PS2_H
0003 #define _CYPRESS_PS2_H
0004 
0005 #include "psmouse.h"
0006 
0007 #define CMD_BITS_MASK 0x03
0008 #define COMPOSIT(x, s) (((x) & CMD_BITS_MASK) << (s))
0009 
0010 #define ENCODE_CMD(aa, bb, cc, dd) \
0011     (COMPOSIT((aa), 6) | COMPOSIT((bb), 4) | COMPOSIT((cc), 2) | COMPOSIT((dd), 0))
0012 #define CYTP_CMD_ABS_NO_PRESSURE_MODE       ENCODE_CMD(0, 1, 0, 0)
0013 #define CYTP_CMD_ABS_WITH_PRESSURE_MODE     ENCODE_CMD(0, 1, 0, 1)
0014 #define CYTP_CMD_SMBUS_MODE                 ENCODE_CMD(0, 1, 1, 0)
0015 #define CYTP_CMD_STANDARD_MODE              ENCODE_CMD(0, 2, 0, 0)  /* not implemented yet. */
0016 #define CYTP_CMD_CYPRESS_REL_MODE           ENCODE_CMD(1, 1, 1, 1)  /* not implemented yet. */
0017 #define CYTP_CMD_READ_CYPRESS_ID            ENCODE_CMD(0, 0, 0, 0)
0018 #define CYTP_CMD_READ_TP_METRICS            ENCODE_CMD(0, 0, 0, 1)
0019 #define CYTP_CMD_SET_HSCROLL_WIDTH(w)       ENCODE_CMD(1, 1, 0, (w))
0020 #define     CYTP_CMD_SET_HSCROLL_MASK       ENCODE_CMD(1, 1, 0, 0)
0021 #define CYTP_CMD_SET_VSCROLL_WIDTH(w)       ENCODE_CMD(1, 2, 0, (w))
0022 #define     CYTP_CMD_SET_VSCROLL_MASK       ENCODE_CMD(1, 2, 0, 0)
0023 #define CYTP_CMD_SET_PALM_GEOMETRY(e)       ENCODE_CMD(1, 2, 1, (e))
0024 #define     CYTP_CMD_PALM_GEMMETRY_MASK     ENCODE_CMD(1, 2, 1, 0)
0025 #define CYTP_CMD_SET_PALM_SENSITIVITY(s)    ENCODE_CMD(1, 2, 2, (s))
0026 #define     CYTP_CMD_PALM_SENSITIVITY_MASK  ENCODE_CMD(1, 2, 2, 0)
0027 #define CYTP_CMD_SET_MOUSE_SENSITIVITY(s)   ENCODE_CMD(1, 3, ((s) >> 2), (s))
0028 #define     CYTP_CMD_MOUSE_SENSITIVITY_MASK ENCODE_CMD(1, 3, 0, 0)
0029 #define CYTP_CMD_REQUEST_BASELINE_STATUS    ENCODE_CMD(2, 0, 0, 1)
0030 #define CYTP_CMD_REQUEST_RECALIBRATION      ENCODE_CMD(2, 0, 0, 3)
0031 
0032 #define DECODE_CMD_AA(x) (((x) >> 6) & CMD_BITS_MASK)
0033 #define DECODE_CMD_BB(x) (((x) >> 4) & CMD_BITS_MASK)
0034 #define DECODE_CMD_CC(x) (((x) >> 2) & CMD_BITS_MASK)
0035 #define DECODE_CMD_DD(x) ((x) & CMD_BITS_MASK)
0036 
0037 /* Cypress trackpad working mode. */
0038 #define CYTP_BIT_ABS_PRESSURE    (1 << 3)
0039 #define CYTP_BIT_ABS_NO_PRESSURE (1 << 2)
0040 #define CYTP_BIT_CYPRESS_REL     (1 << 1)
0041 #define CYTP_BIT_STANDARD_REL    (1 << 0)
0042 #define CYTP_BIT_REL_MASK (CYTP_BIT_CYPRESS_REL | CYTP_BIT_STANDARD_REL)
0043 #define CYTP_BIT_ABS_MASK (CYTP_BIT_ABS_PRESSURE | CYTP_BIT_ABS_NO_PRESSURE)
0044 #define CYTP_BIT_ABS_REL_MASK (CYTP_BIT_ABS_MASK | CYTP_BIT_REL_MASK)
0045 
0046 #define CYTP_BIT_HIGH_RATE       (1 << 4)
0047 /*
0048  * report mode bit is set, firmware working in Remote Mode.
0049  * report mode bit is cleared, firmware working in Stream Mode.
0050  */
0051 #define CYTP_BIT_REPORT_MODE     (1 << 5)
0052 
0053 /* scrolling width values for set HSCROLL and VSCROLL width command. */
0054 #define SCROLL_WIDTH_NARROW 1
0055 #define SCROLL_WIDTH_NORMAL 2
0056 #define SCROLL_WIDTH_WIDE   3
0057 
0058 #define PALM_GEOMETRY_ENABLE  1
0059 #define PALM_GEOMETRY_DISABLE 0
0060 
0061 #define TP_METRICS_MASK  0x80
0062 #define FW_VERSION_MASX    0x7f
0063 #define FW_VER_HIGH_MASK 0x70
0064 #define FW_VER_LOW_MASK  0x0f
0065 
0066 /* Times to retry a ps2_command and millisecond delay between tries. */
0067 #define CYTP_PS2_CMD_TRIES 3
0068 #define CYTP_PS2_CMD_DELAY 500
0069 
0070 /* time out for PS/2 command only in milliseconds. */
0071 #define CYTP_CMD_TIMEOUT  200
0072 #define CYTP_DATA_TIMEOUT 30
0073 
0074 #define CYTP_EXT_CMD   0xe8
0075 #define CYTP_PS2_RETRY 0xfe
0076 #define CYTP_PS2_ERROR 0xfc
0077 
0078 #define CYTP_RESP_RETRY 0x01
0079 #define CYTP_RESP_ERROR 0xfe
0080 
0081 
0082 #define CYTP_105001_WIDTH  97   /* Dell XPS 13 */
0083 #define CYTP_105001_HIGH   59
0084 #define CYTP_DEFAULT_WIDTH (CYTP_105001_WIDTH)
0085 #define CYTP_DEFAULT_HIGH  (CYTP_105001_HIGH)
0086 
0087 #define CYTP_ABS_MAX_X     1600
0088 #define CYTP_ABS_MAX_Y     900
0089 #define CYTP_MAX_PRESSURE  255
0090 #define CYTP_MIN_PRESSURE  0
0091 
0092 /* header byte bits of relative package. */
0093 #define BTN_LEFT_BIT   0x01
0094 #define BTN_RIGHT_BIT  0x02
0095 #define BTN_MIDDLE_BIT 0x04
0096 #define REL_X_SIGN_BIT 0x10
0097 #define REL_Y_SIGN_BIT 0x20
0098 
0099 /* header byte bits of absolute package. */
0100 #define ABS_VSCROLL_BIT 0x10
0101 #define ABS_HSCROLL_BIT 0x20
0102 #define ABS_MULTIFINGER_TAP 0x04
0103 #define ABS_EDGE_MOTION_MASK 0x80
0104 
0105 #define DFLT_RESP_BITS_VALID     0x88  /* SMBus bit should not be set. */
0106 #define DFLT_RESP_SMBUS_BIT      0x80
0107 #define   DFLT_SMBUS_MODE        0x80
0108 #define   DFLT_PS2_MODE          0x00
0109 #define DFLT_RESP_BIT_MODE       0x40
0110 #define   DFLT_RESP_REMOTE_MODE  0x40
0111 #define   DFLT_RESP_STREAM_MODE  0x00
0112 #define DFLT_RESP_BIT_REPORTING  0x20
0113 #define DFLT_RESP_BIT_SCALING    0x10
0114 
0115 #define TP_METRICS_BIT_PALM               0x80
0116 #define TP_METRICS_BIT_STUBBORN           0x40
0117 #define TP_METRICS_BIT_2F_JITTER          0x30
0118 #define TP_METRICS_BIT_1F_JITTER          0x0c
0119 #define TP_METRICS_BIT_APA                0x02
0120 #define TP_METRICS_BIT_MTG                0x01
0121 #define TP_METRICS_BIT_ABS_PKT_FORMAT_SET 0xf0
0122 #define TP_METRICS_BIT_2F_SPIKE           0x0c
0123 #define TP_METRICS_BIT_1F_SPIKE           0x03
0124 
0125 /* bits of first byte response of E9h-Status Request command. */
0126 #define RESP_BTN_RIGHT_BIT  0x01
0127 #define RESP_BTN_MIDDLE_BIT 0x02
0128 #define RESP_BTN_LEFT_BIT   0x04
0129 #define RESP_SCALING_BIT    0x10
0130 #define RESP_ENABLE_BIT     0x20
0131 #define RESP_REMOTE_BIT     0x40
0132 #define RESP_SMBUS_BIT      0x80
0133 
0134 #define CYTP_MAX_MT_SLOTS 2
0135 
0136 struct cytp_contact {
0137     int x;
0138     int y;
0139     int z;  /* also named as touch pressure. */
0140 };
0141 
0142 /* The structure of Cypress Trackpad event data. */
0143 struct cytp_report_data {
0144     int contact_cnt;
0145     struct cytp_contact contacts[CYTP_MAX_MT_SLOTS];
0146     unsigned int left:1;
0147     unsigned int right:1;
0148     unsigned int middle:1;
0149     unsigned int tap:1;  /* multi-finger tap detected. */
0150 };
0151 
0152 /* The structure of Cypress Trackpad device private data. */
0153 struct cytp_data {
0154     int fw_version;
0155 
0156     int pkt_size;
0157     int mode;
0158 
0159     int tp_min_pressure;
0160     int tp_max_pressure;
0161     int tp_width;  /* X direction physical size in mm. */
0162     int tp_high;  /* Y direction physical size in mm. */
0163     int tp_max_abs_x;  /* Max X absolute units that can be reported. */
0164     int tp_max_abs_y;  /* Max Y absolute units that can be reported. */
0165 
0166     int tp_res_x;  /* X resolution in units/mm. */
0167     int tp_res_y;  /* Y resolution in units/mm. */
0168 
0169     int tp_metrics_supported;
0170 };
0171 
0172 
0173 int cypress_detect(struct psmouse *psmouse, bool set_properties);
0174 int cypress_init(struct psmouse *psmouse);
0175 
0176 #endif  /* _CYPRESS_PS2_H */