1 /* SPDX-License-Identifier: GPL-2.0 */
5 #define PSMOUSE_OOB_NONE 0x00
6 #define PSMOUSE_OOB_EXTRA_BTNS 0x01
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
23 #define PSMOUSE_RET_BAT 0xaa
24 #define PSMOUSE_RET_ID 0x00
25 #define PSMOUSE_RET_ACK 0xfa
26 #define PSMOUSE_RET_NAK 0xfe
36 /* psmouse protocol handler return codes */
65 PSMOUSE_SYNAPTICS_RELATIVE
,
70 PSMOUSE_SYNAPTICS_SMBUS
,
71 PSMOUSE_AUTO
/* This one should always be last */
76 struct psmouse_protocol
{
77 enum psmouse_type type
;
79 bool ignore_parity
; /* Protocol should ignore parity errors from KBC */
80 bool try_passthru
; /* Try protocol also on passthrough ports */
81 bool smbus_companion
; /* "Protocol" is a stub, device is on SMBus */
84 int (*detect
)(struct psmouse
*, bool);
85 int (*init
)(struct psmouse
*);
90 struct input_dev
*dev
;
92 struct delayed_work resync_work
;
95 const struct psmouse_protocol
*protocol
;
96 unsigned char packet
[8];
97 unsigned char badbyte
;
99 unsigned char pktsize
;
100 unsigned char oob_data_type
;
101 unsigned char extra_buttons
;
102 bool acks_disable_command
;
105 unsigned long out_of_sync_cnt
;
106 unsigned long num_resyncs
;
107 enum psmouse_state state
;
112 unsigned int resolution
;
113 unsigned int resetafter
;
114 unsigned int resync_time
;
115 bool smartscroll
; /* Logitech only */
117 psmouse_ret_t (*protocol_handler
)(struct psmouse
*psmouse
);
118 void (*set_rate
)(struct psmouse
*psmouse
, unsigned int rate
);
119 void (*set_resolution
)(struct psmouse
*psmouse
, unsigned int resolution
);
120 void (*set_scale
)(struct psmouse
*psmouse
, enum psmouse_scale scale
);
122 int (*reconnect
)(struct psmouse
*psmouse
);
123 int (*fast_reconnect
)(struct psmouse
*psmouse
);
124 void (*disconnect
)(struct psmouse
*psmouse
);
125 void (*cleanup
)(struct psmouse
*psmouse
);
126 int (*poll
)(struct psmouse
*psmouse
);
128 void (*pt_activate
)(struct psmouse
*psmouse
);
129 void (*pt_deactivate
)(struct psmouse
*psmouse
);
132 void psmouse_queue_work(struct psmouse
*psmouse
, struct delayed_work
*work
,
133 unsigned long delay
);
134 int psmouse_sliced_command(struct psmouse
*psmouse
, unsigned char command
);
135 int psmouse_reset(struct psmouse
*psmouse
);
136 void psmouse_set_state(struct psmouse
*psmouse
, enum psmouse_state new_state
);
137 void psmouse_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
);
138 psmouse_ret_t
psmouse_process_byte(struct psmouse
*psmouse
);
139 int psmouse_activate(struct psmouse
*psmouse
);
140 int psmouse_deactivate(struct psmouse
*psmouse
);
141 bool psmouse_matches_pnp_id(struct psmouse
*psmouse
, const char * const ids
[]);
143 struct psmouse_attribute
{
144 struct device_attribute dattr
;
146 ssize_t (*show
)(struct psmouse
*psmouse
, void *data
, char *buf
);
147 ssize_t (*set
)(struct psmouse
*psmouse
, void *data
,
148 const char *buf
, size_t count
);
151 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
153 ssize_t
psmouse_attr_show_helper(struct device
*dev
, struct device_attribute
*attr
,
155 ssize_t
psmouse_attr_set_helper(struct device
*dev
, struct device_attribute
*attr
,
156 const char *buf
, size_t count
);
158 #define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \
159 static struct psmouse_attribute psmouse_attr_##_name = { \
162 .name = __stringify(_name), \
165 .show = psmouse_attr_show_helper, \
166 .store = psmouse_attr_set_helper, \
171 .protect = _protect, \
174 #define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \
175 static ssize_t _show(struct psmouse *, void *, char *); \
176 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
177 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)
179 #define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
180 __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true)
182 #define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \
183 static ssize_t _show(struct psmouse *, void *, char *); \
184 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true)
186 #define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \
187 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
188 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true)
191 #define psmouse_fmt(fmt) KBUILD_BASENAME ": " fmt
194 #define psmouse_dbg(psmouse, format, ...) \
195 dev_dbg(&(psmouse)->ps2dev.serio->dev, \
196 psmouse_fmt(format), ##__VA_ARGS__)
197 #define psmouse_info(psmouse, format, ...) \
198 dev_info(&(psmouse)->ps2dev.serio->dev, \
199 psmouse_fmt(format), ##__VA_ARGS__)
200 #define psmouse_warn(psmouse, format, ...) \
201 dev_warn(&(psmouse)->ps2dev.serio->dev, \
202 psmouse_fmt(format), ##__VA_ARGS__)
203 #define psmouse_err(psmouse, format, ...) \
204 dev_err(&(psmouse)->ps2dev.serio->dev, \
205 psmouse_fmt(format), ##__VA_ARGS__)
206 #define psmouse_notice(psmouse, format, ...) \
207 dev_notice(&(psmouse)->ps2dev.serio->dev, \
208 psmouse_fmt(format), ##__VA_ARGS__)
209 #define psmouse_printk(level, psmouse, format, ...) \
211 &(psmouse)->ps2dev.serio->dev, \
212 psmouse_fmt(format), ##__VA_ARGS__)
214 #ifdef CONFIG_MOUSE_PS2_SMBUS
216 int psmouse_smbus_module_init(void);
217 void psmouse_smbus_module_exit(void);
219 struct i2c_board_info
;
221 int psmouse_smbus_init(struct psmouse
*psmouse
,
222 const struct i2c_board_info
*board
,
223 const void *pdata
, size_t pdata_size
,
224 bool leave_breadcrumbs
);
225 void psmouse_smbus_cleanup(struct psmouse
*psmouse
);
227 #else /* !CONFIG_MOUSE_PS2_SMBUS */
229 static inline int psmouse_smbus_module_init(void)
234 static inline void psmouse_smbus_module_exit(void)
238 static inline void psmouse_smbus_cleanup(struct psmouse
*psmouse
)
242 #endif /* CONFIG_MOUSE_PS2_SMBUS */
244 #endif /* _PSMOUSE_H */