^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Elantech Touchpad driver (v6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2007-2009 Arjan Opmeer <arjan@opmeer.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Trademarks are the property of their respective owners.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/serio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/libps2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "psmouse.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "elantech.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "elan_i2c.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define elantech_debug(fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (etd->info.debug) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) psmouse_printk(KERN_DEBUG, psmouse, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) fmt, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Send a Synaptics style sliced query command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned char *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (ps2_sliced_command(&psmouse->ps2dev, c) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) psmouse_err(psmouse, "%s query 0x%02x failed.\n", __func__, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * V3 and later support this fast command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int elantech_send_cmd(struct psmouse *psmouse, unsigned char c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned char *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct ps2dev *ps2dev = &psmouse->ps2dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (ps2_command(ps2dev, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ps2_command(ps2dev, NULL, c) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) psmouse_err(psmouse, "%s query 0x%02x failed.\n", __func__, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * A retrying version of ps2_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int elantech_ps2_command(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned char *param, int command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct ps2dev *ps2dev = &psmouse->ps2dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int tries = ETP_PS2_COMMAND_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) rc = ps2_command(ps2dev, param, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) tries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) elantech_debug("retrying ps2 command 0x%02x (%d).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) command, tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) msleep(ETP_PS2_COMMAND_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } while (tries > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) psmouse_err(psmouse, "ps2 command 0x%02x failed.\n", command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Send an Elantech style special command to read 3 bytes from a register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static int elantech_read_reg_params(struct psmouse *psmouse, u8 reg, u8 *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) elantech_ps2_command(psmouse, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) "failed to read register %#02x\n", reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Send an Elantech style special command to write a register with a parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int elantech_write_reg_params(struct psmouse *psmouse, u8 reg, u8 *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) elantech_ps2_command(psmouse, NULL, param[0]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) elantech_ps2_command(psmouse, NULL, param[1]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) "failed to write register %#02x with value %#02x%#02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) reg, param[0], param[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Send an Elantech style special command to read a value from a register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int elantech_read_reg(struct psmouse *psmouse, unsigned char reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) unsigned char *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned char param[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (reg < 0x07 || reg > 0x26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (reg > 0x11 && reg < 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) switch (etd->info.hw_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (ps2_sliced_command(&psmouse->ps2dev, ETP_REGISTER_READ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ps2_sliced_command(&psmouse->ps2dev, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) elantech_ps2_command(psmouse, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) case 3 ... 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) elantech_ps2_command(psmouse, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) psmouse_err(psmouse, "failed to read register 0x%02x.\n", reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) else if (etd->info.hw_version != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *val = param[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *val = param[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Send an Elantech style special command to write a register with a value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int elantech_write_reg(struct psmouse *psmouse, unsigned char reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) unsigned char val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (reg < 0x07 || reg > 0x26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (reg > 0x11 && reg < 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) switch (etd->info.hw_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (ps2_sliced_command(&psmouse->ps2dev, ETP_REGISTER_WRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ps2_sliced_command(&psmouse->ps2dev, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ps2_sliced_command(&psmouse->ps2dev, val) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_WRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) elantech_ps2_command(psmouse, NULL, val) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) elantech_ps2_command(psmouse, NULL, val) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) elantech_ps2_command(psmouse, NULL, reg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) elantech_ps2_command(psmouse, NULL, ETP_REGISTER_READWRITE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) elantech_ps2_command(psmouse, NULL, ETP_PS2_CUSTOM_COMMAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) elantech_ps2_command(psmouse, NULL, val) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) elantech_ps2_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) "failed to write register 0x%02x with value 0x%02x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * Dump a complete mouse movement packet to the syslog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static void elantech_packet_dump(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) psmouse_printk(KERN_DEBUG, psmouse, "PS/2 packet [%*ph]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) psmouse->pktsize, psmouse->packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Advertise INPUT_PROP_BUTTONPAD for clickpads. The testing of bit 12 in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * fw_version for this is based on the following fw_version & caps table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * Laptop-model: fw_version: caps: buttons:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * Acer S3 0x461f00 10, 13, 0e clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Acer S7-392 0x581f01 50, 17, 0d clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Acer V5-131 0x461f02 01, 16, 0c clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * Acer V5-551 0x461f00 ? clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * Asus K53SV 0x450f01 78, 15, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * Asus G46VW 0x460f02 00, 18, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Asus G750JX 0x360f00 00, 16, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * Asus TP500LN 0x381f17 10, 14, 0e clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Asus X750JN 0x381f17 10, 14, 0e clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * Asus UX31 0x361f00 20, 15, 0e clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * Asus UX32VD 0x361f02 00, 15, 0e clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Avatar AVIU-145A2 0x361f00 ? clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * Fujitsu CELSIUS H760 0x570f02 40, 14, 0c 3 hw buttons (**)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * Fujitsu CELSIUS H780 0x5d0f02 41, 16, 0d 3 hw buttons (**)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * Fujitsu LIFEBOOK E544 0x470f00 d0, 12, 09 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * Fujitsu LIFEBOOK E546 0x470f00 50, 12, 09 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Fujitsu LIFEBOOK E547 0x470f00 50, 12, 09 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * Fujitsu LIFEBOOK E554 0x570f01 40, 14, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * Fujitsu LIFEBOOK E557 0x570f01 40, 14, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Fujitsu T725 0x470f01 05, 12, 09 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * Fujitsu H730 0x570f00 c0, 14, 0c 3 hw buttons (**)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * Gigabyte U2442 0x450f01 58, 17, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * Lenovo L430 0x350f02 b9, 15, 0c 2 hw buttons (*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * Lenovo L530 0x350f02 b9, 15, 0c 2 hw buttons (*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Samsung NF210 0x150b00 78, 14, 0a 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * Samsung NP770Z5E 0x575f01 10, 15, 0f clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * Samsung NP700Z5B 0x361f06 21, 15, 0f clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Samsung NP900X3E-A02 0x575f03 ? clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * Samsung NP-QX410 0x851b00 19, 14, 0c clickpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * Samsung RC512 0x450f00 08, 15, 0c 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Samsung RF710 0x450f00 ? 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * System76 Pangolin 0x250f01 ? 2 hw buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * (*) + 3 trackpoint buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * (**) + 0 trackpoint buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * Note: Lenovo L430 and Lenovo L530 have the same fw_version/caps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static inline int elantech_is_buttonpad(struct elantech_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return info->fw_version & 0x001000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * Interpret complete data packets and report absolute mode input events for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * hardware version 1. (4 byte packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static void elantech_report_absolute_v1(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (etd->info.fw_version < 0x020000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * byte 0: D U p1 p2 1 p3 R L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * byte 1: f 0 th tw x9 x8 y9 y8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) fingers = ((packet[1] & 0x80) >> 7) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ((packet[1] & 0x30) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * byte 0: n1 n0 p2 p1 1 p3 R L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * byte 1: 0 0 0 0 x9 x8 y9 y8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fingers = (packet[0] & 0xc0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (etd->info.jumpy_cursor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (fingers != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) etd->single_finger_reports = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) } else if (etd->single_finger_reports < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* Discard first 2 reports of one finger, bogus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) etd->single_finger_reports++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) elantech_debug("discarding packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) input_report_key(dev, BTN_TOUCH, fingers != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * byte 2: x7 x6 x5 x4 x3 x2 x1 x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * byte 3: y7 y6 y5 y4 y3 y2 y1 y0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (fingers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) input_report_abs(dev, ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ((packet[1] & 0x0c) << 6) | packet[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) input_report_abs(dev, ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) etd->y_max - (((packet[1] & 0x03) << 8) | packet[3]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) psmouse_report_standard_buttons(dev, packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (etd->info.fw_version < 0x020000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) (etd->info.capabilities[0] & ETP_CAP_HAS_ROCKER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* rocker up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) input_report_key(dev, BTN_FORWARD, packet[0] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* rocker down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) input_report_key(dev, BTN_BACK, packet[0] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void elantech_set_slot(struct input_dev *dev, int slot, bool active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) unsigned int x, unsigned int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) input_mt_slot(dev, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) input_report_abs(dev, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) input_report_abs(dev, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* x1 < x2 and y1 < y2 when two fingers, x = y = 0 when not pressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static void elantech_report_semi_mt_data(struct input_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) unsigned int num_fingers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) unsigned int x1, unsigned int y1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) unsigned int x2, unsigned int y2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) elantech_set_slot(dev, 0, num_fingers != 0, x1, y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) elantech_set_slot(dev, 1, num_fingers >= 2, x2, y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * Interpret complete data packets and report absolute mode input events for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * hardware version 2. (6 byte packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static void elantech_report_absolute_v2(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) unsigned int fingers, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) unsigned int width = 0, pres = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /* byte 0: n1 n0 . . . . R L */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) fingers = (packet[0] & 0xc0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) switch (fingers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * Same as one finger, except report of more than 3 fingers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * byte 3: n4 . w1 w0 . . . .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (packet[3] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) fingers = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * byte 1: . . . . x11 x10 x9 x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * byte 2: x7 x6 x5 x4 x4 x2 x1 x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) x1 = ((packet[1] & 0x0f) << 8) | packet[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * byte 4: . . . . y11 y10 y9 y8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * byte 5: y7 y6 y5 y4 y3 y2 y1 y0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) y1 = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) width = ((packet[0] & 0x30) >> 2) | ((packet[3] & 0x30) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * The coordinate of each finger is reported separately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * with a lower resolution for two finger touches:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * byte 0: . . ay8 ax8 . . . .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * byte 1: ax7 ax6 ax5 ax4 ax3 ax2 ax1 ax0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) x1 = (((packet[0] & 0x10) << 4) | packet[1]) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* byte 2: ay7 ay6 ay5 ay4 ay3 ay2 ay1 ay0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) y1 = etd->y_max -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) ((((packet[0] & 0x20) << 3) | packet[2]) << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * byte 3: . . by8 bx8 . . . .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * byte 4: bx7 bx6 bx5 bx4 bx3 bx2 bx1 bx0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) x2 = (((packet[3] & 0x10) << 4) | packet[4]) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* byte 5: by7 by8 by5 by4 by3 by2 by1 by0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) y2 = etd->y_max -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ((((packet[3] & 0x20) << 3) | packet[5]) << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* Unknown so just report sensible values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) pres = 127;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) width = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) input_report_key(dev, BTN_TOUCH, fingers != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (fingers != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) input_report_abs(dev, ABS_X, x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) input_report_abs(dev, ABS_Y, y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) elantech_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) psmouse_report_standard_buttons(dev, packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (etd->info.reports_pressure) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) input_report_abs(dev, ABS_PRESSURE, pres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) input_report_abs(dev, ABS_TOOL_WIDTH, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static void elantech_report_trackpoint(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) int packet_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * byte 0: 0 0 sx sy 0 M R L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * byte 1:~sx 0 0 0 0 0 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * byte 2:~sy 0 0 0 0 0 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * byte 3: 0 0 ~sy ~sx 0 1 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * byte 4: x7 x6 x5 x4 x3 x2 x1 x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * byte 5: y7 y6 y5 y4 y3 y2 y1 y0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * x and y are written in two's complement spread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * over 9 bits with sx/sy the relative top bit and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * x7..x0 and y7..y0 the lower bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * The sign of y is opposite to what the input driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * expects for a relative movement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct input_dev *tp_dev = etd->tp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) u32 t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) t = get_unaligned_le32(&packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) switch (t & ~7U) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) case 0x06000030U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) case 0x16008020U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) case 0x26800010U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) case 0x36808000U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * This firmware misreport coordinates for trackpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * occasionally. Discard packets outside of [-127, 127] range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * to prevent cursor jumps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (packet[4] == 0x80 || packet[5] == 0x80 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) packet[1] >> 7 == packet[4] >> 7 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) packet[2] >> 7 == packet[5] >> 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) elantech_debug("discarding packet [%6ph]\n", packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) x = packet[4] - (int)((packet[1]^0x80) << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) y = (int)((packet[2]^0x80) << 1) - packet[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) psmouse_report_standard_buttons(tp_dev, packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) input_report_rel(tp_dev, REL_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) input_report_rel(tp_dev, REL_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) input_sync(tp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /* Dump unexpected packet sequences if debug=1 (default) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (etd->info.debug == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) elantech_packet_dump(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Interpret complete data packets and report absolute mode input events for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * hardware version 3. (12 byte packets for two fingers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static void elantech_report_absolute_v3(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int packet_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) unsigned int fingers = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) unsigned int width = 0, pres = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* byte 0: n1 n0 . . . . R L */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) fingers = (packet[0] & 0xc0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) switch (fingers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * byte 1: . . . . x11 x10 x9 x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * byte 2: x7 x6 x5 x4 x4 x2 x1 x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) x1 = ((packet[1] & 0x0f) << 8) | packet[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * byte 4: . . . . y11 y10 y9 y8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * byte 5: y7 y6 y5 y4 y3 y2 y1 y0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) y1 = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (packet_type == PACKET_V3_HEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * byte 1: . . . . ax11 ax10 ax9 ax8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * byte 2: ax7 ax6 ax5 ax4 ax3 ax2 ax1 ax0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) etd->mt[0].x = ((packet[1] & 0x0f) << 8) | packet[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * byte 4: . . . . ay11 ay10 ay9 ay8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * byte 5: ay7 ay6 ay5 ay4 ay3 ay2 ay1 ay0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) etd->mt[0].y = etd->y_max -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) (((packet[4] & 0x0f) << 8) | packet[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * wait for next packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* packet_type == PACKET_V3_TAIL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) x1 = etd->mt[0].x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) y1 = etd->mt[0].y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) x2 = ((packet[1] & 0x0f) << 8) | packet[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) y2 = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) width = ((packet[0] & 0x30) >> 2) | ((packet[3] & 0x30) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) input_report_key(dev, BTN_TOUCH, fingers != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (fingers != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) input_report_abs(dev, ABS_X, x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) input_report_abs(dev, ABS_Y, y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) elantech_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) /* For clickpads map both buttons to BTN_LEFT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (elantech_is_buttonpad(&etd->info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) psmouse_report_standard_buttons(dev, packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) input_report_abs(dev, ABS_PRESSURE, pres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) input_report_abs(dev, ABS_TOOL_WIDTH, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static void elantech_input_sync_v4(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /* For clickpads map both buttons to BTN_LEFT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (elantech_is_buttonpad(&etd->info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) psmouse_report_standard_buttons(dev, packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) input_mt_report_pointer_emulation(dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static void process_packet_status_v4(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) unsigned fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /* notify finger state change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) fingers = packet[1] & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) for (i = 0; i < ETP_MAX_FINGERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if ((fingers & (1 << i)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) input_mt_slot(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) input_mt_report_slot_state(dev, MT_TOOL_FINGER, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) elantech_input_sync_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static void process_packet_head_v4(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) int id = ((packet[3] & 0xe0) >> 5) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int pres, traces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) etd->mt[id].x = ((packet[1] & 0x0f) << 8) | packet[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) etd->mt[id].y = etd->y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) traces = (packet[0] & 0xf0) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) input_mt_slot(dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[id].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[id].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) input_report_abs(dev, ABS_MT_PRESSURE, pres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) input_report_abs(dev, ABS_MT_TOUCH_MAJOR, traces * etd->width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /* report this for backwards compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) input_report_abs(dev, ABS_TOOL_WIDTH, traces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) elantech_input_sync_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static void process_packet_motion_v4(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) int weight, delta_x1 = 0, delta_y1 = 0, delta_x2 = 0, delta_y2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) int id, sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) id = ((packet[0] & 0xe0) >> 5) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) sid = ((packet[3] & 0xe0) >> 5) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) weight = (packet[0] & 0x10) ? ETP_WEIGHT_VALUE : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * Motion packets give us the delta of x, y values of specific fingers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * but in two's complement. Let the compiler do the conversion for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) * Also _enlarge_ the numbers to int, in case of overflow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) delta_x1 = (signed char)packet[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) delta_y1 = (signed char)packet[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) delta_x2 = (signed char)packet[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) delta_y2 = (signed char)packet[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) etd->mt[id].x += delta_x1 * weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) etd->mt[id].y -= delta_y1 * weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) input_mt_slot(dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[id].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[id].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (sid >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) etd->mt[sid].x += delta_x2 * weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) etd->mt[sid].y -= delta_y2 * weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) input_mt_slot(dev, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[sid].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[sid].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) elantech_input_sync_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static void elantech_report_absolute_v4(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int packet_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) switch (packet_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) case PACKET_V4_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) process_packet_status_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) case PACKET_V4_HEAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) process_packet_head_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) case PACKET_V4_MOTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) process_packet_motion_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) case PACKET_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* impossible to get here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) static int elantech_packet_check_v1(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) unsigned char p1, p2, p3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) /* Parity bits are placed differently */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (etd->info.fw_version < 0x020000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /* byte 0: D U p1 p2 1 p3 R L */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) p1 = (packet[0] & 0x20) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) p2 = (packet[0] & 0x10) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* byte 0: n1 n0 p2 p1 1 p3 R L */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) p1 = (packet[0] & 0x10) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) p2 = (packet[0] & 0x20) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) p3 = (packet[0] & 0x04) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) return etd->parity[packet[1]] == p1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) etd->parity[packet[2]] == p2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) etd->parity[packet[3]] == p3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) static int elantech_debounce_check_v2(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * When we encounter packet that matches this exactly, it means the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * hardware is in debounce status. Just ignore the whole packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) static const u8 debounce_packet[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 0x84, 0xff, 0xff, 0x02, 0xff, 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return !memcmp(packet, debounce_packet, sizeof(debounce_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) static int elantech_packet_check_v2(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * V2 hardware has two flavors. Older ones that do not report pressure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * and newer ones that reports pressure and width. With newer ones, all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * packets (1, 2, 3 finger touch) have the same constant bits. With
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * older ones, 1/3 finger touch packets and 2 finger touch packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * have different constant bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) * With all three cases, if the constant bits are not exactly what I
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * expected, I consider them invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) if (etd->info.reports_pressure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) return (packet[0] & 0x0c) == 0x04 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) (packet[3] & 0x0f) == 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if ((packet[0] & 0xc0) == 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return (packet[0] & 0x0c) == 0x0c &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) (packet[3] & 0x0e) == 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return (packet[0] & 0x3c) == 0x3c &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) (packet[1] & 0xf0) == 0x00 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) (packet[3] & 0x3e) == 0x38 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) (packet[4] & 0xf0) == 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * We check the constant bits to determine what packet type we get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * so packet checking is mandatory for v3 and later hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) static int elantech_packet_check_v3(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) static const u8 debounce_packet[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 0xc4, 0xff, 0xff, 0x02, 0xff, 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) * check debounce first, it has the same signature in byte 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) * and byte 3 as PACKET_V3_HEAD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (!memcmp(packet, debounce_packet, sizeof(debounce_packet)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) return PACKET_DEBOUNCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * If the hardware flag 'crc_enabled' is set the packets have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * different signatures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (etd->info.crc_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if ((packet[3] & 0x09) == 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) return PACKET_V3_HEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if ((packet[3] & 0x09) == 0x09)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return PACKET_V3_TAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if ((packet[0] & 0x0c) == 0x04 && (packet[3] & 0xcf) == 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) return PACKET_V3_HEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if ((packet[0] & 0x0c) == 0x0c && (packet[3] & 0xce) == 0x0c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return PACKET_V3_TAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if ((packet[3] & 0x0f) == 0x06)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return PACKET_TRACKPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return PACKET_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) static int elantech_packet_check_v4(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) unsigned char *packet = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) unsigned char packet_type = packet[3] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) unsigned int ic_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) bool sanity_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (etd->tp_dev && (packet[3] & 0x0f) == 0x06)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) return PACKET_TRACKPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) /* This represents the version of IC body. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ic_version = (etd->info.fw_version & 0x0f0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) * Sanity check based on the constant bits of a packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * The constant bits change depending on the value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * the hardware flag 'crc_enabled' and the version of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * the IC body, but are the same for every packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * regardless of the type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (etd->info.crc_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) sanity_check = ((packet[3] & 0x08) == 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) else if (ic_version == 7 && etd->info.samples[1] == 0x2A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) sanity_check = ((packet[3] & 0x1c) == 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) sanity_check = ((packet[0] & 0x08) == 0x00 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) (packet[3] & 0x1c) == 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (!sanity_check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return PACKET_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) switch (packet_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return PACKET_V4_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return PACKET_V4_HEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) return PACKET_V4_MOTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) return PACKET_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) * Process byte stream from mouse and handle complete packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) int packet_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (psmouse->pktcnt < psmouse->pktsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return PSMOUSE_GOOD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (etd->info.debug > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) elantech_packet_dump(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) switch (etd->info.hw_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (etd->info.paritycheck && !elantech_packet_check_v1(psmouse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) return PSMOUSE_BAD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) elantech_report_absolute_v1(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) /* ignore debounce */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (elantech_debounce_check_v2(psmouse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return PSMOUSE_FULL_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (etd->info.paritycheck && !elantech_packet_check_v2(psmouse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return PSMOUSE_BAD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) elantech_report_absolute_v2(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) packet_type = elantech_packet_check_v3(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) switch (packet_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) case PACKET_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return PSMOUSE_BAD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) case PACKET_DEBOUNCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) /* ignore debounce */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) case PACKET_TRACKPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) elantech_report_trackpoint(psmouse, packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) elantech_report_absolute_v3(psmouse, packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) packet_type = elantech_packet_check_v4(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) switch (packet_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) case PACKET_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) return PSMOUSE_BAD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) case PACKET_TRACKPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) elantech_report_trackpoint(psmouse, packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) elantech_report_absolute_v4(psmouse, packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return PSMOUSE_FULL_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) * This writes the reg_07 value again to the hardware at the end of every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) * set_rate call because the register loses its value. reg_07 allows setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * absolute mode on v4 hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static void elantech_set_rate_restore_reg_07(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) unsigned int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) etd->original_set_rate(psmouse, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (elantech_write_reg(psmouse, 0x07, etd->reg_07))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) psmouse_err(psmouse, "restoring reg_07 failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) * Put the touchpad into absolute mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static int elantech_set_absolute_mode(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) int tries = ETP_READ_BACK_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) switch (etd->info.hw_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) etd->reg_10 = 0x16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) etd->reg_11 = 0x8f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) if (elantech_write_reg(psmouse, 0x10, etd->reg_10) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) elantech_write_reg(psmouse, 0x11, etd->reg_11)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /* Windows driver values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) etd->reg_10 = 0x54;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) etd->reg_11 = 0x88; /* 0x8a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) etd->reg_21 = 0x60; /* 0x00 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (elantech_write_reg(psmouse, 0x10, etd->reg_10) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) elantech_write_reg(psmouse, 0x11, etd->reg_11) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) elantech_write_reg(psmouse, 0x21, etd->reg_21)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (etd->info.set_hw_resolution)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) etd->reg_10 = 0x0b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) etd->reg_10 = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (elantech_write_reg(psmouse, 0x10, etd->reg_10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) etd->reg_07 = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (elantech_write_reg(psmouse, 0x07, etd->reg_07))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) goto skip_readback_reg_10; /* v4 has no reg 0x10 to read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * Read back reg 0x10. For hardware version 1 we must make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) * sure the absolute mode bit is set. For hardware version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * the touchpad is probably initializing and not ready until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * we read back the value we just wrote.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) rc = elantech_read_reg(psmouse, 0x10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) tries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) elantech_debug("retrying read (%d).\n", tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) msleep(ETP_READ_BACK_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) } while (tries > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) "failed to read back register 0x10.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) } else if (etd->info.hw_version == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) !(val & ETP_R10_ABSOLUTE_MODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) "touchpad refuses to switch to absolute mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) skip_readback_reg_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) psmouse_err(psmouse, "failed to initialise registers.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) * (value from firmware) * 10 + 790 = dpi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) * we also have to convert dpi to dots/mm (*10/254 to avoid floating point)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) static unsigned int elantech_convert_res(unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return (val * 10 + 790) * 10 / 254;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) static int elantech_get_resolution_v4(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) unsigned int *x_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) unsigned int *y_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) unsigned int *bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) unsigned char param[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (elantech_send_cmd(psmouse, ETP_RESOLUTION_QUERY, param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) *x_res = elantech_convert_res(param[1] & 0x0f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) *y_res = elantech_convert_res((param[1] & 0xf0) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) *bus = param[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static void elantech_set_buttonpad_prop(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) if (elantech_is_buttonpad(&etd->info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) __clear_bit(BTN_RIGHT, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * Some hw_version 4 models do have a middle button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) static const struct dmi_system_id elantech_dmi_has_middle_button[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) #if defined(CONFIG_DMI) && defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) /* Fujitsu H730 has a middle button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H730"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /* Fujitsu H760 also has a middle button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H760"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) /* Fujitsu H780 also has a middle button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H780"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) * Set the appropriate event bits for the input subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) static int elantech_set_input_params(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) struct elantech_device_info *info = &etd->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) unsigned int x_min = info->x_min, y_min = info->y_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) x_max = info->x_max, y_max = info->y_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) width = info->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) __set_bit(INPUT_PROP_POINTER, dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) __set_bit(EV_KEY, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) __set_bit(EV_ABS, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) __clear_bit(EV_REL, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) __set_bit(BTN_LEFT, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) if (info->has_middle_button)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) __set_bit(BTN_MIDDLE, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) __set_bit(BTN_RIGHT, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) __set_bit(BTN_TOUCH, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) __set_bit(BTN_TOOL_FINGER, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) switch (info->hw_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) /* Rocker button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) if (info->fw_version < 0x020000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) (info->capabilities[0] & ETP_CAP_HAS_ROCKER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) __set_bit(BTN_FORWARD, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) __set_bit(BTN_BACK, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (info->hw_version == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) elantech_set_buttonpad_prop(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (info->reports_pressure) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) input_set_abs_params(dev, ABS_PRESSURE, ETP_PMIN_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) ETP_PMAX_V2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) ETP_WMAX_V2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) input_mt_init_slots(dev, 2, INPUT_MT_SEMI_MT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) elantech_set_buttonpad_prop(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) /* For X to recognize me as touchpad. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) * range of pressure and width is the same as v2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * report ABS_PRESSURE, ABS_TOOL_WIDTH for compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) input_set_abs_params(dev, ABS_PRESSURE, ETP_PMIN_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) ETP_PMAX_V2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) ETP_WMAX_V2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) /* Multitouch capable pad, up to 5 fingers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) input_mt_init_slots(dev, ETP_MAX_FINGERS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) input_set_abs_params(dev, ABS_MT_PRESSURE, ETP_PMIN_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) ETP_PMAX_V2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) * The firmware reports how many trace lines the finger spans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) * convert to surface unit as Protocol-B requires.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) input_set_abs_params(dev, ABS_MT_TOUCH_MAJOR, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) ETP_WMAX_V2 * width, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) input_abs_set_res(dev, ABS_X, info->x_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) input_abs_set_res(dev, ABS_Y, info->y_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (info->hw_version > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) input_abs_set_res(dev, ABS_MT_POSITION_X, info->x_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) input_abs_set_res(dev, ABS_MT_POSITION_Y, info->y_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) etd->y_max = y_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) etd->width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) struct elantech_attr_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) size_t field_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) unsigned char reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) * Display a register value by reading a sysfs entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static ssize_t elantech_show_int_attr(struct psmouse *psmouse, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) struct elantech_attr_data *attr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) unsigned char *reg = (unsigned char *) etd + attr->field_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) if (attr->reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) rc = elantech_read_reg(psmouse, attr->reg, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) return sprintf(buf, "0x%02x\n", (attr->reg && rc) ? -1 : *reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) * Write a register value by writing a sysfs entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) static ssize_t elantech_set_int_attr(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) void *data, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct elantech_attr_data *attr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) unsigned char *reg = (unsigned char *) etd + attr->field_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) unsigned char value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) err = kstrtou8(buf, 16, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) /* Do we need to preserve some bits for version 2 hardware too? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) if (etd->info.hw_version == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (attr->reg == 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) /* Force absolute mode always on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) value |= ETP_R10_ABSOLUTE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) else if (attr->reg == 0x11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) /* Force 4 byte mode always on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) value |= ETP_R11_4_BYTE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (!attr->reg || elantech_write_reg(psmouse, attr->reg, value) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) *reg = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) #define ELANTECH_INT_ATTR(_name, _register) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) static struct elantech_attr_data elantech_attr_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) .field_offset = offsetof(struct elantech_data, _name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) .reg = _register, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) PSMOUSE_DEFINE_ATTR(_name, 0644, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) &elantech_attr_##_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) elantech_show_int_attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) elantech_set_int_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) #define ELANTECH_INFO_ATTR(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) static struct elantech_attr_data elantech_attr_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) .field_offset = offsetof(struct elantech_data, info) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) offsetof(struct elantech_device_info, _name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) .reg = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) PSMOUSE_DEFINE_ATTR(_name, 0644, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) &elantech_attr_##_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) elantech_show_int_attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) elantech_set_int_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) ELANTECH_INT_ATTR(reg_07, 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) ELANTECH_INT_ATTR(reg_10, 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) ELANTECH_INT_ATTR(reg_11, 0x11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) ELANTECH_INT_ATTR(reg_20, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) ELANTECH_INT_ATTR(reg_21, 0x21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) ELANTECH_INT_ATTR(reg_22, 0x22);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) ELANTECH_INT_ATTR(reg_23, 0x23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) ELANTECH_INT_ATTR(reg_24, 0x24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) ELANTECH_INT_ATTR(reg_25, 0x25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) ELANTECH_INT_ATTR(reg_26, 0x26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) ELANTECH_INFO_ATTR(debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) ELANTECH_INFO_ATTR(paritycheck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) ELANTECH_INFO_ATTR(crc_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) static struct attribute *elantech_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) &psmouse_attr_reg_07.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) &psmouse_attr_reg_10.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) &psmouse_attr_reg_11.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) &psmouse_attr_reg_20.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) &psmouse_attr_reg_21.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) &psmouse_attr_reg_22.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) &psmouse_attr_reg_23.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) &psmouse_attr_reg_24.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) &psmouse_attr_reg_25.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) &psmouse_attr_reg_26.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) &psmouse_attr_debug.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) &psmouse_attr_paritycheck.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) &psmouse_attr_crc_enabled.dattr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static const struct attribute_group elantech_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) .attrs = elantech_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) static bool elantech_is_signature_valid(const unsigned char *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) if (param[0] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (param[1] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) * Some hw_version >= 4 models have a revision higher then 20. Meaning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) * that param[2] may be 10 or 20, skip the rates check for these.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if ((param[0] & 0x0f) >= 0x06 && (param[1] & 0xaf) == 0x0f &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) param[2] < 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) for (i = 0; i < ARRAY_SIZE(rates); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (param[2] == rates[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) * Use magic knock to detect Elantech touchpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) int elantech_detect(struct psmouse *psmouse, bool set_properties)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) struct ps2dev *ps2dev = &psmouse->ps2dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) unsigned char param[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) psmouse_dbg(psmouse, "sending Elantech magic knock failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) * Report this in case there are Elantech models that use a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) * set of magic numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if (param[0] != 0x3c || param[1] != 0x03 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) (param[2] != 0xc8 && param[2] != 0x00)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) psmouse_dbg(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) "unexpected magic knock result 0x%02x, 0x%02x, 0x%02x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) param[0], param[1], param[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) * Query touchpad's firmware version and see if it reports known
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) * value to avoid mis-detection. Logitech mice are known to respond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) * to Elantech magic knock and there might be more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) if (synaptics_send_cmd(psmouse, ETP_FW_VERSION_QUERY, param)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) psmouse_dbg(psmouse, "failed to query firmware version.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) psmouse_dbg(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) "Elantech version query result 0x%02x, 0x%02x, 0x%02x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) param[0], param[1], param[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) if (!elantech_is_signature_valid(param)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) psmouse_dbg(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) "Probably not a real Elantech touchpad. Aborting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) if (set_properties) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) psmouse->vendor = "Elantech";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) psmouse->name = "Touchpad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) * Clean up sysfs entries when disconnecting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) static void elantech_disconnect(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) struct elantech_data *etd = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * We might have left a breadcrumb when trying to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) * set up SMbus companion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) psmouse_smbus_cleanup(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (etd->tp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) input_unregister_device(etd->tp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) &elantech_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) kfree(psmouse->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) psmouse->private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) * Put the touchpad back into absolute mode when reconnecting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) static int elantech_reconnect(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (elantech_detect(psmouse, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (elantech_set_absolute_mode(psmouse)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) "failed to put touchpad back into absolute mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * Some hw_version 4 models do not work with crc_disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) static const struct dmi_system_id elantech_dmi_force_crc_enabled[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) #if defined(CONFIG_DMI) && defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) /* Fujitsu H730 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H730"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) /* Fujitsu H760 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H760"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) /* Fujitsu LIFEBOOK E544 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E544"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) /* Fujitsu LIFEBOOK E546 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E546"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) /* Fujitsu LIFEBOOK E547 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E547"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /* Fujitsu LIFEBOOK E554 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E554"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) /* Fujitsu LIFEBOOK E556 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E556"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) /* Fujitsu LIFEBOOK E557 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E557"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) /* Fujitsu LIFEBOOK U745 does not work with crc_enabled == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK U745"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) * Some hw_version 3 models go into error state when we try to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) * bit 3 and/or bit 1 of r10.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) static const struct dmi_system_id no_hw_res_dmi_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) #if defined(CONFIG_DMI) && defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) /* Gigabyte U2442 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) DMI_MATCH(DMI_PRODUCT_NAME, "U2442"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) * Change Report id 0x5E to 0x5F.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) static int elantech_change_report_id(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) * NOTE: the code is expecting to receive param[] as an array of 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) * items (see __ps2_command()), even if in this case only 2 are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) * actually needed. Make sure the array size is 3 to avoid potential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) * stack out-of-bound accesses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) unsigned char param[3] = { 0x10, 0x03 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (elantech_write_reg_params(psmouse, 0x7, param) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) elantech_read_reg_params(psmouse, 0x7, param) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) param[0] != 0x10 || param[1] != 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) psmouse_err(psmouse, "Unable to change report ID to 0x5f.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) * determine hardware version and set some properties according to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) static int elantech_set_properties(struct elantech_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) /* This represents the version of IC body. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) info->ic_version = (info->fw_version & 0x0f0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) /* Early version of Elan touchpads doesn't obey the rule. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) if (info->fw_version < 0x020030 || info->fw_version == 0x020600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) info->hw_version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) switch (info->ic_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) info->hw_version = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) info->hw_version = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) case 6 ... 15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) info->hw_version = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) /* Get information pattern for hw_version 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) info->pattern = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) if (info->ic_version == 0x0f && (info->fw_version & 0xff) <= 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) info->pattern = info->fw_version & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) /* decide which send_cmd we're gonna use early */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) info->send_cmd = info->hw_version >= 3 ? elantech_send_cmd :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) synaptics_send_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) /* Turn on packet checking by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) info->paritycheck = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) * This firmware suffers from misreporting coordinates when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * a touch action starts causing the mouse cursor or scrolled page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * to jump. Enable a workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) info->jumpy_cursor =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) (info->fw_version == 0x020022 || info->fw_version == 0x020600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) if (info->hw_version > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) /* For now show extra debug information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) info->debug = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) if (info->fw_version >= 0x020800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) info->reports_pressure = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) * The signatures of v3 and v4 packets change depending on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) * value of this hardware flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) info->crc_enabled = (info->fw_version & 0x4000) == 0x4000 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) dmi_check_system(elantech_dmi_force_crc_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) /* Enable real hardware resolution on hw_version 3 ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) info->set_hw_resolution = !dmi_check_system(no_hw_res_dmi_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) static int elantech_query_info(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) struct elantech_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) unsigned char param[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) unsigned char traces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) unsigned char ic_body[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) memset(info, 0, sizeof(*info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) * Do the version query again so we can store the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (synaptics_send_cmd(psmouse, ETP_FW_VERSION_QUERY, param)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) psmouse_err(psmouse, "failed to query firmware version.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) info->fw_version = (param[0] << 16) | (param[1] << 8) | param[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) if (elantech_set_properties(info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) psmouse_err(psmouse, "unknown hardware version, aborting...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) psmouse_info(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) "assuming hardware version %d (with firmware version 0x%02x%02x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) info->hw_version, param[0], param[1], param[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) if (info->send_cmd(psmouse, ETP_CAPABILITIES_QUERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) info->capabilities)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) psmouse_err(psmouse, "failed to query capabilities.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) psmouse_info(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) "Synaptics capabilities query result 0x%02x, 0x%02x, 0x%02x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) info->capabilities[0], info->capabilities[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) info->capabilities[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) if (info->hw_version != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) if (info->send_cmd(psmouse, ETP_SAMPLE_QUERY, info->samples)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) psmouse_err(psmouse, "failed to query sample data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) psmouse_info(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) "Elan sample query result %02x, %02x, %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) info->samples[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) info->samples[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) info->samples[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) if (info->pattern > 0x00 && info->ic_version == 0xf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) if (info->send_cmd(psmouse, ETP_ICBODY_QUERY, ic_body)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) psmouse_err(psmouse, "failed to query ic body\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) info->ic_version = be16_to_cpup((__be16 *)ic_body);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) psmouse_info(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) "Elan ic body: %#04x, current fw version: %#02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) info->ic_version, ic_body[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) info->product_id = be16_to_cpup((__be16 *)info->samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) if (info->pattern == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) info->product_id &= 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) if (info->samples[1] == 0x74 && info->hw_version == 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) * This module has a bug which makes absolute mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) * unusable, so let's abort so we'll be using standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) * PS/2 protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) psmouse_info(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) "absolute mode broken, forcing standard PS/2 protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) /* The MSB indicates the presence of the trackpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) info->has_trackpoint = (info->capabilities[0] & 0x80) == 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) if (info->has_trackpoint && info->ic_version == 0x0011 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) (info->product_id == 0x08 || info->product_id == 0x09 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) info->product_id == 0x0d || info->product_id == 0x0e)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) * This module has a bug which makes trackpoint in SMBus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) * mode return invalid data unless trackpoint is switched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) * from using 0x5e reports to 0x5f. If we are not able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) * make the switch, let's abort initialization so we'll be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) * using standard PS/2 protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) if (elantech_change_report_id(psmouse)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) psmouse_info(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) "Trackpoint report is broken, forcing standard PS/2 protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) info->x_res = 31;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) info->y_res = 31;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) if (info->hw_version == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) if (elantech_get_resolution_v4(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) &info->x_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) &info->y_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) &info->bus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) psmouse_warn(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) "failed to query resolution data.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) /* query range information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) switch (info->hw_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) info->x_min = ETP_XMIN_V1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) info->y_min = ETP_YMIN_V1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) info->x_max = ETP_XMAX_V1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) info->y_max = ETP_YMAX_V1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) if (info->fw_version == 0x020800 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) info->fw_version == 0x020b00 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) info->fw_version == 0x020030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) info->x_min = ETP_XMIN_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) info->y_min = ETP_YMIN_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) info->x_max = ETP_XMAX_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) info->y_max = ETP_YMAX_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) int fixed_dpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) i = (info->fw_version > 0x020800 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) info->fw_version < 0x020900) ? 1 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) if (info->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) fixed_dpi = param[1] & 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) if (((info->fw_version >> 16) == 0x14) && fixed_dpi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) if (info->send_cmd(psmouse, ETP_SAMPLE_QUERY, param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) info->x_max = (info->capabilities[1] - i) * param[1] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) info->y_max = (info->capabilities[2] - i) * param[2] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) } else if (info->fw_version == 0x040216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) info->x_max = 819;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) info->y_max = 405;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) } else if (info->fw_version == 0x040219 || info->fw_version == 0x040215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) info->x_max = 900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) info->y_max = 500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) info->x_max = (info->capabilities[1] - i) * 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) info->y_max = (info->capabilities[2] - i) * 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) if (info->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) info->x_max = (0x0f & param[0]) << 8 | param[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) info->y_max = (0xf0 & param[0]) << 4 | param[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) if (info->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) info->x_max = (0x0f & param[0]) << 8 | param[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) info->y_max = (0xf0 & param[0]) << 4 | param[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) traces = info->capabilities[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) if ((traces < 2) || (traces > info->x_max))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) info->width = info->x_max / (traces - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) /* column number of traces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) info->x_traces = traces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) /* row number of traces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) traces = info->capabilities[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) if ((traces >= 2) && (traces <= info->y_max))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) info->y_traces = traces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) /* check for the middle button: DMI matching or new v4 firmwares */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) info->has_middle_button = dmi_check_system(elantech_dmi_has_middle_button) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) (ETP_NEW_IC_SMBUS_HOST_NOTIFY(info->fw_version) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) !elantech_is_buttonpad(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) #if defined(CONFIG_MOUSE_PS2_ELANTECH_SMBUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) * The newest Elantech device can use a secondary bus (over SMBus) which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) * provides a better bandwidth and allow a better control of the touchpads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) * This is used to decide if we need to use this bus or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) ELANTECH_SMBUS_NOT_SET = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) ELANTECH_SMBUS_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) ELANTECH_SMBUS_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) static int elantech_smbus = IS_ENABLED(CONFIG_MOUSE_ELAN_I2C_SMBUS) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) ELANTECH_SMBUS_NOT_SET : ELANTECH_SMBUS_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) module_param_named(elantech_smbus, elantech_smbus, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) MODULE_PARM_DESC(elantech_smbus, "Use a secondary bus for the Elantech device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) static const char * const i2c_blacklist_pnp_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) * These are known to not be working properly as bits are missing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) * in elan_i2c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) static int elantech_create_smbus(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct elantech_device_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) bool leave_breadcrumbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) struct property_entry i2c_props[11] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) struct i2c_board_info smbus_board = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) I2C_BOARD_INFO("elan_i2c", 0x15),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) .flags = I2C_CLIENT_HOST_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) unsigned int idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) smbus_board.properties = i2c_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) i2c_props[idx++] = PROPERTY_ENTRY_U32("touchscreen-size-x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) info->x_max + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) i2c_props[idx++] = PROPERTY_ENTRY_U32("touchscreen-size-y",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) info->y_max + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) i2c_props[idx++] = PROPERTY_ENTRY_U32("touchscreen-min-x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) info->x_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) i2c_props[idx++] = PROPERTY_ENTRY_U32("touchscreen-min-y",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) info->y_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) if (info->x_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) i2c_props[idx++] = PROPERTY_ENTRY_U32("touchscreen-x-mm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) (info->x_max + 1) / info->x_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) if (info->y_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) i2c_props[idx++] = PROPERTY_ENTRY_U32("touchscreen-y-mm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) (info->y_max + 1) / info->y_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (info->has_trackpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) i2c_props[idx++] = PROPERTY_ENTRY_BOOL("elan,trackpoint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) if (info->has_middle_button)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) i2c_props[idx++] = PROPERTY_ENTRY_BOOL("elan,middle-button");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (info->x_traces)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) i2c_props[idx++] = PROPERTY_ENTRY_U32("elan,x_traces",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) info->x_traces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) if (info->y_traces)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) i2c_props[idx++] = PROPERTY_ENTRY_U32("elan,y_traces",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) info->y_traces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (elantech_is_buttonpad(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) i2c_props[idx++] = PROPERTY_ENTRY_BOOL("elan,clickpad");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) return psmouse_smbus_init(psmouse, &smbus_board, NULL, 0, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) leave_breadcrumbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) * elantech_setup_smbus - called once the PS/2 devices are enumerated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) * and decides to instantiate a SMBus InterTouch device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) static int elantech_setup_smbus(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) struct elantech_device_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) bool leave_breadcrumbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) if (elantech_smbus == ELANTECH_SMBUS_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) if (elantech_smbus == ELANTECH_SMBUS_NOT_SET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) * New ICs are enabled by default, unless mentioned in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) * i2c_blacklist_pnp_ids.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) * Old ICs are up to the user to decide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) if (!ETP_NEW_IC_SMBUS_HOST_NOTIFY(info->fw_version) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) psmouse_matches_pnp_id(psmouse, i2c_blacklist_pnp_ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) psmouse_info(psmouse, "Trying to set up SMBus access\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) error = elantech_create_smbus(psmouse, info, leave_breadcrumbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) if (error == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) psmouse_info(psmouse, "SMbus companion is not ready yet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) psmouse_err(psmouse, "unable to create intertouch device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) static bool elantech_use_host_notify(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) struct elantech_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) if (ETP_NEW_IC_SMBUS_HOST_NOTIFY(info->fw_version))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) switch (info->bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) case ETP_BUS_PS2_ONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) /* expected case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) case ETP_BUS_SMB_ALERT_ONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) case ETP_BUS_PS2_SMB_ALERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) psmouse_dbg(psmouse, "Ignoring SMBus provider through alert protocol.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) case ETP_BUS_SMB_HST_NTFY_ONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) case ETP_BUS_PS2_SMB_HST_NTFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) psmouse_dbg(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) "Ignoring SMBus bus provider %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) info->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) int elantech_init_smbus(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) struct elantech_device_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) error = elantech_query_info(psmouse, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (info.hw_version < 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) error = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) return elantech_create_smbus(psmouse, &info, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) init_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) #endif /* CONFIG_MOUSE_PS2_ELANTECH_SMBUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) * Initialize the touchpad and create sysfs entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) static int elantech_setup_ps2(struct psmouse *psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) struct elantech_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) struct elantech_data *etd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) int error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) struct input_dev *tp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) psmouse->private = etd = kzalloc(sizeof(*etd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) if (!etd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) etd->info = *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) etd->parity[0] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) for (i = 1; i < 256; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) etd->parity[i] = etd->parity[i & (i - 1)] ^ 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) if (elantech_set_absolute_mode(psmouse)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) "failed to put touchpad into absolute mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) if (info->fw_version == 0x381f17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) etd->original_set_rate = psmouse->set_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) psmouse->set_rate = elantech_set_rate_restore_reg_07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) if (elantech_set_input_params(psmouse)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) psmouse_err(psmouse, "failed to query touchpad range.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) error = sysfs_create_group(&psmouse->ps2dev.serio->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) &elantech_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) psmouse_err(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) "failed to create sysfs attributes, error: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) if (info->has_trackpoint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) tp_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (!tp_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) goto init_fail_tp_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) etd->tp_dev = tp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) snprintf(etd->tp_phys, sizeof(etd->tp_phys), "%s/input1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) psmouse->ps2dev.serio->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) tp_dev->phys = etd->tp_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) tp_dev->name = "ETPS/2 Elantech TrackPoint";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) tp_dev->id.bustype = BUS_I8042;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) tp_dev->id.vendor = 0x0002;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) tp_dev->id.product = PSMOUSE_ELANTECH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) tp_dev->id.version = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) tp_dev->dev.parent = &psmouse->ps2dev.serio->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) tp_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) tp_dev->relbit[BIT_WORD(REL_X)] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) tp_dev->keybit[BIT_WORD(BTN_LEFT)] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) BIT_MASK(BTN_RIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) __set_bit(INPUT_PROP_POINTER, tp_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) __set_bit(INPUT_PROP_POINTING_STICK, tp_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) error = input_register_device(etd->tp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) goto init_fail_tp_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) psmouse->protocol_handler = elantech_process_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) psmouse->disconnect = elantech_disconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) psmouse->reconnect = elantech_reconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) psmouse->pktsize = info->hw_version > 1 ? 6 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) init_fail_tp_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) input_free_device(tp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) init_fail_tp_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) &elantech_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) init_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) kfree(etd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) int elantech_init_ps2(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) struct elantech_device_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) error = elantech_query_info(psmouse, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) error = elantech_setup_ps2(psmouse, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) init_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) int elantech_init(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) struct elantech_device_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) error = elantech_query_info(psmouse, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) #if defined(CONFIG_MOUSE_PS2_ELANTECH_SMBUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) if (elantech_use_host_notify(psmouse, &info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) if (!IS_ENABLED(CONFIG_MOUSE_ELAN_I2C_SMBUS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) !IS_ENABLED(CONFIG_MOUSE_PS2_ELANTECH_SMBUS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) psmouse_warn(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) "The touchpad can support a better bus than the too old PS/2 protocol. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) "Make sure MOUSE_PS2_ELANTECH_SMBUS and MOUSE_ELAN_I2C_SMBUS are enabled to get a better touchpad experience.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) error = elantech_setup_smbus(psmouse, &info, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) return PSMOUSE_ELANTECH_SMBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) #endif /* CONFIG_MOUSE_PS2_ELANTECH_SMBUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) error = elantech_setup_ps2(psmouse, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) * Not using any flavor of Elantech support, so clean up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) * SMbus breadcrumbs, if any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) psmouse_smbus_cleanup(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) goto init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) return PSMOUSE_ELANTECH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) init_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) }