xref: /linux/drivers/input/mouse/psmouse.h (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 #ifndef _PSMOUSE_H
2 #define _PSMOUSE_H
3 
4 #define PSMOUSE_OOB_NONE	0x00
5 #define PSMOUSE_OOB_EXTRA_BTNS	0x01
6 
7 #define PSMOUSE_CMD_SETSCALE11	0x00e6
8 #define PSMOUSE_CMD_SETSCALE21	0x00e7
9 #define PSMOUSE_CMD_SETRES	0x10e8
10 #define PSMOUSE_CMD_GETINFO	0x03e9
11 #define PSMOUSE_CMD_SETSTREAM	0x00ea
12 #define PSMOUSE_CMD_SETPOLL	0x00f0
13 #define PSMOUSE_CMD_POLL	0x00eb	/* caller sets number of bytes to receive */
14 #define PSMOUSE_CMD_RESET_WRAP	0x00ec
15 #define PSMOUSE_CMD_GETID	0x02f2
16 #define PSMOUSE_CMD_SETRATE	0x10f3
17 #define PSMOUSE_CMD_ENABLE	0x00f4
18 #define PSMOUSE_CMD_DISABLE	0x00f5
19 #define PSMOUSE_CMD_RESET_DIS	0x00f6
20 #define PSMOUSE_CMD_RESET_BAT	0x02ff
21 
22 #define PSMOUSE_RET_BAT		0xaa
23 #define PSMOUSE_RET_ID		0x00
24 #define PSMOUSE_RET_ACK		0xfa
25 #define PSMOUSE_RET_NAK		0xfe
26 
27 enum psmouse_state {
28 	PSMOUSE_IGNORE,
29 	PSMOUSE_INITIALIZING,
30 	PSMOUSE_RESYNCING,
31 	PSMOUSE_CMD_MODE,
32 	PSMOUSE_ACTIVATED,
33 };
34 
35 /* psmouse protocol handler return codes */
36 typedef enum {
37 	PSMOUSE_BAD_DATA,
38 	PSMOUSE_GOOD_DATA,
39 	PSMOUSE_FULL_PACKET
40 } psmouse_ret_t;
41 
42 enum psmouse_scale {
43 	PSMOUSE_SCALE11,
44 	PSMOUSE_SCALE21
45 };
46 
47 struct psmouse {
48 	void *private;
49 	struct input_dev *dev;
50 	struct ps2dev ps2dev;
51 	struct delayed_work resync_work;
52 	char *vendor;
53 	char *name;
54 	unsigned char packet[8];
55 	unsigned char badbyte;
56 	unsigned char pktcnt;
57 	unsigned char pktsize;
58 	unsigned char type;
59 	unsigned char oob_data_type;
60 	unsigned char extra_buttons;
61 	bool ignore_parity;
62 	bool acks_disable_command;
63 	unsigned int model;
64 	unsigned long last;
65 	unsigned long out_of_sync_cnt;
66 	unsigned long num_resyncs;
67 	enum psmouse_state state;
68 	char devname[64];
69 	char phys[32];
70 
71 	unsigned int rate;
72 	unsigned int resolution;
73 	unsigned int resetafter;
74 	unsigned int resync_time;
75 	bool smartscroll;	/* Logitech only */
76 
77 	psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse);
78 	void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
79 	void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
80 	void (*set_scale)(struct psmouse *psmouse, enum psmouse_scale scale);
81 
82 	int (*reconnect)(struct psmouse *psmouse);
83 	void (*disconnect)(struct psmouse *psmouse);
84 	void (*cleanup)(struct psmouse *psmouse);
85 	int (*poll)(struct psmouse *psmouse);
86 
87 	void (*pt_activate)(struct psmouse *psmouse);
88 	void (*pt_deactivate)(struct psmouse *psmouse);
89 };
90 
91 enum psmouse_type {
92 	PSMOUSE_NONE,
93 	PSMOUSE_PS2,
94 	PSMOUSE_PS2PP,
95 	PSMOUSE_THINKPS,
96 	PSMOUSE_GENPS,
97 	PSMOUSE_IMPS,
98 	PSMOUSE_IMEX,
99 	PSMOUSE_SYNAPTICS,
100 	PSMOUSE_ALPS,
101 	PSMOUSE_LIFEBOOK,
102 	PSMOUSE_TRACKPOINT,
103 	PSMOUSE_TOUCHKIT_PS2,
104 	PSMOUSE_CORTRON,
105 	PSMOUSE_HGPK,
106 	PSMOUSE_ELANTECH,
107 	PSMOUSE_FSP,
108 	PSMOUSE_SYNAPTICS_RELATIVE,
109 	PSMOUSE_CYPRESS,
110 	PSMOUSE_FOCALTECH,
111 	PSMOUSE_VMMOUSE,
112 	PSMOUSE_BYD,
113 	PSMOUSE_AUTO		/* This one should always be last */
114 };
115 
116 void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
117 		unsigned long delay);
118 int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
119 int psmouse_reset(struct psmouse *psmouse);
120 void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
121 void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
122 psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse);
123 int psmouse_activate(struct psmouse *psmouse);
124 int psmouse_deactivate(struct psmouse *psmouse);
125 bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]);
126 
127 struct psmouse_attribute {
128 	struct device_attribute dattr;
129 	void *data;
130 	ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
131 	ssize_t (*set)(struct psmouse *psmouse, void *data,
132 			const char *buf, size_t count);
133 	bool protect;
134 };
135 #define to_psmouse_attr(a)	container_of((a), struct psmouse_attribute, dattr)
136 
137 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
138 				 char *buf);
139 ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
140 				const char *buf, size_t count);
141 
142 #define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)	\
143 static struct psmouse_attribute psmouse_attr_##_name = {			\
144 	.dattr	= {								\
145 		.attr	= {							\
146 			.name	= __stringify(_name),				\
147 			.mode	= _mode,					\
148 		},								\
149 		.show	= psmouse_attr_show_helper,				\
150 		.store	= psmouse_attr_set_helper,				\
151 	},									\
152 	.data	= _data,							\
153 	.show	= _show,							\
154 	.set	= _set,								\
155 	.protect = _protect,							\
156 }
157 
158 #define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect)	\
159 	static ssize_t _show(struct psmouse *, void *, char *);			\
160 	static ssize_t _set(struct psmouse *, void *, const char *, size_t);	\
161 	__PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)
162 
163 #define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set)			\
164 	__PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true)
165 
166 #define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show)			\
167 	static ssize_t _show(struct psmouse *, void *, char *);			\
168 	__PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true)
169 
170 #define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set)			\
171 	static ssize_t _set(struct psmouse *, void *, const char *, size_t);	\
172 	__PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true)
173 
174 #ifndef psmouse_fmt
175 #define psmouse_fmt(fmt)	KBUILD_BASENAME ": " fmt
176 #endif
177 
178 #define psmouse_dbg(psmouse, format, ...)		\
179 	dev_dbg(&(psmouse)->ps2dev.serio->dev,		\
180 		psmouse_fmt(format), ##__VA_ARGS__)
181 #define psmouse_info(psmouse, format, ...)		\
182 	dev_info(&(psmouse)->ps2dev.serio->dev,		\
183 		 psmouse_fmt(format), ##__VA_ARGS__)
184 #define psmouse_warn(psmouse, format, ...)		\
185 	dev_warn(&(psmouse)->ps2dev.serio->dev,		\
186 		 psmouse_fmt(format), ##__VA_ARGS__)
187 #define psmouse_err(psmouse, format, ...)		\
188 	dev_err(&(psmouse)->ps2dev.serio->dev,		\
189 		psmouse_fmt(format), ##__VA_ARGS__)
190 #define psmouse_notice(psmouse, format, ...)		\
191 	dev_notice(&(psmouse)->ps2dev.serio->dev,	\
192 		   psmouse_fmt(format), ##__VA_ARGS__)
193 #define psmouse_printk(level, psmouse, format, ...)	\
194 	dev_printk(level,				\
195 		   &(psmouse)->ps2dev.serio->dev,	\
196 		   psmouse_fmt(format), ##__VA_ARGS__)
197 
198 
199 #endif /* _PSMOUSE_H */
200