1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
20799a924SDudley Du #ifndef _CYPRESS_PS2_H
30799a924SDudley Du #define _CYPRESS_PS2_H
40799a924SDudley Du 
50799a924SDudley Du #include "psmouse.h"
60799a924SDudley Du 
70799a924SDudley Du #define CMD_BITS_MASK 0x03
80799a924SDudley Du #define COMPOSIT(x, s) (((x) & CMD_BITS_MASK) << (s))
90799a924SDudley Du 
100799a924SDudley Du #define ENCODE_CMD(aa, bb, cc, dd) \
110799a924SDudley Du 	(COMPOSIT((aa), 6) | COMPOSIT((bb), 4) | COMPOSIT((cc), 2) | COMPOSIT((dd), 0))
120799a924SDudley Du #define CYTP_CMD_ABS_NO_PRESSURE_MODE       ENCODE_CMD(0, 1, 0, 0)
130799a924SDudley Du #define CYTP_CMD_ABS_WITH_PRESSURE_MODE     ENCODE_CMD(0, 1, 0, 1)
140799a924SDudley Du #define CYTP_CMD_SMBUS_MODE                 ENCODE_CMD(0, 1, 1, 0)
150799a924SDudley Du #define CYTP_CMD_STANDARD_MODE              ENCODE_CMD(0, 2, 0, 0)  /* not implemented yet. */
160799a924SDudley Du #define CYTP_CMD_CYPRESS_REL_MODE           ENCODE_CMD(1, 1, 1, 1)  /* not implemented yet. */
170799a924SDudley Du #define CYTP_CMD_READ_CYPRESS_ID            ENCODE_CMD(0, 0, 0, 0)
180799a924SDudley Du #define CYTP_CMD_READ_TP_METRICS            ENCODE_CMD(0, 0, 0, 1)
190799a924SDudley Du #define CYTP_CMD_SET_HSCROLL_WIDTH(w)       ENCODE_CMD(1, 1, 0, (w))
200799a924SDudley Du #define     CYTP_CMD_SET_HSCROLL_MASK       ENCODE_CMD(1, 1, 0, 0)
210799a924SDudley Du #define CYTP_CMD_SET_VSCROLL_WIDTH(w)       ENCODE_CMD(1, 2, 0, (w))
220799a924SDudley Du #define     CYTP_CMD_SET_VSCROLL_MASK       ENCODE_CMD(1, 2, 0, 0)
230799a924SDudley Du #define CYTP_CMD_SET_PALM_GEOMETRY(e)       ENCODE_CMD(1, 2, 1, (e))
240799a924SDudley Du #define     CYTP_CMD_PALM_GEMMETRY_MASK     ENCODE_CMD(1, 2, 1, 0)
250799a924SDudley Du #define CYTP_CMD_SET_PALM_SENSITIVITY(s)    ENCODE_CMD(1, 2, 2, (s))
260799a924SDudley Du #define     CYTP_CMD_PALM_SENSITIVITY_MASK  ENCODE_CMD(1, 2, 2, 0)
270799a924SDudley Du #define CYTP_CMD_SET_MOUSE_SENSITIVITY(s)   ENCODE_CMD(1, 3, ((s) >> 2), (s))
280799a924SDudley Du #define     CYTP_CMD_MOUSE_SENSITIVITY_MASK ENCODE_CMD(1, 3, 0, 0)
290799a924SDudley Du #define CYTP_CMD_REQUEST_BASELINE_STATUS    ENCODE_CMD(2, 0, 0, 1)
300799a924SDudley Du #define CYTP_CMD_REQUEST_RECALIBRATION      ENCODE_CMD(2, 0, 0, 3)
310799a924SDudley Du 
320799a924SDudley Du #define DECODE_CMD_AA(x) (((x) >> 6) & CMD_BITS_MASK)
330799a924SDudley Du #define DECODE_CMD_BB(x) (((x) >> 4) & CMD_BITS_MASK)
340799a924SDudley Du #define DECODE_CMD_CC(x) (((x) >> 2) & CMD_BITS_MASK)
350799a924SDudley Du #define DECODE_CMD_DD(x) ((x) & CMD_BITS_MASK)
360799a924SDudley Du 
370799a924SDudley Du /* Cypress trackpad working mode. */
380799a924SDudley Du #define CYTP_BIT_ABS_PRESSURE    (1 << 3)
390799a924SDudley Du #define CYTP_BIT_ABS_NO_PRESSURE (1 << 2)
400799a924SDudley Du #define CYTP_BIT_CYPRESS_REL     (1 << 1)
410799a924SDudley Du #define CYTP_BIT_STANDARD_REL    (1 << 0)
420799a924SDudley Du #define CYTP_BIT_REL_MASK (CYTP_BIT_CYPRESS_REL | CYTP_BIT_STANDARD_REL)
430799a924SDudley Du #define CYTP_BIT_ABS_MASK (CYTP_BIT_ABS_PRESSURE | CYTP_BIT_ABS_NO_PRESSURE)
440799a924SDudley Du #define CYTP_BIT_ABS_REL_MASK (CYTP_BIT_ABS_MASK | CYTP_BIT_REL_MASK)
450799a924SDudley Du 
460799a924SDudley Du #define CYTP_BIT_HIGH_RATE       (1 << 4)
470799a924SDudley Du /*
480799a924SDudley Du  * report mode bit is set, firmware working in Remote Mode.
490799a924SDudley Du  * report mode bit is cleared, firmware working in Stream Mode.
500799a924SDudley Du  */
510799a924SDudley Du #define CYTP_BIT_REPORT_MODE     (1 << 5)
520799a924SDudley Du 
530799a924SDudley Du /* scrolling width values for set HSCROLL and VSCROLL width command. */
540799a924SDudley Du #define SCROLL_WIDTH_NARROW 1
550799a924SDudley Du #define SCROLL_WIDTH_NORMAL 2
560799a924SDudley Du #define SCROLL_WIDTH_WIDE   3
570799a924SDudley Du 
580799a924SDudley Du #define PALM_GEOMETRY_ENABLE  1
590799a924SDudley Du #define PALM_GEOMETRY_DISABLE 0
600799a924SDudley Du 
610799a924SDudley Du #define TP_METRICS_MASK  0x80
620799a924SDudley Du #define FW_VERSION_MASX    0x7f
630799a924SDudley Du #define FW_VER_HIGH_MASK 0x70
640799a924SDudley Du #define FW_VER_LOW_MASK  0x0f
650799a924SDudley Du 
660799a924SDudley Du /* Times to retry a ps2_command and millisecond delay between tries. */
670799a924SDudley Du #define CYTP_PS2_CMD_TRIES 3
680799a924SDudley Du #define CYTP_PS2_CMD_DELAY 500
690799a924SDudley Du 
700799a924SDudley Du /* time out for PS/2 command only in milliseconds. */
710799a924SDudley Du #define CYTP_CMD_TIMEOUT  200
720799a924SDudley Du #define CYTP_DATA_TIMEOUT 30
730799a924SDudley Du 
740799a924SDudley Du #define CYTP_EXT_CMD   0xe8
750799a924SDudley Du #define CYTP_PS2_RETRY 0xfe
760799a924SDudley Du #define CYTP_PS2_ERROR 0xfc
770799a924SDudley Du 
780799a924SDudley Du #define CYTP_RESP_RETRY 0x01
790799a924SDudley Du #define CYTP_RESP_ERROR 0xfe
800799a924SDudley Du 
810799a924SDudley Du 
820799a924SDudley Du #define CYTP_105001_WIDTH  97   /* Dell XPS 13 */
830799a924SDudley Du #define CYTP_105001_HIGH   59
840799a924SDudley Du #define CYTP_DEFAULT_WIDTH (CYTP_105001_WIDTH)
850799a924SDudley Du #define CYTP_DEFAULT_HIGH  (CYTP_105001_HIGH)
860799a924SDudley Du 
870799a924SDudley Du #define CYTP_ABS_MAX_X     1600
880799a924SDudley Du #define CYTP_ABS_MAX_Y     900
890799a924SDudley Du #define CYTP_MAX_PRESSURE  255
900799a924SDudley Du #define CYTP_MIN_PRESSURE  0
910799a924SDudley Du 
920799a924SDudley Du /* header byte bits of relative package. */
930799a924SDudley Du #define BTN_LEFT_BIT   0x01
940799a924SDudley Du #define BTN_RIGHT_BIT  0x02
950799a924SDudley Du #define BTN_MIDDLE_BIT 0x04
960799a924SDudley Du #define REL_X_SIGN_BIT 0x10
970799a924SDudley Du #define REL_Y_SIGN_BIT 0x20
980799a924SDudley Du 
990799a924SDudley Du /* header byte bits of absolute package. */
1000799a924SDudley Du #define ABS_VSCROLL_BIT 0x10
1010799a924SDudley Du #define ABS_HSCROLL_BIT 0x20
1020799a924SDudley Du #define ABS_MULTIFINGER_TAP 0x04
1030799a924SDudley Du #define ABS_EDGE_MOTION_MASK 0x80
1040799a924SDudley Du 
1050799a924SDudley Du #define DFLT_RESP_BITS_VALID     0x88  /* SMBus bit should not be set. */
1060799a924SDudley Du #define DFLT_RESP_SMBUS_BIT      0x80
1070799a924SDudley Du #define   DFLT_SMBUS_MODE        0x80
1080799a924SDudley Du #define   DFLT_PS2_MODE          0x00
1090799a924SDudley Du #define DFLT_RESP_BIT_MODE       0x40
1100799a924SDudley Du #define   DFLT_RESP_REMOTE_MODE  0x40
1110799a924SDudley Du #define   DFLT_RESP_STREAM_MODE  0x00
1120799a924SDudley Du #define DFLT_RESP_BIT_REPORTING  0x20
1130799a924SDudley Du #define DFLT_RESP_BIT_SCALING    0x10
1140799a924SDudley Du 
1150799a924SDudley Du #define TP_METRICS_BIT_PALM               0x80
1160799a924SDudley Du #define TP_METRICS_BIT_STUBBORN           0x40
1170799a924SDudley Du #define TP_METRICS_BIT_2F_JITTER          0x30
1180799a924SDudley Du #define TP_METRICS_BIT_1F_JITTER          0x0c
1190799a924SDudley Du #define TP_METRICS_BIT_APA                0x02
1200799a924SDudley Du #define TP_METRICS_BIT_MTG                0x01
1210799a924SDudley Du #define TP_METRICS_BIT_ABS_PKT_FORMAT_SET 0xf0
1220799a924SDudley Du #define TP_METRICS_BIT_2F_SPIKE           0x0c
1230799a924SDudley Du #define TP_METRICS_BIT_1F_SPIKE           0x03
1240799a924SDudley Du 
1250799a924SDudley Du /* bits of first byte response of E9h-Status Request command. */
1260799a924SDudley Du #define RESP_BTN_RIGHT_BIT  0x01
1270799a924SDudley Du #define RESP_BTN_MIDDLE_BIT 0x02
1280799a924SDudley Du #define RESP_BTN_LEFT_BIT   0x04
1290799a924SDudley Du #define RESP_SCALING_BIT    0x10
1300799a924SDudley Du #define RESP_ENABLE_BIT     0x20
1310799a924SDudley Du #define RESP_REMOTE_BIT     0x40
1320799a924SDudley Du #define RESP_SMBUS_BIT      0x80
1330799a924SDudley Du 
1340799a924SDudley Du #define CYTP_MAX_MT_SLOTS 2
1350799a924SDudley Du 
1360799a924SDudley Du struct cytp_contact {
1370799a924SDudley Du 	int x;
1380799a924SDudley Du 	int y;
1390799a924SDudley Du 	int z;  /* also named as touch pressure. */
1400799a924SDudley Du };
1410799a924SDudley Du 
1420799a924SDudley Du /* The structure of Cypress Trackpad event data. */
1430799a924SDudley Du struct cytp_report_data {
1440799a924SDudley Du 	int contact_cnt;
1450799a924SDudley Du 	struct cytp_contact contacts[CYTP_MAX_MT_SLOTS];
1460799a924SDudley Du 	unsigned int left:1;
1470799a924SDudley Du 	unsigned int right:1;
1480799a924SDudley Du 	unsigned int middle:1;
1490799a924SDudley Du 	unsigned int tap:1;  /* multi-finger tap detected. */
1500799a924SDudley Du };
1510799a924SDudley Du 
1520799a924SDudley Du /* The structure of Cypress Trackpad device private data. */
1530799a924SDudley Du struct cytp_data {
1540799a924SDudley Du 	int fw_version;
1550799a924SDudley Du 
1560799a924SDudley Du 	int pkt_size;
1570799a924SDudley Du 	int mode;
1580799a924SDudley Du 
1590799a924SDudley Du 	int tp_min_pressure;
1600799a924SDudley Du 	int tp_max_pressure;
1610799a924SDudley Du 	int tp_width;  /* X direction physical size in mm. */
1620799a924SDudley Du 	int tp_high;  /* Y direction physical size in mm. */
1630799a924SDudley Du 	int tp_max_abs_x;  /* Max X absolute units that can be reported. */
1640799a924SDudley Du 	int tp_max_abs_y;  /* Max Y absolute units that can be reported. */
1650799a924SDudley Du 
1660799a924SDudley Du 	int tp_res_x;  /* X resolution in units/mm. */
1670799a924SDudley Du 	int tp_res_y;  /* Y resolution in units/mm. */
1680799a924SDudley Du 
1690799a924SDudley Du 	int tp_metrics_supported;
1700799a924SDudley Du };
1710799a924SDudley Du 
1720799a924SDudley Du 
1730799a924SDudley Du #ifdef CONFIG_MOUSE_PS2_CYPRESS
1740799a924SDudley Du int cypress_detect(struct psmouse *psmouse, bool set_properties);
1750799a924SDudley Du int cypress_init(struct psmouse *psmouse);
1760799a924SDudley Du #else
1770799a924SDudley Du inline int cypress_detect(struct psmouse *psmouse, bool set_properties)
1780799a924SDudley Du {
1790799a924SDudley Du 	return -ENOSYS;
1800799a924SDudley Du }
1810799a924SDudley Du inline int cypress_init(struct psmouse *psmouse)
1820799a924SDudley Du {
1830799a924SDudley Du 	return -ENOSYS;
1840799a924SDudley Du }
1850799a924SDudley Du #endif /* CONFIG_MOUSE_PS2_CYPRESS */
1860799a924SDudley Du 
1870799a924SDudley Du #endif  /* _CYPRESS_PS2_H */
188