1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _PSMOUSE_H 3 #define _PSMOUSE_H 4 5 #define PSMOUSE_OOB_NONE 0x00 6 #define PSMOUSE_OOB_EXTRA_BTNS 0x01 7 8 #define PSMOUSE_CMD_SETSCALE11 0x00e6 9 #define PSMOUSE_CMD_SETSCALE21 0x00e7 10 #define PSMOUSE_CMD_SETRES 0x10e8 11 #define PSMOUSE_CMD_GETINFO 0x03e9 12 #define PSMOUSE_CMD_SETSTREAM 0x00ea 13 #define PSMOUSE_CMD_SETPOLL 0x00f0 14 #define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */ 15 #define PSMOUSE_CMD_RESET_WRAP 0x00ec 16 #define PSMOUSE_CMD_GETID 0x02f2 17 #define PSMOUSE_CMD_SETRATE 0x10f3 18 #define PSMOUSE_CMD_ENABLE 0x00f4 19 #define PSMOUSE_CMD_DISABLE 0x00f5 20 #define PSMOUSE_CMD_RESET_DIS 0x00f6 21 #define PSMOUSE_CMD_RESET_BAT 0x02ff 22 23 #define PSMOUSE_RET_BAT 0xaa 24 #define PSMOUSE_RET_ID 0x00 25 #define PSMOUSE_RET_ACK 0xfa 26 #define PSMOUSE_RET_NAK 0xfe 27 28 enum psmouse_state { 29 PSMOUSE_IGNORE, 30 PSMOUSE_INITIALIZING, 31 PSMOUSE_RESYNCING, 32 PSMOUSE_CMD_MODE, 33 PSMOUSE_ACTIVATED, 34 }; 35 36 /* psmouse protocol handler return codes */ 37 typedef enum { 38 PSMOUSE_BAD_DATA, 39 PSMOUSE_GOOD_DATA, 40 PSMOUSE_FULL_PACKET 41 } psmouse_ret_t; 42 43 enum psmouse_scale { 44 PSMOUSE_SCALE11, 45 PSMOUSE_SCALE21 46 }; 47 48 enum psmouse_type { 49 PSMOUSE_NONE, 50 PSMOUSE_PS2, 51 PSMOUSE_PS2PP, 52 PSMOUSE_THINKPS, 53 PSMOUSE_GENPS, 54 PSMOUSE_IMPS, 55 PSMOUSE_IMEX, 56 PSMOUSE_SYNAPTICS, 57 PSMOUSE_ALPS, 58 PSMOUSE_LIFEBOOK, 59 PSMOUSE_TRACKPOINT, 60 PSMOUSE_TOUCHKIT_PS2, 61 PSMOUSE_CORTRON, 62 PSMOUSE_HGPK, 63 PSMOUSE_ELANTECH, 64 PSMOUSE_FSP, 65 PSMOUSE_SYNAPTICS_RELATIVE, 66 PSMOUSE_CYPRESS, 67 PSMOUSE_FOCALTECH, 68 PSMOUSE_VMMOUSE, 69 PSMOUSE_BYD, 70 PSMOUSE_SYNAPTICS_SMBUS, 71 PSMOUSE_ELANTECH_SMBUS, 72 PSMOUSE_PIXART, 73 PSMOUSE_AUTO /* This one should always be last */ 74 }; 75 76 struct psmouse; 77 78 struct psmouse_protocol { 79 enum psmouse_type type; 80 bool maxproto; 81 bool ignore_parity; /* Protocol should ignore parity errors from KBC */ 82 bool try_passthru; /* Try protocol also on passthrough ports */ 83 bool smbus_companion; /* "Protocol" is a stub, device is on SMBus */ 84 const char *name; 85 const char *alias; 86 int (*detect)(struct psmouse *, bool); 87 int (*init)(struct psmouse *); 88 }; 89 90 struct psmouse { 91 void *private; 92 struct input_dev *dev; 93 struct ps2dev ps2dev; 94 struct delayed_work resync_work; 95 const char *vendor; 96 const char *name; 97 const struct psmouse_protocol *protocol; 98 unsigned char packet[16]; 99 unsigned char badbyte; 100 unsigned char pktcnt; 101 unsigned char pktsize; 102 unsigned char oob_data_type; 103 unsigned char extra_buttons; 104 bool acks_disable_command; 105 unsigned int model; 106 unsigned long last; 107 unsigned long out_of_sync_cnt; 108 unsigned long num_resyncs; 109 enum psmouse_state state; 110 char devname[64]; 111 char phys[32]; 112 113 unsigned int rate; 114 unsigned int resolution; 115 unsigned int resetafter; 116 unsigned int resync_time; 117 bool smartscroll; /* Logitech only */ 118 119 psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse); 120 void (*set_rate)(struct psmouse *psmouse, unsigned int rate); 121 void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution); 122 void (*set_scale)(struct psmouse *psmouse, enum psmouse_scale scale); 123 124 int (*reconnect)(struct psmouse *psmouse); 125 int (*fast_reconnect)(struct psmouse *psmouse); 126 void (*disconnect)(struct psmouse *psmouse); 127 void (*cleanup)(struct psmouse *psmouse); 128 int (*poll)(struct psmouse *psmouse); 129 130 void (*pt_activate)(struct psmouse *psmouse); 131 void (*pt_deactivate)(struct psmouse *psmouse); 132 }; 133 134 struct psmouse *psmouse_from_serio(struct serio *serio); 135 136 void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, 137 unsigned long delay); 138 int psmouse_reset(struct psmouse *psmouse); 139 void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state); 140 void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution); 141 psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse); 142 int psmouse_activate(struct psmouse *psmouse); 143 int psmouse_deactivate(struct psmouse *psmouse); 144 bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]); 145 146 void psmouse_report_standard_buttons(struct input_dev *, u8 buttons); 147 void psmouse_report_standard_motion(struct input_dev *, u8 *packet); 148 void psmouse_report_standard_packet(struct input_dev *, u8 *packet); 149 150 struct psmouse_attribute { 151 struct device_attribute dattr; 152 void *data; 153 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf); 154 ssize_t (*set)(struct psmouse *psmouse, void *data, 155 const char *buf, size_t count); 156 bool protect; 157 }; 158 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr) 159 160 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr, 161 char *buf); 162 ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr, 163 const char *buf, size_t count); 164 165 #define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \ 166 static struct psmouse_attribute psmouse_attr_##_name = { \ 167 .dattr = { \ 168 .attr = { \ 169 .name = __stringify(_name), \ 170 .mode = _mode, \ 171 }, \ 172 .show = psmouse_attr_show_helper, \ 173 .store = psmouse_attr_set_helper, \ 174 }, \ 175 .data = _data, \ 176 .show = _show, \ 177 .set = _set, \ 178 .protect = _protect, \ 179 } 180 181 #define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \ 182 static ssize_t _show(struct psmouse *, void *, char *); \ 183 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \ 184 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) 185 186 #define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \ 187 __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true) 188 189 #define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \ 190 static ssize_t _show(struct psmouse *, void *, char *); \ 191 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true) 192 193 #define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \ 194 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \ 195 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true) 196 197 #ifndef psmouse_fmt 198 #define psmouse_fmt(fmt) KBUILD_BASENAME ": " fmt 199 #endif 200 201 #define psmouse_dbg(psmouse, format, ...) \ 202 dev_dbg(&(psmouse)->ps2dev.serio->dev, \ 203 psmouse_fmt(format), ##__VA_ARGS__) 204 #define psmouse_info(psmouse, format, ...) \ 205 dev_info(&(psmouse)->ps2dev.serio->dev, \ 206 psmouse_fmt(format), ##__VA_ARGS__) 207 #define psmouse_warn(psmouse, format, ...) \ 208 dev_warn(&(psmouse)->ps2dev.serio->dev, \ 209 psmouse_fmt(format), ##__VA_ARGS__) 210 #define psmouse_err(psmouse, format, ...) \ 211 dev_err(&(psmouse)->ps2dev.serio->dev, \ 212 psmouse_fmt(format), ##__VA_ARGS__) 213 #define psmouse_notice(psmouse, format, ...) \ 214 dev_notice(&(psmouse)->ps2dev.serio->dev, \ 215 psmouse_fmt(format), ##__VA_ARGS__) 216 #define psmouse_printk(level, psmouse, format, ...) \ 217 dev_printk(level, \ 218 &(psmouse)->ps2dev.serio->dev, \ 219 psmouse_fmt(format), ##__VA_ARGS__) 220 221 #ifdef CONFIG_MOUSE_PS2_SMBUS 222 223 int psmouse_smbus_module_init(void); 224 void psmouse_smbus_module_exit(void); 225 226 struct i2c_board_info; 227 228 int psmouse_smbus_init(struct psmouse *psmouse, 229 const struct i2c_board_info *board, 230 const void *pdata, size_t pdata_size, 231 bool need_deactivate, 232 bool leave_breadcrumbs); 233 void psmouse_smbus_cleanup(struct psmouse *psmouse); 234 235 #else /* !CONFIG_MOUSE_PS2_SMBUS */ 236 237 static inline int psmouse_smbus_module_init(void) 238 { 239 return 0; 240 } 241 242 static inline void psmouse_smbus_module_exit(void) 243 { 244 } 245 246 static inline void psmouse_smbus_cleanup(struct psmouse *psmouse) 247 { 248 } 249 250 #endif /* CONFIG_MOUSE_PS2_SMBUS */ 251 252 #endif /* _PSMOUSE_H */ 253