blob: 9b84b0c4e37189fcd9db65599343cfe4f0f0a806 [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#define PSMOUSE_CMD_GETID 0x02f2
12#define PSMOUSE_CMD_SETRATE 0x10f3
13#define PSMOUSE_CMD_ENABLE 0x00f4
14#define PSMOUSE_CMD_DISABLE 0x00f5
15#define PSMOUSE_CMD_RESET_DIS 0x00f6
16#define PSMOUSE_CMD_RESET_BAT 0x02ff
17
18#define PSMOUSE_RET_BAT 0xaa
19#define PSMOUSE_RET_ID 0x00
20#define PSMOUSE_RET_ACK 0xfa
21#define PSMOUSE_RET_NAK 0xfe
22
23enum psmouse_state {
24 PSMOUSE_IGNORE,
25 PSMOUSE_INITIALIZING,
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050026 PSMOUSE_RESYNCING,
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 PSMOUSE_CMD_MODE,
28 PSMOUSE_ACTIVATED,
29};
30
31/* psmouse protocol handler return codes */
32typedef enum {
33 PSMOUSE_BAD_DATA,
34 PSMOUSE_GOOD_DATA,
35 PSMOUSE_FULL_PACKET
36} psmouse_ret_t;
37
38struct psmouse {
39 void *private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050040 struct input_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 struct ps2dev ps2dev;
Andres Salomon8bf020e2008-09-16 12:30:33 -040042 struct delayed_work resync_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 char *vendor;
44 char *name;
45 unsigned char packet[8];
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050046 unsigned char badbyte;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 unsigned char pktcnt;
48 unsigned char pktsize;
49 unsigned char type;
Dmitry Torokhov6b9d363c2010-04-19 00:42:16 -070050 bool ignore_parity;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070051 bool acks_disable_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 unsigned int model;
53 unsigned long last;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070054 unsigned long out_of_sync_cnt;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050055 unsigned long num_resyncs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 enum psmouse_state state;
57 char devname[64];
58 char phys[32];
59
60 unsigned int rate;
61 unsigned int resolution;
62 unsigned int resetafter;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050063 unsigned int resync_time;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070064 bool smartscroll; /* Logitech only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
David Howells7d12e782006-10-05 14:55:46 +010066 psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
68 void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
69
70 int (*reconnect)(struct psmouse *psmouse);
71 void (*disconnect)(struct psmouse *psmouse);
Dmitry Torokhova1cec062007-02-18 01:40:24 -050072 void (*cleanup)(struct psmouse *psmouse);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050073 int (*poll)(struct psmouse *psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 void (*pt_activate)(struct psmouse *psmouse);
76 void (*pt_deactivate)(struct psmouse *psmouse);
77};
78
79enum psmouse_type {
80 PSMOUSE_NONE,
81 PSMOUSE_PS2,
82 PSMOUSE_PS2PP,
83 PSMOUSE_THINKPS,
84 PSMOUSE_GENPS,
85 PSMOUSE_IMPS,
86 PSMOUSE_IMEX,
87 PSMOUSE_SYNAPTICS,
88 PSMOUSE_ALPS,
Kenan Esau02d7f582005-05-29 02:30:22 -050089 PSMOUSE_LIFEBOOK,
Stephen Evanchik541e3162005-08-08 01:26:18 -050090 PSMOUSE_TRACKPOINT,
Stefan Lucke24bf10a2007-02-18 01:49:10 -050091 PSMOUSE_TOUCHKIT_PS2,
Aristeu Rozanskiaea6a462007-05-10 01:47:18 -040092 PSMOUSE_CORTRON,
Andres Salomondf08ef22008-09-16 12:30:34 -040093 PSMOUSE_HGPK,
Arjan Opmeer2a0bd752008-10-16 22:10:19 -040094 PSMOUSE_ELANTECH,
Tai-hwa Liangfc69f4a2009-05-10 18:15:39 -070095 PSMOUSE_FSP,
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -050096 PSMOUSE_AUTO /* This one should always be last */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
Andres Salomon8bf020e2008-09-16 12:30:33 -040099void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
100 unsigned long delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
102int psmouse_reset(struct psmouse *psmouse);
Andres Salomona48cf5f2008-09-16 12:30:33 -0400103void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
105
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500106struct psmouse_attribute {
107 struct device_attribute dattr;
108 void *data;
109 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
110 ssize_t (*set)(struct psmouse *psmouse, void *data,
111 const char *buf, size_t count);
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700112 bool protect;
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500113};
114#define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
115
116ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
117 char *buf);
118ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
119 const char *buf, size_t count);
120
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700121#define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500122static struct psmouse_attribute psmouse_attr_##_name = { \
123 .dattr = { \
124 .attr = { \
125 .name = __stringify(_name), \
126 .mode = _mode, \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500127 }, \
128 .show = psmouse_attr_show_helper, \
129 .store = psmouse_attr_set_helper, \
130 }, \
131 .data = _data, \
132 .show = _show, \
133 .set = _set, \
Andres Salomon68d48222008-09-16 12:30:34 -0400134 .protect = _protect, \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500135}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700137#define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \
138 static ssize_t _show(struct psmouse *, void *, char *); \
139 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
140 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)
141
142#define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700143 __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true)
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700144
145#define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \
146 static ssize_t _show(struct psmouse *, void *, char *); \
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700147 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true)
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700148
149#define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \
150 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700151 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true)
Andres Salomon68d48222008-09-16 12:30:34 -0400152
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700153#ifndef psmouse_fmt
154#define psmouse_fmt(fmt) KBUILD_BASENAME ": " fmt
155#endif
156
157#define psmouse_dbg(psmouse, format, ...) \
158 dev_dbg(&(psmouse)->ps2dev.serio->dev, \
159 psmouse_fmt(format), ##__VA_ARGS__)
160#define psmouse_info(psmouse, format, ...) \
161 dev_info(&(psmouse)->ps2dev.serio->dev, \
162 psmouse_fmt(format), ##__VA_ARGS__)
163#define psmouse_warn(psmouse, format, ...) \
164 dev_warn(&(psmouse)->ps2dev.serio->dev, \
165 psmouse_fmt(format), ##__VA_ARGS__)
166#define psmouse_err(psmouse, format, ...) \
167 dev_err(&(psmouse)->ps2dev.serio->dev, \
168 psmouse_fmt(format), ##__VA_ARGS__)
169#define psmouse_notice(psmouse, format, ...) \
170 dev_notice(&(psmouse)->ps2dev.serio->dev, \
171 psmouse_fmt(format), ##__VA_ARGS__)
172#define psmouse_printk(level, psmouse, format, ...) \
173 dev_printk(level, \
174 &(psmouse)->ps2dev.serio->dev, \
175 psmouse_fmt(format), ##__VA_ARGS__)
176
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#endif /* _PSMOUSE_H */