Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (64 commits)
Input: tsc2005 - remove 'disable' sysfs attribute
Input: tsc2005 - add open/close
Input: tsc2005 - handle read errors from SPI layer
Input: tsc2005 - do not rearm timer in hardirq handler
Input: tsc2005 - don't use work for 'pen up' handling
Input: tsc2005 - do not use 0 in place of NULL
Input: tsc2005 - use true/false for boolean variables
Input: tsc2005 - hide selftest attribute if we can't reset
Input: tsc2005 - rework driver initialization code
Input: tsc2005 - set up bus type in input device
Input: tsc2005 - set up parent device
Input: tsc2005 - clear driver data after unbinding
Input: tsc2005 - add module description
Input: tsc2005 - remove driver banner message
Input: tsc2005 - remove incorrect module alias
Input: tsc2005 - convert to using dev_pm_ops
Input: tsc2005 - use spi_get/set_drvdata()
Input: introduce tsc2005 driver
Input: xen-kbdfront - move to drivers/input/misc
Input: xen-kbdfront - add grant reference for shared page
...

+3286 -1908
+5 -3
arch/arm/mach-s5pv210/mach-goni.c
··· 15 15 #include <linux/fb.h> 16 16 #include <linux/i2c.h> 17 17 #include <linux/i2c-gpio.h> 18 - #include <linux/i2c/qt602240_ts.h> 18 + #include <linux/i2c/atmel_mxt_ts.h> 19 19 #include <linux/mfd/max8998.h> 20 20 #include <linux/mfd/wm8994/pdata.h> 21 21 #include <linux/regulator/fixed.h> ··· 25 25 #include <linux/gpio_keys.h> 26 26 #include <linux/input.h> 27 27 #include <linux/gpio.h> 28 + #include <linux/interrupt.h> 28 29 29 30 #include <asm/mach/arch.h> 30 31 #include <asm/mach/map.h> ··· 226 225 } 227 226 228 227 /* TSP */ 229 - static struct qt602240_platform_data qt602240_platform_data = { 228 + static struct mxt_platform_data qt602240_platform_data = { 230 229 .x_line = 17, 231 230 .y_line = 11, 232 231 .x_size = 800, ··· 234 233 .blen = 0x21, 235 234 .threshold = 0x28, 236 235 .voltage = 2800000, /* 2.8V */ 237 - .orient = QT602240_DIAGONAL, 236 + .orient = MXT_DIAGONAL, 237 + .irqflags = IRQF_TRIGGER_FALLING, 238 238 }; 239 239 240 240 static struct s3c2410_platform_i2c i2c2_data __initdata = {
+6
drivers/hid/hid-apple.c
··· 481 481 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, 482 482 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), 483 483 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, 484 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI), 485 + .driver_data = APPLE_HAS_FN }, 486 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO), 487 + .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, 488 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS), 489 + .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, 484 490 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), 485 491 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 486 492 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
+6
drivers/hid/hid-core.c
··· 1333 1333 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 1334 1334 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 1335 1335 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 1336 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 1337 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 1338 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 1336 1339 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 1337 1340 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 1338 1341 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, ··· 1843 1840 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 1844 1841 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 1845 1842 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 1843 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 1844 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 1845 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 1846 1846 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1847 1847 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1848 1848 { }
+3
drivers/hid/hid-ids.h
··· 103 103 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242 104 104 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243 105 105 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244 106 + #define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245 107 + #define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246 108 + #define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247 106 109 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239 107 110 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a 108 111 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
+2 -2
drivers/hid/hid-input.c
··· 900 900 hid->ll_driver->hidinput_input_event; 901 901 input_dev->open = hidinput_open; 902 902 input_dev->close = hidinput_close; 903 - input_dev->setkeycode_new = hidinput_setkeycode; 904 - input_dev->getkeycode_new = hidinput_getkeycode; 903 + input_dev->setkeycode = hidinput_setkeycode; 904 + input_dev->getkeycode = hidinput_getkeycode; 905 905 906 906 input_dev->name = hid->name; 907 907 input_dev->phys = hid->phys;
-10
drivers/input/Kconfig
··· 161 161 To compile this driver as a module, choose M here: the 162 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 164 comment "Input Device Drivers" 175 165 176 166 source "drivers/input/keyboard/Kconfig"
-2
drivers/input/Makefile
··· 24 24 obj-$(CONFIG_INPUT_MISC) += misc/ 25 25 26 26 obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o 27 - 28 - obj-$(CONFIG_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
+6 -4
drivers/input/evdev.c
··· 321 321 struct input_event event; 322 322 int retval; 323 323 324 + if (count < input_event_size()) 325 + return -EINVAL; 326 + 324 327 retval = mutex_lock_interruptible(&evdev->mutex); 325 328 if (retval) 326 329 return retval; ··· 333 330 goto out; 334 331 } 335 332 336 - while (retval < count) { 337 - 333 + do { 338 334 if (input_event_from_user(buffer + retval, &event)) { 339 335 retval = -EFAULT; 340 336 goto out; 341 337 } 338 + retval += input_event_size(); 342 339 343 340 input_inject_event(&evdev->handle, 344 341 event.type, event.code, event.value); 345 - retval += input_event_size(); 346 - } 342 + } while (retval + input_event_size() <= count); 347 343 348 344 out: 349 345 mutex_unlock(&evdev->mutex);
+2 -2
drivers/input/input-polldev.c
··· 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 197 * The function allocates memory for a polled device and also 198 198 * for an input device associated with this polled device. ··· 239 239 * with input layer. The device should be allocated with call to 240 240 * input_allocate_polled_device(). Callers should also set up poll() 241 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 244 int input_register_polled_device(struct input_polled_dev *dev) 245 245 {
+7 -48
drivers/input/input.c
··· 791 791 int retval; 792 792 793 793 spin_lock_irqsave(&dev->event_lock, flags); 794 - 795 - if (dev->getkeycode) { 796 - /* 797 - * Support for legacy drivers, that don't implement the new 798 - * ioctls 799 - */ 800 - u32 scancode = ke->index; 801 - 802 - memcpy(ke->scancode, &scancode, sizeof(scancode)); 803 - ke->len = sizeof(scancode); 804 - retval = dev->getkeycode(dev, scancode, &ke->keycode); 805 - } else { 806 - retval = dev->getkeycode_new(dev, ke); 807 - } 808 - 794 + retval = dev->getkeycode(dev, ke); 809 795 spin_unlock_irqrestore(&dev->event_lock, flags); 796 + 810 797 return retval; 811 798 } 812 799 EXPORT_SYMBOL(input_get_keycode); ··· 818 831 819 832 spin_lock_irqsave(&dev->event_lock, flags); 820 833 821 - if (dev->setkeycode) { 822 - /* 823 - * Support for legacy drivers, that don't implement the new 824 - * ioctls 825 - */ 826 - unsigned int scancode; 827 - 828 - retval = input_scancode_to_scalar(ke, &scancode); 829 - if (retval) 830 - goto out; 831 - 832 - /* 833 - * We need to know the old scancode, in order to generate a 834 - * keyup effect, if the set operation happens successfully 835 - */ 836 - if (!dev->getkeycode) { 837 - retval = -EINVAL; 838 - goto out; 839 - } 840 - 841 - retval = dev->getkeycode(dev, scancode, &old_keycode); 842 - if (retval) 843 - goto out; 844 - 845 - retval = dev->setkeycode(dev, scancode, ke->keycode); 846 - } else { 847 - retval = dev->setkeycode_new(dev, ke, &old_keycode); 848 - } 849 - 834 + retval = dev->setkeycode(dev, ke, &old_keycode); 850 835 if (retval) 851 836 goto out; 852 837 ··· 1805 1846 dev->rep[REP_PERIOD] = 33; 1806 1847 } 1807 1848 1808 - if (!dev->getkeycode && !dev->getkeycode_new) 1809 - dev->getkeycode_new = input_default_getkeycode; 1849 + if (!dev->getkeycode) 1850 + dev->getkeycode = input_default_getkeycode; 1810 1851 1811 - if (!dev->setkeycode && !dev->setkeycode_new) 1812 - dev->setkeycode_new = input_default_setkeycode; 1852 + if (!dev->setkeycode) 1853 + dev->setkeycode = input_default_setkeycode; 1813 1854 1814 1855 dev_set_name(&dev->dev, "input%ld", 1815 1856 (unsigned long) atomic_inc_return(&input_no) - 1);
+10
drivers/input/keyboard/Kconfig
··· 112 112 right-hand column will be interpreted as the key shown in the 113 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 125 config KEYBOARD_QT2160 116 126 tristate "Atmel AT42QT2160 Touch Sensor Chip" 117 127 depends on I2C && EXPERIMENTAL
+1
drivers/input/keyboard/Makefile
··· 34 34 obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o 35 35 obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o 36 36 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o 37 + obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o 37 38 obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o 38 39 obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o 39 40 obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
+8 -7
drivers/input/keyboard/lm8323.c
··· 30 30 #include <linux/delay.h> 31 31 #include <linux/input.h> 32 32 #include <linux/leds.h> 33 + #include <linux/pm.h> 33 34 #include <linux/i2c/lm8323.h> 34 35 #include <linux/slab.h> 35 36 ··· 803 802 * We don't need to explicitly suspend the chip, as it already switches off 804 803 * when there's no activity. 805 804 */ 806 - static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg) 805 + static int lm8323_suspend(struct device *dev) 807 806 { 807 + struct i2c_client *client = to_i2c_client(dev); 808 808 struct lm8323_chip *lm = i2c_get_clientdata(client); 809 809 int i; 810 810 ··· 823 821 return 0; 824 822 } 825 823 826 - static int lm8323_resume(struct i2c_client *client) 824 + static int lm8323_resume(struct device *dev) 827 825 { 826 + struct i2c_client *client = to_i2c_client(dev); 828 827 struct lm8323_chip *lm = i2c_get_clientdata(client); 829 828 int i; 830 829 ··· 842 839 843 840 return 0; 844 841 } 845 - #else 846 - #define lm8323_suspend NULL 847 - #define lm8323_resume NULL 848 842 #endif 843 + 844 + static SIMPLE_DEV_PM_OPS(lm8323_pm_ops, lm8323_suspend, lm8323_resume); 849 845 850 846 static const struct i2c_device_id lm8323_id[] = { 851 847 { "lm8323", 0 }, ··· 854 852 static struct i2c_driver lm8323_i2c_driver = { 855 853 .driver = { 856 854 .name = "lm8323", 855 + .pm = &lm8323_pm_ops, 857 856 }, 858 857 .probe = lm8323_probe, 859 858 .remove = __devexit_p(lm8323_remove), 860 - .suspend = lm8323_suspend, 861 - .resume = lm8323_resume, 862 859 .id_table = lm8323_id, 863 860 }; 864 861 MODULE_DEVICE_TABLE(i2c, lm8323_id);
+10 -7
drivers/input/keyboard/max7359_keypad.c
··· 17 17 #include <linux/i2c.h> 18 18 #include <linux/slab.h> 19 19 #include <linux/interrupt.h> 20 + #include <linux/pm.h> 20 21 #include <linux/input.h> 21 22 #include <linux/input/matrix_keypad.h> 22 23 ··· 272 271 } 273 272 274 273 #ifdef CONFIG_PM 275 - static int max7359_suspend(struct i2c_client *client, pm_message_t mesg) 274 + static int max7359_suspend(struct device *dev) 276 275 { 276 + struct i2c_client *client = to_i2c_client(dev); 277 + 277 278 max7359_fall_deepsleep(client); 278 279 279 280 if (device_may_wakeup(&client->dev)) ··· 284 281 return 0; 285 282 } 286 283 287 - static int max7359_resume(struct i2c_client *client) 284 + static int max7359_resume(struct device *dev) 288 285 { 286 + struct i2c_client *client = to_i2c_client(dev); 287 + 289 288 if (device_may_wakeup(&client->dev)) 290 289 disable_irq_wake(client->irq); 291 290 ··· 296 291 297 292 return 0; 298 293 } 299 - #else 300 - #define max7359_suspend NULL 301 - #define max7359_resume NULL 302 294 #endif 295 + 296 + static SIMPLE_DEV_PM_OPS(max7359_pm, max7359_suspend, max7359_resume); 303 297 304 298 static const struct i2c_device_id max7359_ids[] = { 305 299 { "max7359", 0 }, ··· 309 305 static struct i2c_driver max7359_i2c_driver = { 310 306 .driver = { 311 307 .name = "max7359", 308 + .pm = &max7359_pm, 312 309 }, 313 310 .probe = max7359_probe, 314 311 .remove = __devexit_p(max7359_remove), 315 - .suspend = max7359_suspend, 316 - .resume = max7359_resume, 317 312 .id_table = max7359_ids, 318 313 }; 319 314
+56 -1
drivers/input/keyboard/mcs_touchkey.c
··· 1 1 /* 2 - * mcs_touchkey.c - Touchkey driver for MELFAS MCS5000/5080 controller 2 + * Touchkey driver for MELFAS MCS5000/5080 controller 3 3 * 4 4 * Copyright (C) 2010 Samsung Electronics Co.Ltd 5 5 * Author: HeungJun Kim <riverful.kim@samsung.com> ··· 19 19 #include <linux/input.h> 20 20 #include <linux/irq.h> 21 21 #include <linux/slab.h> 22 + #include <linux/pm.h> 22 23 23 24 /* MCS5000 Touchkey */ 24 25 #define MCS5000_TOUCHKEY_STATUS 0x04 ··· 46 45 }; 47 46 48 47 struct mcs_touchkey_data { 48 + void (*poweron)(bool); 49 + 49 50 struct i2c_client *client; 50 51 struct input_dev *input_dev; 51 52 struct mcs_touchkey_chip chip; ··· 172 169 if (pdata->cfg_pin) 173 170 pdata->cfg_pin(); 174 171 172 + if (pdata->poweron) { 173 + data->poweron = pdata->poweron; 174 + data->poweron(true); 175 + } 176 + 175 177 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt, 176 178 IRQF_TRIGGER_FALLING, client->dev.driver->name, data); 177 179 if (error) { ··· 204 196 struct mcs_touchkey_data *data = i2c_get_clientdata(client); 205 197 206 198 free_irq(client->irq, data); 199 + if (data->poweron) 200 + data->poweron(false); 207 201 input_unregister_device(data->input_dev); 208 202 kfree(data); 209 203 210 204 return 0; 211 205 } 206 + 207 + static void mcs_touchkey_shutdown(struct i2c_client *client) 208 + { 209 + struct mcs_touchkey_data *data = i2c_get_clientdata(client); 210 + 211 + if (data->poweron) 212 + data->poweron(false); 213 + } 214 + 215 + #ifdef CONFIG_PM_SLEEP 216 + static int mcs_touchkey_suspend(struct device *dev) 217 + { 218 + struct mcs_touchkey_data *data = dev_get_drvdata(dev); 219 + struct i2c_client *client = data->client; 220 + 221 + /* Disable the work */ 222 + disable_irq(client->irq); 223 + 224 + /* Finally turn off the power */ 225 + if (data->poweron) 226 + data->poweron(false); 227 + 228 + return 0; 229 + } 230 + 231 + static int mcs_touchkey_resume(struct device *dev) 232 + { 233 + struct mcs_touchkey_data *data = dev_get_drvdata(dev); 234 + struct i2c_client *client = data->client; 235 + 236 + /* Enable the device first */ 237 + if (data->poweron) 238 + data->poweron(true); 239 + 240 + /* Enable irq again */ 241 + enable_irq(client->irq); 242 + 243 + return 0; 244 + } 245 + #endif 246 + 247 + static SIMPLE_DEV_PM_OPS(mcs_touchkey_pm_ops, 248 + mcs_touchkey_suspend, mcs_touchkey_resume); 212 249 213 250 static const struct i2c_device_id mcs_touchkey_id[] = { 214 251 { "mcs5000_touchkey", MCS5000_TOUCHKEY }, ··· 266 213 .driver = { 267 214 .name = "mcs_touchkey", 268 215 .owner = THIS_MODULE, 216 + .pm = &mcs_touchkey_pm_ops, 269 217 }, 270 218 .probe = mcs_touchkey_probe, 271 219 .remove = __devexit_p(mcs_touchkey_remove), 220 + .shutdown = mcs_touchkey_shutdown, 272 221 .id_table = mcs_touchkey_id, 273 222 }; 274 223
+55 -19
drivers/input/keyboard/omap4-keypad.c
··· 29 29 #include <linux/io.h> 30 30 #include <linux/input.h> 31 31 #include <linux/slab.h> 32 + #include <linux/pm_runtime.h> 32 33 33 34 #include <plat/omap4-keypad.h> 34 35 ··· 81 80 unsigned short keymap[]; 82 81 }; 83 82 84 - static void __devinit omap4_keypad_config(struct omap4_keypad *keypad_data) 85 - { 86 - __raw_writel(OMAP4_VAL_FUNCTIONALCFG, 87 - keypad_data->base + OMAP4_KBD_CTRL); 88 - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME, 89 - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME); 90 - __raw_writel(OMAP4_VAL_IRQDISABLE, 91 - keypad_data->base + OMAP4_KBD_IRQSTATUS); 92 - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY, 93 - keypad_data->base + OMAP4_KBD_IRQENABLE); 94 - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA, 95 - keypad_data->base + OMAP4_KBD_WAKEUPENABLE); 96 - } 97 - 98 83 /* Interrupt handler */ 99 84 static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) 100 85 { ··· 129 142 keypad_data->base + OMAP4_KBD_IRQENABLE); 130 143 131 144 return IRQ_HANDLED; 145 + } 146 + 147 + static int omap4_keypad_open(struct input_dev *input) 148 + { 149 + struct omap4_keypad *keypad_data = input_get_drvdata(input); 150 + 151 + pm_runtime_get_sync(input->dev.parent); 152 + 153 + disable_irq(keypad_data->irq); 154 + 155 + __raw_writel(OMAP4_VAL_FUNCTIONALCFG, 156 + keypad_data->base + OMAP4_KBD_CTRL); 157 + __raw_writel(OMAP4_VAL_DEBOUNCINGTIME, 158 + keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME); 159 + __raw_writel(OMAP4_VAL_IRQDISABLE, 160 + keypad_data->base + OMAP4_KBD_IRQSTATUS); 161 + __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY, 162 + keypad_data->base + OMAP4_KBD_IRQENABLE); 163 + __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA, 164 + keypad_data->base + OMAP4_KBD_WAKEUPENABLE); 165 + 166 + enable_irq(keypad_data->irq); 167 + 168 + return 0; 169 + } 170 + 171 + static void omap4_keypad_close(struct input_dev *input) 172 + { 173 + struct omap4_keypad *keypad_data = input_get_drvdata(input); 174 + 175 + disable_irq(keypad_data->irq); 176 + 177 + /* Disable interrupts */ 178 + __raw_writel(OMAP4_VAL_IRQDISABLE, 179 + keypad_data->base + OMAP4_KBD_IRQENABLE); 180 + 181 + /* clear pending interrupts */ 182 + __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS), 183 + keypad_data->base + OMAP4_KBD_IRQSTATUS); 184 + 185 + enable_irq(keypad_data->irq); 186 + 187 + pm_runtime_put_sync(input->dev.parent); 132 188 } 133 189 134 190 static int __devinit omap4_keypad_probe(struct platform_device *pdev) ··· 255 225 input_dev->id.product = 0x0001; 256 226 input_dev->id.version = 0x0001; 257 227 228 + input_dev->open = omap4_keypad_open; 229 + input_dev->close = omap4_keypad_close; 230 + 258 231 input_dev->keycode = keypad_data->keymap; 259 232 input_dev->keycodesize = sizeof(keypad_data->keymap[0]); 260 233 input_dev->keycodemax = max_keys; ··· 272 239 matrix_keypad_build_keymap(pdata->keymap_data, row_shift, 273 240 input_dev->keycode, input_dev->keybit); 274 241 275 - omap4_keypad_config(keypad_data); 276 - 277 242 error = request_irq(keypad_data->irq, omap4_keypad_interrupt, 278 243 IRQF_TRIGGER_RISING, 279 244 "omap4-keypad", keypad_data); ··· 280 249 goto err_free_input; 281 250 } 282 251 252 + pm_runtime_enable(&pdev->dev); 253 + 283 254 error = input_register_device(keypad_data->input); 284 255 if (error < 0) { 285 256 dev_err(&pdev->dev, "failed to register input device\n"); 286 - goto err_free_irq; 257 + goto err_pm_disable; 287 258 } 288 - 289 259 290 260 platform_set_drvdata(pdev, keypad_data); 291 261 return 0; 292 262 293 - err_free_irq: 263 + err_pm_disable: 264 + pm_runtime_disable(&pdev->dev); 294 265 free_irq(keypad_data->irq, keypad_data); 295 266 err_free_input: 296 267 input_free_device(input_dev); ··· 311 278 struct resource *res; 312 279 313 280 free_irq(keypad_data->irq, keypad_data); 281 + 282 + pm_runtime_disable(&pdev->dev); 283 + 314 284 input_unregister_device(keypad_data->input); 315 285 316 286 iounmap(keypad_data->base);
+276
drivers/input/keyboard/qt1070.c
··· 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");
+11 -11
drivers/input/keyboard/tc3589x-keypad.c
··· 402 402 return 0; 403 403 } 404 404 405 - #ifdef CONFIG_PM 405 + #ifdef CONFIG_PM_SLEEP 406 406 static int tc3589x_keypad_suspend(struct device *dev) 407 407 { 408 408 struct platform_device *pdev = to_platform_device(dev); ··· 439 439 440 440 return 0; 441 441 } 442 - 443 - static const SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops, 444 - tc3589x_keypad_suspend, tc3589x_keypad_resume); 445 442 #endif 443 + 444 + static SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops, 445 + tc3589x_keypad_suspend, tc3589x_keypad_resume); 446 446 447 447 static struct platform_driver tc3589x_keypad_driver = { 448 - .driver.name = "tc3589x-keypad", 449 - .driver.owner = THIS_MODULE, 450 - #ifdef CONFIG_PM 451 - .driver.pm = &tc3589x_keypad_dev_pm_ops, 452 - #endif 453 - .probe = tc3589x_keypad_probe, 454 - .remove = __devexit_p(tc3589x_keypad_remove), 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 455 }; 456 456 457 457 static int __init tc3589x_keypad_init(void)
+28
drivers/input/keyboard/tca6416-keypad.c
··· 297 297 } 298 298 299 299 i2c_set_clientdata(client, chip); 300 + device_init_wakeup(&client->dev, 1); 300 301 301 302 return 0; 302 303 ··· 327 326 return 0; 328 327 } 329 328 329 + #ifdef CONFIG_PM_SLEEP 330 + static int tca6416_keypad_suspend(struct device *dev) 331 + { 332 + struct i2c_client *client = to_i2c_client(dev); 333 + struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); 334 + 335 + if (device_may_wakeup(dev)) 336 + enable_irq_wake(chip->irqnum); 337 + 338 + return 0; 339 + } 340 + 341 + static int tca6416_keypad_resume(struct device *dev) 342 + { 343 + struct i2c_client *client = to_i2c_client(dev); 344 + struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); 345 + 346 + if (device_may_wakeup(dev)) 347 + disable_irq_wake(chip->irqnum); 348 + 349 + return 0; 350 + } 351 + #endif 352 + 353 + static SIMPLE_DEV_PM_OPS(tca6416_keypad_dev_pm_ops, 354 + tca6416_keypad_suspend, tca6416_keypad_resume); 330 355 331 356 static struct i2c_driver tca6416_keypad_driver = { 332 357 .driver = { 333 358 .name = "tca6416-keypad", 359 + .pm = &tca6416_keypad_dev_pm_ops, 334 360 }, 335 361 .probe = tca6416_keypad_probe, 336 362 .remove = __devexit_p(tca6416_keypad_remove),
+13
drivers/input/misc/Kconfig
··· 454 454 To compile this driver as a module, choose M here: the 455 455 module will be called cma3000_d0x_i2c. 456 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 + 457 470 endif
+1
drivers/input/misc/Makefile
··· 42 42 obj-$(CONFIG_INPUT_UINPUT) += uinput.o 43 43 obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o 44 44 obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o 45 + obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o 45 46 obj-$(CONFIG_INPUT_YEALINK) += yealink.o 46 47
+8 -9
drivers/input/misc/ad714x-i2c.c
··· 10 10 #include <linux/i2c.h> 11 11 #include <linux/module.h> 12 12 #include <linux/types.h> 13 + #include <linux/pm.h> 13 14 #include "ad714x.h" 14 15 15 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 26 #endif 27 + 28 + static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume); 29 29 30 30 static int ad714x_i2c_write(struct device *dev, unsigned short reg, 31 31 unsigned short data) ··· 114 114 static struct i2c_driver ad714x_i2c_driver = { 115 115 .driver = { 116 116 .name = "ad714x_captouch", 117 + .pm = &ad714x_i2c_pm, 117 118 }, 118 119 .probe = ad714x_i2c_probe, 119 120 .remove = __devexit_p(ad714x_i2c_remove), 120 - .suspend = ad714x_i2c_suspend, 121 - .resume = ad714x_i2c_resume, 122 121 .id_table = ad714x_id, 123 122 }; 124 123
+8 -9
drivers/input/misc/ad714x-spi.c
··· 9 9 #include <linux/input.h> /* BUS_I2C */ 10 10 #include <linux/module.h> 11 11 #include <linux/spi/spi.h> 12 + #include <linux/pm.h> 12 13 #include <linux/types.h> 13 14 #include "ad714x.h" 14 15 ··· 17 16 #define AD714x_SPI_READ BIT(10) 18 17 19 18 #ifdef CONFIG_PM 20 - static int ad714x_spi_suspend(struct spi_device *spi, pm_message_t message) 19 + static int ad714x_spi_suspend(struct device *dev) 21 20 { 22 - return ad714x_disable(spi_get_drvdata(spi)); 21 + return ad714x_disable(spi_get_drvdata(to_spi_device(dev))); 23 22 } 24 23 25 - static int ad714x_spi_resume(struct spi_device *spi) 24 + static int ad714x_spi_resume(struct device *dev) 26 25 { 27 - return ad714x_enable(spi_get_drvdata(spi)); 26 + return ad714x_enable(spi_get_drvdata(to_spi_device(dev))); 28 27 } 29 - #else 30 - # define ad714x_spi_suspend NULL 31 - # define ad714x_spi_resume NULL 32 28 #endif 29 + 30 + static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); 33 31 34 32 static int ad714x_spi_read(struct device *dev, unsigned short reg, 35 33 unsigned short *data) ··· 79 79 .driver = { 80 80 .name = "ad714x_captouch", 81 81 .owner = THIS_MODULE, 82 + .pm = &ad714x_spi_pm, 82 83 }, 83 84 .probe = ad714x_spi_probe, 84 85 .remove = __devexit_p(ad714x_spi_remove), 85 - .suspend = ad714x_spi_suspend, 86 - .resume = ad714x_spi_resume, 87 86 }; 88 87 89 88 static __init int ad714x_spi_init(void)
+9 -7
drivers/input/misc/adxl34x-i2c.c
··· 11 11 #include <linux/i2c.h> 12 12 #include <linux/module.h> 13 13 #include <linux/types.h> 14 + #include <linux/pm.h> 14 15 #include "adxl34x.h" 15 16 16 17 static int adxl34x_smbus_read(struct device *dev, unsigned char reg) ··· 106 105 } 107 106 108 107 #ifdef CONFIG_PM 109 - static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) 108 + static int adxl34x_i2c_suspend(struct device *dev) 110 109 { 110 + struct i2c_client *client = to_i2c_client(dev); 111 111 struct adxl34x *ac = i2c_get_clientdata(client); 112 112 113 113 adxl34x_suspend(ac); ··· 116 114 return 0; 117 115 } 118 116 119 - static int adxl34x_i2c_resume(struct i2c_client *client) 117 + static int adxl34x_i2c_resume(struct device *dev) 120 118 { 119 + struct i2c_client *client = to_i2c_client(dev); 121 120 struct adxl34x *ac = i2c_get_clientdata(client); 122 121 123 122 adxl34x_resume(ac); 124 123 125 124 return 0; 126 125 } 127 - #else 128 - # define adxl34x_i2c_suspend NULL 129 - # define adxl34x_i2c_resume NULL 130 126 #endif 127 + 128 + static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend, 129 + adxl34x_i2c_resume); 131 130 132 131 static const struct i2c_device_id adxl34x_id[] = { 133 132 { "adxl34x", 0 }, ··· 141 138 .driver = { 142 139 .name = "adxl34x", 143 140 .owner = THIS_MODULE, 141 + .pm = &adxl34x_i2c_pm, 144 142 }, 145 143 .probe = adxl34x_i2c_probe, 146 144 .remove = __devexit_p(adxl34x_i2c_remove), 147 - .suspend = adxl34x_i2c_suspend, 148 - .resume = adxl34x_i2c_resume, 149 145 .id_table = adxl34x_id, 150 146 }; 151 147
+11 -9
drivers/input/misc/adxl34x-spi.c
··· 10 10 #include <linux/input.h> /* BUS_SPI */ 11 11 #include <linux/module.h> 12 12 #include <linux/spi/spi.h> 13 + #include <linux/pm.h> 13 14 #include <linux/types.h> 14 15 #include "adxl34x.h" 15 16 ··· 58 57 return (status < 0) ? status : 0; 59 58 } 60 59 61 - static const struct adxl34x_bus_ops adx134x_spi_bops = { 60 + static const struct adxl34x_bus_ops adxl34x_spi_bops = { 62 61 .bustype = BUS_SPI, 63 62 .write = adxl34x_spi_write, 64 63 .read = adxl34x_spi_read, ··· 77 76 78 77 ac = adxl34x_probe(&spi->dev, spi->irq, 79 78 spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY, 80 - &adx134x_spi_bops); 79 + &adxl34x_spi_bops); 81 80 82 81 if (IS_ERR(ac)) 83 82 return PTR_ERR(ac); ··· 95 94 } 96 95 97 96 #ifdef CONFIG_PM 98 - static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) 97 + static int adxl34x_spi_suspend(struct device *dev) 99 98 { 99 + struct spi_device *spi = to_spi_device(dev); 100 100 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 101 101 102 102 adxl34x_suspend(ac); ··· 105 103 return 0; 106 104 } 107 105 108 - static int adxl34x_spi_resume(struct spi_device *spi) 106 + static int adxl34x_spi_resume(struct device *dev) 109 107 { 108 + struct spi_device *spi = to_spi_device(dev); 110 109 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 111 110 112 111 adxl34x_resume(ac); 113 112 114 113 return 0; 115 114 } 116 - #else 117 - # define adxl34x_spi_suspend NULL 118 - # define adxl34x_spi_resume NULL 119 115 #endif 116 + 117 + static SIMPLE_DEV_PM_OPS(adxl34x_spi_pm, adxl34x_spi_suspend, 118 + adxl34x_spi_resume); 120 119 121 120 static struct spi_driver adxl34x_driver = { 122 121 .driver = { 123 122 .name = "adxl34x", 124 123 .bus = &spi_bus_type, 125 124 .owner = THIS_MODULE, 125 + .pm = &adxl34x_spi_pm, 126 126 }, 127 127 .probe = adxl34x_spi_probe, 128 128 .remove = __devexit_p(adxl34x_spi_remove), 129 - .suspend = adxl34x_spi_suspend, 130 - .resume = adxl34x_spi_resume, 131 129 }; 132 130 133 131 static int __init adxl34x_spi_init(void)
+2 -2
drivers/input/misc/ati_remote2.c
··· 612 612 idev->open = ati_remote2_open; 613 613 idev->close = ati_remote2_close; 614 614 615 - idev->getkeycode_new = ati_remote2_getkeycode; 616 - idev->setkeycode_new = ati_remote2_setkeycode; 615 + idev->getkeycode = ati_remote2_getkeycode; 616 + idev->setkeycode = ati_remote2_setkeycode; 617 617 618 618 idev->name = ar2->name; 619 619 idev->phys = ar2->phys;
+16 -32
drivers/input/misc/uinput.c
··· 347 347 { 348 348 struct uinput_user_dev *user_dev; 349 349 struct input_dev *dev; 350 - char *name; 351 - int i, size; 350 + int i; 352 351 int retval; 353 352 354 353 if (count != sizeof(struct uinput_user_dev)) ··· 361 362 362 363 dev = udev->dev; 363 364 364 - user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL); 365 - if (!user_dev) 366 - return -ENOMEM; 367 - 368 - if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) { 369 - retval = -EFAULT; 370 - goto exit; 371 - } 365 + user_dev = memdup_user(buffer, sizeof(struct uinput_user_dev)); 366 + if (IS_ERR(user_dev)) 367 + return PTR_ERR(user_dev); 372 368 373 369 udev->ff_effects_max = user_dev->ff_effects_max; 374 370 375 - size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; 376 - if (!size) { 371 + /* Ensure name is filled in */ 372 + if (!user_dev->name[0]) { 377 373 retval = -EINVAL; 378 374 goto exit; 379 375 } 380 376 381 377 kfree(dev->name); 382 - dev->name = name = kmalloc(size, GFP_KERNEL); 383 - if (!name) { 378 + dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE, 379 + GFP_KERNEL); 380 + if (!dev->name) { 384 381 retval = -ENOMEM; 385 382 goto exit; 386 383 } 387 - strlcpy(name, user_dev->name, size); 388 384 389 385 dev->id.bustype = user_dev->id.bustype; 390 386 dev->id.vendor = user_dev->id.vendor; ··· 616 622 struct uinput_ff_upload ff_up; 617 623 struct uinput_ff_erase ff_erase; 618 624 struct uinput_request *req; 619 - int length; 620 625 char *phys; 621 626 622 627 retval = mutex_lock_interruptible(&udev->mutex); ··· 682 689 retval = -EINVAL; 683 690 goto out; 684 691 } 685 - length = strnlen_user(p, 1024); 686 - if (length <= 0) { 687 - retval = -EFAULT; 688 - break; 692 + 693 + phys = strndup_user(p, 1024); 694 + if (IS_ERR(phys)) { 695 + retval = PTR_ERR(phys); 696 + goto out; 689 697 } 698 + 690 699 kfree(udev->dev->phys); 691 - udev->dev->phys = phys = kmalloc(length, GFP_KERNEL); 692 - if (!phys) { 693 - retval = -ENOMEM; 694 - break; 695 - } 696 - if (copy_from_user(phys, p, length)) { 697 - udev->dev->phys = NULL; 698 - kfree(phys); 699 - retval = -EFAULT; 700 - break; 701 - } 702 - phys[length - 1] = '\0'; 700 + udev->dev->phys = phys; 703 701 break; 704 702 705 703 case UI_BEGIN_FF_UPLOAD:
+24 -4
drivers/input/mouse/bcm5974.c
··· 63 63 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242 64 64 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243 65 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 66 70 67 71 #define BCM5974_DEVICE(prod) { \ 68 72 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ ··· 100 96 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI), 101 97 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO), 102 98 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), 99 + /* MacbookPro8 */ 100 + BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI), 101 + BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ISO), 102 + BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_JIS), 103 103 /* Terminating entry */ 104 104 {} 105 105 }; ··· 282 274 { DIM_X, DIM_X / SN_COORD, -4616, 5112 }, 283 275 { DIM_Y, DIM_Y / SN_COORD, -142, 5234 } 284 276 }, 277 + { 278 + USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI, 279 + USB_DEVICE_ID_APPLE_WELLSPRING5_ISO, 280 + USB_DEVICE_ID_APPLE_WELLSPRING5_JIS, 281 + HAS_INTEGRATED_BUTTON, 282 + 0x84, sizeof(struct bt_data), 283 + 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 284 + { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 285 + { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 286 + { DIM_X, DIM_X / SN_COORD, -4415, 5050 }, 287 + { DIM_Y, DIM_Y / SN_COORD, -55, 6680 } 288 + }, 285 289 {} 286 290 }; 287 291 ··· 450 430 ptest = int2bound(&c->p, raw_p); 451 431 origin = raw2int(f->origin); 452 432 453 - /* set the integrated button if applicable */ 454 - if (c->tp_type == TYPE2) 455 - ibt = raw2int(dev->tp_data[BUTTON_TYPE2]); 456 - 457 433 /* while tracking finger still valid, count all fingers */ 458 434 if (ptest > PRESSURE_LOW && origin) { 459 435 abs_p = ptest; ··· 467 451 } 468 452 } 469 453 } 454 + 455 + /* set the integrated button if applicable */ 456 + if (c->tp_type == TYPE2) 457 + ibt = raw2int(dev->tp_data[BUTTON_TYPE2]); 470 458 471 459 if (dev->fingers < nmin) 472 460 dev->fingers = nmin;
+9 -7
drivers/input/mouse/synaptics_i2c.c
··· 18 18 #include <linux/delay.h> 19 19 #include <linux/workqueue.h> 20 20 #include <linux/slab.h> 21 + #include <linux/pm.h> 21 22 22 23 #define DRIVER_NAME "synaptics_i2c" 23 24 /* maximum product id is 15 characters */ ··· 620 619 } 621 620 622 621 #ifdef CONFIG_PM 623 - static int synaptics_i2c_suspend(struct i2c_client *client, pm_message_t mesg) 622 + static int synaptics_i2c_suspend(struct device *dev) 624 623 { 624 + struct i2c_client *client = to_i2c_client(dev); 625 625 struct synaptics_i2c *touch = i2c_get_clientdata(client); 626 626 627 627 cancel_delayed_work_sync(&touch->dwork); ··· 633 631 return 0; 634 632 } 635 633 636 - static int synaptics_i2c_resume(struct i2c_client *client) 634 + static int synaptics_i2c_resume(struct device *dev) 637 635 { 638 636 int ret; 637 + struct i2c_client *client = to_i2c_client(dev); 639 638 struct synaptics_i2c *touch = i2c_get_clientdata(client); 640 639 641 640 ret = synaptics_i2c_reset_config(client); ··· 648 645 649 646 return 0; 650 647 } 651 - #else 652 - #define synaptics_i2c_suspend NULL 653 - #define synaptics_i2c_resume NULL 654 648 #endif 649 + 650 + static SIMPLE_DEV_PM_OPS(synaptics_i2c_pm, synaptics_i2c_suspend, 651 + synaptics_i2c_resume); 655 652 656 653 static const struct i2c_device_id synaptics_i2c_id_table[] = { 657 654 { "synaptics_i2c", 0 }, ··· 663 660 .driver = { 664 661 .name = DRIVER_NAME, 665 662 .owner = THIS_MODULE, 663 + .pm = &synaptics_i2c_pm, 666 664 }, 667 665 668 666 .probe = synaptics_i2c_probe, 669 667 .remove = __devexit_p(synaptics_i2c_remove), 670 668 671 - .suspend = synaptics_i2c_suspend, 672 - .resume = synaptics_i2c_resume, 673 669 .id_table = synaptics_i2c_id_table, 674 670 }; 675 671
+2 -2
drivers/input/sparse-keymap.c
··· 210 210 211 211 dev->keycode = map; 212 212 dev->keycodemax = map_size; 213 - dev->getkeycode_new = sparse_keymap_getkeycode; 214 - dev->setkeycode_new = sparse_keymap_setkeycode; 213 + dev->getkeycode = sparse_keymap_getkeycode; 214 + dev->setkeycode = sparse_keymap_setkeycode; 215 215 216 216 return 0; 217 217
+6 -6
drivers/input/tablet/wacom_sys.c
··· 193 193 case HID_USAGE_X: 194 194 if (usage == WCM_DESKTOP) { 195 195 if (finger) { 196 - features->device_type = BTN_TOOL_DOUBLETAP; 196 + features->device_type = BTN_TOOL_FINGER; 197 197 if (features->type == TABLETPC2FG) { 198 198 /* need to reset back */ 199 199 features->pktlen = WACOM_PKGLEN_TPC2FG; 200 - features->device_type = BTN_TOOL_TRIPLETAP; 200 + features->device_type = BTN_TOOL_DOUBLETAP; 201 201 } 202 202 if (features->type == BAMBOO_PT) { 203 203 /* need to reset back */ 204 204 features->pktlen = WACOM_PKGLEN_BBTOUCH; 205 - features->device_type = BTN_TOOL_TRIPLETAP; 205 + features->device_type = BTN_TOOL_DOUBLETAP; 206 206 features->x_phy = 207 207 get_unaligned_le16(&report[i + 5]); 208 208 features->x_max = ··· 241 241 case HID_USAGE_Y: 242 242 if (usage == WCM_DESKTOP) { 243 243 if (finger) { 244 - features->device_type = BTN_TOOL_DOUBLETAP; 244 + features->device_type = BTN_TOOL_FINGER; 245 245 if (features->type == TABLETPC2FG) { 246 246 /* need to reset back */ 247 247 features->pktlen = WACOM_PKGLEN_TPC2FG; 248 - features->device_type = BTN_TOOL_TRIPLETAP; 248 + features->device_type = BTN_TOOL_DOUBLETAP; 249 249 features->y_max = 250 250 get_unaligned_le16(&report[i + 3]); 251 251 features->y_phy = ··· 254 254 } else if (features->type == BAMBOO_PT) { 255 255 /* need to reset back */ 256 256 features->pktlen = WACOM_PKGLEN_BBTOUCH; 257 - features->device_type = BTN_TOOL_TRIPLETAP; 257 + features->device_type = BTN_TOOL_DOUBLETAP; 258 258 features->y_phy = 259 259 get_unaligned_le16(&report[i + 3]); 260 260 features->y_max =
+92 -159
drivers/input/tablet/wacom_wac.c
··· 675 675 return 1; 676 676 } 677 677 678 - 679 - static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx) 678 + static int wacom_tpc_mt_touch(struct wacom_wac *wacom) 680 679 { 681 680 struct input_dev *input = wacom->input; 682 - int finger = idx + 1; 683 - int x = le16_to_cpup((__le16 *)&data[finger * 2]) & 0x7fff; 684 - int y = le16_to_cpup((__le16 *)&data[4 + finger * 2]) & 0x7fff; 681 + unsigned char *data = wacom->data; 682 + int contact_with_no_pen_down_count = 0; 683 + int i; 685 684 686 - /* 687 - * Work around input core suppressing "duplicate" events since 688 - * we are abusing ABS_X/ABS_Y to transmit multi-finger data. 689 - * This should go away once we switch to true multitouch 690 - * protocol. 691 - */ 692 - if (wacom->last_finger != finger) { 693 - if (x == input_abs_get_val(input, ABS_X)) 694 - x++; 685 + for (i = 0; i < 2; i++) { 686 + int p = data[1] & (1 << i); 687 + bool touch = p && !wacom->shared->stylus_in_proximity; 695 688 696 - if (y == input_abs_get_val(input, ABS_Y)) 697 - y++; 689 + input_mt_slot(input, i); 690 + input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); 691 + if (touch) { 692 + int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff; 693 + int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff; 694 + 695 + input_report_abs(input, ABS_MT_POSITION_X, x); 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 - input_report_abs(input, ABS_Y, y); 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); 701 + /* keep touch state for pen event */ 702 + wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); 708 703 709 - wacom->last_finger = finger; 704 + input_mt_report_pointer_emulation(input, true); 705 + 706 + return 1; 710 707 } 711 708 712 - static void wacom_tpc_touch_out(struct wacom_wac *wacom, int idx) 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 - } 726 - 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 711 char *data = wacom->data; 730 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; 733 - wacom->id[0] = TOUCH_DEVICE_ID; 734 - wacom->tool[2] = BTN_TOOL_TRIPLETAP; 735 - 736 - if (len != WACOM_PKGLEN_TPC1FG) { 737 - 738 - switch (data[0]) { 739 - 740 - case WACOM_REPORT_TPC1FG: 741 - input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); 742 - input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4])); 743 - input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6])); 744 - input_report_key(input, BTN_TOUCH, le16_to_cpup((__le16 *)&data[6])); 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 - 750 - case WACOM_REPORT_TPC2FG: 751 - if (data[1] & 0x01) 752 - wacom_tpc_finger_in(wacom, data, 0); 753 - else if (wacom->id[1] & 0x01) 754 - wacom_tpc_touch_out(wacom, 0); 755 - 756 - if (data[1] & 0x02) 757 - wacom_tpc_finger_in(wacom, data, 1); 758 - else if (wacom->id[1] & 0x02) 759 - wacom_tpc_touch_out(wacom, 1); 760 - break; 716 + if (!wacom->shared->stylus_in_proximity) { 717 + if (len == WACOM_PKGLEN_TPC1FG) { 718 + prox = data[0] & 0x01; 719 + x = get_unaligned_le16(&data[1]); 720 + y = get_unaligned_le16(&data[3]); 721 + } else { /* with capacity */ 722 + prox = data[1] & 0x01; 723 + x = le16_to_cpup((__le16 *)&data[2]); 724 + y = le16_to_cpup((__le16 *)&data[4]); 761 725 } 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); 726 + } else 727 + /* force touch out when pen is in prox */ 728 + prox = 0; 729 + 730 + if (prox) { 731 + input_report_abs(input, ABS_X, x); 732 + input_report_abs(input, ABS_Y, y); 769 733 } 734 + input_report_key(input, BTN_TOUCH, prox); 735 + 736 + /* keep touch state for pen events */ 737 + wacom->shared->touch_down = prox; 738 + 739 + return 1; 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 744 struct wacom_features *features = &wacom->features; 775 745 char *data = wacom->data; 776 746 struct input_dev *input = wacom->input; 777 - int prox = 0, pressure; 778 - int retval = 0; 747 + int pressure; 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 */ 751 + /* Going into proximity select tool */ 752 + wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 781 753 782 - if (len == WACOM_PKGLEN_TPC1FG || /* single touch */ 783 - data[0] == WACOM_REPORT_TPC1FG || /* single touch */ 784 - data[0] == WACOM_REPORT_TPC2FG) { /* 2FG touch */ 754 + /* keep pen state for touch events */ 755 + wacom->shared->stylus_in_proximity = prox; 785 756 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 - 818 - if (wacom->id[1] & 0x02) 819 - wacom_tpc_touch_out(wacom, 1); 820 - } else 821 - /* one finger touch */ 822 - wacom_tpc_touch_out(wacom, 0); 823 - 824 - wacom->id[0] = 0; 825 - } 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 - } 757 + /* send pen events only when touch is up or forced out */ 758 + if (!wacom->shared->touch_down) { 841 759 input_report_key(input, BTN_STYLUS, data[1] & 0x02); 842 760 input_report_key(input, BTN_STYLUS2, data[1] & 0x10); 843 761 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); ··· 765 847 pressure = features->pressure_max + pressure + 1; 766 848 input_report_abs(input, ABS_PRESSURE, pressure); 767 849 input_report_key(input, BTN_TOUCH, data[1] & 0x05); 768 - if (!prox) { /* out-prox */ 769 - wacom->id[0] = 0; 770 - wacom->shared->stylus_in_proximity = false; 771 - } 772 850 input_report_key(input, wacom->tool[0], prox); 773 - input_report_abs(input, ABS_MISC, wacom->id[0]); 774 - retval = 1; 851 + return 1; 775 852 } 776 - return retval; 853 + 854 + return 0; 855 + } 856 + 857 + static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len) 858 + { 859 + char *data = wacom->data; 860 + 861 + dbg("wacom_tpc_irq: received report #%d", data[0]); 862 + 863 + if (len == WACOM_PKGLEN_TPC1FG || data[0] == WACOM_REPORT_TPC1FG) 864 + return wacom_tpc_single_touch(wacom, len); 865 + else if (data[0] == WACOM_REPORT_TPC2FG) 866 + return wacom_tpc_mt_touch(wacom); 867 + else if (data[0] == WACOM_REPORT_PENABLED) 868 + return wacom_tpc_pen(wacom); 869 + 870 + return 0; 777 871 } 778 872 779 873 static int wacom_bpt_touch(struct wacom_wac *wacom) ··· 1008 1078 { 1009 1079 1010 1080 /* touch device found but size is not defined. use default */ 1011 - if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) { 1081 + if (features->device_type == BTN_TOOL_FINGER && !features->x_max) { 1012 1082 features->x_max = 1023; 1013 1083 features->y_max = 1023; 1014 1084 } ··· 1020 1090 1021 1091 /* quirks for bamboo touch */ 1022 1092 if (features->type == BAMBOO_PT && 1023 - features->device_type == BTN_TOOL_TRIPLETAP) { 1093 + features->device_type == BTN_TOOL_DOUBLETAP) { 1024 1094 features->x_max <<= 5; 1025 1095 features->y_max <<= 5; 1026 1096 features->x_fuzz <<= 5; ··· 1156 1226 break; 1157 1227 1158 1228 case TABLETPC2FG: 1159 - if (features->device_type == BTN_TOOL_TRIPLETAP) { 1160 - __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); 1161 - input_set_capability(input_dev, EV_MSC, MSC_SERIAL); 1229 + if (features->device_type == BTN_TOOL_DOUBLETAP) { 1230 + 1231 + input_mt_init_slots(input_dev, 2); 1232 + input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 1233 + 0, MT_TOOL_MAX, 0, 0); 1234 + input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1235 + 0, features->x_max, 0, 0); 1236 + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 1237 + 0, features->y_max, 0, 0); 1162 1238 } 1163 1239 /* fall through */ 1164 1240 1165 1241 case TABLETPC: 1166 - if (features->device_type == BTN_TOOL_DOUBLETAP || 1167 - features->device_type == BTN_TOOL_TRIPLETAP) { 1242 + __clear_bit(ABS_MISC, input_dev->absbit); 1243 + 1244 + if (features->device_type != BTN_TOOL_PEN) { 1168 1245 input_abs_set_res(input_dev, ABS_X, 1169 1246 wacom_calculate_touch_res(features->x_max, 1170 1247 features->x_phy)); 1171 1248 input_abs_set_res(input_dev, ABS_Y, 1172 1249 wacom_calculate_touch_res(features->y_max, 1173 1250 features->y_phy)); 1174 - __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); 1175 - } 1176 - 1177 - if (features->device_type != BTN_TOOL_PEN) 1178 1251 break; /* no need to process stylus stuff */ 1179 - 1252 + } 1180 1253 /* fall through */ 1181 1254 1182 1255 case PL: ··· 1197 1264 case BAMBOO_PT: 1198 1265 __clear_bit(ABS_MISC, input_dev->absbit); 1199 1266 1200 - if (features->device_type == BTN_TOOL_TRIPLETAP) { 1267 + if (features->device_type == BTN_TOOL_DOUBLETAP) { 1201 1268 __set_bit(BTN_LEFT, input_dev->keybit); 1202 1269 __set_bit(BTN_FORWARD, input_dev->keybit); 1203 1270 __set_bit(BTN_BACK, input_dev->keybit);
+3 -3
drivers/input/tablet/wacom_wac.h
··· 88 88 89 89 struct wacom_shared { 90 90 bool stylus_in_proximity; 91 + bool touch_down; 91 92 }; 92 93 93 94 struct wacom_wac { 94 95 char name[64]; 95 96 unsigned char *data; 96 - int tool[3]; 97 - int id[3]; 97 + int tool[2]; 98 + int id[2]; 98 99 __u32 serial[2]; 99 - int last_finger; 100 100 struct wacom_features features; 101 101 struct wacom_shared *shared; 102 102 struct input_dev *input;
+33 -12
drivers/input/touchscreen/Kconfig
··· 86 86 To compile this driver as a module, choose M here: the 87 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 101 config TOUCHSCREEN_BITSY 90 102 tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" 91 103 depends on SA1100_BITSY ··· 351 339 To compile this driver as a module, choose M here: the 352 340 module will be called penmount. 353 341 354 - config TOUCHSCREEN_QT602240 355 - tristate "QT602240 I2C Touchscreen" 356 - depends on I2C 357 - help 358 - Say Y here if you have the AT42QT602240/ATMXT224 I2C touchscreen 359 - connected to your system. 360 - 361 - If unsure, say N. 362 - 363 - To compile this driver as a module, choose M here: the 364 - module will be called qt602240_ts. 365 - 366 342 config TOUCHSCREEN_MIGOR 367 343 tristate "Renesas MIGO-R touchscreen" 368 344 depends on SH_MIGOR && I2C ··· 422 422 423 423 To compile this driver as a module, choose M here: the 424 424 module will be called ucb1400_ts. 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. 425 435 426 436 config TOUCHSCREEN_WM97XX 427 437 tristate "Support for WM97xx AC97 touchscreen controllers" ··· 638 628 639 629 To compile this driver as a module, choose M here: the 640 630 module will be called touchit213. 631 + 632 + config TOUCHSCREEN_TSC2005 633 + tristate "TSC2005 based touchscreens" 634 + depends on SPI_MASTER 635 + help 636 + Say Y here if you have a TSC2005 based touchscreen. 637 + 638 + If unsure, say N. 639 + 640 + To compile this driver as a module, choose M here: the 641 + module will be called tsc2005. 641 642 642 643 config TOUCHSCREEN_TSC2007 643 644 tristate "TSC2007 based touchscreens"
+3 -1
drivers/input/touchscreen/Makefile
··· 12 12 obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o 13 13 obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o 14 14 obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 15 + obj-$(CONFIG_TOUCHSCREEN_ATMEL_MXT) += atmel_mxt_ts.o 15 16 obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o 16 17 obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 17 18 obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o ··· 38 37 obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o 39 38 obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o 40 39 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 41 - obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o 42 40 obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o 43 41 obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o 44 42 obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o ··· 45 45 obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o 46 46 obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 47 47 obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 48 + obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o 48 49 obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o 49 50 obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 50 51 obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o 52 + obj-$(CONFIG_TOUCHSCREEN_WM831X) += wm831x-ts.o 51 53 obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o 52 54 wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o 53 55 wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o
+9 -10
drivers/input/touchscreen/ad7877.c
··· 41 41 #include <linux/delay.h> 42 42 #include <linux/input.h> 43 43 #include <linux/interrupt.h> 44 + #include <linux/pm.h> 44 45 #include <linux/slab.h> 45 46 #include <linux/spi/spi.h> 46 47 #include <linux/spi/ad7877.h> ··· 827 826 return 0; 828 827 } 829 828 830 - #ifdef CONFIG_PM 831 - static int ad7877_suspend(struct spi_device *spi, pm_message_t message) 829 + #ifdef CONFIG_PM_SLEEP 830 + static int ad7877_suspend(struct device *dev) 832 831 { 833 - struct ad7877 *ts = dev_get_drvdata(&spi->dev); 832 + struct ad7877 *ts = dev_get_drvdata(dev); 834 833 835 834 ad7877_disable(ts); 836 835 837 836 return 0; 838 837 } 839 838 840 - static int ad7877_resume(struct spi_device *spi) 839 + static int ad7877_resume(struct device *dev) 841 840 { 842 - struct ad7877 *ts = dev_get_drvdata(&spi->dev); 841 + struct ad7877 *ts = dev_get_drvdata(dev); 843 842 844 843 ad7877_enable(ts); 845 844 846 845 return 0; 847 846 } 848 - #else 849 - #define ad7877_suspend NULL 850 - #define ad7877_resume NULL 851 847 #endif 848 + 849 + static SIMPLE_DEV_PM_OPS(ad7877_pm, ad7877_suspend, ad7877_resume); 852 850 853 851 static struct spi_driver ad7877_driver = { 854 852 .driver = { 855 853 .name = "ad7877", 856 854 .bus = &spi_bus_type, 857 855 .owner = THIS_MODULE, 856 + .pm = &ad7877_pm, 858 857 }, 859 858 .probe = ad7877_probe, 860 859 .remove = __devexit_p(ad7877_remove), 861 - .suspend = ad7877_suspend, 862 - .resume = ad7877_resume, 863 860 }; 864 861 865 862 static int __init ad7877_init(void)
+9 -8
drivers/input/touchscreen/ad7879-spi.c
··· 7 7 */ 8 8 9 9 #include <linux/input.h> /* BUS_SPI */ 10 + #include <linux/pm.h> 10 11 #include <linux/spi/spi.h> 11 12 12 13 #include "ad7879.h" ··· 21 20 #define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) 22 21 #define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) 23 22 24 - #ifdef CONFIG_PM 25 - static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) 23 + #ifdef CONFIG_PM_SLEEP 24 + static int ad7879_spi_suspend(struct device *dev) 26 25 { 26 + struct spi_device *spi = to_spi_device(dev); 27 27 struct ad7879 *ts = spi_get_drvdata(spi); 28 28 29 29 ad7879_suspend(ts); ··· 32 30 return 0; 33 31 } 34 32 35 - static int ad7879_spi_resume(struct spi_device *spi) 33 + static int ad7879_spi_resume(struct device *dev) 36 34 { 35 + struct spi_device *spi = to_spi_device(dev); 37 36 struct ad7879 *ts = spi_get_drvdata(spi); 38 37 39 38 ad7879_resume(ts); 40 39 41 40 return 0; 42 41 } 43 - #else 44 - # define ad7879_spi_suspend NULL 45 - # define ad7879_spi_resume NULL 46 42 #endif 43 + 44 + static SIMPLE_DEV_PM_OPS(ad7879_spi_pm, ad7879_spi_suspend, ad7879_spi_resume); 47 45 48 46 /* 49 47 * ad7879_read/write are only used for initial setup and for sysfs controls. ··· 175 173 .name = "ad7879", 176 174 .bus = &spi_bus_type, 177 175 .owner = THIS_MODULE, 176 + .pm = &ad7879_spi_pm, 178 177 }, 179 178 .probe = ad7879_spi_probe, 180 179 .remove = __devexit_p(ad7879_spi_remove), 181 - .suspend = ad7879_spi_suspend, 182 - .resume = ad7879_spi_resume, 183 180 }; 184 181 185 182 static int __init ad7879_spi_init(void)
+10 -6
drivers/input/touchscreen/ads7846.c
··· 26 26 #include <linux/input.h> 27 27 #include <linux/interrupt.h> 28 28 #include <linux/slab.h> 29 + #include <linux/pm.h> 29 30 #include <linux/gpio.h> 30 31 #include <linux/spi/spi.h> 31 32 #include <linux/spi/ads7846.h> ··· 893 892 return IRQ_HANDLED; 894 893 } 895 894 896 - static int ads7846_suspend(struct spi_device *spi, pm_message_t message) 895 + #ifdef CONFIG_PM_SLEEP 896 + static int ads7846_suspend(struct device *dev) 897 897 { 898 - struct ads7846 *ts = dev_get_drvdata(&spi->dev); 898 + struct ads7846 *ts = dev_get_drvdata(dev); 899 899 900 900 mutex_lock(&ts->lock); 901 901 ··· 916 914 return 0; 917 915 } 918 916 919 - static int ads7846_resume(struct spi_device *spi) 917 + static int ads7846_resume(struct device *dev) 920 918 { 921 - struct ads7846 *ts = dev_get_drvdata(&spi->dev); 919 + struct ads7846 *ts = dev_get_drvdata(dev); 922 920 923 921 mutex_lock(&ts->lock); 924 922 ··· 937 935 938 936 return 0; 939 937 } 938 + #endif 939 + 940 + static SIMPLE_DEV_PM_OPS(ads7846_pm, ads7846_suspend, ads7846_resume); 940 941 941 942 static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) 942 943 { ··· 1413 1408 .name = "ads7846", 1414 1409 .bus = &spi_bus_type, 1415 1410 .owner = THIS_MODULE, 1411 + .pm = &ads7846_pm, 1416 1412 }, 1417 1413 .probe = ads7846_probe, 1418 1414 .remove = __devexit_p(ads7846_remove), 1419 - .suspend = ads7846_suspend, 1420 - .resume = ads7846_resume, 1421 1415 }; 1422 1416 1423 1417 static int __init ads7846_init(void)
+1211
drivers/input/touchscreen/atmel_mxt_ts.c
··· 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");
-1406
drivers/input/touchscreen/qt602240_ts.c
··· 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");
+756
drivers/input/touchscreen/tsc2005.c
··· 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");
+368
drivers/input/touchscreen/wm831x-ts.c
··· 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");
+52 -31
drivers/input/xen-kbdfront.c drivers/input/misc/xen-kbdfront.c
··· 11 11 * more details. 12 12 */ 13 13 14 - /* 15 - * TODO: 16 - * 17 - * Switch to grant tables together with xen-fbfront.c. 18 - */ 19 - 20 14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21 15 22 16 #include <linux/kernel.h> ··· 24 30 #include <xen/xen.h> 25 31 #include <xen/events.h> 26 32 #include <xen/page.h> 33 + #include <xen/grant_table.h> 34 + #include <xen/interface/grant_table.h> 27 35 #include <xen/interface/io/fbif.h> 28 36 #include <xen/interface/io/kbdif.h> 29 37 #include <xen/xenbus.h> ··· 34 38 struct input_dev *kbd; 35 39 struct input_dev *ptr; 36 40 struct xenkbd_page *page; 41 + int gref; 37 42 int irq; 38 43 struct xenbus_device *xbdev; 39 44 char phys[32]; ··· 107 110 static int __devinit xenkbd_probe(struct xenbus_device *dev, 108 111 const struct xenbus_device_id *id) 109 112 { 110 - int ret, i; 113 + int ret, i, abs; 111 114 struct xenkbd_info *info; 112 115 struct input_dev *kbd, *ptr; 113 116 ··· 119 122 dev_set_drvdata(&dev->dev, info); 120 123 info->xbdev = dev; 121 124 info->irq = -1; 125 + info->gref = -1; 122 126 snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename); 123 127 124 128 info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); 125 129 if (!info->page) 126 130 goto error_nomem; 131 + 132 + if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0) 133 + abs = 0; 134 + if (abs) 135 + xenbus_printf(XBT_NIL, dev->nodename, "request-abs-pointer", "1"); 127 136 128 137 /* keyboard */ 129 138 kbd = input_allocate_device(); ··· 140 137 kbd->id.bustype = BUS_PCI; 141 138 kbd->id.vendor = 0x5853; 142 139 kbd->id.product = 0xffff; 143 - kbd->evbit[0] = BIT(EV_KEY); 140 + 141 + __set_bit(EV_KEY, kbd->evbit); 144 142 for (i = KEY_ESC; i < KEY_UNKNOWN; i++) 145 - set_bit(i, kbd->keybit); 143 + __set_bit(i, kbd->keybit); 146 144 for (i = KEY_OK; i < KEY_MAX; i++) 147 - set_bit(i, kbd->keybit); 145 + __set_bit(i, kbd->keybit); 148 146 149 147 ret = input_register_device(kbd); 150 148 if (ret) { ··· 164 160 ptr->id.bustype = BUS_PCI; 165 161 ptr->id.vendor = 0x5853; 166 162 ptr->id.product = 0xfffe; 167 - ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS); 163 + 164 + if (abs) { 165 + __set_bit(EV_ABS, ptr->evbit); 166 + input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0); 167 + input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0); 168 + } else { 169 + input_set_capability(ptr, EV_REL, REL_X); 170 + input_set_capability(ptr, EV_REL, REL_Y); 171 + } 172 + input_set_capability(ptr, EV_REL, REL_WHEEL); 173 + 174 + __set_bit(EV_KEY, ptr->evbit); 168 175 for (i = BTN_LEFT; i <= BTN_TASK; i++) 169 - set_bit(i, ptr->keybit); 170 - ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL); 171 - input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0); 172 - input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0); 176 + __set_bit(i, ptr->keybit); 173 177 174 178 ret = input_register_device(ptr); 175 179 if (ret) { ··· 230 218 int ret, evtchn; 231 219 struct xenbus_transaction xbt; 232 220 221 + ret = gnttab_grant_foreign_access(dev->otherend_id, 222 + virt_to_mfn(info->page), 0); 223 + if (ret < 0) 224 + return ret; 225 + info->gref = ret; 226 + 233 227 ret = xenbus_alloc_evtchn(dev, &evtchn); 234 228 if (ret) 235 - return ret; 229 + goto error_grant; 236 230 ret = bind_evtchn_to_irqhandler(evtchn, input_handler, 237 231 0, dev->devicetype, info); 238 232 if (ret < 0) { 239 - xenbus_free_evtchn(dev, evtchn); 240 233 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); 241 - return ret; 234 + goto error_evtchan; 242 235 } 243 236 info->irq = ret; 244 237 ··· 251 234 ret = xenbus_transaction_start(&xbt); 252 235 if (ret) { 253 236 xenbus_dev_fatal(dev, ret, "starting transaction"); 254 - return ret; 237 + goto error_irqh; 255 238 } 256 239 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", 257 240 virt_to_mfn(info->page)); 241 + if (ret) 242 + goto error_xenbus; 243 + ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref); 258 244 if (ret) 259 245 goto error_xenbus; 260 246 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", ··· 269 249 if (ret == -EAGAIN) 270 250 goto again; 271 251 xenbus_dev_fatal(dev, ret, "completing transaction"); 272 - return ret; 252 + goto error_irqh; 273 253 } 274 254 275 255 xenbus_switch_state(dev, XenbusStateInitialised); ··· 278 258 error_xenbus: 279 259 xenbus_transaction_end(xbt, 1); 280 260 xenbus_dev_fatal(dev, ret, "writing xenstore"); 261 + error_irqh: 262 + unbind_from_irqhandler(info->irq, info); 263 + info->irq = -1; 264 + error_evtchan: 265 + xenbus_free_evtchn(dev, evtchn); 266 + error_grant: 267 + gnttab_end_foreign_access_ref(info->gref, 0); 268 + info->gref = -1; 281 269 return ret; 282 270 } 283 271 ··· 294 266 if (info->irq >= 0) 295 267 unbind_from_irqhandler(info->irq, info); 296 268 info->irq = -1; 269 + if (info->gref >= 0) 270 + gnttab_end_foreign_access_ref(info->gref, 0); 271 + info->gref = -1; 297 272 } 298 273 299 274 static void xenkbd_backend_changed(struct xenbus_device *dev, 300 275 enum xenbus_state backend_state) 301 276 { 302 277 struct xenkbd_info *info = dev_get_drvdata(&dev->dev); 303 - int ret, val; 278 + int val; 304 279 305 280 switch (backend_state) { 306 281 case XenbusStateInitialising: ··· 316 285 317 286 case XenbusStateInitWait: 318 287 InitWait: 319 - ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend, 320 - "feature-abs-pointer", "%d", &val); 321 - if (ret < 0) 322 - val = 0; 323 - if (val) { 324 - ret = xenbus_printf(XBT_NIL, info->xbdev->nodename, 325 - "request-abs-pointer", "1"); 326 - if (ret) 327 - pr_warning("can't request abs-pointer\n"); 328 - } 329 288 xenbus_switch_state(dev, XenbusStateConnected); 330 289 break; 331 290
+68 -41
drivers/media/dvb/dvb-usb/dvb-usb-remote.c
··· 8 8 #include "dvb-usb-common.h" 9 9 #include <linux/usb/input.h> 10 10 11 + static unsigned int 12 + legacy_dvb_usb_get_keymap_index(const struct input_keymap_entry *ke, 13 + struct rc_map_table *keymap, 14 + unsigned int keymap_size) 15 + { 16 + unsigned int index; 17 + unsigned int scancode; 18 + 19 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) { 20 + index = ke->index; 21 + } else { 22 + if (input_scancode_to_scalar(ke, &scancode)) 23 + return keymap_size; 24 + 25 + /* See if we can match the raw key code. */ 26 + for (index = 0; index < keymap_size; index++) 27 + if (keymap[index].scancode == scancode) 28 + break; 29 + 30 + /* See if there is an unused hole in the map */ 31 + if (index >= keymap_size) { 32 + for (index = 0; index < keymap_size; index++) { 33 + if (keymap[index].keycode == KEY_RESERVED || 34 + keymap[index].keycode == KEY_UNKNOWN) { 35 + break; 36 + } 37 + } 38 + } 39 + } 40 + 41 + return index; 42 + } 43 + 11 44 static int legacy_dvb_usb_getkeycode(struct input_dev *dev, 12 - unsigned int scancode, unsigned int *keycode) 45 + struct input_keymap_entry *ke) 13 46 { 14 47 struct dvb_usb_device *d = input_get_drvdata(dev); 15 - 16 48 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; 17 - int i; 49 + unsigned int keymap_size = d->props.rc.legacy.rc_map_size; 50 + unsigned int index; 18 51 19 - /* See if we can match the raw key code. */ 20 - for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 21 - if (keymap[i].scancode == scancode) { 22 - *keycode = keymap[i].keycode; 23 - return 0; 24 - } 52 + index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size); 53 + if (index >= keymap_size) 54 + return -EINVAL; 25 55 26 - /* 27 - * If is there extra space, returns KEY_RESERVED, 28 - * otherwise, input core won't let legacy_dvb_usb_setkeycode 29 - * to work 30 - */ 31 - for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 32 - if (keymap[i].keycode == KEY_RESERVED || 33 - keymap[i].keycode == KEY_UNKNOWN) { 34 - *keycode = KEY_RESERVED; 35 - return 0; 36 - } 56 + ke->keycode = keymap[index].keycode; 57 + if (ke->keycode == KEY_UNKNOWN) 58 + ke->keycode = KEY_RESERVED; 59 + ke->len = sizeof(keymap[index].scancode); 60 + memcpy(&ke->scancode, &keymap[index].scancode, ke->len); 61 + ke->index = index; 37 62 38 - return -EINVAL; 63 + return 0; 39 64 } 40 65 41 66 static int legacy_dvb_usb_setkeycode(struct input_dev *dev, 42 - unsigned int scancode, unsigned int keycode) 67 + const struct input_keymap_entry *ke, 68 + unsigned int *old_keycode) 43 69 { 44 70 struct dvb_usb_device *d = input_get_drvdata(dev); 45 - 46 71 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; 47 - int i; 72 + unsigned int keymap_size = d->props.rc.legacy.rc_map_size; 73 + unsigned int index; 48 74 49 - /* Search if it is replacing an existing keycode */ 50 - for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 51 - if (keymap[i].scancode == scancode) { 52 - keymap[i].keycode = keycode; 53 - return 0; 54 - } 55 - 56 - /* Search if is there a clean entry. If so, use it */ 57 - for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 58 - if (keymap[i].keycode == KEY_RESERVED || 59 - keymap[i].keycode == KEY_UNKNOWN) { 60 - keymap[i].scancode = scancode; 61 - keymap[i].keycode = keycode; 62 - return 0; 63 - } 64 - 75 + index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size); 65 76 /* 66 77 * FIXME: Currently, it is not possible to increase the size of 67 78 * scancode table. For it to happen, one possibility ··· 80 69 * copying data, appending the new key on it, and freeing 81 70 * the old one - or maybe just allocating some spare space 82 71 */ 72 + if (index >= keymap_size) 73 + return -EINVAL; 83 74 84 - return -EINVAL; 75 + *old_keycode = keymap[index].keycode; 76 + keymap->keycode = ke->keycode; 77 + __set_bit(ke->keycode, dev->keybit); 78 + 79 + if (*old_keycode != KEY_RESERVED) { 80 + __clear_bit(*old_keycode, dev->keybit); 81 + for (index = 0; index < keymap_size; index++) { 82 + if (keymap[index].keycode == *old_keycode) { 83 + __set_bit(*old_keycode, dev->keybit); 84 + break; 85 + } 86 + } 87 + } 88 + 89 + return 0; 85 90 } 86 91 87 92 /* Remote-control poll function - called every dib->rc_query_interval ms to see
+2 -2
drivers/media/rc/rc-main.c
··· 966 966 return NULL; 967 967 } 968 968 969 - dev->input_dev->getkeycode_new = ir_getkeycode; 970 - dev->input_dev->setkeycode_new = ir_setkeycode; 969 + dev->input_dev->getkeycode = ir_getkeycode; 970 + dev->input_dev->setkeycode = ir_setkeycode; 971 971 input_set_drvdata(dev->input_dev, dev); 972 972 973 973 spin_lock_init(&dev->rc_map.lock);
+1
include/linux/i2c/mcs.h
··· 18 18 #define MCS_KEY_CODE(v) ((v) & 0xffff) 19 19 20 20 struct mcs_platform_data { 21 + void (*poweron)(bool); 21 22 void (*cfg_pin)(void); 22 23 23 24 /* touchscreen */
+20 -14
include/linux/i2c/qt602240_ts.h include/linux/i2c/atmel_mxt_ts.h
··· 1 1 /* 2 - * AT42QT602240/ATMXT224 Touchscreen driver 2 + * Atmel maXTouch Touchscreen driver 3 3 * 4 4 * Copyright (C) 2010 Samsung Electronics Co.Ltd 5 5 * Author: Joonyoung Shim <jy0922.shim@samsung.com> ··· 10 10 * option) any later version. 11 11 */ 12 12 13 - #ifndef __LINUX_QT602240_TS_H 14 - #define __LINUX_QT602240_TS_H 13 + #ifndef __LINUX_ATMEL_MXT_TS_H 14 + #define __LINUX_ATMEL_MXT_TS_H 15 + 16 + #include <linux/types.h> 15 17 16 18 /* Orient */ 17 - #define QT602240_NORMAL 0x0 18 - #define QT602240_DIAGONAL 0x1 19 - #define QT602240_HORIZONTAL_FLIP 0x2 20 - #define QT602240_ROTATED_90_COUNTER 0x3 21 - #define QT602240_VERTICAL_FLIP 0x4 22 - #define QT602240_ROTATED_90 0x5 23 - #define QT602240_ROTATED_180 0x6 24 - #define QT602240_DIAGONAL_COUNTER 0x7 19 + #define MXT_NORMAL 0x0 20 + #define MXT_DIAGONAL 0x1 21 + #define MXT_HORIZONTAL_FLIP 0x2 22 + #define MXT_ROTATED_90_COUNTER 0x3 23 + #define MXT_VERTICAL_FLIP 0x4 24 + #define MXT_ROTATED_90 0x5 25 + #define MXT_ROTATED_180 0x6 26 + #define MXT_DIAGONAL_COUNTER 0x7 25 27 26 - /* The platform data for the AT42QT602240/ATMXT224 touchscreen driver */ 27 - struct qt602240_platform_data { 28 + /* The platform data for the Atmel maXTouch touchscreen driver */ 29 + struct mxt_platform_data { 30 + const u8 *config; 31 + size_t config_length; 32 + 28 33 unsigned int x_line; 29 34 unsigned int y_line; 30 35 unsigned int x_size; ··· 38 33 unsigned int threshold; 39 34 unsigned int voltage; 40 35 unsigned char orient; 36 + unsigned long irqflags; 41 37 }; 42 38 43 - #endif /* __LINUX_QT602240_TS_H */ 39 + #endif /* __LINUX_ATMEL_MXT_TS_H */
+2 -2
include/linux/input-polldev.h
··· 22 22 * @poll: driver-supplied method that polls the device and posts 23 23 * input events (mandatory). 24 24 * @poll_interval: specifies how often the poll() method should be called. 25 - * Defaults to 500 msec unless overriden when registering the device. 25 + * Defaults to 500 msec unless overridden when registering the device. 26 26 * @poll_interval_max: specifies upper bound for the poll interval. 27 27 * Defaults to the initial value of @poll_interval. 28 28 * @poll_interval_min: specifies lower bound for the poll interval. 29 29 * Defaults to 0. 30 - * @input: input device structire associated with the polled device. 30 + * @input: input device structure associated with the polled device. 31 31 * Must be properly initialized by the driver (id, name, phys, bits). 32 32 * 33 33 * Polled input device provides a skeleton for supporting simple input
+3 -9
include/linux/input.h
··· 1154 1154 * sparse keymaps. If not supplied default mechanism will be used. 1155 1155 * The method is being called while holding event_lock and thus must 1156 1156 * not sleep 1157 - * @getkeycode_new: transition method 1158 - * @setkeycode_new: transition method 1159 1157 * @ff: force feedback structure associated with the device if device 1160 1158 * supports force feedback effects 1161 1159 * @repeat_key: stores key code of the last key pressed; used to implement ··· 1232 1234 void *keycode; 1233 1235 1234 1236 int (*setkeycode)(struct input_dev *dev, 1235 - unsigned int scancode, unsigned int keycode); 1237 + const struct input_keymap_entry *ke, 1238 + unsigned int *old_keycode); 1236 1239 int (*getkeycode)(struct input_dev *dev, 1237 - unsigned int scancode, unsigned int *keycode); 1238 - int (*setkeycode_new)(struct input_dev *dev, 1239 - const struct input_keymap_entry *ke, 1240 - unsigned int *old_keycode); 1241 - int (*getkeycode_new)(struct input_dev *dev, 1242 - struct input_keymap_entry *ke); 1240 + struct input_keymap_entry *ke); 1243 1241 1244 1242 struct ff_device *ff; 1245 1243
+2 -1
include/linux/mfd/wm831x/pdata.h
··· 80 80 int isel; /** Current for pen down (uA) */ 81 81 int rpu; /** Pen down sensitivity resistor divider */ 82 82 int pressure; /** Report pressure (boolean) */ 83 - int data_irq; /** Touch data ready IRQ */ 83 + unsigned int data_irq; /** Touch data ready IRQ */ 84 + unsigned int pd_irq; /** Touch pendown detect IRQ */ 84 85 }; 85 86 86 87 enum wm831x_watchdog_action {
+41
include/linux/spi/tsc2005.h
··· 1 + /* 2 + * This file is part of TSC2005 touchscreen driver 3 + * 4 + * Copyright (C) 2009-2010 Nokia Corporation 5 + * 6 + * Contact: Aaro Koskinen <aaro.koskinen@nokia.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + * 18 + * You should have received a copy of the GNU General Public License 19 + * along with this program; if not, write to the Free Software 20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 + * 22 + */ 23 + 24 + #ifndef _LINUX_SPI_TSC2005_H 25 + #define _LINUX_SPI_TSC2005_H 26 + 27 + #include <linux/types.h> 28 + 29 + struct tsc2005_platform_data { 30 + int ts_pressure_max; 31 + int ts_pressure_fudge; 32 + int ts_x_max; 33 + int ts_x_fudge; 34 + int ts_y_max; 35 + int ts_y_fudge; 36 + int ts_x_plate_ohm; 37 + unsigned int esd_timeout_ms; 38 + void (*set_reset)(bool enable); 39 + }; 40 + 41 + #endif