Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 10 | #define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 11 | #define PSMOUSE_CMD_RESET_WRAP 0x00ec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 27 | PSMOUSE_RESYNCING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | struct psmouse { |
| 40 | void *private; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 41 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | struct ps2dev ps2dev; |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 43 | struct delayed_work resync_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | char *vendor; |
| 45 | char *name; |
| 46 | unsigned char packet[8]; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 47 | unsigned char badbyte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | unsigned char pktcnt; |
| 49 | unsigned char pktsize; |
| 50 | unsigned char type; |
Dmitry Torokhov | 6b9d363 | 2010-04-19 00:42:16 -0700 | [diff] [blame] | 51 | bool ignore_parity; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 52 | bool acks_disable_command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | unsigned int model; |
| 54 | unsigned long last; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 55 | unsigned long out_of_sync_cnt; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 56 | unsigned long num_resyncs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | enum psmouse_state state; |
| 58 | char devname[64]; |
| 59 | char phys[32]; |
| 60 | |
| 61 | unsigned int rate; |
| 62 | unsigned int resolution; |
| 63 | unsigned int resetafter; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 64 | unsigned int resync_time; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 65 | bool smartscroll; /* Logitech only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 67 | psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | void (*set_rate)(struct psmouse *psmouse, unsigned int rate); |
| 69 | void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution); |
| 70 | |
| 71 | int (*reconnect)(struct psmouse *psmouse); |
| 72 | void (*disconnect)(struct psmouse *psmouse); |
Dmitry Torokhov | a1cec06 | 2007-02-18 01:40:24 -0500 | [diff] [blame] | 73 | void (*cleanup)(struct psmouse *psmouse); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 74 | int (*poll)(struct psmouse *psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | void (*pt_activate)(struct psmouse *psmouse); |
| 77 | void (*pt_deactivate)(struct psmouse *psmouse); |
| 78 | }; |
| 79 | |
| 80 | enum psmouse_type { |
| 81 | PSMOUSE_NONE, |
| 82 | PSMOUSE_PS2, |
| 83 | PSMOUSE_PS2PP, |
| 84 | PSMOUSE_THINKPS, |
| 85 | PSMOUSE_GENPS, |
| 86 | PSMOUSE_IMPS, |
| 87 | PSMOUSE_IMEX, |
| 88 | PSMOUSE_SYNAPTICS, |
| 89 | PSMOUSE_ALPS, |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 90 | PSMOUSE_LIFEBOOK, |
Stephen Evanchik | 541e316 | 2005-08-08 01:26:18 -0500 | [diff] [blame] | 91 | PSMOUSE_TRACKPOINT, |
Stefan Lucke | 24bf10a | 2007-02-18 01:49:10 -0500 | [diff] [blame] | 92 | PSMOUSE_TOUCHKIT_PS2, |
Aristeu Rozanski | aea6a46 | 2007-05-10 01:47:18 -0400 | [diff] [blame] | 93 | PSMOUSE_CORTRON, |
Andres Salomon | df08ef2 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 94 | PSMOUSE_HGPK, |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 95 | PSMOUSE_ELANTECH, |
Tai-hwa Liang | fc69f4a | 2009-05-10 18:15:39 -0700 | [diff] [blame] | 96 | PSMOUSE_FSP, |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 97 | PSMOUSE_SYNAPTICS_RELATIVE, |
Dudley Du | 0799a92 | 2013-01-05 00:14:22 -0800 | [diff] [blame] | 98 | PSMOUSE_CYPRESS, |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 99 | PSMOUSE_AUTO /* This one should always be last */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 102 | void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, |
| 103 | unsigned long delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command); |
| 105 | int psmouse_reset(struct psmouse *psmouse); |
Andres Salomon | a48cf5f | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 106 | void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution); |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 108 | psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse); |
Andres Salomon | bd26f3d | 2012-02-24 00:51:37 -0800 | [diff] [blame] | 109 | int psmouse_activate(struct psmouse *psmouse); |
| 110 | int psmouse_deactivate(struct psmouse *psmouse); |
Hans de Goede | 2c75ada | 2014-09-11 10:14:09 -0700 | [diff] [blame] | 111 | bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 113 | struct psmouse_attribute { |
| 114 | struct device_attribute dattr; |
| 115 | void *data; |
| 116 | ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf); |
| 117 | ssize_t (*set)(struct psmouse *psmouse, void *data, |
| 118 | const char *buf, size_t count); |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 119 | bool protect; |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 120 | }; |
| 121 | #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr) |
| 122 | |
| 123 | ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr, |
| 124 | char *buf); |
| 125 | ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr, |
| 126 | const char *buf, size_t count); |
| 127 | |
Dmitry Torokhov | 3b72094 | 2009-08-18 11:45:02 -0700 | [diff] [blame] | 128 | #define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \ |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 129 | static struct psmouse_attribute psmouse_attr_##_name = { \ |
| 130 | .dattr = { \ |
| 131 | .attr = { \ |
| 132 | .name = __stringify(_name), \ |
| 133 | .mode = _mode, \ |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 134 | }, \ |
| 135 | .show = psmouse_attr_show_helper, \ |
| 136 | .store = psmouse_attr_set_helper, \ |
| 137 | }, \ |
| 138 | .data = _data, \ |
| 139 | .show = _show, \ |
| 140 | .set = _set, \ |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 141 | .protect = _protect, \ |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Dmitry Torokhov | 3b72094 | 2009-08-18 11:45:02 -0700 | [diff] [blame] | 144 | #define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \ |
| 145 | static ssize_t _show(struct psmouse *, void *, char *); \ |
| 146 | static ssize_t _set(struct psmouse *, void *, const char *, size_t); \ |
| 147 | __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) |
| 148 | |
| 149 | #define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 150 | __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true) |
Dmitry Torokhov | 3b72094 | 2009-08-18 11:45:02 -0700 | [diff] [blame] | 151 | |
| 152 | #define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \ |
| 153 | static ssize_t _show(struct psmouse *, void *, char *); \ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 154 | __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true) |
Dmitry Torokhov | 3b72094 | 2009-08-18 11:45:02 -0700 | [diff] [blame] | 155 | |
| 156 | #define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \ |
| 157 | static ssize_t _set(struct psmouse *, void *, const char *, size_t); \ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 158 | __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true) |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 159 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 160 | #ifndef psmouse_fmt |
| 161 | #define psmouse_fmt(fmt) KBUILD_BASENAME ": " fmt |
| 162 | #endif |
| 163 | |
| 164 | #define psmouse_dbg(psmouse, format, ...) \ |
| 165 | dev_dbg(&(psmouse)->ps2dev.serio->dev, \ |
| 166 | psmouse_fmt(format), ##__VA_ARGS__) |
| 167 | #define psmouse_info(psmouse, format, ...) \ |
| 168 | dev_info(&(psmouse)->ps2dev.serio->dev, \ |
| 169 | psmouse_fmt(format), ##__VA_ARGS__) |
| 170 | #define psmouse_warn(psmouse, format, ...) \ |
| 171 | dev_warn(&(psmouse)->ps2dev.serio->dev, \ |
| 172 | psmouse_fmt(format), ##__VA_ARGS__) |
| 173 | #define psmouse_err(psmouse, format, ...) \ |
| 174 | dev_err(&(psmouse)->ps2dev.serio->dev, \ |
| 175 | psmouse_fmt(format), ##__VA_ARGS__) |
| 176 | #define psmouse_notice(psmouse, format, ...) \ |
| 177 | dev_notice(&(psmouse)->ps2dev.serio->dev, \ |
| 178 | psmouse_fmt(format), ##__VA_ARGS__) |
| 179 | #define psmouse_printk(level, psmouse, format, ...) \ |
| 180 | dev_printk(level, \ |
| 181 | &(psmouse)->ps2dev.serio->dev, \ |
| 182 | psmouse_fmt(format), ##__VA_ARGS__) |
| 183 | |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | #endif /* _PSMOUSE_H */ |