Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ALPS touchpad PS/2 mouse driver
0004  *
0005  * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
0006  * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
0007  */
0008 
0009 #ifndef _ALPS_H
0010 #define _ALPS_H
0011 
0012 #include <linux/input/mt.h>
0013 
0014 #define ALPS_PROTO_V1       0x100
0015 #define ALPS_PROTO_V2       0x200
0016 #define ALPS_PROTO_V3       0x300
0017 #define ALPS_PROTO_V3_RUSHMORE  0x310
0018 #define ALPS_PROTO_V4       0x400
0019 #define ALPS_PROTO_V5       0x500
0020 #define ALPS_PROTO_V6       0x600
0021 #define ALPS_PROTO_V7       0x700   /* t3btl t4s */
0022 #define ALPS_PROTO_V8       0x800   /* SS4btl SS4s */
0023 #define ALPS_PROTO_V9       0x900   /* ss3btl */
0024 
0025 #define MAX_TOUCHES 4
0026 
0027 #define DOLPHIN_COUNT_PER_ELECTRODE 64
0028 #define DOLPHIN_PROFILE_XOFFSET     8   /* x-electrode offset */
0029 #define DOLPHIN_PROFILE_YOFFSET     1   /* y-electrode offset */
0030 
0031 /*
0032  * enum SS4_PACKET_ID - defines the packet type for V8
0033  * SS4_PACKET_ID_IDLE: There's no finger and no button activity.
0034  * SS4_PACKET_ID_ONE: There's one finger on touchpad
0035  *  or there's button activities.
0036  * SS4_PACKET_ID_TWO: There's two or more fingers on touchpad
0037  * SS4_PACKET_ID_MULTI: There's three or more fingers on touchpad
0038  * SS4_PACKET_ID_STICK: A stick pointer packet
0039 */
0040 enum SS4_PACKET_ID {
0041     SS4_PACKET_ID_IDLE = 0,
0042     SS4_PACKET_ID_ONE,
0043     SS4_PACKET_ID_TWO,
0044     SS4_PACKET_ID_MULTI,
0045     SS4_PACKET_ID_STICK,
0046 };
0047 
0048 #define SS4_COUNT_PER_ELECTRODE     256
0049 #define SS4_NUMSENSOR_XOFFSET       7
0050 #define SS4_NUMSENSOR_YOFFSET       7
0051 #define SS4_MIN_PITCH_MM        50
0052 
0053 #define SS4_MASK_NORMAL_BUTTONS     0x07
0054 
0055 #define SS4PLUS_COUNT_PER_ELECTRODE 128
0056 #define SS4PLUS_NUMSENSOR_XOFFSET   16
0057 #define SS4PLUS_NUMSENSOR_YOFFSET   5
0058 #define SS4PLUS_MIN_PITCH_MM        37
0059 
0060 #define IS_SS4PLUS_DEV(_b)  (((_b[0]) == 0x73) &&   \
0061                  ((_b[1]) == 0x03) &&   \
0062                  ((_b[2]) == 0x28)      \
0063                 )
0064 
0065 #define SS4_IS_IDLE_V2(_b)  (((_b[0]) == 0x18) &&       \
0066                  ((_b[1]) == 0x10) &&       \
0067                  ((_b[2]) == 0x00) &&       \
0068                  ((_b[3] & 0x88) == 0x08) &&    \
0069                  ((_b[4]) == 0x10) &&       \
0070                  ((_b[5]) == 0x00)      \
0071                 )
0072 
0073 #define SS4_1F_X_V2(_b)     (((_b[0]) & 0x0007) |       \
0074                  ((_b[1] << 3) & 0x0078) |  \
0075                  ((_b[1] << 2) & 0x0380) |  \
0076                  ((_b[2] << 5) & 0x1C00)    \
0077                 )
0078 
0079 #define SS4_1F_Y_V2(_b)     (((_b[2]) & 0x000F) |       \
0080                  ((_b[3] >> 2) & 0x0030) |  \
0081                  ((_b[4] << 6) & 0x03C0) |  \
0082                  ((_b[4] << 5) & 0x0C00)    \
0083                 )
0084 
0085 #define SS4_1F_Z_V2(_b)     (((_b[5]) & 0x0F) |     \
0086                  ((_b[5] >> 1) & 0x70) |    \
0087                  ((_b[4]) & 0x80)       \
0088                 )
0089 
0090 #define SS4_1F_LFB_V2(_b)   (((_b[2] >> 4) & 0x01) == 0x01)
0091 
0092 #define SS4_MF_LF_V2(_b, _i)    ((_b[1 + (_i) * 3] & 0x0004) == 0x0004)
0093 
0094 #define SS4_BTN_V2(_b)      ((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS)
0095 
0096 #define SS4_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 5) & 0x00E0) |   \
0097                  ((_b[1 + _i * 3]  << 5) & 0x1F00)  \
0098                 )
0099 
0100 #define SS4_PLUS_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 4) & 0x0070) | \
0101                  ((_b[1 + (_i) * 3]  << 4) & 0x0F80)    \
0102                 )
0103 
0104 #define SS4_STD_MF_Y_V2(_b, _i) (((_b[1 + (_i) * 3] << 3) & 0x0010) |   \
0105                  ((_b[2 + (_i) * 3] << 5) & 0x01E0) |   \
0106                  ((_b[2 + (_i) * 3] << 4) & 0x0E00) \
0107                 )
0108 
0109 #define SS4_BTL_MF_X_V2(_b, _i) (SS4_STD_MF_X_V2(_b, _i) |      \
0110                  ((_b[0 + (_i) * 3] >> 3) & 0x0010) \
0111                 )
0112 
0113 #define SS4_PLUS_BTL_MF_X_V2(_b, _i) (SS4_PLUS_STD_MF_X_V2(_b, _i) |    \
0114                  ((_b[0 + (_i) * 3] >> 4) & 0x0008) \
0115                 )
0116 
0117 #define SS4_BTL_MF_Y_V2(_b, _i) (SS4_STD_MF_Y_V2(_b, _i) | \
0118                  ((_b[0 + (_i) * 3] >> 3) & 0x0008) \
0119                 )
0120 
0121 #define SS4_MF_Z_V2(_b, _i) (((_b[1 + (_i) * 3]) & 0x0001) |    \
0122                  ((_b[1 + (_i) * 3] >> 1) & 0x0002) \
0123                 )
0124 
0125 #define SS4_IS_MF_CONTINUE(_b)  ((_b[2] & 0x10) == 0x10)
0126 #define SS4_IS_5F_DETECTED(_b)  ((_b[2] & 0x10) == 0x10)
0127 
0128 #define SS4_TS_X_V2(_b)     (s8)(               \
0129                  ((_b[0] & 0x01) << 7) |    \
0130                  (_b[1] & 0x7F)     \
0131                 )
0132 
0133 #define SS4_TS_Y_V2(_b)     -(s8)(              \
0134                  ((_b[3] & 0x01) << 7) |    \
0135                  (_b[2] & 0x7F)     \
0136                 )
0137 
0138 #define SS4_TS_Z_V2(_b)     (s8)(_b[4] & 0x7F)
0139 
0140 
0141 #define SS4_MFPACKET_NO_AX      8160    /* X-Coordinate value */
0142 #define SS4_MFPACKET_NO_AY      4080    /* Y-Coordinate value */
0143 #define SS4_MFPACKET_NO_AX_BL       8176    /* Buttonless X-Coord value */
0144 #define SS4_MFPACKET_NO_AY_BL       4088    /* Buttonless Y-Coord value */
0145 #define SS4_PLUS_MFPACKET_NO_AX     4080    /* SS4 PLUS, X */
0146 #define SS4_PLUS_MFPACKET_NO_AX_BL  4088    /* Buttonless SS4 PLUS, X */
0147 
0148 /*
0149  * enum V7_PACKET_ID - defines the packet type for V7
0150  * V7_PACKET_ID_IDLE: There's no finger and no button activity.
0151  * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
0152  *  or there's button activities.
0153  * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
0154  * V7_PACKET_ID_NEW: The finger position in slot is not continues from
0155  *  previous packet.
0156 */
0157 enum V7_PACKET_ID {
0158      V7_PACKET_ID_IDLE,
0159      V7_PACKET_ID_TWO,
0160      V7_PACKET_ID_MULTI,
0161      V7_PACKET_ID_NEW,
0162      V7_PACKET_ID_UNKNOWN,
0163 };
0164 
0165 /**
0166  * struct alps_protocol_info - information about protocol used by a device
0167  * @version: Indicates V1/V2/V3/...
0168  * @byte0: Helps figure out whether a position report packet matches the
0169  *   known format for this model.  The first byte of the report, ANDed with
0170  *   mask0, should match byte0.
0171  * @mask0: The mask used to check the first byte of the report.
0172  * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
0173  */
0174 struct alps_protocol_info {
0175     u16 version;
0176     u8 byte0, mask0;
0177     unsigned int flags;
0178 };
0179 
0180 /**
0181  * struct alps_model_info - touchpad ID table
0182  * @signature: E7 response string to match.
0183  * @protocol_info: information about protocol used by the device.
0184  *
0185  * Many (but not all) ALPS touchpads can be identified by looking at the
0186  * values returned in the "E7 report" and/or the "EC report."  This table
0187  * lists a number of such touchpads.
0188  */
0189 struct alps_model_info {
0190     u8 signature[3];
0191     struct alps_protocol_info protocol_info;
0192 };
0193 
0194 /**
0195  * struct alps_nibble_commands - encodings for register accesses
0196  * @command: PS/2 command used for the nibble
0197  * @data: Data supplied as an argument to the PS/2 command, if applicable
0198  *
0199  * The ALPS protocol uses magic sequences to transmit binary data to the
0200  * touchpad, as it is generally not OK to send arbitrary bytes out the
0201  * PS/2 port.  Each of the sequences in this table sends one nibble of the
0202  * register address or (write) data.  Different versions of the ALPS protocol
0203  * use slightly different encodings.
0204  */
0205 struct alps_nibble_commands {
0206     int command;
0207     unsigned char data;
0208 };
0209 
0210 struct alps_bitmap_point {
0211     int start_bit;
0212     int num_bits;
0213 };
0214 
0215 /**
0216  * struct alps_fields - decoded version of the report packet
0217  * @x_map: Bitmap of active X positions for MT.
0218  * @y_map: Bitmap of active Y positions for MT.
0219  * @fingers: Number of fingers for MT.
0220  * @pressure: Pressure.
0221  * @st: position for ST.
0222  * @mt: position for MT.
0223  * @first_mp: Packet is the first of a multi-packet report.
0224  * @is_mp: Packet is part of a multi-packet report.
0225  * @left: Left touchpad button is active.
0226  * @right: Right touchpad button is active.
0227  * @middle: Middle touchpad button is active.
0228  * @ts_left: Left trackstick button is active.
0229  * @ts_right: Right trackstick button is active.
0230  * @ts_middle: Middle trackstick button is active.
0231  */
0232 struct alps_fields {
0233     unsigned int x_map;
0234     unsigned int y_map;
0235     unsigned int fingers;
0236 
0237     int pressure;
0238     struct input_mt_pos st;
0239     struct input_mt_pos mt[MAX_TOUCHES];
0240 
0241     unsigned int first_mp:1;
0242     unsigned int is_mp:1;
0243 
0244     unsigned int left:1;
0245     unsigned int right:1;
0246     unsigned int middle:1;
0247 
0248     unsigned int ts_left:1;
0249     unsigned int ts_right:1;
0250     unsigned int ts_middle:1;
0251 };
0252 
0253 /**
0254  * struct alps_data - private data structure for the ALPS driver
0255  * @psmouse: Pointer to parent psmouse device
0256  * @dev2: Trackstick device (can be NULL).
0257  * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
0258  * @phys2: Physical path for the trackstick device.
0259  * @phys3: Physical path for the generic PS/2 mouse.
0260  * @dev3_register_work: Delayed work for registering PS/2 mouse.
0261  * @nibble_commands: Command mapping used for touchpad register accesses.
0262  * @addr_command: Command used to tell the touchpad that a register address
0263  *   follows.
0264  * @proto_version: Indicates V1/V2/V3/...
0265  * @byte0: Helps figure out whether a position report packet matches the
0266  *   known format for this model.  The first byte of the report, ANDed with
0267  *   mask0, should match byte0.
0268  * @mask0: The mask used to check the first byte of the report.
0269  * @fw_ver: cached copy of firmware version (EC report)
0270  * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
0271  * @x_max: Largest possible X position value.
0272  * @y_max: Largest possible Y position value.
0273  * @x_bits: Number of X bits in the MT bitmap.
0274  * @y_bits: Number of Y bits in the MT bitmap.
0275  * @hw_init: Protocol-specific hardware init function.
0276  * @process_packet: Protocol-specific function to process a report packet.
0277  * @decode_fields: Protocol-specific function to read packet bitfields.
0278  * @set_abs_params: Protocol-specific function to configure the input_dev.
0279  * @prev_fin: Finger bit from previous packet.
0280  * @multi_packet: Multi-packet data in progress.
0281  * @multi_data: Saved multi-packet data.
0282  * @f: Decoded packet data fields.
0283  * @quirks: Bitmap of ALPS_QUIRK_*.
0284  * @timer: Timer for flushing out the final report packet in the stream.
0285  */
0286 struct alps_data {
0287     struct psmouse *psmouse;
0288     struct input_dev *dev2;
0289     struct input_dev *dev3;
0290     char phys2[32];
0291     char phys3[32];
0292     struct delayed_work dev3_register_work;
0293 
0294     /* these are autodetected when the device is identified */
0295     const struct alps_nibble_commands *nibble_commands;
0296     int addr_command;
0297     u16 proto_version;
0298     u8 byte0, mask0;
0299     u8 dev_id[3];
0300     u8 fw_ver[3];
0301     int flags;
0302     int x_max;
0303     int y_max;
0304     int x_bits;
0305     int y_bits;
0306     unsigned int x_res;
0307     unsigned int y_res;
0308 
0309     int (*hw_init)(struct psmouse *psmouse);
0310     void (*process_packet)(struct psmouse *psmouse);
0311     int (*decode_fields)(struct alps_fields *f, unsigned char *p,
0312                   struct psmouse *psmouse);
0313     void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
0314 
0315     int prev_fin;
0316     int multi_packet;
0317     int second_touch;
0318     unsigned char multi_data[6];
0319     struct alps_fields f;
0320     u8 quirks;
0321     struct timer_list timer;
0322 };
0323 
0324 #define ALPS_QUIRK_TRACKSTICK_BUTTONS   1 /* trakcstick buttons in trackstick packet */
0325 
0326 int alps_detect(struct psmouse *psmouse, bool set_properties);
0327 int alps_init(struct psmouse *psmouse);
0328 
0329 #endif