aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/input/alps.txt188
-rw-r--r--arch/arm/plat-samsung/include/plat/keypad.h27
-rw-r--r--drivers/input/input-polldev.c8
-rw-r--r--drivers/input/keyboard/Kconfig21
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/atkbd.c40
-rw-r--r--drivers/input/keyboard/lm8323.c11
-rw-r--r--drivers/input/keyboard/samsung-keypad.c14
-rw-r--r--drivers/input/keyboard/tca8418_keypad.c430
-rw-r--r--drivers/input/misc/adxl34x.c16
-rw-r--r--drivers/input/misc/ati_remote2.c19
-rw-r--r--drivers/input/mouse/alps.c1036
-rw-r--r--drivers/input/mouse/alps.h19
-rw-r--r--drivers/input/mouse/elantech.c80
-rw-r--r--drivers/input/mouse/elantech.h2
-rw-r--r--drivers/input/mouse/hgpk.c18
-rw-r--r--drivers/input/mouse/logips2pp.c9
-rw-r--r--drivers/input/mouse/psmouse-base.c36
-rw-r--r--drivers/input/mouse/psmouse.h3
-rw-r--r--drivers/input/mouse/sentelic.c43
-rw-r--r--drivers/input/mouse/synaptics.c197
-rw-r--r--drivers/input/mouse/synaptics.h5
-rw-r--r--drivers/input/mouse/trackpoint.c17
-rw-r--r--drivers/input/serio/i8042.c23
-rw-r--r--drivers/input/tablet/aiptek.c34
-rw-r--r--drivers/input/tablet/wacom_sys.c96
-rw-r--r--drivers/input/tablet/wacom_wac.c110
-rw-r--r--drivers/input/tablet/wacom_wac.h4
-rw-r--r--drivers/input/touchscreen/Kconfig16
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/ad7877.c16
-rw-r--r--drivers/input/touchscreen/ad7879-i2c.c26
-rw-r--r--drivers/input/touchscreen/ad7879-spi.c26
-rw-r--r--drivers/input/touchscreen/ad7879.c23
-rw-r--r--drivers/input/touchscreen/ad7879.h4
-rw-r--r--drivers/input/touchscreen/ads7846.c8
-rw-r--r--drivers/input/touchscreen/egalax_ts.c303
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c36
-rw-r--r--include/linux/input/samsung-keypad.h43
-rw-r--r--include/linux/input/tca8418_keypad.h44
40 files changed, 2683 insertions, 370 deletions
diff --git a/Documentation/input/alps.txt b/Documentation/input/alps.txt
new file mode 100644
index 000000000000..f274c28b5103
--- /dev/null
+++ b/Documentation/input/alps.txt
@@ -0,0 +1,188 @@
1ALPS Touchpad Protocol
2----------------------
3
4Introduction
5------------
6
7Currently the ALPS touchpad driver supports four protocol versions in use by
8ALPS touchpads, called versions 1, 2, 3, and 4. Information about the various
9protocol versions is contained in the following sections.
10
11Detection
12---------
13
14All ALPS touchpads should respond to the "E6 report" command sequence:
15E8-E6-E6-E6-E9. An ALPS touchpad should respond with either 00-00-0A or
1600-00-64.
17
18If the E6 report is successful, the touchpad model is identified using the "E7
19report" sequence: E8-E7-E7-E7-E9. The response is the model signature and is
20matched against known models in the alps_model_data_array.
21
22With protocol versions 3 and 4, the E7 report model signature is always
2373-02-64. To differentiate between these versions, the response from the
24"Enter Command Mode" sequence must be inspected as described below.
25
26Command Mode
27------------
28
29Protocol versions 3 and 4 have a command mode that is used to read and write
30one-byte device registers in a 16-bit address space. The command sequence
31EC-EC-EC-E9 places the device in command mode, and the device will respond
32with 88-07 followed by a third byte. This third byte can be used to determine
33whether the devices uses the version 3 or 4 protocol.
34
35To exit command mode, PSMOUSE_CMD_SETSTREAM (EA) is sent to the touchpad.
36
37While in command mode, register addresses can be set by first sending a
38specific command, either EC for v3 devices or F5 for v4 devices. Then the
39address is sent one nibble at a time, where each nibble is encoded as a
40command with optional data. This enoding differs slightly between the v3 and
41v4 protocols.
42
43Once an address has been set, the addressed register can be read by sending
44PSMOUSE_CMD_GETINFO (E9). The first two bytes of the response contains the
45address of the register being read, and the third contains the value of the
46register. Registers are written by writing the value one nibble at a time
47using the same encoding used for addresses.
48
49Packet Format
50-------------
51
52In the following tables, the following notation is used.
53
54 CAPITALS = stick, miniscules = touchpad
55
56?'s can have different meanings on different models, such as wheel rotation,
57extra buttons, stick buttons on a dualpoint, etc.
58
59PS/2 packet format
60------------------
61
62 byte 0: 0 0 YSGN XSGN 1 M R L
63 byte 1: X7 X6 X5 X4 X3 X2 X1 X0
64 byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
65
66Note that the device never signals overflow condition.
67
68ALPS Absolute Mode - Protocol Verion 1
69--------------------------------------
70
71 byte 0: 1 0 0 0 1 x9 x8 x7
72 byte 1: 0 x6 x5 x4 x3 x2 x1 x0
73 byte 2: 0 ? ? l r ? fin ges
74 byte 3: 0 ? ? ? ? y9 y8 y7
75 byte 4: 0 y6 y5 y4 y3 y2 y1 y0
76 byte 5: 0 z6 z5 z4 z3 z2 z1 z0
77
78ALPS Absolute Mode - Protocol Version 2
79---------------------------------------
80
81 byte 0: 1 ? ? ? 1 ? ? ?
82 byte 1: 0 x6 x5 x4 x3 x2 x1 x0
83 byte 2: 0 x10 x9 x8 x7 ? fin ges
84 byte 3: 0 y9 y8 y7 1 M R L
85 byte 4: 0 y6 y5 y4 y3 y2 y1 y0
86 byte 5: 0 z6 z5 z4 z3 z2 z1 z0
87
88Dualpoint device -- interleaved packet format
89---------------------------------------------
90
91 byte 0: 1 1 0 0 1 1 1 1
92 byte 1: 0 x6 x5 x4 x3 x2 x1 x0
93 byte 2: 0 x10 x9 x8 x7 0 fin ges
94 byte 3: 0 0 YSGN XSGN 1 1 1 1
95 byte 4: X7 X6 X5 X4 X3 X2 X1 X0
96 byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
97 byte 6: 0 y9 y8 y7 1 m r l
98 byte 7: 0 y6 y5 y4 y3 y2 y1 y0
99 byte 8: 0 z6 z5 z4 z3 z2 z1 z0
100
101ALPS Absolute Mode - Protocol Version 3
102---------------------------------------
103
104ALPS protocol version 3 has three different packet formats. The first two are
105associated with touchpad events, and the third is associatd with trackstick
106events.
107
108The first type is the touchpad position packet.
109
110 byte 0: 1 ? x1 x0 1 1 1 1
111 byte 1: 0 x10 x9 x8 x7 x6 x5 x4
112 byte 2: 0 y10 y9 y8 y7 y6 y5 y4
113 byte 3: 0 M R L 1 m r l
114 byte 4: 0 mt x3 x2 y3 y2 y1 y0
115 byte 5: 0 z6 z5 z4 z3 z2 z1 z0
116
117Note that for some devices the trackstick buttons are reported in this packet,
118and on others it is reported in the trackstick packets.
119
120The second packet type contains bitmaps representing the x and y axes. In the
121bitmaps a given bit is set if there is a finger covering that position on the
122given axis. Thus the bitmap packet can be used for low-resolution multi-touch
123data, although finger tracking is not possible. This packet also encodes the
124number of contacts (f1 and f0 in the table below).
125
126 byte 0: 1 1 x1 x0 1 1 1 1
127 byte 1: 0 x8 x7 x6 x5 x4 x3 x2
128 byte 2: 0 y7 y6 y5 y4 y3 y2 y1
129 byte 3: 0 y10 y9 y8 1 1 1 1
130 byte 4: 0 x14 x13 x12 x11 x10 x9 y0
131 byte 5: 0 1 ? ? ? ? f1 f0
132
133This packet only appears after a position packet with the mt bit set, and
134ususally only appears when there are two or more contacts (although
135ocassionally it's seen with only a single contact).
136
137The final v3 packet type is the trackstick packet.
138
139 byte 0: 1 1 x7 y7 1 1 1 1
140 byte 1: 0 x6 x5 x4 x3 x2 x1 x0
141 byte 2: 0 y6 y5 y4 y3 y2 y1 y0
142 byte 3: 0 1 0 0 1 0 0 0
143 byte 4: 0 z4 z3 z2 z1 z0 ? ?
144 byte 5: 0 0 1 1 1 1 1 1
145
146ALPS Absolute Mode - Protocol Version 4
147---------------------------------------
148
149Protocol version 4 has an 8-byte packet format.
150
151 byte 0: 1 ? x1 x0 1 1 1 1
152 byte 1: 0 x10 x9 x8 x7 x6 x5 x4
153 byte 2: 0 y10 y9 y8 y7 y6 y5 y4
154 byte 3: 0 1 x3 x2 y3 y2 y1 y0
155 byte 4: 0 ? ? ? 1 ? r l
156 byte 5: 0 z6 z5 z4 z3 z2 z1 z0
157 byte 6: bitmap data (described below)
158 byte 7: bitmap data (described below)
159
160The last two bytes represent a partial bitmap packet, with 3 full packets
161required to construct a complete bitmap packet. Once assembled, the 6-byte
162bitmap packet has the following format:
163
164 byte 0: 0 1 x7 x6 x5 x4 x3 x2
165 byte 1: 0 x1 x0 y4 y3 y2 y1 y0
166 byte 2: 0 0 ? x14 x13 x12 x11 x10
167 byte 3: 0 x9 x8 y9 y8 y7 y6 y5
168 byte 4: 0 0 0 0 0 0 0 0
169 byte 5: 0 0 0 0 0 0 0 y10
170
171There are several things worth noting here.
172
173 1) In the bitmap data, bit 6 of byte 0 serves as a sync byte to
174 identify the first fragment of a bitmap packet.
175
176 2) The bitmaps represent the same data as in the v3 bitmap packets, although
177 the packet layout is different.
178
179 3) There doesn't seem to be a count of the contact points anywhere in the v4
180 protocol packets. Deriving a count of contact points must be done by
181 analyzing the bitmaps.
182
183 4) There is a 3 to 1 ratio of position packets to bitmap packets. Therefore
184 MT position can only be updated for every third ST position update, and
185 the count of contact points can only be updated every third packet as
186 well.
187
188So far no v4 devices with tracksticks have been encountered.
diff --git a/arch/arm/plat-samsung/include/plat/keypad.h b/arch/arm/plat-samsung/include/plat/keypad.h
index b59a6483cd8a..c81ace332a1e 100644
--- a/arch/arm/plat-samsung/include/plat/keypad.h
+++ b/arch/arm/plat-samsung/include/plat/keypad.h
@@ -13,32 +13,7 @@
13#ifndef __PLAT_SAMSUNG_KEYPAD_H 13#ifndef __PLAT_SAMSUNG_KEYPAD_H
14#define __PLAT_SAMSUNG_KEYPAD_H 14#define __PLAT_SAMSUNG_KEYPAD_H
15 15
16#include <linux/input/matrix_keypad.h> 16#include <linux/input/samsung-keypad.h>
17
18#define SAMSUNG_MAX_ROWS 8
19#define SAMSUNG_MAX_COLS 8
20
21/**
22 * struct samsung_keypad_platdata - Platform device data for Samsung Keypad.
23 * @keymap_data: pointer to &matrix_keymap_data.
24 * @rows: number of keypad row supported.
25 * @cols: number of keypad col supported.
26 * @no_autorepeat: disable key autorepeat.
27 * @wakeup: controls whether the device should be set up as wakeup source.
28 * @cfg_gpio: configure the GPIO.
29 *
30 * Initialisation data specific to either the machine or the platform
31 * for the device driver to use or call-back when configuring gpio.
32 */
33struct samsung_keypad_platdata {
34 const struct matrix_keymap_data *keymap_data;
35 unsigned int rows;
36 unsigned int cols;
37 bool no_autorepeat;
38 bool wakeup;
39
40 void (*cfg_gpio)(unsigned int rows, unsigned int cols);
41};
42 17
43/** 18/**
44 * samsung_keypad_set_platdata - Set platform data for Samsung Keypad device. 19 * samsung_keypad_set_platdata - Set platform data for Samsung Keypad device.
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index 7dfe1009fae0..7f161d93203c 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -84,10 +84,12 @@ static ssize_t input_polldev_set_poll(struct device *dev,
84{ 84{
85 struct input_polled_dev *polldev = dev_get_drvdata(dev); 85 struct input_polled_dev *polldev = dev_get_drvdata(dev);
86 struct input_dev *input = polldev->input; 86 struct input_dev *input = polldev->input;
87 unsigned long interval; 87 unsigned int interval;
88 int err;
88 89
89 if (strict_strtoul(buf, 0, &interval)) 90 err = kstrtouint(buf, 0, &interval);
90 return -EINVAL; 91 if (err)
92 return err;
91 93
92 if (interval < polldev->poll_interval_min) 94 if (interval < polldev->poll_interval_min)
93 return -EINVAL; 95 return -EINVAL;
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 615c21f2a553..cdc385b2cf7d 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -221,6 +221,22 @@ config KEYBOARD_TCA6416
221 To compile this driver as a module, choose M here: the 221 To compile this driver as a module, choose M here: the
222 module will be called tca6416_keypad. 222 module will be called tca6416_keypad.
223 223
224config KEYBOARD_TCA8418
225 tristate "TCA8418 Keypad Support"
226 depends on I2C
227 help
228 This driver implements basic keypad functionality
229 for keys connected through TCA8418 keypad decoder.
230
231 Say Y here if your device has keys connected to
232 TCA8418 keypad decoder.
233
234 If enabled the complete TCA8418 device will be managed through
235 this driver.
236
237 To compile this driver as a module, choose M here: the
238 module will be called tca8418_keypad.
239
224config KEYBOARD_MATRIX 240config KEYBOARD_MATRIX
225 tristate "GPIO driven matrix keypad support" 241 tristate "GPIO driven matrix keypad support"
226 depends on GENERIC_GPIO 242 depends on GENERIC_GPIO
@@ -425,9 +441,10 @@ config KEYBOARD_PMIC8XXX
425 441
426config KEYBOARD_SAMSUNG 442config KEYBOARD_SAMSUNG
427 tristate "Samsung keypad support" 443 tristate "Samsung keypad support"
428 depends on SAMSUNG_DEV_KEYPAD 444 depends on HAVE_CLK
429 help 445 help
430 Say Y here if you want to use the Samsung keypad. 446 Say Y here if you want to use the keypad on your Samsung mobile
447 device.
431 448
432 To compile this driver as a module, choose M here: the 449 To compile this driver as a module, choose M here: the
433 module will be called samsung-keypad. 450 module will be called samsung-keypad.
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index ddde0fd476f7..df7061f12918 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
17obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o 17obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o
18obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o 18obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o
19obj-$(CONFIG_KEYBOARD_TCA8418) += tca8418_keypad.o
19obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 20obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
20obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 21obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
21obj-$(CONFIG_KEYBOARD_IMX) += imx_keypad.o 22obj-$(CONFIG_KEYBOARD_IMX) += imx_keypad.o
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 19cfc0cf558c..e05a2e7073c6 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -1305,7 +1305,7 @@ static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1305static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count) 1305static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1306{ 1306{
1307 struct input_dev *old_dev, *new_dev; 1307 struct input_dev *old_dev, *new_dev;
1308 unsigned long value; 1308 unsigned int value;
1309 int err; 1309 int err;
1310 bool old_extra; 1310 bool old_extra;
1311 unsigned char old_set; 1311 unsigned char old_set;
@@ -1313,7 +1313,11 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
1313 if (!atkbd->write) 1313 if (!atkbd->write)
1314 return -EIO; 1314 return -EIO;
1315 1315
1316 if (strict_strtoul(buf, 10, &value) || value > 1) 1316 err = kstrtouint(buf, 10, &value);
1317 if (err)
1318 return err;
1319
1320 if (value > 1)
1317 return -EINVAL; 1321 return -EINVAL;
1318 1322
1319 if (atkbd->extra != value) { 1323 if (atkbd->extra != value) {
@@ -1389,11 +1393,15 @@ static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1389static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count) 1393static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1390{ 1394{
1391 struct input_dev *old_dev, *new_dev; 1395 struct input_dev *old_dev, *new_dev;
1392 unsigned long value; 1396 unsigned int value;
1393 int err; 1397 int err;
1394 bool old_scroll; 1398 bool old_scroll;
1395 1399
1396 if (strict_strtoul(buf, 10, &value) || value > 1) 1400 err = kstrtouint(buf, 10, &value);
1401 if (err)
1402 return err;
1403
1404 if (value > 1)
1397 return -EINVAL; 1405 return -EINVAL;
1398 1406
1399 if (atkbd->scroll != value) { 1407 if (atkbd->scroll != value) {
@@ -1433,7 +1441,7 @@ static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1433static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count) 1441static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1434{ 1442{
1435 struct input_dev *old_dev, *new_dev; 1443 struct input_dev *old_dev, *new_dev;
1436 unsigned long value; 1444 unsigned int value;
1437 int err; 1445 int err;
1438 unsigned char old_set; 1446 unsigned char old_set;
1439 bool old_extra; 1447 bool old_extra;
@@ -1441,7 +1449,11 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1441 if (!atkbd->write) 1449 if (!atkbd->write)
1442 return -EIO; 1450 return -EIO;
1443 1451
1444 if (strict_strtoul(buf, 10, &value) || (value != 2 && value != 3)) 1452 err = kstrtouint(buf, 10, &value);
1453 if (err)
1454 return err;
1455
1456 if (value != 2 && value != 3)
1445 return -EINVAL; 1457 return -EINVAL;
1446 1458
1447 if (atkbd->set != value) { 1459 if (atkbd->set != value) {
@@ -1484,14 +1496,18 @@ static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1484static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count) 1496static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1485{ 1497{
1486 struct input_dev *old_dev, *new_dev; 1498 struct input_dev *old_dev, *new_dev;
1487 unsigned long value; 1499 unsigned int value;
1488 int err; 1500 int err;
1489 bool old_softrepeat, old_softraw; 1501 bool old_softrepeat, old_softraw;
1490 1502
1491 if (!atkbd->write) 1503 if (!atkbd->write)
1492 return -EIO; 1504 return -EIO;
1493 1505
1494 if (strict_strtoul(buf, 10, &value) || value > 1) 1506 err = kstrtouint(buf, 10, &value);
1507 if (err)
1508 return err;
1509
1510 if (value > 1)
1495 return -EINVAL; 1511 return -EINVAL;
1496 1512
1497 if (atkbd->softrepeat != value) { 1513 if (atkbd->softrepeat != value) {
@@ -1534,11 +1550,15 @@ static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1534static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count) 1550static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1535{ 1551{
1536 struct input_dev *old_dev, *new_dev; 1552 struct input_dev *old_dev, *new_dev;
1537 unsigned long value; 1553 unsigned int value;
1538 int err; 1554 int err;
1539 bool old_softraw; 1555 bool old_softraw;
1540 1556
1541 if (strict_strtoul(buf, 10, &value) || value > 1) 1557 err = kstrtouint(buf, 10, &value);
1558 if (err)
1559 return err;
1560
1561 if (value > 1)
1542 return -EINVAL; 1562 return -EINVAL;
1543 1563
1544 if (atkbd->softraw != value) { 1564 if (atkbd->softraw != value) {
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index 82d1dc8badd5..21823bfc7911 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -545,13 +545,12 @@ static ssize_t lm8323_pwm_store_time(struct device *dev,
545{ 545{
546 struct led_classdev *led_cdev = dev_get_drvdata(dev); 546 struct led_classdev *led_cdev = dev_get_drvdata(dev);
547 struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev); 547 struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev);
548 int ret; 548 int ret, time;
549 unsigned long time;
550 549
551 ret = strict_strtoul(buf, 10, &time); 550 ret = kstrtoint(buf, 10, &time);
552 /* Numbers only, please. */ 551 /* Numbers only, please. */
553 if (ret) 552 if (ret)
554 return -EINVAL; 553 return ret;
555 554
556 pwm->fade_time = time; 555 pwm->fade_time = time;
557 556
@@ -613,9 +612,9 @@ static ssize_t lm8323_set_disable(struct device *dev,
613{ 612{
614 struct lm8323_chip *lm = dev_get_drvdata(dev); 613 struct lm8323_chip *lm = dev_get_drvdata(dev);
615 int ret; 614 int ret;
616 unsigned long i; 615 unsigned int i;
617 616
618 ret = strict_strtoul(buf, 10, &i); 617 ret = kstrtouint(buf, 10, &i);
619 618
620 mutex_lock(&lm->lock); 619 mutex_lock(&lm->lock);
621 lm->kp_enabled = !i; 620 lm->kp_enabled = !i;
diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
index f689f49e3109..1a2b755564f2 100644
--- a/drivers/input/keyboard/samsung-keypad.c
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -22,7 +22,7 @@
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/sched.h> 24#include <linux/sched.h>
25#include <plat/keypad.h> 25#include <linux/input/samsung-keypad.h>
26 26
27#define SAMSUNG_KEYIFCON 0x00 27#define SAMSUNG_KEYIFCON 0x00
28#define SAMSUNG_KEYIFSTSCLR 0x04 28#define SAMSUNG_KEYIFSTSCLR 0x04
@@ -381,7 +381,7 @@ static int __devexit samsung_keypad_remove(struct platform_device *pdev)
381 return 0; 381 return 0;
382} 382}
383 383
384#ifdef CONFIG_PM 384#ifdef CONFIG_PM_SLEEP
385static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad, 385static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad,
386 bool enable) 386 bool enable)
387{ 387{
@@ -440,13 +440,11 @@ static int samsung_keypad_resume(struct device *dev)
440 440
441 return 0; 441 return 0;
442} 442}
443
444static const struct dev_pm_ops samsung_keypad_pm_ops = {
445 .suspend = samsung_keypad_suspend,
446 .resume = samsung_keypad_resume,
447};
448#endif 443#endif
449 444
445static SIMPLE_DEV_PM_OPS(samsung_keypad_pm_ops,
446 samsung_keypad_suspend, samsung_keypad_resume);
447
450static struct platform_device_id samsung_keypad_driver_ids[] = { 448static struct platform_device_id samsung_keypad_driver_ids[] = {
451 { 449 {
452 .name = "samsung-keypad", 450 .name = "samsung-keypad",
@@ -465,9 +463,7 @@ static struct platform_driver samsung_keypad_driver = {
465 .driver = { 463 .driver = {
466 .name = "samsung-keypad", 464 .name = "samsung-keypad",
467 .owner = THIS_MODULE, 465 .owner = THIS_MODULE,
468#ifdef CONFIG_PM
469 .pm = &samsung_keypad_pm_ops, 466 .pm = &samsung_keypad_pm_ops,
470#endif
471 }, 467 },
472 .id_table = samsung_keypad_driver_ids, 468 .id_table = samsung_keypad_driver_ids,
473}; 469};
diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c
new file mode 100644
index 000000000000..958ec107bfbc
--- /dev/null
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -0,0 +1,430 @@
1/*
2 * Driver for TCA8418 I2C keyboard
3 *
4 * Copyright (C) 2011 Fuel7, Inc. All rights reserved.
5 *
6 * Author: Kyle Manna <kyle.manna@fuel7.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License v2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 021110-1307, USA.
21 *
22 * If you can't comply with GPLv2, alternative licensing terms may be
23 * arranged. Please contact Fuel7, Inc. (http://fuel7.com/) for proprietary
24 * alternative licensing inquiries.
25 */
26
27#include <linux/types.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/delay.h>
31#include <linux/slab.h>
32#include <linux/interrupt.h>
33#include <linux/workqueue.h>
34#include <linux/gpio.h>
35#include <linux/i2c.h>
36#include <linux/input.h>
37#include <linux/input/tca8418_keypad.h>
38
39/* TCA8418 hardware limits */
40#define TCA8418_MAX_ROWS 8
41#define TCA8418_MAX_COLS 10
42
43/* TCA8418 register offsets */
44#define REG_CFG 0x01
45#define REG_INT_STAT 0x02
46#define REG_KEY_LCK_EC 0x03
47#define REG_KEY_EVENT_A 0x04
48#define REG_KEY_EVENT_B 0x05
49#define REG_KEY_EVENT_C 0x06
50#define REG_KEY_EVENT_D 0x07
51#define REG_KEY_EVENT_E 0x08
52#define REG_KEY_EVENT_F 0x09
53#define REG_KEY_EVENT_G 0x0A
54#define REG_KEY_EVENT_H 0x0B
55#define REG_KEY_EVENT_I 0x0C
56#define REG_KEY_EVENT_J 0x0D
57#define REG_KP_LCK_TIMER 0x0E
58#define REG_UNLOCK1 0x0F
59#define REG_UNLOCK2 0x10
60#define REG_GPIO_INT_STAT1 0x11
61#define REG_GPIO_INT_STAT2 0x12
62#define REG_GPIO_INT_STAT3 0x13
63#define REG_GPIO_DAT_STAT1 0x14
64#define REG_GPIO_DAT_STAT2 0x15
65#define REG_GPIO_DAT_STAT3 0x16
66#define REG_GPIO_DAT_OUT1 0x17
67#define REG_GPIO_DAT_OUT2 0x18
68#define REG_GPIO_DAT_OUT3 0x19
69#define REG_GPIO_INT_EN1 0x1A
70#define REG_GPIO_INT_EN2 0x1B
71#define REG_GPIO_INT_EN3 0x1C
72#define REG_KP_GPIO1 0x1D
73#define REG_KP_GPIO2 0x1E
74#define REG_KP_GPIO3 0x1F
75#define REG_GPI_EM1 0x20
76#define REG_GPI_EM2 0x21
77#define REG_GPI_EM3 0x22
78#define REG_GPIO_DIR1 0x23
79#define REG_GPIO_DIR2 0x24
80#define REG_GPIO_DIR3 0x25
81#define REG_GPIO_INT_LVL1 0x26
82#define REG_GPIO_INT_LVL2 0x27
83#define REG_GPIO_INT_LVL3 0x28
84#define REG_DEBOUNCE_DIS1 0x29
85#define REG_DEBOUNCE_DIS2 0x2A
86#define REG_DEBOUNCE_DIS3 0x2B
87#define REG_GPIO_PULL1 0x2C
88#define REG_GPIO_PULL2 0x2D
89#define REG_GPIO_PULL3 0x2E
90
91/* TCA8418 bit definitions */
92#define CFG_AI BIT(7)
93#define CFG_GPI_E_CFG BIT(6)
94#define CFG_OVR_FLOW_M BIT(5)
95#define CFG_INT_CFG BIT(4)
96#define CFG_OVR_FLOW_IEN BIT(3)
97#define CFG_K_LCK_IEN BIT(2)
98#define CFG_GPI_IEN BIT(1)
99#define CFG_KE_IEN BIT(0)
100
101#define INT_STAT_CAD_INT BIT(4)
102#define INT_STAT_OVR_FLOW_INT BIT(3)
103#define INT_STAT_K_LCK_INT BIT(2)
104#define INT_STAT_GPI_INT BIT(1)
105#define INT_STAT_K_INT BIT(0)
106
107/* TCA8418 register masks */
108#define KEY_LCK_EC_KEC 0x7
109#define KEY_EVENT_CODE 0x7f
110#define KEY_EVENT_VALUE 0x80
111
112
113static const struct i2c_device_id tca8418_id[] = {
114 { TCA8418_NAME, 8418, },
115 { }
116};
117MODULE_DEVICE_TABLE(i2c, tca8418_id);
118
119struct tca8418_keypad {
120 unsigned int rows;
121 unsigned int cols;
122 unsigned int keypad_mask; /* Mask for keypad col/rol regs */
123 unsigned int irq;
124 unsigned int row_shift;
125
126 struct i2c_client *client;
127 struct input_dev *input;
128
129 /* Flexible array member, must be at end of struct */
130 unsigned short keymap[];
131};
132
133/*
134 * Write a byte to the TCA8418
135 */
136static int tca8418_write_byte(struct tca8418_keypad *keypad_data,
137 int reg, u8 val)
138{
139 int error;
140
141 error = i2c_smbus_write_byte_data(keypad_data->client, reg, val);
142 if (error < 0) {
143 dev_err(&keypad_data->client->dev,
144 "%s failed, reg: %d, val: %d, error: %d\n",
145 __func__, reg, val, error);
146 return error;
147 }
148
149 return 0;
150}
151
152/*
153 * Read a byte from the TCA8418
154 */
155static int tca8418_read_byte(struct tca8418_keypad *keypad_data,
156 int reg, u8 *val)
157{
158 int error;
159
160 error = i2c_smbus_read_byte_data(keypad_data->client, reg);
161 if (error < 0) {
162 dev_err(&keypad_data->client->dev,
163 "%s failed, reg: %d, error: %d\n",
164 __func__, reg, error);
165 return error;
166 }
167
168 *val = (u8)error;
169
170 return 0;
171}
172
173static void tca8418_read_keypad(struct tca8418_keypad *keypad_data)
174{
175 int error, col, row;
176 u8 reg, state, code;
177
178 /* Initial read of the key event FIFO */
179 error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, &reg);
180
181 /* Assume that key code 0 signifies empty FIFO */
182 while (error >= 0 && reg > 0) {
183 state = reg & KEY_EVENT_VALUE;
184 code = reg & KEY_EVENT_CODE;
185
186 row = code / TCA8418_MAX_COLS;
187 col = code % TCA8418_MAX_COLS;
188
189 row = (col) ? row : row - 1;
190 col = (col) ? col - 1 : TCA8418_MAX_COLS - 1;
191
192 code = MATRIX_SCAN_CODE(row, col, keypad_data->row_shift);
193 input_event(keypad_data->input, EV_MSC, MSC_SCAN, code);
194 input_report_key(keypad_data->input,
195 keypad_data->keymap[code], state);
196
197 /* Read for next loop */
198 error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, &reg);
199 }
200
201 if (error < 0)
202 dev_err(&keypad_data->client->dev,
203 "unable to read REG_KEY_EVENT_A\n");
204
205 input_sync(keypad_data->input);
206}
207
208/*
209 * Threaded IRQ handler and this can (and will) sleep.
210 */
211static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
212{
213 struct tca8418_keypad *keypad_data = dev_id;
214 u8 reg;
215 int error;
216
217 error = tca8418_read_byte(keypad_data, REG_INT_STAT, &reg);
218 if (error) {
219 dev_err(&keypad_data->client->dev,
220 "unable to read REG_INT_STAT\n");
221 goto exit;
222 }
223
224 if (reg & INT_STAT_OVR_FLOW_INT)
225 dev_warn(&keypad_data->client->dev, "overflow occurred\n");
226
227 if (reg & INT_STAT_K_INT)
228 tca8418_read_keypad(keypad_data);
229
230exit:
231 /* Clear all interrupts, even IRQs we didn't check (GPI, CAD, LCK) */
232 reg = 0xff;
233 error = tca8418_write_byte(keypad_data, REG_INT_STAT, reg);
234 if (error)
235 dev_err(&keypad_data->client->dev,
236 "unable to clear REG_INT_STAT\n");
237
238 return IRQ_HANDLED;
239}
240
241/*
242 * Configure the TCA8418 for keypad operation
243 */
244static int __devinit tca8418_configure(struct tca8418_keypad *keypad_data)
245{
246 int reg, error;
247
248 /* Write config register, if this fails assume device not present */
249 error = tca8418_write_byte(keypad_data, REG_CFG,
250 CFG_INT_CFG | CFG_OVR_FLOW_IEN | CFG_KE_IEN);
251 if (error < 0)
252 return -ENODEV;
253
254
255 /* Assemble a mask for row and column registers */
256 reg = ~(~0 << keypad_data->rows);
257 reg += (~(~0 << keypad_data->cols)) << 8;
258 keypad_data->keypad_mask = reg;
259
260 /* Set registers to keypad mode */
261 error |= tca8418_write_byte(keypad_data, REG_KP_GPIO1, reg);
262 error |= tca8418_write_byte(keypad_data, REG_KP_GPIO2, reg >> 8);
263 error |= tca8418_write_byte(keypad_data, REG_KP_GPIO3, reg >> 16);
264
265 /* Enable column debouncing */
266 error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS1, reg);
267 error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS2, reg >> 8);
268 error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS3, reg >> 16);
269
270 return error;
271}
272
273static int __devinit tca8418_keypad_probe(struct i2c_client *client,
274 const struct i2c_device_id *id)
275{
276 const struct tca8418_keypad_platform_data *pdata =
277 client->dev.platform_data;
278 struct tca8418_keypad *keypad_data;
279 struct input_dev *input;
280 int error, row_shift, max_keys;
281
282 /* Copy the platform data */
283 if (!pdata) {
284 dev_dbg(&client->dev, "no platform data\n");
285 return -EINVAL;
286 }
287
288 if (!pdata->keymap_data) {
289 dev_err(&client->dev, "no keymap data defined\n");
290 return -EINVAL;
291 }
292
293 if (!pdata->rows || pdata->rows > TCA8418_MAX_ROWS) {
294 dev_err(&client->dev, "invalid rows\n");
295 return -EINVAL;
296 }
297
298 if (!pdata->cols || pdata->cols > TCA8418_MAX_COLS) {
299 dev_err(&client->dev, "invalid columns\n");
300 return -EINVAL;
301 }
302
303 /* Check i2c driver capabilities */
304 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
305 dev_err(&client->dev, "%s adapter not supported\n",
306 dev_driver_string(&client->adapter->dev));
307 return -ENODEV;
308 }
309
310 row_shift = get_count_order(pdata->cols);
311 max_keys = pdata->rows << row_shift;
312
313 /* Allocate memory for keypad_data, keymap and input device */
314 keypad_data = kzalloc(sizeof(*keypad_data) +
315 max_keys * sizeof(keypad_data->keymap[0]), GFP_KERNEL);
316 if (!keypad_data)
317 return -ENOMEM;
318
319 keypad_data->rows = pdata->rows;
320 keypad_data->cols = pdata->cols;
321 keypad_data->client = client;
322 keypad_data->row_shift = row_shift;
323
324 /* Initialize the chip or fail if chip isn't present */
325 error = tca8418_configure(keypad_data);
326 if (error < 0)
327 goto fail1;
328
329 /* Configure input device */
330 input = input_allocate_device();
331 if (!input) {
332 error = -ENOMEM;
333 goto fail1;
334 }
335 keypad_data->input = input;
336
337 input->name = client->name;
338 input->dev.parent = &client->dev;
339
340 input->id.bustype = BUS_I2C;
341 input->id.vendor = 0x0001;
342 input->id.product = 0x001;
343 input->id.version = 0x0001;
344
345 input->keycode = keypad_data->keymap;
346 input->keycodesize = sizeof(keypad_data->keymap[0]);
347 input->keycodemax = max_keys;
348
349 __set_bit(EV_KEY, input->evbit);
350 if (pdata->rep)
351 __set_bit(EV_REP, input->evbit);
352
353 input_set_capability(input, EV_MSC, MSC_SCAN);
354
355 input_set_drvdata(input, keypad_data);
356
357 matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
358 input->keycode, input->keybit);
359
360 if (pdata->irq_is_gpio)
361 client->irq = gpio_to_irq(client->irq);
362
363 error = request_threaded_irq(client->irq, NULL, tca8418_irq_handler,
364 IRQF_TRIGGER_FALLING,
365 client->name, keypad_data);
366 if (error) {
367 dev_dbg(&client->dev,
368 "Unable to claim irq %d; error %d\n",
369 client->irq, error);
370 goto fail2;
371 }
372
373 error = input_register_device(input);
374 if (error) {
375 dev_dbg(&client->dev,
376 "Unable to register input device, error: %d\n", error);
377 goto fail3;
378 }
379
380 i2c_set_clientdata(client, keypad_data);
381 return 0;
382
383fail3:
384 free_irq(client->irq, keypad_data);
385fail2:
386 input_free_device(input);
387fail1:
388 kfree(keypad_data);
389 return error;
390}
391
392static int __devexit tca8418_keypad_remove(struct i2c_client *client)
393{
394 struct tca8418_keypad *keypad_data = i2c_get_clientdata(client);
395
396 free_irq(keypad_data->client->irq, keypad_data);
397
398 input_unregister_device(keypad_data->input);
399
400 kfree(keypad_data);
401
402 return 0;
403}
404
405
406static struct i2c_driver tca8418_keypad_driver = {
407 .driver = {
408 .name = TCA8418_NAME,
409 .owner = THIS_MODULE,
410 },
411 .probe = tca8418_keypad_probe,
412 .remove = __devexit_p(tca8418_keypad_remove),
413 .id_table = tca8418_id,
414};
415
416static int __init tca8418_keypad_init(void)
417{
418 return i2c_add_driver(&tca8418_keypad_driver);
419}
420subsys_initcall(tca8418_keypad_init);
421
422static void __exit tca8418_keypad_exit(void)
423{
424 i2c_del_driver(&tca8418_keypad_driver);
425}
426module_exit(tca8418_keypad_exit);
427
428MODULE_AUTHOR("Kyle Manna <kyle.manna@fuel7.com>");
429MODULE_DESCRIPTION("Keypad driver for TCA8418");
430MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index 09244804fb97..1cf72fe513e6 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -452,10 +452,10 @@ static ssize_t adxl34x_disable_store(struct device *dev,
452 const char *buf, size_t count) 452 const char *buf, size_t count)
453{ 453{
454 struct adxl34x *ac = dev_get_drvdata(dev); 454 struct adxl34x *ac = dev_get_drvdata(dev);
455 unsigned long val; 455 unsigned int val;
456 int error; 456 int error;
457 457
458 error = strict_strtoul(buf, 10, &val); 458 error = kstrtouint(buf, 10, &val);
459 if (error) 459 if (error)
460 return error; 460 return error;
461 461
@@ -541,10 +541,10 @@ static ssize_t adxl34x_rate_store(struct device *dev,
541 const char *buf, size_t count) 541 const char *buf, size_t count)
542{ 542{
543 struct adxl34x *ac = dev_get_drvdata(dev); 543 struct adxl34x *ac = dev_get_drvdata(dev);
544 unsigned long val; 544 unsigned char val;
545 int error; 545 int error;
546 546
547 error = strict_strtoul(buf, 10, &val); 547 error = kstrtou8(buf, 10, &val);
548 if (error) 548 if (error)
549 return error; 549 return error;
550 550
@@ -576,10 +576,10 @@ static ssize_t adxl34x_autosleep_store(struct device *dev,
576 const char *buf, size_t count) 576 const char *buf, size_t count)
577{ 577{
578 struct adxl34x *ac = dev_get_drvdata(dev); 578 struct adxl34x *ac = dev_get_drvdata(dev);
579 unsigned long val; 579 unsigned int val;
580 int error; 580 int error;
581 581
582 error = strict_strtoul(buf, 10, &val); 582 error = kstrtouint(buf, 10, &val);
583 if (error) 583 if (error)
584 return error; 584 return error;
585 585
@@ -623,13 +623,13 @@ static ssize_t adxl34x_write_store(struct device *dev,
623 const char *buf, size_t count) 623 const char *buf, size_t count)
624{ 624{
625 struct adxl34x *ac = dev_get_drvdata(dev); 625 struct adxl34x *ac = dev_get_drvdata(dev);
626 unsigned long val; 626 unsigned int val;
627 int error; 627 int error;
628 628
629 /* 629 /*
630 * This allows basic ADXL register write access for debug purposes. 630 * This allows basic ADXL register write access for debug purposes.
631 */ 631 */
632 error = strict_strtoul(buf, 16, &val); 632 error = kstrtouint(buf, 16, &val);
633 if (error) 633 if (error)
634 return error; 634 return error;
635 635
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 8d345e87075e..a34896ed7ed3 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -42,13 +42,13 @@ static int ati_remote2_set_mask(const char *val,
42 const struct kernel_param *kp, 42 const struct kernel_param *kp,
43 unsigned int max) 43 unsigned int max)
44{ 44{
45 unsigned long mask; 45 unsigned int mask;
46 int ret; 46 int ret;
47 47
48 if (!val) 48 if (!val)
49 return -EINVAL; 49 return -EINVAL;
50 50
51 ret = strict_strtoul(val, 0, &mask); 51 ret = kstrtouint(val, 0, &mask);
52 if (ret) 52 if (ret)
53 return ret; 53 return ret;
54 54
@@ -720,11 +720,12 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev,
720 struct usb_device *udev = to_usb_device(dev); 720 struct usb_device *udev = to_usb_device(dev);
721 struct usb_interface *intf = usb_ifnum_to_if(udev, 0); 721 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
722 struct ati_remote2 *ar2 = usb_get_intfdata(intf); 722 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
723 unsigned long mask; 723 unsigned int mask;
724 int r; 724 int r;
725 725
726 if (strict_strtoul(buf, 0, &mask)) 726 r = kstrtouint(buf, 0, &mask);
727 return -EINVAL; 727 if (r)
728 return r;
728 729
729 if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK) 730 if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
730 return -EINVAL; 731 return -EINVAL;
@@ -769,10 +770,12 @@ static ssize_t ati_remote2_store_mode_mask(struct device *dev,
769 struct usb_device *udev = to_usb_device(dev); 770 struct usb_device *udev = to_usb_device(dev);
770 struct usb_interface *intf = usb_ifnum_to_if(udev, 0); 771 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
771 struct ati_remote2 *ar2 = usb_get_intfdata(intf); 772 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
772 unsigned long mask; 773 unsigned int mask;
774 int err;
773 775
774 if (strict_strtoul(buf, 0, &mask)) 776 err = kstrtouint(buf, 0, &mask);
775 return -EINVAL; 777 if (err)
778 return err;
776 779
777 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK) 780 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
778 return -EINVAL; 781 return -EINVAL;
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 003587c71f43..bd87380bd879 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -17,13 +17,63 @@
17 17
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/input.h> 19#include <linux/input.h>
20#include <linux/input/mt.h>
20#include <linux/serio.h> 21#include <linux/serio.h>
21#include <linux/libps2.h> 22#include <linux/libps2.h>
22 23
23#include "psmouse.h" 24#include "psmouse.h"
24#include "alps.h" 25#include "alps.h"
25 26
26#define ALPS_OLDPROTO 0x01 /* old style input */ 27/*
28 * Definitions for ALPS version 3 and 4 command mode protocol
29 */
30#define ALPS_V3_X_MAX 2000
31#define ALPS_V3_Y_MAX 1400
32
33#define ALPS_BITMAP_X_BITS 15
34#define ALPS_BITMAP_Y_BITS 11
35
36#define ALPS_CMD_NIBBLE_10 0x01f2
37
38static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
39 { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
40 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
41 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
42 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
43 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
44 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
45 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
46 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
47 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
48 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
49 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
50 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
51 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
52 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
53 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
54 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
55};
56
57static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
58 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
59 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
60 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
61 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
62 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
63 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
64 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
65 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
66 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
67 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
68 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
69 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
70 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
71 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
72 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
73 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
74};
75
76
27#define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */ 77#define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
28#define ALPS_PASS 0x04 /* device has a pass-through port */ 78#define ALPS_PASS 0x04 /* device has a pass-through port */
29 79
@@ -35,30 +85,33 @@
35 6-byte ALPS packet */ 85 6-byte ALPS packet */
36 86
37static const struct alps_model_info alps_model_data[] = { 87static const struct alps_model_info alps_model_data[] = {
38 { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */ 88 { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
39 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ 89 { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
40 { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, 90 { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
41 { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 91 { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
42 { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */ 92 { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
43 { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, 93 { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
44 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 94 { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
45 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */ 95 { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
46 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ 96 { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
47 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */ 97 { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
48 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, 98 { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
49 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */ 99 { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
50 { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */ 100 { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
51 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, 101 { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
52 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */ 102 { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
53 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ 103 { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
54 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, 104 { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
55 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ 105 { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
56 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ 106 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
57 { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, 107 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
58 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, 108 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
59 { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ 109 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
60 { { 0x52, 0x01, 0x14 }, 0xff, 0xff, 110 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
61 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ 111 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
112 { { 0x73, 0x02, 0x64 }, 0x9b, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
113 { { 0x73, 0x02, 0x64 }, 0x9d, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
114 { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
62}; 115};
63 116
64/* 117/*
@@ -67,42 +120,7 @@ static const struct alps_model_info alps_model_data[] = {
67 * isn't valid per PS/2 spec. 120 * isn't valid per PS/2 spec.
68 */ 121 */
69 122
70/* 123/* Packet formats are described in Documentation/input/alps.txt */
71 * PS/2 packet format
72 *
73 * byte 0: 0 0 YSGN XSGN 1 M R L
74 * byte 1: X7 X6 X5 X4 X3 X2 X1 X0
75 * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
76 *
77 * Note that the device never signals overflow condition.
78 *
79 * ALPS absolute Mode - new format
80 *
81 * byte 0: 1 ? ? ? 1 ? ? ?
82 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
83 * byte 2: 0 x10 x9 x8 x7 ? fin ges
84 * byte 3: 0 y9 y8 y7 1 M R L
85 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
86 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
87 *
88 * Dualpoint device -- interleaved packet format
89 *
90 * byte 0: 1 1 0 0 1 1 1 1
91 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
92 * byte 2: 0 x10 x9 x8 x7 0 fin ges
93 * byte 3: 0 0 YSGN XSGN 1 1 1 1
94 * byte 4: X7 X6 X5 X4 X3 X2 X1 X0
95 * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
96 * byte 6: 0 y9 y8 y7 1 m r l
97 * byte 7: 0 y6 y5 y4 y3 y2 y1 y0
98 * byte 8: 0 z6 z5 z4 z3 z2 z1 z0
99 *
100 * CAPITALS = stick, miniscules = touchpad
101 *
102 * ?'s can have different meanings on different models,
103 * such as wheel rotation, extra buttons, stick buttons
104 * on a dualpoint, etc.
105 */
106 124
107static bool alps_is_valid_first_byte(const struct alps_model_info *model, 125static bool alps_is_valid_first_byte(const struct alps_model_info *model,
108 unsigned char data) 126 unsigned char data)
@@ -137,7 +155,7 @@ static void alps_report_buttons(struct psmouse *psmouse,
137 input_sync(dev2); 155 input_sync(dev2);
138} 156}
139 157
140static void alps_process_packet(struct psmouse *psmouse) 158static void alps_process_packet_v1_v2(struct psmouse *psmouse)
141{ 159{
142 struct alps_data *priv = psmouse->private; 160 struct alps_data *priv = psmouse->private;
143 const struct alps_model_info *model = priv->i; 161 const struct alps_model_info *model = priv->i;
@@ -147,7 +165,7 @@ static void alps_process_packet(struct psmouse *psmouse)
147 int x, y, z, ges, fin, left, right, middle; 165 int x, y, z, ges, fin, left, right, middle;
148 int back = 0, forward = 0; 166 int back = 0, forward = 0;
149 167
150 if (model->flags & ALPS_OLDPROTO) { 168 if (model->proto_version == ALPS_PROTO_V1) {
151 left = packet[2] & 0x10; 169 left = packet[2] & 0x10;
152 right = packet[2] & 0x08; 170 right = packet[2] & 0x08;
153 middle = 0; 171 middle = 0;
@@ -239,6 +257,403 @@ static void alps_process_packet(struct psmouse *psmouse)
239 input_sync(dev); 257 input_sync(dev);
240} 258}
241 259
260/*
261 * Process bitmap data from v3 and v4 protocols. Returns the number of
262 * fingers detected. A return value of 0 means at least one of the
263 * bitmaps was empty.
264 *
265 * The bitmaps don't have enough data to track fingers, so this function
266 * only generates points representing a bounding box of all contacts.
267 * These points are returned in x1, y1, x2, and y2 when the return value
268 * is greater than 0.
269 */
270static int alps_process_bitmap(unsigned int x_map, unsigned int y_map,
271 int *x1, int *y1, int *x2, int *y2)
272{
273 struct alps_bitmap_point {
274 int start_bit;
275 int num_bits;
276 };
277
278 int fingers_x = 0, fingers_y = 0, fingers;
279 int i, bit, prev_bit;
280 struct alps_bitmap_point x_low = {0,}, x_high = {0,};
281 struct alps_bitmap_point y_low = {0,}, y_high = {0,};
282 struct alps_bitmap_point *point;
283
284 if (!x_map || !y_map)
285 return 0;
286
287 *x1 = *y1 = *x2 = *y2 = 0;
288
289 prev_bit = 0;
290 point = &x_low;
291 for (i = 0; x_map != 0; i++, x_map >>= 1) {
292 bit = x_map & 1;
293 if (bit) {
294 if (!prev_bit) {
295 point->start_bit = i;
296 fingers_x++;
297 }
298 point->num_bits++;
299 } else {
300 if (prev_bit)
301 point = &x_high;
302 else
303 point->num_bits = 0;
304 }
305 prev_bit = bit;
306 }
307
308 /*
309 * y bitmap is reversed for what we need (lower positions are in
310 * higher bits), so we process from the top end.
311 */
312 y_map = y_map << (sizeof(y_map) * BITS_PER_BYTE - ALPS_BITMAP_Y_BITS);
313 prev_bit = 0;
314 point = &y_low;
315 for (i = 0; y_map != 0; i++, y_map <<= 1) {
316 bit = y_map & (1 << (sizeof(y_map) * BITS_PER_BYTE - 1));
317 if (bit) {
318 if (!prev_bit) {
319 point->start_bit = i;
320 fingers_y++;
321 }
322 point->num_bits++;
323 } else {
324 if (prev_bit)
325 point = &y_high;
326 else
327 point->num_bits = 0;
328 }
329 prev_bit = bit;
330 }
331
332 /*
333 * Fingers can overlap, so we use the maximum count of fingers
334 * on either axis as the finger count.
335 */
336 fingers = max(fingers_x, fingers_y);
337
338 /*
339 * If total fingers is > 1 but either axis reports only a single
340 * contact, we have overlapping or adjacent fingers. For the
341 * purposes of creating a bounding box, divide the single contact
342 * (roughly) equally between the two points.
343 */
344 if (fingers > 1) {
345 if (fingers_x == 1) {
346 i = x_low.num_bits / 2;
347 x_low.num_bits = x_low.num_bits - i;
348 x_high.start_bit = x_low.start_bit + i;
349 x_high.num_bits = max(i, 1);
350 } else if (fingers_y == 1) {
351 i = y_low.num_bits / 2;
352 y_low.num_bits = y_low.num_bits - i;
353 y_high.start_bit = y_low.start_bit + i;
354 y_high.num_bits = max(i, 1);
355 }
356 }
357
358 *x1 = (ALPS_V3_X_MAX * (2 * x_low.start_bit + x_low.num_bits - 1)) /
359 (2 * (ALPS_BITMAP_X_BITS - 1));
360 *y1 = (ALPS_V3_Y_MAX * (2 * y_low.start_bit + y_low.num_bits - 1)) /
361 (2 * (ALPS_BITMAP_Y_BITS - 1));
362
363 if (fingers > 1) {
364 *x2 = (ALPS_V3_X_MAX * (2 * x_high.start_bit + x_high.num_bits - 1)) /
365 (2 * (ALPS_BITMAP_X_BITS - 1));
366 *y2 = (ALPS_V3_Y_MAX * (2 * y_high.start_bit + y_high.num_bits - 1)) /
367 (2 * (ALPS_BITMAP_Y_BITS - 1));
368 }
369
370 return fingers;
371}
372
373static void alps_set_slot(struct input_dev *dev, int slot, bool active,
374 int x, int y)
375{
376 input_mt_slot(dev, slot);
377 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
378 if (active) {
379 input_report_abs(dev, ABS_MT_POSITION_X, x);
380 input_report_abs(dev, ABS_MT_POSITION_Y, y);
381 }
382}
383
384static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers,
385 int x1, int y1, int x2, int y2)
386{
387 alps_set_slot(dev, 0, num_fingers != 0, x1, y1);
388 alps_set_slot(dev, 1, num_fingers == 2, x2, y2);
389}
390
391static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
392{
393 struct alps_data *priv = psmouse->private;
394 unsigned char *packet = psmouse->packet;
395 struct input_dev *dev = priv->dev2;
396 int x, y, z, left, right, middle;
397
398 /* Sanity check packet */
399 if (!(packet[0] & 0x40)) {
400 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
401 return;
402 }
403
404 /*
405 * There's a special packet that seems to indicate the end
406 * of a stream of trackstick data. Filter these out.
407 */
408 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
409 return;
410
411 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
412 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
413 z = (packet[4] & 0x7c) >> 2;
414
415 /*
416 * The x and y values tend to be quite large, and when used
417 * alone the trackstick is difficult to use. Scale them down
418 * to compensate.
419 */
420 x /= 8;
421 y /= 8;
422
423 input_report_rel(dev, REL_X, x);
424 input_report_rel(dev, REL_Y, -y);
425
426 /*
427 * Most ALPS models report the trackstick buttons in the touchpad
428 * packets, but a few report them here. No reliable way has been
429 * found to differentiate between the models upfront, so we enable
430 * the quirk in response to seeing a button press in the trackstick
431 * packet.
432 */
433 left = packet[3] & 0x01;
434 right = packet[3] & 0x02;
435 middle = packet[3] & 0x04;
436
437 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
438 (left || right || middle))
439 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
440
441 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
442 input_report_key(dev, BTN_LEFT, left);
443 input_report_key(dev, BTN_RIGHT, right);
444 input_report_key(dev, BTN_MIDDLE, middle);
445 }
446
447 input_sync(dev);
448 return;
449}
450
451static void alps_process_touchpad_packet_v3(struct psmouse *psmouse)
452{
453 struct alps_data *priv = psmouse->private;
454 unsigned char *packet = psmouse->packet;
455 struct input_dev *dev = psmouse->dev;
456 struct input_dev *dev2 = priv->dev2;
457 int x, y, z;
458 int left, right, middle;
459 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
460 int fingers = 0, bmap_fingers;
461 unsigned int x_bitmap, y_bitmap;
462
463 /*
464 * There's no single feature of touchpad position and bitmap packets
465 * that can be used to distinguish between them. We rely on the fact
466 * that a bitmap packet should always follow a position packet with
467 * bit 6 of packet[4] set.
468 */
469 if (priv->multi_packet) {
470 /*
471 * Sometimes a position packet will indicate a multi-packet
472 * sequence, but then what follows is another position
473 * packet. Check for this, and when it happens process the
474 * position packet as usual.
475 */
476 if (packet[0] & 0x40) {
477 fingers = (packet[5] & 0x3) + 1;
478 x_bitmap = ((packet[4] & 0x7e) << 8) |
479 ((packet[1] & 0x7f) << 2) |
480 ((packet[0] & 0x30) >> 4);
481 y_bitmap = ((packet[3] & 0x70) << 4) |
482 ((packet[2] & 0x7f) << 1) |
483 (packet[4] & 0x01);
484
485 bmap_fingers = alps_process_bitmap(x_bitmap, y_bitmap,
486 &x1, &y1, &x2, &y2);
487
488 /*
489 * We shouldn't report more than one finger if
490 * we don't have two coordinates.
491 */
492 if (fingers > 1 && bmap_fingers < 2)
493 fingers = bmap_fingers;
494
495 /* Now process position packet */
496 packet = priv->multi_data;
497 } else {
498 priv->multi_packet = 0;
499 }
500 }
501
502 /*
503 * Bit 6 of byte 0 is not usually set in position packets. The only
504 * times it seems to be set is in situations where the data is
505 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
506 * this combined with the fact that this bit is useful for filtering
507 * out misidentified bitmap packets, we reject anything with this
508 * bit set.
509 */
510 if (packet[0] & 0x40)
511 return;
512
513 if (!priv->multi_packet && (packet[4] & 0x40)) {
514 priv->multi_packet = 1;
515 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
516 return;
517 }
518
519 priv->multi_packet = 0;
520
521 left = packet[3] & 0x01;
522 right = packet[3] & 0x02;
523 middle = packet[3] & 0x04;
524
525 x = ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) |
526 ((packet[0] & 0x30) >> 4);
527 y = ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f);
528 z = packet[5] & 0x7f;
529
530 /*
531 * Sometimes the hardware sends a single packet with z = 0
532 * in the middle of a stream. Real releases generate packets
533 * with x, y, and z all zero, so these seem to be flukes.
534 * Ignore them.
535 */
536 if (x && y && !z)
537 return;
538
539 /*
540 * If we don't have MT data or the bitmaps were empty, we have
541 * to rely on ST data.
542 */
543 if (!fingers) {
544 x1 = x;
545 y1 = y;
546 fingers = z > 0 ? 1 : 0;
547 }
548
549 if (z >= 64)
550 input_report_key(dev, BTN_TOUCH, 1);
551 else
552 input_report_key(dev, BTN_TOUCH, 0);
553
554 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
555
556 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
557 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
558 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
559 input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
560
561 input_report_key(dev, BTN_LEFT, left);
562 input_report_key(dev, BTN_RIGHT, right);
563 input_report_key(dev, BTN_MIDDLE, middle);
564
565 if (z > 0) {
566 input_report_abs(dev, ABS_X, x);
567 input_report_abs(dev, ABS_Y, y);
568 }
569 input_report_abs(dev, ABS_PRESSURE, z);
570
571 input_sync(dev);
572
573 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
574 left = packet[3] & 0x10;
575 right = packet[3] & 0x20;
576 middle = packet[3] & 0x40;
577
578 input_report_key(dev2, BTN_LEFT, left);
579 input_report_key(dev2, BTN_RIGHT, right);
580 input_report_key(dev2, BTN_MIDDLE, middle);
581 input_sync(dev2);
582 }
583}
584
585static void alps_process_packet_v3(struct psmouse *psmouse)
586{
587 unsigned char *packet = psmouse->packet;
588
589 /*
590 * v3 protocol packets come in three types, two representing
591 * touchpad data and one representing trackstick data.
592 * Trackstick packets seem to be distinguished by always
593 * having 0x3f in the last byte. This value has never been
594 * observed in the last byte of either of the other types
595 * of packets.
596 */
597 if (packet[5] == 0x3f) {
598 alps_process_trackstick_packet_v3(psmouse);
599 return;
600 }
601
602 alps_process_touchpad_packet_v3(psmouse);
603}
604
605static void alps_process_packet_v4(struct psmouse *psmouse)
606{
607 unsigned char *packet = psmouse->packet;
608 struct input_dev *dev = psmouse->dev;
609 int x, y, z;
610 int left, right;
611
612 left = packet[4] & 0x01;
613 right = packet[4] & 0x02;
614
615 x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
616 ((packet[0] & 0x30) >> 4);
617 y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
618 z = packet[5] & 0x7f;
619
620 if (z >= 64)
621 input_report_key(dev, BTN_TOUCH, 1);
622 else
623 input_report_key(dev, BTN_TOUCH, 0);
624
625 if (z > 0) {
626 input_report_abs(dev, ABS_X, x);
627 input_report_abs(dev, ABS_Y, y);
628 }
629 input_report_abs(dev, ABS_PRESSURE, z);
630
631 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
632 input_report_key(dev, BTN_LEFT, left);
633 input_report_key(dev, BTN_RIGHT, right);
634
635 input_sync(dev);
636}
637
638static void alps_process_packet(struct psmouse *psmouse)
639{
640 struct alps_data *priv = psmouse->private;
641 const struct alps_model_info *model = priv->i;
642
643 switch (model->proto_version) {
644 case ALPS_PROTO_V1:
645 case ALPS_PROTO_V2:
646 alps_process_packet_v1_v2(psmouse);
647 break;
648 case ALPS_PROTO_V3:
649 alps_process_packet_v3(psmouse);
650 break;
651 case ALPS_PROTO_V4:
652 alps_process_packet_v4(psmouse);
653 break;
654 }
655}
656
242static void alps_report_bare_ps2_packet(struct psmouse *psmouse, 657static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
243 unsigned char packet[], 658 unsigned char packet[],
244 bool report_buttons) 659 bool report_buttons)
@@ -344,7 +759,7 @@ static void alps_flush_packet(unsigned long data)
344 759
345 serio_pause_rx(psmouse->ps2dev.serio); 760 serio_pause_rx(psmouse->ps2dev.serio);
346 761
347 if (psmouse->pktcnt == 6) { 762 if (psmouse->pktcnt == psmouse->pktsize) {
348 763
349 /* 764 /*
350 * We did not any more data in reasonable amount of time. 765 * We did not any more data in reasonable amount of time.
@@ -395,8 +810,8 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
395 return PSMOUSE_BAD_DATA; 810 return PSMOUSE_BAD_DATA;
396 } 811 }
397 812
398 /* Bytes 2 - 6 should have 0 in the highest bit */ 813 /* Bytes 2 - pktsize should have 0 in the highest bit */
399 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 && 814 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
400 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { 815 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
401 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", 816 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
402 psmouse->pktcnt - 1, 817 psmouse->pktcnt - 1,
@@ -404,7 +819,7 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
404 return PSMOUSE_BAD_DATA; 819 return PSMOUSE_BAD_DATA;
405 } 820 }
406 821
407 if (psmouse->pktcnt == 6) { 822 if (psmouse->pktcnt == psmouse->pktsize) {
408 alps_process_packet(psmouse); 823 alps_process_packet(psmouse);
409 return PSMOUSE_FULL_PACKET; 824 return PSMOUSE_FULL_PACKET;
410 } 825 }
@@ -412,11 +827,127 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
412 return PSMOUSE_GOOD_DATA; 827 return PSMOUSE_GOOD_DATA;
413} 828}
414 829
830static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
831{
832 struct ps2dev *ps2dev = &psmouse->ps2dev;
833 struct alps_data *priv = psmouse->private;
834 int command;
835 unsigned char *param;
836 unsigned char dummy[4];
837
838 BUG_ON(nibble > 0xf);
839
840 command = priv->nibble_commands[nibble].command;
841 param = (command & 0x0f00) ?
842 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
843
844 if (ps2_command(ps2dev, param, command))
845 return -1;
846
847 return 0;
848}
849
850static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
851{
852 struct ps2dev *ps2dev = &psmouse->ps2dev;
853 struct alps_data *priv = psmouse->private;
854 int i, nibble;
855
856 if (ps2_command(ps2dev, NULL, priv->addr_command))
857 return -1;
858
859 for (i = 12; i >= 0; i -= 4) {
860 nibble = (addr >> i) & 0xf;
861 if (alps_command_mode_send_nibble(psmouse, nibble))
862 return -1;
863 }
864
865 return 0;
866}
867
868static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
869{
870 struct ps2dev *ps2dev = &psmouse->ps2dev;
871 unsigned char param[4];
872
873 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
874 return -1;
875
876 /*
877 * The address being read is returned in the first two bytes
878 * of the result. Check that this address matches the expected
879 * address.
880 */
881 if (addr != ((param[0] << 8) | param[1]))
882 return -1;
883
884 return param[2];
885}
886
887static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
888{
889 if (alps_command_mode_set_addr(psmouse, addr))
890 return -1;
891 return __alps_command_mode_read_reg(psmouse, addr);
892}
893
894static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
895{
896 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
897 return -1;
898 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
899 return -1;
900 return 0;
901}
902
903static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
904 u8 value)
905{
906 if (alps_command_mode_set_addr(psmouse, addr))
907 return -1;
908 return __alps_command_mode_write_reg(psmouse, value);
909}
910
911static int alps_enter_command_mode(struct psmouse *psmouse,
912 unsigned char *resp)
913{
914 unsigned char param[4];
915 struct ps2dev *ps2dev = &psmouse->ps2dev;
916
917 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
918 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
919 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
920 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
921 psmouse_err(psmouse, "failed to enter command mode\n");
922 return -1;
923 }
924
925 if (param[0] != 0x88 && param[1] != 0x07) {
926 psmouse_dbg(psmouse,
927 "unknown response while entering command mode: %2.2x %2.2x %2.2x\n",
928 param[0], param[1], param[2]);
929 return -1;
930 }
931
932 if (resp)
933 *resp = param[2];
934 return 0;
935}
936
937static inline int alps_exit_command_mode(struct psmouse *psmouse)
938{
939 struct ps2dev *ps2dev = &psmouse->ps2dev;
940 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
941 return -1;
942 return 0;
943}
944
415static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version) 945static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
416{ 946{
417 struct ps2dev *ps2dev = &psmouse->ps2dev; 947 struct ps2dev *ps2dev = &psmouse->ps2dev;
418 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 }; 948 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
419 unsigned char param[4]; 949 unsigned char param[4];
950 const struct alps_model_info *model = NULL;
420 int i; 951 int i;
421 952
422 /* 953 /*
@@ -464,12 +995,41 @@ static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int
464 *version = (param[0] << 8) | (param[1] << 4) | i; 995 *version = (param[0] << 8) | (param[1] << 4) | i;
465 } 996 }
466 997
467 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) 998 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
468 if (!memcmp(param, alps_model_data[i].signature, 999 if (!memcmp(param, alps_model_data[i].signature,
469 sizeof(alps_model_data[i].signature))) 1000 sizeof(alps_model_data[i].signature))) {
470 return alps_model_data + i; 1001 model = alps_model_data + i;
1002 break;
1003 }
1004 }
471 1005
472 return NULL; 1006 if (model && model->proto_version > ALPS_PROTO_V2) {
1007 /*
1008 * Need to check command mode response to identify
1009 * model
1010 */
1011 model = NULL;
1012 if (alps_enter_command_mode(psmouse, param)) {
1013 psmouse_warn(psmouse,
1014 "touchpad failed to enter command mode\n");
1015 } else {
1016 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1017 if (alps_model_data[i].proto_version > ALPS_PROTO_V2 &&
1018 alps_model_data[i].command_mode_resp == param[0]) {
1019 model = alps_model_data + i;
1020 break;
1021 }
1022 }
1023 alps_exit_command_mode(psmouse);
1024
1025 if (!model)
1026 psmouse_dbg(psmouse,
1027 "Unknown command mode response %2.2x\n",
1028 param[0]);
1029 }
1030 }
1031
1032 return model;
473} 1033}
474 1034
475/* 1035/*
@@ -477,7 +1037,7 @@ static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int
477 * subsequent commands. It looks like glidepad is behind stickpointer, 1037 * subsequent commands. It looks like glidepad is behind stickpointer,
478 * I'd thought it would be other way around... 1038 * I'd thought it would be other way around...
479 */ 1039 */
480static int alps_passthrough_mode(struct psmouse *psmouse, bool enable) 1040static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
481{ 1041{
482 struct ps2dev *ps2dev = &psmouse->ps2dev; 1042 struct ps2dev *ps2dev = &psmouse->ps2dev;
483 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; 1043 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
@@ -494,7 +1054,7 @@ static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
494 return 0; 1054 return 0;
495} 1055}
496 1056
497static int alps_absolute_mode(struct psmouse *psmouse) 1057static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
498{ 1058{
499 struct ps2dev *ps2dev = &psmouse->ps2dev; 1059 struct ps2dev *ps2dev = &psmouse->ps2dev;
500 1060
@@ -565,17 +1125,17 @@ static int alps_tap_mode(struct psmouse *psmouse, int enable)
565static int alps_poll(struct psmouse *psmouse) 1125static int alps_poll(struct psmouse *psmouse)
566{ 1126{
567 struct alps_data *priv = psmouse->private; 1127 struct alps_data *priv = psmouse->private;
568 unsigned char buf[6]; 1128 unsigned char buf[sizeof(psmouse->packet)];
569 bool poll_failed; 1129 bool poll_failed;
570 1130
571 if (priv->i->flags & ALPS_PASS) 1131 if (priv->i->flags & ALPS_PASS)
572 alps_passthrough_mode(psmouse, true); 1132 alps_passthrough_mode_v2(psmouse, true);
573 1133
574 poll_failed = ps2_command(&psmouse->ps2dev, buf, 1134 poll_failed = ps2_command(&psmouse->ps2dev, buf,
575 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; 1135 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
576 1136
577 if (priv->i->flags & ALPS_PASS) 1137 if (priv->i->flags & ALPS_PASS)
578 alps_passthrough_mode(psmouse, false); 1138 alps_passthrough_mode_v2(psmouse, false);
579 1139
580 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) 1140 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
581 return -1; 1141 return -1;
@@ -592,13 +1152,13 @@ static int alps_poll(struct psmouse *psmouse)
592 return 0; 1152 return 0;
593} 1153}
594 1154
595static int alps_hw_init(struct psmouse *psmouse) 1155static int alps_hw_init_v1_v2(struct psmouse *psmouse)
596{ 1156{
597 struct alps_data *priv = psmouse->private; 1157 struct alps_data *priv = psmouse->private;
598 const struct alps_model_info *model = priv->i; 1158 const struct alps_model_info *model = priv->i;
599 1159
600 if ((model->flags & ALPS_PASS) && 1160 if ((model->flags & ALPS_PASS) &&
601 alps_passthrough_mode(psmouse, true)) { 1161 alps_passthrough_mode_v2(psmouse, true)) {
602 return -1; 1162 return -1;
603 } 1163 }
604 1164
@@ -607,13 +1167,13 @@ static int alps_hw_init(struct psmouse *psmouse)
607 return -1; 1167 return -1;
608 } 1168 }
609 1169
610 if (alps_absolute_mode(psmouse)) { 1170 if (alps_absolute_mode_v1_v2(psmouse)) {
611 psmouse_err(psmouse, "Failed to enable absolute mode\n"); 1171 psmouse_err(psmouse, "Failed to enable absolute mode\n");
612 return -1; 1172 return -1;
613 } 1173 }
614 1174
615 if ((model->flags & ALPS_PASS) && 1175 if ((model->flags & ALPS_PASS) &&
616 alps_passthrough_mode(psmouse, false)) { 1176 alps_passthrough_mode_v2(psmouse, false)) {
617 return -1; 1177 return -1;
618 } 1178 }
619 1179
@@ -626,6 +1186,297 @@ static int alps_hw_init(struct psmouse *psmouse)
626 return 0; 1186 return 0;
627} 1187}
628 1188
1189/*
1190 * Enable or disable passthrough mode to the trackstick. Must be in
1191 * command mode when calling this function.
1192 */
1193static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable)
1194{
1195 int reg_val;
1196
1197 reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
1198 if (reg_val == -1)
1199 return -1;
1200
1201 if (enable)
1202 reg_val |= 0x01;
1203 else
1204 reg_val &= ~0x01;
1205
1206 if (__alps_command_mode_write_reg(psmouse, reg_val))
1207 return -1;
1208
1209 return 0;
1210}
1211
1212/* Must be in command mode when calling this function */
1213static int alps_absolute_mode_v3(struct psmouse *psmouse)
1214{
1215 int reg_val;
1216
1217 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1218 if (reg_val == -1)
1219 return -1;
1220
1221 reg_val |= 0x06;
1222 if (__alps_command_mode_write_reg(psmouse, reg_val))
1223 return -1;
1224
1225 return 0;
1226}
1227
1228static int alps_hw_init_v3(struct psmouse *psmouse)
1229{
1230 struct alps_data *priv = psmouse->private;
1231 struct ps2dev *ps2dev = &psmouse->ps2dev;
1232 int reg_val;
1233 unsigned char param[4];
1234
1235 priv->nibble_commands = alps_v3_nibble_commands;
1236 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
1237
1238 if (alps_enter_command_mode(psmouse, NULL))
1239 goto error;
1240
1241 /* Check for trackstick */
1242 reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
1243 if (reg_val == -1)
1244 goto error;
1245 if (reg_val & 0x80) {
1246 if (alps_passthrough_mode_v3(psmouse, true))
1247 goto error;
1248 if (alps_exit_command_mode(psmouse))
1249 goto error;
1250
1251 /*
1252 * E7 report for the trackstick
1253 *
1254 * There have been reports of failures to seem to trace back
1255 * to the above trackstick check failing. When these occur
1256 * this E7 report fails, so when that happens we continue
1257 * with the assumption that there isn't a trackstick after
1258 * all.
1259 */
1260 param[0] = 0x64;
1261 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1262 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1263 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1264 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
1265 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1266 } else {
1267 psmouse_dbg(psmouse,
1268 "trackstick E7 report: %2.2x %2.2x %2.2x\n",
1269 param[0], param[1], param[2]);
1270
1271 /*
1272 * Not sure what this does, but it is absolutely
1273 * essential. Without it, the touchpad does not
1274 * work at all and the trackstick just emits normal
1275 * PS/2 packets.
1276 */
1277 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1278 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1279 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1280 alps_command_mode_send_nibble(psmouse, 0x9) ||
1281 alps_command_mode_send_nibble(psmouse, 0x4)) {
1282 psmouse_err(psmouse,
1283 "Error sending magic E6 sequence\n");
1284 goto error_passthrough;
1285 }
1286 }
1287
1288 if (alps_enter_command_mode(psmouse, NULL))
1289 goto error_passthrough;
1290 if (alps_passthrough_mode_v3(psmouse, false))
1291 goto error;
1292 }
1293
1294 if (alps_absolute_mode_v3(psmouse)) {
1295 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1296 goto error;
1297 }
1298
1299 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1300 if (reg_val == -1)
1301 goto error;
1302 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1303 goto error;
1304
1305 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1306 if (reg_val == -1)
1307 goto error;
1308 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1309 goto error;
1310
1311 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1312 goto error;
1313 if (__alps_command_mode_write_reg(psmouse, 0x04))
1314 goto error;
1315
1316 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1317 goto error;
1318 if (__alps_command_mode_write_reg(psmouse, 0x03))
1319 goto error;
1320
1321 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1322 goto error;
1323 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1324 goto error;
1325
1326 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1327 goto error;
1328 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1329 goto error;
1330
1331 /*
1332 * This ensures the trackstick packets are in the format
1333 * supported by this driver. If bit 1 isn't set the packet
1334 * format is different.
1335 */
1336 if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82))
1337 goto error;
1338
1339 alps_exit_command_mode(psmouse);
1340
1341 /* Set rate and enable data reporting */
1342 param[0] = 0x64;
1343 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1344 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1345 psmouse_err(psmouse, "Failed to enable data reporting\n");
1346 return -1;
1347 }
1348
1349 return 0;
1350
1351error_passthrough:
1352 /* Something failed while in passthrough mode, so try to get out */
1353 if (!alps_enter_command_mode(psmouse, NULL))
1354 alps_passthrough_mode_v3(psmouse, false);
1355error:
1356 /*
1357 * Leaving the touchpad in command mode will essentially render
1358 * it unusable until the machine reboots, so exit it here just
1359 * to be safe
1360 */
1361 alps_exit_command_mode(psmouse);
1362 return -1;
1363}
1364
1365/* Must be in command mode when calling this function */
1366static int alps_absolute_mode_v4(struct psmouse *psmouse)
1367{
1368 int reg_val;
1369
1370 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1371 if (reg_val == -1)
1372 return -1;
1373
1374 reg_val |= 0x02;
1375 if (__alps_command_mode_write_reg(psmouse, reg_val))
1376 return -1;
1377
1378 return 0;
1379}
1380
1381static int alps_hw_init_v4(struct psmouse *psmouse)
1382{
1383 struct alps_data *priv = psmouse->private;
1384 struct ps2dev *ps2dev = &psmouse->ps2dev;
1385 unsigned char param[4];
1386
1387 priv->nibble_commands = alps_v4_nibble_commands;
1388 priv->addr_command = PSMOUSE_CMD_DISABLE;
1389
1390 if (alps_enter_command_mode(psmouse, NULL))
1391 goto error;
1392
1393 if (alps_absolute_mode_v4(psmouse)) {
1394 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1395 goto error;
1396 }
1397
1398 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1399 goto error;
1400
1401 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1402 goto error;
1403
1404 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1405 goto error;
1406
1407 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1408 goto error;
1409
1410 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1411 goto error;
1412
1413 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1414 goto error;
1415
1416 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1417 goto error;
1418
1419 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1420 goto error;
1421
1422 alps_exit_command_mode(psmouse);
1423
1424 /*
1425 * This sequence changes the output from a 9-byte to an
1426 * 8-byte format. All the same data seems to be present,
1427 * just in a more compact format.
1428 */
1429 param[0] = 0xc8;
1430 param[1] = 0x64;
1431 param[2] = 0x50;
1432 if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1433 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1434 ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1435 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1436 return -1;
1437
1438 /* Set rate and enable data reporting */
1439 param[0] = 0x64;
1440 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1441 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1442 psmouse_err(psmouse, "Failed to enable data reporting\n");
1443 return -1;
1444 }
1445
1446 return 0;
1447
1448error:
1449 /*
1450 * Leaving the touchpad in command mode will essentially render
1451 * it unusable until the machine reboots, so exit it here just
1452 * to be safe
1453 */
1454 alps_exit_command_mode(psmouse);
1455 return -1;
1456}
1457
1458static int alps_hw_init(struct psmouse *psmouse)
1459{
1460 struct alps_data *priv = psmouse->private;
1461 const struct alps_model_info *model = priv->i;
1462 int ret = -1;
1463
1464 switch (model->proto_version) {
1465 case ALPS_PROTO_V1:
1466 case ALPS_PROTO_V2:
1467 ret = alps_hw_init_v1_v2(psmouse);
1468 break;
1469 case ALPS_PROTO_V3:
1470 ret = alps_hw_init_v3(psmouse);
1471 break;
1472 case ALPS_PROTO_V4:
1473 ret = alps_hw_init_v4(psmouse);
1474 break;
1475 }
1476
1477 return ret;
1478}
1479
629static int alps_reconnect(struct psmouse *psmouse) 1480static int alps_reconnect(struct psmouse *psmouse)
630{ 1481{
631 const struct alps_model_info *model; 1482 const struct alps_model_info *model;
@@ -666,6 +1517,8 @@ int alps_init(struct psmouse *psmouse)
666 1517
667 psmouse->private = priv; 1518 psmouse->private = priv;
668 1519
1520 psmouse_reset(psmouse);
1521
669 model = alps_get_model(psmouse, &version); 1522 model = alps_get_model(psmouse, &version);
670 if (!model) 1523 if (!model)
671 goto init_fail; 1524 goto init_fail;
@@ -693,8 +1546,29 @@ int alps_init(struct psmouse *psmouse)
693 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); 1546 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
694 1547
695 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); 1548 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
696 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); 1549
697 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0); 1550 switch (model->proto_version) {
1551 case ALPS_PROTO_V1:
1552 case ALPS_PROTO_V2:
1553 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1554 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1555 break;
1556 case ALPS_PROTO_V3:
1557 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
1558 input_mt_init_slots(dev1, 2);
1559 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0);
1560 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0);
1561
1562 set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
1563 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
1564 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
1565 /* fall through */
1566 case ALPS_PROTO_V4:
1567 input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
1568 input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
1569 break;
1570 }
1571
698 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); 1572 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
699 1573
700 if (model->flags & ALPS_WHEEL) { 1574 if (model->flags & ALPS_WHEEL) {
@@ -737,7 +1611,7 @@ int alps_init(struct psmouse *psmouse)
737 psmouse->poll = alps_poll; 1611 psmouse->poll = alps_poll;
738 psmouse->disconnect = alps_disconnect; 1612 psmouse->disconnect = alps_disconnect;
739 psmouse->reconnect = alps_reconnect; 1613 psmouse->reconnect = alps_reconnect;
740 psmouse->pktsize = 6; 1614 psmouse->pktsize = model->proto_version == ALPS_PROTO_V4 ? 8 : 6;
741 1615
742 /* We are having trouble resyncing ALPS touchpads so disable it for now */ 1616 /* We are having trouble resyncing ALPS touchpads so disable it for now */
743 psmouse->resync_time = 0; 1617 psmouse->resync_time = 0;
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index 904ed8b3c8be..a00a4ab92a0f 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -12,20 +12,39 @@
12#ifndef _ALPS_H 12#ifndef _ALPS_H
13#define _ALPS_H 13#define _ALPS_H
14 14
15#define ALPS_PROTO_V1 0
16#define ALPS_PROTO_V2 1
17#define ALPS_PROTO_V3 2
18#define ALPS_PROTO_V4 3
19
15struct alps_model_info { 20struct alps_model_info {
16 unsigned char signature[3]; 21 unsigned char signature[3];
22 unsigned char command_mode_resp; /* v3/v4 only */
23 unsigned char proto_version;
17 unsigned char byte0, mask0; 24 unsigned char byte0, mask0;
18 unsigned char flags; 25 unsigned char flags;
19}; 26};
20 27
28struct alps_nibble_commands {
29 int command;
30 unsigned char data;
31};
32
21struct alps_data { 33struct alps_data {
22 struct input_dev *dev2; /* Relative device */ 34 struct input_dev *dev2; /* Relative device */
23 char phys[32]; /* Phys */ 35 char phys[32]; /* Phys */
24 const struct alps_model_info *i;/* Info */ 36 const struct alps_model_info *i;/* Info */
37 const struct alps_nibble_commands *nibble_commands;
38 int addr_command; /* Command to set register address */
25 int prev_fin; /* Finger bit from previous packet */ 39 int prev_fin; /* Finger bit from previous packet */
40 int multi_packet; /* Multi-packet data in progress */
41 unsigned char multi_data[6]; /* Saved multi-packet data */
42 u8 quirks;
26 struct timer_list timer; 43 struct timer_list timer;
27}; 44};
28 45
46#define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */
47
29#ifdef CONFIG_MOUSE_PS2_ALPS 48#ifdef CONFIG_MOUSE_PS2_ALPS
30int alps_detect(struct psmouse *psmouse, bool set_properties); 49int alps_detect(struct psmouse *psmouse, bool set_properties);
31int alps_init(struct psmouse *psmouse); 50int alps_init(struct psmouse *psmouse);
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index e2a9867c19d5..d2c0db159b18 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -43,6 +43,24 @@ static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c,
43} 43}
44 44
45/* 45/*
46 * V3 and later support this fast command
47 */
48static int elantech_send_cmd(struct psmouse *psmouse, unsigned char c,
49 unsigned char *param)
50{
51 struct ps2dev *ps2dev = &psmouse->ps2dev;
52
53 if (ps2_command(ps2dev, NULL, ETP_PS2_CUSTOM_COMMAND) ||
54 ps2_command(ps2dev, NULL, c) ||
55 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
56 psmouse_err(psmouse, "%s query 0x%02x failed.\n", __func__, c);
57 return -1;
58 }
59
60 return 0;
61}
62
63/*
46 * A retrying version of ps2_command 64 * A retrying version of ps2_command
47 */ 65 */
48static int elantech_ps2_command(struct psmouse *psmouse, 66static int elantech_ps2_command(struct psmouse *psmouse,
@@ -863,13 +881,13 @@ static int elantech_set_range(struct psmouse *psmouse,
863 i = (etd->fw_version > 0x020800 && 881 i = (etd->fw_version > 0x020800 &&
864 etd->fw_version < 0x020900) ? 1 : 2; 882 etd->fw_version < 0x020900) ? 1 : 2;
865 883
866 if (synaptics_send_cmd(psmouse, ETP_FW_ID_QUERY, param)) 884 if (etd->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
867 return -1; 885 return -1;
868 886
869 fixed_dpi = param[1] & 0x10; 887 fixed_dpi = param[1] & 0x10;
870 888
871 if (((etd->fw_version >> 16) == 0x14) && fixed_dpi) { 889 if (((etd->fw_version >> 16) == 0x14) && fixed_dpi) {
872 if (synaptics_send_cmd(psmouse, ETP_SAMPLE_QUERY, param)) 890 if (etd->send_cmd(psmouse, ETP_SAMPLE_QUERY, param))
873 return -1; 891 return -1;
874 892
875 *x_max = (etd->capabilities[1] - i) * param[1] / 2; 893 *x_max = (etd->capabilities[1] - i) * param[1] / 2;
@@ -888,7 +906,7 @@ static int elantech_set_range(struct psmouse *psmouse,
888 break; 906 break;
889 907
890 case 3: 908 case 3:
891 if (synaptics_send_cmd(psmouse, ETP_FW_ID_QUERY, param)) 909 if (etd->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
892 return -1; 910 return -1;
893 911
894 *x_max = (0x0f & param[0]) << 8 | param[1]; 912 *x_max = (0x0f & param[0]) << 8 | param[1];
@@ -896,7 +914,7 @@ static int elantech_set_range(struct psmouse *psmouse,
896 break; 914 break;
897 915
898 case 4: 916 case 4:
899 if (synaptics_send_cmd(psmouse, ETP_FW_ID_QUERY, param)) 917 if (etd->send_cmd(psmouse, ETP_FW_ID_QUERY, param))
900 return -1; 918 return -1;
901 919
902 *x_max = (0x0f & param[0]) << 8 | param[1]; 920 *x_max = (0x0f & param[0]) << 8 | param[1];
@@ -913,6 +931,30 @@ static int elantech_set_range(struct psmouse *psmouse,
913} 931}
914 932
915/* 933/*
934 * (value from firmware) * 10 + 790 = dpi
935 * we also have to convert dpi to dots/mm (*10/254 to avoid floating point)
936 */
937static unsigned int elantech_convert_res(unsigned int val)
938{
939 return (val * 10 + 790) * 10 / 254;
940}
941
942static int elantech_get_resolution_v4(struct psmouse *psmouse,
943 unsigned int *x_res,
944 unsigned int *y_res)
945{
946 unsigned char param[3];
947
948 if (elantech_send_cmd(psmouse, ETP_RESOLUTION_QUERY, param))
949 return -1;
950
951 *x_res = elantech_convert_res(param[1] & 0x0f);
952 *y_res = elantech_convert_res((param[1] & 0xf0) >> 4);
953
954 return 0;
955}
956
957/*
916 * Set the appropriate event bits for the input subsystem 958 * Set the appropriate event bits for the input subsystem
917 */ 959 */
918static int elantech_set_input_params(struct psmouse *psmouse) 960static int elantech_set_input_params(struct psmouse *psmouse)
@@ -920,6 +962,7 @@ static int elantech_set_input_params(struct psmouse *psmouse)
920 struct input_dev *dev = psmouse->dev; 962 struct input_dev *dev = psmouse->dev;
921 struct elantech_data *etd = psmouse->private; 963 struct elantech_data *etd = psmouse->private;
922 unsigned int x_min = 0, y_min = 0, x_max = 0, y_max = 0, width = 0; 964 unsigned int x_min = 0, y_min = 0, x_max = 0, y_max = 0, width = 0;
965 unsigned int x_res = 0, y_res = 0;
923 966
924 if (elantech_set_range(psmouse, &x_min, &y_min, &x_max, &y_max, &width)) 967 if (elantech_set_range(psmouse, &x_min, &y_min, &x_max, &y_max, &width))
925 return -1; 968 return -1;
@@ -967,10 +1010,20 @@ static int elantech_set_input_params(struct psmouse *psmouse)
967 break; 1010 break;
968 1011
969 case 4: 1012 case 4:
1013 if (elantech_get_resolution_v4(psmouse, &x_res, &y_res)) {
1014 /*
1015 * if query failed, print a warning and leave the values
1016 * zero to resemble synaptics.c behavior.
1017 */
1018 psmouse_warn(psmouse, "couldn't query resolution data.\n");
1019 }
1020
970 __set_bit(BTN_TOOL_QUADTAP, dev->keybit); 1021 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
971 /* For X to recognize me as touchpad. */ 1022 /* For X to recognize me as touchpad. */
972 input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0); 1023 input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
973 input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0); 1024 input_set_abs_params(dev, ABS_Y, y_min, y_max, 0, 0);
1025 input_abs_set_res(dev, ABS_X, x_res);
1026 input_abs_set_res(dev, ABS_Y, y_res);
974 /* 1027 /*
975 * range of pressure and width is the same as v2, 1028 * range of pressure and width is the same as v2,
976 * report ABS_PRESSURE, ABS_TOOL_WIDTH for compatibility. 1029 * report ABS_PRESSURE, ABS_TOOL_WIDTH for compatibility.
@@ -983,6 +1036,8 @@ static int elantech_set_input_params(struct psmouse *psmouse)
983 input_mt_init_slots(dev, ETP_MAX_FINGERS); 1036 input_mt_init_slots(dev, ETP_MAX_FINGERS);
984 input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0); 1037 input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
985 input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0); 1038 input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
1039 input_abs_set_res(dev, ABS_MT_POSITION_X, x_res);
1040 input_abs_set_res(dev, ABS_MT_POSITION_Y, y_res);
986 input_set_abs_params(dev, ABS_MT_PRESSURE, ETP_PMIN_V2, 1041 input_set_abs_params(dev, ABS_MT_PRESSURE, ETP_PMIN_V2,
987 ETP_PMAX_V2, 0, 0); 1042 ETP_PMAX_V2, 0, 0);
988 /* 1043 /*
@@ -1031,16 +1086,13 @@ static ssize_t elantech_set_int_attr(struct psmouse *psmouse,
1031 struct elantech_data *etd = psmouse->private; 1086 struct elantech_data *etd = psmouse->private;
1032 struct elantech_attr_data *attr = data; 1087 struct elantech_attr_data *attr = data;
1033 unsigned char *reg = (unsigned char *) etd + attr->field_offset; 1088 unsigned char *reg = (unsigned char *) etd + attr->field_offset;
1034 unsigned long value; 1089 unsigned char value;
1035 int err; 1090 int err;
1036 1091
1037 err = strict_strtoul(buf, 16, &value); 1092 err = kstrtou8(buf, 16, &value);
1038 if (err) 1093 if (err)
1039 return err; 1094 return err;
1040 1095
1041 if (value > 0xff)
1042 return -EINVAL;
1043
1044 /* Do we need to preserve some bits for version 2 hardware too? */ 1096 /* Do we need to preserve some bits for version 2 hardware too? */
1045 if (etd->hw_version == 1) { 1097 if (etd->hw_version == 1) {
1046 if (attr->reg == 0x10) 1098 if (attr->reg == 0x10)
@@ -1233,9 +1285,11 @@ static int elantech_set_properties(struct elantech_data *etd)
1233 } 1285 }
1234 } 1286 }
1235 1287
1236 /* 1288 /* decide which send_cmd we're gonna use early */
1237 * Turn on packet checking by default. 1289 etd->send_cmd = etd->hw_version >= 3 ? elantech_send_cmd :
1238 */ 1290 synaptics_send_cmd;
1291
1292 /* Turn on packet checking by default */
1239 etd->paritycheck = 1; 1293 etd->paritycheck = 1;
1240 1294
1241 /* 1295 /*
@@ -1291,7 +1345,7 @@ int elantech_init(struct psmouse *psmouse)
1291 "assuming hardware version %d (with firmware version 0x%02x%02x%02x)\n", 1345 "assuming hardware version %d (with firmware version 0x%02x%02x%02x)\n",
1292 etd->hw_version, param[0], param[1], param[2]); 1346 etd->hw_version, param[0], param[1], param[2]);
1293 1347
1294 if (synaptics_send_cmd(psmouse, ETP_CAPABILITIES_QUERY, 1348 if (etd->send_cmd(psmouse, ETP_CAPABILITIES_QUERY,
1295 etd->capabilities)) { 1349 etd->capabilities)) {
1296 psmouse_err(psmouse, "failed to query capabilities.\n"); 1350 psmouse_err(psmouse, "failed to query capabilities.\n");
1297 goto init_fail; 1351 goto init_fail;
diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h
index 9e5f1aabea7e..46db3be45ac9 100644
--- a/drivers/input/mouse/elantech.h
+++ b/drivers/input/mouse/elantech.h
@@ -20,6 +20,7 @@
20#define ETP_FW_VERSION_QUERY 0x01 20#define ETP_FW_VERSION_QUERY 0x01
21#define ETP_CAPABILITIES_QUERY 0x02 21#define ETP_CAPABILITIES_QUERY 0x02
22#define ETP_SAMPLE_QUERY 0x03 22#define ETP_SAMPLE_QUERY 0x03
23#define ETP_RESOLUTION_QUERY 0x04
23 24
24/* 25/*
25 * Command values for register reading or writing 26 * Command values for register reading or writing
@@ -135,6 +136,7 @@ struct elantech_data {
135 unsigned int width; 136 unsigned int width;
136 struct finger_pos mt[ETP_MAX_FINGERS]; 137 struct finger_pos mt[ETP_MAX_FINGERS];
137 unsigned char parity[256]; 138 unsigned char parity[256];
139 int (*send_cmd)(struct psmouse *psmouse, unsigned char c, unsigned char *param);
138}; 140};
139 141
140#ifdef CONFIG_MOUSE_PS2_ELANTECH 142#ifdef CONFIG_MOUSE_PS2_ELANTECH
diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c
index 0470dd46b566..1c5d521de600 100644
--- a/drivers/input/mouse/hgpk.c
+++ b/drivers/input/mouse/hgpk.c
@@ -789,11 +789,14 @@ static ssize_t hgpk_set_powered(struct psmouse *psmouse, void *data,
789 const char *buf, size_t count) 789 const char *buf, size_t count)
790{ 790{
791 struct hgpk_data *priv = psmouse->private; 791 struct hgpk_data *priv = psmouse->private;
792 unsigned long value; 792 unsigned int value;
793 int err; 793 int err;
794 794
795 err = strict_strtoul(buf, 10, &value); 795 err = kstrtouint(buf, 10, &value);
796 if (err || value > 1) 796 if (err)
797 return err;
798
799 if (value > 1)
797 return -EINVAL; 800 return -EINVAL;
798 801
799 if (value != priv->powered) { 802 if (value != priv->powered) {
@@ -881,11 +884,14 @@ static ssize_t hgpk_trigger_recal(struct psmouse *psmouse, void *data,
881 const char *buf, size_t count) 884 const char *buf, size_t count)
882{ 885{
883 struct hgpk_data *priv = psmouse->private; 886 struct hgpk_data *priv = psmouse->private;
884 unsigned long value; 887 unsigned int value;
885 int err; 888 int err;
886 889
887 err = strict_strtoul(buf, 10, &value); 890 err = kstrtouint(buf, 10, &value);
888 if (err || value != 1) 891 if (err)
892 return err;
893
894 if (value != 1)
889 return -EINVAL; 895 return -EINVAL;
890 896
891 /* 897 /*
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index faac2c3bef74..84de2fc6acc1 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -155,9 +155,14 @@ static ssize_t ps2pp_attr_show_smartscroll(struct psmouse *psmouse,
155static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, 155static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data,
156 const char *buf, size_t count) 156 const char *buf, size_t count)
157{ 157{
158 unsigned long value; 158 unsigned int value;
159 int err;
159 160
160 if (strict_strtoul(buf, 10, &value) || value > 1) 161 err = kstrtouint(buf, 10, &value);
162 if (err)
163 return err;
164
165 if (value > 1)
161 return -EINVAL; 166 return -EINVAL;
162 167
163 ps2pp_set_smartscroll(psmouse, value); 168 ps2pp_set_smartscroll(psmouse, value);
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 9f352fbd7b4f..200be9c9dbc7 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -127,7 +127,7 @@ struct psmouse_protocol {
127 * relevant events to the input module once full packet has arrived. 127 * relevant events to the input module once full packet has arrived.
128 */ 128 */
129 129
130static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) 130psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
131{ 131{
132 struct input_dev *dev = psmouse->dev; 132 struct input_dev *dev = psmouse->dev;
133 unsigned char *packet = psmouse->packet; 133 unsigned char *packet = psmouse->packet;
@@ -819,6 +819,13 @@ static const struct psmouse_protocol psmouse_protocols[] = {
819 .detect = synaptics_detect, 819 .detect = synaptics_detect,
820 .init = synaptics_init, 820 .init = synaptics_init,
821 }, 821 },
822 {
823 .type = PSMOUSE_SYNAPTICS_RELATIVE,
824 .name = "SynRelPS/2",
825 .alias = "synaptics-relative",
826 .detect = synaptics_detect,
827 .init = synaptics_init_relative,
828 },
822#endif 829#endif
823#ifdef CONFIG_MOUSE_PS2_ALPS 830#ifdef CONFIG_MOUSE_PS2_ALPS
824 { 831 {
@@ -1558,13 +1565,12 @@ static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char
1558static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count) 1565static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
1559{ 1566{
1560 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset); 1567 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
1561 unsigned long value; 1568 unsigned int value;
1562 1569 int err;
1563 if (strict_strtoul(buf, 10, &value))
1564 return -EINVAL;
1565 1570
1566 if ((unsigned int)value != value) 1571 err = kstrtouint(buf, 10, &value);
1567 return -EINVAL; 1572 if (err)
1573 return err;
1568 1574
1569 *field = value; 1575 *field = value;
1570 1576
@@ -1671,10 +1677,12 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1671 1677
1672static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count) 1678static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1673{ 1679{
1674 unsigned long value; 1680 unsigned int value;
1681 int err;
1675 1682
1676 if (strict_strtoul(buf, 10, &value)) 1683 err = kstrtouint(buf, 10, &value);
1677 return -EINVAL; 1684 if (err)
1685 return err;
1678 1686
1679 psmouse->set_rate(psmouse, value); 1687 psmouse->set_rate(psmouse, value);
1680 return count; 1688 return count;
@@ -1682,10 +1690,12 @@ static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const
1682 1690
1683static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count) 1691static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1684{ 1692{
1685 unsigned long value; 1693 unsigned int value;
1694 int err;
1686 1695
1687 if (strict_strtoul(buf, 10, &value)) 1696 err = kstrtouint(buf, 10, &value);
1688 return -EINVAL; 1697 if (err)
1698 return err;
1689 1699
1690 psmouse->set_resolution(psmouse, value); 1700 psmouse->set_resolution(psmouse, value);
1691 return count; 1701 return count;
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 9b84b0c4e371..6a417092d010 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -8,6 +8,7 @@
8#define PSMOUSE_CMD_SETSTREAM 0x00ea 8#define PSMOUSE_CMD_SETSTREAM 0x00ea
9#define PSMOUSE_CMD_SETPOLL 0x00f0 9#define PSMOUSE_CMD_SETPOLL 0x00f0
10#define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */ 10#define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */
11#define PSMOUSE_CMD_RESET_WRAP 0x00ec
11#define PSMOUSE_CMD_GETID 0x02f2 12#define PSMOUSE_CMD_GETID 0x02f2
12#define PSMOUSE_CMD_SETRATE 0x10f3 13#define PSMOUSE_CMD_SETRATE 0x10f3
13#define PSMOUSE_CMD_ENABLE 0x00f4 14#define PSMOUSE_CMD_ENABLE 0x00f4
@@ -93,6 +94,7 @@ enum psmouse_type {
93 PSMOUSE_HGPK, 94 PSMOUSE_HGPK,
94 PSMOUSE_ELANTECH, 95 PSMOUSE_ELANTECH,
95 PSMOUSE_FSP, 96 PSMOUSE_FSP,
97 PSMOUSE_SYNAPTICS_RELATIVE,
96 PSMOUSE_AUTO /* This one should always be last */ 98 PSMOUSE_AUTO /* This one should always be last */
97}; 99};
98 100
@@ -102,6 +104,7 @@ int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
102int psmouse_reset(struct psmouse *psmouse); 104int psmouse_reset(struct psmouse *psmouse);
103void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state); 105void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
104void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution); 106void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
107psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse);
105 108
106struct psmouse_attribute { 109struct psmouse_attribute {
107 struct device_attribute dattr; 110 struct device_attribute dattr;
diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
index c5b12d2e955a..5babc47b39aa 100644
--- a/drivers/input/mouse/sentelic.c
+++ b/drivers/input/mouse/sentelic.c
@@ -408,7 +408,7 @@ static int fsp_onpad_hscr(struct psmouse *psmouse, bool enable)
408static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data, 408static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
409 const char *buf, size_t count) 409 const char *buf, size_t count)
410{ 410{
411 unsigned long reg, val; 411 int reg, val;
412 char *rest; 412 char *rest;
413 ssize_t retval; 413 ssize_t retval;
414 414
@@ -416,7 +416,11 @@ static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
416 if (rest == buf || *rest != ' ' || reg > 0xff) 416 if (rest == buf || *rest != ' ' || reg > 0xff)
417 return -EINVAL; 417 return -EINVAL;
418 418
419 if (strict_strtoul(rest + 1, 16, &val) || val > 0xff) 419 retval = kstrtoint(rest + 1, 16, &val);
420 if (retval)
421 return retval;
422
423 if (val > 0xff)
420 return -EINVAL; 424 return -EINVAL;
421 425
422 if (fsp_reg_write_enable(psmouse, true)) 426 if (fsp_reg_write_enable(psmouse, true))
@@ -448,10 +452,13 @@ static ssize_t fsp_attr_set_getreg(struct psmouse *psmouse, void *data,
448 const char *buf, size_t count) 452 const char *buf, size_t count)
449{ 453{
450 struct fsp_data *pad = psmouse->private; 454 struct fsp_data *pad = psmouse->private;
451 unsigned long reg; 455 int reg, val, err;
452 int val; 456
457 err = kstrtoint(buf, 16, &reg);
458 if (err)
459 return err;
453 460
454 if (strict_strtoul(buf, 16, &reg) || reg > 0xff) 461 if (reg > 0xff)
455 return -EINVAL; 462 return -EINVAL;
456 463
457 if (fsp_reg_read(psmouse, reg, &val)) 464 if (fsp_reg_read(psmouse, reg, &val))
@@ -480,9 +487,13 @@ static ssize_t fsp_attr_show_pagereg(struct psmouse *psmouse,
480static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data, 487static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data,
481 const char *buf, size_t count) 488 const char *buf, size_t count)
482{ 489{
483 unsigned long val; 490 int val, err;
484 491
485 if (strict_strtoul(buf, 16, &val) || val > 0xff) 492 err = kstrtoint(buf, 16, &val);
493 if (err)
494 return err;
495
496 if (val > 0xff)
486 return -EINVAL; 497 return -EINVAL;
487 498
488 if (fsp_page_reg_write(psmouse, val)) 499 if (fsp_page_reg_write(psmouse, val))
@@ -505,9 +516,14 @@ static ssize_t fsp_attr_show_vscroll(struct psmouse *psmouse,
505static ssize_t fsp_attr_set_vscroll(struct psmouse *psmouse, void *data, 516static ssize_t fsp_attr_set_vscroll(struct psmouse *psmouse, void *data,
506 const char *buf, size_t count) 517 const char *buf, size_t count)
507{ 518{
508 unsigned long val; 519 unsigned int val;
520 int err;
521
522 err = kstrtouint(buf, 10, &val);
523 if (err)
524 return err;
509 525
510 if (strict_strtoul(buf, 10, &val) || val > 1) 526 if (val > 1)
511 return -EINVAL; 527 return -EINVAL;
512 528
513 fsp_onpad_vscr(psmouse, val); 529 fsp_onpad_vscr(psmouse, val);
@@ -529,9 +545,14 @@ static ssize_t fsp_attr_show_hscroll(struct psmouse *psmouse,
529static ssize_t fsp_attr_set_hscroll(struct psmouse *psmouse, void *data, 545static ssize_t fsp_attr_set_hscroll(struct psmouse *psmouse, void *data,
530 const char *buf, size_t count) 546 const char *buf, size_t count)
531{ 547{
532 unsigned long val; 548 unsigned int val;
549 int err;
550
551 err = kstrtouint(buf, 10, &val);
552 if (err)
553 return err;
533 554
534 if (strict_strtoul(buf, 10, &val) || val > 1) 555 if (val > 1)
535 return -EINVAL; 556 return -EINVAL;
536 557
537 fsp_onpad_hscr(psmouse, val); 558 fsp_onpad_hscr(psmouse, val);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index c080b828e5dc..06c9ee57951e 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -268,19 +268,49 @@ static int synaptics_query_hardware(struct psmouse *psmouse)
268 return 0; 268 return 0;
269} 269}
270 270
271static int synaptics_set_absolute_mode(struct psmouse *psmouse) 271static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
272{
273 static unsigned char param = 0xc8;
274 struct synaptics_data *priv = psmouse->private;
275
276 if (!SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
277 return 0;
278
279 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
280 return -1;
281
282 if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
283 return -1;
284
285 /* Advanced gesture mode also sends multi finger data */
286 priv->capabilities |= BIT(1);
287
288 return 0;
289}
290
291static int synaptics_set_mode(struct psmouse *psmouse)
272{ 292{
273 struct synaptics_data *priv = psmouse->private; 293 struct synaptics_data *priv = psmouse->private;
274 294
275 priv->mode = SYN_BIT_ABSOLUTE_MODE; 295 priv->mode = 0;
276 if (SYN_ID_MAJOR(priv->identity) >= 4) 296 if (priv->absolute_mode)
297 priv->mode |= SYN_BIT_ABSOLUTE_MODE;
298 if (priv->disable_gesture)
277 priv->mode |= SYN_BIT_DISABLE_GESTURE; 299 priv->mode |= SYN_BIT_DISABLE_GESTURE;
300 if (psmouse->rate >= 80)
301 priv->mode |= SYN_BIT_HIGH_RATE;
278 if (SYN_CAP_EXTENDED(priv->capabilities)) 302 if (SYN_CAP_EXTENDED(priv->capabilities))
279 priv->mode |= SYN_BIT_W_MODE; 303 priv->mode |= SYN_BIT_W_MODE;
280 304
281 if (synaptics_mode_cmd(psmouse, priv->mode)) 305 if (synaptics_mode_cmd(psmouse, priv->mode))
282 return -1; 306 return -1;
283 307
308 if (priv->absolute_mode &&
309 synaptics_set_advanced_gesture_mode(psmouse)) {
310 psmouse_err(psmouse, "Advanced gesture mode init failed.\n");
311 return -1;
312 }
313
284 return 0; 314 return 0;
285} 315}
286 316
@@ -299,26 +329,6 @@ static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
299 synaptics_mode_cmd(psmouse, priv->mode); 329 synaptics_mode_cmd(psmouse, priv->mode);
300} 330}
301 331
302static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
303{
304 static unsigned char param = 0xc8;
305 struct synaptics_data *priv = psmouse->private;
306
307 if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
308 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
309 return 0;
310
311 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
312 return -1;
313 if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
314 return -1;
315
316 /* Advanced gesture mode also sends multi finger data */
317 priv->capabilities |= BIT(1);
318
319 return 0;
320}
321
322/***************************************************************************** 332/*****************************************************************************
323 * Synaptics pass-through PS/2 port support 333 * Synaptics pass-through PS/2 port support
324 ****************************************************************************/ 334 ****************************************************************************/
@@ -1142,8 +1152,24 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
1142{ 1152{
1143 int i; 1153 int i;
1144 1154
1155 /* Things that apply to both modes */
1145 __set_bit(INPUT_PROP_POINTER, dev->propbit); 1156 __set_bit(INPUT_PROP_POINTER, dev->propbit);
1157 __set_bit(EV_KEY, dev->evbit);
1158 __set_bit(BTN_LEFT, dev->keybit);
1159 __set_bit(BTN_RIGHT, dev->keybit);
1146 1160
1161 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
1162 __set_bit(BTN_MIDDLE, dev->keybit);
1163
1164 if (!priv->absolute_mode) {
1165 /* Relative mode */
1166 __set_bit(EV_REL, dev->evbit);
1167 __set_bit(REL_X, dev->relbit);
1168 __set_bit(REL_Y, dev->relbit);
1169 return;
1170 }
1171
1172 /* Absolute mode */
1147 __set_bit(EV_ABS, dev->evbit); 1173 __set_bit(EV_ABS, dev->evbit);
1148 set_abs_position_params(dev, priv, ABS_X, ABS_Y); 1174 set_abs_position_params(dev, priv, ABS_X, ABS_Y);
1149 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); 1175 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
@@ -1169,20 +1195,14 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
1169 if (SYN_CAP_PALMDETECT(priv->capabilities)) 1195 if (SYN_CAP_PALMDETECT(priv->capabilities))
1170 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); 1196 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
1171 1197
1172 __set_bit(EV_KEY, dev->evbit);
1173 __set_bit(BTN_TOUCH, dev->keybit); 1198 __set_bit(BTN_TOUCH, dev->keybit);
1174 __set_bit(BTN_TOOL_FINGER, dev->keybit); 1199 __set_bit(BTN_TOOL_FINGER, dev->keybit);
1175 __set_bit(BTN_LEFT, dev->keybit);
1176 __set_bit(BTN_RIGHT, dev->keybit);
1177 1200
1178 if (SYN_CAP_MULTIFINGER(priv->capabilities)) { 1201 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
1179 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); 1202 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
1180 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); 1203 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
1181 } 1204 }
1182 1205
1183 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
1184 __set_bit(BTN_MIDDLE, dev->keybit);
1185
1186 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) || 1206 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
1187 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { 1207 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
1188 __set_bit(BTN_FORWARD, dev->keybit); 1208 __set_bit(BTN_FORWARD, dev->keybit);
@@ -1204,10 +1224,58 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
1204 } 1224 }
1205} 1225}
1206 1226
1227static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
1228 void *data, char *buf)
1229{
1230 struct synaptics_data *priv = psmouse->private;
1231
1232 return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
1233}
1234
1235static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
1236 void *data, const char *buf,
1237 size_t len)
1238{
1239 struct synaptics_data *priv = psmouse->private;
1240 unsigned int value;
1241 int err;
1242
1243 err = kstrtouint(buf, 10, &value);
1244 if (err)
1245 return err;
1246
1247 if (value > 1)
1248 return -EINVAL;
1249
1250 if (value == priv->disable_gesture)
1251 return len;
1252
1253 priv->disable_gesture = value;
1254 if (value)
1255 priv->mode |= SYN_BIT_DISABLE_GESTURE;
1256 else
1257 priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
1258
1259 if (synaptics_mode_cmd(psmouse, priv->mode))
1260 return -EIO;
1261
1262 return len;
1263}
1264
1265PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
1266 synaptics_show_disable_gesture,
1267 synaptics_set_disable_gesture);
1268
1207static void synaptics_disconnect(struct psmouse *psmouse) 1269static void synaptics_disconnect(struct psmouse *psmouse)
1208{ 1270{
1271 struct synaptics_data *priv = psmouse->private;
1272
1273 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity))
1274 device_remove_file(&psmouse->ps2dev.serio->dev,
1275 &psmouse_attr_disable_gesture.dattr);
1276
1209 synaptics_reset(psmouse); 1277 synaptics_reset(psmouse);
1210 kfree(psmouse->private); 1278 kfree(priv);
1211 psmouse->private = NULL; 1279 psmouse->private = NULL;
1212} 1280}
1213 1281
@@ -1234,17 +1302,11 @@ static int synaptics_reconnect(struct psmouse *psmouse)
1234 return -1; 1302 return -1;
1235 } 1303 }
1236 1304
1237 if (synaptics_set_absolute_mode(psmouse)) { 1305 if (synaptics_set_mode(psmouse)) {
1238 psmouse_err(psmouse, "Unable to initialize device.\n"); 1306 psmouse_err(psmouse, "Unable to initialize device.\n");
1239 return -1; 1307 return -1;
1240 } 1308 }
1241 1309
1242 if (synaptics_set_advanced_gesture_mode(psmouse)) {
1243 psmouse_err(psmouse,
1244 "Advanced gesture mode reconnect failed.\n");
1245 return -1;
1246 }
1247
1248 if (old_priv.identity != priv->identity || 1310 if (old_priv.identity != priv->identity ||
1249 old_priv.model_id != priv->model_id || 1311 old_priv.model_id != priv->model_id ||
1250 old_priv.capabilities != priv->capabilities || 1312 old_priv.capabilities != priv->capabilities ||
@@ -1321,20 +1383,18 @@ void __init synaptics_module_init(void)
1321 broken_olpc_ec = dmi_check_system(olpc_dmi_table); 1383 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
1322} 1384}
1323 1385
1324int synaptics_init(struct psmouse *psmouse) 1386static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
1325{ 1387{
1326 struct synaptics_data *priv; 1388 struct synaptics_data *priv;
1389 int err = -1;
1327 1390
1328 /* 1391 /*
1329 * The OLPC XO has issues with Synaptics' absolute mode; similarly to 1392 * The OLPC XO has issues with Synaptics' absolute mode; the constant
1330 * the HGPK, it quickly degrades and the hardware becomes jumpy and 1393 * packet spew overloads the EC such that key presses on the keyboard
1331 * overly sensitive. Not only that, but the constant packet spew 1394 * are missed. Given that, don't even attempt to use Absolute mode.
1332 * (even at a lowered 40pps rate) overloads the EC such that key 1395 * Relative mode seems to work just fine.
1333 * presses on the keyboard are missed. Given all of that, don't
1334 * even attempt to use Synaptics mode. Relative mode seems to work
1335 * just fine.
1336 */ 1396 */
1337 if (broken_olpc_ec) { 1397 if (absolute_mode && broken_olpc_ec) {
1338 psmouse_info(psmouse, 1398 psmouse_info(psmouse,
1339 "OLPC XO detected, not enabling Synaptics protocol.\n"); 1399 "OLPC XO detected, not enabling Synaptics protocol.\n");
1340 return -ENODEV; 1400 return -ENODEV;
@@ -1351,13 +1411,12 @@ int synaptics_init(struct psmouse *psmouse)
1351 goto init_fail; 1411 goto init_fail;
1352 } 1412 }
1353 1413
1354 if (synaptics_set_absolute_mode(psmouse)) { 1414 priv->absolute_mode = absolute_mode;
1355 psmouse_err(psmouse, "Unable to initialize device.\n"); 1415 if (SYN_ID_DISGEST_SUPPORTED(priv->identity))
1356 goto init_fail; 1416 priv->disable_gesture = true;
1357 }
1358 1417
1359 if (synaptics_set_advanced_gesture_mode(psmouse)) { 1418 if (synaptics_set_mode(psmouse)) {
1360 psmouse_err(psmouse, "Advanced gesture mode init failed.\n"); 1419 psmouse_err(psmouse, "Unable to initialize device.\n");
1361 goto init_fail; 1420 goto init_fail;
1362 } 1421 }
1363 1422
@@ -1382,12 +1441,19 @@ int synaptics_init(struct psmouse *psmouse)
1382 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) | 1441 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
1383 (priv->model_id & 0x000000ff); 1442 (priv->model_id & 0x000000ff);
1384 1443
1385 psmouse->protocol_handler = synaptics_process_byte; 1444 if (absolute_mode) {
1445 psmouse->protocol_handler = synaptics_process_byte;
1446 psmouse->pktsize = 6;
1447 } else {
1448 /* Relative mode follows standard PS/2 mouse protocol */
1449 psmouse->protocol_handler = psmouse_process_byte;
1450 psmouse->pktsize = 3;
1451 }
1452
1386 psmouse->set_rate = synaptics_set_rate; 1453 psmouse->set_rate = synaptics_set_rate;
1387 psmouse->disconnect = synaptics_disconnect; 1454 psmouse->disconnect = synaptics_disconnect;
1388 psmouse->reconnect = synaptics_reconnect; 1455 psmouse->reconnect = synaptics_reconnect;
1389 psmouse->cleanup = synaptics_reset; 1456 psmouse->cleanup = synaptics_reset;
1390 psmouse->pktsize = 6;
1391 /* Synaptics can usually stay in sync without extra help */ 1457 /* Synaptics can usually stay in sync without extra help */
1392 psmouse->resync_time = 0; 1458 psmouse->resync_time = 0;
1393 1459
@@ -1406,11 +1472,32 @@ int synaptics_init(struct psmouse *psmouse)
1406 psmouse->rate = 40; 1472 psmouse->rate = 40;
1407 } 1473 }
1408 1474
1475 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) {
1476 err = device_create_file(&psmouse->ps2dev.serio->dev,
1477 &psmouse_attr_disable_gesture.dattr);
1478 if (err) {
1479 psmouse_err(psmouse,
1480 "Failed to create disable_gesture attribute (%d)",
1481 err);
1482 goto init_fail;
1483 }
1484 }
1485
1409 return 0; 1486 return 0;
1410 1487
1411 init_fail: 1488 init_fail:
1412 kfree(priv); 1489 kfree(priv);
1413 return -1; 1490 return err;
1491}
1492
1493int synaptics_init(struct psmouse *psmouse)
1494{
1495 return __synaptics_init(psmouse, true);
1496}
1497
1498int synaptics_init_relative(struct psmouse *psmouse)
1499{
1500 return __synaptics_init(psmouse, false);
1414} 1501}
1415 1502
1416bool synaptics_supported(void) 1503bool synaptics_supported(void)
diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
index 622aea8dd7e0..fd26ccca13d7 100644
--- a/drivers/input/mouse/synaptics.h
+++ b/drivers/input/mouse/synaptics.h
@@ -100,6 +100,7 @@
100#define SYN_ID_MINOR(i) (((i) >> 16) & 0xff) 100#define SYN_ID_MINOR(i) (((i) >> 16) & 0xff)
101#define SYN_ID_FULL(i) ((SYN_ID_MAJOR(i) << 8) | SYN_ID_MINOR(i)) 101#define SYN_ID_FULL(i) ((SYN_ID_MAJOR(i) << 8) | SYN_ID_MINOR(i))
102#define SYN_ID_IS_SYNAPTICS(i) ((((i) >> 8) & 0xff) == 0x47) 102#define SYN_ID_IS_SYNAPTICS(i) ((((i) >> 8) & 0xff) == 0x47)
103#define SYN_ID_DISGEST_SUPPORTED(i) (SYN_ID_MAJOR(i) >= 4)
103 104
104/* synaptics special commands */ 105/* synaptics special commands */
105#define SYN_PS_SET_MODE2 0x14 106#define SYN_PS_SET_MODE2 0x14
@@ -159,6 +160,9 @@ struct synaptics_data {
159 unsigned char mode; /* current mode byte */ 160 unsigned char mode; /* current mode byte */
160 int scroll; 161 int scroll;
161 162
163 bool absolute_mode; /* run in Absolute mode */
164 bool disable_gesture; /* disable gestures */
165
162 struct serio *pt_port; /* Pass-through serio port */ 166 struct serio *pt_port; /* Pass-through serio port */
163 167
164 struct synaptics_mt_state mt_state; /* Current mt finger state */ 168 struct synaptics_mt_state mt_state; /* Current mt finger state */
@@ -175,6 +179,7 @@ struct synaptics_data {
175void synaptics_module_init(void); 179void synaptics_module_init(void);
176int synaptics_detect(struct psmouse *psmouse, bool set_properties); 180int synaptics_detect(struct psmouse *psmouse, bool set_properties);
177int synaptics_init(struct psmouse *psmouse); 181int synaptics_init(struct psmouse *psmouse);
182int synaptics_init_relative(struct psmouse *psmouse);
178void synaptics_reset(struct psmouse *psmouse); 183void synaptics_reset(struct psmouse *psmouse);
179bool synaptics_supported(void); 184bool synaptics_supported(void);
180 185
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 54b2fa892e19..22b218018137 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -89,10 +89,12 @@ static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
89 struct trackpoint_data *tp = psmouse->private; 89 struct trackpoint_data *tp = psmouse->private;
90 struct trackpoint_attr_data *attr = data; 90 struct trackpoint_attr_data *attr = data;
91 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 91 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
92 unsigned long value; 92 unsigned char value;
93 int err;
93 94
94 if (strict_strtoul(buf, 10, &value) || value > 255) 95 err = kstrtou8(buf, 10, &value);
95 return -EINVAL; 96 if (err)
97 return err;
96 98
97 *field = value; 99 *field = value;
98 trackpoint_write(&psmouse->ps2dev, attr->command, value); 100 trackpoint_write(&psmouse->ps2dev, attr->command, value);
@@ -115,9 +117,14 @@ static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
115 struct trackpoint_data *tp = psmouse->private; 117 struct trackpoint_data *tp = psmouse->private;
116 struct trackpoint_attr_data *attr = data; 118 struct trackpoint_attr_data *attr = data;
117 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 119 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
118 unsigned long value; 120 unsigned int value;
121 int err;
122
123 err = kstrtouint(buf, 10, &value);
124 if (err)
125 return err;
119 126
120 if (strict_strtoul(buf, 10, &value) || value > 1) 127 if (value > 1)
121 return -EINVAL; 128 return -EINVAL;
122 129
123 if (attr->inverted) 130 if (attr->inverted)
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index d37a48e099d0..86564414b75a 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -991,7 +991,7 @@ static int i8042_controller_init(void)
991 * Reset the controller and reset CRT to the original value set by BIOS. 991 * Reset the controller and reset CRT to the original value set by BIOS.
992 */ 992 */
993 993
994static void i8042_controller_reset(void) 994static void i8042_controller_reset(bool force_reset)
995{ 995{
996 i8042_flush(); 996 i8042_flush();
997 997
@@ -1016,7 +1016,7 @@ static void i8042_controller_reset(void)
1016 * Reset the controller if requested. 1016 * Reset the controller if requested.
1017 */ 1017 */
1018 1018
1019 if (i8042_reset) 1019 if (i8042_reset || force_reset)
1020 i8042_controller_selftest(); 1020 i8042_controller_selftest();
1021 1021
1022/* 1022/*
@@ -1139,9 +1139,9 @@ static int i8042_controller_resume(bool force_reset)
1139 * upsetting it. 1139 * upsetting it.
1140 */ 1140 */
1141 1141
1142static int i8042_pm_reset(struct device *dev) 1142static int i8042_pm_suspend(struct device *dev)
1143{ 1143{
1144 i8042_controller_reset(); 1144 i8042_controller_reset(true);
1145 1145
1146 return 0; 1146 return 0;
1147} 1147}
@@ -1163,13 +1163,20 @@ static int i8042_pm_thaw(struct device *dev)
1163 return 0; 1163 return 0;
1164} 1164}
1165 1165
1166static int i8042_pm_reset(struct device *dev)
1167{
1168 i8042_controller_reset(false);
1169
1170 return 0;
1171}
1172
1166static int i8042_pm_restore(struct device *dev) 1173static int i8042_pm_restore(struct device *dev)
1167{ 1174{
1168 return i8042_controller_resume(false); 1175 return i8042_controller_resume(false);
1169} 1176}
1170 1177
1171static const struct dev_pm_ops i8042_pm_ops = { 1178static const struct dev_pm_ops i8042_pm_ops = {
1172 .suspend = i8042_pm_reset, 1179 .suspend = i8042_pm_suspend,
1173 .resume = i8042_pm_resume, 1180 .resume = i8042_pm_resume,
1174 .thaw = i8042_pm_thaw, 1181 .thaw = i8042_pm_thaw,
1175 .poweroff = i8042_pm_reset, 1182 .poweroff = i8042_pm_reset,
@@ -1185,7 +1192,7 @@ static const struct dev_pm_ops i8042_pm_ops = {
1185 1192
1186static void i8042_shutdown(struct platform_device *dev) 1193static void i8042_shutdown(struct platform_device *dev)
1187{ 1194{
1188 i8042_controller_reset(); 1195 i8042_controller_reset(false);
1189} 1196}
1190 1197
1191static int __init i8042_create_kbd_port(void) 1198static int __init i8042_create_kbd_port(void)
@@ -1424,7 +1431,7 @@ static int __init i8042_probe(struct platform_device *dev)
1424 out_fail: 1431 out_fail:
1425 i8042_free_aux_ports(); /* in case KBD failed but AUX not */ 1432 i8042_free_aux_ports(); /* in case KBD failed but AUX not */
1426 i8042_free_irqs(); 1433 i8042_free_irqs();
1427 i8042_controller_reset(); 1434 i8042_controller_reset(false);
1428 i8042_platform_device = NULL; 1435 i8042_platform_device = NULL;
1429 1436
1430 return error; 1437 return error;
@@ -1434,7 +1441,7 @@ static int __devexit i8042_remove(struct platform_device *dev)
1434{ 1441{
1435 i8042_unregister_ports(); 1442 i8042_unregister_ports();
1436 i8042_free_irqs(); 1443 i8042_free_irqs();
1437 i8042_controller_reset(); 1444 i8042_controller_reset(false);
1438 i8042_platform_device = NULL; 1445 i8042_platform_device = NULL;
1439 1446
1440 return 0; 1447 return 0;
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 6d89fd1842c3..85bace2c8fe8 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -1198,9 +1198,9 @@ static ssize_t
1198store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1198store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1199{ 1199{
1200 struct aiptek *aiptek = dev_get_drvdata(dev); 1200 struct aiptek *aiptek = dev_get_drvdata(dev);
1201 long x; 1201 int x;
1202 1202
1203 if (strict_strtol(buf, 10, &x)) { 1203 if (kstrtoint(buf, 10, &x)) {
1204 size_t len = buf[count - 1] == '\n' ? count - 1 : count; 1204 size_t len = buf[count - 1] == '\n' ? count - 1 : count;
1205 1205
1206 if (strncmp(buf, "disable", len)) 1206 if (strncmp(buf, "disable", len))
@@ -1240,9 +1240,9 @@ static ssize_t
1240store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1240store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1241{ 1241{
1242 struct aiptek *aiptek = dev_get_drvdata(dev); 1242 struct aiptek *aiptek = dev_get_drvdata(dev);
1243 long y; 1243 int y;
1244 1244
1245 if (strict_strtol(buf, 10, &y)) { 1245 if (kstrtoint(buf, 10, &y)) {
1246 size_t len = buf[count - 1] == '\n' ? count - 1 : count; 1246 size_t len = buf[count - 1] == '\n' ? count - 1 : count;
1247 1247
1248 if (strncmp(buf, "disable", len)) 1248 if (strncmp(buf, "disable", len))
@@ -1277,12 +1277,13 @@ static ssize_t
1277store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1277store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1278{ 1278{
1279 struct aiptek *aiptek = dev_get_drvdata(dev); 1279 struct aiptek *aiptek = dev_get_drvdata(dev);
1280 long j; 1280 int err, j;
1281 1281
1282 if (strict_strtol(buf, 10, &j)) 1282 err = kstrtoint(buf, 10, &j);
1283 return -EINVAL; 1283 if (err)
1284 return err;
1284 1285
1285 aiptek->newSetting.jitterDelay = (int)j; 1286 aiptek->newSetting.jitterDelay = j;
1286 return count; 1287 return count;
1287} 1288}
1288 1289
@@ -1306,12 +1307,13 @@ static ssize_t
1306store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1307store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1307{ 1308{
1308 struct aiptek *aiptek = dev_get_drvdata(dev); 1309 struct aiptek *aiptek = dev_get_drvdata(dev);
1309 long d; 1310 int err, d;
1310 1311
1311 if (strict_strtol(buf, 10, &d)) 1312 err = kstrtoint(buf, 10, &d);
1312 return -EINVAL; 1313 if (err)
1314 return err;
1313 1315
1314 aiptek->newSetting.programmableDelay = (int)d; 1316 aiptek->newSetting.programmableDelay = d;
1315 return count; 1317 return count;
1316} 1318}
1317 1319
@@ -1557,11 +1559,13 @@ static ssize_t
1557store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1559store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1558{ 1560{
1559 struct aiptek *aiptek = dev_get_drvdata(dev); 1561 struct aiptek *aiptek = dev_get_drvdata(dev);
1560 long w; 1562 int err, w;
1561 1563
1562 if (strict_strtol(buf, 10, &w)) return -EINVAL; 1564 err = kstrtoint(buf, 10, &w);
1565 if (err)
1566 return err;
1563 1567
1564 aiptek->newSetting.wheel = (int)w; 1568 aiptek->newSetting.wheel = w;
1565 return count; 1569 return count;
1566} 1570}
1567 1571
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 1c1b7b43cf92..2fe21d1a18b7 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -28,7 +28,9 @@
28#define HID_USAGE_Y_TILT 0x3e 28#define HID_USAGE_Y_TILT 0x3e
29#define HID_USAGE_FINGER 0x22 29#define HID_USAGE_FINGER 0x22
30#define HID_USAGE_STYLUS 0x20 30#define HID_USAGE_STYLUS 0x20
31#define HID_COLLECTION 0xc0 31#define HID_COLLECTION 0xa1
32#define HID_COLLECTION_LOGICAL 0x02
33#define HID_COLLECTION_END 0xc0
32 34
33enum { 35enum {
34 WCM_UNDEFINED = 0, 36 WCM_UNDEFINED = 0,
@@ -66,7 +68,8 @@ static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id,
66 do { 68 do {
67 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 69 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
68 USB_REQ_GET_REPORT, 70 USB_REQ_GET_REPORT,
69 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 71 USB_DIR_IN | USB_TYPE_CLASS |
72 USB_RECIP_INTERFACE,
70 (type << 8) + id, 73 (type << 8) + id,
71 intf->altsetting[0].desc.bInterfaceNumber, 74 intf->altsetting[0].desc.bInterfaceNumber,
72 buf, size, 100); 75 buf, size, 100);
@@ -164,7 +167,70 @@ static void wacom_close(struct input_dev *dev)
164 usb_autopm_put_interface(wacom->intf); 167 usb_autopm_put_interface(wacom->intf);
165} 168}
166 169
167static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, 170static int wacom_parse_logical_collection(unsigned char *report,
171 struct wacom_features *features)
172{
173 int length = 0;
174
175 if (features->type == BAMBOO_PT) {
176
177 /* Logical collection is only used by 3rd gen Bamboo Touch */
178 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
179 features->device_type = BTN_TOOL_DOUBLETAP;
180
181 /*
182 * Stylus and Touch have same active area
183 * so compute physical size based on stylus
184 * data before its overwritten.
185 */
186 features->x_phy =
187 (features->x_max * features->x_resolution) / 100;
188 features->y_phy =
189 (features->y_max * features->y_resolution) / 100;
190
191 features->x_max = features->y_max =
192 get_unaligned_le16(&report[10]);
193
194 length = 11;
195 }
196 return length;
197}
198
199/*
200 * Interface Descriptor of wacom devices can be incomplete and
201 * inconsistent so wacom_features table is used to store stylus
202 * device's packet lengths, various maximum values, and tablet
203 * resolution based on product ID's.
204 *
205 * For devices that contain 2 interfaces, wacom_features table is
206 * inaccurate for the touch interface. Since the Interface Descriptor
207 * for touch interfaces has pretty complete data, this function exists
208 * to query tablet for this missing information instead of hard coding in
209 * an additional table.
210 *
211 * A typical Interface Descriptor for a stylus will contain a
212 * boot mouse application collection that is not of interest and this
213 * function will ignore it.
214 *
215 * It also contains a digitizer application collection that also is not
216 * of interest since any information it contains would be duplicate
217 * of what is in wacom_features. Usually it defines a report of an array
218 * of bytes that could be used as max length of the stylus packet returned.
219 * If it happens to define a Digitizer-Stylus Physical Collection then
220 * the X and Y logical values contain valid data but it is ignored.
221 *
222 * A typical Interface Descriptor for a touch interface will contain a
223 * Digitizer-Finger Physical Collection which will define both logical
224 * X/Y maximum as well as the physical size of tablet. Since touch
225 * interfaces haven't supported pressure or distance, this is enough
226 * information to override invalid values in the wacom_features table.
227 *
228 * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
229 * Collection. Instead they define a Logical Collection with a single
230 * Logical Maximum for both X and Y.
231 */
232static int wacom_parse_hid(struct usb_interface *intf,
233 struct hid_descriptor *hid_desc,
168 struct wacom_features *features) 234 struct wacom_features *features)
169{ 235{
170 struct usb_device *dev = interface_to_usbdev(intf); 236 struct usb_device *dev = interface_to_usbdev(intf);
@@ -244,8 +310,6 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
244 /* penabled only accepts exact bytes of data */ 310 /* penabled only accepts exact bytes of data */
245 if (features->type == TABLETPC2FG) 311 if (features->type == TABLETPC2FG)
246 features->pktlen = WACOM_PKGLEN_GRAPHIRE; 312 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
247 if (features->type == BAMBOO_PT)
248 features->pktlen = WACOM_PKGLEN_BBFUN;
249 features->device_type = BTN_TOOL_PEN; 313 features->device_type = BTN_TOOL_PEN;
250 features->x_max = 314 features->x_max =
251 get_unaligned_le16(&report[i + 3]); 315 get_unaligned_le16(&report[i + 3]);
@@ -287,8 +351,6 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
287 /* penabled only accepts exact bytes of data */ 351 /* penabled only accepts exact bytes of data */
288 if (features->type == TABLETPC2FG) 352 if (features->type == TABLETPC2FG)
289 features->pktlen = WACOM_PKGLEN_GRAPHIRE; 353 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
290 if (features->type == BAMBOO_PT)
291 features->pktlen = WACOM_PKGLEN_BBFUN;
292 features->device_type = BTN_TOOL_PEN; 354 features->device_type = BTN_TOOL_PEN;
293 features->y_max = 355 features->y_max =
294 get_unaligned_le16(&report[i + 3]); 356 get_unaligned_le16(&report[i + 3]);
@@ -302,6 +364,11 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
302 i++; 364 i++;
303 break; 365 break;
304 366
367 /*
368 * Requiring Stylus Usage will ignore boot mouse
369 * X/Y values and some cases of invalid Digitizer X/Y
370 * values commonly reported.
371 */
305 case HID_USAGE_STYLUS: 372 case HID_USAGE_STYLUS:
306 pen = 1; 373 pen = 1;
307 i++; 374 i++;
@@ -309,10 +376,20 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
309 } 376 }
310 break; 377 break;
311 378
312 case HID_COLLECTION: 379 case HID_COLLECTION_END:
313 /* reset UsagePage and Finger */ 380 /* reset UsagePage and Finger */
314 finger = usage = 0; 381 finger = usage = 0;
315 break; 382 break;
383
384 case HID_COLLECTION:
385 i++;
386 switch (report[i]) {
387 case HID_COLLECTION_LOGICAL:
388 i += wacom_parse_logical_collection(&report[i],
389 features);
390 break;
391 }
392 break;
316 } 393 }
317 } 394 }
318 395
@@ -348,7 +425,8 @@ static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_feat
348 WAC_HID_FEATURE_REPORT, 425 WAC_HID_FEATURE_REPORT,
349 report_id, rep_data, 4, 1); 426 report_id, rep_data, 4, 1);
350 } while ((error < 0 || rep_data[1] != 4) && limit++ < WAC_MSG_RETRIES); 427 } while ((error < 0 || rep_data[1] != 4) && limit++ < WAC_MSG_RETRIES);
351 } else if (features->type != TABLETPC) { 428 } else if (features->type != TABLETPC &&
429 features->device_type == BTN_TOOL_PEN) {
352 do { 430 do {
353 rep_data[0] = 2; 431 rep_data[0] = 2;
354 rep_data[1] = 2; 432 rep_data[1] = 2;
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index da0d8761e778..ecfcbc8144dc 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -799,6 +799,9 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
799 unsigned char *data = wacom->data; 799 unsigned char *data = wacom->data;
800 int i; 800 int i;
801 801
802 if (data[0] != 0x02)
803 return 0;
804
802 for (i = 0; i < 2; i++) { 805 for (i = 0; i < 2; i++) {
803 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i); 806 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
804 bool touch = data[offset + 3] & 0x80; 807 bool touch = data[offset + 3] & 0x80;
@@ -837,18 +840,77 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
837 return 0; 840 return 0;
838} 841}
839 842
843static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
844{
845 struct input_dev *input = wacom->input;
846 int slot_id = data[0] - 2; /* data[0] is between 2 and 17 */
847 bool touch = data[1] & 0x80;
848
849 touch = touch && !wacom->shared->stylus_in_proximity;
850
851 input_mt_slot(input, slot_id);
852 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
853
854 if (touch) {
855 int x = (data[2] << 4) | (data[4] >> 4);
856 int y = (data[3] << 4) | (data[4] & 0x0f);
857 int w = data[6];
858
859 input_report_abs(input, ABS_MT_POSITION_X, x);
860 input_report_abs(input, ABS_MT_POSITION_Y, y);
861 input_report_abs(input, ABS_MT_TOUCH_MAJOR, w);
862 }
863}
864
865static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
866{
867 struct input_dev *input = wacom->input;
868
869 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
870 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
871 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
872 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
873}
874
875static int wacom_bpt3_touch(struct wacom_wac *wacom)
876{
877 struct input_dev *input = wacom->input;
878 unsigned char *data = wacom->data;
879 int count = data[1] & 0x03;
880 int i;
881
882 if (data[0] != 0x02)
883 return 0;
884
885 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
886 for (i = 0; i < count; i++) {
887 int offset = (8 * i) + 2;
888 int msg_id = data[offset];
889
890 if (msg_id >= 2 && msg_id <= 17)
891 wacom_bpt3_touch_msg(wacom, data + offset);
892 else if (msg_id == 128)
893 wacom_bpt3_button_msg(wacom, data + offset);
894
895 }
896
897 input_mt_report_pointer_emulation(input, true);
898
899 input_sync(input);
900
901 return 0;
902}
903
840static int wacom_bpt_pen(struct wacom_wac *wacom) 904static int wacom_bpt_pen(struct wacom_wac *wacom)
841{ 905{
842 struct input_dev *input = wacom->input; 906 struct input_dev *input = wacom->input;
843 unsigned char *data = wacom->data; 907 unsigned char *data = wacom->data;
844 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0; 908 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
845 909
846 /* 910 if (data[0] != 0x02)
847 * Similar to Graphire protocol, data[1] & 0x20 is proximity and 911 return 0;
848 * data[1] & 0x18 is tool ID. 0x30 is safety check to ignore 912
849 * 2 unused tool ID's. 913 prox = (data[1] & 0x20) == 0x20;
850 */
851 prox = (data[1] & 0x30) == 0x30;
852 914
853 /* 915 /*
854 * All reports shared between PEN and RUBBER tool must be 916 * All reports shared between PEN and RUBBER tool must be
@@ -912,7 +974,9 @@ static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
912{ 974{
913 if (len == WACOM_PKGLEN_BBTOUCH) 975 if (len == WACOM_PKGLEN_BBTOUCH)
914 return wacom_bpt_touch(wacom); 976 return wacom_bpt_touch(wacom);
915 else if (len == WACOM_PKGLEN_BBFUN) 977 else if (len == WACOM_PKGLEN_BBTOUCH3)
978 return wacom_bpt3_touch(wacom);
979 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
916 return wacom_bpt_pen(wacom); 980 return wacom_bpt_pen(wacom);
917 981
918 return 0; 982 return 0;
@@ -1031,9 +1095,9 @@ void wacom_setup_device_quirks(struct wacom_features *features)
1031 features->type == BAMBOO_PT) 1095 features->type == BAMBOO_PT)
1032 features->quirks |= WACOM_QUIRK_MULTI_INPUT; 1096 features->quirks |= WACOM_QUIRK_MULTI_INPUT;
1033 1097
1034 /* quirks for bamboo touch */ 1098 /* quirk for bamboo touch with 2 low res touches */
1035 if (features->type == BAMBOO_PT && 1099 if (features->type == BAMBOO_PT &&
1036 features->device_type == BTN_TOOL_DOUBLETAP) { 1100 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
1037 features->x_max <<= 5; 1101 features->x_max <<= 5;
1038 features->y_max <<= 5; 1102 features->y_max <<= 5;
1039 features->x_fuzz <<= 5; 1103 features->x_fuzz <<= 5;
@@ -1240,7 +1304,21 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev,
1240 __set_bit(BTN_TOOL_FINGER, input_dev->keybit); 1304 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
1241 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); 1305 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
1242 1306
1243 input_mt_init_slots(input_dev, 2); 1307 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
1308 __set_bit(BTN_TOOL_TRIPLETAP,
1309 input_dev->keybit);
1310 __set_bit(BTN_TOOL_QUADTAP,
1311 input_dev->keybit);
1312
1313 input_mt_init_slots(input_dev, 16);
1314
1315 input_set_abs_params(input_dev,
1316 ABS_MT_TOUCH_MAJOR,
1317 0, 255, 0, 0);
1318 } else {
1319 input_mt_init_slots(input_dev, 2);
1320 }
1321
1244 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1322 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1245 0, features->x_max, 1323 0, features->x_max,
1246 features->x_fuzz, 0); 1324 features->x_fuzz, 0);
@@ -1506,6 +1584,15 @@ static const struct wacom_features wacom_features_0xDA =
1506static struct wacom_features wacom_features_0xDB = 1584static struct wacom_features wacom_features_0xDB =
1507 { "Wacom Bamboo 2FG 6x8 SE", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023, 1585 { "Wacom Bamboo 2FG 6x8 SE", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
1508 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 1586 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1587static const struct wacom_features wacom_features_0xDD =
1588 { "Wacom Bamboo Connect", WACOM_PKGLEN_BBPEN, 14720, 9200, 1023,
1589 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1590static const struct wacom_features wacom_features_0xDE =
1591 { "Wacom Bamboo 16FG 4x5", WACOM_PKGLEN_BBPEN, 14720, 9200, 1023,
1592 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1593static const struct wacom_features wacom_features_0xDF =
1594 { "Wacom Bamboo 16FG 6x8", WACOM_PKGLEN_BBPEN, 21648, 13700, 1023,
1595 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1509static const struct wacom_features wacom_features_0x6004 = 1596static const struct wacom_features wacom_features_0x6004 =
1510 { "ISD-V4", WACOM_PKGLEN_GRAPHIRE, 12800, 8000, 255, 1597 { "ISD-V4", WACOM_PKGLEN_GRAPHIRE, 12800, 8000, 255,
1511 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 1598 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
@@ -1601,6 +1688,9 @@ const struct usb_device_id wacom_ids[] = {
1601 { USB_DEVICE_WACOM(0xD8) }, 1688 { USB_DEVICE_WACOM(0xD8) },
1602 { USB_DEVICE_WACOM(0xDA) }, 1689 { USB_DEVICE_WACOM(0xDA) },
1603 { USB_DEVICE_WACOM(0xDB) }, 1690 { USB_DEVICE_WACOM(0xDB) },
1691 { USB_DEVICE_WACOM(0xDD) },
1692 { USB_DEVICE_WACOM(0xDE) },
1693 { USB_DEVICE_WACOM(0xDF) },
1604 { USB_DEVICE_WACOM(0xF0) }, 1694 { USB_DEVICE_WACOM(0xF0) },
1605 { USB_DEVICE_WACOM(0xCC) }, 1695 { USB_DEVICE_WACOM(0xCC) },
1606 { USB_DEVICE_WACOM(0x90) }, 1696 { USB_DEVICE_WACOM(0x90) },
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h
index 53eb71b68330..27f1d1c203a1 100644
--- a/drivers/input/tablet/wacom_wac.h
+++ b/drivers/input/tablet/wacom_wac.h
@@ -12,7 +12,7 @@
12#include <linux/types.h> 12#include <linux/types.h>
13 13
14/* maximum packet length for USB devices */ 14/* maximum packet length for USB devices */
15#define WACOM_PKGLEN_MAX 32 15#define WACOM_PKGLEN_MAX 64
16 16
17/* packet length for individual models */ 17/* packet length for individual models */
18#define WACOM_PKGLEN_PENPRTN 7 18#define WACOM_PKGLEN_PENPRTN 7
@@ -22,6 +22,8 @@
22#define WACOM_PKGLEN_TPC1FG 5 22#define WACOM_PKGLEN_TPC1FG 5
23#define WACOM_PKGLEN_TPC2FG 14 23#define WACOM_PKGLEN_TPC2FG 14
24#define WACOM_PKGLEN_BBTOUCH 20 24#define WACOM_PKGLEN_BBTOUCH 20
25#define WACOM_PKGLEN_BBTOUCH3 64
26#define WACOM_PKGLEN_BBPEN 10
25 27
26/* device IDs */ 28/* device IDs */
27#define STYLUS_DEVICE_ID 0x02 29#define STYLUS_DEVICE_ID 0x02
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 3488ffe1fa0a..2b456a915d77 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -177,6 +177,16 @@ config TOUCHSCREEN_EETI
177 To compile this driver as a module, choose M here: the 177 To compile this driver as a module, choose M here: the
178 module will be called eeti_ts. 178 module will be called eeti_ts.
179 179
180config TOUCHSCREEN_EGALAX
181 tristate "EETI eGalax multi-touch panel support"
182 depends on I2C
183 help
184 Say Y here to enable support for I2C connected EETI
185 eGalax multi-touch panels.
186
187 To compile this driver as a module, choose M here: the
188 module will be called egalax_ts.
189
180config TOUCHSCREEN_FUJITSU 190config TOUCHSCREEN_FUJITSU
181 tristate "Fujitsu serial touchscreen" 191 tristate "Fujitsu serial touchscreen"
182 select SERIO 192 select SERIO
@@ -541,6 +551,7 @@ config TOUCHSCREEN_USB_COMPOSITE
541 - GoTop Super_Q2/GogoPen/PenPower tablets 551 - GoTop Super_Q2/GogoPen/PenPower tablets
542 - JASTEC USB Touch Controller/DigiTech DTR-02U 552 - JASTEC USB Touch Controller/DigiTech DTR-02U
543 - Zytronic controllers 553 - Zytronic controllers
554 - Elo TouchSystems 2700 IntelliTouch
544 555
545 Have a look at <http://linux.chapter7.ch/touchkit/> for 556 Have a look at <http://linux.chapter7.ch/touchkit/> for
546 a usage description and the required user-space stuff. 557 a usage description and the required user-space stuff.
@@ -620,6 +631,11 @@ config TOUCHSCREEN_USB_JASTEC
620 bool "JASTEC/DigiTech DTR-02U USB touch controller device support" if EXPERT 631 bool "JASTEC/DigiTech DTR-02U USB touch controller device support" if EXPERT
621 depends on TOUCHSCREEN_USB_COMPOSITE 632 depends on TOUCHSCREEN_USB_COMPOSITE
622 633
634config TOUCHSCREEN_USB_ELO
635 default y
636 bool "Elo TouchSystems 2700 IntelliTouch controller device support" if EXPERT
637 depends on TOUCHSCREEN_USB_COMPOSITE
638
623config TOUCHSCREEN_USB_E2I 639config TOUCHSCREEN_USB_E2I
624 default y 640 default y
625 bool "e2i Touchscreen controller (e.g. from Mimo 740)" 641 bool "e2i Touchscreen controller (e.g. from Mimo 740)"
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index f957676035a4..a09c546b33b7 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE) += hampshire.o
23obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o 23obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
24obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o 24obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o
25obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o 25obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
26obj-$(CONFIG_TOUCHSCREEN_EGALAX) += egalax_ts.o
26obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o 27obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
27obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o 28obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
28obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o 29obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index 400131df677b..2da9f189e493 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -488,10 +488,10 @@ static ssize_t ad7877_disable_store(struct device *dev,
488 const char *buf, size_t count) 488 const char *buf, size_t count)
489{ 489{
490 struct ad7877 *ts = dev_get_drvdata(dev); 490 struct ad7877 *ts = dev_get_drvdata(dev);
491 unsigned long val; 491 unsigned int val;
492 int error; 492 int error;
493 493
494 error = strict_strtoul(buf, 10, &val); 494 error = kstrtouint(buf, 10, &val);
495 if (error) 495 if (error)
496 return error; 496 return error;
497 497
@@ -518,10 +518,10 @@ static ssize_t ad7877_dac_store(struct device *dev,
518 const char *buf, size_t count) 518 const char *buf, size_t count)
519{ 519{
520 struct ad7877 *ts = dev_get_drvdata(dev); 520 struct ad7877 *ts = dev_get_drvdata(dev);
521 unsigned long val; 521 unsigned int val;
522 int error; 522 int error;
523 523
524 error = strict_strtoul(buf, 10, &val); 524 error = kstrtouint(buf, 10, &val);
525 if (error) 525 if (error)
526 return error; 526 return error;
527 527
@@ -548,10 +548,10 @@ static ssize_t ad7877_gpio3_store(struct device *dev,
548 const char *buf, size_t count) 548 const char *buf, size_t count)
549{ 549{
550 struct ad7877 *ts = dev_get_drvdata(dev); 550 struct ad7877 *ts = dev_get_drvdata(dev);
551 unsigned long val; 551 unsigned int val;
552 int error; 552 int error;
553 553
554 error = strict_strtoul(buf, 10, &val); 554 error = kstrtouint(buf, 10, &val);
555 if (error) 555 if (error)
556 return error; 556 return error;
557 557
@@ -579,10 +579,10 @@ static ssize_t ad7877_gpio4_store(struct device *dev,
579 const char *buf, size_t count) 579 const char *buf, size_t count)
580{ 580{
581 struct ad7877 *ts = dev_get_drvdata(dev); 581 struct ad7877 *ts = dev_get_drvdata(dev);
582 unsigned long val; 582 unsigned int val;
583 int error; 583 int error;
584 584
585 error = strict_strtoul(buf, 10, &val); 585 error = kstrtouint(buf, 10, &val);
586 if (error) 586 if (error)
587 return error; 587 return error;
588 588
diff --git a/drivers/input/touchscreen/ad7879-i2c.c b/drivers/input/touchscreen/ad7879-i2c.c
index c789b974c795..c4b51170c951 100644
--- a/drivers/input/touchscreen/ad7879-i2c.c
+++ b/drivers/input/touchscreen/ad7879-i2c.c
@@ -16,30 +16,6 @@
16 16
17#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */ 17#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
18 18
19#ifdef CONFIG_PM_SLEEP
20static int ad7879_i2c_suspend(struct device *dev)
21{
22 struct i2c_client *client = to_i2c_client(dev);
23 struct ad7879 *ts = i2c_get_clientdata(client);
24
25 ad7879_suspend(ts);
26
27 return 0;
28}
29
30static int ad7879_i2c_resume(struct device *dev)
31{
32 struct i2c_client *client = to_i2c_client(dev);
33 struct ad7879 *ts = i2c_get_clientdata(client);
34
35 ad7879_resume(ts);
36
37 return 0;
38}
39#endif
40
41static SIMPLE_DEV_PM_OPS(ad7879_i2c_pm, ad7879_i2c_suspend, ad7879_i2c_resume);
42
43/* All registers are word-sized. 19/* All registers are word-sized.
44 * AD7879 uses a high-byte first convention. 20 * AD7879 uses a high-byte first convention.
45 */ 21 */
@@ -119,7 +95,7 @@ static struct i2c_driver ad7879_i2c_driver = {
119 .driver = { 95 .driver = {
120 .name = "ad7879", 96 .name = "ad7879",
121 .owner = THIS_MODULE, 97 .owner = THIS_MODULE,
122 .pm = &ad7879_i2c_pm, 98 .pm = &ad7879_pm_ops,
123 }, 99 },
124 .probe = ad7879_i2c_probe, 100 .probe = ad7879_i2c_probe,
125 .remove = __devexit_p(ad7879_i2c_remove), 101 .remove = __devexit_p(ad7879_i2c_remove),
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c
index b1643c8fa7c9..8f391ffbf441 100644
--- a/drivers/input/touchscreen/ad7879-spi.c
+++ b/drivers/input/touchscreen/ad7879-spi.c
@@ -22,30 +22,6 @@
22#define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) 22#define AD7879_WRITECMD(reg) (AD7879_CMD(reg))
23#define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) 23#define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ)
24 24
25#ifdef CONFIG_PM_SLEEP
26static int ad7879_spi_suspend(struct device *dev)
27{
28 struct spi_device *spi = to_spi_device(dev);
29 struct ad7879 *ts = spi_get_drvdata(spi);
30
31 ad7879_suspend(ts);
32
33 return 0;
34}
35
36static int ad7879_spi_resume(struct device *dev)
37{
38 struct spi_device *spi = to_spi_device(dev);
39 struct ad7879 *ts = spi_get_drvdata(spi);
40
41 ad7879_resume(ts);
42
43 return 0;
44}
45#endif
46
47static SIMPLE_DEV_PM_OPS(ad7879_spi_pm, ad7879_spi_suspend, ad7879_spi_resume);
48
49/* 25/*
50 * ad7879_read/write are only used for initial setup and for sysfs controls. 26 * ad7879_read/write are only used for initial setup and for sysfs controls.
51 * The main traffic is done in ad7879_collect(). 27 * The main traffic is done in ad7879_collect().
@@ -176,7 +152,7 @@ static struct spi_driver ad7879_spi_driver = {
176 .name = "ad7879", 152 .name = "ad7879",
177 .bus = &spi_bus_type, 153 .bus = &spi_bus_type,
178 .owner = THIS_MODULE, 154 .owner = THIS_MODULE,
179 .pm = &ad7879_spi_pm, 155 .pm = &ad7879_pm_ops,
180 }, 156 },
181 .probe = ad7879_spi_probe, 157 .probe = ad7879_spi_probe,
182 .remove = __devexit_p(ad7879_spi_remove), 158 .remove = __devexit_p(ad7879_spi_remove),
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index 3b2e9ed2aeec..e2482b40da51 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -281,8 +281,11 @@ static void ad7879_close(struct input_dev* input)
281 __ad7879_disable(ts); 281 __ad7879_disable(ts);
282} 282}
283 283
284void ad7879_suspend(struct ad7879 *ts) 284#ifdef CONFIG_PM_SLEEP
285static int ad7879_suspend(struct device *dev)
285{ 286{
287 struct ad7879 *ts = dev_get_drvdata(dev);
288
286 mutex_lock(&ts->input->mutex); 289 mutex_lock(&ts->input->mutex);
287 290
288 if (!ts->suspended && !ts->disabled && ts->input->users) 291 if (!ts->suspended && !ts->disabled && ts->input->users)
@@ -291,11 +294,14 @@ void ad7879_suspend(struct ad7879 *ts)
291 ts->suspended = true; 294 ts->suspended = true;
292 295
293 mutex_unlock(&ts->input->mutex); 296 mutex_unlock(&ts->input->mutex);
297
298 return 0;
294} 299}
295EXPORT_SYMBOL(ad7879_suspend);
296 300
297void ad7879_resume(struct ad7879 *ts) 301static int ad7879_resume(struct device *dev)
298{ 302{
303 struct ad7879 *ts = dev_get_drvdata(dev);
304
299 mutex_lock(&ts->input->mutex); 305 mutex_lock(&ts->input->mutex);
300 306
301 if (ts->suspended && !ts->disabled && ts->input->users) 307 if (ts->suspended && !ts->disabled && ts->input->users)
@@ -304,8 +310,13 @@ void ad7879_resume(struct ad7879 *ts)
304 ts->suspended = false; 310 ts->suspended = false;
305 311
306 mutex_unlock(&ts->input->mutex); 312 mutex_unlock(&ts->input->mutex);
313
314 return 0;
307} 315}
308EXPORT_SYMBOL(ad7879_resume); 316#endif
317
318SIMPLE_DEV_PM_OPS(ad7879_pm_ops, ad7879_suspend, ad7879_resume);
319EXPORT_SYMBOL(ad7879_pm_ops);
309 320
310static void ad7879_toggle(struct ad7879 *ts, bool disable) 321static void ad7879_toggle(struct ad7879 *ts, bool disable)
311{ 322{
@@ -340,10 +351,10 @@ static ssize_t ad7879_disable_store(struct device *dev,
340 const char *buf, size_t count) 351 const char *buf, size_t count)
341{ 352{
342 struct ad7879 *ts = dev_get_drvdata(dev); 353 struct ad7879 *ts = dev_get_drvdata(dev);
343 unsigned long val; 354 unsigned int val;
344 int error; 355 int error;
345 356
346 error = strict_strtoul(buf, 10, &val); 357 error = kstrtouint(buf, 10, &val);
347 if (error) 358 if (error)
348 return error; 359 return error;
349 360
diff --git a/drivers/input/touchscreen/ad7879.h b/drivers/input/touchscreen/ad7879.h
index 6b45a27236c7..6fd13c48d373 100644
--- a/drivers/input/touchscreen/ad7879.h
+++ b/drivers/input/touchscreen/ad7879.h
@@ -21,8 +21,8 @@ struct ad7879_bus_ops {
21 int (*write)(struct device *dev, u8 reg, u16 val); 21 int (*write)(struct device *dev, u8 reg, u16 val);
22}; 22};
23 23
24void ad7879_suspend(struct ad7879 *); 24extern const struct dev_pm_ops ad7879_pm_ops;
25void ad7879_resume(struct ad7879 *); 25
26struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned irq, 26struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned irq,
27 const struct ad7879_bus_ops *bops); 27 const struct ad7879_bus_ops *bops);
28void ad7879_remove(struct ad7879 *); 28void ad7879_remove(struct ad7879 *);
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index de31ec6fe9e4..4cedae6a36ea 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -602,10 +602,12 @@ static ssize_t ads7846_disable_store(struct device *dev,
602 const char *buf, size_t count) 602 const char *buf, size_t count)
603{ 603{
604 struct ads7846 *ts = dev_get_drvdata(dev); 604 struct ads7846 *ts = dev_get_drvdata(dev);
605 unsigned long i; 605 unsigned int i;
606 int err;
606 607
607 if (strict_strtoul(buf, 10, &i)) 608 err = kstrtouint(buf, 10, &i);
608 return -EINVAL; 609 if (err)
610 return err;
609 611
610 if (i) 612 if (i)
611 ads7846_disable(ts); 613 ads7846_disable(ts);
diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
new file mode 100644
index 000000000000..eadcc2e83c77
--- /dev/null
+++ b/drivers/input/touchscreen/egalax_ts.c
@@ -0,0 +1,303 @@
1/*
2 * Driver for EETI eGalax Multiple Touch Controller
3 *
4 * Copyright (C) 2011 Freescale Semiconductor, Inc.
5 *
6 * based on max11801_ts.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13/* EETI eGalax serial touch screen controller is a I2C based multiple
14 * touch screen controller, it supports 5 point multiple touch. */
15
16/* TODO:
17 - auto idle mode support
18*/
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/i2c.h>
23#include <linux/interrupt.h>
24#include <linux/input.h>
25#include <linux/irq.h>
26#include <linux/gpio.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/bitops.h>
30#include <linux/input/mt.h>
31
32/*
33 * Mouse Mode: some panel may configure the controller to mouse mode,
34 * which can only report one point at a given time.
35 * This driver will ignore events in this mode.
36 */
37#define REPORT_MODE_MOUSE 0x1
38/*
39 * Vendor Mode: this mode is used to transfer some vendor specific
40 * messages.
41 * This driver will ignore events in this mode.
42 */
43#define REPORT_MODE_VENDOR 0x3
44/* Multiple Touch Mode */
45#define REPORT_MODE_MTTOUCH 0x4
46
47#define MAX_SUPPORT_POINTS 5
48
49#define EVENT_VALID_OFFSET 7
50#define EVENT_VALID_MASK (0x1 << EVENT_VALID_OFFSET)
51#define EVENT_ID_OFFSET 2
52#define EVENT_ID_MASK (0xf << EVENT_ID_OFFSET)
53#define EVENT_IN_RANGE (0x1 << 1)
54#define EVENT_DOWN_UP (0X1 << 0)
55
56#define MAX_I2C_DATA_LEN 10
57
58#define EGALAX_MAX_X 32760
59#define EGALAX_MAX_Y 32760
60#define EGALAX_MAX_TRIES 100
61
62struct egalax_ts {
63 struct i2c_client *client;
64 struct input_dev *input_dev;
65};
66
67static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
68{
69 struct egalax_ts *ts = dev_id;
70 struct input_dev *input_dev = ts->input_dev;
71 struct i2c_client *client = ts->client;
72 u8 buf[MAX_I2C_DATA_LEN];
73 int id, ret, x, y, z;
74 int tries = 0;
75 bool down, valid;
76 u8 state;
77
78 do {
79 ret = i2c_master_recv(client, buf, MAX_I2C_DATA_LEN);
80 } while (ret == -EAGAIN && tries++ < EGALAX_MAX_TRIES);
81
82 if (ret < 0)
83 return IRQ_HANDLED;
84
85 if (buf[0] != REPORT_MODE_MTTOUCH) {
86 /* ignore mouse events and vendor events */
87 return IRQ_HANDLED;
88 }
89
90 state = buf[1];
91 x = (buf[3] << 8) | buf[2];
92 y = (buf[5] << 8) | buf[4];
93 z = (buf[7] << 8) | buf[6];
94
95 valid = state & EVENT_VALID_MASK;
96 id = (state & EVENT_ID_MASK) >> EVENT_ID_OFFSET;
97 down = state & EVENT_DOWN_UP;
98
99 if (!valid || id > MAX_SUPPORT_POINTS) {
100 dev_dbg(&client->dev, "point invalid\n");
101 return IRQ_HANDLED;
102 }
103
104 input_mt_slot(input_dev, id);
105 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, down);
106
107 dev_dbg(&client->dev, "%s id:%d x:%d y:%d z:%d",
108 down ? "down" : "up", id, x, y, z);
109
110 if (down) {
111 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
112 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
113 input_report_abs(input_dev, ABS_MT_PRESSURE, z);
114 }
115
116 input_mt_report_pointer_emulation(input_dev, true);
117 input_sync(input_dev);
118
119 return IRQ_HANDLED;
120}
121
122/* wake up controller by an falling edge of interrupt gpio. */
123static int egalax_wake_up_device(struct i2c_client *client)
124{
125 int gpio = irq_to_gpio(client->irq);
126 int ret;
127
128 ret = gpio_request(gpio, "egalax_irq");
129 if (ret < 0) {
130 dev_err(&client->dev,
131 "request gpio failed, cannot wake up controller: %d\n",
132 ret);
133 return ret;
134 }
135
136 /* wake up controller via an falling edge on IRQ gpio. */
137 gpio_direction_output(gpio, 0);
138 gpio_set_value(gpio, 1);
139
140 /* controller should be waken up, return irq. */
141 gpio_direction_input(gpio);
142 gpio_free(gpio);
143
144 return 0;
145}
146
147static int __devinit egalax_firmware_version(struct i2c_client *client)
148{
149 static const u8 cmd[MAX_I2C_DATA_LEN] = { 0x03, 0x03, 0xa, 0x01, 0x41 };
150 int ret;
151
152 ret = i2c_master_send(client, cmd, MAX_I2C_DATA_LEN);
153 if (ret < 0)
154 return ret;
155
156 return 0;
157}
158
159static int __devinit egalax_ts_probe(struct i2c_client *client,
160 const struct i2c_device_id *id)
161{
162 struct egalax_ts *ts;
163 struct input_dev *input_dev;
164 int ret;
165 int error;
166
167 ts = kzalloc(sizeof(struct egalax_ts), GFP_KERNEL);
168 if (!ts) {
169 dev_err(&client->dev, "Failed to allocate memory\n");
170 return -ENOMEM;
171 }
172
173 input_dev = input_allocate_device();
174 if (!input_dev) {
175 dev_err(&client->dev, "Failed to allocate memory\n");
176 error = -ENOMEM;
177 goto err_free_ts;
178 }
179
180 ts->client = client;
181 ts->input_dev = input_dev;
182
183 /* controller may be in sleep, wake it up. */
184 egalax_wake_up_device(client);
185
186 ret = egalax_firmware_version(client);
187 if (ret < 0) {
188 dev_err(&client->dev, "Failed to read firmware version\n");
189 error = -EIO;
190 goto err_free_dev;
191 }
192
193 input_dev->name = "EETI eGalax Touch Screen";
194 input_dev->id.bustype = BUS_I2C;
195 input_dev->dev.parent = &client->dev;
196
197 __set_bit(EV_ABS, input_dev->evbit);
198 __set_bit(EV_KEY, input_dev->evbit);
199 __set_bit(BTN_TOUCH, input_dev->keybit);
200
201 input_set_abs_params(input_dev, ABS_X, 0, EGALAX_MAX_X, 0, 0);
202 input_set_abs_params(input_dev, ABS_Y, 0, EGALAX_MAX_Y, 0, 0);
203 input_set_abs_params(input_dev,
204 ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0);
205 input_set_abs_params(input_dev,
206 ABS_MT_POSITION_X, 0, EGALAX_MAX_Y, 0, 0);
207 input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS);
208
209 input_set_drvdata(input_dev, ts);
210
211 error = request_threaded_irq(client->irq, NULL, egalax_ts_interrupt,
212 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
213 "egalax_ts", ts);
214 if (error < 0) {
215 dev_err(&client->dev, "Failed to register interrupt\n");
216 goto err_free_dev;
217 }
218
219 error = input_register_device(ts->input_dev);
220 if (error)
221 goto err_free_irq;
222
223 i2c_set_clientdata(client, ts);
224 return 0;
225
226err_free_irq:
227 free_irq(client->irq, ts);
228err_free_dev:
229 input_free_device(input_dev);
230err_free_ts:
231 kfree(ts);
232
233 return error;
234}
235
236static __devexit int egalax_ts_remove(struct i2c_client *client)
237{
238 struct egalax_ts *ts = i2c_get_clientdata(client);
239
240 free_irq(client->irq, ts);
241
242 input_unregister_device(ts->input_dev);
243 kfree(ts);
244
245 return 0;
246}
247
248static const struct i2c_device_id egalax_ts_id[] = {
249 { "egalax_ts", 0 },
250 { }
251};
252MODULE_DEVICE_TABLE(i2c, egalax_ts_id);
253
254#ifdef CONFIG_PM_SLEEP
255static int egalax_ts_suspend(struct device *dev)
256{
257 static const u8 suspend_cmd[MAX_I2C_DATA_LEN] = {
258 0x3, 0x6, 0xa, 0x3, 0x36, 0x3f, 0x2, 0, 0, 0
259 };
260 struct i2c_client *client = to_i2c_client(dev);
261 int ret;
262
263 ret = i2c_master_send(client, suspend_cmd, MAX_I2C_DATA_LEN);
264 return ret > 0 ? 0 : ret;
265}
266
267static int egalax_ts_resume(struct device *dev)
268{
269 struct i2c_client *client = to_i2c_client(dev);
270
271 return egalax_wake_up_device(client);
272}
273#endif
274
275static SIMPLE_DEV_PM_OPS(egalax_ts_pm_ops, egalax_ts_suspend, egalax_ts_resume);
276
277static struct i2c_driver egalax_ts_driver = {
278 .driver = {
279 .name = "egalax_ts",
280 .owner = THIS_MODULE,
281 .pm = &egalax_ts_pm_ops,
282 },
283 .id_table = egalax_ts_id,
284 .probe = egalax_ts_probe,
285 .remove = __devexit_p(egalax_ts_remove),
286};
287
288static int __init egalax_ts_init(void)
289{
290 return i2c_add_driver(&egalax_ts_driver);
291}
292
293static void __exit egalax_ts_exit(void)
294{
295 i2c_del_driver(&egalax_ts_driver);
296}
297
298module_init(egalax_ts_init);
299module_exit(egalax_ts_exit);
300
301MODULE_AUTHOR("Freescale Semiconductor, Inc.");
302MODULE_DESCRIPTION("Touchscreen driver for EETI eGalax touch controller");
303MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 73fd6642b681..9dbd8b4d9a6e 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -16,6 +16,7 @@
16 * - JASTEC USB touch controller/DigiTech DTR-02U 16 * - JASTEC USB touch controller/DigiTech DTR-02U
17 * - Zytronic capacitive touchscreen 17 * - Zytronic capacitive touchscreen
18 * - NEXIO/iNexio 18 * - NEXIO/iNexio
19 * - Elo TouchSystems 2700 IntelliTouch
19 * 20 *
20 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch> 21 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
21 * Copyright (C) by Todd E. Johnson (mtouchusb.c) 22 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
@@ -138,6 +139,7 @@ enum {
138 DEVTYPE_ZYTRONIC, 139 DEVTYPE_ZYTRONIC,
139 DEVTYPE_TC45USB, 140 DEVTYPE_TC45USB,
140 DEVTYPE_NEXIO, 141 DEVTYPE_NEXIO,
142 DEVTYPE_ELO,
141}; 143};
142 144
143#define USB_DEVICE_HID_CLASS(vend, prod) \ 145#define USB_DEVICE_HID_CLASS(vend, prod) \
@@ -239,6 +241,10 @@ static const struct usb_device_id usbtouch_devices[] = {
239 .driver_info = DEVTYPE_NEXIO}, 241 .driver_info = DEVTYPE_NEXIO},
240#endif 242#endif
241 243
244#ifdef CONFIG_TOUCHSCREEN_USB_ELO
245 {USB_DEVICE(0x04e7, 0x0020), .driver_info = DEVTYPE_ELO},
246#endif
247
242 {} 248 {}
243}; 249};
244 250
@@ -945,6 +951,24 @@ static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
945 951
946 952
947/***************************************************************************** 953/*****************************************************************************
954 * ELO part
955 */
956
957#ifdef CONFIG_TOUCHSCREEN_USB_ELO
958
959static int elo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
960{
961 dev->x = (pkt[3] << 8) | pkt[2];
962 dev->y = (pkt[5] << 8) | pkt[4];
963 dev->touch = pkt[6] > 0;
964 dev->press = pkt[6];
965
966 return 1;
967}
968#endif
969
970
971/*****************************************************************************
948 * the different device descriptors 972 * the different device descriptors
949 */ 973 */
950#ifdef MULTI_PACKET 974#ifdef MULTI_PACKET
@@ -953,6 +977,18 @@ static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
953#endif 977#endif
954 978
955static struct usbtouch_device_info usbtouch_dev_info[] = { 979static struct usbtouch_device_info usbtouch_dev_info[] = {
980#ifdef CONFIG_TOUCHSCREEN_USB_ELO
981 [DEVTYPE_ELO] = {
982 .min_xc = 0x0,
983 .max_xc = 0x0fff,
984 .min_yc = 0x0,
985 .max_yc = 0x0fff,
986 .max_press = 0xff,
987 .rept_size = 8,
988 .read_data = elo_read_data,
989 },
990#endif
991
956#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 992#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
957 [DEVTYPE_EGALAX] = { 993 [DEVTYPE_EGALAX] = {
958 .min_xc = 0x0, 994 .min_xc = 0x0,
diff --git a/include/linux/input/samsung-keypad.h b/include/linux/input/samsung-keypad.h
new file mode 100644
index 000000000000..f25619bfd8a8
--- /dev/null
+++ b/include/linux/input/samsung-keypad.h
@@ -0,0 +1,43 @@
1/*
2 * Samsung Keypad platform data definitions
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef __SAMSUNG_KEYPAD_H
14#define __SAMSUNG_KEYPAD_H
15
16#include <linux/input/matrix_keypad.h>
17
18#define SAMSUNG_MAX_ROWS 8
19#define SAMSUNG_MAX_COLS 8
20
21/**
22 * struct samsung_keypad_platdata - Platform device data for Samsung Keypad.
23 * @keymap_data: pointer to &matrix_keymap_data.
24 * @rows: number of keypad row supported.
25 * @cols: number of keypad col supported.
26 * @no_autorepeat: disable key autorepeat.
27 * @wakeup: controls whether the device should be set up as wakeup source.
28 * @cfg_gpio: configure the GPIO.
29 *
30 * Initialisation data specific to either the machine or the platform
31 * for the device driver to use or call-back when configuring gpio.
32 */
33struct samsung_keypad_platdata {
34 const struct matrix_keymap_data *keymap_data;
35 unsigned int rows;
36 unsigned int cols;
37 bool no_autorepeat;
38 bool wakeup;
39
40 void (*cfg_gpio)(unsigned int rows, unsigned int cols);
41};
42
43#endif /* __SAMSUNG_KEYPAD_H */
diff --git a/include/linux/input/tca8418_keypad.h b/include/linux/input/tca8418_keypad.h
new file mode 100644
index 000000000000..e71a85dc2cbd
--- /dev/null
+++ b/include/linux/input/tca8418_keypad.h
@@ -0,0 +1,44 @@
1/*
2 * TCA8418 keypad platform support
3 *
4 * Copyright (C) 2011 Fuel7, Inc. All rights reserved.
5 *
6 * Author: Kyle Manna <kyle.manna@fuel7.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License v2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 021110-1307, USA.
21 *
22 * If you can't comply with GPLv2, alternative licensing terms may be
23 * arranged. Please contact Fuel7, Inc. (http://fuel7.com/) for proprietary
24 * alternative licensing inquiries.
25 */
26
27#ifndef _TCA8418_KEYPAD_H
28#define _TCA8418_KEYPAD_H
29
30#include <linux/types.h>
31#include <linux/input/matrix_keypad.h>
32
33#define TCA8418_I2C_ADDR 0x34
34#define TCA8418_NAME "tca8418_keypad"
35
36struct tca8418_keypad_platform_data {
37 const struct matrix_keymap_data *keymap_data;
38 unsigned rows;
39 unsigned cols;
40 bool rep;
41 bool irq_is_gpio;
42};
43
44#endif