aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2010-08-16 13:42:58 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-08-16 13:42:58 -0400
commite4862f2f6f5653dfb67f3ba2b6f0bc74516ed51a (patch)
tree1db5a0540a4eecfad9b7daee476b985e82ddc810 /drivers/input
parentec62dbd7eb8e3dddb221da89ecbcea0fc3dee8c1 (diff)
parentb2c1e07b81a126e5846dfc3d36f559d861df59f4 (diff)
Merge branch 'for-2.6.36' into for-2.6.37
Fairly simple conflicts, the most serious ones are the i.MX ones which I suspect now need another rename. Conflicts: arch/arm/mach-mx2/clock_imx27.c arch/arm/mach-mx2/devices.c arch/arm/mach-omap2/board-rx51-peripherals.c arch/arm/mach-omap2/board-zoom2.c sound/soc/fsl/mpc5200_dma.c sound/soc/fsl/mpc5200_dma.h sound/soc/fsl/mpc8610_hpcd.c sound/soc/pxa/spitz.c
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/evdev.c198
-rw-r--r--drivers/input/input.c220
-rw-r--r--drivers/input/joydev.c38
-rw-r--r--drivers/input/joystick/a3d.c3
-rw-r--r--drivers/input/joystick/adi.c2
-rw-r--r--drivers/input/joystick/amijoy.c4
-rw-r--r--drivers/input/joystick/gamecon.c5
-rw-r--r--drivers/input/joystick/gf2k.c20
-rw-r--r--drivers/input/joystick/interact.c14
-rw-r--r--drivers/input/joystick/sidewinder.c18
-rw-r--r--drivers/input/joystick/xpad.c109
-rw-r--r--drivers/input/keyboard/Kconfig35
-rw-r--r--drivers/input/keyboard/Makefile3
-rw-r--r--drivers/input/keyboard/adp5588-keys.c352
-rw-r--r--drivers/input/keyboard/gpio_keys.c41
-rw-r--r--drivers/input/keyboard/hil_kbd.c21
-rw-r--r--drivers/input/keyboard/lm8323.c14
-rw-r--r--drivers/input/keyboard/matrix_keypad.c108
-rw-r--r--drivers/input/keyboard/max7359_keypad.c1
-rw-r--r--drivers/input/keyboard/mcs_touchkey.c239
-rw-r--r--drivers/input/keyboard/qt2160.c1
-rw-r--r--drivers/input/keyboard/samsung-keypad.c491
-rw-r--r--drivers/input/keyboard/stmpe-keypad.c386
-rw-r--r--drivers/input/keyboard/tca6416-keypad.c2
-rw-r--r--drivers/input/keyboard/twl4030_keypad.c17
-rw-r--r--drivers/input/keyboard/w90p910_keypad.c2
-rw-r--r--drivers/input/misc/Kconfig48
-rw-r--r--drivers/input/misc/Makefile4
-rw-r--r--drivers/input/misc/ad714x-i2c.c1
-rw-r--r--drivers/input/misc/ad714x.c2
-rw-r--r--drivers/input/misc/adxl34x-i2c.c163
-rw-r--r--drivers/input/misc/adxl34x-spi.c145
-rw-r--r--drivers/input/misc/adxl34x.c914
-rw-r--r--drivers/input/misc/adxl34x.h30
-rw-r--r--drivers/input/misc/ati_remote2.c26
-rw-r--r--drivers/input/misc/atlas_btns.c38
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c2
-rw-r--r--drivers/input/misc/ixp4xx-beeper.c3
-rw-r--r--drivers/input/misc/pcf8574_keypad.c4
-rw-r--r--drivers/input/misc/pwm-beeper.c199
-rw-r--r--drivers/input/misc/sparcspkr.c22
-rw-r--r--drivers/input/misc/twl4030-pwrbutton.c12
-rw-r--r--drivers/input/misc/uinput.c29
-rw-r--r--drivers/input/misc/wistron_btns.c4
-rw-r--r--drivers/input/mouse/Kconfig2
-rw-r--r--drivers/input/mouse/appletouch.c6
-rw-r--r--drivers/input/mouse/bcm5974.c23
-rw-r--r--drivers/input/mouse/elantech.c31
-rw-r--r--drivers/input/mouse/elantech.h7
-rw-r--r--drivers/input/mouse/pc110pad.c4
-rw-r--r--drivers/input/mouse/psmouse-base.c14
-rw-r--r--drivers/input/mouse/synaptics.c20
-rw-r--r--drivers/input/mouse/synaptics.h3
-rw-r--r--drivers/input/mouse/synaptics_i2c.c1
-rw-r--r--drivers/input/mousedev.c59
-rw-r--r--drivers/input/serio/Kconfig3
-rw-r--r--drivers/input/serio/i8042-io.h5
-rw-r--r--drivers/input/serio/i8042-ppcio.h75
-rw-r--r--drivers/input/serio/i8042-sparcio.h21
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h17
-rw-r--r--drivers/input/serio/i8042.c90
-rw-r--r--drivers/input/serio/xilinx_ps2.c4
-rw-r--r--drivers/input/tablet/aiptek.c15
-rw-r--r--drivers/input/tablet/wacom_sys.c1
-rw-r--r--drivers/input/tablet/wacom_wac.c130
-rw-r--r--drivers/input/tablet/wacom_wac.h2
-rw-r--r--drivers/input/touchscreen/Kconfig79
-rw-r--r--drivers/input/touchscreen/Makefile7
-rw-r--r--drivers/input/touchscreen/ad7877.c7
-rw-r--r--drivers/input/touchscreen/ad7879-i2c.c143
-rw-r--r--drivers/input/touchscreen/ad7879-spi.c198
-rw-r--r--drivers/input/touchscreen/ad7879.c628
-rw-r--r--drivers/input/touchscreen/ad7879.h30
-rw-r--r--drivers/input/touchscreen/ads7846.c208
-rw-r--r--drivers/input/touchscreen/cy8ctmg110_ts.c363
-rw-r--r--drivers/input/touchscreen/eeti_ts.c2
-rw-r--r--drivers/input/touchscreen/mcs5000_ts.c7
-rw-r--r--drivers/input/touchscreen/qt602240_ts.c1401
-rw-r--r--drivers/input/touchscreen/s3c2410_ts.c2
-rw-r--r--drivers/input/touchscreen/stmpe-ts.c397
-rw-r--r--drivers/input/touchscreen/tps6507x-ts.c15
-rw-r--r--drivers/input/touchscreen/tsc2007.c2
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c215
-rw-r--r--drivers/input/touchscreen/w90p910_ts.c2
-rw-r--r--drivers/input/xen-kbdfront.c2
85 files changed, 7024 insertions, 1207 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 2ee6c7a68bdc..c908c5f83645 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -10,7 +10,8 @@
10 10
11#define EVDEV_MINOR_BASE 64 11#define EVDEV_MINOR_BASE 64
12#define EVDEV_MINORS 32 12#define EVDEV_MINORS 32
13#define EVDEV_BUFFER_SIZE 64 13#define EVDEV_MIN_BUFFER_SIZE 64U
14#define EVDEV_BUF_PACKETS 8
14 15
15#include <linux/poll.h> 16#include <linux/poll.h>
16#include <linux/sched.h> 17#include <linux/sched.h>
@@ -23,7 +24,6 @@
23#include "input-compat.h" 24#include "input-compat.h"
24 25
25struct evdev { 26struct evdev {
26 int exist;
27 int open; 27 int open;
28 int minor; 28 int minor;
29 struct input_handle handle; 29 struct input_handle handle;
@@ -33,16 +33,18 @@ struct evdev {
33 spinlock_t client_lock; /* protects client_list */ 33 spinlock_t client_lock; /* protects client_list */
34 struct mutex mutex; 34 struct mutex mutex;
35 struct device dev; 35 struct device dev;
36 bool exist;
36}; 37};
37 38
38struct evdev_client { 39struct evdev_client {
39 struct input_event buffer[EVDEV_BUFFER_SIZE];
40 int head; 40 int head;
41 int tail; 41 int tail;
42 spinlock_t buffer_lock; /* protects access to buffer, head and tail */ 42 spinlock_t buffer_lock; /* protects access to buffer, head and tail */
43 struct fasync_struct *fasync; 43 struct fasync_struct *fasync;
44 struct evdev *evdev; 44 struct evdev *evdev;
45 struct list_head node; 45 struct list_head node;
46 int bufsize;
47 struct input_event buffer[];
46}; 48};
47 49
48static struct evdev *evdev_table[EVDEV_MINORS]; 50static struct evdev *evdev_table[EVDEV_MINORS];
@@ -52,11 +54,15 @@ static void evdev_pass_event(struct evdev_client *client,
52 struct input_event *event) 54 struct input_event *event)
53{ 55{
54 /* 56 /*
55 * Interrupts are disabled, just acquire the lock 57 * Interrupts are disabled, just acquire the lock.
58 * Make sure we don't leave with the client buffer
59 * "empty" by having client->head == client->tail.
56 */ 60 */
57 spin_lock(&client->buffer_lock); 61 spin_lock(&client->buffer_lock);
58 client->buffer[client->head++] = *event; 62 do {
59 client->head &= EVDEV_BUFFER_SIZE - 1; 63 client->buffer[client->head++] = *event;
64 client->head &= client->bufsize - 1;
65 } while (client->head == client->tail);
60 spin_unlock(&client->buffer_lock); 66 spin_unlock(&client->buffer_lock);
61 67
62 if (event->type == EV_SYN) 68 if (event->type == EV_SYN)
@@ -242,11 +248,21 @@ static int evdev_release(struct inode *inode, struct file *file)
242 return 0; 248 return 0;
243} 249}
244 250
251static unsigned int evdev_compute_buffer_size(struct input_dev *dev)
252{
253 unsigned int n_events =
254 max(dev->hint_events_per_packet * EVDEV_BUF_PACKETS,
255 EVDEV_MIN_BUFFER_SIZE);
256
257 return roundup_pow_of_two(n_events);
258}
259
245static int evdev_open(struct inode *inode, struct file *file) 260static int evdev_open(struct inode *inode, struct file *file)
246{ 261{
247 struct evdev *evdev; 262 struct evdev *evdev;
248 struct evdev_client *client; 263 struct evdev_client *client;
249 int i = iminor(inode) - EVDEV_MINOR_BASE; 264 int i = iminor(inode) - EVDEV_MINOR_BASE;
265 unsigned int bufsize;
250 int error; 266 int error;
251 267
252 if (i >= EVDEV_MINORS) 268 if (i >= EVDEV_MINORS)
@@ -263,12 +279,17 @@ static int evdev_open(struct inode *inode, struct file *file)
263 if (!evdev) 279 if (!evdev)
264 return -ENODEV; 280 return -ENODEV;
265 281
266 client = kzalloc(sizeof(struct evdev_client), GFP_KERNEL); 282 bufsize = evdev_compute_buffer_size(evdev->handle.dev);
283
284 client = kzalloc(sizeof(struct evdev_client) +
285 bufsize * sizeof(struct input_event),
286 GFP_KERNEL);
267 if (!client) { 287 if (!client) {
268 error = -ENOMEM; 288 error = -ENOMEM;
269 goto err_put_evdev; 289 goto err_put_evdev;
270 } 290 }
271 291
292 client->bufsize = bufsize;
272 spin_lock_init(&client->buffer_lock); 293 spin_lock_init(&client->buffer_lock);
273 client->evdev = evdev; 294 client->evdev = evdev;
274 evdev_attach_client(evdev, client); 295 evdev_attach_client(evdev, client);
@@ -334,7 +355,7 @@ static int evdev_fetch_next_event(struct evdev_client *client,
334 have_event = client->head != client->tail; 355 have_event = client->head != client->tail;
335 if (have_event) { 356 if (have_event) {
336 *event = client->buffer[client->tail++]; 357 *event = client->buffer[client->tail++];
337 client->tail &= EVDEV_BUFFER_SIZE - 1; 358 client->tail &= client->bufsize - 1;
338 } 359 }
339 360
340 spin_unlock_irq(&client->buffer_lock); 361 spin_unlock_irq(&client->buffer_lock);
@@ -382,10 +403,15 @@ static unsigned int evdev_poll(struct file *file, poll_table *wait)
382{ 403{
383 struct evdev_client *client = file->private_data; 404 struct evdev_client *client = file->private_data;
384 struct evdev *evdev = client->evdev; 405 struct evdev *evdev = client->evdev;
406 unsigned int mask;
385 407
386 poll_wait(file, &evdev->wait, wait); 408 poll_wait(file, &evdev->wait, wait);
387 return ((client->head == client->tail) ? 0 : (POLLIN | POLLRDNORM)) | 409
388 (evdev->exist ? 0 : (POLLHUP | POLLERR)); 410 mask = evdev->exist ? POLLOUT | POLLWRNORM : POLLHUP | POLLERR;
411 if (client->head != client->tail)
412 mask |= POLLIN | POLLRDNORM;
413
414 return mask;
389} 415}
390 416
391#ifdef CONFIG_COMPAT 417#ifdef CONFIG_COMPAT
@@ -466,13 +492,15 @@ static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
466} 492}
467 493
468#define OLD_KEY_MAX 0x1ff 494#define OLD_KEY_MAX 0x1ff
469static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user *p, int compat_mode) 495static int handle_eviocgbit(struct input_dev *dev,
496 unsigned int type, unsigned int size,
497 void __user *p, int compat_mode)
470{ 498{
471 static unsigned long keymax_warn_time; 499 static unsigned long keymax_warn_time;
472 unsigned long *bits; 500 unsigned long *bits;
473 int len; 501 int len;
474 502
475 switch (_IOC_NR(cmd) & EV_MAX) { 503 switch (type) {
476 504
477 case 0: bits = dev->evbit; len = EV_MAX; break; 505 case 0: bits = dev->evbit; len = EV_MAX; break;
478 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; 506 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
@@ -491,7 +519,7 @@ static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user
491 * EVIOCGBIT(EV_KEY, KEY_MAX) and not realize that 'len' 519 * EVIOCGBIT(EV_KEY, KEY_MAX) and not realize that 'len'
492 * should be in bytes, not in bits. 520 * should be in bytes, not in bits.
493 */ 521 */
494 if ((_IOC_NR(cmd) & EV_MAX) == EV_KEY && _IOC_SIZE(cmd) == OLD_KEY_MAX) { 522 if (type == EV_KEY && size == OLD_KEY_MAX) {
495 len = OLD_KEY_MAX; 523 len = OLD_KEY_MAX;
496 if (printk_timed_ratelimit(&keymax_warn_time, 10 * 1000)) 524 if (printk_timed_ratelimit(&keymax_warn_time, 10 * 1000))
497 printk(KERN_WARNING 525 printk(KERN_WARNING
@@ -502,7 +530,7 @@ static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user
502 BITS_TO_LONGS(OLD_KEY_MAX) * sizeof(long)); 530 BITS_TO_LONGS(OLD_KEY_MAX) * sizeof(long));
503 } 531 }
504 532
505 return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode); 533 return bits_to_user(bits, len, size, p, compat_mode);
506} 534}
507#undef OLD_KEY_MAX 535#undef OLD_KEY_MAX
508 536
@@ -516,8 +544,10 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
516 struct ff_effect effect; 544 struct ff_effect effect;
517 int __user *ip = (int __user *)p; 545 int __user *ip = (int __user *)p;
518 unsigned int i, t, u, v; 546 unsigned int i, t, u, v;
547 unsigned int size;
519 int error; 548 int error;
520 549
550 /* First we check for fixed-length commands */
521 switch (cmd) { 551 switch (cmd) {
522 552
523 case EVIOCGVERSION: 553 case EVIOCGVERSION:
@@ -584,108 +614,102 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
584 return evdev_grab(evdev, client); 614 return evdev_grab(evdev, client);
585 else 615 else
586 return evdev_ungrab(evdev, client); 616 return evdev_ungrab(evdev, client);
617 }
587 618
588 default: 619 size = _IOC_SIZE(cmd);
589
590 if (_IOC_TYPE(cmd) != 'E')
591 return -EINVAL;
592 620
593 if (_IOC_DIR(cmd) == _IOC_READ) { 621 /* Now check variable-length commands */
622#define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
594 623
595 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) 624 switch (EVIOC_MASK_SIZE(cmd)) {
596 return handle_eviocgbit(dev, cmd, p, compat_mode);
597 625
598 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) 626 case EVIOCGKEY(0):
599 return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd), 627 return bits_to_user(dev->key, KEY_MAX, size, p, compat_mode);
600 p, compat_mode);
601 628
602 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) 629 case EVIOCGLED(0):
603 return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd), 630 return bits_to_user(dev->led, LED_MAX, size, p, compat_mode);
604 p, compat_mode);
605 631
606 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) 632 case EVIOCGSND(0):
607 return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd), 633 return bits_to_user(dev->snd, SND_MAX, size, p, compat_mode);
608 p, compat_mode);
609 634
610 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) 635 case EVIOCGSW(0):
611 return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd), 636 return bits_to_user(dev->sw, SW_MAX, size, p, compat_mode);
612 p, compat_mode);
613 637
614 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) 638 case EVIOCGNAME(0):
615 return str_to_user(dev->name, _IOC_SIZE(cmd), p); 639 return str_to_user(dev->name, size, p);
616 640
617 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) 641 case EVIOCGPHYS(0):
618 return str_to_user(dev->phys, _IOC_SIZE(cmd), p); 642 return str_to_user(dev->phys, size, p);
619 643
620 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) 644 case EVIOCGUNIQ(0):
621 return str_to_user(dev->uniq, _IOC_SIZE(cmd), p); 645 return str_to_user(dev->uniq, size, p);
622 646
623 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 647 case EVIOC_MASK_SIZE(EVIOCSFF):
648 if (input_ff_effect_from_user(p, size, &effect))
649 return -EFAULT;
624 650
625 t = _IOC_NR(cmd) & ABS_MAX; 651 error = input_ff_upload(dev, &effect, file);
626 652
627 abs.value = dev->abs[t]; 653 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
628 abs.minimum = dev->absmin[t]; 654 return -EFAULT;
629 abs.maximum = dev->absmax[t];
630 abs.fuzz = dev->absfuzz[t];
631 abs.flat = dev->absflat[t];
632 abs.resolution = dev->absres[t];
633 655
634 if (copy_to_user(p, &abs, min_t(size_t, 656 return error;
635 _IOC_SIZE(cmd), 657 }
636 sizeof(struct input_absinfo))))
637 return -EFAULT;
638 658
639 return 0; 659 /* Multi-number variable-length handlers */
640 } 660 if (_IOC_TYPE(cmd) != 'E')
661 return -EINVAL;
641 662
642 } 663 if (_IOC_DIR(cmd) == _IOC_READ) {
643 664
644 if (_IOC_DIR(cmd) == _IOC_WRITE) { 665 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
666 return handle_eviocgbit(dev,
667 _IOC_NR(cmd) & EV_MAX, size,
668 p, compat_mode);
645 669
646 if (_IOC_NR(cmd) == _IOC_NR(EVIOCSFF)) { 670 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
647 671
648 if (input_ff_effect_from_user(p, _IOC_SIZE(cmd), &effect)) 672 t = _IOC_NR(cmd) & ABS_MAX;
649 return -EFAULT; 673 abs = dev->absinfo[t];
650 674
651 error = input_ff_upload(dev, &effect, file); 675 if (copy_to_user(p, &abs, min_t(size_t,
676 size, sizeof(struct input_absinfo))))
677 return -EFAULT;
652 678
653 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) 679 return 0;
654 return -EFAULT; 680 }
681 }
655 682
656 return error; 683 if (_IOC_DIR(cmd) == _IOC_READ) {
657 }
658 684
659 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 685 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
660 686
661 t = _IOC_NR(cmd) & ABS_MAX; 687 t = _IOC_NR(cmd) & ABS_MAX;
662 688
663 if (copy_from_user(&abs, p, min_t(size_t, 689 if (copy_from_user(&abs, p, min_t(size_t,
664 _IOC_SIZE(cmd), 690 size, sizeof(struct input_absinfo))))
665 sizeof(struct input_absinfo)))) 691 return -EFAULT;
666 return -EFAULT;
667 692
668 /* 693 if (size < sizeof(struct input_absinfo))
669 * Take event lock to ensure that we are not 694 abs.resolution = 0;
670 * changing device parameters in the middle
671 * of event.
672 */
673 spin_lock_irq(&dev->event_lock);
674 695
675 dev->abs[t] = abs.value; 696 /* We can't change number of reserved MT slots */
676 dev->absmin[t] = abs.minimum; 697 if (t == ABS_MT_SLOT)
677 dev->absmax[t] = abs.maximum; 698 return -EINVAL;
678 dev->absfuzz[t] = abs.fuzz;
679 dev->absflat[t] = abs.flat;
680 dev->absres[t] = _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
681 0 : abs.resolution;
682 699
683 spin_unlock_irq(&dev->event_lock); 700 /*
701 * Take event lock to ensure that we are not
702 * changing device parameters in the middle
703 * of event.
704 */
705 spin_lock_irq(&dev->event_lock);
706 dev->absinfo[t] = abs;
707 spin_unlock_irq(&dev->event_lock);
684 708
685 return 0; 709 return 0;
686 }
687 } 710 }
688 } 711 }
712
689 return -EINVAL; 713 return -EINVAL;
690} 714}
691 715
@@ -768,7 +792,7 @@ static void evdev_remove_chrdev(struct evdev *evdev)
768static void evdev_mark_dead(struct evdev *evdev) 792static void evdev_mark_dead(struct evdev *evdev)
769{ 793{
770 mutex_lock(&evdev->mutex); 794 mutex_lock(&evdev->mutex);
771 evdev->exist = 0; 795 evdev->exist = false;
772 mutex_unlock(&evdev->mutex); 796 mutex_unlock(&evdev->mutex);
773} 797}
774 798
@@ -817,7 +841,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
817 init_waitqueue_head(&evdev->wait); 841 init_waitqueue_head(&evdev->wait);
818 842
819 dev_set_name(&evdev->dev, "event%d", minor); 843 dev_set_name(&evdev->dev, "event%d", minor);
820 evdev->exist = 1; 844 evdev->exist = true;
821 evdev->minor = minor; 845 evdev->minor = minor;
822 846
823 evdev->handle.dev = input_get_device(dev); 847 evdev->handle.dev = input_get_device(dev);
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 9c79bd56b51a..a9b025f4147a 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -33,25 +33,6 @@ MODULE_LICENSE("GPL");
33 33
34#define INPUT_DEVICES 256 34#define INPUT_DEVICES 256
35 35
36/*
37 * EV_ABS events which should not be cached are listed here.
38 */
39static unsigned int input_abs_bypass_init_data[] __initdata = {
40 ABS_MT_TOUCH_MAJOR,
41 ABS_MT_TOUCH_MINOR,
42 ABS_MT_WIDTH_MAJOR,
43 ABS_MT_WIDTH_MINOR,
44 ABS_MT_ORIENTATION,
45 ABS_MT_POSITION_X,
46 ABS_MT_POSITION_Y,
47 ABS_MT_TOOL_TYPE,
48 ABS_MT_BLOB_ID,
49 ABS_MT_TRACKING_ID,
50 ABS_MT_PRESSURE,
51 0
52};
53static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)];
54
55static LIST_HEAD(input_dev_list); 36static LIST_HEAD(input_dev_list);
56static LIST_HEAD(input_handler_list); 37static LIST_HEAD(input_handler_list);
57 38
@@ -181,6 +162,56 @@ static void input_stop_autorepeat(struct input_dev *dev)
181#define INPUT_PASS_TO_DEVICE 2 162#define INPUT_PASS_TO_DEVICE 2
182#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 163#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
183 164
165static int input_handle_abs_event(struct input_dev *dev,
166 unsigned int code, int *pval)
167{
168 bool is_mt_event;
169 int *pold;
170
171 if (code == ABS_MT_SLOT) {
172 /*
173 * "Stage" the event; we'll flush it later, when we
174 * get actiual touch data.
175 */
176 if (*pval >= 0 && *pval < dev->mtsize)
177 dev->slot = *pval;
178
179 return INPUT_IGNORE_EVENT;
180 }
181
182 is_mt_event = code >= ABS_MT_FIRST && code <= ABS_MT_LAST;
183
184 if (!is_mt_event) {
185 pold = &dev->absinfo[code].value;
186 } else if (dev->mt) {
187 struct input_mt_slot *mtslot = &dev->mt[dev->slot];
188 pold = &mtslot->abs[code - ABS_MT_FIRST];
189 } else {
190 /*
191 * Bypass filtering for multitouch events when
192 * not employing slots.
193 */
194 pold = NULL;
195 }
196
197 if (pold) {
198 *pval = input_defuzz_abs_event(*pval, *pold,
199 dev->absinfo[code].fuzz);
200 if (*pold == *pval)
201 return INPUT_IGNORE_EVENT;
202
203 *pold = *pval;
204 }
205
206 /* Flush pending "slot" event */
207 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
208 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
209 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
210 }
211
212 return INPUT_PASS_TO_HANDLERS;
213}
214
184static void input_handle_event(struct input_dev *dev, 215static void input_handle_event(struct input_dev *dev,
185 unsigned int type, unsigned int code, int value) 216 unsigned int type, unsigned int code, int value)
186{ 217{
@@ -196,12 +227,12 @@ static void input_handle_event(struct input_dev *dev,
196 227
197 case SYN_REPORT: 228 case SYN_REPORT:
198 if (!dev->sync) { 229 if (!dev->sync) {
199 dev->sync = 1; 230 dev->sync = true;
200 disposition = INPUT_PASS_TO_HANDLERS; 231 disposition = INPUT_PASS_TO_HANDLERS;
201 } 232 }
202 break; 233 break;
203 case SYN_MT_REPORT: 234 case SYN_MT_REPORT:
204 dev->sync = 0; 235 dev->sync = false;
205 disposition = INPUT_PASS_TO_HANDLERS; 236 disposition = INPUT_PASS_TO_HANDLERS;
206 break; 237 break;
207 } 238 }
@@ -233,21 +264,9 @@ static void input_handle_event(struct input_dev *dev,
233 break; 264 break;
234 265
235 case EV_ABS: 266 case EV_ABS:
236 if (is_event_supported(code, dev->absbit, ABS_MAX)) { 267 if (is_event_supported(code, dev->absbit, ABS_MAX))
237 268 disposition = input_handle_abs_event(dev, code, &value);
238 if (test_bit(code, input_abs_bypass)) {
239 disposition = INPUT_PASS_TO_HANDLERS;
240 break;
241 }
242 269
243 value = input_defuzz_abs_event(value,
244 dev->abs[code], dev->absfuzz[code]);
245
246 if (dev->abs[code] != value) {
247 dev->abs[code] = value;
248 disposition = INPUT_PASS_TO_HANDLERS;
249 }
250 }
251 break; 270 break;
252 271
253 case EV_REL: 272 case EV_REL:
@@ -298,7 +317,7 @@ static void input_handle_event(struct input_dev *dev,
298 } 317 }
299 318
300 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 319 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
301 dev->sync = 0; 320 dev->sync = false;
302 321
303 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 322 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
304 dev->event(dev, type, code, value); 323 dev->event(dev, type, code, value);
@@ -372,6 +391,43 @@ void input_inject_event(struct input_handle *handle,
372EXPORT_SYMBOL(input_inject_event); 391EXPORT_SYMBOL(input_inject_event);
373 392
374/** 393/**
394 * input_alloc_absinfo - allocates array of input_absinfo structs
395 * @dev: the input device emitting absolute events
396 *
397 * If the absinfo struct the caller asked for is already allocated, this
398 * functions will not do anything.
399 */
400void input_alloc_absinfo(struct input_dev *dev)
401{
402 if (!dev->absinfo)
403 dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
404 GFP_KERNEL);
405
406 WARN(!dev->absinfo, "%s(): kcalloc() failed?\n", __func__);
407}
408EXPORT_SYMBOL(input_alloc_absinfo);
409
410void input_set_abs_params(struct input_dev *dev, unsigned int axis,
411 int min, int max, int fuzz, int flat)
412{
413 struct input_absinfo *absinfo;
414
415 input_alloc_absinfo(dev);
416 if (!dev->absinfo)
417 return;
418
419 absinfo = &dev->absinfo[axis];
420 absinfo->minimum = min;
421 absinfo->maximum = max;
422 absinfo->fuzz = fuzz;
423 absinfo->flat = flat;
424
425 dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
426}
427EXPORT_SYMBOL(input_set_abs_params);
428
429
430/**
375 * input_grab_device - grabs device for exclusive use 431 * input_grab_device - grabs device for exclusive use
376 * @handle: input handle that wants to own the device 432 * @handle: input handle that wants to own the device
377 * 433 *
@@ -528,12 +584,30 @@ void input_close_device(struct input_handle *handle)
528EXPORT_SYMBOL(input_close_device); 584EXPORT_SYMBOL(input_close_device);
529 585
530/* 586/*
587 * Simulate keyup events for all keys that are marked as pressed.
588 * The function must be called with dev->event_lock held.
589 */
590static void input_dev_release_keys(struct input_dev *dev)
591{
592 int code;
593
594 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
595 for (code = 0; code <= KEY_MAX; code++) {
596 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
597 __test_and_clear_bit(code, dev->key)) {
598 input_pass_event(dev, EV_KEY, code, 0);
599 }
600 }
601 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
602 }
603}
604
605/*
531 * Prepare device for unregistering 606 * Prepare device for unregistering
532 */ 607 */
533static void input_disconnect_device(struct input_dev *dev) 608static void input_disconnect_device(struct input_dev *dev)
534{ 609{
535 struct input_handle *handle; 610 struct input_handle *handle;
536 int code;
537 611
538 /* 612 /*
539 * Mark device as going away. Note that we take dev->mutex here 613 * Mark device as going away. Note that we take dev->mutex here
@@ -552,15 +626,7 @@ static void input_disconnect_device(struct input_dev *dev)
552 * generate events even after we done here but they will not 626 * generate events even after we done here but they will not
553 * reach any handlers. 627 * reach any handlers.
554 */ 628 */
555 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { 629 input_dev_release_keys(dev);
556 for (code = 0; code <= KEY_MAX; code++) {
557 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
558 __test_and_clear_bit(code, dev->key)) {
559 input_pass_event(dev, EV_KEY, code, 0);
560 }
561 }
562 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
563 }
564 630
565 list_for_each_entry(handle, &dev->h_list, d_node) 631 list_for_each_entry(handle, &dev->h_list, d_node)
566 handle->open = 0; 632 handle->open = 0;
@@ -684,7 +750,7 @@ int input_set_keycode(struct input_dev *dev,
684 unsigned int scancode, unsigned int keycode) 750 unsigned int scancode, unsigned int keycode)
685{ 751{
686 unsigned long flags; 752 unsigned long flags;
687 int old_keycode; 753 unsigned int old_keycode;
688 int retval; 754 int retval;
689 755
690 if (keycode > KEY_MAX) 756 if (keycode > KEY_MAX)
@@ -1278,6 +1344,8 @@ static void input_dev_release(struct device *device)
1278 struct input_dev *dev = to_input_dev(device); 1344 struct input_dev *dev = to_input_dev(device);
1279 1345
1280 input_ff_destroy(dev); 1346 input_ff_destroy(dev);
1347 input_mt_destroy_slots(dev);
1348 kfree(dev->absinfo);
1281 kfree(dev); 1349 kfree(dev);
1282 1350
1283 module_put(THIS_MODULE); 1351 module_put(THIS_MODULE);
@@ -1433,6 +1501,15 @@ static int input_dev_resume(struct device *dev)
1433 1501
1434 mutex_lock(&input_dev->mutex); 1502 mutex_lock(&input_dev->mutex);
1435 input_dev_reset(input_dev, true); 1503 input_dev_reset(input_dev, true);
1504
1505 /*
1506 * Keys that have been pressed at suspend time are unlikely
1507 * to be still pressed when we resume.
1508 */
1509 spin_lock_irq(&input_dev->event_lock);
1510 input_dev_release_keys(input_dev);
1511 spin_unlock_irq(&input_dev->event_lock);
1512
1436 mutex_unlock(&input_dev->mutex); 1513 mutex_unlock(&input_dev->mutex);
1437 1514
1438 return 0; 1515 return 0;
@@ -1518,6 +1595,45 @@ void input_free_device(struct input_dev *dev)
1518EXPORT_SYMBOL(input_free_device); 1595EXPORT_SYMBOL(input_free_device);
1519 1596
1520/** 1597/**
1598 * input_mt_create_slots() - create MT input slots
1599 * @dev: input device supporting MT events and finger tracking
1600 * @num_slots: number of slots used by the device
1601 *
1602 * This function allocates all necessary memory for MT slot handling
1603 * in the input device, and adds ABS_MT_SLOT to the device capabilities.
1604 */
1605int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots)
1606{
1607 if (!num_slots)
1608 return 0;
1609
1610 dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL);
1611 if (!dev->mt)
1612 return -ENOMEM;
1613
1614 dev->mtsize = num_slots;
1615 input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
1616
1617 return 0;
1618}
1619EXPORT_SYMBOL(input_mt_create_slots);
1620
1621/**
1622 * input_mt_destroy_slots() - frees the MT slots of the input device
1623 * @dev: input device with allocated MT slots
1624 *
1625 * This function is only needed in error path as the input core will
1626 * automatically free the MT slots when the device is destroyed.
1627 */
1628void input_mt_destroy_slots(struct input_dev *dev)
1629{
1630 kfree(dev->mt);
1631 dev->mt = NULL;
1632 dev->mtsize = 0;
1633}
1634EXPORT_SYMBOL(input_mt_destroy_slots);
1635
1636/**
1521 * input_set_capability - mark device as capable of a certain event 1637 * input_set_capability - mark device as capable of a certain event
1522 * @dev: device that is capable of emitting or accepting event 1638 * @dev: device that is capable of emitting or accepting event
1523 * @type: type of the event (EV_KEY, EV_REL, etc...) 1639 * @type: type of the event (EV_KEY, EV_REL, etc...)
@@ -1926,20 +2042,10 @@ static const struct file_operations input_fops = {
1926 .open = input_open_file, 2042 .open = input_open_file,
1927}; 2043};
1928 2044
1929static void __init input_init_abs_bypass(void)
1930{
1931 const unsigned int *p;
1932
1933 for (p = input_abs_bypass_init_data; *p; p++)
1934 input_abs_bypass[BIT_WORD(*p)] |= BIT_MASK(*p);
1935}
1936
1937static int __init input_init(void) 2045static int __init input_init(void)
1938{ 2046{
1939 int err; 2047 int err;
1940 2048
1941 input_init_abs_bypass();
1942
1943 err = class_register(&input_class); 2049 err = class_register(&input_class);
1944 if (err) { 2050 if (err) {
1945 printk(KERN_ERR "input: unable to register input_dev class\n"); 2051 printk(KERN_ERR "input: unable to register input_dev class\n");
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 34157bb97ed6..d85bd8a7967d 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -37,7 +37,6 @@ MODULE_LICENSE("GPL");
37#define JOYDEV_BUFFER_SIZE 64 37#define JOYDEV_BUFFER_SIZE 64
38 38
39struct joydev { 39struct joydev {
40 int exist;
41 int open; 40 int open;
42 int minor; 41 int minor;
43 struct input_handle handle; 42 struct input_handle handle;
@@ -46,6 +45,7 @@ struct joydev {
46 spinlock_t client_lock; /* protects client_list */ 45 spinlock_t client_lock; /* protects client_list */
47 struct mutex mutex; 46 struct mutex mutex;
48 struct device dev; 47 struct device dev;
48 bool exist;
49 49
50 struct js_corr corr[ABS_CNT]; 50 struct js_corr corr[ABS_CNT];
51 struct JS_DATA_SAVE_TYPE glue; 51 struct JS_DATA_SAVE_TYPE glue;
@@ -530,7 +530,7 @@ static int joydev_ioctl_common(struct joydev *joydev,
530{ 530{
531 struct input_dev *dev = joydev->handle.dev; 531 struct input_dev *dev = joydev->handle.dev;
532 size_t len; 532 size_t len;
533 int i, j; 533 int i;
534 const char *name; 534 const char *name;
535 535
536 /* Process fixed-sized commands. */ 536 /* Process fixed-sized commands. */
@@ -562,12 +562,11 @@ static int joydev_ioctl_common(struct joydev *joydev,
562 case JSIOCSCORR: 562 case JSIOCSCORR:
563 if (copy_from_user(joydev->corr, argp, 563 if (copy_from_user(joydev->corr, argp,
564 sizeof(joydev->corr[0]) * joydev->nabs)) 564 sizeof(joydev->corr[0]) * joydev->nabs))
565 return -EFAULT; 565 return -EFAULT;
566 566
567 for (i = 0; i < joydev->nabs; i++) { 567 for (i = 0; i < joydev->nabs; i++) {
568 j = joydev->abspam[i]; 568 int val = input_abs_get_val(dev, joydev->abspam[i]);
569 joydev->abs[i] = joydev_correct(dev->abs[j], 569 joydev->abs[i] = joydev_correct(val, &joydev->corr[i]);
570 &joydev->corr[i]);
571 } 570 }
572 return 0; 571 return 0;
573 572
@@ -760,7 +759,7 @@ static void joydev_remove_chrdev(struct joydev *joydev)
760static void joydev_mark_dead(struct joydev *joydev) 759static void joydev_mark_dead(struct joydev *joydev)
761{ 760{
762 mutex_lock(&joydev->mutex); 761 mutex_lock(&joydev->mutex);
763 joydev->exist = 0; 762 joydev->exist = false;
764 mutex_unlock(&joydev->mutex); 763 mutex_unlock(&joydev->mutex);
765} 764}
766 765
@@ -817,10 +816,9 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
817 init_waitqueue_head(&joydev->wait); 816 init_waitqueue_head(&joydev->wait);
818 817
819 dev_set_name(&joydev->dev, "js%d", minor); 818 dev_set_name(&joydev->dev, "js%d", minor);
820 joydev->exist = 1; 819 joydev->exist = true;
821 joydev->minor = minor; 820 joydev->minor = minor;
822 821
823 joydev->exist = 1;
824 joydev->handle.dev = input_get_device(dev); 822 joydev->handle.dev = input_get_device(dev);
825 joydev->handle.name = dev_name(&joydev->dev); 823 joydev->handle.name = dev_name(&joydev->dev);
826 joydev->handle.handler = handler; 824 joydev->handle.handler = handler;
@@ -849,25 +847,27 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
849 847
850 for (i = 0; i < joydev->nabs; i++) { 848 for (i = 0; i < joydev->nabs; i++) {
851 j = joydev->abspam[i]; 849 j = joydev->abspam[i];
852 if (dev->absmax[j] == dev->absmin[j]) { 850 if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) {
853 joydev->corr[i].type = JS_CORR_NONE; 851 joydev->corr[i].type = JS_CORR_NONE;
854 joydev->abs[i] = dev->abs[j]; 852 joydev->abs[i] = input_abs_get_val(dev, j);
855 continue; 853 continue;
856 } 854 }
857 joydev->corr[i].type = JS_CORR_BROKEN; 855 joydev->corr[i].type = JS_CORR_BROKEN;
858 joydev->corr[i].prec = dev->absfuzz[j]; 856 joydev->corr[i].prec = input_abs_get_fuzz(dev, j);
859 joydev->corr[i].coef[0] = 857
860 (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j]; 858 t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2;
861 joydev->corr[i].coef[1] = 859 joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j);
862 (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j]; 860 joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j);
863 861
864 t = (dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j]; 862 t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2
863 - 2 * input_abs_get_flat(dev, j);
865 if (t) { 864 if (t) {
866 joydev->corr[i].coef[2] = (1 << 29) / t; 865 joydev->corr[i].coef[2] = (1 << 29) / t;
867 joydev->corr[i].coef[3] = (1 << 29) / t; 866 joydev->corr[i].coef[3] = (1 << 29) / t;
868 867
869 joydev->abs[i] = joydev_correct(dev->abs[j], 868 joydev->abs[i] =
870 joydev->corr + i); 869 joydev_correct(input_abs_get_val(dev, j),
870 joydev->corr + i);
871 } 871 }
872 } 872 }
873 873
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index 6489f4010c4f..d259b41354b8 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -342,7 +342,8 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
342 342
343 for (i = 0; i < 4; i++) { 343 for (i = 0; i < 4; i++) {
344 if (i < 2) 344 if (i < 2)
345 input_set_abs_params(input_dev, axes[i], 48, input_dev->abs[axes[i]] * 2 - 48, 0, 8); 345 input_set_abs_params(input_dev, axes[i],
346 48, input_abs_get_val(input_dev, axes[i]) * 2 - 48, 0, 8);
346 else 347 else
347 input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0); 348 input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0);
348 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0); 349 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 89c4c084d4ad..b992fbf91f2f 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -452,7 +452,7 @@ static void adi_init_center(struct adi *adi)
452 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { 452 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
453 453
454 t = adi->abs[i]; 454 t = adi->abs[i];
455 x = adi->dev->abs[t]; 455 x = input_abs_get_val(adi->dev, t);
456 456
457 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) 457 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
458 x = i < adi->axes10 ? 512 : 128; 458 x = i < adi->axes10 ? 512 : 128;
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index 05022f07ec77..0bc86204213e 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -139,8 +139,8 @@ static int __init amijoy_init(void)
139 amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | 139 amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
140 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); 140 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
141 for (j = 0; j < 2; j++) { 141 for (j = 0; j < 2; j++) {
142 amijoy_dev[i]->absmin[ABS_X + j] = -1; 142 input_set_abs_params(amijoy_dev[i], ABS_X + j,
143 amijoy_dev[i]->absmax[ABS_X + j] = 1; 143 -1, 1, 0, 0);
144 } 144 }
145 145
146 err = input_register_device(amijoy_dev[i]); 146 err = input_register_device(amijoy_dev[i]);
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index fbd62abb66f9..0ffaf2c77a19 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -89,7 +89,6 @@ struct gc_pad {
89struct gc { 89struct gc {
90 struct pardevice *pd; 90 struct pardevice *pd;
91 struct gc_pad pads[GC_MAX_DEVICES]; 91 struct gc_pad pads[GC_MAX_DEVICES];
92 struct input_dev *dev[GC_MAX_DEVICES];
93 struct timer_list timer; 92 struct timer_list timer;
94 int pad_count[GC_MAX]; 93 int pad_count[GC_MAX];
95 int used; 94 int used;
@@ -387,7 +386,7 @@ static void gc_nes_process_packet(struct gc *gc)
387 for (i = 0; i < GC_MAX_DEVICES; i++) { 386 for (i = 0; i < GC_MAX_DEVICES; i++) {
388 387
389 pad = &gc->pads[i]; 388 pad = &gc->pads[i];
390 dev = gc->dev[i]; 389 dev = pad->dev;
391 s = gc_status_bit[i]; 390 s = gc_status_bit[i];
392 391
393 switch (pad->type) { 392 switch (pad->type) {
@@ -579,7 +578,7 @@ static void gc_psx_command(struct gc *gc, int b, unsigned char *data)
579 read = parport_read_status(port) ^ 0x80; 578 read = parport_read_status(port) ^ 0x80;
580 579
581 for (j = 0; j < GC_MAX_DEVICES; j++) { 580 for (j = 0; j < GC_MAX_DEVICES; j++) {
582 struct gc_pad *pad = &gc->pads[i]; 581 struct gc_pad *pad = &gc->pads[j];
583 582
584 if (pad->type == GC_PSX || pad->type == GC_DDR) 583 if (pad->type == GC_PSX || pad->type == GC_DDR)
585 data[j] |= (read & gc_status_bit[j]) ? (1 << i) : 0; 584 data[j] |= (read & gc_status_bit[j]) ? (1 << i) : 0;
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 45ac70eae0aa..0536b1b2f018 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -318,11 +318,8 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
318 for (i = 0; i < gf2k_axes[gf2k->id]; i++) 318 for (i = 0; i < gf2k_axes[gf2k->id]; i++)
319 set_bit(gf2k_abs[i], input_dev->absbit); 319 set_bit(gf2k_abs[i], input_dev->absbit);
320 320
321 for (i = 0; i < gf2k_hats[gf2k->id]; i++) { 321 for (i = 0; i < gf2k_hats[gf2k->id]; i++)
322 set_bit(ABS_HAT0X + i, input_dev->absbit); 322 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
323 input_dev->absmin[ABS_HAT0X + i] = -1;
324 input_dev->absmax[ABS_HAT0X + i] = 1;
325 }
326 323
327 for (i = 0; i < gf2k_joys[gf2k->id]; i++) 324 for (i = 0; i < gf2k_joys[gf2k->id]; i++)
328 set_bit(gf2k_btn_joy[i], input_dev->keybit); 325 set_bit(gf2k_btn_joy[i], input_dev->keybit);
@@ -334,11 +331,14 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
334 gf2k_read(gf2k, data); 331 gf2k_read(gf2k, data);
335 332
336 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 333 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
337 input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 : 334 int max = i < 2 ?
338 input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32; 335 input_abs_get_val(input_dev, gf2k_abs[i]) * 2 :
339 input_dev->absmin[gf2k_abs[i]] = 32; 336 input_abs_get_val(input_dev, gf2k_abs[0]) +
340 input_dev->absfuzz[gf2k_abs[i]] = 8; 337 input_abs_get_val(input_dev, gf2k_abs[1]);
341 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 338 int flat = i < 2 ? 24 : 0;
339
340 input_set_abs_params(input_dev, gf2k_abs[i],
341 32, max - 32, 8, flat);
342 } 342 }
343 343
344 err = input_register_device(gf2k->dev); 344 err = input_register_device(gf2k->dev);
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index 2478289aeeea..16fb19d1ca25 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -270,18 +270,14 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
270 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 270 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
271 271
272 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { 272 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
273 set_bit(t, input_dev->absbit); 273 if (i < interact_type[interact->type].b8)
274 if (i < interact_type[interact->type].b8) { 274 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
275 input_dev->absmin[t] = 0; 275 else
276 input_dev->absmax[t] = 255; 276 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
277 } else {
278 input_dev->absmin[t] = -1;
279 input_dev->absmax[t] = 1;
280 }
281 } 277 }
282 278
283 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) 279 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
284 set_bit(t, input_dev->keybit); 280 __set_bit(t, input_dev->keybit);
285 281
286 err = input_register_device(interact->dev); 282 err = input_register_device(interact->dev);
287 if (err) 283 if (err)
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index ca13a6bec33e..b8d86115644b 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -761,17 +761,21 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
761 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 761 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
762 762
763 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { 763 for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
764 int min, max, fuzz, flat;
765
764 code = sw_abs[sw->type][j]; 766 code = sw_abs[sw->type][j];
765 set_bit(code, input_dev->absbit); 767 min = bits == 1 ? -1 : 0;
766 input_dev->absmax[code] = (1 << bits) - 1; 768 max = (1 << bits) - 1;
767 input_dev->absmin[code] = (bits == 1) ? -1 : 0; 769 fuzz = (bits >> 1) >= 2 ? 1 << ((bits >> 1) - 2) : 0;
768 input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; 770 flat = code == ABS_THROTTLE || bits < 5 ?
769 if (code != ABS_THROTTLE) 771 0 : 1 << (bits - 5);
770 input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; 772
773 input_set_abs_params(input_dev, code,
774 min, max, fuzz, flat);
771 } 775 }
772 776
773 for (j = 0; (code = sw_btn[sw->type][j]); j++) 777 for (j = 0; (code = sw_btn[sw->type][j]); j++)
774 set_bit(code, input_dev->keybit); 778 __set_bit(code, input_dev->keybit);
775 779
776 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); 780 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
777 781
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index c1087ce4cef9..f9fb7fa10af3 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -9,6 +9,7 @@
9 * 2005 Dominic Cerquetti <binary1230@yahoo.com> 9 * 2005 Dominic Cerquetti <binary1230@yahoo.com>
10 * 2006 Adam Buchbinder <adam.buchbinder@gmail.com> 10 * 2006 Adam Buchbinder <adam.buchbinder@gmail.com>
11 * 2007 Jan Kratochvil <honza@jikos.cz> 11 * 2007 Jan Kratochvil <honza@jikos.cz>
12 * 2010 Christoph Fritz <chf.fritz@googlemail.com>
12 * 13 *
13 * This program is free software; you can redistribute it and/or 14 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as 15 * modify it under the terms of the GNU General Public License as
@@ -88,6 +89,9 @@
88 but we map them to axes when possible to simplify things */ 89 but we map them to axes when possible to simplify things */
89#define MAP_DPAD_TO_BUTTONS (1 << 0) 90#define MAP_DPAD_TO_BUTTONS (1 << 0)
90#define MAP_TRIGGERS_TO_BUTTONS (1 << 1) 91#define MAP_TRIGGERS_TO_BUTTONS (1 << 1)
92#define MAP_STICKS_TO_NULL (1 << 2)
93#define DANCEPAD_MAP_CONFIG (MAP_DPAD_TO_BUTTONS | \
94 MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
91 95
92#define XTYPE_XBOX 0 96#define XTYPE_XBOX 0
93#define XTYPE_XBOX360 1 97#define XTYPE_XBOX360 1
@@ -102,6 +106,10 @@ static int triggers_to_buttons;
102module_param(triggers_to_buttons, bool, S_IRUGO); 106module_param(triggers_to_buttons, bool, S_IRUGO);
103MODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads"); 107MODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads");
104 108
109static int sticks_to_null;
110module_param(sticks_to_null, bool, S_IRUGO);
111MODULE_PARM_DESC(sticks_to_null, "Do not map sticks at all for unknown pads");
112
105static const struct xpad_device { 113static const struct xpad_device {
106 u16 idVendor; 114 u16 idVendor;
107 u16 idProduct; 115 u16 idProduct;
@@ -114,7 +122,7 @@ static const struct xpad_device {
114 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX }, 122 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
115 { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX }, 123 { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
116 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 124 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
117 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 125 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", DANCEPAD_MAP_CONFIG, XTYPE_XBOX },
118 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX }, 126 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
119 { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 }, 127 { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
120 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX }, 128 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
@@ -140,6 +148,7 @@ static const struct xpad_device {
140 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX }, 148 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
141 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX }, 149 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
142 { 0x0e6f, 0x0006, "Pelican 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 }, 150 { 0x0e6f, 0x0006, "Pelican 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
151 { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
143 { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX }, 152 { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX },
144 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX }, 153 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
145 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX }, 154 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
@@ -151,6 +160,7 @@ static const struct xpad_device {
151 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 }, 160 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
152 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 161 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
153 { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 162 { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
163 { 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
154 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX }, 164 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
155 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN } 165 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
156}; 166};
@@ -158,7 +168,7 @@ static const struct xpad_device {
158/* buttons shared with xbox and xbox360 */ 168/* buttons shared with xbox and xbox360 */
159static const signed short xpad_common_btn[] = { 169static const signed short xpad_common_btn[] = {
160 BTN_A, BTN_B, BTN_X, BTN_Y, /* "analog" buttons */ 170 BTN_A, BTN_B, BTN_X, BTN_Y, /* "analog" buttons */
161 BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */ 171 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */
162 -1 /* terminating entry */ 172 -1 /* terminating entry */
163}; 173};
164 174
@@ -168,10 +178,10 @@ static const signed short xpad_btn[] = {
168 -1 /* terminating entry */ 178 -1 /* terminating entry */
169}; 179};
170 180
171/* used when dpad is mapped to nuttons */ 181/* used when dpad is mapped to buttons */
172static const signed short xpad_btn_pad[] = { 182static const signed short xpad_btn_pad[] = {
173 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ 183 BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
174 BTN_0, BTN_1, /* d-pad up, down (XXX names??) */ 184 BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
175 -1 /* terminating entry */ 185 -1 /* terminating entry */
176}; 186};
177 187
@@ -279,17 +289,19 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
279{ 289{
280 struct input_dev *dev = xpad->dev; 290 struct input_dev *dev = xpad->dev;
281 291
282 /* left stick */ 292 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
283 input_report_abs(dev, ABS_X, 293 /* left stick */
284 (__s16) le16_to_cpup((__le16 *)(data + 12))); 294 input_report_abs(dev, ABS_X,
285 input_report_abs(dev, ABS_Y, 295 (__s16) le16_to_cpup((__le16 *)(data + 12)));
286 ~(__s16) le16_to_cpup((__le16 *)(data + 14))); 296 input_report_abs(dev, ABS_Y,
287 297 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));
288 /* right stick */ 298
289 input_report_abs(dev, ABS_RX, 299 /* right stick */
290 (__s16) le16_to_cpup((__le16 *)(data + 16))); 300 input_report_abs(dev, ABS_RX,
291 input_report_abs(dev, ABS_RY, 301 (__s16) le16_to_cpup((__le16 *)(data + 16)));
292 ~(__s16) le16_to_cpup((__le16 *)(data + 18))); 302 input_report_abs(dev, ABS_RY,
303 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
304 }
293 305
294 /* triggers left/right */ 306 /* triggers left/right */
295 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 307 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
@@ -302,10 +314,11 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
302 314
303 /* digital pad */ 315 /* digital pad */
304 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 316 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
305 input_report_key(dev, BTN_LEFT, data[2] & 0x04); 317 /* dpad as buttons (left, right, up, down) */
306 input_report_key(dev, BTN_RIGHT, data[2] & 0x08); 318 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
307 input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ 319 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
308 input_report_key(dev, BTN_1, data[2] & 0x02); /* down */ 320 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
321 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
309 } else { 322 } else {
310 input_report_abs(dev, ABS_HAT0X, 323 input_report_abs(dev, ABS_HAT0X,
311 !!(data[2] & 0x08) - !!(data[2] & 0x04)); 324 !!(data[2] & 0x08) - !!(data[2] & 0x04));
@@ -315,7 +328,7 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
315 328
316 /* start/back buttons and stick press left/right */ 329 /* start/back buttons and stick press left/right */
317 input_report_key(dev, BTN_START, data[2] & 0x10); 330 input_report_key(dev, BTN_START, data[2] & 0x10);
318 input_report_key(dev, BTN_BACK, data[2] & 0x20); 331 input_report_key(dev, BTN_SELECT, data[2] & 0x20);
319 input_report_key(dev, BTN_THUMBL, data[2] & 0x40); 332 input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
320 input_report_key(dev, BTN_THUMBR, data[2] & 0x80); 333 input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
321 334
@@ -349,11 +362,11 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
349 362
350 /* digital pad */ 363 /* digital pad */
351 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 364 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
352 /* dpad as buttons (right, left, down, up) */ 365 /* dpad as buttons (left, right, up, down) */
353 input_report_key(dev, BTN_LEFT, data[2] & 0x04); 366 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
354 input_report_key(dev, BTN_RIGHT, data[2] & 0x08); 367 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
355 input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ 368 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
356 input_report_key(dev, BTN_1, data[2] & 0x02); /* down */ 369 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
357 } else { 370 } else {
358 input_report_abs(dev, ABS_HAT0X, 371 input_report_abs(dev, ABS_HAT0X,
359 !!(data[2] & 0x08) - !!(data[2] & 0x04)); 372 !!(data[2] & 0x08) - !!(data[2] & 0x04));
@@ -363,7 +376,7 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
363 376
364 /* start/back buttons */ 377 /* start/back buttons */
365 input_report_key(dev, BTN_START, data[2] & 0x10); 378 input_report_key(dev, BTN_START, data[2] & 0x10);
366 input_report_key(dev, BTN_BACK, data[2] & 0x20); 379 input_report_key(dev, BTN_SELECT, data[2] & 0x20);
367 380
368 /* stick press left/right */ 381 /* stick press left/right */
369 input_report_key(dev, BTN_THUMBL, data[2] & 0x40); 382 input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
@@ -378,17 +391,19 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
378 input_report_key(dev, BTN_TR, data[3] & 0x02); 391 input_report_key(dev, BTN_TR, data[3] & 0x02);
379 input_report_key(dev, BTN_MODE, data[3] & 0x04); 392 input_report_key(dev, BTN_MODE, data[3] & 0x04);
380 393
381 /* left stick */ 394 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
382 input_report_abs(dev, ABS_X, 395 /* left stick */
383 (__s16) le16_to_cpup((__le16 *)(data + 6))); 396 input_report_abs(dev, ABS_X,
384 input_report_abs(dev, ABS_Y, 397 (__s16) le16_to_cpup((__le16 *)(data + 6)));
385 ~(__s16) le16_to_cpup((__le16 *)(data + 8))); 398 input_report_abs(dev, ABS_Y,
386 399 ~(__s16) le16_to_cpup((__le16 *)(data + 8)));
387 /* right stick */ 400
388 input_report_abs(dev, ABS_RX, 401 /* right stick */
389 (__s16) le16_to_cpup((__le16 *)(data + 10))); 402 input_report_abs(dev, ABS_RX,
390 input_report_abs(dev, ABS_RY, 403 (__s16) le16_to_cpup((__le16 *)(data + 10)));
391 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); 404 input_report_abs(dev, ABS_RY,
405 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
406 }
392 407
393 /* triggers left/right */ 408 /* triggers left/right */
394 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 409 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
@@ -814,6 +829,8 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
814 xpad->mapping |= MAP_DPAD_TO_BUTTONS; 829 xpad->mapping |= MAP_DPAD_TO_BUTTONS;
815 if (triggers_to_buttons) 830 if (triggers_to_buttons)
816 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; 831 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS;
832 if (sticks_to_null)
833 xpad->mapping |= MAP_STICKS_TO_NULL;
817 } 834 }
818 835
819 xpad->dev = input_dev; 836 xpad->dev = input_dev;
@@ -830,16 +847,20 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
830 input_dev->open = xpad_open; 847 input_dev->open = xpad_open;
831 input_dev->close = xpad_close; 848 input_dev->close = xpad_close;
832 849
833 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 850 input_dev->evbit[0] = BIT_MASK(EV_KEY);
851
852 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
853 input_dev->evbit[0] |= BIT_MASK(EV_ABS);
854 /* set up axes */
855 for (i = 0; xpad_abs[i] >= 0; i++)
856 xpad_set_up_abs(input_dev, xpad_abs[i]);
857 }
834 858
835 /* set up standard buttons and axes */ 859 /* set up standard buttons */
836 for (i = 0; xpad_common_btn[i] >= 0; i++) 860 for (i = 0; xpad_common_btn[i] >= 0; i++)
837 __set_bit(xpad_common_btn[i], input_dev->keybit); 861 __set_bit(xpad_common_btn[i], input_dev->keybit);
838 862
839 for (i = 0; xpad_abs[i] >= 0; i++) 863 /* set up model-specific ones */
840 xpad_set_up_abs(input_dev, xpad_abs[i]);
841
842 /* Now set up model-specific ones */
843 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) { 864 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) {
844 for (i = 0; xpad360_btn[i] >= 0; i++) 865 for (i = 0; xpad360_btn[i] >= 0; i++)
845 __set_bit(xpad360_btn[i], input_dev->keybit); 866 __set_bit(xpad360_btn[i], input_dev->keybit);
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index d8fa5d724c57..9cc488d21490 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -73,7 +73,7 @@ config KEYBOARD_ATKBD
73 default y 73 default y
74 select SERIO 74 select SERIO
75 select SERIO_LIBPS2 75 select SERIO_LIBPS2
76 select SERIO_I8042 if X86 && !X86_MRST 76 select SERIO_I8042 if X86
77 select SERIO_GSCPS2 if GSC 77 select SERIO_GSCPS2 if GSC
78 help 78 help
79 Say Y here if you want to use a standard AT or PS/2 keyboard. Usually 79 Say Y here if you want to use a standard AT or PS/2 keyboard. Usually
@@ -124,7 +124,7 @@ config KEYBOARD_ATKBD_RDI_KEYCODES
124 right-hand column will be interpreted as the key shown in the 124 right-hand column will be interpreted as the key shown in the
125 left-hand column. 125 left-hand column.
126 126
127config QT2160 127config KEYBOARD_QT2160
128 tristate "Atmel AT42QT2160 Touch Sensor Chip" 128 tristate "Atmel AT42QT2160 Touch Sensor Chip"
129 depends on I2C && EXPERIMENTAL 129 depends on I2C && EXPERIMENTAL
130 help 130 help
@@ -297,6 +297,18 @@ config KEYBOARD_MAX7359
297 To compile this driver as a module, choose M here: the 297 To compile this driver as a module, choose M here: the
298 module will be called max7359_keypad. 298 module will be called max7359_keypad.
299 299
300config KEYBOARD_MCS
301 tristate "MELFAS MCS Touchkey"
302 depends on I2C
303 help
304 Say Y here if you have the MELFAS MCS5000/5080 touchkey controller
305 chip in your system.
306
307 If unsure, say N.
308
309 To compile this driver as a module, choose M here: the
310 module will be called mcs_touchkey.
311
300config KEYBOARD_IMX 312config KEYBOARD_IMX
301 tristate "IMX keypad support" 313 tristate "IMX keypad support"
302 depends on ARCH_MXC 314 depends on ARCH_MXC
@@ -342,6 +354,15 @@ config KEYBOARD_PXA930_ROTARY
342 To compile this driver as a module, choose M here: the 354 To compile this driver as a module, choose M here: the
343 module will be called pxa930_rotary. 355 module will be called pxa930_rotary.
344 356
357config KEYBOARD_SAMSUNG
358 tristate "Samsung keypad support"
359 depends on SAMSUNG_DEV_KEYPAD
360 help
361 Say Y here if you want to use the Samsung keypad.
362
363 To compile this driver as a module, choose M here: the
364 module will be called samsung-keypad.
365
345config KEYBOARD_STOWAWAY 366config KEYBOARD_STOWAWAY
346 tristate "Stowaway keyboard" 367 tristate "Stowaway keyboard"
347 select SERIO 368 select SERIO
@@ -374,6 +395,16 @@ config KEYBOARD_SH_KEYSC
374 To compile this driver as a module, choose M here: the 395 To compile this driver as a module, choose M here: the
375 module will be called sh_keysc. 396 module will be called sh_keysc.
376 397
398config KEYBOARD_STMPE
399 tristate "STMPE keypad support"
400 depends on MFD_STMPE
401 help
402 Say Y here if you want to use the keypad controller on STMPE I/O
403 expanders.
404
405 To compile this driver as a module, choose M here: the module will be
406 called stmpe-keypad.
407
377config KEYBOARD_DAVINCI 408config KEYBOARD_DAVINCI
378 tristate "TI DaVinci Key Scan" 409 tristate "TI DaVinci Key Scan"
379 depends on ARCH_DAVINCI_DM365 410 depends on ARCH_DAVINCI_DM365
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 4596d0c6f922..504b591be0cd 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -26,13 +26,16 @@ obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
26obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o 26obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
27obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o 27obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
28obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 28obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
29obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o
29obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 30obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
30obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 31obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
31obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o 32obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o
32obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o 33obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o
33obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o 34obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
34obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o 35obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o
36obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o
35obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o 37obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
38obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o
36obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 39obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
37obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o 40obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
38obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o 41obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index 4771ab172b59..d6918cb966c0 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -19,6 +19,7 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/input.h> 20#include <linux/input.h>
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/gpio.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23 24
24#include <linux/i2c/adp5588.h> 25#include <linux/i2c/adp5588.h>
@@ -54,6 +55,10 @@
54 55
55#define KEYP_MAX_EVENT 10 56#define KEYP_MAX_EVENT 10
56 57
58#define MAXGPIO 18
59#define ADP_BANK(offs) ((offs) >> 3)
60#define ADP_BIT(offs) (1u << ((offs) & 0x7))
61
57/* 62/*
58 * Early pre 4.0 Silicon required to delay readout by at least 25ms, 63 * Early pre 4.0 Silicon required to delay readout by at least 25ms,
59 * since the Event Counter Register updated 25ms after the interrupt 64 * since the Event Counter Register updated 25ms after the interrupt
@@ -67,6 +72,16 @@ struct adp5588_kpad {
67 struct delayed_work work; 72 struct delayed_work work;
68 unsigned long delay; 73 unsigned long delay;
69 unsigned short keycode[ADP5588_KEYMAPSIZE]; 74 unsigned short keycode[ADP5588_KEYMAPSIZE];
75 const struct adp5588_gpi_map *gpimap;
76 unsigned short gpimapsize;
77#ifdef CONFIG_GPIOLIB
78 unsigned char gpiomap[MAXGPIO];
79 bool export_gpio;
80 struct gpio_chip gc;
81 struct mutex gpio_lock; /* Protect cached dir, dat_out */
82 u8 dat_out[3];
83 u8 dir[3];
84#endif
70}; 85};
71 86
72static int adp5588_read(struct i2c_client *client, u8 reg) 87static int adp5588_read(struct i2c_client *client, u8 reg)
@@ -84,12 +99,222 @@ static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
84 return i2c_smbus_write_byte_data(client, reg, val); 99 return i2c_smbus_write_byte_data(client, reg, val);
85} 100}
86 101
102#ifdef CONFIG_GPIOLIB
103static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
104{
105 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
106 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
107 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
108
109 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit);
110}
111
112static void adp5588_gpio_set_value(struct gpio_chip *chip,
113 unsigned off, int val)
114{
115 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
116 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
117 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
118
119 mutex_lock(&kpad->gpio_lock);
120
121 if (val)
122 kpad->dat_out[bank] |= bit;
123 else
124 kpad->dat_out[bank] &= ~bit;
125
126 adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
127 kpad->dat_out[bank]);
128
129 mutex_unlock(&kpad->gpio_lock);
130}
131
132static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
133{
134 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
135 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
136 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
137 int ret;
138
139 mutex_lock(&kpad->gpio_lock);
140
141 kpad->dir[bank] &= ~bit;
142 ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]);
143
144 mutex_unlock(&kpad->gpio_lock);
145
146 return ret;
147}
148
149static int adp5588_gpio_direction_output(struct gpio_chip *chip,
150 unsigned off, int val)
151{
152 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
153 unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
154 unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
155 int ret;
156
157 mutex_lock(&kpad->gpio_lock);
158
159 kpad->dir[bank] |= bit;
160
161 if (val)
162 kpad->dat_out[bank] |= bit;
163 else
164 kpad->dat_out[bank] &= ~bit;
165
166 ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
167 kpad->dat_out[bank]);
168 ret |= adp5588_write(kpad->client, GPIO_DIR1 + bank,
169 kpad->dir[bank]);
170
171 mutex_unlock(&kpad->gpio_lock);
172
173 return ret;
174}
175
176static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
177 const struct adp5588_kpad_platform_data *pdata)
178{
179 bool pin_used[MAXGPIO];
180 int n_unused = 0;
181 int i;
182
183 memset(pin_used, 0, sizeof(pin_used));
184
185 for (i = 0; i < pdata->rows; i++)
186 pin_used[i] = true;
187
188 for (i = 0; i < pdata->cols; i++)
189 pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true;
190
191 for (i = 0; i < kpad->gpimapsize; i++)
192 pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true;
193
194 for (i = 0; i < MAXGPIO; i++)
195 if (!pin_used[i])
196 kpad->gpiomap[n_unused++] = i;
197
198 return n_unused;
199}
200
201static int __devinit adp5588_gpio_add(struct adp5588_kpad *kpad)
202{
203 struct device *dev = &kpad->client->dev;
204 const struct adp5588_kpad_platform_data *pdata = dev->platform_data;
205 const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
206 int i, error;
207
208 if (!gpio_data)
209 return 0;
210
211 kpad->gc.ngpio = adp5588_build_gpiomap(kpad, pdata);
212 if (kpad->gc.ngpio == 0) {
213 dev_info(dev, "No unused gpios left to export\n");
214 return 0;
215 }
216
217 kpad->export_gpio = true;
218
219 kpad->gc.direction_input = adp5588_gpio_direction_input;
220 kpad->gc.direction_output = adp5588_gpio_direction_output;
221 kpad->gc.get = adp5588_gpio_get_value;
222 kpad->gc.set = adp5588_gpio_set_value;
223 kpad->gc.can_sleep = 1;
224
225 kpad->gc.base = gpio_data->gpio_start;
226 kpad->gc.label = kpad->client->name;
227 kpad->gc.owner = THIS_MODULE;
228
229 mutex_init(&kpad->gpio_lock);
230
231 error = gpiochip_add(&kpad->gc);
232 if (error) {
233 dev_err(dev, "gpiochip_add failed, err: %d\n", error);
234 return error;
235 }
236
237 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
238 kpad->dat_out[i] = adp5588_read(kpad->client,
239 GPIO_DAT_OUT1 + i);
240 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i);
241 }
242
243 if (gpio_data->setup) {
244 error = gpio_data->setup(kpad->client,
245 kpad->gc.base, kpad->gc.ngpio,
246 gpio_data->context);
247 if (error)
248 dev_warn(dev, "setup failed, %d\n", error);
249 }
250
251 return 0;
252}
253
254static void __devexit adp5588_gpio_remove(struct adp5588_kpad *kpad)
255{
256 struct device *dev = &kpad->client->dev;
257 const struct adp5588_kpad_platform_data *pdata = dev->platform_data;
258 const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
259 int error;
260
261 if (!kpad->export_gpio)
262 return;
263
264 if (gpio_data->teardown) {
265 error = gpio_data->teardown(kpad->client,
266 kpad->gc.base, kpad->gc.ngpio,
267 gpio_data->context);
268 if (error)
269 dev_warn(dev, "teardown failed %d\n", error);
270 }
271
272 error = gpiochip_remove(&kpad->gc);
273 if (error)
274 dev_warn(dev, "gpiochip_remove failed %d\n", error);
275}
276#else
277static inline int adp5588_gpio_add(struct adp5588_kpad *kpad)
278{
279 return 0;
280}
281
282static inline void adp5588_gpio_remove(struct adp5588_kpad *kpad)
283{
284}
285#endif
286
287static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
288{
289 int i, j;
290
291 for (i = 0; i < ev_cnt; i++) {
292 int key = adp5588_read(kpad->client, Key_EVENTA + i);
293 int key_val = key & KEY_EV_MASK;
294
295 if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) {
296 for (j = 0; j < kpad->gpimapsize; j++) {
297 if (key_val == kpad->gpimap[j].pin) {
298 input_report_switch(kpad->input,
299 kpad->gpimap[j].sw_evt,
300 key & KEY_EV_PRESSED);
301 break;
302 }
303 }
304 } else {
305 input_report_key(kpad->input,
306 kpad->keycode[key_val - 1],
307 key & KEY_EV_PRESSED);
308 }
309 }
310}
311
87static void adp5588_work(struct work_struct *work) 312static void adp5588_work(struct work_struct *work)
88{ 313{
89 struct adp5588_kpad *kpad = container_of(work, 314 struct adp5588_kpad *kpad = container_of(work,
90 struct adp5588_kpad, work.work); 315 struct adp5588_kpad, work.work);
91 struct i2c_client *client = kpad->client; 316 struct i2c_client *client = kpad->client;
92 int i, key, status, ev_cnt; 317 int status, ev_cnt;
93 318
94 status = adp5588_read(client, INT_STAT); 319 status = adp5588_read(client, INT_STAT);
95 320
@@ -99,12 +324,7 @@ static void adp5588_work(struct work_struct *work)
99 if (status & KE_INT) { 324 if (status & KE_INT) {
100 ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & KEC; 325 ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & KEC;
101 if (ev_cnt) { 326 if (ev_cnt) {
102 for (i = 0; i < ev_cnt; i++) { 327 adp5588_report_events(kpad, ev_cnt);
103 key = adp5588_read(client, Key_EVENTA + i);
104 input_report_key(kpad->input,
105 kpad->keycode[(key & KEY_EV_MASK) - 1],
106 key & KEY_EV_PRESSED);
107 }
108 input_sync(kpad->input); 328 input_sync(kpad->input);
109 } 329 }
110 } 330 }
@@ -128,8 +348,10 @@ static irqreturn_t adp5588_irq(int irq, void *handle)
128 348
129static int __devinit adp5588_setup(struct i2c_client *client) 349static int __devinit adp5588_setup(struct i2c_client *client)
130{ 350{
131 struct adp5588_kpad_platform_data *pdata = client->dev.platform_data; 351 const struct adp5588_kpad_platform_data *pdata = client->dev.platform_data;
352 const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
132 int i, ret; 353 int i, ret;
354 unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
133 355
134 ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows)); 356 ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows));
135 ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF); 357 ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
@@ -144,6 +366,32 @@ static int __devinit adp5588_setup(struct i2c_client *client)
144 for (i = 0; i < KEYP_MAX_EVENT; i++) 366 for (i = 0; i < KEYP_MAX_EVENT; i++)
145 ret |= adp5588_read(client, Key_EVENTA); 367 ret |= adp5588_read(client, Key_EVENTA);
146 368
369 for (i = 0; i < pdata->gpimapsize; i++) {
370 unsigned short pin = pdata->gpimap[i].pin;
371
372 if (pin <= GPI_PIN_ROW_END) {
373 evt_mode1 |= (1 << (pin - GPI_PIN_ROW_BASE));
374 } else {
375 evt_mode2 |= ((1 << (pin - GPI_PIN_COL_BASE)) & 0xFF);
376 evt_mode3 |= ((1 << (pin - GPI_PIN_COL_BASE)) >> 8);
377 }
378 }
379
380 if (pdata->gpimapsize) {
381 ret |= adp5588_write(client, GPI_EM1, evt_mode1);
382 ret |= adp5588_write(client, GPI_EM2, evt_mode2);
383 ret |= adp5588_write(client, GPI_EM3, evt_mode3);
384 }
385
386 if (gpio_data) {
387 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
388 int pull_mask = gpio_data->pullup_dis_mask;
389
390 ret |= adp5588_write(client, GPIO_PULL1 + i,
391 (pull_mask >> (8 * i)) & 0xFF);
392 }
393 }
394
147 ret |= adp5588_write(client, INT_STAT, CMP2_INT | CMP1_INT | 395 ret |= adp5588_write(client, INT_STAT, CMP2_INT | CMP1_INT |
148 OVR_FLOW_INT | K_LCK_INT | 396 OVR_FLOW_INT | K_LCK_INT |
149 GPI_INT | KE_INT); /* Status is W1C */ 397 GPI_INT | KE_INT); /* Status is W1C */
@@ -158,11 +406,49 @@ static int __devinit adp5588_setup(struct i2c_client *client)
158 return 0; 406 return 0;
159} 407}
160 408
409static void __devinit adp5588_report_switch_state(struct adp5588_kpad *kpad)
410{
411 int gpi_stat1 = adp5588_read(kpad->client, GPIO_DAT_STAT1);
412 int gpi_stat2 = adp5588_read(kpad->client, GPIO_DAT_STAT2);
413 int gpi_stat3 = adp5588_read(kpad->client, GPIO_DAT_STAT3);
414 int gpi_stat_tmp, pin_loc;
415 int i;
416
417 for (i = 0; i < kpad->gpimapsize; i++) {
418 unsigned short pin = kpad->gpimap[i].pin;
419
420 if (pin <= GPI_PIN_ROW_END) {
421 gpi_stat_tmp = gpi_stat1;
422 pin_loc = pin - GPI_PIN_ROW_BASE;
423 } else if ((pin - GPI_PIN_COL_BASE) < 8) {
424 gpi_stat_tmp = gpi_stat2;
425 pin_loc = pin - GPI_PIN_COL_BASE;
426 } else {
427 gpi_stat_tmp = gpi_stat3;
428 pin_loc = pin - GPI_PIN_COL_BASE - 8;
429 }
430
431 if (gpi_stat_tmp < 0) {
432 dev_err(&kpad->client->dev,
433 "Can't read GPIO_DAT_STAT switch %d default to OFF\n",
434 pin);
435 gpi_stat_tmp = 0;
436 }
437
438 input_report_switch(kpad->input,
439 kpad->gpimap[i].sw_evt,
440 !(gpi_stat_tmp & (1 << pin_loc)));
441 }
442
443 input_sync(kpad->input);
444}
445
446
161static int __devinit adp5588_probe(struct i2c_client *client, 447static int __devinit adp5588_probe(struct i2c_client *client,
162 const struct i2c_device_id *id) 448 const struct i2c_device_id *id)
163{ 449{
164 struct adp5588_kpad *kpad; 450 struct adp5588_kpad *kpad;
165 struct adp5588_kpad_platform_data *pdata = client->dev.platform_data; 451 const struct adp5588_kpad_platform_data *pdata = client->dev.platform_data;
166 struct input_dev *input; 452 struct input_dev *input;
167 unsigned int revid; 453 unsigned int revid;
168 int ret, i; 454 int ret, i;
@@ -189,6 +475,37 @@ static int __devinit adp5588_probe(struct i2c_client *client,
189 return -EINVAL; 475 return -EINVAL;
190 } 476 }
191 477
478 if (!pdata->gpimap && pdata->gpimapsize) {
479 dev_err(&client->dev, "invalid gpimap from pdata\n");
480 return -EINVAL;
481 }
482
483 if (pdata->gpimapsize > ADP5588_GPIMAPSIZE_MAX) {
484 dev_err(&client->dev, "invalid gpimapsize\n");
485 return -EINVAL;
486 }
487
488 for (i = 0; i < pdata->gpimapsize; i++) {
489 unsigned short pin = pdata->gpimap[i].pin;
490
491 if (pin < GPI_PIN_BASE || pin > GPI_PIN_END) {
492 dev_err(&client->dev, "invalid gpi pin data\n");
493 return -EINVAL;
494 }
495
496 if (pin <= GPI_PIN_ROW_END) {
497 if (pin - GPI_PIN_ROW_BASE + 1 <= pdata->rows) {
498 dev_err(&client->dev, "invalid gpi row data\n");
499 return -EINVAL;
500 }
501 } else {
502 if (pin - GPI_PIN_COL_BASE + 1 <= pdata->cols) {
503 dev_err(&client->dev, "invalid gpi col data\n");
504 return -EINVAL;
505 }
506 }
507 }
508
192 if (!client->irq) { 509 if (!client->irq) {
193 dev_err(&client->dev, "no IRQ?\n"); 510 dev_err(&client->dev, "no IRQ?\n");
194 return -EINVAL; 511 return -EINVAL;
@@ -233,6 +550,9 @@ static int __devinit adp5588_probe(struct i2c_client *client,
233 memcpy(kpad->keycode, pdata->keymap, 550 memcpy(kpad->keycode, pdata->keymap,
234 pdata->keymapsize * input->keycodesize); 551 pdata->keymapsize * input->keycodesize);
235 552
553 kpad->gpimap = pdata->gpimap;
554 kpad->gpimapsize = pdata->gpimapsize;
555
236 /* setup input device */ 556 /* setup input device */
237 __set_bit(EV_KEY, input->evbit); 557 __set_bit(EV_KEY, input->evbit);
238 558
@@ -243,6 +563,11 @@ static int __devinit adp5588_probe(struct i2c_client *client,
243 __set_bit(kpad->keycode[i] & KEY_MAX, input->keybit); 563 __set_bit(kpad->keycode[i] & KEY_MAX, input->keybit);
244 __clear_bit(KEY_RESERVED, input->keybit); 564 __clear_bit(KEY_RESERVED, input->keybit);
245 565
566 if (kpad->gpimapsize)
567 __set_bit(EV_SW, input->evbit);
568 for (i = 0; i < kpad->gpimapsize; i++)
569 __set_bit(kpad->gpimap[i].sw_evt, input->swbit);
570
246 error = input_register_device(input); 571 error = input_register_device(input);
247 if (error) { 572 if (error) {
248 dev_err(&client->dev, "unable to register input device\n"); 573 dev_err(&client->dev, "unable to register input device\n");
@@ -261,6 +586,13 @@ static int __devinit adp5588_probe(struct i2c_client *client,
261 if (error) 586 if (error)
262 goto err_free_irq; 587 goto err_free_irq;
263 588
589 if (kpad->gpimapsize)
590 adp5588_report_switch_state(kpad);
591
592 error = adp5588_gpio_add(kpad);
593 if (error)
594 goto err_free_irq;
595
264 device_init_wakeup(&client->dev, 1); 596 device_init_wakeup(&client->dev, 1);
265 i2c_set_clientdata(client, kpad); 597 i2c_set_clientdata(client, kpad);
266 598
@@ -287,7 +619,7 @@ static int __devexit adp5588_remove(struct i2c_client *client)
287 free_irq(client->irq, kpad); 619 free_irq(client->irq, kpad);
288 cancel_delayed_work_sync(&kpad->work); 620 cancel_delayed_work_sync(&kpad->work);
289 input_unregister_device(kpad->input); 621 input_unregister_device(kpad->input);
290 i2c_set_clientdata(client, NULL); 622 adp5588_gpio_remove(kpad);
291 kfree(kpad); 623 kfree(kpad);
292 624
293 return 0; 625 return 0;
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b8213fd13c3f..6069abe31e42 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -31,6 +31,7 @@ struct gpio_button_data {
31 struct input_dev *input; 31 struct input_dev *input;
32 struct timer_list timer; 32 struct timer_list timer;
33 struct work_struct work; 33 struct work_struct work;
34 int timer_debounce; /* in msecs */
34 bool disabled; 35 bool disabled;
35}; 36};
36 37
@@ -38,6 +39,8 @@ struct gpio_keys_drvdata {
38 struct input_dev *input; 39 struct input_dev *input;
39 struct mutex disable_lock; 40 struct mutex disable_lock;
40 unsigned int n_buttons; 41 unsigned int n_buttons;
42 int (*enable)(struct device *dev);
43 void (*disable)(struct device *dev);
41 struct gpio_button_data data[0]; 44 struct gpio_button_data data[0];
42}; 45};
43 46
@@ -109,7 +112,7 @@ static void gpio_keys_disable_button(struct gpio_button_data *bdata)
109 * Disable IRQ and possible debouncing timer. 112 * Disable IRQ and possible debouncing timer.
110 */ 113 */
111 disable_irq(gpio_to_irq(bdata->button->gpio)); 114 disable_irq(gpio_to_irq(bdata->button->gpio));
112 if (bdata->button->debounce_interval) 115 if (bdata->timer_debounce)
113 del_timer_sync(&bdata->timer); 116 del_timer_sync(&bdata->timer);
114 117
115 bdata->disabled = true; 118 bdata->disabled = true;
@@ -347,9 +350,9 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
347 350
348 BUG_ON(irq != gpio_to_irq(button->gpio)); 351 BUG_ON(irq != gpio_to_irq(button->gpio));
349 352
350 if (button->debounce_interval) 353 if (bdata->timer_debounce)
351 mod_timer(&bdata->timer, 354 mod_timer(&bdata->timer,
352 jiffies + msecs_to_jiffies(button->debounce_interval)); 355 jiffies + msecs_to_jiffies(bdata->timer_debounce));
353 else 356 else
354 schedule_work(&bdata->work); 357 schedule_work(&bdata->work);
355 358
@@ -383,6 +386,14 @@ static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
383 goto fail3; 386 goto fail3;
384 } 387 }
385 388
389 if (button->debounce_interval) {
390 error = gpio_set_debounce(button->gpio,
391 button->debounce_interval * 1000);
392 /* use timer if gpiolib doesn't provide debounce */
393 if (error < 0)
394 bdata->timer_debounce = button->debounce_interval;
395 }
396
386 irq = gpio_to_irq(button->gpio); 397 irq = gpio_to_irq(button->gpio);
387 if (irq < 0) { 398 if (irq < 0) {
388 error = irq; 399 error = irq;
@@ -414,6 +425,21 @@ fail2:
414 return error; 425 return error;
415} 426}
416 427
428static int gpio_keys_open(struct input_dev *input)
429{
430 struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
431
432 return ddata->enable ? ddata->enable(input->dev.parent) : 0;
433}
434
435static void gpio_keys_close(struct input_dev *input)
436{
437 struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
438
439 if (ddata->disable)
440 ddata->disable(input->dev.parent);
441}
442
417static int __devinit gpio_keys_probe(struct platform_device *pdev) 443static int __devinit gpio_keys_probe(struct platform_device *pdev)
418{ 444{
419 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 445 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -435,13 +461,18 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
435 461
436 ddata->input = input; 462 ddata->input = input;
437 ddata->n_buttons = pdata->nbuttons; 463 ddata->n_buttons = pdata->nbuttons;
464 ddata->enable = pdata->enable;
465 ddata->disable = pdata->disable;
438 mutex_init(&ddata->disable_lock); 466 mutex_init(&ddata->disable_lock);
439 467
440 platform_set_drvdata(pdev, ddata); 468 platform_set_drvdata(pdev, ddata);
469 input_set_drvdata(input, ddata);
441 470
442 input->name = pdev->name; 471 input->name = pdev->name;
443 input->phys = "gpio-keys/input0"; 472 input->phys = "gpio-keys/input0";
444 input->dev.parent = &pdev->dev; 473 input->dev.parent = &pdev->dev;
474 input->open = gpio_keys_open;
475 input->close = gpio_keys_close;
445 476
446 input->id.bustype = BUS_HOST; 477 input->id.bustype = BUS_HOST;
447 input->id.vendor = 0x0001; 478 input->id.vendor = 0x0001;
@@ -498,7 +529,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
498 fail2: 529 fail2:
499 while (--i >= 0) { 530 while (--i >= 0) {
500 free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]); 531 free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
501 if (pdata->buttons[i].debounce_interval) 532 if (ddata->data[i].timer_debounce)
502 del_timer_sync(&ddata->data[i].timer); 533 del_timer_sync(&ddata->data[i].timer);
503 cancel_work_sync(&ddata->data[i].work); 534 cancel_work_sync(&ddata->data[i].work);
504 gpio_free(pdata->buttons[i].gpio); 535 gpio_free(pdata->buttons[i].gpio);
@@ -526,7 +557,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
526 for (i = 0; i < pdata->nbuttons; i++) { 557 for (i = 0; i < pdata->nbuttons; i++) {
527 int irq = gpio_to_irq(pdata->buttons[i].gpio); 558 int irq = gpio_to_irq(pdata->buttons[i].gpio);
528 free_irq(irq, &ddata->data[i]); 559 free_irq(irq, &ddata->data[i]);
529 if (pdata->buttons[i].debounce_interval) 560 if (ddata->data[i].timer_debounce)
530 del_timer_sync(&ddata->data[i].timer); 561 del_timer_sync(&ddata->data[i].timer);
531 cancel_work_sync(&ddata->data[i].work); 562 cancel_work_sync(&ddata->data[i].work);
532 gpio_free(pdata->buttons[i].gpio); 563 gpio_free(pdata->buttons[i].gpio);
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index c83f4b2ec7d3..dcc86b97a153 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -232,15 +232,16 @@ static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
232 if (absdev) { 232 if (absdev) {
233 val = lo + (hi << 8); 233 val = lo + (hi << 8);
234#ifdef TABLET_AUTOADJUST 234#ifdef TABLET_AUTOADJUST
235 if (val < dev->absmin[ABS_X + i]) 235 if (val < input_abs_min(dev, ABS_X + i))
236 dev->absmin[ABS_X + i] = val; 236 input_abs_set_min(dev, ABS_X + i, val);
237 if (val > dev->absmax[ABS_X + i]) 237 if (val > input_abs_max(dev, ABS_X + i))
238 dev->absmax[ABS_X + i] = val; 238 input_abs_set_max(dev, ABS_X + i, val);
239#endif 239#endif
240 if (i%3) val = dev->absmax[ABS_X + i] - val; 240 if (i % 3)
241 val = input_abs_max(dev, ABS_X + i) - val;
241 input_report_abs(dev, ABS_X + i, val); 242 input_report_abs(dev, ABS_X + i, val);
242 } else { 243 } else {
243 val = (int) (((int8_t)lo) | ((int8_t)hi << 8)); 244 val = (int) (((int8_t) lo) | ((int8_t) hi << 8));
244 if (i % 3) 245 if (i % 3)
245 val *= -1; 246 val *= -1;
246 input_report_rel(dev, REL_X + i, val); 247 input_report_rel(dev, REL_X + i, val);
@@ -387,9 +388,11 @@ static void hil_dev_pointer_setup(struct hil_dev *ptr)
387 388
388#ifdef TABLET_AUTOADJUST 389#ifdef TABLET_AUTOADJUST
389 for (i = 0; i < ABS_MAX; i++) { 390 for (i = 0; i < ABS_MAX; i++) {
390 int diff = input_dev->absmax[ABS_X + i] / 10; 391 int diff = input_abs_max(input_dev, ABS_X + i) / 10;
391 input_dev->absmin[ABS_X + i] += diff; 392 input_abs_set_min(input_dev, ABS_X + i,
392 input_dev->absmax[ABS_X + i] -= diff; 393 input_abs_min(input_dev, ABS_X + i) + diff)
394 input_abs_set_max(input_dev, ABS_X + i,
395 input_abs_max(input_dev, ABS_X + i) - diff)
393 } 396 }
394#endif 397#endif
395 398
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index bc696931fed7..f7c2a166576b 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -642,6 +642,7 @@ static int __devinit lm8323_probe(struct i2c_client *client,
642 struct lm8323_platform_data *pdata = client->dev.platform_data; 642 struct lm8323_platform_data *pdata = client->dev.platform_data;
643 struct input_dev *idev; 643 struct input_dev *idev;
644 struct lm8323_chip *lm; 644 struct lm8323_chip *lm;
645 int pwm;
645 int i, err; 646 int i, err;
646 unsigned long tmo; 647 unsigned long tmo;
647 u8 data[2]; 648 u8 data[2];
@@ -710,8 +711,9 @@ static int __devinit lm8323_probe(struct i2c_client *client,
710 goto fail1; 711 goto fail1;
711 } 712 }
712 713
713 for (i = 0; i < LM8323_NUM_PWMS; i++) { 714 for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) {
714 err = init_pwm(lm, i + 1, &client->dev, pdata->pwm_names[i]); 715 err = init_pwm(lm, pwm + 1, &client->dev,
716 pdata->pwm_names[pwm]);
715 if (err < 0) 717 if (err < 0)
716 goto fail2; 718 goto fail2;
717 } 719 }
@@ -764,9 +766,9 @@ fail4:
764fail3: 766fail3:
765 device_remove_file(&client->dev, &dev_attr_disable_kp); 767 device_remove_file(&client->dev, &dev_attr_disable_kp);
766fail2: 768fail2:
767 while (--i >= 0) 769 while (--pwm >= 0)
768 if (lm->pwm[i].enabled) 770 if (lm->pwm[pwm].enabled)
769 led_classdev_unregister(&lm->pwm[i].cdev); 771 led_classdev_unregister(&lm->pwm[pwm].cdev);
770fail1: 772fail1:
771 input_free_device(idev); 773 input_free_device(idev);
772 kfree(lm); 774 kfree(lm);
@@ -778,8 +780,6 @@ static int __devexit lm8323_remove(struct i2c_client *client)
778 struct lm8323_chip *lm = i2c_get_clientdata(client); 780 struct lm8323_chip *lm = i2c_get_clientdata(client);
779 int i; 781 int i;
780 782
781 i2c_set_clientdata(client, NULL);
782
783 disable_irq_wake(client->irq); 783 disable_irq_wake(client->irq);
784 free_irq(client->irq, lm); 784 free_irq(client->irq, lm);
785 cancel_work_sync(&lm->work); 785 cancel_work_sync(&lm->work);
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index b443e088fd3c..b02e4268e18f 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -37,6 +37,7 @@ struct matrix_keypad {
37 spinlock_t lock; 37 spinlock_t lock;
38 bool scan_pending; 38 bool scan_pending;
39 bool stopped; 39 bool stopped;
40 bool gpio_all_disabled;
40}; 41};
41 42
42/* 43/*
@@ -87,8 +88,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
87 const struct matrix_keypad_platform_data *pdata = keypad->pdata; 88 const struct matrix_keypad_platform_data *pdata = keypad->pdata;
88 int i; 89 int i;
89 90
90 for (i = 0; i < pdata->num_row_gpios; i++) 91 if (pdata->clustered_irq > 0)
91 enable_irq(gpio_to_irq(pdata->row_gpios[i])); 92 enable_irq(pdata->clustered_irq);
93 else {
94 for (i = 0; i < pdata->num_row_gpios; i++)
95 enable_irq(gpio_to_irq(pdata->row_gpios[i]));
96 }
92} 97}
93 98
94static void disable_row_irqs(struct matrix_keypad *keypad) 99static void disable_row_irqs(struct matrix_keypad *keypad)
@@ -96,8 +101,12 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
96 const struct matrix_keypad_platform_data *pdata = keypad->pdata; 101 const struct matrix_keypad_platform_data *pdata = keypad->pdata;
97 int i; 102 int i;
98 103
99 for (i = 0; i < pdata->num_row_gpios; i++) 104 if (pdata->clustered_irq > 0)
100 disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i])); 105 disable_irq_nosync(pdata->clustered_irq);
106 else {
107 for (i = 0; i < pdata->num_row_gpios; i++)
108 disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
109 }
101} 110}
102 111
103/* 112/*
@@ -216,45 +225,69 @@ static void matrix_keypad_stop(struct input_dev *dev)
216} 225}
217 226
218#ifdef CONFIG_PM 227#ifdef CONFIG_PM
219static int matrix_keypad_suspend(struct device *dev) 228static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad)
220{ 229{
221 struct platform_device *pdev = to_platform_device(dev);
222 struct matrix_keypad *keypad = platform_get_drvdata(pdev);
223 const struct matrix_keypad_platform_data *pdata = keypad->pdata; 230 const struct matrix_keypad_platform_data *pdata = keypad->pdata;
231 unsigned int gpio;
224 int i; 232 int i;
225 233
226 matrix_keypad_stop(keypad->input_dev); 234 if (pdata->clustered_irq > 0) {
235 if (enable_irq_wake(pdata->clustered_irq) == 0)
236 keypad->gpio_all_disabled = true;
237 } else {
227 238
228 if (device_may_wakeup(&pdev->dev)) {
229 for (i = 0; i < pdata->num_row_gpios; i++) { 239 for (i = 0; i < pdata->num_row_gpios; i++) {
230 if (!test_bit(i, keypad->disabled_gpios)) { 240 if (!test_bit(i, keypad->disabled_gpios)) {
231 unsigned int gpio = pdata->row_gpios[i]; 241 gpio = pdata->row_gpios[i];
232 242
233 if (enable_irq_wake(gpio_to_irq(gpio)) == 0) 243 if (enable_irq_wake(gpio_to_irq(gpio)) == 0)
234 __set_bit(i, keypad->disabled_gpios); 244 __set_bit(i, keypad->disabled_gpios);
235 } 245 }
236 } 246 }
237 } 247 }
238
239 return 0;
240} 248}
241 249
242static int matrix_keypad_resume(struct device *dev) 250static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad)
243{ 251{
244 struct platform_device *pdev = to_platform_device(dev);
245 struct matrix_keypad *keypad = platform_get_drvdata(pdev);
246 const struct matrix_keypad_platform_data *pdata = keypad->pdata; 252 const struct matrix_keypad_platform_data *pdata = keypad->pdata;
253 unsigned int gpio;
247 int i; 254 int i;
248 255
249 if (device_may_wakeup(&pdev->dev)) { 256 if (pdata->clustered_irq > 0) {
257 if (keypad->gpio_all_disabled) {
258 disable_irq_wake(pdata->clustered_irq);
259 keypad->gpio_all_disabled = false;
260 }
261 } else {
250 for (i = 0; i < pdata->num_row_gpios; i++) { 262 for (i = 0; i < pdata->num_row_gpios; i++) {
251 if (test_and_clear_bit(i, keypad->disabled_gpios)) { 263 if (test_and_clear_bit(i, keypad->disabled_gpios)) {
252 unsigned int gpio = pdata->row_gpios[i]; 264 gpio = pdata->row_gpios[i];
253
254 disable_irq_wake(gpio_to_irq(gpio)); 265 disable_irq_wake(gpio_to_irq(gpio));
255 } 266 }
256 } 267 }
257 } 268 }
269}
270
271static int matrix_keypad_suspend(struct device *dev)
272{
273 struct platform_device *pdev = to_platform_device(dev);
274 struct matrix_keypad *keypad = platform_get_drvdata(pdev);
275
276 matrix_keypad_stop(keypad->input_dev);
277
278 if (device_may_wakeup(&pdev->dev))
279 matrix_keypad_enable_wakeup(keypad);
280
281 return 0;
282}
283
284static int matrix_keypad_resume(struct device *dev)
285{
286 struct platform_device *pdev = to_platform_device(dev);
287 struct matrix_keypad *keypad = platform_get_drvdata(pdev);
288
289 if (device_may_wakeup(&pdev->dev))
290 matrix_keypad_disable_wakeup(keypad);
258 291
259 matrix_keypad_start(keypad->input_dev); 292 matrix_keypad_start(keypad->input_dev);
260 293
@@ -296,17 +329,31 @@ static int __devinit init_matrix_gpio(struct platform_device *pdev,
296 gpio_direction_input(pdata->row_gpios[i]); 329 gpio_direction_input(pdata->row_gpios[i]);
297 } 330 }
298 331
299 for (i = 0; i < pdata->num_row_gpios; i++) { 332 if (pdata->clustered_irq > 0) {
300 err = request_irq(gpio_to_irq(pdata->row_gpios[i]), 333 err = request_irq(pdata->clustered_irq,
301 matrix_keypad_interrupt, 334 matrix_keypad_interrupt,
302 IRQF_DISABLED | 335 pdata->clustered_irq_flags,
303 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
304 "matrix-keypad", keypad); 336 "matrix-keypad", keypad);
305 if (err) { 337 if (err) {
306 dev_err(&pdev->dev, 338 dev_err(&pdev->dev,
307 "Unable to acquire interrupt for GPIO line %i\n", 339 "Unable to acquire clustered interrupt\n");
308 pdata->row_gpios[i]); 340 goto err_free_rows;
309 goto err_free_irqs; 341 }
342 } else {
343 for (i = 0; i < pdata->num_row_gpios; i++) {
344 err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
345 matrix_keypad_interrupt,
346 IRQF_DISABLED |
347 IRQF_TRIGGER_RISING |
348 IRQF_TRIGGER_FALLING,
349 "matrix-keypad", keypad);
350 if (err) {
351 dev_err(&pdev->dev,
352 "Unable to acquire interrupt "
353 "for GPIO line %i\n",
354 pdata->row_gpios[i]);
355 goto err_free_irqs;
356 }
310 } 357 }
311 } 358 }
312 359
@@ -418,11 +465,16 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
418 465
419 device_init_wakeup(&pdev->dev, 0); 466 device_init_wakeup(&pdev->dev, 0);
420 467
421 for (i = 0; i < pdata->num_row_gpios; i++) { 468 if (pdata->clustered_irq > 0) {
422 free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad); 469 free_irq(pdata->clustered_irq, keypad);
423 gpio_free(pdata->row_gpios[i]); 470 } else {
471 for (i = 0; i < pdata->num_row_gpios; i++)
472 free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
424 } 473 }
425 474
475 for (i = 0; i < pdata->num_row_gpios; i++)
476 gpio_free(pdata->row_gpios[i]);
477
426 for (i = 0; i < pdata->num_col_gpios; i++) 478 for (i = 0; i < pdata->num_col_gpios; i++)
427 gpio_free(pdata->col_gpios[i]); 479 gpio_free(pdata->col_gpios[i]);
428 480
diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c
index 7fc8185e5c1b..9091ff5ea808 100644
--- a/drivers/input/keyboard/max7359_keypad.c
+++ b/drivers/input/keyboard/max7359_keypad.c
@@ -265,7 +265,6 @@ static int __devexit max7359_remove(struct i2c_client *client)
265 265
266 free_irq(client->irq, keypad); 266 free_irq(client->irq, keypad);
267 input_unregister_device(keypad->input_dev); 267 input_unregister_device(keypad->input_dev);
268 i2c_set_clientdata(client, NULL);
269 kfree(keypad); 268 kfree(keypad);
270 269
271 return 0; 270 return 0;
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
new file mode 100644
index 000000000000..63b849d7e90b
--- /dev/null
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -0,0 +1,239 @@
1/*
2 * mcs_touchkey.c - Touchkey driver for MELFAS MCS5000/5080 controller
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: HeungJun Kim <riverful.kim@samsung.com>
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/i2c.h>
17#include <linux/i2c/mcs.h>
18#include <linux/interrupt.h>
19#include <linux/input.h>
20#include <linux/irq.h>
21#include <linux/slab.h>
22
23/* MCS5000 Touchkey */
24#define MCS5000_TOUCHKEY_STATUS 0x04
25#define MCS5000_TOUCHKEY_STATUS_PRESS 7
26#define MCS5000_TOUCHKEY_FW 0x0a
27#define MCS5000_TOUCHKEY_BASE_VAL 0x61
28
29/* MCS5080 Touchkey */
30#define MCS5080_TOUCHKEY_STATUS 0x00
31#define MCS5080_TOUCHKEY_STATUS_PRESS 3
32#define MCS5080_TOUCHKEY_FW 0x01
33#define MCS5080_TOUCHKEY_BASE_VAL 0x1
34
35enum mcs_touchkey_type {
36 MCS5000_TOUCHKEY,
37 MCS5080_TOUCHKEY,
38};
39
40struct mcs_touchkey_chip {
41 unsigned int status_reg;
42 unsigned int pressbit;
43 unsigned int press_invert;
44 unsigned int baseval;
45};
46
47struct mcs_touchkey_data {
48 struct i2c_client *client;
49 struct input_dev *input_dev;
50 struct mcs_touchkey_chip chip;
51 unsigned int key_code;
52 unsigned int key_val;
53 unsigned short keycodes[];
54};
55
56static irqreturn_t mcs_touchkey_interrupt(int irq, void *dev_id)
57{
58 struct mcs_touchkey_data *data = dev_id;
59 struct mcs_touchkey_chip *chip = &data->chip;
60 struct i2c_client *client = data->client;
61 struct input_dev *input = data->input_dev;
62 unsigned int key_val;
63 unsigned int pressed;
64 int val;
65
66 val = i2c_smbus_read_byte_data(client, chip->status_reg);
67 if (val < 0) {
68 dev_err(&client->dev, "i2c read error [%d]\n", val);
69 goto out;
70 }
71
72 pressed = (val & (1 << chip->pressbit)) >> chip->pressbit;
73 if (chip->press_invert)
74 pressed ^= chip->press_invert;
75
76 /* key_val is 0 when released, so we should use key_val of press. */
77 if (pressed) {
78 key_val = val & (0xff >> (8 - chip->pressbit));
79 if (!key_val)
80 goto out;
81 key_val -= chip->baseval;
82 data->key_code = data->keycodes[key_val];
83 data->key_val = key_val;
84 }
85
86 input_event(input, EV_MSC, MSC_SCAN, data->key_val);
87 input_report_key(input, data->key_code, pressed);
88 input_sync(input);
89
90 dev_dbg(&client->dev, "key %d %d %s\n", data->key_val, data->key_code,
91 pressed ? "pressed" : "released");
92
93 out:
94 return IRQ_HANDLED;
95}
96
97static int __devinit mcs_touchkey_probe(struct i2c_client *client,
98 const struct i2c_device_id *id)
99{
100 const struct mcs_platform_data *pdata;
101 struct mcs_touchkey_data *data;
102 struct input_dev *input_dev;
103 unsigned int fw_reg;
104 int fw_ver;
105 int error;
106 int i;
107
108 pdata = client->dev.platform_data;
109 if (!pdata) {
110 dev_err(&client->dev, "no platform data defined\n");
111 return -EINVAL;
112 }
113
114 data = kzalloc(sizeof(struct mcs_touchkey_data) +
115 sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
116 GFP_KERNEL);
117 input_dev = input_allocate_device();
118 if (!data || !input_dev) {
119 dev_err(&client->dev, "Failed to allocate memory\n");
120 error = -ENOMEM;
121 goto err_free_mem;
122 }
123
124 data->client = client;
125 data->input_dev = input_dev;
126
127 if (id->driver_data == MCS5000_TOUCHKEY) {
128 data->chip.status_reg = MCS5000_TOUCHKEY_STATUS;
129 data->chip.pressbit = MCS5000_TOUCHKEY_STATUS_PRESS;
130 data->chip.baseval = MCS5000_TOUCHKEY_BASE_VAL;
131 fw_reg = MCS5000_TOUCHKEY_FW;
132 } else {
133 data->chip.status_reg = MCS5080_TOUCHKEY_STATUS;
134 data->chip.pressbit = MCS5080_TOUCHKEY_STATUS_PRESS;
135 data->chip.press_invert = 1;
136 data->chip.baseval = MCS5080_TOUCHKEY_BASE_VAL;
137 fw_reg = MCS5080_TOUCHKEY_FW;
138 }
139
140 fw_ver = i2c_smbus_read_byte_data(client, fw_reg);
141 if (fw_ver < 0) {
142 error = fw_ver;
143 dev_err(&client->dev, "i2c read error[%d]\n", error);
144 goto err_free_mem;
145 }
146 dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
147
148 input_dev->name = "MELPAS MCS Touchkey";
149 input_dev->id.bustype = BUS_I2C;
150 input_dev->dev.parent = &client->dev;
151 input_dev->evbit[0] = BIT_MASK(EV_KEY);
152 if (!pdata->no_autorepeat)
153 input_dev->evbit[0] |= BIT_MASK(EV_REP);
154 input_dev->keycode = data->keycodes;
155 input_dev->keycodesize = sizeof(data->keycodes[0]);
156 input_dev->keycodemax = pdata->key_maxval + 1;
157
158 for (i = 0; i < pdata->keymap_size; i++) {
159 unsigned int val = MCS_KEY_VAL(pdata->keymap[i]);
160 unsigned int code = MCS_KEY_CODE(pdata->keymap[i]);
161
162 data->keycodes[val] = code;
163 __set_bit(code, input_dev->keybit);
164 }
165
166 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
167 input_set_drvdata(input_dev, data);
168
169 if (pdata->cfg_pin)
170 pdata->cfg_pin();
171
172 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
173 IRQF_TRIGGER_FALLING, client->dev.driver->name, data);
174 if (error) {
175 dev_err(&client->dev, "Failed to register interrupt\n");
176 goto err_free_mem;
177 }
178
179 error = input_register_device(input_dev);
180 if (error)
181 goto err_free_irq;
182
183 i2c_set_clientdata(client, data);
184 return 0;
185
186err_free_irq:
187 free_irq(client->irq, data);
188err_free_mem:
189 input_free_device(input_dev);
190 kfree(data);
191 return error;
192}
193
194static int __devexit mcs_touchkey_remove(struct i2c_client *client)
195{
196 struct mcs_touchkey_data *data = i2c_get_clientdata(client);
197
198 free_irq(client->irq, data);
199 input_unregister_device(data->input_dev);
200 kfree(data);
201
202 return 0;
203}
204
205static const struct i2c_device_id mcs_touchkey_id[] = {
206 { "mcs5000_touchkey", MCS5000_TOUCHKEY },
207 { "mcs5080_touchkey", MCS5080_TOUCHKEY },
208 { }
209};
210MODULE_DEVICE_TABLE(i2c, mcs_touchkey_id);
211
212static struct i2c_driver mcs_touchkey_driver = {
213 .driver = {
214 .name = "mcs_touchkey",
215 .owner = THIS_MODULE,
216 },
217 .probe = mcs_touchkey_probe,
218 .remove = __devexit_p(mcs_touchkey_remove),
219 .id_table = mcs_touchkey_id,
220};
221
222static int __init mcs_touchkey_init(void)
223{
224 return i2c_add_driver(&mcs_touchkey_driver);
225}
226
227static void __exit mcs_touchkey_exit(void)
228{
229 i2c_del_driver(&mcs_touchkey_driver);
230}
231
232module_init(mcs_touchkey_init);
233module_exit(mcs_touchkey_exit);
234
235/* Module information */
236MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
237MODULE_AUTHOR("HeungJun Kim <riverful.kim@samsung.com>");
238MODULE_DESCRIPTION("Touchkey driver for MELFAS MCS5000/5080 controller");
239MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c
index 31f30087b591..fac695157e8a 100644
--- a/drivers/input/keyboard/qt2160.c
+++ b/drivers/input/keyboard/qt2160.c
@@ -358,7 +358,6 @@ static int __devexit qt2160_remove(struct i2c_client *client)
358 input_unregister_device(qt2160->input); 358 input_unregister_device(qt2160->input);
359 kfree(qt2160); 359 kfree(qt2160);
360 360
361 i2c_set_clientdata(client, NULL);
362 return 0; 361 return 0;
363} 362}
364 363
diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
new file mode 100644
index 000000000000..f689f49e3109
--- /dev/null
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -0,0 +1,491 @@
1/*
2 * Samsung keypad driver
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 * Author: Donghwa Lee <dh09.lee@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/clk.h>
15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/init.h>
18#include <linux/input.h>
19#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/slab.h>
24#include <linux/sched.h>
25#include <plat/keypad.h>
26
27#define SAMSUNG_KEYIFCON 0x00
28#define SAMSUNG_KEYIFSTSCLR 0x04
29#define SAMSUNG_KEYIFCOL 0x08
30#define SAMSUNG_KEYIFROW 0x0c
31#define SAMSUNG_KEYIFFC 0x10
32
33/* SAMSUNG_KEYIFCON */
34#define SAMSUNG_KEYIFCON_INT_F_EN (1 << 0)
35#define SAMSUNG_KEYIFCON_INT_R_EN (1 << 1)
36#define SAMSUNG_KEYIFCON_DF_EN (1 << 2)
37#define SAMSUNG_KEYIFCON_FC_EN (1 << 3)
38#define SAMSUNG_KEYIFCON_WAKEUPEN (1 << 4)
39
40/* SAMSUNG_KEYIFSTSCLR */
41#define SAMSUNG_KEYIFSTSCLR_P_INT_MASK (0xff << 0)
42#define SAMSUNG_KEYIFSTSCLR_R_INT_MASK (0xff << 8)
43#define SAMSUNG_KEYIFSTSCLR_R_INT_OFFSET 8
44#define S5PV210_KEYIFSTSCLR_P_INT_MASK (0x3fff << 0)
45#define S5PV210_KEYIFSTSCLR_R_INT_MASK (0x3fff << 16)
46#define S5PV210_KEYIFSTSCLR_R_INT_OFFSET 16
47
48/* SAMSUNG_KEYIFCOL */
49#define SAMSUNG_KEYIFCOL_MASK (0xff << 0)
50#define S5PV210_KEYIFCOLEN_MASK (0xff << 8)
51
52/* SAMSUNG_KEYIFROW */
53#define SAMSUNG_KEYIFROW_MASK (0xff << 0)
54#define S5PV210_KEYIFROW_MASK (0x3fff << 0)
55
56/* SAMSUNG_KEYIFFC */
57#define SAMSUNG_KEYIFFC_MASK (0x3ff << 0)
58
59enum samsung_keypad_type {
60 KEYPAD_TYPE_SAMSUNG,
61 KEYPAD_TYPE_S5PV210,
62};
63
64struct samsung_keypad {
65 struct input_dev *input_dev;
66 struct clk *clk;
67 void __iomem *base;
68 wait_queue_head_t wait;
69 bool stopped;
70 int irq;
71 unsigned int row_shift;
72 unsigned int rows;
73 unsigned int cols;
74 unsigned int row_state[SAMSUNG_MAX_COLS];
75 unsigned short keycodes[];
76};
77
78static int samsung_keypad_is_s5pv210(struct device *dev)
79{
80 struct platform_device *pdev = to_platform_device(dev);
81 enum samsung_keypad_type type =
82 platform_get_device_id(pdev)->driver_data;
83
84 return type == KEYPAD_TYPE_S5PV210;
85}
86
87static void samsung_keypad_scan(struct samsung_keypad *keypad,
88 unsigned int *row_state)
89{
90 struct device *dev = keypad->input_dev->dev.parent;
91 unsigned int col;
92 unsigned int val;
93
94 for (col = 0; col < keypad->cols; col++) {
95 if (samsung_keypad_is_s5pv210(dev)) {
96 val = S5PV210_KEYIFCOLEN_MASK;
97 val &= ~(1 << col) << 8;
98 } else {
99 val = SAMSUNG_KEYIFCOL_MASK;
100 val &= ~(1 << col);
101 }
102
103 writel(val, keypad->base + SAMSUNG_KEYIFCOL);
104 mdelay(1);
105
106 val = readl(keypad->base + SAMSUNG_KEYIFROW);
107 row_state[col] = ~val & ((1 << keypad->rows) - 1);
108 }
109
110 /* KEYIFCOL reg clear */
111 writel(0, keypad->base + SAMSUNG_KEYIFCOL);
112}
113
114static bool samsung_keypad_report(struct samsung_keypad *keypad,
115 unsigned int *row_state)
116{
117 struct input_dev *input_dev = keypad->input_dev;
118 unsigned int changed;
119 unsigned int pressed;
120 unsigned int key_down = 0;
121 unsigned int val;
122 unsigned int col, row;
123
124 for (col = 0; col < keypad->cols; col++) {
125 changed = row_state[col] ^ keypad->row_state[col];
126 key_down |= row_state[col];
127 if (!changed)
128 continue;
129
130 for (row = 0; row < keypad->rows; row++) {
131 if (!(changed & (1 << row)))
132 continue;
133
134 pressed = row_state[col] & (1 << row);
135
136 dev_dbg(&keypad->input_dev->dev,
137 "key %s, row: %d, col: %d\n",
138 pressed ? "pressed" : "released", row, col);
139
140 val = MATRIX_SCAN_CODE(row, col, keypad->row_shift);
141
142 input_event(input_dev, EV_MSC, MSC_SCAN, val);
143 input_report_key(input_dev,
144 keypad->keycodes[val], pressed);
145 }
146 input_sync(keypad->input_dev);
147 }
148
149 memcpy(keypad->row_state, row_state, sizeof(keypad->row_state));
150
151 return key_down;
152}
153
154static irqreturn_t samsung_keypad_irq(int irq, void *dev_id)
155{
156 struct samsung_keypad *keypad = dev_id;
157 unsigned int row_state[SAMSUNG_MAX_COLS];
158 unsigned int val;
159 bool key_down;
160
161 do {
162 val = readl(keypad->base + SAMSUNG_KEYIFSTSCLR);
163 /* Clear interrupt. */
164 writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR);
165
166 samsung_keypad_scan(keypad, row_state);
167
168 key_down = samsung_keypad_report(keypad, row_state);
169 if (key_down)
170 wait_event_timeout(keypad->wait, keypad->stopped,
171 msecs_to_jiffies(50));
172
173 } while (key_down && !keypad->stopped);
174
175 return IRQ_HANDLED;
176}
177
178static void samsung_keypad_start(struct samsung_keypad *keypad)
179{
180 unsigned int val;
181
182 /* Tell IRQ thread that it may poll the device. */
183 keypad->stopped = false;
184
185 clk_enable(keypad->clk);
186
187 /* Enable interrupt bits. */
188 val = readl(keypad->base + SAMSUNG_KEYIFCON);
189 val |= SAMSUNG_KEYIFCON_INT_F_EN | SAMSUNG_KEYIFCON_INT_R_EN;
190 writel(val, keypad->base + SAMSUNG_KEYIFCON);
191
192 /* KEYIFCOL reg clear. */
193 writel(0, keypad->base + SAMSUNG_KEYIFCOL);
194}
195
196static void samsung_keypad_stop(struct samsung_keypad *keypad)
197{
198 unsigned int val;
199
200 /* Signal IRQ thread to stop polling and disable the handler. */
201 keypad->stopped = true;
202 wake_up(&keypad->wait);
203 disable_irq(keypad->irq);
204
205 /* Clear interrupt. */
206 writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR);
207
208 /* Disable interrupt bits. */
209 val = readl(keypad->base + SAMSUNG_KEYIFCON);
210 val &= ~(SAMSUNG_KEYIFCON_INT_F_EN | SAMSUNG_KEYIFCON_INT_R_EN);
211 writel(val, keypad->base + SAMSUNG_KEYIFCON);
212
213 clk_disable(keypad->clk);
214
215 /*
216 * Now that chip should not generate interrupts we can safely
217 * re-enable the handler.
218 */
219 enable_irq(keypad->irq);
220}
221
222static int samsung_keypad_open(struct input_dev *input_dev)
223{
224 struct samsung_keypad *keypad = input_get_drvdata(input_dev);
225
226 samsung_keypad_start(keypad);
227
228 return 0;
229}
230
231static void samsung_keypad_close(struct input_dev *input_dev)
232{
233 struct samsung_keypad *keypad = input_get_drvdata(input_dev);
234
235 samsung_keypad_stop(keypad);
236}
237
238static int __devinit samsung_keypad_probe(struct platform_device *pdev)
239{
240 const struct samsung_keypad_platdata *pdata;
241 const struct matrix_keymap_data *keymap_data;
242 struct samsung_keypad *keypad;
243 struct resource *res;
244 struct input_dev *input_dev;
245 unsigned int row_shift;
246 unsigned int keymap_size;
247 int error;
248
249 pdata = pdev->dev.platform_data;
250 if (!pdata) {
251 dev_err(&pdev->dev, "no platform data defined\n");
252 return -EINVAL;
253 }
254
255 keymap_data = pdata->keymap_data;
256 if (!keymap_data) {
257 dev_err(&pdev->dev, "no keymap data defined\n");
258 return -EINVAL;
259 }
260
261 if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS)
262 return -EINVAL;
263
264 if (!pdata->cols || pdata->cols > SAMSUNG_MAX_COLS)
265 return -EINVAL;
266
267 /* initialize the gpio */
268 if (pdata->cfg_gpio)
269 pdata->cfg_gpio(pdata->rows, pdata->cols);
270
271 row_shift = get_count_order(pdata->cols);
272 keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
273
274 keypad = kzalloc(sizeof(*keypad) + keymap_size, GFP_KERNEL);
275 input_dev = input_allocate_device();
276 if (!keypad || !input_dev) {
277 error = -ENOMEM;
278 goto err_free_mem;
279 }
280
281 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
282 if (!res) {
283 error = -ENODEV;
284 goto err_free_mem;
285 }
286
287 keypad->base = ioremap(res->start, resource_size(res));
288 if (!keypad->base) {
289 error = -EBUSY;
290 goto err_free_mem;
291 }
292
293 keypad->clk = clk_get(&pdev->dev, "keypad");
294 if (IS_ERR(keypad->clk)) {
295 dev_err(&pdev->dev, "failed to get keypad clk\n");
296 error = PTR_ERR(keypad->clk);
297 goto err_unmap_base;
298 }
299
300 keypad->input_dev = input_dev;
301 keypad->row_shift = row_shift;
302 keypad->rows = pdata->rows;
303 keypad->cols = pdata->cols;
304 init_waitqueue_head(&keypad->wait);
305
306 input_dev->name = pdev->name;
307 input_dev->id.bustype = BUS_HOST;
308 input_dev->dev.parent = &pdev->dev;
309 input_set_drvdata(input_dev, keypad);
310
311 input_dev->open = samsung_keypad_open;
312 input_dev->close = samsung_keypad_close;
313
314 input_dev->evbit[0] = BIT_MASK(EV_KEY);
315 if (!pdata->no_autorepeat)
316 input_dev->evbit[0] |= BIT_MASK(EV_REP);
317
318 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
319
320 input_dev->keycode = keypad->keycodes;
321 input_dev->keycodesize = sizeof(keypad->keycodes[0]);
322 input_dev->keycodemax = pdata->rows << row_shift;
323
324 matrix_keypad_build_keymap(keymap_data, row_shift,
325 input_dev->keycode, input_dev->keybit);
326
327 keypad->irq = platform_get_irq(pdev, 0);
328 if (keypad->irq < 0) {
329 error = keypad->irq;
330 goto err_put_clk;
331 }
332
333 error = request_threaded_irq(keypad->irq, NULL, samsung_keypad_irq,
334 IRQF_ONESHOT, dev_name(&pdev->dev), keypad);
335 if (error) {
336 dev_err(&pdev->dev, "failed to register keypad interrupt\n");
337 goto err_put_clk;
338 }
339
340 error = input_register_device(keypad->input_dev);
341 if (error)
342 goto err_free_irq;
343
344 device_init_wakeup(&pdev->dev, pdata->wakeup);
345 platform_set_drvdata(pdev, keypad);
346 return 0;
347
348err_free_irq:
349 free_irq(keypad->irq, keypad);
350err_put_clk:
351 clk_put(keypad->clk);
352err_unmap_base:
353 iounmap(keypad->base);
354err_free_mem:
355 input_free_device(input_dev);
356 kfree(keypad);
357
358 return error;
359}
360
361static int __devexit samsung_keypad_remove(struct platform_device *pdev)
362{
363 struct samsung_keypad *keypad = platform_get_drvdata(pdev);
364
365 device_init_wakeup(&pdev->dev, 0);
366 platform_set_drvdata(pdev, NULL);
367
368 input_unregister_device(keypad->input_dev);
369
370 /*
371 * It is safe to free IRQ after unregistering device because
372 * samsung_keypad_close will shut off interrupts.
373 */
374 free_irq(keypad->irq, keypad);
375
376 clk_put(keypad->clk);
377
378 iounmap(keypad->base);
379 kfree(keypad);
380
381 return 0;
382}
383
384#ifdef CONFIG_PM
385static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad,
386 bool enable)
387{
388 struct device *dev = keypad->input_dev->dev.parent;
389 unsigned int val;
390
391 clk_enable(keypad->clk);
392
393 val = readl(keypad->base + SAMSUNG_KEYIFCON);
394 if (enable) {
395 val |= SAMSUNG_KEYIFCON_WAKEUPEN;
396 if (device_may_wakeup(dev))
397 enable_irq_wake(keypad->irq);
398 } else {
399 val &= ~SAMSUNG_KEYIFCON_WAKEUPEN;
400 if (device_may_wakeup(dev))
401 disable_irq_wake(keypad->irq);
402 }
403 writel(val, keypad->base + SAMSUNG_KEYIFCON);
404
405 clk_disable(keypad->clk);
406}
407
408static int samsung_keypad_suspend(struct device *dev)
409{
410 struct platform_device *pdev = to_platform_device(dev);
411 struct samsung_keypad *keypad = platform_get_drvdata(pdev);
412 struct input_dev *input_dev = keypad->input_dev;
413
414 mutex_lock(&input_dev->mutex);
415
416 if (input_dev->users)
417 samsung_keypad_stop(keypad);
418
419 samsung_keypad_toggle_wakeup(keypad, true);
420
421 mutex_unlock(&input_dev->mutex);
422
423 return 0;
424}
425
426static int samsung_keypad_resume(struct device *dev)
427{
428 struct platform_device *pdev = to_platform_device(dev);
429 struct samsung_keypad *keypad = platform_get_drvdata(pdev);
430 struct input_dev *input_dev = keypad->input_dev;
431
432 mutex_lock(&input_dev->mutex);
433
434 samsung_keypad_toggle_wakeup(keypad, false);
435
436 if (input_dev->users)
437 samsung_keypad_start(keypad);
438
439 mutex_unlock(&input_dev->mutex);
440
441 return 0;
442}
443
444static const struct dev_pm_ops samsung_keypad_pm_ops = {
445 .suspend = samsung_keypad_suspend,
446 .resume = samsung_keypad_resume,
447};
448#endif
449
450static struct platform_device_id samsung_keypad_driver_ids[] = {
451 {
452 .name = "samsung-keypad",
453 .driver_data = KEYPAD_TYPE_SAMSUNG,
454 }, {
455 .name = "s5pv210-keypad",
456 .driver_data = KEYPAD_TYPE_S5PV210,
457 },
458 { },
459};
460MODULE_DEVICE_TABLE(platform, samsung_keypad_driver_ids);
461
462static struct platform_driver samsung_keypad_driver = {
463 .probe = samsung_keypad_probe,
464 .remove = __devexit_p(samsung_keypad_remove),
465 .driver = {
466 .name = "samsung-keypad",
467 .owner = THIS_MODULE,
468#ifdef CONFIG_PM
469 .pm = &samsung_keypad_pm_ops,
470#endif
471 },
472 .id_table = samsung_keypad_driver_ids,
473};
474
475static int __init samsung_keypad_init(void)
476{
477 return platform_driver_register(&samsung_keypad_driver);
478}
479module_init(samsung_keypad_init);
480
481static void __exit samsung_keypad_exit(void)
482{
483 platform_driver_unregister(&samsung_keypad_driver);
484}
485module_exit(samsung_keypad_exit);
486
487MODULE_DESCRIPTION("Samsung keypad driver");
488MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
489MODULE_AUTHOR("Donghwa Lee <dh09.lee@samsung.com>");
490MODULE_LICENSE("GPL");
491MODULE_ALIAS("platform:samsung-keypad");
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
new file mode 100644
index 000000000000..ab7610ca10eb
--- /dev/null
+++ b/drivers/input/keyboard/stmpe-keypad.c
@@ -0,0 +1,386 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/input.h>
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/input/matrix_keypad.h>
15#include <linux/mfd/stmpe.h>
16
17/* These are at the same addresses in all STMPE variants */
18#define STMPE_KPC_COL 0x60
19#define STMPE_KPC_ROW_MSB 0x61
20#define STMPE_KPC_ROW_LSB 0x62
21#define STMPE_KPC_CTRL_MSB 0x63
22#define STMPE_KPC_CTRL_LSB 0x64
23#define STMPE_KPC_COMBI_KEY_0 0x65
24#define STMPE_KPC_COMBI_KEY_1 0x66
25#define STMPE_KPC_COMBI_KEY_2 0x67
26#define STMPE_KPC_DATA_BYTE0 0x68
27#define STMPE_KPC_DATA_BYTE1 0x69
28#define STMPE_KPC_DATA_BYTE2 0x6a
29#define STMPE_KPC_DATA_BYTE3 0x6b
30#define STMPE_KPC_DATA_BYTE4 0x6c
31
32#define STMPE_KPC_CTRL_LSB_SCAN (0x1 << 0)
33#define STMPE_KPC_CTRL_LSB_DEBOUNCE (0x7f << 1)
34#define STMPE_KPC_CTRL_MSB_SCAN_COUNT (0xf << 4)
35
36#define STMPE_KPC_ROW_MSB_ROWS 0xff
37
38#define STMPE_KPC_DATA_UP (0x1 << 7)
39#define STMPE_KPC_DATA_ROW (0xf << 3)
40#define STMPE_KPC_DATA_COL (0x7 << 0)
41#define STMPE_KPC_DATA_NOKEY_MASK 0x78
42
43#define STMPE_KEYPAD_MAX_DEBOUNCE 127
44#define STMPE_KEYPAD_MAX_SCAN_COUNT 15
45
46#define STMPE_KEYPAD_MAX_ROWS 8
47#define STMPE_KEYPAD_MAX_COLS 8
48#define STMPE_KEYPAD_ROW_SHIFT 3
49#define STMPE_KEYPAD_KEYMAP_SIZE \
50 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)
51
52/**
53 * struct stmpe_keypad_variant - model-specific attributes
54 * @auto_increment: whether the KPC_DATA_BYTE register address
55 * auto-increments on multiple read
56 * @num_data: number of data bytes
57 * @num_normal_data: number of normal keys' data bytes
58 * @max_cols: maximum number of columns supported
59 * @max_rows: maximum number of rows supported
60 * @col_gpios: bitmask of gpios which can be used for columns
61 * @row_gpios: bitmask of gpios which can be used for rows
62 */
63struct stmpe_keypad_variant {
64 bool auto_increment;
65 int num_data;
66 int num_normal_data;
67 int max_cols;
68 int max_rows;
69 unsigned int col_gpios;
70 unsigned int row_gpios;
71};
72
73static const struct stmpe_keypad_variant stmpe_keypad_variants[] = {
74 [STMPE1601] = {
75 .auto_increment = true,
76 .num_data = 5,
77 .num_normal_data = 3,
78 .max_cols = 8,
79 .max_rows = 8,
80 .col_gpios = 0x000ff, /* GPIO 0 - 7 */
81 .row_gpios = 0x0ff00, /* GPIO 8 - 15 */
82 },
83 [STMPE2401] = {
84 .auto_increment = false,
85 .num_data = 3,
86 .num_normal_data = 2,
87 .max_cols = 8,
88 .max_rows = 12,
89 .col_gpios = 0x0000ff, /* GPIO 0 - 7*/
90 .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */
91 },
92 [STMPE2403] = {
93 .auto_increment = true,
94 .num_data = 5,
95 .num_normal_data = 3,
96 .max_cols = 8,
97 .max_rows = 12,
98 .col_gpios = 0x0000ff, /* GPIO 0 - 7*/
99 .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */
100 },
101};
102
103struct stmpe_keypad {
104 struct stmpe *stmpe;
105 struct input_dev *input;
106 const struct stmpe_keypad_variant *variant;
107 const struct stmpe_keypad_platform_data *plat;
108
109 unsigned int rows;
110 unsigned int cols;
111
112 unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];
113};
114
115static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)
116{
117 const struct stmpe_keypad_variant *variant = keypad->variant;
118 struct stmpe *stmpe = keypad->stmpe;
119 int ret;
120 int i;
121
122 if (variant->auto_increment)
123 return stmpe_block_read(stmpe, STMPE_KPC_DATA_BYTE0,
124 variant->num_data, data);
125
126 for (i = 0; i < variant->num_data; i++) {
127 ret = stmpe_reg_read(stmpe, STMPE_KPC_DATA_BYTE0 + i);
128 if (ret < 0)
129 return ret;
130
131 data[i] = ret;
132 }
133
134 return 0;
135}
136
137static irqreturn_t stmpe_keypad_irq(int irq, void *dev)
138{
139 struct stmpe_keypad *keypad = dev;
140 struct input_dev *input = keypad->input;
141 const struct stmpe_keypad_variant *variant = keypad->variant;
142 u8 fifo[variant->num_data];
143 int ret;
144 int i;
145
146 ret = stmpe_keypad_read_data(keypad, fifo);
147 if (ret < 0)
148 return IRQ_NONE;
149
150 for (i = 0; i < variant->num_normal_data; i++) {
151 u8 data = fifo[i];
152 int row = (data & STMPE_KPC_DATA_ROW) >> 3;
153 int col = data & STMPE_KPC_DATA_COL;
154 int code = MATRIX_SCAN_CODE(row, col, STMPE_KEYPAD_ROW_SHIFT);
155 bool up = data & STMPE_KPC_DATA_UP;
156
157 if ((data & STMPE_KPC_DATA_NOKEY_MASK)
158 == STMPE_KPC_DATA_NOKEY_MASK)
159 continue;
160
161 input_event(input, EV_MSC, MSC_SCAN, code);
162 input_report_key(input, keypad->keymap[code], !up);
163 input_sync(input);
164 }
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
170{
171 const struct stmpe_keypad_variant *variant = keypad->variant;
172 unsigned int col_gpios = variant->col_gpios;
173 unsigned int row_gpios = variant->row_gpios;
174 struct stmpe *stmpe = keypad->stmpe;
175 unsigned int pins = 0;
176 int i;
177
178 /*
179 * Figure out which pins need to be set to the keypad alternate
180 * function.
181 *
182 * {cols,rows}_gpios are bitmasks of which pins on the chip can be used
183 * for the keypad.
184 *
185 * keypad->{cols,rows} are a bitmask of which pins (of the ones useable
186 * for the keypad) are used on the board.
187 */
188
189 for (i = 0; i < variant->max_cols; i++) {
190 int num = __ffs(col_gpios);
191
192 if (keypad->cols & (1 << i))
193 pins |= 1 << num;
194
195 col_gpios &= ~(1 << num);
196 }
197
198 for (i = 0; i < variant->max_rows; i++) {
199 int num = __ffs(row_gpios);
200
201 if (keypad->rows & (1 << i))
202 pins |= 1 << num;
203
204 row_gpios &= ~(1 << num);
205 }
206
207 return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
208}
209
210static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
211{
212 const struct stmpe_keypad_platform_data *plat = keypad->plat;
213 const struct stmpe_keypad_variant *variant = keypad->variant;
214 struct stmpe *stmpe = keypad->stmpe;
215 int ret;
216
217 if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
218 return -EINVAL;
219
220 if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)
221 return -EINVAL;
222
223 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);
224 if (ret < 0)
225 return ret;
226
227 ret = stmpe_keypad_altfunc_init(keypad);
228 if (ret < 0)
229 return ret;
230
231 ret = stmpe_reg_write(stmpe, STMPE_KPC_COL, keypad->cols);
232 if (ret < 0)
233 return ret;
234
235 ret = stmpe_reg_write(stmpe, STMPE_KPC_ROW_LSB, keypad->rows);
236 if (ret < 0)
237 return ret;
238
239 if (variant->max_rows > 8) {
240 ret = stmpe_set_bits(stmpe, STMPE_KPC_ROW_MSB,
241 STMPE_KPC_ROW_MSB_ROWS,
242 keypad->rows >> 8);
243 if (ret < 0)
244 return ret;
245 }
246
247 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,
248 STMPE_KPC_CTRL_MSB_SCAN_COUNT,
249 plat->scan_count << 4);
250 if (ret < 0)
251 return ret;
252
253 return stmpe_set_bits(stmpe, STMPE_KPC_CTRL_LSB,
254 STMPE_KPC_CTRL_LSB_SCAN |
255 STMPE_KPC_CTRL_LSB_DEBOUNCE,
256 STMPE_KPC_CTRL_LSB_SCAN |
257 (plat->debounce_ms << 1));
258}
259
260static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
261{
262 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
263 struct stmpe_keypad_platform_data *plat;
264 struct stmpe_keypad *keypad;
265 struct input_dev *input;
266 int ret;
267 int irq;
268 int i;
269
270 plat = stmpe->pdata->keypad;
271 if (!plat)
272 return -ENODEV;
273
274 irq = platform_get_irq(pdev, 0);
275 if (irq < 0)
276 return irq;
277
278 keypad = kzalloc(sizeof(struct stmpe_keypad), GFP_KERNEL);
279 if (!keypad)
280 return -ENOMEM;
281
282 input = input_allocate_device();
283 if (!input) {
284 ret = -ENOMEM;
285 goto out_freekeypad;
286 }
287
288 input->name = "STMPE keypad";
289 input->id.bustype = BUS_I2C;
290 input->dev.parent = &pdev->dev;
291
292 input_set_capability(input, EV_MSC, MSC_SCAN);
293
294 __set_bit(EV_KEY, input->evbit);
295 if (!plat->no_autorepeat)
296 __set_bit(EV_REP, input->evbit);
297
298 input->keycode = keypad->keymap;
299 input->keycodesize = sizeof(keypad->keymap[0]);
300 input->keycodemax = ARRAY_SIZE(keypad->keymap);
301
302 matrix_keypad_build_keymap(plat->keymap_data, STMPE_KEYPAD_ROW_SHIFT,
303 input->keycode, input->keybit);
304
305 for (i = 0; i < plat->keymap_data->keymap_size; i++) {
306 unsigned int key = plat->keymap_data->keymap[i];
307
308 keypad->cols |= 1 << KEY_COL(key);
309 keypad->rows |= 1 << KEY_ROW(key);
310 }
311
312 keypad->stmpe = stmpe;
313 keypad->plat = plat;
314 keypad->input = input;
315 keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
316
317 ret = stmpe_keypad_chip_init(keypad);
318 if (ret < 0)
319 goto out_freeinput;
320
321 ret = input_register_device(input);
322 if (ret) {
323 dev_err(&pdev->dev,
324 "unable to register input device: %d\n", ret);
325 goto out_freeinput;
326 }
327
328 ret = request_threaded_irq(irq, NULL, stmpe_keypad_irq, IRQF_ONESHOT,
329 "stmpe-keypad", keypad);
330 if (ret) {
331 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
332 goto out_unregisterinput;
333 }
334
335 platform_set_drvdata(pdev, keypad);
336
337 return 0;
338
339out_unregisterinput:
340 input_unregister_device(input);
341 input = NULL;
342out_freeinput:
343 input_free_device(input);
344out_freekeypad:
345 kfree(keypad);
346 return ret;
347}
348
349static int __devexit stmpe_keypad_remove(struct platform_device *pdev)
350{
351 struct stmpe_keypad *keypad = platform_get_drvdata(pdev);
352 struct stmpe *stmpe = keypad->stmpe;
353 int irq = platform_get_irq(pdev, 0);
354
355 stmpe_disable(stmpe, STMPE_BLOCK_KEYPAD);
356
357 free_irq(irq, keypad);
358 input_unregister_device(keypad->input);
359 platform_set_drvdata(pdev, NULL);
360 kfree(keypad);
361
362 return 0;
363}
364
365static struct platform_driver stmpe_keypad_driver = {
366 .driver.name = "stmpe-keypad",
367 .driver.owner = THIS_MODULE,
368 .probe = stmpe_keypad_probe,
369 .remove = __devexit_p(stmpe_keypad_remove),
370};
371
372static int __init stmpe_keypad_init(void)
373{
374 return platform_driver_register(&stmpe_keypad_driver);
375}
376module_init(stmpe_keypad_init);
377
378static void __exit stmpe_keypad_exit(void)
379{
380 platform_driver_unregister(&stmpe_keypad_driver);
381}
382module_exit(stmpe_keypad_exit);
383
384MODULE_LICENSE("GPL v2");
385MODULE_DESCRIPTION("STMPExxxx keypad driver");
386MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c
index 493c93f25e2a..00137bebcf97 100644
--- a/drivers/input/keyboard/tca6416-keypad.c
+++ b/drivers/input/keyboard/tca6416-keypad.c
@@ -316,8 +316,6 @@ static int __devexit tca6416_keypad_remove(struct i2c_client *client)
316 input_unregister_device(chip->input); 316 input_unregister_device(chip->input);
317 kfree(chip); 317 kfree(chip);
318 318
319 i2c_set_clientdata(client, NULL);
320
321 return 0; 319 return 0;
322} 320}
323 321
diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c
index 7aa59e07b689..fb16b5e5ea13 100644
--- a/drivers/input/keyboard/twl4030_keypad.c
+++ b/drivers/input/keyboard/twl4030_keypad.c
@@ -51,8 +51,12 @@
51 */ 51 */
52#define TWL4030_MAX_ROWS 8 /* TWL4030 hard limit */ 52#define TWL4030_MAX_ROWS 8 /* TWL4030 hard limit */
53#define TWL4030_MAX_COLS 8 53#define TWL4030_MAX_COLS 8
54#define TWL4030_ROW_SHIFT 3 54/*
55#define TWL4030_KEYMAP_SIZE (TWL4030_MAX_ROWS * TWL4030_MAX_COLS) 55 * Note that we add space for an extra column so that we can handle
56 * row lines connected to the gnd (see twl4030_col_xlate()).
57 */
58#define TWL4030_ROW_SHIFT 4
59#define TWL4030_KEYMAP_SIZE (TWL4030_MAX_ROWS << TWL4030_ROW_SHIFT)
56 60
57struct twl4030_keypad { 61struct twl4030_keypad {
58 unsigned short keymap[TWL4030_KEYMAP_SIZE]; 62 unsigned short keymap[TWL4030_KEYMAP_SIZE];
@@ -182,7 +186,7 @@ static int twl4030_read_kp_matrix_state(struct twl4030_keypad *kp, u16 *state)
182 return ret; 186 return ret;
183} 187}
184 188
185static int twl4030_is_in_ghost_state(struct twl4030_keypad *kp, u16 *key_state) 189static bool twl4030_is_in_ghost_state(struct twl4030_keypad *kp, u16 *key_state)
186{ 190{
187 int i; 191 int i;
188 u16 check = 0; 192 u16 check = 0;
@@ -191,12 +195,12 @@ static int twl4030_is_in_ghost_state(struct twl4030_keypad *kp, u16 *key_state)
191 u16 col = key_state[i]; 195 u16 col = key_state[i];
192 196
193 if ((col & check) && hweight16(col) > 1) 197 if ((col & check) && hweight16(col) > 1)
194 return 1; 198 return true;
195 199
196 check |= col; 200 check |= col;
197 } 201 }
198 202
199 return 0; 203 return false;
200} 204}
201 205
202static void twl4030_kp_scan(struct twl4030_keypad *kp, bool release_all) 206static void twl4030_kp_scan(struct twl4030_keypad *kp, bool release_all)
@@ -225,7 +229,8 @@ static void twl4030_kp_scan(struct twl4030_keypad *kp, bool release_all)
225 if (!changed) 229 if (!changed)
226 continue; 230 continue;
227 231
228 for (col = 0; col < kp->n_cols; col++) { 232 /* Extra column handles "all gnd" rows */
233 for (col = 0; col < kp->n_cols + 1; col++) {
229 int code; 234 int code;
230 235
231 if (!(changed & (1 << col))) 236 if (!(changed & (1 << col)))
diff --git a/drivers/input/keyboard/w90p910_keypad.c b/drivers/input/keyboard/w90p910_keypad.c
index 4ef764cc493c..ee2bf6bcf291 100644
--- a/drivers/input/keyboard/w90p910_keypad.c
+++ b/drivers/input/keyboard/w90p910_keypad.c
@@ -258,7 +258,7 @@ static struct platform_driver w90p910_keypad_driver = {
258 .probe = w90p910_keypad_probe, 258 .probe = w90p910_keypad_probe,
259 .remove = __devexit_p(w90p910_keypad_remove), 259 .remove = __devexit_p(w90p910_keypad_remove),
260 .driver = { 260 .driver = {
261 .name = "nuc900-keypad", 261 .name = "nuc900-kpi",
262 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
263 }, 263 },
264}; 264};
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index c44b9eafc556..b49e23379723 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -327,6 +327,17 @@ config INPUT_PCF8574
327 To compile this driver as a module, choose M here: the 327 To compile this driver as a module, choose M here: the
328 module will be called pcf8574_keypad. 328 module will be called pcf8574_keypad.
329 329
330config INPUT_PWM_BEEPER
331 tristate "PWM beeper support"
332 depends on HAVE_PWM
333 help
334 Say Y here to get support for PWM based beeper devices.
335
336 If unsure, say N.
337
338 To compile this driver as a module, choose M here: the module will be
339 called pwm-beeper.
340
330config INPUT_GPIO_ROTARY_ENCODER 341config INPUT_GPIO_ROTARY_ENCODER
331 tristate "Rotary encoders connected to GPIO pins" 342 tristate "Rotary encoders connected to GPIO pins"
332 depends on GPIOLIB && GENERIC_GPIO 343 depends on GPIOLIB && GENERIC_GPIO
@@ -390,4 +401,41 @@ config INPUT_PCAP
390 To compile this driver as a module, choose M here: the 401 To compile this driver as a module, choose M here: the
391 module will be called pcap_keys. 402 module will be called pcap_keys.
392 403
404config INPUT_ADXL34X
405 tristate "Analog Devices ADXL34x Three-Axis Digital Accelerometer"
406 default n
407 help
408 Say Y here if you have a Accelerometer interface using the
409 ADXL345/6 controller, and your board-specific initialization
410 code includes that in its table of devices.
411
412 This driver can use either I2C or SPI communication to the
413 ADXL345/6 controller. Select the appropriate method for
414 your system.
415
416 If unsure, say N (but it's safe to say "Y").
417
418 To compile this driver as a module, choose M here: the
419 module will be called adxl34x.
420
421config INPUT_ADXL34X_I2C
422 tristate "support I2C bus connection"
423 depends on INPUT_ADXL34X && I2C
424 default y
425 help
426 Say Y here if you have ADXL345/6 hooked to an I2C bus.
427
428 To compile this driver as a module, choose M here: the
429 module will be called adxl34x-i2c.
430
431config INPUT_ADXL34X_SPI
432 tristate "support SPI bus connection"
433 depends on INPUT_ADXL34X && SPI
434 default y
435 help
436 Say Y here if you have ADXL345/6 hooked to a SPI bus.
437
438 To compile this driver as a module, choose M here: the
439 module will be called adxl34x-spi.
440
393endif 441endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 71fe57d8023f..19ccca78fa76 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o
8obj-$(CONFIG_INPUT_AD714X) += ad714x.o 8obj-$(CONFIG_INPUT_AD714X) += ad714x.o
9obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o 9obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o
10obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o 10obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o
11obj-$(CONFIG_INPUT_ADXL34X) += adxl34x.o
12obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o
13obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o
11obj-$(CONFIG_INPUT_APANEL) += apanel.o 14obj-$(CONFIG_INPUT_APANEL) += apanel.o
12obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o 15obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o
13obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o 16obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
@@ -26,6 +29,7 @@ obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
26obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o 29obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o
27obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o 30obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
28obj-$(CONFIG_INPUT_POWERMATE) += powermate.o 31obj-$(CONFIG_INPUT_POWERMATE) += powermate.o
32obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o
29obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o 33obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o
30obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o 34obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o
31obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o 35obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c
index e9adbe49f6a4..2bef8fa56c94 100644
--- a/drivers/input/misc/ad714x-i2c.c
+++ b/drivers/input/misc/ad714x-i2c.c
@@ -97,7 +97,6 @@ static int __devexit ad714x_i2c_remove(struct i2c_client *client)
97 struct ad714x_chip *chip = i2c_get_clientdata(client); 97 struct ad714x_chip *chip = i2c_get_clientdata(client);
98 98
99 ad714x_remove(chip); 99 ad714x_remove(chip);
100 i2c_set_clientdata(client, NULL);
101 100
102 return 0; 101 return 0;
103} 102}
diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c
index 0fe27baf5e72..c431d09e401a 100644
--- a/drivers/input/misc/ad714x.c
+++ b/drivers/input/misc/ad714x.c
@@ -1118,7 +1118,7 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq,
1118 if (error) 1118 if (error)
1119 goto err_free_mem; 1119 goto err_free_mem;
1120 1120
1121 /* initilize and request sw/hw resources */ 1121 /* initialize and request sw/hw resources */
1122 1122
1123 ad714x_hw_init(ad714x); 1123 ad714x_hw_init(ad714x);
1124 mutex_init(&ad714x->mutex); 1124 mutex_init(&ad714x->mutex);
diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c
new file mode 100644
index 000000000000..0779724af7e7
--- /dev/null
+++ b/drivers/input/misc/adxl34x-i2c.c
@@ -0,0 +1,163 @@
1/*
2 * ADLX345/346 Three-Axis Digital Accelerometers (I2C Interface)
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/input.h> /* BUS_I2C */
11#include <linux/i2c.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include "adxl34x.h"
15
16static int adxl34x_smbus_read(struct device *dev, unsigned char reg)
17{
18 struct i2c_client *client = to_i2c_client(dev);
19
20 return i2c_smbus_read_byte_data(client, reg);
21}
22
23static int adxl34x_smbus_write(struct device *dev,
24 unsigned char reg, unsigned char val)
25{
26 struct i2c_client *client = to_i2c_client(dev);
27
28 return i2c_smbus_write_byte_data(client, reg, val);
29}
30
31static int adxl34x_smbus_read_block(struct device *dev,
32 unsigned char reg, int count,
33 void *buf)
34{
35 struct i2c_client *client = to_i2c_client(dev);
36
37 return i2c_smbus_read_i2c_block_data(client, reg, count, buf);
38}
39
40static int adxl34x_i2c_read_block(struct device *dev,
41 unsigned char reg, int count,
42 void *buf)
43{
44 struct i2c_client *client = to_i2c_client(dev);
45 int ret;
46
47 ret = i2c_master_send(client, &reg, 1);
48 if (ret < 0)
49 return ret;
50
51 ret = i2c_master_recv(client, buf, count);
52 if (ret < 0)
53 return ret;
54
55 if (ret != count)
56 return -EIO;
57
58 return 0;
59}
60
61static const struct adxl34x_bus_ops adxl34x_smbus_bops = {
62 .bustype = BUS_I2C,
63 .write = adxl34x_smbus_write,
64 .read = adxl34x_smbus_read,
65 .read_block = adxl34x_smbus_read_block,
66};
67
68static const struct adxl34x_bus_ops adxl34x_i2c_bops = {
69 .bustype = BUS_I2C,
70 .write = adxl34x_smbus_write,
71 .read = adxl34x_smbus_read,
72 .read_block = adxl34x_i2c_read_block,
73};
74
75static int __devinit adxl34x_i2c_probe(struct i2c_client *client,
76 const struct i2c_device_id *id)
77{
78 struct adxl34x *ac;
79 int error;
80
81 error = i2c_check_functionality(client->adapter,
82 I2C_FUNC_SMBUS_BYTE_DATA);
83 if (!error) {
84 dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
85 return -EIO;
86 }
87
88 ac = adxl34x_probe(&client->dev, client->irq, false,
89 i2c_check_functionality(client->adapter,
90 I2C_FUNC_SMBUS_READ_I2C_BLOCK) ?
91 &adxl34x_smbus_bops : &adxl34x_i2c_bops);
92 if (IS_ERR(ac))
93 return PTR_ERR(ac);
94
95 i2c_set_clientdata(client, ac);
96
97 return 0;
98}
99
100static int __devexit adxl34x_i2c_remove(struct i2c_client *client)
101{
102 struct adxl34x *ac = i2c_get_clientdata(client);
103
104 return adxl34x_remove(ac);
105}
106
107#ifdef CONFIG_PM
108static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message)
109{
110 struct adxl34x *ac = i2c_get_clientdata(client);
111
112 adxl34x_suspend(ac);
113
114 return 0;
115}
116
117static int adxl34x_i2c_resume(struct i2c_client *client)
118{
119 struct adxl34x *ac = i2c_get_clientdata(client);
120
121 adxl34x_resume(ac);
122
123 return 0;
124}
125#else
126# define adxl34x_i2c_suspend NULL
127# define adxl34x_i2c_resume NULL
128#endif
129
130static const struct i2c_device_id adxl34x_id[] = {
131 { "adxl34x", 0 },
132 { }
133};
134
135MODULE_DEVICE_TABLE(i2c, adxl34x_id);
136
137static struct i2c_driver adxl34x_driver = {
138 .driver = {
139 .name = "adxl34x",
140 .owner = THIS_MODULE,
141 },
142 .probe = adxl34x_i2c_probe,
143 .remove = __devexit_p(adxl34x_i2c_remove),
144 .suspend = adxl34x_i2c_suspend,
145 .resume = adxl34x_i2c_resume,
146 .id_table = adxl34x_id,
147};
148
149static int __init adxl34x_i2c_init(void)
150{
151 return i2c_add_driver(&adxl34x_driver);
152}
153module_init(adxl34x_i2c_init);
154
155static void __exit adxl34x_i2c_exit(void)
156{
157 i2c_del_driver(&adxl34x_driver);
158}
159module_exit(adxl34x_i2c_exit);
160
161MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
162MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer I2C Bus Driver");
163MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c
new file mode 100644
index 000000000000..782de9e89828
--- /dev/null
+++ b/drivers/input/misc/adxl34x-spi.c
@@ -0,0 +1,145 @@
1/*
2 * ADLX345/346 Three-Axis Digital Accelerometers (SPI Interface)
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/input.h> /* BUS_SPI */
11#include <linux/module.h>
12#include <linux/spi/spi.h>
13#include <linux/types.h>
14#include "adxl34x.h"
15
16#define MAX_SPI_FREQ_HZ 5000000
17#define MAX_FREQ_NO_FIFODELAY 1500000
18#define ADXL34X_CMD_MULTB (1 << 6)
19#define ADXL34X_CMD_READ (1 << 7)
20#define ADXL34X_WRITECMD(reg) (reg & 0x3F)
21#define ADXL34X_READCMD(reg) (ADXL34X_CMD_READ | (reg & 0x3F))
22#define ADXL34X_READMB_CMD(reg) (ADXL34X_CMD_READ | ADXL34X_CMD_MULTB \
23 | (reg & 0x3F))
24
25static int adxl34x_spi_read(struct device *dev, unsigned char reg)
26{
27 struct spi_device *spi = to_spi_device(dev);
28 unsigned char cmd;
29
30 cmd = ADXL34X_READCMD(reg);
31
32 return spi_w8r8(spi, cmd);
33}
34
35static int adxl34x_spi_write(struct device *dev,
36 unsigned char reg, unsigned char val)
37{
38 struct spi_device *spi = to_spi_device(dev);
39 unsigned char buf[2];
40
41 buf[0] = ADXL34X_WRITECMD(reg);
42 buf[1] = val;
43
44 return spi_write(spi, buf, sizeof(buf));
45}
46
47static int adxl34x_spi_read_block(struct device *dev,
48 unsigned char reg, int count,
49 void *buf)
50{
51 struct spi_device *spi = to_spi_device(dev);
52 ssize_t status;
53
54 reg = ADXL34X_READMB_CMD(reg);
55 status = spi_write_then_read(spi, &reg, 1, buf, count);
56
57 return (status < 0) ? status : 0;
58}
59
60static const struct adxl34x_bus_ops adx134x_spi_bops = {
61 .bustype = BUS_SPI,
62 .write = adxl34x_spi_write,
63 .read = adxl34x_spi_read,
64 .read_block = adxl34x_spi_read_block,
65};
66
67static int __devinit adxl34x_spi_probe(struct spi_device *spi)
68{
69 struct adxl34x *ac;
70
71 /* don't exceed max specified SPI CLK frequency */
72 if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
73 dev_err(&spi->dev, "SPI CLK %d Hz too fast\n", spi->max_speed_hz);
74 return -EINVAL;
75 }
76
77 ac = adxl34x_probe(&spi->dev, spi->irq,
78 spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY,
79 &adx134x_spi_bops);
80
81 if (IS_ERR(ac))
82 return PTR_ERR(ac);
83
84 spi_set_drvdata(spi, ac);
85
86 return 0;
87}
88
89static int __devexit adxl34x_spi_remove(struct spi_device *spi)
90{
91 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
92
93 return adxl34x_remove(ac);
94}
95
96#ifdef CONFIG_PM
97static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message)
98{
99 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
100
101 adxl34x_suspend(ac);
102
103 return 0;
104}
105
106static int adxl34x_spi_resume(struct spi_device *spi)
107{
108 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
109
110 adxl34x_resume(ac);
111
112 return 0;
113}
114#else
115# define adxl34x_spi_suspend NULL
116# define adxl34x_spi_resume NULL
117#endif
118
119static struct spi_driver adxl34x_driver = {
120 .driver = {
121 .name = "adxl34x",
122 .bus = &spi_bus_type,
123 .owner = THIS_MODULE,
124 },
125 .probe = adxl34x_spi_probe,
126 .remove = __devexit_p(adxl34x_spi_remove),
127 .suspend = adxl34x_spi_suspend,
128 .resume = adxl34x_spi_resume,
129};
130
131static int __init adxl34x_spi_init(void)
132{
133 return spi_register_driver(&adxl34x_driver);
134}
135module_init(adxl34x_spi_init);
136
137static void __exit adxl34x_spi_exit(void)
138{
139 spi_unregister_driver(&adxl34x_driver);
140}
141module_exit(adxl34x_spi_exit);
142
143MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
144MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer SPI Bus Driver");
145MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
new file mode 100644
index 000000000000..de5900d50788
--- /dev/null
+++ b/drivers/input/misc/adxl34x.c
@@ -0,0 +1,914 @@
1/*
2 * ADXL345/346 Three-Axis Digital Accelerometers
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/device.h>
11#include <linux/init.h>
12#include <linux/delay.h>
13#include <linux/input.h>
14#include <linux/interrupt.h>
15#include <linux/irq.h>
16#include <linux/slab.h>
17#include <linux/workqueue.h>
18#include <linux/input/adxl34x.h>
19
20#include "adxl34x.h"
21
22/* ADXL345/6 Register Map */
23#define DEVID 0x00 /* R Device ID */
24#define THRESH_TAP 0x1D /* R/W Tap threshold */
25#define OFSX 0x1E /* R/W X-axis offset */
26#define OFSY 0x1F /* R/W Y-axis offset */
27#define OFSZ 0x20 /* R/W Z-axis offset */
28#define DUR 0x21 /* R/W Tap duration */
29#define LATENT 0x22 /* R/W Tap latency */
30#define WINDOW 0x23 /* R/W Tap window */
31#define THRESH_ACT 0x24 /* R/W Activity threshold */
32#define THRESH_INACT 0x25 /* R/W Inactivity threshold */
33#define TIME_INACT 0x26 /* R/W Inactivity time */
34#define ACT_INACT_CTL 0x27 /* R/W Axis enable control for activity and */
35 /* inactivity detection */
36#define THRESH_FF 0x28 /* R/W Free-fall threshold */
37#define TIME_FF 0x29 /* R/W Free-fall time */
38#define TAP_AXES 0x2A /* R/W Axis control for tap/double tap */
39#define ACT_TAP_STATUS 0x2B /* R Source of tap/double tap */
40#define BW_RATE 0x2C /* R/W Data rate and power mode control */
41#define POWER_CTL 0x2D /* R/W Power saving features control */
42#define INT_ENABLE 0x2E /* R/W Interrupt enable control */
43#define INT_MAP 0x2F /* R/W Interrupt mapping control */
44#define INT_SOURCE 0x30 /* R Source of interrupts */
45#define DATA_FORMAT 0x31 /* R/W Data format control */
46#define DATAX0 0x32 /* R X-Axis Data 0 */
47#define DATAX1 0x33 /* R X-Axis Data 1 */
48#define DATAY0 0x34 /* R Y-Axis Data 0 */
49#define DATAY1 0x35 /* R Y-Axis Data 1 */
50#define DATAZ0 0x36 /* R Z-Axis Data 0 */
51#define DATAZ1 0x37 /* R Z-Axis Data 1 */
52#define FIFO_CTL 0x38 /* R/W FIFO control */
53#define FIFO_STATUS 0x39 /* R FIFO status */
54#define TAP_SIGN 0x3A /* R Sign and source for tap/double tap */
55/* Orientation ADXL346 only */
56#define ORIENT_CONF 0x3B /* R/W Orientation configuration */
57#define ORIENT 0x3C /* R Orientation status */
58
59/* DEVIDs */
60#define ID_ADXL345 0xE5
61#define ID_ADXL346 0xE6
62
63/* INT_ENABLE/INT_MAP/INT_SOURCE Bits */
64#define DATA_READY (1 << 7)
65#define SINGLE_TAP (1 << 6)
66#define DOUBLE_TAP (1 << 5)
67#define ACTIVITY (1 << 4)
68#define INACTIVITY (1 << 3)
69#define FREE_FALL (1 << 2)
70#define WATERMARK (1 << 1)
71#define OVERRUN (1 << 0)
72
73/* ACT_INACT_CONTROL Bits */
74#define ACT_ACDC (1 << 7)
75#define ACT_X_EN (1 << 6)
76#define ACT_Y_EN (1 << 5)
77#define ACT_Z_EN (1 << 4)
78#define INACT_ACDC (1 << 3)
79#define INACT_X_EN (1 << 2)
80#define INACT_Y_EN (1 << 1)
81#define INACT_Z_EN (1 << 0)
82
83/* TAP_AXES Bits */
84#define SUPPRESS (1 << 3)
85#define TAP_X_EN (1 << 2)
86#define TAP_Y_EN (1 << 1)
87#define TAP_Z_EN (1 << 0)
88
89/* ACT_TAP_STATUS Bits */
90#define ACT_X_SRC (1 << 6)
91#define ACT_Y_SRC (1 << 5)
92#define ACT_Z_SRC (1 << 4)
93#define ASLEEP (1 << 3)
94#define TAP_X_SRC (1 << 2)
95#define TAP_Y_SRC (1 << 1)
96#define TAP_Z_SRC (1 << 0)
97
98/* BW_RATE Bits */
99#define LOW_POWER (1 << 4)
100#define RATE(x) ((x) & 0xF)
101
102/* POWER_CTL Bits */
103#define PCTL_LINK (1 << 5)
104#define PCTL_AUTO_SLEEP (1 << 4)
105#define PCTL_MEASURE (1 << 3)
106#define PCTL_SLEEP (1 << 2)
107#define PCTL_WAKEUP(x) ((x) & 0x3)
108
109/* DATA_FORMAT Bits */
110#define SELF_TEST (1 << 7)
111#define SPI (1 << 6)
112#define INT_INVERT (1 << 5)
113#define FULL_RES (1 << 3)
114#define JUSTIFY (1 << 2)
115#define RANGE(x) ((x) & 0x3)
116#define RANGE_PM_2g 0
117#define RANGE_PM_4g 1
118#define RANGE_PM_8g 2
119#define RANGE_PM_16g 3
120
121/*
122 * Maximum value our axis may get in full res mode for the input device
123 * (signed 13 bits)
124 */
125#define ADXL_FULLRES_MAX_VAL 4096
126
127/*
128 * Maximum value our axis may get in fixed res mode for the input device
129 * (signed 10 bits)
130 */
131#define ADXL_FIXEDRES_MAX_VAL 512
132
133/* FIFO_CTL Bits */
134#define FIFO_MODE(x) (((x) & 0x3) << 6)
135#define FIFO_BYPASS 0
136#define FIFO_FIFO 1
137#define FIFO_STREAM 2
138#define FIFO_TRIGGER 3
139#define TRIGGER (1 << 5)
140#define SAMPLES(x) ((x) & 0x1F)
141
142/* FIFO_STATUS Bits */
143#define FIFO_TRIG (1 << 7)
144#define ENTRIES(x) ((x) & 0x3F)
145
146/* TAP_SIGN Bits ADXL346 only */
147#define XSIGN (1 << 6)
148#define YSIGN (1 << 5)
149#define ZSIGN (1 << 4)
150#define XTAP (1 << 3)
151#define YTAP (1 << 2)
152#define ZTAP (1 << 1)
153
154/* ORIENT_CONF ADXL346 only */
155#define ORIENT_DEADZONE(x) (((x) & 0x7) << 4)
156#define ORIENT_DIVISOR(x) ((x) & 0x7)
157
158/* ORIENT ADXL346 only */
159#define ADXL346_2D_VALID (1 << 6)
160#define ADXL346_2D_ORIENT(x) (((x) & 0x3) >> 4)
161#define ADXL346_3D_VALID (1 << 3)
162#define ADXL346_3D_ORIENT(x) ((x) & 0x7)
163#define ADXL346_2D_PORTRAIT_POS 0 /* +X */
164#define ADXL346_2D_PORTRAIT_NEG 1 /* -X */
165#define ADXL346_2D_LANDSCAPE_POS 2 /* +Y */
166#define ADXL346_2D_LANDSCAPE_NEG 3 /* -Y */
167
168#define ADXL346_3D_FRONT 3 /* +X */
169#define ADXL346_3D_BACK 4 /* -X */
170#define ADXL346_3D_RIGHT 2 /* +Y */
171#define ADXL346_3D_LEFT 5 /* -Y */
172#define ADXL346_3D_TOP 1 /* +Z */
173#define ADXL346_3D_BOTTOM 6 /* -Z */
174
175#undef ADXL_DEBUG
176
177#define ADXL_X_AXIS 0
178#define ADXL_Y_AXIS 1
179#define ADXL_Z_AXIS 2
180
181#define AC_READ(ac, reg) ((ac)->bops->read((ac)->dev, reg))
182#define AC_WRITE(ac, reg, val) ((ac)->bops->write((ac)->dev, reg, val))
183
184struct axis_triple {
185 int x;
186 int y;
187 int z;
188};
189
190struct adxl34x {
191 struct device *dev;
192 struct input_dev *input;
193 struct mutex mutex; /* reentrant protection for struct */
194 struct adxl34x_platform_data pdata;
195 struct axis_triple swcal;
196 struct axis_triple hwcal;
197 struct axis_triple saved;
198 char phys[32];
199 unsigned orient2d_saved;
200 unsigned orient3d_saved;
201 bool disabled; /* P: mutex */
202 bool opened; /* P: mutex */
203 bool suspended; /* P: mutex */
204 bool fifo_delay;
205 int irq;
206 unsigned model;
207 unsigned int_mask;
208
209 const struct adxl34x_bus_ops *bops;
210};
211
212static const struct adxl34x_platform_data adxl34x_default_init = {
213 .tap_threshold = 35,
214 .tap_duration = 3,
215 .tap_latency = 20,
216 .tap_window = 20,
217 .tap_axis_control = ADXL_TAP_X_EN | ADXL_TAP_Y_EN | ADXL_TAP_Z_EN,
218 .act_axis_control = 0xFF,
219 .activity_threshold = 6,
220 .inactivity_threshold = 4,
221 .inactivity_time = 3,
222 .free_fall_threshold = 8,
223 .free_fall_time = 0x20,
224 .data_rate = 8,
225 .data_range = ADXL_FULL_RES,
226
227 .ev_type = EV_ABS,
228 .ev_code_x = ABS_X, /* EV_REL */
229 .ev_code_y = ABS_Y, /* EV_REL */
230 .ev_code_z = ABS_Z, /* EV_REL */
231
232 .ev_code_tap = {BTN_TOUCH, BTN_TOUCH, BTN_TOUCH}, /* EV_KEY {x,y,z} */
233 .power_mode = ADXL_AUTO_SLEEP | ADXL_LINK,
234 .fifo_mode = FIFO_STREAM,
235 .watermark = 0,
236};
237
238static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis)
239{
240 short buf[3];
241
242 ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf);
243
244 mutex_lock(&ac->mutex);
245 ac->saved.x = (s16) le16_to_cpu(buf[0]);
246 axis->x = ac->saved.x;
247
248 ac->saved.y = (s16) le16_to_cpu(buf[1]);
249 axis->y = ac->saved.y;
250
251 ac->saved.z = (s16) le16_to_cpu(buf[2]);
252 axis->z = ac->saved.z;
253 mutex_unlock(&ac->mutex);
254}
255
256static void adxl34x_service_ev_fifo(struct adxl34x *ac)
257{
258 struct adxl34x_platform_data *pdata = &ac->pdata;
259 struct axis_triple axis;
260
261 adxl34x_get_triple(ac, &axis);
262
263 input_event(ac->input, pdata->ev_type, pdata->ev_code_x,
264 axis.x - ac->swcal.x);
265 input_event(ac->input, pdata->ev_type, pdata->ev_code_y,
266 axis.y - ac->swcal.y);
267 input_event(ac->input, pdata->ev_type, pdata->ev_code_z,
268 axis.z - ac->swcal.z);
269}
270
271static void adxl34x_report_key_single(struct input_dev *input, int key)
272{
273 input_report_key(input, key, true);
274 input_sync(input);
275 input_report_key(input, key, false);
276}
277
278static void adxl34x_send_key_events(struct adxl34x *ac,
279 struct adxl34x_platform_data *pdata, int status, int press)
280{
281 int i;
282
283 for (i = ADXL_X_AXIS; i <= ADXL_Z_AXIS; i++) {
284 if (status & (1 << (ADXL_Z_AXIS - i)))
285 input_report_key(ac->input,
286 pdata->ev_code_tap[i], press);
287 }
288}
289
290static void adxl34x_do_tap(struct adxl34x *ac,
291 struct adxl34x_platform_data *pdata, int status)
292{
293 adxl34x_send_key_events(ac, pdata, status, true);
294 input_sync(ac->input);
295 adxl34x_send_key_events(ac, pdata, status, false);
296}
297
298static irqreturn_t adxl34x_irq(int irq, void *handle)
299{
300 struct adxl34x *ac = handle;
301 struct adxl34x_platform_data *pdata = &ac->pdata;
302 int int_stat, tap_stat, samples, orient, orient_code;
303
304 /*
305 * ACT_TAP_STATUS should be read before clearing the interrupt
306 * Avoid reading ACT_TAP_STATUS in case TAP detection is disabled
307 */
308
309 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN))
310 tap_stat = AC_READ(ac, ACT_TAP_STATUS);
311 else
312 tap_stat = 0;
313
314 int_stat = AC_READ(ac, INT_SOURCE);
315
316 if (int_stat & FREE_FALL)
317 adxl34x_report_key_single(ac->input, pdata->ev_code_ff);
318
319 if (int_stat & OVERRUN)
320 dev_dbg(ac->dev, "OVERRUN\n");
321
322 if (int_stat & (SINGLE_TAP | DOUBLE_TAP)) {
323 adxl34x_do_tap(ac, pdata, tap_stat);
324
325 if (int_stat & DOUBLE_TAP)
326 adxl34x_do_tap(ac, pdata, tap_stat);
327 }
328
329 if (pdata->ev_code_act_inactivity) {
330 if (int_stat & ACTIVITY)
331 input_report_key(ac->input,
332 pdata->ev_code_act_inactivity, 1);
333 if (int_stat & INACTIVITY)
334 input_report_key(ac->input,
335 pdata->ev_code_act_inactivity, 0);
336 }
337
338 /*
339 * ORIENTATION SENSING ADXL346 only
340 */
341 if (pdata->orientation_enable) {
342 orient = AC_READ(ac, ORIENT);
343 if ((pdata->orientation_enable & ADXL_EN_ORIENTATION_2D) &&
344 (orient & ADXL346_2D_VALID)) {
345
346 orient_code = ADXL346_2D_ORIENT(orient);
347 /* Report orientation only when it changes */
348 if (ac->orient2d_saved != orient_code) {
349 ac->orient2d_saved = orient_code;
350 adxl34x_report_key_single(ac->input,
351 pdata->ev_codes_orient_2d[orient_code]);
352 }
353 }
354
355 if ((pdata->orientation_enable & ADXL_EN_ORIENTATION_3D) &&
356 (orient & ADXL346_3D_VALID)) {
357
358 orient_code = ADXL346_3D_ORIENT(orient) - 1;
359 /* Report orientation only when it changes */
360 if (ac->orient3d_saved != orient_code) {
361 ac->orient3d_saved = orient_code;
362 adxl34x_report_key_single(ac->input,
363 pdata->ev_codes_orient_3d[orient_code]);
364 }
365 }
366 }
367
368 if (int_stat & (DATA_READY | WATERMARK)) {
369
370 if (pdata->fifo_mode)
371 samples = ENTRIES(AC_READ(ac, FIFO_STATUS)) + 1;
372 else
373 samples = 1;
374
375 for (; samples > 0; samples--) {
376 adxl34x_service_ev_fifo(ac);
377 /*
378 * To ensure that the FIFO has
379 * completely popped, there must be at least 5 us between
380 * the end of reading the data registers, signified by the
381 * transition to register 0x38 from 0x37 or the CS pin
382 * going high, and the start of new reads of the FIFO or
383 * reading the FIFO_STATUS register. For SPI operation at
384 * 1.5 MHz or lower, the register addressing portion of the
385 * transmission is sufficient delay to ensure the FIFO has
386 * completely popped. It is necessary for SPI operation
387 * greater than 1.5 MHz to de-assert the CS pin to ensure a
388 * total of 5 us, which is at most 3.4 us at 5 MHz
389 * operation.
390 */
391 if (ac->fifo_delay && (samples > 1))
392 udelay(3);
393 }
394 }
395
396 input_sync(ac->input);
397
398 return IRQ_HANDLED;
399}
400
401static void __adxl34x_disable(struct adxl34x *ac)
402{
403 /*
404 * A '0' places the ADXL34x into standby mode
405 * with minimum power consumption.
406 */
407 AC_WRITE(ac, POWER_CTL, 0);
408}
409
410static void __adxl34x_enable(struct adxl34x *ac)
411{
412 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE);
413}
414
415void adxl34x_suspend(struct adxl34x *ac)
416{
417 mutex_lock(&ac->mutex);
418
419 if (!ac->suspended && !ac->disabled && ac->opened)
420 __adxl34x_disable(ac);
421
422 ac->suspended = true;
423
424 mutex_unlock(&ac->mutex);
425}
426EXPORT_SYMBOL_GPL(adxl34x_suspend);
427
428void adxl34x_resume(struct adxl34x *ac)
429{
430 mutex_lock(&ac->mutex);
431
432 if (ac->suspended && !ac->disabled && ac->opened)
433 __adxl34x_enable(ac);
434
435 ac->suspended = false;
436
437 mutex_unlock(&ac->mutex);
438}
439EXPORT_SYMBOL_GPL(adxl34x_resume);
440
441static ssize_t adxl34x_disable_show(struct device *dev,
442 struct device_attribute *attr, char *buf)
443{
444 struct adxl34x *ac = dev_get_drvdata(dev);
445
446 return sprintf(buf, "%u\n", ac->disabled);
447}
448
449static ssize_t adxl34x_disable_store(struct device *dev,
450 struct device_attribute *attr,
451 const char *buf, size_t count)
452{
453 struct adxl34x *ac = dev_get_drvdata(dev);
454 unsigned long val;
455 int error;
456
457 error = strict_strtoul(buf, 10, &val);
458 if (error)
459 return error;
460
461 mutex_lock(&ac->mutex);
462
463 if (!ac->suspended && ac->opened) {
464 if (val) {
465 if (!ac->disabled)
466 __adxl34x_disable(ac);
467 } else {
468 if (ac->disabled)
469 __adxl34x_enable(ac);
470 }
471 }
472
473 ac->disabled = !!val;
474
475 mutex_unlock(&ac->mutex);
476
477 return count;
478}
479
480static DEVICE_ATTR(disable, 0664, adxl34x_disable_show, adxl34x_disable_store);
481
482static ssize_t adxl34x_calibrate_show(struct device *dev,
483 struct device_attribute *attr, char *buf)
484{
485 struct adxl34x *ac = dev_get_drvdata(dev);
486 ssize_t count;
487
488 mutex_lock(&ac->mutex);
489 count = sprintf(buf, "%d,%d,%d\n",
490 ac->hwcal.x * 4 + ac->swcal.x,
491 ac->hwcal.y * 4 + ac->swcal.y,
492 ac->hwcal.z * 4 + ac->swcal.z);
493 mutex_unlock(&ac->mutex);
494
495 return count;
496}
497
498static ssize_t adxl34x_calibrate_store(struct device *dev,
499 struct device_attribute *attr,
500 const char *buf, size_t count)
501{
502 struct adxl34x *ac = dev_get_drvdata(dev);
503
504 /*
505 * Hardware offset calibration has a resolution of 15.6 mg/LSB.
506 * We use HW calibration and handle the remaining bits in SW. (4mg/LSB)
507 */
508
509 mutex_lock(&ac->mutex);
510 ac->hwcal.x -= (ac->saved.x / 4);
511 ac->swcal.x = ac->saved.x % 4;
512
513 ac->hwcal.y -= (ac->saved.y / 4);
514 ac->swcal.y = ac->saved.y % 4;
515
516 ac->hwcal.z -= (ac->saved.z / 4);
517 ac->swcal.z = ac->saved.z % 4;
518
519 AC_WRITE(ac, OFSX, (s8) ac->hwcal.x);
520 AC_WRITE(ac, OFSY, (s8) ac->hwcal.y);
521 AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z);
522 mutex_unlock(&ac->mutex);
523
524 return count;
525}
526
527static DEVICE_ATTR(calibrate, 0664,
528 adxl34x_calibrate_show, adxl34x_calibrate_store);
529
530static ssize_t adxl34x_rate_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
532{
533 struct adxl34x *ac = dev_get_drvdata(dev);
534
535 return sprintf(buf, "%u\n", RATE(ac->pdata.data_rate));
536}
537
538static ssize_t adxl34x_rate_store(struct device *dev,
539 struct device_attribute *attr,
540 const char *buf, size_t count)
541{
542 struct adxl34x *ac = dev_get_drvdata(dev);
543 unsigned long val;
544 int error;
545
546 error = strict_strtoul(buf, 10, &val);
547 if (error)
548 return error;
549
550 mutex_lock(&ac->mutex);
551
552 ac->pdata.data_rate = RATE(val);
553 AC_WRITE(ac, BW_RATE,
554 ac->pdata.data_rate |
555 (ac->pdata.low_power_mode ? LOW_POWER : 0));
556
557 mutex_unlock(&ac->mutex);
558
559 return count;
560}
561
562static DEVICE_ATTR(rate, 0664, adxl34x_rate_show, adxl34x_rate_store);
563
564static ssize_t adxl34x_autosleep_show(struct device *dev,
565 struct device_attribute *attr, char *buf)
566{
567 struct adxl34x *ac = dev_get_drvdata(dev);
568
569 return sprintf(buf, "%u\n",
570 ac->pdata.power_mode & (PCTL_AUTO_SLEEP | PCTL_LINK) ? 1 : 0);
571}
572
573static ssize_t adxl34x_autosleep_store(struct device *dev,
574 struct device_attribute *attr,
575 const char *buf, size_t count)
576{
577 struct adxl34x *ac = dev_get_drvdata(dev);
578 unsigned long val;
579 int error;
580
581 error = strict_strtoul(buf, 10, &val);
582 if (error)
583 return error;
584
585 mutex_lock(&ac->mutex);
586
587 if (val)
588 ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK);
589 else
590 ac->pdata.power_mode &= ~(PCTL_AUTO_SLEEP | PCTL_LINK);
591
592 if (!ac->disabled && !ac->suspended && ac->opened)
593 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE);
594
595 mutex_unlock(&ac->mutex);
596
597 return count;
598}
599
600static DEVICE_ATTR(autosleep, 0664,
601 adxl34x_autosleep_show, adxl34x_autosleep_store);
602
603static ssize_t adxl34x_position_show(struct device *dev,
604 struct device_attribute *attr, char *buf)
605{
606 struct adxl34x *ac = dev_get_drvdata(dev);
607 ssize_t count;
608
609 mutex_lock(&ac->mutex);
610 count = sprintf(buf, "(%d, %d, %d)\n",
611 ac->saved.x, ac->saved.y, ac->saved.z);
612 mutex_unlock(&ac->mutex);
613
614 return count;
615}
616
617static DEVICE_ATTR(position, S_IRUGO, adxl34x_position_show, NULL);
618
619#ifdef ADXL_DEBUG
620static ssize_t adxl34x_write_store(struct device *dev,
621 struct device_attribute *attr,
622 const char *buf, size_t count)
623{
624 struct adxl34x *ac = dev_get_drvdata(dev);
625 unsigned long val;
626 int error;
627
628 /*
629 * This allows basic ADXL register write access for debug purposes.
630 */
631 error = strict_strtoul(buf, 16, &val);
632 if (error)
633 return error;
634
635 mutex_lock(&ac->mutex);
636 AC_WRITE(ac, val >> 8, val & 0xFF);
637 mutex_unlock(&ac->mutex);
638
639 return count;
640}
641
642static DEVICE_ATTR(write, 0664, NULL, adxl34x_write_store);
643#endif
644
645static struct attribute *adxl34x_attributes[] = {
646 &dev_attr_disable.attr,
647 &dev_attr_calibrate.attr,
648 &dev_attr_rate.attr,
649 &dev_attr_autosleep.attr,
650 &dev_attr_position.attr,
651#ifdef ADXL_DEBUG
652 &dev_attr_write.attr,
653#endif
654 NULL
655};
656
657static const struct attribute_group adxl34x_attr_group = {
658 .attrs = adxl34x_attributes,
659};
660
661static int adxl34x_input_open(struct input_dev *input)
662{
663 struct adxl34x *ac = input_get_drvdata(input);
664
665 mutex_lock(&ac->mutex);
666
667 if (!ac->suspended && !ac->disabled)
668 __adxl34x_enable(ac);
669
670 ac->opened = true;
671
672 mutex_unlock(&ac->mutex);
673
674 return 0;
675}
676
677static void adxl34x_input_close(struct input_dev *input)
678{
679 struct adxl34x *ac = input_get_drvdata(input);
680
681 mutex_lock(&ac->mutex);
682
683 if (!ac->suspended && !ac->disabled)
684 __adxl34x_disable(ac);
685
686 ac->opened = false;
687
688 mutex_unlock(&ac->mutex);
689}
690
691struct adxl34x *adxl34x_probe(struct device *dev, int irq,
692 bool fifo_delay_default,
693 const struct adxl34x_bus_ops *bops)
694{
695 struct adxl34x *ac;
696 struct input_dev *input_dev;
697 const struct adxl34x_platform_data *pdata;
698 int err, range, i;
699 unsigned char revid;
700
701 if (!irq) {
702 dev_err(dev, "no IRQ?\n");
703 err = -ENODEV;
704 goto err_out;
705 }
706
707 ac = kzalloc(sizeof(*ac), GFP_KERNEL);
708 input_dev = input_allocate_device();
709 if (!ac || !input_dev) {
710 err = -ENOMEM;
711 goto err_free_mem;
712 }
713
714 ac->fifo_delay = fifo_delay_default;
715
716 pdata = dev->platform_data;
717 if (!pdata) {
718 dev_dbg(dev,
719 "No platfrom data: Using default initialization\n");
720 pdata = &adxl34x_default_init;
721 }
722
723 ac->pdata = *pdata;
724 pdata = &ac->pdata;
725
726 ac->input = input_dev;
727 ac->dev = dev;
728 ac->irq = irq;
729 ac->bops = bops;
730
731 mutex_init(&ac->mutex);
732
733 input_dev->name = "ADXL34x accelerometer";
734 revid = ac->bops->read(dev, DEVID);
735
736 switch (revid) {
737 case ID_ADXL345:
738 ac->model = 345;
739 break;
740 case ID_ADXL346:
741 ac->model = 346;
742 break;
743 default:
744 dev_err(dev, "Failed to probe %s\n", input_dev->name);
745 err = -ENODEV;
746 goto err_free_mem;
747 }
748
749 snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev));
750
751 input_dev->phys = ac->phys;
752 input_dev->dev.parent = dev;
753 input_dev->id.product = ac->model;
754 input_dev->id.bustype = bops->bustype;
755 input_dev->open = adxl34x_input_open;
756 input_dev->close = adxl34x_input_close;
757
758 input_set_drvdata(input_dev, ac);
759
760 __set_bit(ac->pdata.ev_type, input_dev->evbit);
761
762 if (ac->pdata.ev_type == EV_REL) {
763 __set_bit(REL_X, input_dev->relbit);
764 __set_bit(REL_Y, input_dev->relbit);
765 __set_bit(REL_Z, input_dev->relbit);
766 } else {
767 /* EV_ABS */
768 __set_bit(ABS_X, input_dev->absbit);
769 __set_bit(ABS_Y, input_dev->absbit);
770 __set_bit(ABS_Z, input_dev->absbit);
771
772 if (pdata->data_range & FULL_RES)
773 range = ADXL_FULLRES_MAX_VAL; /* Signed 13-bit */
774 else
775 range = ADXL_FIXEDRES_MAX_VAL; /* Signed 10-bit */
776
777 input_set_abs_params(input_dev, ABS_X, -range, range, 3, 3);
778 input_set_abs_params(input_dev, ABS_Y, -range, range, 3, 3);
779 input_set_abs_params(input_dev, ABS_Z, -range, range, 3, 3);
780 }
781
782 __set_bit(EV_KEY, input_dev->evbit);
783 __set_bit(pdata->ev_code_tap[ADXL_X_AXIS], input_dev->keybit);
784 __set_bit(pdata->ev_code_tap[ADXL_Y_AXIS], input_dev->keybit);
785 __set_bit(pdata->ev_code_tap[ADXL_Z_AXIS], input_dev->keybit);
786
787 if (pdata->ev_code_ff) {
788 ac->int_mask = FREE_FALL;
789 __set_bit(pdata->ev_code_ff, input_dev->keybit);
790 }
791
792 if (pdata->ev_code_act_inactivity)
793 __set_bit(pdata->ev_code_act_inactivity, input_dev->keybit);
794
795 ac->int_mask |= ACTIVITY | INACTIVITY;
796
797 if (pdata->watermark) {
798 ac->int_mask |= WATERMARK;
799 if (!FIFO_MODE(pdata->fifo_mode))
800 ac->pdata.fifo_mode |= FIFO_STREAM;
801 } else {
802 ac->int_mask |= DATA_READY;
803 }
804
805 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN))
806 ac->int_mask |= SINGLE_TAP | DOUBLE_TAP;
807
808 if (FIFO_MODE(pdata->fifo_mode) == FIFO_BYPASS)
809 ac->fifo_delay = false;
810
811 ac->bops->write(dev, POWER_CTL, 0);
812
813 err = request_threaded_irq(ac->irq, NULL, adxl34x_irq,
814 IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
815 dev_name(dev), ac);
816 if (err) {
817 dev_err(dev, "irq %d busy?\n", ac->irq);
818 goto err_free_mem;
819 }
820
821 err = sysfs_create_group(&dev->kobj, &adxl34x_attr_group);
822 if (err)
823 goto err_free_irq;
824
825 err = input_register_device(input_dev);
826 if (err)
827 goto err_remove_attr;
828
829 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold);
830 AC_WRITE(ac, OFSX, pdata->x_axis_offset);
831 ac->hwcal.x = pdata->x_axis_offset;
832 AC_WRITE(ac, OFSY, pdata->y_axis_offset);
833 ac->hwcal.y = pdata->y_axis_offset;
834 AC_WRITE(ac, OFSZ, pdata->z_axis_offset);
835 ac->hwcal.z = pdata->z_axis_offset;
836 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold);
837 AC_WRITE(ac, DUR, pdata->tap_duration);
838 AC_WRITE(ac, LATENT, pdata->tap_latency);
839 AC_WRITE(ac, WINDOW, pdata->tap_window);
840 AC_WRITE(ac, THRESH_ACT, pdata->activity_threshold);
841 AC_WRITE(ac, THRESH_INACT, pdata->inactivity_threshold);
842 AC_WRITE(ac, TIME_INACT, pdata->inactivity_time);
843 AC_WRITE(ac, THRESH_FF, pdata->free_fall_threshold);
844 AC_WRITE(ac, TIME_FF, pdata->free_fall_time);
845 AC_WRITE(ac, TAP_AXES, pdata->tap_axis_control);
846 AC_WRITE(ac, ACT_INACT_CTL, pdata->act_axis_control);
847 AC_WRITE(ac, BW_RATE, RATE(ac->pdata.data_rate) |
848 (pdata->low_power_mode ? LOW_POWER : 0));
849 AC_WRITE(ac, DATA_FORMAT, pdata->data_range);
850 AC_WRITE(ac, FIFO_CTL, FIFO_MODE(pdata->fifo_mode) |
851 SAMPLES(pdata->watermark));
852
853 if (pdata->use_int2) {
854 /* Map all INTs to INT2 */
855 AC_WRITE(ac, INT_MAP, ac->int_mask | OVERRUN);
856 } else {
857 /* Map all INTs to INT1 */
858 AC_WRITE(ac, INT_MAP, 0);
859 }
860
861 if (ac->model == 346 && ac->pdata.orientation_enable) {
862 AC_WRITE(ac, ORIENT_CONF,
863 ORIENT_DEADZONE(ac->pdata.deadzone_angle) |
864 ORIENT_DIVISOR(ac->pdata.divisor_length));
865
866 ac->orient2d_saved = 1234;
867 ac->orient3d_saved = 1234;
868
869 if (pdata->orientation_enable & ADXL_EN_ORIENTATION_3D)
870 for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_3d); i++)
871 __set_bit(pdata->ev_codes_orient_3d[i],
872 input_dev->keybit);
873
874 if (pdata->orientation_enable & ADXL_EN_ORIENTATION_2D)
875 for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_2d); i++)
876 __set_bit(pdata->ev_codes_orient_2d[i],
877 input_dev->keybit);
878 } else {
879 ac->pdata.orientation_enable = 0;
880 }
881
882 AC_WRITE(ac, INT_ENABLE, ac->int_mask | OVERRUN);
883
884 ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK);
885
886 return ac;
887
888 err_remove_attr:
889 sysfs_remove_group(&dev->kobj, &adxl34x_attr_group);
890 err_free_irq:
891 free_irq(ac->irq, ac);
892 err_free_mem:
893 input_free_device(input_dev);
894 kfree(ac);
895 err_out:
896 return ERR_PTR(err);
897}
898EXPORT_SYMBOL_GPL(adxl34x_probe);
899
900int adxl34x_remove(struct adxl34x *ac)
901{
902 sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group);
903 free_irq(ac->irq, ac);
904 input_unregister_device(ac->input);
905 dev_dbg(ac->dev, "unregistered accelerometer\n");
906 kfree(ac);
907
908 return 0;
909}
910EXPORT_SYMBOL_GPL(adxl34x_remove);
911
912MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
913MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer Driver");
914MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x.h b/drivers/input/misc/adxl34x.h
new file mode 100644
index 000000000000..bbbc80fda164
--- /dev/null
+++ b/drivers/input/misc/adxl34x.h
@@ -0,0 +1,30 @@
1/*
2 * ADXL345/346 Three-Axis Digital Accelerometers (I2C/SPI Interface)
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#ifndef _ADXL34X_H_
11#define _ADXL34X_H_
12
13struct device;
14struct adxl34x;
15
16struct adxl34x_bus_ops {
17 u16 bustype;
18 int (*read)(struct device *, unsigned char);
19 int (*read_block)(struct device *, unsigned char, int, void *);
20 int (*write)(struct device *, unsigned char, unsigned char);
21};
22
23void adxl34x_suspend(struct adxl34x *ac);
24void adxl34x_resume(struct adxl34x *ac);
25struct adxl34x *adxl34x_probe(struct device *dev, int irq,
26 bool fifo_delay_default,
27 const struct adxl34x_bus_ops *bops);
28int adxl34x_remove(struct adxl34x *ac);
29
30#endif
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index e148749b5851..23257652b8e8 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -38,7 +38,8 @@ enum {
38}; 38};
39 39
40static int ati_remote2_set_mask(const char *val, 40static int ati_remote2_set_mask(const char *val,
41 struct kernel_param *kp, unsigned int max) 41 const struct kernel_param *kp,
42 unsigned int max)
42{ 43{
43 unsigned long mask; 44 unsigned long mask;
44 int ret; 45 int ret;
@@ -59,28 +60,31 @@ static int ati_remote2_set_mask(const char *val,
59} 60}
60 61
61static int ati_remote2_set_channel_mask(const char *val, 62static int ati_remote2_set_channel_mask(const char *val,
62 struct kernel_param *kp) 63 const struct kernel_param *kp)
63{ 64{
64 pr_debug("%s()\n", __func__); 65 pr_debug("%s()\n", __func__);
65 66
66 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK); 67 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
67} 68}
68 69
69static int ati_remote2_get_channel_mask(char *buffer, struct kernel_param *kp) 70static int ati_remote2_get_channel_mask(char *buffer,
71 const struct kernel_param *kp)
70{ 72{
71 pr_debug("%s()\n", __func__); 73 pr_debug("%s()\n", __func__);
72 74
73 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg); 75 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
74} 76}
75 77
76static int ati_remote2_set_mode_mask(const char *val, struct kernel_param *kp) 78static int ati_remote2_set_mode_mask(const char *val,
79 const struct kernel_param *kp)
77{ 80{
78 pr_debug("%s()\n", __func__); 81 pr_debug("%s()\n", __func__);
79 82
80 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK); 83 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
81} 84}
82 85
83static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp) 86static int ati_remote2_get_mode_mask(char *buffer,
87 const struct kernel_param *kp)
84{ 88{
85 pr_debug("%s()\n", __func__); 89 pr_debug("%s()\n", __func__);
86 90
@@ -89,15 +93,19 @@ static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp)
89 93
90static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; 94static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
91#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int) 95#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
92#define param_set_channel_mask ati_remote2_set_channel_mask 96static struct kernel_param_ops param_ops_channel_mask = {
93#define param_get_channel_mask ati_remote2_get_channel_mask 97 .set = ati_remote2_set_channel_mask,
98 .get = ati_remote2_get_channel_mask,
99};
94module_param(channel_mask, channel_mask, 0644); 100module_param(channel_mask, channel_mask, 0644);
95MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); 101MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
96 102
97static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; 103static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
98#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int) 104#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
99#define param_set_mode_mask ati_remote2_set_mode_mask 105static struct kernel_param_ops param_ops_mode_mask = {
100#define param_get_mode_mask ati_remote2_get_mode_mask 106 .set = ati_remote2_set_mode_mask,
107 .get = ati_remote2_get_mode_mask,
108};
101module_param(mode_mask, mode_mask, 0644); 109module_param(mode_mask, mode_mask, 0644);
102MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); 110MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
103 111
diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
index dfaa9a045ed8..601f7372f9c4 100644
--- a/drivers/input/misc/atlas_btns.c
+++ b/drivers/input/misc/atlas_btns.c
@@ -21,6 +21,8 @@
21 * 21 *
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/kernel.h> 26#include <linux/kernel.h>
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/init.h> 28#include <linux/init.h>
@@ -60,12 +62,11 @@ static acpi_status acpi_atlas_button_handler(u32 function,
60 input_report_key(input_dev, atlas_keymap[code], key_down); 62 input_report_key(input_dev, atlas_keymap[code], key_down);
61 input_sync(input_dev); 63 input_sync(input_dev);
62 64
63 status = 0; 65 status = AE_OK;
64 } else { 66 } else {
65 printk(KERN_WARNING "atlas: shrugged on unexpected function" 67 pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
66 ":function=%x,address=%lx,value=%x\n",
67 function, (unsigned long)address, (u32)*value); 68 function, (unsigned long)address, (u32)*value);
68 status = -EINVAL; 69 status = AE_BAD_PARAMETER;
69 } 70 }
70 71
71 return status; 72 return status;
@@ -79,7 +80,7 @@ static int atlas_acpi_button_add(struct acpi_device *device)
79 80
80 input_dev = input_allocate_device(); 81 input_dev = input_allocate_device();
81 if (!input_dev) { 82 if (!input_dev) {
82 printk(KERN_ERR "atlas: unable to allocate input device\n"); 83 pr_err("unable to allocate input device\n");
83 return -ENOMEM; 84 return -ENOMEM;
84 } 85 }
85 86
@@ -102,7 +103,7 @@ static int atlas_acpi_button_add(struct acpi_device *device)
102 103
103 err = input_register_device(input_dev); 104 err = input_register_device(input_dev);
104 if (err) { 105 if (err) {
105 printk(KERN_ERR "atlas: couldn't register input device\n"); 106 pr_err("couldn't register input device\n");
106 input_free_device(input_dev); 107 input_free_device(input_dev);
107 return err; 108 return err;
108 } 109 }
@@ -112,12 +113,12 @@ static int atlas_acpi_button_add(struct acpi_device *device)
112 0x81, &acpi_atlas_button_handler, 113 0x81, &acpi_atlas_button_handler,
113 &acpi_atlas_button_setup, device); 114 &acpi_atlas_button_setup, device);
114 if (ACPI_FAILURE(status)) { 115 if (ACPI_FAILURE(status)) {
115 printk(KERN_ERR "Atlas: Error installing addr spc handler\n"); 116 pr_err("error installing addr spc handler\n");
116 input_unregister_device(input_dev); 117 input_unregister_device(input_dev);
117 status = -EINVAL; 118 err = -EINVAL;
118 } 119 }
119 120
120 return status; 121 return err;
121} 122}
122 123
123static int atlas_acpi_button_remove(struct acpi_device *device, int type) 124static int atlas_acpi_button_remove(struct acpi_device *device, int type)
@@ -126,14 +127,12 @@ static int atlas_acpi_button_remove(struct acpi_device *device, int type)
126 127
127 status = acpi_remove_address_space_handler(device->handle, 128 status = acpi_remove_address_space_handler(device->handle,
128 0x81, &acpi_atlas_button_handler); 129 0x81, &acpi_atlas_button_handler);
129 if (ACPI_FAILURE(status)) { 130 if (ACPI_FAILURE(status))
130 printk(KERN_ERR "Atlas: Error removing addr spc handler\n"); 131 pr_err("error removing addr spc handler\n");
131 status = -EINVAL;
132 }
133 132
134 input_unregister_device(input_dev); 133 input_unregister_device(input_dev);
135 134
136 return status; 135 return 0;
137} 136}
138 137
139static const struct acpi_device_id atlas_device_ids[] = { 138static const struct acpi_device_id atlas_device_ids[] = {
@@ -145,6 +144,7 @@ MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
145static struct acpi_driver atlas_acpi_driver = { 144static struct acpi_driver atlas_acpi_driver = {
146 .name = ACPI_ATLAS_NAME, 145 .name = ACPI_ATLAS_NAME,
147 .class = ACPI_ATLAS_CLASS, 146 .class = ACPI_ATLAS_CLASS,
147 .owner = THIS_MODULE,
148 .ids = atlas_device_ids, 148 .ids = atlas_device_ids,
149 .ops = { 149 .ops = {
150 .add = atlas_acpi_button_add, 150 .add = atlas_acpi_button_add,
@@ -154,18 +154,10 @@ static struct acpi_driver atlas_acpi_driver = {
154 154
155static int __init atlas_acpi_init(void) 155static int __init atlas_acpi_init(void)
156{ 156{
157 int result;
158
159 if (acpi_disabled) 157 if (acpi_disabled)
160 return -ENODEV; 158 return -ENODEV;
161 159
162 result = acpi_bus_register_driver(&atlas_acpi_driver); 160 return acpi_bus_register_driver(&atlas_acpi_driver);
163 if (result < 0) {
164 printk(KERN_ERR "Atlas ACPI: Unable to register driver\n");
165 return -ENODEV;
166 }
167
168 return 0;
169} 161}
170 162
171static void __exit atlas_acpi_exit(void) 163static void __exit atlas_acpi_exit(void)
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index e00a1cc79c0a..c19066479057 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -678,7 +678,7 @@ static const struct file_operations hp_sdc_rtc_fops = {
678 .llseek = no_llseek, 678 .llseek = no_llseek,
679 .read = hp_sdc_rtc_read, 679 .read = hp_sdc_rtc_read,
680 .poll = hp_sdc_rtc_poll, 680 .poll = hp_sdc_rtc_poll,
681 .unlocked_ioctl = hp_sdc_rtc_ioctl, 681 .unlocked_ioctl = hp_sdc_rtc_unlocked_ioctl,
682 .open = hp_sdc_rtc_open, 682 .open = hp_sdc_rtc_open,
683 .fasync = hp_sdc_rtc_fasync, 683 .fasync = hp_sdc_rtc_fasync,
684}; 684};
diff --git a/drivers/input/misc/ixp4xx-beeper.c b/drivers/input/misc/ixp4xx-beeper.c
index 9946d73624b9..9dfd6e5f786f 100644
--- a/drivers/input/misc/ixp4xx-beeper.c
+++ b/drivers/input/misc/ixp4xx-beeper.c
@@ -115,7 +115,8 @@ static int __devinit ixp4xx_spkr_probe(struct platform_device *dev)
115 input_dev->event = ixp4xx_spkr_event; 115 input_dev->event = ixp4xx_spkr_event;
116 116
117 err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt, 117 err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt,
118 IRQF_DISABLED | IRQF_TIMER, "ixp4xx-beeper", (void *) dev->id); 118 IRQF_DISABLED | IRQF_NO_SUSPEND, "ixp4xx-beeper",
119 (void *) dev->id);
119 if (err) 120 if (err)
120 goto err_free_device; 121 goto err_free_device;
121 122
diff --git a/drivers/input/misc/pcf8574_keypad.c b/drivers/input/misc/pcf8574_keypad.c
index 5c3ac4e0b055..4b42ffc0532a 100644
--- a/drivers/input/misc/pcf8574_keypad.c
+++ b/drivers/input/misc/pcf8574_keypad.c
@@ -69,7 +69,7 @@ static irqreturn_t pcf8574_kp_irq_handler(int irq, void *dev_id)
69 unsigned char nextstate = read_state(lp); 69 unsigned char nextstate = read_state(lp);
70 70
71 if (lp->laststate != nextstate) { 71 if (lp->laststate != nextstate) {
72 int key_down = nextstate <= ARRAY_SIZE(lp->btncode); 72 int key_down = nextstate < ARRAY_SIZE(lp->btncode);
73 unsigned short keycode = key_down ? 73 unsigned short keycode = key_down ?
74 lp->btncode[nextstate] : lp->btncode[lp->laststate]; 74 lp->btncode[nextstate] : lp->btncode[lp->laststate];
75 75
@@ -168,8 +168,6 @@ static int __devexit pcf8574_kp_remove(struct i2c_client *client)
168 input_unregister_device(lp->idev); 168 input_unregister_device(lp->idev);
169 kfree(lp); 169 kfree(lp);
170 170
171 i2c_set_clientdata(client, NULL);
172
173 return 0; 171 return 0;
174} 172}
175 173
diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
new file mode 100644
index 000000000000..57c294f07198
--- /dev/null
+++ b/drivers/input/misc/pwm-beeper.c
@@ -0,0 +1,199 @@
1/*
2 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3 * PWM beeper driver
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/input.h>
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/platform_device.h>
20#include <linux/pwm.h>
21#include <linux/slab.h>
22
23struct pwm_beeper {
24 struct input_dev *input;
25 struct pwm_device *pwm;
26 unsigned long period;
27};
28
29#define HZ_TO_NANOSECONDS(x) (1000000000UL/(x))
30
31static int pwm_beeper_event(struct input_dev *input,
32 unsigned int type, unsigned int code, int value)
33{
34 int ret = 0;
35 struct pwm_beeper *beeper = input_get_drvdata(input);
36 unsigned long period;
37
38 if (type != EV_SND || value < 0)
39 return -EINVAL;
40
41 switch (code) {
42 case SND_BELL:
43 value = value ? 1000 : 0;
44 break;
45 case SND_TONE:
46 break;
47 default:
48 return -EINVAL;
49 }
50
51 if (value == 0) {
52 pwm_config(beeper->pwm, 0, 0);
53 pwm_disable(beeper->pwm);
54 } else {
55 period = HZ_TO_NANOSECONDS(value);
56 ret = pwm_config(beeper->pwm, period / 2, period);
57 if (ret)
58 return ret;
59 ret = pwm_enable(beeper->pwm);
60 if (ret)
61 return ret;
62 beeper->period = period;
63 }
64
65 return 0;
66}
67
68static int __devinit pwm_beeper_probe(struct platform_device *pdev)
69{
70 unsigned long pwm_id = (unsigned long)pdev->dev.platform_data;
71 struct pwm_beeper *beeper;
72 int error;
73
74 beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
75 if (!beeper)
76 return -ENOMEM;
77
78 beeper->pwm = pwm_request(pwm_id, "pwm beeper");
79
80 if (IS_ERR(beeper->pwm)) {
81 error = PTR_ERR(beeper->pwm);
82 dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error);
83 goto err_free;
84 }
85
86 beeper->input = input_allocate_device();
87 if (!beeper->input) {
88 dev_err(&pdev->dev, "Failed to allocate input device\n");
89 error = -ENOMEM;
90 goto err_pwm_free;
91 }
92 beeper->input->dev.parent = &pdev->dev;
93
94 beeper->input->name = "pwm-beeper";
95 beeper->input->phys = "pwm/input0";
96 beeper->input->id.bustype = BUS_HOST;
97 beeper->input->id.vendor = 0x001f;
98 beeper->input->id.product = 0x0001;
99 beeper->input->id.version = 0x0100;
100
101 beeper->input->evbit[0] = BIT(EV_SND);
102 beeper->input->sndbit[0] = BIT(SND_TONE) | BIT(SND_BELL);
103
104 beeper->input->event = pwm_beeper_event;
105
106 input_set_drvdata(beeper->input, beeper);
107
108 error = input_register_device(beeper->input);
109 if (error) {
110 dev_err(&pdev->dev, "Failed to register input device: %d\n", error);
111 goto err_input_free;
112 }
113
114 platform_set_drvdata(pdev, beeper);
115
116 return 0;
117
118err_input_free:
119 input_free_device(beeper->input);
120err_pwm_free:
121 pwm_free(beeper->pwm);
122err_free:
123 kfree(beeper);
124
125 return error;
126}
127
128static int __devexit pwm_beeper_remove(struct platform_device *pdev)
129{
130 struct pwm_beeper *beeper = platform_get_drvdata(pdev);
131
132 platform_set_drvdata(pdev, NULL);
133 input_unregister_device(beeper->input);
134
135 pwm_disable(beeper->pwm);
136 pwm_free(beeper->pwm);
137
138 kfree(beeper);
139
140 return 0;
141}
142
143#ifdef CONFIG_PM
144static int pwm_beeper_suspend(struct device *dev)
145{
146 struct pwm_beeper *beeper = dev_get_drvdata(dev);
147
148 if (beeper->period)
149 pwm_disable(beeper->pwm);
150
151 return 0;
152}
153
154static int pwm_beeper_resume(struct device *dev)
155{
156 struct pwm_beeper *beeper = dev_get_drvdata(dev);
157
158 if (beeper->period) {
159 pwm_config(beeper->pwm, beeper->period / 2, beeper->period);
160 pwm_enable(beeper->pwm);
161 }
162
163 return 0;
164}
165
166static SIMPLE_DEV_PM_OPS(pwm_beeper_pm_ops,
167 pwm_beeper_suspend, pwm_beeper_resume);
168
169#define PWM_BEEPER_PM_OPS (&pwm_beeper_pm_ops)
170#else
171#define PWM_BEEPER_PM_OPS NULL
172#endif
173
174static struct platform_driver pwm_beeper_driver = {
175 .probe = pwm_beeper_probe,
176 .remove = __devexit_p(pwm_beeper_remove),
177 .driver = {
178 .name = "pwm-beeper",
179 .owner = THIS_MODULE,
180 .pm = PWM_BEEPER_PM_OPS,
181 },
182};
183
184static int __init pwm_beeper_init(void)
185{
186 return platform_driver_register(&pwm_beeper_driver);
187}
188module_init(pwm_beeper_init);
189
190static void __exit pwm_beeper_exit(void)
191{
192 platform_driver_unregister(&pwm_beeper_driver);
193}
194module_exit(pwm_beeper_exit);
195
196MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
197MODULE_DESCRIPTION("PWM beeper driver");
198MODULE_LICENSE("GPL");
199MODULE_ALIAS("platform:pwm-beeper");
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index 1dacae4b43f0..8e130bf7d32b 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -173,7 +173,7 @@ static int __devinit sparcspkr_probe(struct device *dev)
173 return 0; 173 return 0;
174} 174}
175 175
176static int sparcspkr_shutdown(struct of_device *dev) 176static int sparcspkr_shutdown(struct platform_device *dev)
177{ 177{
178 struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); 178 struct sparcspkr_state *state = dev_get_drvdata(&dev->dev);
179 struct input_dev *input_dev = state->input_dev; 179 struct input_dev *input_dev = state->input_dev;
@@ -184,7 +184,7 @@ static int sparcspkr_shutdown(struct of_device *dev)
184 return 0; 184 return 0;
185} 185}
186 186
187static int __devinit bbc_beep_probe(struct of_device *op, const struct of_device_id *match) 187static int __devinit bbc_beep_probe(struct platform_device *op, const struct of_device_id *match)
188{ 188{
189 struct sparcspkr_state *state; 189 struct sparcspkr_state *state;
190 struct bbc_beep_info *info; 190 struct bbc_beep_info *info;
@@ -231,7 +231,7 @@ out_err:
231 return err; 231 return err;
232} 232}
233 233
234static int __devexit bbc_remove(struct of_device *op) 234static int __devexit bbc_remove(struct platform_device *op)
235{ 235{
236 struct sparcspkr_state *state = dev_get_drvdata(&op->dev); 236 struct sparcspkr_state *state = dev_get_drvdata(&op->dev);
237 struct input_dev *input_dev = state->input_dev; 237 struct input_dev *input_dev = state->input_dev;
@@ -269,7 +269,7 @@ static struct of_platform_driver bbc_beep_driver = {
269 .shutdown = sparcspkr_shutdown, 269 .shutdown = sparcspkr_shutdown,
270}; 270};
271 271
272static int __devinit grover_beep_probe(struct of_device *op, const struct of_device_id *match) 272static int __devinit grover_beep_probe(struct platform_device *op, const struct of_device_id *match)
273{ 273{
274 struct sparcspkr_state *state; 274 struct sparcspkr_state *state;
275 struct grover_beep_info *info; 275 struct grover_beep_info *info;
@@ -312,7 +312,7 @@ out_err:
312 return err; 312 return err;
313} 313}
314 314
315static int __devexit grover_remove(struct of_device *op) 315static int __devexit grover_remove(struct platform_device *op)
316{ 316{
317 struct sparcspkr_state *state = dev_get_drvdata(&op->dev); 317 struct sparcspkr_state *state = dev_get_drvdata(&op->dev);
318 struct grover_beep_info *info = &state->u.grover; 318 struct grover_beep_info *info = &state->u.grover;
@@ -353,14 +353,12 @@ static struct of_platform_driver grover_beep_driver = {
353 353
354static int __init sparcspkr_init(void) 354static int __init sparcspkr_init(void)
355{ 355{
356 int err = of_register_driver(&bbc_beep_driver, 356 int err = of_register_platform_driver(&bbc_beep_driver);
357 &of_platform_bus_type);
358 357
359 if (!err) { 358 if (!err) {
360 err = of_register_driver(&grover_beep_driver, 359 err = of_register_platform_driver(&grover_beep_driver);
361 &of_platform_bus_type);
362 if (err) 360 if (err)
363 of_unregister_driver(&bbc_beep_driver); 361 of_unregister_platform_driver(&bbc_beep_driver);
364 } 362 }
365 363
366 return err; 364 return err;
@@ -368,8 +366,8 @@ static int __init sparcspkr_init(void)
368 366
369static void __exit sparcspkr_exit(void) 367static void __exit sparcspkr_exit(void)
370{ 368{
371 of_unregister_driver(&bbc_beep_driver); 369 of_unregister_platform_driver(&bbc_beep_driver);
372 of_unregister_driver(&grover_beep_driver); 370 of_unregister_platform_driver(&grover_beep_driver);
373} 371}
374 372
375module_init(sparcspkr_init); 373module_init(sparcspkr_init);
diff --git a/drivers/input/misc/twl4030-pwrbutton.c b/drivers/input/misc/twl4030-pwrbutton.c
index e9069b87fde2..f16972bddca4 100644
--- a/drivers/input/misc/twl4030-pwrbutton.c
+++ b/drivers/input/misc/twl4030-pwrbutton.c
@@ -52,7 +52,7 @@ static irqreturn_t powerbutton_irq(int irq, void *_pwr)
52 return IRQ_HANDLED; 52 return IRQ_HANDLED;
53} 53}
54 54
55static int __devinit twl4030_pwrbutton_probe(struct platform_device *pdev) 55static int __init twl4030_pwrbutton_probe(struct platform_device *pdev)
56{ 56{
57 struct input_dev *pwr; 57 struct input_dev *pwr;
58 int irq = platform_get_irq(pdev, 0); 58 int irq = platform_get_irq(pdev, 0);
@@ -95,7 +95,7 @@ free_input_dev:
95 return err; 95 return err;
96} 96}
97 97
98static int __devexit twl4030_pwrbutton_remove(struct platform_device *pdev) 98static int __exit twl4030_pwrbutton_remove(struct platform_device *pdev)
99{ 99{
100 struct input_dev *pwr = platform_get_drvdata(pdev); 100 struct input_dev *pwr = platform_get_drvdata(pdev);
101 int irq = platform_get_irq(pdev, 0); 101 int irq = platform_get_irq(pdev, 0);
@@ -106,9 +106,8 @@ static int __devexit twl4030_pwrbutton_remove(struct platform_device *pdev)
106 return 0; 106 return 0;
107} 107}
108 108
109struct platform_driver twl4030_pwrbutton_driver = { 109static struct platform_driver twl4030_pwrbutton_driver = {
110 .probe = twl4030_pwrbutton_probe, 110 .remove = __exit_p(twl4030_pwrbutton_remove),
111 .remove = __devexit_p(twl4030_pwrbutton_remove),
112 .driver = { 111 .driver = {
113 .name = "twl4030_pwrbutton", 112 .name = "twl4030_pwrbutton",
114 .owner = THIS_MODULE, 113 .owner = THIS_MODULE,
@@ -117,7 +116,8 @@ struct platform_driver twl4030_pwrbutton_driver = {
117 116
118static int __init twl4030_pwrbutton_init(void) 117static int __init twl4030_pwrbutton_init(void)
119{ 118{
120 return platform_driver_register(&twl4030_pwrbutton_driver); 119 return platform_driver_probe(&twl4030_pwrbutton_driver,
120 twl4030_pwrbutton_probe);
121} 121}
122module_init(twl4030_pwrbutton_init); 122module_init(twl4030_pwrbutton_init);
123 123
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index b71eb55f2dbc..bb53fd33cd1c 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -304,21 +304,25 @@ static int uinput_validate_absbits(struct input_dev *dev)
304 if (!test_bit(cnt, dev->absbit)) 304 if (!test_bit(cnt, dev->absbit))
305 continue; 305 continue;
306 306
307 if ((dev->absmax[cnt] <= dev->absmin[cnt])) { 307 if (input_abs_get_max(dev, cnt) <= input_abs_get_min(dev, cnt)) {
308 printk(KERN_DEBUG 308 printk(KERN_DEBUG
309 "%s: invalid abs[%02x] min:%d max:%d\n", 309 "%s: invalid abs[%02x] min:%d max:%d\n",
310 UINPUT_NAME, cnt, 310 UINPUT_NAME, cnt,
311 dev->absmin[cnt], dev->absmax[cnt]); 311 input_abs_get_min(dev, cnt),
312 input_abs_get_max(dev, cnt));
312 retval = -EINVAL; 313 retval = -EINVAL;
313 break; 314 break;
314 } 315 }
315 316
316 if (dev->absflat[cnt] > (dev->absmax[cnt] - dev->absmin[cnt])) { 317 if (input_abs_get_flat(dev, cnt) >
318 input_abs_get_max(dev, cnt) - input_abs_get_min(dev, cnt)) {
317 printk(KERN_DEBUG 319 printk(KERN_DEBUG
318 "%s: absflat[%02x] out of range: %d " 320 "%s: abs_flat #%02x out of range: %d "
319 "(min:%d/max:%d)\n", 321 "(min:%d/max:%d)\n",
320 UINPUT_NAME, cnt, dev->absflat[cnt], 322 UINPUT_NAME, cnt,
321 dev->absmin[cnt], dev->absmax[cnt]); 323 input_abs_get_flat(dev, cnt),
324 input_abs_get_min(dev, cnt),
325 input_abs_get_max(dev, cnt));
322 retval = -EINVAL; 326 retval = -EINVAL;
323 break; 327 break;
324 } 328 }
@@ -343,7 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
343 struct uinput_user_dev *user_dev; 347 struct uinput_user_dev *user_dev;
344 struct input_dev *dev; 348 struct input_dev *dev;
345 char *name; 349 char *name;
346 int size; 350 int i, size;
347 int retval; 351 int retval;
348 352
349 if (count != sizeof(struct uinput_user_dev)) 353 if (count != sizeof(struct uinput_user_dev))
@@ -387,11 +391,12 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
387 dev->id.product = user_dev->id.product; 391 dev->id.product = user_dev->id.product;
388 dev->id.version = user_dev->id.version; 392 dev->id.version = user_dev->id.version;
389 393
390 size = sizeof(int) * ABS_CNT; 394 for (i = 0; i < ABS_CNT; i++) {
391 memcpy(dev->absmax, user_dev->absmax, size); 395 input_abs_set_max(dev, i, user_dev->absmax[i]);
392 memcpy(dev->absmin, user_dev->absmin, size); 396 input_abs_set_min(dev, i, user_dev->absmin[i]);
393 memcpy(dev->absfuzz, user_dev->absfuzz, size); 397 input_abs_set_fuzz(dev, i, user_dev->absfuzz[i]);
394 memcpy(dev->absflat, user_dev->absflat, size); 398 input_abs_set_flat(dev, i, user_dev->absflat[i]);
399 }
395 400
396 /* check if absmin/absmax/absfuzz/absflat are filled as 401 /* check if absmin/absmax/absfuzz/absflat are filled as
397 * told in Documentation/input/input-programming.txt */ 402 * told in Documentation/input/input-programming.txt */
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index 4dac8b79fcd4..12501de0c5cd 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -1347,7 +1347,7 @@ static int __init wb_module_init(void)
1347 1347
1348 err = map_bios(); 1348 err = map_bios();
1349 if (err) 1349 if (err)
1350 return err; 1350 goto err_free_keymap;
1351 1351
1352 err = platform_driver_register(&wistron_driver); 1352 err = platform_driver_register(&wistron_driver);
1353 if (err) 1353 if (err)
@@ -1371,6 +1371,8 @@ static int __init wb_module_init(void)
1371 platform_driver_unregister(&wistron_driver); 1371 platform_driver_unregister(&wistron_driver);
1372 err_unmap_bios: 1372 err_unmap_bios:
1373 unmap_bios(); 1373 unmap_bios();
1374 err_free_keymap:
1375 kfree(keymap);
1374 1376
1375 return err; 1377 return err;
1376} 1378}
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index eeb58c1cac16..c714ca2407f8 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -17,7 +17,7 @@ config MOUSE_PS2
17 default y 17 default y
18 select SERIO 18 select SERIO
19 select SERIO_LIBPS2 19 select SERIO_LIBPS2
20 select SERIO_I8042 if X86 && !X86_MRST 20 select SERIO_I8042 if X86
21 select SERIO_GSCPS2 if GSC 21 select SERIO_GSCPS2 if GSC
22 help 22 help
23 Say Y here if you have a PS/2 mouse connected to your system. This 23 Say Y here if you have a PS/2 mouse connected to your system. This
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index 05edd75abca0..a9cf76831634 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -205,8 +205,8 @@ struct atp {
205 bool overflow_warned; 205 bool overflow_warned;
206 int x_old; /* last reported x/y, */ 206 int x_old; /* last reported x/y, */
207 int y_old; /* used for smoothing */ 207 int y_old; /* used for smoothing */
208 u8 xy_cur[ATP_XSENSORS + ATP_YSENSORS]; 208 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
209 u8 xy_old[ATP_XSENSORS + ATP_YSENSORS]; 209 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
210 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 210 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
211 int idlecount; /* number of empty packets */ 211 int idlecount; /* number of empty packets */
212 struct work_struct work; 212 struct work_struct work;
@@ -531,7 +531,7 @@ static void atp_complete_geyser_1_2(struct urb *urb)
531 531
532 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { 532 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
533 /* accumulate the change */ 533 /* accumulate the change */
534 int change = dev->xy_old[i] - dev->xy_cur[i]; 534 signed char change = dev->xy_old[i] - dev->xy_cur[i];
535 dev->xy_acc[i] -= change; 535 dev->xy_acc[i] -= change;
536 536
537 /* prevent down drifting */ 537 /* prevent down drifting */
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index 6dedded27222..ea67c49146a3 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -312,6 +312,8 @@ static void setup_events_to_report(struct input_dev *input_dev,
312 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); 312 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
313 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit); 313 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
314 __set_bit(BTN_LEFT, input_dev->keybit); 314 __set_bit(BTN_LEFT, input_dev->keybit);
315
316 input_set_events_per_packet(input_dev, 60);
315} 317}
316 318
317/* report button data as logical button state */ 319/* report button data as logical button state */
@@ -580,23 +582,30 @@ exit:
580 */ 582 */
581static int bcm5974_start_traffic(struct bcm5974 *dev) 583static int bcm5974_start_traffic(struct bcm5974 *dev)
582{ 584{
583 if (bcm5974_wellspring_mode(dev, true)) { 585 int error;
586
587 error = bcm5974_wellspring_mode(dev, true);
588 if (error) {
584 dprintk(1, "bcm5974: mode switch failed\n"); 589 dprintk(1, "bcm5974: mode switch failed\n");
585 goto error; 590 goto err_out;
586 } 591 }
587 592
588 if (usb_submit_urb(dev->bt_urb, GFP_KERNEL)) 593 error = usb_submit_urb(dev->bt_urb, GFP_KERNEL);
589 goto error; 594 if (error)
595 goto err_reset_mode;
590 596
591 if (usb_submit_urb(dev->tp_urb, GFP_KERNEL)) 597 error = usb_submit_urb(dev->tp_urb, GFP_KERNEL);
598 if (error)
592 goto err_kill_bt; 599 goto err_kill_bt;
593 600
594 return 0; 601 return 0;
595 602
596err_kill_bt: 603err_kill_bt:
597 usb_kill_urb(dev->bt_urb); 604 usb_kill_urb(dev->bt_urb);
598error: 605err_reset_mode:
599 return -EIO; 606 bcm5974_wellspring_mode(dev, false);
607err_out:
608 return error;
600} 609}
601 610
602static void bcm5974_pause_traffic(struct bcm5974 *dev) 611static void bcm5974_pause_traffic(struct bcm5974 *dev)
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index b18862b2a70e..48311204ba51 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -185,7 +185,6 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse)
185 struct elantech_data *etd = psmouse->private; 185 struct elantech_data *etd = psmouse->private;
186 unsigned char *packet = psmouse->packet; 186 unsigned char *packet = psmouse->packet;
187 int fingers; 187 int fingers;
188 static int old_fingers;
189 188
190 if (etd->fw_version < 0x020000) { 189 if (etd->fw_version < 0x020000) {
191 /* 190 /*
@@ -203,10 +202,13 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse)
203 } 202 }
204 203
205 if (etd->jumpy_cursor) { 204 if (etd->jumpy_cursor) {
206 /* Discard packets that are likely to have bogus coordinates */ 205 if (fingers != 1) {
207 if (fingers > old_fingers) { 206 etd->single_finger_reports = 0;
207 } else if (etd->single_finger_reports < 2) {
208 /* Discard first 2 reports of one finger, bogus */
209 etd->single_finger_reports++;
208 elantech_debug("discarding packet\n"); 210 elantech_debug("discarding packet\n");
209 goto discard_packet_v1; 211 return;
210 } 212 }
211 } 213 }
212 214
@@ -238,9 +240,6 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse)
238 } 240 }
239 241
240 input_sync(dev); 242 input_sync(dev);
241
242 discard_packet_v1:
243 old_fingers = fingers;
244} 243}
245 244
246/* 245/*
@@ -258,6 +257,14 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse)
258 input_report_key(dev, BTN_TOUCH, fingers != 0); 257 input_report_key(dev, BTN_TOUCH, fingers != 0);
259 258
260 switch (fingers) { 259 switch (fingers) {
260 case 3:
261 /*
262 * Same as one finger, except report of more than 3 fingers:
263 * byte 3: n4 . w1 w0 . . . .
264 */
265 if (packet[3] & 0x80)
266 fingers = 4;
267 /* pass through... */
261 case 1: 268 case 1:
262 /* 269 /*
263 * byte 1: . . . . . x10 x9 x8 270 * byte 1: . . . . . x10 x9 x8
@@ -310,6 +317,7 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse)
310 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1); 317 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
311 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); 318 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
312 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 319 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
320 input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
313 input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 321 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
314 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 322 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
315 323
@@ -467,6 +475,7 @@ static void elantech_set_input_params(struct psmouse *psmouse)
467 break; 475 break;
468 476
469 case 2: 477 case 2:
478 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
470 input_set_abs_params(dev, ABS_X, ETP_XMIN_V2, ETP_XMAX_V2, 0, 0); 479 input_set_abs_params(dev, ABS_X, ETP_XMIN_V2, ETP_XMAX_V2, 0, 0);
471 input_set_abs_params(dev, ABS_Y, ETP_YMIN_V2, ETP_YMAX_V2, 0, 0); 480 input_set_abs_params(dev, ABS_Y, ETP_YMIN_V2, ETP_YMAX_V2, 0, 0);
472 input_set_abs_params(dev, ABS_HAT0X, ETP_2FT_XMIN, ETP_2FT_XMAX, 0, 0); 481 input_set_abs_params(dev, ABS_HAT0X, ETP_2FT_XMIN, ETP_2FT_XMAX, 0, 0);
@@ -733,13 +742,13 @@ int elantech_init(struct psmouse *psmouse)
733 etd->capabilities = param[0]; 742 etd->capabilities = param[0];
734 743
735 /* 744 /*
736 * This firmware seems to suffer from misreporting coordinates when 745 * This firmware suffers from misreporting coordinates when
737 * a touch action starts causing the mouse cursor or scrolled page 746 * a touch action starts causing the mouse cursor or scrolled page
738 * to jump. Enable a workaround. 747 * to jump. Enable a workaround.
739 */ 748 */
740 if (etd->fw_version == 0x020022) { 749 if (etd->fw_version == 0x020022 || etd->fw_version == 0x020600) {
741 pr_info("firmware version 2.0.34 detected, enabling jumpy cursor workaround\n"); 750 pr_info("firmware version 2.0.34/2.6.0 detected, enabling jumpy cursor workaround\n");
742 etd->jumpy_cursor = 1; 751 etd->jumpy_cursor = true;
743 } 752 }
744 753
745 if (elantech_set_absolute_mode(psmouse)) { 754 if (elantech_set_absolute_mode(psmouse)) {
diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h
index ac57bde1bb9f..aa4aac5d2198 100644
--- a/drivers/input/mouse/elantech.h
+++ b/drivers/input/mouse/elantech.h
@@ -100,10 +100,11 @@ struct elantech_data {
100 unsigned char reg_26; 100 unsigned char reg_26;
101 unsigned char debug; 101 unsigned char debug;
102 unsigned char capabilities; 102 unsigned char capabilities;
103 unsigned char paritycheck; 103 bool paritycheck;
104 unsigned char jumpy_cursor; 104 bool jumpy_cursor;
105 unsigned char hw_version; 105 unsigned char hw_version;
106 unsigned int fw_version; 106 unsigned int fw_version;
107 unsigned int single_finger_reports;
107 unsigned char parity[256]; 108 unsigned char parity[256];
108}; 109};
109 110
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 3941f97cfa60..7b02b652e267 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -145,8 +145,8 @@ static int __init pc110pad_init(void)
145 pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y); 145 pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
146 pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 146 pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
147 147
148 pc110pad_dev->absmax[ABS_X] = 0x1ff; 148 input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
149 pc110pad_dev->absmax[ABS_Y] = 0x0ff; 149 input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
150 150
151 pc110pad_dev->open = pc110pad_open; 151 pc110pad_dev->open = pc110pad_open;
152 pc110pad_dev->close = pc110pad_close; 152 pc110pad_dev->close = pc110pad_close;
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 979c50215282..73a7af2542a8 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -39,11 +39,13 @@ MODULE_DESCRIPTION(DRIVER_DESC);
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40 40
41static unsigned int psmouse_max_proto = PSMOUSE_AUTO; 41static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
42static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); 42static int psmouse_set_maxproto(const char *val, const struct kernel_param *);
43static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); 43static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp);
44static struct kernel_param_ops param_ops_proto_abbrev = {
45 .set = psmouse_set_maxproto,
46 .get = psmouse_get_maxproto,
47};
44#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) 48#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
45#define param_set_proto_abbrev psmouse_set_maxproto
46#define param_get_proto_abbrev psmouse_get_maxproto
47module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644); 49module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
48MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches."); 50MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
49 51
@@ -1679,7 +1681,7 @@ static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data,
1679} 1681}
1680 1682
1681 1683
1682static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1684static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)
1683{ 1685{
1684 const struct psmouse_protocol *proto; 1686 const struct psmouse_protocol *proto;
1685 1687
@@ -1696,7 +1698,7 @@ static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1696 return 0; 1698 return 0;
1697} 1699}
1698 1700
1699static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1701static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp)
1700{ 1702{
1701 int type = *((unsigned int *)kp->arg); 1703 int type = *((unsigned int *)kp->arg);
1702 1704
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 40cea334ad13..96b70a43515f 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -141,8 +141,13 @@ static int synaptics_capability(struct psmouse *psmouse)
141 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2]; 141 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
142 priv->ext_cap = priv->ext_cap_0c = 0; 142 priv->ext_cap = priv->ext_cap_0c = 0;
143 143
144 if (!SYN_CAP_VALID(priv->capabilities)) 144 /*
145 * Older firmwares had submodel ID fixed to 0x47
146 */
147 if (SYN_ID_FULL(priv->identity) < 0x705 &&
148 SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
145 return -1; 149 return -1;
150 }
146 151
147 /* 152 /*
148 * Unless capExtended is set the rest of the flags should be ignored 153 * Unless capExtended is set the rest of the flags should be ignored
@@ -206,6 +211,7 @@ static int synaptics_resolution(struct psmouse *psmouse)
206 unsigned char max[3]; 211 unsigned char max[3];
207 212
208 if (SYN_ID_MAJOR(priv->identity) < 4) 213 if (SYN_ID_MAJOR(priv->identity) < 4)
214 return 0;
209 215
210 if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, res) == 0) { 216 if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, res) == 0) {
211 if (res[0] != 0 && (res[1] & 0x80) && res[2] != 0) { 217 if (res[0] != 0 && (res[1] & 0x80) && res[2] != 0) {
@@ -496,7 +502,9 @@ static void synaptics_process_packet(struct psmouse *psmouse)
496 } 502 }
497 input_report_abs(dev, ABS_PRESSURE, hw.z); 503 input_report_abs(dev, ABS_PRESSURE, hw.z);
498 504
499 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); 505 if (SYN_CAP_PALMDETECT(priv->capabilities))
506 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
507
500 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); 508 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
501 input_report_key(dev, BTN_LEFT, hw.left); 509 input_report_key(dev, BTN_LEFT, hw.left);
502 input_report_key(dev, BTN_RIGHT, hw.right); 510 input_report_key(dev, BTN_RIGHT, hw.right);
@@ -596,7 +604,9 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
596 input_set_abs_params(dev, ABS_Y, 604 input_set_abs_params(dev, ABS_Y,
597 YMIN_NOMINAL, priv->y_max ?: YMAX_NOMINAL, 0, 0); 605 YMIN_NOMINAL, priv->y_max ?: YMAX_NOMINAL, 0, 0);
598 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); 606 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
599 __set_bit(ABS_TOOL_WIDTH, dev->absbit); 607
608 if (SYN_CAP_PALMDETECT(priv->capabilities))
609 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
600 610
601 __set_bit(EV_KEY, dev->evbit); 611 __set_bit(EV_KEY, dev->evbit);
602 __set_bit(BTN_TOUCH, dev->keybit); 612 __set_bit(BTN_TOUCH, dev->keybit);
@@ -625,8 +635,8 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
625 __clear_bit(REL_X, dev->relbit); 635 __clear_bit(REL_X, dev->relbit);
626 __clear_bit(REL_Y, dev->relbit); 636 __clear_bit(REL_Y, dev->relbit);
627 637
628 dev->absres[ABS_X] = priv->x_res; 638 input_abs_set_res(dev, ABS_X, priv->x_res);
629 dev->absres[ABS_Y] = priv->y_res; 639 input_abs_set_res(dev, ABS_Y, priv->y_res);
630 640
631 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { 641 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
632 /* Clickpads report only left button */ 642 /* Clickpads report only left button */
diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
index 7d4d5e12c0df..b6aa7d20d8a3 100644
--- a/drivers/input/mouse/synaptics.h
+++ b/drivers/input/mouse/synaptics.h
@@ -47,7 +47,7 @@
47#define SYN_CAP_FOUR_BUTTON(c) ((c) & (1 << 3)) 47#define SYN_CAP_FOUR_BUTTON(c) ((c) & (1 << 3))
48#define SYN_CAP_MULTIFINGER(c) ((c) & (1 << 1)) 48#define SYN_CAP_MULTIFINGER(c) ((c) & (1 << 1))
49#define SYN_CAP_PALMDETECT(c) ((c) & (1 << 0)) 49#define SYN_CAP_PALMDETECT(c) ((c) & (1 << 0))
50#define SYN_CAP_VALID(c) ((((c) & 0x00ff00) >> 8) == 0x47) 50#define SYN_CAP_SUBMODEL_ID(c) (((c) & 0x00ff00) >> 8)
51#define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20) 51#define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20)
52#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12) 52#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12)
53#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16) 53#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16)
@@ -66,6 +66,7 @@
66#define SYN_ID_MODEL(i) (((i) >> 4) & 0x0f) 66#define SYN_ID_MODEL(i) (((i) >> 4) & 0x0f)
67#define SYN_ID_MAJOR(i) ((i) & 0x0f) 67#define SYN_ID_MAJOR(i) ((i) & 0x0f)
68#define SYN_ID_MINOR(i) (((i) >> 16) & 0xff) 68#define SYN_ID_MINOR(i) (((i) >> 16) & 0xff)
69#define SYN_ID_FULL(i) ((SYN_ID_MAJOR(i) << 8) | SYN_ID_MINOR(i))
69#define SYN_ID_IS_SYNAPTICS(i) ((((i) >> 8) & 0xff) == 0x47) 70#define SYN_ID_IS_SYNAPTICS(i) ((((i) >> 8) & 0xff) == 0x47)
70 71
71/* synaptics special commands */ 72/* synaptics special commands */
diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c
index 8291e7399ffa..0ae62f0bcb32 100644
--- a/drivers/input/mouse/synaptics_i2c.c
+++ b/drivers/input/mouse/synaptics_i2c.c
@@ -613,7 +613,6 @@ static int __devexit synaptics_i2c_remove(struct i2c_client *client)
613 free_irq(client->irq, touch); 613 free_irq(client->irq, touch);
614 614
615 input_unregister_device(touch->input); 615 input_unregister_device(touch->input);
616 i2c_set_clientdata(client, NULL);
617 kfree(touch); 616 kfree(touch);
618 617
619 return 0; 618 return 0;
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index f34b22bce4ff..83c24cca234a 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -22,6 +22,7 @@
22#include <linux/random.h> 22#include <linux/random.h>
23#include <linux/major.h> 23#include <linux/major.h>
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/kernel.h>
25#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 26#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
26#include <linux/miscdevice.h> 27#include <linux/miscdevice.h>
27#endif 28#endif
@@ -57,7 +58,6 @@ struct mousedev_hw_data {
57}; 58};
58 59
59struct mousedev { 60struct mousedev {
60 int exist;
61 int open; 61 int open;
62 int minor; 62 int minor;
63 struct input_handle handle; 63 struct input_handle handle;
@@ -66,6 +66,7 @@ struct mousedev {
66 spinlock_t client_lock; /* protects client_list */ 66 spinlock_t client_lock; /* protects client_list */
67 struct mutex mutex; 67 struct mutex mutex;
68 struct device dev; 68 struct device dev;
69 bool exist;
69 70
70 struct list_head mixdev_node; 71 struct list_head mixdev_node;
71 int mixdev_open; 72 int mixdev_open;
@@ -134,11 +135,14 @@ static void mousedev_touchpad_event(struct input_dev *dev,
134 switch (code) { 135 switch (code) {
135 136
136 case ABS_X: 137 case ABS_X:
138
137 fx(0) = value; 139 fx(0) = value;
138 if (mousedev->touch && mousedev->pkt_count >= 2) { 140 if (mousedev->touch && mousedev->pkt_count >= 2) {
139 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 141 size = input_abs_get_min(dev, ABS_X) -
142 input_abs_get_max(dev, ABS_X);
140 if (size == 0) 143 if (size == 0)
141 size = 256 * 2; 144 size = 256 * 2;
145
142 tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size; 146 tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size;
143 tmp += mousedev->frac_dx; 147 tmp += mousedev->frac_dx;
144 mousedev->packet.dx = tmp / FRACTION_DENOM; 148 mousedev->packet.dx = tmp / FRACTION_DENOM;
@@ -150,10 +154,12 @@ static void mousedev_touchpad_event(struct input_dev *dev,
150 case ABS_Y: 154 case ABS_Y:
151 fy(0) = value; 155 fy(0) = value;
152 if (mousedev->touch && mousedev->pkt_count >= 2) { 156 if (mousedev->touch && mousedev->pkt_count >= 2) {
153 /* use X size to keep the same scale */ 157 /* use X size for ABS_Y to keep the same scale */
154 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 158 size = input_abs_get_min(dev, ABS_X) -
159 input_abs_get_max(dev, ABS_X);
155 if (size == 0) 160 if (size == 0)
156 size = 256 * 2; 161 size = 256 * 2;
162
157 tmp = -((value - fy(2)) * 256 * FRACTION_DENOM) / size; 163 tmp = -((value - fy(2)) * 256 * FRACTION_DENOM) / size;
158 tmp += mousedev->frac_dy; 164 tmp += mousedev->frac_dy;
159 mousedev->packet.dy = tmp / FRACTION_DENOM; 165 mousedev->packet.dy = tmp / FRACTION_DENOM;
@@ -167,33 +173,35 @@ static void mousedev_touchpad_event(struct input_dev *dev,
167static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, 173static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev,
168 unsigned int code, int value) 174 unsigned int code, int value)
169{ 175{
170 int size; 176 int min, max, size;
171 177
172 switch (code) { 178 switch (code) {
173 179
174 case ABS_X: 180 case ABS_X:
175 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 181 min = input_abs_get_min(dev, ABS_X);
182 max = input_abs_get_max(dev, ABS_X);
183
184 size = max - min;
176 if (size == 0) 185 if (size == 0)
177 size = xres ? : 1; 186 size = xres ? : 1;
178 if (value > dev->absmax[ABS_X]) 187
179 value = dev->absmax[ABS_X]; 188 clamp(value, min, max);
180 if (value < dev->absmin[ABS_X]) 189
181 value = dev->absmin[ABS_X]; 190 mousedev->packet.x = ((value - min) * xres) / size;
182 mousedev->packet.x =
183 ((value - dev->absmin[ABS_X]) * xres) / size;
184 mousedev->packet.abs_event = 1; 191 mousedev->packet.abs_event = 1;
185 break; 192 break;
186 193
187 case ABS_Y: 194 case ABS_Y:
188 size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y]; 195 min = input_abs_get_min(dev, ABS_Y);
196 max = input_abs_get_max(dev, ABS_Y);
197
198 size = max - min;
189 if (size == 0) 199 if (size == 0)
190 size = yres ? : 1; 200 size = yres ? : 1;
191 if (value > dev->absmax[ABS_Y]) 201
192 value = dev->absmax[ABS_Y]; 202 clamp(value, min, max);
193 if (value < dev->absmin[ABS_Y]) 203
194 value = dev->absmin[ABS_Y]; 204 mousedev->packet.y = yres - ((value - min) * yres) / size;
195 mousedev->packet.y = yres -
196 ((value - dev->absmin[ABS_Y]) * yres) / size;
197 mousedev->packet.abs_event = 1; 205 mousedev->packet.abs_event = 1;
198 break; 206 break;
199 } 207 }
@@ -765,10 +773,15 @@ static unsigned int mousedev_poll(struct file *file, poll_table *wait)
765{ 773{
766 struct mousedev_client *client = file->private_data; 774 struct mousedev_client *client = file->private_data;
767 struct mousedev *mousedev = client->mousedev; 775 struct mousedev *mousedev = client->mousedev;
776 unsigned int mask;
768 777
769 poll_wait(file, &mousedev->wait, wait); 778 poll_wait(file, &mousedev->wait, wait);
770 return ((client->ready || client->buffer) ? (POLLIN | POLLRDNORM) : 0) | 779
771 (mousedev->exist ? 0 : (POLLHUP | POLLERR)); 780 mask = mousedev->exist ? POLLOUT | POLLWRNORM : POLLHUP | POLLERR;
781 if (client->ready || client->buffer)
782 mask |= POLLIN | POLLRDNORM;
783
784 return mask;
772} 785}
773 786
774static const struct file_operations mousedev_fops = { 787static const struct file_operations mousedev_fops = {
@@ -802,7 +815,7 @@ static void mousedev_remove_chrdev(struct mousedev *mousedev)
802static void mousedev_mark_dead(struct mousedev *mousedev) 815static void mousedev_mark_dead(struct mousedev *mousedev)
803{ 816{
804 mutex_lock(&mousedev->mutex); 817 mutex_lock(&mousedev->mutex);
805 mousedev->exist = 0; 818 mousedev->exist = false;
806 mutex_unlock(&mousedev->mutex); 819 mutex_unlock(&mousedev->mutex);
807} 820}
808 821
@@ -862,7 +875,7 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
862 dev_set_name(&mousedev->dev, "mouse%d", minor); 875 dev_set_name(&mousedev->dev, "mouse%d", minor);
863 876
864 mousedev->minor = minor; 877 mousedev->minor = minor;
865 mousedev->exist = 1; 878 mousedev->exist = true;
866 mousedev->handle.dev = input_get_device(dev); 879 mousedev->handle.dev = input_get_device(dev);
867 mousedev->handle.name = dev_name(&mousedev->dev); 880 mousedev->handle.name = dev_name(&mousedev->dev);
868 mousedev->handle.handler = handler; 881 mousedev->handle.handler = handler;
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index f34f1dbeb577..3bfe8fafc6ad 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -21,7 +21,8 @@ if SERIO
21config SERIO_I8042 21config SERIO_I8042
22 tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86 22 tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86
23 default y 23 default y
24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && !M68K && !BLACKFIN 24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && \
25 (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN
25 help 26 help
26 i8042 is the chip over which the standard AT keyboard and PS/2 27 i8042 is the chip over which the standard AT keyboard and PS/2
27 mouse are connected to the computer. If you use these devices, 28 mouse are connected to the computer. If you use these devices,
diff --git a/drivers/input/serio/i8042-io.h b/drivers/input/serio/i8042-io.h
index 847f4aad7ed5..5d48bb66aa73 100644
--- a/drivers/input/serio/i8042-io.h
+++ b/drivers/input/serio/i8042-io.h
@@ -27,6 +27,11 @@
27#include <asm/irq.h> 27#include <asm/irq.h>
28#elif defined(CONFIG_SH_CAYMAN) 28#elif defined(CONFIG_SH_CAYMAN)
29#include <asm/irq.h> 29#include <asm/irq.h>
30#elif defined(CONFIG_PPC)
31extern int of_i8042_kbd_irq;
32extern int of_i8042_aux_irq;
33# define I8042_KBD_IRQ of_i8042_kbd_irq
34# define I8042_AUX_IRQ of_i8042_aux_irq
30#else 35#else
31# define I8042_KBD_IRQ 1 36# define I8042_KBD_IRQ 1
32# define I8042_AUX_IRQ 12 37# define I8042_AUX_IRQ 12
diff --git a/drivers/input/serio/i8042-ppcio.h b/drivers/input/serio/i8042-ppcio.h
index 2906e1b60c04..f708c75d16f1 100644
--- a/drivers/input/serio/i8042-ppcio.h
+++ b/drivers/input/serio/i8042-ppcio.h
@@ -52,81 +52,6 @@ static inline void i8042_platform_exit(void)
52{ 52{
53} 53}
54 54
55#elif defined(CONFIG_SPRUCE)
56
57#define I8042_KBD_IRQ 22
58#define I8042_AUX_IRQ 21
59
60#define I8042_KBD_PHYS_DESC "spruceps2/serio0"
61#define I8042_AUX_PHYS_DESC "spruceps2/serio1"
62#define I8042_MUX_PHYS_DESC "spruceps2/serio%d"
63
64#define I8042_COMMAND_REG 0xff810000
65#define I8042_DATA_REG 0xff810001
66
67static inline int i8042_read_data(void)
68{
69 unsigned long kbd_data;
70
71 __raw_writel(0x00000088, 0xff500008);
72 eieio();
73
74 __raw_writel(0x03000000, 0xff50000c);
75 eieio();
76
77 asm volatile("lis 7,0xff88 \n\
78 lswi 6,7,0x8 \n\
79 mr %0,6"
80 : "=r" (kbd_data) :: "6", "7");
81
82 __raw_writel(0x00000000, 0xff50000c);
83 eieio();
84
85 return (unsigned char)(kbd_data >> 24);
86}
87
88static inline int i8042_read_status(void)
89{
90 unsigned long kbd_status;
91
92 __raw_writel(0x00000088, 0xff500008);
93 eieio();
94
95 __raw_writel(0x03000000, 0xff50000c);
96 eieio();
97
98 asm volatile("lis 7,0xff88 \n\
99 ori 7,7,0x8 \n\
100 lswi 6,7,0x8 \n\
101 mr %0,6"
102 : "=r" (kbd_status) :: "6", "7");
103
104 __raw_writel(0x00000000, 0xff50000c);
105 eieio();
106
107 return (unsigned char)(kbd_status >> 24);
108}
109
110static inline void i8042_write_data(int val)
111{
112 *((unsigned char *)0xff810000) = (char)val;
113}
114
115static inline void i8042_write_command(int val)
116{
117 *((unsigned char *)0xff810001) = (char)val;
118}
119
120static inline int i8042_platform_init(void)
121{
122 i8042_reset = 1;
123 return 0;
124}
125
126static inline void i8042_platform_exit(void)
127{
128}
129
130#else 55#else
131 56
132#include "i8042-io.h" 57#include "i8042-io.h"
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 04e32f2d1241..c5cc4508d6df 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -49,7 +49,7 @@ static inline void i8042_write_command(int val)
49#define OBP_PS2MS_NAME1 "kdmouse" 49#define OBP_PS2MS_NAME1 "kdmouse"
50#define OBP_PS2MS_NAME2 "mouse" 50#define OBP_PS2MS_NAME2 "mouse"
51 51
52static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_device_id *match) 52static int __devinit sparc_i8042_probe(struct platform_device *op, const struct of_device_id *match)
53{ 53{
54 struct device_node *dp = op->dev.of_node; 54 struct device_node *dp = op->dev.of_node;
55 55
@@ -57,20 +57,20 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
57 while (dp) { 57 while (dp) {
58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || 58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) { 59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
60 struct of_device *kbd = of_find_device_by_node(dp); 60 struct platform_device *kbd = of_find_device_by_node(dp);
61 unsigned int irq = kbd->irqs[0]; 61 unsigned int irq = kbd->archdata.irqs[0];
62 if (irq == 0xffffffff) 62 if (irq == 0xffffffff)
63 irq = op->irqs[0]; 63 irq = op->archdata.irqs[0];
64 i8042_kbd_irq = irq; 64 i8042_kbd_irq = irq;
65 kbd_iobase = of_ioremap(&kbd->resource[0], 65 kbd_iobase = of_ioremap(&kbd->resource[0],
66 0, 8, "kbd"); 66 0, 8, "kbd");
67 kbd_res = &kbd->resource[0]; 67 kbd_res = &kbd->resource[0];
68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || 68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
69 !strcmp(dp->name, OBP_PS2MS_NAME2)) { 69 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
70 struct of_device *ms = of_find_device_by_node(dp); 70 struct platform_device *ms = of_find_device_by_node(dp);
71 unsigned int irq = ms->irqs[0]; 71 unsigned int irq = ms->archdata.irqs[0];
72 if (irq == 0xffffffff) 72 if (irq == 0xffffffff)
73 irq = op->irqs[0]; 73 irq = op->archdata.irqs[0];
74 i8042_aux_irq = irq; 74 i8042_aux_irq = irq;
75 } 75 }
76 76
@@ -80,7 +80,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
80 return 0; 80 return 0;
81} 81}
82 82
83static int __devexit sparc_i8042_remove(struct of_device *op) 83static int __devexit sparc_i8042_remove(struct platform_device *op)
84{ 84{
85 of_iounmap(kbd_res, kbd_iobase, 8); 85 of_iounmap(kbd_res, kbd_iobase, 8);
86 86
@@ -116,8 +116,7 @@ static int __init i8042_platform_init(void)
116 if (!kbd_iobase) 116 if (!kbd_iobase)
117 return -ENODEV; 117 return -ENODEV;
118 } else { 118 } else {
119 int err = of_register_driver(&sparc_i8042_driver, 119 int err = of_register_platform_driver(&sparc_i8042_driver);
120 &of_bus_type);
121 if (err) 120 if (err)
122 return err; 121 return err;
123 122
@@ -141,7 +140,7 @@ static inline void i8042_platform_exit(void)
141 struct device_node *root = of_find_node_by_path("/"); 140 struct device_node *root = of_find_node_by_path("/");
142 141
143 if (strcmp(root->name, "SUNW,JavaStation-1")) 142 if (strcmp(root->name, "SUNW,JavaStation-1"))
144 of_unregister_driver(&sparc_i8042_driver); 143 of_unregister_platform_driver(&sparc_i8042_driver);
145} 144}
146 145
147#else /* !CONFIG_PCI */ 146#else /* !CONFIG_PCI */
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 6168469ad1a6..ed7ad7416b24 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -7,6 +7,10 @@
7 * the Free Software Foundation. 7 * the Free Software Foundation.
8 */ 8 */
9 9
10#ifdef CONFIG_X86
11#include <asm/x86_init.h>
12#endif
13
10/* 14/*
11 * Names. 15 * Names.
12 */ 16 */
@@ -166,6 +170,13 @@ static const struct dmi_system_id __initconst i8042_dmi_noloop_table[] = {
166 }, 170 },
167 }, 171 },
168 { 172 {
173 /* Gigabyte Spring Peak - defines wrong chassis type */
174 .matches = {
175 DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
176 DMI_MATCH(DMI_PRODUCT_NAME, "Spring Peak"),
177 },
178 },
179 {
169 .matches = { 180 .matches = {
170 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 181 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
171 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv9700"), 182 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv9700"),
@@ -840,6 +851,12 @@ static int __init i8042_platform_init(void)
840{ 851{
841 int retval; 852 int retval;
842 853
854#ifdef CONFIG_X86
855 /* Just return if pre-detection shows no i8042 controller exist */
856 if (!x86_platform.i8042_detect())
857 return -ENODEV;
858#endif
859
843/* 860/*
844 * On ix86 platforms touching the i8042 data register region can do really 861 * On ix86 platforms touching the i8042 data register region can do really
845 * bad things. Because of this the region is always reserved on ix86 boxes. 862 * bad things. Because of this the region is always reserved on ix86 boxes.
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 6440a8f55686..46e4ba0b9246 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -61,10 +61,6 @@ static bool i8042_noloop;
61module_param_named(noloop, i8042_noloop, bool, 0); 61module_param_named(noloop, i8042_noloop, bool, 0);
62MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port"); 62MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port");
63 63
64static unsigned int i8042_blink_frequency = 500;
65module_param_named(panicblink, i8042_blink_frequency, uint, 0600);
66MODULE_PARM_DESC(panicblink, "Frequency with which keyboard LEDs should blink when kernel panics");
67
68#ifdef CONFIG_X86 64#ifdef CONFIG_X86
69static bool i8042_dritek; 65static bool i8042_dritek;
70module_param_named(dritek, i8042_dritek, bool, 0); 66module_param_named(dritek, i8042_dritek, bool, 0);
@@ -861,9 +857,6 @@ static int i8042_controller_selftest(void)
861 unsigned char param; 857 unsigned char param;
862 int i = 0; 858 int i = 0;
863 859
864 if (!i8042_reset)
865 return 0;
866
867 /* 860 /*
868 * We try this 5 times; on some really fragile systems this does not 861 * We try this 5 times; on some really fragile systems this does not
869 * take the first time... 862 * take the first time...
@@ -1020,7 +1013,8 @@ static void i8042_controller_reset(void)
1020 * Reset the controller if requested. 1013 * Reset the controller if requested.
1021 */ 1014 */
1022 1015
1023 i8042_controller_selftest(); 1016 if (i8042_reset)
1017 i8042_controller_selftest();
1024 1018
1025/* 1019/*
1026 * Restore the original control register setting. 1020 * Restore the original control register setting.
@@ -1032,8 +1026,8 @@ static void i8042_controller_reset(void)
1032 1026
1033 1027
1034/* 1028/*
1035 * i8042_panic_blink() will flash the keyboard LEDs and is called when 1029 * i8042_panic_blink() will turn the keyboard LEDs on or off and is called
1036 * kernel panics. Flashing LEDs is useful for users running X who may 1030 * when kernel panics. Flashing LEDs is useful for users running X who may
1037 * not see the console and will help distingushing panics from "real" 1031 * not see the console and will help distingushing panics from "real"
1038 * lockups. 1032 * lockups.
1039 * 1033 *
@@ -1043,22 +1037,12 @@ static void i8042_controller_reset(void)
1043 1037
1044#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0) 1038#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0)
1045 1039
1046static long i8042_panic_blink(long count) 1040static long i8042_panic_blink(int state)
1047{ 1041{
1048 long delay = 0; 1042 long delay = 0;
1049 static long last_blink; 1043 char led;
1050 static char led;
1051 1044
1052 /* 1045 led = (state) ? 0x01 | 0x04 : 0;
1053 * We expect frequency to be about 1/2s. KDB uses about 1s.
1054 * Make sure they are different.
1055 */
1056 if (!i8042_blink_frequency)
1057 return 0;
1058 if (count - last_blink < i8042_blink_frequency)
1059 return 0;
1060
1061 led ^= 0x01 | 0x04;
1062 while (i8042_read_status() & I8042_STR_IBF) 1046 while (i8042_read_status() & I8042_STR_IBF)
1063 DELAY; 1047 DELAY;
1064 dbg("%02x -> i8042 (panic blink)", 0xed); 1048 dbg("%02x -> i8042 (panic blink)", 0xed);
@@ -1071,7 +1055,6 @@ static long i8042_panic_blink(long count)
1071 dbg("%02x -> i8042 (panic blink)", led); 1055 dbg("%02x -> i8042 (panic blink)", led);
1072 i8042_write_data(led); 1056 i8042_write_data(led);
1073 DELAY; 1057 DELAY;
1074 last_blink = count;
1075 return delay; 1058 return delay;
1076} 1059}
1077 1060
@@ -1094,23 +1077,11 @@ static void i8042_dritek_enable(void)
1094#ifdef CONFIG_PM 1077#ifdef CONFIG_PM
1095 1078
1096/* 1079/*
1097 * Here we try to restore the original BIOS settings to avoid
1098 * upsetting it.
1099 */
1100
1101static int i8042_pm_reset(struct device *dev)
1102{
1103 i8042_controller_reset();
1104
1105 return 0;
1106}
1107
1108/*
1109 * Here we try to reset everything back to a state we had 1080 * Here we try to reset everything back to a state we had
1110 * before suspending. 1081 * before suspending.
1111 */ 1082 */
1112 1083
1113static int i8042_pm_restore(struct device *dev) 1084static int i8042_controller_resume(bool force_reset)
1114{ 1085{
1115 int error; 1086 int error;
1116 1087
@@ -1118,9 +1089,11 @@ static int i8042_pm_restore(struct device *dev)
1118 if (error) 1089 if (error)
1119 return error; 1090 return error;
1120 1091
1121 error = i8042_controller_selftest(); 1092 if (i8042_reset || force_reset) {
1122 if (error) 1093 error = i8042_controller_selftest();
1123 return error; 1094 if (error)
1095 return error;
1096 }
1124 1097
1125/* 1098/*
1126 * Restore original CTR value and disable all ports 1099 * Restore original CTR value and disable all ports
@@ -1162,6 +1135,28 @@ static int i8042_pm_restore(struct device *dev)
1162 return 0; 1135 return 0;
1163} 1136}
1164 1137
1138/*
1139 * Here we try to restore the original BIOS settings to avoid
1140 * upsetting it.
1141 */
1142
1143static int i8042_pm_reset(struct device *dev)
1144{
1145 i8042_controller_reset();
1146
1147 return 0;
1148}
1149
1150static int i8042_pm_resume(struct device *dev)
1151{
1152 /*
1153 * On resume from S2R we always try to reset the controller
1154 * to bring it in a sane state. (In case of S2D we expect
1155 * BIOS to reset the controller for us.)
1156 */
1157 return i8042_controller_resume(true);
1158}
1159
1165static int i8042_pm_thaw(struct device *dev) 1160static int i8042_pm_thaw(struct device *dev)
1166{ 1161{
1167 i8042_interrupt(0, NULL); 1162 i8042_interrupt(0, NULL);
@@ -1169,9 +1164,14 @@ static int i8042_pm_thaw(struct device *dev)
1169 return 0; 1164 return 0;
1170} 1165}
1171 1166
1167static int i8042_pm_restore(struct device *dev)
1168{
1169 return i8042_controller_resume(false);
1170}
1171
1172static const struct dev_pm_ops i8042_pm_ops = { 1172static const struct dev_pm_ops i8042_pm_ops = {
1173 .suspend = i8042_pm_reset, 1173 .suspend = i8042_pm_reset,
1174 .resume = i8042_pm_restore, 1174 .resume = i8042_pm_resume,
1175 .thaw = i8042_pm_thaw, 1175 .thaw = i8042_pm_thaw,
1176 .poweroff = i8042_pm_reset, 1176 .poweroff = i8042_pm_reset,
1177 .restore = i8042_pm_restore, 1177 .restore = i8042_pm_restore,
@@ -1389,9 +1389,11 @@ static int __init i8042_probe(struct platform_device *dev)
1389 1389
1390 i8042_platform_device = dev; 1390 i8042_platform_device = dev;
1391 1391
1392 error = i8042_controller_selftest(); 1392 if (i8042_reset) {
1393 if (error) 1393 error = i8042_controller_selftest();
1394 return error; 1394 if (error)
1395 return error;
1396 }
1395 1397
1396 error = i8042_controller_init(); 1398 error = i8042_controller_init();
1397 if (error) 1399 if (error)
diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
index e2c028d2638f..bb14449fb022 100644
--- a/drivers/input/serio/xilinx_ps2.c
+++ b/drivers/input/serio/xilinx_ps2.c
@@ -232,7 +232,7 @@ static void sxps2_close(struct serio *pserio)
232 * It returns 0, if the driver is bound to the PS/2 device, or a negative 232 * It returns 0, if the driver is bound to the PS/2 device, or a negative
233 * value if there is an error. 233 * value if there is an error.
234 */ 234 */
235static int __devinit xps2_of_probe(struct of_device *ofdev, 235static int __devinit xps2_of_probe(struct platform_device *ofdev,
236 const struct of_device_id *match) 236 const struct of_device_id *match)
237{ 237{
238 struct resource r_irq; /* Interrupt resources */ 238 struct resource r_irq; /* Interrupt resources */
@@ -332,7 +332,7 @@ failed1:
332 * if the driver module is being unloaded. It frees any resources allocated to 332 * if the driver module is being unloaded. It frees any resources allocated to
333 * the device. 333 * the device.
334 */ 334 */
335static int __devexit xps2_of_remove(struct of_device *of_dev) 335static int __devexit xps2_of_remove(struct platform_device *of_dev)
336{ 336{
337 struct device *dev = &of_dev->dev; 337 struct device *dev = &of_dev->dev;
338 struct xps2data *drvdata = dev_get_drvdata(dev); 338 struct xps2data *drvdata = dev_get_drvdata(dev);
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 51b80b08d467..57b25b84d1fc 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -987,20 +987,17 @@ static int aiptek_program_tablet(struct aiptek *aiptek)
987 /* Query getXextension */ 987 /* Query getXextension */
988 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0) 988 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
989 return ret; 989 return ret;
990 aiptek->inputdev->absmin[ABS_X] = 0; 990 input_set_abs_params(aiptek->inputdev, ABS_X, 0, ret - 1, 0, 0);
991 aiptek->inputdev->absmax[ABS_X] = ret - 1;
992 991
993 /* Query getYextension */ 992 /* Query getYextension */
994 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0) 993 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
995 return ret; 994 return ret;
996 aiptek->inputdev->absmin[ABS_Y] = 0; 995 input_set_abs_params(aiptek->inputdev, ABS_Y, 0, ret - 1, 0, 0);
997 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
998 996
999 /* Query getPressureLevels */ 997 /* Query getPressureLevels */
1000 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0) 998 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
1001 return ret; 999 return ret;
1002 aiptek->inputdev->absmin[ABS_PRESSURE] = 0; 1000 input_set_abs_params(aiptek->inputdev, ABS_PRESSURE, 0, ret - 1, 0, 0);
1003 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
1004 1001
1005 /* Depending on whether we are in absolute or relative mode, we will 1002 /* Depending on whether we are in absolute or relative mode, we will
1006 * do a switchToTablet(absolute) or switchToMouse(relative) command. 1003 * do a switchToTablet(absolute) or switchToMouse(relative) command.
@@ -1054,8 +1051,8 @@ static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr
1054 struct aiptek *aiptek = dev_get_drvdata(dev); 1051 struct aiptek *aiptek = dev_get_drvdata(dev);
1055 1052
1056 return snprintf(buf, PAGE_SIZE, "%dx%d\n", 1053 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
1057 aiptek->inputdev->absmax[ABS_X] + 1, 1054 input_abs_get_max(aiptek->inputdev, ABS_X) + 1,
1058 aiptek->inputdev->absmax[ABS_Y] + 1); 1055 input_abs_get_max(aiptek->inputdev, ABS_Y) + 1);
1059} 1056}
1060 1057
1061/* These structs define the sysfs files, param #1 is the name of the 1058/* These structs define the sysfs files, param #1 is the name of the
@@ -1843,7 +1840,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1843 for (i = 0; i < ARRAY_SIZE(speeds); ++i) { 1840 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
1844 aiptek->curSetting.programmableDelay = speeds[i]; 1841 aiptek->curSetting.programmableDelay = speeds[i];
1845 (void)aiptek_program_tablet(aiptek); 1842 (void)aiptek_program_tablet(aiptek);
1846 if (aiptek->inputdev->absmax[ABS_X] > 0) { 1843 if (input_abs_get_max(aiptek->inputdev, ABS_X) > 0) {
1847 dev_info(&intf->dev, 1844 dev_info(&intf->dev,
1848 "Aiptek using %d ms programming speed\n", 1845 "Aiptek using %d ms programming speed\n",
1849 aiptek->curSetting.programmableDelay); 1846 aiptek->curSetting.programmableDelay);
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 2dc0c07c0469..42ba3691d908 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -508,7 +508,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
508 } 508 }
509 509
510 input_dev->name = wacom_wac->name; 510 input_dev->name = wacom_wac->name;
511 input_dev->name = wacom_wac->name;
512 input_dev->dev.parent = &intf->dev; 511 input_dev->dev.parent = &intf->dev;
513 input_dev->open = wacom_open; 512 input_dev->open = wacom_open;
514 input_dev->close = wacom_close; 513 input_dev->close = wacom_close;
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 847fd0135bcf..40d77ba8fdc1 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -158,6 +158,39 @@ static int wacom_ptu_irq(struct wacom_wac *wacom)
158 return 1; 158 return 1;
159} 159}
160 160
161static int wacom_dtu_irq(struct wacom_wac *wacom)
162{
163 struct wacom_features *features = &wacom->features;
164 char *data = wacom->data;
165 struct input_dev *input = wacom->input;
166 int prox = data[1] & 0x20, pressure;
167
168 dbg("wacom_dtu_irq: received report #%d", data[0]);
169
170 if (prox) {
171 /* Going into proximity select tool */
172 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
173 if (wacom->tool[0] == BTN_TOOL_PEN)
174 wacom->id[0] = STYLUS_DEVICE_ID;
175 else
176 wacom->id[0] = ERASER_DEVICE_ID;
177 }
178 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
179 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
180 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
181 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
182 pressure = ((data[7] & 0x01) << 8) | data[6];
183 if (pressure < 0)
184 pressure = features->pressure_max + pressure + 1;
185 input_report_abs(input, ABS_PRESSURE, pressure);
186 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
187 if (!prox) /* out-prox */
188 wacom->id[0] = 0;
189 input_report_key(input, wacom->tool[0], prox);
190 input_report_abs(input, ABS_MISC, wacom->id[0]);
191 return 1;
192}
193
161static int wacom_graphire_irq(struct wacom_wac *wacom) 194static int wacom_graphire_irq(struct wacom_wac *wacom)
162{ 195{
163 struct wacom_features *features = &wacom->features; 196 struct wacom_features *features = &wacom->features;
@@ -284,12 +317,13 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
284 (data[4] << 20) + (data[5] << 12) + 317 (data[4] << 20) + (data[5] << 12) +
285 (data[6] << 4) + (data[7] >> 4); 318 (data[6] << 4) + (data[7] >> 4);
286 319
287 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4); 320 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
321 ((data[7] & 0x0f) << 20) | ((data[8] & 0xf0) << 12);
288 322
289 switch (wacom->id[idx]) { 323 switch (wacom->id[idx] & 0xfffff) {
290 case 0x812: /* Inking pen */ 324 case 0x812: /* Inking pen */
291 case 0x801: /* Intuos3 Inking pen */ 325 case 0x801: /* Intuos3 Inking pen */
292 case 0x20802: /* Intuos4 Classic Pen */ 326 case 0x20802: /* Intuos4 Inking Pen */
293 case 0x012: 327 case 0x012:
294 wacom->tool[idx] = BTN_TOOL_PENCIL; 328 wacom->tool[idx] = BTN_TOOL_PENCIL;
295 break; 329 break;
@@ -300,7 +334,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
300 case 0x823: /* Intuos3 Grip Pen */ 334 case 0x823: /* Intuos3 Grip Pen */
301 case 0x813: /* Intuos3 Classic Pen */ 335 case 0x813: /* Intuos3 Classic Pen */
302 case 0x885: /* Intuos3 Marker Pen */ 336 case 0x885: /* Intuos3 Marker Pen */
303 case 0x802: /* Intuos4 Grip Pen Eraser */ 337 case 0x802: /* Intuos4 General Pen */
304 case 0x804: /* Intuos4 Marker Pen */ 338 case 0x804: /* Intuos4 Marker Pen */
305 case 0x40802: /* Intuos4 Classic Pen */ 339 case 0x40802: /* Intuos4 Classic Pen */
306 case 0x022: 340 case 0x022:
@@ -335,7 +369,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
335 case 0x81b: /* Intuos3 Classic Pen Eraser */ 369 case 0x81b: /* Intuos3 Classic Pen Eraser */
336 case 0x91b: /* Intuos3 Airbrush Eraser */ 370 case 0x91b: /* Intuos3 Airbrush Eraser */
337 case 0x80c: /* Intuos4 Marker Pen Eraser */ 371 case 0x80c: /* Intuos4 Marker Pen Eraser */
338 case 0x80a: /* Intuos4 Grip Pen Eraser */ 372 case 0x80a: /* Intuos4 General Pen Eraser */
339 case 0x4080a: /* Intuos4 Classic Pen Eraser */ 373 case 0x4080a: /* Intuos4 Classic Pen Eraser */
340 case 0x90a: /* Intuos4 Airbrush Eraser */ 374 case 0x90a: /* Intuos4 Airbrush Eraser */
341 wacom->tool[idx] = BTN_TOOL_RUBBER; 375 wacom->tool[idx] = BTN_TOOL_RUBBER;
@@ -356,6 +390,11 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
356 return 1; 390 return 1;
357 } 391 }
358 392
393 /* older I4 styli don't work with new Cintiqs */
394 if (!((wacom->id[idx] >> 20) & 0x01) &&
395 (features->type == WACOM_21UX2))
396 return 1;
397
359 /* Exit report */ 398 /* Exit report */
360 if ((data[1] & 0xfe) == 0x80) { 399 if ((data[1] & 0xfe) == 0x80) {
361 /* 400 /*
@@ -474,21 +513,43 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
474 input_report_abs(input, ABS_MISC, 0); 513 input_report_abs(input, ABS_MISC, 0);
475 } 514 }
476 } else { 515 } else {
477 input_report_key(input, BTN_0, (data[5] & 0x01)); 516 if (features->type == WACOM_21UX2) {
478 input_report_key(input, BTN_1, (data[5] & 0x02)); 517 input_report_key(input, BTN_0, (data[5] & 0x01));
479 input_report_key(input, BTN_2, (data[5] & 0x04)); 518 input_report_key(input, BTN_1, (data[6] & 0x01));
480 input_report_key(input, BTN_3, (data[5] & 0x08)); 519 input_report_key(input, BTN_2, (data[6] & 0x02));
481 input_report_key(input, BTN_4, (data[6] & 0x01)); 520 input_report_key(input, BTN_3, (data[6] & 0x04));
482 input_report_key(input, BTN_5, (data[6] & 0x02)); 521 input_report_key(input, BTN_4, (data[6] & 0x08));
483 input_report_key(input, BTN_6, (data[6] & 0x04)); 522 input_report_key(input, BTN_5, (data[6] & 0x10));
484 input_report_key(input, BTN_7, (data[6] & 0x08)); 523 input_report_key(input, BTN_6, (data[6] & 0x20));
485 input_report_key(input, BTN_8, (data[5] & 0x10)); 524 input_report_key(input, BTN_7, (data[6] & 0x40));
486 input_report_key(input, BTN_9, (data[6] & 0x10)); 525 input_report_key(input, BTN_8, (data[6] & 0x80));
526 input_report_key(input, BTN_9, (data[7] & 0x01));
527 input_report_key(input, BTN_A, (data[8] & 0x01));
528 input_report_key(input, BTN_B, (data[8] & 0x02));
529 input_report_key(input, BTN_C, (data[8] & 0x04));
530 input_report_key(input, BTN_X, (data[8] & 0x08));
531 input_report_key(input, BTN_Y, (data[8] & 0x10));
532 input_report_key(input, BTN_Z, (data[8] & 0x20));
533 input_report_key(input, BTN_BASE, (data[8] & 0x40));
534 input_report_key(input, BTN_BASE2, (data[8] & 0x80));
535 } else {
536 input_report_key(input, BTN_0, (data[5] & 0x01));
537 input_report_key(input, BTN_1, (data[5] & 0x02));
538 input_report_key(input, BTN_2, (data[5] & 0x04));
539 input_report_key(input, BTN_3, (data[5] & 0x08));
540 input_report_key(input, BTN_4, (data[6] & 0x01));
541 input_report_key(input, BTN_5, (data[6] & 0x02));
542 input_report_key(input, BTN_6, (data[6] & 0x04));
543 input_report_key(input, BTN_7, (data[6] & 0x08));
544 input_report_key(input, BTN_8, (data[5] & 0x10));
545 input_report_key(input, BTN_9, (data[6] & 0x10));
546 }
487 input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); 547 input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
488 input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); 548 input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
489 549
490 if ((data[5] & 0x1f) | (data[6] & 0x1f) | (data[1] & 0x1f) | 550 if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
491 data[2] | (data[3] & 0x1f) | data[4]) { 551 data[2] | (data[3] & 0x1f) | data[4] | data[8] |
552 (data[7] & 0x01)) {
492 input_report_key(input, wacom->tool[1], 1); 553 input_report_key(input, wacom->tool[1], 1);
493 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); 554 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
494 } else { 555 } else {
@@ -626,10 +687,10 @@ static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx)
626 * protocol. 687 * protocol.
627 */ 688 */
628 if (wacom->last_finger != finger) { 689 if (wacom->last_finger != finger) {
629 if (x == input->abs[ABS_X]) 690 if (x == input_abs_get_val(input, ABS_X))
630 x++; 691 x++;
631 692
632 if (y == input->abs[ABS_Y]) 693 if (y == input_abs_get_val(input, ABS_Y))
633 y++; 694 y++;
634 } 695 }
635 696
@@ -640,7 +701,7 @@ static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx)
640 if (!idx) 701 if (!idx)
641 input_report_key(input, BTN_TOUCH, 1); 702 input_report_key(input, BTN_TOUCH, 1);
642 input_event(input, EV_MSC, MSC_SERIAL, finger); 703 input_event(input, EV_MSC, MSC_SERIAL, finger);
643 input_sync(wacom->input); 704 input_sync(input);
644 705
645 wacom->last_finger = finger; 706 wacom->last_finger = finger;
646} 707}
@@ -817,6 +878,10 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
817 sync = wacom_ptu_irq(wacom_wac); 878 sync = wacom_ptu_irq(wacom_wac);
818 break; 879 break;
819 880
881 case DTU:
882 sync = wacom_dtu_irq(wacom_wac);
883 break;
884
820 case INTUOS: 885 case INTUOS:
821 case INTUOS3S: 886 case INTUOS3S:
822 case INTUOS3: 887 case INTUOS3:
@@ -826,6 +891,7 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
826 case INTUOS4L: 891 case INTUOS4L:
827 case CINTIQ: 892 case CINTIQ:
828 case WACOM_BEE: 893 case WACOM_BEE:
894 case WACOM_21UX2:
829 sync = wacom_intuos_irq(wacom_wac); 895 sync = wacom_intuos_irq(wacom_wac);
830 break; 896 break;
831 897
@@ -921,6 +987,17 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev,
921 __set_bit(BTN_STYLUS2, input_dev->keybit); 987 __set_bit(BTN_STYLUS2, input_dev->keybit);
922 break; 988 break;
923 989
990 case WACOM_21UX2:
991 __set_bit(BTN_A, input_dev->keybit);
992 __set_bit(BTN_B, input_dev->keybit);
993 __set_bit(BTN_C, input_dev->keybit);
994 __set_bit(BTN_X, input_dev->keybit);
995 __set_bit(BTN_Y, input_dev->keybit);
996 __set_bit(BTN_Z, input_dev->keybit);
997 __set_bit(BTN_BASE, input_dev->keybit);
998 __set_bit(BTN_BASE2, input_dev->keybit);
999 /* fall through */
1000
924 case WACOM_BEE: 1001 case WACOM_BEE:
925 __set_bit(BTN_8, input_dev->keybit); 1002 __set_bit(BTN_8, input_dev->keybit);
926 __set_bit(BTN_9, input_dev->keybit); 1003 __set_bit(BTN_9, input_dev->keybit);
@@ -990,6 +1067,7 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev,
990 1067
991 case PL: 1068 case PL:
992 case PTU: 1069 case PTU:
1070 case DTU:
993 __set_bit(BTN_TOOL_PEN, input_dev->keybit); 1071 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
994 __set_bit(BTN_STYLUS, input_dev->keybit); 1072 __set_bit(BTN_STYLUS, input_dev->keybit);
995 __set_bit(BTN_STYLUS2, input_dev->keybit); 1073 __set_bit(BTN_STYLUS2, input_dev->keybit);
@@ -1105,6 +1183,8 @@ static const struct wacom_features wacom_features_0xBA =
1105 { "Wacom Intuos4 8x13", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047, 63, INTUOS4L }; 1183 { "Wacom Intuos4 8x13", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047, 63, INTUOS4L };
1106static const struct wacom_features wacom_features_0xBB = 1184static const struct wacom_features wacom_features_0xBB =
1107 { "Wacom Intuos4 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 2047, 63, INTUOS4L }; 1185 { "Wacom Intuos4 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 2047, 63, INTUOS4L };
1186static const struct wacom_features wacom_features_0xBC =
1187 { "Wacom Intuos4 WL", WACOM_PKGLEN_INTUOS, 40840, 25400, 2047, 63, INTUOS4 };
1108static const struct wacom_features wacom_features_0x3F = 1188static const struct wacom_features wacom_features_0x3F =
1109 { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023, 63, CINTIQ }; 1189 { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023, 63, CINTIQ };
1110static const struct wacom_features wacom_features_0xC5 = 1190static const struct wacom_features wacom_features_0xC5 =
@@ -1113,6 +1193,12 @@ static const struct wacom_features wacom_features_0xC6 =
1113 { "Wacom Cintiq 12WX", WACOM_PKGLEN_INTUOS, 53020, 33440, 1023, 63, WACOM_BEE }; 1193 { "Wacom Cintiq 12WX", WACOM_PKGLEN_INTUOS, 53020, 33440, 1023, 63, WACOM_BEE };
1114static const struct wacom_features wacom_features_0xC7 = 1194static const struct wacom_features wacom_features_0xC7 =
1115 { "Wacom DTU1931", WACOM_PKGLEN_GRAPHIRE, 37832, 30305, 511, 0, PL }; 1195 { "Wacom DTU1931", WACOM_PKGLEN_GRAPHIRE, 37832, 30305, 511, 0, PL };
1196static const struct wacom_features wacom_features_0xCE =
1197 { "Wacom DTU2231", WACOM_PKGLEN_GRAPHIRE, 47864, 27011, 511, 0, DTU };
1198static const struct wacom_features wacom_features_0xF0 =
1199 { "Wacom DTU1631", WACOM_PKGLEN_GRAPHIRE, 34623, 19553, 511, 0, DTU };
1200static const struct wacom_features wacom_features_0xCC =
1201 { "Wacom Cintiq 21UX2", WACOM_PKGLEN_INTUOS, 87200, 65600, 2047, 63, WACOM_21UX2 };
1116static const struct wacom_features wacom_features_0x90 = 1202static const struct wacom_features wacom_features_0x90 =
1117 { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC }; 1203 { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC };
1118static const struct wacom_features wacom_features_0x93 = 1204static const struct wacom_features wacom_features_0x93 =
@@ -1185,10 +1271,14 @@ const struct usb_device_id wacom_ids[] = {
1185 { USB_DEVICE_WACOM(0xB9) }, 1271 { USB_DEVICE_WACOM(0xB9) },
1186 { USB_DEVICE_WACOM(0xBA) }, 1272 { USB_DEVICE_WACOM(0xBA) },
1187 { USB_DEVICE_WACOM(0xBB) }, 1273 { USB_DEVICE_WACOM(0xBB) },
1274 { USB_DEVICE_WACOM(0xBC) },
1188 { USB_DEVICE_WACOM(0x3F) }, 1275 { USB_DEVICE_WACOM(0x3F) },
1189 { USB_DEVICE_WACOM(0xC5) }, 1276 { USB_DEVICE_WACOM(0xC5) },
1190 { USB_DEVICE_WACOM(0xC6) }, 1277 { USB_DEVICE_WACOM(0xC6) },
1191 { USB_DEVICE_WACOM(0xC7) }, 1278 { USB_DEVICE_WACOM(0xC7) },
1279 { USB_DEVICE_WACOM(0xCE) },
1280 { USB_DEVICE_WACOM(0xF0) },
1281 { USB_DEVICE_WACOM(0xCC) },
1192 { USB_DEVICE_WACOM(0x90) }, 1282 { USB_DEVICE_WACOM(0x90) },
1193 { USB_DEVICE_WACOM(0x93) }, 1283 { USB_DEVICE_WACOM(0x93) },
1194 { USB_DEVICE_WACOM(0x9A) }, 1284 { USB_DEVICE_WACOM(0x9A) },
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h
index 063f1af3204f..99e1a54cd305 100644
--- a/drivers/input/tablet/wacom_wac.h
+++ b/drivers/input/tablet/wacom_wac.h
@@ -43,6 +43,7 @@ enum {
43 WACOM_G4, 43 WACOM_G4,
44 PTU, 44 PTU,
45 PL, 45 PL,
46 DTU,
46 INTUOS, 47 INTUOS,
47 INTUOS3S, 48 INTUOS3S,
48 INTUOS3, 49 INTUOS3,
@@ -50,6 +51,7 @@ enum {
50 INTUOS4S, 51 INTUOS4S,
51 INTUOS4, 52 INTUOS4,
52 INTUOS4L, 53 INTUOS4L,
54 WACOM_21UX2,
53 CINTIQ, 55 CINTIQ,
54 WACOM_BEE, 56 WACOM_BEE,
55 WACOM_MO, 57 WACOM_MO,
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 6703c6b9800a..0069d9703fda 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -55,37 +55,36 @@ config TOUCHSCREEN_AD7877
55 To compile this driver as a module, choose M here: the 55 To compile this driver as a module, choose M here: the
56 module will be called ad7877. 56 module will be called ad7877.
57 57
58config TOUCHSCREEN_AD7879_I2C 58config TOUCHSCREEN_AD7879
59 tristate "AD7879 based touchscreens: AD7879-1 I2C Interface" 59 tristate "Analog Devices AD7879-1/AD7889-1 touchscreen interface"
60 depends on I2C
61 select TOUCHSCREEN_AD7879
62 help 60 help
63 Say Y here if you have a touchscreen interface using the 61 Say Y here if you want to support a touchscreen interface using
64 AD7879-1/AD7889-1 controller, and your board-specific 62 the AD7879-1/AD7889-1 controller.
65 initialization code includes that in its table of I2C devices.
66 63
67 If unsure, say N (but it's safe to say "Y"). 64 You should select a bus connection too.
68 65
69 To compile this driver as a module, choose M here: the 66 To compile this driver as a module, choose M here: the
70 module will be called ad7879. 67 module will be called ad7879.
71 68
69config TOUCHSCREEN_AD7879_I2C
70 tristate "support I2C bus connection"
71 depends on TOUCHSCREEN_AD7879 && I2C
72 help
73 Say Y here if you have AD7879-1/AD7889-1 hooked to an I2C bus.
74
75 To compile this driver as a module, choose M here: the
76 module will be called ad7879-i2c.
77
72config TOUCHSCREEN_AD7879_SPI 78config TOUCHSCREEN_AD7879_SPI
73 tristate "AD7879 based touchscreens: AD7879 SPI Interface" 79 tristate "support SPI bus connection"
74 depends on SPI_MASTER && TOUCHSCREEN_AD7879_I2C = n 80 depends on TOUCHSCREEN_AD7879 && SPI_MASTER
75 select TOUCHSCREEN_AD7879
76 help 81 help
77 Say Y here if you have a touchscreen interface using the 82 Say Y here if you have AD7879-1/AD7889-1 hooked to a SPI bus.
78 AD7879/AD7889 controller, and your board-specific initialization
79 code includes that in its table of SPI devices.
80 83
81 If unsure, say N (but it's safe to say "Y"). 84 If unsure, say N (but it's safe to say "Y").
82 85
83 To compile this driver as a module, choose M here: the 86 To compile this driver as a module, choose M here: the
84 module will be called ad7879. 87 module will be called ad7879-spi.
85
86config TOUCHSCREEN_AD7879
87 tristate
88 default n
89 88
90config TOUCHSCREEN_BITSY 89config TOUCHSCREEN_BITSY
91 tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" 90 tristate "Compaq iPAQ H3600 (Bitsy) touchscreen"
@@ -99,6 +98,20 @@ config TOUCHSCREEN_BITSY
99 To compile this driver as a module, choose M here: the 98 To compile this driver as a module, choose M here: the
100 module will be called h3600_ts_input. 99 module will be called h3600_ts_input.
101 100
101config TOUCHSCREEN_CY8CTMG110
102 tristate "cy8ctmg110 touchscreen"
103 depends on I2C
104 depends on GPIOLIB
105
106 help
107 Say Y here if you have a cy8ctmg110 capacitive touchscreen on
108 an AAVA device.
109
110 If unsure, say N.
111
112 To compile this driver as a module, choose M here: the
113 module will be called cy8ctmg110_ts.
114
102config TOUCHSCREEN_DA9034 115config TOUCHSCREEN_DA9034
103 tristate "Touchscreen support for Dialog Semiconductor DA9034" 116 tristate "Touchscreen support for Dialog Semiconductor DA9034"
104 depends on PMIC_DA903X 117 depends on PMIC_DA903X
@@ -156,7 +169,7 @@ config TOUCHSCREEN_FUJITSU
156config TOUCHSCREEN_S3C2410 169config TOUCHSCREEN_S3C2410
157 tristate "Samsung S3C2410/generic touchscreen input driver" 170 tristate "Samsung S3C2410/generic touchscreen input driver"
158 depends on ARCH_S3C2410 || SAMSUNG_DEV_TS 171 depends on ARCH_S3C2410 || SAMSUNG_DEV_TS
159 select S3C24XX_ADC 172 select S3C_ADC
160 help 173 help
161 Say Y here if you have the s3c2410 touchscreen. 174 Say Y here if you have the s3c2410 touchscreen.
162 175
@@ -292,6 +305,18 @@ config TOUCHSCREEN_PENMOUNT
292 To compile this driver as a module, choose M here: the 305 To compile this driver as a module, choose M here: the
293 module will be called penmount. 306 module will be called penmount.
294 307
308config TOUCHSCREEN_QT602240
309 tristate "QT602240 I2C Touchscreen"
310 depends on I2C
311 help
312 Say Y here if you have the AT42QT602240/ATMXT224 I2C touchscreen
313 connected to your system.
314
315 If unsure, say N.
316
317 To compile this driver as a module, choose M here: the
318 module will be called qt602240_ts.
319
295config TOUCHSCREEN_MIGOR 320config TOUCHSCREEN_MIGOR
296 tristate "Renesas MIGO-R touchscreen" 321 tristate "Renesas MIGO-R touchscreen"
297 depends on SH_MIGOR && I2C 322 depends on SH_MIGOR && I2C
@@ -540,9 +565,9 @@ config TOUCHSCREEN_USB_ZYTRONIC
540 bool "Zytronic controller" if EMBEDDED 565 bool "Zytronic controller" if EMBEDDED
541 depends on TOUCHSCREEN_USB_COMPOSITE 566 depends on TOUCHSCREEN_USB_COMPOSITE
542 567
543config TOUCHSCREEN_USB_ETT_TC5UH 568config TOUCHSCREEN_USB_ETT_TC45USB
544 default y 569 default y
545 bool "ET&T TC5UH touchscreen controler support" if EMBEDDED 570 bool "ET&T USB series TC4UM/TC5UH touchscreen controler support" if EMBEDDED
546 depends on TOUCHSCREEN_USB_COMPOSITE 571 depends on TOUCHSCREEN_USB_COMPOSITE
547 572
548config TOUCHSCREEN_USB_NEXIO 573config TOUCHSCREEN_USB_NEXIO
@@ -603,4 +628,14 @@ config TOUCHSCREEN_TPS6507X
603 To compile this driver as a module, choose M here: the 628 To compile this driver as a module, choose M here: the
604 module will be called tps6507x_ts. 629 module will be called tps6507x_ts.
605 630
631config TOUCHSCREEN_STMPE
632 tristate "STMicroelectronics STMPE touchscreens"
633 depends on MFD_STMPE
634 help
635 Say Y here if you want support for STMicroelectronics
636 STMPE touchscreen controllers.
637
638 To compile this driver as a module, choose M here: the
639 module will be called stmpe-ts.
640
606endif 641endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 497964a7a214..28217e1dcafd 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -9,9 +9,13 @@ wm97xx-ts-y := wm97xx-core.o
9obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o 9obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o
10obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o 10obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o
11obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o 11obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o
12obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o
13obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o
12obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 14obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o
13obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o 15obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o
14obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 16obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
17obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o
18obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o
15obj-$(CONFIG_TOUCHSCREEN_DYNAPRO) += dynapro.o 19obj-$(CONFIG_TOUCHSCREEN_DYNAPRO) += dynapro.o
16obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE) += hampshire.o 20obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE) += hampshire.o
17obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o 21obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
@@ -30,7 +34,9 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o
30obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o 34obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o
31obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o 35obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o
32obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 36obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
37obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o
33obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o 38obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o
39obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o
34obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o 40obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
35obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 41obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
36obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 42obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
@@ -38,7 +44,6 @@ obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o
38obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 44obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
39obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o 45obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o
40obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o 46obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o
41obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o
42wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o 47wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o
43wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o 48wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o
44wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o 49wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index 0d2d7e54b465..5f0221cffef9 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -679,6 +679,13 @@ static int __devinit ad7877_probe(struct spi_device *spi)
679 return -EINVAL; 679 return -EINVAL;
680 } 680 }
681 681
682 spi->bits_per_word = 16;
683 err = spi_setup(spi);
684 if (err) {
685 dev_dbg(&spi->dev, "spi master doesn't support 16 bits/word\n");
686 return err;
687 }
688
682 ts = kzalloc(sizeof(struct ad7877), GFP_KERNEL); 689 ts = kzalloc(sizeof(struct ad7877), GFP_KERNEL);
683 input_dev = input_allocate_device(); 690 input_dev = input_allocate_device();
684 if (!ts || !input_dev) { 691 if (!ts || !input_dev) {
diff --git a/drivers/input/touchscreen/ad7879-i2c.c b/drivers/input/touchscreen/ad7879-i2c.c
new file mode 100644
index 000000000000..d82a38ee9a3e
--- /dev/null
+++ b/drivers/input/touchscreen/ad7879-i2c.c
@@ -0,0 +1,143 @@
1/*
2 * AD7879-1/AD7889-1 touchscreen (I2C bus)
3 *
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/input.h> /* BUS_I2C */
10#include <linux/i2c.h>
11#include <linux/module.h>
12#include <linux/types.h>
13
14#include "ad7879.h"
15
16#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
17
18#ifdef CONFIG_PM
19static int ad7879_i2c_suspend(struct i2c_client *client, pm_message_t message)
20{
21 struct ad7879 *ts = i2c_get_clientdata(client);
22
23 ad7879_suspend(ts);
24
25 return 0;
26}
27
28static int ad7879_i2c_resume(struct i2c_client *client)
29{
30 struct ad7879 *ts = i2c_get_clientdata(client);
31
32 ad7879_resume(ts);
33
34 return 0;
35}
36#else
37# define ad7879_i2c_suspend NULL
38# define ad7879_i2c_resume NULL
39#endif
40
41/* All registers are word-sized.
42 * AD7879 uses a high-byte first convention.
43 */
44static int ad7879_i2c_read(struct device *dev, u8 reg)
45{
46 struct i2c_client *client = to_i2c_client(dev);
47
48 return swab16(i2c_smbus_read_word_data(client, reg));
49}
50
51static int ad7879_i2c_multi_read(struct device *dev,
52 u8 first_reg, u8 count, u16 *buf)
53{
54 struct i2c_client *client = to_i2c_client(dev);
55 u8 idx;
56
57 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
58
59 for (idx = 0; idx < count; ++idx)
60 buf[idx] = swab16(buf[idx]);
61
62 return 0;
63}
64
65static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
66{
67 struct i2c_client *client = to_i2c_client(dev);
68
69 return i2c_smbus_write_word_data(client, reg, swab16(val));
70}
71
72static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
73 .bustype = BUS_I2C,
74 .read = ad7879_i2c_read,
75 .multi_read = ad7879_i2c_multi_read,
76 .write = ad7879_i2c_write,
77};
78
79static int __devinit ad7879_i2c_probe(struct i2c_client *client,
80 const struct i2c_device_id *id)
81{
82 struct ad7879 *ts;
83
84 if (!i2c_check_functionality(client->adapter,
85 I2C_FUNC_SMBUS_WORD_DATA)) {
86 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
87 return -EIO;
88 }
89
90 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
91 &ad7879_i2c_bus_ops);
92 if (IS_ERR(ts))
93 return PTR_ERR(ts);
94
95 i2c_set_clientdata(client, ts);
96
97 return 0;
98}
99
100static int __devexit ad7879_i2c_remove(struct i2c_client *client)
101{
102 struct ad7879 *ts = i2c_get_clientdata(client);
103
104 ad7879_remove(ts);
105
106 return 0;
107}
108
109static const struct i2c_device_id ad7879_id[] = {
110 { "ad7879", 0 },
111 { "ad7889", 0 },
112 { }
113};
114MODULE_DEVICE_TABLE(i2c, ad7879_id);
115
116static struct i2c_driver ad7879_i2c_driver = {
117 .driver = {
118 .name = "ad7879",
119 .owner = THIS_MODULE,
120 },
121 .probe = ad7879_i2c_probe,
122 .remove = __devexit_p(ad7879_i2c_remove),
123 .suspend = ad7879_i2c_suspend,
124 .resume = ad7879_i2c_resume,
125 .id_table = ad7879_id,
126};
127
128static int __init ad7879_i2c_init(void)
129{
130 return i2c_add_driver(&ad7879_i2c_driver);
131}
132module_init(ad7879_i2c_init);
133
134static void __exit ad7879_i2c_exit(void)
135{
136 i2c_del_driver(&ad7879_i2c_driver);
137}
138module_exit(ad7879_i2c_exit);
139
140MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
141MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
142MODULE_LICENSE("GPL");
143MODULE_ALIAS("i2c:ad7879");
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c
new file mode 100644
index 000000000000..59c6e68c4325
--- /dev/null
+++ b/drivers/input/touchscreen/ad7879-spi.c
@@ -0,0 +1,198 @@
1/*
2 * AD7879/AD7889 touchscreen (SPI bus)
3 *
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/input.h> /* BUS_SPI */
10#include <linux/spi/spi.h>
11
12#include "ad7879.h"
13
14#define AD7879_DEVID 0x7A /* AD7879/AD7889 */
15
16#define MAX_SPI_FREQ_HZ 5000000
17#define AD7879_CMD_MAGIC 0xE000
18#define AD7879_CMD_READ (1 << 10)
19#define AD7879_CMD(reg) (AD7879_CMD_MAGIC | ((reg) & 0xF))
20#define AD7879_WRITECMD(reg) (AD7879_CMD(reg))
21#define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ)
22
23#ifdef CONFIG_PM
24static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message)
25{
26 struct ad7879 *ts = spi_get_drvdata(spi);
27
28 ad7879_suspend(ts);
29
30 return 0;
31}
32
33static int ad7879_spi_resume(struct spi_device *spi)
34{
35 struct ad7879 *ts = spi_get_drvdata(spi);
36
37 ad7879_resume(ts);
38
39 return 0;
40}
41#else
42# define ad7879_spi_suspend NULL
43# define ad7879_spi_resume NULL
44#endif
45
46/*
47 * ad7879_read/write are only used for initial setup and for sysfs controls.
48 * The main traffic is done in ad7879_collect().
49 */
50
51static int ad7879_spi_xfer(struct spi_device *spi,
52 u16 cmd, u8 count, u16 *tx_buf, u16 *rx_buf)
53{
54 struct spi_message msg;
55 struct spi_transfer *xfers;
56 void *spi_data;
57 u16 *command;
58 u16 *_rx_buf = _rx_buf; /* shut gcc up */
59 u8 idx;
60 int ret;
61
62 xfers = spi_data = kzalloc(sizeof(*xfers) * (count + 2), GFP_KERNEL);
63 if (!spi_data)
64 return -ENOMEM;
65
66 spi_message_init(&msg);
67
68 command = spi_data;
69 command[0] = cmd;
70 if (count == 1) {
71 /* ad7879_spi_{read,write} gave us buf on stack */
72 command[1] = *tx_buf;
73 tx_buf = &command[1];
74 _rx_buf = rx_buf;
75 rx_buf = &command[2];
76 }
77
78 ++xfers;
79 xfers[0].tx_buf = command;
80 xfers[0].len = 2;
81 spi_message_add_tail(&xfers[0], &msg);
82 ++xfers;
83
84 for (idx = 0; idx < count; ++idx) {
85 if (rx_buf)
86 xfers[idx].rx_buf = &rx_buf[idx];
87 if (tx_buf)
88 xfers[idx].tx_buf = &tx_buf[idx];
89 xfers[idx].len = 2;
90 spi_message_add_tail(&xfers[idx], &msg);
91 }
92
93 ret = spi_sync(spi, &msg);
94
95 if (count == 1)
96 _rx_buf[0] = command[2];
97
98 kfree(spi_data);
99
100 return ret;
101}
102
103static int ad7879_spi_multi_read(struct device *dev,
104 u8 first_reg, u8 count, u16 *buf)
105{
106 struct spi_device *spi = to_spi_device(dev);
107
108 return ad7879_spi_xfer(spi, AD7879_READCMD(first_reg), count, NULL, buf);
109}
110
111static int ad7879_spi_read(struct device *dev, u8 reg)
112{
113 struct spi_device *spi = to_spi_device(dev);
114 u16 ret, dummy;
115
116 return ad7879_spi_xfer(spi, AD7879_READCMD(reg), 1, &dummy, &ret) ? : ret;
117}
118
119static int ad7879_spi_write(struct device *dev, u8 reg, u16 val)
120{
121 struct spi_device *spi = to_spi_device(dev);
122 u16 dummy;
123
124 return ad7879_spi_xfer(spi, AD7879_WRITECMD(reg), 1, &val, &dummy);
125}
126
127static const struct ad7879_bus_ops ad7879_spi_bus_ops = {
128 .bustype = BUS_SPI,
129 .read = ad7879_spi_read,
130 .multi_read = ad7879_spi_multi_read,
131 .write = ad7879_spi_write,
132};
133
134static int __devinit ad7879_spi_probe(struct spi_device *spi)
135{
136 struct ad7879 *ts;
137 int err;
138
139 /* don't exceed max specified SPI CLK frequency */
140 if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
141 dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz);
142 return -EINVAL;
143 }
144
145 spi->bits_per_word = 16;
146 err = spi_setup(spi);
147 if (err) {
148 dev_dbg(&spi->dev, "spi master doesn't support 16 bits/word\n");
149 return err;
150 }
151
152 ts = ad7879_probe(&spi->dev, AD7879_DEVID, spi->irq, &ad7879_spi_bus_ops);
153 if (IS_ERR(ts))
154 return PTR_ERR(ts);
155
156 spi_set_drvdata(spi, ts);
157
158 return 0;
159}
160
161static int __devexit ad7879_spi_remove(struct spi_device *spi)
162{
163 struct ad7879 *ts = spi_get_drvdata(spi);
164
165 ad7879_remove(ts);
166 spi_set_drvdata(spi, NULL);
167
168 return 0;
169}
170
171static struct spi_driver ad7879_spi_driver = {
172 .driver = {
173 .name = "ad7879",
174 .bus = &spi_bus_type,
175 .owner = THIS_MODULE,
176 },
177 .probe = ad7879_spi_probe,
178 .remove = __devexit_p(ad7879_spi_remove),
179 .suspend = ad7879_spi_suspend,
180 .resume = ad7879_spi_resume,
181};
182
183static int __init ad7879_spi_init(void)
184{
185 return spi_register_driver(&ad7879_spi_driver);
186}
187module_init(ad7879_spi_init);
188
189static void __exit ad7879_spi_exit(void)
190{
191 spi_unregister_driver(&ad7879_spi_driver);
192}
193module_exit(ad7879_spi_exit);
194
195MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
196MODULE_DESCRIPTION("AD7879(-1) touchscreen SPI bus driver");
197MODULE_LICENSE("GPL");
198MODULE_ALIAS("spi:ad7879");
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index 794d070c6900..ba6f0bd1e762 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -1,25 +1,9 @@
1/* 1/*
2 * Copyright (C) 2008-2009 Michael Hennerich, Analog Devices Inc. 2 * AD7879/AD7889 based touchscreen and GPIO driver
3 * 3 *
4 * Description: AD7879/AD7889 based touchscreen, and GPIO driver 4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 * (I2C/SPI Interface)
6 * 5 *
7 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 6 * Licensed under the GPL-2 or later.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see the file COPYING, or write
21 * to the Free Software Foundation, Inc.,
22 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * 7 *
24 * History: 8 * History:
25 * Copyright (c) 2005 David Brownell 9 * Copyright (c) 2005 David Brownell
@@ -44,12 +28,12 @@
44#include <linux/interrupt.h> 28#include <linux/interrupt.h>
45#include <linux/irq.h> 29#include <linux/irq.h>
46#include <linux/slab.h> 30#include <linux/slab.h>
47#include <linux/workqueue.h>
48#include <linux/spi/spi.h> 31#include <linux/spi/spi.h>
49#include <linux/i2c.h> 32#include <linux/i2c.h>
50#include <linux/gpio.h> 33#include <linux/gpio.h>
51 34
52#include <linux/spi/ad7879.h> 35#include <linux/spi/ad7879.h>
36#include "ad7879.h"
53 37
54#define AD7879_REG_ZEROS 0 38#define AD7879_REG_ZEROS 0
55#define AD7879_REG_CTRL1 1 39#define AD7879_REG_CTRL1 1
@@ -120,30 +104,19 @@ enum {
120#define MAX_12BIT ((1<<12)-1) 104#define MAX_12BIT ((1<<12)-1)
121#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50) 105#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50)
122 106
123#if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE)
124#define AD7879_DEVID 0x7A
125typedef struct spi_device bus_device;
126#elif defined(CONFIG_TOUCHSCREEN_AD7879_I2C) || defined(CONFIG_TOUCHSCREEN_AD7879_I2C_MODULE)
127#define AD7879_DEVID 0x79
128typedef struct i2c_client bus_device;
129#endif
130
131struct ad7879 { 107struct ad7879 {
132 bus_device *bus; 108 const struct ad7879_bus_ops *bops;
109
110 struct device *dev;
133 struct input_dev *input; 111 struct input_dev *input;
134 struct work_struct work;
135 struct timer_list timer; 112 struct timer_list timer;
136#ifdef CONFIG_GPIOLIB 113#ifdef CONFIG_GPIOLIB
137 struct gpio_chip gc; 114 struct gpio_chip gc;
138#endif
139 struct mutex mutex; 115 struct mutex mutex;
140 unsigned disabled:1; /* P: mutex */
141
142#if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE)
143 struct spi_message msg;
144 struct spi_transfer xfer[AD7879_NR_SENSE + 1];
145 u16 cmd;
146#endif 116#endif
117 unsigned int irq;
118 bool disabled; /* P: input->mutex */
119 bool suspended; /* P: input->mutex */
147 u16 conversion_data[AD7879_NR_SENSE]; 120 u16 conversion_data[AD7879_NR_SENSE];
148 char phys[32]; 121 char phys[32];
149 u8 first_conversion_delay; 122 u8 first_conversion_delay;
@@ -158,11 +131,22 @@ struct ad7879 {
158 u16 cmd_crtl3; 131 u16 cmd_crtl3;
159}; 132};
160 133
161static int ad7879_read(bus_device *, u8); 134static int ad7879_read(struct ad7879 *ts, u8 reg)
162static int ad7879_write(bus_device *, u8, u16); 135{
163static void ad7879_collect(struct ad7879 *); 136 return ts->bops->read(ts->dev, reg);
137}
138
139static int ad7879_multi_read(struct ad7879 *ts, u8 first_reg, u8 count, u16 *buf)
140{
141 return ts->bops->multi_read(ts->dev, first_reg, count, buf);
142}
164 143
165static void ad7879_report(struct ad7879 *ts) 144static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val)
145{
146 return ts->bops->write(ts->dev, reg, val);
147}
148
149static int ad7879_report(struct ad7879 *ts)
166{ 150{
167 struct input_dev *input_dev = ts->input; 151 struct input_dev *input_dev = ts->input;
168 unsigned Rt; 152 unsigned Rt;
@@ -175,12 +159,14 @@ static void ad7879_report(struct ad7879 *ts)
175 159
176 /* 160 /*
177 * The samples processed here are already preprocessed by the AD7879. 161 * The samples processed here are already preprocessed by the AD7879.
178 * The preprocessing function consists of a median and an averaging filter. 162 * The preprocessing function consists of a median and an averaging
179 * The combination of these two techniques provides a robust solution, 163 * filter. The combination of these two techniques provides a robust
180 * discarding the spurious noise in the signal and keeping only the data of interest. 164 * solution, discarding the spurious noise in the signal and keeping
181 * The size of both filters is programmable. (dev.platform_data, see linux/spi/ad7879.h) 165 * only the data of interest. The size of both filters is
182 * Other user-programmable conversion controls include variable acquisition time, 166 * programmable. (dev.platform_data, see linux/spi/ad7879.h) Other
183 * and first conversion delay. Up to 16 averages can be taken per conversion. 167 * user-programmable conversion controls include variable acquisition
168 * time, and first conversion delay. Up to 16 averages can be taken
169 * per conversion.
184 */ 170 */
185 171
186 if (likely(x && z1)) { 172 if (likely(x && z1)) {
@@ -189,21 +175,17 @@ static void ad7879_report(struct ad7879 *ts)
189 Rt /= z1; 175 Rt /= z1;
190 Rt = (Rt + 2047) >> 12; 176 Rt = (Rt + 2047) >> 12;
191 177
178 if (!timer_pending(&ts->timer))
179 input_report_key(input_dev, BTN_TOUCH, 1);
180
192 input_report_abs(input_dev, ABS_X, x); 181 input_report_abs(input_dev, ABS_X, x);
193 input_report_abs(input_dev, ABS_Y, y); 182 input_report_abs(input_dev, ABS_Y, y);
194 input_report_abs(input_dev, ABS_PRESSURE, Rt); 183 input_report_abs(input_dev, ABS_PRESSURE, Rt);
195 input_sync(input_dev); 184 input_sync(input_dev);
185 return 0;
196 } 186 }
197}
198
199static void ad7879_work(struct work_struct *work)
200{
201 struct ad7879 *ts = container_of(work, struct ad7879, work);
202 187
203 /* use keventd context to read the result registers */ 188 return -EINVAL;
204 ad7879_collect(ts);
205 ad7879_report(ts);
206 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
207} 189}
208 190
209static void ad7879_ts_event_release(struct ad7879 *ts) 191static void ad7879_ts_event_release(struct ad7879 *ts)
@@ -211,6 +193,7 @@ static void ad7879_ts_event_release(struct ad7879 *ts)
211 struct input_dev *input_dev = ts->input; 193 struct input_dev *input_dev = ts->input;
212 194
213 input_report_abs(input_dev, ABS_PRESSURE, 0); 195 input_report_abs(input_dev, ABS_PRESSURE, 0);
196 input_report_key(input_dev, BTN_TOUCH, 0);
214 input_sync(input_dev); 197 input_sync(input_dev);
215} 198}
216 199
@@ -225,56 +208,98 @@ static irqreturn_t ad7879_irq(int irq, void *handle)
225{ 208{
226 struct ad7879 *ts = handle; 209 struct ad7879 *ts = handle;
227 210
228 /* The repeated conversion sequencer controlled by TMR kicked off too fast. 211 ad7879_multi_read(ts, AD7879_REG_XPLUS, AD7879_NR_SENSE, ts->conversion_data);
229 * We ignore the last and process the sample sequence currently in the queue.
230 * It can't be older than 9.4ms
231 */
232 212
233 if (!work_pending(&ts->work)) 213 if (!ad7879_report(ts))
234 schedule_work(&ts->work); 214 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
235 215
236 return IRQ_HANDLED; 216 return IRQ_HANDLED;
237} 217}
238 218
239static void ad7879_setup(struct ad7879 *ts) 219static void __ad7879_enable(struct ad7879 *ts)
240{ 220{
241 ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); 221 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
242 ad7879_write(ts->bus, AD7879_REG_CTRL3, ts->cmd_crtl3); 222 ad7879_write(ts, AD7879_REG_CTRL3, ts->cmd_crtl3);
243 ad7879_write(ts->bus, AD7879_REG_CTRL1, ts->cmd_crtl1); 223 ad7879_write(ts, AD7879_REG_CTRL1, ts->cmd_crtl1);
224
225 enable_irq(ts->irq);
244} 226}
245 227
246static void ad7879_disable(struct ad7879 *ts) 228static void __ad7879_disable(struct ad7879 *ts)
247{ 229{
248 mutex_lock(&ts->mutex); 230 disable_irq(ts->irq);
231
232 if (del_timer_sync(&ts->timer))
233 ad7879_ts_event_release(ts);
234
235 ad7879_write(ts, AD7879_REG_CTRL2, AD7879_PM(AD7879_PM_SHUTDOWN));
236}
249 237
250 if (!ts->disabled) {
251 238
252 ts->disabled = 1; 239static int ad7879_open(struct input_dev *input)
253 disable_irq(ts->bus->irq); 240{
241 struct ad7879 *ts = input_get_drvdata(input);
254 242
255 cancel_work_sync(&ts->work); 243 /* protected by input->mutex */
244 if (!ts->disabled && !ts->suspended)
245 __ad7879_enable(ts);
256 246
257 if (del_timer_sync(&ts->timer)) 247 return 0;
258 ad7879_ts_event_release(ts); 248}
259 249
260 ad7879_write(ts->bus, AD7879_REG_CTRL2, 250static void ad7879_close(struct input_dev* input)
261 AD7879_PM(AD7879_PM_SHUTDOWN)); 251{
262 } 252 struct ad7879 *ts = input_get_drvdata(input);
263 253
264 mutex_unlock(&ts->mutex); 254 /* protected by input->mutex */
255 if (!ts->disabled && !ts->suspended)
256 __ad7879_disable(ts);
265} 257}
266 258
267static void ad7879_enable(struct ad7879 *ts) 259void ad7879_suspend(struct ad7879 *ts)
268{ 260{
269 mutex_lock(&ts->mutex); 261 mutex_lock(&ts->input->mutex);
262
263 if (!ts->suspended && !ts->disabled && ts->input->users)
264 __ad7879_disable(ts);
265
266 ts->suspended = true;
270 267
271 if (ts->disabled) { 268 mutex_unlock(&ts->input->mutex);
272 ad7879_setup(ts); 269}
273 ts->disabled = 0; 270EXPORT_SYMBOL(ad7879_suspend);
274 enable_irq(ts->bus->irq); 271
272void ad7879_resume(struct ad7879 *ts)
273{
274 mutex_lock(&ts->input->mutex);
275
276 if (ts->suspended && !ts->disabled && ts->input->users)
277 __ad7879_enable(ts);
278
279 ts->suspended = false;
280
281 mutex_unlock(&ts->input->mutex);
282}
283EXPORT_SYMBOL(ad7879_resume);
284
285static void ad7879_toggle(struct ad7879 *ts, bool disable)
286{
287 mutex_lock(&ts->input->mutex);
288
289 if (!ts->suspended && ts->input->users != 0) {
290
291 if (disable) {
292 if (ts->disabled)
293 __ad7879_enable(ts);
294 } else {
295 if (!ts->disabled)
296 __ad7879_disable(ts);
297 }
275 } 298 }
276 299
277 mutex_unlock(&ts->mutex); 300 ts->disabled = disable;
301
302 mutex_unlock(&ts->input->mutex);
278} 303}
279 304
280static ssize_t ad7879_disable_show(struct device *dev, 305static ssize_t ad7879_disable_show(struct device *dev,
@@ -297,10 +322,7 @@ static ssize_t ad7879_disable_store(struct device *dev,
297 if (error) 322 if (error)
298 return error; 323 return error;
299 324
300 if (val) 325 ad7879_toggle(ts, val);
301 ad7879_disable(ts);
302 else
303 ad7879_enable(ts);
304 326
305 return count; 327 return count;
306} 328}
@@ -325,7 +347,7 @@ static int ad7879_gpio_direction_input(struct gpio_chip *chip,
325 347
326 mutex_lock(&ts->mutex); 348 mutex_lock(&ts->mutex);
327 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; 349 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL;
328 err = ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); 350 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
329 mutex_unlock(&ts->mutex); 351 mutex_unlock(&ts->mutex);
330 352
331 return err; 353 return err;
@@ -345,7 +367,7 @@ static int ad7879_gpio_direction_output(struct gpio_chip *chip,
345 else 367 else
346 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; 368 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA;
347 369
348 err = ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); 370 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
349 mutex_unlock(&ts->mutex); 371 mutex_unlock(&ts->mutex);
350 372
351 return err; 373 return err;
@@ -357,7 +379,7 @@ static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
357 u16 val; 379 u16 val;
358 380
359 mutex_lock(&ts->mutex); 381 mutex_lock(&ts->mutex);
360 val = ad7879_read(ts->bus, AD7879_REG_CTRL2); 382 val = ad7879_read(ts, AD7879_REG_CTRL2);
361 mutex_unlock(&ts->mutex); 383 mutex_unlock(&ts->mutex);
362 384
363 return !!(val & AD7879_GPIO_DATA); 385 return !!(val & AD7879_GPIO_DATA);
@@ -374,16 +396,17 @@ static void ad7879_gpio_set_value(struct gpio_chip *chip,
374 else 396 else
375 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; 397 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA;
376 398
377 ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); 399 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
378 mutex_unlock(&ts->mutex); 400 mutex_unlock(&ts->mutex);
379} 401}
380 402
381static int __devinit ad7879_gpio_add(struct device *dev) 403static int ad7879_gpio_add(struct ad7879 *ts,
404 const struct ad7879_platform_data *pdata)
382{ 405{
383 struct ad7879 *ts = dev_get_drvdata(dev);
384 struct ad7879_platform_data *pdata = dev->platform_data;
385 int ret = 0; 406 int ret = 0;
386 407
408 mutex_init(&ts->mutex);
409
387 if (pdata->gpio_export) { 410 if (pdata->gpio_export) {
388 ts->gc.direction_input = ad7879_gpio_direction_input; 411 ts->gc.direction_input = ad7879_gpio_direction_input;
389 ts->gc.direction_output = ad7879_gpio_direction_output; 412 ts->gc.direction_output = ad7879_gpio_direction_output;
@@ -394,72 +417,75 @@ static int __devinit ad7879_gpio_add(struct device *dev)
394 ts->gc.ngpio = 1; 417 ts->gc.ngpio = 1;
395 ts->gc.label = "AD7879-GPIO"; 418 ts->gc.label = "AD7879-GPIO";
396 ts->gc.owner = THIS_MODULE; 419 ts->gc.owner = THIS_MODULE;
397 ts->gc.dev = dev; 420 ts->gc.dev = ts->dev;
398 421
399 ret = gpiochip_add(&ts->gc); 422 ret = gpiochip_add(&ts->gc);
400 if (ret) 423 if (ret)
401 dev_err(dev, "failed to register gpio %d\n", 424 dev_err(ts->dev, "failed to register gpio %d\n",
402 ts->gc.base); 425 ts->gc.base);
403 } 426 }
404 427
405 return ret; 428 return ret;
406} 429}
407 430
408/* 431static void ad7879_gpio_remove(struct ad7879 *ts)
409 * We mark ad7879_gpio_remove inline so there is a chance the code
410 * gets discarded when not needed. We can't do __devinit/__devexit
411 * markup since it is used in both probe and remove methods.
412 */
413static inline void ad7879_gpio_remove(struct device *dev)
414{ 432{
415 struct ad7879 *ts = dev_get_drvdata(dev); 433 const struct ad7879_platform_data *pdata = ts->dev->platform_data;
416 struct ad7879_platform_data *pdata = dev->platform_data;
417 int ret; 434 int ret;
418 435
419 if (pdata->gpio_export) { 436 if (pdata->gpio_export) {
420 ret = gpiochip_remove(&ts->gc); 437 ret = gpiochip_remove(&ts->gc);
421 if (ret) 438 if (ret)
422 dev_err(dev, "failed to remove gpio %d\n", 439 dev_err(ts->dev, "failed to remove gpio %d\n",
423 ts->gc.base); 440 ts->gc.base);
424 } 441 }
425} 442}
426#else 443#else
427static inline int ad7879_gpio_add(struct device *dev) 444static inline int ad7879_gpio_add(struct ad7879 *ts,
445 const struct ad7879_platform_data *pdata)
428{ 446{
429 return 0; 447 return 0;
430} 448}
431 449
432static inline void ad7879_gpio_remove(struct device *dev) 450static inline void ad7879_gpio_remove(struct ad7879 *ts)
433{ 451{
434} 452}
435#endif 453#endif
436 454
437static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) 455struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq,
456 const struct ad7879_bus_ops *bops)
438{ 457{
458 struct ad7879_platform_data *pdata = dev->platform_data;
459 struct ad7879 *ts;
439 struct input_dev *input_dev; 460 struct input_dev *input_dev;
440 struct ad7879_platform_data *pdata = bus->dev.platform_data;
441 int err; 461 int err;
442 u16 revid; 462 u16 revid;
443 463
444 if (!bus->irq) { 464 if (!irq) {
445 dev_err(&bus->dev, "no IRQ?\n"); 465 dev_err(dev, "no IRQ?\n");
446 return -ENODEV; 466 err = -EINVAL;
467 goto err_out;
447 } 468 }
448 469
449 if (!pdata) { 470 if (!pdata) {
450 dev_err(&bus->dev, "no platform data?\n"); 471 dev_err(dev, "no platform data?\n");
451 return -ENODEV; 472 err = -EINVAL;
473 goto err_out;
452 } 474 }
453 475
476 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
454 input_dev = input_allocate_device(); 477 input_dev = input_allocate_device();
455 if (!input_dev) 478 if (!ts || !input_dev) {
456 return -ENOMEM; 479 err = -ENOMEM;
480 goto err_free_mem;
481 }
457 482
483 ts->bops = bops;
484 ts->dev = dev;
458 ts->input = input_dev; 485 ts->input = input_dev;
486 ts->irq = irq;
459 487
460 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts); 488 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts);
461 INIT_WORK(&ts->work, ad7879_work);
462 mutex_init(&ts->mutex);
463 489
464 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; 490 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
465 ts->pressure_max = pdata->pressure_max ? : ~0; 491 ts->pressure_max = pdata->pressure_max ? : ~0;
@@ -470,17 +496,26 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
470 ts->pen_down_acc_interval = pdata->pen_down_acc_interval; 496 ts->pen_down_acc_interval = pdata->pen_down_acc_interval;
471 ts->median = pdata->median; 497 ts->median = pdata->median;
472 498
473 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&bus->dev)); 499 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev));
474 500
475 input_dev->name = "AD7879 Touchscreen"; 501 input_dev->name = "AD7879 Touchscreen";
476 input_dev->phys = ts->phys; 502 input_dev->phys = ts->phys;
477 input_dev->dev.parent = &bus->dev; 503 input_dev->dev.parent = dev;
504 input_dev->id.bustype = bops->bustype;
505
506 input_dev->open = ad7879_open;
507 input_dev->close = ad7879_close;
508
509 input_set_drvdata(input_dev, ts);
478 510
479 __set_bit(EV_ABS, input_dev->evbit); 511 __set_bit(EV_ABS, input_dev->evbit);
480 __set_bit(ABS_X, input_dev->absbit); 512 __set_bit(ABS_X, input_dev->absbit);
481 __set_bit(ABS_Y, input_dev->absbit); 513 __set_bit(ABS_Y, input_dev->absbit);
482 __set_bit(ABS_PRESSURE, input_dev->absbit); 514 __set_bit(ABS_PRESSURE, input_dev->absbit);
483 515
516 __set_bit(EV_KEY, input_dev->evbit);
517 __set_bit(BTN_TOUCH, input_dev->keybit);
518
484 input_set_abs_params(input_dev, ABS_X, 519 input_set_abs_params(input_dev, ABS_X,
485 pdata->x_min ? : 0, 520 pdata->x_min ? : 0,
486 pdata->x_max ? : MAX_12BIT, 521 pdata->x_max ? : MAX_12BIT,
@@ -492,17 +527,18 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
492 input_set_abs_params(input_dev, ABS_PRESSURE, 527 input_set_abs_params(input_dev, ABS_PRESSURE,
493 pdata->pressure_min, pdata->pressure_max, 0, 0); 528 pdata->pressure_min, pdata->pressure_max, 0, 0);
494 529
495 err = ad7879_write(bus, AD7879_REG_CTRL2, AD7879_RESET); 530 err = ad7879_write(ts, AD7879_REG_CTRL2, AD7879_RESET);
496
497 if (err < 0) { 531 if (err < 0) {
498 dev_err(&bus->dev, "Failed to write %s\n", input_dev->name); 532 dev_err(dev, "Failed to write %s\n", input_dev->name);
499 goto err_free_mem; 533 goto err_free_mem;
500 } 534 }
501 535
502 revid = ad7879_read(bus, AD7879_REG_REVID); 536 revid = ad7879_read(ts, AD7879_REG_REVID);
503 537 input_dev->id.product = (revid & 0xff);
504 if ((revid & 0xFF) != AD7879_DEVID) { 538 input_dev->id.version = revid >> 8;
505 dev_err(&bus->dev, "Failed to probe %s\n", input_dev->name); 539 if (input_dev->id.product != devid) {
540 dev_err(dev, "Failed to probe %s (%x vs %x)\n",
541 input_dev->name, devid, revid);
506 err = -ENODEV; 542 err = -ENODEV;
507 goto err_free_mem; 543 goto err_free_mem;
508 } 544 }
@@ -524,21 +560,21 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
524 AD7879_ACQ(ts->acquisition_time) | 560 AD7879_ACQ(ts->acquisition_time) |
525 AD7879_TMR(ts->pen_down_acc_interval); 561 AD7879_TMR(ts->pen_down_acc_interval);
526 562
527 ad7879_setup(ts); 563 err = request_threaded_irq(ts->irq, NULL, ad7879_irq,
528 564 IRQF_TRIGGER_FALLING,
529 err = request_irq(bus->irq, ad7879_irq, 565 dev_name(dev), ts);
530 IRQF_TRIGGER_FALLING, bus->dev.driver->name, ts);
531
532 if (err) { 566 if (err) {
533 dev_err(&bus->dev, "irq %d busy?\n", bus->irq); 567 dev_err(dev, "irq %d busy?\n", ts->irq);
534 goto err_free_mem; 568 goto err_free_mem;
535 } 569 }
536 570
537 err = sysfs_create_group(&bus->dev.kobj, &ad7879_attr_group); 571 __ad7879_disable(ts);
572
573 err = sysfs_create_group(&dev->kobj, &ad7879_attr_group);
538 if (err) 574 if (err)
539 goto err_free_irq; 575 goto err_free_irq;
540 576
541 err = ad7879_gpio_add(&bus->dev); 577 err = ad7879_gpio_add(ts, pdata);
542 if (err) 578 if (err)
543 goto err_remove_attr; 579 goto err_remove_attr;
544 580
@@ -546,324 +582,32 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
546 if (err) 582 if (err)
547 goto err_remove_gpio; 583 goto err_remove_gpio;
548 584
549 dev_info(&bus->dev, "Rev.%d touchscreen, irq %d\n", 585 return ts;
550 revid >> 8, bus->irq);
551
552 return 0;
553 586
554err_remove_gpio: 587err_remove_gpio:
555 ad7879_gpio_remove(&bus->dev); 588 ad7879_gpio_remove(ts);
556err_remove_attr: 589err_remove_attr:
557 sysfs_remove_group(&bus->dev.kobj, &ad7879_attr_group); 590 sysfs_remove_group(&dev->kobj, &ad7879_attr_group);
558err_free_irq: 591err_free_irq:
559 free_irq(bus->irq, ts); 592 free_irq(ts->irq, ts);
560err_free_mem: 593err_free_mem:
561 input_free_device(input_dev); 594 input_free_device(input_dev);
562
563 return err;
564}
565
566static int __devexit ad7879_destroy(bus_device *bus, struct ad7879 *ts)
567{
568 ad7879_gpio_remove(&bus->dev);
569 ad7879_disable(ts);
570 sysfs_remove_group(&ts->bus->dev.kobj, &ad7879_attr_group);
571 free_irq(ts->bus->irq, ts);
572 input_unregister_device(ts->input);
573 dev_dbg(&bus->dev, "unregistered touchscreen\n");
574
575 return 0;
576}
577
578#ifdef CONFIG_PM
579static int ad7879_suspend(bus_device *bus, pm_message_t message)
580{
581 struct ad7879 *ts = dev_get_drvdata(&bus->dev);
582
583 ad7879_disable(ts);
584
585 return 0;
586}
587
588static int ad7879_resume(bus_device *bus)
589{
590 struct ad7879 *ts = dev_get_drvdata(&bus->dev);
591
592 ad7879_enable(ts);
593
594 return 0;
595}
596#else
597#define ad7879_suspend NULL
598#define ad7879_resume NULL
599#endif
600
601#if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE)
602#define MAX_SPI_FREQ_HZ 5000000
603#define AD7879_CMD_MAGIC 0xE000
604#define AD7879_CMD_READ (1 << 10)
605#define AD7879_WRITECMD(reg) (AD7879_CMD_MAGIC | (reg & 0xF))
606#define AD7879_READCMD(reg) (AD7879_CMD_MAGIC | AD7879_CMD_READ | (reg & 0xF))
607
608struct ser_req {
609 u16 command;
610 u16 data;
611 struct spi_message msg;
612 struct spi_transfer xfer[2];
613};
614
615/*
616 * ad7879_read/write are only used for initial setup and for sysfs controls.
617 * The main traffic is done in ad7879_collect().
618 */
619
620static int ad7879_read(struct spi_device *spi, u8 reg)
621{
622 struct ser_req *req;
623 int status, ret;
624
625 req = kzalloc(sizeof *req, GFP_KERNEL);
626 if (!req)
627 return -ENOMEM;
628
629 spi_message_init(&req->msg);
630
631 req->command = (u16) AD7879_READCMD(reg);
632 req->xfer[0].tx_buf = &req->command;
633 req->xfer[0].len = 2;
634
635 req->xfer[1].rx_buf = &req->data;
636 req->xfer[1].len = 2;
637
638 spi_message_add_tail(&req->xfer[0], &req->msg);
639 spi_message_add_tail(&req->xfer[1], &req->msg);
640
641 status = spi_sync(spi, &req->msg);
642 ret = status ? : req->data;
643
644 kfree(req);
645
646 return ret;
647}
648
649static int ad7879_write(struct spi_device *spi, u8 reg, u16 val)
650{
651 struct ser_req *req;
652 int status;
653
654 req = kzalloc(sizeof *req, GFP_KERNEL);
655 if (!req)
656 return -ENOMEM;
657
658 spi_message_init(&req->msg);
659
660 req->command = (u16) AD7879_WRITECMD(reg);
661 req->xfer[0].tx_buf = &req->command;
662 req->xfer[0].len = 2;
663
664 req->data = val;
665 req->xfer[1].tx_buf = &req->data;
666 req->xfer[1].len = 2;
667
668 spi_message_add_tail(&req->xfer[0], &req->msg);
669 spi_message_add_tail(&req->xfer[1], &req->msg);
670
671 status = spi_sync(spi, &req->msg);
672
673 kfree(req);
674
675 return status;
676}
677
678static void ad7879_collect(struct ad7879 *ts)
679{
680 int status = spi_sync(ts->bus, &ts->msg);
681
682 if (status)
683 dev_err(&ts->bus->dev, "spi_sync --> %d\n", status);
684}
685
686static void ad7879_setup_ts_def_msg(struct ad7879 *ts)
687{
688 struct spi_message *m;
689 int i;
690
691 ts->cmd = (u16) AD7879_READCMD(AD7879_REG_XPLUS);
692
693 m = &ts->msg;
694 spi_message_init(m);
695 ts->xfer[0].tx_buf = &ts->cmd;
696 ts->xfer[0].len = 2;
697
698 spi_message_add_tail(&ts->xfer[0], m);
699
700 for (i = 0; i < AD7879_NR_SENSE; i++) {
701 ts->xfer[i + 1].rx_buf = &ts->conversion_data[i];
702 ts->xfer[i + 1].len = 2;
703 spi_message_add_tail(&ts->xfer[i + 1], m);
704 }
705}
706
707static int __devinit ad7879_probe(struct spi_device *spi)
708{
709 struct ad7879 *ts;
710 int error;
711
712 /* don't exceed max specified SPI CLK frequency */
713 if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
714 dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz);
715 return -EINVAL;
716 }
717
718 ts = kzalloc(sizeof(struct ad7879), GFP_KERNEL);
719 if (!ts)
720 return -ENOMEM;
721
722 dev_set_drvdata(&spi->dev, ts);
723 ts->bus = spi;
724
725 ad7879_setup_ts_def_msg(ts);
726
727 error = ad7879_construct(spi, ts);
728 if (error) {
729 dev_set_drvdata(&spi->dev, NULL);
730 kfree(ts);
731 }
732
733 return error;
734}
735
736static int __devexit ad7879_remove(struct spi_device *spi)
737{
738 struct ad7879 *ts = dev_get_drvdata(&spi->dev);
739
740 ad7879_destroy(spi, ts);
741 dev_set_drvdata(&spi->dev, NULL);
742 kfree(ts); 595 kfree(ts);
743 596err_out:
744 return 0; 597 return ERR_PTR(err);
745} 598}
599EXPORT_SYMBOL(ad7879_probe);
746 600
747static struct spi_driver ad7879_driver = { 601void ad7879_remove(struct ad7879 *ts)
748 .driver = {
749 .name = "ad7879",
750 .bus = &spi_bus_type,
751 .owner = THIS_MODULE,
752 },
753 .probe = ad7879_probe,
754 .remove = __devexit_p(ad7879_remove),
755 .suspend = ad7879_suspend,
756 .resume = ad7879_resume,
757};
758
759static int __init ad7879_init(void)
760{
761 return spi_register_driver(&ad7879_driver);
762}
763module_init(ad7879_init);
764
765static void __exit ad7879_exit(void)
766{
767 spi_unregister_driver(&ad7879_driver);
768}
769module_exit(ad7879_exit);
770
771#elif defined(CONFIG_TOUCHSCREEN_AD7879_I2C) || defined(CONFIG_TOUCHSCREEN_AD7879_I2C_MODULE)
772
773/* All registers are word-sized.
774 * AD7879 uses a high-byte first convention.
775 */
776static int ad7879_read(struct i2c_client *client, u8 reg)
777{ 602{
778 return swab16(i2c_smbus_read_word_data(client, reg)); 603 ad7879_gpio_remove(ts);
779} 604 sysfs_remove_group(&ts->dev->kobj, &ad7879_attr_group);
780 605 free_irq(ts->irq, ts);
781static int ad7879_write(struct i2c_client *client, u8 reg, u16 val) 606 input_unregister_device(ts->input);
782{
783 return i2c_smbus_write_word_data(client, reg, swab16(val));
784}
785
786static void ad7879_collect(struct ad7879 *ts)
787{
788 int i;
789
790 for (i = 0; i < AD7879_NR_SENSE; i++)
791 ts->conversion_data[i] = ad7879_read(ts->bus,
792 AD7879_REG_XPLUS + i);
793}
794
795static int __devinit ad7879_probe(struct i2c_client *client,
796 const struct i2c_device_id *id)
797{
798 struct ad7879 *ts;
799 int error;
800
801 if (!i2c_check_functionality(client->adapter,
802 I2C_FUNC_SMBUS_WORD_DATA)) {
803 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
804 return -EIO;
805 }
806
807 ts = kzalloc(sizeof(struct ad7879), GFP_KERNEL);
808 if (!ts)
809 return -ENOMEM;
810
811 i2c_set_clientdata(client, ts);
812 ts->bus = client;
813
814 error = ad7879_construct(client, ts);
815 if (error) {
816 i2c_set_clientdata(client, NULL);
817 kfree(ts);
818 }
819
820 return error;
821}
822
823static int __devexit ad7879_remove(struct i2c_client *client)
824{
825 struct ad7879 *ts = dev_get_drvdata(&client->dev);
826
827 ad7879_destroy(client, ts);
828 i2c_set_clientdata(client, NULL);
829 kfree(ts); 607 kfree(ts);
830
831 return 0;
832}
833
834static const struct i2c_device_id ad7879_id[] = {
835 { "ad7879", 0 },
836 { "ad7889", 0 },
837 { }
838};
839MODULE_DEVICE_TABLE(i2c, ad7879_id);
840
841static struct i2c_driver ad7879_driver = {
842 .driver = {
843 .name = "ad7879",
844 .owner = THIS_MODULE,
845 },
846 .probe = ad7879_probe,
847 .remove = __devexit_p(ad7879_remove),
848 .suspend = ad7879_suspend,
849 .resume = ad7879_resume,
850 .id_table = ad7879_id,
851};
852
853static int __init ad7879_init(void)
854{
855 return i2c_add_driver(&ad7879_driver);
856}
857module_init(ad7879_init);
858
859static void __exit ad7879_exit(void)
860{
861 i2c_del_driver(&ad7879_driver);
862} 608}
863module_exit(ad7879_exit); 609EXPORT_SYMBOL(ad7879_remove);
864#endif
865 610
866MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 611MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
867MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver"); 612MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver");
868MODULE_LICENSE("GPL"); 613MODULE_LICENSE("GPL");
869MODULE_ALIAS("spi:ad7879");
diff --git a/drivers/input/touchscreen/ad7879.h b/drivers/input/touchscreen/ad7879.h
new file mode 100644
index 000000000000..6b45a27236c7
--- /dev/null
+++ b/drivers/input/touchscreen/ad7879.h
@@ -0,0 +1,30 @@
1/*
2 * AD7879/AD7889 touchscreen (bus interfaces)
3 *
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef _AD7879_H_
10#define _AD7879_H_
11
12#include <linux/types.h>
13
14struct ad7879;
15struct device;
16
17struct ad7879_bus_ops {
18 u16 bustype;
19 int (*read)(struct device *dev, u8 reg);
20 int (*multi_read)(struct device *dev, u8 first_reg, u8 count, u16 *buf);
21 int (*write)(struct device *dev, u8 reg, u16 val);
22};
23
24void ad7879_suspend(struct ad7879 *);
25void ad7879_resume(struct ad7879 *);
26struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned irq,
27 const struct ad7879_bus_ops *bops);
28void ad7879_remove(struct ad7879 *);
29
30#endif
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 634f6f6b9b13..16031933a8f6 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -68,6 +68,8 @@ struct ts_event {
68 u16 y; 68 u16 y;
69 u16 z1, z2; 69 u16 z1, z2;
70 int ignore; 70 int ignore;
71 u8 x_buf[3];
72 u8 y_buf[3];
71}; 73};
72 74
73/* 75/*
@@ -79,6 +81,8 @@ struct ads7846_packet {
79 u8 read_x, read_y, read_z1, read_z2, pwrdown; 81 u8 read_x, read_y, read_z1, read_z2, pwrdown;
80 u16 dummy; /* for the pwrdown read */ 82 u16 dummy; /* for the pwrdown read */
81 struct ts_event tc; 83 struct ts_event tc;
84 /* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
85 u8 read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
82}; 86};
83 87
84struct ads7846 { 88struct ads7846 {
@@ -207,6 +211,14 @@ struct ser_req {
207 struct spi_transfer xfer[6]; 211 struct spi_transfer xfer[6];
208}; 212};
209 213
214struct ads7845_ser_req {
215 u8 command[3];
216 u8 pwrdown[3];
217 u8 sample[3];
218 struct spi_message msg;
219 struct spi_transfer xfer[2];
220};
221
210static void ads7846_enable(struct ads7846 *ts); 222static void ads7846_enable(struct ads7846 *ts);
211static void ads7846_disable(struct ads7846 *ts); 223static void ads7846_disable(struct ads7846 *ts);
212 224
@@ -287,6 +299,41 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
287 return status; 299 return status;
288} 300}
289 301
302static int ads7845_read12_ser(struct device *dev, unsigned command)
303{
304 struct spi_device *spi = to_spi_device(dev);
305 struct ads7846 *ts = dev_get_drvdata(dev);
306 struct ads7845_ser_req *req = kzalloc(sizeof *req, GFP_KERNEL);
307 int status;
308
309 if (!req)
310 return -ENOMEM;
311
312 spi_message_init(&req->msg);
313
314 req->command[0] = (u8) command;
315 req->xfer[0].tx_buf = req->command;
316 req->xfer[0].rx_buf = req->sample;
317 req->xfer[0].len = 3;
318 spi_message_add_tail(&req->xfer[0], &req->msg);
319
320 ts->irq_disabled = 1;
321 disable_irq(spi->irq);
322 status = spi_sync(spi, &req->msg);
323 ts->irq_disabled = 0;
324 enable_irq(spi->irq);
325
326 if (status == 0) {
327 /* BE12 value, then padding */
328 status = be16_to_cpu(*((u16 *)&req->sample[1]));
329 status = status >> 3;
330 status &= 0x0fff;
331 }
332
333 kfree(req);
334 return status;
335}
336
290#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) 337#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
291 338
292#define SHOW(name, var, adjust) static ssize_t \ 339#define SHOW(name, var, adjust) static ssize_t \
@@ -540,10 +587,17 @@ static void ads7846_rx(void *ads)
540 /* ads7846_rx_val() did in-place conversion (including byteswap) from 587 /* ads7846_rx_val() did in-place conversion (including byteswap) from
541 * on-the-wire format as part of debouncing to get stable readings. 588 * on-the-wire format as part of debouncing to get stable readings.
542 */ 589 */
543 x = packet->tc.x; 590 if (ts->model == 7845) {
544 y = packet->tc.y; 591 x = *(u16 *)packet->tc.x_buf;
545 z1 = packet->tc.z1; 592 y = *(u16 *)packet->tc.y_buf;
546 z2 = packet->tc.z2; 593 z1 = 0;
594 z2 = 0;
595 } else {
596 x = packet->tc.x;
597 y = packet->tc.y;
598 z1 = packet->tc.z1;
599 z2 = packet->tc.z2;
600 }
547 601
548 /* range filtering */ 602 /* range filtering */
549 if (x == MAX_12BIT) 603 if (x == MAX_12BIT)
@@ -551,6 +605,12 @@ static void ads7846_rx(void *ads)
551 605
552 if (ts->model == 7843) { 606 if (ts->model == 7843) {
553 Rt = ts->pressure_max / 2; 607 Rt = ts->pressure_max / 2;
608 } else if (ts->model == 7845) {
609 if (get_pendown_state(ts))
610 Rt = ts->pressure_max / 2;
611 else
612 Rt = 0;
613 dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt);
554 } else if (likely(x && z1)) { 614 } else if (likely(x && z1)) {
555 /* compute touch pressure resistance using equation #2 */ 615 /* compute touch pressure resistance using equation #2 */
556 Rt = z2; 616 Rt = z2;
@@ -671,10 +731,14 @@ static void ads7846_rx_val(void *ads)
671 m = &ts->msg[ts->msg_idx]; 731 m = &ts->msg[ts->msg_idx];
672 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); 732 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
673 733
674 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; 734 if (ts->model == 7845) {
675 * built from two 8 bit values written msb-first. 735 val = be16_to_cpup((__be16 *)&(((char*)t->rx_buf)[1])) >> 3;
676 */ 736 } else {
677 val = be16_to_cpup((__be16 *)t->rx_buf) >> 3; 737 /* adjust: on-wire is a must-ignore bit, a BE12 value, then
738 * padding; built from two 8 bit values written msb-first.
739 */
740 val = be16_to_cpup((__be16 *)t->rx_buf) >> 3;
741 }
678 742
679 action = ts->filter(ts->filter_data, ts->msg_idx, &val); 743 action = ts->filter(ts->filter_data, ts->msg_idx, &val);
680 switch (action) { 744 switch (action) {
@@ -878,14 +942,15 @@ static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts)
878 942
879static int __devinit ads7846_probe(struct spi_device *spi) 943static int __devinit ads7846_probe(struct spi_device *spi)
880{ 944{
881 struct ads7846 *ts; 945 struct ads7846 *ts;
882 struct ads7846_packet *packet; 946 struct ads7846_packet *packet;
883 struct input_dev *input_dev; 947 struct input_dev *input_dev;
884 struct ads7846_platform_data *pdata = spi->dev.platform_data; 948 const struct ads7846_platform_data *pdata = spi->dev.platform_data;
885 struct spi_message *m; 949 struct spi_message *m;
886 struct spi_transfer *x; 950 struct spi_transfer *x;
887 int vref; 951 unsigned long irq_flags;
888 int err; 952 int vref;
953 int err;
889 954
890 if (!spi->irq) { 955 if (!spi->irq) {
891 dev_dbg(&spi->dev, "no IRQ?\n"); 956 dev_dbg(&spi->dev, "no IRQ?\n");
@@ -1008,16 +1073,26 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1008 1073
1009 spi_message_init(m); 1074 spi_message_init(m);
1010 1075
1011 /* y- still on; turn on only y+ (and ADC) */ 1076 if (ts->model == 7845) {
1012 packet->read_y = READ_Y(vref); 1077 packet->read_y_cmd[0] = READ_Y(vref);
1013 x->tx_buf = &packet->read_y; 1078 packet->read_y_cmd[1] = 0;
1014 x->len = 1; 1079 packet->read_y_cmd[2] = 0;
1015 spi_message_add_tail(x, m); 1080 x->tx_buf = &packet->read_y_cmd[0];
1081 x->rx_buf = &packet->tc.y_buf[0];
1082 x->len = 3;
1083 spi_message_add_tail(x, m);
1084 } else {
1085 /* y- still on; turn on only y+ (and ADC) */
1086 packet->read_y = READ_Y(vref);
1087 x->tx_buf = &packet->read_y;
1088 x->len = 1;
1089 spi_message_add_tail(x, m);
1016 1090
1017 x++; 1091 x++;
1018 x->rx_buf = &packet->tc.y; 1092 x->rx_buf = &packet->tc.y;
1019 x->len = 2; 1093 x->len = 2;
1020 spi_message_add_tail(x, m); 1094 spi_message_add_tail(x, m);
1095 }
1021 1096
1022 /* the first sample after switching drivers can be low quality; 1097 /* the first sample after switching drivers can be low quality;
1023 * optionally discard it, using a second one after the signals 1098 * optionally discard it, using a second one after the signals
@@ -1043,17 +1118,28 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1043 m++; 1118 m++;
1044 spi_message_init(m); 1119 spi_message_init(m);
1045 1120
1046 /* turn y- off, x+ on, then leave in lowpower */ 1121 if (ts->model == 7845) {
1047 x++; 1122 x++;
1048 packet->read_x = READ_X(vref); 1123 packet->read_x_cmd[0] = READ_X(vref);
1049 x->tx_buf = &packet->read_x; 1124 packet->read_x_cmd[1] = 0;
1050 x->len = 1; 1125 packet->read_x_cmd[2] = 0;
1051 spi_message_add_tail(x, m); 1126 x->tx_buf = &packet->read_x_cmd[0];
1127 x->rx_buf = &packet->tc.x_buf[0];
1128 x->len = 3;
1129 spi_message_add_tail(x, m);
1130 } else {
1131 /* turn y- off, x+ on, then leave in lowpower */
1132 x++;
1133 packet->read_x = READ_X(vref);
1134 x->tx_buf = &packet->read_x;
1135 x->len = 1;
1136 spi_message_add_tail(x, m);
1052 1137
1053 x++; 1138 x++;
1054 x->rx_buf = &packet->tc.x; 1139 x->rx_buf = &packet->tc.x;
1055 x->len = 2; 1140 x->len = 2;
1056 spi_message_add_tail(x, m); 1141 spi_message_add_tail(x, m);
1142 }
1057 1143
1058 /* ... maybe discard first sample ... */ 1144 /* ... maybe discard first sample ... */
1059 if (pdata->settle_delay_usecs) { 1145 if (pdata->settle_delay_usecs) {
@@ -1144,15 +1230,25 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1144 m++; 1230 m++;
1145 spi_message_init(m); 1231 spi_message_init(m);
1146 1232
1147 x++; 1233 if (ts->model == 7845) {
1148 packet->pwrdown = PWRDOWN; 1234 x++;
1149 x->tx_buf = &packet->pwrdown; 1235 packet->pwrdown_cmd[0] = PWRDOWN;
1150 x->len = 1; 1236 packet->pwrdown_cmd[1] = 0;
1151 spi_message_add_tail(x, m); 1237 packet->pwrdown_cmd[2] = 0;
1238 x->tx_buf = &packet->pwrdown_cmd[0];
1239 x->len = 3;
1240 } else {
1241 x++;
1242 packet->pwrdown = PWRDOWN;
1243 x->tx_buf = &packet->pwrdown;
1244 x->len = 1;
1245 spi_message_add_tail(x, m);
1246
1247 x++;
1248 x->rx_buf = &packet->dummy;
1249 x->len = 2;
1250 }
1152 1251
1153 x++;
1154 x->rx_buf = &packet->dummy;
1155 x->len = 2;
1156 CS_CHANGE(*x); 1252 CS_CHANGE(*x);
1157 spi_message_add_tail(x, m); 1253 spi_message_add_tail(x, m);
1158 1254
@@ -1164,7 +1260,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1164 ts->reg = regulator_get(&spi->dev, "vcc"); 1260 ts->reg = regulator_get(&spi->dev, "vcc");
1165 if (IS_ERR(ts->reg)) { 1261 if (IS_ERR(ts->reg)) {
1166 err = PTR_ERR(ts->reg); 1262 err = PTR_ERR(ts->reg);
1167 dev_err(&spi->dev, "unable to get regulator: %ld\n", err); 1263 dev_err(&spi->dev, "unable to get regulator: %d\n", err);
1168 goto err_free_gpio; 1264 goto err_free_gpio;
1169 } 1265 }
1170 1266
@@ -1174,17 +1270,22 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1174 goto err_put_regulator; 1270 goto err_put_regulator;
1175 } 1271 }
1176 1272
1177 if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING, 1273 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING;
1178 spi->dev.driver->name, ts)) { 1274
1275 err = request_irq(spi->irq, ads7846_irq, irq_flags,
1276 spi->dev.driver->name, ts);
1277
1278 if (err && !pdata->irq_flags) {
1179 dev_info(&spi->dev, 1279 dev_info(&spi->dev,
1180 "trying pin change workaround on irq %d\n", spi->irq); 1280 "trying pin change workaround on irq %d\n", spi->irq);
1181 err = request_irq(spi->irq, ads7846_irq, 1281 err = request_irq(spi->irq, ads7846_irq,
1182 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 1282 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
1183 spi->dev.driver->name, ts); 1283 spi->dev.driver->name, ts);
1184 if (err) { 1284 }
1185 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 1285
1186 goto err_disable_regulator; 1286 if (err) {
1187 } 1287 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
1288 goto err_disable_regulator;
1188 } 1289 }
1189 1290
1190 err = ads784x_hwmon_register(spi, ts); 1291 err = ads784x_hwmon_register(spi, ts);
@@ -1196,8 +1297,11 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1196 /* take a first sample, leaving nPENIRQ active and vREF off; avoid 1297 /* take a first sample, leaving nPENIRQ active and vREF off; avoid
1197 * the touchscreen, in case it's not connected. 1298 * the touchscreen, in case it's not connected.
1198 */ 1299 */
1199 (void) ads7846_read12_ser(&spi->dev, 1300 if (ts->model == 7845)
1200 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); 1301 ads7845_read12_ser(&spi->dev, PWRDOWN);
1302 else
1303 (void) ads7846_read12_ser(&spi->dev,
1304 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
1201 1305
1202 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); 1306 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group);
1203 if (err) 1307 if (err)
diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c
new file mode 100644
index 000000000000..5ec0946938fe
--- /dev/null
+++ b/drivers/input/touchscreen/cy8ctmg110_ts.c
@@ -0,0 +1,363 @@
1/*
2 * Driver for cypress touch screen controller
3 *
4 * Copyright (c) 2009 Aava Mobile
5 *
6 * Some cleanups by Alan Cox <alan@linux.intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/input.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/io.h>
28#include <linux/i2c.h>
29#include <linux/gpio.h>
30#include <linux/input/cy8ctmg110_pdata.h>
31
32#define CY8CTMG110_DRIVER_NAME "cy8ctmg110"
33
34/* Touch coordinates */
35#define CY8CTMG110_X_MIN 0
36#define CY8CTMG110_Y_MIN 0
37#define CY8CTMG110_X_MAX 759
38#define CY8CTMG110_Y_MAX 465
39
40
41/* cy8ctmg110 register definitions */
42#define CY8CTMG110_TOUCH_WAKEUP_TIME 0
43#define CY8CTMG110_TOUCH_SLEEP_TIME 2
44#define CY8CTMG110_TOUCH_X1 3
45#define CY8CTMG110_TOUCH_Y1 5
46#define CY8CTMG110_TOUCH_X2 7
47#define CY8CTMG110_TOUCH_Y2 9
48#define CY8CTMG110_FINGERS 11
49#define CY8CTMG110_GESTURE 12
50#define CY8CTMG110_REG_MAX 13
51
52
53/*
54 * The touch driver structure.
55 */
56struct cy8ctmg110 {
57 struct input_dev *input;
58 char phys[32];
59 struct i2c_client *client;
60 int reset_pin;
61 int irq_pin;
62};
63
64/*
65 * cy8ctmg110_power is the routine that is called when touch hardware
66 * will powered off or on.
67 */
68static void cy8ctmg110_power(struct cy8ctmg110 *ts, bool poweron)
69{
70 if (ts->reset_pin)
71 gpio_direction_output(ts->reset_pin, 1 - poweron);
72}
73
74static int cy8ctmg110_write_regs(struct cy8ctmg110 *tsc, unsigned char reg,
75 unsigned char len, unsigned char *value)
76{
77 struct i2c_client *client = tsc->client;
78 int ret;
79 unsigned char i2c_data[6];
80
81 BUG_ON(len > 5);
82
83 i2c_data[0] = reg;
84 memcpy(i2c_data + 1, value, len);
85
86 ret = i2c_master_send(client, i2c_data, len + 1);
87 if (ret != 1) {
88 dev_err(&client->dev, "i2c write data cmd failed\n");
89 return ret ? ret : -EIO;
90 }
91
92 return 0;
93}
94
95static int cy8ctmg110_read_regs(struct cy8ctmg110 *tsc,
96 unsigned char *data, unsigned char len, unsigned char cmd)
97{
98 struct i2c_client *client = tsc->client;
99 int ret;
100 struct i2c_msg msg[2] = {
101 /* first write slave position to i2c devices */
102 { client->addr, 0, 1, &cmd },
103 /* Second read data from position */
104 { client->addr, I2C_M_RD, len, data }
105 };
106
107 ret = i2c_transfer(client->adapter, msg, 2);
108 if (ret < 0)
109 return ret;
110
111 return 0;
112}
113
114static int cy8ctmg110_touch_pos(struct cy8ctmg110 *tsc)
115{
116 struct input_dev *input = tsc->input;
117 unsigned char reg_p[CY8CTMG110_REG_MAX];
118 int x, y;
119
120 memset(reg_p, 0, CY8CTMG110_REG_MAX);
121
122 /* Reading coordinates */
123 if (cy8ctmg110_read_regs(tsc, reg_p, 9, CY8CTMG110_TOUCH_X1) != 0)
124 return -EIO;
125
126 y = reg_p[2] << 8 | reg_p[3];
127 x = reg_p[0] << 8 | reg_p[1];
128
129 /* Number of touch */
130 if (reg_p[8] == 0) {
131 input_report_key(input, BTN_TOUCH, 0);
132 } else {
133 input_report_key(input, BTN_TOUCH, 1);
134 input_report_abs(input, ABS_X, x);
135 input_report_abs(input, ABS_Y, y);
136 }
137
138 input_sync(input);
139
140 return 0;
141}
142
143static int cy8ctmg110_set_sleepmode(struct cy8ctmg110 *ts, bool sleep)
144{
145 unsigned char reg_p[3];
146
147 if (sleep) {
148 reg_p[0] = 0x00;
149 reg_p[1] = 0xff;
150 reg_p[2] = 5;
151 } else {
152 reg_p[0] = 0x10;
153 reg_p[1] = 0xff;
154 reg_p[2] = 0;
155 }
156
157 return cy8ctmg110_write_regs(ts, CY8CTMG110_TOUCH_WAKEUP_TIME, 3, reg_p);
158}
159
160static irqreturn_t cy8ctmg110_irq_thread(int irq, void *dev_id)
161{
162 struct cy8ctmg110 *tsc = dev_id;
163
164 cy8ctmg110_touch_pos(tsc);
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit cy8ctmg110_probe(struct i2c_client *client,
170 const struct i2c_device_id *id)
171{
172 const struct cy8ctmg110_pdata *pdata = client->dev.platform_data;
173 struct cy8ctmg110 *ts;
174 struct input_dev *input_dev;
175 int err;
176
177 /* No pdata no way forward */
178 if (pdata == NULL) {
179 dev_err(&client->dev, "no pdata\n");
180 return -ENODEV;
181 }
182
183 if (!i2c_check_functionality(client->adapter,
184 I2C_FUNC_SMBUS_READ_WORD_DATA))
185 return -EIO;
186
187 ts = kzalloc(sizeof(struct cy8ctmg110), GFP_KERNEL);
188 input_dev = input_allocate_device();
189 if (!ts || !input_dev) {
190 err = -ENOMEM;
191 goto err_free_mem;
192 }
193
194 ts->client = client;
195 ts->input = input_dev;
196
197 snprintf(ts->phys, sizeof(ts->phys),
198 "%s/input0", dev_name(&client->dev));
199
200 input_dev->name = CY8CTMG110_DRIVER_NAME " Touchscreen";
201 input_dev->phys = ts->phys;
202 input_dev->id.bustype = BUS_I2C;
203 input_dev->dev.parent = &client->dev;
204
205 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
206 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
207
208 input_set_abs_params(input_dev, ABS_X,
209 CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 0, 0);
210 input_set_abs_params(input_dev, ABS_Y,
211 CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 0, 0);
212
213 if (ts->reset_pin) {
214 err = gpio_request(ts->reset_pin, NULL);
215 if (err) {
216 dev_err(&client->dev,
217 "Unable to request GPIO pin %d.\n",
218 ts->reset_pin);
219 goto err_free_mem;
220 }
221 }
222
223 cy8ctmg110_power(ts, true);
224 cy8ctmg110_set_sleepmode(ts, false);
225
226 err = gpio_request(ts->irq_pin, "touch_irq_key");
227 if (err < 0) {
228 dev_err(&client->dev,
229 "Failed to request GPIO %d, error %d\n",
230 ts->irq_pin, err);
231 goto err_shutoff_device;
232 }
233
234 err = gpio_direction_input(ts->irq_pin);
235 if (err < 0) {
236 dev_err(&client->dev,
237 "Failed to configure input direction for GPIO %d, error %d\n",
238 ts->irq_pin, err);
239 goto err_free_irq_gpio;
240 }
241
242 client->irq = gpio_to_irq(ts->irq_pin);
243 if (client->irq < 0) {
244 err = client->irq;
245 dev_err(&client->dev,
246 "Unable to get irq number for GPIO %d, error %d\n",
247 ts->irq_pin, err);
248 goto err_free_irq_gpio;
249 }
250
251 err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread,
252 IRQF_TRIGGER_RISING, "touch_reset_key", ts);
253 if (err < 0) {
254 dev_err(&client->dev,
255 "irq %d busy? error %d\n", client->irq, err);
256 goto err_free_irq_gpio;
257 }
258
259 err = input_register_device(input_dev);
260 if (err)
261 goto err_free_irq;
262
263 i2c_set_clientdata(client, ts);
264 device_init_wakeup(&client->dev, 1);
265 return 0;
266
267err_free_irq:
268 free_irq(client->irq, ts);
269err_free_irq_gpio:
270 gpio_free(ts->irq_pin);
271err_shutoff_device:
272 cy8ctmg110_set_sleepmode(ts, true);
273 cy8ctmg110_power(ts, false);
274 if (ts->reset_pin)
275 gpio_free(ts->reset_pin);
276err_free_mem:
277 input_free_device(input_dev);
278 kfree(ts);
279 return err;
280}
281
282#ifdef CONFIG_PM
283static int cy8ctmg110_suspend(struct i2c_client *client, pm_message_t mesg)
284{
285 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
286
287 if (device_may_wakeup(&client->dev))
288 enable_irq_wake(client->irq);
289 else {
290 cy8ctmg110_set_sleepmode(ts, true);
291 cy8ctmg110_power(ts, false);
292 }
293 return 0;
294}
295
296static int cy8ctmg110_resume(struct i2c_client *client)
297{
298 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
299
300 if (device_may_wakeup(&client->dev))
301 disable_irq_wake(client->irq);
302 else {
303 cy8ctmg110_power(ts, true);
304 cy8ctmg110_set_sleepmode(ts, false);
305 }
306 return 0;
307}
308#endif
309
310static int __devexit cy8ctmg110_remove(struct i2c_client *client)
311{
312 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
313
314 cy8ctmg110_set_sleepmode(ts, true);
315 cy8ctmg110_power(ts, false);
316
317 free_irq(client->irq, ts);
318 input_unregister_device(ts->input);
319 gpio_free(ts->irq_pin);
320 if (ts->reset_pin)
321 gpio_free(ts->reset_pin);
322 kfree(ts);
323
324 return 0;
325}
326
327static struct i2c_device_id cy8ctmg110_idtable[] = {
328 { CY8CTMG110_DRIVER_NAME, 1 },
329 { }
330};
331
332MODULE_DEVICE_TABLE(i2c, cy8ctmg110_idtable);
333
334static struct i2c_driver cy8ctmg110_driver = {
335 .driver = {
336 .owner = THIS_MODULE,
337 .name = CY8CTMG110_DRIVER_NAME,
338 },
339 .id_table = cy8ctmg110_idtable,
340 .probe = cy8ctmg110_probe,
341 .remove = __devexit_p(cy8ctmg110_remove),
342#ifdef CONFIG_PM
343 .suspend = cy8ctmg110_suspend,
344 .resume = cy8ctmg110_resume,
345#endif
346};
347
348static int __init cy8ctmg110_init(void)
349{
350 return i2c_add_driver(&cy8ctmg110_driver);
351}
352
353static void __exit cy8ctmg110_exit(void)
354{
355 i2c_del_driver(&cy8ctmg110_driver);
356}
357
358module_init(cy8ctmg110_init);
359module_exit(cy8ctmg110_exit);
360
361MODULE_AUTHOR("Samuli Konttila <samuli.konttila@aavamobile.com>");
362MODULE_DESCRIPTION("cy8ctmg110 TouchScreen Driver");
363MODULE_LICENSE("GPL v2");
diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c
index 75f8b73010fa..7a3a916f84a8 100644
--- a/drivers/input/touchscreen/eeti_ts.c
+++ b/drivers/input/touchscreen/eeti_ts.c
@@ -238,7 +238,6 @@ err2:
238 input = NULL; /* so we dont try to free it below */ 238 input = NULL; /* so we dont try to free it below */
239err1: 239err1:
240 input_free_device(input); 240 input_free_device(input);
241 i2c_set_clientdata(client, NULL);
242 kfree(priv); 241 kfree(priv);
243err0: 242err0:
244 return err; 243 return err;
@@ -256,7 +255,6 @@ static int __devexit eeti_ts_remove(struct i2c_client *client)
256 enable_irq(priv->irq); 255 enable_irq(priv->irq);
257 256
258 input_unregister_device(priv->input); 257 input_unregister_device(priv->input);
259 i2c_set_clientdata(client, NULL);
260 kfree(priv); 258 kfree(priv);
261 259
262 return 0; 260 return 0;
diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c
index ce8ab0269f6f..6ee9940aaf5b 100644
--- a/drivers/input/touchscreen/mcs5000_ts.c
+++ b/drivers/input/touchscreen/mcs5000_ts.c
@@ -16,7 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/i2c/mcs5000_ts.h> 19#include <linux/i2c/mcs.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/input.h> 21#include <linux/input.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
@@ -105,7 +105,7 @@ enum mcs5000_ts_read_offset {
105struct mcs5000_ts_data { 105struct mcs5000_ts_data {
106 struct i2c_client *client; 106 struct i2c_client *client;
107 struct input_dev *input_dev; 107 struct input_dev *input_dev;
108 const struct mcs5000_ts_platform_data *platform_data; 108 const struct mcs_platform_data *platform_data;
109}; 109};
110 110
111static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id) 111static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
@@ -164,7 +164,7 @@ static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
164 164
165static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data) 165static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data)
166{ 166{
167 const struct mcs5000_ts_platform_data *platform_data = 167 const struct mcs_platform_data *platform_data =
168 data->platform_data; 168 data->platform_data;
169 struct i2c_client *client = data->client; 169 struct i2c_client *client = data->client;
170 170
@@ -256,7 +256,6 @@ static int __devexit mcs5000_ts_remove(struct i2c_client *client)
256 free_irq(client->irq, data); 256 free_irq(client->irq, data);
257 input_unregister_device(data->input_dev); 257 input_unregister_device(data->input_dev);
258 kfree(data); 258 kfree(data);
259 i2c_set_clientdata(client, NULL);
260 259
261 return 0; 260 return 0;
262} 261}
diff --git a/drivers/input/touchscreen/qt602240_ts.c b/drivers/input/touchscreen/qt602240_ts.c
new file mode 100644
index 000000000000..66b26ad3032a
--- /dev/null
+++ b/drivers/input/touchscreen/qt602240_ts.c
@@ -0,0 +1,1401 @@
1/*
2 * AT42QT602240/ATMXT224 Touchscreen driver
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/firmware.h>
18#include <linux/i2c.h>
19#include <linux/i2c/qt602240_ts.h>
20#include <linux/input.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
23
24/* Version */
25#define QT602240_VER_20 20
26#define QT602240_VER_21 21
27#define QT602240_VER_22 22
28
29/* Slave addresses */
30#define QT602240_APP_LOW 0x4a
31#define QT602240_APP_HIGH 0x4b
32#define QT602240_BOOT_LOW 0x24
33#define QT602240_BOOT_HIGH 0x25
34
35/* Firmware */
36#define QT602240_FW_NAME "qt602240.fw"
37
38/* Registers */
39#define QT602240_FAMILY_ID 0x00
40#define QT602240_VARIANT_ID 0x01
41#define QT602240_VERSION 0x02
42#define QT602240_BUILD 0x03
43#define QT602240_MATRIX_X_SIZE 0x04
44#define QT602240_MATRIX_Y_SIZE 0x05
45#define QT602240_OBJECT_NUM 0x06
46#define QT602240_OBJECT_START 0x07
47
48#define QT602240_OBJECT_SIZE 6
49
50/* Object types */
51#define QT602240_DEBUG_DIAGNOSTIC 37
52#define QT602240_GEN_MESSAGE 5
53#define QT602240_GEN_COMMAND 6
54#define QT602240_GEN_POWER 7
55#define QT602240_GEN_ACQUIRE 8
56#define QT602240_TOUCH_MULTI 9
57#define QT602240_TOUCH_KEYARRAY 15
58#define QT602240_TOUCH_PROXIMITY 23
59#define QT602240_PROCI_GRIPFACE 20
60#define QT602240_PROCG_NOISE 22
61#define QT602240_PROCI_ONETOUCH 24
62#define QT602240_PROCI_TWOTOUCH 27
63#define QT602240_SPT_COMMSCONFIG 18 /* firmware ver 21 over */
64#define QT602240_SPT_GPIOPWM 19
65#define QT602240_SPT_SELFTEST 25
66#define QT602240_SPT_CTECONFIG 28
67#define QT602240_SPT_USERDATA 38 /* firmware ver 21 over */
68
69/* QT602240_GEN_COMMAND field */
70#define QT602240_COMMAND_RESET 0
71#define QT602240_COMMAND_BACKUPNV 1
72#define QT602240_COMMAND_CALIBRATE 2
73#define QT602240_COMMAND_REPORTALL 3
74#define QT602240_COMMAND_DIAGNOSTIC 5
75
76/* QT602240_GEN_POWER field */
77#define QT602240_POWER_IDLEACQINT 0
78#define QT602240_POWER_ACTVACQINT 1
79#define QT602240_POWER_ACTV2IDLETO 2
80
81/* QT602240_GEN_ACQUIRE field */
82#define QT602240_ACQUIRE_CHRGTIME 0
83#define QT602240_ACQUIRE_TCHDRIFT 2
84#define QT602240_ACQUIRE_DRIFTST 3
85#define QT602240_ACQUIRE_TCHAUTOCAL 4
86#define QT602240_ACQUIRE_SYNC 5
87#define QT602240_ACQUIRE_ATCHCALST 6
88#define QT602240_ACQUIRE_ATCHCALSTHR 7
89
90/* QT602240_TOUCH_MULTI field */
91#define QT602240_TOUCH_CTRL 0
92#define QT602240_TOUCH_XORIGIN 1
93#define QT602240_TOUCH_YORIGIN 2
94#define QT602240_TOUCH_XSIZE 3
95#define QT602240_TOUCH_YSIZE 4
96#define QT602240_TOUCH_BLEN 6
97#define QT602240_TOUCH_TCHTHR 7
98#define QT602240_TOUCH_TCHDI 8
99#define QT602240_TOUCH_ORIENT 9
100#define QT602240_TOUCH_MOVHYSTI 11
101#define QT602240_TOUCH_MOVHYSTN 12
102#define QT602240_TOUCH_NUMTOUCH 14
103#define QT602240_TOUCH_MRGHYST 15
104#define QT602240_TOUCH_MRGTHR 16
105#define QT602240_TOUCH_AMPHYST 17
106#define QT602240_TOUCH_XRANGE_LSB 18
107#define QT602240_TOUCH_XRANGE_MSB 19
108#define QT602240_TOUCH_YRANGE_LSB 20
109#define QT602240_TOUCH_YRANGE_MSB 21
110#define QT602240_TOUCH_XLOCLIP 22
111#define QT602240_TOUCH_XHICLIP 23
112#define QT602240_TOUCH_YLOCLIP 24
113#define QT602240_TOUCH_YHICLIP 25
114#define QT602240_TOUCH_XEDGECTRL 26
115#define QT602240_TOUCH_XEDGEDIST 27
116#define QT602240_TOUCH_YEDGECTRL 28
117#define QT602240_TOUCH_YEDGEDIST 29
118#define QT602240_TOUCH_JUMPLIMIT 30 /* firmware ver 22 over */
119
120/* QT602240_PROCI_GRIPFACE field */
121#define QT602240_GRIPFACE_CTRL 0
122#define QT602240_GRIPFACE_XLOGRIP 1
123#define QT602240_GRIPFACE_XHIGRIP 2
124#define QT602240_GRIPFACE_YLOGRIP 3
125#define QT602240_GRIPFACE_YHIGRIP 4
126#define QT602240_GRIPFACE_MAXTCHS 5
127#define QT602240_GRIPFACE_SZTHR1 7
128#define QT602240_GRIPFACE_SZTHR2 8
129#define QT602240_GRIPFACE_SHPTHR1 9
130#define QT602240_GRIPFACE_SHPTHR2 10
131#define QT602240_GRIPFACE_SUPEXTTO 11
132
133/* QT602240_PROCI_NOISE field */
134#define QT602240_NOISE_CTRL 0
135#define QT602240_NOISE_OUTFLEN 1
136#define QT602240_NOISE_GCAFUL_LSB 3
137#define QT602240_NOISE_GCAFUL_MSB 4
138#define QT602240_NOISE_GCAFLL_LSB 5
139#define QT602240_NOISE_GCAFLL_MSB 6
140#define QT602240_NOISE_ACTVGCAFVALID 7
141#define QT602240_NOISE_NOISETHR 8
142#define QT602240_NOISE_FREQHOPSCALE 10
143#define QT602240_NOISE_FREQ0 11
144#define QT602240_NOISE_FREQ1 12
145#define QT602240_NOISE_FREQ2 13
146#define QT602240_NOISE_FREQ3 14
147#define QT602240_NOISE_FREQ4 15
148#define QT602240_NOISE_IDLEGCAFVALID 16
149
150/* QT602240_SPT_COMMSCONFIG */
151#define QT602240_COMMS_CTRL 0
152#define QT602240_COMMS_CMD 1
153
154/* QT602240_SPT_CTECONFIG field */
155#define QT602240_CTE_CTRL 0
156#define QT602240_CTE_CMD 1
157#define QT602240_CTE_MODE 2
158#define QT602240_CTE_IDLEGCAFDEPTH 3
159#define QT602240_CTE_ACTVGCAFDEPTH 4
160#define QT602240_CTE_VOLTAGE 5 /* firmware ver 21 over */
161
162#define QT602240_VOLTAGE_DEFAULT 2700000
163#define QT602240_VOLTAGE_STEP 10000
164
165/* Define for QT602240_GEN_COMMAND */
166#define QT602240_BOOT_VALUE 0xa5
167#define QT602240_BACKUP_VALUE 0x55
168#define QT602240_BACKUP_TIME 25 /* msec */
169#define QT602240_RESET_TIME 65 /* msec */
170
171#define QT602240_FWRESET_TIME 175 /* msec */
172
173/* Command to unlock bootloader */
174#define QT602240_UNLOCK_CMD_MSB 0xaa
175#define QT602240_UNLOCK_CMD_LSB 0xdc
176
177/* Bootloader mode status */
178#define QT602240_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
179#define QT602240_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
180#define QT602240_FRAME_CRC_CHECK 0x02
181#define QT602240_FRAME_CRC_FAIL 0x03
182#define QT602240_FRAME_CRC_PASS 0x04
183#define QT602240_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
184#define QT602240_BOOT_STATUS_MASK 0x3f
185
186/* Touch status */
187#define QT602240_SUPPRESS (1 << 1)
188#define QT602240_AMP (1 << 2)
189#define QT602240_VECTOR (1 << 3)
190#define QT602240_MOVE (1 << 4)
191#define QT602240_RELEASE (1 << 5)
192#define QT602240_PRESS (1 << 6)
193#define QT602240_DETECT (1 << 7)
194
195/* Touchscreen absolute values */
196#define QT602240_MAX_XC 0x3ff
197#define QT602240_MAX_YC 0x3ff
198#define QT602240_MAX_AREA 0xff
199
200#define QT602240_MAX_FINGER 10
201
202/* Initial register values recommended from chip vendor */
203static const u8 init_vals_ver_20[] = {
204 /* QT602240_GEN_COMMAND(6) */
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206 /* QT602240_GEN_POWER(7) */
207 0x20, 0xff, 0x32,
208 /* QT602240_GEN_ACQUIRE(8) */
209 0x08, 0x05, 0x05, 0x00, 0x00, 0x00, 0x05, 0x14,
210 /* QT602240_TOUCH_MULTI(9) */
211 0x00, 0x00, 0x00, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00,
212 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x64,
214 /* QT602240_TOUCH_KEYARRAY(15) */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216 0x00,
217 /* QT602240_SPT_GPIOPWM(19) */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00,
220 /* QT602240_PROCI_GRIPFACE(20) */
221 0x00, 0x64, 0x64, 0x64, 0x64, 0x00, 0x00, 0x1e, 0x14, 0x04,
222 0x1e, 0x00,
223 /* QT602240_PROCG_NOISE(22) */
224 0x05, 0x00, 0x00, 0x19, 0x00, 0xe7, 0xff, 0x04, 0x32, 0x00,
225 0x01, 0x0a, 0x0f, 0x14, 0x00, 0x00, 0xe8,
226 /* QT602240_TOUCH_PROXIMITY(23) */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00,
229 /* QT602240_PROCI_ONETOUCH(24) */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 /* QT602240_SPT_SELFTEST(25) */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00,
235 /* QT602240_PROCI_TWOTOUCH(27) */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 /* QT602240_SPT_CTECONFIG(28) */
238 0x00, 0x00, 0x00, 0x04, 0x08,
239};
240
241static const u8 init_vals_ver_21[] = {
242 /* QT602240_GEN_COMMAND(6) */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 /* QT602240_GEN_POWER(7) */
245 0x20, 0xff, 0x32,
246 /* QT602240_GEN_ACQUIRE(8) */
247 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23,
248 /* QT602240_TOUCH_MULTI(9) */
249 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00,
250 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 /* QT602240_TOUCH_KEYARRAY(15) */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00,
255 /* QT602240_SPT_GPIOPWM(19) */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 /* QT602240_PROCI_GRIPFACE(20) */
259 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04,
260 0x0f, 0x0a,
261 /* QT602240_PROCG_NOISE(22) */
262 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00,
263 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03,
264 /* QT602240_TOUCH_PROXIMITY(23) */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00,
267 /* QT602240_PROCI_ONETOUCH(24) */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 /* QT602240_SPT_SELFTEST(25) */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00,
273 /* QT602240_PROCI_TWOTOUCH(27) */
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275 /* QT602240_SPT_CTECONFIG(28) */
276 0x00, 0x00, 0x00, 0x08, 0x10, 0x00,
277};
278
279static const u8 init_vals_ver_22[] = {
280 /* QT602240_GEN_COMMAND(6) */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282 /* QT602240_GEN_POWER(7) */
283 0x20, 0xff, 0x32,
284 /* QT602240_GEN_ACQUIRE(8) */
285 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23,
286 /* QT602240_TOUCH_MULTI(9) */
287 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00,
288 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00,
291 /* QT602240_TOUCH_KEYARRAY(15) */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00,
294 /* QT602240_SPT_GPIOPWM(19) */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297 /* QT602240_PROCI_GRIPFACE(20) */
298 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04,
299 0x0f, 0x0a,
300 /* QT602240_PROCG_NOISE(22) */
301 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00,
302 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03,
303 /* QT602240_TOUCH_PROXIMITY(23) */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00,
306 /* QT602240_PROCI_ONETOUCH(24) */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 /* QT602240_SPT_SELFTEST(25) */
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00,
312 /* QT602240_PROCI_TWOTOUCH(27) */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 /* QT602240_SPT_CTECONFIG(28) */
315 0x00, 0x00, 0x00, 0x08, 0x10, 0x00,
316};
317
318struct qt602240_info {
319 u8 family_id;
320 u8 variant_id;
321 u8 version;
322 u8 build;
323 u8 matrix_xsize;
324 u8 matrix_ysize;
325 u8 object_num;
326};
327
328struct qt602240_object {
329 u8 type;
330 u16 start_address;
331 u8 size;
332 u8 instances;
333 u8 num_report_ids;
334
335 /* to map object and message */
336 u8 max_reportid;
337};
338
339struct qt602240_message {
340 u8 reportid;
341 u8 message[7];
342 u8 checksum;
343};
344
345struct qt602240_finger {
346 int status;
347 int x;
348 int y;
349 int area;
350};
351
352/* Each client has this additional data */
353struct qt602240_data {
354 struct i2c_client *client;
355 struct input_dev *input_dev;
356 const struct qt602240_platform_data *pdata;
357 struct qt602240_object *object_table;
358 struct qt602240_info info;
359 struct qt602240_finger finger[QT602240_MAX_FINGER];
360 unsigned int irq;
361};
362
363static bool qt602240_object_readable(unsigned int type)
364{
365 switch (type) {
366 case QT602240_GEN_MESSAGE:
367 case QT602240_GEN_COMMAND:
368 case QT602240_GEN_POWER:
369 case QT602240_GEN_ACQUIRE:
370 case QT602240_TOUCH_MULTI:
371 case QT602240_TOUCH_KEYARRAY:
372 case QT602240_TOUCH_PROXIMITY:
373 case QT602240_PROCI_GRIPFACE:
374 case QT602240_PROCG_NOISE:
375 case QT602240_PROCI_ONETOUCH:
376 case QT602240_PROCI_TWOTOUCH:
377 case QT602240_SPT_COMMSCONFIG:
378 case QT602240_SPT_GPIOPWM:
379 case QT602240_SPT_SELFTEST:
380 case QT602240_SPT_CTECONFIG:
381 case QT602240_SPT_USERDATA:
382 return true;
383 default:
384 return false;
385 }
386}
387
388static bool qt602240_object_writable(unsigned int type)
389{
390 switch (type) {
391 case QT602240_GEN_COMMAND:
392 case QT602240_GEN_POWER:
393 case QT602240_GEN_ACQUIRE:
394 case QT602240_TOUCH_MULTI:
395 case QT602240_TOUCH_KEYARRAY:
396 case QT602240_TOUCH_PROXIMITY:
397 case QT602240_PROCI_GRIPFACE:
398 case QT602240_PROCG_NOISE:
399 case QT602240_PROCI_ONETOUCH:
400 case QT602240_PROCI_TWOTOUCH:
401 case QT602240_SPT_GPIOPWM:
402 case QT602240_SPT_SELFTEST:
403 case QT602240_SPT_CTECONFIG:
404 return true;
405 default:
406 return false;
407 }
408}
409
410static void qt602240_dump_message(struct device *dev,
411 struct qt602240_message *message)
412{
413 dev_dbg(dev, "reportid:\t0x%x\n", message->reportid);
414 dev_dbg(dev, "message1:\t0x%x\n", message->message[0]);
415 dev_dbg(dev, "message2:\t0x%x\n", message->message[1]);
416 dev_dbg(dev, "message3:\t0x%x\n", message->message[2]);
417 dev_dbg(dev, "message4:\t0x%x\n", message->message[3]);
418 dev_dbg(dev, "message5:\t0x%x\n", message->message[4]);
419 dev_dbg(dev, "message6:\t0x%x\n", message->message[5]);
420 dev_dbg(dev, "message7:\t0x%x\n", message->message[6]);
421 dev_dbg(dev, "checksum:\t0x%x\n", message->checksum);
422}
423
424static int qt602240_check_bootloader(struct i2c_client *client,
425 unsigned int state)
426{
427 u8 val;
428
429recheck:
430 if (i2c_master_recv(client, &val, 1) != 1) {
431 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
432 return -EIO;
433 }
434
435 switch (state) {
436 case QT602240_WAITING_BOOTLOAD_CMD:
437 case QT602240_WAITING_FRAME_DATA:
438 val &= ~QT602240_BOOT_STATUS_MASK;
439 break;
440 case QT602240_FRAME_CRC_PASS:
441 if (val == QT602240_FRAME_CRC_CHECK)
442 goto recheck;
443 break;
444 default:
445 return -EINVAL;
446 }
447
448 if (val != state) {
449 dev_err(&client->dev, "Unvalid bootloader mode state\n");
450 return -EINVAL;
451 }
452
453 return 0;
454}
455
456static int qt602240_unlock_bootloader(struct i2c_client *client)
457{
458 u8 buf[2];
459
460 buf[0] = QT602240_UNLOCK_CMD_LSB;
461 buf[1] = QT602240_UNLOCK_CMD_MSB;
462
463 if (i2c_master_send(client, buf, 2) != 2) {
464 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
465 return -EIO;
466 }
467
468 return 0;
469}
470
471static int qt602240_fw_write(struct i2c_client *client,
472 const u8 *data, unsigned int frame_size)
473{
474 if (i2c_master_send(client, data, frame_size) != frame_size) {
475 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
476 return -EIO;
477 }
478
479 return 0;
480}
481
482static int __qt602240_read_reg(struct i2c_client *client,
483 u16 reg, u16 len, void *val)
484{
485 struct i2c_msg xfer[2];
486 u8 buf[2];
487
488 buf[0] = reg & 0xff;
489 buf[1] = (reg >> 8) & 0xff;
490
491 /* Write register */
492 xfer[0].addr = client->addr;
493 xfer[0].flags = 0;
494 xfer[0].len = 2;
495 xfer[0].buf = buf;
496
497 /* Read data */
498 xfer[1].addr = client->addr;
499 xfer[1].flags = I2C_M_RD;
500 xfer[1].len = len;
501 xfer[1].buf = val;
502
503 if (i2c_transfer(client->adapter, xfer, 2) != 2) {
504 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
505 return -EIO;
506 }
507
508 return 0;
509}
510
511static int qt602240_read_reg(struct i2c_client *client, u16 reg, u8 *val)
512{
513 return __qt602240_read_reg(client, reg, 1, val);
514}
515
516static int qt602240_write_reg(struct i2c_client *client, u16 reg, u8 val)
517{
518 u8 buf[3];
519
520 buf[0] = reg & 0xff;
521 buf[1] = (reg >> 8) & 0xff;
522 buf[2] = val;
523
524 if (i2c_master_send(client, buf, 3) != 3) {
525 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
526 return -EIO;
527 }
528
529 return 0;
530}
531
532static int qt602240_read_object_table(struct i2c_client *client,
533 u16 reg, u8 *object_buf)
534{
535 return __qt602240_read_reg(client, reg, QT602240_OBJECT_SIZE,
536 object_buf);
537}
538
539static struct qt602240_object *
540qt602240_get_object(struct qt602240_data *data, u8 type)
541{
542 struct qt602240_object *object;
543 int i;
544
545 for (i = 0; i < data->info.object_num; i++) {
546 object = data->object_table + i;
547 if (object->type == type)
548 return object;
549 }
550
551 dev_err(&data->client->dev, "Invalid object type\n");
552 return NULL;
553}
554
555static int qt602240_read_message(struct qt602240_data *data,
556 struct qt602240_message *message)
557{
558 struct qt602240_object *object;
559 u16 reg;
560
561 object = qt602240_get_object(data, QT602240_GEN_MESSAGE);
562 if (!object)
563 return -EINVAL;
564
565 reg = object->start_address;
566 return __qt602240_read_reg(data->client, reg,
567 sizeof(struct qt602240_message), message);
568}
569
570static int qt602240_read_object(struct qt602240_data *data,
571 u8 type, u8 offset, u8 *val)
572{
573 struct qt602240_object *object;
574 u16 reg;
575
576 object = qt602240_get_object(data, type);
577 if (!object)
578 return -EINVAL;
579
580 reg = object->start_address;
581 return __qt602240_read_reg(data->client, reg + offset, 1, val);
582}
583
584static int qt602240_write_object(struct qt602240_data *data,
585 u8 type, u8 offset, u8 val)
586{
587 struct qt602240_object *object;
588 u16 reg;
589
590 object = qt602240_get_object(data, type);
591 if (!object)
592 return -EINVAL;
593
594 reg = object->start_address;
595 return qt602240_write_reg(data->client, reg + offset, val);
596}
597
598static void qt602240_input_report(struct qt602240_data *data, int single_id)
599{
600 struct qt602240_finger *finger = data->finger;
601 struct input_dev *input_dev = data->input_dev;
602 int status = finger[single_id].status;
603 int finger_num = 0;
604 int id;
605
606 for (id = 0; id < QT602240_MAX_FINGER; id++) {
607 if (!finger[id].status)
608 continue;
609
610 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
611 finger[id].status != QT602240_RELEASE ?
612 finger[id].area : 0);
613 input_report_abs(input_dev, ABS_MT_POSITION_X,
614 finger[id].x);
615 input_report_abs(input_dev, ABS_MT_POSITION_Y,
616 finger[id].y);
617 input_mt_sync(input_dev);
618
619 if (finger[id].status == QT602240_RELEASE)
620 finger[id].status = 0;
621 else
622 finger_num++;
623 }
624
625 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
626
627 if (status != QT602240_RELEASE) {
628 input_report_abs(input_dev, ABS_X, finger[single_id].x);
629 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
630 }
631
632 input_sync(input_dev);
633}
634
635static void qt602240_input_touchevent(struct qt602240_data *data,
636 struct qt602240_message *message, int id)
637{
638 struct qt602240_finger *finger = data->finger;
639 struct device *dev = &data->client->dev;
640 u8 status = message->message[0];
641 int x;
642 int y;
643 int area;
644
645 /* Check the touch is present on the screen */
646 if (!(status & QT602240_DETECT)) {
647 if (status & QT602240_RELEASE) {
648 dev_dbg(dev, "[%d] released\n", id);
649
650 finger[id].status = QT602240_RELEASE;
651 qt602240_input_report(data, id);
652 }
653 return;
654 }
655
656 /* Check only AMP detection */
657 if (!(status & (QT602240_PRESS | QT602240_MOVE)))
658 return;
659
660 x = (message->message[1] << 2) | ((message->message[3] & ~0x3f) >> 6);
661 y = (message->message[2] << 2) | ((message->message[3] & ~0xf3) >> 2);
662 area = message->message[4];
663
664 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
665 status & QT602240_MOVE ? "moved" : "pressed",
666 x, y, area);
667
668 finger[id].status = status & QT602240_MOVE ?
669 QT602240_MOVE : QT602240_PRESS;
670 finger[id].x = x;
671 finger[id].y = y;
672 finger[id].area = area;
673
674 qt602240_input_report(data, id);
675}
676
677static irqreturn_t qt602240_interrupt(int irq, void *dev_id)
678{
679 struct qt602240_data *data = dev_id;
680 struct qt602240_message message;
681 struct qt602240_object *object;
682 struct device *dev = &data->client->dev;
683 int id;
684 u8 reportid;
685 u8 max_reportid;
686 u8 min_reportid;
687
688 do {
689 if (qt602240_read_message(data, &message)) {
690 dev_err(dev, "Failed to read message\n");
691 goto end;
692 }
693
694 reportid = message.reportid;
695
696 /* whether reportid is thing of QT602240_TOUCH_MULTI */
697 object = qt602240_get_object(data, QT602240_TOUCH_MULTI);
698 if (!object)
699 goto end;
700
701 max_reportid = object->max_reportid;
702 min_reportid = max_reportid - object->num_report_ids + 1;
703 id = reportid - min_reportid;
704
705 if (reportid >= min_reportid && reportid <= max_reportid)
706 qt602240_input_touchevent(data, &message, id);
707 else
708 qt602240_dump_message(dev, &message);
709 } while (reportid != 0xff);
710
711end:
712 return IRQ_HANDLED;
713}
714
715static int qt602240_check_reg_init(struct qt602240_data *data)
716{
717 struct qt602240_object *object;
718 struct device *dev = &data->client->dev;
719 int index = 0;
720 int i, j;
721 u8 version = data->info.version;
722 u8 *init_vals;
723
724 switch (version) {
725 case QT602240_VER_20:
726 init_vals = (u8 *)init_vals_ver_20;
727 break;
728 case QT602240_VER_21:
729 init_vals = (u8 *)init_vals_ver_21;
730 break;
731 case QT602240_VER_22:
732 init_vals = (u8 *)init_vals_ver_22;
733 break;
734 default:
735 dev_err(dev, "Firmware version %d doesn't support\n", version);
736 return -EINVAL;
737 }
738
739 for (i = 0; i < data->info.object_num; i++) {
740 object = data->object_table + i;
741
742 if (!qt602240_object_writable(object->type))
743 continue;
744
745 for (j = 0; j < object->size + 1; j++)
746 qt602240_write_object(data, object->type, j,
747 init_vals[index + j]);
748
749 index += object->size + 1;
750 }
751
752 return 0;
753}
754
755static int qt602240_check_matrix_size(struct qt602240_data *data)
756{
757 const struct qt602240_platform_data *pdata = data->pdata;
758 struct device *dev = &data->client->dev;
759 int mode = -1;
760 int error;
761 u8 val;
762
763 dev_dbg(dev, "Number of X lines: %d\n", pdata->x_line);
764 dev_dbg(dev, "Number of Y lines: %d\n", pdata->y_line);
765
766 switch (pdata->x_line) {
767 case 0 ... 15:
768 if (pdata->y_line <= 14)
769 mode = 0;
770 break;
771 case 16:
772 if (pdata->y_line <= 12)
773 mode = 1;
774 if (pdata->y_line == 13 || pdata->y_line == 14)
775 mode = 0;
776 break;
777 case 17:
778 if (pdata->y_line <= 11)
779 mode = 2;
780 if (pdata->y_line == 12 || pdata->y_line == 13)
781 mode = 1;
782 break;
783 case 18:
784 if (pdata->y_line <= 10)
785 mode = 3;
786 if (pdata->y_line == 11 || pdata->y_line == 12)
787 mode = 2;
788 break;
789 case 19:
790 if (pdata->y_line <= 9)
791 mode = 4;
792 if (pdata->y_line == 10 || pdata->y_line == 11)
793 mode = 3;
794 break;
795 case 20:
796 mode = 4;
797 }
798
799 if (mode < 0) {
800 dev_err(dev, "Invalid X/Y lines\n");
801 return -EINVAL;
802 }
803
804 error = qt602240_read_object(data, QT602240_SPT_CTECONFIG,
805 QT602240_CTE_MODE, &val);
806 if (error)
807 return error;
808
809 if (mode == val)
810 return 0;
811
812 /* Change the CTE configuration */
813 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
814 QT602240_CTE_CTRL, 1);
815 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
816 QT602240_CTE_MODE, mode);
817 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
818 QT602240_CTE_CTRL, 0);
819
820 return 0;
821}
822
823static int qt602240_make_highchg(struct qt602240_data *data)
824{
825 struct device *dev = &data->client->dev;
826 int count = 10;
827 int error;
828 u8 val;
829
830 /* Read dummy message to make high CHG pin */
831 do {
832 error = qt602240_read_object(data, QT602240_GEN_MESSAGE, 0, &val);
833 if (error)
834 return error;
835 } while ((val != 0xff) && --count);
836
837 if (!count) {
838 dev_err(dev, "CHG pin isn't cleared\n");
839 return -EBUSY;
840 }
841
842 return 0;
843}
844
845static void qt602240_handle_pdata(struct qt602240_data *data)
846{
847 const struct qt602240_platform_data *pdata = data->pdata;
848 u8 voltage;
849
850 /* Set touchscreen lines */
851 qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_XSIZE,
852 pdata->x_line);
853 qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_YSIZE,
854 pdata->y_line);
855
856 /* Set touchscreen orient */
857 qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_ORIENT,
858 pdata->orient);
859
860 /* Set touchscreen burst length */
861 qt602240_write_object(data, QT602240_TOUCH_MULTI,
862 QT602240_TOUCH_BLEN, pdata->blen);
863
864 /* Set touchscreen threshold */
865 qt602240_write_object(data, QT602240_TOUCH_MULTI,
866 QT602240_TOUCH_TCHTHR, pdata->threshold);
867
868 /* Set touchscreen resolution */
869 qt602240_write_object(data, QT602240_TOUCH_MULTI,
870 QT602240_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
871 qt602240_write_object(data, QT602240_TOUCH_MULTI,
872 QT602240_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
873 qt602240_write_object(data, QT602240_TOUCH_MULTI,
874 QT602240_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
875 qt602240_write_object(data, QT602240_TOUCH_MULTI,
876 QT602240_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
877
878 /* Set touchscreen voltage */
879 if (data->info.version >= QT602240_VER_21 && pdata->voltage) {
880 if (pdata->voltage < QT602240_VOLTAGE_DEFAULT) {
881 voltage = (QT602240_VOLTAGE_DEFAULT - pdata->voltage) /
882 QT602240_VOLTAGE_STEP;
883 voltage = 0xff - voltage + 1;
884 } else
885 voltage = (pdata->voltage - QT602240_VOLTAGE_DEFAULT) /
886 QT602240_VOLTAGE_STEP;
887
888 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
889 QT602240_CTE_VOLTAGE, voltage);
890 }
891}
892
893static int qt602240_get_info(struct qt602240_data *data)
894{
895 struct i2c_client *client = data->client;
896 struct qt602240_info *info = &data->info;
897 int error;
898 u8 val;
899
900 error = qt602240_read_reg(client, QT602240_FAMILY_ID, &val);
901 if (error)
902 return error;
903 info->family_id = val;
904
905 error = qt602240_read_reg(client, QT602240_VARIANT_ID, &val);
906 if (error)
907 return error;
908 info->variant_id = val;
909
910 error = qt602240_read_reg(client, QT602240_VERSION, &val);
911 if (error)
912 return error;
913 info->version = val;
914
915 error = qt602240_read_reg(client, QT602240_BUILD, &val);
916 if (error)
917 return error;
918 info->build = val;
919
920 error = qt602240_read_reg(client, QT602240_OBJECT_NUM, &val);
921 if (error)
922 return error;
923 info->object_num = val;
924
925 return 0;
926}
927
928static int qt602240_get_object_table(struct qt602240_data *data)
929{
930 int error;
931 int i;
932 u16 reg;
933 u8 reportid = 0;
934 u8 buf[QT602240_OBJECT_SIZE];
935
936 for (i = 0; i < data->info.object_num; i++) {
937 struct qt602240_object *object = data->object_table + i;
938
939 reg = QT602240_OBJECT_START + QT602240_OBJECT_SIZE * i;
940 error = qt602240_read_object_table(data->client, reg, buf);
941 if (error)
942 return error;
943
944 object->type = buf[0];
945 object->start_address = (buf[2] << 8) | buf[1];
946 object->size = buf[3];
947 object->instances = buf[4];
948 object->num_report_ids = buf[5];
949
950 if (object->num_report_ids) {
951 reportid += object->num_report_ids *
952 (object->instances + 1);
953 object->max_reportid = reportid;
954 }
955 }
956
957 return 0;
958}
959
960static int qt602240_initialize(struct qt602240_data *data)
961{
962 struct i2c_client *client = data->client;
963 struct qt602240_info *info = &data->info;
964 int error;
965 u8 val;
966
967 error = qt602240_get_info(data);
968 if (error)
969 return error;
970
971 data->object_table = kcalloc(info->object_num,
972 sizeof(struct qt602240_data),
973 GFP_KERNEL);
974 if (!data->object_table) {
975 dev_err(&client->dev, "Failed to allocate memory\n");
976 return -ENOMEM;
977 }
978
979 /* Get object table information */
980 error = qt602240_get_object_table(data);
981 if (error)
982 return error;
983
984 /* Check register init values */
985 error = qt602240_check_reg_init(data);
986 if (error)
987 return error;
988
989 /* Check X/Y matrix size */
990 error = qt602240_check_matrix_size(data);
991 if (error)
992 return error;
993
994 error = qt602240_make_highchg(data);
995 if (error)
996 return error;
997
998 qt602240_handle_pdata(data);
999
1000 /* Backup to memory */
1001 qt602240_write_object(data, QT602240_GEN_COMMAND,
1002 QT602240_COMMAND_BACKUPNV,
1003 QT602240_BACKUP_VALUE);
1004 msleep(QT602240_BACKUP_TIME);
1005
1006 /* Soft reset */
1007 qt602240_write_object(data, QT602240_GEN_COMMAND,
1008 QT602240_COMMAND_RESET, 1);
1009 msleep(QT602240_RESET_TIME);
1010
1011 /* Update matrix size at info struct */
1012 error = qt602240_read_reg(client, QT602240_MATRIX_X_SIZE, &val);
1013 if (error)
1014 return error;
1015 info->matrix_xsize = val;
1016
1017 error = qt602240_read_reg(client, QT602240_MATRIX_Y_SIZE, &val);
1018 if (error)
1019 return error;
1020 info->matrix_ysize = val;
1021
1022 dev_info(&client->dev,
1023 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
1024 info->family_id, info->variant_id, info->version,
1025 info->build);
1026
1027 dev_info(&client->dev,
1028 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
1029 info->matrix_xsize, info->matrix_ysize,
1030 info->object_num);
1031
1032 return 0;
1033}
1034
1035static ssize_t qt602240_object_show(struct device *dev,
1036 struct device_attribute *attr, char *buf)
1037{
1038 struct qt602240_data *data = dev_get_drvdata(dev);
1039 struct qt602240_object *object;
1040 int count = 0;
1041 int i, j;
1042 int error;
1043 u8 val;
1044
1045 for (i = 0; i < data->info.object_num; i++) {
1046 object = data->object_table + i;
1047
1048 count += sprintf(buf + count,
1049 "Object Table Element %d(Type %d)\n",
1050 i + 1, object->type);
1051
1052 if (!qt602240_object_readable(object->type)) {
1053 count += sprintf(buf + count, "\n");
1054 continue;
1055 }
1056
1057 for (j = 0; j < object->size + 1; j++) {
1058 error = qt602240_read_object(data,
1059 object->type, j, &val);
1060 if (error)
1061 return error;
1062
1063 count += sprintf(buf + count,
1064 " Byte %d: 0x%x (%d)\n", j, val, val);
1065 }
1066
1067 count += sprintf(buf + count, "\n");
1068 }
1069
1070 return count;
1071}
1072
1073static int qt602240_load_fw(struct device *dev, const char *fn)
1074{
1075 struct qt602240_data *data = dev_get_drvdata(dev);
1076 struct i2c_client *client = data->client;
1077 const struct firmware *fw = NULL;
1078 unsigned int frame_size;
1079 unsigned int pos = 0;
1080 int ret;
1081
1082 ret = request_firmware(&fw, fn, dev);
1083 if (ret) {
1084 dev_err(dev, "Unable to open firmware %s\n", fn);
1085 return ret;
1086 }
1087
1088 /* Change to the bootloader mode */
1089 qt602240_write_object(data, QT602240_GEN_COMMAND,
1090 QT602240_COMMAND_RESET, QT602240_BOOT_VALUE);
1091 msleep(QT602240_RESET_TIME);
1092
1093 /* Change to slave address of bootloader */
1094 if (client->addr == QT602240_APP_LOW)
1095 client->addr = QT602240_BOOT_LOW;
1096 else
1097 client->addr = QT602240_BOOT_HIGH;
1098
1099 ret = qt602240_check_bootloader(client, QT602240_WAITING_BOOTLOAD_CMD);
1100 if (ret)
1101 goto out;
1102
1103 /* Unlock bootloader */
1104 qt602240_unlock_bootloader(client);
1105
1106 while (pos < fw->size) {
1107 ret = qt602240_check_bootloader(client,
1108 QT602240_WAITING_FRAME_DATA);
1109 if (ret)
1110 goto out;
1111
1112 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
1113
1114 /* We should add 2 at frame size as the the firmware data is not
1115 * included the CRC bytes.
1116 */
1117 frame_size += 2;
1118
1119 /* Write one frame to device */
1120 qt602240_fw_write(client, fw->data + pos, frame_size);
1121
1122 ret = qt602240_check_bootloader(client,
1123 QT602240_FRAME_CRC_PASS);
1124 if (ret)
1125 goto out;
1126
1127 pos += frame_size;
1128
1129 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
1130 }
1131
1132out:
1133 release_firmware(fw);
1134
1135 /* Change to slave address of application */
1136 if (client->addr == QT602240_BOOT_LOW)
1137 client->addr = QT602240_APP_LOW;
1138 else
1139 client->addr = QT602240_APP_HIGH;
1140
1141 return ret;
1142}
1143
1144static ssize_t qt602240_update_fw_store(struct device *dev,
1145 struct device_attribute *attr,
1146 const char *buf, size_t count)
1147{
1148 struct qt602240_data *data = dev_get_drvdata(dev);
1149 unsigned int version;
1150 int error;
1151
1152 if (sscanf(buf, "%u", &version) != 1) {
1153 dev_err(dev, "Invalid values\n");
1154 return -EINVAL;
1155 }
1156
1157 if (data->info.version < QT602240_VER_21 || version < QT602240_VER_21) {
1158 dev_err(dev, "FW update supported starting with version 21\n");
1159 return -EINVAL;
1160 }
1161
1162 disable_irq(data->irq);
1163
1164 error = qt602240_load_fw(dev, QT602240_FW_NAME);
1165 if (error) {
1166 dev_err(dev, "The firmware update failed(%d)\n", error);
1167 count = error;
1168 } else {
1169 dev_dbg(dev, "The firmware update succeeded\n");
1170
1171 /* Wait for reset */
1172 msleep(QT602240_FWRESET_TIME);
1173
1174 kfree(data->object_table);
1175 data->object_table = NULL;
1176
1177 qt602240_initialize(data);
1178 }
1179
1180 enable_irq(data->irq);
1181
1182 return count;
1183}
1184
1185static DEVICE_ATTR(object, 0444, qt602240_object_show, NULL);
1186static DEVICE_ATTR(update_fw, 0664, NULL, qt602240_update_fw_store);
1187
1188static struct attribute *qt602240_attrs[] = {
1189 &dev_attr_object.attr,
1190 &dev_attr_update_fw.attr,
1191 NULL
1192};
1193
1194static const struct attribute_group qt602240_attr_group = {
1195 .attrs = qt602240_attrs,
1196};
1197
1198static void qt602240_start(struct qt602240_data *data)
1199{
1200 /* Touch enable */
1201 qt602240_write_object(data,
1202 QT602240_TOUCH_MULTI, QT602240_TOUCH_CTRL, 0x83);
1203}
1204
1205static void qt602240_stop(struct qt602240_data *data)
1206{
1207 /* Touch disable */
1208 qt602240_write_object(data,
1209 QT602240_TOUCH_MULTI, QT602240_TOUCH_CTRL, 0);
1210}
1211
1212static int qt602240_input_open(struct input_dev *dev)
1213{
1214 struct qt602240_data *data = input_get_drvdata(dev);
1215
1216 qt602240_start(data);
1217
1218 return 0;
1219}
1220
1221static void qt602240_input_close(struct input_dev *dev)
1222{
1223 struct qt602240_data *data = input_get_drvdata(dev);
1224
1225 qt602240_stop(data);
1226}
1227
1228static int __devinit qt602240_probe(struct i2c_client *client,
1229 const struct i2c_device_id *id)
1230{
1231 struct qt602240_data *data;
1232 struct input_dev *input_dev;
1233 int error;
1234
1235 if (!client->dev.platform_data)
1236 return -EINVAL;
1237
1238 data = kzalloc(sizeof(struct qt602240_data), GFP_KERNEL);
1239 input_dev = input_allocate_device();
1240 if (!data || !input_dev) {
1241 dev_err(&client->dev, "Failed to allocate memory\n");
1242 error = -ENOMEM;
1243 goto err_free_mem;
1244 }
1245
1246 input_dev->name = "AT42QT602240/ATMXT224 Touchscreen";
1247 input_dev->id.bustype = BUS_I2C;
1248 input_dev->dev.parent = &client->dev;
1249 input_dev->open = qt602240_input_open;
1250 input_dev->close = qt602240_input_close;
1251
1252 __set_bit(EV_ABS, input_dev->evbit);
1253 __set_bit(EV_KEY, input_dev->evbit);
1254 __set_bit(BTN_TOUCH, input_dev->keybit);
1255
1256 /* For single touch */
1257 input_set_abs_params(input_dev, ABS_X,
1258 0, QT602240_MAX_XC, 0, 0);
1259 input_set_abs_params(input_dev, ABS_Y,
1260 0, QT602240_MAX_YC, 0, 0);
1261
1262 /* For multi touch */
1263 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1264 0, QT602240_MAX_AREA, 0, 0);
1265 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1266 0, QT602240_MAX_XC, 0, 0);
1267 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1268 0, QT602240_MAX_YC, 0, 0);
1269
1270 input_set_drvdata(input_dev, data);
1271
1272 data->client = client;
1273 data->input_dev = input_dev;
1274 data->pdata = client->dev.platform_data;
1275 data->irq = client->irq;
1276
1277 i2c_set_clientdata(client, data);
1278
1279 error = qt602240_initialize(data);
1280 if (error)
1281 goto err_free_object;
1282
1283 error = request_threaded_irq(client->irq, NULL, qt602240_interrupt,
1284 IRQF_TRIGGER_FALLING, client->dev.driver->name, data);
1285 if (error) {
1286 dev_err(&client->dev, "Failed to register interrupt\n");
1287 goto err_free_object;
1288 }
1289
1290 error = input_register_device(input_dev);
1291 if (error)
1292 goto err_free_irq;
1293
1294 error = sysfs_create_group(&client->dev.kobj, &qt602240_attr_group);
1295 if (error)
1296 goto err_unregister_device;
1297
1298 return 0;
1299
1300err_unregister_device:
1301 input_unregister_device(input_dev);
1302 input_dev = NULL;
1303err_free_irq:
1304 free_irq(client->irq, data);
1305err_free_object:
1306 kfree(data->object_table);
1307err_free_mem:
1308 input_free_device(input_dev);
1309 kfree(data);
1310 return error;
1311}
1312
1313static int __devexit qt602240_remove(struct i2c_client *client)
1314{
1315 struct qt602240_data *data = i2c_get_clientdata(client);
1316
1317 sysfs_remove_group(&client->dev.kobj, &qt602240_attr_group);
1318 free_irq(data->irq, data);
1319 input_unregister_device(data->input_dev);
1320 kfree(data->object_table);
1321 kfree(data);
1322
1323 return 0;
1324}
1325
1326#ifdef CONFIG_PM
1327static int qt602240_suspend(struct i2c_client *client, pm_message_t mesg)
1328{
1329 struct qt602240_data *data = i2c_get_clientdata(client);
1330 struct input_dev *input_dev = data->input_dev;
1331
1332 mutex_lock(&input_dev->mutex);
1333
1334 if (input_dev->users)
1335 qt602240_stop(data);
1336
1337 mutex_unlock(&input_dev->mutex);
1338
1339 return 0;
1340}
1341
1342static int qt602240_resume(struct i2c_client *client)
1343{
1344 struct qt602240_data *data = i2c_get_clientdata(client);
1345 struct input_dev *input_dev = data->input_dev;
1346
1347 /* Soft reset */
1348 qt602240_write_object(data, QT602240_GEN_COMMAND,
1349 QT602240_COMMAND_RESET, 1);
1350
1351 msleep(QT602240_RESET_TIME);
1352
1353 mutex_lock(&input_dev->mutex);
1354
1355 if (input_dev->users)
1356 qt602240_start(data);
1357
1358 mutex_unlock(&input_dev->mutex);
1359
1360 return 0;
1361}
1362#else
1363#define qt602240_suspend NULL
1364#define qt602240_resume NULL
1365#endif
1366
1367static const struct i2c_device_id qt602240_id[] = {
1368 { "qt602240_ts", 0 },
1369 { }
1370};
1371MODULE_DEVICE_TABLE(i2c, qt602240_id);
1372
1373static struct i2c_driver qt602240_driver = {
1374 .driver = {
1375 .name = "qt602240_ts",
1376 .owner = THIS_MODULE,
1377 },
1378 .probe = qt602240_probe,
1379 .remove = __devexit_p(qt602240_remove),
1380 .suspend = qt602240_suspend,
1381 .resume = qt602240_resume,
1382 .id_table = qt602240_id,
1383};
1384
1385static int __init qt602240_init(void)
1386{
1387 return i2c_add_driver(&qt602240_driver);
1388}
1389
1390static void __exit qt602240_exit(void)
1391{
1392 i2c_del_driver(&qt602240_driver);
1393}
1394
1395module_init(qt602240_init);
1396module_exit(qt602240_exit);
1397
1398/* Module information */
1399MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
1400MODULE_DESCRIPTION("AT42QT602240/ATMXT224 Touchscreen driver");
1401MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/s3c2410_ts.c b/drivers/input/touchscreen/s3c2410_ts.c
index ac5d0f9b0cb1..6085d12fd561 100644
--- a/drivers/input/touchscreen/s3c2410_ts.c
+++ b/drivers/input/touchscreen/s3c2410_ts.c
@@ -173,7 +173,7 @@ static irqreturn_t stylus_irq(int irq, void *dev_id)
173 if (down) 173 if (down)
174 s3c_adc_start(ts.client, 0, 1 << ts.shift); 174 s3c_adc_start(ts.client, 0, 1 << ts.shift);
175 else 175 else
176 dev_info(ts.dev, "%s: count=%d\n", __func__, ts.count); 176 dev_dbg(ts.dev, "%s: count=%d\n", __func__, ts.count);
177 177
178 if (ts.features & FEAT_PEN_IRQ) { 178 if (ts.features & FEAT_PEN_IRQ) {
179 /* Clear pen down/up interrupt */ 179 /* Clear pen down/up interrupt */
diff --git a/drivers/input/touchscreen/stmpe-ts.c b/drivers/input/touchscreen/stmpe-ts.c
new file mode 100644
index 000000000000..656148ec0027
--- /dev/null
+++ b/drivers/input/touchscreen/stmpe-ts.c
@@ -0,0 +1,397 @@
1/* STMicroelectronics STMPE811 Touchscreen Driver
2 *
3 * (C) 2010 Luotao Fu <l.fu@pengutronix.de>
4 * All rights reserved.
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 as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <linux/interrupt.h>
17#include <linux/init.h>
18#include <linux/device.h>
19#include <linux/platform_device.h>
20#include <linux/input.h>
21#include <linux/slab.h>
22#include <linux/delay.h>
23#include <linux/i2c.h>
24#include <linux/workqueue.h>
25
26#include <linux/mfd/stmpe.h>
27
28/* Register layouts and functionalities are identical on all stmpexxx variants
29 * with touchscreen controller
30 */
31#define STMPE_REG_INT_STA 0x0B
32#define STMPE_REG_ADC_CTRL1 0x20
33#define STMPE_REG_ADC_CTRL2 0x21
34#define STMPE_REG_TSC_CTRL 0x40
35#define STMPE_REG_TSC_CFG 0x41
36#define STMPE_REG_FIFO_TH 0x4A
37#define STMPE_REG_FIFO_STA 0x4B
38#define STMPE_REG_FIFO_SIZE 0x4C
39#define STMPE_REG_TSC_DATA_XYZ 0x52
40#define STMPE_REG_TSC_FRACTION_Z 0x56
41#define STMPE_REG_TSC_I_DRIVE 0x58
42
43#define OP_MOD_XYZ 0
44
45#define STMPE_TSC_CTRL_TSC_EN (1<<0)
46
47#define STMPE_FIFO_STA_RESET (1<<0)
48
49#define STMPE_IRQ_TOUCH_DET 0
50
51#define SAMPLE_TIME(x) ((x & 0xf) << 4)
52#define MOD_12B(x) ((x & 0x1) << 3)
53#define REF_SEL(x) ((x & 0x1) << 1)
54#define ADC_FREQ(x) (x & 0x3)
55#define AVE_CTRL(x) ((x & 0x3) << 6)
56#define DET_DELAY(x) ((x & 0x7) << 3)
57#define SETTLING(x) (x & 0x7)
58#define FRACTION_Z(x) (x & 0x7)
59#define I_DRIVE(x) (x & 0x1)
60#define OP_MODE(x) ((x & 0x7) << 1)
61
62#define STMPE_TS_NAME "stmpe-ts"
63#define XY_MASK 0xfff
64
65struct stmpe_touch {
66 struct stmpe *stmpe;
67 struct input_dev *idev;
68 struct delayed_work work;
69 struct device *dev;
70 u8 sample_time;
71 u8 mod_12b;
72 u8 ref_sel;
73 u8 adc_freq;
74 u8 ave_ctrl;
75 u8 touch_det_delay;
76 u8 settling;
77 u8 fraction_z;
78 u8 i_drive;
79};
80
81static int __stmpe_reset_fifo(struct stmpe *stmpe)
82{
83 int ret;
84
85 ret = stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
86 STMPE_FIFO_STA_RESET, STMPE_FIFO_STA_RESET);
87 if (ret)
88 return ret;
89
90 return stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
91 STMPE_FIFO_STA_RESET, 0);
92}
93
94static void stmpe_work(struct work_struct *work)
95{
96 int int_sta;
97 u32 timeout = 40;
98
99 struct stmpe_touch *ts =
100 container_of(work, struct stmpe_touch, work.work);
101
102 int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
103
104 /*
105 * touch_det sometimes get desasserted or just get stuck. This appears
106 * to be a silicon bug, We still have to clearify this with the
107 * manufacture. As a workaround We release the key anyway if the
108 * touch_det keeps coming in after 4ms, while the FIFO contains no value
109 * during the whole time.
110 */
111 while ((int_sta & (1 << STMPE_IRQ_TOUCH_DET)) && (timeout > 0)) {
112 timeout--;
113 int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
114 udelay(100);
115 }
116
117 /* reset the FIFO before we report release event */
118 __stmpe_reset_fifo(ts->stmpe);
119
120 input_report_abs(ts->idev, ABS_PRESSURE, 0);
121 input_sync(ts->idev);
122}
123
124static irqreturn_t stmpe_ts_handler(int irq, void *data)
125{
126 u8 data_set[4];
127 int x, y, z;
128 struct stmpe_touch *ts = data;
129
130 /*
131 * Cancel scheduled polling for release if we have new value
132 * available. Wait if the polling is already running.
133 */
134 cancel_delayed_work_sync(&ts->work);
135
136 /*
137 * The FIFO sometimes just crashes and stops generating interrupts. This
138 * appears to be a silicon bug. We still have to clearify this with
139 * the manufacture. As a workaround we disable the TSC while we are
140 * collecting data and flush the FIFO after reading
141 */
142 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
143 STMPE_TSC_CTRL_TSC_EN, 0);
144
145 stmpe_block_read(ts->stmpe, STMPE_REG_TSC_DATA_XYZ, 4, data_set);
146
147 x = (data_set[0] << 4) | (data_set[1] >> 4);
148 y = ((data_set[1] & 0xf) << 8) | data_set[2];
149 z = data_set[3];
150
151 input_report_abs(ts->idev, ABS_X, x);
152 input_report_abs(ts->idev, ABS_Y, y);
153 input_report_abs(ts->idev, ABS_PRESSURE, z);
154 input_sync(ts->idev);
155
156 /* flush the FIFO after we have read out our values. */
157 __stmpe_reset_fifo(ts->stmpe);
158
159 /* reenable the tsc */
160 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
161 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
162
163 /* start polling for touch_det to detect release */
164 schedule_delayed_work(&ts->work, HZ / 50);
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit stmpe_init_hw(struct stmpe_touch *ts)
170{
171 int ret;
172 u8 adc_ctrl1, adc_ctrl1_mask, tsc_cfg, tsc_cfg_mask;
173 struct stmpe *stmpe = ts->stmpe;
174 struct device *dev = ts->dev;
175
176 ret = stmpe_enable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC);
177 if (ret) {
178 dev_err(dev, "Could not enable clock for ADC and TS\n");
179 return ret;
180 }
181
182 adc_ctrl1 = SAMPLE_TIME(ts->sample_time) | MOD_12B(ts->mod_12b) |
183 REF_SEL(ts->ref_sel);
184 adc_ctrl1_mask = SAMPLE_TIME(0xff) | MOD_12B(0xff) | REF_SEL(0xff);
185
186 ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL1,
187 adc_ctrl1_mask, adc_ctrl1);
188 if (ret) {
189 dev_err(dev, "Could not setup ADC\n");
190 return ret;
191 }
192
193 ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL2,
194 ADC_FREQ(0xff), ADC_FREQ(ts->adc_freq));
195 if (ret) {
196 dev_err(dev, "Could not setup ADC\n");
197 return ret;
198 }
199
200 tsc_cfg = AVE_CTRL(ts->ave_ctrl) | DET_DELAY(ts->touch_det_delay) |
201 SETTLING(ts->settling);
202 tsc_cfg_mask = AVE_CTRL(0xff) | DET_DELAY(0xff) | SETTLING(0xff);
203
204 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg);
205 if (ret) {
206 dev_err(dev, "Could not config touch\n");
207 return ret;
208 }
209
210 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_FRACTION_Z,
211 FRACTION_Z(0xff), FRACTION_Z(ts->fraction_z));
212 if (ret) {
213 dev_err(dev, "Could not config touch\n");
214 return ret;
215 }
216
217 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_I_DRIVE,
218 I_DRIVE(0xff), I_DRIVE(ts->i_drive));
219 if (ret) {
220 dev_err(dev, "Could not config touch\n");
221 return ret;
222 }
223
224 /* set FIFO to 1 for single point reading */
225 ret = stmpe_reg_write(stmpe, STMPE_REG_FIFO_TH, 1);
226 if (ret) {
227 dev_err(dev, "Could not set FIFO\n");
228 return ret;
229 }
230
231 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CTRL,
232 OP_MODE(0xff), OP_MODE(OP_MOD_XYZ));
233 if (ret) {
234 dev_err(dev, "Could not set mode\n");
235 return ret;
236 }
237
238 return 0;
239}
240
241static int stmpe_ts_open(struct input_dev *dev)
242{
243 struct stmpe_touch *ts = input_get_drvdata(dev);
244 int ret = 0;
245
246 ret = __stmpe_reset_fifo(ts->stmpe);
247 if (ret)
248 return ret;
249
250 return stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
251 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
252}
253
254static void stmpe_ts_close(struct input_dev *dev)
255{
256 struct stmpe_touch *ts = input_get_drvdata(dev);
257
258 cancel_delayed_work_sync(&ts->work);
259
260 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
261 STMPE_TSC_CTRL_TSC_EN, 0);
262}
263
264static int __devinit stmpe_input_probe(struct platform_device *pdev)
265{
266 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
267 struct stmpe_platform_data *pdata = stmpe->pdata;
268 struct stmpe_touch *ts;
269 struct input_dev *idev;
270 struct stmpe_ts_platform_data *ts_pdata = NULL;
271 int ret = 0;
272 int ts_irq;
273
274 ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
275 if (ts_irq < 0)
276 return ts_irq;
277
278 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
279 if (!ts)
280 goto err_out;
281
282 idev = input_allocate_device();
283 if (!idev)
284 goto err_free_ts;
285
286 platform_set_drvdata(pdev, ts);
287 ts->stmpe = stmpe;
288 ts->idev = idev;
289 ts->dev = &pdev->dev;
290
291 if (pdata)
292 ts_pdata = pdata->ts;
293
294 if (ts_pdata) {
295 ts->sample_time = ts_pdata->sample_time;
296 ts->mod_12b = ts_pdata->mod_12b;
297 ts->ref_sel = ts_pdata->ref_sel;
298 ts->adc_freq = ts_pdata->adc_freq;
299 ts->ave_ctrl = ts_pdata->ave_ctrl;
300 ts->touch_det_delay = ts_pdata->touch_det_delay;
301 ts->settling = ts_pdata->settling;
302 ts->fraction_z = ts_pdata->fraction_z;
303 ts->i_drive = ts_pdata->i_drive;
304 }
305
306 INIT_DELAYED_WORK(&ts->work, stmpe_work);
307
308 ret = request_threaded_irq(ts_irq, NULL, stmpe_ts_handler,
309 IRQF_ONESHOT, STMPE_TS_NAME, ts);
310 if (ret) {
311 dev_err(&pdev->dev, "Failed to request IRQ %d\n", ts_irq);
312 goto err_free_input;
313 }
314
315 ret = stmpe_init_hw(ts);
316 if (ret)
317 goto err_free_irq;
318
319 idev->name = STMPE_TS_NAME;
320 idev->id.bustype = BUS_I2C;
321 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
322 idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
323
324 idev->open = stmpe_ts_open;
325 idev->close = stmpe_ts_close;
326
327 input_set_drvdata(idev, ts);
328
329 input_set_abs_params(idev, ABS_X, 0, XY_MASK, 0, 0);
330 input_set_abs_params(idev, ABS_Y, 0, XY_MASK, 0, 0);
331 input_set_abs_params(idev, ABS_PRESSURE, 0x0, 0xff, 0, 0);
332
333 ret = input_register_device(idev);
334 if (ret) {
335 dev_err(&pdev->dev, "Could not register input device\n");
336 goto err_free_irq;
337 }
338
339 return ret;
340
341err_free_irq:
342 free_irq(ts_irq, ts);
343err_free_input:
344 input_free_device(idev);
345 platform_set_drvdata(pdev, NULL);
346err_free_ts:
347 kfree(ts);
348err_out:
349 return ret;
350}
351
352static int __devexit stmpe_ts_remove(struct platform_device *pdev)
353{
354 struct stmpe_touch *ts = platform_get_drvdata(pdev);
355 unsigned int ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
356
357 stmpe_disable(ts->stmpe, STMPE_BLOCK_TOUCHSCREEN);
358
359 free_irq(ts_irq, ts);
360
361 platform_set_drvdata(pdev, NULL);
362
363 input_unregister_device(ts->idev);
364 input_free_device(ts->idev);
365
366 kfree(ts);
367
368 return 0;
369}
370
371static struct platform_driver stmpe_ts_driver = {
372 .driver = {
373 .name = STMPE_TS_NAME,
374 .owner = THIS_MODULE,
375 },
376 .probe = stmpe_input_probe,
377 .remove = __devexit_p(stmpe_ts_remove),
378};
379
380static int __init stmpe_ts_init(void)
381{
382 return platform_driver_register(&stmpe_ts_driver);
383}
384
385module_init(stmpe_ts_init);
386
387static void __exit stmpe_ts_exit(void)
388{
389 platform_driver_unregister(&stmpe_ts_driver);
390}
391
392module_exit(stmpe_ts_exit);
393
394MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
395MODULE_DESCRIPTION("STMPEXXX touchscreen driver");
396MODULE_LICENSE("GPL");
397MODULE_ALIAS("platform:" STMPE_TS_NAME);
diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c
index 5de80a1a730b..a644d18c04dc 100644
--- a/drivers/input/touchscreen/tps6507x-ts.c
+++ b/drivers/input/touchscreen/tps6507x-ts.c
@@ -221,7 +221,7 @@ done:
221 221
222 if (poll) { 222 if (poll) {
223 schd = queue_delayed_work(tsc->wq, &tsc->work, 223 schd = queue_delayed_work(tsc->wq, &tsc->work,
224 tsc->poll_period * HZ / 1000); 224 msecs_to_jiffies(tsc->poll_period));
225 if (schd) 225 if (schd)
226 tsc->polling = 1; 226 tsc->polling = 1;
227 else { 227 else {
@@ -326,7 +326,7 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
326 goto err2; 326 goto err2;
327 327
328 schd = queue_delayed_work(tsc->wq, &tsc->work, 328 schd = queue_delayed_work(tsc->wq, &tsc->work,
329 tsc->poll_period * HZ / 1000); 329 msecs_to_jiffies(tsc->poll_period));
330 330
331 if (schd) 331 if (schd)
332 tsc->polling = 1; 332 tsc->polling = 1;
@@ -339,10 +339,8 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
339 return 0; 339 return 0;
340 340
341err2: 341err2:
342 cancel_delayed_work(&tsc->work); 342 cancel_delayed_work_sync(&tsc->work);
343 flush_workqueue(tsc->wq);
344 destroy_workqueue(tsc->wq); 343 destroy_workqueue(tsc->wq);
345 tsc->wq = 0;
346 input_free_device(input_dev); 344 input_free_device(input_dev);
347err1: 345err1:
348 kfree(tsc); 346 kfree(tsc);
@@ -357,13 +355,8 @@ static int __devexit tps6507x_ts_remove(struct platform_device *pdev)
357 struct tps6507x_ts *tsc = tps6507x_dev->ts; 355 struct tps6507x_ts *tsc = tps6507x_dev->ts;
358 struct input_dev *input_dev = tsc->input_dev; 356 struct input_dev *input_dev = tsc->input_dev;
359 357
360 if (!tsc) 358 cancel_delayed_work_sync(&tsc->work);
361 return 0;
362
363 cancel_delayed_work(&tsc->work);
364 flush_workqueue(tsc->wq);
365 destroy_workqueue(tsc->wq); 359 destroy_workqueue(tsc->wq);
366 tsc->wq = 0;
367 360
368 input_free_device(input_dev); 361 input_free_device(input_dev);
369 362
diff --git a/drivers/input/touchscreen/tsc2007.c b/drivers/input/touchscreen/tsc2007.c
index 769b479fcaa6..be23780e8a3e 100644
--- a/drivers/input/touchscreen/tsc2007.c
+++ b/drivers/input/touchscreen/tsc2007.c
@@ -347,8 +347,6 @@ static int __devexit tsc2007_remove(struct i2c_client *client)
347 struct tsc2007 *ts = i2c_get_clientdata(client); 347 struct tsc2007 *ts = i2c_get_clientdata(client);
348 struct tsc2007_platform_data *pdata = client->dev.platform_data; 348 struct tsc2007_platform_data *pdata = client->dev.platform_data;
349 349
350 i2c_set_clientdata(client, NULL);
351
352 tsc2007_free_irq(ts); 350 tsc2007_free_irq(ts);
353 351
354 if (pdata->exit_platform_hw) 352 if (pdata->exit_platform_hw)
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 567d57215c28..f45f80f6d336 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -95,6 +95,7 @@ struct usbtouch_device_info {
95 int (*get_pkt_len) (unsigned char *pkt, int len); 95 int (*get_pkt_len) (unsigned char *pkt, int len);
96 96
97 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt); 97 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
98 int (*alloc) (struct usbtouch_usb *usbtouch);
98 int (*init) (struct usbtouch_usb *usbtouch); 99 int (*init) (struct usbtouch_usb *usbtouch);
99 void (*exit) (struct usbtouch_usb *usbtouch); 100 void (*exit) (struct usbtouch_usb *usbtouch);
100}; 101};
@@ -135,7 +136,7 @@ enum {
135 DEVTYPE_JASTEC, 136 DEVTYPE_JASTEC,
136 DEVTYPE_E2I, 137 DEVTYPE_E2I,
137 DEVTYPE_ZYTRONIC, 138 DEVTYPE_ZYTRONIC,
138 DEVTYPE_TC5UH, 139 DEVTYPE_TC45USB,
139 DEVTYPE_NEXIO, 140 DEVTYPE_NEXIO,
140}; 141};
141 142
@@ -222,8 +223,11 @@ static const struct usb_device_id usbtouch_devices[] = {
222 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC}, 223 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
223#endif 224#endif
224 225
225#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH 226#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
226 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH}, 227 /* TC5UH */
228 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB},
229 /* TC4UM */
230 {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB},
227#endif 231#endif
228 232
229#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO 233#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
@@ -507,7 +511,7 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
507 int ret = -ENOMEM; 511 int ret = -ENOMEM;
508 unsigned char *buf; 512 unsigned char *buf;
509 513
510 buf = kmalloc(2, GFP_KERNEL); 514 buf = kmalloc(2, GFP_NOIO);
511 if (!buf) 515 if (!buf)
512 goto err_nobuf; 516 goto err_nobuf;
513 /* reset */ 517 /* reset */
@@ -574,10 +578,10 @@ static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
574#endif 578#endif
575 579
576/***************************************************************************** 580/*****************************************************************************
577 * ET&T TC5UH part 581 * ET&T TC5UH/TC4UM part
578 */ 582 */
579#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH 583#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
580static int tc5uh_read_data(struct usbtouch_usb *dev, unsigned char *pkt) 584static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
581{ 585{
582 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; 586 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
583 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; 587 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
@@ -732,11 +736,43 @@ static void nexio_ack_complete(struct urb *urb)
732{ 736{
733} 737}
734 738
739static int nexio_alloc(struct usbtouch_usb *usbtouch)
740{
741 struct nexio_priv *priv;
742 int ret = -ENOMEM;
743
744 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
745 if (!usbtouch->priv)
746 goto out_buf;
747
748 priv = usbtouch->priv;
749
750 priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt),
751 GFP_KERNEL);
752 if (!priv->ack_buf)
753 goto err_priv;
754
755 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
756 if (!priv->ack) {
757 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
758 goto err_ack_buf;
759 }
760
761 return 0;
762
763err_ack_buf:
764 kfree(priv->ack_buf);
765err_priv:
766 kfree(priv);
767out_buf:
768 return ret;
769}
770
735static int nexio_init(struct usbtouch_usb *usbtouch) 771static int nexio_init(struct usbtouch_usb *usbtouch)
736{ 772{
737 struct usb_device *dev = interface_to_usbdev(usbtouch->interface); 773 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
738 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting; 774 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
739 struct nexio_priv *priv; 775 struct nexio_priv *priv = usbtouch->priv;
740 int ret = -ENOMEM; 776 int ret = -ENOMEM;
741 int actual_len, i; 777 int actual_len, i;
742 unsigned char *buf; 778 unsigned char *buf;
@@ -755,7 +791,7 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
755 if (!input_ep || !output_ep) 791 if (!input_ep || !output_ep)
756 return -ENXIO; 792 return -ENXIO;
757 793
758 buf = kmalloc(NEXIO_BUFSIZE, GFP_KERNEL); 794 buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
759 if (!buf) 795 if (!buf)
760 goto out_buf; 796 goto out_buf;
761 797
@@ -787,11 +823,11 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
787 switch (buf[0]) { 823 switch (buf[0]) {
788 case 0x83: /* firmware version */ 824 case 0x83: /* firmware version */
789 if (!firmware_ver) 825 if (!firmware_ver)
790 firmware_ver = kstrdup(&buf[2], GFP_KERNEL); 826 firmware_ver = kstrdup(&buf[2], GFP_NOIO);
791 break; 827 break;
792 case 0x84: /* device name */ 828 case 0x84: /* device name */
793 if (!device_name) 829 if (!device_name)
794 device_name = kstrdup(&buf[2], GFP_KERNEL); 830 device_name = kstrdup(&buf[2], GFP_NOIO);
795 break; 831 break;
796 } 832 }
797 } 833 }
@@ -802,36 +838,11 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
802 kfree(firmware_ver); 838 kfree(firmware_ver);
803 kfree(device_name); 839 kfree(device_name);
804 840
805 /* prepare ACK URB */
806 ret = -ENOMEM;
807
808 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
809 if (!usbtouch->priv)
810 goto out_buf;
811
812 priv = usbtouch->priv;
813
814 priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt),
815 GFP_KERNEL);
816 if (!priv->ack_buf)
817 goto err_priv;
818
819 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
820 if (!priv->ack) {
821 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
822 goto err_ack_buf;
823 }
824
825 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep), 841 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
826 priv->ack_buf, sizeof(nexio_ack_pkt), 842 priv->ack_buf, sizeof(nexio_ack_pkt),
827 nexio_ack_complete, usbtouch); 843 nexio_ack_complete, usbtouch);
828 ret = 0; 844 ret = 0;
829 goto out_buf;
830 845
831err_ack_buf:
832 kfree(priv->ack_buf);
833err_priv:
834 kfree(priv);
835out_buf: 846out_buf:
836 kfree(buf); 847 kfree(buf);
837 return ret; 848 return ret;
@@ -849,29 +860,32 @@ static void nexio_exit(struct usbtouch_usb *usbtouch)
849 860
850static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt) 861static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
851{ 862{
852 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
853 struct nexio_touch_packet *packet = (void *) pkt; 863 struct nexio_touch_packet *packet = (void *) pkt;
854 struct nexio_priv *priv = usbtouch->priv; 864 struct nexio_priv *priv = usbtouch->priv;
865 unsigned int data_len = be16_to_cpu(packet->data_len);
866 unsigned int x_len = be16_to_cpu(packet->x_len);
867 unsigned int y_len = be16_to_cpu(packet->y_len);
868 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
855 869
856 /* got touch data? */ 870 /* got touch data? */
857 if ((pkt[0] & 0xe0) != 0xe0) 871 if ((pkt[0] & 0xe0) != 0xe0)
858 return 0; 872 return 0;
859 873
860 if (be16_to_cpu(packet->data_len) > 0xff) 874 if (data_len > 0xff)
861 packet->data_len = cpu_to_be16(be16_to_cpu(packet->data_len) - 0x100); 875 data_len -= 0x100;
862 if (be16_to_cpu(packet->x_len) > 0xff) 876 if (x_len > 0xff)
863 packet->x_len = cpu_to_be16(be16_to_cpu(packet->x_len) - 0x80); 877 x_len -= 0x80;
864 878
865 /* send ACK */ 879 /* send ACK */
866 ret = usb_submit_urb(priv->ack, GFP_ATOMIC); 880 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
867 881
868 if (!usbtouch->type->max_xc) { 882 if (!usbtouch->type->max_xc) {
869 usbtouch->type->max_xc = 2 * be16_to_cpu(packet->x_len); 883 usbtouch->type->max_xc = 2 * x_len;
870 input_set_abs_params(usbtouch->input, ABS_X, 0, 884 input_set_abs_params(usbtouch->input, ABS_X,
871 2 * be16_to_cpu(packet->x_len), 0, 0); 885 0, usbtouch->type->max_xc, 0, 0);
872 usbtouch->type->max_yc = 2 * be16_to_cpu(packet->y_len); 886 usbtouch->type->max_yc = 2 * y_len;
873 input_set_abs_params(usbtouch->input, ABS_Y, 0, 887 input_set_abs_params(usbtouch->input, ABS_Y,
874 2 * be16_to_cpu(packet->y_len), 0, 0); 888 0, usbtouch->type->max_yc, 0, 0);
875 } 889 }
876 /* 890 /*
877 * The device reports state of IR sensors on X and Y axes. 891 * The device reports state of IR sensors on X and Y axes.
@@ -881,22 +895,21 @@ static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
881 * it's disabled (and untested) here as there's no X driver for that. 895 * it's disabled (and untested) here as there's no X driver for that.
882 */ 896 */
883 begin_x = end_x = begin_y = end_y = -1; 897 begin_x = end_x = begin_y = end_y = -1;
884 for (x = 0; x < be16_to_cpu(packet->x_len); x++) { 898 for (x = 0; x < x_len; x++) {
885 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) { 899 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
886 begin_x = x; 900 begin_x = x;
887 continue; 901 continue;
888 } 902 }
889 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) { 903 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
890 end_x = x - 1; 904 end_x = x - 1;
891 for (y = be16_to_cpu(packet->x_len); 905 for (y = x_len; y < data_len; y++) {
892 y < be16_to_cpu(packet->data_len); y++) {
893 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) { 906 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
894 begin_y = y - be16_to_cpu(packet->x_len); 907 begin_y = y - x_len;
895 continue; 908 continue;
896 } 909 }
897 if (end_y == -1 && 910 if (end_y == -1 &&
898 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) { 911 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
899 end_y = y - 1 - be16_to_cpu(packet->x_len); 912 end_y = y - 1 - x_len;
900 w = end_x - begin_x; 913 w = end_x - begin_x;
901 h = end_y - begin_y; 914 h = end_y - begin_y;
902#if 0 915#if 0
@@ -1104,14 +1117,14 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
1104 }, 1117 },
1105#endif 1118#endif
1106 1119
1107#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH 1120#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1108 [DEVTYPE_TC5UH] = { 1121 [DEVTYPE_TC45USB] = {
1109 .min_xc = 0x0, 1122 .min_xc = 0x0,
1110 .max_xc = 0x0fff, 1123 .max_xc = 0x0fff,
1111 .min_yc = 0x0, 1124 .min_yc = 0x0,
1112 .max_yc = 0x0fff, 1125 .max_yc = 0x0fff,
1113 .rept_size = 5, 1126 .rept_size = 5,
1114 .read_data = tc5uh_read_data, 1127 .read_data = tc45usb_read_data,
1115 }, 1128 },
1116#endif 1129#endif
1117 1130
@@ -1120,6 +1133,7 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
1120 .rept_size = 1024, 1133 .rept_size = 1024,
1121 .irq_always = true, 1134 .irq_always = true,
1122 .read_data = nexio_read_data, 1135 .read_data = nexio_read_data,
1136 .alloc = nexio_alloc,
1123 .init = nexio_init, 1137 .init = nexio_init,
1124 .exit = nexio_exit, 1138 .exit = nexio_exit,
1125 }, 1139 },
@@ -1263,6 +1277,7 @@ static void usbtouch_irq(struct urb *urb)
1263 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length); 1277 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
1264 1278
1265exit: 1279exit:
1280 usb_mark_last_busy(interface_to_usbdev(usbtouch->interface));
1266 retval = usb_submit_urb(urb, GFP_ATOMIC); 1281 retval = usb_submit_urb(urb, GFP_ATOMIC);
1267 if (retval) 1282 if (retval)
1268 err("%s - usb_submit_urb failed with result: %d", 1283 err("%s - usb_submit_urb failed with result: %d",
@@ -1272,25 +1287,89 @@ exit:
1272static int usbtouch_open(struct input_dev *input) 1287static int usbtouch_open(struct input_dev *input)
1273{ 1288{
1274 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1289 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1290 int r;
1275 1291
1276 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface); 1292 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
1277 1293
1294 r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0;
1295 if (r < 0)
1296 goto out;
1297
1278 if (!usbtouch->type->irq_always) { 1298 if (!usbtouch->type->irq_always) {
1279 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) 1299 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) {
1280 return -EIO; 1300 r = -EIO;
1301 goto out_put;
1302 }
1281 } 1303 }
1282 1304
1283 return 0; 1305 usbtouch->interface->needs_remote_wakeup = 1;
1306out_put:
1307 usb_autopm_put_interface(usbtouch->interface);
1308out:
1309 return r;
1284} 1310}
1285 1311
1286static void usbtouch_close(struct input_dev *input) 1312static void usbtouch_close(struct input_dev *input)
1287{ 1313{
1288 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1314 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1315 int r;
1289 1316
1290 if (!usbtouch->type->irq_always) 1317 if (!usbtouch->type->irq_always)
1291 usb_kill_urb(usbtouch->irq); 1318 usb_kill_urb(usbtouch->irq);
1319 r = usb_autopm_get_interface(usbtouch->interface);
1320 usbtouch->interface->needs_remote_wakeup = 0;
1321 if (!r)
1322 usb_autopm_put_interface(usbtouch->interface);
1292} 1323}
1293 1324
1325static int usbtouch_suspend
1326(struct usb_interface *intf, pm_message_t message)
1327{
1328 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1329
1330 usb_kill_urb(usbtouch->irq);
1331
1332 return 0;
1333}
1334
1335static int usbtouch_resume(struct usb_interface *intf)
1336{
1337 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1338 struct input_dev *input = usbtouch->input;
1339 int result = 0;
1340
1341 mutex_lock(&input->mutex);
1342 if (input->users || usbtouch->type->irq_always)
1343 result = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1344 mutex_unlock(&input->mutex);
1345
1346 return result;
1347}
1348
1349static int usbtouch_reset_resume(struct usb_interface *intf)
1350{
1351 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1352 struct input_dev *input = usbtouch->input;
1353 int err = 0;
1354
1355 /* reinit the device */
1356 if (usbtouch->type->init) {
1357 err = usbtouch->type->init(usbtouch);
1358 if (err) {
1359 dbg("%s - type->init() failed, err: %d",
1360 __func__, err);
1361 return err;
1362 }
1363 }
1364
1365 /* restart IO if needed */
1366 mutex_lock(&input->mutex);
1367 if (input->users)
1368 err = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1369 mutex_unlock(&input->mutex);
1370
1371 return err;
1372}
1294 1373
1295static void usbtouch_free_buffers(struct usb_device *udev, 1374static void usbtouch_free_buffers(struct usb_device *udev,
1296 struct usbtouch_usb *usbtouch) 1375 struct usbtouch_usb *usbtouch)
@@ -1411,12 +1490,21 @@ static int usbtouch_probe(struct usb_interface *intf,
1411 usbtouch->irq->transfer_dma = usbtouch->data_dma; 1490 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1412 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1491 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1413 1492
1414 /* device specific init */ 1493 /* device specific allocations */
1494 if (type->alloc) {
1495 err = type->alloc(usbtouch);
1496 if (err) {
1497 dbg("%s - type->alloc() failed, err: %d", __func__, err);
1498 goto out_free_urb;
1499 }
1500 }
1501
1502 /* device specific initialisation*/
1415 if (type->init) { 1503 if (type->init) {
1416 err = type->init(usbtouch); 1504 err = type->init(usbtouch);
1417 if (err) { 1505 if (err) {
1418 dbg("%s - type->init() failed, err: %d", __func__, err); 1506 dbg("%s - type->init() failed, err: %d", __func__, err);
1419 goto out_free_urb; 1507 goto out_do_exit;
1420 } 1508 }
1421 } 1509 }
1422 1510
@@ -1429,8 +1517,11 @@ static int usbtouch_probe(struct usb_interface *intf,
1429 usb_set_intfdata(intf, usbtouch); 1517 usb_set_intfdata(intf, usbtouch);
1430 1518
1431 if (usbtouch->type->irq_always) { 1519 if (usbtouch->type->irq_always) {
1520 /* this can't fail */
1521 usb_autopm_get_interface(intf);
1432 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL); 1522 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1433 if (err) { 1523 if (err) {
1524 usb_autopm_put_interface(intf);
1434 err("%s - usb_submit_urb failed with result: %d", 1525 err("%s - usb_submit_urb failed with result: %d",
1435 __func__, err); 1526 __func__, err);
1436 goto out_unregister_input; 1527 goto out_unregister_input;
@@ -1481,7 +1572,11 @@ static struct usb_driver usbtouch_driver = {
1481 .name = "usbtouchscreen", 1572 .name = "usbtouchscreen",
1482 .probe = usbtouch_probe, 1573 .probe = usbtouch_probe,
1483 .disconnect = usbtouch_disconnect, 1574 .disconnect = usbtouch_disconnect,
1575 .suspend = usbtouch_suspend,
1576 .resume = usbtouch_resume,
1577 .reset_resume = usbtouch_reset_resume,
1484 .id_table = usbtouch_devices, 1578 .id_table = usbtouch_devices,
1579 .supports_autosuspend = 1,
1485}; 1580};
1486 1581
1487static int __init usbtouch_init(void) 1582static int __init usbtouch_init(void)
diff --git a/drivers/input/touchscreen/w90p910_ts.c b/drivers/input/touchscreen/w90p910_ts.c
index cc18265be1a8..7a45d68c3516 100644
--- a/drivers/input/touchscreen/w90p910_ts.c
+++ b/drivers/input/touchscreen/w90p910_ts.c
@@ -233,7 +233,7 @@ static int __devinit w90x900ts_probe(struct platform_device *pdev)
233 w90p910_ts->state = TS_IDLE; 233 w90p910_ts->state = TS_IDLE;
234 spin_lock_init(&w90p910_ts->lock); 234 spin_lock_init(&w90p910_ts->lock);
235 setup_timer(&w90p910_ts->timer, w90p910_check_pen_up, 235 setup_timer(&w90p910_ts->timer, w90p910_check_pen_up,
236 (unsigned long)&w90p910_ts); 236 (unsigned long)w90p910_ts);
237 237
238 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 238 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
239 if (!res) { 239 if (!res) {
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c
index e14081675bb2..ebb11907d402 100644
--- a/drivers/input/xen-kbdfront.c
+++ b/drivers/input/xen-kbdfront.c
@@ -339,7 +339,7 @@ static struct xenbus_driver xenkbd_driver = {
339 339
340static int __init xenkbd_init(void) 340static int __init xenkbd_init(void)
341{ 341{
342 if (!xen_domain()) 342 if (!xen_pv_domain())
343 return -ENODEV; 343 return -ENODEV;
344 344
345 /* Nothing to do if running in dom0. */ 345 /* Nothing to do if running in dom0. */