blob: d02e1bdc9ae4934d56e5290f8adedcb3a2297566 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050010#define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */
Seth Forshee25bded72011-11-07 19:53:36 -080011#define PSMOUSE_CMD_RESET_WRAP 0x00ec
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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
24enum psmouse_state {
25 PSMOUSE_IGNORE,
26 PSMOUSE_INITIALIZING,
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050027 PSMOUSE_RESYNCING,
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 PSMOUSE_CMD_MODE,
29 PSMOUSE_ACTIVATED,
30};
31
32/* psmouse protocol handler return codes */
33typedef enum {
34 PSMOUSE_BAD_DATA,
35 PSMOUSE_GOOD_DATA,
36 PSMOUSE_FULL_PACKET
37} psmouse_ret_t;
38
Mathias Gottschlag4ec212f2015-03-07 13:32:10 -080039enum psmouse_scale {
40 PSMOUSE_SCALE11,
41 PSMOUSE_SCALE21
42};
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044struct psmouse {
45 void *private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050046 struct input_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 struct ps2dev ps2dev;
Andres Salomon8bf020e2008-09-16 12:30:33 -040048 struct delayed_work resync_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 char *vendor;
50 char *name;
51 unsigned char packet[8];
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050052 unsigned char badbyte;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 unsigned char pktcnt;
54 unsigned char pktsize;
55 unsigned char type;
Dmitry Torokhov6b9d363c2010-04-19 00:42:16 -070056 bool ignore_parity;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070057 bool acks_disable_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 unsigned int model;
59 unsigned long last;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070060 unsigned long out_of_sync_cnt;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050061 unsigned long num_resyncs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 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;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050069 unsigned int resync_time;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070070 bool smartscroll; /* Logitech only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
David Howells7d12e782006-10-05 14:55:46 +010072 psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
74 void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
Mathias Gottschlag4ec212f2015-03-07 13:32:10 -080075 void (*set_scale)(struct psmouse *psmouse, enum psmouse_scale scale);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 int (*reconnect)(struct psmouse *psmouse);
78 void (*disconnect)(struct psmouse *psmouse);
Dmitry Torokhova1cec062007-02-18 01:40:24 -050079 void (*cleanup)(struct psmouse *psmouse);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050080 int (*poll)(struct psmouse *psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 void (*pt_activate)(struct psmouse *psmouse);
83 void (*pt_deactivate)(struct psmouse *psmouse);
84};
85
86enum 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,
Kenan Esau02d7f582005-05-29 02:30:22 -050096 PSMOUSE_LIFEBOOK,
Stephen Evanchik541e3162005-08-08 01:26:18 -050097 PSMOUSE_TRACKPOINT,
Stefan Lucke24bf10a2007-02-18 01:49:10 -050098 PSMOUSE_TOUCHKIT_PS2,
Aristeu Rozanskiaea6a462007-05-10 01:47:18 -040099 PSMOUSE_CORTRON,
Andres Salomondf08ef22008-09-16 12:30:34 -0400100 PSMOUSE_HGPK,
Arjan Opmeer2a0bd752008-10-16 22:10:19 -0400101 PSMOUSE_ELANTECH,
Tai-hwa Liangfc69f4a2009-05-10 18:15:39 -0700102 PSMOUSE_FSP,
Daniel Drake7968a5d2011-11-08 00:00:35 -0800103 PSMOUSE_SYNAPTICS_RELATIVE,
Dudley Du0799a922013-01-05 00:14:22 -0800104 PSMOUSE_CYPRESS,
Mathias Gottschlag05be1d02014-12-29 09:26:35 -0800105 PSMOUSE_FOCALTECH,
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500106 PSMOUSE_AUTO /* This one should always be last */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Andres Salomon8bf020e2008-09-16 12:30:33 -0400109void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
110 unsigned long delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
112int psmouse_reset(struct psmouse *psmouse);
Andres Salomona48cf5f2008-09-16 12:30:33 -0400113void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
Daniel Drake7968a5d2011-11-08 00:00:35 -0800115psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse);
Andres Salomonbd26f3d2012-02-24 00:51:37 -0800116int psmouse_activate(struct psmouse *psmouse);
117int psmouse_deactivate(struct psmouse *psmouse);
Hans de Goede2c75ada2014-09-11 10:14:09 -0700118bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500120struct psmouse_attribute {
121 struct device_attribute dattr;
122 void *data;
123 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
124 ssize_t (*set)(struct psmouse *psmouse, void *data,
125 const char *buf, size_t count);
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700126 bool protect;
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500127};
128#define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
129
130ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
131 char *buf);
132ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
133 const char *buf, size_t count);
134
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700135#define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500136static struct psmouse_attribute psmouse_attr_##_name = { \
137 .dattr = { \
138 .attr = { \
139 .name = __stringify(_name), \
140 .mode = _mode, \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500141 }, \
142 .show = psmouse_attr_show_helper, \
143 .store = psmouse_attr_set_helper, \
144 }, \
145 .data = _data, \
146 .show = _show, \
147 .set = _set, \
Andres Salomon68d48222008-09-16 12:30:34 -0400148 .protect = _protect, \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500149}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700151#define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \
152 static ssize_t _show(struct psmouse *, void *, char *); \
153 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
154 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)
155
156#define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700157 __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true)
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700158
159#define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \
160 static ssize_t _show(struct psmouse *, void *, char *); \
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700161 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true)
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700162
163#define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \
164 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700165 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true)
Andres Salomon68d48222008-09-16 12:30:34 -0400166
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700167#ifndef psmouse_fmt
168#define psmouse_fmt(fmt) KBUILD_BASENAME ": " fmt
169#endif
170
171#define psmouse_dbg(psmouse, format, ...) \
172 dev_dbg(&(psmouse)->ps2dev.serio->dev, \
173 psmouse_fmt(format), ##__VA_ARGS__)
174#define psmouse_info(psmouse, format, ...) \
175 dev_info(&(psmouse)->ps2dev.serio->dev, \
176 psmouse_fmt(format), ##__VA_ARGS__)
177#define psmouse_warn(psmouse, format, ...) \
178 dev_warn(&(psmouse)->ps2dev.serio->dev, \
179 psmouse_fmt(format), ##__VA_ARGS__)
180#define psmouse_err(psmouse, format, ...) \
181 dev_err(&(psmouse)->ps2dev.serio->dev, \
182 psmouse_fmt(format), ##__VA_ARGS__)
183#define psmouse_notice(psmouse, format, ...) \
184 dev_notice(&(psmouse)->ps2dev.serio->dev, \
185 psmouse_fmt(format), ##__VA_ARGS__)
186#define psmouse_printk(level, psmouse, format, ...) \
187 dev_printk(level, \
188 &(psmouse)->ps2dev.serio->dev, \
189 psmouse_fmt(format), ##__VA_ARGS__)
190
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#endif /* _PSMOUSE_H */