blob: cca1744c2a08e8c614dd89752ffb6283b10731be [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 Torokhovf0d5c6f42006-01-14 00:27:37 -050050 unsigned char acks_disable_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 unsigned int model;
52 unsigned long last;
53 unsigned long out_of_sync;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050054 unsigned long num_resyncs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 enum psmouse_state state;
56 char devname[64];
57 char phys[32];
58
59 unsigned int rate;
60 unsigned int resolution;
61 unsigned int resetafter;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050062 unsigned int resync_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned int smartscroll; /* Logitech only */
64
David Howells7d12e782006-10-05 14:55:46 +010065 psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
67 void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
68
69 int (*reconnect)(struct psmouse *psmouse);
70 void (*disconnect)(struct psmouse *psmouse);
Dmitry Torokhova1cec062007-02-18 01:40:24 -050071 void (*cleanup)(struct psmouse *psmouse);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050072 int (*poll)(struct psmouse *psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 void (*pt_activate)(struct psmouse *psmouse);
75 void (*pt_deactivate)(struct psmouse *psmouse);
76};
77
78enum psmouse_type {
79 PSMOUSE_NONE,
80 PSMOUSE_PS2,
81 PSMOUSE_PS2PP,
82 PSMOUSE_THINKPS,
83 PSMOUSE_GENPS,
84 PSMOUSE_IMPS,
85 PSMOUSE_IMEX,
86 PSMOUSE_SYNAPTICS,
87 PSMOUSE_ALPS,
Kenan Esau02d7f582005-05-29 02:30:22 -050088 PSMOUSE_LIFEBOOK,
Stephen Evanchik541e3162005-08-08 01:26:18 -050089 PSMOUSE_TRACKPOINT,
Stefan Lucke24bf10a2007-02-18 01:49:10 -050090 PSMOUSE_TOUCHKIT_PS2,
Aristeu Rozanskiaea6a462007-05-10 01:47:18 -040091 PSMOUSE_CORTRON,
Andres Salomondf08ef22008-09-16 12:30:34 -040092 PSMOUSE_HGPK,
Arjan Opmeer2a0bd752008-10-16 22:10:19 -040093 PSMOUSE_ELANTECH,
Tai-hwa Liangfc69f4a2009-05-10 18:15:39 -070094 PSMOUSE_FSP,
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -050095 PSMOUSE_AUTO /* This one should always be last */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
Andres Salomon8bf020e2008-09-16 12:30:33 -040098void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
99 unsigned long delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
101int psmouse_reset(struct psmouse *psmouse);
Andres Salomona48cf5f2008-09-16 12:30:33 -0400102void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
104
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500105struct psmouse_attribute {
106 struct device_attribute dattr;
107 void *data;
108 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
109 ssize_t (*set)(struct psmouse *psmouse, void *data,
110 const char *buf, size_t count);
Andres Salomon68d48222008-09-16 12:30:34 -0400111 int protect;
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500112};
113#define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
114
115ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
116 char *buf);
117ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
118 const char *buf, size_t count);
119
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700120#define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500121static struct psmouse_attribute psmouse_attr_##_name = { \
122 .dattr = { \
123 .attr = { \
124 .name = __stringify(_name), \
125 .mode = _mode, \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500126 }, \
127 .show = psmouse_attr_show_helper, \
128 .store = psmouse_attr_set_helper, \
129 }, \
130 .data = _data, \
131 .show = _show, \
132 .set = _set, \
Andres Salomon68d48222008-09-16 12:30:34 -0400133 .protect = _protect, \
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -0500134}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Dmitry Torokhov3b720942009-08-18 11:45:02 -0700136#define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \
137 static ssize_t _show(struct psmouse *, void *, char *); \
138 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
139 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)
140
141#define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
142 __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, 1)
143
144#define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \
145 static ssize_t _show(struct psmouse *, void *, char *); \
146 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, 1)
147
148#define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \
149 static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
150 __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, 1)
Andres Salomon68d48222008-09-16 12:30:34 -0400151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif /* _PSMOUSE_H */