^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) * ALPS touchpad PS/2 mouse driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _ALPS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _ALPS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define ALPS_PROTO_V1 0x100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define ALPS_PROTO_V2 0x200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ALPS_PROTO_V3 0x300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ALPS_PROTO_V3_RUSHMORE 0x310
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ALPS_PROTO_V4 0x400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ALPS_PROTO_V5 0x500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ALPS_PROTO_V6 0x600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ALPS_PROTO_V7 0x700 /* t3btl t4s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ALPS_PROTO_V8 0x800 /* SS4btl SS4s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ALPS_PROTO_V9 0x900 /* ss3btl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define MAX_TOUCHES 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DOLPHIN_COUNT_PER_ELECTRODE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DOLPHIN_PROFILE_XOFFSET 8 /* x-electrode offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define DOLPHIN_PROFILE_YOFFSET 1 /* y-electrode offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * enum SS4_PACKET_ID - defines the packet type for V8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * SS4_PACKET_ID_IDLE: There's no finger and no button activity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * SS4_PACKET_ID_ONE: There's one finger on touchpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * or there's button activities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * SS4_PACKET_ID_TWO: There's two or more fingers on touchpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * SS4_PACKET_ID_MULTI: There's three or more fingers on touchpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * SS4_PACKET_ID_STICK: A stick pointer packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) enum SS4_PACKET_ID {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) SS4_PACKET_ID_IDLE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) SS4_PACKET_ID_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) SS4_PACKET_ID_TWO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) SS4_PACKET_ID_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) SS4_PACKET_ID_STICK,
^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) #define SS4_COUNT_PER_ELECTRODE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define SS4_NUMSENSOR_XOFFSET 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define SS4_NUMSENSOR_YOFFSET 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define SS4_MIN_PITCH_MM 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define SS4_MASK_NORMAL_BUTTONS 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define SS4PLUS_COUNT_PER_ELECTRODE 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define SS4PLUS_NUMSENSOR_XOFFSET 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define SS4PLUS_NUMSENSOR_YOFFSET 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define SS4PLUS_MIN_PITCH_MM 37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define IS_SS4PLUS_DEV(_b) (((_b[0]) == 0x73) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ((_b[1]) == 0x03) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ((_b[2]) == 0x28) \
^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) #define SS4_IS_IDLE_V2(_b) (((_b[0]) == 0x18) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ((_b[1]) == 0x10) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ((_b[2]) == 0x00) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ((_b[3] & 0x88) == 0x08) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ((_b[4]) == 0x10) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ((_b[5]) == 0x00) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define SS4_1F_X_V2(_b) (((_b[0]) & 0x0007) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ((_b[1] << 3) & 0x0078) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ((_b[1] << 2) & 0x0380) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ((_b[2] << 5) & 0x1C00) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define SS4_1F_Y_V2(_b) (((_b[2]) & 0x000F) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ((_b[3] >> 2) & 0x0030) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ((_b[4] << 6) & 0x03C0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ((_b[4] << 5) & 0x0C00) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define SS4_1F_Z_V2(_b) (((_b[5]) & 0x0F) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ((_b[5] >> 1) & 0x70) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ((_b[4]) & 0x80) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define SS4_1F_LFB_V2(_b) (((_b[2] >> 4) & 0x01) == 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define SS4_MF_LF_V2(_b, _i) ((_b[1 + (_i) * 3] & 0x0004) == 0x0004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define SS4_BTN_V2(_b) ((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define SS4_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 5) & 0x00E0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ((_b[1 + _i * 3] << 5) & 0x1F00) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define SS4_PLUS_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 4) & 0x0070) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ((_b[1 + (_i) * 3] << 4) & 0x0F80) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define SS4_STD_MF_Y_V2(_b, _i) (((_b[1 + (_i) * 3] << 3) & 0x0010) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ((_b[2 + (_i) * 3] << 5) & 0x01E0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ((_b[2 + (_i) * 3] << 4) & 0x0E00) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define SS4_BTL_MF_X_V2(_b, _i) (SS4_STD_MF_X_V2(_b, _i) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ((_b[0 + (_i) * 3] >> 3) & 0x0010) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define SS4_PLUS_BTL_MF_X_V2(_b, _i) (SS4_PLUS_STD_MF_X_V2(_b, _i) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ((_b[0 + (_i) * 3] >> 4) & 0x0008) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define SS4_BTL_MF_Y_V2(_b, _i) (SS4_STD_MF_Y_V2(_b, _i) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ((_b[0 + (_i) * 3] >> 3) & 0x0008) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define SS4_MF_Z_V2(_b, _i) (((_b[1 + (_i) * 3]) & 0x0001) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ((_b[1 + (_i) * 3] >> 1) & 0x0002) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define SS4_IS_MF_CONTINUE(_b) ((_b[2] & 0x10) == 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define SS4_IS_5F_DETECTED(_b) ((_b[2] & 0x10) == 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define SS4_TS_X_V2(_b) (s8)( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ((_b[0] & 0x01) << 7) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) (_b[1] & 0x7F) \
^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) #define SS4_TS_Y_V2(_b) -(s8)( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ((_b[3] & 0x01) << 7) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) (_b[2] & 0x7F) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define SS4_TS_Z_V2(_b) (s8)(_b[4] & 0x7F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define SS4_MFPACKET_NO_AX 8160 /* X-Coordinate value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define SS4_MFPACKET_NO_AY 4080 /* Y-Coordinate value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define SS4_MFPACKET_NO_AX_BL 8176 /* Buttonless X-Coord value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define SS4_MFPACKET_NO_AY_BL 4088 /* Buttonless Y-Coord value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define SS4_PLUS_MFPACKET_NO_AX 4080 /* SS4 PLUS, X */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define SS4_PLUS_MFPACKET_NO_AX_BL 4088 /* Buttonless SS4 PLUS, X */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * enum V7_PACKET_ID - defines the packet type for V7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * V7_PACKET_ID_IDLE: There's no finger and no button activity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * or there's button activities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * V7_PACKET_ID_NEW: The finger position in slot is not continues from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * previous packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) enum V7_PACKET_ID {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) V7_PACKET_ID_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) V7_PACKET_ID_TWO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) V7_PACKET_ID_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) V7_PACKET_ID_NEW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) V7_PACKET_ID_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * struct alps_protocol_info - information about protocol used by a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @version: Indicates V1/V2/V3/...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @byte0: Helps figure out whether a position report packet matches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * known format for this model. The first byte of the report, ANDed with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * mask0, should match byte0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * @mask0: The mask used to check the first byte of the report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct alps_protocol_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u8 byte0, mask0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * struct alps_model_info - touchpad ID table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * @signature: E7 response string to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * @protocol_info: information about protocol used by the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Many (but not all) ALPS touchpads can be identified by looking at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * values returned in the "E7 report" and/or the "EC report." This table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * lists a number of such touchpads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct alps_model_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) u8 signature[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct alps_protocol_info protocol_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * struct alps_nibble_commands - encodings for register accesses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * @command: PS/2 command used for the nibble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * @data: Data supplied as an argument to the PS/2 command, if applicable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * The ALPS protocol uses magic sequences to transmit binary data to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * touchpad, as it is generally not OK to send arbitrary bytes out the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * PS/2 port. Each of the sequences in this table sends one nibble of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * register address or (write) data. Different versions of the ALPS protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * use slightly different encodings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct alps_nibble_commands {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned char data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct alps_bitmap_point {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int start_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int num_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * struct alps_fields - decoded version of the report packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * @x_map: Bitmap of active X positions for MT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * @y_map: Bitmap of active Y positions for MT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * @fingers: Number of fingers for MT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @pressure: Pressure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @st: position for ST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * @mt: position for MT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * @first_mp: Packet is the first of a multi-packet report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * @is_mp: Packet is part of a multi-packet report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @left: Left touchpad button is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @right: Right touchpad button is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * @middle: Middle touchpad button is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * @ts_left: Left trackstick button is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * @ts_right: Right trackstick button is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * @ts_middle: Middle trackstick button is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct alps_fields {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned int x_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) unsigned int y_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) unsigned int fingers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct input_mt_pos st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct input_mt_pos mt[MAX_TOUCHES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned int first_mp:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned int is_mp:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) unsigned int left:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) unsigned int right:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) unsigned int middle:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) unsigned int ts_left:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) unsigned int ts_right:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned int ts_middle:1;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * struct alps_data - private data structure for the ALPS driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * @psmouse: Pointer to parent psmouse device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * @dev2: Trackstick device (can be NULL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * @phys2: Physical path for the trackstick device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * @phys3: Physical path for the generic PS/2 mouse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * @dev3_register_work: Delayed work for registering PS/2 mouse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * @nibble_commands: Command mapping used for touchpad register accesses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * @addr_command: Command used to tell the touchpad that a register address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * follows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * @proto_version: Indicates V1/V2/V3/...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * @byte0: Helps figure out whether a position report packet matches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * known format for this model. The first byte of the report, ANDed with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * mask0, should match byte0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * @mask0: The mask used to check the first byte of the report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * @fw_ver: cached copy of firmware version (EC report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * @x_max: Largest possible X position value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * @y_max: Largest possible Y position value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @x_bits: Number of X bits in the MT bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * @y_bits: Number of Y bits in the MT bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * @hw_init: Protocol-specific hardware init function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * @process_packet: Protocol-specific function to process a report packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * @decode_fields: Protocol-specific function to read packet bitfields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * @set_abs_params: Protocol-specific function to configure the input_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * @prev_fin: Finger bit from previous packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * @multi_packet: Multi-packet data in progress.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @multi_data: Saved multi-packet data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * @f: Decoded packet data fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @quirks: Bitmap of ALPS_QUIRK_*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @timer: Timer for flushing out the final report packet in the stream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct alps_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct psmouse *psmouse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct input_dev *dev2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct input_dev *dev3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) char phys2[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) char phys3[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct delayed_work dev3_register_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* these are autodetected when the device is identified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) const struct alps_nibble_commands *nibble_commands;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int addr_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) u16 proto_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) u8 byte0, mask0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) u8 dev_id[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) u8 fw_ver[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int x_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int y_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int x_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int y_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) unsigned int x_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) unsigned int y_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int (*hw_init)(struct psmouse *psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) void (*process_packet)(struct psmouse *psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int (*decode_fields)(struct alps_fields *f, unsigned char *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct psmouse *psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int prev_fin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int multi_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int second_touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) unsigned char multi_data[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct alps_fields f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) u8 quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int alps_detect(struct psmouse *psmouse, bool set_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int alps_init(struct psmouse *psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #endif