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