diff options
| author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-03-19 02:38:50 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-03-19 02:38:50 -0400 |
| commit | 97eb3f24352ec6632c2127b35d8087d2a809a9b9 (patch) | |
| tree | 722948059bbd325bbca232269490124231df80d4 /drivers/input | |
| parent | 439581ec07fa9cf3f519dd461a2cf41cfd3adcb4 (diff) | |
| parent | def179c271ac9b5020deca798470521f14d11edd (diff) | |
Merge branch 'next' into for-linus
Diffstat (limited to 'drivers/input')
44 files changed, 3675 insertions, 3496 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 07c2cd43109c..23e82e46656d 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig | |||
| @@ -6,7 +6,7 @@ menu "Input device support" | |||
| 6 | depends on !S390 | 6 | depends on !S390 |
| 7 | 7 | ||
| 8 | config INPUT | 8 | config INPUT |
| 9 | tristate "Generic input layer (needed for keyboard, mouse, ...)" if EMBEDDED | 9 | tristate "Generic input layer (needed for keyboard, mouse, ...)" if EXPERT |
| 10 | default y | 10 | default y |
| 11 | help | 11 | help |
| 12 | Say Y here if you have any input device (mouse, keyboard, tablet, | 12 | Say Y here if you have any input device (mouse, keyboard, tablet, |
| @@ -67,7 +67,7 @@ config INPUT_SPARSEKMAP | |||
| 67 | comment "Userland interfaces" | 67 | comment "Userland interfaces" |
| 68 | 68 | ||
| 69 | config INPUT_MOUSEDEV | 69 | config INPUT_MOUSEDEV |
| 70 | tristate "Mouse interface" if EMBEDDED | 70 | tristate "Mouse interface" if EXPERT |
| 71 | default y | 71 | default y |
| 72 | help | 72 | help |
| 73 | Say Y here if you want your mouse to be accessible as char devices | 73 | Say Y here if you want your mouse to be accessible as char devices |
| @@ -150,7 +150,7 @@ config INPUT_EVBUG | |||
| 150 | module will be called evbug. | 150 | module will be called evbug. |
| 151 | 151 | ||
| 152 | config INPUT_APMPOWER | 152 | config INPUT_APMPOWER |
| 153 | tristate "Input Power Event -> APM Bridge" if EMBEDDED | 153 | tristate "Input Power Event -> APM Bridge" if EXPERT |
| 154 | depends on INPUT && APM_EMULATION | 154 | depends on INPUT && APM_EMULATION |
| 155 | help | 155 | help |
| 156 | Say Y here if you want suspend key events to trigger a user | 156 | Say Y here if you want suspend key events to trigger a user |
| @@ -161,16 +161,6 @@ config INPUT_APMPOWER | |||
| 161 | To compile this driver as a module, choose M here: the | 161 | To compile this driver as a module, choose M here: the |
| 162 | module will be called apm-power. | 162 | module will be called apm-power. |
| 163 | 163 | ||
| 164 | config XEN_KBDDEV_FRONTEND | ||
| 165 | tristate "Xen virtual keyboard and mouse support" | ||
| 166 | depends on XEN_FBDEV_FRONTEND | ||
| 167 | default y | ||
| 168 | select XEN_XENBUS_FRONTEND | ||
| 169 | help | ||
| 170 | This driver implements the front-end of the Xen virtual | ||
| 171 | keyboard and mouse device driver. It communicates with a back-end | ||
| 172 | in another domain. | ||
| 173 | |||
| 174 | comment "Input Device Drivers" | 164 | comment "Input Device Drivers" |
| 175 | 165 | ||
| 176 | source "drivers/input/keyboard/Kconfig" | 166 | source "drivers/input/keyboard/Kconfig" |
diff --git a/drivers/input/Makefile b/drivers/input/Makefile index 09614ce74961..0c789490e0b3 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile | |||
| @@ -24,5 +24,3 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/ | |||
| 24 | obj-$(CONFIG_INPUT_MISC) += misc/ | 24 | obj-$(CONFIG_INPUT_MISC) += misc/ |
| 25 | 25 | ||
| 26 | obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o | 26 | obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o |
| 27 | |||
| 28 | obj-$(CONFIG_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o | ||
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index ce57ede6e981..5b8f59d6c3e8 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c | |||
| @@ -121,7 +121,7 @@ static int gameport_measure_speed(struct gameport *gameport) | |||
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | gameport_close(gameport); | 123 | gameport_close(gameport); |
| 124 | return (cpu_data(raw_smp_processor_id()).loops_per_jiffy * | 124 | return (this_cpu_read(cpu_info.loops_per_jiffy) * |
| 125 | (unsigned long)HZ / (1000 / 50)) / (tx < 1 ? 1 : tx); | 125 | (unsigned long)HZ / (1000 / 50)) / (tx < 1 ? 1 : tx); |
| 126 | 126 | ||
| 127 | #else | 127 | #else |
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c index 0559e309bac9..3037842a60d8 100644 --- a/drivers/input/input-polldev.c +++ b/drivers/input/input-polldev.c | |||
| @@ -192,7 +192,7 @@ static struct attribute_group input_polldev_attribute_group = { | |||
| 192 | }; | 192 | }; |
| 193 | 193 | ||
| 194 | /** | 194 | /** |
| 195 | * input_allocate_polled_device - allocated memory polled device | 195 | * input_allocate_polled_device - allocate memory for polled device |
| 196 | * | 196 | * |
| 197 | * The function allocates memory for a polled device and also | 197 | * The function allocates memory for a polled device and also |
| 198 | * for an input device associated with this polled device. | 198 | * for an input device associated with this polled device. |
| @@ -239,7 +239,7 @@ EXPORT_SYMBOL(input_free_polled_device); | |||
| 239 | * with input layer. The device should be allocated with call to | 239 | * with input layer. The device should be allocated with call to |
| 240 | * input_allocate_polled_device(). Callers should also set up poll() | 240 | * input_allocate_polled_device(). Callers should also set up poll() |
| 241 | * method and set up capabilities (id, name, phys, bits) of the | 241 | * method and set up capabilities (id, name, phys, bits) of the |
| 242 | * corresponing input_dev structure. | 242 | * corresponding input_dev structure. |
| 243 | */ | 243 | */ |
| 244 | int input_register_polled_device(struct input_polled_dev *dev) | 244 | int input_register_polled_device(struct input_polled_dev *dev) |
| 245 | { | 245 | { |
diff --git a/drivers/input/input.c b/drivers/input/input.c index b8894a059f87..d6e8bd8a851c 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | #include <linux/device.h> | 26 | #include <linux/device.h> |
| 27 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
| 28 | #include <linux/rcupdate.h> | 28 | #include <linux/rcupdate.h> |
| 29 | #include <linux/smp_lock.h> | ||
| 30 | #include "input-compat.h" | 29 | #include "input-compat.h" |
| 31 | 30 | ||
| 32 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); | 31 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); |
| @@ -792,22 +791,9 @@ int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke) | |||
| 792 | int retval; | 791 | int retval; |
| 793 | 792 | ||
| 794 | spin_lock_irqsave(&dev->event_lock, flags); | 793 | spin_lock_irqsave(&dev->event_lock, flags); |
| 795 | 794 | retval = dev->getkeycode(dev, ke); | |
| 796 | if (dev->getkeycode) { | ||
| 797 | /* | ||
| 798 | * Support for legacy drivers, that don't implement the new | ||
| 799 | * ioctls | ||
| 800 | */ | ||
| 801 | u32 scancode = ke->index; | ||
| 802 | |||
| 803 | memcpy(ke->scancode, &scancode, sizeof(scancode)); | ||
| 804 | ke->len = sizeof(scancode); | ||
| 805 | retval = dev->getkeycode(dev, scancode, &ke->keycode); | ||
| 806 | } else { | ||
| 807 | retval = dev->getkeycode_new(dev, ke); | ||
| 808 | } | ||
| 809 | |||
| 810 | spin_unlock_irqrestore(&dev->event_lock, flags); | 795 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 796 | |||
| 811 | return retval; | 797 | return retval; |
| 812 | } | 798 | } |
| 813 | EXPORT_SYMBOL(input_get_keycode); | 799 | EXPORT_SYMBOL(input_get_keycode); |
| @@ -832,35 +818,7 @@ int input_set_keycode(struct input_dev *dev, | |||
| 832 | 818 | ||
| 833 | spin_lock_irqsave(&dev->event_lock, flags); | 819 | spin_lock_irqsave(&dev->event_lock, flags); |
| 834 | 820 | ||
| 835 | if (dev->setkeycode) { | 821 | retval = dev->setkeycode(dev, ke, &old_keycode); |
| 836 | /* | ||
| 837 | * Support for legacy drivers, that don't implement the new | ||
| 838 | * ioctls | ||
| 839 | */ | ||
| 840 | unsigned int scancode; | ||
| 841 | |||
| 842 | retval = input_scancode_to_scalar(ke, &scancode); | ||
| 843 | if (retval) | ||
| 844 | goto out; | ||
| 845 | |||
| 846 | /* | ||
| 847 | * We need to know the old scancode, in order to generate a | ||
| 848 | * keyup effect, if the set operation happens successfully | ||
| 849 | */ | ||
| 850 | if (!dev->getkeycode) { | ||
| 851 | retval = -EINVAL; | ||
| 852 | goto out; | ||
| 853 | } | ||
| 854 | |||
| 855 | retval = dev->getkeycode(dev, scancode, &old_keycode); | ||
| 856 | if (retval) | ||
| 857 | goto out; | ||
| 858 | |||
| 859 | retval = dev->setkeycode(dev, scancode, ke->keycode); | ||
| 860 | } else { | ||
| 861 | retval = dev->setkeycode_new(dev, ke, &old_keycode); | ||
| 862 | } | ||
| 863 | |||
| 864 | if (retval) | 822 | if (retval) |
| 865 | goto out; | 823 | goto out; |
| 866 | 824 | ||
| @@ -1847,11 +1805,11 @@ int input_register_device(struct input_dev *dev) | |||
| 1847 | dev->rep[REP_PERIOD] = 33; | 1805 | dev->rep[REP_PERIOD] = 33; |
| 1848 | } | 1806 | } |
| 1849 | 1807 | ||
| 1850 | if (!dev->getkeycode && !dev->getkeycode_new) | 1808 | if (!dev->getkeycode) |
| 1851 | dev->getkeycode_new = input_default_getkeycode; | 1809 | dev->getkeycode = input_default_getkeycode; |
| 1852 | 1810 | ||
| 1853 | if (!dev->setkeycode && !dev->setkeycode_new) | 1811 | if (!dev->setkeycode) |
| 1854 | dev->setkeycode_new = input_default_setkeycode; | 1812 | dev->setkeycode = input_default_setkeycode; |
| 1855 | 1813 | ||
| 1856 | dev_set_name(&dev->dev, "input%ld", | 1814 | dev_set_name(&dev->dev, "input%ld", |
| 1857 | (unsigned long) atomic_inc_return(&input_no) - 1); | 1815 | (unsigned long) atomic_inc_return(&input_no) - 1); |
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index b7dca74eb9be..b16bed038f72 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | # Input core configuration | 2 | # Input core configuration |
| 3 | # | 3 | # |
| 4 | menuconfig INPUT_KEYBOARD | 4 | menuconfig INPUT_KEYBOARD |
| 5 | bool "Keyboards" if EMBEDDED || !X86 | 5 | bool "Keyboards" if EXPERT || !X86 |
| 6 | default y | 6 | default y |
| 7 | help | 7 | help |
| 8 | Say Y here, and a list of supported keyboards will be displayed. | 8 | Say Y here, and a list of supported keyboards will be displayed. |
| @@ -57,7 +57,7 @@ config KEYBOARD_ATARI | |||
| 57 | module will be called atakbd. | 57 | module will be called atakbd. |
| 58 | 58 | ||
| 59 | config KEYBOARD_ATKBD | 59 | config KEYBOARD_ATKBD |
| 60 | tristate "AT keyboard" if EMBEDDED || !X86 | 60 | tristate "AT keyboard" if EXPERT || !X86 |
| 61 | default y | 61 | default y |
| 62 | select SERIO | 62 | select SERIO |
| 63 | select SERIO_LIBPS2 | 63 | select SERIO_LIBPS2 |
| @@ -112,6 +112,16 @@ config KEYBOARD_ATKBD_RDI_KEYCODES | |||
| 112 | right-hand column will be interpreted as the key shown in the | 112 | right-hand column will be interpreted as the key shown in the |
| 113 | left-hand column. | 113 | left-hand column. |
| 114 | 114 | ||
| 115 | config KEYBOARD_QT1070 | ||
| 116 | tristate "Atmel AT42QT1070 Touch Sensor Chip" | ||
| 117 | depends on I2C | ||
| 118 | help | ||
| 119 | Say Y here if you want to use Atmel AT42QT1070 QTouch | ||
| 120 | Sensor chip as input device. | ||
| 121 | |||
| 122 | To compile this driver as a module, choose M here: | ||
| 123 | the module will be called qt1070 | ||
| 124 | |||
| 115 | config KEYBOARD_QT2160 | 125 | config KEYBOARD_QT2160 |
| 116 | tristate "Atmel AT42QT2160 Touch Sensor Chip" | 126 | tristate "Atmel AT42QT2160 Touch Sensor Chip" |
| 117 | depends on I2C && EXPERIMENTAL | 127 | depends on I2C && EXPERIMENTAL |
| @@ -468,6 +478,16 @@ config KEYBOARD_SPEAR | |||
| 468 | To compile this driver as a module, choose M here: the | 478 | To compile this driver as a module, choose M here: the |
| 469 | module will be called spear-keboard. | 479 | module will be called spear-keboard. |
| 470 | 480 | ||
| 481 | config KEYBOARD_TC3589X | ||
| 482 | tristate "TC3589X Keypad support" | ||
| 483 | depends on MFD_TC3589X | ||
| 484 | help | ||
| 485 | Say Y here if you want to use the keypad controller on | ||
| 486 | TC35892/3 I/O expander. | ||
| 487 | |||
| 488 | To compile this driver as a module, choose M here: the | ||
| 489 | module will be called tc3589x-keypad. | ||
| 490 | |||
| 471 | config KEYBOARD_TNETV107X | 491 | config KEYBOARD_TNETV107X |
| 472 | tristate "TI TNETV107X keypad support" | 492 | tristate "TI TNETV107X keypad support" |
| 473 | depends on ARCH_DAVINCI_TNETV107X | 493 | depends on ARCH_DAVINCI_TNETV107X |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 3456b931e254..878e6c20deb0 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
| @@ -34,6 +34,7 @@ obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o | |||
| 34 | obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o | 34 | obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o |
| 35 | obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o | 35 | obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o |
| 36 | obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o | 36 | obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o |
| 37 | obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o | ||
| 37 | obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o | 38 | obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o |
| 38 | obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o | 39 | obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o |
| 39 | obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o | 40 | obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o |
| @@ -41,6 +42,7 @@ obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o | |||
| 41 | obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o | 42 | obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o |
| 42 | obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o | 43 | obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o |
| 43 | obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o | 44 | obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o |
| 45 | obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o | ||
| 44 | obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o | 46 | obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o |
| 45 | obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o | 47 | obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o |
| 46 | obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o | 48 | obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o |
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c index f7c2a166576b..b732870ecc89 100644 --- a/drivers/input/keyboard/lm8323.c +++ b/drivers/input/keyboard/lm8323.c | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | #include <linux/delay.h> | 30 | #include <linux/delay.h> |
| 31 | #include <linux/input.h> | 31 | #include <linux/input.h> |
| 32 | #include <linux/leds.h> | 32 | #include <linux/leds.h> |
| 33 | #include <linux/pm.h> | ||
| 33 | #include <linux/i2c/lm8323.h> | 34 | #include <linux/i2c/lm8323.h> |
| 34 | #include <linux/slab.h> | 35 | #include <linux/slab.h> |
| 35 | 36 | ||
| @@ -802,8 +803,9 @@ static int __devexit lm8323_remove(struct i2c_client *client) | |||
| 802 | * We don't need to explicitly suspend the chip, as it already switches off | 803 | * We don't need to explicitly suspend the chip, as it already switches off |
| 803 | * when there's no activity. | 804 | * when there's no activity. |
| 804 | */ | 805 | */ |
| 805 | static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg) | 806 | static int lm8323_suspend(struct device *dev) |
| 806 | { | 807 | { |
| 808 | struct i2c_client *client = to_i2c_client(dev); | ||
| 807 | struct lm8323_chip *lm = i2c_get_clientdata(client); | 809 | struct lm8323_chip *lm = i2c_get_clientdata(client); |
| 808 | int i; | 810 | int i; |
| 809 | 811 | ||
| @@ -821,8 +823,9 @@ static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg) | |||
| 821 | return 0; | 823 | return 0; |
| 822 | } | 824 | } |
| 823 | 825 | ||
| 824 | static int lm8323_resume(struct i2c_client *client) | 826 | static int lm8323_resume(struct device *dev) |
| 825 | { | 827 | { |
| 828 | struct i2c_client *client = to_i2c_client(dev); | ||
| 826 | struct lm8323_chip *lm = i2c_get_clientdata(client); | 829 | struct lm8323_chip *lm = i2c_get_clientdata(client); |
| 827 | int i; | 830 | int i; |
| 828 | 831 | ||
| @@ -839,11 +842,10 @@ static int lm8323_resume(struct i2c_client *client) | |||
| 839 | 842 | ||
| 840 | return 0; | 843 | return 0; |
| 841 | } | 844 | } |
| 842 | #else | ||
| 843 | #define lm8323_suspend NULL | ||
| 844 | #define lm8323_resume NULL | ||
| 845 | #endif | 845 | #endif |
| 846 | 846 | ||
| 847 | static SIMPLE_DEV_PM_OPS(lm8323_pm_ops, lm8323_suspend, lm8323_resume); | ||
| 848 | |||
| 847 | static const struct i2c_device_id lm8323_id[] = { | 849 | static const struct i2c_device_id lm8323_id[] = { |
| 848 | { "lm8323", 0 }, | 850 | { "lm8323", 0 }, |
| 849 | { } | 851 | { } |
| @@ -852,11 +854,10 @@ static const struct i2c_device_id lm8323_id[] = { | |||
| 852 | static struct i2c_driver lm8323_i2c_driver = { | 854 | static struct i2c_driver lm8323_i2c_driver = { |
| 853 | .driver = { | 855 | .driver = { |
| 854 | .name = "lm8323", | 856 | .name = "lm8323", |
| 857 | .pm = &lm8323_pm_ops, | ||
| 855 | }, | 858 | }, |
| 856 | .probe = lm8323_probe, | 859 | .probe = lm8323_probe, |
| 857 | .remove = __devexit_p(lm8323_remove), | 860 | .remove = __devexit_p(lm8323_remove), |
| 858 | .suspend = lm8323_suspend, | ||
| 859 | .resume = lm8323_resume, | ||
| 860 | .id_table = lm8323_id, | 861 | .id_table = lm8323_id, |
| 861 | }; | 862 | }; |
| 862 | MODULE_DEVICE_TABLE(i2c, lm8323_id); | 863 | MODULE_DEVICE_TABLE(i2c, lm8323_id); |
diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c index 9091ff5ea808..5afe35ad24d3 100644 --- a/drivers/input/keyboard/max7359_keypad.c +++ b/drivers/input/keyboard/max7359_keypad.c | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
| 18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
| 19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/pm.h> | ||
| 20 | #include <linux/input.h> | 21 | #include <linux/input.h> |
| 21 | #include <linux/input/matrix_keypad.h> | 22 | #include <linux/input/matrix_keypad.h> |
| 22 | 23 | ||
| @@ -271,8 +272,10 @@ static int __devexit max7359_remove(struct i2c_client *client) | |||
| 271 | } | 272 | } |
| 272 | 273 | ||
| 273 | #ifdef CONFIG_PM | 274 | #ifdef CONFIG_PM |
| 274 | static int max7359_suspend(struct i2c_client *client, pm_message_t mesg) | 275 | static int max7359_suspend(struct device *dev) |
| 275 | { | 276 | { |
| 277 | struct i2c_client *client = to_i2c_client(dev); | ||
| 278 | |||
| 276 | max7359_fall_deepsleep(client); | 279 | max7359_fall_deepsleep(client); |
| 277 | 280 | ||
| 278 | if (device_may_wakeup(&client->dev)) | 281 | if (device_may_wakeup(&client->dev)) |
| @@ -281,8 +284,10 @@ static int max7359_suspend(struct i2c_client *client, pm_message_t mesg) | |||
| 281 | return 0; | 284 | return 0; |
| 282 | } | 285 | } |
| 283 | 286 | ||
| 284 | static int max7359_resume(struct i2c_client *client) | 287 | static int max7359_resume(struct device *dev) |
| 285 | { | 288 | { |
| 289 | struct i2c_client *client = to_i2c_client(dev); | ||
| 290 | |||
| 286 | if (device_may_wakeup(&client->dev)) | 291 | if (device_may_wakeup(&client->dev)) |
| 287 | disable_irq_wake(client->irq); | 292 | disable_irq_wake(client->irq); |
| 288 | 293 | ||
| @@ -291,11 +296,10 @@ static int max7359_resume(struct i2c_client *client) | |||
| 291 | 296 | ||
| 292 | return 0; | 297 | return 0; |
| 293 | } | 298 | } |
| 294 | #else | ||
| 295 | #define max7359_suspend NULL | ||
| 296 | #define max7359_resume NULL | ||
| 297 | #endif | 299 | #endif |
| 298 | 300 | ||
| 301 | static SIMPLE_DEV_PM_OPS(max7359_pm, max7359_suspend, max7359_resume); | ||
| 302 | |||
| 299 | static const struct i2c_device_id max7359_ids[] = { | 303 | static const struct i2c_device_id max7359_ids[] = { |
| 300 | { "max7359", 0 }, | 304 | { "max7359", 0 }, |
| 301 | { } | 305 | { } |
| @@ -305,11 +309,10 @@ MODULE_DEVICE_TABLE(i2c, max7359_ids); | |||
| 305 | static struct i2c_driver max7359_i2c_driver = { | 309 | static struct i2c_driver max7359_i2c_driver = { |
| 306 | .driver = { | 310 | .driver = { |
| 307 | .name = "max7359", | 311 | .name = "max7359", |
| 312 | .pm = &max7359_pm, | ||
| 308 | }, | 313 | }, |
| 309 | .probe = max7359_probe, | 314 | .probe = max7359_probe, |
| 310 | .remove = __devexit_p(max7359_remove), | 315 | .remove = __devexit_p(max7359_remove), |
| 311 | .suspend = max7359_suspend, | ||
| 312 | .resume = max7359_resume, | ||
| 313 | .id_table = max7359_ids, | 316 | .id_table = max7359_ids, |
| 314 | }; | 317 | }; |
| 315 | 318 | ||
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c index 63b849d7e90b..af1aab324a4c 100644 --- a/drivers/input/keyboard/mcs_touchkey.c +++ b/drivers/input/keyboard/mcs_touchkey.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * mcs_touchkey.c - Touchkey driver for MELFAS MCS5000/5080 controller | 2 | * Touchkey driver for MELFAS MCS5000/5080 controller |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd |
| 5 | * Author: HeungJun Kim <riverful.kim@samsung.com> | 5 | * Author: HeungJun Kim <riverful.kim@samsung.com> |
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <linux/input.h> | 19 | #include <linux/input.h> |
| 20 | #include <linux/irq.h> | 20 | #include <linux/irq.h> |
| 21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
| 22 | #include <linux/pm.h> | ||
| 22 | 23 | ||
| 23 | /* MCS5000 Touchkey */ | 24 | /* MCS5000 Touchkey */ |
| 24 | #define MCS5000_TOUCHKEY_STATUS 0x04 | 25 | #define MCS5000_TOUCHKEY_STATUS 0x04 |
| @@ -45,6 +46,8 @@ struct mcs_touchkey_chip { | |||
| 45 | }; | 46 | }; |
| 46 | 47 | ||
| 47 | struct mcs_touchkey_data { | 48 | struct mcs_touchkey_data { |
| 49 | void (*poweron)(bool); | ||
| 50 | |||
| 48 | struct i2c_client *client; | 51 | struct i2c_client *client; |
| 49 | struct input_dev *input_dev; | 52 | struct input_dev *input_dev; |
| 50 | struct mcs_touchkey_chip chip; | 53 | struct mcs_touchkey_chip chip; |
| @@ -169,6 +172,11 @@ static int __devinit mcs_touchkey_probe(struct i2c_client *client, | |||
| 169 | if (pdata->cfg_pin) | 172 | if (pdata->cfg_pin) |
| 170 | pdata->cfg_pin(); | 173 | pdata->cfg_pin(); |
| 171 | 174 | ||
| 175 | if (pdata->poweron) { | ||
| 176 | data->poweron = pdata->poweron; | ||
| 177 | data->poweron(true); | ||
| 178 | } | ||
| 179 | |||
| 172 | error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt, | 180 | error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt, |
| 173 | IRQF_TRIGGER_FALLING, client->dev.driver->name, data); | 181 | IRQF_TRIGGER_FALLING, client->dev.driver->name, data); |
| 174 | if (error) { | 182 | if (error) { |
| @@ -196,12 +204,57 @@ static int __devexit mcs_touchkey_remove(struct i2c_client *client) | |||
| 196 | struct mcs_touchkey_data *data = i2c_get_clientdata(client); | 204 | struct mcs_touchkey_data *data = i2c_get_clientdata(client); |
| 197 | 205 | ||
| 198 | free_irq(client->irq, data); | 206 | free_irq(client->irq, data); |
| 207 | if (data->poweron) | ||
| 208 | data->poweron(false); | ||
| 199 | input_unregister_device(data->input_dev); | 209 | input_unregister_device(data->input_dev); |
| 200 | kfree(data); | 210 | kfree(data); |
| 201 | 211 | ||
| 202 | return 0; | 212 | return 0; |
| 203 | } | 213 | } |
| 204 | 214 | ||
| 215 | static void mcs_touchkey_shutdown(struct i2c_client *client) | ||
| 216 | { | ||
| 217 | struct mcs_touchkey_data *data = i2c_get_clientdata(client); | ||
| 218 | |||
| 219 | if (data->poweron) | ||
| 220 | data->poweron(false); | ||
| 221 | } | ||
| 222 | |||
| 223 | #ifdef CONFIG_PM_SLEEP | ||
| 224 | static int mcs_touchkey_suspend(struct device *dev) | ||
| 225 | { | ||
| 226 | struct mcs_touchkey_data *data = dev_get_drvdata(dev); | ||
| 227 | struct i2c_client *client = data->client; | ||
| 228 | |||
| 229 | /* Disable the work */ | ||
| 230 | disable_irq(client->irq); | ||
| 231 | |||
| 232 | /* Finally turn off the power */ | ||
| 233 | if (data->poweron) | ||
| 234 | data->poweron(false); | ||
| 235 | |||
| 236 | return 0; | ||
| 237 | } | ||
| 238 | |||
| 239 | static int mcs_touchkey_resume(struct device *dev) | ||
| 240 | { | ||
| 241 | struct mcs_touchkey_data *data = dev_get_drvdata(dev); | ||
| 242 | struct i2c_client *client = data->client; | ||
| 243 | |||
| 244 | /* Enable the device first */ | ||
| 245 | if (data->poweron) | ||
| 246 | data->poweron(true); | ||
| 247 | |||
| 248 | /* Enable irq again */ | ||
| 249 | enable_irq(client->irq); | ||
| 250 | |||
| 251 | return 0; | ||
| 252 | } | ||
| 253 | #endif | ||
| 254 | |||
| 255 | static SIMPLE_DEV_PM_OPS(mcs_touchkey_pm_ops, | ||
| 256 | mcs_touchkey_suspend, mcs_touchkey_resume); | ||
| 257 | |||
| 205 | static const struct i2c_device_id mcs_touchkey_id[] = { | 258 | static const struct i2c_device_id mcs_touchkey_id[] = { |
| 206 | { "mcs5000_touchkey", MCS5000_TOUCHKEY }, | 259 | { "mcs5000_touchkey", MCS5000_TOUCHKEY }, |
| 207 | { "mcs5080_touchkey", MCS5080_TOUCHKEY }, | 260 | { "mcs5080_touchkey", MCS5080_TOUCHKEY }, |
| @@ -213,9 +266,11 @@ static struct i2c_driver mcs_touchkey_driver = { | |||
| 213 | .driver = { | 266 | .driver = { |
| 214 | .name = "mcs_touchkey", | 267 | .name = "mcs_touchkey", |
| 215 | .owner = THIS_MODULE, | 268 | .owner = THIS_MODULE, |
| 269 | .pm = &mcs_touchkey_pm_ops, | ||
| 216 | }, | 270 | }, |
| 217 | .probe = mcs_touchkey_probe, | 271 | .probe = mcs_touchkey_probe, |
| 218 | .remove = __devexit_p(mcs_touchkey_remove), | 272 | .remove = __devexit_p(mcs_touchkey_remove), |
| 273 | .shutdown = mcs_touchkey_shutdown, | ||
| 219 | .id_table = mcs_touchkey_id, | 274 | .id_table = mcs_touchkey_id, |
| 220 | }; | 275 | }; |
| 221 | 276 | ||
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c index a72e61ddca91..0e2a19cb43d8 100644 --- a/drivers/input/keyboard/omap-keypad.c +++ b/drivers/input/keyboard/omap-keypad.c | |||
| @@ -65,7 +65,6 @@ struct omap_kp { | |||
| 65 | 65 | ||
| 66 | static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0); | 66 | static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0); |
| 67 | 67 | ||
| 68 | static int *keymap; | ||
| 69 | static unsigned int *row_gpios; | 68 | static unsigned int *row_gpios; |
| 70 | static unsigned int *col_gpios; | 69 | static unsigned int *col_gpios; |
| 71 | 70 | ||
| @@ -162,20 +161,11 @@ static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state) | |||
| 162 | } | 161 | } |
| 163 | } | 162 | } |
| 164 | 163 | ||
| 165 | static inline int omap_kp_find_key(int col, int row) | ||
| 166 | { | ||
| 167 | int i, key; | ||
| 168 | |||
| 169 | key = KEY(col, row, 0); | ||
| 170 | for (i = 0; keymap[i] != 0; i++) | ||
| 171 | if ((keymap[i] & 0xff000000) == key) | ||
| 172 | return keymap[i] & 0x00ffffff; | ||
| 173 | return -1; | ||
| 174 | } | ||
| 175 | |||
| 176 | static void omap_kp_tasklet(unsigned long data) | 164 | static void omap_kp_tasklet(unsigned long data) |
| 177 | { | 165 | { |
| 178 | struct omap_kp *omap_kp_data = (struct omap_kp *) data; | 166 | struct omap_kp *omap_kp_data = (struct omap_kp *) data; |
| 167 | unsigned short *keycodes = omap_kp_data->input->keycode; | ||
| 168 | unsigned int row_shift = get_count_order(omap_kp_data->cols); | ||
| 179 | unsigned char new_state[8], changed, key_down = 0; | 169 | unsigned char new_state[8], changed, key_down = 0; |
| 180 | int col, row; | 170 | int col, row; |
| 181 | int spurious = 0; | 171 | int spurious = 0; |
| @@ -199,7 +189,7 @@ static void omap_kp_tasklet(unsigned long data) | |||
| 199 | row, (new_state[col] & (1 << row)) ? | 189 | row, (new_state[col] & (1 << row)) ? |
| 200 | "pressed" : "released"); | 190 | "pressed" : "released"); |
| 201 | #else | 191 | #else |
| 202 | key = omap_kp_find_key(col, row); | 192 | key = keycodes[MATRIX_SCAN_CODE(row, col, row_shift)]; |
| 203 | if (key < 0) { | 193 | if (key < 0) { |
| 204 | printk(KERN_WARNING | 194 | printk(KERN_WARNING |
| 205 | "omap-keypad: Spurious key event %d-%d\n", | 195 | "omap-keypad: Spurious key event %d-%d\n", |
| @@ -298,13 +288,18 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
| 298 | struct input_dev *input_dev; | 288 | struct input_dev *input_dev; |
| 299 | struct omap_kp_platform_data *pdata = pdev->dev.platform_data; | 289 | struct omap_kp_platform_data *pdata = pdev->dev.platform_data; |
| 300 | int i, col_idx, row_idx, irq_idx, ret; | 290 | int i, col_idx, row_idx, irq_idx, ret; |
| 291 | unsigned int row_shift, keycodemax; | ||
| 301 | 292 | ||
| 302 | if (!pdata->rows || !pdata->cols || !pdata->keymap) { | 293 | if (!pdata->rows || !pdata->cols || !pdata->keymap_data) { |
| 303 | printk(KERN_ERR "No rows, cols or keymap from pdata\n"); | 294 | printk(KERN_ERR "No rows, cols or keymap_data from pdata\n"); |
| 304 | return -EINVAL; | 295 | return -EINVAL; |
| 305 | } | 296 | } |
| 306 | 297 | ||
| 307 | omap_kp = kzalloc(sizeof(struct omap_kp), GFP_KERNEL); | 298 | row_shift = get_count_order(pdata->cols); |
| 299 | keycodemax = pdata->rows << row_shift; | ||
| 300 | |||
| 301 | omap_kp = kzalloc(sizeof(struct omap_kp) + | ||
| 302 | keycodemax * sizeof(unsigned short), GFP_KERNEL); | ||
| 308 | input_dev = input_allocate_device(); | 303 | input_dev = input_allocate_device(); |
| 309 | if (!omap_kp || !input_dev) { | 304 | if (!omap_kp || !input_dev) { |
| 310 | kfree(omap_kp); | 305 | kfree(omap_kp); |
| @@ -320,7 +315,9 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
| 320 | if (!cpu_is_omap24xx()) | 315 | if (!cpu_is_omap24xx()) |
| 321 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 316 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
| 322 | 317 | ||
| 323 | keymap = pdata->keymap; | 318 | input_dev->keycode = &omap_kp[1]; |
| 319 | input_dev->keycodesize = sizeof(unsigned short); | ||
| 320 | input_dev->keycodemax = keycodemax; | ||
| 324 | 321 | ||
| 325 | if (pdata->rep) | 322 | if (pdata->rep) |
| 326 | __set_bit(EV_REP, input_dev->evbit); | 323 | __set_bit(EV_REP, input_dev->evbit); |
| @@ -374,8 +371,8 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
| 374 | 371 | ||
| 375 | /* setup input device */ | 372 | /* setup input device */ |
| 376 | __set_bit(EV_KEY, input_dev->evbit); | 373 | __set_bit(EV_KEY, input_dev->evbit); |
| 377 | for (i = 0; keymap[i] != 0; i++) | 374 | matrix_keypad_build_keymap(pdata->keymap_data, row_shift, |
| 378 | __set_bit(keymap[i] & KEY_MAX, input_dev->keybit); | 375 | input_dev->keycode, input_dev->keybit); |
| 379 | input_dev->name = "omap-keypad"; | 376 | input_dev->name = "omap-keypad"; |
| 380 | input_dev->phys = "omap-keypad/input0"; | 377 | input_dev->phys = "omap-keypad/input0"; |
| 381 | input_dev->dev.parent = &pdev->dev; | 378 | input_dev->dev.parent = &pdev->dev; |
| @@ -416,7 +413,7 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
| 416 | return 0; | 413 | return 0; |
| 417 | err5: | 414 | err5: |
| 418 | for (i = irq_idx - 1; i >=0; i--) | 415 | for (i = irq_idx - 1; i >=0; i--) |
| 419 | free_irq(row_gpios[i], 0); | 416 | free_irq(row_gpios[i], NULL); |
| 420 | err4: | 417 | err4: |
| 421 | input_unregister_device(omap_kp->input); | 418 | input_unregister_device(omap_kp->input); |
| 422 | input_dev = NULL; | 419 | input_dev = NULL; |
| @@ -447,11 +444,11 @@ static int __devexit omap_kp_remove(struct platform_device *pdev) | |||
| 447 | gpio_free(col_gpios[i]); | 444 | gpio_free(col_gpios[i]); |
| 448 | for (i = 0; i < omap_kp->rows; i++) { | 445 | for (i = 0; i < omap_kp->rows; i++) { |
| 449 | gpio_free(row_gpios[i]); | 446 | gpio_free(row_gpios[i]); |
| 450 | free_irq(gpio_to_irq(row_gpios[i]), 0); | 447 | free_irq(gpio_to_irq(row_gpios[i]), NULL); |
| 451 | } | 448 | } |
| 452 | } else { | 449 | } else { |
| 453 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 450 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
| 454 | free_irq(omap_kp->irq, 0); | 451 | free_irq(omap_kp->irq, NULL); |
| 455 | } | 452 | } |
| 456 | 453 | ||
| 457 | del_timer_sync(&omap_kp->timer); | 454 | del_timer_sync(&omap_kp->timer); |
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c index 45bd0977d006..c51a3c4a7feb 100644 --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #include <linux/io.h> | 29 | #include <linux/io.h> |
| 30 | #include <linux/input.h> | 30 | #include <linux/input.h> |
| 31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
| 32 | #include <linux/pm_runtime.h> | ||
| 32 | 33 | ||
| 33 | #include <plat/omap4-keypad.h> | 34 | #include <plat/omap4-keypad.h> |
| 34 | 35 | ||
| @@ -80,20 +81,6 @@ struct omap4_keypad { | |||
| 80 | unsigned short keymap[]; | 81 | unsigned short keymap[]; |
| 81 | }; | 82 | }; |
| 82 | 83 | ||
| 83 | static void __devinit omap4_keypad_config(struct omap4_keypad *keypad_data) | ||
| 84 | { | ||
| 85 | __raw_writel(OMAP4_VAL_FUNCTIONALCFG, | ||
| 86 | keypad_data->base + OMAP4_KBD_CTRL); | ||
| 87 | __raw_writel(OMAP4_VAL_DEBOUNCINGTIME, | ||
| 88 | keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME); | ||
| 89 | __raw_writel(OMAP4_VAL_IRQDISABLE, | ||
| 90 | keypad_data->base + OMAP4_KBD_IRQSTATUS); | ||
| 91 | __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY, | ||
| 92 | keypad_data->base + OMAP4_KBD_IRQENABLE); | ||
| 93 | __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA, | ||
| 94 | keypad_data->base + OMAP4_KBD_WAKEUPENABLE); | ||
| 95 | } | ||
| 96 | |||
| 97 | /* Interrupt handler */ | 84 | /* Interrupt handler */ |
| 98 | static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) | 85 | static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) |
| 99 | { | 86 | { |
| @@ -144,6 +131,49 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) | |||
| 144 | return IRQ_HANDLED; | 131 | return IRQ_HANDLED; |
| 145 | } | 132 | } |
| 146 | 133 | ||
| 134 | static int omap4_keypad_open(struct input_dev *input) | ||
| 135 | { | ||
| 136 | struct omap4_keypad *keypad_data = input_get_drvdata(input); | ||
| 137 | |||
| 138 | pm_runtime_get_sync(input->dev.parent); | ||
| 139 | |||
| 140 | disable_irq(keypad_data->irq); | ||
| 141 | |||
| 142 | __raw_writel(OMAP4_VAL_FUNCTIONALCFG, | ||
| 143 | keypad_data->base + OMAP4_KBD_CTRL); | ||
| 144 | __raw_writel(OMAP4_VAL_DEBOUNCINGTIME, | ||
| 145 | keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME); | ||
| 146 | __raw_writel(OMAP4_VAL_IRQDISABLE, | ||
| 147 | keypad_data->base + OMAP4_KBD_IRQSTATUS); | ||
| 148 | __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY, | ||
| 149 | keypad_data->base + OMAP4_KBD_IRQENABLE); | ||
| 150 | __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA, | ||
| 151 | keypad_data->base + OMAP4_KBD_WAKEUPENABLE); | ||
| 152 | |||
| 153 | enable_irq(keypad_data->irq); | ||
| 154 | |||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | |||
| 158 | static void omap4_keypad_close(struct input_dev *input) | ||
| 159 | { | ||
| 160 | struct omap4_keypad *keypad_data = input_get_drvdata(input); | ||
| 161 | |||
| 162 | disable_irq(keypad_data->irq); | ||
| 163 | |||
| 164 | /* Disable interrupts */ | ||
| 165 | __raw_writel(OMAP4_VAL_IRQDISABLE, | ||
| 166 | keypad_data->base + OMAP4_KBD_IRQENABLE); | ||
| 167 | |||
| 168 | /* clear pending interrupts */ | ||
| 169 | __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS), | ||
| 170 | keypad_data->base + OMAP4_KBD_IRQSTATUS); | ||
| 171 | |||
| 172 | enable_irq(keypad_data->irq); | ||
| 173 | |||
| 174 | pm_runtime_put_sync(input->dev.parent); | ||
| 175 | } | ||
| 176 | |||
| 147 | static int __devinit omap4_keypad_probe(struct platform_device *pdev) | 177 | static int __devinit omap4_keypad_probe(struct platform_device *pdev) |
| 148 | { | 178 | { |
| 149 | const struct omap4_keypad_platform_data *pdata; | 179 | const struct omap4_keypad_platform_data *pdata; |
| @@ -225,6 +255,9 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev) | |||
| 225 | input_dev->id.product = 0x0001; | 255 | input_dev->id.product = 0x0001; |
| 226 | input_dev->id.version = 0x0001; | 256 | input_dev->id.version = 0x0001; |
| 227 | 257 | ||
| 258 | input_dev->open = omap4_keypad_open; | ||
| 259 | input_dev->close = omap4_keypad_close; | ||
| 260 | |||
| 228 | input_dev->keycode = keypad_data->keymap; | 261 | input_dev->keycode = keypad_data->keymap; |
| 229 | input_dev->keycodesize = sizeof(keypad_data->keymap[0]); | 262 | input_dev->keycodesize = sizeof(keypad_data->keymap[0]); |
| 230 | input_dev->keycodemax = max_keys; | 263 | input_dev->keycodemax = max_keys; |
| @@ -239,8 +272,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev) | |||
| 239 | matrix_keypad_build_keymap(pdata->keymap_data, row_shift, | 272 | matrix_keypad_build_keymap(pdata->keymap_data, row_shift, |
| 240 | input_dev->keycode, input_dev->keybit); | 273 | input_dev->keycode, input_dev->keybit); |
| 241 | 274 | ||
| 242 | omap4_keypad_config(keypad_data); | ||
| 243 | |||
| 244 | error = request_irq(keypad_data->irq, omap4_keypad_interrupt, | 275 | error = request_irq(keypad_data->irq, omap4_keypad_interrupt, |
| 245 | IRQF_TRIGGER_RISING, | 276 | IRQF_TRIGGER_RISING, |
| 246 | "omap4-keypad", keypad_data); | 277 | "omap4-keypad", keypad_data); |
| @@ -249,17 +280,19 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev) | |||
| 249 | goto err_free_input; | 280 | goto err_free_input; |
| 250 | } | 281 | } |
| 251 | 282 | ||
| 283 | pm_runtime_enable(&pdev->dev); | ||
| 284 | |||
| 252 | error = input_register_device(keypad_data->input); | 285 | error = input_register_device(keypad_data->input); |
| 253 | if (error < 0) { | 286 | if (error < 0) { |
| 254 | dev_err(&pdev->dev, "failed to register input device\n"); | 287 | dev_err(&pdev->dev, "failed to register input device\n"); |
| 255 | goto err_free_irq; | 288 | goto err_pm_disable; |
| 256 | } | 289 | } |
| 257 | 290 | ||
| 258 | |||
| 259 | platform_set_drvdata(pdev, keypad_data); | 291 | platform_set_drvdata(pdev, keypad_data); |
| 260 | return 0; | 292 | return 0; |
| 261 | 293 | ||
| 262 | err_free_irq: | 294 | err_pm_disable: |
| 295 | pm_runtime_disable(&pdev->dev); | ||
| 263 | free_irq(keypad_data->irq, keypad_data); | 296 | free_irq(keypad_data->irq, keypad_data); |
| 264 | err_free_input: | 297 | err_free_input: |
| 265 | input_free_device(input_dev); | 298 | input_free_device(input_dev); |
| @@ -278,6 +311,9 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev) | |||
| 278 | struct resource *res; | 311 | struct resource *res; |
| 279 | 312 | ||
| 280 | free_irq(keypad_data->irq, keypad_data); | 313 | free_irq(keypad_data->irq, keypad_data); |
| 314 | |||
| 315 | pm_runtime_disable(&pdev->dev); | ||
| 316 | |||
| 281 | input_unregister_device(keypad_data->input); | 317 | input_unregister_device(keypad_data->input); |
| 282 | 318 | ||
| 283 | iounmap(keypad_data->base); | 319 | iounmap(keypad_data->base); |
diff --git a/drivers/input/keyboard/qt1070.c b/drivers/input/keyboard/qt1070.c new file mode 100644 index 000000000000..fba8404c7297 --- /dev/null +++ b/drivers/input/keyboard/qt1070.c | |||
| @@ -0,0 +1,276 @@ | |||
| 1 | /* | ||
| 2 | * Atmel AT42QT1070 QTouch Sensor Controller | ||
| 3 | * | ||
| 4 | * Copyright (C) 2011 Atmel | ||
| 5 | * | ||
| 6 | * Authors: Bo Shen <voice.shen@atmel.com> | ||
| 7 | * | ||
| 8 | * Base on AT42QT2160 driver by: | ||
| 9 | * Raphael Derosso Pereira <raphaelpereira@gmail.com> | ||
| 10 | * Copyright (C) 2009 | ||
| 11 | * | ||
| 12 | * This program is free software; you can redistribute it and/or modify | ||
| 13 | * it under the terms of the GNU General Public License as published by | ||
| 14 | * the Free Software Foundation; either version 2 of the License, or | ||
| 15 | * (at your option) any later version. | ||
| 16 | * | ||
| 17 | * This program is distributed in the hope that it will be useful, | ||
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | * GNU General Public License for more details. | ||
| 21 | * | ||
| 22 | * You should have received a copy of the GNU General Public License | ||
| 23 | * along with this program; if not, write to the Free Software | ||
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 25 | */ | ||
| 26 | #include <linux/kernel.h> | ||
| 27 | #include <linux/module.h> | ||
| 28 | #include <linux/init.h> | ||
| 29 | #include <linux/i2c.h> | ||
| 30 | #include <linux/input.h> | ||
| 31 | #include <linux/slab.h> | ||
| 32 | #include <linux/irq.h> | ||
| 33 | #include <linux/interrupt.h> | ||
| 34 | #include <linux/jiffies.h> | ||
| 35 | #include <linux/delay.h> | ||
| 36 | |||
| 37 | /* Address for each register */ | ||
| 38 | #define CHIP_ID 0x00 | ||
| 39 | #define QT1070_CHIP_ID 0x2E | ||
| 40 | |||
| 41 | #define FW_VERSION 0x01 | ||
| 42 | #define QT1070_FW_VERSION 0x15 | ||
| 43 | |||
| 44 | #define DET_STATUS 0x02 | ||
| 45 | |||
| 46 | #define KEY_STATUS 0x03 | ||
| 47 | |||
| 48 | /* Calibrate */ | ||
| 49 | #define CALIBRATE_CMD 0x38 | ||
| 50 | #define QT1070_CAL_TIME 200 | ||
| 51 | |||
| 52 | /* Reset */ | ||
| 53 | #define RESET 0x39 | ||
| 54 | #define QT1070_RESET_TIME 255 | ||
| 55 | |||
| 56 | /* AT42QT1070 support up to 7 keys */ | ||
| 57 | static const unsigned short qt1070_key2code[] = { | ||
| 58 | KEY_0, KEY_1, KEY_2, KEY_3, | ||
| 59 | KEY_4, KEY_5, KEY_6, | ||
| 60 | }; | ||
| 61 | |||
| 62 | struct qt1070_data { | ||
| 63 | struct i2c_client *client; | ||
| 64 | struct input_dev *input; | ||
| 65 | unsigned int irq; | ||
| 66 | unsigned short keycodes[ARRAY_SIZE(qt1070_key2code)]; | ||
| 67 | u8 last_keys; | ||
| 68 | }; | ||
| 69 | |||
| 70 | static int qt1070_read(struct i2c_client *client, u8 reg) | ||
| 71 | { | ||
| 72 | int ret; | ||
| 73 | |||
| 74 | ret = i2c_smbus_read_byte_data(client, reg); | ||
| 75 | if (ret < 0) | ||
| 76 | dev_err(&client->dev, | ||
| 77 | "can not read register, returned %d\n", ret); | ||
| 78 | |||
| 79 | return ret; | ||
| 80 | } | ||
| 81 | |||
| 82 | static int qt1070_write(struct i2c_client *client, u8 reg, u8 data) | ||
| 83 | { | ||
| 84 | int ret; | ||
| 85 | |||
| 86 | ret = i2c_smbus_write_byte_data(client, reg, data); | ||
| 87 | if (ret < 0) | ||
| 88 | dev_err(&client->dev, | ||
| 89 | "can not write register, returned %d\n", ret); | ||
| 90 | |||
| 91 | return ret; | ||
| 92 | } | ||
| 93 | |||
| 94 | static bool __devinit qt1070_identify(struct i2c_client *client) | ||
| 95 | { | ||
| 96 | int id, ver; | ||
| 97 | |||
| 98 | /* Read Chip ID */ | ||
| 99 | id = qt1070_read(client, CHIP_ID); | ||
| 100 | if (id != QT1070_CHIP_ID) { | ||
| 101 | dev_err(&client->dev, "ID %d not supported\n", id); | ||
| 102 | return false; | ||
| 103 | } | ||
| 104 | |||
| 105 | /* Read firmware version */ | ||
| 106 | ver = qt1070_read(client, FW_VERSION); | ||
| 107 | if (ver < 0) { | ||
| 108 | dev_err(&client->dev, "could not read the firmware version\n"); | ||
| 109 | return false; | ||
| 110 | } | ||
| 111 | |||
| 112 | dev_info(&client->dev, "AT42QT1070 firmware version %x\n", ver); | ||
| 113 | |||
| 114 | return true; | ||
| 115 | } | ||
| 116 | |||
| 117 | static irqreturn_t qt1070_interrupt(int irq, void *dev_id) | ||
| 118 | { | ||
| 119 | struct qt1070_data *data = dev_id; | ||
| 120 | struct i2c_client *client = data->client; | ||
| 121 | struct input_dev *input = data->input; | ||
| 122 | int i; | ||
| 123 | u8 new_keys, keyval, mask = 0x01; | ||
| 124 | |||
| 125 | /* Read the detected status register, thus clearing interrupt */ | ||
| 126 | qt1070_read(client, DET_STATUS); | ||
| 127 | |||
| 128 | /* Read which key changed */ | ||
| 129 | new_keys = qt1070_read(client, KEY_STATUS); | ||
| 130 | |||
| 131 | for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) { | ||
| 132 | keyval = new_keys & mask; | ||
| 133 | if ((data->last_keys & mask) != keyval) | ||
| 134 | input_report_key(input, data->keycodes[i], keyval); | ||
| 135 | mask <<= 1; | ||
| 136 | } | ||
| 137 | input_sync(input); | ||
| 138 | |||
| 139 | data->last_keys = new_keys; | ||
| 140 | return IRQ_HANDLED; | ||
| 141 | } | ||
| 142 | |||
| 143 | static int __devinit qt1070_probe(struct i2c_client *client, | ||
| 144 | const struct i2c_device_id *id) | ||
| 145 | { | ||
| 146 | struct qt1070_data *data; | ||
| 147 | struct input_dev *input; | ||
| 148 | int i; | ||
| 149 | int err; | ||
| 150 | |||
| 151 | err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE); | ||
| 152 | if (!err) { | ||
| 153 | dev_err(&client->dev, "%s adapter not supported\n", | ||
| 154 | dev_driver_string(&client->adapter->dev)); | ||
| 155 | return -ENODEV; | ||
| 156 | } | ||
| 157 | |||
| 158 | if (!client->irq) { | ||
| 159 | dev_err(&client->dev, "please assign the irq to this device\n"); | ||
| 160 | return -EINVAL; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* Identify the qt1070 chip */ | ||
| 164 | if (!qt1070_identify(client)) | ||
| 165 | return -ENODEV; | ||
| 166 | |||
| 167 | data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL); | ||
| 168 | input = input_allocate_device(); | ||
| 169 | if (!data || !input) { | ||
| 170 | dev_err(&client->dev, "insufficient memory\n"); | ||
| 171 | err = -ENOMEM; | ||
| 172 | goto err_free_mem; | ||
| 173 | } | ||
| 174 | |||
| 175 | data->client = client; | ||
| 176 | data->input = input; | ||
| 177 | data->irq = client->irq; | ||
| 178 | |||
| 179 | input->name = "AT42QT1070 QTouch Sensor"; | ||
| 180 | input->dev.parent = &client->dev; | ||
| 181 | input->id.bustype = BUS_I2C; | ||
| 182 | |||
| 183 | /* Add the keycode */ | ||
| 184 | input->keycode = data->keycodes; | ||
| 185 | input->keycodesize = sizeof(data->keycodes[0]); | ||
| 186 | input->keycodemax = ARRAY_SIZE(qt1070_key2code); | ||
| 187 | |||
| 188 | __set_bit(EV_KEY, input->evbit); | ||
| 189 | |||
| 190 | for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) { | ||
| 191 | data->keycodes[i] = qt1070_key2code[i]; | ||
| 192 | __set_bit(qt1070_key2code[i], input->keybit); | ||
| 193 | } | ||
| 194 | |||
| 195 | /* Calibrate device */ | ||
| 196 | qt1070_write(client, CALIBRATE_CMD, 1); | ||
| 197 | msleep(QT1070_CAL_TIME); | ||
| 198 | |||
| 199 | /* Soft reset */ | ||
| 200 | qt1070_write(client, RESET, 1); | ||
| 201 | msleep(QT1070_RESET_TIME); | ||
| 202 | |||
| 203 | err = request_threaded_irq(client->irq, NULL, qt1070_interrupt, | ||
| 204 | IRQF_TRIGGER_NONE, client->dev.driver->name, data); | ||
| 205 | if (err) { | ||
| 206 | dev_err(&client->dev, "fail to request irq\n"); | ||
| 207 | goto err_free_mem; | ||
| 208 | } | ||
| 209 | |||
| 210 | /* Register the input device */ | ||
| 211 | err = input_register_device(data->input); | ||
| 212 | if (err) { | ||
| 213 | dev_err(&client->dev, "Failed to register input device\n"); | ||
| 214 | goto err_free_irq; | ||
| 215 | } | ||
| 216 | |||
| 217 | i2c_set_clientdata(client, data); | ||
| 218 | |||
| 219 | /* Read to clear the chang line */ | ||
| 220 | qt1070_read(client, DET_STATUS); | ||
| 221 | |||
| 222 | return 0; | ||
| 223 | |||
| 224 | err_free_irq: | ||
| 225 | free_irq(client->irq, data); | ||
| 226 | err_free_mem: | ||
| 227 | input_free_device(input); | ||
| 228 | kfree(data); | ||
| 229 | return err; | ||
| 230 | } | ||
| 231 | |||
| 232 | static int __devexit qt1070_remove(struct i2c_client *client) | ||
| 233 | { | ||
| 234 | struct qt1070_data *data = i2c_get_clientdata(client); | ||
| 235 | |||
| 236 | /* Release IRQ */ | ||
| 237 | free_irq(client->irq, data); | ||
| 238 | |||
| 239 | input_unregister_device(data->input); | ||
| 240 | kfree(data); | ||
| 241 | |||
| 242 | i2c_set_clientdata(client, NULL); | ||
| 243 | |||
| 244 | return 0; | ||
| 245 | } | ||
| 246 | |||
| 247 | static const struct i2c_device_id qt1070_id[] = { | ||
| 248 | { "qt1070", 0 }, | ||
| 249 | { }, | ||
| 250 | }; | ||
| 251 | |||
| 252 | static struct i2c_driver qt1070_driver = { | ||
| 253 | .driver = { | ||
| 254 | .name = "qt1070", | ||
| 255 | .owner = THIS_MODULE, | ||
| 256 | }, | ||
| 257 | .id_table = qt1070_id, | ||
| 258 | .probe = qt1070_probe, | ||
| 259 | .remove = __devexit_p(qt1070_remove), | ||
| 260 | }; | ||
| 261 | |||
| 262 | static int __init qt1070_init(void) | ||
| 263 | { | ||
| 264 | return i2c_add_driver(&qt1070_driver); | ||
| 265 | } | ||
| 266 | module_init(qt1070_init); | ||
| 267 | |||
| 268 | static void __exit qt1070_exit(void) | ||
| 269 | { | ||
| 270 | i2c_del_driver(&qt1070_driver); | ||
| 271 | } | ||
| 272 | module_exit(qt1070_exit); | ||
| 273 | |||
| 274 | MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>"); | ||
| 275 | MODULE_DESCRIPTION("Driver for AT42QT1070 QTouch sensor"); | ||
| 276 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c new file mode 100644 index 000000000000..99122f59e988 --- /dev/null +++ b/drivers/input/keyboard/tc3589x-keypad.c | |||
| @@ -0,0 +1,472 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) ST-Ericsson SA 2010 | ||
| 3 | * | ||
| 4 | * Author: Jayeeta Banerjee <jayeeta.banerjee@stericsson.com> | ||
| 5 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> | ||
| 6 | * | ||
| 7 | * License Terms: GNU General Public License, version 2 | ||
| 8 | * | ||
| 9 | * TC35893 MFD Keypad Controller driver | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/interrupt.h> | ||
| 15 | #include <linux/input.h> | ||
| 16 | #include <linux/platform_device.h> | ||
| 17 | #include <linux/input/matrix_keypad.h> | ||
| 18 | #include <linux/i2c.h> | ||
| 19 | #include <linux/slab.h> | ||
| 20 | #include <linux/mfd/tc3589x.h> | ||
| 21 | |||
| 22 | /* Maximum supported keypad matrix row/columns size */ | ||
| 23 | #define TC3589x_MAX_KPROW 8 | ||
| 24 | #define TC3589x_MAX_KPCOL 12 | ||
| 25 | |||
| 26 | /* keypad related Constants */ | ||
| 27 | #define TC3589x_MAX_DEBOUNCE_SETTLE 0xFF | ||
| 28 | #define DEDICATED_KEY_VAL 0xFF | ||
| 29 | |||
| 30 | /* Pull up/down masks */ | ||
| 31 | #define TC3589x_NO_PULL_MASK 0x0 | ||
| 32 | #define TC3589x_PULL_DOWN_MASK 0x1 | ||
| 33 | #define TC3589x_PULL_UP_MASK 0x2 | ||
| 34 | #define TC3589x_PULLUP_ALL_MASK 0xAA | ||
| 35 | #define TC3589x_IO_PULL_VAL(index, mask) ((mask)<<((index)%4)*2)) | ||
| 36 | |||
| 37 | /* Bit masks for IOCFG register */ | ||
| 38 | #define IOCFG_BALLCFG 0x01 | ||
| 39 | #define IOCFG_IG 0x08 | ||
| 40 | |||
| 41 | #define KP_EVCODE_COL_MASK 0x0F | ||
| 42 | #define KP_EVCODE_ROW_MASK 0x70 | ||
| 43 | #define KP_RELEASE_EVT_MASK 0x80 | ||
| 44 | |||
| 45 | #define KP_ROW_SHIFT 4 | ||
| 46 | |||
| 47 | #define KP_NO_VALID_KEY_MASK 0x7F | ||
| 48 | |||
| 49 | /* bit masks for RESTCTRL register */ | ||
| 50 | #define TC3589x_KBDRST 0x2 | ||
| 51 | #define TC3589x_IRQRST 0x10 | ||
| 52 | #define TC3589x_RESET_ALL 0x1B | ||
| 53 | |||
| 54 | /* KBDMFS register bit mask */ | ||
| 55 | #define TC3589x_KBDMFS_EN 0x1 | ||
| 56 | |||
| 57 | /* CLKEN register bitmask */ | ||
| 58 | #define KPD_CLK_EN 0x1 | ||
| 59 | |||
| 60 | /* RSTINTCLR register bit mask */ | ||
| 61 | #define IRQ_CLEAR 0x1 | ||
| 62 | |||
| 63 | /* bit masks for keyboard interrupts*/ | ||
| 64 | #define TC3589x_EVT_LOSS_INT 0x8 | ||
| 65 | #define TC3589x_EVT_INT 0x4 | ||
| 66 | #define TC3589x_KBD_LOSS_INT 0x2 | ||
| 67 | #define TC3589x_KBD_INT 0x1 | ||
| 68 | |||
| 69 | /* bit masks for keyboard interrupt clear*/ | ||
| 70 | #define TC3589x_EVT_INT_CLR 0x2 | ||
| 71 | #define TC3589x_KBD_INT_CLR 0x1 | ||
| 72 | |||
| 73 | #define TC3589x_KBD_KEYMAP_SIZE 64 | ||
| 74 | |||
| 75 | /** | ||
| 76 | * struct tc_keypad - data structure used by keypad driver | ||
| 77 | * @input: pointer to input device object | ||
| 78 | * @board: keypad platform device | ||
| 79 | * @krow: number of rows | ||
| 80 | * @kcol: number of coloumns | ||
| 81 | * @keymap: matrix scan code table for keycodes | ||
| 82 | */ | ||
| 83 | struct tc_keypad { | ||
| 84 | struct tc3589x *tc3589x; | ||
| 85 | struct input_dev *input; | ||
| 86 | const struct tc3589x_keypad_platform_data *board; | ||
| 87 | unsigned int krow; | ||
| 88 | unsigned int kcol; | ||
| 89 | unsigned short keymap[TC3589x_KBD_KEYMAP_SIZE]; | ||
| 90 | bool keypad_stopped; | ||
| 91 | }; | ||
| 92 | |||
| 93 | static int __devinit tc3589x_keypad_init_key_hardware(struct tc_keypad *keypad) | ||
| 94 | { | ||
| 95 | int ret; | ||
| 96 | struct tc3589x *tc3589x = keypad->tc3589x; | ||
| 97 | u8 settle_time = keypad->board->settle_time; | ||
| 98 | u8 dbounce_period = keypad->board->debounce_period; | ||
| 99 | u8 rows = keypad->board->krow & 0xf; /* mask out the nibble */ | ||
| 100 | u8 column = keypad->board->kcol & 0xf; /* mask out the nibble */ | ||
| 101 | |||
| 102 | /* validate platform configurations */ | ||
| 103 | if (keypad->board->kcol > TC3589x_MAX_KPCOL || | ||
| 104 | keypad->board->krow > TC3589x_MAX_KPROW || | ||
| 105 | keypad->board->debounce_period > TC3589x_MAX_DEBOUNCE_SETTLE || | ||
| 106 | keypad->board->settle_time > TC3589x_MAX_DEBOUNCE_SETTLE) | ||
| 107 | return -EINVAL; | ||
| 108 | |||
| 109 | /* configure KBDSIZE 4 LSbits for cols and 4 MSbits for rows */ | ||
| 110 | ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSIZE, | ||
| 111 | (rows << KP_ROW_SHIFT) | column); | ||
| 112 | if (ret < 0) | ||
| 113 | return ret; | ||
| 114 | |||
| 115 | /* configure dedicated key config, no dedicated key selected */ | ||
| 116 | ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_LSB, DEDICATED_KEY_VAL); | ||
| 117 | if (ret < 0) | ||
| 118 | return ret; | ||
| 119 | |||
| 120 | ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_MSB, DEDICATED_KEY_VAL); | ||
| 121 | if (ret < 0) | ||
| 122 | return ret; | ||
| 123 | |||
| 124 | /* Configure settle time */ | ||
| 125 | ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSETTLE_REG, settle_time); | ||
| 126 | if (ret < 0) | ||
| 127 | return ret; | ||
| 128 | |||
| 129 | /* Configure debounce time */ | ||
| 130 | ret = tc3589x_reg_write(tc3589x, TC3589x_KBDBOUNCE, dbounce_period); | ||
| 131 | if (ret < 0) | ||
| 132 | return ret; | ||
| 133 | |||
| 134 | /* Start of initialise keypad GPIOs */ | ||
| 135 | ret = tc3589x_set_bits(tc3589x, TC3589x_IOCFG, 0x0, IOCFG_IG); | ||
| 136 | if (ret < 0) | ||
| 137 | return ret; | ||
| 138 | |||
| 139 | /* Configure pull-up resistors for all row GPIOs */ | ||
| 140 | ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_LSB, | ||
| 141 | TC3589x_PULLUP_ALL_MASK); | ||
| 142 | if (ret < 0) | ||
| 143 | return ret; | ||
| 144 | |||
| 145 | ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_MSB, | ||
| 146 | TC3589x_PULLUP_ALL_MASK); | ||
| 147 | if (ret < 0) | ||
| 148 | return ret; | ||
| 149 | |||
| 150 | /* Configure pull-up resistors for all column GPIOs */ | ||
| 151 | ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_LSB, | ||
| 152 | TC3589x_PULLUP_ALL_MASK); | ||
| 153 | if (ret < 0) | ||
| 154 | return ret; | ||
| 155 | |||
| 156 | ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_MSB, | ||
| 157 | TC3589x_PULLUP_ALL_MASK); | ||
| 158 | if (ret < 0) | ||
| 159 | return ret; | ||
| 160 | |||
| 161 | ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG2_LSB, | ||
| 162 | TC3589x_PULLUP_ALL_MASK); | ||
| 163 | |||
| 164 | return ret; | ||
| 165 | } | ||
| 166 | |||
| 167 | #define TC35893_DATA_REGS 4 | ||
| 168 | #define TC35893_KEYCODE_FIFO_EMPTY 0x7f | ||
| 169 | #define TC35893_KEYCODE_FIFO_CLEAR 0xff | ||
| 170 | #define TC35893_KEYPAD_ROW_SHIFT 0x3 | ||
| 171 | |||
| 172 | static irqreturn_t tc3589x_keypad_irq(int irq, void *dev) | ||
| 173 | { | ||
| 174 | struct tc_keypad *keypad = dev; | ||
| 175 | struct tc3589x *tc3589x = keypad->tc3589x; | ||
| 176 | u8 i, row_index, col_index, kbd_code, up; | ||
| 177 | u8 code; | ||
| 178 | |||
| 179 | for (i = 0; i < TC35893_DATA_REGS * 2; i++) { | ||
| 180 | kbd_code = tc3589x_reg_read(tc3589x, TC3589x_EVTCODE_FIFO); | ||
| 181 | |||
| 182 | /* loop till fifo is empty and no more keys are pressed */ | ||
| 183 | if (kbd_code == TC35893_KEYCODE_FIFO_EMPTY || | ||
| 184 | kbd_code == TC35893_KEYCODE_FIFO_CLEAR) | ||
| 185 | continue; | ||
| 186 | |||
| 187 | /* valid key is found */ | ||
| 188 | col_index = kbd_code & KP_EVCODE_COL_MASK; | ||
| 189 | row_index = (kbd_code & KP_EVCODE_ROW_MASK) >> KP_ROW_SHIFT; | ||
| 190 | code = MATRIX_SCAN_CODE(row_index, col_index, | ||
| 191 | TC35893_KEYPAD_ROW_SHIFT); | ||
| 192 | up = kbd_code & KP_RELEASE_EVT_MASK; | ||
| 193 | |||
| 194 | input_event(keypad->input, EV_MSC, MSC_SCAN, code); | ||
| 195 | input_report_key(keypad->input, keypad->keymap[code], !up); | ||
| 196 | input_sync(keypad->input); | ||
| 197 | } | ||
| 198 | |||
| 199 | /* clear IRQ */ | ||
| 200 | tc3589x_set_bits(tc3589x, TC3589x_KBDIC, | ||
| 201 | 0x0, TC3589x_EVT_INT_CLR | TC3589x_KBD_INT_CLR); | ||
| 202 | /* enable IRQ */ | ||
| 203 | tc3589x_set_bits(tc3589x, TC3589x_KBDMSK, | ||
| 204 | 0x0, TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT); | ||
| 205 | |||
| 206 | return IRQ_HANDLED; | ||
| 207 | } | ||
| 208 | |||
| 209 | static int tc3589x_keypad_enable(struct tc_keypad *keypad) | ||
| 210 | { | ||
| 211 | struct tc3589x *tc3589x = keypad->tc3589x; | ||
| 212 | int ret; | ||
| 213 | |||
| 214 | /* pull the keypad module out of reset */ | ||
| 215 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, TC3589x_KBDRST, 0x0); | ||
| 216 | if (ret < 0) | ||
| 217 | return ret; | ||
| 218 | |||
| 219 | /* configure KBDMFS */ | ||
| 220 | ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMFS, 0x0, TC3589x_KBDMFS_EN); | ||
| 221 | if (ret < 0) | ||
| 222 | return ret; | ||
| 223 | |||
| 224 | /* enable the keypad clock */ | ||
| 225 | ret = tc3589x_set_bits(tc3589x, TC3589x_CLKEN, 0x0, KPD_CLK_EN); | ||
| 226 | if (ret < 0) | ||
| 227 | return ret; | ||
| 228 | |||
| 229 | /* clear pending IRQs */ | ||
| 230 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTINTCLR, 0x0, 0x1); | ||
| 231 | if (ret < 0) | ||
| 232 | return ret; | ||
| 233 | |||
| 234 | /* enable the IRQs */ | ||
| 235 | ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMSK, 0x0, | ||
| 236 | TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT); | ||
| 237 | if (ret < 0) | ||
| 238 | return ret; | ||
| 239 | |||
| 240 | keypad->keypad_stopped = false; | ||
| 241 | |||
| 242 | return ret; | ||
| 243 | } | ||
| 244 | |||
| 245 | static int tc3589x_keypad_disable(struct tc_keypad *keypad) | ||
| 246 | { | ||
| 247 | struct tc3589x *tc3589x = keypad->tc3589x; | ||
| 248 | int ret; | ||
| 249 | |||
| 250 | /* clear IRQ */ | ||
| 251 | ret = tc3589x_set_bits(tc3589x, TC3589x_KBDIC, | ||
| 252 | 0x0, TC3589x_EVT_INT_CLR | TC3589x_KBD_INT_CLR); | ||
| 253 | if (ret < 0) | ||
| 254 | return ret; | ||
| 255 | |||
| 256 | /* disable all interrupts */ | ||
| 257 | ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMSK, | ||
| 258 | ~(TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT), 0x0); | ||
| 259 | if (ret < 0) | ||
| 260 | return ret; | ||
| 261 | |||
| 262 | /* disable the keypad module */ | ||
| 263 | ret = tc3589x_set_bits(tc3589x, TC3589x_CLKEN, 0x1, 0x0); | ||
| 264 | if (ret < 0) | ||
| 265 | return ret; | ||
| 266 | |||
| 267 | /* put the keypad module into reset */ | ||
| 268 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, TC3589x_KBDRST, 0x1); | ||
| 269 | |||
| 270 | keypad->keypad_stopped = true; | ||
| 271 | |||
| 272 | return ret; | ||
| 273 | } | ||
| 274 | |||
| 275 | static int tc3589x_keypad_open(struct input_dev *input) | ||
| 276 | { | ||
| 277 | int error; | ||
| 278 | struct tc_keypad *keypad = input_get_drvdata(input); | ||
| 279 | |||
| 280 | /* enable the keypad module */ | ||
| 281 | error = tc3589x_keypad_enable(keypad); | ||
| 282 | if (error < 0) { | ||
| 283 | dev_err(&input->dev, "failed to enable keypad module\n"); | ||
| 284 | return error; | ||
| 285 | } | ||
| 286 | |||
| 287 | error = tc3589x_keypad_init_key_hardware(keypad); | ||
| 288 | if (error < 0) { | ||
| 289 | dev_err(&input->dev, "failed to configure keypad module\n"); | ||
| 290 | return error; | ||
| 291 | } | ||
| 292 | |||
| 293 | return 0; | ||
| 294 | } | ||
| 295 | |||
| 296 | static void tc3589x_keypad_close(struct input_dev *input) | ||
| 297 | { | ||
| 298 | struct tc_keypad *keypad = input_get_drvdata(input); | ||
| 299 | |||
| 300 | /* disable the keypad module */ | ||
| 301 | tc3589x_keypad_disable(keypad); | ||
| 302 | } | ||
| 303 | |||
| 304 | static int __devinit tc3589x_keypad_probe(struct platform_device *pdev) | ||
| 305 | { | ||
| 306 | struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); | ||
| 307 | struct tc_keypad *keypad; | ||
| 308 | struct input_dev *input; | ||
| 309 | const struct tc3589x_keypad_platform_data *plat; | ||
| 310 | int error, irq; | ||
| 311 | |||
| 312 | plat = tc3589x->pdata->keypad; | ||
| 313 | if (!plat) { | ||
| 314 | dev_err(&pdev->dev, "invalid keypad platform data\n"); | ||
| 315 | return -EINVAL; | ||
| 316 | } | ||
| 317 | |||
| 318 | irq = platform_get_irq(pdev, 0); | ||
| 319 | if (irq < 0) | ||
| 320 | return irq; | ||
| 321 | |||
| 322 | keypad = kzalloc(sizeof(struct tc_keypad), GFP_KERNEL); | ||
| 323 | input = input_allocate_device(); | ||
| 324 | if (!keypad || !input) { | ||
| 325 | dev_err(&pdev->dev, "failed to allocate keypad memory\n"); | ||
| 326 | error = -ENOMEM; | ||
| 327 | goto err_free_mem; | ||
| 328 | } | ||
| 329 | |||
| 330 | keypad->board = plat; | ||
| 331 | keypad->input = input; | ||
| 332 | keypad->tc3589x = tc3589x; | ||
| 333 | |||
| 334 | input->id.bustype = BUS_I2C; | ||
| 335 | input->name = pdev->name; | ||
| 336 | input->dev.parent = &pdev->dev; | ||
| 337 | |||
| 338 | input->keycode = keypad->keymap; | ||
| 339 | input->keycodesize = sizeof(keypad->keymap[0]); | ||
| 340 | input->keycodemax = ARRAY_SIZE(keypad->keymap); | ||
| 341 | |||
| 342 | input->open = tc3589x_keypad_open; | ||
| 343 | input->close = tc3589x_keypad_close; | ||
| 344 | |||
| 345 | input_set_drvdata(input, keypad); | ||
| 346 | |||
| 347 | input_set_capability(input, EV_MSC, MSC_SCAN); | ||
| 348 | |||
| 349 | __set_bit(EV_KEY, input->evbit); | ||
| 350 | if (!plat->no_autorepeat) | ||
| 351 | __set_bit(EV_REP, input->evbit); | ||
| 352 | |||
| 353 | matrix_keypad_build_keymap(plat->keymap_data, 0x3, | ||
| 354 | input->keycode, input->keybit); | ||
| 355 | |||
| 356 | error = request_threaded_irq(irq, NULL, | ||
| 357 | tc3589x_keypad_irq, plat->irqtype, | ||
| 358 | "tc3589x-keypad", keypad); | ||
| 359 | if (error < 0) { | ||
| 360 | dev_err(&pdev->dev, | ||
| 361 | "Could not allocate irq %d,error %d\n", | ||
| 362 | irq, error); | ||
| 363 | goto err_free_mem; | ||
| 364 | } | ||
| 365 | |||
| 366 | error = input_register_device(input); | ||
| 367 | if (error) { | ||
| 368 | dev_err(&pdev->dev, "Could not register input device\n"); | ||
| 369 | goto err_free_irq; | ||
| 370 | } | ||
| 371 | |||
| 372 | /* let platform decide if keypad is a wakeup source or not */ | ||
| 373 | device_init_wakeup(&pdev->dev, plat->enable_wakeup); | ||
| 374 | device_set_wakeup_capable(&pdev->dev, plat->enable_wakeup); | ||
| 375 | |||
| 376 | platform_set_drvdata(pdev, keypad); | ||
| 377 | |||
| 378 | return 0; | ||
| 379 | |||
| 380 | err_free_irq: | ||
| 381 | free_irq(irq, keypad); | ||
| 382 | err_free_mem: | ||
| 383 | input_free_device(input); | ||
| 384 | kfree(keypad); | ||
| 385 | return error; | ||
| 386 | } | ||
| 387 | |||
| 388 | static int __devexit tc3589x_keypad_remove(struct platform_device *pdev) | ||
| 389 | { | ||
| 390 | struct tc_keypad *keypad = platform_get_drvdata(pdev); | ||
| 391 | int irq = platform_get_irq(pdev, 0); | ||
| 392 | |||
| 393 | if (!keypad->keypad_stopped) | ||
| 394 | tc3589x_keypad_disable(keypad); | ||
| 395 | |||
| 396 | free_irq(irq, keypad); | ||
| 397 | |||
| 398 | input_unregister_device(keypad->input); | ||
| 399 | |||
| 400 | kfree(keypad); | ||
| 401 | |||
| 402 | return 0; | ||
| 403 | } | ||
| 404 | |||
| 405 | #ifdef CONFIG_PM_SLEEP | ||
| 406 | static int tc3589x_keypad_suspend(struct device *dev) | ||
| 407 | { | ||
| 408 | struct platform_device *pdev = to_platform_device(dev); | ||
| 409 | struct tc_keypad *keypad = platform_get_drvdata(pdev); | ||
| 410 | int irq = platform_get_irq(pdev, 0); | ||
| 411 | |||
| 412 | /* keypad is already off; we do nothing */ | ||
| 413 | if (keypad->keypad_stopped) | ||
| 414 | return 0; | ||
| 415 | |||
| 416 | /* if device is not a wakeup source, disable it for powersave */ | ||
| 417 | if (!device_may_wakeup(&pdev->dev)) | ||
| 418 | tc3589x_keypad_disable(keypad); | ||
| 419 | else | ||
| 420 | enable_irq_wake(irq); | ||
| 421 | |||
| 422 | return 0; | ||
| 423 | } | ||
| 424 | |||
| 425 | static int tc3589x_keypad_resume(struct device *dev) | ||
| 426 | { | ||
| 427 | struct platform_device *pdev = to_platform_device(dev); | ||
| 428 | struct tc_keypad *keypad = platform_get_drvdata(pdev); | ||
| 429 | int irq = platform_get_irq(pdev, 0); | ||
| 430 | |||
| 431 | if (!keypad->keypad_stopped) | ||
| 432 | return 0; | ||
| 433 | |||
| 434 | /* enable the device to resume normal operations */ | ||
| 435 | if (!device_may_wakeup(&pdev->dev)) | ||
| 436 | tc3589x_keypad_enable(keypad); | ||
| 437 | else | ||
| 438 | disable_irq_wake(irq); | ||
| 439 | |||
| 440 | return 0; | ||
| 441 | } | ||
| 442 | #endif | ||
| 443 | |||
| 444 | static SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops, | ||
| 445 | tc3589x_keypad_suspend, tc3589x_keypad_resume); | ||
| 446 | |||
| 447 | static struct platform_driver tc3589x_keypad_driver = { | ||
| 448 | .driver = { | ||
| 449 | .name = "tc3589x-keypad", | ||
| 450 | .owner = THIS_MODULE, | ||
| 451 | .pm = &tc3589x_keypad_dev_pm_ops, | ||
| 452 | }, | ||
| 453 | .probe = tc3589x_keypad_probe, | ||
| 454 | .remove = __devexit_p(tc3589x_keypad_remove), | ||
| 455 | }; | ||
| 456 | |||
| 457 | static int __init tc3589x_keypad_init(void) | ||
| 458 | { | ||
| 459 | return platform_driver_register(&tc3589x_keypad_driver); | ||
| 460 | } | ||
| 461 | module_init(tc3589x_keypad_init); | ||
| 462 | |||
| 463 | static void __exit tc3589x_keypad_exit(void) | ||
| 464 | { | ||
| 465 | return platform_driver_unregister(&tc3589x_keypad_driver); | ||
| 466 | } | ||
| 467 | module_exit(tc3589x_keypad_exit); | ||
| 468 | |||
| 469 | MODULE_LICENSE("GPL v2"); | ||
| 470 | MODULE_AUTHOR("Jayeeta Banerjee/Sundar Iyer"); | ||
| 471 | MODULE_DESCRIPTION("TC35893 Keypad Driver"); | ||
| 472 | MODULE_ALIAS("platform:tc3589x-keypad"); | ||
diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c index 800fbccf1f0f..3afea3f89718 100644 --- a/drivers/input/keyboard/tca6416-keypad.c +++ b/drivers/input/keyboard/tca6416-keypad.c | |||
| @@ -297,6 +297,7 @@ static int __devinit tca6416_keypad_probe(struct i2c_client *client, | |||
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | i2c_set_clientdata(client, chip); | 299 | i2c_set_clientdata(client, chip); |
| 300 | device_init_wakeup(&client->dev, 1); | ||
| 300 | 301 | ||
| 301 | return 0; | 302 | return 0; |
| 302 | 303 | ||
| @@ -326,10 +327,37 @@ static int __devexit tca6416_keypad_remove(struct i2c_client *client) | |||
| 326 | return 0; | 327 | return 0; |
| 327 | } | 328 | } |
| 328 | 329 | ||
| 330 | #ifdef CONFIG_PM_SLEEP | ||
| 331 | static int tca6416_keypad_suspend(struct device *dev) | ||
| 332 | { | ||
| 333 | struct i2c_client *client = to_i2c_client(dev); | ||
| 334 | struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); | ||
| 335 | |||
| 336 | if (device_may_wakeup(dev)) | ||
| 337 | enable_irq_wake(chip->irqnum); | ||
| 338 | |||
| 339 | return 0; | ||
| 340 | } | ||
| 341 | |||
| 342 | static int tca6416_keypad_resume(struct device *dev) | ||
| 343 | { | ||
| 344 | struct i2c_client *client = to_i2c_client(dev); | ||
| 345 | struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); | ||
| 346 | |||
| 347 | if (device_may_wakeup(dev)) | ||
| 348 | disable_irq_wake(chip->irqnum); | ||
| 349 | |||
| 350 | return 0; | ||
| 351 | } | ||
| 352 | #endif | ||
| 353 | |||
| 354 | static SIMPLE_DEV_PM_OPS(tca6416_keypad_dev_pm_ops, | ||
| 355 | tca6416_keypad_suspend, tca6416_keypad_resume); | ||
| 329 | 356 | ||
| 330 | static struct i2c_driver tca6416_keypad_driver = { | 357 | static struct i2c_driver tca6416_keypad_driver = { |
| 331 | .driver = { | 358 | .driver = { |
| 332 | .name = "tca6416-keypad", | 359 | .name = "tca6416-keypad", |
| 360 | .pm = &tca6416_keypad_dev_pm_ops, | ||
| 333 | }, | 361 | }, |
| 334 | .probe = tca6416_keypad_probe, | 362 | .probe = tca6416_keypad_probe, |
| 335 | .remove = __devexit_p(tca6416_keypad_remove), | 363 | .remove = __devexit_p(tca6416_keypad_remove), |
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index f0d90172a65f..f9cf0881b0e3 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
| @@ -294,24 +294,6 @@ config INPUT_SGI_BTNS | |||
| 294 | To compile this driver as a module, choose M here: the | 294 | To compile this driver as a module, choose M here: the |
| 295 | module will be called sgi_btns. | 295 | module will be called sgi_btns. |
| 296 | 296 | ||
| 297 | config INPUT_WINBOND_CIR | ||
| 298 | tristate "Winbond IR remote control" | ||
| 299 | depends on X86 && PNP | ||
| 300 | select NEW_LEDS | ||
| 301 | select LEDS_CLASS | ||
| 302 | select LEDS_TRIGGERS | ||
| 303 | select BITREVERSE | ||
| 304 | help | ||
| 305 | Say Y here if you want to use the IR remote functionality found | ||
| 306 | in some Winbond SuperI/O chips. Currently only the WPCD376I | ||
| 307 | chip is supported (included in some Intel Media series motherboards). | ||
| 308 | |||
| 309 | IR Receive and wake-on-IR from suspend and power-off is currently | ||
| 310 | supported. | ||
| 311 | |||
| 312 | To compile this driver as a module, choose M here: the module will be | ||
| 313 | called winbond_cir. | ||
| 314 | |||
| 315 | config HP_SDC_RTC | 297 | config HP_SDC_RTC |
| 316 | tristate "HP SDC Real Time Clock" | 298 | tristate "HP SDC Real Time Clock" |
| 317 | depends on (GSC || HP300) && SERIO | 299 | depends on (GSC || HP300) && SERIO |
| @@ -472,4 +454,17 @@ config INPUT_CMA3000_I2C | |||
| 472 | To compile this driver as a module, choose M here: the | 454 | To compile this driver as a module, choose M here: the |
| 473 | module will be called cma3000_d0x_i2c. | 455 | module will be called cma3000_d0x_i2c. |
| 474 | 456 | ||
| 457 | config INPUT_XEN_KBDDEV_FRONTEND | ||
| 458 | tristate "Xen virtual keyboard and mouse support" | ||
| 459 | depends on XEN_FBDEV_FRONTEND | ||
| 460 | default y | ||
| 461 | select XEN_XENBUS_FRONTEND | ||
| 462 | help | ||
| 463 | This driver implements the front-end of the Xen virtual | ||
| 464 | keyboard and mouse device driver. It communicates with a back-end | ||
| 465 | in another domain. | ||
| 466 | |||
| 467 | To compile this driver as a module, choose M here: the | ||
| 468 | module will be called xen-kbdfront. | ||
| 469 | |||
| 475 | endif | 470 | endif |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 35bcfe46555e..e3f7984e6274 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
| @@ -40,8 +40,8 @@ obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o | |||
| 40 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o | 40 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o |
| 41 | obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o | 41 | obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o |
| 42 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o | 42 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o |
| 43 | obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.o | ||
| 44 | obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o | 43 | obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o |
| 45 | obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o | 44 | obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o |
| 45 | obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o | ||
| 46 | obj-$(CONFIG_INPUT_YEALINK) += yealink.o | 46 | obj-$(CONFIG_INPUT_YEALINK) += yealink.o |
| 47 | 47 | ||
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c index 2bef8fa56c94..e21deb1baa8a 100644 --- a/drivers/input/misc/ad714x-i2c.c +++ b/drivers/input/misc/ad714x-i2c.c | |||
| @@ -10,23 +10,23 @@ | |||
| 10 | #include <linux/i2c.h> | 10 | #include <linux/i2c.h> |
| 11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
| 12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
| 13 | #include <linux/pm.h> | ||
| 13 | #include "ad714x.h" | 14 | #include "ad714x.h" |
| 14 | 15 | ||
| 15 | #ifdef CONFIG_PM | 16 | #ifdef CONFIG_PM |
| 16 | static int ad714x_i2c_suspend(struct i2c_client *client, pm_message_t message) | 17 | static int ad714x_i2c_suspend(struct device *dev) |
| 17 | { | 18 | { |
| 18 | return ad714x_disable(i2c_get_clientdata(client)); | 19 | return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev))); |
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | static int ad714x_i2c_resume(struct i2c_client *client) | 22 | static int ad714x_i2c_resume(struct device *dev) |
| 22 | { | 23 | { |
| 23 | return ad714x_enable(i2c_get_clientdata(client)); | 24 | return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev))); |
| 24 | } | 25 | } |
| 25 | #else | ||
| 26 | # define ad714x_i2c_suspend NULL | ||
| 27 | # define ad714x_i2c_resume NULL | ||
| 28 | #endif | 26 | #endif |
| 29 | 27 | ||
| 28 | static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume); | ||
| 29 | |||
| 30 | static int ad714x_i2c_write(struct device *dev, unsigned short reg, | 30 | static int ad714x_i2c_write(struct device *dev, unsigned short reg, |
| 31 | unsigned short data) | 31 | unsigned short data) |
| 32 | { | 32 | { |
| @@ -114,11 +114,10 @@ MODULE_DEVICE_TABLE(i2c, ad714x_id); | |||
| 114 | static struct i2c_driver ad714x_i2c_driver = { | 114 | static struct i2c_driver ad714x_i2c_driver = { |
| 115 | .driver = { | 115 | .driver = { |
| 116 | .name = "ad714x_captouch", | 116 | .name = "ad714x_captouch", |
| 117 | .pm = &ad714x_i2c_pm, | ||
| 117 | }, | 118 | }, |
| 118 | .probe = ad714x_i2c_probe, | 119 | .probe = ad714x_i2c_probe, |
| 119 | .remove = __devexit_p(ad714x_i2c_remove), | 120 | .remove = __devexit_p(ad714x_i2c_remove), |
| 120 | .suspend = ad714x_i2c_suspend, | ||
| 121 | .resume = ad714x_i2c_resume, | ||
| 122 | .id_table = ad714x_id, | 121 | .id_table = ad714x_id, |
| 123 | }; | 122 | }; |
| 124 | 123 | ||
diff --git a/drivers/input/misc/ad714x-spi.c b/drivers/input/misc/ad714x-spi.c index 7f8dedfd1bfe..4120dd549305 100644 --- a/drivers/input/misc/ad714x-spi.c +++ b/drivers/input/misc/ad714x-spi.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/input.h> /* BUS_I2C */ | 9 | #include <linux/input.h> /* BUS_I2C */ |
| 10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
| 11 | #include <linux/spi/spi.h> | 11 | #include <linux/spi/spi.h> |
| 12 | #include <linux/pm.h> | ||
| 12 | #include <linux/types.h> | 13 | #include <linux/types.h> |
| 13 | #include "ad714x.h" | 14 | #include "ad714x.h" |
| 14 | 15 | ||
| @@ -16,20 +17,19 @@ | |||
| 16 | #define AD714x_SPI_READ BIT(10) | 17 | #define AD714x_SPI_READ BIT(10) |
| 17 | 18 | ||
| 18 | #ifdef CONFIG_PM | 19 | #ifdef CONFIG_PM |
| 19 | static int ad714x_spi_suspend(struct spi_device *spi, pm_message_t message) | 20 | static int ad714x_spi_suspend(struct device *dev) |
| 20 | { | 21 | { |
| 21 | return ad714x_disable(spi_get_drvdata(spi)); | 22 | return ad714x_disable(spi_get_drvdata(to_spi_device(dev))); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | static int ad714x_spi_resume(struct spi_device *spi) | 25 | static int ad714x_spi_resume(struct device *dev) |
| 25 | { | 26 | { |
| 26 | return ad714x_enable(spi_get_drvdata(spi)); | 27 | return ad714x_enable(spi_get_drvdata(to_spi_device(dev))); |
| 27 | } | 28 | } |
| 28 | #else | ||
| 29 | # define ad714x_spi_suspend NULL | ||
| 30 | # define ad714x_spi_resume NULL | ||
| 31 | #endif | 29 | #endif |
| 32 | 30 | ||
| 31 | static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); | ||
| 32 | |||
| 33 | static int ad714x_spi_read(struct device *dev, unsigned short reg, | 33 | static int ad714x_spi_read(struct device *dev, unsigned short reg, |
| 34 | unsigned short *data) | 34 | unsigned short *data) |
| 35 | { | 35 | { |
| @@ -79,11 +79,10 @@ static struct spi_driver ad714x_spi_driver = { | |||
| 79 | .driver = { | 79 | .driver = { |
| 80 | .name = "ad714x_captouch", | 80 | .name = "ad714x_captouch", |
| 81 | .owner = THIS_MODULE, | 81 | .owner = THIS_MODULE, |
| 82 | .pm = &ad714x_spi_pm, | ||
| 82 | }, | 83 | }, |
| 83 | .probe = ad714x_spi_probe, | 84 | .probe = ad714x_spi_probe, |
| 84 | .remove = __devexit_p(ad714x_spi_remove), | 85 | .remove = __devexit_p(ad714x_spi_remove), |
| 85 | .suspend = ad714x_spi_suspend, | ||
| 86 | .resume = ad714x_spi_resume, | ||
| 87 | }; | 86 | }; |
| 88 | 87 | ||
| 89 | static __init int ad714x_spi_init(void) | 88 | static __init int ad714x_spi_init(void) |
diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c index 0779724af7e7..ccacf2bb06a4 100644 --- a/drivers/input/misc/adxl34x-i2c.c +++ b/drivers/input/misc/adxl34x-i2c.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <linux/i2c.h> | 11 | #include <linux/i2c.h> |
| 12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
| 13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
| 14 | #include <linux/pm.h> | ||
| 14 | #include "adxl34x.h" | 15 | #include "adxl34x.h" |
| 15 | 16 | ||
| 16 | static int adxl34x_smbus_read(struct device *dev, unsigned char reg) | 17 | static int adxl34x_smbus_read(struct device *dev, unsigned char reg) |
| @@ -105,8 +106,9 @@ static int __devexit adxl34x_i2c_remove(struct i2c_client *client) | |||
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | #ifdef CONFIG_PM | 108 | #ifdef CONFIG_PM |
| 108 | static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) | 109 | static int adxl34x_i2c_suspend(struct device *dev) |
| 109 | { | 110 | { |
| 111 | struct i2c_client *client = to_i2c_client(dev); | ||
| 110 | struct adxl34x *ac = i2c_get_clientdata(client); | 112 | struct adxl34x *ac = i2c_get_clientdata(client); |
| 111 | 113 | ||
| 112 | adxl34x_suspend(ac); | 114 | adxl34x_suspend(ac); |
| @@ -114,19 +116,20 @@ static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) | |||
| 114 | return 0; | 116 | return 0; |
| 115 | } | 117 | } |
| 116 | 118 | ||
| 117 | static int adxl34x_i2c_resume(struct i2c_client *client) | 119 | static int adxl34x_i2c_resume(struct device *dev) |
| 118 | { | 120 | { |
| 121 | struct i2c_client *client = to_i2c_client(dev); | ||
| 119 | struct adxl34x *ac = i2c_get_clientdata(client); | 122 | struct adxl34x *ac = i2c_get_clientdata(client); |
| 120 | 123 | ||
| 121 | adxl34x_resume(ac); | 124 | adxl34x_resume(ac); |
| 122 | 125 | ||
| 123 | return 0; | 126 | return 0; |
| 124 | } | 127 | } |
| 125 | #else | ||
| 126 | # define adxl34x_i2c_suspend NULL | ||
| 127 | # define adxl34x_i2c_resume NULL | ||
| 128 | #endif | 128 | #endif |
| 129 | 129 | ||
| 130 | static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend, | ||
| 131 | adxl34x_i2c_resume); | ||
| 132 | |||
| 130 | static const struct i2c_device_id adxl34x_id[] = { | 133 | static const struct i2c_device_id adxl34x_id[] = { |
| 131 | { "adxl34x", 0 }, | 134 | { "adxl34x", 0 }, |
| 132 | { } | 135 | { } |
| @@ -138,11 +141,10 @@ static struct i2c_driver adxl34x_driver = { | |||
| 138 | .driver = { | 141 | .driver = { |
| 139 | .name = "adxl34x", | 142 | .name = "adxl34x", |
| 140 | .owner = THIS_MODULE, | 143 | .owner = THIS_MODULE, |
| 144 | .pm = &adxl34x_i2c_pm, | ||
| 141 | }, | 145 | }, |
| 142 | .probe = adxl34x_i2c_probe, | 146 | .probe = adxl34x_i2c_probe, |
| 143 | .remove = __devexit_p(adxl34x_i2c_remove), | 147 | .remove = __devexit_p(adxl34x_i2c_remove), |
| 144 | .suspend = adxl34x_i2c_suspend, | ||
| 145 | .resume = adxl34x_i2c_resume, | ||
| 146 | .id_table = adxl34x_id, | 148 | .id_table = adxl34x_id, |
| 147 | }; | 149 | }; |
| 148 | 150 | ||
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c index 782de9e89828..f29de22fdda0 100644 --- a/drivers/input/misc/adxl34x-spi.c +++ b/drivers/input/misc/adxl34x-spi.c | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <linux/input.h> /* BUS_SPI */ | 10 | #include <linux/input.h> /* BUS_SPI */ |
| 11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
| 12 | #include <linux/spi/spi.h> | 12 | #include <linux/spi/spi.h> |
| 13 | #include <linux/pm.h> | ||
| 13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
| 14 | #include "adxl34x.h" | 15 | #include "adxl34x.h" |
| 15 | 16 | ||
| @@ -57,7 +58,7 @@ static int adxl34x_spi_read_block(struct device *dev, | |||
| 57 | return (status < 0) ? status : 0; | 58 | return (status < 0) ? status : 0; |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | static const struct adxl34x_bus_ops adx134x_spi_bops = { | 61 | static const struct adxl34x_bus_ops adxl34x_spi_bops = { |
| 61 | .bustype = BUS_SPI, | 62 | .bustype = BUS_SPI, |
| 62 | .write = adxl34x_spi_write, | 63 | .write = adxl34x_spi_write, |
| 63 | .read = adxl34x_spi_read, | 64 | .read = adxl34x_spi_read, |
| @@ -76,7 +77,7 @@ static int __devinit adxl34x_spi_probe(struct spi_device *spi) | |||
| 76 | 77 | ||
| 77 | ac = adxl34x_probe(&spi->dev, spi->irq, | 78 | ac = adxl34x_probe(&spi->dev, spi->irq, |
| 78 | spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY, | 79 | spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY, |
| 79 | &adx134x_spi_bops); | 80 | &adxl34x_spi_bops); |
| 80 | 81 | ||
| 81 | if (IS_ERR(ac)) | 82 | if (IS_ERR(ac)) |
| 82 | return PTR_ERR(ac); | 83 | return PTR_ERR(ac); |
| @@ -94,8 +95,9 @@ static int __devexit adxl34x_spi_remove(struct spi_device *spi) | |||
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | #ifdef CONFIG_PM | 97 | #ifdef CONFIG_PM |
| 97 | static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) | 98 | static int adxl34x_spi_suspend(struct device *dev) |
| 98 | { | 99 | { |
| 100 | struct spi_device *spi = to_spi_device(dev); | ||
| 99 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); | 101 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); |
| 100 | 102 | ||
| 101 | adxl34x_suspend(ac); | 103 | adxl34x_suspend(ac); |
| @@ -103,29 +105,29 @@ static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) | |||
| 103 | return 0; | 105 | return 0; |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 106 | static int adxl34x_spi_resume(struct spi_device *spi) | 108 | static int adxl34x_spi_resume(struct device *dev) |
| 107 | { | 109 | { |
| 110 | struct spi_device *spi = to_spi_device(dev); | ||
| 108 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); | 111 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); |
| 109 | 112 | ||
| 110 | adxl34x_resume(ac); | 113 | adxl34x_resume(ac); |
| 111 | 114 | ||
| 112 | return 0; | 115 | return 0; |
| 113 | } | 116 | } |
| 114 | #else | ||
| 115 | # define adxl34x_spi_suspend NULL | ||
| 116 | # define adxl34x_spi_resume NULL | ||
| 117 | #endif | 117 | #endif |
| 118 | 118 | ||
| 119 | static SIMPLE_DEV_PM_OPS(adxl34x_spi_pm, adxl34x_spi_suspend, | ||
| 120 | adxl34x_spi_resume); | ||
| 121 | |||
| 119 | static struct spi_driver adxl34x_driver = { | 122 | static struct spi_driver adxl34x_driver = { |
| 120 | .driver = { | 123 | .driver = { |
| 121 | .name = "adxl34x", | 124 | .name = "adxl34x", |
| 122 | .bus = &spi_bus_type, | 125 | .bus = &spi_bus_type, |
| 123 | .owner = THIS_MODULE, | 126 | .owner = THIS_MODULE, |
| 127 | .pm = &adxl34x_spi_pm, | ||
| 124 | }, | 128 | }, |
| 125 | .probe = adxl34x_spi_probe, | 129 | .probe = adxl34x_spi_probe, |
| 126 | .remove = __devexit_p(adxl34x_spi_remove), | 130 | .remove = __devexit_p(adxl34x_spi_remove), |
| 127 | .suspend = adxl34x_spi_suspend, | ||
| 128 | .resume = adxl34x_spi_resume, | ||
| 129 | }; | 131 | }; |
| 130 | 132 | ||
| 131 | static int __init adxl34x_spi_init(void) | 133 | static int __init adxl34x_spi_init(void) |
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c index 0b0e9be63542..9ccdb82d869a 100644 --- a/drivers/input/misc/ati_remote2.c +++ b/drivers/input/misc/ati_remote2.c | |||
| @@ -612,8 +612,8 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2) | |||
| 612 | idev->open = ati_remote2_open; | 612 | idev->open = ati_remote2_open; |
| 613 | idev->close = ati_remote2_close; | 613 | idev->close = ati_remote2_close; |
| 614 | 614 | ||
| 615 | idev->getkeycode_new = ati_remote2_getkeycode; | 615 | idev->getkeycode = ati_remote2_getkeycode; |
| 616 | idev->setkeycode_new = ati_remote2_setkeycode; | 616 | idev->setkeycode = ati_remote2_setkeycode; |
| 617 | 617 | ||
| 618 | idev->name = ar2->name; | 618 | idev->name = ar2->name; |
| 619 | idev->phys = ar2->phys; | 619 | idev->phys = ar2->phys; |
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 82542a1c1098..364bdf43a381 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c | |||
| @@ -347,8 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
| 347 | { | 347 | { |
| 348 | struct uinput_user_dev *user_dev; | 348 | struct uinput_user_dev *user_dev; |
| 349 | struct input_dev *dev; | 349 | struct input_dev *dev; |
| 350 | char *name; | 350 | int i; |
| 351 | int i, size; | ||
| 352 | int retval; | 351 | int retval; |
| 353 | 352 | ||
| 354 | if (count != sizeof(struct uinput_user_dev)) | 353 | if (count != sizeof(struct uinput_user_dev)) |
| @@ -362,30 +361,25 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
| 362 | 361 | ||
| 363 | dev = udev->dev; | 362 | dev = udev->dev; |
| 364 | 363 | ||
| 365 | user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL); | 364 | user_dev = memdup_user(buffer, sizeof(struct uinput_user_dev)); |
| 366 | if (!user_dev) | 365 | if (IS_ERR(user_dev)) |
| 367 | return -ENOMEM; | 366 | return PTR_ERR(user_dev); |
| 368 | |||
| 369 | if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) { | ||
| 370 | retval = -EFAULT; | ||
| 371 | goto exit; | ||
| 372 | } | ||
| 373 | 367 | ||
| 374 | udev->ff_effects_max = user_dev->ff_effects_max; | 368 | udev->ff_effects_max = user_dev->ff_effects_max; |
| 375 | 369 | ||
| 376 | size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; | 370 | /* Ensure name is filled in */ |
| 377 | if (!size) { | 371 | if (!user_dev->name[0]) { |
| 378 | retval = -EINVAL; | 372 | retval = -EINVAL; |
| 379 | goto exit; | 373 | goto exit; |
| 380 | } | 374 | } |
| 381 | 375 | ||
| 382 | kfree(dev->name); | 376 | kfree(dev->name); |
| 383 | dev->name = name = kmalloc(size, GFP_KERNEL); | 377 | dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE, |
| 384 | if (!name) { | 378 | GFP_KERNEL); |
| 379 | if (!dev->name) { | ||
| 385 | retval = -ENOMEM; | 380 | retval = -ENOMEM; |
| 386 | goto exit; | 381 | goto exit; |
| 387 | } | 382 | } |
| 388 | strlcpy(name, user_dev->name, size); | ||
| 389 | 383 | ||
| 390 | dev->id.bustype = user_dev->id.bustype; | 384 | dev->id.bustype = user_dev->id.bustype; |
| 391 | dev->id.vendor = user_dev->id.vendor; | 385 | dev->id.vendor = user_dev->id.vendor; |
| @@ -622,7 +616,6 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, | |||
| 622 | struct uinput_ff_upload ff_up; | 616 | struct uinput_ff_upload ff_up; |
| 623 | struct uinput_ff_erase ff_erase; | 617 | struct uinput_ff_erase ff_erase; |
| 624 | struct uinput_request *req; | 618 | struct uinput_request *req; |
| 625 | int length; | ||
| 626 | char *phys; | 619 | char *phys; |
| 627 | 620 | ||
| 628 | retval = mutex_lock_interruptible(&udev->mutex); | 621 | retval = mutex_lock_interruptible(&udev->mutex); |
| @@ -689,24 +682,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, | |||
| 689 | retval = -EINVAL; | 682 | retval = -EINVAL; |
| 690 | goto out; | 683 | goto out; |
| 691 | } | 684 | } |
| 692 | length = strnlen_user(p, 1024); | 685 | |
| 693 | if (length <= 0) { | 686 | phys = strndup_user(p, 1024); |
| 694 | retval = -EFAULT; | 687 | if (IS_ERR(phys)) { |
| 695 | break; | 688 | retval = PTR_ERR(phys); |
| 689 | goto out; | ||
| 696 | } | 690 | } |
| 691 | |||
| 697 | kfree(udev->dev->phys); | 692 | kfree(udev->dev->phys); |
| 698 | udev->dev->phys = phys = kmalloc(length, GFP_KERNEL); | 693 | udev->dev->phys = phys; |
| 699 | if (!phys) { | ||
| 700 | retval = -ENOMEM; | ||
| 701 | break; | ||
| 702 | } | ||
| 703 | if (copy_from_user(phys, p, length)) { | ||
| 704 | udev->dev->phys = NULL; | ||
| 705 | kfree(phys); | ||
| 706 | retval = -EFAULT; | ||
| 707 | break; | ||
| 708 | } | ||
| 709 | phys[length - 1] = '\0'; | ||
| 710 | break; | 694 | break; |
| 711 | 695 | ||
| 712 | case UI_BEGIN_FF_UPLOAD: | 696 | case UI_BEGIN_FF_UPLOAD: |
diff --git a/drivers/input/misc/winbond-cir.c b/drivers/input/misc/winbond-cir.c deleted file mode 100644 index 64f1de7960c6..000000000000 --- a/drivers/input/misc/winbond-cir.c +++ /dev/null | |||
| @@ -1,1608 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * winbond-cir.c - Driver for the Consumer IR functionality of Winbond | ||
| 3 | * SuperI/O chips. | ||
| 4 | * | ||
| 5 | * Currently supports the Winbond WPCD376i chip (PNP id WEC1022), but | ||
| 6 | * could probably support others (Winbond WEC102X, NatSemi, etc) | ||
| 7 | * with minor modifications. | ||
| 8 | * | ||
| 9 | * Original Author: David Härdeman <david@hardeman.nu> | ||
| 10 | * Copyright (C) 2009 David Härdeman <david@hardeman.nu> | ||
| 11 | * | ||
| 12 | * Dedicated to Matilda, my newborn daughter, without whose loving attention | ||
| 13 | * this driver would have been finished in half the time and with a fraction | ||
| 14 | * of the bugs. | ||
| 15 | * | ||
| 16 | * Written using: | ||
| 17 | * o Winbond WPCD376I datasheet helpfully provided by Jesse Barnes at Intel | ||
| 18 | * o NatSemi PC87338/PC97338 datasheet (for the serial port stuff) | ||
| 19 | * o DSDT dumps | ||
| 20 | * | ||
| 21 | * Supported features: | ||
| 22 | * o RC6 | ||
| 23 | * o Wake-On-CIR functionality | ||
| 24 | * | ||
| 25 | * To do: | ||
| 26 | * o Test NEC and RC5 | ||
| 27 | * | ||
| 28 | * Left as an exercise for the reader: | ||
| 29 | * o Learning (I have neither the hardware, nor the need) | ||
| 30 | * o IR Transmit (ibid) | ||
| 31 | * | ||
| 32 | * This program is free software; you can redistribute it and/or modify | ||
| 33 | * it under the terms of the GNU General Public License as published by | ||
| 34 | * the Free Software Foundation; either version 2 of the License, or | ||
| 35 | * (at your option) any later version. | ||
| 36 | * | ||
| 37 | * This program is distributed in the hope that it will be useful, | ||
| 38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 40 | * GNU General Public License for more details. | ||
| 41 | * | ||
| 42 | * You should have received a copy of the GNU General Public License | ||
| 43 | * along with this program; if not, write to the Free Software | ||
| 44 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 45 | */ | ||
| 46 | |||
| 47 | #include <linux/module.h> | ||
| 48 | #include <linux/pnp.h> | ||
| 49 | #include <linux/interrupt.h> | ||
| 50 | #include <linux/timer.h> | ||
| 51 | #include <linux/input.h> | ||
| 52 | #include <linux/leds.h> | ||
| 53 | #include <linux/list.h> | ||
| 54 | #include <linux/spinlock.h> | ||
| 55 | #include <linux/pci_ids.h> | ||
| 56 | #include <linux/io.h> | ||
| 57 | #include <linux/bitrev.h> | ||
| 58 | #include <linux/bitops.h> | ||
| 59 | #include <linux/slab.h> | ||
| 60 | |||
| 61 | #define DRVNAME "winbond-cir" | ||
| 62 | |||
| 63 | /* CEIR Wake-Up Registers, relative to data->wbase */ | ||
| 64 | #define WBCIR_REG_WCEIR_CTL 0x03 /* CEIR Receiver Control */ | ||
| 65 | #define WBCIR_REG_WCEIR_STS 0x04 /* CEIR Receiver Status */ | ||
| 66 | #define WBCIR_REG_WCEIR_EV_EN 0x05 /* CEIR Receiver Event Enable */ | ||
| 67 | #define WBCIR_REG_WCEIR_CNTL 0x06 /* CEIR Receiver Counter Low */ | ||
| 68 | #define WBCIR_REG_WCEIR_CNTH 0x07 /* CEIR Receiver Counter High */ | ||
| 69 | #define WBCIR_REG_WCEIR_INDEX 0x08 /* CEIR Receiver Index */ | ||
| 70 | #define WBCIR_REG_WCEIR_DATA 0x09 /* CEIR Receiver Data */ | ||
| 71 | #define WBCIR_REG_WCEIR_CSL 0x0A /* CEIR Re. Compare Strlen */ | ||
| 72 | #define WBCIR_REG_WCEIR_CFG1 0x0B /* CEIR Re. Configuration 1 */ | ||
| 73 | #define WBCIR_REG_WCEIR_CFG2 0x0C /* CEIR Re. Configuration 2 */ | ||
| 74 | |||
| 75 | /* CEIR Enhanced Functionality Registers, relative to data->ebase */ | ||
| 76 | #define WBCIR_REG_ECEIR_CTS 0x00 /* Enhanced IR Control Status */ | ||
| 77 | #define WBCIR_REG_ECEIR_CCTL 0x01 /* Infrared Counter Control */ | ||
| 78 | #define WBCIR_REG_ECEIR_CNT_LO 0x02 /* Infrared Counter LSB */ | ||
| 79 | #define WBCIR_REG_ECEIR_CNT_HI 0x03 /* Infrared Counter MSB */ | ||
| 80 | #define WBCIR_REG_ECEIR_IREM 0x04 /* Infrared Emitter Status */ | ||
| 81 | |||
| 82 | /* SP3 Banked Registers, relative to data->sbase */ | ||
| 83 | #define WBCIR_REG_SP3_BSR 0x03 /* Bank Select, all banks */ | ||
| 84 | /* Bank 0 */ | ||
| 85 | #define WBCIR_REG_SP3_RXDATA 0x00 /* FIFO RX data (r) */ | ||
| 86 | #define WBCIR_REG_SP3_TXDATA 0x00 /* FIFO TX data (w) */ | ||
| 87 | #define WBCIR_REG_SP3_IER 0x01 /* Interrupt Enable */ | ||
| 88 | #define WBCIR_REG_SP3_EIR 0x02 /* Event Identification (r) */ | ||
| 89 | #define WBCIR_REG_SP3_FCR 0x02 /* FIFO Control (w) */ | ||
| 90 | #define WBCIR_REG_SP3_MCR 0x04 /* Mode Control */ | ||
| 91 | #define WBCIR_REG_SP3_LSR 0x05 /* Link Status */ | ||
| 92 | #define WBCIR_REG_SP3_MSR 0x06 /* Modem Status */ | ||
| 93 | #define WBCIR_REG_SP3_ASCR 0x07 /* Aux Status and Control */ | ||
| 94 | /* Bank 2 */ | ||
| 95 | #define WBCIR_REG_SP3_BGDL 0x00 /* Baud Divisor LSB */ | ||
| 96 | #define WBCIR_REG_SP3_BGDH 0x01 /* Baud Divisor MSB */ | ||
| 97 | #define WBCIR_REG_SP3_EXCR1 0x02 /* Extended Control 1 */ | ||
| 98 | #define WBCIR_REG_SP3_EXCR2 0x04 /* Extended Control 2 */ | ||
| 99 | #define WBCIR_REG_SP3_TXFLV 0x06 /* TX FIFO Level */ | ||
| 100 | #define WBCIR_REG_SP3_RXFLV 0x07 /* RX FIFO Level */ | ||
| 101 | /* Bank 3 */ | ||
| 102 | #define WBCIR_REG_SP3_MRID 0x00 /* Module Identification */ | ||
| 103 | #define WBCIR_REG_SP3_SH_LCR 0x01 /* LCR Shadow */ | ||
| 104 | #define WBCIR_REG_SP3_SH_FCR 0x02 /* FCR Shadow */ | ||
| 105 | /* Bank 4 */ | ||
| 106 | #define WBCIR_REG_SP3_IRCR1 0x02 /* Infrared Control 1 */ | ||
| 107 | /* Bank 5 */ | ||
| 108 | #define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */ | ||
| 109 | /* Bank 6 */ | ||
| 110 | #define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */ | ||
| 111 | #define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */ | ||
| 112 | /* Bank 7 */ | ||
| 113 | #define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */ | ||
| 114 | #define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */ | ||
| 115 | #define WBCIR_REG_SP3_RCCFG 0x02 /* CEIR Config */ | ||
| 116 | #define WBCIR_REG_SP3_IRCFG1 0x04 /* Infrared Config 1 */ | ||
| 117 | #define WBCIR_REG_SP3_IRCFG4 0x07 /* Infrared Config 4 */ | ||
| 118 | |||
| 119 | /* | ||
| 120 | * Magic values follow | ||
| 121 | */ | ||
| 122 | |||
| 123 | /* No interrupts for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
| 124 | #define WBCIR_IRQ_NONE 0x00 | ||
| 125 | /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
| 126 | #define WBCIR_IRQ_RX 0x01 | ||
| 127 | /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
| 128 | #define WBCIR_IRQ_ERR 0x04 | ||
| 129 | /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */ | ||
| 130 | #define WBCIR_LED_ENABLE 0x80 | ||
| 131 | /* RX data available bit for WBCIR_REG_SP3_LSR */ | ||
| 132 | #define WBCIR_RX_AVAIL 0x01 | ||
| 133 | /* RX disable bit for WBCIR_REG_SP3_ASCR */ | ||
| 134 | #define WBCIR_RX_DISABLE 0x20 | ||
| 135 | /* Extended mode enable bit for WBCIR_REG_SP3_EXCR1 */ | ||
| 136 | #define WBCIR_EXT_ENABLE 0x01 | ||
| 137 | /* Select compare register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | ||
| 138 | #define WBCIR_REGSEL_COMPARE 0x10 | ||
| 139 | /* Select mask register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | ||
| 140 | #define WBCIR_REGSEL_MASK 0x20 | ||
| 141 | /* Starting address of selected register in WBCIR_REG_WCEIR_INDEX */ | ||
| 142 | #define WBCIR_REG_ADDR0 0x00 | ||
| 143 | |||
| 144 | /* Valid banks for the SP3 UART */ | ||
| 145 | enum wbcir_bank { | ||
| 146 | WBCIR_BANK_0 = 0x00, | ||
| 147 | WBCIR_BANK_1 = 0x80, | ||
| 148 | WBCIR_BANK_2 = 0xE0, | ||
| 149 | WBCIR_BANK_3 = 0xE4, | ||
| 150 | WBCIR_BANK_4 = 0xE8, | ||
| 151 | WBCIR_BANK_5 = 0xEC, | ||
| 152 | WBCIR_BANK_6 = 0xF0, | ||
| 153 | WBCIR_BANK_7 = 0xF4, | ||
| 154 | }; | ||
| 155 | |||
| 156 | /* Supported IR Protocols */ | ||
| 157 | enum wbcir_protocol { | ||
| 158 | IR_PROTOCOL_RC5 = 0x0, | ||
| 159 | IR_PROTOCOL_NEC = 0x1, | ||
| 160 | IR_PROTOCOL_RC6 = 0x2, | ||
| 161 | }; | ||
| 162 | |||
| 163 | /* Misc */ | ||
| 164 | #define WBCIR_NAME "Winbond CIR" | ||
| 165 | #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */ | ||
| 166 | #define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */ | ||
| 167 | #define IR_KEYPRESS_TIMEOUT 250 /* FIXME: should be per-protocol? */ | ||
| 168 | #define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */ | ||
| 169 | #define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */ | ||
| 170 | #define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */ | ||
| 171 | #define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */ | ||
| 172 | #define WBCIR_MAX_IDLE_BYTES 10 | ||
| 173 | |||
| 174 | static DEFINE_SPINLOCK(wbcir_lock); | ||
| 175 | static DEFINE_RWLOCK(keytable_lock); | ||
| 176 | |||
| 177 | struct wbcir_key { | ||
| 178 | u32 scancode; | ||
| 179 | unsigned int keycode; | ||
| 180 | }; | ||
| 181 | |||
| 182 | struct wbcir_keyentry { | ||
| 183 | struct wbcir_key key; | ||
| 184 | struct list_head list; | ||
| 185 | }; | ||
| 186 | |||
| 187 | static struct wbcir_key rc6_def_keymap[] = { | ||
| 188 | { 0x800F0400, KEY_NUMERIC_0 }, | ||
| 189 | { 0x800F0401, KEY_NUMERIC_1 }, | ||
| 190 | { 0x800F0402, KEY_NUMERIC_2 }, | ||
| 191 | { 0x800F0403, KEY_NUMERIC_3 }, | ||
| 192 | { 0x800F0404, KEY_NUMERIC_4 }, | ||
| 193 | { 0x800F0405, KEY_NUMERIC_5 }, | ||
| 194 | { 0x800F0406, KEY_NUMERIC_6 }, | ||
| 195 | { 0x800F0407, KEY_NUMERIC_7 }, | ||
| 196 | { 0x800F0408, KEY_NUMERIC_8 }, | ||
| 197 | { 0x800F0409, KEY_NUMERIC_9 }, | ||
| 198 | { 0x800F041D, KEY_NUMERIC_STAR }, | ||
| 199 | { 0x800F041C, KEY_NUMERIC_POUND }, | ||
| 200 | { 0x800F0410, KEY_VOLUMEUP }, | ||
| 201 | { 0x800F0411, KEY_VOLUMEDOWN }, | ||
| 202 | { 0x800F0412, KEY_CHANNELUP }, | ||
| 203 | { 0x800F0413, KEY_CHANNELDOWN }, | ||
| 204 | { 0x800F040E, KEY_MUTE }, | ||
| 205 | { 0x800F040D, KEY_VENDOR }, /* Vista Logo Key */ | ||
| 206 | { 0x800F041E, KEY_UP }, | ||
| 207 | { 0x800F041F, KEY_DOWN }, | ||
| 208 | { 0x800F0420, KEY_LEFT }, | ||
| 209 | { 0x800F0421, KEY_RIGHT }, | ||
| 210 | { 0x800F0422, KEY_OK }, | ||
| 211 | { 0x800F0423, KEY_ESC }, | ||
| 212 | { 0x800F040F, KEY_INFO }, | ||
| 213 | { 0x800F040A, KEY_CLEAR }, | ||
| 214 | { 0x800F040B, KEY_ENTER }, | ||
| 215 | { 0x800F045B, KEY_RED }, | ||
| 216 | { 0x800F045C, KEY_GREEN }, | ||
| 217 | { 0x800F045D, KEY_YELLOW }, | ||
| 218 | { 0x800F045E, KEY_BLUE }, | ||
| 219 | { 0x800F045A, KEY_TEXT }, | ||
| 220 | { 0x800F0427, KEY_SWITCHVIDEOMODE }, | ||
| 221 | { 0x800F040C, KEY_POWER }, | ||
| 222 | { 0x800F0450, KEY_RADIO }, | ||
| 223 | { 0x800F0448, KEY_PVR }, | ||
| 224 | { 0x800F0447, KEY_AUDIO }, | ||
| 225 | { 0x800F0426, KEY_EPG }, | ||
| 226 | { 0x800F0449, KEY_CAMERA }, | ||
| 227 | { 0x800F0425, KEY_TV }, | ||
| 228 | { 0x800F044A, KEY_VIDEO }, | ||
| 229 | { 0x800F0424, KEY_DVD }, | ||
| 230 | { 0x800F0416, KEY_PLAY }, | ||
| 231 | { 0x800F0418, KEY_PAUSE }, | ||
| 232 | { 0x800F0419, KEY_STOP }, | ||
| 233 | { 0x800F0414, KEY_FASTFORWARD }, | ||
| 234 | { 0x800F041A, KEY_NEXT }, | ||
| 235 | { 0x800F041B, KEY_PREVIOUS }, | ||
| 236 | { 0x800F0415, KEY_REWIND }, | ||
| 237 | { 0x800F0417, KEY_RECORD }, | ||
| 238 | }; | ||
| 239 | |||
| 240 | /* Registers and other state is protected by wbcir_lock */ | ||
| 241 | struct wbcir_data { | ||
| 242 | unsigned long wbase; /* Wake-Up Baseaddr */ | ||
| 243 | unsigned long ebase; /* Enhanced Func. Baseaddr */ | ||
| 244 | unsigned long sbase; /* Serial Port Baseaddr */ | ||
| 245 | unsigned int irq; /* Serial Port IRQ */ | ||
| 246 | |||
| 247 | struct input_dev *input_dev; | ||
| 248 | struct timer_list timer_keyup; | ||
| 249 | struct led_trigger *rxtrigger; | ||
| 250 | struct led_trigger *txtrigger; | ||
| 251 | struct led_classdev led; | ||
| 252 | |||
| 253 | u32 last_scancode; | ||
| 254 | unsigned int last_keycode; | ||
| 255 | u8 last_toggle; | ||
| 256 | u8 keypressed; | ||
| 257 | unsigned long keyup_jiffies; | ||
| 258 | unsigned int idle_count; | ||
| 259 | |||
| 260 | /* RX irdata and parsing state */ | ||
| 261 | unsigned long irdata[30]; | ||
| 262 | unsigned int irdata_count; | ||
| 263 | unsigned int irdata_idle; | ||
| 264 | unsigned int irdata_off; | ||
| 265 | unsigned int irdata_error; | ||
| 266 | |||
| 267 | /* Protected by keytable_lock */ | ||
| 268 | struct list_head keytable; | ||
| 269 | }; | ||
| 270 | |||
| 271 | static enum wbcir_protocol protocol = IR_PROTOCOL_RC6; | ||
| 272 | module_param(protocol, uint, 0444); | ||
| 273 | MODULE_PARM_DESC(protocol, "IR protocol to use " | ||
| 274 | "(0 = RC5, 1 = NEC, 2 = RC6A, default)"); | ||
| 275 | |||
| 276 | static int invert; /* default = 0 */ | ||
| 277 | module_param(invert, bool, 0444); | ||
| 278 | MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver"); | ||
| 279 | |||
| 280 | static unsigned int wake_sc = 0x800F040C; | ||
| 281 | module_param(wake_sc, uint, 0644); | ||
| 282 | MODULE_PARM_DESC(wake_sc, "Scancode of the power-on IR command"); | ||
| 283 | |||
| 284 | static unsigned int wake_rc6mode = 6; | ||
| 285 | module_param(wake_rc6mode, uint, 0644); | ||
| 286 | MODULE_PARM_DESC(wake_rc6mode, "RC6 mode for the power-on command " | ||
| 287 | "(0 = 0, 6 = 6A, default)"); | ||
| 288 | |||
| 289 | |||
| 290 | |||
| 291 | /***************************************************************************** | ||
| 292 | * | ||
| 293 | * UTILITY FUNCTIONS | ||
| 294 | * | ||
| 295 | *****************************************************************************/ | ||
| 296 | |||
| 297 | /* Caller needs to hold wbcir_lock */ | ||
| 298 | static void | ||
| 299 | wbcir_set_bits(unsigned long addr, u8 bits, u8 mask) | ||
| 300 | { | ||
| 301 | u8 val; | ||
| 302 | |||
| 303 | val = inb(addr); | ||
| 304 | val = ((val & ~mask) | (bits & mask)); | ||
| 305 | outb(val, addr); | ||
| 306 | } | ||
| 307 | |||
| 308 | /* Selects the register bank for the serial port */ | ||
| 309 | static inline void | ||
| 310 | wbcir_select_bank(struct wbcir_data *data, enum wbcir_bank bank) | ||
| 311 | { | ||
| 312 | outb(bank, data->sbase + WBCIR_REG_SP3_BSR); | ||
| 313 | } | ||
| 314 | |||
| 315 | static enum led_brightness | ||
| 316 | wbcir_led_brightness_get(struct led_classdev *led_cdev) | ||
| 317 | { | ||
| 318 | struct wbcir_data *data = container_of(led_cdev, | ||
| 319 | struct wbcir_data, | ||
| 320 | led); | ||
| 321 | |||
| 322 | if (inb(data->ebase + WBCIR_REG_ECEIR_CTS) & WBCIR_LED_ENABLE) | ||
| 323 | return LED_FULL; | ||
| 324 | else | ||
| 325 | return LED_OFF; | ||
| 326 | } | ||
| 327 | |||
| 328 | static void | ||
| 329 | wbcir_led_brightness_set(struct led_classdev *led_cdev, | ||
| 330 | enum led_brightness brightness) | ||
| 331 | { | ||
| 332 | struct wbcir_data *data = container_of(led_cdev, | ||
| 333 | struct wbcir_data, | ||
| 334 | led); | ||
| 335 | |||
| 336 | wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CTS, | ||
| 337 | brightness == LED_OFF ? 0x00 : WBCIR_LED_ENABLE, | ||
| 338 | WBCIR_LED_ENABLE); | ||
| 339 | } | ||
| 340 | |||
| 341 | /* Manchester encodes bits to RC6 message cells (see wbcir_parse_rc6) */ | ||
| 342 | static u8 | ||
| 343 | wbcir_to_rc6cells(u8 val) | ||
| 344 | { | ||
| 345 | u8 coded = 0x00; | ||
| 346 | int i; | ||
| 347 | |||
| 348 | val &= 0x0F; | ||
| 349 | for (i = 0; i < 4; i++) { | ||
| 350 | if (val & 0x01) | ||
| 351 | coded |= 0x02 << (i * 2); | ||
| 352 | else | ||
| 353 | coded |= 0x01 << (i * 2); | ||
| 354 | val >>= 1; | ||
| 355 | } | ||
| 356 | |||
| 357 | return coded; | ||
| 358 | } | ||
| 359 | |||
| 360 | |||
| 361 | |||
| 362 | /***************************************************************************** | ||
| 363 | * | ||
| 364 | * INPUT FUNCTIONS | ||
| 365 | * | ||
| 366 | *****************************************************************************/ | ||
| 367 | |||
| 368 | static unsigned int | ||
| 369 | wbcir_do_getkeycode(struct wbcir_data *data, u32 scancode) | ||
| 370 | { | ||
| 371 | struct wbcir_keyentry *keyentry; | ||
| 372 | unsigned int keycode = KEY_RESERVED; | ||
| 373 | unsigned long flags; | ||
| 374 | |||
| 375 | read_lock_irqsave(&keytable_lock, flags); | ||
| 376 | |||
| 377 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
| 378 | if (keyentry->key.scancode == scancode) { | ||
| 379 | keycode = keyentry->key.keycode; | ||
| 380 | break; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | read_unlock_irqrestore(&keytable_lock, flags); | ||
| 385 | return keycode; | ||
| 386 | } | ||
| 387 | |||
| 388 | static int | ||
| 389 | wbcir_getkeycode(struct input_dev *dev, | ||
| 390 | unsigned int scancode, unsigned int *keycode) | ||
| 391 | { | ||
| 392 | struct wbcir_data *data = input_get_drvdata(dev); | ||
| 393 | |||
| 394 | *keycode = wbcir_do_getkeycode(data, scancode); | ||
| 395 | return 0; | ||
| 396 | } | ||
| 397 | |||
| 398 | static int | ||
| 399 | wbcir_setkeycode(struct input_dev *dev, | ||
| 400 | unsigned int scancode, unsigned int keycode) | ||
| 401 | { | ||
| 402 | struct wbcir_data *data = input_get_drvdata(dev); | ||
| 403 | struct wbcir_keyentry *keyentry; | ||
| 404 | struct wbcir_keyentry *new_keyentry; | ||
| 405 | unsigned long flags; | ||
| 406 | unsigned int old_keycode = KEY_RESERVED; | ||
| 407 | |||
| 408 | new_keyentry = kmalloc(sizeof(*new_keyentry), GFP_KERNEL); | ||
| 409 | if (!new_keyentry) | ||
| 410 | return -ENOMEM; | ||
| 411 | |||
| 412 | write_lock_irqsave(&keytable_lock, flags); | ||
| 413 | |||
| 414 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
| 415 | if (keyentry->key.scancode != scancode) | ||
| 416 | continue; | ||
| 417 | |||
| 418 | old_keycode = keyentry->key.keycode; | ||
| 419 | keyentry->key.keycode = keycode; | ||
| 420 | |||
| 421 | if (keyentry->key.keycode == KEY_RESERVED) { | ||
| 422 | list_del(&keyentry->list); | ||
| 423 | kfree(keyentry); | ||
| 424 | } | ||
| 425 | |||
| 426 | break; | ||
| 427 | } | ||
| 428 | |||
| 429 | set_bit(keycode, dev->keybit); | ||
| 430 | |||
| 431 | if (old_keycode == KEY_RESERVED) { | ||
| 432 | new_keyentry->key.scancode = scancode; | ||
| 433 | new_keyentry->key.keycode = keycode; | ||
| 434 | list_add(&new_keyentry->list, &data->keytable); | ||
| 435 | } else { | ||
| 436 | kfree(new_keyentry); | ||
| 437 | clear_bit(old_keycode, dev->keybit); | ||
| 438 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
| 439 | if (keyentry->key.keycode == old_keycode) { | ||
| 440 | set_bit(old_keycode, dev->keybit); | ||
| 441 | break; | ||
| 442 | } | ||
| 443 | } | ||
| 444 | } | ||
| 445 | |||
| 446 | write_unlock_irqrestore(&keytable_lock, flags); | ||
| 447 | return 0; | ||
| 448 | } | ||
| 449 | |||
| 450 | /* | ||
| 451 | * Timer function to report keyup event some time after keydown is | ||
| 452 | * reported by the ISR. | ||
| 453 | */ | ||
| 454 | static void | ||
| 455 | wbcir_keyup(unsigned long cookie) | ||
| 456 | { | ||
| 457 | struct wbcir_data *data = (struct wbcir_data *)cookie; | ||
| 458 | unsigned long flags; | ||
| 459 | |||
| 460 | /* | ||
| 461 | * data->keyup_jiffies is used to prevent a race condition if a | ||
| 462 | * hardware interrupt occurs at this point and the keyup timer | ||
| 463 | * event is moved further into the future as a result. | ||
| 464 | * | ||
| 465 | * The timer will then be reactivated and this function called | ||
| 466 | * again in the future. We need to exit gracefully in that case | ||
| 467 | * to allow the input subsystem to do its auto-repeat magic or | ||
| 468 | * a keyup event might follow immediately after the keydown. | ||
| 469 | */ | ||
| 470 | |||
| 471 | spin_lock_irqsave(&wbcir_lock, flags); | ||
| 472 | |||
| 473 | if (time_is_after_eq_jiffies(data->keyup_jiffies) && data->keypressed) { | ||
| 474 | data->keypressed = 0; | ||
| 475 | led_trigger_event(data->rxtrigger, LED_OFF); | ||
| 476 | input_report_key(data->input_dev, data->last_keycode, 0); | ||
| 477 | input_sync(data->input_dev); | ||
| 478 | } | ||
| 479 | |||
| 480 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
| 481 | } | ||
| 482 | |||
| 483 | static void | ||
| 484 | wbcir_keydown(struct wbcir_data *data, u32 scancode, u8 toggle) | ||
| 485 | { | ||
| 486 | unsigned int keycode; | ||
| 487 | |||
| 488 | /* Repeat? */ | ||
| 489 | if (data->last_scancode == scancode && | ||
| 490 | data->last_toggle == toggle && | ||
| 491 | data->keypressed) | ||
| 492 | goto set_timer; | ||
| 493 | data->last_scancode = scancode; | ||
| 494 | |||
| 495 | /* Do we need to release an old keypress? */ | ||
| 496 | if (data->keypressed) { | ||
| 497 | input_report_key(data->input_dev, data->last_keycode, 0); | ||
| 498 | input_sync(data->input_dev); | ||
| 499 | data->keypressed = 0; | ||
| 500 | } | ||
| 501 | |||
| 502 | /* Report scancode */ | ||
| 503 | input_event(data->input_dev, EV_MSC, MSC_SCAN, (int)scancode); | ||
| 504 | |||
| 505 | /* Do we know this scancode? */ | ||
| 506 | keycode = wbcir_do_getkeycode(data, scancode); | ||
| 507 | if (keycode == KEY_RESERVED) | ||
| 508 | goto set_timer; | ||
| 509 | |||
| 510 | /* Register a keypress */ | ||
| 511 | input_report_key(data->input_dev, keycode, 1); | ||
| 512 | data->keypressed = 1; | ||
| 513 | data->last_keycode = keycode; | ||
| 514 | data->last_toggle = toggle; | ||
| 515 | |||
| 516 | set_timer: | ||
| 517 | input_sync(data->input_dev); | ||
| 518 | led_trigger_event(data->rxtrigger, | ||
| 519 | data->keypressed ? LED_FULL : LED_OFF); | ||
| 520 | data->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); | ||
| 521 | mod_timer(&data->timer_keyup, data->keyup_jiffies); | ||
| 522 | } | ||
| 523 | |||
| 524 | |||
| 525 | |||
| 526 | /***************************************************************************** | ||
| 527 | * | ||
| 528 | * IR PARSING FUNCTIONS | ||
| 529 | * | ||
| 530 | *****************************************************************************/ | ||
| 531 | |||
| 532 | /* Resets all irdata */ | ||
| 533 | static void | ||
| 534 | wbcir_reset_irdata(struct wbcir_data *data) | ||
| 535 | { | ||
| 536 | memset(data->irdata, 0, sizeof(data->irdata)); | ||
| 537 | data->irdata_count = 0; | ||
| 538 | data->irdata_off = 0; | ||
| 539 | data->irdata_error = 0; | ||
| 540 | data->idle_count = 0; | ||
| 541 | } | ||
| 542 | |||
| 543 | /* Adds one bit of irdata */ | ||
| 544 | static void | ||
| 545 | add_irdata_bit(struct wbcir_data *data, int set) | ||
| 546 | { | ||
| 547 | if (data->irdata_count >= sizeof(data->irdata) * 8) { | ||
| 548 | data->irdata_error = 1; | ||
| 549 | return; | ||
| 550 | } | ||
| 551 | |||
| 552 | if (set) | ||
| 553 | __set_bit(data->irdata_count, data->irdata); | ||
| 554 | data->irdata_count++; | ||
| 555 | } | ||
| 556 | |||
| 557 | /* Gets count bits of irdata */ | ||
| 558 | static u16 | ||
| 559 | get_bits(struct wbcir_data *data, int count) | ||
| 560 | { | ||
| 561 | u16 val = 0x0; | ||
| 562 | |||
| 563 | if (data->irdata_count - data->irdata_off < count) { | ||
| 564 | data->irdata_error = 1; | ||
| 565 | return 0x0; | ||
| 566 | } | ||
| 567 | |||
| 568 | while (count > 0) { | ||
| 569 | val <<= 1; | ||
| 570 | if (test_bit(data->irdata_off, data->irdata)) | ||
| 571 | val |= 0x1; | ||
| 572 | count--; | ||
| 573 | data->irdata_off++; | ||
| 574 | } | ||
| 575 | |||
| 576 | return val; | ||
| 577 | } | ||
| 578 | |||
| 579 | /* Reads 16 cells and converts them to a byte */ | ||
| 580 | static u8 | ||
| 581 | wbcir_rc6cells_to_byte(struct wbcir_data *data) | ||
| 582 | { | ||
| 583 | u16 raw = get_bits(data, 16); | ||
| 584 | u8 val = 0x00; | ||
| 585 | int bit; | ||
| 586 | |||
| 587 | for (bit = 0; bit < 8; bit++) { | ||
| 588 | switch (raw & 0x03) { | ||
| 589 | case 0x01: | ||
| 590 | break; | ||
| 591 | case 0x02: | ||
| 592 | val |= (0x01 << bit); | ||
| 593 | break; | ||
| 594 | default: | ||
| 595 | data->irdata_error = 1; | ||
| 596 | break; | ||
| 597 | } | ||
| 598 | raw >>= 2; | ||
| 599 | } | ||
| 600 | |||
| 601 | return val; | ||
| 602 | } | ||
| 603 | |||
| 604 | /* Decodes a number of bits from raw RC5 data */ | ||
| 605 | static u8 | ||
| 606 | wbcir_get_rc5bits(struct wbcir_data *data, unsigned int count) | ||
| 607 | { | ||
| 608 | u16 raw = get_bits(data, count * 2); | ||
| 609 | u8 val = 0x00; | ||
| 610 | int bit; | ||
| 611 | |||
| 612 | for (bit = 0; bit < count; bit++) { | ||
| 613 | switch (raw & 0x03) { | ||
| 614 | case 0x01: | ||
| 615 | val |= (0x01 << bit); | ||
| 616 | break; | ||
| 617 | case 0x02: | ||
| 618 | break; | ||
| 619 | default: | ||
| 620 | data->irdata_error = 1; | ||
| 621 | break; | ||
| 622 | } | ||
| 623 | raw >>= 2; | ||
| 624 | } | ||
| 625 | |||
| 626 | return val; | ||
| 627 | } | ||
| 628 | |||
| 629 | static void | ||
| 630 | wbcir_parse_rc6(struct device *dev, struct wbcir_data *data) | ||
| 631 | { | ||
| 632 | /* | ||
| 633 | * Normal bits are manchester coded as follows: | ||
| 634 | * cell0 + cell1 = logic "0" | ||
| 635 | * cell1 + cell0 = logic "1" | ||
| 636 | * | ||
| 637 | * The IR pulse has the following components: | ||
| 638 | * | ||
| 639 | * Leader - 6 * cell1 - discarded | ||
| 640 | * Gap - 2 * cell0 - discarded | ||
| 641 | * Start bit - Normal Coding - always "1" | ||
| 642 | * Mode Bit 2 - 0 - Normal Coding | ||
| 643 | * Toggle bit - Normal Coding with double bit time, | ||
| 644 | * e.g. cell0 + cell0 + cell1 + cell1 | ||
| 645 | * means logic "0". | ||
| 646 | * | ||
| 647 | * The rest depends on the mode, the following modes are known: | ||
| 648 | * | ||
| 649 | * MODE 0: | ||
| 650 | * Address Bit 7 - 0 - Normal Coding | ||
| 651 | * Command Bit 7 - 0 - Normal Coding | ||
| 652 | * | ||
| 653 | * MODE 6: | ||
| 654 | * The above Toggle Bit is used as a submode bit, 0 = A, 1 = B. | ||
| 655 | * Submode B is for pointing devices, only remotes using submode A | ||
| 656 | * are supported. | ||
| 657 | * | ||
| 658 | * Customer range bit - 0 => Customer = 7 bits, 0...127 | ||
| 659 | * 1 => Customer = 15 bits, 32768...65535 | ||
| 660 | * Customer Bits - Normal Coding | ||
| 661 | * | ||
| 662 | * Customer codes are allocated by Philips. The rest of the bits | ||
| 663 | * are customer dependent. The following is commonly used (and the | ||
| 664 | * only supported config): | ||
| 665 | * | ||
| 666 | * Toggle Bit - Normal Coding | ||
| 667 | * Address Bit 6 - 0 - Normal Coding | ||
| 668 | * Command Bit 7 - 0 - Normal Coding | ||
| 669 | * | ||
| 670 | * All modes are followed by at least 6 * cell0. | ||
| 671 | * | ||
| 672 | * MODE 0 msglen: | ||
| 673 | * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (toggle) + | ||
| 674 | * 8 * 2 (address) + 8 * 2 (command) = | ||
| 675 | * 44 cells | ||
| 676 | * | ||
| 677 | * MODE 6A msglen: | ||
| 678 | * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (submode) + | ||
| 679 | * 1 * 2 (customer range bit) + 7/15 * 2 (customer bits) + | ||
| 680 | * 1 * 2 (toggle bit) + 7 * 2 (address) + 8 * 2 (command) = | ||
| 681 | * 60 - 76 cells | ||
| 682 | */ | ||
| 683 | u8 mode; | ||
| 684 | u8 toggle; | ||
| 685 | u16 customer = 0x0; | ||
| 686 | u8 address; | ||
| 687 | u8 command; | ||
| 688 | u32 scancode; | ||
| 689 | |||
| 690 | /* Leader mark */ | ||
| 691 | while (get_bits(data, 1) && !data->irdata_error) | ||
| 692 | /* Do nothing */; | ||
| 693 | |||
| 694 | /* Leader space */ | ||
| 695 | if (get_bits(data, 1)) { | ||
| 696 | dev_dbg(dev, "RC6 - Invalid leader space\n"); | ||
| 697 | return; | ||
| 698 | } | ||
| 699 | |||
| 700 | /* Start bit */ | ||
| 701 | if (get_bits(data, 2) != 0x02) { | ||
| 702 | dev_dbg(dev, "RC6 - Invalid start bit\n"); | ||
| 703 | return; | ||
| 704 | } | ||
| 705 | |||
| 706 | /* Mode */ | ||
| 707 | mode = get_bits(data, 6); | ||
| 708 | switch (mode) { | ||
| 709 | case 0x15: /* 010101 = b000 */ | ||
| 710 | mode = 0; | ||
| 711 | break; | ||
| 712 | case 0x29: /* 101001 = b110 */ | ||
| 713 | mode = 6; | ||
| 714 | break; | ||
| 715 | default: | ||
| 716 | dev_dbg(dev, "RC6 - Invalid mode\n"); | ||
| 717 | return; | ||
| 718 | } | ||
| 719 | |||
| 720 | /* Toggle bit / Submode bit */ | ||
| 721 | toggle = get_bits(data, 4); | ||
| 722 | switch (toggle) { | ||
| 723 | case 0x03: | ||
| 724 | toggle = 0; | ||
| 725 | break; | ||
| 726 | case 0x0C: | ||
| 727 | toggle = 1; | ||
| 728 | break; | ||
| 729 | default: | ||
| 730 | dev_dbg(dev, "RC6 - Toggle bit error\n"); | ||
| 731 | break; | ||
| 732 | } | ||
| 733 | |||
| 734 | /* Customer */ | ||
| 735 | if (mode == 6) { | ||
| 736 | if (toggle != 0) { | ||
| 737 | dev_dbg(dev, "RC6B - Not Supported\n"); | ||
| 738 | return; | ||
| 739 | } | ||
| 740 | |||
| 741 | customer = wbcir_rc6cells_to_byte(data); | ||
| 742 | |||
| 743 | if (customer & 0x80) { | ||
| 744 | /* 15 bit customer value */ | ||
| 745 | customer <<= 8; | ||
| 746 | customer |= wbcir_rc6cells_to_byte(data); | ||
| 747 | } | ||
| 748 | } | ||
| 749 | |||
| 750 | /* Address */ | ||
| 751 | address = wbcir_rc6cells_to_byte(data); | ||
| 752 | if (mode == 6) { | ||
| 753 | toggle = address >> 7; | ||
| 754 | address &= 0x7F; | ||
| 755 | } | ||
| 756 | |||
| 757 | /* Command */ | ||
| 758 | command = wbcir_rc6cells_to_byte(data); | ||
| 759 | |||
| 760 | /* Create scancode */ | ||
| 761 | scancode = command; | ||
| 762 | scancode |= address << 8; | ||
| 763 | scancode |= customer << 16; | ||
| 764 | |||
| 765 | /* Last sanity check */ | ||
| 766 | if (data->irdata_error) { | ||
| 767 | dev_dbg(dev, "RC6 - Cell error(s)\n"); | ||
| 768 | return; | ||
| 769 | } | ||
| 770 | |||
| 771 | dev_dbg(dev, "IR-RC6 ad 0x%02X cm 0x%02X cu 0x%04X " | ||
| 772 | "toggle %u mode %u scan 0x%08X\n", | ||
| 773 | address, | ||
| 774 | command, | ||
| 775 | customer, | ||
| 776 | (unsigned int)toggle, | ||
| 777 | (unsigned int)mode, | ||
| 778 | scancode); | ||
| 779 | |||
| 780 | wbcir_keydown(data, scancode, toggle); | ||
| 781 | } | ||
| 782 | |||
| 783 | static void | ||
| 784 | wbcir_parse_rc5(struct device *dev, struct wbcir_data *data) | ||
| 785 | { | ||
| 786 | /* | ||
| 787 | * Bits are manchester coded as follows: | ||
| 788 | * cell1 + cell0 = logic "0" | ||
| 789 | * cell0 + cell1 = logic "1" | ||
| 790 | * (i.e. the reverse of RC6) | ||
| 791 | * | ||
| 792 | * Start bit 1 - "1" - discarded | ||
| 793 | * Start bit 2 - Must be inverted to get command bit 6 | ||
| 794 | * Toggle bit | ||
| 795 | * Address Bit 4 - 0 | ||
| 796 | * Command Bit 5 - 0 | ||
| 797 | */ | ||
| 798 | u8 toggle; | ||
| 799 | u8 address; | ||
| 800 | u8 command; | ||
| 801 | u32 scancode; | ||
| 802 | |||
| 803 | /* Start bit 1 */ | ||
| 804 | if (!get_bits(data, 1)) { | ||
| 805 | dev_dbg(dev, "RC5 - Invalid start bit\n"); | ||
| 806 | return; | ||
| 807 | } | ||
| 808 | |||
| 809 | /* Start bit 2 */ | ||
| 810 | if (!wbcir_get_rc5bits(data, 1)) | ||
| 811 | command = 0x40; | ||
| 812 | else | ||
| 813 | command = 0x00; | ||
| 814 | |||
| 815 | toggle = wbcir_get_rc5bits(data, 1); | ||
| 816 | address = wbcir_get_rc5bits(data, 5); | ||
| 817 | command |= wbcir_get_rc5bits(data, 6); | ||
| 818 | scancode = address << 7 | command; | ||
| 819 | |||
| 820 | /* Last sanity check */ | ||
| 821 | if (data->irdata_error) { | ||
| 822 | dev_dbg(dev, "RC5 - Invalid message\n"); | ||
| 823 | return; | ||
| 824 | } | ||
| 825 | |||
| 826 | dev_dbg(dev, "IR-RC5 ad %u cm %u t %u s %u\n", | ||
| 827 | (unsigned int)address, | ||
| 828 | (unsigned int)command, | ||
| 829 | (unsigned int)toggle, | ||
| 830 | (unsigned int)scancode); | ||
| 831 | |||
| 832 | wbcir_keydown(data, scancode, toggle); | ||
| 833 | } | ||
| 834 | |||
| 835 | static void | ||
| 836 | wbcir_parse_nec(struct device *dev, struct wbcir_data *data) | ||
| 837 | { | ||
| 838 | /* | ||
| 839 | * Each bit represents 560 us. | ||
| 840 | * | ||
| 841 | * Leader - 9 ms burst | ||
| 842 | * Gap - 4.5 ms silence | ||
| 843 | * Address1 bit 0 - 7 - Address 1 | ||
| 844 | * Address2 bit 0 - 7 - Address 2 | ||
| 845 | * Command1 bit 0 - 7 - Command 1 | ||
| 846 | * Command2 bit 0 - 7 - Command 2 | ||
| 847 | * | ||
| 848 | * Note the bit order! | ||
| 849 | * | ||
| 850 | * With the old NEC protocol, Address2 was the inverse of Address1 | ||
| 851 | * and Command2 was the inverse of Command1 and were used as | ||
| 852 | * an error check. | ||
| 853 | * | ||
| 854 | * With NEC extended, Address1 is the LSB of the Address and | ||
| 855 | * Address2 is the MSB, Command parsing remains unchanged. | ||
| 856 | * | ||
| 857 | * A repeat message is coded as: | ||
| 858 | * Leader - 9 ms burst | ||
| 859 | * Gap - 2.25 ms silence | ||
| 860 | * Repeat - 560 us active | ||
| 861 | */ | ||
| 862 | u8 address1; | ||
| 863 | u8 address2; | ||
| 864 | u8 command1; | ||
| 865 | u8 command2; | ||
| 866 | u16 address; | ||
| 867 | u32 scancode; | ||
| 868 | |||
| 869 | /* Leader mark */ | ||
| 870 | while (get_bits(data, 1) && !data->irdata_error) | ||
| 871 | /* Do nothing */; | ||
| 872 | |||
| 873 | /* Leader space */ | ||
| 874 | if (get_bits(data, 4)) { | ||
| 875 | dev_dbg(dev, "NEC - Invalid leader space\n"); | ||
| 876 | return; | ||
| 877 | } | ||
| 878 | |||
| 879 | /* Repeat? */ | ||
| 880 | if (get_bits(data, 1)) { | ||
| 881 | if (!data->keypressed) { | ||
| 882 | dev_dbg(dev, "NEC - Stray repeat message\n"); | ||
| 883 | return; | ||
| 884 | } | ||
| 885 | |||
| 886 | dev_dbg(dev, "IR-NEC repeat s %u\n", | ||
| 887 | (unsigned int)data->last_scancode); | ||
| 888 | |||
| 889 | wbcir_keydown(data, data->last_scancode, data->last_toggle); | ||
| 890 | return; | ||
| 891 | } | ||
| 892 | |||
| 893 | /* Remaining leader space */ | ||
| 894 | if (get_bits(data, 3)) { | ||
| 895 | dev_dbg(dev, "NEC - Invalid leader space\n"); | ||
| 896 | return; | ||
| 897 | } | ||
| 898 | |||
| 899 | address1 = bitrev8(get_bits(data, 8)); | ||
| 900 | address2 = bitrev8(get_bits(data, 8)); | ||
| 901 | command1 = bitrev8(get_bits(data, 8)); | ||
| 902 | command2 = bitrev8(get_bits(data, 8)); | ||
| 903 | |||
| 904 | /* Sanity check */ | ||
| 905 | if (data->irdata_error) { | ||
| 906 | dev_dbg(dev, "NEC - Invalid message\n"); | ||
| 907 | return; | ||
| 908 | } | ||
| 909 | |||
| 910 | /* Check command validity */ | ||
| 911 | if (command1 != ~command2) { | ||
| 912 | dev_dbg(dev, "NEC - Command bytes mismatch\n"); | ||
| 913 | return; | ||
| 914 | } | ||
| 915 | |||
| 916 | /* Check for extended NEC protocol */ | ||
| 917 | address = address1; | ||
| 918 | if (address1 != ~address2) | ||
| 919 | address |= address2 << 8; | ||
| 920 | |||
| 921 | scancode = address << 8 | command1; | ||
| 922 | |||
| 923 | dev_dbg(dev, "IR-NEC ad %u cm %u s %u\n", | ||
| 924 | (unsigned int)address, | ||
| 925 | (unsigned int)command1, | ||
| 926 | (unsigned int)scancode); | ||
| 927 | |||
| 928 | wbcir_keydown(data, scancode, !data->last_toggle); | ||
| 929 | } | ||
| 930 | |||
| 931 | |||
| 932 | |||
| 933 | /***************************************************************************** | ||
| 934 | * | ||
| 935 | * INTERRUPT FUNCTIONS | ||
| 936 | * | ||
| 937 | *****************************************************************************/ | ||
| 938 | |||
| 939 | static irqreturn_t | ||
| 940 | wbcir_irq_handler(int irqno, void *cookie) | ||
| 941 | { | ||
| 942 | struct pnp_dev *device = cookie; | ||
| 943 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
| 944 | struct device *dev = &device->dev; | ||
| 945 | u8 status; | ||
| 946 | unsigned long flags; | ||
| 947 | u8 irdata[8]; | ||
| 948 | int i; | ||
| 949 | unsigned int hw; | ||
| 950 | |||
| 951 | spin_lock_irqsave(&wbcir_lock, flags); | ||
| 952 | |||
| 953 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
| 954 | |||
| 955 | status = inb(data->sbase + WBCIR_REG_SP3_EIR); | ||
| 956 | |||
| 957 | if (!(status & (WBCIR_IRQ_RX | WBCIR_IRQ_ERR))) { | ||
| 958 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
| 959 | return IRQ_NONE; | ||
| 960 | } | ||
| 961 | |||
| 962 | if (status & WBCIR_IRQ_ERR) | ||
| 963 | data->irdata_error = 1; | ||
| 964 | |||
| 965 | if (!(status & WBCIR_IRQ_RX)) | ||
| 966 | goto out; | ||
| 967 | |||
| 968 | /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */ | ||
| 969 | insb(data->sbase + WBCIR_REG_SP3_RXDATA, &irdata[0], 8); | ||
| 970 | |||
| 971 | for (i = 0; i < sizeof(irdata); i++) { | ||
| 972 | hw = hweight8(irdata[i]); | ||
| 973 | if (hw > 4) | ||
| 974 | add_irdata_bit(data, 0); | ||
| 975 | else | ||
| 976 | add_irdata_bit(data, 1); | ||
| 977 | |||
| 978 | if (hw == 8) | ||
| 979 | data->idle_count++; | ||
| 980 | else | ||
| 981 | data->idle_count = 0; | ||
| 982 | } | ||
| 983 | |||
| 984 | if (data->idle_count > WBCIR_MAX_IDLE_BYTES) { | ||
| 985 | /* Set RXINACTIVE... */ | ||
| 986 | outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR); | ||
| 987 | |||
| 988 | /* ...and drain the FIFO */ | ||
| 989 | while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL) | ||
| 990 | inb(data->sbase + WBCIR_REG_SP3_RXDATA); | ||
| 991 | |||
| 992 | dev_dbg(dev, "IRDATA:\n"); | ||
| 993 | for (i = 0; i < data->irdata_count; i += BITS_PER_LONG) | ||
| 994 | dev_dbg(dev, "0x%08lX\n", data->irdata[i/BITS_PER_LONG]); | ||
| 995 | |||
| 996 | switch (protocol) { | ||
| 997 | case IR_PROTOCOL_RC5: | ||
| 998 | wbcir_parse_rc5(dev, data); | ||
| 999 | break; | ||
| 1000 | case IR_PROTOCOL_RC6: | ||
| 1001 | wbcir_parse_rc6(dev, data); | ||
| 1002 | break; | ||
| 1003 | case IR_PROTOCOL_NEC: | ||
| 1004 | wbcir_parse_nec(dev, data); | ||
| 1005 | break; | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | wbcir_reset_irdata(data); | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | out: | ||
| 1012 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
| 1013 | return IRQ_HANDLED; | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | |||
| 1017 | |||
| 1018 | /***************************************************************************** | ||
| 1019 | * | ||
| 1020 | * SETUP/INIT/SUSPEND/RESUME FUNCTIONS | ||
| 1021 | * | ||
| 1022 | *****************************************************************************/ | ||
| 1023 | |||
| 1024 | static void | ||
| 1025 | wbcir_shutdown(struct pnp_dev *device) | ||
| 1026 | { | ||
| 1027 | struct device *dev = &device->dev; | ||
| 1028 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
| 1029 | int do_wake = 1; | ||
| 1030 | u8 match[11]; | ||
| 1031 | u8 mask[11]; | ||
| 1032 | u8 rc6_csl = 0; | ||
| 1033 | int i; | ||
| 1034 | |||
| 1035 | memset(match, 0, sizeof(match)); | ||
| 1036 | memset(mask, 0, sizeof(mask)); | ||
| 1037 | |||
| 1038 | if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) { | ||
| 1039 | do_wake = 0; | ||
| 1040 | goto finish; | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | switch (protocol) { | ||
| 1044 | case IR_PROTOCOL_RC5: | ||
| 1045 | if (wake_sc > 0xFFF) { | ||
| 1046 | do_wake = 0; | ||
| 1047 | dev_err(dev, "RC5 - Invalid wake scancode\n"); | ||
| 1048 | break; | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | /* Mask = 13 bits, ex toggle */ | ||
| 1052 | mask[0] = 0xFF; | ||
| 1053 | mask[1] = 0x17; | ||
| 1054 | |||
| 1055 | match[0] = (wake_sc & 0x003F); /* 6 command bits */ | ||
| 1056 | match[0] |= (wake_sc & 0x0180) >> 1; /* 2 address bits */ | ||
| 1057 | match[1] = (wake_sc & 0x0E00) >> 9; /* 3 address bits */ | ||
| 1058 | if (!(wake_sc & 0x0040)) /* 2nd start bit */ | ||
| 1059 | match[1] |= 0x10; | ||
| 1060 | |||
| 1061 | break; | ||
| 1062 | |||
| 1063 | case IR_PROTOCOL_NEC: | ||
| 1064 | if (wake_sc > 0xFFFFFF) { | ||
| 1065 | do_wake = 0; | ||
| 1066 | dev_err(dev, "NEC - Invalid wake scancode\n"); | ||
| 1067 | break; | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | mask[0] = mask[1] = mask[2] = mask[3] = 0xFF; | ||
| 1071 | |||
| 1072 | match[1] = bitrev8((wake_sc & 0xFF)); | ||
| 1073 | match[0] = ~match[1]; | ||
| 1074 | |||
| 1075 | match[3] = bitrev8((wake_sc & 0xFF00) >> 8); | ||
| 1076 | if (wake_sc > 0xFFFF) | ||
| 1077 | match[2] = bitrev8((wake_sc & 0xFF0000) >> 16); | ||
| 1078 | else | ||
| 1079 | match[2] = ~match[3]; | ||
| 1080 | |||
| 1081 | break; | ||
| 1082 | |||
| 1083 | case IR_PROTOCOL_RC6: | ||
| 1084 | |||
| 1085 | if (wake_rc6mode == 0) { | ||
| 1086 | if (wake_sc > 0xFFFF) { | ||
| 1087 | do_wake = 0; | ||
| 1088 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | ||
| 1089 | break; | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | /* Command */ | ||
| 1093 | match[0] = wbcir_to_rc6cells(wake_sc >> 0); | ||
| 1094 | mask[0] = 0xFF; | ||
| 1095 | match[1] = wbcir_to_rc6cells(wake_sc >> 4); | ||
| 1096 | mask[1] = 0xFF; | ||
| 1097 | |||
| 1098 | /* Address */ | ||
| 1099 | match[2] = wbcir_to_rc6cells(wake_sc >> 8); | ||
| 1100 | mask[2] = 0xFF; | ||
| 1101 | match[3] = wbcir_to_rc6cells(wake_sc >> 12); | ||
| 1102 | mask[3] = 0xFF; | ||
| 1103 | |||
| 1104 | /* Header */ | ||
| 1105 | match[4] = 0x50; /* mode1 = mode0 = 0, ignore toggle */ | ||
| 1106 | mask[4] = 0xF0; | ||
| 1107 | match[5] = 0x09; /* start bit = 1, mode2 = 0 */ | ||
| 1108 | mask[5] = 0x0F; | ||
| 1109 | |||
| 1110 | rc6_csl = 44; | ||
| 1111 | |||
| 1112 | } else if (wake_rc6mode == 6) { | ||
| 1113 | i = 0; | ||
| 1114 | |||
| 1115 | /* Command */ | ||
| 1116 | match[i] = wbcir_to_rc6cells(wake_sc >> 0); | ||
| 1117 | mask[i++] = 0xFF; | ||
| 1118 | match[i] = wbcir_to_rc6cells(wake_sc >> 4); | ||
| 1119 | mask[i++] = 0xFF; | ||
| 1120 | |||
| 1121 | /* Address + Toggle */ | ||
| 1122 | match[i] = wbcir_to_rc6cells(wake_sc >> 8); | ||
| 1123 | mask[i++] = 0xFF; | ||
| 1124 | match[i] = wbcir_to_rc6cells(wake_sc >> 12); | ||
| 1125 | mask[i++] = 0x3F; | ||
| 1126 | |||
| 1127 | /* Customer bits 7 - 0 */ | ||
| 1128 | match[i] = wbcir_to_rc6cells(wake_sc >> 16); | ||
| 1129 | mask[i++] = 0xFF; | ||
| 1130 | match[i] = wbcir_to_rc6cells(wake_sc >> 20); | ||
| 1131 | mask[i++] = 0xFF; | ||
| 1132 | |||
| 1133 | if (wake_sc & 0x80000000) { | ||
| 1134 | /* Customer range bit and bits 15 - 8 */ | ||
| 1135 | match[i] = wbcir_to_rc6cells(wake_sc >> 24); | ||
| 1136 | mask[i++] = 0xFF; | ||
| 1137 | match[i] = wbcir_to_rc6cells(wake_sc >> 28); | ||
| 1138 | mask[i++] = 0xFF; | ||
| 1139 | rc6_csl = 76; | ||
| 1140 | } else if (wake_sc <= 0x007FFFFF) { | ||
| 1141 | rc6_csl = 60; | ||
| 1142 | } else { | ||
| 1143 | do_wake = 0; | ||
| 1144 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | ||
| 1145 | break; | ||
| 1146 | } | ||
| 1147 | |||
| 1148 | /* Header */ | ||
| 1149 | match[i] = 0x93; /* mode1 = mode0 = 1, submode = 0 */ | ||
| 1150 | mask[i++] = 0xFF; | ||
| 1151 | match[i] = 0x0A; /* start bit = 1, mode2 = 1 */ | ||
| 1152 | mask[i++] = 0x0F; | ||
| 1153 | |||
| 1154 | } else { | ||
| 1155 | do_wake = 0; | ||
| 1156 | dev_err(dev, "RC6 - Invalid wake mode\n"); | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | break; | ||
| 1160 | |||
| 1161 | default: | ||
| 1162 | do_wake = 0; | ||
| 1163 | break; | ||
| 1164 | } | ||
| 1165 | |||
| 1166 | finish: | ||
| 1167 | if (do_wake) { | ||
| 1168 | /* Set compare and compare mask */ | ||
| 1169 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX, | ||
| 1170 | WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0, | ||
| 1171 | 0x3F); | ||
| 1172 | outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11); | ||
| 1173 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX, | ||
| 1174 | WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0, | ||
| 1175 | 0x3F); | ||
| 1176 | outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11); | ||
| 1177 | |||
| 1178 | /* RC6 Compare String Len */ | ||
| 1179 | outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL); | ||
| 1180 | |||
| 1181 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
| 1182 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
| 1183 | |||
| 1184 | /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ | ||
| 1185 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07); | ||
| 1186 | |||
| 1187 | /* Set CEIR_EN */ | ||
| 1188 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01); | ||
| 1189 | |||
| 1190 | } else { | ||
| 1191 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
| 1192 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
| 1193 | |||
| 1194 | /* Clear CEIR_EN */ | ||
| 1195 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | /* Disable interrupts */ | ||
| 1199 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
| 1200 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
| 1201 | |||
| 1202 | /* | ||
| 1203 | * ACPI will set the HW disable bit for SP3 which means that the | ||
| 1204 | * output signals are left in an undefined state which may cause | ||
| 1205 | * spurious interrupts which we need to ignore until the hardware | ||
| 1206 | * is reinitialized. | ||
| 1207 | */ | ||
| 1208 | disable_irq(data->irq); | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | static int | ||
| 1212 | wbcir_suspend(struct pnp_dev *device, pm_message_t state) | ||
| 1213 | { | ||
| 1214 | wbcir_shutdown(device); | ||
| 1215 | return 0; | ||
| 1216 | } | ||
| 1217 | |||
| 1218 | static void | ||
| 1219 | wbcir_init_hw(struct wbcir_data *data) | ||
| 1220 | { | ||
| 1221 | u8 tmp; | ||
| 1222 | |||
| 1223 | /* Disable interrupts */ | ||
| 1224 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
| 1225 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
| 1226 | |||
| 1227 | /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */ | ||
| 1228 | tmp = protocol << 4; | ||
| 1229 | if (invert) | ||
| 1230 | tmp |= 0x08; | ||
| 1231 | outb(tmp, data->wbase + WBCIR_REG_WCEIR_CTL); | ||
| 1232 | |||
| 1233 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
| 1234 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
| 1235 | |||
| 1236 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
| 1237 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
| 1238 | |||
| 1239 | /* Set RC5 cell time to correspond to 36 kHz */ | ||
| 1240 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CFG1, 0x4A, 0x7F); | ||
| 1241 | |||
| 1242 | /* Set IRTX_INV */ | ||
| 1243 | if (invert) | ||
| 1244 | outb(0x04, data->ebase + WBCIR_REG_ECEIR_CCTL); | ||
| 1245 | else | ||
| 1246 | outb(0x00, data->ebase + WBCIR_REG_ECEIR_CCTL); | ||
| 1247 | |||
| 1248 | /* | ||
| 1249 | * Clear IR LED, set SP3 clock to 24Mhz | ||
| 1250 | * set SP3_IRRX_SW to binary 01, helpfully not documented | ||
| 1251 | */ | ||
| 1252 | outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS); | ||
| 1253 | |||
| 1254 | /* Enable extended mode */ | ||
| 1255 | wbcir_select_bank(data, WBCIR_BANK_2); | ||
| 1256 | outb(WBCIR_EXT_ENABLE, data->sbase + WBCIR_REG_SP3_EXCR1); | ||
| 1257 | |||
| 1258 | /* | ||
| 1259 | * Configure baud generator, IR data will be sampled at | ||
| 1260 | * a bitrate of: (24Mhz * prescaler) / (divisor * 16). | ||
| 1261 | * | ||
| 1262 | * The ECIR registers include a flag to change the | ||
| 1263 | * 24Mhz clock freq to 48Mhz. | ||
| 1264 | * | ||
| 1265 | * It's not documented in the specs, but fifo levels | ||
| 1266 | * other than 16 seems to be unsupported. | ||
| 1267 | */ | ||
| 1268 | |||
| 1269 | /* prescaler 1.0, tx/rx fifo lvl 16 */ | ||
| 1270 | outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2); | ||
| 1271 | |||
| 1272 | /* Set baud divisor to generate one byte per bit/cell */ | ||
| 1273 | switch (protocol) { | ||
| 1274 | case IR_PROTOCOL_RC5: | ||
| 1275 | outb(0xA7, data->sbase + WBCIR_REG_SP3_BGDL); | ||
| 1276 | break; | ||
| 1277 | case IR_PROTOCOL_RC6: | ||
| 1278 | outb(0x53, data->sbase + WBCIR_REG_SP3_BGDL); | ||
| 1279 | break; | ||
| 1280 | case IR_PROTOCOL_NEC: | ||
| 1281 | outb(0x69, data->sbase + WBCIR_REG_SP3_BGDL); | ||
| 1282 | break; | ||
| 1283 | } | ||
| 1284 | outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH); | ||
| 1285 | |||
| 1286 | /* Set CEIR mode */ | ||
| 1287 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
| 1288 | outb(0xC0, data->sbase + WBCIR_REG_SP3_MCR); | ||
| 1289 | inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */ | ||
| 1290 | inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */ | ||
| 1291 | |||
| 1292 | /* Disable RX demod, run-length encoding/decoding, set freq span */ | ||
| 1293 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
| 1294 | outb(0x10, data->sbase + WBCIR_REG_SP3_RCCFG); | ||
| 1295 | |||
| 1296 | /* Disable timer */ | ||
| 1297 | wbcir_select_bank(data, WBCIR_BANK_4); | ||
| 1298 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1); | ||
| 1299 | |||
| 1300 | /* Enable MSR interrupt, Clear AUX_IRX */ | ||
| 1301 | wbcir_select_bank(data, WBCIR_BANK_5); | ||
| 1302 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR2); | ||
| 1303 | |||
| 1304 | /* Disable CRC */ | ||
| 1305 | wbcir_select_bank(data, WBCIR_BANK_6); | ||
| 1306 | outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3); | ||
| 1307 | |||
| 1308 | /* Set RX/TX (de)modulation freq, not really used */ | ||
| 1309 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
| 1310 | outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC); | ||
| 1311 | outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC); | ||
| 1312 | |||
| 1313 | /* Set invert and pin direction */ | ||
| 1314 | if (invert) | ||
| 1315 | outb(0x10, data->sbase + WBCIR_REG_SP3_IRCFG4); | ||
| 1316 | else | ||
| 1317 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCFG4); | ||
| 1318 | |||
| 1319 | /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */ | ||
| 1320 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
| 1321 | outb(0x97, data->sbase + WBCIR_REG_SP3_FCR); | ||
| 1322 | |||
| 1323 | /* Clear AUX status bits */ | ||
| 1324 | outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR); | ||
| 1325 | |||
| 1326 | /* Enable interrupts */ | ||
| 1327 | wbcir_reset_irdata(data); | ||
| 1328 | outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER); | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | static int | ||
| 1332 | wbcir_resume(struct pnp_dev *device) | ||
| 1333 | { | ||
| 1334 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
| 1335 | |||
| 1336 | wbcir_init_hw(data); | ||
| 1337 | enable_irq(data->irq); | ||
| 1338 | |||
| 1339 | return 0; | ||
| 1340 | } | ||
| 1341 | |||
| 1342 | static int __devinit | ||
| 1343 | wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id) | ||
| 1344 | { | ||
| 1345 | struct device *dev = &device->dev; | ||
| 1346 | struct wbcir_data *data; | ||
| 1347 | int err; | ||
| 1348 | |||
| 1349 | if (!(pnp_port_len(device, 0) == EHFUNC_IOMEM_LEN && | ||
| 1350 | pnp_port_len(device, 1) == WAKEUP_IOMEM_LEN && | ||
| 1351 | pnp_port_len(device, 2) == SP_IOMEM_LEN)) { | ||
| 1352 | dev_err(dev, "Invalid resources\n"); | ||
| 1353 | return -ENODEV; | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
| 1357 | if (!data) { | ||
| 1358 | err = -ENOMEM; | ||
| 1359 | goto exit; | ||
| 1360 | } | ||
| 1361 | |||
| 1362 | pnp_set_drvdata(device, data); | ||
| 1363 | |||
| 1364 | data->ebase = pnp_port_start(device, 0); | ||
| 1365 | data->wbase = pnp_port_start(device, 1); | ||
| 1366 | data->sbase = pnp_port_start(device, 2); | ||
| 1367 | data->irq = pnp_irq(device, 0); | ||
| 1368 | |||
| 1369 | if (data->wbase == 0 || data->ebase == 0 || | ||
| 1370 | data->sbase == 0 || data->irq == 0) { | ||
| 1371 | err = -ENODEV; | ||
| 1372 | dev_err(dev, "Invalid resources\n"); | ||
| 1373 | goto exit_free_data; | ||
| 1374 | } | ||
| 1375 | |||
| 1376 | dev_dbg(&device->dev, "Found device " | ||
| 1377 | "(w: 0x%lX, e: 0x%lX, s: 0x%lX, i: %u)\n", | ||
| 1378 | data->wbase, data->ebase, data->sbase, data->irq); | ||
| 1379 | |||
| 1380 | if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) { | ||
| 1381 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
| 1382 | data->wbase, data->wbase + WAKEUP_IOMEM_LEN - 1); | ||
| 1383 | err = -EBUSY; | ||
| 1384 | goto exit_free_data; | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | if (!request_region(data->ebase, EHFUNC_IOMEM_LEN, DRVNAME)) { | ||
| 1388 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
| 1389 | data->ebase, data->ebase + EHFUNC_IOMEM_LEN - 1); | ||
| 1390 | err = -EBUSY; | ||
| 1391 | goto exit_release_wbase; | ||
| 1392 | } | ||
| 1393 | |||
| 1394 | if (!request_region(data->sbase, SP_IOMEM_LEN, DRVNAME)) { | ||
| 1395 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
| 1396 | data->sbase, data->sbase + SP_IOMEM_LEN - 1); | ||
| 1397 | err = -EBUSY; | ||
| 1398 | goto exit_release_ebase; | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | err = request_irq(data->irq, wbcir_irq_handler, | ||
| 1402 | IRQF_DISABLED, DRVNAME, device); | ||
| 1403 | if (err) { | ||
| 1404 | dev_err(dev, "Failed to claim IRQ %u\n", data->irq); | ||
| 1405 | err = -EBUSY; | ||
| 1406 | goto exit_release_sbase; | ||
| 1407 | } | ||
| 1408 | |||
| 1409 | led_trigger_register_simple("cir-tx", &data->txtrigger); | ||
| 1410 | if (!data->txtrigger) { | ||
| 1411 | err = -ENOMEM; | ||
| 1412 | goto exit_free_irq; | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | led_trigger_register_simple("cir-rx", &data->rxtrigger); | ||
| 1416 | if (!data->rxtrigger) { | ||
| 1417 | err = -ENOMEM; | ||
| 1418 | goto exit_unregister_txtrigger; | ||
| 1419 | } | ||
| 1420 | |||
| 1421 | data->led.name = "cir::activity"; | ||
| 1422 | data->led.default_trigger = "cir-rx"; | ||
| 1423 | data->led.brightness_set = wbcir_led_brightness_set; | ||
| 1424 | data->led.brightness_get = wbcir_led_brightness_get; | ||
| 1425 | err = led_classdev_register(&device->dev, &data->led); | ||
| 1426 | if (err) | ||
| 1427 | goto exit_unregister_rxtrigger; | ||
| 1428 | |||
| 1429 | data->input_dev = input_allocate_device(); | ||
| 1430 | if (!data->input_dev) { | ||
| 1431 | err = -ENOMEM; | ||
| 1432 | goto exit_unregister_led; | ||
| 1433 | } | ||
| 1434 | |||
| 1435 | data->input_dev->evbit[0] = BIT(EV_KEY); | ||
| 1436 | data->input_dev->name = WBCIR_NAME; | ||
| 1437 | data->input_dev->phys = "wbcir/cir0"; | ||
| 1438 | data->input_dev->id.bustype = BUS_HOST; | ||
| 1439 | data->input_dev->id.vendor = PCI_VENDOR_ID_WINBOND; | ||
| 1440 | data->input_dev->id.product = WBCIR_ID_FAMILY; | ||
| 1441 | data->input_dev->id.version = WBCIR_ID_CHIP; | ||
| 1442 | data->input_dev->getkeycode = wbcir_getkeycode; | ||
| 1443 | data->input_dev->setkeycode = wbcir_setkeycode; | ||
| 1444 | input_set_capability(data->input_dev, EV_MSC, MSC_SCAN); | ||
| 1445 | input_set_drvdata(data->input_dev, data); | ||
| 1446 | |||
| 1447 | err = input_register_device(data->input_dev); | ||
| 1448 | if (err) | ||
| 1449 | goto exit_free_input; | ||
| 1450 | |||
| 1451 | data->last_scancode = INVALID_SCANCODE; | ||
| 1452 | INIT_LIST_HEAD(&data->keytable); | ||
| 1453 | setup_timer(&data->timer_keyup, wbcir_keyup, (unsigned long)data); | ||
| 1454 | |||
| 1455 | /* Load default keymaps */ | ||
| 1456 | if (protocol == IR_PROTOCOL_RC6) { | ||
| 1457 | int i; | ||
| 1458 | for (i = 0; i < ARRAY_SIZE(rc6_def_keymap); i++) { | ||
| 1459 | err = wbcir_setkeycode(data->input_dev, | ||
| 1460 | (int)rc6_def_keymap[i].scancode, | ||
| 1461 | (int)rc6_def_keymap[i].keycode); | ||
| 1462 | if (err) | ||
| 1463 | goto exit_unregister_keys; | ||
| 1464 | } | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | device_init_wakeup(&device->dev, 1); | ||
| 1468 | |||
| 1469 | wbcir_init_hw(data); | ||
| 1470 | |||
| 1471 | return 0; | ||
| 1472 | |||
| 1473 | exit_unregister_keys: | ||
| 1474 | if (!list_empty(&data->keytable)) { | ||
| 1475 | struct wbcir_keyentry *key; | ||
| 1476 | struct wbcir_keyentry *keytmp; | ||
| 1477 | |||
| 1478 | list_for_each_entry_safe(key, keytmp, &data->keytable, list) { | ||
| 1479 | list_del(&key->list); | ||
| 1480 | kfree(key); | ||
| 1481 | } | ||
| 1482 | } | ||
| 1483 | input_unregister_device(data->input_dev); | ||
| 1484 | /* Can't call input_free_device on an unregistered device */ | ||
| 1485 | data->input_dev = NULL; | ||
| 1486 | exit_free_input: | ||
| 1487 | input_free_device(data->input_dev); | ||
| 1488 | exit_unregister_led: | ||
| 1489 | led_classdev_unregister(&data->led); | ||
| 1490 | exit_unregister_rxtrigger: | ||
| 1491 | led_trigger_unregister_simple(data->rxtrigger); | ||
| 1492 | exit_unregister_txtrigger: | ||
| 1493 | led_trigger_unregister_simple(data->txtrigger); | ||
| 1494 | exit_free_irq: | ||
| 1495 | free_irq(data->irq, device); | ||
| 1496 | exit_release_sbase: | ||
| 1497 | release_region(data->sbase, SP_IOMEM_LEN); | ||
| 1498 | exit_release_ebase: | ||
| 1499 | release_region(data->ebase, EHFUNC_IOMEM_LEN); | ||
| 1500 | exit_release_wbase: | ||
| 1501 | release_region(data->wbase, WAKEUP_IOMEM_LEN); | ||
| 1502 | exit_free_data: | ||
| 1503 | kfree(data); | ||
| 1504 | pnp_set_drvdata(device, NULL); | ||
| 1505 | exit: | ||
| 1506 | return err; | ||
| 1507 | } | ||
| 1508 | |||
| 1509 | static void __devexit | ||
| 1510 | wbcir_remove(struct pnp_dev *device) | ||
| 1511 | { | ||
| 1512 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
| 1513 | struct wbcir_keyentry *key; | ||
| 1514 | struct wbcir_keyentry *keytmp; | ||
| 1515 | |||
| 1516 | /* Disable interrupts */ | ||
| 1517 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
| 1518 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
| 1519 | |||
| 1520 | del_timer_sync(&data->timer_keyup); | ||
| 1521 | |||
| 1522 | free_irq(data->irq, device); | ||
| 1523 | |||
| 1524 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
| 1525 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
| 1526 | |||
| 1527 | /* Clear CEIR_EN */ | ||
| 1528 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
| 1529 | |||
| 1530 | /* Clear BUFF_EN, END_EN, MATCH_EN */ | ||
| 1531 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
| 1532 | |||
| 1533 | /* This will generate a keyup event if necessary */ | ||
| 1534 | input_unregister_device(data->input_dev); | ||
| 1535 | |||
| 1536 | led_trigger_unregister_simple(data->rxtrigger); | ||
| 1537 | led_trigger_unregister_simple(data->txtrigger); | ||
| 1538 | led_classdev_unregister(&data->led); | ||
| 1539 | |||
| 1540 | /* This is ok since &data->led isn't actually used */ | ||
| 1541 | wbcir_led_brightness_set(&data->led, LED_OFF); | ||
| 1542 | |||
| 1543 | release_region(data->wbase, WAKEUP_IOMEM_LEN); | ||
| 1544 | release_region(data->ebase, EHFUNC_IOMEM_LEN); | ||
| 1545 | release_region(data->sbase, SP_IOMEM_LEN); | ||
| 1546 | |||
| 1547 | list_for_each_entry_safe(key, keytmp, &data->keytable, list) { | ||
| 1548 | list_del(&key->list); | ||
| 1549 | kfree(key); | ||
| 1550 | } | ||
| 1551 | |||
| 1552 | kfree(data); | ||
| 1553 | |||
| 1554 | pnp_set_drvdata(device, NULL); | ||
| 1555 | } | ||
| 1556 | |||
| 1557 | static const struct pnp_device_id wbcir_ids[] = { | ||
| 1558 | { "WEC1022", 0 }, | ||
| 1559 | { "", 0 } | ||
| 1560 | }; | ||
| 1561 | MODULE_DEVICE_TABLE(pnp, wbcir_ids); | ||
| 1562 | |||
| 1563 | static struct pnp_driver wbcir_driver = { | ||
| 1564 | .name = WBCIR_NAME, | ||
| 1565 | .id_table = wbcir_ids, | ||
| 1566 | .probe = wbcir_probe, | ||
| 1567 | .remove = __devexit_p(wbcir_remove), | ||
| 1568 | .suspend = wbcir_suspend, | ||
| 1569 | .resume = wbcir_resume, | ||
| 1570 | .shutdown = wbcir_shutdown | ||
| 1571 | }; | ||
| 1572 | |||
| 1573 | static int __init | ||
| 1574 | wbcir_init(void) | ||
| 1575 | { | ||
| 1576 | int ret; | ||
| 1577 | |||
| 1578 | switch (protocol) { | ||
| 1579 | case IR_PROTOCOL_RC5: | ||
| 1580 | case IR_PROTOCOL_NEC: | ||
| 1581 | case IR_PROTOCOL_RC6: | ||
| 1582 | break; | ||
| 1583 | default: | ||
| 1584 | printk(KERN_ERR DRVNAME ": Invalid protocol argument\n"); | ||
| 1585 | return -EINVAL; | ||
| 1586 | } | ||
| 1587 | |||
| 1588 | ret = pnp_register_driver(&wbcir_driver); | ||
| 1589 | if (ret) | ||
| 1590 | printk(KERN_ERR DRVNAME ": Unable to register driver\n"); | ||
| 1591 | |||
| 1592 | return ret; | ||
| 1593 | } | ||
| 1594 | |||
| 1595 | static void __exit | ||
| 1596 | wbcir_exit(void) | ||
| 1597 | { | ||
| 1598 | pnp_unregister_driver(&wbcir_driver); | ||
| 1599 | } | ||
| 1600 | |||
| 1601 | MODULE_AUTHOR("David Härdeman <david@hardeman.nu>"); | ||
| 1602 | MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver"); | ||
| 1603 | MODULE_LICENSE("GPL"); | ||
| 1604 | |||
| 1605 | module_init(wbcir_init); | ||
| 1606 | module_exit(wbcir_exit); | ||
| 1607 | |||
| 1608 | |||
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c index 7f85a862ad11..7077f9bf5ead 100644 --- a/drivers/input/xen-kbdfront.c +++ b/drivers/input/misc/xen-kbdfront.c | |||
| @@ -11,12 +11,6 @@ | |||
| 11 | * more details. | 11 | * more details. |
| 12 | */ | 12 | */ |
| 13 | 13 | ||
| 14 | /* | ||
| 15 | * TODO: | ||
| 16 | * | ||
| 17 | * Switch to grant tables together with xen-fbfront.c. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | 15 | ||
| 22 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
| @@ -30,6 +24,8 @@ | |||
| 30 | #include <xen/xen.h> | 24 | #include <xen/xen.h> |
| 31 | #include <xen/events.h> | 25 | #include <xen/events.h> |
| 32 | #include <xen/page.h> | 26 | #include <xen/page.h> |
| 27 | #include <xen/grant_table.h> | ||
| 28 | #include <xen/interface/grant_table.h> | ||
| 33 | #include <xen/interface/io/fbif.h> | 29 | #include <xen/interface/io/fbif.h> |
| 34 | #include <xen/interface/io/kbdif.h> | 30 | #include <xen/interface/io/kbdif.h> |
| 35 | #include <xen/xenbus.h> | 31 | #include <xen/xenbus.h> |
| @@ -38,6 +34,7 @@ struct xenkbd_info { | |||
| 38 | struct input_dev *kbd; | 34 | struct input_dev *kbd; |
| 39 | struct input_dev *ptr; | 35 | struct input_dev *ptr; |
| 40 | struct xenkbd_page *page; | 36 | struct xenkbd_page *page; |
| 37 | int gref; | ||
| 41 | int irq; | 38 | int irq; |
| 42 | struct xenbus_device *xbdev; | 39 | struct xenbus_device *xbdev; |
| 43 | char phys[32]; | 40 | char phys[32]; |
| @@ -110,7 +107,7 @@ static irqreturn_t input_handler(int rq, void *dev_id) | |||
| 110 | static int __devinit xenkbd_probe(struct xenbus_device *dev, | 107 | static int __devinit xenkbd_probe(struct xenbus_device *dev, |
| 111 | const struct xenbus_device_id *id) | 108 | const struct xenbus_device_id *id) |
| 112 | { | 109 | { |
| 113 | int ret, i; | 110 | int ret, i, abs; |
| 114 | struct xenkbd_info *info; | 111 | struct xenkbd_info *info; |
| 115 | struct input_dev *kbd, *ptr; | 112 | struct input_dev *kbd, *ptr; |
| 116 | 113 | ||
| @@ -122,12 +119,18 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev, | |||
| 122 | dev_set_drvdata(&dev->dev, info); | 119 | dev_set_drvdata(&dev->dev, info); |
| 123 | info->xbdev = dev; | 120 | info->xbdev = dev; |
| 124 | info->irq = -1; | 121 | info->irq = -1; |
| 122 | info->gref = -1; | ||
| 125 | snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename); | 123 | snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename); |
| 126 | 124 | ||
| 127 | info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); | 125 | info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); |
| 128 | if (!info->page) | 126 | if (!info->page) |
| 129 | goto error_nomem; | 127 | goto error_nomem; |
| 130 | 128 | ||
| 129 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0) | ||
| 130 | abs = 0; | ||
| 131 | if (abs) | ||
| 132 | xenbus_printf(XBT_NIL, dev->nodename, "request-abs-pointer", "1"); | ||
| 133 | |||
| 131 | /* keyboard */ | 134 | /* keyboard */ |
| 132 | kbd = input_allocate_device(); | 135 | kbd = input_allocate_device(); |
| 133 | if (!kbd) | 136 | if (!kbd) |
| @@ -137,11 +140,12 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev, | |||
| 137 | kbd->id.bustype = BUS_PCI; | 140 | kbd->id.bustype = BUS_PCI; |
| 138 | kbd->id.vendor = 0x5853; | 141 | kbd->id.vendor = 0x5853; |
| 139 | kbd->id.product = 0xffff; | 142 | kbd->id.product = 0xffff; |
| 140 | kbd->evbit[0] = BIT(EV_KEY); | 143 | |
| 144 | __set_bit(EV_KEY, kbd->evbit); | ||
| 141 | for (i = KEY_ESC; i < KEY_UNKNOWN; i++) | 145 | for (i = KEY_ESC; i < KEY_UNKNOWN; i++) |
| 142 | set_bit(i, kbd->keybit); | 146 | __set_bit(i, kbd->keybit); |
| 143 | for (i = KEY_OK; i < KEY_MAX; i++) | 147 | for (i = KEY_OK; i < KEY_MAX; i++) |
| 144 | set_bit(i, kbd->keybit); | 148 | __set_bit(i, kbd->keybit); |
| 145 | 149 | ||
| 146 | ret = input_register_device(kbd); | 150 | ret = input_register_device(kbd); |
| 147 | if (ret) { | 151 | if (ret) { |
| @@ -160,12 +164,20 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev, | |||
| 160 | ptr->id.bustype = BUS_PCI; | 164 | ptr->id.bustype = BUS_PCI; |
| 161 | ptr->id.vendor = 0x5853; | 165 | ptr->id.vendor = 0x5853; |
| 162 | ptr->id.product = 0xfffe; | 166 | ptr->id.product = 0xfffe; |
| 163 | ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS); | 167 | |
| 168 | if (abs) { | ||
| 169 | __set_bit(EV_ABS, ptr->evbit); | ||
| 170 | input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0); | ||
| 171 | input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0); | ||
| 172 | } else { | ||
| 173 | input_set_capability(ptr, EV_REL, REL_X); | ||
| 174 | input_set_capability(ptr, EV_REL, REL_Y); | ||
| 175 | } | ||
| 176 | input_set_capability(ptr, EV_REL, REL_WHEEL); | ||
| 177 | |||
| 178 | __set_bit(EV_KEY, ptr->evbit); | ||
| 164 | for (i = BTN_LEFT; i <= BTN_TASK; i++) | 179 | for (i = BTN_LEFT; i <= BTN_TASK; i++) |
| 165 | set_bit(i, ptr->keybit); | 180 | __set_bit(i, ptr->keybit); |
| 166 | ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL); | ||
| 167 | input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0); | ||
| 168 | input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0); | ||
| 169 | 181 | ||
| 170 | ret = input_register_device(ptr); | 182 | ret = input_register_device(ptr); |
| 171 | if (ret) { | 183 | if (ret) { |
| @@ -218,15 +230,20 @@ static int xenkbd_connect_backend(struct xenbus_device *dev, | |||
| 218 | int ret, evtchn; | 230 | int ret, evtchn; |
| 219 | struct xenbus_transaction xbt; | 231 | struct xenbus_transaction xbt; |
| 220 | 232 | ||
| 233 | ret = gnttab_grant_foreign_access(dev->otherend_id, | ||
| 234 | virt_to_mfn(info->page), 0); | ||
| 235 | if (ret < 0) | ||
| 236 | return ret; | ||
| 237 | info->gref = ret; | ||
| 238 | |||
| 221 | ret = xenbus_alloc_evtchn(dev, &evtchn); | 239 | ret = xenbus_alloc_evtchn(dev, &evtchn); |
| 222 | if (ret) | 240 | if (ret) |
| 223 | return ret; | 241 | goto error_grant; |
| 224 | ret = bind_evtchn_to_irqhandler(evtchn, input_handler, | 242 | ret = bind_evtchn_to_irqhandler(evtchn, input_handler, |
| 225 | 0, dev->devicetype, info); | 243 | 0, dev->devicetype, info); |
| 226 | if (ret < 0) { | 244 | if (ret < 0) { |
| 227 | xenbus_free_evtchn(dev, evtchn); | ||
| 228 | xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); | 245 | xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); |
| 229 | return ret; | 246 | goto error_evtchan; |
| 230 | } | 247 | } |
| 231 | info->irq = ret; | 248 | info->irq = ret; |
| 232 | 249 | ||
| @@ -234,12 +251,15 @@ static int xenkbd_connect_backend(struct xenbus_device *dev, | |||
| 234 | ret = xenbus_transaction_start(&xbt); | 251 | ret = xenbus_transaction_start(&xbt); |
| 235 | if (ret) { | 252 | if (ret) { |
| 236 | xenbus_dev_fatal(dev, ret, "starting transaction"); | 253 | xenbus_dev_fatal(dev, ret, "starting transaction"); |
| 237 | return ret; | 254 | goto error_irqh; |
| 238 | } | 255 | } |
| 239 | ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", | 256 | ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", |
| 240 | virt_to_mfn(info->page)); | 257 | virt_to_mfn(info->page)); |
| 241 | if (ret) | 258 | if (ret) |
| 242 | goto error_xenbus; | 259 | goto error_xenbus; |
| 260 | ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref); | ||
| 261 | if (ret) | ||
| 262 | goto error_xenbus; | ||
| 243 | ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", | 263 | ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", |
| 244 | evtchn); | 264 | evtchn); |
| 245 | if (ret) | 265 | if (ret) |
| @@ -249,7 +269,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev, | |||
| 249 | if (ret == -EAGAIN) | 269 | if (ret == -EAGAIN) |
| 250 | goto again; | 270 | goto again; |
| 251 | xenbus_dev_fatal(dev, ret, "completing transaction"); | 271 | xenbus_dev_fatal(dev, ret, "completing transaction"); |
| 252 | return ret; | 272 | goto error_irqh; |
| 253 | } | 273 | } |
| 254 | 274 | ||
| 255 | xenbus_switch_state(dev, XenbusStateInitialised); | 275 | xenbus_switch_state(dev, XenbusStateInitialised); |
| @@ -258,6 +278,14 @@ static int xenkbd_connect_backend(struct xenbus_device *dev, | |||
| 258 | error_xenbus: | 278 | error_xenbus: |
| 259 | xenbus_transaction_end(xbt, 1); | 279 | xenbus_transaction_end(xbt, 1); |
| 260 | xenbus_dev_fatal(dev, ret, "writing xenstore"); | 280 | xenbus_dev_fatal(dev, ret, "writing xenstore"); |
| 281 | error_irqh: | ||
| 282 | unbind_from_irqhandler(info->irq, info); | ||
| 283 | info->irq = -1; | ||
| 284 | error_evtchan: | ||
| 285 | xenbus_free_evtchn(dev, evtchn); | ||
| 286 | error_grant: | ||
| 287 | gnttab_end_foreign_access_ref(info->gref, 0); | ||
| 288 | info->gref = -1; | ||
| 261 | return ret; | 289 | return ret; |
| 262 | } | 290 | } |
| 263 | 291 | ||
| @@ -266,13 +294,16 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *info) | |||
| 266 | if (info->irq >= 0) | 294 | if (info->irq >= 0) |
| 267 | unbind_from_irqhandler(info->irq, info); | 295 | unbind_from_irqhandler(info->irq, info); |
| 268 | info->irq = -1; | 296 | info->irq = -1; |
| 297 | if (info->gref >= 0) | ||
| 298 | gnttab_end_foreign_access_ref(info->gref, 0); | ||
| 299 | info->gref = -1; | ||
| 269 | } | 300 | } |
| 270 | 301 | ||
| 271 | static void xenkbd_backend_changed(struct xenbus_device *dev, | 302 | static void xenkbd_backend_changed(struct xenbus_device *dev, |
| 272 | enum xenbus_state backend_state) | 303 | enum xenbus_state backend_state) |
| 273 | { | 304 | { |
| 274 | struct xenkbd_info *info = dev_get_drvdata(&dev->dev); | 305 | struct xenkbd_info *info = dev_get_drvdata(&dev->dev); |
| 275 | int ret, val; | 306 | int val; |
| 276 | 307 | ||
| 277 | switch (backend_state) { | 308 | switch (backend_state) { |
| 278 | case XenbusStateInitialising: | 309 | case XenbusStateInitialising: |
| @@ -285,16 +316,6 @@ static void xenkbd_backend_changed(struct xenbus_device *dev, | |||
| 285 | 316 | ||
| 286 | case XenbusStateInitWait: | 317 | case XenbusStateInitWait: |
| 287 | InitWait: | 318 | InitWait: |
| 288 | ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | ||
| 289 | "feature-abs-pointer", "%d", &val); | ||
| 290 | if (ret < 0) | ||
| 291 | val = 0; | ||
| 292 | if (val) { | ||
| 293 | ret = xenbus_printf(XBT_NIL, info->xbdev->nodename, | ||
| 294 | "request-abs-pointer", "1"); | ||
| 295 | if (ret) | ||
| 296 | pr_warning("can't request abs-pointer\n"); | ||
| 297 | } | ||
| 298 | xenbus_switch_state(dev, XenbusStateConnected); | 319 | xenbus_switch_state(dev, XenbusStateConnected); |
| 299 | break; | 320 | break; |
| 300 | 321 | ||
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig index bf5fd7f6a313..9c1e6ee83531 100644 --- a/drivers/input/mouse/Kconfig +++ b/drivers/input/mouse/Kconfig | |||
| @@ -39,7 +39,7 @@ config MOUSE_PS2 | |||
| 39 | module will be called psmouse. | 39 | module will be called psmouse. |
| 40 | 40 | ||
| 41 | config MOUSE_PS2_ALPS | 41 | config MOUSE_PS2_ALPS |
| 42 | bool "ALPS PS/2 mouse protocol extension" if EMBEDDED | 42 | bool "ALPS PS/2 mouse protocol extension" if EXPERT |
| 43 | default y | 43 | default y |
| 44 | depends on MOUSE_PS2 | 44 | depends on MOUSE_PS2 |
| 45 | help | 45 | help |
| @@ -49,7 +49,7 @@ config MOUSE_PS2_ALPS | |||
| 49 | If unsure, say Y. | 49 | If unsure, say Y. |
| 50 | 50 | ||
| 51 | config MOUSE_PS2_LOGIPS2PP | 51 | config MOUSE_PS2_LOGIPS2PP |
| 52 | bool "Logitech PS/2++ mouse protocol extension" if EMBEDDED | 52 | bool "Logitech PS/2++ mouse protocol extension" if EXPERT |
| 53 | default y | 53 | default y |
| 54 | depends on MOUSE_PS2 | 54 | depends on MOUSE_PS2 |
| 55 | help | 55 | help |
| @@ -59,7 +59,7 @@ config MOUSE_PS2_LOGIPS2PP | |||
| 59 | If unsure, say Y. | 59 | If unsure, say Y. |
| 60 | 60 | ||
| 61 | config MOUSE_PS2_SYNAPTICS | 61 | config MOUSE_PS2_SYNAPTICS |
| 62 | bool "Synaptics PS/2 mouse protocol extension" if EMBEDDED | 62 | bool "Synaptics PS/2 mouse protocol extension" if EXPERT |
| 63 | default y | 63 | default y |
| 64 | depends on MOUSE_PS2 | 64 | depends on MOUSE_PS2 |
| 65 | help | 65 | help |
| @@ -69,7 +69,7 @@ config MOUSE_PS2_SYNAPTICS | |||
| 69 | If unsure, say Y. | 69 | If unsure, say Y. |
| 70 | 70 | ||
| 71 | config MOUSE_PS2_LIFEBOOK | 71 | config MOUSE_PS2_LIFEBOOK |
| 72 | bool "Fujitsu Lifebook PS/2 mouse protocol extension" if EMBEDDED | 72 | bool "Fujitsu Lifebook PS/2 mouse protocol extension" if EXPERT |
| 73 | default y | 73 | default y |
| 74 | depends on MOUSE_PS2 && X86 && DMI | 74 | depends on MOUSE_PS2 && X86 && DMI |
| 75 | help | 75 | help |
| @@ -79,7 +79,7 @@ config MOUSE_PS2_LIFEBOOK | |||
| 79 | If unsure, say Y. | 79 | If unsure, say Y. |
| 80 | 80 | ||
| 81 | config MOUSE_PS2_TRACKPOINT | 81 | config MOUSE_PS2_TRACKPOINT |
| 82 | bool "IBM Trackpoint PS/2 mouse protocol extension" if EMBEDDED | 82 | bool "IBM Trackpoint PS/2 mouse protocol extension" if EXPERT |
| 83 | default y | 83 | default y |
| 84 | depends on MOUSE_PS2 | 84 | depends on MOUSE_PS2 |
| 85 | help | 85 | help |
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c index d24837210f04..3aead91bacc8 100644 --- a/drivers/input/mouse/bcm5974.c +++ b/drivers/input/mouse/bcm5974.c | |||
| @@ -55,6 +55,18 @@ | |||
| 55 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236 | 55 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236 |
| 56 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237 | 56 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237 |
| 57 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238 | 57 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238 |
| 58 | /* MacbookAir3,2 (unibody), aka wellspring5 */ | ||
| 59 | #define USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI 0x023f | ||
| 60 | #define USB_DEVICE_ID_APPLE_WELLSPRING4_ISO 0x0240 | ||
| 61 | #define USB_DEVICE_ID_APPLE_WELLSPRING4_JIS 0x0241 | ||
| 62 | /* MacbookAir3,1 (unibody), aka wellspring4 */ | ||
| 63 | #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242 | ||
| 64 | #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243 | ||
| 65 | #define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244 | ||
| 66 | /* Macbook8 (unibody, March 2011) */ | ||
| 67 | #define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245 | ||
| 68 | #define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246 | ||
| 69 | #define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247 | ||
| 58 | 70 | ||
| 59 | #define BCM5974_DEVICE(prod) { \ | 71 | #define BCM5974_DEVICE(prod) { \ |
| 60 | .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ | 72 | .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ |
| @@ -80,6 +92,18 @@ static const struct usb_device_id bcm5974_table[] = { | |||
| 80 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI), | 92 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI), |
| 81 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO), | 93 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO), |
| 82 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), | 94 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), |
| 95 | /* MacbookAir3,2 */ | ||
| 96 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI), | ||
| 97 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ISO), | ||
| 98 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_JIS), | ||
| 99 | /* MacbookAir3,1 */ | ||
| 100 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI), | ||
| 101 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO), | ||
| 102 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), | ||
| 103 | /* MacbookPro8 */ | ||
| 104 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI), | ||
| 105 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ISO), | ||
| 106 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_JIS), | ||
| 83 | /* Terminating entry */ | 107 | /* Terminating entry */ |
| 84 | {} | 108 | {} |
| 85 | }; | 109 | }; |
| @@ -234,6 +258,42 @@ static const struct bcm5974_config bcm5974_config_table[] = { | |||
| 234 | { DIM_X, DIM_X / SN_COORD, -4460, 5166 }, | 258 | { DIM_X, DIM_X / SN_COORD, -4460, 5166 }, |
| 235 | { DIM_Y, DIM_Y / SN_COORD, -75, 6700 } | 259 | { DIM_Y, DIM_Y / SN_COORD, -75, 6700 } |
| 236 | }, | 260 | }, |
| 261 | { | ||
| 262 | USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI, | ||
| 263 | USB_DEVICE_ID_APPLE_WELLSPRING4_ISO, | ||
| 264 | USB_DEVICE_ID_APPLE_WELLSPRING4_JIS, | ||
| 265 | HAS_INTEGRATED_BUTTON, | ||
| 266 | 0x84, sizeof(struct bt_data), | ||
| 267 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, | ||
| 268 | { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, | ||
| 269 | { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, | ||
| 270 | { DIM_X, DIM_X / SN_COORD, -4620, 5140 }, | ||
| 271 | { DIM_Y, DIM_Y / SN_COORD, -150, 6600 } | ||
| 272 | }, | ||
| 273 | { | ||
| 274 | USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI, | ||
| 275 | USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO, | ||
| 276 | USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS, | ||
| 277 | HAS_INTEGRATED_BUTTON, | ||
| 278 | 0x84, sizeof(struct bt_data), | ||
| 279 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, | ||
| 280 | { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, | ||
| 281 | { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, | ||
| 282 | { DIM_X, DIM_X / SN_COORD, -4616, 5112 }, | ||
| 283 | { DIM_Y, DIM_Y / SN_COORD, -142, 5234 } | ||
| 284 | }, | ||
| 285 | { | ||
| 286 | USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI, | ||
| 287 | USB_DEVICE_ID_APPLE_WELLSPRING5_ISO, | ||
| 288 | USB_DEVICE_ID_APPLE_WELLSPRING5_JIS, | ||
| 289 | HAS_INTEGRATED_BUTTON, | ||
| 290 | 0x84, sizeof(struct bt_data), | ||
| 291 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, | ||
| 292 | { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, | ||
| 293 | { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, | ||
| 294 | { DIM_X, DIM_X / SN_COORD, -4415, 5050 }, | ||
| 295 | { DIM_Y, DIM_Y / SN_COORD, -55, 6680 } | ||
| 296 | }, | ||
| 237 | {} | 297 | {} |
| 238 | }; | 298 | }; |
| 239 | 299 | ||
diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c index 0ae62f0bcb32..f6aa26d305ed 100644 --- a/drivers/input/mouse/synaptics_i2c.c +++ b/drivers/input/mouse/synaptics_i2c.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
| 19 | #include <linux/workqueue.h> | 19 | #include <linux/workqueue.h> |
| 20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
| 21 | #include <linux/pm.h> | ||
| 21 | 22 | ||
| 22 | #define DRIVER_NAME "synaptics_i2c" | 23 | #define DRIVER_NAME "synaptics_i2c" |
| 23 | /* maximum product id is 15 characters */ | 24 | /* maximum product id is 15 characters */ |
| @@ -619,8 +620,9 @@ static int __devexit synaptics_i2c_remove(struct i2c_client *client) | |||
| 619 | } | 620 | } |
| 620 | 621 | ||
| 621 | #ifdef CONFIG_PM | 622 | #ifdef CONFIG_PM |
| 622 | static int synaptics_i2c_suspend(struct i2c_client *client, pm_message_t mesg) | 623 | static int synaptics_i2c_suspend(struct device *dev) |
| 623 | { | 624 | { |
| 625 | struct i2c_client *client = to_i2c_client(dev); | ||
| 624 | struct synaptics_i2c *touch = i2c_get_clientdata(client); | 626 | struct synaptics_i2c *touch = i2c_get_clientdata(client); |
| 625 | 627 | ||
| 626 | cancel_delayed_work_sync(&touch->dwork); | 628 | cancel_delayed_work_sync(&touch->dwork); |
| @@ -631,9 +633,10 @@ static int synaptics_i2c_suspend(struct i2c_client *client, pm_message_t mesg) | |||
| 631 | return 0; | 633 | return 0; |
| 632 | } | 634 | } |
| 633 | 635 | ||
| 634 | static int synaptics_i2c_resume(struct i2c_client *client) | 636 | static int synaptics_i2c_resume(struct device *dev) |
| 635 | { | 637 | { |
| 636 | int ret; | 638 | int ret; |
| 639 | struct i2c_client *client = to_i2c_client(dev); | ||
| 637 | struct synaptics_i2c *touch = i2c_get_clientdata(client); | 640 | struct synaptics_i2c *touch = i2c_get_clientdata(client); |
| 638 | 641 | ||
| 639 | ret = synaptics_i2c_reset_config(client); | 642 | ret = synaptics_i2c_reset_config(client); |
| @@ -645,11 +648,11 @@ static int synaptics_i2c_resume(struct i2c_client *client) | |||
| 645 | 648 | ||
| 646 | return 0; | 649 | return 0; |
| 647 | } | 650 | } |
| 648 | #else | ||
| 649 | #define synaptics_i2c_suspend NULL | ||
| 650 | #define synaptics_i2c_resume NULL | ||
| 651 | #endif | 651 | #endif |
| 652 | 652 | ||
| 653 | static SIMPLE_DEV_PM_OPS(synaptics_i2c_pm, synaptics_i2c_suspend, | ||
| 654 | synaptics_i2c_resume); | ||
| 655 | |||
| 653 | static const struct i2c_device_id synaptics_i2c_id_table[] = { | 656 | static const struct i2c_device_id synaptics_i2c_id_table[] = { |
| 654 | { "synaptics_i2c", 0 }, | 657 | { "synaptics_i2c", 0 }, |
| 655 | { }, | 658 | { }, |
| @@ -660,13 +663,12 @@ static struct i2c_driver synaptics_i2c_driver = { | |||
| 660 | .driver = { | 663 | .driver = { |
| 661 | .name = DRIVER_NAME, | 664 | .name = DRIVER_NAME, |
| 662 | .owner = THIS_MODULE, | 665 | .owner = THIS_MODULE, |
| 666 | .pm = &synaptics_i2c_pm, | ||
| 663 | }, | 667 | }, |
| 664 | 668 | ||
| 665 | .probe = synaptics_i2c_probe, | 669 | .probe = synaptics_i2c_probe, |
| 666 | .remove = __devexit_p(synaptics_i2c_remove), | 670 | .remove = __devexit_p(synaptics_i2c_remove), |
| 667 | 671 | ||
| 668 | .suspend = synaptics_i2c_suspend, | ||
| 669 | .resume = synaptics_i2c_resume, | ||
| 670 | .id_table = synaptics_i2c_id_table, | 672 | .id_table = synaptics_i2c_id_table, |
| 671 | }; | 673 | }; |
| 672 | 674 | ||
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig index 6256233d2bfb..55f2c2293ec6 100644 --- a/drivers/input/serio/Kconfig +++ b/drivers/input/serio/Kconfig | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | # Input core configuration | 2 | # Input core configuration |
| 3 | # | 3 | # |
| 4 | config SERIO | 4 | config SERIO |
| 5 | tristate "Serial I/O support" if EMBEDDED || !X86 | 5 | tristate "Serial I/O support" if EXPERT || !X86 |
| 6 | default y | 6 | default y |
| 7 | help | 7 | help |
| 8 | Say Yes here if you have any input device that uses serial I/O to | 8 | Say Yes here if you have any input device that uses serial I/O to |
| @@ -19,7 +19,7 @@ config SERIO | |||
| 19 | if SERIO | 19 | if SERIO |
| 20 | 20 | ||
| 21 | config SERIO_I8042 | 21 | config SERIO_I8042 |
| 22 | tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86 | 22 | tristate "i8042 PC Keyboard controller" if EXPERT || !X86 |
| 23 | default y | 23 | default y |
| 24 | depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && \ | 24 | depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && \ |
| 25 | (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN | 25 | (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN |
| @@ -168,7 +168,7 @@ config SERIO_MACEPS2 | |||
| 168 | module will be called maceps2. | 168 | module will be called maceps2. |
| 169 | 169 | ||
| 170 | config SERIO_LIBPS2 | 170 | config SERIO_LIBPS2 |
| 171 | tristate "PS/2 driver library" if EMBEDDED | 171 | tristate "PS/2 driver library" if EXPERT |
| 172 | depends on SERIO_I8042 || SERIO_I8042=n | 172 | depends on SERIO_I8042 || SERIO_I8042=n |
| 173 | help | 173 | help |
| 174 | Say Y here if you are using a driver for device connected | 174 | Say Y here if you are using a driver for device connected |
| @@ -214,7 +214,6 @@ config SERIO_AMS_DELTA | |||
| 214 | tristate "Amstrad Delta (E3) mailboard support" | 214 | tristate "Amstrad Delta (E3) mailboard support" |
| 215 | depends on MACH_AMS_DELTA | 215 | depends on MACH_AMS_DELTA |
| 216 | default y | 216 | default y |
| 217 | select AMS_DELTA_FIQ | ||
| 218 | ---help--- | 217 | ---help--- |
| 219 | Say Y here if you have an E3 and want to use its mailboard, | 218 | Say Y here if you have an E3 and want to use its mailboard, |
| 220 | or any standard AT keyboard connected to the mailboard port. | 219 | or any standard AT keyboard connected to the mailboard port. |
| @@ -230,7 +229,7 @@ config SERIO_PS2MULT | |||
| 230 | tristate "TQC PS/2 multiplexer" | 229 | tristate "TQC PS/2 multiplexer" |
| 231 | help | 230 | help |
| 232 | Say Y here if you have the PS/2 line multiplexer like the one | 231 | Say Y here if you have the PS/2 line multiplexer like the one |
| 233 | present on TQC boads. | 232 | present on TQC boards. |
| 234 | 233 | ||
| 235 | To compile this driver as a module, choose M here: the | 234 | To compile this driver as a module, choose M here: the |
| 236 | module will be called ps2mult. | 235 | module will be called ps2mult. |
diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c index 3c287dd879d3..4225f5d6b15f 100644 --- a/drivers/input/serio/gscps2.c +++ b/drivers/input/serio/gscps2.c | |||
| @@ -358,7 +358,7 @@ static int __devinit gscps2_probe(struct parisc_device *dev) | |||
| 358 | gscps2_reset(ps2port); | 358 | gscps2_reset(ps2port); |
| 359 | ps2port->id = readb(ps2port->addr + GSC_ID) & 0x0f; | 359 | ps2port->id = readb(ps2port->addr + GSC_ID) & 0x0f; |
| 360 | 360 | ||
| 361 | snprintf(serio->name, sizeof(serio->name), "GSC PS/2 %s", | 361 | snprintf(serio->name, sizeof(serio->name), "gsc-ps2-%s", |
| 362 | (ps2port->id == GSC_ID_KEYBOARD) ? "keyboard" : "mouse"); | 362 | (ps2port->id == GSC_ID_KEYBOARD) ? "keyboard" : "mouse"); |
| 363 | strlcpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys)); | 363 | strlcpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys)); |
| 364 | serio->id.type = SERIO_8042; | 364 | serio->id.type = SERIO_8042; |
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c index cd82bb125915..b7ba4597f7f0 100644 --- a/drivers/input/serio/serio_raw.c +++ b/drivers/input/serio/serio_raw.c | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | 11 | ||
| 12 | #include <linux/sched.h> | 12 | #include <linux/sched.h> |
| 13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
| 14 | #include <linux/smp_lock.h> | ||
| 15 | #include <linux/poll.h> | 14 | #include <linux/poll.h> |
| 16 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| 17 | #include <linux/serio.h> | 16 | #include <linux/serio.h> |
diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c index 7729e547ba65..337bf51bc984 100644 --- a/drivers/input/sparse-keymap.c +++ b/drivers/input/sparse-keymap.c | |||
| @@ -210,8 +210,8 @@ int sparse_keymap_setup(struct input_dev *dev, | |||
| 210 | 210 | ||
| 211 | dev->keycode = map; | 211 | dev->keycode = map; |
| 212 | dev->keycodemax = map_size; | 212 | dev->keycodemax = map_size; |
| 213 | dev->getkeycode_new = sparse_keymap_getkeycode; | 213 | dev->getkeycode = sparse_keymap_getkeycode; |
| 214 | dev->setkeycode_new = sparse_keymap_setkeycode; | 214 | dev->setkeycode = sparse_keymap_setkeycode; |
| 215 | 215 | ||
| 216 | return 0; | 216 | return 0; |
| 217 | 217 | ||
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c index cf8fb9f5d4a8..449c0a46dbac 100644 --- a/drivers/input/tablet/wacom_sys.c +++ b/drivers/input/tablet/wacom_sys.c | |||
| @@ -193,16 +193,16 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi | |||
| 193 | case HID_USAGE_X: | 193 | case HID_USAGE_X: |
| 194 | if (usage == WCM_DESKTOP) { | 194 | if (usage == WCM_DESKTOP) { |
| 195 | if (finger) { | 195 | if (finger) { |
| 196 | features->device_type = BTN_TOOL_DOUBLETAP; | 196 | features->device_type = BTN_TOOL_FINGER; |
| 197 | if (features->type == TABLETPC2FG) { | 197 | if (features->type == TABLETPC2FG) { |
| 198 | /* need to reset back */ | 198 | /* need to reset back */ |
| 199 | features->pktlen = WACOM_PKGLEN_TPC2FG; | 199 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
| 200 | features->device_type = BTN_TOOL_TRIPLETAP; | 200 | features->device_type = BTN_TOOL_DOUBLETAP; |
| 201 | } | 201 | } |
| 202 | if (features->type == BAMBOO_PT) { | 202 | if (features->type == BAMBOO_PT) { |
| 203 | /* need to reset back */ | 203 | /* need to reset back */ |
| 204 | features->pktlen = WACOM_PKGLEN_BBTOUCH; | 204 | features->pktlen = WACOM_PKGLEN_BBTOUCH; |
| 205 | features->device_type = BTN_TOOL_TRIPLETAP; | 205 | features->device_type = BTN_TOOL_DOUBLETAP; |
| 206 | features->x_phy = | 206 | features->x_phy = |
| 207 | get_unaligned_le16(&report[i + 5]); | 207 | get_unaligned_le16(&report[i + 5]); |
| 208 | features->x_max = | 208 | features->x_max = |
| @@ -241,11 +241,11 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi | |||
| 241 | case HID_USAGE_Y: | 241 | case HID_USAGE_Y: |
| 242 | if (usage == WCM_DESKTOP) { | 242 | if (usage == WCM_DESKTOP) { |
| 243 | if (finger) { | 243 | if (finger) { |
| 244 | features->device_type = BTN_TOOL_DOUBLETAP; | 244 | features->device_type = BTN_TOOL_FINGER; |
| 245 | if (features->type == TABLETPC2FG) { | 245 | if (features->type == TABLETPC2FG) { |
| 246 | /* need to reset back */ | 246 | /* need to reset back */ |
| 247 | features->pktlen = WACOM_PKGLEN_TPC2FG; | 247 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
| 248 | features->device_type = BTN_TOOL_TRIPLETAP; | 248 | features->device_type = BTN_TOOL_DOUBLETAP; |
| 249 | features->y_max = | 249 | features->y_max = |
| 250 | get_unaligned_le16(&report[i + 3]); | 250 | get_unaligned_le16(&report[i + 3]); |
| 251 | features->y_phy = | 251 | features->y_phy = |
| @@ -254,7 +254,7 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi | |||
| 254 | } else if (features->type == BAMBOO_PT) { | 254 | } else if (features->type == BAMBOO_PT) { |
| 255 | /* need to reset back */ | 255 | /* need to reset back */ |
| 256 | features->pktlen = WACOM_PKGLEN_BBTOUCH; | 256 | features->pktlen = WACOM_PKGLEN_BBTOUCH; |
| 257 | features->device_type = BTN_TOOL_TRIPLETAP; | 257 | features->device_type = BTN_TOOL_DOUBLETAP; |
| 258 | features->y_phy = | 258 | features->y_phy = |
| 259 | get_unaligned_le16(&report[i + 3]); | 259 | get_unaligned_le16(&report[i + 3]); |
| 260 | features->y_max = | 260 | features->y_max = |
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c index 367fa82a607e..5597637cfd41 100644 --- a/drivers/input/tablet/wacom_wac.c +++ b/drivers/input/tablet/wacom_wac.c | |||
| @@ -675,169 +675,87 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) | |||
| 675 | return 1; | 675 | return 1; |
| 676 | } | 676 | } |
| 677 | 677 | ||
| 678 | 678 | static int wacom_tpc_mt_touch(struct wacom_wac *wacom) | |
| 679 | static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx) | ||
| 680 | { | 679 | { |
| 681 | struct input_dev *input = wacom->input; | 680 | struct input_dev *input = wacom->input; |
| 682 | int finger = idx + 1; | 681 | unsigned char *data = wacom->data; |
| 683 | int x = le16_to_cpup((__le16 *)&data[finger * 2]) & 0x7fff; | 682 | int contact_with_no_pen_down_count = 0; |
| 684 | int y = le16_to_cpup((__le16 *)&data[4 + finger * 2]) & 0x7fff; | 683 | int i; |
| 685 | 684 | ||
| 686 | /* | 685 | for (i = 0; i < 2; i++) { |
| 687 | * Work around input core suppressing "duplicate" events since | 686 | int p = data[1] & (1 << i); |
| 688 | * we are abusing ABS_X/ABS_Y to transmit multi-finger data. | 687 | bool touch = p && !wacom->shared->stylus_in_proximity; |
| 689 | * This should go away once we switch to true multitouch | 688 | |
| 690 | * protocol. | 689 | input_mt_slot(input, i); |
| 691 | */ | 690 | input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); |
| 692 | if (wacom->last_finger != finger) { | 691 | if (touch) { |
| 693 | if (x == input_abs_get_val(input, ABS_X)) | 692 | int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff; |
| 694 | x++; | 693 | int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff; |
| 695 | 694 | ||
| 696 | if (y == input_abs_get_val(input, ABS_Y)) | 695 | input_report_abs(input, ABS_MT_POSITION_X, x); |
| 697 | y++; | 696 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
| 697 | contact_with_no_pen_down_count++; | ||
| 698 | } | ||
| 698 | } | 699 | } |
| 699 | 700 | ||
| 700 | input_report_abs(input, ABS_X, x); | 701 | /* keep touch state for pen event */ |
| 701 | input_report_abs(input, ABS_Y, y); | 702 | wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); |
| 702 | input_report_abs(input, ABS_MISC, wacom->id[0]); | ||
| 703 | input_report_key(input, wacom->tool[finger], 1); | ||
| 704 | if (!idx) | ||
| 705 | input_report_key(input, BTN_TOUCH, 1); | ||
| 706 | input_event(input, EV_MSC, MSC_SERIAL, finger); | ||
| 707 | input_sync(input); | ||
| 708 | 703 | ||
| 709 | wacom->last_finger = finger; | 704 | input_mt_report_pointer_emulation(input, true); |
| 710 | } | ||
| 711 | 705 | ||
| 712 | static void wacom_tpc_touch_out(struct wacom_wac *wacom, int idx) | 706 | return 1; |
| 713 | { | ||
| 714 | struct input_dev *input = wacom->input; | ||
| 715 | int finger = idx + 1; | ||
| 716 | |||
| 717 | input_report_abs(input, ABS_X, 0); | ||
| 718 | input_report_abs(input, ABS_Y, 0); | ||
| 719 | input_report_abs(input, ABS_MISC, 0); | ||
| 720 | input_report_key(input, wacom->tool[finger], 0); | ||
| 721 | if (!idx) | ||
| 722 | input_report_key(input, BTN_TOUCH, 0); | ||
| 723 | input_event(input, EV_MSC, MSC_SERIAL, finger); | ||
| 724 | input_sync(input); | ||
| 725 | } | 707 | } |
| 726 | 708 | ||
| 727 | static void wacom_tpc_touch_in(struct wacom_wac *wacom, size_t len) | 709 | static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len) |
| 728 | { | 710 | { |
| 729 | char *data = wacom->data; | 711 | char *data = wacom->data; |
| 730 | struct input_dev *input = wacom->input; | 712 | struct input_dev *input = wacom->input; |
| 713 | bool prox; | ||
| 714 | int x = 0, y = 0; | ||
| 731 | 715 | ||
| 732 | wacom->tool[1] = BTN_TOOL_DOUBLETAP; | 716 | if (!wacom->shared->stylus_in_proximity) { |
| 733 | wacom->id[0] = TOUCH_DEVICE_ID; | 717 | if (len == WACOM_PKGLEN_TPC1FG) { |
| 734 | wacom->tool[2] = BTN_TOOL_TRIPLETAP; | 718 | prox = data[0] & 0x01; |
| 735 | 719 | x = get_unaligned_le16(&data[1]); | |
| 736 | if (len != WACOM_PKGLEN_TPC1FG) { | 720 | y = get_unaligned_le16(&data[3]); |
| 737 | 721 | } else { /* with capacity */ | |
| 738 | switch (data[0]) { | 722 | prox = data[1] & 0x01; |
| 723 | x = le16_to_cpup((__le16 *)&data[2]); | ||
| 724 | y = le16_to_cpup((__le16 *)&data[4]); | ||
| 725 | } | ||
| 726 | } else | ||
| 727 | /* force touch out when pen is in prox */ | ||
| 728 | prox = 0; | ||
| 739 | 729 | ||
| 740 | case WACOM_REPORT_TPC1FG: | 730 | if (prox) { |
| 741 | input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); | 731 | input_report_abs(input, ABS_X, x); |
| 742 | input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4])); | 732 | input_report_abs(input, ABS_Y, y); |
| 743 | input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6])); | 733 | } |
| 744 | input_report_key(input, BTN_TOUCH, le16_to_cpup((__le16 *)&data[6])); | 734 | input_report_key(input, BTN_TOUCH, prox); |
| 745 | input_report_abs(input, ABS_MISC, wacom->id[0]); | ||
| 746 | input_report_key(input, wacom->tool[1], 1); | ||
| 747 | input_sync(input); | ||
| 748 | break; | ||
| 749 | 735 | ||
| 750 | case WACOM_REPORT_TPC2FG: | 736 | /* keep touch state for pen events */ |
| 751 | if (data[1] & 0x01) | 737 | wacom->shared->touch_down = prox; |
| 752 | wacom_tpc_finger_in(wacom, data, 0); | ||
| 753 | else if (wacom->id[1] & 0x01) | ||
| 754 | wacom_tpc_touch_out(wacom, 0); | ||
| 755 | 738 | ||
| 756 | if (data[1] & 0x02) | 739 | return 1; |
| 757 | wacom_tpc_finger_in(wacom, data, 1); | ||
| 758 | else if (wacom->id[1] & 0x02) | ||
| 759 | wacom_tpc_touch_out(wacom, 1); | ||
| 760 | break; | ||
| 761 | } | ||
| 762 | } else { | ||
| 763 | input_report_abs(input, ABS_X, get_unaligned_le16(&data[1])); | ||
| 764 | input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3])); | ||
| 765 | input_report_key(input, BTN_TOUCH, 1); | ||
| 766 | input_report_abs(input, ABS_MISC, wacom->id[1]); | ||
| 767 | input_report_key(input, wacom->tool[1], 1); | ||
| 768 | input_sync(input); | ||
| 769 | } | ||
| 770 | } | 740 | } |
| 771 | 741 | ||
| 772 | static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len) | 742 | static int wacom_tpc_pen(struct wacom_wac *wacom) |
| 773 | { | 743 | { |
| 774 | struct wacom_features *features = &wacom->features; | 744 | struct wacom_features *features = &wacom->features; |
| 775 | char *data = wacom->data; | 745 | char *data = wacom->data; |
| 776 | struct input_dev *input = wacom->input; | 746 | struct input_dev *input = wacom->input; |
| 777 | int prox = 0, pressure; | 747 | int pressure; |
| 778 | int retval = 0; | 748 | bool prox = data[1] & 0x20; |
| 779 | 749 | ||
| 780 | dbg("wacom_tpc_irq: received report #%d", data[0]); | 750 | if (!wacom->shared->stylus_in_proximity) /* first in prox */ |
| 781 | 751 | /* Going into proximity select tool */ | |
| 782 | if (len == WACOM_PKGLEN_TPC1FG || /* single touch */ | 752 | wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; |
| 783 | data[0] == WACOM_REPORT_TPC1FG || /* single touch */ | ||
| 784 | data[0] == WACOM_REPORT_TPC2FG) { /* 2FG touch */ | ||
| 785 | |||
| 786 | if (wacom->shared->stylus_in_proximity) { | ||
| 787 | if (wacom->id[1] & 0x01) | ||
| 788 | wacom_tpc_touch_out(wacom, 0); | ||
| 789 | |||
| 790 | if (wacom->id[1] & 0x02) | ||
| 791 | wacom_tpc_touch_out(wacom, 1); | ||
| 792 | |||
| 793 | wacom->id[1] = 0; | ||
| 794 | return 0; | ||
| 795 | } | ||
| 796 | |||
| 797 | if (len == WACOM_PKGLEN_TPC1FG) { /* with touch */ | ||
| 798 | prox = data[0] & 0x01; | ||
| 799 | } else { /* with capacity */ | ||
| 800 | if (data[0] == WACOM_REPORT_TPC1FG) | ||
| 801 | /* single touch */ | ||
| 802 | prox = data[1] & 0x01; | ||
| 803 | else | ||
| 804 | /* 2FG touch data */ | ||
| 805 | prox = data[1] & 0x03; | ||
| 806 | } | ||
| 807 | |||
| 808 | if (prox) { | ||
| 809 | if (!wacom->id[1]) | ||
| 810 | wacom->last_finger = 1; | ||
| 811 | wacom_tpc_touch_in(wacom, len); | ||
| 812 | } else { | ||
| 813 | if (data[0] == WACOM_REPORT_TPC2FG) { | ||
| 814 | /* 2FGT out-prox */ | ||
| 815 | if (wacom->id[1] & 0x01) | ||
| 816 | wacom_tpc_touch_out(wacom, 0); | ||
| 817 | 753 | ||
| 818 | if (wacom->id[1] & 0x02) | 754 | /* keep pen state for touch events */ |
| 819 | wacom_tpc_touch_out(wacom, 1); | 755 | wacom->shared->stylus_in_proximity = prox; |
| 820 | } else | ||
| 821 | /* one finger touch */ | ||
| 822 | wacom_tpc_touch_out(wacom, 0); | ||
| 823 | 756 | ||
| 824 | wacom->id[0] = 0; | 757 | /* send pen events only when touch is up or forced out */ |
| 825 | } | 758 | if (!wacom->shared->touch_down) { |
| 826 | /* keep prox bit to send proper out-prox event */ | ||
| 827 | wacom->id[1] = prox; | ||
| 828 | } else if (data[0] == WACOM_REPORT_PENABLED) { /* Penabled */ | ||
| 829 | prox = data[1] & 0x20; | ||
| 830 | |||
| 831 | if (!wacom->shared->stylus_in_proximity) { /* first in prox */ | ||
| 832 | /* Going into proximity select tool */ | ||
| 833 | wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; | ||
| 834 | if (wacom->tool[0] == BTN_TOOL_PEN) | ||
| 835 | wacom->id[0] = STYLUS_DEVICE_ID; | ||
| 836 | else | ||
| 837 | wacom->id[0] = ERASER_DEVICE_ID; | ||
| 838 | |||
| 839 | wacom->shared->stylus_in_proximity = true; | ||
| 840 | } | ||
| 841 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); | 759 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); |
| 842 | input_report_key(input, BTN_STYLUS2, data[1] & 0x10); | 760 | input_report_key(input, BTN_STYLUS2, data[1] & 0x10); |
| 843 | input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); | 761 | input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); |
| @@ -847,15 +765,27 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len) | |||
| 847 | pressure = features->pressure_max + pressure + 1; | 765 | pressure = features->pressure_max + pressure + 1; |
| 848 | input_report_abs(input, ABS_PRESSURE, pressure); | 766 | input_report_abs(input, ABS_PRESSURE, pressure); |
| 849 | input_report_key(input, BTN_TOUCH, data[1] & 0x05); | 767 | input_report_key(input, BTN_TOUCH, data[1] & 0x05); |
| 850 | if (!prox) { /* out-prox */ | ||
| 851 | wacom->id[0] = 0; | ||
| 852 | wacom->shared->stylus_in_proximity = false; | ||
| 853 | } | ||
| 854 | input_report_key(input, wacom->tool[0], prox); | 768 | input_report_key(input, wacom->tool[0], prox); |
| 855 | input_report_abs(input, ABS_MISC, wacom->id[0]); | 769 | return 1; |
| 856 | retval = 1; | ||
| 857 | } | 770 | } |
| 858 | return retval; | 771 | |
| 772 | return 0; | ||
| 773 | } | ||
| 774 | |||
| 775 | static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len) | ||
| 776 | { | ||
| 777 | char *data = wacom->data; | ||
| 778 | |||
| 779 | dbg("wacom_tpc_irq: received report #%d", data[0]); | ||
| 780 | |||
| 781 | if (len == WACOM_PKGLEN_TPC1FG || data[0] == WACOM_REPORT_TPC1FG) | ||
| 782 | return wacom_tpc_single_touch(wacom, len); | ||
| 783 | else if (data[0] == WACOM_REPORT_TPC2FG) | ||
| 784 | return wacom_tpc_mt_touch(wacom); | ||
| 785 | else if (data[0] == WACOM_REPORT_PENABLED) | ||
| 786 | return wacom_tpc_pen(wacom); | ||
| 787 | |||
| 788 | return 0; | ||
| 859 | } | 789 | } |
| 860 | 790 | ||
| 861 | static int wacom_bpt_touch(struct wacom_wac *wacom) | 791 | static int wacom_bpt_touch(struct wacom_wac *wacom) |
| @@ -1078,7 +1008,7 @@ void wacom_setup_device_quirks(struct wacom_features *features) | |||
| 1078 | { | 1008 | { |
| 1079 | 1009 | ||
| 1080 | /* touch device found but size is not defined. use default */ | 1010 | /* touch device found but size is not defined. use default */ |
| 1081 | if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) { | 1011 | if (features->device_type == BTN_TOOL_FINGER && !features->x_max) { |
| 1082 | features->x_max = 1023; | 1012 | features->x_max = 1023; |
| 1083 | features->y_max = 1023; | 1013 | features->y_max = 1023; |
| 1084 | } | 1014 | } |
| @@ -1090,7 +1020,7 @@ void wacom_setup_device_quirks(struct wacom_features *features) | |||
| 1090 | 1020 | ||
| 1091 | /* quirks for bamboo touch */ | 1021 | /* quirks for bamboo touch */ |
| 1092 | if (features->type == BAMBOO_PT && | 1022 | if (features->type == BAMBOO_PT && |
| 1093 | features->device_type == BTN_TOOL_TRIPLETAP) { | 1023 | features->device_type == BTN_TOOL_DOUBLETAP) { |
| 1094 | features->x_max <<= 5; | 1024 | features->x_max <<= 5; |
| 1095 | features->y_max <<= 5; | 1025 | features->y_max <<= 5; |
| 1096 | features->x_fuzz <<= 5; | 1026 | features->x_fuzz <<= 5; |
| @@ -1226,27 +1156,30 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev, | |||
| 1226 | break; | 1156 | break; |
| 1227 | 1157 | ||
| 1228 | case TABLETPC2FG: | 1158 | case TABLETPC2FG: |
| 1229 | if (features->device_type == BTN_TOOL_TRIPLETAP) { | 1159 | if (features->device_type == BTN_TOOL_DOUBLETAP) { |
| 1230 | __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); | 1160 | |
| 1231 | input_set_capability(input_dev, EV_MSC, MSC_SERIAL); | 1161 | input_mt_init_slots(input_dev, 2); |
| 1162 | input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, | ||
| 1163 | 0, MT_TOOL_MAX, 0, 0); | ||
| 1164 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, | ||
| 1165 | 0, features->x_max, 0, 0); | ||
| 1166 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, | ||
| 1167 | 0, features->y_max, 0, 0); | ||
| 1232 | } | 1168 | } |
| 1233 | /* fall through */ | 1169 | /* fall through */ |
| 1234 | 1170 | ||
| 1235 | case TABLETPC: | 1171 | case TABLETPC: |
| 1236 | if (features->device_type == BTN_TOOL_DOUBLETAP || | 1172 | __clear_bit(ABS_MISC, input_dev->absbit); |
| 1237 | features->device_type == BTN_TOOL_TRIPLETAP) { | 1173 | |
| 1174 | if (features->device_type != BTN_TOOL_PEN) { | ||
| 1238 | input_abs_set_res(input_dev, ABS_X, | 1175 | input_abs_set_res(input_dev, ABS_X, |
| 1239 | wacom_calculate_touch_res(features->x_max, | 1176 | wacom_calculate_touch_res(features->x_max, |
| 1240 | features->x_phy)); | 1177 | features->x_phy)); |
| 1241 | input_abs_set_res(input_dev, ABS_Y, | 1178 | input_abs_set_res(input_dev, ABS_Y, |
| 1242 | wacom_calculate_touch_res(features->y_max, | 1179 | wacom_calculate_touch_res(features->y_max, |
| 1243 | features->y_phy)); | 1180 | features->y_phy)); |
| 1244 | __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); | ||
| 1245 | } | ||
| 1246 | |||
| 1247 | if (features->device_type != BTN_TOOL_PEN) | ||
| 1248 | break; /* no need to process stylus stuff */ | 1181 | break; /* no need to process stylus stuff */ |
| 1249 | 1182 | } | |
| 1250 | /* fall through */ | 1183 | /* fall through */ |
| 1251 | 1184 | ||
| 1252 | case PL: | 1185 | case PL: |
| @@ -1264,7 +1197,7 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev, | |||
| 1264 | case BAMBOO_PT: | 1197 | case BAMBOO_PT: |
| 1265 | __clear_bit(ABS_MISC, input_dev->absbit); | 1198 | __clear_bit(ABS_MISC, input_dev->absbit); |
| 1266 | 1199 | ||
| 1267 | if (features->device_type == BTN_TOOL_TRIPLETAP) { | 1200 | if (features->device_type == BTN_TOOL_DOUBLETAP) { |
| 1268 | __set_bit(BTN_LEFT, input_dev->keybit); | 1201 | __set_bit(BTN_LEFT, input_dev->keybit); |
| 1269 | __set_bit(BTN_FORWARD, input_dev->keybit); | 1202 | __set_bit(BTN_FORWARD, input_dev->keybit); |
| 1270 | __set_bit(BTN_BACK, input_dev->keybit); | 1203 | __set_bit(BTN_BACK, input_dev->keybit); |
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h index b1310ec9720c..835f756b150c 100644 --- a/drivers/input/tablet/wacom_wac.h +++ b/drivers/input/tablet/wacom_wac.h | |||
| @@ -88,15 +88,15 @@ struct wacom_features { | |||
| 88 | 88 | ||
| 89 | struct wacom_shared { | 89 | struct wacom_shared { |
| 90 | bool stylus_in_proximity; | 90 | bool stylus_in_proximity; |
| 91 | bool touch_down; | ||
| 91 | }; | 92 | }; |
| 92 | 93 | ||
| 93 | struct wacom_wac { | 94 | struct wacom_wac { |
| 94 | char name[64]; | 95 | char name[64]; |
| 95 | unsigned char *data; | 96 | unsigned char *data; |
| 96 | int tool[3]; | 97 | int tool[2]; |
| 97 | int id[3]; | 98 | int id[2]; |
| 98 | __u32 serial[2]; | 99 | __u32 serial[2]; |
| 99 | int last_finger; | ||
| 100 | struct wacom_features features; | 100 | struct wacom_features features; |
| 101 | struct wacom_shared *shared; | 101 | struct wacom_shared *shared; |
| 102 | struct input_dev *input; | 102 | struct input_dev *input; |
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 07ac77d393a4..112ec55f2939 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
| @@ -86,6 +86,18 @@ config TOUCHSCREEN_AD7879_SPI | |||
| 86 | To compile this driver as a module, choose M here: the | 86 | To compile this driver as a module, choose M here: the |
| 87 | module will be called ad7879-spi. | 87 | module will be called ad7879-spi. |
| 88 | 88 | ||
| 89 | config TOUCHSCREEN_ATMEL_MXT | ||
| 90 | tristate "Atmel mXT I2C Touchscreen" | ||
| 91 | depends on I2C | ||
| 92 | help | ||
| 93 | Say Y here if you have Atmel mXT series I2C touchscreen, | ||
| 94 | such as AT42QT602240/ATMXT224, connected to your system. | ||
| 95 | |||
| 96 | If unsure, say N. | ||
| 97 | |||
| 98 | To compile this driver as a module, choose M here: the | ||
| 99 | module will be called atmel_mxt_ts. | ||
| 100 | |||
| 89 | config TOUCHSCREEN_BITSY | 101 | config TOUCHSCREEN_BITSY |
| 90 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" | 102 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" |
| 91 | depends on SA1100_BITSY | 103 | depends on SA1100_BITSY |
| @@ -339,18 +351,6 @@ config TOUCHSCREEN_PENMOUNT | |||
| 339 | To compile this driver as a module, choose M here: the | 351 | To compile this driver as a module, choose M here: the |
| 340 | module will be called penmount. | 352 | module will be called penmount. |
| 341 | 353 | ||
| 342 | config TOUCHSCREEN_QT602240 | ||
| 343 | tristate "QT602240 I2C Touchscreen" | ||
| 344 | depends on I2C | ||
| 345 | help | ||
| 346 | Say Y here if you have the AT42QT602240/ATMXT224 I2C touchscreen | ||
| 347 | connected to your system. | ||
| 348 | |||
| 349 | If unsure, say N. | ||
| 350 | |||
| 351 | To compile this driver as a module, choose M here: the | ||
| 352 | module will be called qt602240_ts. | ||
| 353 | |||
| 354 | config TOUCHSCREEN_MIGOR | 354 | config TOUCHSCREEN_MIGOR |
| 355 | tristate "Renesas MIGO-R touchscreen" | 355 | tristate "Renesas MIGO-R touchscreen" |
| 356 | depends on SH_MIGOR && I2C | 356 | depends on SH_MIGOR && I2C |
| @@ -423,6 +423,16 @@ config TOUCHSCREEN_UCB1400 | |||
| 423 | To compile this driver as a module, choose M here: the | 423 | To compile this driver as a module, choose M here: the |
| 424 | module will be called ucb1400_ts. | 424 | module will be called ucb1400_ts. |
| 425 | 425 | ||
| 426 | config TOUCHSCREEN_WM831X | ||
| 427 | tristate "Support for WM831x touchscreen controllers" | ||
| 428 | depends on MFD_WM831X | ||
| 429 | help | ||
| 430 | This enables support for the touchscreen controller on the WM831x | ||
| 431 | series of PMICs. | ||
| 432 | |||
| 433 | To compile this driver as a module, choose M here: the | ||
| 434 | module will be called wm831x-ts. | ||
| 435 | |||
| 426 | config TOUCHSCREEN_WM97XX | 436 | config TOUCHSCREEN_WM97XX |
| 427 | tristate "Support for WM97xx AC97 touchscreen controllers" | 437 | tristate "Support for WM97xx AC97 touchscreen controllers" |
| 428 | depends on AC97_BUS | 438 | depends on AC97_BUS |
| @@ -540,62 +550,62 @@ config TOUCHSCREEN_MC13783 | |||
| 540 | 550 | ||
| 541 | config TOUCHSCREEN_USB_EGALAX | 551 | config TOUCHSCREEN_USB_EGALAX |
| 542 | default y | 552 | default y |
| 543 | bool "eGalax, eTurboTouch CT-410/510/700 device support" if EMBEDDED | 553 | bool "eGalax, eTurboTouch CT-410/510/700 device support" if EXPERT |
| 544 | depends on TOUCHSCREEN_USB_COMPOSITE | 554 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 545 | 555 | ||
| 546 | config TOUCHSCREEN_USB_PANJIT | 556 | config TOUCHSCREEN_USB_PANJIT |
| 547 | default y | 557 | default y |
| 548 | bool "PanJit device support" if EMBEDDED | 558 | bool "PanJit device support" if EXPERT |
| 549 | depends on TOUCHSCREEN_USB_COMPOSITE | 559 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 550 | 560 | ||
| 551 | config TOUCHSCREEN_USB_3M | 561 | config TOUCHSCREEN_USB_3M |
| 552 | default y | 562 | default y |
| 553 | bool "3M/Microtouch EX II series device support" if EMBEDDED | 563 | bool "3M/Microtouch EX II series device support" if EXPERT |
| 554 | depends on TOUCHSCREEN_USB_COMPOSITE | 564 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 555 | 565 | ||
| 556 | config TOUCHSCREEN_USB_ITM | 566 | config TOUCHSCREEN_USB_ITM |
| 557 | default y | 567 | default y |
| 558 | bool "ITM device support" if EMBEDDED | 568 | bool "ITM device support" if EXPERT |
| 559 | depends on TOUCHSCREEN_USB_COMPOSITE | 569 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 560 | 570 | ||
| 561 | config TOUCHSCREEN_USB_ETURBO | 571 | config TOUCHSCREEN_USB_ETURBO |
| 562 | default y | 572 | default y |
| 563 | bool "eTurboTouch (non-eGalax compatible) device support" if EMBEDDED | 573 | bool "eTurboTouch (non-eGalax compatible) device support" if EXPERT |
| 564 | depends on TOUCHSCREEN_USB_COMPOSITE | 574 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 565 | 575 | ||
| 566 | config TOUCHSCREEN_USB_GUNZE | 576 | config TOUCHSCREEN_USB_GUNZE |
| 567 | default y | 577 | default y |
| 568 | bool "Gunze AHL61 device support" if EMBEDDED | 578 | bool "Gunze AHL61 device support" if EXPERT |
| 569 | depends on TOUCHSCREEN_USB_COMPOSITE | 579 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 570 | 580 | ||
| 571 | config TOUCHSCREEN_USB_DMC_TSC10 | 581 | config TOUCHSCREEN_USB_DMC_TSC10 |
| 572 | default y | 582 | default y |
| 573 | bool "DMC TSC-10/25 device support" if EMBEDDED | 583 | bool "DMC TSC-10/25 device support" if EXPERT |
| 574 | depends on TOUCHSCREEN_USB_COMPOSITE | 584 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 575 | 585 | ||
| 576 | config TOUCHSCREEN_USB_IRTOUCH | 586 | config TOUCHSCREEN_USB_IRTOUCH |
| 577 | default y | 587 | default y |
| 578 | bool "IRTOUCHSYSTEMS/UNITOP device support" if EMBEDDED | 588 | bool "IRTOUCHSYSTEMS/UNITOP device support" if EXPERT |
| 579 | depends on TOUCHSCREEN_USB_COMPOSITE | 589 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 580 | 590 | ||
| 581 | config TOUCHSCREEN_USB_IDEALTEK | 591 | config TOUCHSCREEN_USB_IDEALTEK |
| 582 | default y | 592 | default y |
| 583 | bool "IdealTEK URTC1000 device support" if EMBEDDED | 593 | bool "IdealTEK URTC1000 device support" if EXPERT |
| 584 | depends on TOUCHSCREEN_USB_COMPOSITE | 594 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 585 | 595 | ||
| 586 | config TOUCHSCREEN_USB_GENERAL_TOUCH | 596 | config TOUCHSCREEN_USB_GENERAL_TOUCH |
| 587 | default y | 597 | default y |
| 588 | bool "GeneralTouch Touchscreen device support" if EMBEDDED | 598 | bool "GeneralTouch Touchscreen device support" if EXPERT |
| 589 | depends on TOUCHSCREEN_USB_COMPOSITE | 599 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 590 | 600 | ||
| 591 | config TOUCHSCREEN_USB_GOTOP | 601 | config TOUCHSCREEN_USB_GOTOP |
| 592 | default y | 602 | default y |
| 593 | bool "GoTop Super_Q2/GogoPen/PenPower tablet device support" if EMBEDDED | 603 | bool "GoTop Super_Q2/GogoPen/PenPower tablet device support" if EXPERT |
| 594 | depends on TOUCHSCREEN_USB_COMPOSITE | 604 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 595 | 605 | ||
| 596 | config TOUCHSCREEN_USB_JASTEC | 606 | config TOUCHSCREEN_USB_JASTEC |
| 597 | default y | 607 | default y |
| 598 | bool "JASTEC/DigiTech DTR-02U USB touch controller device support" if EMBEDDED | 608 | bool "JASTEC/DigiTech DTR-02U USB touch controller device support" if EXPERT |
| 599 | depends on TOUCHSCREEN_USB_COMPOSITE | 609 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 600 | 610 | ||
| 601 | config TOUCHSCREEN_USB_E2I | 611 | config TOUCHSCREEN_USB_E2I |
| @@ -605,17 +615,17 @@ config TOUCHSCREEN_USB_E2I | |||
| 605 | 615 | ||
| 606 | config TOUCHSCREEN_USB_ZYTRONIC | 616 | config TOUCHSCREEN_USB_ZYTRONIC |
| 607 | default y | 617 | default y |
| 608 | bool "Zytronic controller" if EMBEDDED | 618 | bool "Zytronic controller" if EXPERT |
| 609 | depends on TOUCHSCREEN_USB_COMPOSITE | 619 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 610 | 620 | ||
| 611 | config TOUCHSCREEN_USB_ETT_TC45USB | 621 | config TOUCHSCREEN_USB_ETT_TC45USB |
| 612 | default y | 622 | default y |
| 613 | bool "ET&T USB series TC4UM/TC5UH touchscreen controler support" if EMBEDDED | 623 | bool "ET&T USB series TC4UM/TC5UH touchscreen controller support" if EXPERT |
| 614 | depends on TOUCHSCREEN_USB_COMPOSITE | 624 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 615 | 625 | ||
| 616 | config TOUCHSCREEN_USB_NEXIO | 626 | config TOUCHSCREEN_USB_NEXIO |
| 617 | default y | 627 | default y |
| 618 | bool "NEXIO/iNexio device support" if EMBEDDED | 628 | bool "NEXIO/iNexio device support" if EXPERT |
| 619 | depends on TOUCHSCREEN_USB_COMPOSITE | 629 | depends on TOUCHSCREEN_USB_COMPOSITE |
| 620 | 630 | ||
| 621 | config TOUCHSCREEN_TOUCHIT213 | 631 | config TOUCHSCREEN_TOUCHIT213 |
| @@ -629,6 +639,17 @@ config TOUCHSCREEN_TOUCHIT213 | |||
| 629 | To compile this driver as a module, choose M here: the | 639 | To compile this driver as a module, choose M here: the |
| 630 | module will be called touchit213. | 640 | module will be called touchit213. |
| 631 | 641 | ||
| 642 | config TOUCHSCREEN_TSC2005 | ||
| 643 | tristate "TSC2005 based touchscreens" | ||
| 644 | depends on SPI_MASTER | ||
| 645 | help | ||
| 646 | Say Y here if you have a TSC2005 based touchscreen. | ||
| 647 | |||
| 648 | If unsure, say N. | ||
| 649 | |||
| 650 | To compile this driver as a module, choose M here: the | ||
| 651 | module will be called tsc2005. | ||
| 652 | |||
| 632 | config TOUCHSCREEN_TSC2007 | 653 | config TOUCHSCREEN_TSC2007 |
| 633 | tristate "TSC2007 based touchscreens" | 654 | tristate "TSC2007 based touchscreens" |
| 634 | depends on I2C | 655 | depends on I2C |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 718bcc814952..ca94098d4c92 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
| @@ -12,6 +12,7 @@ obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o | |||
| 12 | obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o | 12 | obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o |
| 13 | obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o | 13 | obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o |
| 14 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o | 14 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o |
| 15 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_MXT) += atmel_mxt_ts.o | ||
| 15 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o | 16 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o |
| 16 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | 17 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o |
| 17 | obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o | 18 | obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o |
| @@ -37,7 +38,6 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o | |||
| 37 | obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o | 38 | obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o |
| 38 | obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o | 39 | obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o |
| 39 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o | 40 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o |
| 40 | obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o | ||
| 41 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o | 41 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o |
| 42 | obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o | 42 | obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o |
| 43 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o | 43 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o |
| @@ -45,9 +45,11 @@ obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o | |||
| 45 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o | 45 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o |
| 46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o | 46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o |
| 47 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o | 47 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o |
| 48 | obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o | ||
| 48 | obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o | 49 | obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o |
| 49 | obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o | 50 | obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o |
| 50 | obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o | 51 | obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o |
| 52 | obj-$(CONFIG_TOUCHSCREEN_WM831X) += wm831x-ts.o | ||
| 51 | obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o | 53 | obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o |
| 52 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o | 54 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o |
| 53 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o | 55 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o |
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c index a1952fcc083e..714d4e0f9f95 100644 --- a/drivers/input/touchscreen/ad7877.c +++ b/drivers/input/touchscreen/ad7877.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
| 42 | #include <linux/input.h> | 42 | #include <linux/input.h> |
| 43 | #include <linux/interrupt.h> | 43 | #include <linux/interrupt.h> |
| 44 | #include <linux/pm.h> | ||
| 44 | #include <linux/slab.h> | 45 | #include <linux/slab.h> |
| 45 | #include <linux/spi/spi.h> | 46 | #include <linux/spi/spi.h> |
| 46 | #include <linux/spi/ad7877.h> | 47 | #include <linux/spi/ad7877.h> |
| @@ -826,39 +827,37 @@ static int __devexit ad7877_remove(struct spi_device *spi) | |||
| 826 | return 0; | 827 | return 0; |
| 827 | } | 828 | } |
| 828 | 829 | ||
| 829 | #ifdef CONFIG_PM | 830 | #ifdef CONFIG_PM_SLEEP |
| 830 | static int ad7877_suspend(struct spi_device *spi, pm_message_t message) | 831 | static int ad7877_suspend(struct device *dev) |
| 831 | { | 832 | { |
| 832 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | 833 | struct ad7877 *ts = dev_get_drvdata(dev); |
| 833 | 834 | ||
| 834 | ad7877_disable(ts); | 835 | ad7877_disable(ts); |
| 835 | 836 | ||
| 836 | return 0; | 837 | return 0; |
| 837 | } | 838 | } |
| 838 | 839 | ||
| 839 | static int ad7877_resume(struct spi_device *spi) | 840 | static int ad7877_resume(struct device *dev) |
| 840 | { | 841 | { |
| 841 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | 842 | struct ad7877 *ts = dev_get_drvdata(dev); |
| 842 | 843 | ||
| 843 | ad7877_enable(ts); | 844 | ad7877_enable(ts); |
| 844 | 845 | ||
| 845 | return 0; | 846 | return 0; |
| 846 | } | 847 | } |
| 847 | #else | ||
| 848 | #define ad7877_suspend NULL | ||
| 849 | #define ad7877_resume NULL | ||
| 850 | #endif | 848 | #endif |
| 851 | 849 | ||
| 850 | static SIMPLE_DEV_PM_OPS(ad7877_pm, ad7877_suspend, ad7877_resume); | ||
| 851 | |||
| 852 | static struct spi_driver ad7877_driver = { | 852 | static struct spi_driver ad7877_driver = { |
| 853 | .driver = { | 853 | .driver = { |
| 854 | .name = "ad7877", | 854 | .name = "ad7877", |
| 855 | .bus = &spi_bus_type, | 855 | .bus = &spi_bus_type, |
| 856 | .owner = THIS_MODULE, | 856 | .owner = THIS_MODULE, |
| 857 | .pm = &ad7877_pm, | ||
| 857 | }, | 858 | }, |
| 858 | .probe = ad7877_probe, | 859 | .probe = ad7877_probe, |
| 859 | .remove = __devexit_p(ad7877_remove), | 860 | .remove = __devexit_p(ad7877_remove), |
| 860 | .suspend = ad7877_suspend, | ||
| 861 | .resume = ad7877_resume, | ||
| 862 | }; | 861 | }; |
| 863 | 862 | ||
| 864 | static int __init ad7877_init(void) | 863 | static int __init ad7877_init(void) |
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c index 59c6e68c4325..ddf732f3cafc 100644 --- a/drivers/input/touchscreen/ad7879-spi.c +++ b/drivers/input/touchscreen/ad7879-spi.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include <linux/input.h> /* BUS_SPI */ | 9 | #include <linux/input.h> /* BUS_SPI */ |
| 10 | #include <linux/pm.h> | ||
| 10 | #include <linux/spi/spi.h> | 11 | #include <linux/spi/spi.h> |
| 11 | 12 | ||
| 12 | #include "ad7879.h" | 13 | #include "ad7879.h" |
| @@ -20,9 +21,10 @@ | |||
| 20 | #define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) | 21 | #define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) |
| 21 | #define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) | 22 | #define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) |
| 22 | 23 | ||
| 23 | #ifdef CONFIG_PM | 24 | #ifdef CONFIG_PM_SLEEP |
| 24 | static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) | 25 | static int ad7879_spi_suspend(struct device *dev) |
| 25 | { | 26 | { |
| 27 | struct spi_device *spi = to_spi_device(dev); | ||
| 26 | struct ad7879 *ts = spi_get_drvdata(spi); | 28 | struct ad7879 *ts = spi_get_drvdata(spi); |
| 27 | 29 | ||
| 28 | ad7879_suspend(ts); | 30 | ad7879_suspend(ts); |
| @@ -30,19 +32,19 @@ static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) | |||
| 30 | return 0; | 32 | return 0; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | static int ad7879_spi_resume(struct spi_device *spi) | 35 | static int ad7879_spi_resume(struct device *dev) |
| 34 | { | 36 | { |
| 37 | struct spi_device *spi = to_spi_device(dev); | ||
| 35 | struct ad7879 *ts = spi_get_drvdata(spi); | 38 | struct ad7879 *ts = spi_get_drvdata(spi); |
| 36 | 39 | ||
| 37 | ad7879_resume(ts); | 40 | ad7879_resume(ts); |
| 38 | 41 | ||
| 39 | return 0; | 42 | return 0; |
| 40 | } | 43 | } |
| 41 | #else | ||
| 42 | # define ad7879_spi_suspend NULL | ||
| 43 | # define ad7879_spi_resume NULL | ||
| 44 | #endif | 44 | #endif |
| 45 | 45 | ||
| 46 | static SIMPLE_DEV_PM_OPS(ad7879_spi_pm, ad7879_spi_suspend, ad7879_spi_resume); | ||
| 47 | |||
| 46 | /* | 48 | /* |
| 47 | * ad7879_read/write are only used for initial setup and for sysfs controls. | 49 | * ad7879_read/write are only used for initial setup and for sysfs controls. |
| 48 | * The main traffic is done in ad7879_collect(). | 50 | * The main traffic is done in ad7879_collect(). |
| @@ -173,11 +175,10 @@ static struct spi_driver ad7879_spi_driver = { | |||
| 173 | .name = "ad7879", | 175 | .name = "ad7879", |
| 174 | .bus = &spi_bus_type, | 176 | .bus = &spi_bus_type, |
| 175 | .owner = THIS_MODULE, | 177 | .owner = THIS_MODULE, |
| 178 | .pm = &ad7879_spi_pm, | ||
| 176 | }, | 179 | }, |
| 177 | .probe = ad7879_spi_probe, | 180 | .probe = ad7879_spi_probe, |
| 178 | .remove = __devexit_p(ad7879_spi_remove), | 181 | .remove = __devexit_p(ad7879_spi_remove), |
| 179 | .suspend = ad7879_spi_suspend, | ||
| 180 | .resume = ad7879_spi_resume, | ||
| 181 | }; | 182 | }; |
| 182 | 183 | ||
| 183 | static int __init ad7879_spi_init(void) | 184 | static int __init ad7879_spi_init(void) |
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 4bf2316e3284..c24946f51256 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <linux/input.h> | 26 | #include <linux/input.h> |
| 27 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
| 29 | #include <linux/pm.h> | ||
| 29 | #include <linux/gpio.h> | 30 | #include <linux/gpio.h> |
| 30 | #include <linux/spi/spi.h> | 31 | #include <linux/spi/spi.h> |
| 31 | #include <linux/spi/ads7846.h> | 32 | #include <linux/spi/ads7846.h> |
| @@ -892,9 +893,10 @@ static irqreturn_t ads7846_irq(int irq, void *handle) | |||
| 892 | return IRQ_HANDLED; | 893 | return IRQ_HANDLED; |
| 893 | } | 894 | } |
| 894 | 895 | ||
| 895 | static int ads7846_suspend(struct spi_device *spi, pm_message_t message) | 896 | #ifdef CONFIG_PM_SLEEP |
| 897 | static int ads7846_suspend(struct device *dev) | ||
| 896 | { | 898 | { |
| 897 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); | 899 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 898 | 900 | ||
| 899 | mutex_lock(&ts->lock); | 901 | mutex_lock(&ts->lock); |
| 900 | 902 | ||
| @@ -914,9 +916,9 @@ static int ads7846_suspend(struct spi_device *spi, pm_message_t message) | |||
| 914 | return 0; | 916 | return 0; |
| 915 | } | 917 | } |
| 916 | 918 | ||
| 917 | static int ads7846_resume(struct spi_device *spi) | 919 | static int ads7846_resume(struct device *dev) |
| 918 | { | 920 | { |
| 919 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); | 921 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 920 | 922 | ||
| 921 | mutex_lock(&ts->lock); | 923 | mutex_lock(&ts->lock); |
| 922 | 924 | ||
| @@ -935,6 +937,9 @@ static int ads7846_resume(struct spi_device *spi) | |||
| 935 | 937 | ||
| 936 | return 0; | 938 | return 0; |
| 937 | } | 939 | } |
| 940 | #endif | ||
| 941 | |||
| 942 | static SIMPLE_DEV_PM_OPS(ads7846_pm, ads7846_suspend, ads7846_resume); | ||
| 938 | 943 | ||
| 939 | static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) | 944 | static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) |
| 940 | { | 945 | { |
| @@ -1408,11 +1413,10 @@ static struct spi_driver ads7846_driver = { | |||
| 1408 | .name = "ads7846", | 1413 | .name = "ads7846", |
| 1409 | .bus = &spi_bus_type, | 1414 | .bus = &spi_bus_type, |
| 1410 | .owner = THIS_MODULE, | 1415 | .owner = THIS_MODULE, |
| 1416 | .pm = &ads7846_pm, | ||
| 1411 | }, | 1417 | }, |
| 1412 | .probe = ads7846_probe, | 1418 | .probe = ads7846_probe, |
| 1413 | .remove = __devexit_p(ads7846_remove), | 1419 | .remove = __devexit_p(ads7846_remove), |
| 1414 | .suspend = ads7846_suspend, | ||
| 1415 | .resume = ads7846_resume, | ||
| 1416 | }; | 1420 | }; |
| 1417 | 1421 | ||
| 1418 | static int __init ads7846_init(void) | 1422 | static int __init ads7846_init(void) |
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c new file mode 100644 index 000000000000..4012436633b1 --- /dev/null +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
| @@ -0,0 +1,1211 @@ | |||
| 1 | /* | ||
| 2 | * Atmel maXTouch 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/atmel_mxt_ts.h> | ||
| 20 | #include <linux/input.h> | ||
| 21 | #include <linux/interrupt.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | |||
| 24 | /* Version */ | ||
| 25 | #define MXT_VER_20 20 | ||
| 26 | #define MXT_VER_21 21 | ||
| 27 | #define MXT_VER_22 22 | ||
| 28 | |||
| 29 | /* Slave addresses */ | ||
| 30 | #define MXT_APP_LOW 0x4a | ||
| 31 | #define MXT_APP_HIGH 0x4b | ||
| 32 | #define MXT_BOOT_LOW 0x24 | ||
| 33 | #define MXT_BOOT_HIGH 0x25 | ||
| 34 | |||
| 35 | /* Firmware */ | ||
| 36 | #define MXT_FW_NAME "maxtouch.fw" | ||
| 37 | |||
| 38 | /* Registers */ | ||
| 39 | #define MXT_FAMILY_ID 0x00 | ||
| 40 | #define MXT_VARIANT_ID 0x01 | ||
| 41 | #define MXT_VERSION 0x02 | ||
| 42 | #define MXT_BUILD 0x03 | ||
| 43 | #define MXT_MATRIX_X_SIZE 0x04 | ||
| 44 | #define MXT_MATRIX_Y_SIZE 0x05 | ||
| 45 | #define MXT_OBJECT_NUM 0x06 | ||
| 46 | #define MXT_OBJECT_START 0x07 | ||
| 47 | |||
| 48 | #define MXT_OBJECT_SIZE 6 | ||
| 49 | |||
| 50 | /* Object types */ | ||
| 51 | #define MXT_DEBUG_DIAGNOSTIC 37 | ||
| 52 | #define MXT_GEN_MESSAGE 5 | ||
| 53 | #define MXT_GEN_COMMAND 6 | ||
| 54 | #define MXT_GEN_POWER 7 | ||
| 55 | #define MXT_GEN_ACQUIRE 8 | ||
| 56 | #define MXT_TOUCH_MULTI 9 | ||
| 57 | #define MXT_TOUCH_KEYARRAY 15 | ||
| 58 | #define MXT_TOUCH_PROXIMITY 23 | ||
| 59 | #define MXT_PROCI_GRIPFACE 20 | ||
| 60 | #define MXT_PROCG_NOISE 22 | ||
| 61 | #define MXT_PROCI_ONETOUCH 24 | ||
| 62 | #define MXT_PROCI_TWOTOUCH 27 | ||
| 63 | #define MXT_PROCI_GRIP 40 | ||
| 64 | #define MXT_PROCI_PALM 41 | ||
| 65 | #define MXT_SPT_COMMSCONFIG 18 | ||
| 66 | #define MXT_SPT_GPIOPWM 19 | ||
| 67 | #define MXT_SPT_SELFTEST 25 | ||
| 68 | #define MXT_SPT_CTECONFIG 28 | ||
| 69 | #define MXT_SPT_USERDATA 38 | ||
| 70 | #define MXT_SPT_DIGITIZER 43 | ||
| 71 | #define MXT_SPT_MESSAGECOUNT 44 | ||
| 72 | |||
| 73 | /* MXT_GEN_COMMAND field */ | ||
| 74 | #define MXT_COMMAND_RESET 0 | ||
| 75 | #define MXT_COMMAND_BACKUPNV 1 | ||
| 76 | #define MXT_COMMAND_CALIBRATE 2 | ||
| 77 | #define MXT_COMMAND_REPORTALL 3 | ||
| 78 | #define MXT_COMMAND_DIAGNOSTIC 5 | ||
| 79 | |||
| 80 | /* MXT_GEN_POWER field */ | ||
| 81 | #define MXT_POWER_IDLEACQINT 0 | ||
| 82 | #define MXT_POWER_ACTVACQINT 1 | ||
| 83 | #define MXT_POWER_ACTV2IDLETO 2 | ||
| 84 | |||
| 85 | /* MXT_GEN_ACQUIRE field */ | ||
| 86 | #define MXT_ACQUIRE_CHRGTIME 0 | ||
| 87 | #define MXT_ACQUIRE_TCHDRIFT 2 | ||
| 88 | #define MXT_ACQUIRE_DRIFTST 3 | ||
| 89 | #define MXT_ACQUIRE_TCHAUTOCAL 4 | ||
| 90 | #define MXT_ACQUIRE_SYNC 5 | ||
| 91 | #define MXT_ACQUIRE_ATCHCALST 6 | ||
| 92 | #define MXT_ACQUIRE_ATCHCALSTHR 7 | ||
| 93 | |||
| 94 | /* MXT_TOUCH_MULTI field */ | ||
| 95 | #define MXT_TOUCH_CTRL 0 | ||
| 96 | #define MXT_TOUCH_XORIGIN 1 | ||
| 97 | #define MXT_TOUCH_YORIGIN 2 | ||
| 98 | #define MXT_TOUCH_XSIZE 3 | ||
| 99 | #define MXT_TOUCH_YSIZE 4 | ||
| 100 | #define MXT_TOUCH_BLEN 6 | ||
| 101 | #define MXT_TOUCH_TCHTHR 7 | ||
| 102 | #define MXT_TOUCH_TCHDI 8 | ||
| 103 | #define MXT_TOUCH_ORIENT 9 | ||
| 104 | #define MXT_TOUCH_MOVHYSTI 11 | ||
| 105 | #define MXT_TOUCH_MOVHYSTN 12 | ||
| 106 | #define MXT_TOUCH_NUMTOUCH 14 | ||
| 107 | #define MXT_TOUCH_MRGHYST 15 | ||
| 108 | #define MXT_TOUCH_MRGTHR 16 | ||
| 109 | #define MXT_TOUCH_AMPHYST 17 | ||
| 110 | #define MXT_TOUCH_XRANGE_LSB 18 | ||
| 111 | #define MXT_TOUCH_XRANGE_MSB 19 | ||
| 112 | #define MXT_TOUCH_YRANGE_LSB 20 | ||
| 113 | #define MXT_TOUCH_YRANGE_MSB 21 | ||
| 114 | #define MXT_TOUCH_XLOCLIP 22 | ||
| 115 | #define MXT_TOUCH_XHICLIP 23 | ||
| 116 | #define MXT_TOUCH_YLOCLIP 24 | ||
| 117 | #define MXT_TOUCH_YHICLIP 25 | ||
| 118 | #define MXT_TOUCH_XEDGECTRL 26 | ||
| 119 | #define MXT_TOUCH_XEDGEDIST 27 | ||
| 120 | #define MXT_TOUCH_YEDGECTRL 28 | ||
| 121 | #define MXT_TOUCH_YEDGEDIST 29 | ||
| 122 | #define MXT_TOUCH_JUMPLIMIT 30 | ||
| 123 | |||
| 124 | /* MXT_PROCI_GRIPFACE field */ | ||
| 125 | #define MXT_GRIPFACE_CTRL 0 | ||
| 126 | #define MXT_GRIPFACE_XLOGRIP 1 | ||
| 127 | #define MXT_GRIPFACE_XHIGRIP 2 | ||
| 128 | #define MXT_GRIPFACE_YLOGRIP 3 | ||
| 129 | #define MXT_GRIPFACE_YHIGRIP 4 | ||
| 130 | #define MXT_GRIPFACE_MAXTCHS 5 | ||
| 131 | #define MXT_GRIPFACE_SZTHR1 7 | ||
| 132 | #define MXT_GRIPFACE_SZTHR2 8 | ||
| 133 | #define MXT_GRIPFACE_SHPTHR1 9 | ||
| 134 | #define MXT_GRIPFACE_SHPTHR2 10 | ||
| 135 | #define MXT_GRIPFACE_SUPEXTTO 11 | ||
| 136 | |||
| 137 | /* MXT_PROCI_NOISE field */ | ||
| 138 | #define MXT_NOISE_CTRL 0 | ||
| 139 | #define MXT_NOISE_OUTFLEN 1 | ||
| 140 | #define MXT_NOISE_GCAFUL_LSB 3 | ||
| 141 | #define MXT_NOISE_GCAFUL_MSB 4 | ||
| 142 | #define MXT_NOISE_GCAFLL_LSB 5 | ||
| 143 | #define MXT_NOISE_GCAFLL_MSB 6 | ||
| 144 | #define MXT_NOISE_ACTVGCAFVALID 7 | ||
| 145 | #define MXT_NOISE_NOISETHR 8 | ||
| 146 | #define MXT_NOISE_FREQHOPSCALE 10 | ||
| 147 | #define MXT_NOISE_FREQ0 11 | ||
| 148 | #define MXT_NOISE_FREQ1 12 | ||
| 149 | #define MXT_NOISE_FREQ2 13 | ||
| 150 | #define MXT_NOISE_FREQ3 14 | ||
| 151 | #define MXT_NOISE_FREQ4 15 | ||
| 152 | #define MXT_NOISE_IDLEGCAFVALID 16 | ||
| 153 | |||
| 154 | /* MXT_SPT_COMMSCONFIG */ | ||
| 155 | #define MXT_COMMS_CTRL 0 | ||
| 156 | #define MXT_COMMS_CMD 1 | ||
| 157 | |||
| 158 | /* MXT_SPT_CTECONFIG field */ | ||
| 159 | #define MXT_CTE_CTRL 0 | ||
| 160 | #define MXT_CTE_CMD 1 | ||
| 161 | #define MXT_CTE_MODE 2 | ||
| 162 | #define MXT_CTE_IDLEGCAFDEPTH 3 | ||
| 163 | #define MXT_CTE_ACTVGCAFDEPTH 4 | ||
| 164 | #define MXT_CTE_VOLTAGE 5 | ||
| 165 | |||
| 166 | #define MXT_VOLTAGE_DEFAULT 2700000 | ||
| 167 | #define MXT_VOLTAGE_STEP 10000 | ||
| 168 | |||
| 169 | /* Define for MXT_GEN_COMMAND */ | ||
| 170 | #define MXT_BOOT_VALUE 0xa5 | ||
| 171 | #define MXT_BACKUP_VALUE 0x55 | ||
| 172 | #define MXT_BACKUP_TIME 25 /* msec */ | ||
| 173 | #define MXT_RESET_TIME 65 /* msec */ | ||
| 174 | |||
| 175 | #define MXT_FWRESET_TIME 175 /* msec */ | ||
| 176 | |||
| 177 | /* Command to unlock bootloader */ | ||
| 178 | #define MXT_UNLOCK_CMD_MSB 0xaa | ||
| 179 | #define MXT_UNLOCK_CMD_LSB 0xdc | ||
| 180 | |||
| 181 | /* Bootloader mode status */ | ||
| 182 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ | ||
| 183 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ | ||
| 184 | #define MXT_FRAME_CRC_CHECK 0x02 | ||
| 185 | #define MXT_FRAME_CRC_FAIL 0x03 | ||
| 186 | #define MXT_FRAME_CRC_PASS 0x04 | ||
| 187 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ | ||
| 188 | #define MXT_BOOT_STATUS_MASK 0x3f | ||
| 189 | |||
| 190 | /* Touch status */ | ||
| 191 | #define MXT_SUPPRESS (1 << 1) | ||
| 192 | #define MXT_AMP (1 << 2) | ||
| 193 | #define MXT_VECTOR (1 << 3) | ||
| 194 | #define MXT_MOVE (1 << 4) | ||
| 195 | #define MXT_RELEASE (1 << 5) | ||
| 196 | #define MXT_PRESS (1 << 6) | ||
| 197 | #define MXT_DETECT (1 << 7) | ||
| 198 | |||
| 199 | /* Touchscreen absolute values */ | ||
| 200 | #define MXT_MAX_XC 0x3ff | ||
| 201 | #define MXT_MAX_YC 0x3ff | ||
| 202 | #define MXT_MAX_AREA 0xff | ||
| 203 | |||
| 204 | #define MXT_MAX_FINGER 10 | ||
| 205 | |||
| 206 | struct mxt_info { | ||
| 207 | u8 family_id; | ||
| 208 | u8 variant_id; | ||
| 209 | u8 version; | ||
| 210 | u8 build; | ||
| 211 | u8 matrix_xsize; | ||
| 212 | u8 matrix_ysize; | ||
| 213 | u8 object_num; | ||
| 214 | }; | ||
| 215 | |||
| 216 | struct mxt_object { | ||
| 217 | u8 type; | ||
| 218 | u16 start_address; | ||
| 219 | u8 size; | ||
| 220 | u8 instances; | ||
| 221 | u8 num_report_ids; | ||
| 222 | |||
| 223 | /* to map object and message */ | ||
| 224 | u8 max_reportid; | ||
| 225 | }; | ||
| 226 | |||
| 227 | struct mxt_message { | ||
| 228 | u8 reportid; | ||
| 229 | u8 message[7]; | ||
| 230 | u8 checksum; | ||
| 231 | }; | ||
| 232 | |||
| 233 | struct mxt_finger { | ||
| 234 | int status; | ||
| 235 | int x; | ||
| 236 | int y; | ||
| 237 | int area; | ||
| 238 | }; | ||
| 239 | |||
| 240 | /* Each client has this additional data */ | ||
| 241 | struct mxt_data { | ||
| 242 | struct i2c_client *client; | ||
| 243 | struct input_dev *input_dev; | ||
| 244 | const struct mxt_platform_data *pdata; | ||
| 245 | struct mxt_object *object_table; | ||
| 246 | struct mxt_info info; | ||
| 247 | struct mxt_finger finger[MXT_MAX_FINGER]; | ||
| 248 | unsigned int irq; | ||
| 249 | }; | ||
| 250 | |||
| 251 | static bool mxt_object_readable(unsigned int type) | ||
| 252 | { | ||
| 253 | switch (type) { | ||
| 254 | case MXT_GEN_MESSAGE: | ||
| 255 | case MXT_GEN_COMMAND: | ||
| 256 | case MXT_GEN_POWER: | ||
| 257 | case MXT_GEN_ACQUIRE: | ||
| 258 | case MXT_TOUCH_MULTI: | ||
| 259 | case MXT_TOUCH_KEYARRAY: | ||
| 260 | case MXT_TOUCH_PROXIMITY: | ||
| 261 | case MXT_PROCI_GRIPFACE: | ||
| 262 | case MXT_PROCG_NOISE: | ||
| 263 | case MXT_PROCI_ONETOUCH: | ||
| 264 | case MXT_PROCI_TWOTOUCH: | ||
| 265 | case MXT_PROCI_GRIP: | ||
| 266 | case MXT_PROCI_PALM: | ||
| 267 | case MXT_SPT_COMMSCONFIG: | ||
| 268 | case MXT_SPT_GPIOPWM: | ||
| 269 | case MXT_SPT_SELFTEST: | ||
| 270 | case MXT_SPT_CTECONFIG: | ||
| 271 | case MXT_SPT_USERDATA: | ||
| 272 | return true; | ||
| 273 | default: | ||
| 274 | return false; | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | static bool mxt_object_writable(unsigned int type) | ||
| 279 | { | ||
| 280 | switch (type) { | ||
| 281 | case MXT_GEN_COMMAND: | ||
| 282 | case MXT_GEN_POWER: | ||
| 283 | case MXT_GEN_ACQUIRE: | ||
| 284 | case MXT_TOUCH_MULTI: | ||
| 285 | case MXT_TOUCH_KEYARRAY: | ||
| 286 | case MXT_TOUCH_PROXIMITY: | ||
| 287 | case MXT_PROCI_GRIPFACE: | ||
| 288 | case MXT_PROCG_NOISE: | ||
| 289 | case MXT_PROCI_ONETOUCH: | ||
| 290 | case MXT_PROCI_TWOTOUCH: | ||
| 291 | case MXT_PROCI_GRIP: | ||
| 292 | case MXT_PROCI_PALM: | ||
| 293 | case MXT_SPT_GPIOPWM: | ||
| 294 | case MXT_SPT_SELFTEST: | ||
| 295 | case MXT_SPT_CTECONFIG: | ||
| 296 | return true; | ||
| 297 | default: | ||
| 298 | return false; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | static void mxt_dump_message(struct device *dev, | ||
| 303 | struct mxt_message *message) | ||
| 304 | { | ||
| 305 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); | ||
| 306 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); | ||
| 307 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); | ||
| 308 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); | ||
| 309 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); | ||
| 310 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); | ||
| 311 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); | ||
| 312 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); | ||
| 313 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); | ||
| 314 | } | ||
| 315 | |||
| 316 | static int mxt_check_bootloader(struct i2c_client *client, | ||
| 317 | unsigned int state) | ||
| 318 | { | ||
| 319 | u8 val; | ||
| 320 | |||
| 321 | recheck: | ||
| 322 | if (i2c_master_recv(client, &val, 1) != 1) { | ||
| 323 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); | ||
| 324 | return -EIO; | ||
| 325 | } | ||
| 326 | |||
| 327 | switch (state) { | ||
| 328 | case MXT_WAITING_BOOTLOAD_CMD: | ||
| 329 | case MXT_WAITING_FRAME_DATA: | ||
| 330 | val &= ~MXT_BOOT_STATUS_MASK; | ||
| 331 | break; | ||
| 332 | case MXT_FRAME_CRC_PASS: | ||
| 333 | if (val == MXT_FRAME_CRC_CHECK) | ||
| 334 | goto recheck; | ||
| 335 | break; | ||
| 336 | default: | ||
| 337 | return -EINVAL; | ||
| 338 | } | ||
| 339 | |||
| 340 | if (val != state) { | ||
| 341 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); | ||
| 342 | return -EINVAL; | ||
| 343 | } | ||
| 344 | |||
| 345 | return 0; | ||
| 346 | } | ||
| 347 | |||
| 348 | static int mxt_unlock_bootloader(struct i2c_client *client) | ||
| 349 | { | ||
| 350 | u8 buf[2]; | ||
| 351 | |||
| 352 | buf[0] = MXT_UNLOCK_CMD_LSB; | ||
| 353 | buf[1] = MXT_UNLOCK_CMD_MSB; | ||
| 354 | |||
| 355 | if (i2c_master_send(client, buf, 2) != 2) { | ||
| 356 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 357 | return -EIO; | ||
| 358 | } | ||
| 359 | |||
| 360 | return 0; | ||
| 361 | } | ||
| 362 | |||
| 363 | static int mxt_fw_write(struct i2c_client *client, | ||
| 364 | const u8 *data, unsigned int frame_size) | ||
| 365 | { | ||
| 366 | if (i2c_master_send(client, data, frame_size) != frame_size) { | ||
| 367 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 368 | return -EIO; | ||
| 369 | } | ||
| 370 | |||
| 371 | return 0; | ||
| 372 | } | ||
| 373 | |||
| 374 | static int __mxt_read_reg(struct i2c_client *client, | ||
| 375 | u16 reg, u16 len, void *val) | ||
| 376 | { | ||
| 377 | struct i2c_msg xfer[2]; | ||
| 378 | u8 buf[2]; | ||
| 379 | |||
| 380 | buf[0] = reg & 0xff; | ||
| 381 | buf[1] = (reg >> 8) & 0xff; | ||
| 382 | |||
| 383 | /* Write register */ | ||
| 384 | xfer[0].addr = client->addr; | ||
| 385 | xfer[0].flags = 0; | ||
| 386 | xfer[0].len = 2; | ||
| 387 | xfer[0].buf = buf; | ||
| 388 | |||
| 389 | /* Read data */ | ||
| 390 | xfer[1].addr = client->addr; | ||
| 391 | xfer[1].flags = I2C_M_RD; | ||
| 392 | xfer[1].len = len; | ||
| 393 | xfer[1].buf = val; | ||
| 394 | |||
| 395 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { | ||
| 396 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); | ||
| 397 | return -EIO; | ||
| 398 | } | ||
| 399 | |||
| 400 | return 0; | ||
| 401 | } | ||
| 402 | |||
| 403 | static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) | ||
| 404 | { | ||
| 405 | return __mxt_read_reg(client, reg, 1, val); | ||
| 406 | } | ||
| 407 | |||
| 408 | static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) | ||
| 409 | { | ||
| 410 | u8 buf[3]; | ||
| 411 | |||
| 412 | buf[0] = reg & 0xff; | ||
| 413 | buf[1] = (reg >> 8) & 0xff; | ||
| 414 | buf[2] = val; | ||
| 415 | |||
| 416 | if (i2c_master_send(client, buf, 3) != 3) { | ||
| 417 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 418 | return -EIO; | ||
| 419 | } | ||
| 420 | |||
| 421 | return 0; | ||
| 422 | } | ||
| 423 | |||
| 424 | static int mxt_read_object_table(struct i2c_client *client, | ||
| 425 | u16 reg, u8 *object_buf) | ||
| 426 | { | ||
| 427 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, | ||
| 428 | object_buf); | ||
| 429 | } | ||
| 430 | |||
| 431 | static struct mxt_object * | ||
| 432 | mxt_get_object(struct mxt_data *data, u8 type) | ||
| 433 | { | ||
| 434 | struct mxt_object *object; | ||
| 435 | int i; | ||
| 436 | |||
| 437 | for (i = 0; i < data->info.object_num; i++) { | ||
| 438 | object = data->object_table + i; | ||
| 439 | if (object->type == type) | ||
| 440 | return object; | ||
| 441 | } | ||
| 442 | |||
| 443 | dev_err(&data->client->dev, "Invalid object type\n"); | ||
| 444 | return NULL; | ||
| 445 | } | ||
| 446 | |||
| 447 | static int mxt_read_message(struct mxt_data *data, | ||
| 448 | struct mxt_message *message) | ||
| 449 | { | ||
| 450 | struct mxt_object *object; | ||
| 451 | u16 reg; | ||
| 452 | |||
| 453 | object = mxt_get_object(data, MXT_GEN_MESSAGE); | ||
| 454 | if (!object) | ||
| 455 | return -EINVAL; | ||
| 456 | |||
| 457 | reg = object->start_address; | ||
| 458 | return __mxt_read_reg(data->client, reg, | ||
| 459 | sizeof(struct mxt_message), message); | ||
| 460 | } | ||
| 461 | |||
| 462 | static int mxt_read_object(struct mxt_data *data, | ||
| 463 | u8 type, u8 offset, u8 *val) | ||
| 464 | { | ||
| 465 | struct mxt_object *object; | ||
| 466 | u16 reg; | ||
| 467 | |||
| 468 | object = mxt_get_object(data, type); | ||
| 469 | if (!object) | ||
| 470 | return -EINVAL; | ||
| 471 | |||
| 472 | reg = object->start_address; | ||
| 473 | return __mxt_read_reg(data->client, reg + offset, 1, val); | ||
| 474 | } | ||
| 475 | |||
| 476 | static int mxt_write_object(struct mxt_data *data, | ||
| 477 | u8 type, u8 offset, u8 val) | ||
| 478 | { | ||
| 479 | struct mxt_object *object; | ||
| 480 | u16 reg; | ||
| 481 | |||
| 482 | object = mxt_get_object(data, type); | ||
| 483 | if (!object) | ||
| 484 | return -EINVAL; | ||
| 485 | |||
| 486 | reg = object->start_address; | ||
| 487 | return mxt_write_reg(data->client, reg + offset, val); | ||
| 488 | } | ||
| 489 | |||
| 490 | static void mxt_input_report(struct mxt_data *data, int single_id) | ||
| 491 | { | ||
| 492 | struct mxt_finger *finger = data->finger; | ||
| 493 | struct input_dev *input_dev = data->input_dev; | ||
| 494 | int status = finger[single_id].status; | ||
| 495 | int finger_num = 0; | ||
| 496 | int id; | ||
| 497 | |||
| 498 | for (id = 0; id < MXT_MAX_FINGER; id++) { | ||
| 499 | if (!finger[id].status) | ||
| 500 | continue; | ||
| 501 | |||
| 502 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, | ||
| 503 | finger[id].status != MXT_RELEASE ? | ||
| 504 | finger[id].area : 0); | ||
| 505 | input_report_abs(input_dev, ABS_MT_POSITION_X, | ||
| 506 | finger[id].x); | ||
| 507 | input_report_abs(input_dev, ABS_MT_POSITION_Y, | ||
| 508 | finger[id].y); | ||
| 509 | input_mt_sync(input_dev); | ||
| 510 | |||
| 511 | if (finger[id].status == MXT_RELEASE) | ||
| 512 | finger[id].status = 0; | ||
| 513 | else | ||
| 514 | finger_num++; | ||
| 515 | } | ||
| 516 | |||
| 517 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); | ||
| 518 | |||
| 519 | if (status != MXT_RELEASE) { | ||
| 520 | input_report_abs(input_dev, ABS_X, finger[single_id].x); | ||
| 521 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); | ||
| 522 | } | ||
| 523 | |||
| 524 | input_sync(input_dev); | ||
| 525 | } | ||
| 526 | |||
| 527 | static void mxt_input_touchevent(struct mxt_data *data, | ||
| 528 | struct mxt_message *message, int id) | ||
| 529 | { | ||
| 530 | struct mxt_finger *finger = data->finger; | ||
| 531 | struct device *dev = &data->client->dev; | ||
| 532 | u8 status = message->message[0]; | ||
| 533 | int x; | ||
| 534 | int y; | ||
| 535 | int area; | ||
| 536 | |||
| 537 | /* Check the touch is present on the screen */ | ||
| 538 | if (!(status & MXT_DETECT)) { | ||
| 539 | if (status & MXT_RELEASE) { | ||
| 540 | dev_dbg(dev, "[%d] released\n", id); | ||
| 541 | |||
| 542 | finger[id].status = MXT_RELEASE; | ||
| 543 | mxt_input_report(data, id); | ||
| 544 | } | ||
| 545 | return; | ||
| 546 | } | ||
| 547 | |||
| 548 | /* Check only AMP detection */ | ||
| 549 | if (!(status & (MXT_PRESS | MXT_MOVE))) | ||
| 550 | return; | ||
| 551 | |||
| 552 | x = (message->message[1] << 2) | ((message->message[3] & ~0x3f) >> 6); | ||
| 553 | y = (message->message[2] << 2) | ((message->message[3] & ~0xf3) >> 2); | ||
| 554 | area = message->message[4]; | ||
| 555 | |||
| 556 | dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, | ||
| 557 | status & MXT_MOVE ? "moved" : "pressed", | ||
| 558 | x, y, area); | ||
| 559 | |||
| 560 | finger[id].status = status & MXT_MOVE ? | ||
| 561 | MXT_MOVE : MXT_PRESS; | ||
| 562 | finger[id].x = x; | ||
| 563 | finger[id].y = y; | ||
| 564 | finger[id].area = area; | ||
| 565 | |||
| 566 | mxt_input_report(data, id); | ||
| 567 | } | ||
| 568 | |||
| 569 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) | ||
| 570 | { | ||
| 571 | struct mxt_data *data = dev_id; | ||
| 572 | struct mxt_message message; | ||
| 573 | struct mxt_object *object; | ||
| 574 | struct device *dev = &data->client->dev; | ||
| 575 | int id; | ||
| 576 | u8 reportid; | ||
| 577 | u8 max_reportid; | ||
| 578 | u8 min_reportid; | ||
| 579 | |||
| 580 | do { | ||
| 581 | if (mxt_read_message(data, &message)) { | ||
| 582 | dev_err(dev, "Failed to read message\n"); | ||
| 583 | goto end; | ||
| 584 | } | ||
| 585 | |||
| 586 | reportid = message.reportid; | ||
| 587 | |||
| 588 | /* whether reportid is thing of MXT_TOUCH_MULTI */ | ||
| 589 | object = mxt_get_object(data, MXT_TOUCH_MULTI); | ||
| 590 | if (!object) | ||
| 591 | goto end; | ||
| 592 | |||
| 593 | max_reportid = object->max_reportid; | ||
| 594 | min_reportid = max_reportid - object->num_report_ids + 1; | ||
| 595 | id = reportid - min_reportid; | ||
| 596 | |||
| 597 | if (reportid >= min_reportid && reportid <= max_reportid) | ||
| 598 | mxt_input_touchevent(data, &message, id); | ||
| 599 | else | ||
| 600 | mxt_dump_message(dev, &message); | ||
| 601 | } while (reportid != 0xff); | ||
| 602 | |||
| 603 | end: | ||
| 604 | return IRQ_HANDLED; | ||
| 605 | } | ||
| 606 | |||
| 607 | static int mxt_check_reg_init(struct mxt_data *data) | ||
| 608 | { | ||
| 609 | const struct mxt_platform_data *pdata = data->pdata; | ||
| 610 | struct mxt_object *object; | ||
| 611 | struct device *dev = &data->client->dev; | ||
| 612 | int index = 0; | ||
| 613 | int i, j, config_offset; | ||
| 614 | |||
| 615 | if (!pdata->config) { | ||
| 616 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); | ||
| 617 | return 0; | ||
| 618 | } | ||
| 619 | |||
| 620 | for (i = 0; i < data->info.object_num; i++) { | ||
| 621 | object = data->object_table + i; | ||
| 622 | |||
| 623 | if (!mxt_object_writable(object->type)) | ||
| 624 | continue; | ||
| 625 | |||
| 626 | for (j = 0; j < object->size + 1; j++) { | ||
| 627 | config_offset = index + j; | ||
| 628 | if (config_offset > pdata->config_length) { | ||
| 629 | dev_err(dev, "Not enough config data!\n"); | ||
| 630 | return -EINVAL; | ||
| 631 | } | ||
| 632 | mxt_write_object(data, object->type, j, | ||
| 633 | pdata->config[config_offset]); | ||
| 634 | } | ||
| 635 | index += object->size + 1; | ||
| 636 | } | ||
| 637 | |||
| 638 | return 0; | ||
| 639 | } | ||
| 640 | |||
| 641 | static int mxt_make_highchg(struct mxt_data *data) | ||
| 642 | { | ||
| 643 | struct device *dev = &data->client->dev; | ||
| 644 | struct mxt_message message; | ||
| 645 | int count = 10; | ||
| 646 | int error; | ||
| 647 | |||
| 648 | /* Read dummy message to make high CHG pin */ | ||
| 649 | do { | ||
| 650 | error = mxt_read_message(data, &message); | ||
| 651 | if (error) | ||
| 652 | return error; | ||
| 653 | } while (message.reportid != 0xff && --count); | ||
| 654 | |||
| 655 | if (!count) { | ||
| 656 | dev_err(dev, "CHG pin isn't cleared\n"); | ||
| 657 | return -EBUSY; | ||
| 658 | } | ||
| 659 | |||
| 660 | return 0; | ||
| 661 | } | ||
| 662 | |||
| 663 | static void mxt_handle_pdata(struct mxt_data *data) | ||
| 664 | { | ||
| 665 | const struct mxt_platform_data *pdata = data->pdata; | ||
| 666 | u8 voltage; | ||
| 667 | |||
| 668 | /* Set touchscreen lines */ | ||
| 669 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_XSIZE, | ||
| 670 | pdata->x_line); | ||
| 671 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_YSIZE, | ||
| 672 | pdata->y_line); | ||
| 673 | |||
| 674 | /* Set touchscreen orient */ | ||
| 675 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_ORIENT, | ||
| 676 | pdata->orient); | ||
| 677 | |||
| 678 | /* Set touchscreen burst length */ | ||
| 679 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 680 | MXT_TOUCH_BLEN, pdata->blen); | ||
| 681 | |||
| 682 | /* Set touchscreen threshold */ | ||
| 683 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 684 | MXT_TOUCH_TCHTHR, pdata->threshold); | ||
| 685 | |||
| 686 | /* Set touchscreen resolution */ | ||
| 687 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 688 | MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff); | ||
| 689 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 690 | MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8); | ||
| 691 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 692 | MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff); | ||
| 693 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 694 | MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8); | ||
| 695 | |||
| 696 | /* Set touchscreen voltage */ | ||
| 697 | if (pdata->voltage) { | ||
| 698 | if (pdata->voltage < MXT_VOLTAGE_DEFAULT) { | ||
| 699 | voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) / | ||
| 700 | MXT_VOLTAGE_STEP; | ||
| 701 | voltage = 0xff - voltage + 1; | ||
| 702 | } else | ||
| 703 | voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) / | ||
| 704 | MXT_VOLTAGE_STEP; | ||
| 705 | |||
| 706 | mxt_write_object(data, MXT_SPT_CTECONFIG, | ||
| 707 | MXT_CTE_VOLTAGE, voltage); | ||
| 708 | } | ||
| 709 | } | ||
| 710 | |||
| 711 | static int mxt_get_info(struct mxt_data *data) | ||
| 712 | { | ||
| 713 | struct i2c_client *client = data->client; | ||
| 714 | struct mxt_info *info = &data->info; | ||
| 715 | int error; | ||
| 716 | u8 val; | ||
| 717 | |||
| 718 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); | ||
| 719 | if (error) | ||
| 720 | return error; | ||
| 721 | info->family_id = val; | ||
| 722 | |||
| 723 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); | ||
| 724 | if (error) | ||
| 725 | return error; | ||
| 726 | info->variant_id = val; | ||
| 727 | |||
| 728 | error = mxt_read_reg(client, MXT_VERSION, &val); | ||
| 729 | if (error) | ||
| 730 | return error; | ||
| 731 | info->version = val; | ||
| 732 | |||
| 733 | error = mxt_read_reg(client, MXT_BUILD, &val); | ||
| 734 | if (error) | ||
| 735 | return error; | ||
| 736 | info->build = val; | ||
| 737 | |||
| 738 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); | ||
| 739 | if (error) | ||
| 740 | return error; | ||
| 741 | info->object_num = val; | ||
| 742 | |||
| 743 | return 0; | ||
| 744 | } | ||
| 745 | |||
| 746 | static int mxt_get_object_table(struct mxt_data *data) | ||
| 747 | { | ||
| 748 | int error; | ||
| 749 | int i; | ||
| 750 | u16 reg; | ||
| 751 | u8 reportid = 0; | ||
| 752 | u8 buf[MXT_OBJECT_SIZE]; | ||
| 753 | |||
| 754 | for (i = 0; i < data->info.object_num; i++) { | ||
| 755 | struct mxt_object *object = data->object_table + i; | ||
| 756 | |||
| 757 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; | ||
| 758 | error = mxt_read_object_table(data->client, reg, buf); | ||
| 759 | if (error) | ||
| 760 | return error; | ||
| 761 | |||
| 762 | object->type = buf[0]; | ||
| 763 | object->start_address = (buf[2] << 8) | buf[1]; | ||
| 764 | object->size = buf[3]; | ||
| 765 | object->instances = buf[4]; | ||
| 766 | object->num_report_ids = buf[5]; | ||
| 767 | |||
| 768 | if (object->num_report_ids) { | ||
| 769 | reportid += object->num_report_ids * | ||
| 770 | (object->instances + 1); | ||
| 771 | object->max_reportid = reportid; | ||
| 772 | } | ||
| 773 | } | ||
| 774 | |||
| 775 | return 0; | ||
| 776 | } | ||
| 777 | |||
| 778 | static int mxt_initialize(struct mxt_data *data) | ||
| 779 | { | ||
| 780 | struct i2c_client *client = data->client; | ||
| 781 | struct mxt_info *info = &data->info; | ||
| 782 | int error; | ||
| 783 | u8 val; | ||
| 784 | |||
| 785 | error = mxt_get_info(data); | ||
| 786 | if (error) | ||
| 787 | return error; | ||
| 788 | |||
| 789 | data->object_table = kcalloc(info->object_num, | ||
| 790 | sizeof(struct mxt_object), | ||
| 791 | GFP_KERNEL); | ||
| 792 | if (!data->object_table) { | ||
| 793 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 794 | return -ENOMEM; | ||
| 795 | } | ||
| 796 | |||
| 797 | /* Get object table information */ | ||
| 798 | error = mxt_get_object_table(data); | ||
| 799 | if (error) | ||
| 800 | return error; | ||
| 801 | |||
| 802 | /* Check register init values */ | ||
| 803 | error = mxt_check_reg_init(data); | ||
| 804 | if (error) | ||
| 805 | return error; | ||
| 806 | |||
| 807 | error = mxt_make_highchg(data); | ||
| 808 | if (error) | ||
| 809 | return error; | ||
| 810 | |||
| 811 | mxt_handle_pdata(data); | ||
| 812 | |||
| 813 | /* Backup to memory */ | ||
| 814 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 815 | MXT_COMMAND_BACKUPNV, | ||
| 816 | MXT_BACKUP_VALUE); | ||
| 817 | msleep(MXT_BACKUP_TIME); | ||
| 818 | |||
| 819 | /* Soft reset */ | ||
| 820 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 821 | MXT_COMMAND_RESET, 1); | ||
| 822 | msleep(MXT_RESET_TIME); | ||
| 823 | |||
| 824 | /* Update matrix size at info struct */ | ||
| 825 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); | ||
| 826 | if (error) | ||
| 827 | return error; | ||
| 828 | info->matrix_xsize = val; | ||
| 829 | |||
| 830 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); | ||
| 831 | if (error) | ||
| 832 | return error; | ||
| 833 | info->matrix_ysize = val; | ||
| 834 | |||
| 835 | dev_info(&client->dev, | ||
| 836 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", | ||
| 837 | info->family_id, info->variant_id, info->version, | ||
| 838 | info->build); | ||
| 839 | |||
| 840 | dev_info(&client->dev, | ||
| 841 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", | ||
| 842 | info->matrix_xsize, info->matrix_ysize, | ||
| 843 | info->object_num); | ||
| 844 | |||
| 845 | return 0; | ||
| 846 | } | ||
| 847 | |||
| 848 | static ssize_t mxt_object_show(struct device *dev, | ||
| 849 | struct device_attribute *attr, char *buf) | ||
| 850 | { | ||
| 851 | struct mxt_data *data = dev_get_drvdata(dev); | ||
| 852 | struct mxt_object *object; | ||
| 853 | int count = 0; | ||
| 854 | int i, j; | ||
| 855 | int error; | ||
| 856 | u8 val; | ||
| 857 | |||
| 858 | for (i = 0; i < data->info.object_num; i++) { | ||
| 859 | object = data->object_table + i; | ||
| 860 | |||
| 861 | count += sprintf(buf + count, | ||
| 862 | "Object Table Element %d(Type %d)\n", | ||
| 863 | i + 1, object->type); | ||
| 864 | |||
| 865 | if (!mxt_object_readable(object->type)) { | ||
| 866 | count += sprintf(buf + count, "\n"); | ||
| 867 | continue; | ||
| 868 | } | ||
| 869 | |||
| 870 | for (j = 0; j < object->size + 1; j++) { | ||
| 871 | error = mxt_read_object(data, | ||
| 872 | object->type, j, &val); | ||
| 873 | if (error) | ||
| 874 | return error; | ||
| 875 | |||
| 876 | count += sprintf(buf + count, | ||
| 877 | " Byte %d: 0x%x (%d)\n", j, val, val); | ||
| 878 | } | ||
| 879 | |||
| 880 | count += sprintf(buf + count, "\n"); | ||
| 881 | } | ||
| 882 | |||
| 883 | return count; | ||
| 884 | } | ||
| 885 | |||
| 886 | static int mxt_load_fw(struct device *dev, const char *fn) | ||
| 887 | { | ||
| 888 | struct mxt_data *data = dev_get_drvdata(dev); | ||
| 889 | struct i2c_client *client = data->client; | ||
| 890 | const struct firmware *fw = NULL; | ||
| 891 | unsigned int frame_size; | ||
| 892 | unsigned int pos = 0; | ||
| 893 | int ret; | ||
| 894 | |||
| 895 | ret = request_firmware(&fw, fn, dev); | ||
| 896 | if (ret) { | ||
| 897 | dev_err(dev, "Unable to open firmware %s\n", fn); | ||
| 898 | return ret; | ||
| 899 | } | ||
| 900 | |||
| 901 | /* Change to the bootloader mode */ | ||
| 902 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 903 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); | ||
| 904 | msleep(MXT_RESET_TIME); | ||
| 905 | |||
| 906 | /* Change to slave address of bootloader */ | ||
| 907 | if (client->addr == MXT_APP_LOW) | ||
| 908 | client->addr = MXT_BOOT_LOW; | ||
| 909 | else | ||
| 910 | client->addr = MXT_BOOT_HIGH; | ||
| 911 | |||
| 912 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); | ||
| 913 | if (ret) | ||
| 914 | goto out; | ||
| 915 | |||
| 916 | /* Unlock bootloader */ | ||
| 917 | mxt_unlock_bootloader(client); | ||
| 918 | |||
| 919 | while (pos < fw->size) { | ||
| 920 | ret = mxt_check_bootloader(client, | ||
| 921 | MXT_WAITING_FRAME_DATA); | ||
| 922 | if (ret) | ||
| 923 | goto out; | ||
| 924 | |||
| 925 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); | ||
| 926 | |||
| 927 | /* We should add 2 at frame size as the the firmware data is not | ||
| 928 | * included the CRC bytes. | ||
| 929 | */ | ||
| 930 | frame_size += 2; | ||
| 931 | |||
| 932 | /* Write one frame to device */ | ||
| 933 | mxt_fw_write(client, fw->data + pos, frame_size); | ||
| 934 | |||
| 935 | ret = mxt_check_bootloader(client, | ||
| 936 | MXT_FRAME_CRC_PASS); | ||
| 937 | if (ret) | ||
| 938 | goto out; | ||
| 939 | |||
| 940 | pos += frame_size; | ||
| 941 | |||
| 942 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); | ||
| 943 | } | ||
| 944 | |||
| 945 | out: | ||
| 946 | release_firmware(fw); | ||
| 947 | |||
| 948 | /* Change to slave address of application */ | ||
| 949 | if (client->addr == MXT_BOOT_LOW) | ||
| 950 | client->addr = MXT_APP_LOW; | ||
| 951 | else | ||
| 952 | client->addr = MXT_APP_HIGH; | ||
| 953 | |||
| 954 | return ret; | ||
| 955 | } | ||
| 956 | |||
| 957 | static ssize_t mxt_update_fw_store(struct device *dev, | ||
| 958 | struct device_attribute *attr, | ||
| 959 | const char *buf, size_t count) | ||
| 960 | { | ||
| 961 | struct mxt_data *data = dev_get_drvdata(dev); | ||
| 962 | int error; | ||
| 963 | |||
| 964 | disable_irq(data->irq); | ||
| 965 | |||
| 966 | error = mxt_load_fw(dev, MXT_FW_NAME); | ||
| 967 | if (error) { | ||
| 968 | dev_err(dev, "The firmware update failed(%d)\n", error); | ||
| 969 | count = error; | ||
| 970 | } else { | ||
| 971 | dev_dbg(dev, "The firmware update succeeded\n"); | ||
| 972 | |||
| 973 | /* Wait for reset */ | ||
| 974 | msleep(MXT_FWRESET_TIME); | ||
| 975 | |||
| 976 | kfree(data->object_table); | ||
| 977 | data->object_table = NULL; | ||
| 978 | |||
| 979 | mxt_initialize(data); | ||
| 980 | } | ||
| 981 | |||
| 982 | enable_irq(data->irq); | ||
| 983 | |||
| 984 | return count; | ||
| 985 | } | ||
| 986 | |||
| 987 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); | ||
| 988 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); | ||
| 989 | |||
| 990 | static struct attribute *mxt_attrs[] = { | ||
| 991 | &dev_attr_object.attr, | ||
| 992 | &dev_attr_update_fw.attr, | ||
| 993 | NULL | ||
| 994 | }; | ||
| 995 | |||
| 996 | static const struct attribute_group mxt_attr_group = { | ||
| 997 | .attrs = mxt_attrs, | ||
| 998 | }; | ||
| 999 | |||
| 1000 | static void mxt_start(struct mxt_data *data) | ||
| 1001 | { | ||
| 1002 | /* Touch enable */ | ||
| 1003 | mxt_write_object(data, | ||
| 1004 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0x83); | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | static void mxt_stop(struct mxt_data *data) | ||
| 1008 | { | ||
| 1009 | /* Touch disable */ | ||
| 1010 | mxt_write_object(data, | ||
| 1011 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | static int mxt_input_open(struct input_dev *dev) | ||
| 1015 | { | ||
| 1016 | struct mxt_data *data = input_get_drvdata(dev); | ||
| 1017 | |||
| 1018 | mxt_start(data); | ||
| 1019 | |||
| 1020 | return 0; | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | static void mxt_input_close(struct input_dev *dev) | ||
| 1024 | { | ||
| 1025 | struct mxt_data *data = input_get_drvdata(dev); | ||
| 1026 | |||
| 1027 | mxt_stop(data); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | static int __devinit mxt_probe(struct i2c_client *client, | ||
| 1031 | const struct i2c_device_id *id) | ||
| 1032 | { | ||
| 1033 | const struct mxt_platform_data *pdata = client->dev.platform_data; | ||
| 1034 | struct mxt_data *data; | ||
| 1035 | struct input_dev *input_dev; | ||
| 1036 | int error; | ||
| 1037 | |||
| 1038 | if (!pdata) | ||
| 1039 | return -EINVAL; | ||
| 1040 | |||
| 1041 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); | ||
| 1042 | input_dev = input_allocate_device(); | ||
| 1043 | if (!data || !input_dev) { | ||
| 1044 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 1045 | error = -ENOMEM; | ||
| 1046 | goto err_free_mem; | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | input_dev->name = "Atmel maXTouch Touchscreen"; | ||
| 1050 | input_dev->id.bustype = BUS_I2C; | ||
| 1051 | input_dev->dev.parent = &client->dev; | ||
| 1052 | input_dev->open = mxt_input_open; | ||
| 1053 | input_dev->close = mxt_input_close; | ||
| 1054 | |||
| 1055 | __set_bit(EV_ABS, input_dev->evbit); | ||
| 1056 | __set_bit(EV_KEY, input_dev->evbit); | ||
| 1057 | __set_bit(BTN_TOUCH, input_dev->keybit); | ||
| 1058 | |||
| 1059 | /* For single touch */ | ||
| 1060 | input_set_abs_params(input_dev, ABS_X, | ||
| 1061 | 0, MXT_MAX_XC, 0, 0); | ||
| 1062 | input_set_abs_params(input_dev, ABS_Y, | ||
| 1063 | 0, MXT_MAX_YC, 0, 0); | ||
| 1064 | |||
| 1065 | /* For multi touch */ | ||
| 1066 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, | ||
| 1067 | 0, MXT_MAX_AREA, 0, 0); | ||
| 1068 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, | ||
| 1069 | 0, MXT_MAX_XC, 0, 0); | ||
| 1070 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, | ||
| 1071 | 0, MXT_MAX_YC, 0, 0); | ||
| 1072 | |||
| 1073 | input_set_drvdata(input_dev, data); | ||
| 1074 | |||
| 1075 | data->client = client; | ||
| 1076 | data->input_dev = input_dev; | ||
| 1077 | data->pdata = pdata; | ||
| 1078 | data->irq = client->irq; | ||
| 1079 | |||
| 1080 | i2c_set_clientdata(client, data); | ||
| 1081 | |||
| 1082 | error = mxt_initialize(data); | ||
| 1083 | if (error) | ||
| 1084 | goto err_free_object; | ||
| 1085 | |||
| 1086 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, | ||
| 1087 | pdata->irqflags, client->dev.driver->name, data); | ||
| 1088 | if (error) { | ||
| 1089 | dev_err(&client->dev, "Failed to register interrupt\n"); | ||
| 1090 | goto err_free_object; | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | error = input_register_device(input_dev); | ||
| 1094 | if (error) | ||
| 1095 | goto err_free_irq; | ||
| 1096 | |||
| 1097 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); | ||
| 1098 | if (error) | ||
| 1099 | goto err_unregister_device; | ||
| 1100 | |||
| 1101 | return 0; | ||
| 1102 | |||
| 1103 | err_unregister_device: | ||
| 1104 | input_unregister_device(input_dev); | ||
| 1105 | input_dev = NULL; | ||
| 1106 | err_free_irq: | ||
| 1107 | free_irq(client->irq, data); | ||
| 1108 | err_free_object: | ||
| 1109 | kfree(data->object_table); | ||
| 1110 | err_free_mem: | ||
| 1111 | input_free_device(input_dev); | ||
| 1112 | kfree(data); | ||
| 1113 | return error; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | static int __devexit mxt_remove(struct i2c_client *client) | ||
| 1117 | { | ||
| 1118 | struct mxt_data *data = i2c_get_clientdata(client); | ||
| 1119 | |||
| 1120 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); | ||
| 1121 | free_irq(data->irq, data); | ||
| 1122 | input_unregister_device(data->input_dev); | ||
| 1123 | kfree(data->object_table); | ||
| 1124 | kfree(data); | ||
| 1125 | |||
| 1126 | return 0; | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | #ifdef CONFIG_PM | ||
| 1130 | static int mxt_suspend(struct device *dev) | ||
| 1131 | { | ||
| 1132 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1133 | struct mxt_data *data = i2c_get_clientdata(client); | ||
| 1134 | struct input_dev *input_dev = data->input_dev; | ||
| 1135 | |||
| 1136 | mutex_lock(&input_dev->mutex); | ||
| 1137 | |||
| 1138 | if (input_dev->users) | ||
| 1139 | mxt_stop(data); | ||
| 1140 | |||
| 1141 | mutex_unlock(&input_dev->mutex); | ||
| 1142 | |||
| 1143 | return 0; | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | static int mxt_resume(struct device *dev) | ||
| 1147 | { | ||
| 1148 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1149 | struct mxt_data *data = i2c_get_clientdata(client); | ||
| 1150 | struct input_dev *input_dev = data->input_dev; | ||
| 1151 | |||
| 1152 | /* Soft reset */ | ||
| 1153 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 1154 | MXT_COMMAND_RESET, 1); | ||
| 1155 | |||
| 1156 | msleep(MXT_RESET_TIME); | ||
| 1157 | |||
| 1158 | mutex_lock(&input_dev->mutex); | ||
| 1159 | |||
| 1160 | if (input_dev->users) | ||
| 1161 | mxt_start(data); | ||
| 1162 | |||
| 1163 | mutex_unlock(&input_dev->mutex); | ||
| 1164 | |||
| 1165 | return 0; | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | static const struct dev_pm_ops mxt_pm_ops = { | ||
| 1169 | .suspend = mxt_suspend, | ||
| 1170 | .resume = mxt_resume, | ||
| 1171 | }; | ||
| 1172 | #endif | ||
| 1173 | |||
| 1174 | static const struct i2c_device_id mxt_id[] = { | ||
| 1175 | { "qt602240_ts", 0 }, | ||
| 1176 | { "atmel_mxt_ts", 0 }, | ||
| 1177 | { "mXT224", 0 }, | ||
| 1178 | { } | ||
| 1179 | }; | ||
| 1180 | MODULE_DEVICE_TABLE(i2c, mxt_id); | ||
| 1181 | |||
| 1182 | static struct i2c_driver mxt_driver = { | ||
| 1183 | .driver = { | ||
| 1184 | .name = "atmel_mxt_ts", | ||
| 1185 | .owner = THIS_MODULE, | ||
| 1186 | #ifdef CONFIG_PM | ||
| 1187 | .pm = &mxt_pm_ops, | ||
| 1188 | #endif | ||
| 1189 | }, | ||
| 1190 | .probe = mxt_probe, | ||
| 1191 | .remove = __devexit_p(mxt_remove), | ||
| 1192 | .id_table = mxt_id, | ||
| 1193 | }; | ||
| 1194 | |||
| 1195 | static int __init mxt_init(void) | ||
| 1196 | { | ||
| 1197 | return i2c_add_driver(&mxt_driver); | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | static void __exit mxt_exit(void) | ||
| 1201 | { | ||
| 1202 | i2c_del_driver(&mxt_driver); | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | module_init(mxt_init); | ||
| 1206 | module_exit(mxt_exit); | ||
| 1207 | |||
| 1208 | /* Module information */ | ||
| 1209 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | ||
| 1210 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); | ||
| 1211 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/qt602240_ts.c b/drivers/input/touchscreen/qt602240_ts.c deleted file mode 100644 index 4dcb0e872f6a..000000000000 --- a/drivers/input/touchscreen/qt602240_ts.c +++ /dev/null | |||
| @@ -1,1406 +0,0 @@ | |||
| 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 */ | ||
| 203 | static 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 | |||
| 241 | static 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 | |||
| 279 | static 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 | |||
| 318 | struct 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 | |||
| 328 | struct 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 | |||
| 339 | struct qt602240_message { | ||
| 340 | u8 reportid; | ||
| 341 | u8 message[7]; | ||
| 342 | u8 checksum; | ||
| 343 | }; | ||
| 344 | |||
| 345 | struct qt602240_finger { | ||
| 346 | int status; | ||
| 347 | int x; | ||
| 348 | int y; | ||
| 349 | int area; | ||
| 350 | }; | ||
| 351 | |||
| 352 | /* Each client has this additional data */ | ||
| 353 | struct 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 | |||
| 363 | static 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 | |||
| 388 | static 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 | |||
| 410 | static 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 | |||
| 424 | static int qt602240_check_bootloader(struct i2c_client *client, | ||
| 425 | unsigned int state) | ||
| 426 | { | ||
| 427 | u8 val; | ||
| 428 | |||
| 429 | recheck: | ||
| 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 | |||
| 456 | static 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 | |||
| 471 | static 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 | |||
| 482 | static 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 | |||
| 511 | static int qt602240_read_reg(struct i2c_client *client, u16 reg, u8 *val) | ||
| 512 | { | ||
| 513 | return __qt602240_read_reg(client, reg, 1, val); | ||
| 514 | } | ||
| 515 | |||
| 516 | static 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 | |||
| 532 | static 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 | |||
| 539 | static struct qt602240_object * | ||
| 540 | qt602240_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 | |||
| 555 | static 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 | |||
| 570 | static 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 | |||
| 584 | static 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 | |||
| 598 | static 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 | |||
| 635 | static 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 | |||
| 677 | static 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 | |||
| 711 | end: | ||
| 712 | return IRQ_HANDLED; | ||
| 713 | } | ||
| 714 | |||
| 715 | static 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 | |||
| 755 | static 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 | |||
| 823 | static 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 | |||
| 845 | static 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 | |||
| 893 | static 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 | |||
| 928 | static 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 | |||
| 960 | static 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_object), | ||
| 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 | |||
| 1035 | static 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 | |||
| 1073 | static 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 | |||
| 1132 | out: | ||
| 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 | |||
| 1144 | static 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 | |||
| 1185 | static DEVICE_ATTR(object, 0444, qt602240_object_show, NULL); | ||
| 1186 | static DEVICE_ATTR(update_fw, 0664, NULL, qt602240_update_fw_store); | ||
| 1187 | |||
| 1188 | static struct attribute *qt602240_attrs[] = { | ||
| 1189 | &dev_attr_object.attr, | ||
| 1190 | &dev_attr_update_fw.attr, | ||
| 1191 | NULL | ||
| 1192 | }; | ||
| 1193 | |||
| 1194 | static const struct attribute_group qt602240_attr_group = { | ||
| 1195 | .attrs = qt602240_attrs, | ||
| 1196 | }; | ||
| 1197 | |||
| 1198 | static 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 | |||
| 1205 | static 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 | |||
| 1212 | static 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 | |||
| 1221 | static 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 | |||
| 1228 | static 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 | |||
| 1300 | err_unregister_device: | ||
| 1301 | input_unregister_device(input_dev); | ||
| 1302 | input_dev = NULL; | ||
| 1303 | err_free_irq: | ||
| 1304 | free_irq(client->irq, data); | ||
| 1305 | err_free_object: | ||
| 1306 | kfree(data->object_table); | ||
| 1307 | err_free_mem: | ||
| 1308 | input_free_device(input_dev); | ||
| 1309 | kfree(data); | ||
| 1310 | return error; | ||
| 1311 | } | ||
| 1312 | |||
| 1313 | static 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 | ||
| 1327 | static int qt602240_suspend(struct device *dev) | ||
| 1328 | { | ||
| 1329 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1330 | struct qt602240_data *data = i2c_get_clientdata(client); | ||
| 1331 | struct input_dev *input_dev = data->input_dev; | ||
| 1332 | |||
| 1333 | mutex_lock(&input_dev->mutex); | ||
| 1334 | |||
| 1335 | if (input_dev->users) | ||
| 1336 | qt602240_stop(data); | ||
| 1337 | |||
| 1338 | mutex_unlock(&input_dev->mutex); | ||
| 1339 | |||
| 1340 | return 0; | ||
| 1341 | } | ||
| 1342 | |||
| 1343 | static int qt602240_resume(struct device *dev) | ||
| 1344 | { | ||
| 1345 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1346 | struct qt602240_data *data = i2c_get_clientdata(client); | ||
| 1347 | struct input_dev *input_dev = data->input_dev; | ||
| 1348 | |||
| 1349 | /* Soft reset */ | ||
| 1350 | qt602240_write_object(data, QT602240_GEN_COMMAND, | ||
| 1351 | QT602240_COMMAND_RESET, 1); | ||
| 1352 | |||
| 1353 | msleep(QT602240_RESET_TIME); | ||
| 1354 | |||
| 1355 | mutex_lock(&input_dev->mutex); | ||
| 1356 | |||
| 1357 | if (input_dev->users) | ||
| 1358 | qt602240_start(data); | ||
| 1359 | |||
| 1360 | mutex_unlock(&input_dev->mutex); | ||
| 1361 | |||
| 1362 | return 0; | ||
| 1363 | } | ||
| 1364 | |||
| 1365 | static const struct dev_pm_ops qt602240_pm_ops = { | ||
| 1366 | .suspend = qt602240_suspend, | ||
| 1367 | .resume = qt602240_resume, | ||
| 1368 | }; | ||
| 1369 | #endif | ||
| 1370 | |||
| 1371 | static const struct i2c_device_id qt602240_id[] = { | ||
| 1372 | { "qt602240_ts", 0 }, | ||
| 1373 | { } | ||
| 1374 | }; | ||
| 1375 | MODULE_DEVICE_TABLE(i2c, qt602240_id); | ||
| 1376 | |||
| 1377 | static struct i2c_driver qt602240_driver = { | ||
| 1378 | .driver = { | ||
| 1379 | .name = "qt602240_ts", | ||
| 1380 | .owner = THIS_MODULE, | ||
| 1381 | #ifdef CONFIG_PM | ||
| 1382 | .pm = &qt602240_pm_ops, | ||
| 1383 | #endif | ||
| 1384 | }, | ||
| 1385 | .probe = qt602240_probe, | ||
| 1386 | .remove = __devexit_p(qt602240_remove), | ||
| 1387 | .id_table = qt602240_id, | ||
| 1388 | }; | ||
| 1389 | |||
| 1390 | static int __init qt602240_init(void) | ||
| 1391 | { | ||
| 1392 | return i2c_add_driver(&qt602240_driver); | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | static void __exit qt602240_exit(void) | ||
| 1396 | { | ||
| 1397 | i2c_del_driver(&qt602240_driver); | ||
| 1398 | } | ||
| 1399 | |||
| 1400 | module_init(qt602240_init); | ||
| 1401 | module_exit(qt602240_exit); | ||
| 1402 | |||
| 1403 | /* Module information */ | ||
| 1404 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | ||
| 1405 | MODULE_DESCRIPTION("AT42QT602240/ATMXT224 Touchscreen driver"); | ||
| 1406 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c new file mode 100644 index 000000000000..87420616efa4 --- /dev/null +++ b/drivers/input/touchscreen/tsc2005.c | |||
| @@ -0,0 +1,756 @@ | |||
| 1 | /* | ||
| 2 | * TSC2005 touchscreen driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2006-2010 Nokia Corporation | ||
| 5 | * | ||
| 6 | * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com> | ||
| 7 | * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com> | ||
| 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, write to the Free Software | ||
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | * | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <linux/kernel.h> | ||
| 26 | #include <linux/module.h> | ||
| 27 | #include <linux/input.h> | ||
| 28 | #include <linux/interrupt.h> | ||
| 29 | #include <linux/delay.h> | ||
| 30 | #include <linux/pm.h> | ||
| 31 | #include <linux/spi/spi.h> | ||
| 32 | #include <linux/spi/tsc2005.h> | ||
| 33 | |||
| 34 | /* | ||
| 35 | * The touchscreen interface operates as follows: | ||
| 36 | * | ||
| 37 | * 1) Pen is pressed against the touchscreen. | ||
| 38 | * 2) TSC2005 performs AD conversion. | ||
| 39 | * 3) After the conversion is done TSC2005 drives DAV line down. | ||
| 40 | * 4) GPIO IRQ is received and tsc2005_irq_thread() is scheduled. | ||
| 41 | * 5) tsc2005_irq_thread() queues up an spi transfer to fetch the x, y, z1, z2 | ||
| 42 | * values. | ||
| 43 | * 6) tsc2005_irq_thread() reports coordinates to input layer and sets up | ||
| 44 | * tsc2005_penup_timer() to be called after TSC2005_PENUP_TIME_MS (40ms). | ||
| 45 | * 7) When the penup timer expires, there have not been touch or DAV interrupts | ||
| 46 | * during the last 40ms which means the pen has been lifted. | ||
| 47 | * | ||
| 48 | * ESD recovery via a hardware reset is done if the TSC2005 doesn't respond | ||
| 49 | * after a configurable period (in ms) of activity. If esd_timeout is 0, the | ||
| 50 | * watchdog is disabled. | ||
| 51 | */ | ||
| 52 | |||
| 53 | /* control byte 1 */ | ||
| 54 | #define TSC2005_CMD 0x80 | ||
| 55 | #define TSC2005_CMD_NORMAL 0x00 | ||
| 56 | #define TSC2005_CMD_STOP 0x01 | ||
| 57 | #define TSC2005_CMD_12BIT 0x04 | ||
| 58 | |||
| 59 | /* control byte 0 */ | ||
| 60 | #define TSC2005_REG_READ 0x0001 | ||
| 61 | #define TSC2005_REG_PND0 0x0002 | ||
| 62 | #define TSC2005_REG_X 0x0000 | ||
| 63 | #define TSC2005_REG_Y 0x0008 | ||
| 64 | #define TSC2005_REG_Z1 0x0010 | ||
| 65 | #define TSC2005_REG_Z2 0x0018 | ||
| 66 | #define TSC2005_REG_TEMP_HIGH 0x0050 | ||
| 67 | #define TSC2005_REG_CFR0 0x0060 | ||
| 68 | #define TSC2005_REG_CFR1 0x0068 | ||
| 69 | #define TSC2005_REG_CFR2 0x0070 | ||
| 70 | |||
| 71 | /* configuration register 0 */ | ||
| 72 | #define TSC2005_CFR0_PRECHARGE_276US 0x0040 | ||
| 73 | #define TSC2005_CFR0_STABTIME_1MS 0x0300 | ||
| 74 | #define TSC2005_CFR0_CLOCK_1MHZ 0x1000 | ||
| 75 | #define TSC2005_CFR0_RESOLUTION12 0x2000 | ||
| 76 | #define TSC2005_CFR0_PENMODE 0x8000 | ||
| 77 | #define TSC2005_CFR0_INITVALUE (TSC2005_CFR0_STABTIME_1MS | \ | ||
| 78 | TSC2005_CFR0_CLOCK_1MHZ | \ | ||
| 79 | TSC2005_CFR0_RESOLUTION12 | \ | ||
| 80 | TSC2005_CFR0_PRECHARGE_276US | \ | ||
| 81 | TSC2005_CFR0_PENMODE) | ||
| 82 | |||
| 83 | /* bits common to both read and write of configuration register 0 */ | ||
| 84 | #define TSC2005_CFR0_RW_MASK 0x3fff | ||
| 85 | |||
| 86 | /* configuration register 1 */ | ||
| 87 | #define TSC2005_CFR1_BATCHDELAY_4MS 0x0003 | ||
| 88 | #define TSC2005_CFR1_INITVALUE TSC2005_CFR1_BATCHDELAY_4MS | ||
| 89 | |||
| 90 | /* configuration register 2 */ | ||
| 91 | #define TSC2005_CFR2_MAVE_Z 0x0004 | ||
| 92 | #define TSC2005_CFR2_MAVE_Y 0x0008 | ||
| 93 | #define TSC2005_CFR2_MAVE_X 0x0010 | ||
| 94 | #define TSC2005_CFR2_AVG_7 0x0800 | ||
| 95 | #define TSC2005_CFR2_MEDIUM_15 0x3000 | ||
| 96 | #define TSC2005_CFR2_INITVALUE (TSC2005_CFR2_MAVE_X | \ | ||
| 97 | TSC2005_CFR2_MAVE_Y | \ | ||
| 98 | TSC2005_CFR2_MAVE_Z | \ | ||
| 99 | TSC2005_CFR2_MEDIUM_15 | \ | ||
| 100 | TSC2005_CFR2_AVG_7) | ||
| 101 | |||
| 102 | #define MAX_12BIT 0xfff | ||
| 103 | #define TSC2005_SPI_MAX_SPEED_HZ 10000000 | ||
| 104 | #define TSC2005_PENUP_TIME_MS 40 | ||
| 105 | |||
| 106 | struct tsc2005_spi_rd { | ||
| 107 | struct spi_transfer spi_xfer; | ||
| 108 | u32 spi_tx; | ||
| 109 | u32 spi_rx; | ||
| 110 | }; | ||
| 111 | |||
| 112 | struct tsc2005 { | ||
| 113 | struct spi_device *spi; | ||
| 114 | |||
| 115 | struct spi_message spi_read_msg; | ||
| 116 | struct tsc2005_spi_rd spi_x; | ||
| 117 | struct tsc2005_spi_rd spi_y; | ||
| 118 | struct tsc2005_spi_rd spi_z1; | ||
| 119 | struct tsc2005_spi_rd spi_z2; | ||
| 120 | |||
| 121 | struct input_dev *idev; | ||
| 122 | char phys[32]; | ||
| 123 | |||
| 124 | struct mutex mutex; | ||
| 125 | |||
| 126 | /* raw copy of previous x,y,z */ | ||
| 127 | int in_x; | ||
| 128 | int in_y; | ||
| 129 | int in_z1; | ||
| 130 | int in_z2; | ||
| 131 | |||
| 132 | spinlock_t lock; | ||
| 133 | struct timer_list penup_timer; | ||
| 134 | |||
| 135 | unsigned int esd_timeout; | ||
| 136 | struct delayed_work esd_work; | ||
| 137 | unsigned long last_valid_interrupt; | ||
| 138 | |||
| 139 | unsigned int x_plate_ohm; | ||
| 140 | |||
| 141 | bool opened; | ||
| 142 | bool suspended; | ||
| 143 | |||
| 144 | bool pen_down; | ||
| 145 | |||
| 146 | void (*set_reset)(bool enable); | ||
| 147 | }; | ||
| 148 | |||
| 149 | static int tsc2005_cmd(struct tsc2005 *ts, u8 cmd) | ||
| 150 | { | ||
| 151 | u8 tx = TSC2005_CMD | TSC2005_CMD_12BIT | cmd; | ||
| 152 | struct spi_transfer xfer = { | ||
| 153 | .tx_buf = &tx, | ||
| 154 | .len = 1, | ||
| 155 | .bits_per_word = 8, | ||
| 156 | }; | ||
| 157 | struct spi_message msg; | ||
| 158 | int error; | ||
| 159 | |||
| 160 | spi_message_init(&msg); | ||
| 161 | spi_message_add_tail(&xfer, &msg); | ||
| 162 | |||
| 163 | error = spi_sync(ts->spi, &msg); | ||
| 164 | if (error) { | ||
| 165 | dev_err(&ts->spi->dev, "%s: failed, command: %x, error: %d\n", | ||
| 166 | __func__, cmd, error); | ||
| 167 | return error; | ||
| 168 | } | ||
| 169 | |||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | |||
| 173 | static int tsc2005_write(struct tsc2005 *ts, u8 reg, u16 value) | ||
| 174 | { | ||
| 175 | u32 tx = ((reg | TSC2005_REG_PND0) << 16) | value; | ||
| 176 | struct spi_transfer xfer = { | ||
| 177 | .tx_buf = &tx, | ||
| 178 | .len = 4, | ||
| 179 | .bits_per_word = 24, | ||
| 180 | }; | ||
| 181 | struct spi_message msg; | ||
| 182 | int error; | ||
| 183 | |||
| 184 | spi_message_init(&msg); | ||
| 185 | spi_message_add_tail(&xfer, &msg); | ||
| 186 | |||
| 187 | error = spi_sync(ts->spi, &msg); | ||
| 188 | if (error) { | ||
| 189 | dev_err(&ts->spi->dev, | ||
| 190 | "%s: failed, register: %x, value: %x, error: %d\n", | ||
| 191 | __func__, reg, value, error); | ||
| 192 | return error; | ||
| 193 | } | ||
| 194 | |||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | static void tsc2005_setup_read(struct tsc2005_spi_rd *rd, u8 reg, bool last) | ||
| 199 | { | ||
| 200 | memset(rd, 0, sizeof(*rd)); | ||
| 201 | |||
| 202 | rd->spi_tx = (reg | TSC2005_REG_READ) << 16; | ||
| 203 | rd->spi_xfer.tx_buf = &rd->spi_tx; | ||
| 204 | rd->spi_xfer.rx_buf = &rd->spi_rx; | ||
| 205 | rd->spi_xfer.len = 4; | ||
| 206 | rd->spi_xfer.bits_per_word = 24; | ||
| 207 | rd->spi_xfer.cs_change = !last; | ||
| 208 | } | ||
| 209 | |||
| 210 | static int tsc2005_read(struct tsc2005 *ts, u8 reg, u16 *value) | ||
| 211 | { | ||
| 212 | struct tsc2005_spi_rd spi_rd; | ||
| 213 | struct spi_message msg; | ||
| 214 | int error; | ||
| 215 | |||
| 216 | tsc2005_setup_read(&spi_rd, reg, true); | ||
| 217 | |||
| 218 | spi_message_init(&msg); | ||
| 219 | spi_message_add_tail(&spi_rd.spi_xfer, &msg); | ||
| 220 | |||
| 221 | error = spi_sync(ts->spi, &msg); | ||
| 222 | if (error) | ||
| 223 | return error; | ||
| 224 | |||
| 225 | *value = spi_rd.spi_rx; | ||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | |||
| 229 | static void tsc2005_update_pen_state(struct tsc2005 *ts, | ||
| 230 | int x, int y, int pressure) | ||
| 231 | { | ||
| 232 | if (pressure) { | ||
| 233 | input_report_abs(ts->idev, ABS_X, x); | ||
| 234 | input_report_abs(ts->idev, ABS_Y, y); | ||
| 235 | input_report_abs(ts->idev, ABS_PRESSURE, pressure); | ||
| 236 | if (!ts->pen_down) { | ||
| 237 | input_report_key(ts->idev, BTN_TOUCH, !!pressure); | ||
| 238 | ts->pen_down = true; | ||
| 239 | } | ||
| 240 | } else { | ||
| 241 | input_report_abs(ts->idev, ABS_PRESSURE, 0); | ||
| 242 | if (ts->pen_down) { | ||
| 243 | input_report_key(ts->idev, BTN_TOUCH, 0); | ||
| 244 | ts->pen_down = false; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | input_sync(ts->idev); | ||
| 248 | dev_dbg(&ts->spi->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, | ||
| 249 | pressure); | ||
| 250 | } | ||
| 251 | |||
| 252 | static irqreturn_t tsc2005_irq_thread(int irq, void *_ts) | ||
| 253 | { | ||
| 254 | struct tsc2005 *ts = _ts; | ||
| 255 | unsigned long flags; | ||
| 256 | unsigned int pressure; | ||
| 257 | u32 x, y; | ||
| 258 | u32 z1, z2; | ||
| 259 | int error; | ||
| 260 | |||
| 261 | /* read the coordinates */ | ||
| 262 | error = spi_sync(ts->spi, &ts->spi_read_msg); | ||
| 263 | if (unlikely(error)) | ||
| 264 | goto out; | ||
| 265 | |||
| 266 | x = ts->spi_x.spi_rx; | ||
| 267 | y = ts->spi_y.spi_rx; | ||
| 268 | z1 = ts->spi_z1.spi_rx; | ||
| 269 | z2 = ts->spi_z2.spi_rx; | ||
| 270 | |||
| 271 | /* validate position */ | ||
| 272 | if (unlikely(x > MAX_12BIT || y > MAX_12BIT)) | ||
| 273 | goto out; | ||
| 274 | |||
| 275 | /* Skip reading if the pressure components are out of range */ | ||
| 276 | if (unlikely(z1 == 0 || z2 > MAX_12BIT || z1 >= z2)) | ||
| 277 | goto out; | ||
| 278 | |||
| 279 | /* | ||
| 280 | * Skip point if this is a pen down with the exact same values as | ||
| 281 | * the value before pen-up - that implies SPI fed us stale data | ||
| 282 | */ | ||
| 283 | if (!ts->pen_down && | ||
| 284 | ts->in_x == x && ts->in_y == y && | ||
| 285 | ts->in_z1 == z1 && ts->in_z2 == z2) { | ||
| 286 | goto out; | ||
| 287 | } | ||
| 288 | |||
| 289 | /* | ||
| 290 | * At this point we are happy we have a valid and useful reading. | ||
| 291 | * Remember it for later comparisons. We may now begin downsampling. | ||
| 292 | */ | ||
| 293 | ts->in_x = x; | ||
| 294 | ts->in_y = y; | ||
| 295 | ts->in_z1 = z1; | ||
| 296 | ts->in_z2 = z2; | ||
| 297 | |||
| 298 | /* Compute touch pressure resistance using equation #1 */ | ||
| 299 | pressure = x * (z2 - z1) / z1; | ||
| 300 | pressure = pressure * ts->x_plate_ohm / 4096; | ||
| 301 | if (unlikely(pressure > MAX_12BIT)) | ||
| 302 | goto out; | ||
| 303 | |||
| 304 | spin_lock_irqsave(&ts->lock, flags); | ||
| 305 | |||
| 306 | tsc2005_update_pen_state(ts, x, y, pressure); | ||
| 307 | mod_timer(&ts->penup_timer, | ||
| 308 | jiffies + msecs_to_jiffies(TSC2005_PENUP_TIME_MS)); | ||
| 309 | |||
| 310 | spin_unlock_irqrestore(&ts->lock, flags); | ||
| 311 | |||
| 312 | ts->last_valid_interrupt = jiffies; | ||
| 313 | out: | ||
| 314 | return IRQ_HANDLED; | ||
| 315 | } | ||
| 316 | |||
| 317 | static void tsc2005_penup_timer(unsigned long data) | ||
| 318 | { | ||
| 319 | struct tsc2005 *ts = (struct tsc2005 *)data; | ||
| 320 | unsigned long flags; | ||
| 321 | |||
| 322 | spin_lock_irqsave(&ts->lock, flags); | ||
| 323 | tsc2005_update_pen_state(ts, 0, 0, 0); | ||
| 324 | spin_unlock_irqrestore(&ts->lock, flags); | ||
| 325 | } | ||
| 326 | |||
| 327 | static void tsc2005_start_scan(struct tsc2005 *ts) | ||
| 328 | { | ||
| 329 | tsc2005_write(ts, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE); | ||
| 330 | tsc2005_write(ts, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE); | ||
| 331 | tsc2005_write(ts, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE); | ||
| 332 | tsc2005_cmd(ts, TSC2005_CMD_NORMAL); | ||
| 333 | } | ||
| 334 | |||
| 335 | static void tsc2005_stop_scan(struct tsc2005 *ts) | ||
| 336 | { | ||
| 337 | tsc2005_cmd(ts, TSC2005_CMD_STOP); | ||
| 338 | } | ||
| 339 | |||
| 340 | /* must be called with ts->mutex held */ | ||
| 341 | static void __tsc2005_disable(struct tsc2005 *ts) | ||
| 342 | { | ||
| 343 | tsc2005_stop_scan(ts); | ||
| 344 | |||
| 345 | disable_irq(ts->spi->irq); | ||
| 346 | del_timer_sync(&ts->penup_timer); | ||
| 347 | |||
| 348 | cancel_delayed_work_sync(&ts->esd_work); | ||
| 349 | |||
| 350 | enable_irq(ts->spi->irq); | ||
| 351 | } | ||
| 352 | |||
| 353 | /* must be called with ts->mutex held */ | ||
| 354 | static void __tsc2005_enable(struct tsc2005 *ts) | ||
| 355 | { | ||
| 356 | tsc2005_start_scan(ts); | ||
| 357 | |||
| 358 | if (ts->esd_timeout && ts->set_reset) { | ||
| 359 | ts->last_valid_interrupt = jiffies; | ||
| 360 | schedule_delayed_work(&ts->esd_work, | ||
| 361 | round_jiffies(jiffies + | ||
| 362 | msecs_to_jiffies(ts->esd_timeout))); | ||
| 363 | } | ||
| 364 | |||
| 365 | } | ||
| 366 | |||
| 367 | static ssize_t tsc2005_selftest_show(struct device *dev, | ||
| 368 | struct device_attribute *attr, | ||
| 369 | char *buf) | ||
| 370 | { | ||
| 371 | struct spi_device *spi = to_spi_device(dev); | ||
| 372 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 373 | u16 temp_high; | ||
| 374 | u16 temp_high_orig; | ||
| 375 | u16 temp_high_test; | ||
| 376 | bool success = true; | ||
| 377 | int error; | ||
| 378 | |||
| 379 | mutex_lock(&ts->mutex); | ||
| 380 | |||
| 381 | /* | ||
| 382 | * Test TSC2005 communications via temp high register. | ||
| 383 | */ | ||
| 384 | __tsc2005_disable(ts); | ||
| 385 | |||
| 386 | error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig); | ||
| 387 | if (error) { | ||
| 388 | dev_warn(dev, "selftest failed: read error %d\n", error); | ||
| 389 | success = false; | ||
| 390 | goto out; | ||
| 391 | } | ||
| 392 | |||
| 393 | temp_high_test = (temp_high_orig - 1) & MAX_12BIT; | ||
| 394 | |||
| 395 | error = tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test); | ||
| 396 | if (error) { | ||
| 397 | dev_warn(dev, "selftest failed: write error %d\n", error); | ||
| 398 | success = false; | ||
| 399 | goto out; | ||
| 400 | } | ||
| 401 | |||
| 402 | error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high); | ||
| 403 | if (error) { | ||
| 404 | dev_warn(dev, "selftest failed: read error %d after write\n", | ||
| 405 | error); | ||
| 406 | success = false; | ||
| 407 | goto out; | ||
| 408 | } | ||
| 409 | |||
| 410 | if (temp_high != temp_high_test) { | ||
| 411 | dev_warn(dev, "selftest failed: %d != %d\n", | ||
| 412 | temp_high, temp_high_test); | ||
| 413 | success = false; | ||
| 414 | } | ||
| 415 | |||
| 416 | /* hardware reset */ | ||
| 417 | ts->set_reset(false); | ||
| 418 | usleep_range(100, 500); /* only 10us required */ | ||
| 419 | ts->set_reset(true); | ||
| 420 | |||
| 421 | if (!success) | ||
| 422 | goto out; | ||
| 423 | |||
| 424 | /* test that the reset really happened */ | ||
| 425 | error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high); | ||
| 426 | if (error) { | ||
| 427 | dev_warn(dev, "selftest failed: read error %d after reset\n", | ||
| 428 | error); | ||
| 429 | success = false; | ||
| 430 | goto out; | ||
| 431 | } | ||
| 432 | |||
| 433 | if (temp_high != temp_high_orig) { | ||
| 434 | dev_warn(dev, "selftest failed after reset: %d != %d\n", | ||
| 435 | temp_high, temp_high_orig); | ||
| 436 | success = false; | ||
| 437 | } | ||
| 438 | |||
| 439 | out: | ||
| 440 | __tsc2005_enable(ts); | ||
| 441 | mutex_unlock(&ts->mutex); | ||
| 442 | |||
| 443 | return sprintf(buf, "%d\n", success); | ||
| 444 | } | ||
| 445 | |||
| 446 | static DEVICE_ATTR(selftest, S_IRUGO, tsc2005_selftest_show, NULL); | ||
| 447 | |||
| 448 | static struct attribute *tsc2005_attrs[] = { | ||
| 449 | &dev_attr_selftest.attr, | ||
| 450 | NULL | ||
| 451 | }; | ||
| 452 | |||
| 453 | static mode_t tsc2005_attr_is_visible(struct kobject *kobj, | ||
| 454 | struct attribute *attr, int n) | ||
| 455 | { | ||
| 456 | struct device *dev = container_of(kobj, struct device, kobj); | ||
| 457 | struct spi_device *spi = to_spi_device(dev); | ||
| 458 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 459 | mode_t mode = attr->mode; | ||
| 460 | |||
| 461 | if (attr == &dev_attr_selftest.attr) { | ||
| 462 | if (!ts->set_reset) | ||
| 463 | mode = 0; | ||
| 464 | } | ||
| 465 | |||
| 466 | return mode; | ||
| 467 | } | ||
| 468 | |||
| 469 | static const struct attribute_group tsc2005_attr_group = { | ||
| 470 | .is_visible = tsc2005_attr_is_visible, | ||
| 471 | .attrs = tsc2005_attrs, | ||
| 472 | }; | ||
| 473 | |||
| 474 | static void tsc2005_esd_work(struct work_struct *work) | ||
| 475 | { | ||
| 476 | struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work.work); | ||
| 477 | int error; | ||
| 478 | u16 r; | ||
| 479 | |||
| 480 | mutex_lock(&ts->mutex); | ||
| 481 | |||
| 482 | if (time_is_after_jiffies(ts->last_valid_interrupt + | ||
| 483 | msecs_to_jiffies(ts->esd_timeout))) | ||
| 484 | goto out; | ||
| 485 | |||
| 486 | /* We should be able to read register without disabling interrupts. */ | ||
| 487 | error = tsc2005_read(ts, TSC2005_REG_CFR0, &r); | ||
| 488 | if (!error && | ||
| 489 | !((r ^ TSC2005_CFR0_INITVALUE) & TSC2005_CFR0_RW_MASK)) { | ||
| 490 | goto out; | ||
| 491 | } | ||
| 492 | |||
| 493 | /* | ||
| 494 | * If we could not read our known value from configuration register 0 | ||
| 495 | * then we should reset the controller as if from power-up and start | ||
| 496 | * scanning again. | ||
| 497 | */ | ||
| 498 | dev_info(&ts->spi->dev, "TSC2005 not responding - resetting\n"); | ||
| 499 | |||
| 500 | disable_irq(ts->spi->irq); | ||
| 501 | del_timer_sync(&ts->penup_timer); | ||
| 502 | |||
| 503 | tsc2005_update_pen_state(ts, 0, 0, 0); | ||
| 504 | |||
| 505 | ts->set_reset(false); | ||
| 506 | usleep_range(100, 500); /* only 10us required */ | ||
| 507 | ts->set_reset(true); | ||
| 508 | |||
| 509 | enable_irq(ts->spi->irq); | ||
| 510 | tsc2005_start_scan(ts); | ||
| 511 | |||
| 512 | out: | ||
| 513 | /* re-arm the watchdog */ | ||
| 514 | schedule_delayed_work(&ts->esd_work, | ||
| 515 | round_jiffies(jiffies + | ||
| 516 | msecs_to_jiffies(ts->esd_timeout))); | ||
| 517 | mutex_unlock(&ts->mutex); | ||
| 518 | } | ||
| 519 | |||
| 520 | static int tsc2005_open(struct input_dev *input) | ||
| 521 | { | ||
| 522 | struct tsc2005 *ts = input_get_drvdata(input); | ||
| 523 | |||
| 524 | mutex_lock(&ts->mutex); | ||
| 525 | |||
| 526 | if (!ts->suspended) | ||
| 527 | __tsc2005_enable(ts); | ||
| 528 | |||
| 529 | ts->opened = true; | ||
| 530 | |||
| 531 | mutex_unlock(&ts->mutex); | ||
| 532 | |||
| 533 | return 0; | ||
| 534 | } | ||
| 535 | |||
| 536 | static void tsc2005_close(struct input_dev *input) | ||
| 537 | { | ||
| 538 | struct tsc2005 *ts = input_get_drvdata(input); | ||
| 539 | |||
| 540 | mutex_lock(&ts->mutex); | ||
| 541 | |||
| 542 | if (!ts->suspended) | ||
| 543 | __tsc2005_disable(ts); | ||
| 544 | |||
| 545 | ts->opened = false; | ||
| 546 | |||
| 547 | mutex_unlock(&ts->mutex); | ||
| 548 | } | ||
| 549 | |||
| 550 | static void __devinit tsc2005_setup_spi_xfer(struct tsc2005 *ts) | ||
| 551 | { | ||
| 552 | tsc2005_setup_read(&ts->spi_x, TSC2005_REG_X, false); | ||
| 553 | tsc2005_setup_read(&ts->spi_y, TSC2005_REG_Y, false); | ||
| 554 | tsc2005_setup_read(&ts->spi_z1, TSC2005_REG_Z1, false); | ||
| 555 | tsc2005_setup_read(&ts->spi_z2, TSC2005_REG_Z2, true); | ||
| 556 | |||
| 557 | spi_message_init(&ts->spi_read_msg); | ||
| 558 | spi_message_add_tail(&ts->spi_x.spi_xfer, &ts->spi_read_msg); | ||
| 559 | spi_message_add_tail(&ts->spi_y.spi_xfer, &ts->spi_read_msg); | ||
| 560 | spi_message_add_tail(&ts->spi_z1.spi_xfer, &ts->spi_read_msg); | ||
| 561 | spi_message_add_tail(&ts->spi_z2.spi_xfer, &ts->spi_read_msg); | ||
| 562 | } | ||
| 563 | |||
| 564 | static int __devinit tsc2005_probe(struct spi_device *spi) | ||
| 565 | { | ||
| 566 | const struct tsc2005_platform_data *pdata = spi->dev.platform_data; | ||
| 567 | struct tsc2005 *ts; | ||
| 568 | struct input_dev *input_dev; | ||
| 569 | unsigned int max_x, max_y, max_p; | ||
| 570 | unsigned int fudge_x, fudge_y, fudge_p; | ||
| 571 | int error; | ||
| 572 | |||
| 573 | if (!pdata) { | ||
| 574 | dev_dbg(&spi->dev, "no platform data\n"); | ||
| 575 | return -ENODEV; | ||
| 576 | } | ||
| 577 | |||
| 578 | fudge_x = pdata->ts_x_fudge ? : 4; | ||
| 579 | fudge_y = pdata->ts_y_fudge ? : 8; | ||
| 580 | fudge_p = pdata->ts_pressure_fudge ? : 2; | ||
| 581 | max_x = pdata->ts_x_max ? : MAX_12BIT; | ||
| 582 | max_y = pdata->ts_y_max ? : MAX_12BIT; | ||
| 583 | max_p = pdata->ts_pressure_max ? : MAX_12BIT; | ||
| 584 | |||
| 585 | if (spi->irq <= 0) { | ||
| 586 | dev_dbg(&spi->dev, "no irq\n"); | ||
| 587 | return -ENODEV; | ||
| 588 | } | ||
| 589 | |||
| 590 | spi->mode = SPI_MODE_0; | ||
| 591 | spi->bits_per_word = 8; | ||
| 592 | if (!spi->max_speed_hz) | ||
| 593 | spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ; | ||
| 594 | |||
| 595 | error = spi_setup(spi); | ||
| 596 | if (error) | ||
| 597 | return error; | ||
| 598 | |||
| 599 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); | ||
| 600 | input_dev = input_allocate_device(); | ||
| 601 | if (!ts || !input_dev) { | ||
| 602 | error = -ENOMEM; | ||
| 603 | goto err_free_mem; | ||
| 604 | } | ||
| 605 | |||
| 606 | ts->spi = spi; | ||
| 607 | ts->idev = input_dev; | ||
| 608 | |||
| 609 | ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280; | ||
| 610 | ts->esd_timeout = pdata->esd_timeout_ms; | ||
| 611 | ts->set_reset = pdata->set_reset; | ||
| 612 | |||
| 613 | mutex_init(&ts->mutex); | ||
| 614 | |||
| 615 | spin_lock_init(&ts->lock); | ||
| 616 | setup_timer(&ts->penup_timer, tsc2005_penup_timer, (unsigned long)ts); | ||
| 617 | |||
| 618 | INIT_DELAYED_WORK(&ts->esd_work, tsc2005_esd_work); | ||
| 619 | |||
| 620 | tsc2005_setup_spi_xfer(ts); | ||
| 621 | |||
| 622 | snprintf(ts->phys, sizeof(ts->phys), | ||
| 623 | "%s/input-ts", dev_name(&spi->dev)); | ||
| 624 | |||
| 625 | input_dev->name = "TSC2005 touchscreen"; | ||
| 626 | input_dev->phys = ts->phys; | ||
| 627 | input_dev->id.bustype = BUS_SPI; | ||
| 628 | input_dev->dev.parent = &spi->dev; | ||
| 629 | input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); | ||
| 630 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
| 631 | |||
| 632 | input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0); | ||
| 633 | input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0); | ||
| 634 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0); | ||
| 635 | |||
| 636 | input_dev->open = tsc2005_open; | ||
| 637 | input_dev->close = tsc2005_close; | ||
| 638 | |||
| 639 | input_set_drvdata(input_dev, ts); | ||
| 640 | |||
| 641 | /* Ensure the touchscreen is off */ | ||
| 642 | tsc2005_stop_scan(ts); | ||
| 643 | |||
| 644 | error = request_threaded_irq(spi->irq, NULL, tsc2005_irq_thread, | ||
| 645 | IRQF_TRIGGER_RISING, "tsc2005", ts); | ||
| 646 | if (error) { | ||
| 647 | dev_err(&spi->dev, "Failed to request irq, err: %d\n", error); | ||
| 648 | goto err_free_mem; | ||
| 649 | } | ||
| 650 | |||
| 651 | spi_set_drvdata(spi, ts); | ||
| 652 | error = sysfs_create_group(&spi->dev.kobj, &tsc2005_attr_group); | ||
| 653 | if (error) { | ||
| 654 | dev_err(&spi->dev, | ||
| 655 | "Failed to create sysfs attributes, err: %d\n", error); | ||
| 656 | goto err_clear_drvdata; | ||
| 657 | } | ||
| 658 | |||
| 659 | error = input_register_device(ts->idev); | ||
| 660 | if (error) { | ||
| 661 | dev_err(&spi->dev, | ||
| 662 | "Failed to register input device, err: %d\n", error); | ||
| 663 | goto err_remove_sysfs; | ||
| 664 | } | ||
| 665 | |||
| 666 | set_irq_wake(spi->irq, 1); | ||
| 667 | return 0; | ||
| 668 | |||
| 669 | err_remove_sysfs: | ||
| 670 | sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); | ||
| 671 | err_clear_drvdata: | ||
| 672 | spi_set_drvdata(spi, NULL); | ||
| 673 | free_irq(spi->irq, ts); | ||
| 674 | err_free_mem: | ||
| 675 | input_free_device(input_dev); | ||
| 676 | kfree(ts); | ||
| 677 | return error; | ||
| 678 | } | ||
| 679 | |||
| 680 | static int __devexit tsc2005_remove(struct spi_device *spi) | ||
| 681 | { | ||
| 682 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 683 | |||
| 684 | sysfs_remove_group(&ts->spi->dev.kobj, &tsc2005_attr_group); | ||
| 685 | |||
| 686 | free_irq(ts->spi->irq, ts); | ||
| 687 | input_unregister_device(ts->idev); | ||
| 688 | kfree(ts); | ||
| 689 | |||
| 690 | spi_set_drvdata(spi, NULL); | ||
| 691 | return 0; | ||
| 692 | } | ||
| 693 | |||
| 694 | #ifdef CONFIG_PM_SLEEP | ||
| 695 | static int tsc2005_suspend(struct device *dev) | ||
| 696 | { | ||
| 697 | struct spi_device *spi = to_spi_device(dev); | ||
| 698 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 699 | |||
| 700 | mutex_lock(&ts->mutex); | ||
| 701 | |||
| 702 | if (!ts->suspended && ts->opened) | ||
| 703 | __tsc2005_disable(ts); | ||
| 704 | |||
| 705 | ts->suspended = true; | ||
| 706 | |||
| 707 | mutex_unlock(&ts->mutex); | ||
| 708 | |||
| 709 | return 0; | ||
| 710 | } | ||
| 711 | |||
| 712 | static int tsc2005_resume(struct device *dev) | ||
| 713 | { | ||
| 714 | struct spi_device *spi = to_spi_device(dev); | ||
| 715 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 716 | |||
| 717 | mutex_lock(&ts->mutex); | ||
| 718 | |||
| 719 | if (ts->suspended && ts->opened) | ||
| 720 | __tsc2005_enable(ts); | ||
| 721 | |||
| 722 | ts->suspended = false; | ||
| 723 | |||
| 724 | mutex_unlock(&ts->mutex); | ||
| 725 | |||
| 726 | return 0; | ||
| 727 | } | ||
| 728 | #endif | ||
| 729 | |||
| 730 | static SIMPLE_DEV_PM_OPS(tsc2005_pm_ops, tsc2005_suspend, tsc2005_resume); | ||
| 731 | |||
| 732 | static struct spi_driver tsc2005_driver = { | ||
| 733 | .driver = { | ||
| 734 | .name = "tsc2005", | ||
| 735 | .owner = THIS_MODULE, | ||
| 736 | .pm = &tsc2005_pm_ops, | ||
| 737 | }, | ||
| 738 | .probe = tsc2005_probe, | ||
| 739 | .remove = __devexit_p(tsc2005_remove), | ||
| 740 | }; | ||
| 741 | |||
| 742 | static int __init tsc2005_init(void) | ||
| 743 | { | ||
| 744 | return spi_register_driver(&tsc2005_driver); | ||
| 745 | } | ||
| 746 | module_init(tsc2005_init); | ||
| 747 | |||
| 748 | static void __exit tsc2005_exit(void) | ||
| 749 | { | ||
| 750 | spi_unregister_driver(&tsc2005_driver); | ||
| 751 | } | ||
| 752 | module_exit(tsc2005_exit); | ||
| 753 | |||
| 754 | MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>"); | ||
| 755 | MODULE_DESCRIPTION("TSC2005 Touchscreen Driver"); | ||
| 756 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/wm831x-ts.c b/drivers/input/touchscreen/wm831x-ts.c new file mode 100644 index 000000000000..6ae054f8e0aa --- /dev/null +++ b/drivers/input/touchscreen/wm831x-ts.c | |||
| @@ -0,0 +1,368 @@ | |||
| 1 | /* | ||
| 2 | * Touchscreen driver for WM831x PMICs | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc. | ||
| 5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.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 | #include <linux/module.h> | ||
| 14 | #include <linux/moduleparam.h> | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/init.h> | ||
| 17 | #include <linux/string.h> | ||
| 18 | #include <linux/pm.h> | ||
| 19 | #include <linux/input.h> | ||
| 20 | #include <linux/interrupt.h> | ||
| 21 | #include <linux/io.h> | ||
| 22 | #include <linux/mfd/wm831x/core.h> | ||
| 23 | #include <linux/mfd/wm831x/irq.h> | ||
| 24 | #include <linux/mfd/wm831x/pdata.h> | ||
| 25 | #include <linux/platform_device.h> | ||
| 26 | #include <linux/slab.h> | ||
| 27 | #include <linux/types.h> | ||
| 28 | |||
| 29 | /* | ||
| 30 | * R16424 (0x4028) - Touch Control 1 | ||
| 31 | */ | ||
| 32 | #define WM831X_TCH_ENA 0x8000 /* TCH_ENA */ | ||
| 33 | #define WM831X_TCH_CVT_ENA 0x4000 /* TCH_CVT_ENA */ | ||
| 34 | #define WM831X_TCH_SLPENA 0x1000 /* TCH_SLPENA */ | ||
| 35 | #define WM831X_TCH_Z_ENA 0x0400 /* TCH_Z_ENA */ | ||
| 36 | #define WM831X_TCH_Y_ENA 0x0200 /* TCH_Y_ENA */ | ||
| 37 | #define WM831X_TCH_X_ENA 0x0100 /* TCH_X_ENA */ | ||
| 38 | #define WM831X_TCH_DELAY_MASK 0x00E0 /* TCH_DELAY - [7:5] */ | ||
| 39 | #define WM831X_TCH_DELAY_SHIFT 5 /* TCH_DELAY - [7:5] */ | ||
| 40 | #define WM831X_TCH_DELAY_WIDTH 3 /* TCH_DELAY - [7:5] */ | ||
| 41 | #define WM831X_TCH_RATE_MASK 0x001F /* TCH_RATE - [4:0] */ | ||
| 42 | #define WM831X_TCH_RATE_SHIFT 0 /* TCH_RATE - [4:0] */ | ||
| 43 | #define WM831X_TCH_RATE_WIDTH 5 /* TCH_RATE - [4:0] */ | ||
| 44 | |||
| 45 | /* | ||
| 46 | * R16425 (0x4029) - Touch Control 2 | ||
| 47 | */ | ||
| 48 | #define WM831X_TCH_PD_WK 0x2000 /* TCH_PD_WK */ | ||
| 49 | #define WM831X_TCH_5WIRE 0x1000 /* TCH_5WIRE */ | ||
| 50 | #define WM831X_TCH_PDONLY 0x0800 /* TCH_PDONLY */ | ||
| 51 | #define WM831X_TCH_ISEL 0x0100 /* TCH_ISEL */ | ||
| 52 | #define WM831X_TCH_RPU_MASK 0x000F /* TCH_RPU - [3:0] */ | ||
| 53 | #define WM831X_TCH_RPU_SHIFT 0 /* TCH_RPU - [3:0] */ | ||
| 54 | #define WM831X_TCH_RPU_WIDTH 4 /* TCH_RPU - [3:0] */ | ||
| 55 | |||
| 56 | /* | ||
| 57 | * R16426-8 (0x402A-C) - Touch Data X/Y/X | ||
| 58 | */ | ||
| 59 | #define WM831X_TCH_PD 0x8000 /* TCH_PD1 */ | ||
| 60 | #define WM831X_TCH_DATA_MASK 0x0FFF /* TCH_DATA - [11:0] */ | ||
| 61 | #define WM831X_TCH_DATA_SHIFT 0 /* TCH_DATA - [11:0] */ | ||
| 62 | #define WM831X_TCH_DATA_WIDTH 12 /* TCH_DATA - [11:0] */ | ||
| 63 | |||
| 64 | struct wm831x_ts { | ||
| 65 | struct input_dev *input_dev; | ||
| 66 | struct wm831x *wm831x; | ||
| 67 | unsigned int data_irq; | ||
| 68 | unsigned int pd_irq; | ||
| 69 | bool pressure; | ||
| 70 | bool pen_down; | ||
| 71 | }; | ||
| 72 | |||
| 73 | static irqreturn_t wm831x_ts_data_irq(int irq, void *irq_data) | ||
| 74 | { | ||
| 75 | struct wm831x_ts *wm831x_ts = irq_data; | ||
| 76 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 77 | static int data_types[] = { ABS_X, ABS_Y, ABS_PRESSURE }; | ||
| 78 | u16 data[3]; | ||
| 79 | int count; | ||
| 80 | int i, ret; | ||
| 81 | |||
| 82 | if (wm831x_ts->pressure) | ||
| 83 | count = 3; | ||
| 84 | else | ||
| 85 | count = 2; | ||
| 86 | |||
| 87 | wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1, | ||
| 88 | WM831X_TCHDATA_EINT, WM831X_TCHDATA_EINT); | ||
| 89 | |||
| 90 | ret = wm831x_bulk_read(wm831x, WM831X_TOUCH_DATA_X, count, | ||
| 91 | data); | ||
| 92 | if (ret != 0) { | ||
| 93 | dev_err(wm831x->dev, "Failed to read touch data: %d\n", | ||
| 94 | ret); | ||
| 95 | return IRQ_NONE; | ||
| 96 | } | ||
| 97 | |||
| 98 | /* | ||
| 99 | * We get a pen down reading on every reading, report pen up if any | ||
| 100 | * individual reading does so. | ||
| 101 | */ | ||
| 102 | wm831x_ts->pen_down = true; | ||
| 103 | for (i = 0; i < count; i++) { | ||
| 104 | if (!(data[i] & WM831X_TCH_PD)) { | ||
| 105 | wm831x_ts->pen_down = false; | ||
| 106 | continue; | ||
| 107 | } | ||
| 108 | input_report_abs(wm831x_ts->input_dev, data_types[i], | ||
| 109 | data[i] & WM831X_TCH_DATA_MASK); | ||
| 110 | } | ||
| 111 | |||
| 112 | if (!wm831x_ts->pen_down) { | ||
| 113 | disable_irq_nosync(wm831x_ts->data_irq); | ||
| 114 | |||
| 115 | /* Don't need data any more */ | ||
| 116 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 117 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | | ||
| 118 | WM831X_TCH_Z_ENA, 0); | ||
| 119 | |||
| 120 | /* Flush any final samples that arrived while reading */ | ||
| 121 | wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1, | ||
| 122 | WM831X_TCHDATA_EINT, WM831X_TCHDATA_EINT); | ||
| 123 | |||
| 124 | wm831x_bulk_read(wm831x, WM831X_TOUCH_DATA_X, count, data); | ||
| 125 | |||
| 126 | if (wm831x_ts->pressure) | ||
| 127 | input_report_abs(wm831x_ts->input_dev, | ||
| 128 | ABS_PRESSURE, 0); | ||
| 129 | |||
| 130 | input_report_key(wm831x_ts->input_dev, BTN_TOUCH, 0); | ||
| 131 | } | ||
| 132 | |||
| 133 | input_sync(wm831x_ts->input_dev); | ||
| 134 | |||
| 135 | return IRQ_HANDLED; | ||
| 136 | } | ||
| 137 | |||
| 138 | static irqreturn_t wm831x_ts_pen_down_irq(int irq, void *irq_data) | ||
| 139 | { | ||
| 140 | struct wm831x_ts *wm831x_ts = irq_data; | ||
| 141 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 142 | int ena = 0; | ||
| 143 | |||
| 144 | /* Start collecting data */ | ||
| 145 | if (wm831x_ts->pressure) | ||
| 146 | ena |= WM831X_TCH_Z_ENA; | ||
| 147 | |||
| 148 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 149 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | WM831X_TCH_Z_ENA, | ||
| 150 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | ena); | ||
| 151 | |||
| 152 | input_report_key(wm831x_ts->input_dev, BTN_TOUCH, 1); | ||
| 153 | input_sync(wm831x_ts->input_dev); | ||
| 154 | |||
| 155 | wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1, | ||
| 156 | WM831X_TCHPD_EINT, WM831X_TCHPD_EINT); | ||
| 157 | |||
| 158 | wm831x_ts->pen_down = true; | ||
| 159 | enable_irq(wm831x_ts->data_irq); | ||
| 160 | |||
| 161 | return IRQ_HANDLED; | ||
| 162 | } | ||
| 163 | |||
| 164 | static int wm831x_ts_input_open(struct input_dev *idev) | ||
| 165 | { | ||
| 166 | struct wm831x_ts *wm831x_ts = input_get_drvdata(idev); | ||
| 167 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 168 | |||
| 169 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 170 | WM831X_TCH_ENA | WM831X_TCH_CVT_ENA | | ||
| 171 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | | ||
| 172 | WM831X_TCH_Z_ENA, WM831X_TCH_ENA); | ||
| 173 | |||
| 174 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 175 | WM831X_TCH_CVT_ENA, WM831X_TCH_CVT_ENA); | ||
| 176 | |||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | |||
| 180 | static void wm831x_ts_input_close(struct input_dev *idev) | ||
| 181 | { | ||
| 182 | struct wm831x_ts *wm831x_ts = input_get_drvdata(idev); | ||
| 183 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 184 | |||
| 185 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 186 | WM831X_TCH_ENA | WM831X_TCH_CVT_ENA | | ||
| 187 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | | ||
| 188 | WM831X_TCH_Z_ENA, 0); | ||
| 189 | |||
| 190 | if (wm831x_ts->pen_down) | ||
| 191 | disable_irq(wm831x_ts->data_irq); | ||
| 192 | } | ||
| 193 | |||
| 194 | static __devinit int wm831x_ts_probe(struct platform_device *pdev) | ||
| 195 | { | ||
| 196 | struct wm831x_ts *wm831x_ts; | ||
| 197 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | ||
| 198 | struct wm831x_pdata *core_pdata = dev_get_platdata(pdev->dev.parent); | ||
| 199 | struct wm831x_touch_pdata *pdata = NULL; | ||
| 200 | struct input_dev *input_dev; | ||
| 201 | int error; | ||
| 202 | |||
| 203 | if (core_pdata) | ||
| 204 | pdata = core_pdata->touch; | ||
| 205 | |||
| 206 | wm831x_ts = kzalloc(sizeof(struct wm831x_ts), GFP_KERNEL); | ||
| 207 | input_dev = input_allocate_device(); | ||
| 208 | if (!wm831x_ts || !input_dev) { | ||
| 209 | error = -ENOMEM; | ||
| 210 | goto err_alloc; | ||
| 211 | } | ||
| 212 | |||
| 213 | wm831x_ts->wm831x = wm831x; | ||
| 214 | wm831x_ts->input_dev = input_dev; | ||
| 215 | |||
| 216 | /* | ||
| 217 | * If we have a direct IRQ use it, otherwise use the interrupt | ||
| 218 | * from the WM831x IRQ controller. | ||
| 219 | */ | ||
| 220 | if (pdata && pdata->data_irq) | ||
| 221 | wm831x_ts->data_irq = pdata->data_irq; | ||
| 222 | else | ||
| 223 | wm831x_ts->data_irq = platform_get_irq_byname(pdev, "TCHDATA"); | ||
| 224 | |||
| 225 | if (pdata && pdata->pd_irq) | ||
| 226 | wm831x_ts->pd_irq = pdata->pd_irq; | ||
| 227 | else | ||
| 228 | wm831x_ts->pd_irq = platform_get_irq_byname(pdev, "TCHPD"); | ||
| 229 | |||
| 230 | if (pdata) | ||
| 231 | wm831x_ts->pressure = pdata->pressure; | ||
| 232 | else | ||
| 233 | wm831x_ts->pressure = true; | ||
| 234 | |||
| 235 | /* Five wire touchscreens can't report pressure */ | ||
| 236 | if (pdata && pdata->fivewire) { | ||
| 237 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 238 | WM831X_TCH_5WIRE, WM831X_TCH_5WIRE); | ||
| 239 | |||
| 240 | /* Pressure measurements are not possible for five wire mode */ | ||
| 241 | WARN_ON(pdata->pressure && pdata->fivewire); | ||
| 242 | wm831x_ts->pressure = false; | ||
| 243 | } else { | ||
| 244 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 245 | WM831X_TCH_5WIRE, 0); | ||
| 246 | } | ||
| 247 | |||
| 248 | if (pdata) { | ||
| 249 | switch (pdata->isel) { | ||
| 250 | default: | ||
| 251 | dev_err(&pdev->dev, "Unsupported ISEL setting: %d\n", | ||
| 252 | pdata->isel); | ||
| 253 | /* Fall through */ | ||
| 254 | case 200: | ||
| 255 | case 0: | ||
| 256 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 257 | WM831X_TCH_ISEL, 0); | ||
| 258 | break; | ||
| 259 | case 400: | ||
| 260 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 261 | WM831X_TCH_ISEL, WM831X_TCH_ISEL); | ||
| 262 | break; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 267 | WM831X_TCH_PDONLY, 0); | ||
| 268 | |||
| 269 | /* Default to 96 samples/sec */ | ||
| 270 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 271 | WM831X_TCH_RATE_MASK, 6); | ||
| 272 | |||
| 273 | error = request_threaded_irq(wm831x_ts->data_irq, | ||
| 274 | NULL, wm831x_ts_data_irq, | ||
| 275 | IRQF_ONESHOT, | ||
| 276 | "Touchscreen data", wm831x_ts); | ||
| 277 | if (error) { | ||
| 278 | dev_err(&pdev->dev, "Failed to request data IRQ %d: %d\n", | ||
| 279 | wm831x_ts->data_irq, error); | ||
| 280 | goto err_alloc; | ||
| 281 | } | ||
| 282 | disable_irq(wm831x_ts->data_irq); | ||
| 283 | |||
| 284 | error = request_threaded_irq(wm831x_ts->pd_irq, | ||
| 285 | NULL, wm831x_ts_pen_down_irq, | ||
| 286 | IRQF_ONESHOT, | ||
| 287 | "Touchscreen pen down", wm831x_ts); | ||
| 288 | if (error) { | ||
| 289 | dev_err(&pdev->dev, "Failed to request pen down IRQ %d: %d\n", | ||
| 290 | wm831x_ts->pd_irq, error); | ||
| 291 | goto err_data_irq; | ||
| 292 | } | ||
| 293 | |||
| 294 | /* set up touch configuration */ | ||
| 295 | input_dev->name = "WM831x touchscreen"; | ||
| 296 | input_dev->phys = "wm831x"; | ||
| 297 | input_dev->open = wm831x_ts_input_open; | ||
| 298 | input_dev->close = wm831x_ts_input_close; | ||
| 299 | |||
| 300 | __set_bit(EV_ABS, input_dev->evbit); | ||
| 301 | __set_bit(EV_KEY, input_dev->evbit); | ||
| 302 | __set_bit(BTN_TOUCH, input_dev->keybit); | ||
| 303 | |||
| 304 | input_set_abs_params(input_dev, ABS_X, 0, 4095, 5, 0); | ||
| 305 | input_set_abs_params(input_dev, ABS_Y, 0, 4095, 5, 0); | ||
| 306 | if (wm831x_ts->pressure) | ||
| 307 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, 4095, 5, 0); | ||
| 308 | |||
| 309 | input_set_drvdata(input_dev, wm831x_ts); | ||
| 310 | input_dev->dev.parent = &pdev->dev; | ||
| 311 | |||
| 312 | error = input_register_device(input_dev); | ||
| 313 | if (error) | ||
| 314 | goto err_pd_irq; | ||
| 315 | |||
| 316 | platform_set_drvdata(pdev, wm831x_ts); | ||
| 317 | return 0; | ||
| 318 | |||
| 319 | err_pd_irq: | ||
| 320 | free_irq(wm831x_ts->pd_irq, wm831x_ts); | ||
| 321 | err_data_irq: | ||
| 322 | free_irq(wm831x_ts->data_irq, wm831x_ts); | ||
| 323 | err_alloc: | ||
| 324 | input_free_device(input_dev); | ||
| 325 | kfree(wm831x_ts); | ||
| 326 | |||
| 327 | return error; | ||
| 328 | } | ||
| 329 | |||
| 330 | static __devexit int wm831x_ts_remove(struct platform_device *pdev) | ||
| 331 | { | ||
| 332 | struct wm831x_ts *wm831x_ts = platform_get_drvdata(pdev); | ||
| 333 | |||
| 334 | free_irq(wm831x_ts->pd_irq, wm831x_ts); | ||
| 335 | free_irq(wm831x_ts->data_irq, wm831x_ts); | ||
| 336 | input_unregister_device(wm831x_ts->input_dev); | ||
| 337 | kfree(wm831x_ts); | ||
| 338 | |||
| 339 | platform_set_drvdata(pdev, NULL); | ||
| 340 | return 0; | ||
| 341 | } | ||
| 342 | |||
| 343 | static struct platform_driver wm831x_ts_driver = { | ||
| 344 | .driver = { | ||
| 345 | .name = "wm831x-touch", | ||
| 346 | .owner = THIS_MODULE, | ||
| 347 | }, | ||
| 348 | .probe = wm831x_ts_probe, | ||
| 349 | .remove = __devexit_p(wm831x_ts_remove), | ||
| 350 | }; | ||
| 351 | |||
| 352 | static int __init wm831x_ts_init(void) | ||
| 353 | { | ||
| 354 | return platform_driver_register(&wm831x_ts_driver); | ||
| 355 | } | ||
| 356 | module_init(wm831x_ts_init); | ||
| 357 | |||
| 358 | static void __exit wm831x_ts_exit(void) | ||
| 359 | { | ||
| 360 | platform_driver_unregister(&wm831x_ts_driver); | ||
| 361 | } | ||
| 362 | module_exit(wm831x_ts_exit); | ||
| 363 | |||
| 364 | /* Module information */ | ||
| 365 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
| 366 | MODULE_DESCRIPTION("WM831x PMIC touchscreen driver"); | ||
| 367 | MODULE_LICENSE("GPL"); | ||
| 368 | MODULE_ALIAS("platform:wm831x-touch"); | ||
