aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/Kconfig9
-rw-r--r--drivers/input/Makefile2
-rw-r--r--drivers/input/input-polldev.c6
-rw-r--r--drivers/input/joystick/Kconfig12
-rw-r--r--drivers/input/joystick/Makefile3
-rw-r--r--drivers/input/joystick/xpad.c213
-rw-r--r--drivers/input/joystick/zhenhua.c243
-rw-r--r--drivers/input/keyboard/aaed2000_kbd.c4
-rw-r--r--drivers/input/keyboard/bf54x-keys.c37
-rw-r--r--drivers/input/keyboard/corgikbd.c2
-rw-r--r--drivers/input/keyboard/gpio_keys.c5
-rw-r--r--drivers/input/keyboard/jornada680_kbd.c2
-rw-r--r--drivers/input/keyboard/jornada720_kbd.c4
-rw-r--r--drivers/input/keyboard/locomokbd.c73
-rw-r--r--drivers/input/keyboard/omap-keypad.c9
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c4
-rw-r--r--drivers/input/keyboard/spitzkbd.c1
-rw-r--r--drivers/input/keyboard/tosakbd.c23
-rw-r--r--drivers/input/misc/cobalt_btns.c3
-rw-r--r--drivers/input/mouse/gpio_mouse.c4
-rw-r--r--drivers/input/serio/Kconfig10
-rw-r--r--drivers/input/serio/Makefile1
-rw-r--r--drivers/input/serio/at32psif.c375
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h12
-rw-r--r--drivers/input/serio/rpckbd.c2
-rw-r--r--drivers/input/tablet/Kconfig10
-rw-r--r--drivers/input/tablet/aiptek.c2
-rw-r--r--drivers/input/tablet/wacom.h3
-rw-r--r--drivers/input/tablet/wacom_sys.c76
-rw-r--r--drivers/input/tablet/wacom_wac.c2
-rw-r--r--drivers/input/touchscreen/Kconfig53
-rw-r--r--drivers/input/touchscreen/Makefile7
-rw-r--r--drivers/input/touchscreen/ads7846.c22
-rw-r--r--drivers/input/touchscreen/corgi_ts.c2
-rw-r--r--drivers/input/touchscreen/jornada720_ts.c4
-rw-r--r--drivers/input/touchscreen/mainstone-wm97xx.c302
-rw-r--r--drivers/input/touchscreen/ucb1400_ts.c4
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c31
-rw-r--r--drivers/input/touchscreen/wm9705.c353
-rw-r--r--drivers/input/touchscreen/wm9712.c462
-rw-r--r--drivers/input/touchscreen/wm9713.c460
-rw-r--r--drivers/input/touchscreen/wm97xx-core.c829
-rw-r--r--drivers/input/xen-kbdfront.c340
43 files changed, 3910 insertions, 111 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 9dea14db724c..5f9d860925a1 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -149,6 +149,15 @@ config INPUT_APMPOWER
149 To compile this driver as a module, choose M here: the 149 To compile this driver as a module, choose M here: the
150 module will be called apm-power. 150 module will be called apm-power.
151 151
152config XEN_KBDDEV_FRONTEND
153 tristate "Xen virtual keyboard and mouse support"
154 depends on XEN_FBDEV_FRONTEND
155 default y
156 help
157 This driver implements the front-end of the Xen virtual
158 keyboard and mouse device driver. It communicates with a back-end
159 in another domain.
160
152comment "Input Device Drivers" 161comment "Input Device Drivers"
153 162
154source "drivers/input/keyboard/Kconfig" 163source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 2ae87b19caa8..98c4f9a77876 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -23,3 +23,5 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
23obj-$(CONFIG_INPUT_MISC) += misc/ 23obj-$(CONFIG_INPUT_MISC) += misc/
24 24
25obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o 25obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
26
27obj-$(CONFIG_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index 490918a5d192..0d3ce7a50fb1 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -73,7 +73,7 @@ static void input_polled_device_work(struct work_struct *work)
73 73
74static int input_open_polled_device(struct input_dev *input) 74static int input_open_polled_device(struct input_dev *input)
75{ 75{
76 struct input_polled_dev *dev = input->private; 76 struct input_polled_dev *dev = input_get_drvdata(input);
77 int error; 77 int error;
78 78
79 error = input_polldev_start_workqueue(); 79 error = input_polldev_start_workqueue();
@@ -91,7 +91,7 @@ static int input_open_polled_device(struct input_dev *input)
91 91
92static void input_close_polled_device(struct input_dev *input) 92static void input_close_polled_device(struct input_dev *input)
93{ 93{
94 struct input_polled_dev *dev = input->private; 94 struct input_polled_dev *dev = input_get_drvdata(input);
95 95
96 cancel_delayed_work_sync(&dev->work); 96 cancel_delayed_work_sync(&dev->work);
97 input_polldev_stop_workqueue(); 97 input_polldev_stop_workqueue();
@@ -151,10 +151,10 @@ int input_register_polled_device(struct input_polled_dev *dev)
151{ 151{
152 struct input_dev *input = dev->input; 152 struct input_dev *input = dev->input;
153 153
154 input_set_drvdata(input, dev);
154 INIT_DELAYED_WORK(&dev->work, input_polled_device_work); 155 INIT_DELAYED_WORK(&dev->work, input_polled_device_work);
155 if (!dev->poll_interval) 156 if (!dev->poll_interval)
156 dev->poll_interval = 500; 157 dev->poll_interval = 500;
157 input->private = dev;
158 input->open = input_open_polled_device; 158 input->open = input_open_polled_device;
159 input->close = input_close_polled_device; 159 input->close = input_close_polled_device;
160 160
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 7c662ee594a3..be5c14a5a0a4 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -193,6 +193,18 @@ config JOYSTICK_TWIDJOY
193 To compile this driver as a module, choose M here: the 193 To compile this driver as a module, choose M here: the
194 module will be called twidjoy. 194 module will be called twidjoy.
195 195
196config JOYSTICK_ZHENHUA
197 tristate "5-byte Zhenhua RC transmitter"
198 select SERIO
199 help
200 Say Y here if you have a Zhen Hua PPM-4CH transmitter which is
201 supplied with a ready to fly micro electric indoor helicopters
202 such as EasyCopter, Lama, MiniCopter, DragonFly or Jabo and want
203 to use it via serial cable as a joystick.
204
205 To compile this driver as a module, choose M here: the
206 module will be called zhenhua.
207
196config JOYSTICK_DB9 208config JOYSTICK_DB9
197 tristate "Multisystem, Sega Genesis, Saturn joysticks and gamepads" 209 tristate "Multisystem, Sega Genesis, Saturn joysticks and gamepads"
198 depends on PARPORT 210 depends on PARPORT
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
index e855abb0cc51..fdbf8c4c2876 100644
--- a/drivers/input/joystick/Makefile
+++ b/drivers/input/joystick/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_JOYSTICK_GF2K) += gf2k.o
15obj-$(CONFIG_JOYSTICK_GRIP) += grip.o 15obj-$(CONFIG_JOYSTICK_GRIP) += grip.o
16obj-$(CONFIG_JOYSTICK_GRIP_MP) += grip_mp.o 16obj-$(CONFIG_JOYSTICK_GRIP_MP) += grip_mp.o
17obj-$(CONFIG_JOYSTICK_GUILLEMOT) += guillemot.o 17obj-$(CONFIG_JOYSTICK_GUILLEMOT) += guillemot.o
18obj-$(CONFIG_JOYSTICK_IFORCE) += iforce/
18obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o 19obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o
19obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o 20obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o
20obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o 21obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o
@@ -27,5 +28,5 @@ obj-$(CONFIG_JOYSTICK_TURBOGRAFX) += turbografx.o
27obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o 28obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o
28obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o 29obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o
29obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o 30obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
31obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
30 32
31obj-$(CONFIG_JOYSTICK_IFORCE) += iforce/
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 2854c8fc334b..4b07bdadb81e 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * X-Box gamepad - v0.0.6 2 * X-Box gamepad driver
3 * 3 *
4 * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de> 4 * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
5 * 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>, 5 * 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>,
@@ -68,6 +68,8 @@
68 * - dance pads will map D-PAD to buttons, not axes 68 * - dance pads will map D-PAD to buttons, not axes
69 * - pass the module paramater 'dpad_to_buttons' to force 69 * - pass the module paramater 'dpad_to_buttons' to force
70 * the D-PAD to map to buttons if your pad is not detected 70 * the D-PAD to map to buttons if your pad is not detected
71 *
72 * Later changes can be tracked in SCM.
71 */ 73 */
72 74
73#include <linux/kernel.h> 75#include <linux/kernel.h>
@@ -77,7 +79,6 @@
77#include <linux/module.h> 79#include <linux/module.h>
78#include <linux/usb/input.h> 80#include <linux/usb/input.h>
79 81
80#define DRIVER_VERSION "v0.0.6"
81#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" 82#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>"
82#define DRIVER_DESC "X-Box pad driver" 83#define DRIVER_DESC "X-Box pad driver"
83 84
@@ -87,10 +88,12 @@
87 but we map them to axes when possible to simplify things */ 88 but we map them to axes when possible to simplify things */
88#define MAP_DPAD_TO_BUTTONS 0 89#define MAP_DPAD_TO_BUTTONS 0
89#define MAP_DPAD_TO_AXES 1 90#define MAP_DPAD_TO_AXES 1
90#define MAP_DPAD_UNKNOWN -1 91#define MAP_DPAD_UNKNOWN 2
91 92
92#define XTYPE_XBOX 0 93#define XTYPE_XBOX 0
93#define XTYPE_XBOX360 1 94#define XTYPE_XBOX360 1
95#define XTYPE_XBOX360W 2
96#define XTYPE_UNKNOWN 3
94 97
95static int dpad_to_buttons; 98static int dpad_to_buttons;
96module_param(dpad_to_buttons, bool, S_IRUGO); 99module_param(dpad_to_buttons, bool, S_IRUGO);
@@ -107,8 +110,10 @@ static const struct xpad_device {
107 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 110 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX },
108 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 111 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES, XTYPE_XBOX },
109 { 0x045e, 0x0287, "Microsoft Xbox Controller S", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 112 { 0x045e, 0x0287, "Microsoft Xbox Controller S", MAP_DPAD_TO_AXES, XTYPE_XBOX },
113 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
110 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 114 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
111 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 115 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
116 { 0x046d, 0xc242, "Logitech Chillstream Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
112 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 117 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
113 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 118 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", MAP_DPAD_TO_AXES, XTYPE_XBOX },
114 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 119 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", MAP_DPAD_TO_AXES, XTYPE_XBOX },
@@ -135,18 +140,26 @@ static const struct xpad_device {
135 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 140 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
136 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 141 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
137 { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 142 { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
143 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
138 { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 144 { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
139 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 145 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
140 { 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 146 { 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
141 { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_XBOX } 147 { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_UNKNOWN }
142}; 148};
143 149
144static const signed short xpad_btn[] = { 150/* buttons shared with xbox and xbox360 */
145 BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, /* "analog" buttons */ 151static const signed short xpad_common_btn[] = {
152 BTN_A, BTN_B, BTN_X, BTN_Y, /* "analog" buttons */
146 BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */ 153 BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */
147 -1 /* terminating entry */ 154 -1 /* terminating entry */
148}; 155};
149 156
157/* original xbox controllers only */
158static const signed short xpad_btn[] = {
159 BTN_C, BTN_Z, /* "analog" buttons */
160 -1 /* terminating entry */
161};
162
150/* only used if MAP_DPAD_TO_BUTTONS */ 163/* only used if MAP_DPAD_TO_BUTTONS */
151static const signed short xpad_btn_pad[] = { 164static const signed short xpad_btn_pad[] = {
152 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ 165 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */
@@ -173,12 +186,27 @@ static const signed short xpad_abs_pad[] = {
173 -1 /* terminating entry */ 186 -1 /* terminating entry */
174}; 187};
175 188
176/* Xbox 360 has a vendor-specific (sub)class, so we cannot match it with only 189/* Xbox 360 has a vendor-specific class, so we cannot match it with only
177 * USB_INTERFACE_INFO, more to that this device has 4 InterfaceProtocols, 190 * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
178 * but we need only one of them. */ 191 * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
192 * wireless controllers have protocol 129. */
193#define XPAD_XBOX360_VENDOR_PROTOCOL(vend,pr) \
194 .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
195 .idVendor = (vend), \
196 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
197 .bInterfaceSubClass = 93, \
198 .bInterfaceProtocol = (pr)
199#define XPAD_XBOX360_VENDOR(vend) \
200 { XPAD_XBOX360_VENDOR_PROTOCOL(vend,1) }, \
201 { XPAD_XBOX360_VENDOR_PROTOCOL(vend,129) }
202
179static struct usb_device_id xpad_table [] = { 203static struct usb_device_id xpad_table [] = {
180 { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */ 204 { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */
181 { USB_DEVICE_INTERFACE_PROTOCOL(0x045e, 0x028e, 1) }, /* X-Box 360 controller */ 205 XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */
206 XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */
207 XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */
208 XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */
209 XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */
182 { } 210 { }
183}; 211};
184 212
@@ -188,10 +216,15 @@ struct usb_xpad {
188 struct input_dev *dev; /* input device interface */ 216 struct input_dev *dev; /* input device interface */
189 struct usb_device *udev; /* usb device */ 217 struct usb_device *udev; /* usb device */
190 218
219 int pad_present;
220
191 struct urb *irq_in; /* urb for interrupt in report */ 221 struct urb *irq_in; /* urb for interrupt in report */
192 unsigned char *idata; /* input data */ 222 unsigned char *idata; /* input data */
193 dma_addr_t idata_dma; 223 dma_addr_t idata_dma;
194 224
225 struct urb *bulk_out;
226 unsigned char *bdata;
227
195#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS) 228#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
196 struct urb *irq_out; /* urb for interrupt out report */ 229 struct urb *irq_out; /* urb for interrupt out report */
197 unsigned char *odata; /* output data */ 230 unsigned char *odata; /* output data */
@@ -227,13 +260,13 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
227 input_report_abs(dev, ABS_X, 260 input_report_abs(dev, ABS_X,
228 (__s16) le16_to_cpup((__le16 *)(data + 12))); 261 (__s16) le16_to_cpup((__le16 *)(data + 12)));
229 input_report_abs(dev, ABS_Y, 262 input_report_abs(dev, ABS_Y,
230 (__s16) le16_to_cpup((__le16 *)(data + 14))); 263 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));
231 264
232 /* right stick */ 265 /* right stick */
233 input_report_abs(dev, ABS_RX, 266 input_report_abs(dev, ABS_RX,
234 (__s16) le16_to_cpup((__le16 *)(data + 16))); 267 (__s16) le16_to_cpup((__le16 *)(data + 16)));
235 input_report_abs(dev, ABS_RY, 268 input_report_abs(dev, ABS_RY,
236 (__s16) le16_to_cpup((__le16 *)(data + 18))); 269 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
237 270
238 /* triggers left/right */ 271 /* triggers left/right */
239 input_report_abs(dev, ABS_Z, data[10]); 272 input_report_abs(dev, ABS_Z, data[10]);
@@ -321,13 +354,13 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
321 input_report_abs(dev, ABS_X, 354 input_report_abs(dev, ABS_X,
322 (__s16) le16_to_cpup((__le16 *)(data + 6))); 355 (__s16) le16_to_cpup((__le16 *)(data + 6)));
323 input_report_abs(dev, ABS_Y, 356 input_report_abs(dev, ABS_Y,
324 (__s16) le16_to_cpup((__le16 *)(data + 8))); 357 ~(__s16) le16_to_cpup((__le16 *)(data + 8)));
325 358
326 /* right stick */ 359 /* right stick */
327 input_report_abs(dev, ABS_RX, 360 input_report_abs(dev, ABS_RX,
328 (__s16) le16_to_cpup((__le16 *)(data + 10))); 361 (__s16) le16_to_cpup((__le16 *)(data + 10)));
329 input_report_abs(dev, ABS_RY, 362 input_report_abs(dev, ABS_RY,
330 (__s16) le16_to_cpup((__le16 *)(data + 12))); 363 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
331 364
332 /* triggers left/right */ 365 /* triggers left/right */
333 input_report_abs(dev, ABS_Z, data[4]); 366 input_report_abs(dev, ABS_Z, data[4]);
@@ -336,6 +369,39 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
336 input_sync(dev); 369 input_sync(dev);
337} 370}
338 371
372/*
373 * xpad360w_process_packet
374 *
375 * Completes a request by converting the data into events for the
376 * input subsystem. It is version for xbox 360 wireless controller.
377 *
378 * Byte.Bit
379 * 00.1 - Status change: The controller or headset has connected/disconnected
380 * Bits 01.7 and 01.6 are valid
381 * 01.7 - Controller present
382 * 01.6 - Headset present
383 * 01.1 - Pad state (Bytes 4+) valid
384 *
385 */
386
387static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
388{
389 /* Presence change */
390 if (data[0] & 0x08) {
391 if (data[1] & 0x80) {
392 xpad->pad_present = 1;
393 usb_submit_urb(xpad->bulk_out, GFP_ATOMIC);
394 } else
395 xpad->pad_present = 0;
396 }
397
398 /* Valid pad data */
399 if (!(data[1] & 0x1))
400 return;
401
402 xpad360_process_packet(xpad, cmd, &data[4]);
403}
404
339static void xpad_irq_in(struct urb *urb) 405static void xpad_irq_in(struct urb *urb)
340{ 406{
341 struct usb_xpad *xpad = urb->context; 407 struct usb_xpad *xpad = urb->context;
@@ -360,10 +426,16 @@ static void xpad_irq_in(struct urb *urb)
360 goto exit; 426 goto exit;
361 } 427 }
362 428
363 if (xpad->xtype == XTYPE_XBOX360) 429 switch (xpad->xtype) {
430 case XTYPE_XBOX360:
364 xpad360_process_packet(xpad, 0, xpad->idata); 431 xpad360_process_packet(xpad, 0, xpad->idata);
365 else 432 break;
433 case XTYPE_XBOX360W:
434 xpad360w_process_packet(xpad, 0, xpad->idata);
435 break;
436 default:
366 xpad_process_packet(xpad, 0, xpad->idata); 437 xpad_process_packet(xpad, 0, xpad->idata);
438 }
367 439
368exit: 440exit:
369 retval = usb_submit_urb (urb, GFP_ATOMIC); 441 retval = usb_submit_urb (urb, GFP_ATOMIC);
@@ -403,6 +475,23 @@ exit:
403 __FUNCTION__, retval); 475 __FUNCTION__, retval);
404} 476}
405 477
478static void xpad_bulk_out(struct urb *urb)
479{
480 switch (urb->status) {
481 case 0:
482 /* success */
483 break;
484 case -ECONNRESET:
485 case -ENOENT:
486 case -ESHUTDOWN:
487 /* this urb is terminated, clean up */
488 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
489 break;
490 default:
491 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
492 }
493}
494
406static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) 495static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
407{ 496{
408 struct usb_endpoint_descriptor *ep_irq_out; 497 struct usb_endpoint_descriptor *ep_irq_out;
@@ -412,7 +501,7 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
412 return 0; 501 return 0;
413 502
414 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, 503 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN,
415 GFP_ATOMIC, &xpad->odata_dma ); 504 GFP_KERNEL, &xpad->odata_dma);
416 if (!xpad->odata) 505 if (!xpad->odata)
417 goto fail1; 506 goto fail1;
418 507
@@ -473,6 +562,7 @@ static int xpad_play_effect(struct input_dev *dev, void *data,
473 xpad->odata[5] = 0x00; 562 xpad->odata[5] = 0x00;
474 xpad->odata[6] = 0x00; 563 xpad->odata[6] = 0x00;
475 xpad->odata[7] = 0x00; 564 xpad->odata[7] = 0x00;
565 xpad->irq_out->transfer_buffer_length = 8;
476 usb_submit_urb(xpad->irq_out, GFP_KERNEL); 566 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
477 } 567 }
478 568
@@ -481,6 +571,9 @@ static int xpad_play_effect(struct input_dev *dev, void *data,
481 571
482static int xpad_init_ff(struct usb_xpad *xpad) 572static int xpad_init_ff(struct usb_xpad *xpad)
483{ 573{
574 if (xpad->xtype != XTYPE_XBOX360)
575 return 0;
576
484 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); 577 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
485 578
486 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); 579 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
@@ -506,6 +599,7 @@ static void xpad_send_led_command(struct usb_xpad *xpad, int command)
506 xpad->odata[0] = 0x01; 599 xpad->odata[0] = 0x01;
507 xpad->odata[1] = 0x03; 600 xpad->odata[1] = 0x03;
508 xpad->odata[2] = command; 601 xpad->odata[2] = command;
602 xpad->irq_out->transfer_buffer_length = 3;
509 usb_submit_urb(xpad->irq_out, GFP_KERNEL); 603 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
510 mutex_unlock(&xpad->odata_mutex); 604 mutex_unlock(&xpad->odata_mutex);
511 } 605 }
@@ -578,6 +672,10 @@ static int xpad_open(struct input_dev *dev)
578{ 672{
579 struct usb_xpad *xpad = input_get_drvdata(dev); 673 struct usb_xpad *xpad = input_get_drvdata(dev);
580 674
675 /* URB was submitted in probe */
676 if(xpad->xtype == XTYPE_XBOX360W)
677 return 0;
678
581 xpad->irq_in->dev = xpad->udev; 679 xpad->irq_in->dev = xpad->udev;
582 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) 680 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
583 return -EIO; 681 return -EIO;
@@ -589,7 +687,8 @@ static void xpad_close(struct input_dev *dev)
589{ 687{
590 struct usb_xpad *xpad = input_get_drvdata(dev); 688 struct usb_xpad *xpad = input_get_drvdata(dev);
591 689
592 usb_kill_urb(xpad->irq_in); 690 if(xpad->xtype != XTYPE_XBOX360W)
691 usb_kill_urb(xpad->irq_in);
593 xpad_stop_output(xpad); 692 xpad_stop_output(xpad);
594} 693}
595 694
@@ -636,7 +735,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
636 goto fail1; 735 goto fail1;
637 736
638 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 737 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
639 GFP_ATOMIC, &xpad->idata_dma); 738 GFP_KERNEL, &xpad->idata_dma);
640 if (!xpad->idata) 739 if (!xpad->idata)
641 goto fail1; 740 goto fail1;
642 741
@@ -648,7 +747,16 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
648 xpad->dpad_mapping = xpad_device[i].dpad_mapping; 747 xpad->dpad_mapping = xpad_device[i].dpad_mapping;
649 xpad->xtype = xpad_device[i].xtype; 748 xpad->xtype = xpad_device[i].xtype;
650 if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN) 749 if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN)
651 xpad->dpad_mapping = dpad_to_buttons; 750 xpad->dpad_mapping = !dpad_to_buttons;
751 if (xpad->xtype == XTYPE_UNKNOWN) {
752 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
753 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
754 xpad->xtype = XTYPE_XBOX360W;
755 else
756 xpad->xtype = XTYPE_XBOX360;
757 } else
758 xpad->xtype = XTYPE_XBOX;
759 }
652 xpad->dev = input_dev; 760 xpad->dev = input_dev;
653 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); 761 usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
654 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); 762 strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
@@ -666,11 +774,14 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
666 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 774 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
667 775
668 /* set up buttons */ 776 /* set up buttons */
669 for (i = 0; xpad_btn[i] >= 0; i++) 777 for (i = 0; xpad_common_btn[i] >= 0; i++)
670 set_bit(xpad_btn[i], input_dev->keybit); 778 set_bit(xpad_common_btn[i], input_dev->keybit);
671 if (xpad->xtype == XTYPE_XBOX360) 779 if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W))
672 for (i = 0; xpad360_btn[i] >= 0; i++) 780 for (i = 0; xpad360_btn[i] >= 0; i++)
673 set_bit(xpad360_btn[i], input_dev->keybit); 781 set_bit(xpad360_btn[i], input_dev->keybit);
782 else
783 for (i = 0; xpad_btn[i] >= 0; i++)
784 set_bit(xpad_btn[i], input_dev->keybit);
674 if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) 785 if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS)
675 for (i = 0; xpad_btn_pad[i] >= 0; i++) 786 for (i = 0; xpad_btn_pad[i] >= 0; i++)
676 set_bit(xpad_btn_pad[i], input_dev->keybit); 787 set_bit(xpad_btn_pad[i], input_dev->keybit);
@@ -707,8 +818,57 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
707 goto fail4; 818 goto fail4;
708 819
709 usb_set_intfdata(intf, xpad); 820 usb_set_intfdata(intf, xpad);
821
822 /*
823 * Submit the int URB immediatly rather than waiting for open
824 * because we get status messages from the device whether
825 * or not any controllers are attached. In fact, it's
826 * exactly the message that a controller has arrived that
827 * we're waiting for.
828 */
829 if (xpad->xtype == XTYPE_XBOX360W) {
830 xpad->irq_in->dev = xpad->udev;
831 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
832 if (error)
833 goto fail4;
834
835 /*
836 * Setup the message to set the LEDs on the
837 * controller when it shows up
838 */
839 xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
840 if(!xpad->bulk_out)
841 goto fail5;
842
843 xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
844 if(!xpad->bdata)
845 goto fail6;
846
847 xpad->bdata[2] = 0x08;
848 switch (intf->cur_altsetting->desc.bInterfaceNumber) {
849 case 0:
850 xpad->bdata[3] = 0x42;
851 break;
852 case 2:
853 xpad->bdata[3] = 0x43;
854 break;
855 case 4:
856 xpad->bdata[3] = 0x44;
857 break;
858 case 6:
859 xpad->bdata[3] = 0x45;
860 }
861
862 ep_irq_in = &intf->cur_altsetting->endpoint[1].desc;
863 usb_fill_bulk_urb(xpad->bulk_out, udev,
864 usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress),
865 xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad);
866 }
867
710 return 0; 868 return 0;
711 869
870 fail6: usb_free_urb(xpad->bulk_out);
871 fail5: usb_kill_urb(xpad->irq_in);
712 fail4: usb_free_urb(xpad->irq_in); 872 fail4: usb_free_urb(xpad->irq_in);
713 fail3: xpad_deinit_output(xpad); 873 fail3: xpad_deinit_output(xpad);
714 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 874 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
@@ -727,6 +887,11 @@ static void xpad_disconnect(struct usb_interface *intf)
727 xpad_led_disconnect(xpad); 887 xpad_led_disconnect(xpad);
728 input_unregister_device(xpad->dev); 888 input_unregister_device(xpad->dev);
729 xpad_deinit_output(xpad); 889 xpad_deinit_output(xpad);
890 if (xpad->xtype == XTYPE_XBOX360W) {
891 usb_kill_urb(xpad->bulk_out);
892 usb_free_urb(xpad->bulk_out);
893 usb_kill_urb(xpad->irq_in);
894 }
730 usb_free_urb(xpad->irq_in); 895 usb_free_urb(xpad->irq_in);
731 usb_buffer_free(xpad->udev, XPAD_PKT_LEN, 896 usb_buffer_free(xpad->udev, XPAD_PKT_LEN,
732 xpad->idata, xpad->idata_dma); 897 xpad->idata, xpad->idata_dma);
@@ -745,7 +910,7 @@ static int __init usb_xpad_init(void)
745{ 910{
746 int result = usb_register(&xpad_driver); 911 int result = usb_register(&xpad_driver);
747 if (result == 0) 912 if (result == 0)
748 info(DRIVER_DESC ":" DRIVER_VERSION); 913 info(DRIVER_DESC);
749 return result; 914 return result;
750} 915}
751 916
diff --git a/drivers/input/joystick/zhenhua.c b/drivers/input/joystick/zhenhua.c
new file mode 100644
index 000000000000..b5853125c898
--- /dev/null
+++ b/drivers/input/joystick/zhenhua.c
@@ -0,0 +1,243 @@
1/*
2 * derived from "twidjoy.c"
3 *
4 * Copyright (c) 2008 Martin Kebert
5 * Copyright (c) 2001 Arndt Schoenewald
6 * Copyright (c) 2000-2001 Vojtech Pavlik
7 * Copyright (c) 2000 Mark Fletcher
8 *
9 */
10
11/*
12 * Driver to use 4CH RC transmitter using Zhen Hua 5-byte protocol (Walkera Lama,
13 * EasyCopter etc.) as a joystick under Linux.
14 *
15 * RC transmitters using Zhen Hua 5-byte protocol are cheap four channels
16 * transmitters for control a RC planes or RC helicopters with possibility to
17 * connect on a serial port.
18 * Data coming from transmitter is in this order:
19 * 1. byte = synchronisation byte
20 * 2. byte = X axis
21 * 3. byte = Y axis
22 * 4. byte = RZ axis
23 * 5. byte = Z axis
24 * (and this is repeated)
25 *
26 * For questions or feedback regarding this driver module please contact:
27 * Martin Kebert <gkmarty@gmail.com> - but I am not a C-programmer nor kernel
28 * coder :-(
29 */
30
31/*
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
36 *
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
41 *
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45 */
46
47#include <linux/kernel.h>
48#include <linux/module.h>
49#include <linux/slab.h>
50#include <linux/input.h>
51#include <linux/serio.h>
52#include <linux/init.h>
53
54#define DRIVER_DESC "RC transmitter with 5-byte Zhen Hua protocol joystick driver"
55
56MODULE_DESCRIPTION(DRIVER_DESC);
57MODULE_LICENSE("GPL");
58
59/*
60 * Constants.
61 */
62
63#define ZHENHUA_MAX_LENGTH 5
64
65/*
66 * Zhen Hua data.
67 */
68
69struct zhenhua {
70 struct input_dev *dev;
71 int idx;
72 unsigned char data[ZHENHUA_MAX_LENGTH];
73 char phys[32];
74};
75
76
77/* bits in all incoming bytes needs to be "reversed" */
78static int zhenhua_bitreverse(int x)
79{
80 x = ((x & 0xaa) >> 1) | ((x & 0x55) << 1);
81 x = ((x & 0xcc) >> 2) | ((x & 0x33) << 2);
82 x = ((x & 0xf0) >> 4) | ((x & 0x0f) << 4);
83 return x;
84}
85
86/*
87 * zhenhua_process_packet() decodes packets the driver receives from the
88 * RC transmitter. It updates the data accordingly.
89 */
90
91static void zhenhua_process_packet(struct zhenhua *zhenhua)
92{
93 struct input_dev *dev = zhenhua->dev;
94 unsigned char *data = zhenhua->data;
95
96 input_report_abs(dev, ABS_Y, data[1]);
97 input_report_abs(dev, ABS_X, data[2]);
98 input_report_abs(dev, ABS_RZ, data[3]);
99 input_report_abs(dev, ABS_Z, data[4]);
100
101 input_sync(dev);
102}
103
104/*
105 * zhenhua_interrupt() is called by the low level driver when characters
106 * are ready for us. We then buffer them for further processing, or call the
107 * packet processing routine.
108 */
109
110static irqreturn_t zhenhua_interrupt(struct serio *serio, unsigned char data, unsigned int flags)
111{
112 struct zhenhua *zhenhua = serio_get_drvdata(serio);
113
114 /* All Zhen Hua packets are 5 bytes. The fact that the first byte
115 * is allways 0xf7 and all others are in range 0x32 - 0xc8 (50-200)
116 * can be used to check and regain sync. */
117
118 if (data == 0xef)
119 zhenhua->idx = 0; /* this byte starts a new packet */
120 else if (zhenhua->idx == 0)
121 return IRQ_HANDLED; /* wrong MSB -- ignore this byte */
122
123 if (zhenhua->idx < ZHENHUA_MAX_LENGTH)
124 zhenhua->data[zhenhua->idx++] = zhenhua_bitreverse(data);
125
126 if (zhenhua->idx == ZHENHUA_MAX_LENGTH) {
127 zhenhua_process_packet(zhenhua);
128 zhenhua->idx = 0;
129 }
130
131 return IRQ_HANDLED;
132}
133
134/*
135 * zhenhua_disconnect() is the opposite of zhenhua_connect()
136 */
137
138static void zhenhua_disconnect(struct serio *serio)
139{
140 struct zhenhua *zhenhua = serio_get_drvdata(serio);
141
142 serio_close(serio);
143 serio_set_drvdata(serio, NULL);
144 input_unregister_device(zhenhua->dev);
145 kfree(zhenhua);
146}
147
148/*
149 * zhenhua_connect() is the routine that is called when someone adds a
150 * new serio device. It looks for the Twiddler, and if found, registers
151 * it as an input device.
152 */
153
154static int zhenhua_connect(struct serio *serio, struct serio_driver *drv)
155{
156 struct zhenhua *zhenhua;
157 struct input_dev *input_dev;
158 int err = -ENOMEM;
159
160 zhenhua = kzalloc(sizeof(struct zhenhua), GFP_KERNEL);
161 input_dev = input_allocate_device();
162 if (!zhenhua || !input_dev)
163 goto fail1;
164
165 zhenhua->dev = input_dev;
166 snprintf(zhenhua->phys, sizeof(zhenhua->phys), "%s/input0", serio->phys);
167
168 input_dev->name = "Zhen Hua 5-byte device";
169 input_dev->phys = zhenhua->phys;
170 input_dev->id.bustype = BUS_RS232;
171 input_dev->id.vendor = SERIO_ZHENHUA;
172 input_dev->id.product = 0x0001;
173 input_dev->id.version = 0x0100;
174 input_dev->dev.parent = &serio->dev;
175
176 input_dev->evbit[0] = BIT(EV_ABS);
177 input_set_abs_params(input_dev, ABS_X, 50, 200, 0, 0);
178 input_set_abs_params(input_dev, ABS_Y, 50, 200, 0, 0);
179 input_set_abs_params(input_dev, ABS_Z, 50, 200, 0, 0);
180 input_set_abs_params(input_dev, ABS_RZ, 50, 200, 0, 0);
181
182 serio_set_drvdata(serio, zhenhua);
183
184 err = serio_open(serio, drv);
185 if (err)
186 goto fail2;
187
188 err = input_register_device(zhenhua->dev);
189 if (err)
190 goto fail3;
191
192 return 0;
193
194 fail3: serio_close(serio);
195 fail2: serio_set_drvdata(serio, NULL);
196 fail1: input_free_device(input_dev);
197 kfree(zhenhua);
198 return err;
199}
200
201/*
202 * The serio driver structure.
203 */
204
205static struct serio_device_id zhenhua_serio_ids[] = {
206 {
207 .type = SERIO_RS232,
208 .proto = SERIO_ZHENHUA,
209 .id = SERIO_ANY,
210 .extra = SERIO_ANY,
211 },
212 { 0 }
213};
214
215MODULE_DEVICE_TABLE(serio, zhenhua_serio_ids);
216
217static struct serio_driver zhenhua_drv = {
218 .driver = {
219 .name = "zhenhua",
220 },
221 .description = DRIVER_DESC,
222 .id_table = zhenhua_serio_ids,
223 .interrupt = zhenhua_interrupt,
224 .connect = zhenhua_connect,
225 .disconnect = zhenhua_disconnect,
226};
227
228/*
229 * The functions for inserting/removing us as a module.
230 */
231
232static int __init zhenhua_init(void)
233{
234 return serio_register_driver(&zhenhua_drv);
235}
236
237static void __exit zhenhua_exit(void)
238{
239 serio_unregister_driver(&zhenhua_drv);
240}
241
242module_init(zhenhua_init);
243module_exit(zhenhua_exit);
diff --git a/drivers/input/keyboard/aaed2000_kbd.c b/drivers/input/keyboard/aaed2000_kbd.c
index 72abc196ce66..a293e8b3f508 100644
--- a/drivers/input/keyboard/aaed2000_kbd.c
+++ b/drivers/input/keyboard/aaed2000_kbd.c
@@ -156,11 +156,15 @@ static int __devexit aaedkbd_remove(struct platform_device *pdev)
156 return 0; 156 return 0;
157} 157}
158 158
159/* work with hotplug and coldplug */
160MODULE_ALIAS("platform:aaed2000-keyboard");
161
159static struct platform_driver aaedkbd_driver = { 162static struct platform_driver aaedkbd_driver = {
160 .probe = aaedkbd_probe, 163 .probe = aaedkbd_probe,
161 .remove = __devexit_p(aaedkbd_remove), 164 .remove = __devexit_p(aaedkbd_remove),
162 .driver = { 165 .driver = {
163 .name = "aaed2000-keyboard", 166 .name = "aaed2000-keyboard",
167 .owner = THIS_MODULE,
164 }, 168 },
165}; 169};
166 170
diff --git a/drivers/input/keyboard/bf54x-keys.c b/drivers/input/keyboard/bf54x-keys.c
index 05e3494cf8b8..54ed8e2e1c02 100644
--- a/drivers/input/keyboard/bf54x-keys.c
+++ b/drivers/input/keyboard/bf54x-keys.c
@@ -312,6 +312,8 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
312 312
313 bfin_write_KPAD_CTL(bfin_read_KPAD_CTL() | KPAD_EN); 313 bfin_write_KPAD_CTL(bfin_read_KPAD_CTL() | KPAD_EN);
314 314
315 device_init_wakeup(&pdev->dev, 1);
316
315 printk(KERN_ERR DRV_NAME 317 printk(KERN_ERR DRV_NAME
316 ": Blackfin BF54x Keypad registered IRQ %d\n", bf54x_kpad->irq); 318 ": Blackfin BF54x Keypad registered IRQ %d\n", bf54x_kpad->irq);
317 319
@@ -354,12 +356,40 @@ static int __devexit bfin_kpad_remove(struct platform_device *pdev)
354 return 0; 356 return 0;
355} 357}
356 358
359#ifdef CONFIG_PM
360static int bfin_kpad_suspend(struct platform_device *pdev, pm_message_t state)
361{
362 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
363
364 if (device_may_wakeup(&pdev->dev))
365 enable_irq_wake(bf54x_kpad->irq);
366
367 return 0;
368}
369
370static int bfin_kpad_resume(struct platform_device *pdev)
371{
372 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
373
374 if (device_may_wakeup(&pdev->dev))
375 disable_irq_wake(bf54x_kpad->irq);
376
377 return 0;
378}
379#else
380# define bfin_kpad_suspend NULL
381# define bfin_kpad_resume NULL
382#endif
383
357struct platform_driver bfin_kpad_device_driver = { 384struct platform_driver bfin_kpad_device_driver = {
358 .probe = bfin_kpad_probe,
359 .remove = __devexit_p(bfin_kpad_remove),
360 .driver = { 385 .driver = {
361 .name = DRV_NAME, 386 .name = DRV_NAME,
362 } 387 .owner = THIS_MODULE,
388 },
389 .probe = bfin_kpad_probe,
390 .remove = __devexit_p(bfin_kpad_remove),
391 .suspend = bfin_kpad_suspend,
392 .resume = bfin_kpad_resume,
363}; 393};
364 394
365static int __init bfin_kpad_init(void) 395static int __init bfin_kpad_init(void)
@@ -378,3 +408,4 @@ module_exit(bfin_kpad_exit);
378MODULE_LICENSE("GPL"); 408MODULE_LICENSE("GPL");
379MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 409MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
380MODULE_DESCRIPTION("Keypad driver for BF54x Processors"); 410MODULE_DESCRIPTION("Keypad driver for BF54x Processors");
411MODULE_ALIAS("platform:bf54x-keys");
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index 5d6cc7f1dc94..29fbec6218b9 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -393,6 +393,7 @@ static struct platform_driver corgikbd_driver = {
393 .resume = corgikbd_resume, 393 .resume = corgikbd_resume,
394 .driver = { 394 .driver = {
395 .name = "corgi-keyboard", 395 .name = "corgi-keyboard",
396 .owner = THIS_MODULE,
396 }, 397 },
397}; 398};
398 399
@@ -412,3 +413,4 @@ module_exit(corgikbd_exit);
412MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); 413MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
413MODULE_DESCRIPTION("Corgi Keyboard Driver"); 414MODULE_DESCRIPTION("Corgi Keyboard Driver");
414MODULE_LICENSE("GPLv2"); 415MODULE_LICENSE("GPLv2");
416MODULE_ALIAS("platform:corgi-keyboard");
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 6a9ca4bdcb74..bbd00c3fe98c 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -43,10 +43,11 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
43 43
44 input_event(input, type, button->code, !!state); 44 input_event(input, type, button->code, !!state);
45 input_sync(input); 45 input_sync(input);
46 return IRQ_HANDLED;
46 } 47 }
47 } 48 }
48 49
49 return IRQ_HANDLED; 50 return IRQ_NONE;
50} 51}
51 52
52static int __devinit gpio_keys_probe(struct platform_device *pdev) 53static int __devinit gpio_keys_probe(struct platform_device *pdev)
@@ -213,6 +214,7 @@ struct platform_driver gpio_keys_device_driver = {
213 .resume = gpio_keys_resume, 214 .resume = gpio_keys_resume,
214 .driver = { 215 .driver = {
215 .name = "gpio-keys", 216 .name = "gpio-keys",
217 .owner = THIS_MODULE,
216 } 218 }
217}; 219};
218 220
@@ -232,3 +234,4 @@ module_exit(gpio_keys_exit);
232MODULE_LICENSE("GPL"); 234MODULE_LICENSE("GPL");
233MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>"); 235MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>");
234MODULE_DESCRIPTION("Keyboard driver for CPU GPIOs"); 236MODULE_DESCRIPTION("Keyboard driver for CPU GPIOs");
237MODULE_ALIAS("platform:gpio-keys");
diff --git a/drivers/input/keyboard/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c
index a23633a2e1b4..9387da343f97 100644
--- a/drivers/input/keyboard/jornada680_kbd.c
+++ b/drivers/input/keyboard/jornada680_kbd.c
@@ -254,6 +254,7 @@ static int __devexit jornada680kbd_remove(struct platform_device *pdev)
254static struct platform_driver jornada680kbd_driver = { 254static struct platform_driver jornada680kbd_driver = {
255 .driver = { 255 .driver = {
256 .name = "jornada680_kbd", 256 .name = "jornada680_kbd",
257 .owner = THIS_MODULE,
257 }, 258 },
258 .probe = jornada680kbd_probe, 259 .probe = jornada680kbd_probe,
259 .remove = __devexit_p(jornada680kbd_remove), 260 .remove = __devexit_p(jornada680kbd_remove),
@@ -275,3 +276,4 @@ module_exit(jornada680kbd_exit);
275MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>"); 276MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
276MODULE_DESCRIPTION("HP Jornada 620/660/680/690 Keyboard Driver"); 277MODULE_DESCRIPTION("HP Jornada 620/660/680/690 Keyboard Driver");
277MODULE_LICENSE("GPLv2"); 278MODULE_LICENSE("GPLv2");
279MODULE_ALIAS("platform:jornada680_kbd");
diff --git a/drivers/input/keyboard/jornada720_kbd.c b/drivers/input/keyboard/jornada720_kbd.c
index 986f93cfc6b8..a1164a0c7736 100644
--- a/drivers/input/keyboard/jornada720_kbd.c
+++ b/drivers/input/keyboard/jornada720_kbd.c
@@ -162,9 +162,13 @@ static int __devexit jornada720_kbd_remove(struct platform_device *pdev)
162 return 0; 162 return 0;
163} 163}
164 164
165/* work with hotplug and coldplug */
166MODULE_ALIAS("platform:jornada720_kbd");
167
165static struct platform_driver jornada720_kbd_driver = { 168static struct platform_driver jornada720_kbd_driver = {
166 .driver = { 169 .driver = {
167 .name = "jornada720_kbd", 170 .name = "jornada720_kbd",
171 .owner = THIS_MODULE,
168 }, 172 },
169 .probe = jornada720_kbd_probe, 173 .probe = jornada720_kbd_probe,
170 .remove = __devexit_p(jornada720_kbd_remove), 174 .remove = __devexit_p(jornada720_kbd_remove),
diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c
index 5a0ca18d6755..9caed30f3bbb 100644
--- a/drivers/input/keyboard/locomokbd.c
+++ b/drivers/input/keyboard/locomokbd.c
@@ -1,14 +1,12 @@
1/* 1/*
2 * Copyright (c) 2005 John Lenz 2 * LoCoMo keyboard driver for Linux-based ARM PDAs:
3 * - SHARP Zaurus Collie (SL-5500)
4 * - SHARP Zaurus Poodle (SL-5600)
3 * 5 *
6 * Copyright (c) 2005 John Lenz
4 * Based on from xtkbd.c 7 * Based on from xtkbd.c
5 */ 8 *
6 9 *
7/*
8 * LoCoMo keyboard driver for Linux/ARM
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
@@ -47,7 +45,8 @@ MODULE_LICENSE("GPL");
47#define KEY_CONTACT KEY_F18 45#define KEY_CONTACT KEY_F18
48#define KEY_CENTER KEY_F15 46#define KEY_CENTER KEY_F15
49 47
50static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { 48static const unsigned char
49locomokbd_keycode[LOCOMOKBD_NUMKEYS] __devinitconst = {
51 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */ 50 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */
52 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */ 51 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */ 52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */
@@ -67,22 +66,21 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
67#define KB_COLS 8 66#define KB_COLS 8
68#define KB_ROWMASK(r) (1 << (r)) 67#define KB_ROWMASK(r) (1 << (r))
69#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 ) 68#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
70#define NR_SCANCODES 128
71 69
72#define KB_DELAY 8 70#define KB_DELAY 8
73#define SCAN_INTERVAL (HZ/10) 71#define SCAN_INTERVAL (HZ/10)
74#define LOCOMOKBD_PRESSED 1
75 72
76struct locomokbd { 73struct locomokbd {
77 unsigned char keycode[LOCOMOKBD_NUMKEYS]; 74 unsigned char keycode[LOCOMOKBD_NUMKEYS];
78 struct input_dev *input; 75 struct input_dev *input;
79 char phys[32]; 76 char phys[32];
80 77
81 struct locomo_dev *ldev;
82 unsigned long base; 78 unsigned long base;
83 spinlock_t lock; 79 spinlock_t lock;
84 80
85 struct timer_list timer; 81 struct timer_list timer;
82 unsigned long suspend_jiffies;
83 unsigned int count_cancel;
86}; 84};
87 85
88/* helper functions for reading the keyboard matrix */ 86/* helper functions for reading the keyboard matrix */
@@ -128,7 +126,7 @@ static inline void locomokbd_reset_col(unsigned long membase, int col)
128/* Scan the hardware keyboard and push any changes up through the input layer */ 126/* Scan the hardware keyboard and push any changes up through the input layer */
129static void locomokbd_scankeyboard(struct locomokbd *locomokbd) 127static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
130{ 128{
131 unsigned int row, col, rowd, scancode; 129 unsigned int row, col, rowd;
132 unsigned long flags; 130 unsigned long flags;
133 unsigned int num_pressed; 131 unsigned int num_pressed;
134 unsigned long membase = locomokbd->base; 132 unsigned long membase = locomokbd->base;
@@ -145,13 +143,33 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
145 143
146 rowd = ~locomo_readl(membase + LOCOMO_KIB); 144 rowd = ~locomo_readl(membase + LOCOMO_KIB);
147 for (row = 0; row < KB_ROWS; row++) { 145 for (row = 0; row < KB_ROWS; row++) {
146 unsigned int scancode, pressed, key;
147
148 scancode = SCANCODE(col, row); 148 scancode = SCANCODE(col, row);
149 if (rowd & KB_ROWMASK(row)) { 149 pressed = rowd & KB_ROWMASK(row);
150 num_pressed += 1; 150 key = locomokbd->keycode[scancode];
151 input_report_key(locomokbd->input, locomokbd->keycode[scancode], 1); 151
152 } else { 152 input_report_key(locomokbd->input, key, pressed);
153 input_report_key(locomokbd->input, locomokbd->keycode[scancode], 0); 153 if (likely(!pressed))
154 } 154 continue;
155
156 num_pressed++;
157
158 /* The "Cancel/ESC" key is labeled "On/Off" on
159 * Collie and Poodle and should suspend the device
160 * if it was pressed for more than a second. */
161 if (unlikely(key == KEY_ESC)) {
162 if (!time_after(jiffies,
163 locomokbd->suspend_jiffies + HZ))
164 continue;
165 if (locomokbd->count_cancel++
166 != (HZ/SCAN_INTERVAL + 1))
167 continue;
168 input_event(locomokbd->input, EV_PWR,
169 KEY_SUSPEND, 1);
170 locomokbd->suspend_jiffies = jiffies;
171 } else
172 locomokbd->count_cancel = 0;
155 } 173 }
156 locomokbd_reset_col(membase, col); 174 locomokbd_reset_col(membase, col);
157 } 175 }
@@ -162,6 +180,8 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
162 /* if any keys are pressed, enable the timer */ 180 /* if any keys are pressed, enable the timer */
163 if (num_pressed) 181 if (num_pressed)
164 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL); 182 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
183 else
184 locomokbd->count_cancel = 0;
165 185
166 spin_unlock_irqrestore(&locomokbd->lock, flags); 186 spin_unlock_irqrestore(&locomokbd->lock, flags);
167} 187}
@@ -186,10 +206,11 @@ static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
186static void locomokbd_timer_callback(unsigned long data) 206static void locomokbd_timer_callback(unsigned long data)
187{ 207{
188 struct locomokbd *locomokbd = (struct locomokbd *) data; 208 struct locomokbd *locomokbd = (struct locomokbd *) data;
209
189 locomokbd_scankeyboard(locomokbd); 210 locomokbd_scankeyboard(locomokbd);
190} 211}
191 212
192static int locomokbd_probe(struct locomo_dev *dev) 213static int __devinit locomokbd_probe(struct locomo_dev *dev)
193{ 214{
194 struct locomokbd *locomokbd; 215 struct locomokbd *locomokbd;
195 struct input_dev *input_dev; 216 struct input_dev *input_dev;
@@ -211,7 +232,6 @@ static int locomokbd_probe(struct locomo_dev *dev)
211 goto err_free_mem; 232 goto err_free_mem;
212 } 233 }
213 234
214 locomokbd->ldev = dev;
215 locomo_set_drvdata(dev, locomokbd); 235 locomo_set_drvdata(dev, locomokbd);
216 236
217 locomokbd->base = (unsigned long) dev->mapbase; 237 locomokbd->base = (unsigned long) dev->mapbase;
@@ -222,6 +242,8 @@ static int locomokbd_probe(struct locomo_dev *dev)
222 locomokbd->timer.function = locomokbd_timer_callback; 242 locomokbd->timer.function = locomokbd_timer_callback;
223 locomokbd->timer.data = (unsigned long) locomokbd; 243 locomokbd->timer.data = (unsigned long) locomokbd;
224 244
245 locomokbd->suspend_jiffies = jiffies;
246
225 locomokbd->input = input_dev; 247 locomokbd->input = input_dev;
226 strcpy(locomokbd->phys, "locomokbd/input0"); 248 strcpy(locomokbd->phys, "locomokbd/input0");
227 249
@@ -233,9 +255,10 @@ static int locomokbd_probe(struct locomo_dev *dev)
233 input_dev->id.version = 0x0100; 255 input_dev->id.version = 0x0100;
234 input_dev->dev.parent = &dev->dev; 256 input_dev->dev.parent = &dev->dev;
235 257
236 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); 258 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
259 BIT_MASK(EV_PWR);
237 input_dev->keycode = locomokbd->keycode; 260 input_dev->keycode = locomokbd->keycode;
238 input_dev->keycodesize = sizeof(unsigned char); 261 input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
239 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode); 262 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
240 263
241 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); 264 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
@@ -268,7 +291,7 @@ static int locomokbd_probe(struct locomo_dev *dev)
268 return err; 291 return err;
269} 292}
270 293
271static int locomokbd_remove(struct locomo_dev *dev) 294static int __devexit locomokbd_remove(struct locomo_dev *dev)
272{ 295{
273 struct locomokbd *locomokbd = locomo_get_drvdata(dev); 296 struct locomokbd *locomokbd = locomo_get_drvdata(dev);
274 297
@@ -292,7 +315,7 @@ static struct locomo_driver keyboard_driver = {
292 }, 315 },
293 .devid = LOCOMO_DEVID_KEYBOARD, 316 .devid = LOCOMO_DEVID_KEYBOARD,
294 .probe = locomokbd_probe, 317 .probe = locomokbd_probe,
295 .remove = locomokbd_remove, 318 .remove = __devexit_p(locomokbd_remove),
296}; 319};
297 320
298static int __init locomokbd_init(void) 321static int __init locomokbd_init(void)
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c
index babc913d5492..10afd2068068 100644
--- a/drivers/input/keyboard/omap-keypad.c
+++ b/drivers/input/keyboard/omap-keypad.c
@@ -352,6 +352,9 @@ static int __init omap_kp_probe(struct platform_device *pdev)
352 } 352 }
353 omap_set_gpio_direction(row_gpios[row_idx], 1); 353 omap_set_gpio_direction(row_gpios[row_idx], 1);
354 } 354 }
355 } else {
356 col_idx = 0;
357 row_idx = 0;
355 } 358 }
356 359
357 setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp); 360 setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp);
@@ -415,10 +418,10 @@ err4:
415err3: 418err3:
416 device_remove_file(&pdev->dev, &dev_attr_enable); 419 device_remove_file(&pdev->dev, &dev_attr_enable);
417err2: 420err2:
418 for (i = row_idx-1; i >=0; i--) 421 for (i = row_idx - 1; i >=0; i--)
419 omap_free_gpio(row_gpios[i]); 422 omap_free_gpio(row_gpios[i]);
420err1: 423err1:
421 for (i = col_idx-1; i >=0; i--) 424 for (i = col_idx - 1; i >=0; i--)
422 omap_free_gpio(col_gpios[i]); 425 omap_free_gpio(col_gpios[i]);
423 426
424 kfree(omap_kp); 427 kfree(omap_kp);
@@ -464,6 +467,7 @@ static struct platform_driver omap_kp_driver = {
464 .resume = omap_kp_resume, 467 .resume = omap_kp_resume,
465 .driver = { 468 .driver = {
466 .name = "omap-keypad", 469 .name = "omap-keypad",
470 .owner = THIS_MODULE,
467 }, 471 },
468}; 472};
469 473
@@ -484,3 +488,4 @@ module_exit(omap_kp_exit);
484MODULE_AUTHOR("Timo Teräs"); 488MODULE_AUTHOR("Timo Teräs");
485MODULE_DESCRIPTION("OMAP Keypad Driver"); 489MODULE_DESCRIPTION("OMAP Keypad Driver");
486MODULE_LICENSE("GPL"); 490MODULE_LICENSE("GPL");
491MODULE_ALIAS("platform:omap-keypad");
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index 4e651c11c1da..3dea0c5077a9 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -545,6 +545,9 @@ static int __devexit pxa27x_keypad_remove(struct platform_device *pdev)
545 return 0; 545 return 0;
546} 546}
547 547
548/* work with hotplug and coldplug */
549MODULE_ALIAS("platform:pxa27x-keypad");
550
548static struct platform_driver pxa27x_keypad_driver = { 551static struct platform_driver pxa27x_keypad_driver = {
549 .probe = pxa27x_keypad_probe, 552 .probe = pxa27x_keypad_probe,
550 .remove = __devexit_p(pxa27x_keypad_remove), 553 .remove = __devexit_p(pxa27x_keypad_remove),
@@ -552,6 +555,7 @@ static struct platform_driver pxa27x_keypad_driver = {
552 .resume = pxa27x_keypad_resume, 555 .resume = pxa27x_keypad_resume,
553 .driver = { 556 .driver = {
554 .name = "pxa27x-keypad", 557 .name = "pxa27x-keypad",
558 .owner = THIS_MODULE,
555 }, 559 },
556}; 560};
557 561
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 0be74bfc58fe..61e401bc9109 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -495,3 +495,4 @@ module_exit(spitzkbd_exit);
495MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); 495MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
496MODULE_DESCRIPTION("Spitz Keyboard Driver"); 496MODULE_DESCRIPTION("Spitz Keyboard Driver");
497MODULE_LICENSE("GPLv2"); 497MODULE_LICENSE("GPLv2");
498MODULE_ALIAS("platform:spitz-keyboard");
diff --git a/drivers/input/keyboard/tosakbd.c b/drivers/input/keyboard/tosakbd.c
index 3884d1e3f070..94e444b4ee15 100644
--- a/drivers/input/keyboard/tosakbd.c
+++ b/drivers/input/keyboard/tosakbd.c
@@ -52,7 +52,7 @@ KEY_X, KEY_F, KEY_SPACE, KEY_APOSTROPHE, TOSA_KEY_MAIL, KEY_LEFT, KEY_DOWN, KEY_
52struct tosakbd { 52struct tosakbd {
53 unsigned int keycode[ARRAY_SIZE(tosakbd_keycode)]; 53 unsigned int keycode[ARRAY_SIZE(tosakbd_keycode)];
54 struct input_dev *input; 54 struct input_dev *input;
55 55 int suspended;
56 spinlock_t lock; /* protect kbd scanning */ 56 spinlock_t lock; /* protect kbd scanning */
57 struct timer_list timer; 57 struct timer_list timer;
58}; 58};
@@ -133,6 +133,9 @@ static void tosakbd_scankeyboard(struct platform_device *dev)
133 133
134 spin_lock_irqsave(&tosakbd->lock, flags); 134 spin_lock_irqsave(&tosakbd->lock, flags);
135 135
136 if (tosakbd->suspended)
137 goto out;
138
136 for (col = 0; col < TOSA_KEY_STROBE_NUM; col++) { 139 for (col = 0; col < TOSA_KEY_STROBE_NUM; col++) {
137 /* 140 /*
138 * Discharge the output driver capacitatance 141 * Discharge the output driver capacitatance
@@ -174,6 +177,7 @@ static void tosakbd_scankeyboard(struct platform_device *dev)
174 if (num_pressed) 177 if (num_pressed)
175 mod_timer(&tosakbd->timer, jiffies + SCAN_INTERVAL); 178 mod_timer(&tosakbd->timer, jiffies + SCAN_INTERVAL);
176 179
180 out:
177 spin_unlock_irqrestore(&tosakbd->lock, flags); 181 spin_unlock_irqrestore(&tosakbd->lock, flags);
178} 182}
179 183
@@ -200,6 +204,7 @@ static irqreturn_t tosakbd_interrupt(int irq, void *__dev)
200static void tosakbd_timer_callback(unsigned long __dev) 204static void tosakbd_timer_callback(unsigned long __dev)
201{ 205{
202 struct platform_device *dev = (struct platform_device *)__dev; 206 struct platform_device *dev = (struct platform_device *)__dev;
207
203 tosakbd_scankeyboard(dev); 208 tosakbd_scankeyboard(dev);
204} 209}
205 210
@@ -207,6 +212,13 @@ static void tosakbd_timer_callback(unsigned long __dev)
207static int tosakbd_suspend(struct platform_device *dev, pm_message_t state) 212static int tosakbd_suspend(struct platform_device *dev, pm_message_t state)
208{ 213{
209 struct tosakbd *tosakbd = platform_get_drvdata(dev); 214 struct tosakbd *tosakbd = platform_get_drvdata(dev);
215 unsigned long flags;
216
217 spin_lock_irqsave(&tosakbd->lock, flags);
218 PGSR1 = (PGSR1 & ~TOSA_GPIO_LOW_STROBE_BIT);
219 PGSR2 = (PGSR2 & ~TOSA_GPIO_HIGH_STROBE_BIT);
220 tosakbd->suspended = 1;
221 spin_unlock_irqrestore(&tosakbd->lock, flags);
210 222
211 del_timer_sync(&tosakbd->timer); 223 del_timer_sync(&tosakbd->timer);
212 224
@@ -215,6 +227,9 @@ static int tosakbd_suspend(struct platform_device *dev, pm_message_t state)
215 227
216static int tosakbd_resume(struct platform_device *dev) 228static int tosakbd_resume(struct platform_device *dev)
217{ 229{
230 struct tosakbd *tosakbd = platform_get_drvdata(dev);
231
232 tosakbd->suspended = 0;
218 tosakbd_scankeyboard(dev); 233 tosakbd_scankeyboard(dev);
219 234
220 return 0; 235 return 0;
@@ -365,8 +380,8 @@ fail:
365 return error; 380 return error;
366} 381}
367 382
368static int __devexit tosakbd_remove(struct platform_device *dev) { 383static int __devexit tosakbd_remove(struct platform_device *dev)
369 384{
370 int i; 385 int i;
371 struct tosakbd *tosakbd = platform_get_drvdata(dev); 386 struct tosakbd *tosakbd = platform_get_drvdata(dev);
372 387
@@ -394,6 +409,7 @@ static struct platform_driver tosakbd_driver = {
394 .resume = tosakbd_resume, 409 .resume = tosakbd_resume,
395 .driver = { 410 .driver = {
396 .name = "tosa-keyboard", 411 .name = "tosa-keyboard",
412 .owner = THIS_MODULE,
397 }, 413 },
398}; 414};
399 415
@@ -413,3 +429,4 @@ module_exit(tosakbd_exit);
413MODULE_AUTHOR("Dirk Opfer <Dirk@Opfer-Online.de>"); 429MODULE_AUTHOR("Dirk Opfer <Dirk@Opfer-Online.de>");
414MODULE_DESCRIPTION("Tosa Keyboard Driver"); 430MODULE_DESCRIPTION("Tosa Keyboard Driver");
415MODULE_LICENSE("GPL v2"); 431MODULE_LICENSE("GPL v2");
432MODULE_ALIAS("platform:tosa-keyboard");
diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c
index 5511ef006a66..6a1f48b76e32 100644
--- a/drivers/input/misc/cobalt_btns.c
+++ b/drivers/input/misc/cobalt_btns.c
@@ -148,6 +148,9 @@ static int __devexit cobalt_buttons_remove(struct platform_device *pdev)
148 return 0; 148 return 0;
149} 149}
150 150
151/* work with hotplug and coldplug */
152MODULE_ALIAS("platform:Cobalt buttons");
153
151static struct platform_driver cobalt_buttons_driver = { 154static struct platform_driver cobalt_buttons_driver = {
152 .probe = cobalt_buttons_probe, 155 .probe = cobalt_buttons_probe,
153 .remove = __devexit_p(cobalt_buttons_remove), 156 .remove = __devexit_p(cobalt_buttons_remove),
diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index 0936d6ba015c..339290184871 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -171,10 +171,14 @@ static int __devexit gpio_mouse_remove(struct platform_device *pdev)
171 return 0; 171 return 0;
172} 172}
173 173
174/* work with hotplug and coldplug */
175MODULE_ALIAS("platform:gpio_mouse");
176
174struct platform_driver gpio_mouse_device_driver = { 177struct platform_driver gpio_mouse_device_driver = {
175 .remove = __devexit_p(gpio_mouse_remove), 178 .remove = __devexit_p(gpio_mouse_remove),
176 .driver = { 179 .driver = {
177 .name = "gpio_mouse", 180 .name = "gpio_mouse",
181 .owner = THIS_MODULE,
178 } 182 }
179}; 183};
180 184
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index b88569e21d60..ec4b6610f730 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -88,6 +88,16 @@ config SERIO_RPCKBD
88 To compile this driver as a module, choose M here: the 88 To compile this driver as a module, choose M here: the
89 module will be called rpckbd. 89 module will be called rpckbd.
90 90
91config SERIO_AT32PSIF
92 tristate "AVR32 PSIF PS/2 keyboard and mouse controller"
93 depends on AVR32
94 help
95 Say Y here if you want to use the PSIF peripheral on AVR32 devices
96 and connect a PS/2 keyboard and/or mouse to it.
97
98 To compile this driver as a module, choose M here: the module will
99 be called at32psif.
100
91config SERIO_AMBAKMI 101config SERIO_AMBAKMI
92 tristate "AMBA KMI keyboard controller" 102 tristate "AMBA KMI keyboard controller"
93 depends on ARM_AMBA 103 depends on ARM_AMBA
diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile
index 4155197867a3..38b886887cbc 100644
--- a/drivers/input/serio/Makefile
+++ b/drivers/input/serio/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_SERIO_CT82C710) += ct82c710.o
12obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o 12obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o
13obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o 13obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o
14obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o 14obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o
15obj-$(CONFIG_SERIO_AT32PSIF) += at32psif.o
15obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o 16obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o
16obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o 17obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o
17obj-$(CONFIG_HP_SDC) += hp_sdc.o 18obj-$(CONFIG_HP_SDC) += hp_sdc.o
diff --git a/drivers/input/serio/at32psif.c b/drivers/input/serio/at32psif.c
new file mode 100644
index 000000000000..41fda8c67b1e
--- /dev/null
+++ b/drivers/input/serio/at32psif.c
@@ -0,0 +1,375 @@
1/*
2 * Copyright (C) 2007 Atmel Corporation
3 *
4 * Driver for the AT32AP700X PS/2 controller (PSIF).
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/device.h>
13#include <linux/init.h>
14#include <linux/serio.h>
15#include <linux/interrupt.h>
16#include <linux/delay.h>
17#include <linux/err.h>
18#include <linux/io.h>
19#include <linux/clk.h>
20#include <linux/platform_device.h>
21
22/* PSIF register offsets */
23#define PSIF_CR 0x00
24#define PSIF_RHR 0x04
25#define PSIF_THR 0x08
26#define PSIF_SR 0x10
27#define PSIF_IER 0x14
28#define PSIF_IDR 0x18
29#define PSIF_IMR 0x1c
30#define PSIF_PSR 0x24
31
32/* Bitfields in control register. */
33#define PSIF_CR_RXDIS_OFFSET 1
34#define PSIF_CR_RXDIS_SIZE 1
35#define PSIF_CR_RXEN_OFFSET 0
36#define PSIF_CR_RXEN_SIZE 1
37#define PSIF_CR_SWRST_OFFSET 15
38#define PSIF_CR_SWRST_SIZE 1
39#define PSIF_CR_TXDIS_OFFSET 9
40#define PSIF_CR_TXDIS_SIZE 1
41#define PSIF_CR_TXEN_OFFSET 8
42#define PSIF_CR_TXEN_SIZE 1
43
44/* Bitfields in interrupt disable, enable, mask and status register. */
45#define PSIF_NACK_OFFSET 8
46#define PSIF_NACK_SIZE 1
47#define PSIF_OVRUN_OFFSET 5
48#define PSIF_OVRUN_SIZE 1
49#define PSIF_PARITY_OFFSET 9
50#define PSIF_PARITY_SIZE 1
51#define PSIF_RXRDY_OFFSET 4
52#define PSIF_RXRDY_SIZE 1
53#define PSIF_TXEMPTY_OFFSET 1
54#define PSIF_TXEMPTY_SIZE 1
55#define PSIF_TXRDY_OFFSET 0
56#define PSIF_TXRDY_SIZE 1
57
58/* Bitfields in prescale register. */
59#define PSIF_PSR_PRSCV_OFFSET 0
60#define PSIF_PSR_PRSCV_SIZE 12
61
62/* Bitfields in receive hold register. */
63#define PSIF_RHR_RXDATA_OFFSET 0
64#define PSIF_RHR_RXDATA_SIZE 8
65
66/* Bitfields in transmit hold register. */
67#define PSIF_THR_TXDATA_OFFSET 0
68#define PSIF_THR_TXDATA_SIZE 8
69
70/* Bit manipulation macros */
71#define PSIF_BIT(name) \
72 (1 << PSIF_##name##_OFFSET)
73
74#define PSIF_BF(name, value) \
75 (((value) & ((1 << PSIF_##name##_SIZE) - 1)) \
76 << PSIF_##name##_OFFSET)
77
78#define PSIF_BFEXT(name, value) \
79 (((value) >> PSIF_##name##_OFFSET) \
80 & ((1 << PSIF_##name##_SIZE) - 1))
81
82#define PSIF_BFINS(name, value, old) \
83 (((old) & ~(((1 << PSIF_##name##_SIZE) - 1) \
84 << PSIF_##name##_OFFSET)) \
85 | PSIF_BF(name, value))
86
87/* Register access macros */
88#define psif_readl(port, reg) \
89 __raw_readl((port)->regs + PSIF_##reg)
90
91#define psif_writel(port, reg, value) \
92 __raw_writel((value), (port)->regs + PSIF_##reg)
93
94struct psif {
95 struct platform_device *pdev;
96 struct clk *pclk;
97 struct serio *io;
98 void __iomem *regs;
99 unsigned int irq;
100 unsigned int open;
101 /* Prevent concurrent writes to PSIF THR. */
102 spinlock_t lock;
103};
104
105static irqreturn_t psif_interrupt(int irq, void *_ptr)
106{
107 struct psif *psif = _ptr;
108 int retval = IRQ_NONE;
109 unsigned int io_flags = 0;
110 unsigned long status;
111
112 status = psif_readl(psif, SR);
113
114 if (status & PSIF_BIT(RXRDY)) {
115 unsigned char val = (unsigned char) psif_readl(psif, RHR);
116
117 if (status & PSIF_BIT(PARITY))
118 io_flags |= SERIO_PARITY;
119 if (status & PSIF_BIT(OVRUN))
120 dev_err(&psif->pdev->dev, "overrun read error\n");
121
122 serio_interrupt(psif->io, val, io_flags);
123
124 retval = IRQ_HANDLED;
125 }
126
127 return retval;
128}
129
130static int psif_write(struct serio *io, unsigned char val)
131{
132 struct psif *psif = io->port_data;
133 unsigned long flags;
134 int timeout = 10;
135 int retval = 0;
136
137 spin_lock_irqsave(&psif->lock, flags);
138
139 while (!(psif_readl(psif, SR) & PSIF_BIT(TXEMPTY)) && timeout--)
140 msleep(10);
141
142 if (timeout >= 0) {
143 psif_writel(psif, THR, val);
144 } else {
145 dev_dbg(&psif->pdev->dev, "timeout writing to THR\n");
146 retval = -EBUSY;
147 }
148
149 spin_unlock_irqrestore(&psif->lock, flags);
150
151 return retval;
152}
153
154static int psif_open(struct serio *io)
155{
156 struct psif *psif = io->port_data;
157 int retval;
158
159 retval = clk_enable(psif->pclk);
160 if (retval)
161 goto out;
162
163 psif_writel(psif, CR, PSIF_BIT(CR_TXEN) | PSIF_BIT(CR_RXEN));
164 psif_writel(psif, IER, PSIF_BIT(RXRDY));
165
166 psif->open = 1;
167out:
168 return retval;
169}
170
171static void psif_close(struct serio *io)
172{
173 struct psif *psif = io->port_data;
174
175 psif->open = 0;
176
177 psif_writel(psif, IDR, ~0UL);
178 psif_writel(psif, CR, PSIF_BIT(CR_TXDIS) | PSIF_BIT(CR_RXDIS));
179
180 clk_disable(psif->pclk);
181}
182
183static void psif_set_prescaler(struct psif *psif)
184{
185 unsigned long prscv;
186 unsigned long rate = clk_get_rate(psif->pclk);
187
188 /* PRSCV = Pulse length (100 us) * PSIF module frequency. */
189 prscv = 100 * (rate / 1000000UL);
190
191 if (prscv > ((1<<PSIF_PSR_PRSCV_SIZE) - 1)) {
192 prscv = (1<<PSIF_PSR_PRSCV_SIZE) - 1;
193 dev_dbg(&psif->pdev->dev, "pclk too fast, "
194 "prescaler set to max\n");
195 }
196
197 clk_enable(psif->pclk);
198 psif_writel(psif, PSR, prscv);
199 clk_disable(psif->pclk);
200}
201
202static int __init psif_probe(struct platform_device *pdev)
203{
204 struct resource *regs;
205 struct psif *psif;
206 struct serio *io;
207 struct clk *pclk;
208 int irq;
209 int ret;
210
211 psif = kzalloc(sizeof(struct psif), GFP_KERNEL);
212 if (!psif) {
213 dev_dbg(&pdev->dev, "out of memory\n");
214 ret = -ENOMEM;
215 goto out;
216 }
217 psif->pdev = pdev;
218
219 io = kzalloc(sizeof(struct serio), GFP_KERNEL);
220 if (!io) {
221 dev_dbg(&pdev->dev, "out of memory\n");
222 ret = -ENOMEM;
223 goto out_free_psif;
224 }
225 psif->io = io;
226
227 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
228 if (!regs) {
229 dev_dbg(&pdev->dev, "no mmio resources defined\n");
230 ret = -ENOMEM;
231 goto out_free_io;
232 }
233
234 psif->regs = ioremap(regs->start, regs->end - regs->start + 1);
235 if (!psif->regs) {
236 ret = -ENOMEM;
237 dev_dbg(&pdev->dev, "could not map I/O memory\n");
238 goto out_free_io;
239 }
240
241 pclk = clk_get(&pdev->dev, "pclk");
242 if (IS_ERR(pclk)) {
243 dev_dbg(&pdev->dev, "could not get peripheral clock\n");
244 ret = PTR_ERR(pclk);
245 goto out_iounmap;
246 }
247 psif->pclk = pclk;
248
249 /* Reset the PSIF to enter at a known state. */
250 ret = clk_enable(pclk);
251 if (ret) {
252 dev_dbg(&pdev->dev, "could not enable pclk\n");
253 goto out_put_clk;
254 }
255 psif_writel(psif, CR, PSIF_BIT(CR_SWRST));
256 clk_disable(pclk);
257
258 irq = platform_get_irq(pdev, 0);
259 if (irq < 0) {
260 dev_dbg(&pdev->dev, "could not get irq\n");
261 ret = -ENXIO;
262 goto out_put_clk;
263 }
264 ret = request_irq(irq, psif_interrupt, IRQF_SHARED, "at32psif", psif);
265 if (ret) {
266 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
267 goto out_put_clk;
268 }
269 psif->irq = irq;
270
271 io->id.type = SERIO_8042;
272 io->write = psif_write;
273 io->open = psif_open;
274 io->close = psif_close;
275 snprintf(io->name, sizeof(io->name), "AVR32 PS/2 port%d", pdev->id);
276 snprintf(io->phys, sizeof(io->phys), "at32psif/serio%d", pdev->id);
277 io->port_data = psif;
278 io->dev.parent = &pdev->dev;
279
280 psif_set_prescaler(psif);
281
282 spin_lock_init(&psif->lock);
283 serio_register_port(psif->io);
284 platform_set_drvdata(pdev, psif);
285
286 dev_info(&pdev->dev, "Atmel AVR32 PSIF PS/2 driver on 0x%08x irq %d\n",
287 (int)psif->regs, psif->irq);
288
289 return 0;
290
291out_put_clk:
292 clk_put(psif->pclk);
293out_iounmap:
294 iounmap(psif->regs);
295out_free_io:
296 kfree(io);
297out_free_psif:
298 kfree(psif);
299out:
300 return ret;
301}
302
303static int __exit psif_remove(struct platform_device *pdev)
304{
305 struct psif *psif = platform_get_drvdata(pdev);
306
307 psif_writel(psif, IDR, ~0UL);
308 psif_writel(psif, CR, PSIF_BIT(CR_TXDIS) | PSIF_BIT(CR_RXDIS));
309
310 serio_unregister_port(psif->io);
311 iounmap(psif->regs);
312 free_irq(psif->irq, psif);
313 clk_put(psif->pclk);
314 kfree(psif);
315
316 platform_set_drvdata(pdev, NULL);
317
318 return 0;
319}
320
321#ifdef CONFIG_PM
322static int psif_suspend(struct platform_device *pdev, pm_message_t state)
323{
324 struct psif *psif = platform_get_drvdata(pdev);
325
326 if (psif->open) {
327 psif_writel(psif, CR, PSIF_BIT(CR_RXDIS) | PSIF_BIT(CR_TXDIS));
328 clk_disable(psif->pclk);
329 }
330
331 return 0;
332}
333
334static int psif_resume(struct platform_device *pdev)
335{
336 struct psif *psif = platform_get_drvdata(pdev);
337
338 if (psif->open) {
339 clk_enable(psif->pclk);
340 psif_set_prescaler(psif);
341 psif_writel(psif, CR, PSIF_BIT(CR_RXEN) | PSIF_BIT(CR_TXEN));
342 }
343
344 return 0;
345}
346#else
347#define psif_suspend NULL
348#define psif_resume NULL
349#endif
350
351static struct platform_driver psif_driver = {
352 .remove = __exit_p(psif_remove),
353 .driver = {
354 .name = "atmel_psif",
355 },
356 .suspend = psif_suspend,
357 .resume = psif_resume,
358};
359
360static int __init psif_init(void)
361{
362 return platform_driver_probe(&psif_driver, psif_probe);
363}
364
365static void __exit psif_exit(void)
366{
367 platform_driver_unregister(&psif_driver);
368}
369
370module_init(psif_init);
371module_exit(psif_exit);
372
373MODULE_AUTHOR("Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>");
374MODULE_DESCRIPTION("Atmel AVR32 PSIF PS/2 driver");
375MODULE_LICENSE("GPL");
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 60931aceb828..5ece9f56babc 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -370,10 +370,10 @@ static int i8042_pnp_kbd_probe(struct pnp_dev *dev, const struct pnp_device_id *
370 if (pnp_irq_valid(dev,0)) 370 if (pnp_irq_valid(dev,0))
371 i8042_pnp_kbd_irq = pnp_irq(dev, 0); 371 i8042_pnp_kbd_irq = pnp_irq(dev, 0);
372 372
373 strncpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name)); 373 strlcpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name));
374 if (strlen(pnp_dev_name(dev))) { 374 if (strlen(pnp_dev_name(dev))) {
375 strncat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name)); 375 strlcat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name));
376 strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name)); 376 strlcat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
377 } 377 }
378 378
379 i8042_pnp_kbd_devices++; 379 i8042_pnp_kbd_devices++;
@@ -391,10 +391,10 @@ static int i8042_pnp_aux_probe(struct pnp_dev *dev, const struct pnp_device_id *
391 if (pnp_irq_valid(dev, 0)) 391 if (pnp_irq_valid(dev, 0))
392 i8042_pnp_aux_irq = pnp_irq(dev, 0); 392 i8042_pnp_aux_irq = pnp_irq(dev, 0);
393 393
394 strncpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name)); 394 strlcpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name));
395 if (strlen(pnp_dev_name(dev))) { 395 if (strlen(pnp_dev_name(dev))) {
396 strncat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name)); 396 strlcat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name));
397 strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name)); 397 strlcat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
398 } 398 }
399 399
400 i8042_pnp_aux_devices++; 400 i8042_pnp_aux_devices++;
diff --git a/drivers/input/serio/rpckbd.c b/drivers/input/serio/rpckbd.c
index 49f84315cb32..34c59d9c6205 100644
--- a/drivers/input/serio/rpckbd.c
+++ b/drivers/input/serio/rpckbd.c
@@ -45,6 +45,7 @@
45MODULE_AUTHOR("Vojtech Pavlik, Russell King"); 45MODULE_AUTHOR("Vojtech Pavlik, Russell King");
46MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver"); 46MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48MODULE_ALIAS("platform:kart");
48 49
49static int rpckbd_write(struct serio *port, unsigned char val) 50static int rpckbd_write(struct serio *port, unsigned char val)
50{ 51{
@@ -140,6 +141,7 @@ static struct platform_driver rpckbd_driver = {
140 .remove = __devexit_p(rpckbd_remove), 141 .remove = __devexit_p(rpckbd_remove),
141 .driver = { 142 .driver = {
142 .name = "kart", 143 .name = "kart",
144 .owner = THIS_MODULE,
143 }, 145 },
144}; 146};
145 147
diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index d371c0bdc0bd..effb49ea24aa 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -25,14 +25,14 @@ config TABLET_USB_ACECAD
25 module will be called acecad. 25 module will be called acecad.
26 26
27config TABLET_USB_AIPTEK 27config TABLET_USB_AIPTEK
28 tristate "Aiptek 6000U/8000U tablet support (USB)" 28 tristate "Aiptek 6000U/8000U and Genius G_PEN tablet support (USB)"
29 depends on USB_ARCH_HAS_HCD 29 depends on USB_ARCH_HAS_HCD
30 select USB 30 select USB
31 help 31 help
32 Say Y here if you want to use the USB version of the Aiptek 6000U 32 Say Y here if you want to use the USB version of the Aiptek 6000U,
33 or Aiptek 8000U tablet. Make sure to say Y to "Mouse support" 33 Aiptek 8000U or Genius G-PEN 560 tablet. Make sure to say Y to
34 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support" 34 "Mouse support" (CONFIG_INPUT_MOUSEDEV) and/or "Event interface
35 (CONFIG_INPUT_EVDEV) as well. 35 support" (CONFIG_INPUT_EVDEV) as well.
36 36
37 To compile this driver as a module, choose M here: the 37 To compile this driver as a module, choose M here: the
38 module will be called aiptek. 38 module will be called aiptek.
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 94683f58c9e1..1d759f6f8076 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -184,6 +184,7 @@
184 */ 184 */
185 185
186#define USB_VENDOR_ID_AIPTEK 0x08ca 186#define USB_VENDOR_ID_AIPTEK 0x08ca
187#define USB_VENDOR_ID_KYE 0x0458
187#define USB_REQ_GET_REPORT 0x01 188#define USB_REQ_GET_REPORT 0x01
188#define USB_REQ_SET_REPORT 0x09 189#define USB_REQ_SET_REPORT 0x09
189 190
@@ -832,6 +833,7 @@ static const struct usb_device_id aiptek_ids[] = {
832 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)}, 833 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
833 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)}, 834 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
834 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)}, 835 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
836 {USB_DEVICE(USB_VENDOR_ID_KYE, 0x5003)},
835 {} 837 {}
836}; 838};
837 839
diff --git a/drivers/input/tablet/wacom.h b/drivers/input/tablet/wacom.h
index acf9830698cb..706619d06f71 100644
--- a/drivers/input/tablet/wacom.h
+++ b/drivers/input/tablet/wacom.h
@@ -101,8 +101,11 @@ struct wacom {
101 dma_addr_t data_dma; 101 dma_addr_t data_dma;
102 struct input_dev *dev; 102 struct input_dev *dev;
103 struct usb_device *usbdev; 103 struct usb_device *usbdev;
104 struct usb_interface *intf;
104 struct urb *irq; 105 struct urb *irq;
105 struct wacom_wac * wacom_wac; 106 struct wacom_wac * wacom_wac;
107 struct mutex lock;
108 int open:1;
106 char phys[32]; 109 char phys[32];
107}; 110};
108 111
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 41caaef8e2d7..71cc0c140790 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -70,6 +70,7 @@ static void wacom_sys_irq(struct urb *urb)
70 input_sync(get_input_dev(&wcombo)); 70 input_sync(get_input_dev(&wcombo));
71 71
72 exit: 72 exit:
73 usb_mark_last_busy(wacom->usbdev);
73 retval = usb_submit_urb (urb, GFP_ATOMIC); 74 retval = usb_submit_urb (urb, GFP_ATOMIC);
74 if (retval) 75 if (retval)
75 err ("%s - usb_submit_urb failed with result %d", 76 err ("%s - usb_submit_urb failed with result %d",
@@ -124,10 +125,25 @@ static int wacom_open(struct input_dev *dev)
124{ 125{
125 struct wacom *wacom = input_get_drvdata(dev); 126 struct wacom *wacom = input_get_drvdata(dev);
126 127
128 mutex_lock(&wacom->lock);
129
127 wacom->irq->dev = wacom->usbdev; 130 wacom->irq->dev = wacom->usbdev;
128 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) 131
132 if (usb_autopm_get_interface(wacom->intf) < 0) {
133 mutex_unlock(&wacom->lock);
129 return -EIO; 134 return -EIO;
135 }
136
137 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
138 usb_autopm_put_interface(wacom->intf);
139 mutex_unlock(&wacom->lock);
140 return -EIO;
141 }
142
143 wacom->open = 1;
144 wacom->intf->needs_remote_wakeup = 1;
130 145
146 mutex_unlock(&wacom->lock);
131 return 0; 147 return 0;
132} 148}
133 149
@@ -135,7 +151,11 @@ static void wacom_close(struct input_dev *dev)
135{ 151{
136 struct wacom *wacom = input_get_drvdata(dev); 152 struct wacom *wacom = input_get_drvdata(dev);
137 153
154 mutex_lock(&wacom->lock);
138 usb_kill_urb(wacom->irq); 155 usb_kill_urb(wacom->irq);
156 wacom->open = 0;
157 wacom->intf->needs_remote_wakeup = 0;
158 mutex_unlock(&wacom->lock);
139} 159}
140 160
141void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 161void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
@@ -243,6 +263,8 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
243 263
244 wacom->usbdev = dev; 264 wacom->usbdev = dev;
245 wacom->dev = input_dev; 265 wacom->dev = input_dev;
266 wacom->intf = intf;
267 mutex_init(&wacom->lock);
246 usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); 268 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
247 strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); 269 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
248 270
@@ -304,23 +326,57 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
304 326
305static void wacom_disconnect(struct usb_interface *intf) 327static void wacom_disconnect(struct usb_interface *intf)
306{ 328{
307 struct wacom *wacom = usb_get_intfdata (intf); 329 struct wacom *wacom = usb_get_intfdata(intf);
308 330
309 usb_set_intfdata(intf, NULL); 331 usb_set_intfdata(intf, NULL);
310 if (wacom) { 332
311 usb_kill_urb(wacom->irq); 333 usb_kill_urb(wacom->irq);
312 input_unregister_device(wacom->dev); 334 input_unregister_device(wacom->dev);
313 usb_free_urb(wacom->irq); 335 usb_free_urb(wacom->irq);
314 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->wacom_wac->data, wacom->data_dma); 336 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->wacom_wac->data, wacom->data_dma);
315 kfree(wacom->wacom_wac); 337 kfree(wacom->wacom_wac);
316 kfree(wacom); 338 kfree(wacom);
317 } 339}
340
341static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
342{
343 struct wacom *wacom = usb_get_intfdata(intf);
344
345 mutex_lock(&wacom->lock);
346 usb_kill_urb(wacom->irq);
347 mutex_unlock(&wacom->lock);
348
349 return 0;
350}
351
352static int wacom_resume(struct usb_interface *intf)
353{
354 struct wacom *wacom = usb_get_intfdata(intf);
355 int rv;
356
357 mutex_lock(&wacom->lock);
358 if (wacom->open)
359 rv = usb_submit_urb(wacom->irq, GFP_NOIO);
360 else
361 rv = 0;
362 mutex_unlock(&wacom->lock);
363
364 return rv;
365}
366
367static int wacom_reset_resume(struct usb_interface *intf)
368{
369 return wacom_resume(intf);
318} 370}
319 371
320static struct usb_driver wacom_driver = { 372static struct usb_driver wacom_driver = {
321 .name = "wacom", 373 .name = "wacom",
322 .probe = wacom_probe, 374 .probe = wacom_probe,
323 .disconnect = wacom_disconnect, 375 .disconnect = wacom_disconnect,
376 .suspend = wacom_suspend,
377 .resume = wacom_resume,
378 .reset_resume = wacom_reset_resume,
379 .supports_autosuspend = 1,
324}; 380};
325 381
326static int __init wacom_init(void) 382static int __init wacom_init(void)
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index ffe33842143f..192513e1f04c 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -649,6 +649,7 @@ static struct wacom_features wacom_features[] = {
649 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, 649 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
650 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S }, 650 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
651 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, 651 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
652 { "Wacom Cintiq 20WSX", 10, 86680, 54180, 1023, 63, WACOM_BEE },
652 { "Wacom Cintiq 12WX", 10, 53020, 33440, 1023, 63, WACOM_BEE }, 653 { "Wacom Cintiq 12WX", 10, 53020, 33440, 1023, 63, WACOM_BEE },
653 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS }, 654 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
654 { } 655 { }
@@ -702,6 +703,7 @@ static struct usb_device_id wacom_ids[] = {
702 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) }, 703 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
703 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) }, 704 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) },
704 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) }, 705 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
706 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC5) },
705 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6) }, 707 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6) },
706 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) }, 708 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
707 { } 709 { }
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 90e8e92dfe47..565ec711c2ee 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -185,6 +185,59 @@ config TOUCHSCREEN_UCB1400
185 To compile this driver as a module, choose M here: the 185 To compile this driver as a module, choose M here: the
186 module will be called ucb1400_ts. 186 module will be called ucb1400_ts.
187 187
188config TOUCHSCREEN_WM97XX
189 tristate "Support for WM97xx AC97 touchscreen controllers"
190 depends on AC97_BUS
191 help
192 Say Y here if you have a Wolfson Microelectronics WM97xx
193 touchscreen connected to your system. Note that this option
194 only enables core driver, you will also need to select
195 support for appropriate chip below.
196
197 If unsure, say N.
198
199 To compile this driver as a module, choose M here: the
200 module will be called wm97xx-ts.
201
202config TOUCHSCREEN_WM9705
203 bool "WM9705 Touchscreen interface support"
204 depends on TOUCHSCREEN_WM97XX
205 help
206 Say Y here if you have a Wolfson Microelectronics WM9705
207 touchscreen controller connected to your system.
208
209 If unsure, say N.
210
211config TOUCHSCREEN_WM9712
212 bool "WM9712 Touchscreen interface support"
213 depends on TOUCHSCREEN_WM97XX
214 help
215 Say Y here if you have a Wolfson Microelectronics WM9712
216 touchscreen controller connected to your system.
217
218 If unsure, say N.
219
220config TOUCHSCREEN_WM9713
221 bool "WM9713 Touchscreen interface support"
222 depends on TOUCHSCREEN_WM97XX
223 help
224 Say Y here if you have a Wolfson Microelectronics WM9713 touchscreen
225 controller connected to your system.
226
227 If unsure, say N.
228
229config TOUCHSCREEN_WM97XX_MAINSTONE
230 tristate "WM97xx Mainstone accelerated touch"
231 depends on TOUCHSCREEN_WM97XX && ARCH_PXA
232 help
233 Say Y here for support for streaming mode with WM97xx touchscreens
234 on Mainstone systems.
235
236 If unsure, say N.
237
238 To compile this driver as a module, choose M here: the
239 module will be called mainstone-wm97xx.
240
188config TOUCHSCREEN_USB_COMPOSITE 241config TOUCHSCREEN_USB_COMPOSITE
189 tristate "USB Touchscreen Driver" 242 tristate "USB Touchscreen Driver"
190 depends on USB_ARCH_HAS_HCD 243 depends on USB_ARCH_HAS_HCD
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 35d4097df35a..3c096d75651d 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -4,6 +4,8 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7wm97xx-ts-y := wm97xx-core.o
8
7obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 9obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o
8obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 10obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
9obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o 11obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
@@ -19,3 +21,8 @@ obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
19obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 21obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
20obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 22obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
21obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 23obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
24obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o
25wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o
26wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o
27wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o
28obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 39573b91c8de..907a45fe9d40 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -80,6 +80,7 @@ struct ads7846 {
80#endif 80#endif
81 81
82 u16 model; 82 u16 model;
83 u16 vref_mv;
83 u16 vref_delay_usecs; 84 u16 vref_delay_usecs;
84 u16 x_plate_ohms; 85 u16 x_plate_ohms;
85 u16 pressure_max; 86 u16 pressure_max;
@@ -177,9 +178,6 @@ struct ads7846 {
177 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF; 178 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
178 * ads7846 lets that pin be unconnected, to use internal vREF. 179 * ads7846 lets that pin be unconnected, to use internal vREF.
179 */ 180 */
180static unsigned vREF_mV;
181module_param(vREF_mV, uint, 0);
182MODULE_PARM_DESC(vREF_mV, "external vREF voltage, in milliVolts");
183 181
184struct ser_req { 182struct ser_req {
185 u8 ref_on; 183 u8 ref_on;
@@ -206,7 +204,6 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
206 struct ads7846 *ts = dev_get_drvdata(dev); 204 struct ads7846 *ts = dev_get_drvdata(dev);
207 struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); 205 struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL);
208 int status; 206 int status;
209 int uninitialized_var(sample);
210 int use_internal; 207 int use_internal;
211 208
212 if (!req) 209 if (!req)
@@ -263,13 +260,13 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
263 260
264 if (status == 0) { 261 if (status == 0) {
265 /* on-wire is a must-ignore bit, a BE12 value, then padding */ 262 /* on-wire is a must-ignore bit, a BE12 value, then padding */
266 sample = be16_to_cpu(req->sample); 263 status = be16_to_cpu(req->sample);
267 sample = sample >> 3; 264 status = status >> 3;
268 sample &= 0x0fff; 265 status &= 0x0fff;
269 } 266 }
270 267
271 kfree(req); 268 kfree(req);
272 return status ? status : sample; 269 return status;
273} 270}
274 271
275#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) 272#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
@@ -310,7 +307,7 @@ static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
310 unsigned retval = v; 307 unsigned retval = v;
311 308
312 /* external resistors may scale vAUX into 0..vREF */ 309 /* external resistors may scale vAUX into 0..vREF */
313 retval *= vREF_mV; 310 retval *= ts->vref_mv;
314 retval = retval >> 12; 311 retval = retval >> 12;
315 return retval; 312 return retval;
316} 313}
@@ -368,14 +365,14 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
368 /* hwmon sensors need a reference voltage */ 365 /* hwmon sensors need a reference voltage */
369 switch (ts->model) { 366 switch (ts->model) {
370 case 7846: 367 case 7846:
371 if (!vREF_mV) { 368 if (!ts->vref_mv) {
372 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); 369 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n");
373 vREF_mV = 2500; 370 ts->vref_mv = 2500;
374 } 371 }
375 break; 372 break;
376 case 7845: 373 case 7845:
377 case 7843: 374 case 7843:
378 if (!vREF_mV) { 375 if (!ts->vref_mv) {
379 dev_warn(&spi->dev, 376 dev_warn(&spi->dev,
380 "external vREF for ADS%d not specified\n", 377 "external vREF for ADS%d not specified\n",
381 ts->model); 378 ts->model);
@@ -868,6 +865,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
868 865
869 ts->spi = spi; 866 ts->spi = spi;
870 ts->input = input_dev; 867 ts->input = input_dev;
868 ts->vref_mv = pdata->vref_mv;
871 869
872 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 870 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
873 ts->timer.function = ads7846_timer; 871 ts->timer.function = ads7846_timer;
diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c
index a22576779acd..4e9d8eece2e0 100644
--- a/drivers/input/touchscreen/corgi_ts.c
+++ b/drivers/input/touchscreen/corgi_ts.c
@@ -362,6 +362,7 @@ static struct platform_driver corgits_driver = {
362 .resume = corgits_resume, 362 .resume = corgits_resume,
363 .driver = { 363 .driver = {
364 .name = "corgi-ts", 364 .name = "corgi-ts",
365 .owner = THIS_MODULE,
365 }, 366 },
366}; 367};
367 368
@@ -381,3 +382,4 @@ module_exit(corgits_exit);
381MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); 382MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
382MODULE_DESCRIPTION("Corgi TouchScreen Driver"); 383MODULE_DESCRIPTION("Corgi TouchScreen Driver");
383MODULE_LICENSE("GPL"); 384MODULE_LICENSE("GPL");
385MODULE_ALIAS("platform:corgi-ts");
diff --git a/drivers/input/touchscreen/jornada720_ts.c b/drivers/input/touchscreen/jornada720_ts.c
index 42a1c9a1940e..742242111bf1 100644
--- a/drivers/input/touchscreen/jornada720_ts.c
+++ b/drivers/input/touchscreen/jornada720_ts.c
@@ -160,11 +160,15 @@ static int __devexit jornada720_ts_remove(struct platform_device *pdev)
160 return 0; 160 return 0;
161} 161}
162 162
163/* work with hotplug and coldplug */
164MODULE_ALIAS("platform:jornada_ts");
165
163static struct platform_driver jornada720_ts_driver = { 166static struct platform_driver jornada720_ts_driver = {
164 .probe = jornada720_ts_probe, 167 .probe = jornada720_ts_probe,
165 .remove = __devexit_p(jornada720_ts_remove), 168 .remove = __devexit_p(jornada720_ts_remove),
166 .driver = { 169 .driver = {
167 .name = "jornada_ts", 170 .name = "jornada_ts",
171 .owner = THIS_MODULE,
168 }, 172 },
169}; 173};
170 174
diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c b/drivers/input/touchscreen/mainstone-wm97xx.c
new file mode 100644
index 000000000000..a79f029b91c0
--- /dev/null
+++ b/drivers/input/touchscreen/mainstone-wm97xx.c
@@ -0,0 +1,302 @@
1/*
2 * mainstone-wm97xx.c -- Mainstone Continuous Touch screen driver for
3 * Wolfson WM97xx AC97 Codecs.
4 *
5 * Copyright 2004, 2007 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * Notes:
17 * This is a wm97xx extended touch driver to capture touch
18 * data in a continuous manner on the Intel XScale archictecture
19 *
20 * Features:
21 * - codecs supported:- WM9705, WM9712, WM9713
22 * - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x
23 *
24 */
25
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/version.h>
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/irq.h>
33#include <linux/interrupt.h>
34#include <linux/wm97xx.h>
35#include <linux/io.h>
36#include <asm/arch/pxa-regs.h>
37
38#define VERSION "0.13"
39
40struct continuous {
41 u16 id; /* codec id */
42 u8 code; /* continuous code */
43 u8 reads; /* number of coord reads per read cycle */
44 u32 speed; /* number of coords per second */
45};
46
47#define WM_READS(sp) ((sp / HZ) + 1)
48
49static const struct continuous cinfo[] = {
50 {WM9705_ID2, 0, WM_READS(94), 94},
51 {WM9705_ID2, 1, WM_READS(188), 188},
52 {WM9705_ID2, 2, WM_READS(375), 375},
53 {WM9705_ID2, 3, WM_READS(750), 750},
54 {WM9712_ID2, 0, WM_READS(94), 94},
55 {WM9712_ID2, 1, WM_READS(188), 188},
56 {WM9712_ID2, 2, WM_READS(375), 375},
57 {WM9712_ID2, 3, WM_READS(750), 750},
58 {WM9713_ID2, 0, WM_READS(94), 94},
59 {WM9713_ID2, 1, WM_READS(120), 120},
60 {WM9713_ID2, 2, WM_READS(154), 154},
61 {WM9713_ID2, 3, WM_READS(188), 188},
62};
63
64/* continuous speed index */
65static int sp_idx;
66static u16 last, tries;
67
68/*
69 * Pen sampling frequency (Hz) in continuous mode.
70 */
71static int cont_rate = 200;
72module_param(cont_rate, int, 0);
73MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
74
75/*
76 * Pen down detection.
77 *
78 * This driver can either poll or use an interrupt to indicate a pen down
79 * event. If the irq request fails then it will fall back to polling mode.
80 */
81static int pen_int;
82module_param(pen_int, int, 0);
83MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");
84
85/*
86 * Pressure readback.
87 *
88 * Set to 1 to read back pen down pressure
89 */
90static int pressure;
91module_param(pressure, int, 0);
92MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");
93
94/*
95 * AC97 touch data slot.
96 *
97 * Touch screen readback data ac97 slot
98 */
99static int ac97_touch_slot = 5;
100module_param(ac97_touch_slot, int, 0);
101MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
102
103
104/* flush AC97 slot 5 FIFO on pxa machines */
105#ifdef CONFIG_PXA27x
106static void wm97xx_acc_pen_up(struct wm97xx *wm)
107{
108 schedule_timeout_uninterruptible(1);
109
110 while (MISR & (1 << 2))
111 MODR;
112}
113#else
114static void wm97xx_acc_pen_up(struct wm97xx *wm)
115{
116 int count = 16;
117 schedule_timeout_uninterruptible(1);
118
119 while (count < 16) {
120 MODR;
121 count--;
122 }
123}
124#endif
125
126static int wm97xx_acc_pen_down(struct wm97xx *wm)
127{
128 u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
129 int reads = 0;
130
131 /* When the AC97 queue has been drained we need to allow time
132 * to buffer up samples otherwise we end up spinning polling
133 * for samples. The controller can't have a suitably low
134 * threashold set to use the notifications it gives.
135 */
136 schedule_timeout_uninterruptible(1);
137
138 if (tries > 5) {
139 tries = 0;
140 return RC_PENUP;
141 }
142
143 x = MODR;
144 if (x == last) {
145 tries++;
146 return RC_AGAIN;
147 }
148 last = x;
149 do {
150 if (reads)
151 x = MODR;
152 y = MODR;
153 if (pressure)
154 p = MODR;
155
156 /* are samples valid */
157 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||
158 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||
159 (p & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_PRES)
160 goto up;
161
162 /* coordinate is good */
163 tries = 0;
164 input_report_abs(wm->input_dev, ABS_X, x & 0xfff);
165 input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);
166 input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);
167 input_sync(wm->input_dev);
168 reads++;
169 } while (reads < cinfo[sp_idx].reads);
170up:
171 return RC_PENDOWN | RC_AGAIN;
172}
173
174static int wm97xx_acc_startup(struct wm97xx *wm)
175{
176 int idx = 0;
177
178 /* check we have a codec */
179 if (wm->ac97 == NULL)
180 return -ENODEV;
181
182 /* Go you big red fire engine */
183 for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {
184 if (wm->id != cinfo[idx].id)
185 continue;
186 sp_idx = idx;
187 if (cont_rate <= cinfo[idx].speed)
188 break;
189 }
190 wm->acc_rate = cinfo[sp_idx].code;
191 wm->acc_slot = ac97_touch_slot;
192 dev_info(wm->dev,
193 "mainstone accelerated touchscreen driver, %d samples/sec\n",
194 cinfo[sp_idx].speed);
195
196 /* codec specific irq config */
197 if (pen_int) {
198 switch (wm->id) {
199 case WM9705_ID2:
200 wm->pen_irq = IRQ_GPIO(4);
201 set_irq_type(IRQ_GPIO(4), IRQT_BOTHEDGE);
202 break;
203 case WM9712_ID2:
204 case WM9713_ID2:
205 /* enable pen down interrupt */
206 /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */
207 wm->pen_irq = MAINSTONE_AC97_IRQ;
208 wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
209 WM97XX_GPIO_POL_HIGH,
210 WM97XX_GPIO_STICKY,
211 WM97XX_GPIO_WAKE);
212 wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,
213 WM97XX_GPIO_POL_HIGH,
214 WM97XX_GPIO_NOTSTICKY,
215 WM97XX_GPIO_NOWAKE);
216 break;
217 default:
218 dev_err(wm->dev,
219 "pen down irq not supported on this device\n");
220 pen_int = 0;
221 break;
222 }
223 }
224
225 return 0;
226}
227
228static void wm97xx_acc_shutdown(struct wm97xx *wm)
229{
230 /* codec specific deconfig */
231 if (pen_int) {
232 switch (wm->id & 0xffff) {
233 case WM9705_ID2:
234 wm->pen_irq = 0;
235 break;
236 case WM9712_ID2:
237 case WM9713_ID2:
238 /* disable interrupt */
239 wm->pen_irq = 0;
240 break;
241 }
242 }
243}
244
245static void wm97xx_irq_enable(struct wm97xx *wm, int enable)
246{
247 if (enable)
248 enable_irq(wm->pen_irq);
249 else
250 disable_irq(wm->pen_irq);
251}
252
253static struct wm97xx_mach_ops mainstone_mach_ops = {
254 .acc_enabled = 1,
255 .acc_pen_up = wm97xx_acc_pen_up,
256 .acc_pen_down = wm97xx_acc_pen_down,
257 .acc_startup = wm97xx_acc_startup,
258 .acc_shutdown = wm97xx_acc_shutdown,
259 .irq_enable = wm97xx_irq_enable,
260 .irq_gpio = WM97XX_GPIO_2,
261};
262
263static int mainstone_wm97xx_probe(struct platform_device *pdev)
264{
265 struct wm97xx *wm = platform_get_drvdata(pdev);
266
267 return wm97xx_register_mach_ops(wm, &mainstone_mach_ops);
268}
269
270static int mainstone_wm97xx_remove(struct platform_device *pdev)
271{
272 struct wm97xx *wm = platform_get_drvdata(pdev);
273
274 wm97xx_unregister_mach_ops(wm);
275 return 0;
276}
277
278static struct platform_driver mainstone_wm97xx_driver = {
279 .probe = mainstone_wm97xx_probe,
280 .remove = mainstone_wm97xx_remove,
281 .driver = {
282 .name = "wm97xx-touch",
283 },
284};
285
286static int __init mainstone_wm97xx_init(void)
287{
288 return platform_driver_register(&mainstone_wm97xx_driver);
289}
290
291static void __exit mainstone_wm97xx_exit(void)
292{
293 platform_driver_unregister(&mainstone_wm97xx_driver);
294}
295
296module_init(mainstone_wm97xx_init);
297module_exit(mainstone_wm97xx_exit);
298
299/* Module information */
300MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
301MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone");
302MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/ucb1400_ts.c b/drivers/input/touchscreen/ucb1400_ts.c
index 607f9933aa1f..bce018e45bce 100644
--- a/drivers/input/touchscreen/ucb1400_ts.c
+++ b/drivers/input/touchscreen/ucb1400_ts.c
@@ -427,10 +427,6 @@ static int ucb1400_detect_irq(struct ucb1400 *ucb)
427 unsigned long mask, timeout; 427 unsigned long mask, timeout;
428 428
429 mask = probe_irq_on(); 429 mask = probe_irq_on();
430 if (!mask) {
431 probe_irq_off(mask);
432 return -EBUSY;
433 }
434 430
435 /* Enable the ADC interrupt. */ 431 /* Enable the ADC interrupt. */
436 ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC); 432 ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC);
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 63f9664a066f..3a0a8ca57076 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -396,9 +396,12 @@ static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
396static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) 396static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
397{ 397{
398 struct usb_device *dev = usbtouch->udev; 398 struct usb_device *dev = usbtouch->udev;
399 int ret; 399 int ret = -ENOMEM;
400 unsigned char buf[2]; 400 unsigned char *buf;
401 401
402 buf = kmalloc(2, GFP_KERNEL);
403 if (!buf)
404 goto err_nobuf;
402 /* reset */ 405 /* reset */
403 buf[0] = buf[1] = 0xFF; 406 buf[0] = buf[1] = 0xFF;
404 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), 407 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
@@ -406,9 +409,11 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
406 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 409 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
407 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 410 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
408 if (ret < 0) 411 if (ret < 0)
409 return ret; 412 goto err_out;
410 if (buf[0] != 0x06 || buf[1] != 0x00) 413 if (buf[0] != 0x06 || buf[1] != 0x00) {
411 return -ENODEV; 414 ret = -ENODEV;
415 goto err_out;
416 }
412 417
413 /* set coordinate output rate */ 418 /* set coordinate output rate */
414 buf[0] = buf[1] = 0xFF; 419 buf[0] = buf[1] = 0xFF;
@@ -417,20 +422,22 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
417 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 422 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
418 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 423 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
419 if (ret < 0) 424 if (ret < 0)
420 return ret; 425 goto err_out;
421 if ((buf[0] != 0x06 || buf[1] != 0x00) && 426 if ((buf[0] != 0x06 || buf[1] != 0x00) &&
422 (buf[0] != 0x15 || buf[1] != 0x01)) 427 (buf[0] != 0x15 || buf[1] != 0x01)) {
423 return -ENODEV; 428 ret = -ENODEV;
429 goto err_out;
430 }
424 431
425 /* start sending data */ 432 /* start sending data */
426 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), 433 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
427 TSC10_CMD_DATA1, 434 TSC10_CMD_DATA1,
428 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 435 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
429 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 436 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
430 if (ret < 0) 437err_out:
431 return ret; 438 kfree(buf);
432 439err_nobuf:
433 return 0; 440 return ret;
434} 441}
435 442
436 443
diff --git a/drivers/input/touchscreen/wm9705.c b/drivers/input/touchscreen/wm9705.c
new file mode 100644
index 000000000000..978e1a13ffc7
--- /dev/null
+++ b/drivers/input/touchscreen/wm9705.c
@@ -0,0 +1,353 @@
1/*
2 * wm9705.c -- Codec driver for Wolfson WM9705 AC97 Codec.
3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/bitops.h>
25#include <linux/wm97xx.h>
26
27#define TS_NAME "wm97xx"
28#define WM9705_VERSION "1.00"
29#define DEFAULT_PRESSURE 0xb0c0
30
31/*
32 * Module parameters
33 */
34
35/*
36 * Set current used for pressure measurement.
37 *
38 * Set pil = 2 to use 400uA
39 * pil = 1 to use 200uA and
40 * pil = 0 to disable pressure measurement.
41 *
42 * This is used to increase the range of values returned by the adc
43 * when measureing touchpanel pressure.
44 */
45static int pil;
46module_param(pil, int, 0);
47MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
48
49/*
50 * Set threshold for pressure measurement.
51 *
52 * Pen down pressure below threshold is ignored.
53 */
54static int pressure = DEFAULT_PRESSURE & 0xfff;
55module_param(pressure, int, 0);
56MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
57
58/*
59 * Set adc sample delay.
60 *
61 * For accurate touchpanel measurements, some settling time may be
62 * required between the switch matrix applying a voltage across the
63 * touchpanel plate and the ADC sampling the signal.
64 *
65 * This delay can be set by setting delay = n, where n is the array
66 * position of the delay in the array delay_table below.
67 * Long delays > 1ms are supported for completeness, but are not
68 * recommended.
69 */
70static int delay = 4;
71module_param(delay, int, 0);
72MODULE_PARM_DESC(delay, "Set adc sample delay.");
73
74/*
75 * Pen detect comparator threshold.
76 *
77 * 0 to Vmid in 15 steps, 0 = use zero power comparator with Vmid threshold
78 * i.e. 1 = Vmid/15 threshold
79 * 15 = Vmid/1 threshold
80 *
81 * Adjust this value if you are having problems with pen detect not
82 * detecting any down events.
83 */
84static int pdd = 8;
85module_param(pdd, int, 0);
86MODULE_PARM_DESC(pdd, "Set pen detect comparator threshold");
87
88/*
89 * Set adc mask function.
90 *
91 * Sources of glitch noise, such as signals driving an LCD display, may feed
92 * through to the touch screen plates and affect measurement accuracy. In
93 * order to minimise this, a signal may be applied to the MASK pin to delay or
94 * synchronise the sampling.
95 *
96 * 0 = No delay or sync
97 * 1 = High on pin stops conversions
98 * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
99 * 3 = Edge triggered, edge on pin starts conversion after delay param
100 */
101static int mask;
102module_param(mask, int, 0);
103MODULE_PARM_DESC(mask, "Set adc mask function.");
104
105/*
106 * ADC sample delay times in uS
107 */
108static const int delay_table[] = {
109 21, /* 1 AC97 Link frames */
110 42, /* 2 */
111 84, /* 4 */
112 167, /* 8 */
113 333, /* 16 */
114 667, /* 32 */
115 1000, /* 48 */
116 1333, /* 64 */
117 2000, /* 96 */
118 2667, /* 128 */
119 3333, /* 160 */
120 4000, /* 192 */
121 4667, /* 224 */
122 5333, /* 256 */
123 6000, /* 288 */
124 0 /* No delay, switch matrix always on */
125};
126
127/*
128 * Delay after issuing a POLL command.
129 *
130 * The delay is 3 AC97 link frames + the touchpanel settling delay
131 */
132static inline void poll_delay(int d)
133{
134 udelay(3 * AC97_LINK_FRAME + delay_table[d]);
135}
136
137/*
138 * set up the physical settings of the WM9705
139 */
140static void wm9705_phy_init(struct wm97xx *wm)
141{
142 u16 dig1 = 0, dig2 = WM97XX_RPR;
143
144 /*
145 * mute VIDEO and AUX as they share X and Y touchscreen
146 * inputs on the WM9705
147 */
148 wm97xx_reg_write(wm, AC97_AUX, 0x8000);
149 wm97xx_reg_write(wm, AC97_VIDEO, 0x8000);
150
151 /* touchpanel pressure current*/
152 if (pil == 2) {
153 dig2 |= WM9705_PIL;
154 dev_dbg(wm->dev,
155 "setting pressure measurement current to 400uA.");
156 } else if (pil)
157 dev_dbg(wm->dev,
158 "setting pressure measurement current to 200uA.");
159 if (!pil)
160 pressure = 0;
161
162 /* polling mode sample settling delay */
163 if (delay != 4) {
164 if (delay < 0 || delay > 15) {
165 dev_dbg(wm->dev, "supplied delay out of range.");
166 delay = 4;
167 }
168 }
169 dig1 &= 0xff0f;
170 dig1 |= WM97XX_DELAY(delay);
171 dev_dbg(wm->dev, "setting adc sample delay to %d u Secs.",
172 delay_table[delay]);
173
174 /* WM9705 pdd */
175 dig2 |= (pdd & 0x000f);
176 dev_dbg(wm->dev, "setting pdd to Vmid/%d", 1 - (pdd & 0x000f));
177
178 /* mask */
179 dig2 |= ((mask & 0x3) << 4);
180
181 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
182 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
183}
184
185static void wm9705_dig_enable(struct wm97xx *wm, int enable)
186{
187 if (enable) {
188 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
189 wm->dig[2] | WM97XX_PRP_DET_DIG);
190 wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
191 } else
192 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
193 wm->dig[2] & ~WM97XX_PRP_DET_DIG);
194}
195
196static void wm9705_aux_prepare(struct wm97xx *wm)
197{
198 memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
199 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0);
200 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG);
201}
202
203static void wm9705_dig_restore(struct wm97xx *wm)
204{
205 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]);
206 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]);
207}
208
209static inline int is_pden(struct wm97xx *wm)
210{
211 return wm->dig[2] & WM9705_PDEN;
212}
213
214/*
215 * Read a sample from the WM9705 adc in polling mode.
216 */
217static int wm9705_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
218{
219 int timeout = 5 * delay;
220
221 if (!wm->pen_probably_down) {
222 u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
223 if (!(data & WM97XX_PEN_DOWN))
224 return RC_PENUP;
225 wm->pen_probably_down = 1;
226 }
227
228 /* set up digitiser */
229 if (adcsel & 0x8000)
230 adcsel = ((adcsel & 0x7fff) + 3) << 12;
231
232 if (wm->mach_ops && wm->mach_ops->pre_sample)
233 wm->mach_ops->pre_sample(adcsel);
234 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1,
235 adcsel | WM97XX_POLL | WM97XX_DELAY(delay));
236
237 /* wait 3 AC97 time slots + delay for conversion */
238 poll_delay(delay);
239
240 /* wait for POLL to go low */
241 while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL)
242 && timeout) {
243 udelay(AC97_LINK_FRAME);
244 timeout--;
245 }
246
247 if (timeout == 0) {
248 /* If PDEN is set, we can get a timeout when pen goes up */
249 if (is_pden(wm))
250 wm->pen_probably_down = 0;
251 else
252 dev_dbg(wm->dev, "adc sample timeout");
253 return RC_PENUP;
254 }
255
256 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
257 if (wm->mach_ops && wm->mach_ops->post_sample)
258 wm->mach_ops->post_sample(adcsel);
259
260 /* check we have correct sample */
261 if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) {
262 dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
263 *sample & WM97XX_ADCSEL_MASK);
264 return RC_PENUP;
265 }
266
267 if (!(*sample & WM97XX_PEN_DOWN)) {
268 wm->pen_probably_down = 0;
269 return RC_PENUP;
270 }
271
272 return RC_VALID;
273}
274
275/*
276 * Sample the WM9705 touchscreen in polling mode
277 */
278static int wm9705_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
279{
280 int rc;
281
282 rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_X, &data->x);
283 if (rc != RC_VALID)
284 return rc;
285 rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y);
286 if (rc != RC_VALID)
287 return rc;
288 if (pil) {
289 rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p);
290 if (rc != RC_VALID)
291 return rc;
292 } else
293 data->p = DEFAULT_PRESSURE;
294
295 return RC_VALID;
296}
297
298/*
299 * Enable WM9705 continuous mode, i.e. touch data is streamed across
300 * an AC97 slot
301 */
302static int wm9705_acc_enable(struct wm97xx *wm, int enable)
303{
304 u16 dig1, dig2;
305 int ret = 0;
306
307 dig1 = wm->dig[1];
308 dig2 = wm->dig[2];
309
310 if (enable) {
311 /* continous mode */
312 if (wm->mach_ops->acc_startup &&
313 (ret = wm->mach_ops->acc_startup(wm)) < 0)
314 return ret;
315 dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK |
316 WM97XX_DELAY_MASK | WM97XX_SLT_MASK);
317 dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN |
318 WM97XX_DELAY(delay) |
319 WM97XX_SLT(wm->acc_slot) |
320 WM97XX_RATE(wm->acc_rate);
321 if (pil)
322 dig1 |= WM97XX_ADCSEL_PRES;
323 dig2 |= WM9705_PDEN;
324 } else {
325 dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN);
326 dig2 &= ~WM9705_PDEN;
327 if (wm->mach_ops->acc_shutdown)
328 wm->mach_ops->acc_shutdown(wm);
329 }
330
331 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
332 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
333
334 return ret;
335}
336
337struct wm97xx_codec_drv wm9705_codec = {
338 .id = WM9705_ID2,
339 .name = "wm9705",
340 .poll_sample = wm9705_poll_sample,
341 .poll_touch = wm9705_poll_touch,
342 .acc_enable = wm9705_acc_enable,
343 .phy_init = wm9705_phy_init,
344 .dig_enable = wm9705_dig_enable,
345 .dig_restore = wm9705_dig_restore,
346 .aux_prepare = wm9705_aux_prepare,
347};
348EXPORT_SYMBOL_GPL(wm9705_codec);
349
350/* Module information */
351MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
352MODULE_DESCRIPTION("WM9705 Touch Screen Driver");
353MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
new file mode 100644
index 000000000000..0b6e4cfa6a21
--- /dev/null
+++ b/drivers/input/touchscreen/wm9712.c
@@ -0,0 +1,462 @@
1/*
2 * wm9712.c -- Codec driver for Wolfson WM9712 AC97 Codecs.
3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/bitops.h>
25#include <linux/wm97xx.h>
26
27#define TS_NAME "wm97xx"
28#define WM9712_VERSION "1.00"
29#define DEFAULT_PRESSURE 0xb0c0
30
31/*
32 * Module parameters
33 */
34
35/*
36 * Set internal pull up for pen detect.
37 *
38 * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
39 * i.e. pull up resistance = 64k Ohms / rpu.
40 *
41 * Adjust this value if you are having problems with pen detect not
42 * detecting any down event.
43 */
44static int rpu = 8;
45module_param(rpu, int, 0);
46MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
47
48/*
49 * Set current used for pressure measurement.
50 *
51 * Set pil = 2 to use 400uA
52 * pil = 1 to use 200uA and
53 * pil = 0 to disable pressure measurement.
54 *
55 * This is used to increase the range of values returned by the adc
56 * when measureing touchpanel pressure.
57 */
58static int pil;
59module_param(pil, int, 0);
60MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
61
62/*
63 * Set threshold for pressure measurement.
64 *
65 * Pen down pressure below threshold is ignored.
66 */
67static int pressure = DEFAULT_PRESSURE & 0xfff;
68module_param(pressure, int, 0);
69MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
70
71/*
72 * Set adc sample delay.
73 *
74 * For accurate touchpanel measurements, some settling time may be
75 * required between the switch matrix applying a voltage across the
76 * touchpanel plate and the ADC sampling the signal.
77 *
78 * This delay can be set by setting delay = n, where n is the array
79 * position of the delay in the array delay_table below.
80 * Long delays > 1ms are supported for completeness, but are not
81 * recommended.
82 */
83static int delay = 3;
84module_param(delay, int, 0);
85MODULE_PARM_DESC(delay, "Set adc sample delay.");
86
87/*
88 * Set five_wire = 1 to use a 5 wire touchscreen.
89 *
90 * NOTE: Five wire mode does not allow for readback of pressure.
91 */
92static int five_wire;
93module_param(five_wire, int, 0);
94MODULE_PARM_DESC(five_wire, "Set to '1' to use 5-wire touchscreen.");
95
96/*
97 * Set adc mask function.
98 *
99 * Sources of glitch noise, such as signals driving an LCD display, may feed
100 * through to the touch screen plates and affect measurement accuracy. In
101 * order to minimise this, a signal may be applied to the MASK pin to delay or
102 * synchronise the sampling.
103 *
104 * 0 = No delay or sync
105 * 1 = High on pin stops conversions
106 * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
107 * 3 = Edge triggered, edge on pin starts conversion after delay param
108 */
109static int mask;
110module_param(mask, int, 0);
111MODULE_PARM_DESC(mask, "Set adc mask function.");
112
113/*
114 * Coordinate Polling Enable.
115 *
116 * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together
117 * for every poll.
118 */
119static int coord;
120module_param(coord, int, 0);
121MODULE_PARM_DESC(coord, "Polling coordinate mode");
122
123/*
124 * ADC sample delay times in uS
125 */
126static const int delay_table[] = {
127 21, /* 1 AC97 Link frames */
128 42, /* 2 */
129 84, /* 4 */
130 167, /* 8 */
131 333, /* 16 */
132 667, /* 32 */
133 1000, /* 48 */
134 1333, /* 64 */
135 2000, /* 96 */
136 2667, /* 128 */
137 3333, /* 160 */
138 4000, /* 192 */
139 4667, /* 224 */
140 5333, /* 256 */
141 6000, /* 288 */
142 0 /* No delay, switch matrix always on */
143};
144
145/*
146 * Delay after issuing a POLL command.
147 *
148 * The delay is 3 AC97 link frames + the touchpanel settling delay
149 */
150static inline void poll_delay(int d)
151{
152 udelay(3 * AC97_LINK_FRAME + delay_table[d]);
153}
154
155/*
156 * set up the physical settings of the WM9712
157 */
158static void wm9712_phy_init(struct wm97xx *wm)
159{
160 u16 dig1 = 0;
161 u16 dig2 = WM97XX_RPR | WM9712_RPU(1);
162
163 /* WM9712 rpu */
164 if (rpu) {
165 dig2 &= 0xffc0;
166 dig2 |= WM9712_RPU(rpu);
167 dev_dbg(wm->dev, "setting pen detect pull-up to %d Ohms",
168 64000 / rpu);
169 }
170
171 /* touchpanel pressure current*/
172 if (pil == 2) {
173 dig2 |= WM9712_PIL;
174 dev_dbg(wm->dev,
175 "setting pressure measurement current to 400uA.");
176 } else if (pil)
177 dev_dbg(wm->dev,
178 "setting pressure measurement current to 200uA.");
179 if (!pil)
180 pressure = 0;
181
182 /* WM9712 five wire */
183 if (five_wire) {
184 dig2 |= WM9712_45W;
185 dev_dbg(wm->dev, "setting 5-wire touchscreen mode.");
186 }
187
188 /* polling mode sample settling delay */
189 if (delay < 0 || delay > 15) {
190 dev_dbg(wm->dev, "supplied delay out of range.");
191 delay = 4;
192 }
193 dig1 &= 0xff0f;
194 dig1 |= WM97XX_DELAY(delay);
195 dev_dbg(wm->dev, "setting adc sample delay to %d u Secs.",
196 delay_table[delay]);
197
198 /* mask */
199 dig2 |= ((mask & 0x3) << 6);
200 if (mask) {
201 u16 reg;
202 /* Set GPIO4 as Mask Pin*/
203 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
204 wm97xx_reg_write(wm, AC97_MISC_AFE, reg | WM97XX_GPIO_4);
205 reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
206 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg | WM97XX_GPIO_4);
207 }
208
209 /* wait - coord mode */
210 if (coord)
211 dig2 |= WM9712_WAIT;
212
213 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
214 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
215}
216
217static void wm9712_dig_enable(struct wm97xx *wm, int enable)
218{
219 u16 dig2 = wm->dig[2];
220
221 if (enable) {
222 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
223 dig2 | WM97XX_PRP_DET_DIG);
224 wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
225 } else
226 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
227 dig2 & ~WM97XX_PRP_DET_DIG);
228}
229
230static void wm9712_aux_prepare(struct wm97xx *wm)
231{
232 memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
233 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0);
234 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG);
235}
236
237static void wm9712_dig_restore(struct wm97xx *wm)
238{
239 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]);
240 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]);
241}
242
243static inline int is_pden(struct wm97xx *wm)
244{
245 return wm->dig[2] & WM9712_PDEN;
246}
247
248/*
249 * Read a sample from the WM9712 adc in polling mode.
250 */
251static int wm9712_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
252{
253 int timeout = 5 * delay;
254
255 if (!wm->pen_probably_down) {
256 u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
257 if (!(data & WM97XX_PEN_DOWN))
258 return RC_PENUP;
259 wm->pen_probably_down = 1;
260 }
261
262 /* set up digitiser */
263 if (adcsel & 0x8000)
264 adcsel = ((adcsel & 0x7fff) + 3) << 12;
265
266 if (wm->mach_ops && wm->mach_ops->pre_sample)
267 wm->mach_ops->pre_sample(adcsel);
268 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1,
269 adcsel | WM97XX_POLL | WM97XX_DELAY(delay));
270
271 /* wait 3 AC97 time slots + delay for conversion */
272 poll_delay(delay);
273
274 /* wait for POLL to go low */
275 while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL)
276 && timeout) {
277 udelay(AC97_LINK_FRAME);
278 timeout--;
279 }
280
281 if (timeout <= 0) {
282 /* If PDEN is set, we can get a timeout when pen goes up */
283 if (is_pden(wm))
284 wm->pen_probably_down = 0;
285 else
286 dev_dbg(wm->dev, "adc sample timeout");
287 return RC_PENUP;
288 }
289
290 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
291 if (wm->mach_ops && wm->mach_ops->post_sample)
292 wm->mach_ops->post_sample(adcsel);
293
294 /* check we have correct sample */
295 if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) {
296 dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
297 *sample & WM97XX_ADCSEL_MASK);
298 return RC_PENUP;
299 }
300
301 if (!(*sample & WM97XX_PEN_DOWN)) {
302 wm->pen_probably_down = 0;
303 return RC_PENUP;
304 }
305
306 return RC_VALID;
307}
308
309/*
310 * Read a coord from the WM9712 adc in polling mode.
311 */
312static int wm9712_poll_coord(struct wm97xx *wm, struct wm97xx_data *data)
313{
314 int timeout = 5 * delay;
315
316 if (!wm->pen_probably_down) {
317 u16 data_rd = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
318 if (!(data_rd & WM97XX_PEN_DOWN))
319 return RC_PENUP;
320 wm->pen_probably_down = 1;
321 }
322
323 /* set up digitiser */
324 if (wm->mach_ops && wm->mach_ops->pre_sample)
325 wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
326
327 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1,
328 WM97XX_COO | WM97XX_POLL | WM97XX_DELAY(delay));
329
330 /* wait 3 AC97 time slots + delay for conversion and read x */
331 poll_delay(delay);
332 data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
333 /* wait for POLL to go low */
334 while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL)
335 && timeout) {
336 udelay(AC97_LINK_FRAME);
337 timeout--;
338 }
339
340 if (timeout <= 0) {
341 /* If PDEN is set, we can get a timeout when pen goes up */
342 if (is_pden(wm))
343 wm->pen_probably_down = 0;
344 else
345 dev_dbg(wm->dev, "adc sample timeout");
346 return RC_PENUP;
347 }
348
349 /* read back y data */
350 data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
351 if (pil)
352 data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
353 else
354 data->p = DEFAULT_PRESSURE;
355
356 if (wm->mach_ops && wm->mach_ops->post_sample)
357 wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
358
359 /* check we have correct sample */
360 if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y))
361 goto err;
362 if (pil && !(data->p & WM97XX_ADCSEL_PRES))
363 goto err;
364
365 if (!(data->x & WM97XX_PEN_DOWN) || !(data->y & WM97XX_PEN_DOWN)) {
366 wm->pen_probably_down = 0;
367 return RC_PENUP;
368 }
369 return RC_VALID;
370err:
371 return 0;
372}
373
374/*
375 * Sample the WM9712 touchscreen in polling mode
376 */
377static int wm9712_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
378{
379 int rc;
380
381 if (coord) {
382 rc = wm9712_poll_coord(wm, data);
383 if (rc != RC_VALID)
384 return rc;
385 } else {
386 rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_X, &data->x);
387 if (rc != RC_VALID)
388 return rc;
389
390 rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y);
391 if (rc != RC_VALID)
392 return rc;
393
394 if (pil && !five_wire) {
395 rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_PRES,
396 &data->p);
397 if (rc != RC_VALID)
398 return rc;
399 } else
400 data->p = DEFAULT_PRESSURE;
401 }
402 return RC_VALID;
403}
404
405/*
406 * Enable WM9712 continuous mode, i.e. touch data is streamed across
407 * an AC97 slot
408 */
409static int wm9712_acc_enable(struct wm97xx *wm, int enable)
410{
411 u16 dig1, dig2;
412 int ret = 0;
413
414 dig1 = wm->dig[1];
415 dig2 = wm->dig[2];
416
417 if (enable) {
418 /* continous mode */
419 if (wm->mach_ops->acc_startup) {
420 ret = wm->mach_ops->acc_startup(wm);
421 if (ret < 0)
422 return ret;
423 }
424 dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK |
425 WM97XX_DELAY_MASK | WM97XX_SLT_MASK);
426 dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN |
427 WM97XX_DELAY(delay) |
428 WM97XX_SLT(wm->acc_slot) |
429 WM97XX_RATE(wm->acc_rate);
430 if (pil)
431 dig1 |= WM97XX_ADCSEL_PRES;
432 dig2 |= WM9712_PDEN;
433 } else {
434 dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN);
435 dig2 &= ~WM9712_PDEN;
436 if (wm->mach_ops->acc_shutdown)
437 wm->mach_ops->acc_shutdown(wm);
438 }
439
440 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
441 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
442
443 return 0;
444}
445
446struct wm97xx_codec_drv wm9712_codec = {
447 .id = WM9712_ID2,
448 .name = "wm9712",
449 .poll_sample = wm9712_poll_sample,
450 .poll_touch = wm9712_poll_touch,
451 .acc_enable = wm9712_acc_enable,
452 .phy_init = wm9712_phy_init,
453 .dig_enable = wm9712_dig_enable,
454 .dig_restore = wm9712_dig_restore,
455 .aux_prepare = wm9712_aux_prepare,
456};
457EXPORT_SYMBOL_GPL(wm9712_codec);
458
459/* Module information */
460MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
461MODULE_DESCRIPTION("WM9712 Touch Screen Driver");
462MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
new file mode 100644
index 000000000000..01278bd7e65c
--- /dev/null
+++ b/drivers/input/touchscreen/wm9713.c
@@ -0,0 +1,460 @@
1/*
2 * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec.
3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/bitops.h>
25#include <linux/wm97xx.h>
26
27#define TS_NAME "wm97xx"
28#define WM9713_VERSION "1.00"
29#define DEFAULT_PRESSURE 0xb0c0
30
31/*
32 * Module parameters
33 */
34
35/*
36 * Set internal pull up for pen detect.
37 *
38 * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
39 * i.e. pull up resistance = 64k Ohms / rpu.
40 *
41 * Adjust this value if you are having problems with pen detect not
42 * detecting any down event.
43 */
44static int rpu = 8;
45module_param(rpu, int, 0);
46MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
47
48/*
49 * Set current used for pressure measurement.
50 *
51 * Set pil = 2 to use 400uA
52 * pil = 1 to use 200uA and
53 * pil = 0 to disable pressure measurement.
54 *
55 * This is used to increase the range of values returned by the adc
56 * when measureing touchpanel pressure.
57 */
58static int pil;
59module_param(pil, int, 0);
60MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
61
62/*
63 * Set threshold for pressure measurement.
64 *
65 * Pen down pressure below threshold is ignored.
66 */
67static int pressure = DEFAULT_PRESSURE & 0xfff;
68module_param(pressure, int, 0);
69MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
70
71/*
72 * Set adc sample delay.
73 *
74 * For accurate touchpanel measurements, some settling time may be
75 * required between the switch matrix applying a voltage across the
76 * touchpanel plate and the ADC sampling the signal.
77 *
78 * This delay can be set by setting delay = n, where n is the array
79 * position of the delay in the array delay_table below.
80 * Long delays > 1ms are supported for completeness, but are not
81 * recommended.
82 */
83static int delay = 4;
84module_param(delay, int, 0);
85MODULE_PARM_DESC(delay, "Set adc sample delay.");
86
87/*
88 * Set adc mask function.
89 *
90 * Sources of glitch noise, such as signals driving an LCD display, may feed
91 * through to the touch screen plates and affect measurement accuracy. In
92 * order to minimise this, a signal may be applied to the MASK pin to delay or
93 * synchronise the sampling.
94 *
95 * 0 = No delay or sync
96 * 1 = High on pin stops conversions
97 * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
98 * 3 = Edge triggered, edge on pin starts conversion after delay param
99 */
100static int mask;
101module_param(mask, int, 0);
102MODULE_PARM_DESC(mask, "Set adc mask function.");
103
104/*
105 * Coordinate Polling Enable.
106 *
107 * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together
108 * for every poll.
109 */
110static int coord;
111module_param(coord, int, 0);
112MODULE_PARM_DESC(coord, "Polling coordinate mode");
113
114/*
115 * ADC sample delay times in uS
116 */
117static const int delay_table[] = {
118 21, /* 1 AC97 Link frames */
119 42, /* 2 */
120 84, /* 4 */
121 167, /* 8 */
122 333, /* 16 */
123 667, /* 32 */
124 1000, /* 48 */
125 1333, /* 64 */
126 2000, /* 96 */
127 2667, /* 128 */
128 3333, /* 160 */
129 4000, /* 192 */
130 4667, /* 224 */
131 5333, /* 256 */
132 6000, /* 288 */
133 0 /* No delay, switch matrix always on */
134};
135
136/*
137 * Delay after issuing a POLL command.
138 *
139 * The delay is 3 AC97 link frames + the touchpanel settling delay
140 */
141static inline void poll_delay(int d)
142{
143 udelay(3 * AC97_LINK_FRAME + delay_table[d]);
144}
145
146/*
147 * set up the physical settings of the WM9713
148 */
149static void wm9713_phy_init(struct wm97xx *wm)
150{
151 u16 dig1 = 0, dig2, dig3;
152
153 /* default values */
154 dig2 = WM97XX_DELAY(4) | WM97XX_SLT(5);
155 dig3 = WM9712_RPU(1);
156
157 /* rpu */
158 if (rpu) {
159 dig3 &= 0xffc0;
160 dig3 |= WM9712_RPU(rpu);
161 dev_info(wm->dev, "setting pen detect pull-up to %d Ohms\n",
162 64000 / rpu);
163 }
164
165 /* touchpanel pressure */
166 if (pil == 2) {
167 dig3 |= WM9712_PIL;
168 dev_info(wm->dev,
169 "setting pressure measurement current to 400uA.");
170 } else if (pil)
171 dev_info(wm->dev,
172 "setting pressure measurement current to 200uA.");
173 if (!pil)
174 pressure = 0;
175
176 /* sample settling delay */
177 if (delay < 0 || delay > 15) {
178 dev_info(wm->dev, "supplied delay out of range.");
179 delay = 4;
180 dev_info(wm->dev, "setting adc sample delay to %d u Secs.",
181 delay_table[delay]);
182 }
183 dig2 &= 0xff0f;
184 dig2 |= WM97XX_DELAY(delay);
185
186 /* mask */
187 dig3 |= ((mask & 0x3) << 4);
188 if (coord)
189 dig3 |= WM9713_WAIT;
190
191 wm->misc = wm97xx_reg_read(wm, 0x5a);
192
193 wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1);
194 wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2);
195 wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3);
196 wm97xx_reg_write(wm, AC97_GPIO_STICKY, 0x0);
197}
198
199static void wm9713_dig_enable(struct wm97xx *wm, int enable)
200{
201 u16 val;
202
203 if (enable) {
204 val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
205 wm97xx_reg_write(wm, AC97_EXTENDED_MID, val & 0x7fff);
206 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] |
207 WM97XX_PRP_DET_DIG);
208 wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
209 } else {
210 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] &
211 ~WM97XX_PRP_DET_DIG);
212 val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
213 wm97xx_reg_write(wm, AC97_EXTENDED_MID, val | 0x8000);
214 }
215}
216
217static void wm9713_dig_restore(struct wm97xx *wm)
218{
219 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig_save[0]);
220 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig_save[1]);
221 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig_save[2]);
222}
223
224static void wm9713_aux_prepare(struct wm97xx *wm)
225{
226 memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
227 wm97xx_reg_write(wm, AC97_WM9713_DIG1, 0);
228 wm97xx_reg_write(wm, AC97_WM9713_DIG2, 0);
229 wm97xx_reg_write(wm, AC97_WM9713_DIG3, WM97XX_PRP_DET_DIG);
230}
231
232static inline int is_pden(struct wm97xx *wm)
233{
234 return wm->dig[2] & WM9713_PDEN;
235}
236
237/*
238 * Read a sample from the WM9713 adc in polling mode.
239 */
240static int wm9713_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
241{
242 u16 dig1;
243 int timeout = 5 * delay;
244
245 if (!wm->pen_probably_down) {
246 u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
247 if (!(data & WM97XX_PEN_DOWN))
248 return RC_PENUP;
249 wm->pen_probably_down = 1;
250 }
251
252 /* set up digitiser */
253 if (adcsel & 0x8000)
254 adcsel = 1 << ((adcsel & 0x7fff) + 3);
255
256 dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
257 dig1 &= ~WM9713_ADCSEL_MASK;
258
259 if (wm->mach_ops && wm->mach_ops->pre_sample)
260 wm->mach_ops->pre_sample(adcsel);
261 wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | adcsel | WM9713_POLL);
262
263 /* wait 3 AC97 time slots + delay for conversion */
264 poll_delay(delay);
265
266 /* wait for POLL to go low */
267 while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) &&
268 timeout) {
269 udelay(AC97_LINK_FRAME);
270 timeout--;
271 }
272
273 if (timeout <= 0) {
274 /* If PDEN is set, we can get a timeout when pen goes up */
275 if (is_pden(wm))
276 wm->pen_probably_down = 0;
277 else
278 dev_dbg(wm->dev, "adc sample timeout");
279 return RC_PENUP;
280 }
281
282 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
283 if (wm->mach_ops && wm->mach_ops->post_sample)
284 wm->mach_ops->post_sample(adcsel);
285
286 /* check we have correct sample */
287 if ((*sample & WM97XX_ADCSRC_MASK) != ffs(adcsel >> 1) << 12) {
288 dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
289 *sample & WM97XX_ADCSRC_MASK);
290 return RC_PENUP;
291 }
292
293 if (!(*sample & WM97XX_PEN_DOWN)) {
294 wm->pen_probably_down = 0;
295 return RC_PENUP;
296 }
297
298 return RC_VALID;
299}
300
301/*
302 * Read a coordinate from the WM9713 adc in polling mode.
303 */
304static int wm9713_poll_coord(struct wm97xx *wm, struct wm97xx_data *data)
305{
306 u16 dig1;
307 int timeout = 5 * delay;
308
309 if (!wm->pen_probably_down) {
310 u16 val = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
311 if (!(val & WM97XX_PEN_DOWN))
312 return RC_PENUP;
313 wm->pen_probably_down = 1;
314 }
315
316 /* set up digitiser */
317 dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
318 dig1 &= ~WM9713_ADCSEL_MASK;
319 if (pil)
320 dig1 |= WM9713_ADCSEL_PRES;
321
322 if (wm->mach_ops && wm->mach_ops->pre_sample)
323 wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
324 wm97xx_reg_write(wm, AC97_WM9713_DIG1,
325 dig1 | WM9713_POLL | WM9713_COO);
326
327 /* wait 3 AC97 time slots + delay for conversion */
328 poll_delay(delay);
329 data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
330 /* wait for POLL to go low */
331 while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL)
332 && timeout) {
333 udelay(AC97_LINK_FRAME);
334 timeout--;
335 }
336
337 if (timeout <= 0) {
338 /* If PDEN is set, we can get a timeout when pen goes up */
339 if (is_pden(wm))
340 wm->pen_probably_down = 0;
341 else
342 dev_dbg(wm->dev, "adc sample timeout");
343 return RC_PENUP;
344 }
345
346 /* read back data */
347 data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
348 if (pil)
349 data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
350 else
351 data->p = DEFAULT_PRESSURE;
352
353 if (wm->mach_ops && wm->mach_ops->post_sample)
354 wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
355
356 /* check we have correct sample */
357 if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y))
358 goto err;
359 if (pil && !(data->p & WM97XX_ADCSEL_PRES))
360 goto err;
361
362 if (!(data->x & WM97XX_PEN_DOWN) || !(data->y & WM97XX_PEN_DOWN)) {
363 wm->pen_probably_down = 0;
364 return RC_PENUP;
365 }
366 return RC_VALID;
367err:
368 return 0;
369}
370
371/*
372 * Sample the WM9713 touchscreen in polling mode
373 */
374static int wm9713_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
375{
376 int rc;
377
378 if (coord) {
379 rc = wm9713_poll_coord(wm, data);
380 if (rc != RC_VALID)
381 return rc;
382 } else {
383 rc = wm9713_poll_sample(wm, WM9713_ADCSEL_X, &data->x);
384 if (rc != RC_VALID)
385 return rc;
386 rc = wm9713_poll_sample(wm, WM9713_ADCSEL_Y, &data->y);
387 if (rc != RC_VALID)
388 return rc;
389 if (pil) {
390 rc = wm9713_poll_sample(wm, WM9713_ADCSEL_PRES,
391 &data->p);
392 if (rc != RC_VALID)
393 return rc;
394 } else
395 data->p = DEFAULT_PRESSURE;
396 }
397 return RC_VALID;
398}
399
400/*
401 * Enable WM9713 continuous mode, i.e. touch data is streamed across
402 * an AC97 slot
403 */
404static int wm9713_acc_enable(struct wm97xx *wm, int enable)
405{
406 u16 dig1, dig2, dig3;
407 int ret = 0;
408
409 dig1 = wm->dig[0];
410 dig2 = wm->dig[1];
411 dig3 = wm->dig[2];
412
413 if (enable) {
414 /* continous mode */
415 if (wm->mach_ops->acc_startup &&
416 (ret = wm->mach_ops->acc_startup(wm)) < 0)
417 return ret;
418
419 dig1 &= ~WM9713_ADCSEL_MASK;
420 dig1 |= WM9713_CTC | WM9713_COO | WM9713_ADCSEL_X |
421 WM9713_ADCSEL_Y;
422 if (pil)
423 dig1 |= WM9713_ADCSEL_PRES;
424 dig2 &= ~(WM97XX_DELAY_MASK | WM97XX_SLT_MASK |
425 WM97XX_CM_RATE_MASK);
426 dig2 |= WM97XX_SLEN | WM97XX_DELAY(delay) |
427 WM97XX_SLT(wm->acc_slot) | WM97XX_RATE(wm->acc_rate);
428 dig3 |= WM9713_PDEN;
429 } else {
430 dig1 &= ~(WM9713_CTC | WM9713_COO);
431 dig2 &= ~WM97XX_SLEN;
432 dig3 &= ~WM9713_PDEN;
433 if (wm->mach_ops->acc_shutdown)
434 wm->mach_ops->acc_shutdown(wm);
435 }
436
437 wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1);
438 wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2);
439 wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3);
440
441 return ret;
442}
443
444struct wm97xx_codec_drv wm9713_codec = {
445 .id = WM9713_ID2,
446 .name = "wm9713",
447 .poll_sample = wm9713_poll_sample,
448 .poll_touch = wm9713_poll_touch,
449 .acc_enable = wm9713_acc_enable,
450 .phy_init = wm9713_phy_init,
451 .dig_enable = wm9713_dig_enable,
452 .dig_restore = wm9713_dig_restore,
453 .aux_prepare = wm9713_aux_prepare,
454};
455EXPORT_SYMBOL_GPL(wm9713_codec);
456
457/* Module information */
458MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
459MODULE_DESCRIPTION("WM9713 Touch Screen Driver");
460MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
new file mode 100644
index 000000000000..e9c7ea46b6e3
--- /dev/null
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -0,0 +1,829 @@
1/*
2 * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712
3 * and WM9713 AC97 Codecs.
4 *
5 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
10 * Russell King <rmk@arm.linux.org.uk>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * Notes:
18 *
19 * Features:
20 * - supports WM9705, WM9712, WM9713
21 * - polling mode
22 * - continuous mode (arch-dependent)
23 * - adjustable rpu/dpp settings
24 * - adjustable pressure current
25 * - adjustable sample settle delay
26 * - 4 and 5 wire touchscreens (5 wire is WM9712 only)
27 * - pen down detection
28 * - battery monitor
29 * - sample AUX adcs
30 * - power management
31 * - codec GPIO
32 * - codec event notification
33 * Todo
34 * - Support for async sampling control for noisy LCDs.
35 *
36 */
37
38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/version.h>
41#include <linux/kernel.h>
42#include <linux/init.h>
43#include <linux/delay.h>
44#include <linux/string.h>
45#include <linux/proc_fs.h>
46#include <linux/pm.h>
47#include <linux/interrupt.h>
48#include <linux/bitops.h>
49#include <linux/workqueue.h>
50#include <linux/wm97xx.h>
51#include <linux/uaccess.h>
52#include <linux/io.h>
53
54#define TS_NAME "wm97xx"
55#define WM_CORE_VERSION "1.00"
56#define DEFAULT_PRESSURE 0xb0c0
57
58
59/*
60 * Touchscreen absolute values
61 *
62 * These parameters are used to help the input layer discard out of
63 * range readings and reduce jitter etc.
64 *
65 * o min, max:- indicate the min and max values your touch screen returns
66 * o fuzz:- use a higher number to reduce jitter
67 *
68 * The default values correspond to Mainstone II in QVGA mode
69 *
70 * Please read
71 * Documentation/input/input-programming.txt for more details.
72 */
73
74static int abs_x[3] = {350, 3900, 5};
75module_param_array(abs_x, int, NULL, 0);
76MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
77
78static int abs_y[3] = {320, 3750, 40};
79module_param_array(abs_y, int, NULL, 0);
80MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
81
82static int abs_p[3] = {0, 150, 4};
83module_param_array(abs_p, int, NULL, 0);
84MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
85
86/*
87 * wm97xx IO access, all IO locking done by AC97 layer
88 */
89int wm97xx_reg_read(struct wm97xx *wm, u16 reg)
90{
91 if (wm->ac97)
92 return wm->ac97->bus->ops->read(wm->ac97, reg);
93 else
94 return -1;
95}
96EXPORT_SYMBOL_GPL(wm97xx_reg_read);
97
98void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val)
99{
100 /* cache digitiser registers */
101 if (reg >= AC97_WM9713_DIG1 && reg <= AC97_WM9713_DIG3)
102 wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val;
103
104 /* cache gpio regs */
105 if (reg >= AC97_GPIO_CFG && reg <= AC97_MISC_AFE)
106 wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val;
107
108 /* wm9713 irq reg */
109 if (reg == 0x5a)
110 wm->misc = val;
111
112 if (wm->ac97)
113 wm->ac97->bus->ops->write(wm->ac97, reg, val);
114}
115EXPORT_SYMBOL_GPL(wm97xx_reg_write);
116
117/**
118 * wm97xx_read_aux_adc - Read the aux adc.
119 * @wm: wm97xx device.
120 * @adcsel: codec ADC to be read
121 *
122 * Reads the selected AUX ADC.
123 */
124
125int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel)
126{
127 int power_adc = 0, auxval;
128 u16 power = 0;
129
130 /* get codec */
131 mutex_lock(&wm->codec_mutex);
132
133 /* When the touchscreen is not in use, we may have to power up
134 * the AUX ADC before we can use sample the AUX inputs->
135 */
136 if (wm->id == WM9713_ID2 &&
137 (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) {
138 power_adc = 1;
139 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff);
140 }
141
142 /* Prepare the codec for AUX reading */
143 wm->codec->aux_prepare(wm);
144
145 /* Turn polling mode on to read AUX ADC */
146 wm->pen_probably_down = 1;
147 wm->codec->poll_sample(wm, adcsel, &auxval);
148
149 if (power_adc)
150 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000);
151
152 wm->codec->dig_restore(wm);
153
154 wm->pen_probably_down = 0;
155
156 mutex_unlock(&wm->codec_mutex);
157 return auxval & 0xfff;
158}
159EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc);
160
161/**
162 * wm97xx_get_gpio - Get the status of a codec GPIO.
163 * @wm: wm97xx device.
164 * @gpio: gpio
165 *
166 * Get the status of a codec GPIO pin
167 */
168
169enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio)
170{
171 u16 status;
172 enum wm97xx_gpio_status ret;
173
174 mutex_lock(&wm->codec_mutex);
175 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
176
177 if (status & gpio)
178 ret = WM97XX_GPIO_HIGH;
179 else
180 ret = WM97XX_GPIO_LOW;
181
182 mutex_unlock(&wm->codec_mutex);
183 return ret;
184}
185EXPORT_SYMBOL_GPL(wm97xx_get_gpio);
186
187/**
188 * wm97xx_set_gpio - Set the status of a codec GPIO.
189 * @wm: wm97xx device.
190 * @gpio: gpio
191 *
192 *
193 * Set the status of a codec GPIO pin
194 */
195
196void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
197 enum wm97xx_gpio_status status)
198{
199 u16 reg;
200
201 mutex_lock(&wm->codec_mutex);
202 reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
203
204 if (status & WM97XX_GPIO_HIGH)
205 reg |= gpio;
206 else
207 reg &= ~gpio;
208
209 if (wm->id == WM9712_ID2)
210 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1);
211 else
212 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg);
213 mutex_unlock(&wm->codec_mutex);
214}
215EXPORT_SYMBOL_GPL(wm97xx_set_gpio);
216
217/*
218 * Codec GPIO pin configuration, this sets pin direction, polarity,
219 * stickyness and wake up.
220 */
221void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, enum wm97xx_gpio_dir dir,
222 enum wm97xx_gpio_pol pol, enum wm97xx_gpio_sticky sticky,
223 enum wm97xx_gpio_wake wake)
224{
225 u16 reg;
226
227 mutex_lock(&wm->codec_mutex);
228 reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
229
230 if (pol == WM97XX_GPIO_POL_HIGH)
231 reg |= gpio;
232 else
233 reg &= ~gpio;
234
235 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg);
236 reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
237
238 if (sticky == WM97XX_GPIO_STICKY)
239 reg |= gpio;
240 else
241 reg &= ~gpio;
242
243 wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg);
244 reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
245
246 if (wake == WM97XX_GPIO_WAKE)
247 reg |= gpio;
248 else
249 reg &= ~gpio;
250
251 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg);
252 reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
253
254 if (dir == WM97XX_GPIO_IN)
255 reg |= gpio;
256 else
257 reg &= ~gpio;
258
259 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg);
260 mutex_unlock(&wm->codec_mutex);
261}
262EXPORT_SYMBOL_GPL(wm97xx_config_gpio);
263
264/*
265 * Configure the WM97XX_PRP value to use while system is suspended.
266 * If a value other than 0 is set then WM97xx pen detection will be
267 * left enabled in the configured mode while the system is in suspend,
268 * the device has users and suspend has not been disabled via the
269 * wakeup sysfs entries.
270 *
271 * @wm: WM97xx device to configure
272 * @mode: WM97XX_PRP value to configure while suspended
273 */
274void wm97xx_set_suspend_mode(struct wm97xx *wm, u16 mode)
275{
276 wm->suspend_mode = mode;
277 device_init_wakeup(&wm->input_dev->dev, mode != 0);
278}
279EXPORT_SYMBOL_GPL(wm97xx_set_suspend_mode);
280
281/*
282 * Handle a pen down interrupt.
283 */
284static void wm97xx_pen_irq_worker(struct work_struct *work)
285{
286 struct wm97xx *wm = container_of(work, struct wm97xx, pen_event_work);
287 int pen_was_down = wm->pen_is_down;
288
289 /* do we need to enable the touch panel reader */
290 if (wm->id == WM9705_ID2) {
291 if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) &
292 WM97XX_PEN_DOWN)
293 wm->pen_is_down = 1;
294 else
295 wm->pen_is_down = 0;
296 } else {
297 u16 status, pol;
298 mutex_lock(&wm->codec_mutex);
299 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
300 pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
301
302 if (WM97XX_GPIO_13 & pol & status) {
303 wm->pen_is_down = 1;
304 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol &
305 ~WM97XX_GPIO_13);
306 } else {
307 wm->pen_is_down = 0;
308 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol |
309 WM97XX_GPIO_13);
310 }
311
312 if (wm->id == WM9712_ID2)
313 wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status &
314 ~WM97XX_GPIO_13) << 1);
315 else
316 wm97xx_reg_write(wm, AC97_GPIO_STATUS, status &
317 ~WM97XX_GPIO_13);
318 mutex_unlock(&wm->codec_mutex);
319 }
320
321 /* If the system is not using continuous mode or it provides a
322 * pen down operation then we need to schedule polls while the
323 * pen is down. Otherwise the machine driver is responsible
324 * for scheduling reads.
325 */
326 if (!wm->mach_ops->acc_enabled || wm->mach_ops->acc_pen_down) {
327 if (wm->pen_is_down && !pen_was_down) {
328 /* Data is not availiable immediately on pen down */
329 queue_delayed_work(wm->ts_workq, &wm->ts_reader, 1);
330 }
331
332 /* Let ts_reader report the pen up for debounce. */
333 if (!wm->pen_is_down && pen_was_down)
334 wm->pen_is_down = 1;
335 }
336
337 if (!wm->pen_is_down && wm->mach_ops->acc_enabled)
338 wm->mach_ops->acc_pen_up(wm);
339
340 wm->mach_ops->irq_enable(wm, 1);
341}
342
343/*
344 * Codec PENDOWN irq handler
345 *
346 * We have to disable the codec interrupt in the handler because it
347 * can take upto 1ms to clear the interrupt source. We schedule a task
348 * in a work queue to do the actual interaction with the chip. The
349 * interrupt is then enabled again in the slow handler when the source
350 * has been cleared.
351 */
352static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id)
353{
354 struct wm97xx *wm = dev_id;
355
356 if (!work_pending(&wm->pen_event_work)) {
357 wm->mach_ops->irq_enable(wm, 0);
358 queue_work(wm->ts_workq, &wm->pen_event_work);
359 }
360
361 return IRQ_HANDLED;
362}
363
364/*
365 * initialise pen IRQ handler and workqueue
366 */
367static int wm97xx_init_pen_irq(struct wm97xx *wm)
368{
369 u16 reg;
370
371 /* If an interrupt is supplied an IRQ enable operation must also be
372 * provided. */
373 BUG_ON(!wm->mach_ops->irq_enable);
374
375 if (request_irq(wm->pen_irq, wm97xx_pen_interrupt,
376 IRQF_SHARED | IRQF_SAMPLE_RANDOM,
377 "wm97xx-pen", wm)) {
378 dev_err(wm->dev,
379 "Failed to register pen down interrupt, polling");
380 wm->pen_irq = 0;
381 return -EINVAL;
382 }
383
384 /* Configure GPIO as interrupt source on WM971x */
385 if (wm->id != WM9705_ID2) {
386 BUG_ON(!wm->mach_ops->irq_gpio);
387 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
388 wm97xx_reg_write(wm, AC97_MISC_AFE,
389 reg & ~(wm->mach_ops->irq_gpio));
390 reg = wm97xx_reg_read(wm, 0x5a);
391 wm97xx_reg_write(wm, 0x5a, reg & ~0x0001);
392 }
393
394 return 0;
395}
396
397static int wm97xx_read_samples(struct wm97xx *wm)
398{
399 struct wm97xx_data data;
400 int rc;
401
402 mutex_lock(&wm->codec_mutex);
403
404 if (wm->mach_ops && wm->mach_ops->acc_enabled)
405 rc = wm->mach_ops->acc_pen_down(wm);
406 else
407 rc = wm->codec->poll_touch(wm, &data);
408
409 if (rc & RC_PENUP) {
410 if (wm->pen_is_down) {
411 wm->pen_is_down = 0;
412 dev_dbg(wm->dev, "pen up\n");
413 input_report_abs(wm->input_dev, ABS_PRESSURE, 0);
414 input_sync(wm->input_dev);
415 } else if (!(rc & RC_AGAIN)) {
416 /* We need high frequency updates only while
417 * pen is down, the user never will be able to
418 * touch screen faster than a few times per
419 * second... On the other hand, when the user
420 * is actively working with the touchscreen we
421 * don't want to lose the quick response. So we
422 * will slowly increase sleep time after the
423 * pen is up and quicky restore it to ~one task
424 * switch when pen is down again.
425 */
426 if (wm->ts_reader_interval < HZ / 10)
427 wm->ts_reader_interval++;
428 }
429
430 } else if (rc & RC_VALID) {
431 dev_dbg(wm->dev,
432 "pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n",
433 data.x >> 12, data.x & 0xfff, data.y >> 12,
434 data.y & 0xfff, data.p >> 12, data.p & 0xfff);
435 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
436 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
437 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
438 input_sync(wm->input_dev);
439 wm->pen_is_down = 1;
440 wm->ts_reader_interval = wm->ts_reader_min_interval;
441 } else if (rc & RC_PENDOWN) {
442 dev_dbg(wm->dev, "pen down\n");
443 wm->pen_is_down = 1;
444 wm->ts_reader_interval = wm->ts_reader_min_interval;
445 }
446
447 mutex_unlock(&wm->codec_mutex);
448 return rc;
449}
450
451/*
452* The touchscreen sample reader.
453*/
454static void wm97xx_ts_reader(struct work_struct *work)
455{
456 int rc;
457 struct wm97xx *wm = container_of(work, struct wm97xx, ts_reader.work);
458
459 BUG_ON(!wm->codec);
460
461 do {
462 rc = wm97xx_read_samples(wm);
463 } while (rc & RC_AGAIN);
464
465 if (wm->pen_is_down || !wm->pen_irq)
466 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
467 wm->ts_reader_interval);
468}
469
470/**
471 * wm97xx_ts_input_open - Open the touch screen input device.
472 * @idev: Input device to be opened.
473 *
474 * Called by the input sub system to open a wm97xx touchscreen device.
475 * Starts the touchscreen thread and touch digitiser.
476 */
477static int wm97xx_ts_input_open(struct input_dev *idev)
478{
479 struct wm97xx *wm = input_get_drvdata(idev);
480
481 wm->ts_workq = create_singlethread_workqueue("kwm97xx");
482 if (wm->ts_workq == NULL) {
483 dev_err(wm->dev,
484 "Failed to create workqueue\n");
485 return -EINVAL;
486 }
487
488 /* start digitiser */
489 if (wm->mach_ops && wm->mach_ops->acc_enabled)
490 wm->codec->acc_enable(wm, 1);
491 wm->codec->dig_enable(wm, 1);
492
493 INIT_DELAYED_WORK(&wm->ts_reader, wm97xx_ts_reader);
494 INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker);
495
496 wm->ts_reader_min_interval = HZ >= 100 ? HZ / 100 : 1;
497 if (wm->ts_reader_min_interval < 1)
498 wm->ts_reader_min_interval = 1;
499 wm->ts_reader_interval = wm->ts_reader_min_interval;
500
501 wm->pen_is_down = 0;
502 if (wm->pen_irq)
503 wm97xx_init_pen_irq(wm);
504 else
505 dev_err(wm->dev, "No IRQ specified\n");
506
507 /* If we either don't have an interrupt for pen down events or
508 * failed to acquire it then we need to poll.
509 */
510 if (wm->pen_irq == 0)
511 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
512 wm->ts_reader_interval);
513
514 return 0;
515}
516
517/**
518 * wm97xx_ts_input_close - Close the touch screen input device.
519 * @idev: Input device to be closed.
520 *
521 * Called by the input sub system to close a wm97xx touchscreen
522 * device. Kills the touchscreen thread and stops the touch
523 * digitiser.
524 */
525
526static void wm97xx_ts_input_close(struct input_dev *idev)
527{
528 struct wm97xx *wm = input_get_drvdata(idev);
529 u16 reg;
530
531 if (wm->pen_irq) {
532 /* Return the interrupt to GPIO usage (disabling it) */
533 if (wm->id != WM9705_ID2) {
534 BUG_ON(!wm->mach_ops->irq_gpio);
535 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
536 wm97xx_reg_write(wm, AC97_MISC_AFE,
537 reg | wm->mach_ops->irq_gpio);
538 }
539
540 free_irq(wm->pen_irq, wm);
541 }
542
543 wm->pen_is_down = 0;
544
545 /* Balance out interrupt disables/enables */
546 if (cancel_work_sync(&wm->pen_event_work))
547 wm->mach_ops->irq_enable(wm, 1);
548
549 /* ts_reader rearms itself so we need to explicitly stop it
550 * before we destroy the workqueue.
551 */
552 cancel_delayed_work_sync(&wm->ts_reader);
553
554 destroy_workqueue(wm->ts_workq);
555
556 /* stop digitiser */
557 wm->codec->dig_enable(wm, 0);
558 if (wm->mach_ops && wm->mach_ops->acc_enabled)
559 wm->codec->acc_enable(wm, 0);
560}
561
562static int wm97xx_probe(struct device *dev)
563{
564 struct wm97xx *wm;
565 int ret = 0, id = 0;
566
567 wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL);
568 if (!wm)
569 return -ENOMEM;
570 mutex_init(&wm->codec_mutex);
571
572 wm->dev = dev;
573 dev->driver_data = wm;
574 wm->ac97 = to_ac97_t(dev);
575
576 /* check that we have a supported codec */
577 id = wm97xx_reg_read(wm, AC97_VENDOR_ID1);
578 if (id != WM97XX_ID1) {
579 dev_err(dev, "Device with vendor %04x is not a wm97xx\n", id);
580 ret = -ENODEV;
581 goto alloc_err;
582 }
583
584 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
585
586 dev_info(wm->dev, "detected a wm97%02x codec\n", wm->id & 0xff);
587
588 switch (wm->id & 0xff) {
589#ifdef CONFIG_TOUCHSCREEN_WM9705
590 case 0x05:
591 wm->codec = &wm9705_codec;
592 break;
593#endif
594#ifdef CONFIG_TOUCHSCREEN_WM9712
595 case 0x12:
596 wm->codec = &wm9712_codec;
597 break;
598#endif
599#ifdef CONFIG_TOUCHSCREEN_WM9713
600 case 0x13:
601 wm->codec = &wm9713_codec;
602 break;
603#endif
604 default:
605 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n",
606 wm->id & 0xff);
607 ret = -ENODEV;
608 goto alloc_err;
609 }
610
611 wm->input_dev = input_allocate_device();
612 if (wm->input_dev == NULL) {
613 ret = -ENOMEM;
614 goto alloc_err;
615 }
616
617 /* set up touch configuration */
618 wm->input_dev->name = "wm97xx touchscreen";
619 wm->input_dev->open = wm97xx_ts_input_open;
620 wm->input_dev->close = wm97xx_ts_input_close;
621 set_bit(EV_ABS, wm->input_dev->evbit);
622 set_bit(ABS_X, wm->input_dev->absbit);
623 set_bit(ABS_Y, wm->input_dev->absbit);
624 set_bit(ABS_PRESSURE, wm->input_dev->absbit);
625 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
626 abs_x[2], 0);
627 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
628 abs_y[2], 0);
629 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
630 abs_p[2], 0);
631 input_set_drvdata(wm->input_dev, wm);
632 wm->input_dev->dev.parent = dev;
633 ret = input_register_device(wm->input_dev);
634 if (ret < 0)
635 goto dev_alloc_err;
636
637 /* set up physical characteristics */
638 wm->codec->phy_init(wm);
639
640 /* load gpio cache */
641 wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG);
642 wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
643 wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
644 wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
645 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
646 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE);
647
648 /* register our battery device */
649 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1);
650 if (!wm->battery_dev) {
651 ret = -ENOMEM;
652 goto batt_err;
653 }
654 platform_set_drvdata(wm->battery_dev, wm);
655 wm->battery_dev->dev.parent = dev;
656 ret = platform_device_add(wm->battery_dev);
657 if (ret < 0)
658 goto batt_reg_err;
659
660 /* register our extended touch device (for machine specific
661 * extensions) */
662 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
663 if (!wm->touch_dev) {
664 ret = -ENOMEM;
665 goto touch_err;
666 }
667 platform_set_drvdata(wm->touch_dev, wm);
668 wm->touch_dev->dev.parent = dev;
669 ret = platform_device_add(wm->touch_dev);
670 if (ret < 0)
671 goto touch_reg_err;
672
673 return ret;
674
675 touch_reg_err:
676 platform_device_put(wm->touch_dev);
677 touch_err:
678 platform_device_unregister(wm->battery_dev);
679 wm->battery_dev = NULL;
680 batt_reg_err:
681 platform_device_put(wm->battery_dev);
682 batt_err:
683 input_unregister_device(wm->input_dev);
684 wm->input_dev = NULL;
685 dev_alloc_err:
686 input_free_device(wm->input_dev);
687 alloc_err:
688 kfree(wm);
689
690 return ret;
691}
692
693static int wm97xx_remove(struct device *dev)
694{
695 struct wm97xx *wm = dev_get_drvdata(dev);
696
697 platform_device_unregister(wm->battery_dev);
698 platform_device_unregister(wm->touch_dev);
699 input_unregister_device(wm->input_dev);
700 kfree(wm);
701
702 return 0;
703}
704
705#ifdef CONFIG_PM
706static int wm97xx_suspend(struct device *dev, pm_message_t state)
707{
708 struct wm97xx *wm = dev_get_drvdata(dev);
709 u16 reg;
710 int suspend_mode;
711
712 if (device_may_wakeup(&wm->input_dev->dev))
713 suspend_mode = wm->suspend_mode;
714 else
715 suspend_mode = 0;
716
717 if (wm->input_dev->users)
718 cancel_delayed_work_sync(&wm->ts_reader);
719
720 /* Power down the digitiser (bypassing the cache for resume) */
721 reg = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER2);
722 reg &= ~WM97XX_PRP_DET_DIG;
723 if (wm->input_dev->users)
724 reg |= suspend_mode;
725 wm->ac97->bus->ops->write(wm->ac97, AC97_WM97XX_DIGITISER2, reg);
726
727 /* WM9713 has an additional power bit - turn it off if there
728 * are no users or if suspend mode is zero. */
729 if (wm->id == WM9713_ID2 &&
730 (!wm->input_dev->users || !suspend_mode)) {
731 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) | 0x8000;
732 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
733 }
734
735 return 0;
736}
737
738static int wm97xx_resume(struct device *dev)
739{
740 struct wm97xx *wm = dev_get_drvdata(dev);
741
742 /* restore digitiser and gpios */
743 if (wm->id == WM9713_ID2) {
744 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]);
745 wm97xx_reg_write(wm, 0x5a, wm->misc);
746 if (wm->input_dev->users) {
747 u16 reg;
748 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) & 0x7fff;
749 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
750 }
751 }
752
753 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]);
754 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]);
755
756 wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]);
757 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]);
758 wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]);
759 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]);
760 wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]);
761 wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]);
762
763 if (wm->input_dev->users && !wm->pen_irq) {
764 wm->ts_reader_interval = wm->ts_reader_min_interval;
765 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
766 wm->ts_reader_interval);
767 }
768
769 return 0;
770}
771
772#else
773#define wm97xx_suspend NULL
774#define wm97xx_resume NULL
775#endif
776
777/*
778 * Machine specific operations
779 */
780int wm97xx_register_mach_ops(struct wm97xx *wm,
781 struct wm97xx_mach_ops *mach_ops)
782{
783 mutex_lock(&wm->codec_mutex);
784 if (wm->mach_ops) {
785 mutex_unlock(&wm->codec_mutex);
786 return -EINVAL;
787 }
788 wm->mach_ops = mach_ops;
789 mutex_unlock(&wm->codec_mutex);
790
791 return 0;
792}
793EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops);
794
795void wm97xx_unregister_mach_ops(struct wm97xx *wm)
796{
797 mutex_lock(&wm->codec_mutex);
798 wm->mach_ops = NULL;
799 mutex_unlock(&wm->codec_mutex);
800}
801EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops);
802
803static struct device_driver wm97xx_driver = {
804 .name = "ac97",
805 .bus = &ac97_bus_type,
806 .owner = THIS_MODULE,
807 .probe = wm97xx_probe,
808 .remove = wm97xx_remove,
809 .suspend = wm97xx_suspend,
810 .resume = wm97xx_resume,
811};
812
813static int __init wm97xx_init(void)
814{
815 return driver_register(&wm97xx_driver);
816}
817
818static void __exit wm97xx_exit(void)
819{
820 driver_unregister(&wm97xx_driver);
821}
822
823module_init(wm97xx_init);
824module_exit(wm97xx_exit);
825
826/* Module information */
827MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
828MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
829MODULE_LICENSE("GPL");
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c
new file mode 100644
index 000000000000..0f47f4697cdf
--- /dev/null
+++ b/drivers/input/xen-kbdfront.c
@@ -0,0 +1,340 @@
1/*
2 * Xen para-virtual input device
3 *
4 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
5 * Copyright (C) 2006-2008 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
6 *
7 * Based on linux/drivers/input/mouse/sermouse.c
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 */
13
14/*
15 * TODO:
16 *
17 * Switch to grant tables together with xen-fbfront.c.
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/module.h>
23#include <linux/input.h>
24#include <asm/xen/hypervisor.h>
25#include <xen/events.h>
26#include <xen/page.h>
27#include <xen/interface/io/fbif.h>
28#include <xen/interface/io/kbdif.h>
29#include <xen/xenbus.h>
30
31struct xenkbd_info {
32 struct input_dev *kbd;
33 struct input_dev *ptr;
34 struct xenkbd_page *page;
35 int irq;
36 struct xenbus_device *xbdev;
37 char phys[32];
38};
39
40static int xenkbd_remove(struct xenbus_device *);
41static int xenkbd_connect_backend(struct xenbus_device *, struct xenkbd_info *);
42static void xenkbd_disconnect_backend(struct xenkbd_info *);
43
44/*
45 * Note: if you need to send out events, see xenfb_do_update() for how
46 * to do that.
47 */
48
49static irqreturn_t input_handler(int rq, void *dev_id)
50{
51 struct xenkbd_info *info = dev_id;
52 struct xenkbd_page *page = info->page;
53 __u32 cons, prod;
54
55 prod = page->in_prod;
56 if (prod == page->in_cons)
57 return IRQ_HANDLED;
58 rmb(); /* ensure we see ring contents up to prod */
59 for (cons = page->in_cons; cons != prod; cons++) {
60 union xenkbd_in_event *event;
61 struct input_dev *dev;
62 event = &XENKBD_IN_RING_REF(page, cons);
63
64 dev = info->ptr;
65 switch (event->type) {
66 case XENKBD_TYPE_MOTION:
67 input_report_rel(dev, REL_X, event->motion.rel_x);
68 input_report_rel(dev, REL_Y, event->motion.rel_y);
69 break;
70 case XENKBD_TYPE_KEY:
71 dev = NULL;
72 if (test_bit(event->key.keycode, info->kbd->keybit))
73 dev = info->kbd;
74 if (test_bit(event->key.keycode, info->ptr->keybit))
75 dev = info->ptr;
76 if (dev)
77 input_report_key(dev, event->key.keycode,
78 event->key.pressed);
79 else
80 printk(KERN_WARNING
81 "xenkbd: unhandled keycode 0x%x\n",
82 event->key.keycode);
83 break;
84 case XENKBD_TYPE_POS:
85 input_report_abs(dev, ABS_X, event->pos.abs_x);
86 input_report_abs(dev, ABS_Y, event->pos.abs_y);
87 break;
88 }
89 if (dev)
90 input_sync(dev);
91 }
92 mb(); /* ensure we got ring contents */
93 page->in_cons = cons;
94 notify_remote_via_irq(info->irq);
95
96 return IRQ_HANDLED;
97}
98
99static int __devinit xenkbd_probe(struct xenbus_device *dev,
100 const struct xenbus_device_id *id)
101{
102 int ret, i;
103 struct xenkbd_info *info;
104 struct input_dev *kbd, *ptr;
105
106 info = kzalloc(sizeof(*info), GFP_KERNEL);
107 if (!info) {
108 xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
109 return -ENOMEM;
110 }
111 dev->dev.driver_data = info;
112 info->xbdev = dev;
113 info->irq = -1;
114 snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
115
116 info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
117 if (!info->page)
118 goto error_nomem;
119
120 /* keyboard */
121 kbd = input_allocate_device();
122 if (!kbd)
123 goto error_nomem;
124 kbd->name = "Xen Virtual Keyboard";
125 kbd->phys = info->phys;
126 kbd->id.bustype = BUS_PCI;
127 kbd->id.vendor = 0x5853;
128 kbd->id.product = 0xffff;
129 kbd->evbit[0] = BIT(EV_KEY);
130 for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
131 set_bit(i, kbd->keybit);
132 for (i = KEY_OK; i < KEY_MAX; i++)
133 set_bit(i, kbd->keybit);
134
135 ret = input_register_device(kbd);
136 if (ret) {
137 input_free_device(kbd);
138 xenbus_dev_fatal(dev, ret, "input_register_device(kbd)");
139 goto error;
140 }
141 info->kbd = kbd;
142
143 /* pointing device */
144 ptr = input_allocate_device();
145 if (!ptr)
146 goto error_nomem;
147 ptr->name = "Xen Virtual Pointer";
148 ptr->phys = info->phys;
149 ptr->id.bustype = BUS_PCI;
150 ptr->id.vendor = 0x5853;
151 ptr->id.product = 0xfffe;
152 ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
153 for (i = BTN_LEFT; i <= BTN_TASK; i++)
154 set_bit(i, ptr->keybit);
155 ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y);
156 input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0);
157 input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0);
158
159 ret = input_register_device(ptr);
160 if (ret) {
161 input_free_device(ptr);
162 xenbus_dev_fatal(dev, ret, "input_register_device(ptr)");
163 goto error;
164 }
165 info->ptr = ptr;
166
167 ret = xenkbd_connect_backend(dev, info);
168 if (ret < 0)
169 goto error;
170
171 return 0;
172
173 error_nomem:
174 ret = -ENOMEM;
175 xenbus_dev_fatal(dev, ret, "allocating device memory");
176 error:
177 xenkbd_remove(dev);
178 return ret;
179}
180
181static int xenkbd_resume(struct xenbus_device *dev)
182{
183 struct xenkbd_info *info = dev->dev.driver_data;
184
185 xenkbd_disconnect_backend(info);
186 memset(info->page, 0, PAGE_SIZE);
187 return xenkbd_connect_backend(dev, info);
188}
189
190static int xenkbd_remove(struct xenbus_device *dev)
191{
192 struct xenkbd_info *info = dev->dev.driver_data;
193
194 xenkbd_disconnect_backend(info);
195 if (info->kbd)
196 input_unregister_device(info->kbd);
197 if (info->ptr)
198 input_unregister_device(info->ptr);
199 free_page((unsigned long)info->page);
200 kfree(info);
201 return 0;
202}
203
204static int xenkbd_connect_backend(struct xenbus_device *dev,
205 struct xenkbd_info *info)
206{
207 int ret, evtchn;
208 struct xenbus_transaction xbt;
209
210 ret = xenbus_alloc_evtchn(dev, &evtchn);
211 if (ret)
212 return ret;
213 ret = bind_evtchn_to_irqhandler(evtchn, input_handler,
214 0, dev->devicetype, info);
215 if (ret < 0) {
216 xenbus_free_evtchn(dev, evtchn);
217 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
218 return ret;
219 }
220 info->irq = ret;
221
222 again:
223 ret = xenbus_transaction_start(&xbt);
224 if (ret) {
225 xenbus_dev_fatal(dev, ret, "starting transaction");
226 return ret;
227 }
228 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
229 virt_to_mfn(info->page));
230 if (ret)
231 goto error_xenbus;
232 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
233 evtchn);
234 if (ret)
235 goto error_xenbus;
236 ret = xenbus_transaction_end(xbt, 0);
237 if (ret) {
238 if (ret == -EAGAIN)
239 goto again;
240 xenbus_dev_fatal(dev, ret, "completing transaction");
241 return ret;
242 }
243
244 xenbus_switch_state(dev, XenbusStateInitialised);
245 return 0;
246
247 error_xenbus:
248 xenbus_transaction_end(xbt, 1);
249 xenbus_dev_fatal(dev, ret, "writing xenstore");
250 return ret;
251}
252
253static void xenkbd_disconnect_backend(struct xenkbd_info *info)
254{
255 if (info->irq >= 0)
256 unbind_from_irqhandler(info->irq, info);
257 info->irq = -1;
258}
259
260static void xenkbd_backend_changed(struct xenbus_device *dev,
261 enum xenbus_state backend_state)
262{
263 struct xenkbd_info *info = dev->dev.driver_data;
264 int ret, val;
265
266 switch (backend_state) {
267 case XenbusStateInitialising:
268 case XenbusStateInitialised:
269 case XenbusStateUnknown:
270 case XenbusStateClosed:
271 break;
272
273 case XenbusStateInitWait:
274InitWait:
275 ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
276 "feature-abs-pointer", "%d", &val);
277 if (ret < 0)
278 val = 0;
279 if (val) {
280 ret = xenbus_printf(XBT_NIL, info->xbdev->nodename,
281 "request-abs-pointer", "1");
282 if (ret)
283 printk(KERN_WARNING
284 "xenkbd: can't request abs-pointer");
285 }
286 xenbus_switch_state(dev, XenbusStateConnected);
287 break;
288
289 case XenbusStateConnected:
290 /*
291 * Work around xenbus race condition: If backend goes
292 * through InitWait to Connected fast enough, we can
293 * get Connected twice here.
294 */
295 if (dev->state != XenbusStateConnected)
296 goto InitWait; /* no InitWait seen yet, fudge it */
297 break;
298
299 case XenbusStateClosing:
300 xenbus_frontend_closed(dev);
301 break;
302 }
303}
304
305static struct xenbus_device_id xenkbd_ids[] = {
306 { "vkbd" },
307 { "" }
308};
309
310static struct xenbus_driver xenkbd = {
311 .name = "vkbd",
312 .owner = THIS_MODULE,
313 .ids = xenkbd_ids,
314 .probe = xenkbd_probe,
315 .remove = xenkbd_remove,
316 .resume = xenkbd_resume,
317 .otherend_changed = xenkbd_backend_changed,
318};
319
320static int __init xenkbd_init(void)
321{
322 if (!is_running_on_xen())
323 return -ENODEV;
324
325 /* Nothing to do if running in dom0. */
326 if (is_initial_xendomain())
327 return -ENODEV;
328
329 return xenbus_register_frontend(&xenkbd);
330}
331
332static void __exit xenkbd_cleanup(void)
333{
334 xenbus_unregister_driver(&xenkbd);
335}
336
337module_init(xenkbd_init);
338module_exit(xenkbd_cleanup);
339
340MODULE_LICENSE("GPL");