Merge branch 'next' into for-linus

+5789 -1853
+129
arch/arm/mach-ux500/board-mop500.c
··· 18 18 #include <linux/amba/pl022.h> 19 19 #include <linux/spi/spi.h> 20 20 #include <linux/mfd/ab8500.h> 21 + #include <linux/input/matrix_keypad.h> 21 22 22 23 #include <asm/mach-types.h> 23 24 #include <asm/mach/arch.h> 24 25 25 26 #include <plat/pincfg.h> 26 27 #include <plat/i2c.h> 28 + #include <plat/ske.h> 27 29 28 30 #include <mach/hardware.h> 29 31 #include <mach/setup.h> ··· 49 47 GPIO11_I2C2_SCL, 50 48 GPIO229_I2C3_SDA, 51 49 GPIO230_I2C3_SCL, 50 + 51 + /* SKE keypad */ 52 + GPIO153_KP_I7, 53 + GPIO154_KP_I6, 54 + GPIO155_KP_I5, 55 + GPIO156_KP_I4, 56 + GPIO157_KP_O7, 57 + GPIO158_KP_O6, 58 + GPIO159_KP_O5, 59 + GPIO160_KP_O4, 60 + GPIO161_KP_I3, 61 + GPIO162_KP_I2, 62 + GPIO163_KP_I1, 63 + GPIO164_KP_I0, 64 + GPIO165_KP_O3, 65 + GPIO166_KP_O2, 66 + GPIO167_KP_O1, 67 + GPIO168_KP_O0, 52 68 }; 53 69 54 70 static void ab4500_spi_cs_control(u32 command) ··· 154 134 &u8500_ssp0_device, 155 135 }; 156 136 137 + static const unsigned int ux500_keymap[] = { 138 + KEY(2, 5, KEY_END), 139 + KEY(4, 1, KEY_POWER), 140 + KEY(3, 5, KEY_VOLUMEDOWN), 141 + KEY(1, 3, KEY_3), 142 + KEY(5, 2, KEY_RIGHT), 143 + KEY(5, 0, KEY_9), 144 + 145 + KEY(0, 5, KEY_MENU), 146 + KEY(7, 6, KEY_ENTER), 147 + KEY(4, 5, KEY_0), 148 + KEY(6, 7, KEY_2), 149 + KEY(3, 4, KEY_UP), 150 + KEY(3, 3, KEY_DOWN), 151 + 152 + KEY(6, 4, KEY_SEND), 153 + KEY(6, 2, KEY_BACK), 154 + KEY(4, 2, KEY_VOLUMEUP), 155 + KEY(5, 5, KEY_1), 156 + KEY(4, 3, KEY_LEFT), 157 + KEY(3, 2, KEY_7), 158 + }; 159 + 160 + static const struct matrix_keymap_data ux500_keymap_data = { 161 + .keymap = ux500_keymap, 162 + .keymap_size = ARRAY_SIZE(ux500_keymap), 163 + }; 164 + 165 + /* 166 + * Nomadik SKE keypad 167 + */ 168 + #define ROW_PIN_I0 164 169 + #define ROW_PIN_I1 163 170 + #define ROW_PIN_I2 162 171 + #define ROW_PIN_I3 161 172 + #define ROW_PIN_I4 156 173 + #define ROW_PIN_I5 155 174 + #define ROW_PIN_I6 154 175 + #define ROW_PIN_I7 153 176 + #define COL_PIN_O0 168 177 + #define COL_PIN_O1 167 178 + #define COL_PIN_O2 166 179 + #define COL_PIN_O3 165 180 + #define COL_PIN_O4 160 181 + #define COL_PIN_O5 159 182 + #define COL_PIN_O6 158 183 + #define COL_PIN_O7 157 184 + 185 + #define SKE_KPD_MAX_ROWS 8 186 + #define SKE_KPD_MAX_COLS 8 187 + 188 + static int ske_kp_rows[] = { 189 + ROW_PIN_I0, ROW_PIN_I1, ROW_PIN_I2, ROW_PIN_I3, 190 + ROW_PIN_I4, ROW_PIN_I5, ROW_PIN_I6, ROW_PIN_I7, 191 + }; 192 + 193 + /* 194 + * ske_set_gpio_row: request and set gpio rows 195 + */ 196 + static int ske_set_gpio_row(int gpio) 197 + { 198 + int ret; 199 + 200 + ret = gpio_request(gpio, "ske-kp"); 201 + if (ret < 0) { 202 + pr_err("ske_set_gpio_row: gpio request failed\n"); 203 + return ret; 204 + } 205 + 206 + ret = gpio_direction_output(gpio, 1); 207 + if (ret < 0) { 208 + pr_err("ske_set_gpio_row: gpio direction failed\n"); 209 + gpio_free(gpio); 210 + } 211 + 212 + return ret; 213 + } 214 + 215 + /* 216 + * ske_kp_init - enable the gpio configuration 217 + */ 218 + static int ske_kp_init(void) 219 + { 220 + int ret, i; 221 + 222 + for (i = 0; i < SKE_KPD_MAX_ROWS; i++) { 223 + ret = ske_set_gpio_row(ske_kp_rows[i]); 224 + if (ret < 0) { 225 + pr_err("ske_kp_init: failed init\n"); 226 + return ret; 227 + } 228 + } 229 + 230 + return 0; 231 + } 232 + 233 + static struct ske_keypad_platform_data ske_keypad_board = { 234 + .init = ske_kp_init, 235 + .keymap_data = &ux500_keymap_data, 236 + .no_autorepeat = true, 237 + .krow = SKE_KPD_MAX_ROWS, /* 8x8 matrix */ 238 + .kcol = SKE_KPD_MAX_COLS, 239 + .debounce_ms = 40, /* in millsecs */ 240 + }; 241 + 242 + 243 + 157 244 /* add any platform devices here - TODO */ 158 245 static struct platform_device *platform_devs[] __initdata = { 159 246 &u8500_i2c0_device, 160 247 &ux500_i2c1_device, 161 248 &ux500_i2c2_device, 162 249 &ux500_i2c3_device, 250 + &ux500_ske_keypad_device, 163 251 }; 164 252 165 253 static void __init u8500_init_machine(void) ··· 282 154 ux500_i2c1_device.dev.platform_data = &u8500_i2c1_data; 283 155 ux500_i2c2_device.dev.platform_data = &u8500_i2c2_data; 284 156 ux500_i2c3_device.dev.platform_data = &u8500_i2c3_data; 157 + ux500_ske_keypad_device.dev.platform_data = &ske_keypad_board; 285 158 286 159 u8500_ssp0_device.dev.platform_data = &ssp0_platform_data; 287 160
+1
arch/arm/mach-ux500/clock.c
··· 477 477 CLK(sdi5, "sdi5", NULL), 478 478 CLK(uart2, "uart2", NULL), 479 479 CLK(ske, "ske", NULL), 480 + CLK(ske, "nmk-ske-keypad", NULL), 480 481 CLK(sdi2, "sdi2", NULL), 481 482 CLK(i2c0, "nmk-i2c.0", NULL), 482 483 CLK(fsmc, "fsmc", NULL),
+20
arch/arm/mach-ux500/devices-db8500.c
··· 216 216 dma40_resources[1].start = U8500_DMA_LCPA_BASE_ED; 217 217 dma40_resources[1].end = U8500_DMA_LCPA_BASE_ED + 2 * SZ_1K - 1; 218 218 } 219 + 220 + struct resource keypad_resources[] = { 221 + [0] = { 222 + .start = U8500_SKE_BASE, 223 + .end = U8500_SKE_BASE + SZ_4K - 1, 224 + .flags = IORESOURCE_MEM, 225 + }, 226 + [1] = { 227 + .start = IRQ_DB8500_KB, 228 + .end = IRQ_DB8500_KB, 229 + .flags = IORESOURCE_IRQ, 230 + }, 231 + }; 232 + 233 + struct platform_device ux500_ske_keypad_device = { 234 + .name = "nmk-ske-keypad", 235 + .id = -1, 236 + .num_resources = ARRAY_SIZE(keypad_resources), 237 + .resource = keypad_resources, 238 + };
+1
arch/arm/mach-ux500/include/mach/devices.h
··· 26 26 extern struct platform_device u8500_i2c0_device; 27 27 extern struct platform_device u8500_i2c4_device; 28 28 extern struct platform_device u8500_dma40_device; 29 + extern struct platform_device ux500_ske_keypad_device; 29 30 30 31 void dma40_u8500ed_fixup(void); 31 32
+16 -16
arch/arm/mach-ux500/pins-db8500.h
··· 459 459 #define GPIO152_KP_O9 PIN_CFG(152, ALT_C) 460 460 461 461 #define GPIO153_GPIO PIN_CFG(153, GPIO) 462 - #define GPIO153_KP_I7 PIN_CFG(153, ALT_A) 462 + #define GPIO153_KP_I7 PIN_CFG_PULL(153, ALT_A, DOWN) 463 463 #define GPIO153_LCD_D24 PIN_CFG(153, ALT_B) 464 464 #define GPIO153_U2_RXD PIN_CFG(153, ALT_C) 465 465 466 466 #define GPIO154_GPIO PIN_CFG(154, GPIO) 467 - #define GPIO154_KP_I6 PIN_CFG(154, ALT_A) 467 + #define GPIO154_KP_I6 PIN_CFG_PULL(154, ALT_A, DOWN) 468 468 #define GPIO154_LCD_D25 PIN_CFG(154, ALT_B) 469 469 #define GPIO154_U2_TXD PIN_CFG(154, ALT_C) 470 470 471 471 #define GPIO155_GPIO PIN_CFG(155, GPIO) 472 - #define GPIO155_KP_I5 PIN_CFG(155, ALT_A) 472 + #define GPIO155_KP_I5 PIN_CFG_PULL(155, ALT_A, DOWN) 473 473 #define GPIO155_LCD_D26 PIN_CFG(155, ALT_B) 474 474 #define GPIO155_STMAPE_CLK PIN_CFG(155, ALT_C) 475 475 476 476 #define GPIO156_GPIO PIN_CFG(156, GPIO) 477 - #define GPIO156_KP_I4 PIN_CFG(156, ALT_A) 477 + #define GPIO156_KP_I4 PIN_CFG_PULL(156, ALT_A, DOWN) 478 478 #define GPIO156_LCD_D27 PIN_CFG(156, ALT_B) 479 479 #define GPIO156_STMAPE_DAT3 PIN_CFG(156, ALT_C) 480 480 481 481 #define GPIO157_GPIO PIN_CFG(157, GPIO) 482 - #define GPIO157_KP_O7 PIN_CFG(157, ALT_A) 482 + #define GPIO157_KP_O7 PIN_CFG_PULL(157, ALT_A, UP) 483 483 #define GPIO157_LCD_D28 PIN_CFG(157, ALT_B) 484 484 #define GPIO157_STMAPE_DAT2 PIN_CFG(157, ALT_C) 485 485 486 486 #define GPIO158_GPIO PIN_CFG(158, GPIO) 487 - #define GPIO158_KP_O6 PIN_CFG(158, ALT_A) 487 + #define GPIO158_KP_O6 PIN_CFG_PULL(158, ALT_A, UP) 488 488 #define GPIO158_LCD_D29 PIN_CFG(158, ALT_B) 489 489 #define GPIO158_STMAPE_DAT1 PIN_CFG(158, ALT_C) 490 490 491 491 #define GPIO159_GPIO PIN_CFG(159, GPIO) 492 - #define GPIO159_KP_O5 PIN_CFG(159, ALT_A) 492 + #define GPIO159_KP_O5 PIN_CFG_PULL(159, ALT_A, UP) 493 493 #define GPIO159_LCD_D30 PIN_CFG(159, ALT_B) 494 494 #define GPIO159_STMAPE_DAT0 PIN_CFG(159, ALT_C) 495 495 496 496 #define GPIO160_GPIO PIN_CFG(160, GPIO) 497 - #define GPIO160_KP_O4 PIN_CFG(160, ALT_A) 497 + #define GPIO160_KP_O4 PIN_CFG_PULL(160, ALT_A, UP) 498 498 #define GPIO160_LCD_D31 PIN_CFG(160, ALT_B) 499 499 #define GPIO160_NONE PIN_CFG(160, ALT_C) 500 500 501 501 #define GPIO161_GPIO PIN_CFG(161, GPIO) 502 - #define GPIO161_KP_I3 PIN_CFG(161, ALT_A) 502 + #define GPIO161_KP_I3 PIN_CFG_PULL(161, ALT_A, DOWN) 503 503 #define GPIO161_LCD_D32 PIN_CFG(161, ALT_B) 504 504 #define GPIO161_UARTMOD_RXD PIN_CFG(161, ALT_C) 505 505 506 506 #define GPIO162_GPIO PIN_CFG(162, GPIO) 507 - #define GPIO162_KP_I2 PIN_CFG(162, ALT_A) 507 + #define GPIO162_KP_I2 PIN_CFG_PULL(162, ALT_A, DOWN) 508 508 #define GPIO162_LCD_D33 PIN_CFG(162, ALT_B) 509 509 #define GPIO162_UARTMOD_TXD PIN_CFG(162, ALT_C) 510 510 511 511 #define GPIO163_GPIO PIN_CFG(163, GPIO) 512 - #define GPIO163_KP_I1 PIN_CFG(163, ALT_A) 512 + #define GPIO163_KP_I1 PIN_CFG_PULL(163, ALT_A, DOWN) 513 513 #define GPIO163_LCD_D34 PIN_CFG(163, ALT_B) 514 514 #define GPIO163_STMMOD_CLK PIN_CFG(163, ALT_C) 515 515 516 516 #define GPIO164_GPIO PIN_CFG(164, GPIO) 517 - #define GPIO164_KP_I0 PIN_CFG(164, ALT_A) 517 + #define GPIO164_KP_I0 PIN_CFG_PULL(164, ALT_A, UP) 518 518 #define GPIO164_LCD_D35 PIN_CFG(164, ALT_B) 519 519 #define GPIO164_STMMOD_DAT3 PIN_CFG(164, ALT_C) 520 520 521 521 #define GPIO165_GPIO PIN_CFG(165, GPIO) 522 - #define GPIO165_KP_O3 PIN_CFG(165, ALT_A) 522 + #define GPIO165_KP_O3 PIN_CFG_PULL(165, ALT_A, UP) 523 523 #define GPIO165_LCD_D36 PIN_CFG(165, ALT_B) 524 524 #define GPIO165_STMMOD_DAT2 PIN_CFG(165, ALT_C) 525 525 526 526 #define GPIO166_GPIO PIN_CFG(166, GPIO) 527 - #define GPIO166_KP_O2 PIN_CFG(166, ALT_A) 527 + #define GPIO166_KP_O2 PIN_CFG_PULL(166, ALT_A, UP) 528 528 #define GPIO166_LCD_D37 PIN_CFG(166, ALT_B) 529 529 #define GPIO166_STMMOD_DAT1 PIN_CFG(166, ALT_C) 530 530 531 531 #define GPIO167_GPIO PIN_CFG(167, GPIO) 532 - #define GPIO167_KP_O1 PIN_CFG(167, ALT_A) 532 + #define GPIO167_KP_O1 PIN_CFG_PULL(167, ALT_A, UP) 533 533 #define GPIO167_LCD_D38 PIN_CFG(167, ALT_B) 534 534 #define GPIO167_STMMOD_DAT0 PIN_CFG(167, ALT_C) 535 535 536 536 #define GPIO168_GPIO PIN_CFG(168, GPIO) 537 - #define GPIO168_KP_O0 PIN_CFG(168, ALT_A) 537 + #define GPIO168_KP_O0 PIN_CFG_PULL(168, ALT_A, UP) 538 538 #define GPIO168_LCD_D39 PIN_CFG(168, ALT_B) 539 539 #define GPIO168_NONE PIN_CFG(168, ALT_C) 540 540
+50
arch/arm/plat-nomadik/include/plat/ske.h
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * 4 + * License Terms: GNU General Public License v2 5 + * Author: Naveen Kumar Gaddipati <naveen.gaddipati@stericsson.com> 6 + * 7 + * ux500 Scroll key and Keypad Encoder (SKE) header 8 + */ 9 + 10 + #ifndef __SKE_H 11 + #define __SKE_H 12 + 13 + #include <linux/input/matrix_keypad.h> 14 + 15 + /* register definitions for SKE peripheral */ 16 + #define SKE_CR 0x00 17 + #define SKE_VAL0 0x04 18 + #define SKE_VAL1 0x08 19 + #define SKE_DBCR 0x0C 20 + #define SKE_IMSC 0x10 21 + #define SKE_RIS 0x14 22 + #define SKE_MIS 0x18 23 + #define SKE_ICR 0x1C 24 + 25 + /* 26 + * Keypad module 27 + */ 28 + 29 + /** 30 + * struct keypad_platform_data - structure for platform specific data 31 + * @init: pointer to keypad init function 32 + * @exit: pointer to keypad deinitialisation function 33 + * @keymap_data: matrix scan code table for keycodes 34 + * @krow: maximum number of rows 35 + * @kcol: maximum number of columns 36 + * @debounce_ms: platform specific debounce time 37 + * @no_autorepeat: flag for auto repetition 38 + * @wakeup_enable: allow waking up the system 39 + */ 40 + struct ske_keypad_platform_data { 41 + int (*init)(void); 42 + int (*exit)(void); 43 + const struct matrix_keymap_data *keymap_data; 44 + u8 krow; 45 + u8 kcol; 46 + u8 debounce_ms; 47 + bool no_autorepeat; 48 + bool wakeup_enable; 49 + }; 50 + #endif /*__SKE_KPD_H*/
+14
arch/arm/plat-omap/include/plat/omap4-keypad.h
··· 1 + #ifndef ARCH_ARM_PLAT_OMAP4_KEYPAD_H 2 + #define ARCH_ARM_PLAT_OMAP4_KEYPAD_H 3 + 4 + #include <linux/input/matrix_keypad.h> 5 + 6 + struct omap4_keypad_platform_data { 7 + const struct matrix_keymap_data *keymap_data; 8 + 9 + u8 rows; 10 + u8 cols; 11 + }; 12 + 13 + extern int omap4_keyboard_init(struct omap4_keypad_platform_data *); 14 + #endif
+24 -7
drivers/char/keyboard.c
··· 175 175 */ 176 176 177 177 struct getset_keycode_data { 178 - unsigned int scancode; 179 - unsigned int keycode; 178 + struct input_keymap_entry ke; 180 179 int error; 181 180 }; 182 181 ··· 183 184 { 184 185 struct getset_keycode_data *d = data; 185 186 186 - d->error = input_get_keycode(handle->dev, d->scancode, &d->keycode); 187 + d->error = input_get_keycode(handle->dev, &d->ke); 187 188 188 189 return d->error == 0; /* stop as soon as we successfully get one */ 189 190 } 190 191 191 192 int getkeycode(unsigned int scancode) 192 193 { 193 - struct getset_keycode_data d = { scancode, 0, -ENODEV }; 194 + struct getset_keycode_data d = { 195 + .ke = { 196 + .flags = 0, 197 + .len = sizeof(scancode), 198 + .keycode = 0, 199 + }, 200 + .error = -ENODEV, 201 + }; 202 + 203 + memcpy(d.ke.scancode, &scancode, sizeof(scancode)); 194 204 195 205 input_handler_for_each_handle(&kbd_handler, &d, getkeycode_helper); 196 206 197 - return d.error ?: d.keycode; 207 + return d.error ?: d.ke.keycode; 198 208 } 199 209 200 210 static int setkeycode_helper(struct input_handle *handle, void *data) 201 211 { 202 212 struct getset_keycode_data *d = data; 203 213 204 - d->error = input_set_keycode(handle->dev, d->scancode, d->keycode); 214 + d->error = input_set_keycode(handle->dev, &d->ke); 205 215 206 216 return d->error == 0; /* stop as soon as we successfully set one */ 207 217 } 208 218 209 219 int setkeycode(unsigned int scancode, unsigned int keycode) 210 220 { 211 - struct getset_keycode_data d = { scancode, keycode, -ENODEV }; 221 + struct getset_keycode_data d = { 222 + .ke = { 223 + .flags = 0, 224 + .len = sizeof(scancode), 225 + .keycode = keycode, 226 + }, 227 + .error = -ENODEV, 228 + }; 229 + 230 + memcpy(d.ke.scancode, &scancode, sizeof(scancode)); 212 231 213 232 input_handler_for_each_handle(&kbd_handler, &d, setkeycode_helper); 214 233
+12 -3
drivers/char/sysrq.c
··· 566 566 static bool sysrq_down; 567 567 static int sysrq_alt_use; 568 568 static int sysrq_alt; 569 + static DEFINE_SPINLOCK(sysrq_event_lock); 569 570 570 571 static bool sysrq_filter(struct input_handle *handle, unsigned int type, 571 572 unsigned int code, int value) 572 573 { 574 + bool suppress; 575 + 576 + /* We are called with interrupts disabled, just take the lock */ 577 + spin_lock(&sysrq_event_lock); 578 + 573 579 if (type != EV_KEY) 574 580 goto out; 575 581 ··· 607 601 } 608 602 609 603 out: 610 - return sysrq_down; 604 + suppress = sysrq_down; 605 + spin_unlock(&sysrq_event_lock); 606 + 607 + return suppress; 611 608 } 612 609 613 610 static int sysrq_connect(struct input_handler *handler, ··· 661 652 } 662 653 663 654 /* 664 - * We are matching on KEY_LEFTALT insteard of KEY_SYSRQ because not all 665 - * keyboards have SysRq ikey predefined and so user may add it to keymap 655 + * We are matching on KEY_LEFTALT instead of KEY_SYSRQ because not all 656 + * keyboards have SysRq key predefined and so user may add it to keymap 666 657 * later, but we expect all such keyboards to have left alt. 667 658 */ 668 659 static const struct input_device_id sysrq_ids[] = {
+5
drivers/hid/hid-core.c
··· 1766 1766 hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST) 1767 1767 return true; 1768 1768 break; 1769 + case USB_VENDOR_ID_HANWANG: 1770 + if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST && 1771 + hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST) 1772 + return true; 1773 + break; 1769 1774 } 1770 1775 1771 1776 if (hdev->type == HID_TYPE_USBMOUSE &&
+4
drivers/hid/hid-ids.h
··· 291 291 #define USB_DEVICE_ID_GYRATION_REMOTE_2 0x0003 292 292 #define USB_DEVICE_ID_GYRATION_REMOTE_3 0x0008 293 293 294 + #define USB_VENDOR_ID_HANWANG 0x0b57 295 + #define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000 296 + #define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff 297 + 294 298 #define USB_VENDOR_ID_HAPP 0x078b 295 299 #define USB_DEVICE_ID_UGCI_DRIVING 0x0010 296 300 #define USB_DEVICE_ID_UGCI_FLYING 0x0020
+76 -34
drivers/hid/hid-input.c
··· 68 68 #define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \ 69 69 &max, EV_KEY, (c)) 70 70 71 - static inline int match_scancode(unsigned int code, unsigned int scancode) 71 + static bool match_scancode(struct hid_usage *usage, 72 + unsigned int cur_idx, unsigned int scancode) 72 73 { 73 - if (scancode == 0) 74 - return 1; 75 - 76 - return (code & (HID_USAGE_PAGE | HID_USAGE)) == scancode; 74 + return (usage->hid & (HID_USAGE_PAGE | HID_USAGE)) == scancode; 77 75 } 78 76 79 - static inline int match_keycode(unsigned int code, unsigned int keycode) 77 + static bool match_keycode(struct hid_usage *usage, 78 + unsigned int cur_idx, unsigned int keycode) 80 79 { 81 - if (keycode == 0) 82 - return 1; 83 - 84 - return code == keycode; 80 + /* 81 + * We should exclude unmapped usages when doing lookup by keycode. 82 + */ 83 + return (usage->type == EV_KEY && usage->code == keycode); 85 84 } 85 + 86 + static bool match_index(struct hid_usage *usage, 87 + unsigned int cur_idx, unsigned int idx) 88 + { 89 + return cur_idx == idx; 90 + } 91 + 92 + typedef bool (*hid_usage_cmp_t)(struct hid_usage *usage, 93 + unsigned int cur_idx, unsigned int val); 86 94 87 95 static struct hid_usage *hidinput_find_key(struct hid_device *hid, 88 - unsigned int scancode, 89 - unsigned int keycode) 96 + hid_usage_cmp_t match, 97 + unsigned int value, 98 + unsigned int *usage_idx) 90 99 { 91 - int i, j, k; 100 + unsigned int i, j, k, cur_idx = 0; 92 101 struct hid_report *report; 93 102 struct hid_usage *usage; 94 103 95 104 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { 96 105 list_for_each_entry(report, &hid->report_enum[k].report_list, list) { 97 106 for (i = 0; i < report->maxfield; i++) { 98 - for ( j = 0; j < report->field[i]->maxusage; j++) { 107 + for (j = 0; j < report->field[i]->maxusage; j++) { 99 108 usage = report->field[i]->usage + j; 100 - if (usage->type == EV_KEY && 101 - match_scancode(usage->hid, scancode) && 102 - match_keycode(usage->code, keycode)) 103 - return usage; 109 + if (usage->type == EV_KEY || usage->type == 0) { 110 + if (match(usage, cur_idx, value)) { 111 + if (usage_idx) 112 + *usage_idx = cur_idx; 113 + return usage; 114 + } 115 + cur_idx++; 116 + } 104 117 } 105 118 } 106 119 } ··· 121 108 return NULL; 122 109 } 123 110 111 + static struct hid_usage *hidinput_locate_usage(struct hid_device *hid, 112 + const struct input_keymap_entry *ke, 113 + unsigned int *index) 114 + { 115 + struct hid_usage *usage; 116 + unsigned int scancode; 117 + 118 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) 119 + usage = hidinput_find_key(hid, match_index, ke->index, index); 120 + else if (input_scancode_to_scalar(ke, &scancode) == 0) 121 + usage = hidinput_find_key(hid, match_scancode, scancode, index); 122 + else 123 + usage = NULL; 124 + 125 + return usage; 126 + } 127 + 124 128 static int hidinput_getkeycode(struct input_dev *dev, 125 - unsigned int scancode, unsigned int *keycode) 129 + struct input_keymap_entry *ke) 126 130 { 127 131 struct hid_device *hid = input_get_drvdata(dev); 128 132 struct hid_usage *usage; 133 + unsigned int scancode, index; 129 134 130 - usage = hidinput_find_key(hid, scancode, 0); 135 + usage = hidinput_locate_usage(hid, ke, &index); 131 136 if (usage) { 132 - *keycode = usage->code; 137 + ke->keycode = usage->type == EV_KEY ? 138 + usage->code : KEY_RESERVED; 139 + ke->index = index; 140 + scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE); 141 + ke->len = sizeof(scancode); 142 + memcpy(ke->scancode, &scancode, sizeof(scancode)); 133 143 return 0; 134 144 } 145 + 135 146 return -EINVAL; 136 147 } 137 148 138 149 static int hidinput_setkeycode(struct input_dev *dev, 139 - unsigned int scancode, unsigned int keycode) 150 + const struct input_keymap_entry *ke, 151 + unsigned int *old_keycode) 140 152 { 141 153 struct hid_device *hid = input_get_drvdata(dev); 142 154 struct hid_usage *usage; 143 - int old_keycode; 144 155 145 - usage = hidinput_find_key(hid, scancode, 0); 156 + usage = hidinput_locate_usage(hid, ke, NULL); 146 157 if (usage) { 147 - old_keycode = usage->code; 148 - usage->code = keycode; 158 + *old_keycode = usage->type == EV_KEY ? 159 + usage->code : KEY_RESERVED; 160 + usage->code = ke->keycode; 149 161 150 - clear_bit(old_keycode, dev->keybit); 162 + clear_bit(*old_keycode, dev->keybit); 151 163 set_bit(usage->code, dev->keybit); 152 - dbg_hid(KERN_DEBUG "Assigned keycode %d to HID usage code %x\n", keycode, scancode); 153 - /* Set the keybit for the old keycode if the old keycode is used 154 - * by another key */ 155 - if (hidinput_find_key (hid, 0, old_keycode)) 156 - set_bit(old_keycode, dev->keybit); 164 + dbg_hid(KERN_DEBUG "Assigned keycode %d to HID usage code %x\n", 165 + usage->code, usage->hid); 166 + 167 + /* 168 + * Set the keybit for the old keycode if the old keycode is used 169 + * by another key 170 + */ 171 + if (hidinput_find_key(hid, match_keycode, *old_keycode, NULL)) 172 + set_bit(*old_keycode, dev->keybit); 157 173 158 174 return 0; 159 175 } ··· 790 748 hid->ll_driver->hidinput_input_event; 791 749 input_dev->open = hidinput_open; 792 750 input_dev->close = hidinput_close; 793 - input_dev->setkeycode = hidinput_setkeycode; 794 - input_dev->getkeycode = hidinput_getkeycode; 751 + input_dev->setkeycode_new = hidinput_setkeycode; 752 + input_dev->getkeycode_new = hidinput_getkeycode; 795 753 796 754 input_dev->name = hid->name; 797 755 input_dev->phys = hid->phys;
+80 -20
drivers/input/evdev.c
··· 534 534 } 535 535 #undef OLD_KEY_MAX 536 536 537 + static int evdev_handle_get_keycode(struct input_dev *dev, 538 + void __user *p, size_t size) 539 + { 540 + struct input_keymap_entry ke; 541 + int error; 542 + 543 + memset(&ke, 0, sizeof(ke)); 544 + 545 + if (size == sizeof(unsigned int[2])) { 546 + /* legacy case */ 547 + int __user *ip = (int __user *)p; 548 + 549 + if (copy_from_user(ke.scancode, p, sizeof(unsigned int))) 550 + return -EFAULT; 551 + 552 + ke.len = sizeof(unsigned int); 553 + ke.flags = 0; 554 + 555 + error = input_get_keycode(dev, &ke); 556 + if (error) 557 + return error; 558 + 559 + if (put_user(ke.keycode, ip + 1)) 560 + return -EFAULT; 561 + 562 + } else { 563 + size = min(size, sizeof(ke)); 564 + 565 + if (copy_from_user(&ke, p, size)) 566 + return -EFAULT; 567 + 568 + error = input_get_keycode(dev, &ke); 569 + if (error) 570 + return error; 571 + 572 + if (copy_to_user(p, &ke, size)) 573 + return -EFAULT; 574 + } 575 + return 0; 576 + } 577 + 578 + static int evdev_handle_set_keycode(struct input_dev *dev, 579 + void __user *p, size_t size) 580 + { 581 + struct input_keymap_entry ke; 582 + 583 + memset(&ke, 0, sizeof(ke)); 584 + 585 + if (size == sizeof(unsigned int[2])) { 586 + /* legacy case */ 587 + int __user *ip = (int __user *)p; 588 + 589 + if (copy_from_user(ke.scancode, p, sizeof(unsigned int))) 590 + return -EFAULT; 591 + 592 + if (get_user(ke.keycode, ip + 1)) 593 + return -EFAULT; 594 + 595 + ke.len = sizeof(unsigned int); 596 + ke.flags = 0; 597 + 598 + } else { 599 + size = min(size, sizeof(ke)); 600 + 601 + if (copy_from_user(&ke, p, size)) 602 + return -EFAULT; 603 + 604 + if (ke.len > sizeof(ke.scancode)) 605 + return -EINVAL; 606 + } 607 + 608 + return input_set_keycode(dev, &ke); 609 + } 610 + 537 611 static long evdev_do_ioctl(struct file *file, unsigned int cmd, 538 612 void __user *p, int compat_mode) 539 613 { ··· 654 580 655 581 return 0; 656 582 657 - case EVIOCGKEYCODE: 658 - if (get_user(t, ip)) 659 - return -EFAULT; 660 - 661 - error = input_get_keycode(dev, t, &v); 662 - if (error) 663 - return error; 664 - 665 - if (put_user(v, ip + 1)) 666 - return -EFAULT; 667 - 668 - return 0; 669 - 670 - case EVIOCSKEYCODE: 671 - if (get_user(t, ip) || get_user(v, ip + 1)) 672 - return -EFAULT; 673 - 674 - return input_set_keycode(dev, t, v); 675 - 676 583 case EVIOCRMFF: 677 584 return input_ff_erase(dev, (int)(unsigned long) p, file); 678 585 ··· 675 620 676 621 /* Now check variable-length commands */ 677 622 #define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT)) 678 - 679 623 switch (EVIOC_MASK_SIZE(cmd)) { 680 624 681 625 case EVIOCGKEY(0): ··· 708 654 return -EFAULT; 709 655 710 656 return error; 657 + 658 + case EVIOC_MASK_SIZE(EVIOCGKEYCODE): 659 + return evdev_handle_get_keycode(dev, p, size); 660 + 661 + case EVIOC_MASK_SIZE(EVIOCSKEYCODE): 662 + return evdev_handle_set_keycode(dev, p, size); 711 663 } 712 664 713 665 /* Multi-number variable-length handlers */
+27 -17
drivers/input/gameport/emu10k1-gp.c
··· 59 59 60 60 static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 61 61 { 62 - int ioport, iolen; 63 62 struct emu *emu; 64 63 struct gameport *port; 65 - 66 - if (pci_enable_device(pdev)) 67 - return -EBUSY; 68 - 69 - ioport = pci_resource_start(pdev, 0); 70 - iolen = pci_resource_len(pdev, 0); 71 - 72 - if (!request_region(ioport, iolen, "emu10k1-gp")) 73 - return -EBUSY; 64 + int error; 74 65 75 66 emu = kzalloc(sizeof(struct emu), GFP_KERNEL); 76 67 port = gameport_allocate_port(); 77 68 if (!emu || !port) { 78 69 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n"); 79 - release_region(ioport, iolen); 80 - kfree(emu); 81 - gameport_free_port(port); 82 - return -ENOMEM; 70 + error = -ENOMEM; 71 + goto err_out_free; 83 72 } 84 73 85 - emu->io = ioport; 86 - emu->size = iolen; 74 + error = pci_enable_device(pdev); 75 + if (error) 76 + goto err_out_free; 77 + 78 + emu->io = pci_resource_start(pdev, 0); 79 + emu->size = pci_resource_len(pdev, 0); 80 + 87 81 emu->dev = pdev; 88 82 emu->gameport = port; 89 83 90 84 gameport_set_name(port, "EMU10K1"); 91 85 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev)); 92 86 port->dev.parent = &pdev->dev; 93 - port->io = ioport; 87 + port->io = emu->io; 88 + 89 + if (!request_region(emu->io, emu->size, "emu10k1-gp")) { 90 + printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n", 91 + emu->io, emu->io + emu->size - 1); 92 + error = -EBUSY; 93 + goto err_out_disable_dev; 94 + } 94 95 95 96 pci_set_drvdata(pdev, emu); 96 97 97 98 gameport_register_port(port); 98 99 99 100 return 0; 101 + 102 + err_out_disable_dev: 103 + pci_disable_device(pdev); 104 + err_out_free: 105 + gameport_free_port(port); 106 + kfree(emu); 107 + return error; 100 108 } 101 109 102 110 static void __devexit emu_remove(struct pci_dev *pdev) ··· 114 106 gameport_unregister_port(emu->gameport); 115 107 release_region(emu->io, emu->size); 116 108 kfree(emu); 109 + 110 + pci_disable_device(pdev); 117 111 } 118 112 119 113 static struct pci_driver emu_driver = {
+5 -5
drivers/input/gameport/fm801-gp.c
··· 133 133 { 134 134 struct fm801_gp *gp = pci_get_drvdata(pci); 135 135 136 - if (gp) { 137 - gameport_unregister_port(gp->gameport); 138 - release_resource(gp->res_port); 139 - kfree(gp); 140 - } 136 + gameport_unregister_port(gp->gameport); 137 + release_resource(gp->res_port); 138 + kfree(gp); 139 + 140 + pci_disable_device(pci); 141 141 } 142 142 143 143 static const struct pci_device_id fm801_gp_id_table[] = {
+148 -52
drivers/input/input.c
··· 171 171 if (code == ABS_MT_SLOT) { 172 172 /* 173 173 * "Stage" the event; we'll flush it later, when we 174 - * get actiual touch data. 174 + * get actual touch data. 175 175 */ 176 176 if (*pval >= 0 && *pval < dev->mtsize) 177 177 dev->slot = *pval; ··· 188 188 pold = &mtslot->abs[code - ABS_MT_FIRST]; 189 189 } else { 190 190 /* 191 - * Bypass filtering for multitouch events when 191 + * Bypass filtering for multi-touch events when 192 192 * not employing slots. 193 193 */ 194 194 pold = NULL; ··· 634 634 spin_unlock_irq(&dev->event_lock); 635 635 } 636 636 637 - static int input_fetch_keycode(struct input_dev *dev, int scancode) 637 + /** 638 + * input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry 639 + * @ke: keymap entry containing scancode to be converted. 640 + * @scancode: pointer to the location where converted scancode should 641 + * be stored. 642 + * 643 + * This function is used to convert scancode stored in &struct keymap_entry 644 + * into scalar form understood by legacy keymap handling methods. These 645 + * methods expect scancodes to be represented as 'unsigned int'. 646 + */ 647 + int input_scancode_to_scalar(const struct input_keymap_entry *ke, 648 + unsigned int *scancode) 649 + { 650 + switch (ke->len) { 651 + case 1: 652 + *scancode = *((u8 *)ke->scancode); 653 + break; 654 + 655 + case 2: 656 + *scancode = *((u16 *)ke->scancode); 657 + break; 658 + 659 + case 4: 660 + *scancode = *((u32 *)ke->scancode); 661 + break; 662 + 663 + default: 664 + return -EINVAL; 665 + } 666 + 667 + return 0; 668 + } 669 + EXPORT_SYMBOL(input_scancode_to_scalar); 670 + 671 + /* 672 + * Those routines handle the default case where no [gs]etkeycode() is 673 + * defined. In this case, an array indexed by the scancode is used. 674 + */ 675 + 676 + static unsigned int input_fetch_keycode(struct input_dev *dev, 677 + unsigned int index) 638 678 { 639 679 switch (dev->keycodesize) { 640 - case 1: 641 - return ((u8 *)dev->keycode)[scancode]; 680 + case 1: 681 + return ((u8 *)dev->keycode)[index]; 642 682 643 - case 2: 644 - return ((u16 *)dev->keycode)[scancode]; 683 + case 2: 684 + return ((u16 *)dev->keycode)[index]; 645 685 646 - default: 647 - return ((u32 *)dev->keycode)[scancode]; 686 + default: 687 + return ((u32 *)dev->keycode)[index]; 648 688 } 649 689 } 650 690 651 691 static int input_default_getkeycode(struct input_dev *dev, 652 - unsigned int scancode, 653 - unsigned int *keycode) 692 + struct input_keymap_entry *ke) 654 693 { 694 + unsigned int index; 695 + int error; 696 + 655 697 if (!dev->keycodesize) 656 698 return -EINVAL; 657 699 658 - if (scancode >= dev->keycodemax) 700 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) 701 + index = ke->index; 702 + else { 703 + error = input_scancode_to_scalar(ke, &index); 704 + if (error) 705 + return error; 706 + } 707 + 708 + if (index >= dev->keycodemax) 659 709 return -EINVAL; 660 710 661 - *keycode = input_fetch_keycode(dev, scancode); 711 + ke->keycode = input_fetch_keycode(dev, index); 712 + ke->index = index; 713 + ke->len = sizeof(index); 714 + memcpy(ke->scancode, &index, sizeof(index)); 662 715 663 716 return 0; 664 717 } 665 718 666 719 static int input_default_setkeycode(struct input_dev *dev, 667 - unsigned int scancode, 668 - unsigned int keycode) 720 + const struct input_keymap_entry *ke, 721 + unsigned int *old_keycode) 669 722 { 670 - int old_keycode; 723 + unsigned int index; 724 + int error; 671 725 int i; 672 - 673 - if (scancode >= dev->keycodemax) 674 - return -EINVAL; 675 726 676 727 if (!dev->keycodesize) 677 728 return -EINVAL; 678 729 679 - if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8))) 730 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) { 731 + index = ke->index; 732 + } else { 733 + error = input_scancode_to_scalar(ke, &index); 734 + if (error) 735 + return error; 736 + } 737 + 738 + if (index >= dev->keycodemax) 739 + return -EINVAL; 740 + 741 + if (dev->keycodesize < sizeof(dev->keycode) && 742 + (ke->keycode >> (dev->keycodesize * 8))) 680 743 return -EINVAL; 681 744 682 745 switch (dev->keycodesize) { 683 746 case 1: { 684 747 u8 *k = (u8 *)dev->keycode; 685 - old_keycode = k[scancode]; 686 - k[scancode] = keycode; 748 + *old_keycode = k[index]; 749 + k[index] = ke->keycode; 687 750 break; 688 751 } 689 752 case 2: { 690 753 u16 *k = (u16 *)dev->keycode; 691 - old_keycode = k[scancode]; 692 - k[scancode] = keycode; 754 + *old_keycode = k[index]; 755 + k[index] = ke->keycode; 693 756 break; 694 757 } 695 758 default: { 696 759 u32 *k = (u32 *)dev->keycode; 697 - old_keycode = k[scancode]; 698 - k[scancode] = keycode; 760 + *old_keycode = k[index]; 761 + k[index] = ke->keycode; 699 762 break; 700 763 } 701 764 } 702 765 703 - __clear_bit(old_keycode, dev->keybit); 704 - __set_bit(keycode, dev->keybit); 766 + __clear_bit(*old_keycode, dev->keybit); 767 + __set_bit(ke->keycode, dev->keybit); 705 768 706 769 for (i = 0; i < dev->keycodemax; i++) { 707 - if (input_fetch_keycode(dev, i) == old_keycode) { 708 - __set_bit(old_keycode, dev->keybit); 770 + if (input_fetch_keycode(dev, i) == *old_keycode) { 771 + __set_bit(*old_keycode, dev->keybit); 709 772 break; /* Setting the bit twice is useless, so break */ 710 773 } 711 774 } ··· 779 716 /** 780 717 * input_get_keycode - retrieve keycode currently mapped to a given scancode 781 718 * @dev: input device which keymap is being queried 782 - * @scancode: scancode (or its equivalent for device in question) for which 783 - * keycode is needed 784 - * @keycode: result 719 + * @ke: keymap entry 785 720 * 786 721 * This function should be called by anyone interested in retrieving current 787 - * keymap. Presently keyboard and evdev handlers use it. 722 + * keymap. Presently evdev handlers use it. 788 723 */ 789 - int input_get_keycode(struct input_dev *dev, 790 - unsigned int scancode, unsigned int *keycode) 724 + int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke) 791 725 { 792 726 unsigned long flags; 793 727 int retval; 794 728 795 729 spin_lock_irqsave(&dev->event_lock, flags); 796 - retval = dev->getkeycode(dev, scancode, keycode); 797 - spin_unlock_irqrestore(&dev->event_lock, flags); 798 730 731 + if (dev->getkeycode) { 732 + /* 733 + * Support for legacy drivers, that don't implement the new 734 + * ioctls 735 + */ 736 + u32 scancode = ke->index; 737 + 738 + memcpy(ke->scancode, &scancode, sizeof(scancode)); 739 + ke->len = sizeof(scancode); 740 + retval = dev->getkeycode(dev, scancode, &ke->keycode); 741 + } else { 742 + retval = dev->getkeycode_new(dev, ke); 743 + } 744 + 745 + spin_unlock_irqrestore(&dev->event_lock, flags); 799 746 return retval; 800 747 } 801 748 EXPORT_SYMBOL(input_get_keycode); 802 749 803 750 /** 804 - * input_get_keycode - assign new keycode to a given scancode 751 + * input_set_keycode - attribute a keycode to a given scancode 805 752 * @dev: input device which keymap is being updated 806 - * @scancode: scancode (or its equivalent for device in question) 807 - * @keycode: new keycode to be assigned to the scancode 753 + * @ke: new keymap entry 808 754 * 809 755 * This function should be called by anyone needing to update current 810 756 * keymap. Presently keyboard and evdev handlers use it. 811 757 */ 812 758 int input_set_keycode(struct input_dev *dev, 813 - unsigned int scancode, unsigned int keycode) 759 + const struct input_keymap_entry *ke) 814 760 { 815 761 unsigned long flags; 816 762 unsigned int old_keycode; 817 763 int retval; 818 764 819 - if (keycode > KEY_MAX) 765 + if (ke->keycode > KEY_MAX) 820 766 return -EINVAL; 821 767 822 768 spin_lock_irqsave(&dev->event_lock, flags); 823 769 824 - retval = dev->getkeycode(dev, scancode, &old_keycode); 825 - if (retval) 826 - goto out; 770 + if (dev->setkeycode) { 771 + /* 772 + * Support for legacy drivers, that don't implement the new 773 + * ioctls 774 + */ 775 + unsigned int scancode; 827 776 828 - retval = dev->setkeycode(dev, scancode, keycode); 777 + retval = input_scancode_to_scalar(ke, &scancode); 778 + if (retval) 779 + goto out; 780 + 781 + /* 782 + * We need to know the old scancode, in order to generate a 783 + * keyup effect, if the set operation happens successfully 784 + */ 785 + if (!dev->getkeycode) { 786 + retval = -EINVAL; 787 + goto out; 788 + } 789 + 790 + retval = dev->getkeycode(dev, scancode, &old_keycode); 791 + if (retval) 792 + goto out; 793 + 794 + retval = dev->setkeycode(dev, scancode, ke->keycode); 795 + } else { 796 + retval = dev->setkeycode_new(dev, ke, &old_keycode); 797 + } 798 + 829 799 if (retval) 830 800 goto out; 831 801 ··· 1697 1601 * 1698 1602 * This function allocates all necessary memory for MT slot handling in the 1699 1603 * input device, and adds ABS_MT_SLOT to the device capabilities. All slots 1700 - * are initially marked as unused iby setting ABS_MT_TRACKING_ID to -1. 1604 + * are initially marked as unused by setting ABS_MT_TRACKING_ID to -1. 1701 1605 */ 1702 1606 int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots) 1703 1607 { ··· 1855 1759 dev->rep[REP_PERIOD] = 33; 1856 1760 } 1857 1761 1858 - if (!dev->getkeycode) 1859 - dev->getkeycode = input_default_getkeycode; 1762 + if (!dev->getkeycode && !dev->getkeycode_new) 1763 + dev->getkeycode_new = input_default_getkeycode; 1860 1764 1861 - if (!dev->setkeycode) 1862 - dev->setkeycode = input_default_setkeycode; 1765 + if (!dev->setkeycode && !dev->setkeycode_new) 1766 + dev->setkeycode_new = input_default_setkeycode; 1863 1767 1864 1768 dev_set_name(&dev->dev, "input%ld", 1865 1769 (unsigned long) atomic_inc_return(&input_no) - 1);
+19
drivers/input/keyboard/Kconfig
··· 327 327 To compile this driver as a module, choose M here: the 328 328 module will be called newtonkbd. 329 329 330 + config KEYBOARD_NOMADIK 331 + tristate "ST-Ericsson Nomadik SKE keyboard" 332 + depends on PLAT_NOMADIK 333 + help 334 + Say Y here if you want to use a keypad provided on the SKE controller 335 + used on the Ux500 and Nomadik platforms 336 + 337 + To compile this driver as a module, choose M here: the 338 + module will be called nmk-ske-keypad. 339 + 330 340 config KEYBOARD_OPENCORES 331 341 tristate "OpenCores Keyboard Controller" 332 342 help ··· 433 423 434 424 To compile this driver as a module, choose M here: the 435 425 module will be called omap-keypad. 426 + 427 + config KEYBOARD_OMAP4 428 + tristate "TI OMAP4 keypad support" 429 + depends on ARCH_OMAP4 430 + help 431 + Say Y here if you want to use the OMAP4 keypad. 432 + 433 + To compile this driver as a module, choose M here: the 434 + module will be called omap4-keypad. 436 435 437 436 config KEYBOARD_TWL4030 438 437 tristate "TI TWL4030/TWL5030/TPS659x0 keypad support"
+2
drivers/input/keyboard/Makefile
··· 28 28 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 29 29 obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o 30 30 obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 31 + obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o 31 32 obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 33 + obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o 32 34 obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o 33 35 obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o 34 36 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
+1 -1
drivers/input/keyboard/adp5588-keys.c
··· 660 660 #endif 661 661 662 662 static const struct i2c_device_id adp5588_id[] = { 663 - { KBUILD_MODNAME, 0 }, 663 + { "adp5588-keys", 0 }, 664 664 { "adp5587-keys", 0 }, 665 665 { } 666 666 };
+2
drivers/input/keyboard/hil_kbd.c
··· 570 570 { 0 } 571 571 }; 572 572 573 + MODULE_DEVICE_TABLE(serio, hil_dev_ids); 574 + 573 575 static struct serio_driver hil_serio_drv = { 574 576 .driver = { 575 577 .name = "hil_dev",
+408
drivers/input/keyboard/nomadik-ske-keypad.c
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * 4 + * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson 5 + * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 6 + * 7 + * License terms:GNU General Public License (GPL) version 2 8 + * 9 + * Keypad controller driver for the SKE (Scroll Key Encoder) module used in 10 + * the Nomadik 8815 and Ux500 platforms. 11 + */ 12 + 13 + #include <linux/platform_device.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/spinlock.h> 16 + #include <linux/io.h> 17 + #include <linux/delay.h> 18 + #include <linux/input.h> 19 + #include <linux/slab.h> 20 + #include <linux/clk.h> 21 + 22 + #include <plat/ske.h> 23 + 24 + /* SKE_CR bits */ 25 + #define SKE_KPMLT (0x1 << 6) 26 + #define SKE_KPCN (0x7 << 3) 27 + #define SKE_KPASEN (0x1 << 2) 28 + #define SKE_KPASON (0x1 << 7) 29 + 30 + /* SKE_IMSC bits */ 31 + #define SKE_KPIMA (0x1 << 2) 32 + 33 + /* SKE_ICR bits */ 34 + #define SKE_KPICS (0x1 << 3) 35 + #define SKE_KPICA (0x1 << 2) 36 + 37 + /* SKE_RIS bits */ 38 + #define SKE_KPRISA (0x1 << 2) 39 + 40 + #define SKE_KEYPAD_ROW_SHIFT 3 41 + #define SKE_KPD_KEYMAP_SIZE (8 * 8) 42 + 43 + /* keypad auto scan registers */ 44 + #define SKE_ASR0 0x20 45 + #define SKE_ASR1 0x24 46 + #define SKE_ASR2 0x28 47 + #define SKE_ASR3 0x2C 48 + 49 + #define SKE_NUM_ASRX_REGISTERS (4) 50 + 51 + /** 52 + * struct ske_keypad - data structure used by keypad driver 53 + * @irq: irq no 54 + * @reg_base: ske regsiters base address 55 + * @input: pointer to input device object 56 + * @board: keypad platform device 57 + * @keymap: matrix scan code table for keycodes 58 + * @clk: clock structure pointer 59 + */ 60 + struct ske_keypad { 61 + int irq; 62 + void __iomem *reg_base; 63 + struct input_dev *input; 64 + const struct ske_keypad_platform_data *board; 65 + unsigned short keymap[SKE_KPD_KEYMAP_SIZE]; 66 + struct clk *clk; 67 + spinlock_t ske_keypad_lock; 68 + }; 69 + 70 + static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr, 71 + u8 mask, u8 data) 72 + { 73 + u32 ret; 74 + 75 + spin_lock(&keypad->ske_keypad_lock); 76 + 77 + ret = readl(keypad->reg_base + addr); 78 + ret &= ~mask; 79 + ret |= data; 80 + writel(ret, keypad->reg_base + addr); 81 + 82 + spin_unlock(&keypad->ske_keypad_lock); 83 + } 84 + 85 + /* 86 + * ske_keypad_chip_init: init keypad controller configuration 87 + * 88 + * Enable Multi key press detection, auto scan mode 89 + */ 90 + static int __devinit ske_keypad_chip_init(struct ske_keypad *keypad) 91 + { 92 + u32 value; 93 + int timeout = 50; 94 + 95 + /* check SKE_RIS to be 0 */ 96 + while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--) 97 + cpu_relax(); 98 + 99 + if (!timeout) 100 + return -EINVAL; 101 + 102 + /* 103 + * set debounce value 104 + * keypad dbounce is configured in DBCR[15:8] 105 + * dbounce value in steps of 32/32.768 ms 106 + */ 107 + spin_lock(&keypad->ske_keypad_lock); 108 + value = readl(keypad->reg_base + SKE_DBCR); 109 + value = value & 0xff; 110 + value |= ((keypad->board->debounce_ms * 32000)/32768) << 8; 111 + writel(value, keypad->reg_base + SKE_DBCR); 112 + spin_unlock(&keypad->ske_keypad_lock); 113 + 114 + /* enable multi key detection */ 115 + ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPMLT); 116 + 117 + /* 118 + * set up the number of columns 119 + * KPCN[5:3] defines no. of keypad columns to be auto scanned 120 + */ 121 + value = (keypad->board->kcol - 1) << 3; 122 + ske_keypad_set_bits(keypad, SKE_CR, SKE_KPCN, value); 123 + 124 + /* clear keypad interrupt for auto(and pending SW) scans */ 125 + ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA | SKE_KPICS); 126 + 127 + /* un-mask keypad interrupts */ 128 + ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 129 + 130 + /* enable automatic scan */ 131 + ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPASEN); 132 + 133 + return 0; 134 + } 135 + 136 + static void ske_keypad_read_data(struct ske_keypad *keypad) 137 + { 138 + struct input_dev *input = keypad->input; 139 + u16 status; 140 + int col = 0, row = 0, code; 141 + int ske_asr, ske_ris, key_pressed, i; 142 + 143 + /* 144 + * Read the auto scan registers 145 + * 146 + * Each SKE_ASRx (x=0 to x=3) contains two row values. 147 + * lower byte contains row value for column 2*x, 148 + * upper byte contains row value for column 2*x + 1 149 + */ 150 + for (i = 0; i < SKE_NUM_ASRX_REGISTERS; i++) { 151 + ske_asr = readl(keypad->reg_base + SKE_ASR0 + (4 * i)); 152 + if (!ske_asr) 153 + continue; 154 + 155 + /* now that ASRx is zero, find out the column x and row y*/ 156 + if (ske_asr & 0xff) { 157 + col = i * 2; 158 + status = ske_asr & 0xff; 159 + } else { 160 + col = (i * 2) + 1; 161 + status = (ske_asr & 0xff00) >> 8; 162 + } 163 + 164 + /* find out the row */ 165 + row = __ffs(status); 166 + 167 + code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT); 168 + ske_ris = readl(keypad->reg_base + SKE_RIS); 169 + key_pressed = ske_ris & SKE_KPRISA; 170 + 171 + input_event(input, EV_MSC, MSC_SCAN, code); 172 + input_report_key(input, keypad->keymap[code], key_pressed); 173 + input_sync(input); 174 + } 175 + } 176 + 177 + static irqreturn_t ske_keypad_irq(int irq, void *dev_id) 178 + { 179 + struct ske_keypad *keypad = dev_id; 180 + int retries = 20; 181 + 182 + /* disable auto scan interrupt; mask the interrupt generated */ 183 + ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); 184 + ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA); 185 + 186 + while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --retries) 187 + msleep(5); 188 + 189 + if (retries) { 190 + /* SKEx registers are stable and can be read */ 191 + ske_keypad_read_data(keypad); 192 + } 193 + 194 + /* enable auto scan interrupts */ 195 + ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 196 + 197 + return IRQ_HANDLED; 198 + } 199 + 200 + static int __devinit ske_keypad_probe(struct platform_device *pdev) 201 + { 202 + const struct ske_keypad_platform_data *plat = pdev->dev.platform_data; 203 + struct ske_keypad *keypad; 204 + struct input_dev *input; 205 + struct resource *res; 206 + int irq; 207 + int error; 208 + 209 + if (!plat) { 210 + dev_err(&pdev->dev, "invalid keypad platform data\n"); 211 + return -EINVAL; 212 + } 213 + 214 + irq = platform_get_irq(pdev, 0); 215 + if (irq < 0) { 216 + dev_err(&pdev->dev, "failed to get keypad irq\n"); 217 + return -EINVAL; 218 + } 219 + 220 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 221 + if (!res) { 222 + dev_err(&pdev->dev, "missing platform resources\n"); 223 + return -EINVAL; 224 + } 225 + 226 + keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL); 227 + input = input_allocate_device(); 228 + if (!keypad || !input) { 229 + dev_err(&pdev->dev, "failed to allocate keypad memory\n"); 230 + error = -ENOMEM; 231 + goto err_free_mem; 232 + } 233 + 234 + keypad->irq = irq; 235 + keypad->board = plat; 236 + keypad->input = input; 237 + spin_lock_init(&keypad->ske_keypad_lock); 238 + 239 + if (!request_mem_region(res->start, resource_size(res), pdev->name)) { 240 + dev_err(&pdev->dev, "failed to request I/O memory\n"); 241 + error = -EBUSY; 242 + goto err_free_mem; 243 + } 244 + 245 + keypad->reg_base = ioremap(res->start, resource_size(res)); 246 + if (!keypad->reg_base) { 247 + dev_err(&pdev->dev, "failed to remap I/O memory\n"); 248 + error = -ENXIO; 249 + goto err_free_mem_region; 250 + } 251 + 252 + keypad->clk = clk_get(&pdev->dev, NULL); 253 + if (IS_ERR(keypad->clk)) { 254 + dev_err(&pdev->dev, "failed to get clk\n"); 255 + error = PTR_ERR(keypad->clk); 256 + goto err_iounmap; 257 + } 258 + 259 + input->id.bustype = BUS_HOST; 260 + input->name = "ux500-ske-keypad"; 261 + input->dev.parent = &pdev->dev; 262 + 263 + input->keycode = keypad->keymap; 264 + input->keycodesize = sizeof(keypad->keymap[0]); 265 + input->keycodemax = ARRAY_SIZE(keypad->keymap); 266 + 267 + input_set_capability(input, EV_MSC, MSC_SCAN); 268 + 269 + __set_bit(EV_KEY, input->evbit); 270 + if (!plat->no_autorepeat) 271 + __set_bit(EV_REP, input->evbit); 272 + 273 + matrix_keypad_build_keymap(plat->keymap_data, SKE_KEYPAD_ROW_SHIFT, 274 + input->keycode, input->keybit); 275 + 276 + clk_enable(keypad->clk); 277 + 278 + /* go through board initialization helpers */ 279 + if (keypad->board->init) 280 + keypad->board->init(); 281 + 282 + error = ske_keypad_chip_init(keypad); 283 + if (error) { 284 + dev_err(&pdev->dev, "unable to init keypad hardware\n"); 285 + goto err_clk_disable; 286 + } 287 + 288 + error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq, 289 + IRQF_ONESHOT, "ske-keypad", keypad); 290 + if (error) { 291 + dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq); 292 + goto err_clk_disable; 293 + } 294 + 295 + error = input_register_device(input); 296 + if (error) { 297 + dev_err(&pdev->dev, 298 + "unable to register input device: %d\n", error); 299 + goto err_free_irq; 300 + } 301 + 302 + if (plat->wakeup_enable) 303 + device_init_wakeup(&pdev->dev, true); 304 + 305 + platform_set_drvdata(pdev, keypad); 306 + 307 + return 0; 308 + 309 + err_free_irq: 310 + free_irq(keypad->irq, keypad); 311 + err_clk_disable: 312 + clk_disable(keypad->clk); 313 + clk_put(keypad->clk); 314 + err_iounmap: 315 + iounmap(keypad->reg_base); 316 + err_free_mem_region: 317 + release_mem_region(res->start, resource_size(res)); 318 + err_free_mem: 319 + input_free_device(input); 320 + kfree(keypad); 321 + return error; 322 + } 323 + 324 + static int __devexit ske_keypad_remove(struct platform_device *pdev) 325 + { 326 + struct ske_keypad *keypad = platform_get_drvdata(pdev); 327 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 328 + 329 + free_irq(keypad->irq, keypad); 330 + 331 + input_unregister_device(keypad->input); 332 + 333 + clk_disable(keypad->clk); 334 + clk_put(keypad->clk); 335 + 336 + if (keypad->board->exit) 337 + keypad->board->exit(); 338 + 339 + iounmap(keypad->reg_base); 340 + release_mem_region(res->start, resource_size(res)); 341 + kfree(keypad); 342 + 343 + return 0; 344 + } 345 + 346 + #ifdef CONFIG_PM 347 + static int ske_keypad_suspend(struct device *dev) 348 + { 349 + struct platform_device *pdev = to_platform_device(dev); 350 + struct ske_keypad *keypad = platform_get_drvdata(pdev); 351 + int irq = platform_get_irq(pdev, 0); 352 + 353 + if (device_may_wakeup(dev)) 354 + enable_irq_wake(irq); 355 + else 356 + ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); 357 + 358 + return 0; 359 + } 360 + 361 + static int ske_keypad_resume(struct device *dev) 362 + { 363 + struct platform_device *pdev = to_platform_device(dev); 364 + struct ske_keypad *keypad = platform_get_drvdata(pdev); 365 + int irq = platform_get_irq(pdev, 0); 366 + 367 + if (device_may_wakeup(dev)) 368 + disable_irq_wake(irq); 369 + else 370 + ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 371 + 372 + return 0; 373 + } 374 + 375 + static const struct dev_pm_ops ske_keypad_dev_pm_ops = { 376 + .suspend = ske_keypad_suspend, 377 + .resume = ske_keypad_resume, 378 + }; 379 + #endif 380 + 381 + struct platform_driver ske_keypad_driver = { 382 + .driver = { 383 + .name = "nmk-ske-keypad", 384 + .owner = THIS_MODULE, 385 + #ifdef CONFIG_PM 386 + .pm = &ske_keypad_dev_pm_ops, 387 + #endif 388 + }, 389 + .probe = ske_keypad_probe, 390 + .remove = __devexit_p(ske_keypad_remove), 391 + }; 392 + 393 + static int __init ske_keypad_init(void) 394 + { 395 + return platform_driver_probe(&ske_keypad_driver, ske_keypad_probe); 396 + } 397 + module_init(ske_keypad_init); 398 + 399 + static void __exit ske_keypad_exit(void) 400 + { 401 + platform_driver_unregister(&ske_keypad_driver); 402 + } 403 + module_exit(ske_keypad_exit); 404 + 405 + MODULE_LICENSE("GPL v2"); 406 + MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>"); 407 + MODULE_DESCRIPTION("Nomadik Scroll-Key-Encoder Keypad Driver"); 408 + MODULE_ALIAS("platform:nomadik-ske-keypad");
+318
drivers/input/keyboard/omap4-keypad.c
··· 1 + /* 2 + * OMAP4 Keypad Driver 3 + * 4 + * Copyright (C) 2010 Texas Instruments 5 + * 6 + * Author: Abraham Arce <x0066660@ti.com> 7 + * Initial Code: Syed Rafiuddin <rafiuddin.syed@ti.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 + #include <linux/module.h> 25 + #include <linux/init.h> 26 + #include <linux/interrupt.h> 27 + #include <linux/platform_device.h> 28 + #include <linux/errno.h> 29 + #include <linux/io.h> 30 + #include <linux/input.h> 31 + #include <linux/slab.h> 32 + 33 + #include <plat/omap4-keypad.h> 34 + 35 + /* OMAP4 registers */ 36 + #define OMAP4_KBD_REVISION 0x00 37 + #define OMAP4_KBD_SYSCONFIG 0x10 38 + #define OMAP4_KBD_SYSSTATUS 0x14 39 + #define OMAP4_KBD_IRQSTATUS 0x18 40 + #define OMAP4_KBD_IRQENABLE 0x1C 41 + #define OMAP4_KBD_WAKEUPENABLE 0x20 42 + #define OMAP4_KBD_PENDING 0x24 43 + #define OMAP4_KBD_CTRL 0x28 44 + #define OMAP4_KBD_DEBOUNCINGTIME 0x2C 45 + #define OMAP4_KBD_LONGKEYTIME 0x30 46 + #define OMAP4_KBD_TIMEOUT 0x34 47 + #define OMAP4_KBD_STATEMACHINE 0x38 48 + #define OMAP4_KBD_ROWINPUTS 0x3C 49 + #define OMAP4_KBD_COLUMNOUTPUTS 0x40 50 + #define OMAP4_KBD_FULLCODE31_0 0x44 51 + #define OMAP4_KBD_FULLCODE63_32 0x48 52 + 53 + /* OMAP4 bit definitions */ 54 + #define OMAP4_DEF_IRQENABLE_EVENTEN (1 << 0) 55 + #define OMAP4_DEF_IRQENABLE_LONGKEY (1 << 1) 56 + #define OMAP4_DEF_IRQENABLE_TIMEOUTEN (1 << 2) 57 + #define OMAP4_DEF_WUP_EVENT_ENA (1 << 0) 58 + #define OMAP4_DEF_WUP_LONG_KEY_ENA (1 << 1) 59 + #define OMAP4_DEF_CTRL_NOSOFTMODE (1 << 1) 60 + #define OMAP4_DEF_CTRLPTVVALUE (1 << 2) 61 + #define OMAP4_DEF_CTRLPTV (1 << 1) 62 + 63 + /* OMAP4 values */ 64 + #define OMAP4_VAL_IRQDISABLE 0x00 65 + #define OMAP4_VAL_DEBOUNCINGTIME 0x07 66 + #define OMAP4_VAL_FUNCTIONALCFG 0x1E 67 + 68 + #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF 69 + 70 + struct omap4_keypad { 71 + struct input_dev *input; 72 + 73 + void __iomem *base; 74 + int irq; 75 + 76 + unsigned int rows; 77 + unsigned int cols; 78 + unsigned int row_shift; 79 + unsigned char key_state[8]; 80 + unsigned short keymap[]; 81 + }; 82 + 83 + static void __devinit omap4_keypad_config(struct omap4_keypad *keypad_data) 84 + { 85 + __raw_writel(OMAP4_VAL_FUNCTIONALCFG, 86 + keypad_data->base + OMAP4_KBD_CTRL); 87 + __raw_writel(OMAP4_VAL_DEBOUNCINGTIME, 88 + keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME); 89 + __raw_writel(OMAP4_VAL_IRQDISABLE, 90 + keypad_data->base + OMAP4_KBD_IRQSTATUS); 91 + __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY, 92 + keypad_data->base + OMAP4_KBD_IRQENABLE); 93 + __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA, 94 + keypad_data->base + OMAP4_KBD_WAKEUPENABLE); 95 + } 96 + 97 + /* Interrupt handler */ 98 + static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) 99 + { 100 + struct omap4_keypad *keypad_data = dev_id; 101 + struct input_dev *input_dev = keypad_data->input; 102 + unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)]; 103 + unsigned int col, row, code, changed; 104 + u32 *new_state = (u32 *) key_state; 105 + 106 + /* Disable interrupts */ 107 + __raw_writel(OMAP4_VAL_IRQDISABLE, 108 + keypad_data->base + OMAP4_KBD_IRQENABLE); 109 + 110 + *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0); 111 + *(new_state + 1) = __raw_readl(keypad_data->base 112 + + OMAP4_KBD_FULLCODE63_32); 113 + 114 + for (row = 0; row < keypad_data->rows; row++) { 115 + changed = key_state[row] ^ keypad_data->key_state[row]; 116 + if (!changed) 117 + continue; 118 + 119 + for (col = 0; col < keypad_data->cols; col++) { 120 + if (changed & (1 << col)) { 121 + code = MATRIX_SCAN_CODE(row, col, 122 + keypad_data->row_shift); 123 + input_event(input_dev, EV_MSC, MSC_SCAN, code); 124 + input_report_key(input_dev, 125 + keypad_data->keymap[code], 126 + key_state[row] & (1 << col)); 127 + } 128 + } 129 + } 130 + 131 + input_sync(input_dev); 132 + 133 + memcpy(keypad_data->key_state, key_state, 134 + sizeof(keypad_data->key_state)); 135 + 136 + /* clear pending interrupts */ 137 + __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS), 138 + keypad_data->base + OMAP4_KBD_IRQSTATUS); 139 + 140 + /* enable interrupts */ 141 + __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY, 142 + keypad_data->base + OMAP4_KBD_IRQENABLE); 143 + 144 + return IRQ_HANDLED; 145 + } 146 + 147 + static int __devinit omap4_keypad_probe(struct platform_device *pdev) 148 + { 149 + const struct omap4_keypad_platform_data *pdata; 150 + struct omap4_keypad *keypad_data; 151 + struct input_dev *input_dev; 152 + struct resource *res; 153 + resource_size_t size; 154 + unsigned int row_shift, max_keys; 155 + int irq; 156 + int error; 157 + 158 + /* platform data */ 159 + pdata = pdev->dev.platform_data; 160 + if (!pdata) { 161 + dev_err(&pdev->dev, "no platform data defined\n"); 162 + return -EINVAL; 163 + } 164 + 165 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 166 + if (!res) { 167 + dev_err(&pdev->dev, "no base address specified\n"); 168 + return -EINVAL; 169 + } 170 + 171 + irq = platform_get_irq(pdev, 0); 172 + if (!irq) { 173 + dev_err(&pdev->dev, "no keyboard irq assigned\n"); 174 + return -EINVAL; 175 + } 176 + 177 + if (!pdata->keymap_data) { 178 + dev_err(&pdev->dev, "no keymap data defined\n"); 179 + return -EINVAL; 180 + } 181 + 182 + row_shift = get_count_order(pdata->cols); 183 + max_keys = pdata->rows << row_shift; 184 + 185 + keypad_data = kzalloc(sizeof(struct omap4_keypad) + 186 + max_keys * sizeof(keypad_data->keymap[0]), 187 + GFP_KERNEL); 188 + if (!keypad_data) { 189 + dev_err(&pdev->dev, "keypad_data memory allocation failed\n"); 190 + return -ENOMEM; 191 + } 192 + 193 + size = resource_size(res); 194 + 195 + res = request_mem_region(res->start, size, pdev->name); 196 + if (!res) { 197 + dev_err(&pdev->dev, "can't request mem region\n"); 198 + error = -EBUSY; 199 + goto err_free_keypad; 200 + } 201 + 202 + keypad_data->base = ioremap(res->start, resource_size(res)); 203 + if (!keypad_data->base) { 204 + dev_err(&pdev->dev, "can't ioremap mem resource\n"); 205 + error = -ENOMEM; 206 + goto err_release_mem; 207 + } 208 + 209 + keypad_data->irq = irq; 210 + keypad_data->row_shift = row_shift; 211 + keypad_data->rows = pdata->rows; 212 + keypad_data->cols = pdata->cols; 213 + 214 + /* input device allocation */ 215 + keypad_data->input = input_dev = input_allocate_device(); 216 + if (!input_dev) { 217 + error = -ENOMEM; 218 + goto err_unmap; 219 + } 220 + 221 + input_dev->name = pdev->name; 222 + input_dev->dev.parent = &pdev->dev; 223 + input_dev->id.bustype = BUS_HOST; 224 + input_dev->id.vendor = 0x0001; 225 + input_dev->id.product = 0x0001; 226 + input_dev->id.version = 0x0001; 227 + 228 + input_dev->keycode = keypad_data->keymap; 229 + input_dev->keycodesize = sizeof(keypad_data->keymap[0]); 230 + input_dev->keycodemax = max_keys; 231 + 232 + __set_bit(EV_KEY, input_dev->evbit); 233 + __set_bit(EV_REP, input_dev->evbit); 234 + 235 + input_set_capability(input_dev, EV_MSC, MSC_SCAN); 236 + 237 + input_set_drvdata(input_dev, keypad_data); 238 + 239 + matrix_keypad_build_keymap(pdata->keymap_data, row_shift, 240 + input_dev->keycode, input_dev->keybit); 241 + 242 + omap4_keypad_config(keypad_data); 243 + 244 + error = request_irq(keypad_data->irq, omap4_keypad_interrupt, 245 + IRQF_TRIGGER_RISING, 246 + "omap4-keypad", keypad_data); 247 + if (error) { 248 + dev_err(&pdev->dev, "failed to register interrupt\n"); 249 + goto err_free_input; 250 + } 251 + 252 + error = input_register_device(keypad_data->input); 253 + if (error < 0) { 254 + dev_err(&pdev->dev, "failed to register input device\n"); 255 + goto err_free_irq; 256 + } 257 + 258 + 259 + platform_set_drvdata(pdev, keypad_data); 260 + return 0; 261 + 262 + err_free_irq: 263 + free_irq(keypad_data->irq, keypad_data); 264 + err_free_input: 265 + input_free_device(input_dev); 266 + err_unmap: 267 + iounmap(keypad_data->base); 268 + err_release_mem: 269 + release_mem_region(res->start, size); 270 + err_free_keypad: 271 + kfree(keypad_data); 272 + return error; 273 + } 274 + 275 + static int __devexit omap4_keypad_remove(struct platform_device *pdev) 276 + { 277 + struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); 278 + struct resource *res; 279 + 280 + free_irq(keypad_data->irq, keypad_data); 281 + input_unregister_device(keypad_data->input); 282 + 283 + iounmap(keypad_data->base); 284 + 285 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 286 + release_mem_region(res->start, resource_size(res)); 287 + 288 + kfree(keypad_data); 289 + platform_set_drvdata(pdev, NULL); 290 + 291 + return 0; 292 + } 293 + 294 + static struct platform_driver omap4_keypad_driver = { 295 + .probe = omap4_keypad_probe, 296 + .remove = __devexit_p(omap4_keypad_remove), 297 + .driver = { 298 + .name = "omap4-keypad", 299 + .owner = THIS_MODULE, 300 + }, 301 + }; 302 + 303 + static int __init omap4_keypad_init(void) 304 + { 305 + return platform_driver_register(&omap4_keypad_driver); 306 + } 307 + module_init(omap4_keypad_init); 308 + 309 + static void __exit omap4_keypad_exit(void) 310 + { 311 + platform_driver_unregister(&omap4_keypad_driver); 312 + } 313 + module_exit(omap4_keypad_exit); 314 + 315 + MODULE_AUTHOR("Texas Instruments"); 316 + MODULE_DESCRIPTION("OMAP4 Keypad Driver"); 317 + MODULE_LICENSE("GPL"); 318 + MODULE_ALIAS("platform:omap4-keypad");
+3 -4
drivers/input/keyboard/twl4030_keypad.c
··· 406 406 if (error) { 407 407 dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n", 408 408 kp->irq); 409 - goto err3; 409 + goto err2; 410 410 } 411 411 412 412 /* Enable KP and TO interrupts now. */ 413 413 reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO); 414 414 if (twl4030_kpwrite_u8(kp, reg, KEYP_IMR1)) { 415 415 error = -EIO; 416 - goto err4; 416 + goto err3; 417 417 } 418 418 419 419 platform_set_drvdata(pdev, kp); 420 420 return 0; 421 421 422 - err4: 422 + err3: 423 423 /* mask all events - we don't care about the result */ 424 424 (void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1); 425 - err3: 426 425 free_irq(kp->irq, NULL); 427 426 err2: 428 427 input_unregister_device(input);
+10
drivers/input/misc/Kconfig
··· 22 22 To compile this driver as a module, choose M here: the module 23 23 will be called 88pm860x_onkey. 24 24 25 + config INPUT_AB8500_PONKEY 26 + tristate "AB8500 Pon (PowerOn) Key" 27 + depends on AB8500_CORE 28 + help 29 + Say Y here to use the PowerOn Key for ST-Ericsson's AB8500 30 + Mix-Sig PMIC. 31 + 32 + To compile this driver as a module, choose M here: the module 33 + will be called ab8500-ponkey. 34 + 25 35 config INPUT_AD714X 26 36 tristate "Analog Devices AD714x Capacitance Touch Sensor" 27 37 help
+1
drivers/input/misc/Makefile
··· 5 5 # Each configuration option enables a list of files. 6 6 7 7 obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o 8 + obj-$(CONFIG_INPUT_AB8500_PONKEY) += ab8500-ponkey.o 8 9 obj-$(CONFIG_INPUT_AD714X) += ad714x.o 9 10 obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o 10 11 obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o
+157
drivers/input/misc/ab8500-ponkey.c
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * 4 + * License Terms: GNU General Public License v2 5 + * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 6 + * 7 + * AB8500 Power-On Key handler 8 + */ 9 + 10 + #include <linux/kernel.h> 11 + #include <linux/module.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/input.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/mfd/ab8500.h> 16 + #include <linux/slab.h> 17 + 18 + /** 19 + * struct ab8500_ponkey - ab8500 ponkey information 20 + * @input_dev: pointer to input device 21 + * @ab8500: ab8500 parent 22 + * @irq_dbf: irq number for falling transition 23 + * @irq_dbr: irq number for rising transition 24 + */ 25 + struct ab8500_ponkey { 26 + struct input_dev *idev; 27 + struct ab8500 *ab8500; 28 + int irq_dbf; 29 + int irq_dbr; 30 + }; 31 + 32 + /* AB8500 gives us an interrupt when ONKEY is held */ 33 + static irqreturn_t ab8500_ponkey_handler(int irq, void *data) 34 + { 35 + struct ab8500_ponkey *ponkey = data; 36 + 37 + if (irq == ponkey->irq_dbf) 38 + input_report_key(ponkey->idev, KEY_POWER, true); 39 + else if (irq == ponkey->irq_dbr) 40 + input_report_key(ponkey->idev, KEY_POWER, false); 41 + 42 + input_sync(ponkey->idev); 43 + 44 + return IRQ_HANDLED; 45 + } 46 + 47 + static int __devinit ab8500_ponkey_probe(struct platform_device *pdev) 48 + { 49 + struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); 50 + struct ab8500_ponkey *ponkey; 51 + struct input_dev *input; 52 + int irq_dbf, irq_dbr; 53 + int error; 54 + 55 + irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF"); 56 + if (irq_dbf < 0) { 57 + dev_err(&pdev->dev, "No IRQ for ONKEY_DBF, error=%d\n", irq_dbf); 58 + return irq_dbf; 59 + } 60 + 61 + irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR"); 62 + if (irq_dbr < 0) { 63 + dev_err(&pdev->dev, "No IRQ for ONKEY_DBR, error=%d\n", irq_dbr); 64 + return irq_dbr; 65 + } 66 + 67 + ponkey = kzalloc(sizeof(struct ab8500_ponkey), GFP_KERNEL); 68 + input = input_allocate_device(); 69 + if (!ponkey || !input) { 70 + error = -ENOMEM; 71 + goto err_free_mem; 72 + } 73 + 74 + ponkey->idev = input; 75 + ponkey->ab8500 = ab8500; 76 + ponkey->irq_dbf = irq_dbf; 77 + ponkey->irq_dbr = irq_dbr; 78 + 79 + input->name = "AB8500 POn(PowerOn) Key"; 80 + input->dev.parent = &pdev->dev; 81 + 82 + input_set_capability(input, EV_KEY, KEY_POWER); 83 + 84 + error = request_any_context_irq(ponkey->irq_dbf, ab8500_ponkey_handler, 85 + 0, "ab8500-ponkey-dbf", ponkey); 86 + if (error < 0) { 87 + dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n", 88 + ponkey->irq_dbf, error); 89 + goto err_free_mem; 90 + } 91 + 92 + error = request_any_context_irq(ponkey->irq_dbr, ab8500_ponkey_handler, 93 + 0, "ab8500-ponkey-dbr", ponkey); 94 + if (error < 0) { 95 + dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n", 96 + ponkey->irq_dbr, error); 97 + goto err_free_dbf_irq; 98 + } 99 + 100 + error = input_register_device(ponkey->idev); 101 + if (error) { 102 + dev_err(ab8500->dev, "Can't register input device: %d\n", error); 103 + goto err_free_dbr_irq; 104 + } 105 + 106 + platform_set_drvdata(pdev, ponkey); 107 + return 0; 108 + 109 + err_free_dbr_irq: 110 + free_irq(ponkey->irq_dbr, ponkey); 111 + err_free_dbf_irq: 112 + free_irq(ponkey->irq_dbf, ponkey); 113 + err_free_mem: 114 + input_free_device(input); 115 + kfree(ponkey); 116 + 117 + return error; 118 + } 119 + 120 + static int __devexit ab8500_ponkey_remove(struct platform_device *pdev) 121 + { 122 + struct ab8500_ponkey *ponkey = platform_get_drvdata(pdev); 123 + 124 + free_irq(ponkey->irq_dbf, ponkey); 125 + free_irq(ponkey->irq_dbr, ponkey); 126 + input_unregister_device(ponkey->idev); 127 + kfree(ponkey); 128 + 129 + platform_set_drvdata(pdev, NULL); 130 + 131 + return 0; 132 + } 133 + 134 + static struct platform_driver ab8500_ponkey_driver = { 135 + .driver = { 136 + .name = "ab8500-poweron-key", 137 + .owner = THIS_MODULE, 138 + }, 139 + .probe = ab8500_ponkey_probe, 140 + .remove = __devexit_p(ab8500_ponkey_remove), 141 + }; 142 + 143 + static int __init ab8500_ponkey_init(void) 144 + { 145 + return platform_driver_register(&ab8500_ponkey_driver); 146 + } 147 + module_init(ab8500_ponkey_init); 148 + 149 + static void __exit ab8500_ponkey_exit(void) 150 + { 151 + platform_driver_unregister(&ab8500_ponkey_driver); 152 + } 153 + module_exit(ab8500_ponkey_exit); 154 + 155 + MODULE_LICENSE("GPL v2"); 156 + MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); 157 + MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver");
+62 -25
drivers/input/misc/ati_remote2.c
··· 483 483 } 484 484 485 485 static int ati_remote2_getkeycode(struct input_dev *idev, 486 - unsigned int scancode, unsigned int *keycode) 486 + struct input_keymap_entry *ke) 487 487 { 488 488 struct ati_remote2 *ar2 = input_get_drvdata(idev); 489 489 unsigned int mode; 490 - int index; 490 + int offset; 491 + unsigned int index; 492 + unsigned int scancode; 491 493 492 - mode = scancode >> 8; 493 - if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) 494 - return -EINVAL; 494 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) { 495 + index = ke->index; 496 + if (index >= ATI_REMOTE2_MODES * 497 + ARRAY_SIZE(ati_remote2_key_table)) 498 + return -EINVAL; 495 499 496 - index = ati_remote2_lookup(scancode & 0xFF); 497 - if (index < 0) 498 - return -EINVAL; 500 + mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); 501 + offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); 502 + scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code; 503 + } else { 504 + if (input_scancode_to_scalar(ke, &scancode)) 505 + return -EINVAL; 499 506 500 - *keycode = ar2->keycode[mode][index]; 507 + mode = scancode >> 8; 508 + if (mode > ATI_REMOTE2_PC) 509 + return -EINVAL; 510 + 511 + offset = ati_remote2_lookup(scancode & 0xff); 512 + if (offset < 0) 513 + return -EINVAL; 514 + 515 + index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset; 516 + } 517 + 518 + ke->keycode = ar2->keycode[mode][offset]; 519 + ke->len = sizeof(scancode); 520 + memcpy(&ke->scancode, &scancode, sizeof(scancode)); 521 + ke->index = index; 522 + 501 523 return 0; 502 524 } 503 525 504 526 static int ati_remote2_setkeycode(struct input_dev *idev, 505 - unsigned int scancode, unsigned int keycode) 527 + const struct input_keymap_entry *ke, 528 + unsigned int *old_keycode) 506 529 { 507 530 struct ati_remote2 *ar2 = input_get_drvdata(idev); 508 - unsigned int mode, old_keycode; 509 - int index; 531 + unsigned int mode; 532 + int offset; 533 + unsigned int index; 534 + unsigned int scancode; 510 535 511 - mode = scancode >> 8; 512 - if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) 513 - return -EINVAL; 536 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) { 537 + if (ke->index >= ATI_REMOTE2_MODES * 538 + ARRAY_SIZE(ati_remote2_key_table)) 539 + return -EINVAL; 514 540 515 - index = ati_remote2_lookup(scancode & 0xFF); 516 - if (index < 0) 517 - return -EINVAL; 541 + mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); 542 + offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); 543 + } else { 544 + if (input_scancode_to_scalar(ke, &scancode)) 545 + return -EINVAL; 518 546 519 - old_keycode = ar2->keycode[mode][index]; 520 - ar2->keycode[mode][index] = keycode; 521 - __set_bit(keycode, idev->keybit); 547 + mode = scancode >> 8; 548 + if (mode > ATI_REMOTE2_PC) 549 + return -EINVAL; 550 + 551 + offset = ati_remote2_lookup(scancode & 0xff); 552 + if (offset < 0) 553 + return -EINVAL; 554 + } 555 + 556 + *old_keycode = ar2->keycode[mode][offset]; 557 + ar2->keycode[mode][offset] = ke->keycode; 558 + __set_bit(ke->keycode, idev->keybit); 522 559 523 560 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { 524 561 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) { 525 - if (ar2->keycode[mode][index] == old_keycode) 562 + if (ar2->keycode[mode][index] == *old_keycode) 526 563 return 0; 527 564 } 528 565 } 529 566 530 - __clear_bit(old_keycode, idev->keybit); 567 + __clear_bit(*old_keycode, idev->keybit); 531 568 532 569 return 0; 533 570 } ··· 612 575 idev->open = ati_remote2_open; 613 576 idev->close = ati_remote2_close; 614 577 615 - idev->getkeycode = ati_remote2_getkeycode; 616 - idev->setkeycode = ati_remote2_setkeycode; 578 + idev->getkeycode_new = ati_remote2_getkeycode; 579 + idev->setkeycode_new = ati_remote2_setkeycode; 617 580 618 581 idev->name = ar2->name; 619 582 idev->phys = ar2->phys;
+1 -1
drivers/input/misc/powermate.c
··· 280 280 281 281 pm->configcr = kmalloc(sizeof(*(pm->configcr)), GFP_KERNEL); 282 282 if (!pm->configcr) 283 - return -1; 283 + return -ENOMEM; 284 284 285 285 return 0; 286 286 }
+1 -1
drivers/input/mouse/elantech.c
··· 699 699 700 700 psmouse->private = etd = kzalloc(sizeof(struct elantech_data), GFP_KERNEL); 701 701 if (!etd) 702 - return -1; 702 + return -ENOMEM; 703 703 704 704 etd->parity[0] = 1; 705 705 for (i = 1; i < 256; i++)
+2 -2
drivers/input/mouse/psmouse-base.c
··· 1584 1584 if (!new_dev) 1585 1585 return -ENOMEM; 1586 1586 1587 - while (serio->child) { 1587 + while (!list_empty(&serio->children)) { 1588 1588 if (++retry > 3) { 1589 1589 printk(KERN_WARNING 1590 - "psmouse: failed to destroy child port, " 1590 + "psmouse: failed to destroy children ports, " 1591 1591 "protocol change aborted.\n"); 1592 1592 input_free_device(new_dev); 1593 1593 return -EIO;
+31 -7
drivers/input/mouse/synaptics.c
··· 294 294 return 0; 295 295 } 296 296 297 - static inline int synaptics_is_pt_packet(unsigned char *buf) 297 + static int synaptics_pt_start(struct serio *serio) 298 + { 299 + struct psmouse *parent = serio_get_drvdata(serio->parent); 300 + struct synaptics_data *priv = parent->private; 301 + 302 + serio_pause_rx(parent->ps2dev.serio); 303 + priv->pt_port = serio; 304 + serio_continue_rx(parent->ps2dev.serio); 305 + 306 + return 0; 307 + } 308 + 309 + static void synaptics_pt_stop(struct serio *serio) 310 + { 311 + struct psmouse *parent = serio_get_drvdata(serio->parent); 312 + struct synaptics_data *priv = parent->private; 313 + 314 + serio_pause_rx(parent->ps2dev.serio); 315 + priv->pt_port = NULL; 316 + serio_continue_rx(parent->ps2dev.serio); 317 + } 318 + 319 + static int synaptics_is_pt_packet(unsigned char *buf) 298 320 { 299 321 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4; 300 322 } ··· 337 315 338 316 static void synaptics_pt_activate(struct psmouse *psmouse) 339 317 { 340 - struct serio *ptport = psmouse->ps2dev.serio->child; 341 - struct psmouse *child = serio_get_drvdata(ptport); 342 318 struct synaptics_data *priv = psmouse->private; 319 + struct psmouse *child = serio_get_drvdata(priv->pt_port); 343 320 344 321 /* adjust the touchpad to child's choice of protocol */ 345 322 if (child) { ··· 366 345 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); 367 346 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); 368 347 serio->write = synaptics_pt_write; 348 + serio->start = synaptics_pt_start; 349 + serio->stop = synaptics_pt_stop; 369 350 serio->parent = psmouse->ps2dev.serio; 370 351 371 352 psmouse->pt_activate = synaptics_pt_activate; ··· 601 578 if (unlikely(priv->pkt_type == SYN_NEWABS)) 602 579 priv->pkt_type = synaptics_detect_pkt_type(psmouse); 603 580 604 - if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) { 605 - if (psmouse->ps2dev.serio->child) 606 - synaptics_pass_pt_packet(psmouse->ps2dev.serio->child, psmouse->packet); 581 + if (SYN_CAP_PASS_THROUGH(priv->capabilities) && 582 + synaptics_is_pt_packet(psmouse->packet)) { 583 + if (priv->pt_port) 584 + synaptics_pass_pt_packet(priv->pt_port, psmouse->packet); 607 585 } else 608 586 synaptics_process_packet(psmouse); 609 587 ··· 755 731 756 732 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL); 757 733 if (!priv) 758 - return -1; 734 + return -ENOMEM; 759 735 760 736 psmouse_reset(psmouse); 761 737
+2
drivers/input/mouse/synaptics.h
··· 110 110 unsigned char pkt_type; /* packet type - old, new, etc */ 111 111 unsigned char mode; /* current mode byte */ 112 112 int scroll; 113 + 114 + struct serio *pt_port; /* Pass-through serio port */ 113 115 }; 114 116 115 117 void synaptics_module_init(void);
+1 -1
drivers/input/mouse/trackpoint.c
··· 303 303 304 304 psmouse->private = kzalloc(sizeof(struct trackpoint_data), GFP_KERNEL); 305 305 if (!psmouse->private) 306 - return -1; 306 + return -ENOMEM; 307 307 308 308 psmouse->vendor = "IBM"; 309 309 psmouse->name = "TrackPoint";
+1 -1
drivers/input/mousedev.c
··· 866 866 spin_lock_init(&mousedev->client_lock); 867 867 mutex_init(&mousedev->mutex); 868 868 lockdep_set_subclass(&mousedev->mutex, 869 - minor == MOUSEDEV_MIX ? MOUSEDEV_MIX : 0); 869 + minor == MOUSEDEV_MIX ? SINGLE_DEPTH_NESTING : 0); 870 870 init_waitqueue_head(&mousedev->wait); 871 871 872 872 if (minor == MOUSEDEV_MIX)
+9
drivers/input/serio/Kconfig
··· 226 226 To compile this driver as a module, choose M here; 227 227 the module will be called ams_delta_serio. 228 228 229 + config SERIO_PS2MULT 230 + tristate "TQC PS/2 multiplexer" 231 + help 232 + Say Y here if you have the PS/2 line multiplexer like the one 233 + present on TQC boads. 234 + 235 + To compile this driver as a module, choose M here: the 236 + module will be called ps2mult. 237 + 229 238 endif
+1
drivers/input/serio/Makefile
··· 18 18 obj-$(CONFIG_HP_SDC) += hp_sdc.o 19 19 obj-$(CONFIG_HIL_MLC) += hp_sdc_mlc.o hil_mlc.o 20 20 obj-$(CONFIG_SERIO_PCIPS2) += pcips2.o 21 + obj-$(CONFIG_SERIO_PS2MULT) += ps2mult.o 21 22 obj-$(CONFIG_SERIO_MACEPS2) += maceps2.o 22 23 obj-$(CONFIG_SERIO_LIBPS2) += libps2.o 23 24 obj-$(CONFIG_SERIO_RAW) += serio_raw.o
+1 -1
drivers/input/serio/i8042.c
··· 1063 1063 #ifdef CONFIG_X86 1064 1064 static void i8042_dritek_enable(void) 1065 1065 { 1066 - char param = 0x90; 1066 + unsigned char param = 0x90; 1067 1067 int error; 1068 1068 1069 1069 error = i8042_command(&param, 0x1059);
+318
drivers/input/serio/ps2mult.c
··· 1 + /* 2 + * TQC PS/2 Multiplexer driver 3 + * 4 + * Copyright (C) 2010 Dmitry Eremin-Solenikov 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License version 2 as published by 8 + * the Free Software Foundation. 9 + */ 10 + 11 + 12 + #include <linux/kernel.h> 13 + #include <linux/slab.h> 14 + #include <linux/module.h> 15 + #include <linux/serio.h> 16 + 17 + MODULE_AUTHOR("Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>"); 18 + MODULE_DESCRIPTION("TQC PS/2 Multiplexer driver"); 19 + MODULE_LICENSE("GPL"); 20 + 21 + #define PS2MULT_KB_SELECTOR 0xA0 22 + #define PS2MULT_MS_SELECTOR 0xA1 23 + #define PS2MULT_ESCAPE 0x7D 24 + #define PS2MULT_BSYNC 0x7E 25 + #define PS2MULT_SESSION_START 0x55 26 + #define PS2MULT_SESSION_END 0x56 27 + 28 + struct ps2mult_port { 29 + struct serio *serio; 30 + unsigned char sel; 31 + bool registered; 32 + }; 33 + 34 + #define PS2MULT_NUM_PORTS 2 35 + #define PS2MULT_KBD_PORT 0 36 + #define PS2MULT_MOUSE_PORT 1 37 + 38 + struct ps2mult { 39 + struct serio *mx_serio; 40 + struct ps2mult_port ports[PS2MULT_NUM_PORTS]; 41 + 42 + spinlock_t lock; 43 + struct ps2mult_port *in_port; 44 + struct ps2mult_port *out_port; 45 + bool escape; 46 + }; 47 + 48 + /* First MUST come PS2MULT_NUM_PORTS selectors */ 49 + static const unsigned char ps2mult_controls[] = { 50 + PS2MULT_KB_SELECTOR, PS2MULT_MS_SELECTOR, 51 + PS2MULT_ESCAPE, PS2MULT_BSYNC, 52 + PS2MULT_SESSION_START, PS2MULT_SESSION_END, 53 + }; 54 + 55 + static const struct serio_device_id ps2mult_serio_ids[] = { 56 + { 57 + .type = SERIO_RS232, 58 + .proto = SERIO_PS2MULT, 59 + .id = SERIO_ANY, 60 + .extra = SERIO_ANY, 61 + }, 62 + { 0 } 63 + }; 64 + 65 + MODULE_DEVICE_TABLE(serio, ps2mult_serio_ids); 66 + 67 + static void ps2mult_select_port(struct ps2mult *psm, struct ps2mult_port *port) 68 + { 69 + struct serio *mx_serio = psm->mx_serio; 70 + 71 + serio_write(mx_serio, port->sel); 72 + psm->out_port = port; 73 + dev_dbg(&mx_serio->dev, "switched to sel %02x\n", port->sel); 74 + } 75 + 76 + static int ps2mult_serio_write(struct serio *serio, unsigned char data) 77 + { 78 + struct serio *mx_port = serio->parent; 79 + struct ps2mult *psm = serio_get_drvdata(mx_port); 80 + struct ps2mult_port *port = serio->port_data; 81 + bool need_escape; 82 + unsigned long flags; 83 + 84 + spin_lock_irqsave(&psm->lock, flags); 85 + 86 + if (psm->out_port != port) 87 + ps2mult_select_port(psm, port); 88 + 89 + need_escape = memchr(ps2mult_controls, data, sizeof(ps2mult_controls)); 90 + 91 + dev_dbg(&serio->dev, 92 + "write: %s%02x\n", need_escape ? "ESC " : "", data); 93 + 94 + if (need_escape) 95 + serio_write(mx_port, PS2MULT_ESCAPE); 96 + 97 + serio_write(mx_port, data); 98 + 99 + spin_unlock_irqrestore(&psm->lock, flags); 100 + 101 + return 0; 102 + } 103 + 104 + static int ps2mult_serio_start(struct serio *serio) 105 + { 106 + struct ps2mult *psm = serio_get_drvdata(serio->parent); 107 + struct ps2mult_port *port = serio->port_data; 108 + unsigned long flags; 109 + 110 + spin_lock_irqsave(&psm->lock, flags); 111 + port->registered = true; 112 + spin_unlock_irqrestore(&psm->lock, flags); 113 + 114 + return 0; 115 + } 116 + 117 + static void ps2mult_serio_stop(struct serio *serio) 118 + { 119 + struct ps2mult *psm = serio_get_drvdata(serio->parent); 120 + struct ps2mult_port *port = serio->port_data; 121 + unsigned long flags; 122 + 123 + spin_lock_irqsave(&psm->lock, flags); 124 + port->registered = false; 125 + spin_unlock_irqrestore(&psm->lock, flags); 126 + } 127 + 128 + static int ps2mult_create_port(struct ps2mult *psm, int i) 129 + { 130 + struct serio *mx_serio = psm->mx_serio; 131 + struct serio *serio; 132 + 133 + serio = kzalloc(sizeof(struct serio), GFP_KERNEL); 134 + if (!serio) 135 + return -ENOMEM; 136 + 137 + strlcpy(serio->name, "TQC PS/2 Multiplexer", sizeof(serio->name)); 138 + snprintf(serio->phys, sizeof(serio->phys), 139 + "%s/port%d", mx_serio->phys, i); 140 + serio->id.type = SERIO_8042; 141 + serio->write = ps2mult_serio_write; 142 + serio->start = ps2mult_serio_start; 143 + serio->stop = ps2mult_serio_stop; 144 + serio->parent = psm->mx_serio; 145 + serio->port_data = &psm->ports[i]; 146 + 147 + psm->ports[i].serio = serio; 148 + 149 + return 0; 150 + } 151 + 152 + static void ps2mult_reset(struct ps2mult *psm) 153 + { 154 + unsigned long flags; 155 + 156 + spin_lock_irqsave(&psm->lock, flags); 157 + 158 + serio_write(psm->mx_serio, PS2MULT_SESSION_END); 159 + serio_write(psm->mx_serio, PS2MULT_SESSION_START); 160 + 161 + ps2mult_select_port(psm, &psm->ports[PS2MULT_KBD_PORT]); 162 + 163 + spin_unlock_irqrestore(&psm->lock, flags); 164 + } 165 + 166 + static int ps2mult_connect(struct serio *serio, struct serio_driver *drv) 167 + { 168 + struct ps2mult *psm; 169 + int i; 170 + int error; 171 + 172 + if (!serio->write) 173 + return -EINVAL; 174 + 175 + psm = kzalloc(sizeof(*psm), GFP_KERNEL); 176 + if (!psm) 177 + return -ENOMEM; 178 + 179 + spin_lock_init(&psm->lock); 180 + psm->mx_serio = serio; 181 + 182 + for (i = 0; i < PS2MULT_NUM_PORTS; i++) { 183 + psm->ports[i].sel = ps2mult_controls[i]; 184 + error = ps2mult_create_port(psm, i); 185 + if (error) 186 + goto err_out; 187 + } 188 + 189 + psm->in_port = psm->out_port = &psm->ports[PS2MULT_KBD_PORT]; 190 + 191 + serio_set_drvdata(serio, psm); 192 + error = serio_open(serio, drv); 193 + if (error) 194 + goto err_out; 195 + 196 + ps2mult_reset(psm); 197 + 198 + for (i = 0; i < PS2MULT_NUM_PORTS; i++) { 199 + struct serio *s = psm->ports[i].serio; 200 + 201 + dev_info(&serio->dev, "%s port at %s\n", s->name, serio->phys); 202 + serio_register_port(s); 203 + } 204 + 205 + return 0; 206 + 207 + err_out: 208 + while (--i >= 0) 209 + kfree(psm->ports[i].serio); 210 + kfree(serio); 211 + return error; 212 + } 213 + 214 + static void ps2mult_disconnect(struct serio *serio) 215 + { 216 + struct ps2mult *psm = serio_get_drvdata(serio); 217 + 218 + /* Note that serio core already take care of children ports */ 219 + serio_write(serio, PS2MULT_SESSION_END); 220 + serio_close(serio); 221 + kfree(psm); 222 + 223 + serio_set_drvdata(serio, NULL); 224 + } 225 + 226 + static int ps2mult_reconnect(struct serio *serio) 227 + { 228 + struct ps2mult *psm = serio_get_drvdata(serio); 229 + 230 + ps2mult_reset(psm); 231 + 232 + return 0; 233 + } 234 + 235 + static irqreturn_t ps2mult_interrupt(struct serio *serio, 236 + unsigned char data, unsigned int dfl) 237 + { 238 + struct ps2mult *psm = serio_get_drvdata(serio); 239 + struct ps2mult_port *in_port; 240 + unsigned long flags; 241 + 242 + dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, dfl); 243 + 244 + spin_lock_irqsave(&psm->lock, flags); 245 + 246 + if (psm->escape) { 247 + psm->escape = false; 248 + in_port = psm->in_port; 249 + if (in_port->registered) 250 + serio_interrupt(in_port->serio, data, dfl); 251 + goto out; 252 + } 253 + 254 + switch (data) { 255 + case PS2MULT_ESCAPE: 256 + dev_dbg(&serio->dev, "ESCAPE\n"); 257 + psm->escape = true; 258 + break; 259 + 260 + case PS2MULT_BSYNC: 261 + dev_dbg(&serio->dev, "BSYNC\n"); 262 + psm->in_port = psm->out_port; 263 + break; 264 + 265 + case PS2MULT_SESSION_START: 266 + dev_dbg(&serio->dev, "SS\n"); 267 + break; 268 + 269 + case PS2MULT_SESSION_END: 270 + dev_dbg(&serio->dev, "SE\n"); 271 + break; 272 + 273 + case PS2MULT_KB_SELECTOR: 274 + dev_dbg(&serio->dev, "KB\n"); 275 + psm->in_port = &psm->ports[PS2MULT_KBD_PORT]; 276 + break; 277 + 278 + case PS2MULT_MS_SELECTOR: 279 + dev_dbg(&serio->dev, "MS\n"); 280 + psm->in_port = &psm->ports[PS2MULT_MOUSE_PORT]; 281 + break; 282 + 283 + default: 284 + in_port = psm->in_port; 285 + if (in_port->registered) 286 + serio_interrupt(in_port->serio, data, dfl); 287 + break; 288 + } 289 + 290 + out: 291 + spin_unlock_irqrestore(&psm->lock, flags); 292 + return IRQ_HANDLED; 293 + } 294 + 295 + static struct serio_driver ps2mult_drv = { 296 + .driver = { 297 + .name = "ps2mult", 298 + }, 299 + .description = "TQC PS/2 Multiplexer driver", 300 + .id_table = ps2mult_serio_ids, 301 + .interrupt = ps2mult_interrupt, 302 + .connect = ps2mult_connect, 303 + .disconnect = ps2mult_disconnect, 304 + .reconnect = ps2mult_reconnect, 305 + }; 306 + 307 + static int __init ps2mult_init(void) 308 + { 309 + return serio_register_driver(&ps2mult_drv); 310 + } 311 + 312 + static void __exit ps2mult_exit(void) 313 + { 314 + serio_unregister_driver(&ps2mult_drv); 315 + } 316 + 317 + module_init(ps2mult_init); 318 + module_exit(ps2mult_exit);
+81 -44
drivers/input/serio/serio.c
··· 37 37 #include <linux/slab.h> 38 38 #include <linux/kthread.h> 39 39 #include <linux/mutex.h> 40 - #include <linux/freezer.h> 41 40 42 41 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 43 42 MODULE_DESCRIPTION("Serio abstraction core"); ··· 55 56 static void serio_add_port(struct serio *serio); 56 57 static int serio_reconnect_port(struct serio *serio); 57 58 static void serio_disconnect_port(struct serio *serio); 58 - static void serio_reconnect_chain(struct serio *serio); 59 + static void serio_reconnect_subtree(struct serio *serio); 59 60 static void serio_attach_driver(struct serio_driver *drv); 60 61 61 62 static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) ··· 151 152 enum serio_event_type { 152 153 SERIO_RESCAN_PORT, 153 154 SERIO_RECONNECT_PORT, 154 - SERIO_RECONNECT_CHAIN, 155 + SERIO_RECONNECT_SUBTREE, 155 156 SERIO_REGISTER_PORT, 156 157 SERIO_ATTACH_DRIVER, 157 158 }; ··· 291 292 serio_find_driver(event->object); 292 293 break; 293 294 294 - case SERIO_RECONNECT_CHAIN: 295 - serio_reconnect_chain(event->object); 295 + case SERIO_RECONNECT_SUBTREE: 296 + serio_reconnect_subtree(event->object); 296 297 break; 297 298 298 299 case SERIO_ATTACH_DRIVER: ··· 329 330 } 330 331 331 332 /* 332 - * Destroy child serio port (if any) that has not been fully registered yet. 333 + * Locate child serio port (if any) that has not been fully registered yet. 333 334 * 334 - * Note that we rely on the fact that port can have only one child and therefore 335 - * only one child registration request can be pending. Additionally, children 336 - * are registered by driver's connect() handler so there can't be a grandchild 337 - * pending registration together with a child. 335 + * Children are registered by driver's connect() handler so there can't be a 336 + * grandchild pending registration together with a child. 338 337 */ 339 338 static struct serio *serio_get_pending_child(struct serio *parent) 340 339 { ··· 446 449 if (!strncmp(buf, "none", count)) { 447 450 serio_disconnect_port(serio); 448 451 } else if (!strncmp(buf, "reconnect", count)) { 449 - serio_reconnect_chain(serio); 452 + serio_reconnect_subtree(serio); 450 453 } else if (!strncmp(buf, "rescan", count)) { 451 454 serio_disconnect_port(serio); 452 455 serio_find_driver(serio); ··· 513 516 __module_get(THIS_MODULE); 514 517 515 518 INIT_LIST_HEAD(&serio->node); 519 + INIT_LIST_HEAD(&serio->child_node); 520 + INIT_LIST_HEAD(&serio->children); 516 521 spin_lock_init(&serio->lock); 517 522 mutex_init(&serio->drv_mutex); 518 523 device_initialize(&serio->dev); ··· 537 538 */ 538 539 static void serio_add_port(struct serio *serio) 539 540 { 541 + struct serio *parent = serio->parent; 540 542 int error; 541 543 542 - if (serio->parent) { 543 - serio_pause_rx(serio->parent); 544 - serio->parent->child = serio; 545 - serio_continue_rx(serio->parent); 544 + if (parent) { 545 + serio_pause_rx(parent); 546 + list_add_tail(&serio->child_node, &parent->children); 547 + serio_continue_rx(parent); 546 548 } 547 549 548 550 list_add_tail(&serio->node, &serio_list); ··· 559 559 } 560 560 561 561 /* 562 - * serio_destroy_port() completes deregistration process and removes 562 + * serio_destroy_port() completes unregistration process and removes 563 563 * port from the system 564 564 */ 565 565 static void serio_destroy_port(struct serio *serio) 566 566 { 567 567 struct serio *child; 568 568 569 - child = serio_get_pending_child(serio); 570 - if (child) { 569 + while ((child = serio_get_pending_child(serio)) != NULL) { 571 570 serio_remove_pending_events(child); 572 571 put_device(&child->dev); 573 572 } ··· 576 577 577 578 if (serio->parent) { 578 579 serio_pause_rx(serio->parent); 579 - serio->parent->child = NULL; 580 + list_del_init(&serio->child_node); 580 581 serio_continue_rx(serio->parent); 581 582 serio->parent = NULL; 582 583 } ··· 608 609 } 609 610 610 611 /* 611 - * Reconnect serio port and all its children (re-initialize attached devices) 612 + * Reconnect serio port and all its children (re-initialize attached 613 + * devices). 612 614 */ 613 - static void serio_reconnect_chain(struct serio *serio) 615 + static void serio_reconnect_subtree(struct serio *root) 614 616 { 617 + struct serio *s = root; 618 + int error; 619 + 615 620 do { 616 - if (serio_reconnect_port(serio)) { 617 - /* Ok, old children are now gone, we are done */ 618 - break; 621 + error = serio_reconnect_port(s); 622 + if (!error) { 623 + /* 624 + * Reconnect was successful, move on to do the 625 + * first child. 626 + */ 627 + if (!list_empty(&s->children)) { 628 + s = list_first_entry(&s->children, 629 + struct serio, child_node); 630 + continue; 631 + } 619 632 } 620 - serio = serio->child; 621 - } while (serio); 633 + 634 + /* 635 + * Either it was a leaf node or reconnect failed and it 636 + * became a leaf node. Continue reconnecting starting with 637 + * the next sibling of the parent node. 638 + */ 639 + while (s != root) { 640 + struct serio *parent = s->parent; 641 + 642 + if (!list_is_last(&s->child_node, &parent->children)) { 643 + s = list_entry(s->child_node.next, 644 + struct serio, child_node); 645 + break; 646 + } 647 + 648 + s = parent; 649 + } 650 + } while (s != root); 622 651 } 623 652 624 653 /* 625 654 * serio_disconnect_port() unbinds a port from its driver. As a side effect 626 - * all child ports are unbound and destroyed. 655 + * all children ports are unbound and destroyed. 627 656 */ 628 657 static void serio_disconnect_port(struct serio *serio) 629 658 { 630 - struct serio *s, *parent; 659 + struct serio *s = serio; 631 660 632 - if (serio->child) { 661 + /* 662 + * Children ports should be disconnected and destroyed 663 + * first; we travel the tree in depth-first order. 664 + */ 665 + while (!list_empty(&serio->children)) { 666 + 667 + /* Locate a leaf */ 668 + while (!list_empty(&s->children)) 669 + s = list_first_entry(&s->children, 670 + struct serio, child_node); 671 + 633 672 /* 634 - * Children ports should be disconnected and destroyed 635 - * first, staring with the leaf one, since we don't want 636 - * to do recursion 673 + * Prune this leaf node unless it is the one we 674 + * started with. 637 675 */ 638 - for (s = serio; s->child; s = s->child) 639 - /* empty */; 640 - 641 - do { 642 - parent = s->parent; 676 + if (s != serio) { 677 + struct serio *parent = s->parent; 643 678 644 679 device_release_driver(&s->dev); 645 680 serio_destroy_port(s); 646 - } while ((s = parent) != serio); 681 + 682 + s = parent; 683 + } 647 684 } 648 685 649 686 /* 650 - * Ok, no children left, now disconnect this port 687 + * OK, no children left, now disconnect this port. 651 688 */ 652 689 device_release_driver(&serio->dev); 653 690 } ··· 696 661 697 662 void serio_reconnect(struct serio *serio) 698 663 { 699 - serio_queue_event(serio, NULL, SERIO_RECONNECT_CHAIN); 664 + serio_queue_event(serio, NULL, SERIO_RECONNECT_SUBTREE); 700 665 } 701 666 EXPORT_SYMBOL(serio_reconnect); 702 667 ··· 724 689 EXPORT_SYMBOL(serio_unregister_port); 725 690 726 691 /* 727 - * Safely unregisters child port if one is present. 692 + * Safely unregisters children ports if they are present. 728 693 */ 729 694 void serio_unregister_child_port(struct serio *serio) 730 695 { 696 + struct serio *s, *next; 697 + 731 698 mutex_lock(&serio_mutex); 732 - if (serio->child) { 733 - serio_disconnect_port(serio->child); 734 - serio_destroy_port(serio->child); 699 + list_for_each_entry_safe(s, next, &serio->children, child_node) { 700 + serio_disconnect_port(s); 701 + serio_destroy_port(s); 735 702 } 736 703 mutex_unlock(&serio_mutex); 737 704 }
+65 -16
drivers/input/sparse-keymap.c
··· 22 22 MODULE_LICENSE("GPL v2"); 23 23 MODULE_VERSION("0.1"); 24 24 25 + static unsigned int sparse_keymap_get_key_index(struct input_dev *dev, 26 + const struct key_entry *k) 27 + { 28 + struct key_entry *key; 29 + unsigned int idx = 0; 30 + 31 + for (key = dev->keycode; key->type != KE_END; key++) { 32 + if (key->type == KE_KEY) { 33 + if (key == k) 34 + break; 35 + idx++; 36 + } 37 + } 38 + 39 + return idx; 40 + } 41 + 42 + static struct key_entry *sparse_keymap_entry_by_index(struct input_dev *dev, 43 + unsigned int index) 44 + { 45 + struct key_entry *key; 46 + unsigned int key_cnt = 0; 47 + 48 + for (key = dev->keycode; key->type != KE_END; key++) 49 + if (key->type == KE_KEY) 50 + if (key_cnt++ == index) 51 + return key; 52 + 53 + return NULL; 54 + } 55 + 25 56 /** 26 57 * sparse_keymap_entry_from_scancode - perform sparse keymap lookup 27 58 * @dev: Input device using sparse keymap ··· 95 64 } 96 65 EXPORT_SYMBOL(sparse_keymap_entry_from_keycode); 97 66 67 + static struct key_entry *sparse_keymap_locate(struct input_dev *dev, 68 + const struct input_keymap_entry *ke) 69 + { 70 + struct key_entry *key; 71 + unsigned int scancode; 72 + 73 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) 74 + key = sparse_keymap_entry_by_index(dev, ke->index); 75 + else if (input_scancode_to_scalar(ke, &scancode) == 0) 76 + key = sparse_keymap_entry_from_scancode(dev, scancode); 77 + else 78 + key = NULL; 79 + 80 + return key; 81 + } 82 + 98 83 static int sparse_keymap_getkeycode(struct input_dev *dev, 99 - unsigned int scancode, 100 - unsigned int *keycode) 84 + struct input_keymap_entry *ke) 101 85 { 102 86 const struct key_entry *key; 103 87 104 88 if (dev->keycode) { 105 - key = sparse_keymap_entry_from_scancode(dev, scancode); 89 + key = sparse_keymap_locate(dev, ke); 106 90 if (key && key->type == KE_KEY) { 107 - *keycode = key->keycode; 91 + ke->keycode = key->keycode; 92 + if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) 93 + ke->index = 94 + sparse_keymap_get_key_index(dev, key); 95 + ke->len = sizeof(key->code); 96 + memcpy(ke->scancode, &key->code, sizeof(key->code)); 108 97 return 0; 109 98 } 110 99 } ··· 133 82 } 134 83 135 84 static int sparse_keymap_setkeycode(struct input_dev *dev, 136 - unsigned int scancode, 137 - unsigned int keycode) 85 + const struct input_keymap_entry *ke, 86 + unsigned int *old_keycode) 138 87 { 139 88 struct key_entry *key; 140 - int old_keycode; 141 89 142 90 if (dev->keycode) { 143 - key = sparse_keymap_entry_from_scancode(dev, scancode); 91 + key = sparse_keymap_locate(dev, ke); 144 92 if (key && key->type == KE_KEY) { 145 - old_keycode = key->keycode; 146 - key->keycode = keycode; 147 - set_bit(keycode, dev->keybit); 148 - if (!sparse_keymap_entry_from_keycode(dev, old_keycode)) 149 - clear_bit(old_keycode, dev->keybit); 93 + *old_keycode = key->keycode; 94 + key->keycode = ke->keycode; 95 + set_bit(ke->keycode, dev->keybit); 96 + if (!sparse_keymap_entry_from_keycode(dev, *old_keycode)) 97 + clear_bit(*old_keycode, dev->keybit); 150 98 return 0; 151 99 } 152 100 } ··· 209 159 210 160 dev->keycode = map; 211 161 dev->keycodemax = map_size; 212 - dev->getkeycode = sparse_keymap_getkeycode; 213 - dev->setkeycode = sparse_keymap_setkeycode; 162 + dev->getkeycode_new = sparse_keymap_getkeycode; 163 + dev->setkeycode_new = sparse_keymap_setkeycode; 214 164 215 165 return 0; 216 166 217 167 err_out: 218 168 kfree(map); 219 169 return error; 220 - 221 170 } 222 171 EXPORT_SYMBOL(sparse_keymap_setup); 223 172
+11
drivers/input/tablet/Kconfig
··· 49 49 To compile this driver as a module, choose M here: the 50 50 module will be called gtco. 51 51 52 + config TABLET_USB_HANWANG 53 + tristate "Hanwang Art Master III tablet support (USB)" 54 + depends on USB_ARCH_HAS_HCD 55 + select USB 56 + help 57 + Say Y here if you want to use the USB version of the Hanwang Art 58 + Master III tablet. 59 + 60 + To compile this driver as a module, choose M here: the 61 + module will be called hanwang. 62 + 52 63 config TABLET_USB_KBTAB 53 64 tristate "KB Gear JamStudio tablet support (USB)" 54 65 depends on USB_ARCH_HAS_HCD
+1
drivers/input/tablet/Makefile
··· 8 8 obj-$(CONFIG_TABLET_USB_ACECAD) += acecad.o 9 9 obj-$(CONFIG_TABLET_USB_AIPTEK) += aiptek.o 10 10 obj-$(CONFIG_TABLET_USB_GTCO) += gtco.o 11 + obj-$(CONFIG_TABLET_USB_HANWANG) += hanwang.o 11 12 obj-$(CONFIG_TABLET_USB_KBTAB) += kbtab.o 12 13 obj-$(CONFIG_TABLET_USB_WACOM) += wacom.o
+446
drivers/input/tablet/hanwang.c
··· 1 + /* 2 + * USB Hanwang tablet support 3 + * 4 + * Copyright (c) 2010 Xing Wei <weixing@hanwang.com.cn> 5 + * 6 + */ 7 + 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/types.h> 26 + #include <linux/kernel.h> 27 + #include <linux/slab.h> 28 + #include <linux/module.h> 29 + #include <linux/init.h> 30 + #include <linux/usb/input.h> 31 + 32 + #define DRIVER_AUTHOR "Xing Wei <weixing@hanwang.com.cn>" 33 + #define DRIVER_DESC "USB Hanwang tablet driver" 34 + #define DRIVER_LICENSE "GPL" 35 + 36 + MODULE_AUTHOR(DRIVER_AUTHOR); 37 + MODULE_DESCRIPTION(DRIVER_DESC); 38 + MODULE_LICENSE(DRIVER_LICENSE); 39 + 40 + #define USB_VENDOR_ID_HANWANG 0x0b57 41 + #define HANWANG_TABLET_INT_CLASS 0x0003 42 + #define HANWANG_TABLET_INT_SUB_CLASS 0x0001 43 + #define HANWANG_TABLET_INT_PROTOCOL 0x0002 44 + 45 + #define ART_MASTER_PKGLEN_MAX 10 46 + 47 + /* device IDs */ 48 + #define STYLUS_DEVICE_ID 0x02 49 + #define TOUCH_DEVICE_ID 0x03 50 + #define CURSOR_DEVICE_ID 0x06 51 + #define ERASER_DEVICE_ID 0x0A 52 + #define PAD_DEVICE_ID 0x0F 53 + 54 + /* match vendor and interface info */ 55 + #define HANWANG_TABLET_DEVICE(vend, cl, sc, pr) \ 56 + .match_flags = USB_DEVICE_ID_MATCH_VENDOR \ 57 + | USB_DEVICE_ID_MATCH_INT_INFO, \ 58 + .idVendor = (vend), \ 59 + .bInterfaceClass = (cl), \ 60 + .bInterfaceSubClass = (sc), \ 61 + .bInterfaceProtocol = (pr) 62 + 63 + enum hanwang_tablet_type { 64 + HANWANG_ART_MASTER_III, 65 + HANWANG_ART_MASTER_HD, 66 + }; 67 + 68 + struct hanwang { 69 + unsigned char *data; 70 + dma_addr_t data_dma; 71 + struct input_dev *dev; 72 + struct usb_device *usbdev; 73 + struct urb *irq; 74 + const struct hanwang_features *features; 75 + unsigned int current_tool; 76 + unsigned int current_id; 77 + char name[64]; 78 + char phys[32]; 79 + }; 80 + 81 + struct hanwang_features { 82 + unsigned short pid; 83 + char *name; 84 + enum hanwang_tablet_type type; 85 + int pkg_len; 86 + int max_x; 87 + int max_y; 88 + int max_tilt_x; 89 + int max_tilt_y; 90 + int max_pressure; 91 + }; 92 + 93 + static const struct hanwang_features features_array[] = { 94 + { 0x8528, "Hanwang Art Master III 0906", HANWANG_ART_MASTER_III, 95 + ART_MASTER_PKGLEN_MAX, 0x5757, 0x3692, 0x3f, 0x7f, 2048 }, 96 + { 0x8529, "Hanwang Art Master III 0604", HANWANG_ART_MASTER_III, 97 + ART_MASTER_PKGLEN_MAX, 0x3d84, 0x2672, 0x3f, 0x7f, 2048 }, 98 + { 0x852a, "Hanwang Art Master III 1308", HANWANG_ART_MASTER_III, 99 + ART_MASTER_PKGLEN_MAX, 0x7f00, 0x4f60, 0x3f, 0x7f, 2048 }, 100 + { 0x8401, "Hanwang Art Master HD 5012", HANWANG_ART_MASTER_HD, 101 + ART_MASTER_PKGLEN_MAX, 0x678e, 0x4150, 0x3f, 0x7f, 1024 }, 102 + }; 103 + 104 + static const int hw_eventtypes[] = { 105 + EV_KEY, EV_ABS, EV_MSC, 106 + }; 107 + 108 + static const int hw_absevents[] = { 109 + ABS_X, ABS_Y, ABS_TILT_X, ABS_TILT_Y, ABS_WHEEL, 110 + ABS_RX, ABS_RY, ABS_PRESSURE, ABS_MISC, 111 + }; 112 + 113 + static const int hw_btnevents[] = { 114 + BTN_STYLUS, BTN_STYLUS2, BTN_TOOL_PEN, BTN_TOOL_RUBBER, 115 + BTN_TOOL_MOUSE, BTN_TOOL_FINGER, 116 + BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8, 117 + }; 118 + 119 + static const int hw_mscevents[] = { 120 + MSC_SERIAL, 121 + }; 122 + 123 + static void hanwang_parse_packet(struct hanwang *hanwang) 124 + { 125 + unsigned char *data = hanwang->data; 126 + struct input_dev *input_dev = hanwang->dev; 127 + struct usb_device *dev = hanwang->usbdev; 128 + enum hanwang_tablet_type type = hanwang->features->type; 129 + int i; 130 + u16 x, y, p; 131 + 132 + switch (data[0]) { 133 + case 0x02: /* data packet */ 134 + switch (data[1]) { 135 + case 0x80: /* tool prox out */ 136 + hanwang->current_id = 0; 137 + input_report_key(input_dev, hanwang->current_tool, 0); 138 + break; 139 + 140 + case 0xc2: /* first time tool prox in */ 141 + switch (data[3] & 0xf0) { 142 + case 0x20: /* art_master III */ 143 + case 0x30: /* art_master_HD */ 144 + hanwang->current_id = STYLUS_DEVICE_ID; 145 + hanwang->current_tool = BTN_TOOL_PEN; 146 + input_report_key(input_dev, BTN_TOOL_PEN, 1); 147 + break; 148 + case 0xa0: /* art_master III */ 149 + case 0xb0: /* art_master_HD */ 150 + hanwang->current_id = ERASER_DEVICE_ID; 151 + hanwang->current_tool = BTN_TOOL_RUBBER; 152 + input_report_key(input_dev, BTN_TOOL_RUBBER, 1); 153 + break; 154 + default: 155 + hanwang->current_id = 0; 156 + dev_dbg(&dev->dev, 157 + "unknown tablet tool %02x ", data[0]); 158 + break; 159 + } 160 + break; 161 + 162 + default: /* tool data packet */ 163 + x = (data[2] << 8) | data[3]; 164 + y = (data[4] << 8) | data[5]; 165 + 166 + switch (type) { 167 + case HANWANG_ART_MASTER_III: 168 + p = (data[6] << 3) | 169 + ((data[7] & 0xc0) >> 5) | 170 + (data[1] & 0x01); 171 + break; 172 + 173 + case HANWANG_ART_MASTER_HD: 174 + p = (data[7] >> 6) | (data[6] << 2); 175 + break; 176 + 177 + default: 178 + p = 0; 179 + break; 180 + } 181 + 182 + input_report_abs(input_dev, ABS_X, 183 + le16_to_cpup((__le16 *)&x)); 184 + input_report_abs(input_dev, ABS_Y, 185 + le16_to_cpup((__le16 *)&y)); 186 + input_report_abs(input_dev, ABS_PRESSURE, 187 + le16_to_cpup((__le16 *)&p)); 188 + input_report_abs(input_dev, ABS_TILT_X, data[7] & 0x3f); 189 + input_report_abs(input_dev, ABS_TILT_Y, data[8] & 0x7f); 190 + input_report_key(input_dev, BTN_STYLUS, data[1] & 0x02); 191 + input_report_key(input_dev, BTN_STYLUS2, data[1] & 0x04); 192 + break; 193 + } 194 + input_report_abs(input_dev, ABS_MISC, hanwang->current_id); 195 + input_event(input_dev, EV_MSC, MSC_SERIAL, 196 + hanwang->features->pid); 197 + break; 198 + 199 + case 0x0c: 200 + /* roll wheel */ 201 + hanwang->current_id = PAD_DEVICE_ID; 202 + 203 + switch (type) { 204 + case HANWANG_ART_MASTER_III: 205 + input_report_key(input_dev, BTN_TOOL_FINGER, data[1] || 206 + data[2] || data[3]); 207 + input_report_abs(input_dev, ABS_WHEEL, data[1]); 208 + input_report_key(input_dev, BTN_0, data[2]); 209 + for (i = 0; i < 8; i++) 210 + input_report_key(input_dev, 211 + BTN_1 + i, data[3] & (1 << i)); 212 + break; 213 + 214 + case HANWANG_ART_MASTER_HD: 215 + input_report_key(input_dev, BTN_TOOL_FINGER, data[1] || 216 + data[2] || data[3] || data[4] || 217 + data[5] || data[6]); 218 + input_report_abs(input_dev, ABS_RX, 219 + ((data[1] & 0x1f) << 8) | data[2]); 220 + input_report_abs(input_dev, ABS_RY, 221 + ((data[3] & 0x1f) << 8) | data[4]); 222 + input_report_key(input_dev, BTN_0, data[5] & 0x01); 223 + for (i = 0; i < 4; i++) { 224 + input_report_key(input_dev, 225 + BTN_1 + i, data[5] & (1 << i)); 226 + input_report_key(input_dev, 227 + BTN_5 + i, data[6] & (1 << i)); 228 + } 229 + break; 230 + } 231 + 232 + input_report_abs(input_dev, ABS_MISC, hanwang->current_id); 233 + input_event(input_dev, EV_MSC, MSC_SERIAL, 0xffffffff); 234 + break; 235 + 236 + default: 237 + dev_dbg(&dev->dev, "error packet %02x ", data[0]); 238 + break; 239 + } 240 + 241 + input_sync(input_dev); 242 + } 243 + 244 + static void hanwang_irq(struct urb *urb) 245 + { 246 + struct hanwang *hanwang = urb->context; 247 + struct usb_device *dev = hanwang->usbdev; 248 + int retval; 249 + 250 + switch (urb->status) { 251 + case 0: 252 + /* success */; 253 + hanwang_parse_packet(hanwang); 254 + break; 255 + case -ECONNRESET: 256 + case -ENOENT: 257 + case -ESHUTDOWN: 258 + /* this urb is terminated, clean up */ 259 + dev_err(&dev->dev, "%s - urb shutting down with status: %d", 260 + __func__, urb->status); 261 + return; 262 + default: 263 + dev_err(&dev->dev, "%s - nonzero urb status received: %d", 264 + __func__, urb->status); 265 + break; 266 + } 267 + 268 + retval = usb_submit_urb(urb, GFP_ATOMIC); 269 + if (retval) 270 + dev_err(&dev->dev, "%s - usb_submit_urb failed with result %d", 271 + __func__, retval); 272 + } 273 + 274 + static int hanwang_open(struct input_dev *dev) 275 + { 276 + struct hanwang *hanwang = input_get_drvdata(dev); 277 + 278 + hanwang->irq->dev = hanwang->usbdev; 279 + if (usb_submit_urb(hanwang->irq, GFP_KERNEL)) 280 + return -EIO; 281 + 282 + return 0; 283 + } 284 + 285 + static void hanwang_close(struct input_dev *dev) 286 + { 287 + struct hanwang *hanwang = input_get_drvdata(dev); 288 + 289 + usb_kill_urb(hanwang->irq); 290 + } 291 + 292 + static bool get_features(struct usb_device *dev, struct hanwang *hanwang) 293 + { 294 + int i; 295 + 296 + for (i = 0; i < ARRAY_SIZE(features_array); i++) { 297 + if (le16_to_cpu(dev->descriptor.idProduct) == 298 + features_array[i].pid) { 299 + hanwang->features = &features_array[i]; 300 + return true; 301 + } 302 + } 303 + 304 + return false; 305 + } 306 + 307 + 308 + static int hanwang_probe(struct usb_interface *intf, const struct usb_device_id *id) 309 + { 310 + struct usb_device *dev = interface_to_usbdev(intf); 311 + struct usb_endpoint_descriptor *endpoint; 312 + struct hanwang *hanwang; 313 + struct input_dev *input_dev; 314 + int error; 315 + int i; 316 + 317 + hanwang = kzalloc(sizeof(struct hanwang), GFP_KERNEL); 318 + input_dev = input_allocate_device(); 319 + if (!hanwang || !input_dev) { 320 + error = -ENOMEM; 321 + goto fail1; 322 + } 323 + 324 + if (!get_features(dev, hanwang)) { 325 + error = -ENXIO; 326 + goto fail1; 327 + } 328 + 329 + hanwang->data = usb_alloc_coherent(dev, hanwang->features->pkg_len, 330 + GFP_KERNEL, &hanwang->data_dma); 331 + if (!hanwang->data) { 332 + error = -ENOMEM; 333 + goto fail1; 334 + } 335 + 336 + hanwang->irq = usb_alloc_urb(0, GFP_KERNEL); 337 + if (!hanwang->irq) { 338 + error = -ENOMEM; 339 + goto fail2; 340 + } 341 + 342 + hanwang->usbdev = dev; 343 + hanwang->dev = input_dev; 344 + 345 + usb_make_path(dev, hanwang->phys, sizeof(hanwang->phys)); 346 + strlcat(hanwang->phys, "/input0", sizeof(hanwang->phys)); 347 + 348 + strlcpy(hanwang->name, hanwang->features->name, sizeof(hanwang->name)); 349 + input_dev->name = hanwang->name; 350 + input_dev->phys = hanwang->phys; 351 + usb_to_input_id(dev, &input_dev->id); 352 + input_dev->dev.parent = &intf->dev; 353 + 354 + input_set_drvdata(input_dev, hanwang); 355 + 356 + input_dev->open = hanwang_open; 357 + input_dev->close = hanwang_close; 358 + 359 + for (i = 0; i < ARRAY_SIZE(hw_eventtypes); ++i) 360 + __set_bit(hw_eventtypes[i], input_dev->evbit); 361 + 362 + for (i = 0; i < ARRAY_SIZE(hw_absevents); ++i) 363 + __set_bit(hw_absevents[i], input_dev->absbit); 364 + 365 + for (i = 0; i < ARRAY_SIZE(hw_btnevents); ++i) 366 + __set_bit(hw_btnevents[i], input_dev->keybit); 367 + 368 + for (i = 0; i < ARRAY_SIZE(hw_mscevents); ++i) 369 + __set_bit(hw_mscevents[i], input_dev->mscbit); 370 + 371 + input_set_abs_params(input_dev, ABS_X, 372 + 0, hanwang->features->max_x, 4, 0); 373 + input_set_abs_params(input_dev, ABS_Y, 374 + 0, hanwang->features->max_y, 4, 0); 375 + input_set_abs_params(input_dev, ABS_TILT_X, 376 + 0, hanwang->features->max_tilt_x, 0, 0); 377 + input_set_abs_params(input_dev, ABS_TILT_Y, 378 + 0, hanwang->features->max_tilt_y, 0, 0); 379 + input_set_abs_params(input_dev, ABS_PRESSURE, 380 + 0, hanwang->features->max_pressure, 0, 0); 381 + 382 + endpoint = &intf->cur_altsetting->endpoint[0].desc; 383 + usb_fill_int_urb(hanwang->irq, dev, 384 + usb_rcvintpipe(dev, endpoint->bEndpointAddress), 385 + hanwang->data, hanwang->features->pkg_len, 386 + hanwang_irq, hanwang, endpoint->bInterval); 387 + hanwang->irq->transfer_dma = hanwang->data_dma; 388 + hanwang->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 389 + 390 + error = input_register_device(hanwang->dev); 391 + if (error) 392 + goto fail3; 393 + 394 + usb_set_intfdata(intf, hanwang); 395 + 396 + return 0; 397 + 398 + fail3: usb_free_urb(hanwang->irq); 399 + fail2: usb_free_coherent(dev, hanwang->features->pkg_len, 400 + hanwang->data, hanwang->data_dma); 401 + fail1: input_free_device(input_dev); 402 + kfree(hanwang); 403 + return error; 404 + 405 + } 406 + 407 + static void hanwang_disconnect(struct usb_interface *intf) 408 + { 409 + struct hanwang *hanwang = usb_get_intfdata(intf); 410 + 411 + input_unregister_device(hanwang->dev); 412 + usb_free_urb(hanwang->irq); 413 + usb_free_coherent(interface_to_usbdev(intf), 414 + hanwang->features->pkg_len, hanwang->data, 415 + hanwang->data_dma); 416 + kfree(hanwang); 417 + usb_set_intfdata(intf, NULL); 418 + } 419 + 420 + static const struct usb_device_id hanwang_ids[] = { 421 + { HANWANG_TABLET_DEVICE(USB_VENDOR_ID_HANWANG, HANWANG_TABLET_INT_CLASS, 422 + HANWANG_TABLET_INT_SUB_CLASS, HANWANG_TABLET_INT_PROTOCOL) }, 423 + {} 424 + }; 425 + 426 + MODULE_DEVICE_TABLE(usb, hanwang_ids); 427 + 428 + static struct usb_driver hanwang_driver = { 429 + .name = "hanwang", 430 + .probe = hanwang_probe, 431 + .disconnect = hanwang_disconnect, 432 + .id_table = hanwang_ids, 433 + }; 434 + 435 + static int __init hanwang_init(void) 436 + { 437 + return usb_register(&hanwang_driver); 438 + } 439 + 440 + static void __exit hanwang_exit(void) 441 + { 442 + usb_deregister(&hanwang_driver); 443 + } 444 + 445 + module_init(hanwang_init); 446 + module_exit(hanwang_exit);
+1
drivers/input/tablet/wacom.h
··· 118 118 extern const struct usb_device_id wacom_ids[]; 119 119 120 120 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); 121 + void wacom_setup_device_quirks(struct wacom_features *features); 121 122 void wacom_setup_input_capabilities(struct input_dev *input_dev, 122 123 struct wacom_wac *wacom_wac); 123 124 #endif
+52 -23
drivers/input/tablet/wacom_sys.c
··· 120 120 121 121 out: 122 122 mutex_unlock(&wacom->lock); 123 - if (retval) 124 - usb_autopm_put_interface(wacom->intf); 123 + usb_autopm_put_interface(wacom->intf); 125 124 return retval; 126 125 } 127 126 128 127 static void wacom_close(struct input_dev *dev) 129 128 { 130 129 struct wacom *wacom = input_get_drvdata(dev); 130 + int autopm_error; 131 + 132 + autopm_error = usb_autopm_get_interface(wacom->intf); 131 133 132 134 mutex_lock(&wacom->lock); 133 135 usb_kill_urb(wacom->irq); ··· 137 135 wacom->intf->needs_remote_wakeup = 0; 138 136 mutex_unlock(&wacom->lock); 139 137 140 - usb_autopm_put_interface(wacom->intf); 138 + if (!autopm_error) 139 + usb_autopm_put_interface(wacom->intf); 141 140 } 142 141 143 142 static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, ··· 199 196 features->pktlen = WACOM_PKGLEN_TPC2FG; 200 197 features->device_type = BTN_TOOL_TRIPLETAP; 201 198 } 202 - features->x_max = 203 - get_unaligned_le16(&report[i + 3]); 204 - features->x_phy = 205 - get_unaligned_le16(&report[i + 6]); 206 - features->unit = report[i + 9]; 207 - features->unitExpo = report[i + 11]; 208 - i += 12; 199 + if (features->type == BAMBOO_PT) { 200 + /* need to reset back */ 201 + features->pktlen = WACOM_PKGLEN_BBTOUCH; 202 + features->device_type = BTN_TOOL_TRIPLETAP; 203 + features->x_phy = 204 + get_unaligned_le16(&report[i + 5]); 205 + features->x_max = 206 + get_unaligned_le16(&report[i + 8]); 207 + i += 15; 208 + } else { 209 + features->x_max = 210 + get_unaligned_le16(&report[i + 3]); 211 + features->x_phy = 212 + get_unaligned_le16(&report[i + 6]); 213 + features->unit = report[i + 9]; 214 + features->unitExpo = report[i + 11]; 215 + i += 12; 216 + } 209 217 } else if (pen) { 210 218 /* penabled only accepts exact bytes of data */ 211 219 if (features->type == TABLETPC2FG) 212 220 features->pktlen = WACOM_PKGLEN_GRAPHIRE; 221 + if (features->type == BAMBOO_PT) 222 + features->pktlen = WACOM_PKGLEN_BBFUN; 213 223 features->device_type = BTN_TOOL_PEN; 214 224 features->x_max = 215 225 get_unaligned_le16(&report[i + 3]); ··· 251 235 features->y_phy = 252 236 get_unaligned_le16(&report[i + 6]); 253 237 i += 7; 238 + } else if (features->type == BAMBOO_PT) { 239 + /* need to reset back */ 240 + features->pktlen = WACOM_PKGLEN_BBTOUCH; 241 + features->device_type = BTN_TOOL_TRIPLETAP; 242 + features->y_phy = 243 + get_unaligned_le16(&report[i + 3]); 244 + features->y_max = 245 + get_unaligned_le16(&report[i + 6]); 246 + i += 12; 254 247 } else { 255 248 features->y_max = 256 249 features->x_max; ··· 271 246 /* penabled only accepts exact bytes of data */ 272 247 if (features->type == TABLETPC2FG) 273 248 features->pktlen = WACOM_PKGLEN_GRAPHIRE; 249 + if (features->type == BAMBOO_PT) 250 + features->pktlen = WACOM_PKGLEN_BBFUN; 274 251 features->device_type = BTN_TOOL_PEN; 275 252 features->y_max = 276 253 get_unaligned_le16(&report[i + 3]); ··· 323 296 if (!rep_data) 324 297 return error; 325 298 326 - /* ask to report tablet data if it is 2FGT or not a Tablet PC */ 327 - if (features->device_type == BTN_TOOL_TRIPLETAP) { 299 + /* ask to report tablet data if it is 2FGT Tablet PC or 300 + * not a Tablet PC */ 301 + if (features->type == TABLETPC2FG) { 328 302 do { 329 303 rep_data[0] = 3; 330 304 rep_data[1] = 4; ··· 337 309 WAC_HID_FEATURE_REPORT, report_id, 338 310 rep_data, 3); 339 311 } while ((error < 0 || rep_data[1] != 4) && limit++ < 5); 340 - } else if (features->type != TABLETPC && features->type != TABLETPC2FG) { 312 + } else if (features->type != TABLETPC) { 341 313 do { 342 314 rep_data[0] = 2; 343 315 rep_data[1] = 2; ··· 362 334 struct usb_host_interface *interface = intf->cur_altsetting; 363 335 struct hid_descriptor *hid_desc; 364 336 365 - /* default device to penabled */ 337 + /* default features */ 366 338 features->device_type = BTN_TOOL_PEN; 339 + features->x_fuzz = 4; 340 + features->y_fuzz = 4; 341 + features->pressure_fuzz = 0; 342 + features->distance_fuzz = 0; 367 343 368 - /* only Tablet PCs need to retrieve the info */ 369 - if ((features->type != TABLETPC) && (features->type != TABLETPC2FG)) 344 + /* only Tablet PCs and Bamboo P&T need to retrieve the info */ 345 + if ((features->type != TABLETPC) && (features->type != TABLETPC2FG) && 346 + (features->type != BAMBOO_PT)) 370 347 goto out; 371 348 372 349 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) { ··· 385 352 error = wacom_parse_hid(intf, hid_desc, features); 386 353 if (error) 387 354 goto out; 388 - 389 - /* touch device found but size is not defined. use default */ 390 - if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) { 391 - features->x_max = 1023; 392 - features->y_max = 1023; 393 - } 394 355 395 356 out: 396 357 return error; ··· 521 494 if (error) 522 495 goto fail2; 523 496 497 + wacom_setup_device_quirks(features); 498 + 524 499 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); 525 500 526 - if (features->type == TABLETPC || features->type == TABLETPC2FG) { 501 + if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { 527 502 /* Append the device type to the name */ 528 503 strlcat(wacom_wac->name, 529 504 features->device_type == BTN_TOOL_PEN ?
+239 -14
drivers/input/tablet/wacom_wac.c
··· 857 857 return retval; 858 858 } 859 859 860 + static int wacom_bpt_touch(struct wacom_wac *wacom) 861 + { 862 + struct wacom_features *features = &wacom->features; 863 + struct input_dev *input = wacom->input; 864 + unsigned char *data = wacom->data; 865 + int sp = 0, sx = 0, sy = 0, count = 0; 866 + int i; 867 + 868 + for (i = 0; i < 2; i++) { 869 + int p = data[9 * i + 2]; 870 + input_mt_slot(input, i); 871 + /* 872 + * Touch events need to be disabled while stylus is 873 + * in proximity because user's hand is resting on touchpad 874 + * and sending unwanted events. User expects tablet buttons 875 + * to continue working though. 876 + */ 877 + if (p && !wacom->shared->stylus_in_proximity) { 878 + int x = get_unaligned_be16(&data[9 * i + 3]) & 0x7ff; 879 + int y = get_unaligned_be16(&data[9 * i + 5]) & 0x7ff; 880 + if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) { 881 + x <<= 5; 882 + y <<= 5; 883 + } 884 + input_report_abs(input, ABS_MT_PRESSURE, p); 885 + input_report_abs(input, ABS_MT_POSITION_X, x); 886 + input_report_abs(input, ABS_MT_POSITION_Y, y); 887 + if (wacom->id[i] < 0) 888 + wacom->id[i] = wacom->trk_id++ & MAX_TRACKING_ID; 889 + if (!count++) 890 + sp = p, sx = x, sy = y; 891 + } else { 892 + wacom->id[i] = -1; 893 + } 894 + input_report_abs(input, ABS_MT_TRACKING_ID, wacom->id[i]); 895 + } 896 + 897 + input_report_key(input, BTN_TOUCH, count > 0); 898 + input_report_key(input, BTN_TOOL_FINGER, count == 1); 899 + input_report_key(input, BTN_TOOL_DOUBLETAP, count == 2); 900 + 901 + input_report_abs(input, ABS_PRESSURE, sp); 902 + input_report_abs(input, ABS_X, sx); 903 + input_report_abs(input, ABS_Y, sy); 904 + 905 + input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0); 906 + input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0); 907 + input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0); 908 + input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0); 909 + 910 + input_sync(input); 911 + 912 + return 0; 913 + } 914 + 915 + static int wacom_bpt_pen(struct wacom_wac *wacom) 916 + { 917 + struct input_dev *input = wacom->input; 918 + unsigned char *data = wacom->data; 919 + int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0; 920 + 921 + /* 922 + * Similar to Graphire protocol, data[1] & 0x20 is proximity and 923 + * data[1] & 0x18 is tool ID. 0x30 is safety check to ignore 924 + * 2 unused tool ID's. 925 + */ 926 + prox = (data[1] & 0x30) == 0x30; 927 + 928 + /* 929 + * All reports shared between PEN and RUBBER tool must be 930 + * forced to a known starting value (zero) when transitioning to 931 + * out-of-prox. 932 + * 933 + * If not reset then, to userspace, it will look like lost events 934 + * if new tool comes in-prox with same values as previous tool sent. 935 + * 936 + * Hardware does report zero in most out-of-prox cases but not all. 937 + */ 938 + if (prox) { 939 + if (!wacom->shared->stylus_in_proximity) { 940 + if (data[1] & 0x08) { 941 + wacom->tool[0] = BTN_TOOL_RUBBER; 942 + wacom->id[0] = ERASER_DEVICE_ID; 943 + } else { 944 + wacom->tool[0] = BTN_TOOL_PEN; 945 + wacom->id[0] = STYLUS_DEVICE_ID; 946 + } 947 + wacom->shared->stylus_in_proximity = true; 948 + } 949 + x = le16_to_cpup((__le16 *)&data[2]); 950 + y = le16_to_cpup((__le16 *)&data[4]); 951 + p = le16_to_cpup((__le16 *)&data[6]); 952 + d = data[8]; 953 + pen = data[1] & 0x01; 954 + btn1 = data[1] & 0x02; 955 + btn2 = data[1] & 0x04; 956 + } 957 + 958 + input_report_key(input, BTN_TOUCH, pen); 959 + input_report_key(input, BTN_STYLUS, btn1); 960 + input_report_key(input, BTN_STYLUS2, btn2); 961 + 962 + input_report_abs(input, ABS_X, x); 963 + input_report_abs(input, ABS_Y, y); 964 + input_report_abs(input, ABS_PRESSURE, p); 965 + input_report_abs(input, ABS_DISTANCE, d); 966 + 967 + if (!prox) { 968 + wacom->id[0] = 0; 969 + wacom->shared->stylus_in_proximity = false; 970 + } 971 + 972 + input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */ 973 + input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */ 974 + 975 + return 1; 976 + } 977 + 978 + static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len) 979 + { 980 + if (len == WACOM_PKGLEN_BBTOUCH) 981 + return wacom_bpt_touch(wacom); 982 + else if (len == WACOM_PKGLEN_BBFUN) 983 + return wacom_bpt_pen(wacom); 984 + 985 + return 0; 986 + } 987 + 860 988 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len) 861 989 { 862 990 bool sync; ··· 1030 902 sync = wacom_tpc_irq(wacom_wac, len); 1031 903 break; 1032 904 905 + case BAMBOO_PT: 906 + sync = wacom_bpt_irq(wacom_wac, len); 907 + break; 908 + 1033 909 default: 1034 910 sync = false; 1035 911 break; ··· 1043 911 input_sync(wacom_wac->input); 1044 912 } 1045 913 1046 - static void wacom_setup_intuos(struct wacom_wac *wacom_wac) 914 + static void wacom_setup_cintiq(struct wacom_wac *wacom_wac) 1047 915 { 1048 916 struct input_dev *input_dev = wacom_wac->input; 1049 917 1050 918 input_set_capability(input_dev, EV_MSC, MSC_SERIAL); 1051 - input_set_capability(input_dev, EV_REL, REL_WHEEL); 1052 - 1053 - __set_bit(BTN_LEFT, input_dev->keybit); 1054 - __set_bit(BTN_RIGHT, input_dev->keybit); 1055 - __set_bit(BTN_MIDDLE, input_dev->keybit); 1056 - __set_bit(BTN_SIDE, input_dev->keybit); 1057 - __set_bit(BTN_EXTRA, input_dev->keybit); 1058 919 1059 920 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit); 1060 921 __set_bit(BTN_TOOL_PEN, input_dev->keybit); 1061 - __set_bit(BTN_TOOL_MOUSE, input_dev->keybit); 1062 922 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit); 1063 923 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit); 1064 924 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit); 1065 - __set_bit(BTN_TOOL_LENS, input_dev->keybit); 1066 925 __set_bit(BTN_STYLUS, input_dev->keybit); 1067 926 __set_bit(BTN_STYLUS2, input_dev->keybit); 1068 927 ··· 1062 939 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0); 1063 940 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0); 1064 941 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0); 942 + } 943 + 944 + static void wacom_setup_intuos(struct wacom_wac *wacom_wac) 945 + { 946 + struct input_dev *input_dev = wacom_wac->input; 947 + 948 + input_set_capability(input_dev, EV_REL, REL_WHEEL); 949 + 950 + wacom_setup_cintiq(wacom_wac); 951 + 952 + __set_bit(BTN_LEFT, input_dev->keybit); 953 + __set_bit(BTN_RIGHT, input_dev->keybit); 954 + __set_bit(BTN_MIDDLE, input_dev->keybit); 955 + __set_bit(BTN_SIDE, input_dev->keybit); 956 + __set_bit(BTN_EXTRA, input_dev->keybit); 957 + __set_bit(BTN_TOOL_MOUSE, input_dev->keybit); 958 + __set_bit(BTN_TOOL_LENS, input_dev->keybit); 959 + 1065 960 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0); 1066 961 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0); 962 + } 963 + 964 + void wacom_setup_device_quirks(struct wacom_features *features) 965 + { 966 + 967 + /* touch device found but size is not defined. use default */ 968 + if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) { 969 + features->x_max = 1023; 970 + features->y_max = 1023; 971 + } 972 + 973 + /* these device have multiple inputs */ 974 + if (features->type == TABLETPC || features->type == TABLETPC2FG || 975 + features->type == BAMBOO_PT) 976 + features->quirks |= WACOM_QUIRK_MULTI_INPUT; 977 + 978 + /* quirks for bamboo touch */ 979 + if (features->type == BAMBOO_PT && 980 + features->device_type == BTN_TOOL_TRIPLETAP) { 981 + features->x_max <<= 5; 982 + features->y_max <<= 5; 983 + features->x_fuzz <<= 5; 984 + features->y_fuzz <<= 5; 985 + features->pressure_max = 256; 986 + features->pressure_fuzz = 16; 987 + features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES; 988 + } 1067 989 } 1068 990 1069 991 void wacom_setup_input_capabilities(struct input_dev *input_dev, ··· 1121 953 1122 954 __set_bit(BTN_TOUCH, input_dev->keybit); 1123 955 1124 - input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0); 1125 - input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0); 1126 - input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0); 956 + input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 957 + features->x_fuzz, 0); 958 + input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 959 + features->y_fuzz, 0); 960 + input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 961 + features->pressure_fuzz, 0); 1127 962 1128 963 __set_bit(ABS_MISC, input_dev->absbit); 1129 964 ··· 1176 1005 __set_bit(BTN_9, input_dev->keybit); 1177 1006 /* fall through */ 1178 1007 1008 + case CINTIQ: 1009 + for (i = 0; i < 8; i++) 1010 + __set_bit(BTN_0 + i, input_dev->keybit); 1011 + __set_bit(BTN_TOOL_FINGER, input_dev->keybit); 1012 + 1013 + input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0); 1014 + input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0); 1015 + input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0); 1016 + wacom_setup_cintiq(wacom_wac); 1017 + break; 1018 + 1179 1019 case INTUOS3: 1180 1020 case INTUOS3L: 1181 - case CINTIQ: 1182 1021 __set_bit(BTN_4, input_dev->keybit); 1183 1022 __set_bit(BTN_5, input_dev->keybit); 1184 1023 __set_bit(BTN_6, input_dev->keybit); ··· 1258 1077 1259 1078 case PENPARTNER: 1260 1079 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit); 1080 + break; 1081 + 1082 + case BAMBOO_PT: 1083 + __clear_bit(ABS_MISC, input_dev->absbit); 1084 + 1085 + if (features->device_type == BTN_TOOL_TRIPLETAP) { 1086 + __set_bit(BTN_LEFT, input_dev->keybit); 1087 + __set_bit(BTN_FORWARD, input_dev->keybit); 1088 + __set_bit(BTN_BACK, input_dev->keybit); 1089 + __set_bit(BTN_RIGHT, input_dev->keybit); 1090 + 1091 + __set_bit(BTN_TOOL_FINGER, input_dev->keybit); 1092 + __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); 1093 + 1094 + input_mt_create_slots(input_dev, 2); 1095 + input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1096 + 0, features->x_max, 1097 + features->x_fuzz, 0); 1098 + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 1099 + 0, features->y_max, 1100 + features->y_fuzz, 0); 1101 + input_set_abs_params(input_dev, ABS_MT_PRESSURE, 1102 + 0, features->pressure_max, 1103 + features->pressure_fuzz, 0); 1104 + input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 1105 + MAX_TRACKING_ID, 0, 0); 1106 + } else if (features->device_type == BTN_TOOL_PEN) { 1107 + __set_bit(BTN_TOOL_RUBBER, input_dev->keybit); 1108 + __set_bit(BTN_TOOL_PEN, input_dev->keybit); 1109 + __set_bit(BTN_STYLUS, input_dev->keybit); 1110 + __set_bit(BTN_STYLUS2, input_dev->keybit); 1111 + } 1261 1112 break; 1262 1113 } 1263 1114 } ··· 1428 1215 { "Wacom ISDv4 E3", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255, 0, TABLETPC2FG }; 1429 1216 static const struct wacom_features wacom_features_0x47 = 1430 1217 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS }; 1218 + static struct wacom_features wacom_features_0xD0 = 1219 + { "Wacom Bamboo 2FG", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023, 63, BAMBOO_PT }; 1220 + static struct wacom_features wacom_features_0xD1 = 1221 + { "Wacom Bamboo 2FG 4x5", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023, 63, BAMBOO_PT }; 1222 + static struct wacom_features wacom_features_0xD2 = 1223 + { "Wacom Bamboo Craft", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023, 63, BAMBOO_PT }; 1224 + static struct wacom_features wacom_features_0xD3 = 1225 + { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 1023, 63, BAMBOO_PT }; 1431 1226 1432 1227 #define USB_DEVICE_WACOM(prod) \ 1433 1228 USB_DEVICE(USB_VENDOR_ID_WACOM, prod), \ ··· 1500 1279 { USB_DEVICE_WACOM(0xC6) }, 1501 1280 { USB_DEVICE_WACOM(0xC7) }, 1502 1281 { USB_DEVICE_WACOM(0xCE) }, 1282 + { USB_DEVICE_WACOM(0xD0) }, 1283 + { USB_DEVICE_WACOM(0xD1) }, 1284 + { USB_DEVICE_WACOM(0xD2) }, 1285 + { USB_DEVICE_WACOM(0xD3) }, 1503 1286 { USB_DEVICE_WACOM(0xF0) }, 1504 1287 { USB_DEVICE_WACOM(0xCC) }, 1505 1288 { USB_DEVICE_WACOM(0x90) },
+15
drivers/input/tablet/wacom_wac.h
··· 21 21 #define WACOM_PKGLEN_INTUOS 10 22 22 #define WACOM_PKGLEN_TPC1FG 5 23 23 #define WACOM_PKGLEN_TPC2FG 14 24 + #define WACOM_PKGLEN_BBTOUCH 20 24 25 25 26 /* device IDs */ 26 27 #define STYLUS_DEVICE_ID 0x02 ··· 38 37 #define WACOM_REPORT_TPC1FG 6 39 38 #define WACOM_REPORT_TPC2FG 13 40 39 40 + /* device quirks */ 41 + #define WACOM_QUIRK_MULTI_INPUT 0x0001 42 + #define WACOM_QUIRK_BBTOUCH_LOWRES 0x0002 43 + 44 + /* largest reported tracking id */ 45 + #define MAX_TRACKING_ID 0xfff 46 + 41 47 enum { 42 48 PENPARTNER = 0, 43 49 GRAPHIRE, ··· 52 44 PTU, 53 45 PL, 54 46 DTU, 47 + BAMBOO_PT, 55 48 INTUOS, 56 49 INTUOS3S, 57 50 INTUOS3, ··· 82 73 int y_phy; 83 74 unsigned char unit; 84 75 unsigned char unitExpo; 76 + int x_fuzz; 77 + int y_fuzz; 78 + int pressure_fuzz; 79 + int distance_fuzz; 80 + unsigned quirks; 85 81 }; 86 82 87 83 struct wacom_shared { ··· 100 86 int id[3]; 101 87 __u32 serial[2]; 102 88 int last_finger; 89 + int trk_id; 103 90 struct wacom_features features; 104 91 struct wacom_shared *shared; 105 92 struct input_dev *input;
+34
drivers/input/touchscreen/Kconfig
··· 98 98 To compile this driver as a module, choose M here: the 99 99 module will be called h3600_ts_input. 100 100 101 + config TOUCHSCREEN_BU21013 102 + tristate "BU21013 based touch panel controllers" 103 + depends on I2C 104 + help 105 + Say Y here if you have a bu21013 touchscreen connected to 106 + your system. 107 + 108 + If unsure, say N. 109 + 110 + To compile this driver as a module, choose M here: the 111 + module will be called bu21013_ts. 112 + 101 113 config TOUCHSCREEN_CY8CTMG110 102 114 tristate "cy8ctmg110 touchscreen" 103 115 depends on I2C ··· 226 214 To compile this driver as a module, choose M here: the 227 215 module will be called wacom_w8001. 228 216 217 + config TOUCHSCREEN_LPC32XX 218 + tristate "LPC32XX touchscreen controller" 219 + depends on ARCH_LPC32XX 220 + help 221 + Say Y here if you have a LPC32XX device and want 222 + to support the built-in touchscreen. 223 + 224 + To compile this driver as a module, choose M here: the 225 + module will be called lpc32xx_ts. 226 + 229 227 config TOUCHSCREEN_MCS5000 230 228 tristate "MELFAS MCS-5000 touchscreen" 231 229 depends on I2C ··· 271 249 272 250 To compile this driver as a module, choose M here: the 273 251 module will be called inexio. 252 + 253 + config TOUCHSCREEN_INTEL_MID 254 + tristate "Intel MID platform resistive touchscreen" 255 + depends on INTEL_SCU_IPC 256 + help 257 + Say Y here if you have a Intel MID based touchscreen in 258 + your system. 259 + 260 + If unsure, say N. 261 + 262 + To compile this driver as a module, choose M here: the 263 + module will be called intel_mid_touch. 274 264 275 265 config TOUCHSCREEN_MK712 276 266 tristate "ICS MicroClock MK712 touchscreen"
+3
drivers/input/touchscreen/Makefile
··· 14 14 obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 15 15 obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o 16 16 obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 17 + obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o 17 18 obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o 18 19 obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o 19 20 obj-$(CONFIG_TOUCHSCREEN_DYNAPRO) += dynapro.o ··· 24 23 obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o 25 24 obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o 26 25 obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o 26 + obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o 27 + obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o 27 28 obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o 28 29 obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o 29 30 obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
+81 -63
drivers/input/touchscreen/ad7877.c
··· 191 191 struct spi_message msg; 192 192 193 193 struct mutex mutex; 194 - unsigned disabled:1; /* P: mutex */ 195 - unsigned gpio3:1; /* P: mutex */ 196 - unsigned gpio4:1; /* P: mutex */ 194 + bool disabled; /* P: mutex */ 195 + bool gpio3; /* P: mutex */ 196 + bool gpio4; /* P: mutex */ 197 197 198 198 spinlock_t lock; 199 199 struct timer_list timer; /* P: lock */ 200 - unsigned pending:1; /* P: lock */ 201 200 202 201 /* 203 202 * DMA (thus cache coherency maintenance) requires the ··· 205 206 u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned; 206 207 }; 207 208 208 - static int gpio3; 209 - module_param(gpio3, int, 0); 209 + static bool gpio3; 210 + module_param(gpio3, bool, 0); 210 211 MODULE_PARM_DESC(gpio3, "If gpio3 is set to 1 AUX3 acts as GPIO3"); 211 212 212 213 /* ··· 229 230 AD7877_READADD(reg)); 230 231 req->xfer[0].tx_buf = &req->command; 231 232 req->xfer[0].len = 2; 233 + req->xfer[0].cs_change = 1; 232 234 233 235 req->xfer[1].rx_buf = &req->sample; 234 236 req->xfer[1].len = 2; ··· 295 295 296 296 req->xfer[0].tx_buf = &req->reset; 297 297 req->xfer[0].len = 2; 298 + req->xfer[0].cs_change = 1; 298 299 299 300 req->xfer[1].tx_buf = &req->ref_on; 300 301 req->xfer[1].len = 2; 301 302 req->xfer[1].delay_usecs = ts->vref_delay_usecs; 303 + req->xfer[1].cs_change = 1; 302 304 303 305 req->xfer[2].tx_buf = &req->command; 304 306 req->xfer[2].len = 2; 305 307 req->xfer[2].delay_usecs = ts->vref_delay_usecs; 308 + req->xfer[2].cs_change = 1; 306 309 307 310 req->xfer[3].rx_buf = &req->sample; 308 311 req->xfer[3].len = 2; 312 + req->xfer[3].cs_change = 1; 309 313 310 314 req->xfer[4].tx_buf = &ts->cmd_crtl2; /*REF OFF*/ 311 315 req->xfer[4].len = 2; 316 + req->xfer[4].cs_change = 1; 312 317 313 318 req->xfer[5].tx_buf = &ts->cmd_crtl1; /*DEFAULT*/ 314 319 req->xfer[5].len = 2; ··· 332 327 return status ? : sample; 333 328 } 334 329 335 - static void ad7877_rx(struct ad7877 *ts) 330 + static int ad7877_process_data(struct ad7877 *ts) 336 331 { 337 332 struct input_dev *input_dev = ts->input; 338 333 unsigned Rt; ··· 359 354 Rt /= z1; 360 355 Rt = (Rt + 2047) >> 12; 361 356 357 + /* 358 + * Sample found inconsistent, pressure is beyond 359 + * the maximum. Don't report it to user space. 360 + */ 361 + if (Rt > ts->pressure_max) 362 + return -EINVAL; 363 + 364 + if (!timer_pending(&ts->timer)) 365 + input_report_key(input_dev, BTN_TOUCH, 1); 366 + 362 367 input_report_abs(input_dev, ABS_X, x); 363 368 input_report_abs(input_dev, ABS_Y, y); 364 369 input_report_abs(input_dev, ABS_PRESSURE, Rt); 365 370 input_sync(input_dev); 371 + 372 + return 0; 366 373 } 374 + 375 + return -EINVAL; 367 376 } 368 377 369 378 static inline void ad7877_ts_event_release(struct ad7877 *ts) ··· 385 366 struct input_dev *input_dev = ts->input; 386 367 387 368 input_report_abs(input_dev, ABS_PRESSURE, 0); 369 + input_report_key(input_dev, BTN_TOUCH, 0); 388 370 input_sync(input_dev); 389 371 } 390 372 391 373 static void ad7877_timer(unsigned long handle) 392 374 { 393 375 struct ad7877 *ts = (void *)handle; 376 + unsigned long flags; 394 377 378 + spin_lock_irqsave(&ts->lock, flags); 395 379 ad7877_ts_event_release(ts); 380 + spin_unlock_irqrestore(&ts->lock, flags); 396 381 } 397 382 398 383 static irqreturn_t ad7877_irq(int irq, void *handle) 399 384 { 400 385 struct ad7877 *ts = handle; 401 386 unsigned long flags; 402 - int status; 387 + int error; 403 388 404 - /* 405 - * The repeated conversion sequencer controlled by TMR kicked off 406 - * too fast. We ignore the last and process the sample sequence 407 - * currently in the queue. It can't be older than 9.4ms, and we 408 - * need to avoid that ts->msg doesn't get issued twice while in work. 409 - */ 389 + error = spi_sync(ts->spi, &ts->msg); 390 + if (error) { 391 + dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); 392 + goto out; 393 + } 410 394 411 395 spin_lock_irqsave(&ts->lock, flags); 412 - if (!ts->pending) { 413 - ts->pending = 1; 414 - 415 - status = spi_async(ts->spi, &ts->msg); 416 - if (status) 417 - dev_err(&ts->spi->dev, "spi_sync --> %d\n", status); 418 - } 396 + error = ad7877_process_data(ts); 397 + if (!error) 398 + mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); 419 399 spin_unlock_irqrestore(&ts->lock, flags); 420 400 401 + out: 421 402 return IRQ_HANDLED; 422 - } 423 - 424 - static void ad7877_callback(void *_ts) 425 - { 426 - struct ad7877 *ts = _ts; 427 - 428 - spin_lock_irq(&ts->lock); 429 - 430 - ad7877_rx(ts); 431 - ts->pending = 0; 432 - mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); 433 - 434 - spin_unlock_irq(&ts->lock); 435 403 } 436 404 437 405 static void ad7877_disable(struct ad7877 *ts) ··· 426 420 mutex_lock(&ts->mutex); 427 421 428 422 if (!ts->disabled) { 429 - ts->disabled = 1; 423 + ts->disabled = true; 430 424 disable_irq(ts->spi->irq); 431 - 432 - /* Wait for spi_async callback */ 433 - while (ts->pending) 434 - msleep(1); 435 425 436 426 if (del_timer_sync(&ts->timer)) 437 427 ad7877_ts_event_release(ts); 438 428 } 439 429 440 - /* we know the chip's in lowpower mode since we always 430 + /* 431 + * We know the chip's in lowpower mode since we always 441 432 * leave it that way after every request 442 433 */ 443 434 ··· 446 443 mutex_lock(&ts->mutex); 447 444 448 445 if (ts->disabled) { 449 - ts->disabled = 0; 446 + ts->disabled = false; 450 447 enable_irq(ts->spi->irq); 451 448 } 452 449 ··· 456 453 #define SHOW(name) static ssize_t \ 457 454 name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ 458 455 { \ 459 - struct ad7877 *ts = dev_get_drvdata(dev); \ 456 + struct ad7877 *ts = dev_get_drvdata(dev); \ 460 457 ssize_t v = ad7877_read_adc(ts->spi, \ 461 458 AD7877_READ_CHAN(name)); \ 462 459 if (v < 0) \ ··· 476 473 static ssize_t ad7877_disable_show(struct device *dev, 477 474 struct device_attribute *attr, char *buf) 478 475 { 479 - struct ad7877 *ts = dev_get_drvdata(dev); 476 + struct ad7877 *ts = dev_get_drvdata(dev); 480 477 481 478 return sprintf(buf, "%u\n", ts->disabled); 482 479 } ··· 506 503 static ssize_t ad7877_dac_show(struct device *dev, 507 504 struct device_attribute *attr, char *buf) 508 505 { 509 - struct ad7877 *ts = dev_get_drvdata(dev); 506 + struct ad7877 *ts = dev_get_drvdata(dev); 510 507 511 508 return sprintf(buf, "%u\n", ts->dac); 512 509 } ··· 536 533 static ssize_t ad7877_gpio3_show(struct device *dev, 537 534 struct device_attribute *attr, char *buf) 538 535 { 539 - struct ad7877 *ts = dev_get_drvdata(dev); 536 + struct ad7877 *ts = dev_get_drvdata(dev); 540 537 541 538 return sprintf(buf, "%u\n", ts->gpio3); 542 539 } ··· 567 564 static ssize_t ad7877_gpio4_show(struct device *dev, 568 565 struct device_attribute *attr, char *buf) 569 566 { 570 - struct ad7877 *ts = dev_get_drvdata(dev); 567 + struct ad7877 *ts = dev_get_drvdata(dev); 571 568 572 569 return sprintf(buf, "%u\n", ts->gpio4); 573 570 } ··· 600 597 &dev_attr_temp2.attr, 601 598 &dev_attr_aux1.attr, 602 599 &dev_attr_aux2.attr, 600 + &dev_attr_aux3.attr, 603 601 &dev_attr_bat1.attr, 604 602 &dev_attr_bat2.attr, 605 603 &dev_attr_disable.attr, 606 604 &dev_attr_dac.attr, 605 + &dev_attr_gpio3.attr, 607 606 &dev_attr_gpio4.attr, 608 607 NULL 609 608 }; 610 609 610 + static mode_t ad7877_attr_is_visible(struct kobject *kobj, 611 + struct attribute *attr, int n) 612 + { 613 + mode_t mode = attr->mode; 614 + 615 + if (attr == &dev_attr_aux3.attr) { 616 + if (gpio3) 617 + mode = 0; 618 + } else if (attr == &dev_attr_gpio3.attr) { 619 + if (!gpio3) 620 + mode = 0; 621 + } 622 + 623 + return mode; 624 + } 625 + 611 626 static const struct attribute_group ad7877_attr_group = { 612 - .attrs = ad7877_attributes, 627 + .is_visible = ad7877_attr_is_visible, 628 + .attrs = ad7877_attributes, 613 629 }; 614 630 615 631 static void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts) ··· 657 635 658 636 spi_message_init(m); 659 637 660 - m->complete = ad7877_callback; 661 638 m->context = ts; 662 639 663 640 ts->xfer[0].tx_buf = &ts->cmd_crtl1; 664 641 ts->xfer[0].len = 2; 642 + ts->xfer[0].cs_change = 1; 665 643 666 644 spi_message_add_tail(&ts->xfer[0], m); 667 645 668 646 ts->xfer[1].tx_buf = &ts->cmd_dummy; /* Send ZERO */ 669 647 ts->xfer[1].len = 2; 648 + ts->xfer[1].cs_change = 1; 670 649 671 650 spi_message_add_tail(&ts->xfer[1], m); 672 651 673 - for (i = 0; i < 11; i++) { 652 + for (i = 0; i < AD7877_NR_SENSE; i++) { 674 653 ts->xfer[i + 2].rx_buf = &ts->conversion_data[AD7877_SEQ_YPOS + i]; 675 654 ts->xfer[i + 2].len = 2; 655 + if (i < (AD7877_NR_SENSE - 1)) 656 + ts->xfer[i + 2].cs_change = 1; 676 657 spi_message_add_tail(&ts->xfer[i + 2], m); 677 658 } 678 659 } ··· 743 718 input_dev->phys = ts->phys; 744 719 input_dev->dev.parent = &spi->dev; 745 720 721 + __set_bit(EV_KEY, input_dev->evbit); 722 + __set_bit(BTN_TOUCH, input_dev->keybit); 746 723 __set_bit(EV_ABS, input_dev->evbit); 747 724 __set_bit(ABS_X, input_dev->absbit); 748 725 __set_bit(ABS_Y, input_dev->absbit); ··· 779 752 780 753 /* Request AD7877 /DAV GPIO interrupt */ 781 754 782 - err = request_irq(spi->irq, ad7877_irq, IRQF_TRIGGER_FALLING, 783 - spi->dev.driver->name, ts); 755 + err = request_threaded_irq(spi->irq, NULL, ad7877_irq, 756 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 757 + spi->dev.driver->name, ts); 784 758 if (err) { 785 759 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 786 760 goto err_free_mem; ··· 791 763 if (err) 792 764 goto err_free_irq; 793 765 794 - err = device_create_file(&spi->dev, 795 - gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); 766 + err = input_register_device(input_dev); 796 767 if (err) 797 768 goto err_remove_attr_group; 798 769 799 - err = input_register_device(input_dev); 800 - if (err) 801 - goto err_remove_attr; 802 - 803 770 return 0; 804 771 805 - err_remove_attr: 806 - device_remove_file(&spi->dev, 807 - gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); 808 772 err_remove_attr_group: 809 773 sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); 810 774 err_free_irq: ··· 810 790 811 791 static int __devexit ad7877_remove(struct spi_device *spi) 812 792 { 813 - struct ad7877 *ts = dev_get_drvdata(&spi->dev); 793 + struct ad7877 *ts = dev_get_drvdata(&spi->dev); 814 794 815 795 sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); 816 - device_remove_file(&spi->dev, 817 - gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); 818 796 819 797 ad7877_disable(ts); 820 798 free_irq(ts->spi->irq, ts);
+465 -439
drivers/input/touchscreen/ads7846.c
··· 17 17 * it under the terms of the GNU General Public License version 2 as 18 18 * published by the Free Software Foundation. 19 19 */ 20 + #include <linux/types.h> 20 21 #include <linux/hwmon.h> 21 22 #include <linux/init.h> 22 23 #include <linux/err.h> 24 + #include <linux/sched.h> 23 25 #include <linux/delay.h> 24 26 #include <linux/input.h> 25 27 #include <linux/interrupt.h> ··· 54 52 * files. 55 53 */ 56 54 57 - #define TS_POLL_DELAY (1 * 1000000) /* ns delay before the first sample */ 58 - #define TS_POLL_PERIOD (5 * 1000000) /* ns delay between samples */ 55 + #define TS_POLL_DELAY 1 /* ms delay before the first sample */ 56 + #define TS_POLL_PERIOD 5 /* ms delay between samples */ 59 57 60 58 /* this driver doesn't aim at the peak continuous sample rate */ 61 59 #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */) 62 60 63 61 struct ts_event { 64 - /* For portability, we can't read 12 bit values using SPI (which 65 - * would make the controller deliver them as native byteorder u16 62 + /* 63 + * For portability, we can't read 12 bit values using SPI (which 64 + * would make the controller deliver them as native byte order u16 66 65 * with msbs zeroed). Instead, we read them as two 8-bit values, 67 66 * *** WHICH NEED BYTESWAPPING *** and range adjustment. 68 67 */ 69 68 u16 x; 70 69 u16 y; 71 70 u16 z1, z2; 72 - int ignore; 71 + bool ignore; 73 72 u8 x_buf[3]; 74 73 u8 y_buf[3]; 75 74 }; ··· 113 110 114 111 struct spi_transfer xfer[18]; 115 112 struct spi_message msg[5]; 116 - struct spi_message *last_msg; 117 - int msg_idx; 113 + int msg_count; 114 + wait_queue_head_t wait; 115 + 116 + bool pendown; 117 + 118 118 int read_cnt; 119 119 int read_rep; 120 120 int last_read; ··· 128 122 129 123 u16 penirq_recheck_delay_usecs; 130 124 131 - spinlock_t lock; 132 - struct hrtimer timer; 133 - unsigned pendown:1; /* P: lock */ 134 - unsigned pending:1; /* P: lock */ 135 - // FIXME remove "irq_disabled" 136 - unsigned irq_disabled:1; /* P: lock */ 137 - unsigned disabled:1; 138 - unsigned is_suspended:1; 125 + struct mutex lock; 126 + bool stopped; /* P: lock */ 127 + bool disabled; /* P: lock */ 128 + bool suspended; /* P: lock */ 139 129 140 130 int (*filter)(void *data, int data_idx, int *val); 141 131 void *filter_data; ··· 167 165 #define ADS_12_BIT (0 << 3) 168 166 #define ADS_SER (1 << 2) /* non-differential */ 169 167 #define ADS_DFR (0 << 2) /* differential */ 170 - #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */ 168 + #define ADS_PD10_PDOWN (0 << 0) /* low power mode + penirq */ 171 169 #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */ 172 170 #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */ 173 171 #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */ ··· 195 193 #define REF_ON (READ_12BIT_DFR(x, 1, 1)) 196 194 #define REF_OFF (READ_12BIT_DFR(y, 0, 0)) 197 195 196 + /* Must be called with ts->lock held */ 197 + static void ads7846_stop(struct ads7846 *ts) 198 + { 199 + if (!ts->disabled && !ts->suspended) { 200 + /* Signal IRQ thread to stop polling and disable the handler. */ 201 + ts->stopped = true; 202 + mb(); 203 + wake_up(&ts->wait); 204 + disable_irq(ts->spi->irq); 205 + } 206 + } 207 + 208 + /* Must be called with ts->lock held */ 209 + static void ads7846_restart(struct ads7846 *ts) 210 + { 211 + if (!ts->disabled && !ts->suspended) { 212 + /* Tell IRQ thread that it may poll the device. */ 213 + ts->stopped = false; 214 + mb(); 215 + enable_irq(ts->spi->irq); 216 + } 217 + } 218 + 219 + /* Must be called with ts->lock held */ 220 + static void __ads7846_disable(struct ads7846 *ts) 221 + { 222 + ads7846_stop(ts); 223 + regulator_disable(ts->reg); 224 + 225 + /* 226 + * We know the chip's in low power mode since we always 227 + * leave it that way after every request 228 + */ 229 + } 230 + 231 + /* Must be called with ts->lock held */ 232 + static void __ads7846_enable(struct ads7846 *ts) 233 + { 234 + regulator_enable(ts->reg); 235 + ads7846_restart(ts); 236 + } 237 + 238 + static void ads7846_disable(struct ads7846 *ts) 239 + { 240 + mutex_lock(&ts->lock); 241 + 242 + if (!ts->disabled) { 243 + 244 + if (!ts->suspended) 245 + __ads7846_disable(ts); 246 + 247 + ts->disabled = true; 248 + } 249 + 250 + mutex_unlock(&ts->lock); 251 + } 252 + 253 + static void ads7846_enable(struct ads7846 *ts) 254 + { 255 + mutex_lock(&ts->lock); 256 + 257 + if (ts->disabled) { 258 + 259 + ts->disabled = false; 260 + 261 + if (!ts->suspended) 262 + __ads7846_enable(ts); 263 + } 264 + 265 + mutex_unlock(&ts->lock); 266 + } 267 + 198 268 /*--------------------------------------------------------------------------*/ 199 269 200 270 /* ··· 293 219 struct spi_transfer xfer[2]; 294 220 }; 295 221 296 - static void ads7846_enable(struct ads7846 *ts); 297 - static void ads7846_disable(struct ads7846 *ts); 298 - 299 - static int device_suspended(struct device *dev) 300 - { 301 - struct ads7846 *ts = dev_get_drvdata(dev); 302 - return ts->is_suspended || ts->disabled; 303 - } 304 - 305 222 static int ads7846_read12_ser(struct device *dev, unsigned command) 306 223 { 307 - struct spi_device *spi = to_spi_device(dev); 308 - struct ads7846 *ts = dev_get_drvdata(dev); 309 - struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); 310 - int status; 311 - int use_internal; 224 + struct spi_device *spi = to_spi_device(dev); 225 + struct ads7846 *ts = dev_get_drvdata(dev); 226 + struct ser_req *req; 227 + int status; 228 + int use_internal; 312 229 230 + req = kzalloc(sizeof *req, GFP_KERNEL); 313 231 if (!req) 314 232 return -ENOMEM; 315 233 ··· 348 282 CS_CHANGE(req->xfer[5]); 349 283 spi_message_add_tail(&req->xfer[5], &req->msg); 350 284 351 - ts->irq_disabled = 1; 352 - disable_irq(spi->irq); 285 + mutex_lock(&ts->lock); 286 + ads7846_stop(ts); 353 287 status = spi_sync(spi, &req->msg); 354 - ts->irq_disabled = 0; 355 - enable_irq(spi->irq); 288 + ads7846_restart(ts); 289 + mutex_unlock(&ts->lock); 356 290 357 291 if (status == 0) { 358 292 /* on-wire is a must-ignore bit, a BE12 value, then padding */ ··· 367 301 368 302 static int ads7845_read12_ser(struct device *dev, unsigned command) 369 303 { 370 - struct spi_device *spi = to_spi_device(dev); 371 - struct ads7846 *ts = dev_get_drvdata(dev); 372 - struct ads7845_ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); 373 - int status; 304 + struct spi_device *spi = to_spi_device(dev); 305 + struct ads7846 *ts = dev_get_drvdata(dev); 306 + struct ads7845_ser_req *req; 307 + int status; 374 308 309 + req = kzalloc(sizeof *req, GFP_KERNEL); 375 310 if (!req) 376 311 return -ENOMEM; 377 312 ··· 384 317 req->xfer[0].len = 3; 385 318 spi_message_add_tail(&req->xfer[0], &req->msg); 386 319 387 - ts->irq_disabled = 1; 388 - disable_irq(spi->irq); 320 + mutex_lock(&ts->lock); 321 + ads7846_stop(ts); 389 322 status = spi_sync(spi, &req->msg); 390 - ts->irq_disabled = 0; 391 - enable_irq(spi->irq); 323 + ads7846_restart(ts); 324 + mutex_unlock(&ts->lock); 392 325 393 326 if (status == 0) { 394 327 /* BE12 value, then padding */ ··· 441 374 /* external resistors may scale vAUX into 0..vREF */ 442 375 retval *= ts->vref_mv; 443 376 retval = retval >> 12; 377 + 444 378 return retval; 445 379 } 446 380 ··· 452 384 /* ads7846 has a resistor ladder to scale this signal down */ 453 385 if (ts->model == 7846) 454 386 retval *= 4; 387 + 455 388 return retval; 456 389 } 457 390 458 391 SHOW(in0_input, vaux, vaux_adjust) 459 392 SHOW(in1_input, vbatt, vbatt_adjust) 460 - 461 393 462 394 static struct attribute *ads7846_attributes[] = { 463 395 &dev_attr_temp0.attr, ··· 566 498 } 567 499 #endif 568 500 569 - static int is_pen_down(struct device *dev) 570 - { 571 - struct ads7846 *ts = dev_get_drvdata(dev); 572 - 573 - return ts->pendown; 574 - } 575 - 576 501 static ssize_t ads7846_pen_down_show(struct device *dev, 577 502 struct device_attribute *attr, char *buf) 578 503 { 579 - return sprintf(buf, "%u\n", is_pen_down(dev)); 504 + struct ads7846 *ts = dev_get_drvdata(dev); 505 + 506 + return sprintf(buf, "%u\n", ts->pendown); 580 507 } 581 508 582 509 static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL); ··· 579 516 static ssize_t ads7846_disable_show(struct device *dev, 580 517 struct device_attribute *attr, char *buf) 581 518 { 582 - struct ads7846 *ts = dev_get_drvdata(dev); 519 + struct ads7846 *ts = dev_get_drvdata(dev); 583 520 584 521 return sprintf(buf, "%u\n", ts->disabled); 585 522 } ··· 594 531 if (strict_strtoul(buf, 10, &i)) 595 532 return -EINVAL; 596 533 597 - spin_lock_irq(&ts->lock); 598 - 599 534 if (i) 600 535 ads7846_disable(ts); 601 536 else 602 537 ads7846_enable(ts); 603 - 604 - spin_unlock_irq(&ts->lock); 605 538 606 539 return count; 607 540 } ··· 628 569 { 629 570 } 630 571 631 - /* 632 - * PENIRQ only kicks the timer. The timer only reissues the SPI transfer, 633 - * to retrieve touchscreen status. 634 - * 635 - * The SPI transfer completion callback does the real work. It reports 636 - * touchscreen events and reactivates the timer (or IRQ) as appropriate. 637 - */ 638 - 639 - static void ads7846_rx(void *ads) 572 + static int ads7846_debounce_filter(void *ads, int data_idx, int *val) 640 573 { 641 - struct ads7846 *ts = ads; 642 - struct ads7846_packet *packet = ts->packet; 643 - unsigned Rt; 644 - u16 x, y, z1, z2; 574 + struct ads7846 *ts = ads; 645 575 646 - /* ads7846_rx_val() did in-place conversion (including byteswap) from 647 - * on-the-wire format as part of debouncing to get stable readings. 576 + if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { 577 + /* Start over collecting consistent readings. */ 578 + ts->read_rep = 0; 579 + /* 580 + * Repeat it, if this was the first read or the read 581 + * wasn't consistent enough. 582 + */ 583 + if (ts->read_cnt < ts->debounce_max) { 584 + ts->last_read = *val; 585 + ts->read_cnt++; 586 + return ADS7846_FILTER_REPEAT; 587 + } else { 588 + /* 589 + * Maximum number of debouncing reached and still 590 + * not enough number of consistent readings. Abort 591 + * the whole sample, repeat it in the next sampling 592 + * period. 593 + */ 594 + ts->read_cnt = 0; 595 + return ADS7846_FILTER_IGNORE; 596 + } 597 + } else { 598 + if (++ts->read_rep > ts->debounce_rep) { 599 + /* 600 + * Got a good reading for this coordinate, 601 + * go for the next one. 602 + */ 603 + ts->read_cnt = 0; 604 + ts->read_rep = 0; 605 + return ADS7846_FILTER_OK; 606 + } else { 607 + /* Read more values that are consistent. */ 608 + ts->read_cnt++; 609 + return ADS7846_FILTER_REPEAT; 610 + } 611 + } 612 + } 613 + 614 + static int ads7846_no_filter(void *ads, int data_idx, int *val) 615 + { 616 + return ADS7846_FILTER_OK; 617 + } 618 + 619 + static int ads7846_get_value(struct ads7846 *ts, struct spi_message *m) 620 + { 621 + struct spi_transfer *t = 622 + list_entry(m->transfers.prev, struct spi_transfer, transfer_list); 623 + 624 + if (ts->model == 7845) { 625 + return be16_to_cpup((__be16 *)&(((char*)t->rx_buf)[1])) >> 3; 626 + } else { 627 + /* 628 + * adjust: on-wire is a must-ignore bit, a BE12 value, then 629 + * padding; built from two 8 bit values written msb-first. 630 + */ 631 + return be16_to_cpup((__be16 *)t->rx_buf) >> 3; 632 + } 633 + } 634 + 635 + static void ads7846_update_value(struct spi_message *m, int val) 636 + { 637 + struct spi_transfer *t = 638 + list_entry(m->transfers.prev, struct spi_transfer, transfer_list); 639 + 640 + *(u16 *)t->rx_buf = val; 641 + } 642 + 643 + static void ads7846_read_state(struct ads7846 *ts) 644 + { 645 + struct ads7846_packet *packet = ts->packet; 646 + struct spi_message *m; 647 + int msg_idx = 0; 648 + int val; 649 + int action; 650 + int error; 651 + 652 + while (msg_idx < ts->msg_count) { 653 + 654 + ts->wait_for_sync(); 655 + 656 + m = &ts->msg[msg_idx]; 657 + error = spi_sync(ts->spi, m); 658 + if (error) { 659 + dev_err(&ts->spi->dev, "spi_async --> %d\n", error); 660 + packet->tc.ignore = true; 661 + return; 662 + } 663 + 664 + /* 665 + * Last message is power down request, no need to convert 666 + * or filter the value. 667 + */ 668 + if (msg_idx < ts->msg_count - 1) { 669 + 670 + val = ads7846_get_value(ts, m); 671 + 672 + action = ts->filter(ts->filter_data, msg_idx, &val); 673 + switch (action) { 674 + case ADS7846_FILTER_REPEAT: 675 + continue; 676 + 677 + case ADS7846_FILTER_IGNORE: 678 + packet->tc.ignore = true; 679 + msg_idx = ts->msg_count - 1; 680 + continue; 681 + 682 + case ADS7846_FILTER_OK: 683 + ads7846_update_value(m, val); 684 + packet->tc.ignore = false; 685 + msg_idx++; 686 + break; 687 + 688 + default: 689 + BUG(); 690 + } 691 + } else { 692 + msg_idx++; 693 + } 694 + } 695 + } 696 + 697 + static void ads7846_report_state(struct ads7846 *ts) 698 + { 699 + struct ads7846_packet *packet = ts->packet; 700 + unsigned int Rt; 701 + u16 x, y, z1, z2; 702 + 703 + /* 704 + * ads7846_get_value() does in-place conversion (including byte swap) 705 + * from on-the-wire format as part of debouncing to get stable 706 + * readings. 648 707 */ 649 708 if (ts->model == 7845) { 650 709 x = *(u16 *)packet->tc.x_buf; ··· 800 623 Rt = 0; 801 624 } 802 625 803 - /* Sample found inconsistent by debouncing or pressure is beyond 626 + /* 627 + * Sample found inconsistent by debouncing or pressure is beyond 804 628 * the maximum. Don't report it to user space, repeat at least 805 629 * once more the measurement 806 630 */ 807 631 if (packet->tc.ignore || Rt > ts->pressure_max) { 808 632 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", 809 633 packet->tc.ignore, Rt); 810 - hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), 811 - HRTIMER_MODE_REL); 812 634 return; 813 635 } 814 636 815 - /* Maybe check the pendown state before reporting. This discards 637 + /* 638 + * Maybe check the pendown state before reporting. This discards 816 639 * false readings when the pen is lifted. 817 640 */ 818 641 if (ts->penirq_recheck_delay_usecs) { ··· 821 644 Rt = 0; 822 645 } 823 646 824 - /* NOTE: We can't rely on the pressure to determine the pen down 825 - * state, even this controller has a pressure sensor. The pressure 647 + /* 648 + * NOTE: We can't rely on the pressure to determine the pen down 649 + * state, even this controller has a pressure sensor. The pressure 826 650 * value can fluctuate for quite a while after lifting the pen and 827 651 * in some cases may not even settle at the expected value. 828 652 * ··· 833 655 if (Rt) { 834 656 struct input_dev *input = ts->input; 835 657 836 - if (!ts->pendown) { 837 - input_report_key(input, BTN_TOUCH, 1); 838 - ts->pendown = 1; 839 - dev_vdbg(&ts->spi->dev, "DOWN\n"); 840 - } 841 - 842 658 if (ts->swap_xy) 843 659 swap(x, y); 660 + 661 + if (!ts->pendown) { 662 + input_report_key(input, BTN_TOUCH, 1); 663 + ts->pendown = true; 664 + dev_vdbg(&ts->spi->dev, "DOWN\n"); 665 + } 844 666 845 667 input_report_abs(input, ABS_X, x); 846 668 input_report_abs(input, ABS_Y, y); ··· 849 671 input_sync(input); 850 672 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); 851 673 } 852 - 853 - hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), 854 - HRTIMER_MODE_REL); 855 674 } 856 675 857 - static int ads7846_debounce(void *ads, int data_idx, int *val) 676 + static irqreturn_t ads7846_hard_irq(int irq, void *handle) 858 677 { 859 - struct ads7846 *ts = ads; 678 + struct ads7846 *ts = handle; 860 679 861 - if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { 862 - /* Start over collecting consistent readings. */ 863 - ts->read_rep = 0; 864 - /* Repeat it, if this was the first read or the read 865 - * wasn't consistent enough. */ 866 - if (ts->read_cnt < ts->debounce_max) { 867 - ts->last_read = *val; 868 - ts->read_cnt++; 869 - return ADS7846_FILTER_REPEAT; 870 - } else { 871 - /* Maximum number of debouncing reached and still 872 - * not enough number of consistent readings. Abort 873 - * the whole sample, repeat it in the next sampling 874 - * period. 875 - */ 876 - ts->read_cnt = 0; 877 - return ADS7846_FILTER_IGNORE; 878 - } 879 - } else { 880 - if (++ts->read_rep > ts->debounce_rep) { 881 - /* Got a good reading for this coordinate, 882 - * go for the next one. */ 883 - ts->read_cnt = 0; 884 - ts->read_rep = 0; 885 - return ADS7846_FILTER_OK; 886 - } else { 887 - /* Read more values that are consistent. */ 888 - ts->read_cnt++; 889 - return ADS7846_FILTER_REPEAT; 890 - } 891 - } 680 + return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; 892 681 } 893 682 894 - static int ads7846_no_filter(void *ads, int data_idx, int *val) 895 - { 896 - return ADS7846_FILTER_OK; 897 - } 898 - 899 - static void ads7846_rx_val(void *ads) 900 - { 901 - struct ads7846 *ts = ads; 902 - struct ads7846_packet *packet = ts->packet; 903 - struct spi_message *m; 904 - struct spi_transfer *t; 905 - int val; 906 - int action; 907 - int status; 908 - 909 - m = &ts->msg[ts->msg_idx]; 910 - t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); 911 - 912 - if (ts->model == 7845) { 913 - val = be16_to_cpup((__be16 *)&(((char*)t->rx_buf)[1])) >> 3; 914 - } else { 915 - /* adjust: on-wire is a must-ignore bit, a BE12 value, then 916 - * padding; built from two 8 bit values written msb-first. 917 - */ 918 - val = be16_to_cpup((__be16 *)t->rx_buf) >> 3; 919 - } 920 - 921 - action = ts->filter(ts->filter_data, ts->msg_idx, &val); 922 - switch (action) { 923 - case ADS7846_FILTER_REPEAT: 924 - break; 925 - case ADS7846_FILTER_IGNORE: 926 - packet->tc.ignore = 1; 927 - /* Last message will contain ads7846_rx() as the 928 - * completion function. 929 - */ 930 - m = ts->last_msg; 931 - break; 932 - case ADS7846_FILTER_OK: 933 - *(u16 *)t->rx_buf = val; 934 - packet->tc.ignore = 0; 935 - m = &ts->msg[++ts->msg_idx]; 936 - break; 937 - default: 938 - BUG(); 939 - } 940 - ts->wait_for_sync(); 941 - status = spi_async(ts->spi, m); 942 - if (status) 943 - dev_err(&ts->spi->dev, "spi_async --> %d\n", 944 - status); 945 - } 946 - 947 - static enum hrtimer_restart ads7846_timer(struct hrtimer *handle) 948 - { 949 - struct ads7846 *ts = container_of(handle, struct ads7846, timer); 950 - int status = 0; 951 - 952 - spin_lock(&ts->lock); 953 - 954 - if (unlikely(!get_pendown_state(ts) || 955 - device_suspended(&ts->spi->dev))) { 956 - if (ts->pendown) { 957 - struct input_dev *input = ts->input; 958 - 959 - input_report_key(input, BTN_TOUCH, 0); 960 - input_report_abs(input, ABS_PRESSURE, 0); 961 - input_sync(input); 962 - 963 - ts->pendown = 0; 964 - dev_vdbg(&ts->spi->dev, "UP\n"); 965 - } 966 - 967 - /* measurement cycle ended */ 968 - if (!device_suspended(&ts->spi->dev)) { 969 - ts->irq_disabled = 0; 970 - enable_irq(ts->spi->irq); 971 - } 972 - ts->pending = 0; 973 - } else { 974 - /* pen is still down, continue with the measurement */ 975 - ts->msg_idx = 0; 976 - ts->wait_for_sync(); 977 - status = spi_async(ts->spi, &ts->msg[0]); 978 - if (status) 979 - dev_err(&ts->spi->dev, "spi_async --> %d\n", status); 980 - } 981 - 982 - spin_unlock(&ts->lock); 983 - return HRTIMER_NORESTART; 984 - } 985 683 986 684 static irqreturn_t ads7846_irq(int irq, void *handle) 987 685 { 988 686 struct ads7846 *ts = handle; 989 - unsigned long flags; 990 687 991 - spin_lock_irqsave(&ts->lock, flags); 992 - if (likely(get_pendown_state(ts))) { 993 - if (!ts->irq_disabled) { 994 - /* The ARM do_simple_IRQ() dispatcher doesn't act 995 - * like the other dispatchers: it will report IRQs 996 - * even after they've been disabled. We work around 997 - * that here. (The "generic irq" framework may help...) 998 - */ 999 - ts->irq_disabled = 1; 1000 - disable_irq_nosync(ts->spi->irq); 1001 - ts->pending = 1; 1002 - hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY), 1003 - HRTIMER_MODE_REL); 1004 - } 688 + /* Start with a small delay before checking pendown state */ 689 + msleep(TS_POLL_DELAY); 690 + 691 + while (!ts->stopped && get_pendown_state(ts)) { 692 + 693 + /* pen is down, continue with the measurement */ 694 + ads7846_read_state(ts); 695 + 696 + if (!ts->stopped) 697 + ads7846_report_state(ts); 698 + 699 + wait_event_timeout(ts->wait, ts->stopped, 700 + msecs_to_jiffies(TS_POLL_PERIOD)); 1005 701 } 1006 - spin_unlock_irqrestore(&ts->lock, flags); 702 + 703 + if (ts->pendown) { 704 + struct input_dev *input = ts->input; 705 + 706 + input_report_key(input, BTN_TOUCH, 0); 707 + input_report_abs(input, ABS_PRESSURE, 0); 708 + input_sync(input); 709 + 710 + ts->pendown = false; 711 + dev_vdbg(&ts->spi->dev, "UP\n"); 712 + } 1007 713 1008 714 return IRQ_HANDLED; 1009 - } 1010 - 1011 - /*--------------------------------------------------------------------------*/ 1012 - 1013 - /* Must be called with ts->lock held */ 1014 - static void ads7846_disable(struct ads7846 *ts) 1015 - { 1016 - if (ts->disabled) 1017 - return; 1018 - 1019 - ts->disabled = 1; 1020 - 1021 - /* are we waiting for IRQ, or polling? */ 1022 - if (!ts->pending) { 1023 - ts->irq_disabled = 1; 1024 - disable_irq(ts->spi->irq); 1025 - } else { 1026 - /* the timer will run at least once more, and 1027 - * leave everything in a clean state, IRQ disabled 1028 - */ 1029 - while (ts->pending) { 1030 - spin_unlock_irq(&ts->lock); 1031 - msleep(1); 1032 - spin_lock_irq(&ts->lock); 1033 - } 1034 - } 1035 - 1036 - regulator_disable(ts->reg); 1037 - 1038 - /* we know the chip's in lowpower mode since we always 1039 - * leave it that way after every request 1040 - */ 1041 - } 1042 - 1043 - /* Must be called with ts->lock held */ 1044 - static void ads7846_enable(struct ads7846 *ts) 1045 - { 1046 - if (!ts->disabled) 1047 - return; 1048 - 1049 - regulator_enable(ts->reg); 1050 - 1051 - ts->disabled = 0; 1052 - ts->irq_disabled = 0; 1053 - enable_irq(ts->spi->irq); 1054 715 } 1055 716 1056 717 static int ads7846_suspend(struct spi_device *spi, pm_message_t message) 1057 718 { 1058 719 struct ads7846 *ts = dev_get_drvdata(&spi->dev); 1059 720 1060 - spin_lock_irq(&ts->lock); 721 + mutex_lock(&ts->lock); 1061 722 1062 - ts->is_suspended = 1; 1063 - ads7846_disable(ts); 723 + if (!ts->suspended) { 1064 724 1065 - spin_unlock_irq(&ts->lock); 725 + if (!ts->disabled) 726 + __ads7846_disable(ts); 1066 727 1067 - if (device_may_wakeup(&ts->spi->dev)) 1068 - enable_irq_wake(ts->spi->irq); 728 + if (device_may_wakeup(&ts->spi->dev)) 729 + enable_irq_wake(ts->spi->irq); 730 + 731 + ts->suspended = true; 732 + } 733 + 734 + mutex_unlock(&ts->lock); 1069 735 1070 736 return 0; 1071 - 1072 737 } 1073 738 1074 739 static int ads7846_resume(struct spi_device *spi) 1075 740 { 1076 741 struct ads7846 *ts = dev_get_drvdata(&spi->dev); 1077 742 1078 - if (device_may_wakeup(&ts->spi->dev)) 1079 - disable_irq_wake(ts->spi->irq); 743 + mutex_lock(&ts->lock); 1080 744 1081 - spin_lock_irq(&ts->lock); 745 + if (ts->suspended) { 1082 746 1083 - ts->is_suspended = 0; 1084 - ads7846_enable(ts); 747 + ts->suspended = false; 1085 748 1086 - spin_unlock_irq(&ts->lock); 749 + if (device_may_wakeup(&ts->spi->dev)) 750 + disable_irq_wake(ts->spi->irq); 751 + 752 + if (!ts->disabled) 753 + __ads7846_enable(ts); 754 + } 755 + 756 + mutex_unlock(&ts->lock); 1087 757 1088 758 return 0; 1089 759 } 1090 760 1091 - static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts) 761 + static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) 1092 762 { 1093 763 struct ads7846_platform_data *pdata = spi->dev.platform_data; 1094 764 int err; ··· 958 932 err = gpio_request(pdata->gpio_pendown, "ads7846_pendown"); 959 933 if (err) { 960 934 dev_err(&spi->dev, "failed to request pendown GPIO%d\n", 961 - pdata->gpio_pendown); 935 + pdata->gpio_pendown); 962 936 return err; 963 937 } 964 938 965 939 ts->gpio_pendown = pdata->gpio_pendown; 940 + 966 941 return 0; 967 942 } 968 943 969 - static int __devinit ads7846_probe(struct spi_device *spi) 944 + /* 945 + * Set up the transfers to read touchscreen state; this assumes we 946 + * use formula #2 for pressure, not #3. 947 + */ 948 + static void __devinit ads7846_setup_spi_msg(struct ads7846 *ts, 949 + const struct ads7846_platform_data *pdata) 970 950 { 971 - struct ads7846 *ts; 972 - struct ads7846_packet *packet; 973 - struct input_dev *input_dev; 974 - const struct ads7846_platform_data *pdata = spi->dev.platform_data; 975 - struct spi_message *m; 976 - struct spi_transfer *x; 977 - unsigned long irq_flags; 978 - int vref; 979 - int err; 980 - 981 - if (!spi->irq) { 982 - dev_dbg(&spi->dev, "no IRQ?\n"); 983 - return -ENODEV; 984 - } 985 - 986 - if (!pdata) { 987 - dev_dbg(&spi->dev, "no platform data?\n"); 988 - return -ENODEV; 989 - } 990 - 991 - /* don't exceed max specified sample rate */ 992 - if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { 993 - dev_dbg(&spi->dev, "f(sample) %d KHz?\n", 994 - (spi->max_speed_hz/SAMPLE_BITS)/1000); 995 - return -EINVAL; 996 - } 997 - 998 - /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except 999 - * that even if the hardware can do that, the SPI controller driver 1000 - * may not. So we stick to very-portable 8 bit words, both RX and TX. 1001 - */ 1002 - spi->bits_per_word = 8; 1003 - spi->mode = SPI_MODE_0; 1004 - err = spi_setup(spi); 1005 - if (err < 0) 1006 - return err; 1007 - 1008 - ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 1009 - packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL); 1010 - input_dev = input_allocate_device(); 1011 - if (!ts || !packet || !input_dev) { 1012 - err = -ENOMEM; 1013 - goto err_free_mem; 1014 - } 1015 - 1016 - dev_set_drvdata(&spi->dev, ts); 1017 - 1018 - ts->packet = packet; 1019 - ts->spi = spi; 1020 - ts->input = input_dev; 1021 - ts->vref_mv = pdata->vref_mv; 1022 - ts->swap_xy = pdata->swap_xy; 1023 - 1024 - hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1025 - ts->timer.function = ads7846_timer; 1026 - 1027 - spin_lock_init(&ts->lock); 1028 - 1029 - ts->model = pdata->model ? : 7846; 1030 - ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; 1031 - ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; 1032 - ts->pressure_max = pdata->pressure_max ? : ~0; 1033 - 1034 - if (pdata->filter != NULL) { 1035 - if (pdata->filter_init != NULL) { 1036 - err = pdata->filter_init(pdata, &ts->filter_data); 1037 - if (err < 0) 1038 - goto err_free_mem; 1039 - } 1040 - ts->filter = pdata->filter; 1041 - ts->filter_cleanup = pdata->filter_cleanup; 1042 - } else if (pdata->debounce_max) { 1043 - ts->debounce_max = pdata->debounce_max; 1044 - if (ts->debounce_max < 2) 1045 - ts->debounce_max = 2; 1046 - ts->debounce_tol = pdata->debounce_tol; 1047 - ts->debounce_rep = pdata->debounce_rep; 1048 - ts->filter = ads7846_debounce; 1049 - ts->filter_data = ts; 1050 - } else 1051 - ts->filter = ads7846_no_filter; 1052 - 1053 - err = setup_pendown(spi, ts); 1054 - if (err) 1055 - goto err_cleanup_filter; 1056 - 1057 - if (pdata->penirq_recheck_delay_usecs) 1058 - ts->penirq_recheck_delay_usecs = 1059 - pdata->penirq_recheck_delay_usecs; 1060 - 1061 - ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; 1062 - 1063 - snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); 1064 - snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); 1065 - 1066 - input_dev->name = ts->name; 1067 - input_dev->phys = ts->phys; 1068 - input_dev->dev.parent = &spi->dev; 1069 - 1070 - input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 1071 - input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 1072 - input_set_abs_params(input_dev, ABS_X, 1073 - pdata->x_min ? : 0, 1074 - pdata->x_max ? : MAX_12BIT, 1075 - 0, 0); 1076 - input_set_abs_params(input_dev, ABS_Y, 1077 - pdata->y_min ? : 0, 1078 - pdata->y_max ? : MAX_12BIT, 1079 - 0, 0); 1080 - input_set_abs_params(input_dev, ABS_PRESSURE, 1081 - pdata->pressure_min, pdata->pressure_max, 0, 0); 1082 - 1083 - vref = pdata->keep_vref_on; 951 + struct spi_message *m = &ts->msg[0]; 952 + struct spi_transfer *x = ts->xfer; 953 + struct ads7846_packet *packet = ts->packet; 954 + int vref = pdata->keep_vref_on; 1084 955 1085 956 if (ts->model == 7873) { 1086 - /* The AD7873 is almost identical to the ADS7846 957 + /* 958 + * The AD7873 is almost identical to the ADS7846 1087 959 * keep VREF off during differential/ratiometric 1088 - * conversion modes 960 + * conversion modes. 1089 961 */ 1090 962 ts->model = 7846; 1091 963 vref = 0; 1092 964 } 1093 965 1094 - /* set up the transfers to read touchscreen state; this assumes we 1095 - * use formula #2 for pressure, not #3. 1096 - */ 1097 - m = &ts->msg[0]; 1098 - x = ts->xfer; 1099 - 966 + ts->msg_count = 1; 1100 967 spi_message_init(m); 968 + m->context = ts; 1101 969 1102 970 if (ts->model == 7845) { 1103 971 packet->read_y_cmd[0] = READ_Y(vref); ··· 1014 1094 spi_message_add_tail(x, m); 1015 1095 } 1016 1096 1017 - /* the first sample after switching drivers can be low quality; 1097 + /* 1098 + * The first sample after switching drivers can be low quality; 1018 1099 * optionally discard it, using a second one after the signals 1019 1100 * have had enough time to stabilize. 1020 1101 */ ··· 1033 1112 spi_message_add_tail(x, m); 1034 1113 } 1035 1114 1036 - m->complete = ads7846_rx_val; 1037 - m->context = ts; 1038 - 1115 + ts->msg_count++; 1039 1116 m++; 1040 1117 spi_message_init(m); 1118 + m->context = ts; 1041 1119 1042 1120 if (ts->model == 7845) { 1043 1121 x++; ··· 1076 1156 spi_message_add_tail(x, m); 1077 1157 } 1078 1158 1079 - m->complete = ads7846_rx_val; 1080 - m->context = ts; 1081 - 1082 1159 /* turn y+ off, x- on; we'll use formula #2 */ 1083 1160 if (ts->model == 7846) { 1161 + ts->msg_count++; 1084 1162 m++; 1085 1163 spi_message_init(m); 1164 + m->context = ts; 1086 1165 1087 1166 x++; 1088 1167 packet->read_z1 = READ_Z1(vref); ··· 1109 1190 spi_message_add_tail(x, m); 1110 1191 } 1111 1192 1112 - m->complete = ads7846_rx_val; 1113 - m->context = ts; 1114 - 1193 + ts->msg_count++; 1115 1194 m++; 1116 1195 spi_message_init(m); 1196 + m->context = ts; 1117 1197 1118 1198 x++; 1119 1199 packet->read_z2 = READ_Z2(vref); ··· 1139 1221 x->len = 2; 1140 1222 spi_message_add_tail(x, m); 1141 1223 } 1142 - 1143 - m->complete = ads7846_rx_val; 1144 - m->context = ts; 1145 1224 } 1146 1225 1147 1226 /* power down */ 1227 + ts->msg_count++; 1148 1228 m++; 1149 1229 spi_message_init(m); 1230 + m->context = ts; 1150 1231 1151 1232 if (ts->model == 7845) { 1152 1233 x++; ··· 1168 1251 1169 1252 CS_CHANGE(*x); 1170 1253 spi_message_add_tail(x, m); 1254 + } 1171 1255 1172 - m->complete = ads7846_rx; 1173 - m->context = ts; 1256 + static int __devinit ads7846_probe(struct spi_device *spi) 1257 + { 1258 + struct ads7846 *ts; 1259 + struct ads7846_packet *packet; 1260 + struct input_dev *input_dev; 1261 + struct ads7846_platform_data *pdata = spi->dev.platform_data; 1262 + unsigned long irq_flags; 1263 + int err; 1174 1264 1175 - ts->last_msg = m; 1265 + if (!spi->irq) { 1266 + dev_dbg(&spi->dev, "no IRQ?\n"); 1267 + return -ENODEV; 1268 + } 1269 + 1270 + if (!pdata) { 1271 + dev_dbg(&spi->dev, "no platform data?\n"); 1272 + return -ENODEV; 1273 + } 1274 + 1275 + /* don't exceed max specified sample rate */ 1276 + if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { 1277 + dev_dbg(&spi->dev, "f(sample) %d KHz?\n", 1278 + (spi->max_speed_hz/SAMPLE_BITS)/1000); 1279 + return -EINVAL; 1280 + } 1281 + 1282 + /* We'd set TX word size 8 bits and RX word size to 13 bits ... except 1283 + * that even if the hardware can do that, the SPI controller driver 1284 + * may not. So we stick to very-portable 8 bit words, both RX and TX. 1285 + */ 1286 + spi->bits_per_word = 8; 1287 + spi->mode = SPI_MODE_0; 1288 + err = spi_setup(spi); 1289 + if (err < 0) 1290 + return err; 1291 + 1292 + ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 1293 + packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL); 1294 + input_dev = input_allocate_device(); 1295 + if (!ts || !packet || !input_dev) { 1296 + err = -ENOMEM; 1297 + goto err_free_mem; 1298 + } 1299 + 1300 + dev_set_drvdata(&spi->dev, ts); 1301 + 1302 + ts->packet = packet; 1303 + ts->spi = spi; 1304 + ts->input = input_dev; 1305 + ts->vref_mv = pdata->vref_mv; 1306 + ts->swap_xy = pdata->swap_xy; 1307 + 1308 + mutex_init(&ts->lock); 1309 + init_waitqueue_head(&ts->wait); 1310 + 1311 + ts->model = pdata->model ? : 7846; 1312 + ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; 1313 + ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; 1314 + ts->pressure_max = pdata->pressure_max ? : ~0; 1315 + 1316 + if (pdata->filter != NULL) { 1317 + if (pdata->filter_init != NULL) { 1318 + err = pdata->filter_init(pdata, &ts->filter_data); 1319 + if (err < 0) 1320 + goto err_free_mem; 1321 + } 1322 + ts->filter = pdata->filter; 1323 + ts->filter_cleanup = pdata->filter_cleanup; 1324 + } else if (pdata->debounce_max) { 1325 + ts->debounce_max = pdata->debounce_max; 1326 + if (ts->debounce_max < 2) 1327 + ts->debounce_max = 2; 1328 + ts->debounce_tol = pdata->debounce_tol; 1329 + ts->debounce_rep = pdata->debounce_rep; 1330 + ts->filter = ads7846_debounce_filter; 1331 + ts->filter_data = ts; 1332 + } else { 1333 + ts->filter = ads7846_no_filter; 1334 + } 1335 + 1336 + err = ads7846_setup_pendown(spi, ts); 1337 + if (err) 1338 + goto err_cleanup_filter; 1339 + 1340 + if (pdata->penirq_recheck_delay_usecs) 1341 + ts->penirq_recheck_delay_usecs = 1342 + pdata->penirq_recheck_delay_usecs; 1343 + 1344 + ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; 1345 + 1346 + snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); 1347 + snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); 1348 + 1349 + input_dev->name = ts->name; 1350 + input_dev->phys = ts->phys; 1351 + input_dev->dev.parent = &spi->dev; 1352 + 1353 + input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 1354 + input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 1355 + input_set_abs_params(input_dev, ABS_X, 1356 + pdata->x_min ? : 0, 1357 + pdata->x_max ? : MAX_12BIT, 1358 + 0, 0); 1359 + input_set_abs_params(input_dev, ABS_Y, 1360 + pdata->y_min ? : 0, 1361 + pdata->y_max ? : MAX_12BIT, 1362 + 0, 0); 1363 + input_set_abs_params(input_dev, ABS_PRESSURE, 1364 + pdata->pressure_min, pdata->pressure_max, 0, 0); 1365 + 1366 + ads7846_setup_spi_msg(ts, pdata); 1176 1367 1177 1368 ts->reg = regulator_get(&spi->dev, "vcc"); 1178 1369 if (IS_ERR(ts->reg)) { ··· 1296 1271 } 1297 1272 1298 1273 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; 1274 + irq_flags |= IRQF_ONESHOT; 1299 1275 1300 - err = request_irq(spi->irq, ads7846_irq, irq_flags, 1301 - spi->dev.driver->name, ts); 1302 - 1276 + err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, 1277 + irq_flags, spi->dev.driver->name, ts); 1303 1278 if (err && !pdata->irq_flags) { 1304 1279 dev_info(&spi->dev, 1305 1280 "trying pin change workaround on irq %d\n", spi->irq); 1306 - err = request_irq(spi->irq, ads7846_irq, 1307 - IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 1308 - spi->dev.driver->name, ts); 1281 + irq_flags |= IRQF_TRIGGER_RISING; 1282 + err = request_threaded_irq(spi->irq, 1283 + ads7846_hard_irq, ads7846_irq, 1284 + irq_flags, spi->dev.driver->name, ts); 1309 1285 } 1310 1286 1311 1287 if (err) { ··· 1320 1294 1321 1295 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); 1322 1296 1323 - /* take a first sample, leaving nPENIRQ active and vREF off; avoid 1297 + /* 1298 + * Take a first sample, leaving nPENIRQ active and vREF off; avoid 1324 1299 * the touchscreen, in case it's not connected. 1325 1300 */ 1326 1301 if (ts->model == 7845) ··· 1367 1340 1368 1341 static int __devexit ads7846_remove(struct spi_device *spi) 1369 1342 { 1370 - struct ads7846 *ts = dev_get_drvdata(&spi->dev); 1343 + struct ads7846 *ts = dev_get_drvdata(&spi->dev); 1371 1344 1372 1345 device_init_wakeup(&spi->dev, false); 1373 1346 1374 - ads784x_hwmon_unregister(spi, ts); 1375 - input_unregister_device(ts->input); 1376 - 1377 - ads7846_suspend(spi, PMSG_SUSPEND); 1378 - 1379 1347 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); 1380 1348 1349 + ads7846_disable(ts); 1381 1350 free_irq(ts->spi->irq, ts); 1382 - /* suspend left the IRQ disabled */ 1383 - enable_irq(ts->spi->irq); 1351 + 1352 + input_unregister_device(ts->input); 1353 + 1354 + ads784x_hwmon_unregister(spi, ts); 1384 1355 1385 1356 regulator_disable(ts->reg); 1386 1357 regulator_put(ts->reg); ··· 1393 1368 kfree(ts); 1394 1369 1395 1370 dev_dbg(&spi->dev, "unregistered touchscreen\n"); 1371 + 1396 1372 return 0; 1397 1373 } 1398 1374
+648
drivers/input/touchscreen/bu21013_ts.c
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson 4 + * License terms:GNU General Public License (GPL) version 2 5 + */ 6 + 7 + #include <linux/kernel.h> 8 + #include <linux/delay.h> 9 + #include <linux/interrupt.h> 10 + #include <linux/i2c.h> 11 + #include <linux/workqueue.h> 12 + #include <linux/input.h> 13 + #include <linux/input/bu21013.h> 14 + #include <linux/slab.h> 15 + 16 + #define PEN_DOWN_INTR 0 17 + #define MAX_FINGERS 2 18 + #define RESET_DELAY 30 19 + #define PENUP_TIMEOUT (10) 20 + #define DELTA_MIN 16 21 + #define MASK_BITS 0x03 22 + #define SHIFT_8 8 23 + #define SHIFT_2 2 24 + #define LENGTH_OF_BUFFER 11 25 + #define I2C_RETRY_COUNT 5 26 + 27 + #define BU21013_SENSORS_BTN_0_7_REG 0x70 28 + #define BU21013_SENSORS_BTN_8_15_REG 0x71 29 + #define BU21013_SENSORS_BTN_16_23_REG 0x72 30 + #define BU21013_X1_POS_MSB_REG 0x73 31 + #define BU21013_X1_POS_LSB_REG 0x74 32 + #define BU21013_Y1_POS_MSB_REG 0x75 33 + #define BU21013_Y1_POS_LSB_REG 0x76 34 + #define BU21013_X2_POS_MSB_REG 0x77 35 + #define BU21013_X2_POS_LSB_REG 0x78 36 + #define BU21013_Y2_POS_MSB_REG 0x79 37 + #define BU21013_Y2_POS_LSB_REG 0x7A 38 + #define BU21013_INT_CLR_REG 0xE8 39 + #define BU21013_INT_MODE_REG 0xE9 40 + #define BU21013_GAIN_REG 0xEA 41 + #define BU21013_OFFSET_MODE_REG 0xEB 42 + #define BU21013_XY_EDGE_REG 0xEC 43 + #define BU21013_RESET_REG 0xED 44 + #define BU21013_CALIB_REG 0xEE 45 + #define BU21013_DONE_REG 0xEF 46 + #define BU21013_SENSOR_0_7_REG 0xF0 47 + #define BU21013_SENSOR_8_15_REG 0xF1 48 + #define BU21013_SENSOR_16_23_REG 0xF2 49 + #define BU21013_POS_MODE1_REG 0xF3 50 + #define BU21013_POS_MODE2_REG 0xF4 51 + #define BU21013_CLK_MODE_REG 0xF5 52 + #define BU21013_IDLE_REG 0xFA 53 + #define BU21013_FILTER_REG 0xFB 54 + #define BU21013_TH_ON_REG 0xFC 55 + #define BU21013_TH_OFF_REG 0xFD 56 + 57 + 58 + #define BU21013_RESET_ENABLE 0x01 59 + 60 + #define BU21013_SENSORS_EN_0_7 0x3F 61 + #define BU21013_SENSORS_EN_8_15 0xFC 62 + #define BU21013_SENSORS_EN_16_23 0x1F 63 + 64 + #define BU21013_POS_MODE1_0 0x02 65 + #define BU21013_POS_MODE1_1 0x04 66 + #define BU21013_POS_MODE1_2 0x08 67 + 68 + #define BU21013_POS_MODE2_ZERO 0x01 69 + #define BU21013_POS_MODE2_AVG1 0x02 70 + #define BU21013_POS_MODE2_AVG2 0x04 71 + #define BU21013_POS_MODE2_EN_XY 0x08 72 + #define BU21013_POS_MODE2_EN_RAW 0x10 73 + #define BU21013_POS_MODE2_MULTI 0x80 74 + 75 + #define BU21013_CLK_MODE_DIV 0x01 76 + #define BU21013_CLK_MODE_EXT 0x02 77 + #define BU21013_CLK_MODE_CALIB 0x80 78 + 79 + #define BU21013_IDLET_0 0x01 80 + #define BU21013_IDLET_1 0x02 81 + #define BU21013_IDLET_2 0x04 82 + #define BU21013_IDLET_3 0x08 83 + #define BU21013_IDLE_INTERMIT_EN 0x10 84 + 85 + #define BU21013_DELTA_0_6 0x7F 86 + #define BU21013_FILTER_EN 0x80 87 + 88 + #define BU21013_INT_MODE_LEVEL 0x00 89 + #define BU21013_INT_MODE_EDGE 0x01 90 + 91 + #define BU21013_GAIN_0 0x01 92 + #define BU21013_GAIN_1 0x02 93 + #define BU21013_GAIN_2 0x04 94 + 95 + #define BU21013_OFFSET_MODE_DEFAULT 0x00 96 + #define BU21013_OFFSET_MODE_MOVE 0x01 97 + #define BU21013_OFFSET_MODE_DISABLE 0x02 98 + 99 + #define BU21013_TH_ON_0 0x01 100 + #define BU21013_TH_ON_1 0x02 101 + #define BU21013_TH_ON_2 0x04 102 + #define BU21013_TH_ON_3 0x08 103 + #define BU21013_TH_ON_4 0x10 104 + #define BU21013_TH_ON_5 0x20 105 + #define BU21013_TH_ON_6 0x40 106 + #define BU21013_TH_ON_7 0x80 107 + #define BU21013_TH_ON_MAX 0xFF 108 + 109 + #define BU21013_TH_OFF_0 0x01 110 + #define BU21013_TH_OFF_1 0x02 111 + #define BU21013_TH_OFF_2 0x04 112 + #define BU21013_TH_OFF_3 0x08 113 + #define BU21013_TH_OFF_4 0x10 114 + #define BU21013_TH_OFF_5 0x20 115 + #define BU21013_TH_OFF_6 0x40 116 + #define BU21013_TH_OFF_7 0x80 117 + #define BU21013_TH_OFF_MAX 0xFF 118 + 119 + #define BU21013_X_EDGE_0 0x01 120 + #define BU21013_X_EDGE_1 0x02 121 + #define BU21013_X_EDGE_2 0x04 122 + #define BU21013_X_EDGE_3 0x08 123 + #define BU21013_Y_EDGE_0 0x10 124 + #define BU21013_Y_EDGE_1 0x20 125 + #define BU21013_Y_EDGE_2 0x40 126 + #define BU21013_Y_EDGE_3 0x80 127 + 128 + #define BU21013_DONE 0x01 129 + #define BU21013_NUMBER_OF_X_SENSORS (6) 130 + #define BU21013_NUMBER_OF_Y_SENSORS (11) 131 + 132 + #define DRIVER_TP "bu21013_tp" 133 + 134 + /** 135 + * struct bu21013_ts_data - touch panel data structure 136 + * @client: pointer to the i2c client 137 + * @wait: variable to wait_queue_head_t structure 138 + * @touch_stopped: touch stop flag 139 + * @chip: pointer to the touch panel controller 140 + * @in_dev: pointer to the input device structure 141 + * @intr_pin: interrupt pin value 142 + * 143 + * Touch panel device data structure 144 + */ 145 + struct bu21013_ts_data { 146 + struct i2c_client *client; 147 + wait_queue_head_t wait; 148 + bool touch_stopped; 149 + const struct bu21013_platform_device *chip; 150 + struct input_dev *in_dev; 151 + unsigned int intr_pin; 152 + }; 153 + 154 + /** 155 + * bu21013_read_block_data(): read the touch co-ordinates 156 + * @data: bu21013_ts_data structure pointer 157 + * @buf: byte pointer 158 + * 159 + * Read the touch co-ordinates using i2c read block into buffer 160 + * and returns integer. 161 + */ 162 + static int bu21013_read_block_data(struct bu21013_ts_data *data, u8 *buf) 163 + { 164 + int ret, i; 165 + 166 + for (i = 0; i < I2C_RETRY_COUNT; i++) { 167 + ret = i2c_smbus_read_i2c_block_data 168 + (data->client, BU21013_SENSORS_BTN_0_7_REG, 169 + LENGTH_OF_BUFFER, buf); 170 + if (ret == LENGTH_OF_BUFFER) 171 + return 0; 172 + } 173 + return -EINVAL; 174 + } 175 + 176 + /** 177 + * bu21013_do_touch_report(): Get the touch co-ordinates 178 + * @data: bu21013_ts_data structure pointer 179 + * 180 + * Get the touch co-ordinates from touch sensor registers and writes 181 + * into device structure and returns integer. 182 + */ 183 + static int bu21013_do_touch_report(struct bu21013_ts_data *data) 184 + { 185 + u8 buf[LENGTH_OF_BUFFER]; 186 + unsigned int pos_x[2], pos_y[2]; 187 + bool has_x_sensors, has_y_sensors; 188 + int finger_down_count = 0; 189 + int i; 190 + 191 + if (data == NULL) 192 + return -EINVAL; 193 + 194 + if (bu21013_read_block_data(data, buf) < 0) 195 + return -EINVAL; 196 + 197 + has_x_sensors = hweight32(buf[0] & BU21013_SENSORS_EN_0_7); 198 + has_y_sensors = hweight32(((buf[1] & BU21013_SENSORS_EN_8_15) | 199 + ((buf[2] & BU21013_SENSORS_EN_16_23) << SHIFT_8)) >> SHIFT_2); 200 + if (!has_x_sensors || !has_y_sensors) 201 + return 0; 202 + 203 + for (i = 0; i < MAX_FINGERS; i++) { 204 + const u8 *p = &buf[4 * i + 3]; 205 + unsigned int x = p[0] << SHIFT_2 | (p[1] & MASK_BITS); 206 + unsigned int y = p[2] << SHIFT_2 | (p[3] & MASK_BITS); 207 + if (x == 0 || y == 0) 208 + continue; 209 + pos_x[finger_down_count] = x; 210 + pos_y[finger_down_count] = y; 211 + finger_down_count++; 212 + } 213 + 214 + if (finger_down_count) { 215 + if (finger_down_count == 2 && 216 + (abs(pos_x[0] - pos_x[1]) < DELTA_MIN || 217 + abs(pos_y[0] - pos_y[1]) < DELTA_MIN)) { 218 + return 0; 219 + } 220 + 221 + for (i = 0; i < finger_down_count; i++) { 222 + if (data->chip->x_flip) 223 + pos_x[i] = data->chip->touch_x_max - pos_x[i]; 224 + if (data->chip->y_flip) 225 + pos_y[i] = data->chip->touch_y_max - pos_y[i]; 226 + 227 + input_report_abs(data->in_dev, 228 + ABS_MT_POSITION_X, pos_x[i]); 229 + input_report_abs(data->in_dev, 230 + ABS_MT_POSITION_Y, pos_y[i]); 231 + input_mt_sync(data->in_dev); 232 + } 233 + } else 234 + input_mt_sync(data->in_dev); 235 + 236 + input_sync(data->in_dev); 237 + 238 + return 0; 239 + } 240 + /** 241 + * bu21013_gpio_irq() - gpio thread function for touch interrupt 242 + * @irq: irq value 243 + * @device_data: void pointer 244 + * 245 + * This gpio thread function for touch interrupt 246 + * and returns irqreturn_t. 247 + */ 248 + static irqreturn_t bu21013_gpio_irq(int irq, void *device_data) 249 + { 250 + struct bu21013_ts_data *data = device_data; 251 + struct i2c_client *i2c = data->client; 252 + int retval; 253 + 254 + do { 255 + retval = bu21013_do_touch_report(data); 256 + if (retval < 0) { 257 + dev_err(&i2c->dev, "bu21013_do_touch_report failed\n"); 258 + return IRQ_NONE; 259 + } 260 + 261 + data->intr_pin = data->chip->irq_read_val(); 262 + if (data->intr_pin == PEN_DOWN_INTR) 263 + wait_event_timeout(data->wait, data->touch_stopped, 264 + msecs_to_jiffies(2)); 265 + } while (!data->intr_pin && !data->touch_stopped); 266 + 267 + return IRQ_HANDLED; 268 + } 269 + 270 + /** 271 + * bu21013_init_chip() - power on sequence for the bu21013 controller 272 + * @data: device structure pointer 273 + * 274 + * This function is used to power on 275 + * the bu21013 controller and returns integer. 276 + */ 277 + static int bu21013_init_chip(struct bu21013_ts_data *data) 278 + { 279 + int retval; 280 + struct i2c_client *i2c = data->client; 281 + 282 + retval = i2c_smbus_write_byte_data(i2c, BU21013_RESET_REG, 283 + BU21013_RESET_ENABLE); 284 + if (retval < 0) { 285 + dev_err(&i2c->dev, "BU21013_RESET reg write failed\n"); 286 + return retval; 287 + } 288 + msleep(RESET_DELAY); 289 + 290 + retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_0_7_REG, 291 + BU21013_SENSORS_EN_0_7); 292 + if (retval < 0) { 293 + dev_err(&i2c->dev, "BU21013_SENSOR_0_7 reg write failed\n"); 294 + return retval; 295 + } 296 + 297 + retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_8_15_REG, 298 + BU21013_SENSORS_EN_8_15); 299 + if (retval < 0) { 300 + dev_err(&i2c->dev, "BU21013_SENSOR_8_15 reg write failed\n"); 301 + return retval; 302 + } 303 + 304 + retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_16_23_REG, 305 + BU21013_SENSORS_EN_16_23); 306 + if (retval < 0) { 307 + dev_err(&i2c->dev, "BU21013_SENSOR_16_23 reg write failed\n"); 308 + return retval; 309 + } 310 + 311 + retval = i2c_smbus_write_byte_data(i2c, BU21013_POS_MODE1_REG, 312 + (BU21013_POS_MODE1_0 | BU21013_POS_MODE1_1)); 313 + if (retval < 0) { 314 + dev_err(&i2c->dev, "BU21013_POS_MODE1 reg write failed\n"); 315 + return retval; 316 + } 317 + 318 + retval = i2c_smbus_write_byte_data(i2c, BU21013_POS_MODE2_REG, 319 + (BU21013_POS_MODE2_ZERO | BU21013_POS_MODE2_AVG1 | 320 + BU21013_POS_MODE2_AVG2 | BU21013_POS_MODE2_EN_RAW | 321 + BU21013_POS_MODE2_MULTI)); 322 + if (retval < 0) { 323 + dev_err(&i2c->dev, "BU21013_POS_MODE2 reg write failed\n"); 324 + return retval; 325 + } 326 + 327 + if (data->chip->ext_clk) 328 + retval = i2c_smbus_write_byte_data(i2c, BU21013_CLK_MODE_REG, 329 + (BU21013_CLK_MODE_EXT | BU21013_CLK_MODE_CALIB)); 330 + else 331 + retval = i2c_smbus_write_byte_data(i2c, BU21013_CLK_MODE_REG, 332 + (BU21013_CLK_MODE_DIV | BU21013_CLK_MODE_CALIB)); 333 + if (retval < 0) { 334 + dev_err(&i2c->dev, "BU21013_CLK_MODE reg write failed\n"); 335 + return retval; 336 + } 337 + 338 + retval = i2c_smbus_write_byte_data(i2c, BU21013_IDLE_REG, 339 + (BU21013_IDLET_0 | BU21013_IDLE_INTERMIT_EN)); 340 + if (retval < 0) { 341 + dev_err(&i2c->dev, "BU21013_IDLE reg write failed\n"); 342 + return retval; 343 + } 344 + 345 + retval = i2c_smbus_write_byte_data(i2c, BU21013_INT_MODE_REG, 346 + BU21013_INT_MODE_LEVEL); 347 + if (retval < 0) { 348 + dev_err(&i2c->dev, "BU21013_INT_MODE reg write failed\n"); 349 + return retval; 350 + } 351 + 352 + retval = i2c_smbus_write_byte_data(i2c, BU21013_FILTER_REG, 353 + (BU21013_DELTA_0_6 | 354 + BU21013_FILTER_EN)); 355 + if (retval < 0) { 356 + dev_err(&i2c->dev, "BU21013_FILTER reg write failed\n"); 357 + return retval; 358 + } 359 + 360 + retval = i2c_smbus_write_byte_data(i2c, BU21013_TH_ON_REG, 361 + BU21013_TH_ON_5); 362 + if (retval < 0) { 363 + dev_err(&i2c->dev, "BU21013_TH_ON reg write failed\n"); 364 + return retval; 365 + } 366 + 367 + retval = i2c_smbus_write_byte_data(i2c, BU21013_TH_OFF_REG, 368 + BU21013_TH_OFF_4 || BU21013_TH_OFF_3); 369 + if (retval < 0) { 370 + dev_err(&i2c->dev, "BU21013_TH_OFF reg write failed\n"); 371 + return retval; 372 + } 373 + 374 + retval = i2c_smbus_write_byte_data(i2c, BU21013_GAIN_REG, 375 + (BU21013_GAIN_0 | BU21013_GAIN_1)); 376 + if (retval < 0) { 377 + dev_err(&i2c->dev, "BU21013_GAIN reg write failed\n"); 378 + return retval; 379 + } 380 + 381 + retval = i2c_smbus_write_byte_data(i2c, BU21013_OFFSET_MODE_REG, 382 + BU21013_OFFSET_MODE_DEFAULT); 383 + if (retval < 0) { 384 + dev_err(&i2c->dev, "BU21013_OFFSET_MODE reg write failed\n"); 385 + return retval; 386 + } 387 + 388 + retval = i2c_smbus_write_byte_data(i2c, BU21013_XY_EDGE_REG, 389 + (BU21013_X_EDGE_0 | BU21013_X_EDGE_2 | 390 + BU21013_Y_EDGE_1 | BU21013_Y_EDGE_3)); 391 + if (retval < 0) { 392 + dev_err(&i2c->dev, "BU21013_XY_EDGE reg write failed\n"); 393 + return retval; 394 + } 395 + 396 + retval = i2c_smbus_write_byte_data(i2c, BU21013_DONE_REG, 397 + BU21013_DONE); 398 + if (retval < 0) { 399 + dev_err(&i2c->dev, "BU21013_REG_DONE reg write failed\n"); 400 + return retval; 401 + } 402 + 403 + return 0; 404 + } 405 + 406 + /** 407 + * bu21013_free_irq() - frees IRQ registered for touchscreen 408 + * @bu21013_data: device structure pointer 409 + * 410 + * This function signals interrupt thread to stop processing and 411 + * frees interrupt. 412 + */ 413 + static void bu21013_free_irq(struct bu21013_ts_data *bu21013_data) 414 + { 415 + bu21013_data->touch_stopped = true; 416 + wake_up(&bu21013_data->wait); 417 + free_irq(bu21013_data->chip->irq, bu21013_data); 418 + } 419 + 420 + /** 421 + * bu21013_probe() - initializes the i2c-client touchscreen driver 422 + * @client: i2c client structure pointer 423 + * @id: i2c device id pointer 424 + * 425 + * This function used to initializes the i2c-client touchscreen 426 + * driver and returns integer. 427 + */ 428 + static int __devinit bu21013_probe(struct i2c_client *client, 429 + const struct i2c_device_id *id) 430 + { 431 + struct bu21013_ts_data *bu21013_data; 432 + struct input_dev *in_dev; 433 + const struct bu21013_platform_device *pdata = 434 + client->dev.platform_data; 435 + int error; 436 + 437 + if (!i2c_check_functionality(client->adapter, 438 + I2C_FUNC_SMBUS_BYTE_DATA)) { 439 + dev_err(&client->dev, "i2c smbus byte data not supported\n"); 440 + return -EIO; 441 + } 442 + 443 + if (!pdata) { 444 + dev_err(&client->dev, "platform data not defined\n"); 445 + return -EINVAL; 446 + } 447 + 448 + bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL); 449 + in_dev = input_allocate_device(); 450 + if (!bu21013_data || !in_dev) { 451 + dev_err(&client->dev, "device memory alloc failed\n"); 452 + error = -ENOMEM; 453 + goto err_free_mem; 454 + } 455 + 456 + bu21013_data->in_dev = in_dev; 457 + bu21013_data->chip = pdata; 458 + bu21013_data->client = client; 459 + bu21013_data->touch_stopped = false; 460 + init_waitqueue_head(&bu21013_data->wait); 461 + 462 + /* configure the gpio pins */ 463 + if (pdata->cs_en) { 464 + error = pdata->cs_en(pdata->cs_pin); 465 + if (error < 0) { 466 + dev_err(&client->dev, "chip init failed\n"); 467 + goto err_free_mem; 468 + } 469 + } 470 + 471 + /* configure the touch panel controller */ 472 + error = bu21013_init_chip(bu21013_data); 473 + if (error) { 474 + dev_err(&client->dev, "error in bu21013 config\n"); 475 + goto err_cs_disable; 476 + } 477 + 478 + /* register the device to input subsystem */ 479 + in_dev->name = DRIVER_TP; 480 + in_dev->id.bustype = BUS_I2C; 481 + in_dev->dev.parent = &client->dev; 482 + 483 + __set_bit(EV_SYN, in_dev->evbit); 484 + __set_bit(EV_KEY, in_dev->evbit); 485 + __set_bit(EV_ABS, in_dev->evbit); 486 + 487 + input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0, 488 + pdata->x_max_res, 0, 0); 489 + input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0, 490 + pdata->y_max_res, 0, 0); 491 + input_set_drvdata(in_dev, bu21013_data); 492 + 493 + error = request_threaded_irq(pdata->irq, NULL, bu21013_gpio_irq, 494 + IRQF_TRIGGER_FALLING | IRQF_SHARED, 495 + DRIVER_TP, bu21013_data); 496 + if (error) { 497 + dev_err(&client->dev, "request irq %d failed\n", pdata->irq); 498 + goto err_cs_disable; 499 + } 500 + 501 + error = input_register_device(in_dev); 502 + if (error) { 503 + dev_err(&client->dev, "failed to register input device\n"); 504 + goto err_free_irq; 505 + } 506 + 507 + device_init_wakeup(&client->dev, pdata->wakeup); 508 + i2c_set_clientdata(client, bu21013_data); 509 + 510 + return 0; 511 + 512 + err_free_irq: 513 + bu21013_free_irq(bu21013_data); 514 + err_cs_disable: 515 + pdata->cs_dis(pdata->cs_pin); 516 + err_free_mem: 517 + input_free_device(bu21013_data->in_dev); 518 + kfree(bu21013_data); 519 + 520 + return error; 521 + } 522 + /** 523 + * bu21013_remove() - removes the i2c-client touchscreen driver 524 + * @client: i2c client structure pointer 525 + * 526 + * This function uses to remove the i2c-client 527 + * touchscreen driver and returns integer. 528 + */ 529 + static int __devexit bu21013_remove(struct i2c_client *client) 530 + { 531 + struct bu21013_ts_data *bu21013_data = i2c_get_clientdata(client); 532 + 533 + bu21013_free_irq(bu21013_data); 534 + 535 + bu21013_data->chip->cs_dis(bu21013_data->chip->cs_pin); 536 + 537 + input_unregister_device(bu21013_data->in_dev); 538 + kfree(bu21013_data); 539 + 540 + device_init_wakeup(&client->dev, false); 541 + 542 + return 0; 543 + } 544 + 545 + #ifdef CONFIG_PM 546 + /** 547 + * bu21013_suspend() - suspend the touch screen controller 548 + * @dev: pointer to device structure 549 + * 550 + * This function is used to suspend the 551 + * touch panel controller and returns integer 552 + */ 553 + static int bu21013_suspend(struct device *dev) 554 + { 555 + struct bu21013_ts_data *bu21013_data = dev_get_drvdata(dev); 556 + struct i2c_client *client = bu21013_data->client; 557 + 558 + bu21013_data->touch_stopped = true; 559 + if (device_may_wakeup(&client->dev)) 560 + enable_irq_wake(bu21013_data->chip->irq); 561 + else 562 + disable_irq(bu21013_data->chip->irq); 563 + 564 + return 0; 565 + } 566 + 567 + /** 568 + * bu21013_resume() - resume the touch screen controller 569 + * @dev: pointer to device structure 570 + * 571 + * This function is used to resume the touch panel 572 + * controller and returns integer. 573 + */ 574 + static int bu21013_resume(struct device *dev) 575 + { 576 + struct bu21013_ts_data *bu21013_data = dev_get_drvdata(dev); 577 + struct i2c_client *client = bu21013_data->client; 578 + int retval; 579 + 580 + retval = bu21013_init_chip(bu21013_data); 581 + if (retval < 0) { 582 + dev_err(&client->dev, "bu21013 controller config failed\n"); 583 + return retval; 584 + } 585 + 586 + bu21013_data->touch_stopped = false; 587 + 588 + if (device_may_wakeup(&client->dev)) 589 + disable_irq_wake(bu21013_data->chip->irq); 590 + else 591 + enable_irq(bu21013_data->chip->irq); 592 + 593 + return 0; 594 + } 595 + 596 + static const struct dev_pm_ops bu21013_dev_pm_ops = { 597 + .suspend = bu21013_suspend, 598 + .resume = bu21013_resume, 599 + }; 600 + #endif 601 + 602 + static const struct i2c_device_id bu21013_id[] = { 603 + { DRIVER_TP, 0 }, 604 + { } 605 + }; 606 + MODULE_DEVICE_TABLE(i2c, bu21013_id); 607 + 608 + static struct i2c_driver bu21013_driver = { 609 + .driver = { 610 + .name = DRIVER_TP, 611 + .owner = THIS_MODULE, 612 + #ifdef CONFIG_PM 613 + .pm = &bu21013_dev_pm_ops, 614 + #endif 615 + }, 616 + .probe = bu21013_probe, 617 + .remove = __devexit_p(bu21013_remove), 618 + .id_table = bu21013_id, 619 + }; 620 + 621 + /** 622 + * bu21013_init() - initializes the bu21013 touchscreen driver 623 + * 624 + * This function used to initializes the bu21013 625 + * touchscreen driver and returns integer. 626 + */ 627 + static int __init bu21013_init(void) 628 + { 629 + return i2c_add_driver(&bu21013_driver); 630 + } 631 + 632 + /** 633 + * bu21013_exit() - de-initializes the bu21013 touchscreen driver 634 + * 635 + * This function uses to de-initializes the bu21013 636 + * touchscreen driver and returns none. 637 + */ 638 + static void __exit bu21013_exit(void) 639 + { 640 + i2c_del_driver(&bu21013_driver); 641 + } 642 + 643 + module_init(bu21013_init); 644 + module_exit(bu21013_exit); 645 + 646 + MODULE_LICENSE("GPL v2"); 647 + MODULE_AUTHOR("Naveen Kumar G <naveen.gaddipati@stericsson.com>"); 648 + MODULE_DESCRIPTION("bu21013 touch screen controller driver");
+2 -2
drivers/input/touchscreen/cy8ctmg110_ts.c
··· 206 206 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 207 207 208 208 input_set_abs_params(input_dev, ABS_X, 209 - CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 0, 0); 209 + CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 4, 0); 210 210 input_set_abs_params(input_dev, ABS_Y, 211 - CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 0, 0); 211 + CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 4, 0); 212 212 213 213 if (ts->reset_pin) { 214 214 err = gpio_request(ts->reset_pin, NULL);
+2 -4
drivers/input/touchscreen/hp680_ts_input.c
··· 107 107 return 0; 108 108 109 109 fail2: free_irq(HP680_TS_IRQ, NULL); 110 - cancel_delayed_work(&work); 111 - flush_scheduled_work(); 110 + cancel_delayed_work_sync(&work); 112 111 fail1: input_free_device(hp680_ts_dev); 113 112 return err; 114 113 } ··· 115 116 static void __exit hp680_ts_exit(void) 116 117 { 117 118 free_irq(HP680_TS_IRQ, NULL); 118 - cancel_delayed_work(&work); 119 - flush_scheduled_work(); 119 + cancel_delayed_work_sync(&work); 120 120 input_unregister_device(hp680_ts_dev); 121 121 } 122 122
+687
drivers/input/touchscreen/intel-mid-touch.c
··· 1 + /* 2 + * Intel MID Resistive Touch Screen Driver 3 + * 4 + * Copyright (C) 2008 Intel Corp 5 + * 6 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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; version 2 of the License. 11 + * 12 + * This program is distributed in the hope that it will be useful, but 13 + * WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 + * General Public License for more details. 16 + * 17 + * You should have received a copy of the GNU General Public License along 18 + * with this program; if not, write to the Free Software Foundation, Inc., 19 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 + * 21 + * Questions/Comments/Bug fixes to Sreedhara (sreedhara.ds@intel.com) 22 + * Ramesh Agarwal (ramesh.agarwal@intel.com) 23 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 + * 25 + * TODO: 26 + * review conversion of r/m/w sequences 27 + */ 28 + 29 + #include <linux/module.h> 30 + #include <linux/init.h> 31 + #include <linux/input.h> 32 + #include <linux/interrupt.h> 33 + #include <linux/err.h> 34 + #include <linux/param.h> 35 + #include <linux/slab.h> 36 + #include <linux/platform_device.h> 37 + #include <linux/irq.h> 38 + #include <linux/delay.h> 39 + #include <asm/intel_scu_ipc.h> 40 + 41 + /* PMIC Interrupt registers */ 42 + #define PMIC_REG_ID1 0x00 /* PMIC ID1 register */ 43 + 44 + /* PMIC Interrupt registers */ 45 + #define PMIC_REG_INT 0x04 /* PMIC interrupt register */ 46 + #define PMIC_REG_MINT 0x05 /* PMIC interrupt mask register */ 47 + 48 + /* ADC Interrupt registers */ 49 + #define PMIC_REG_ADCINT 0x5F /* ADC interrupt register */ 50 + #define PMIC_REG_MADCINT 0x60 /* ADC interrupt mask register */ 51 + 52 + /* ADC Control registers */ 53 + #define PMIC_REG_ADCCNTL1 0x61 /* ADC control register */ 54 + 55 + /* ADC Channel Selection registers */ 56 + #define PMICADDR0 0xA4 57 + #define END_OF_CHANNEL 0x1F 58 + 59 + /* ADC Result register */ 60 + #define PMIC_REG_ADCSNS0H 0x64 61 + 62 + /* ADC channels for touch screen */ 63 + #define MRST_TS_CHAN10 0xA /* Touch screen X+ connection */ 64 + #define MRST_TS_CHAN11 0xB /* Touch screen X- connection */ 65 + #define MRST_TS_CHAN12 0xC /* Touch screen Y+ connection */ 66 + #define MRST_TS_CHAN13 0xD /* Touch screen Y- connection */ 67 + 68 + /* Touch screen channel BIAS constants */ 69 + #define MRST_XBIAS 0x20 70 + #define MRST_YBIAS 0x40 71 + #define MRST_ZBIAS 0x80 72 + 73 + /* Touch screen coordinates */ 74 + #define MRST_X_MIN 10 75 + #define MRST_X_MAX 1024 76 + #define MRST_X_FUZZ 5 77 + #define MRST_Y_MIN 10 78 + #define MRST_Y_MAX 1024 79 + #define MRST_Y_FUZZ 5 80 + #define MRST_PRESSURE_MIN 0 81 + #define MRST_PRESSURE_NOMINAL 50 82 + #define MRST_PRESSURE_MAX 100 83 + 84 + #define WAIT_ADC_COMPLETION 10 /* msec */ 85 + 86 + /* PMIC ADC round robin delays */ 87 + #define ADC_LOOP_DELAY0 0x0 /* Continuous loop */ 88 + #define ADC_LOOP_DELAY1 0x1 /* 4.5 ms approximate */ 89 + 90 + /* PMIC Vendor Identifiers */ 91 + #define PMIC_VENDOR_FS 0 /* PMIC vendor FreeScale */ 92 + #define PMIC_VENDOR_MAXIM 1 /* PMIC vendor MAXIM */ 93 + #define PMIC_VENDOR_NEC 2 /* PMIC vendor NEC */ 94 + #define MRSTOUCH_MAX_CHANNELS 32 /* Maximum ADC channels */ 95 + 96 + /* Touch screen device structure */ 97 + struct mrstouch_dev { 98 + struct device *dev; /* device associated with touch screen */ 99 + struct input_dev *input; 100 + char phys[32]; 101 + u16 asr; /* Address selection register */ 102 + int irq; 103 + unsigned int vendor; /* PMIC vendor */ 104 + unsigned int rev; /* PMIC revision */ 105 + 106 + int (*read_prepare)(struct mrstouch_dev *tsdev); 107 + int (*read)(struct mrstouch_dev *tsdev, u16 *x, u16 *y, u16 *z); 108 + int (*read_finish)(struct mrstouch_dev *tsdev); 109 + }; 110 + 111 + 112 + /*************************** NEC and Maxim Interface ************************/ 113 + 114 + static int mrstouch_nec_adc_read_prepare(struct mrstouch_dev *tsdev) 115 + { 116 + return intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0, 0x20); 117 + } 118 + 119 + /* 120 + * Enables PENDET interrupt. 121 + */ 122 + static int mrstouch_nec_adc_read_finish(struct mrstouch_dev *tsdev) 123 + { 124 + int err; 125 + 126 + err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x20, 0x20); 127 + if (!err) 128 + err = intel_scu_ipc_update_register(PMIC_REG_ADCCNTL1, 0, 0x05); 129 + 130 + return err; 131 + } 132 + 133 + /* 134 + * Reads PMIC ADC touch screen result 135 + * Reads ADC storage registers for higher 7 and lower 3 bits and 136 + * converts the two readings into a single value and turns off gain bit 137 + */ 138 + static int mrstouch_ts_chan_read(u16 offset, u16 chan, u16 *vp, u16 *vm) 139 + { 140 + int err; 141 + u16 result; 142 + u32 res; 143 + 144 + result = PMIC_REG_ADCSNS0H + offset; 145 + 146 + if (chan == MRST_TS_CHAN12) 147 + result += 4; 148 + 149 + err = intel_scu_ipc_ioread32(result, &res); 150 + if (err) 151 + return err; 152 + 153 + /* Mash the bits up */ 154 + 155 + *vp = (res & 0xFF) << 3; /* Highest 7 bits */ 156 + *vp |= (res >> 8) & 0x07; /* Lower 3 bits */ 157 + *vp &= 0x3FF; 158 + 159 + res >>= 16; 160 + 161 + *vm = (res & 0xFF) << 3; /* Highest 7 bits */ 162 + *vm |= (res >> 8) & 0x07; /* Lower 3 bits */ 163 + *vm &= 0x3FF; 164 + 165 + return 0; 166 + } 167 + 168 + /* 169 + * Enables X, Y and Z bias values 170 + * Enables YPYM for X channels and XPXM for Y channels 171 + */ 172 + static int mrstouch_ts_bias_set(uint offset, uint bias) 173 + { 174 + int count; 175 + u16 chan, start; 176 + u16 reg[4]; 177 + u8 data[4]; 178 + 179 + chan = PMICADDR0 + offset; 180 + start = MRST_TS_CHAN10; 181 + 182 + for (count = 0; count <= 3; count++) { 183 + reg[count] = chan++; 184 + data[count] = bias | (start + count); 185 + } 186 + 187 + return intel_scu_ipc_writev(reg, data, 4); 188 + } 189 + 190 + /* To read touch screen channel values */ 191 + static int mrstouch_nec_adc_read(struct mrstouch_dev *tsdev, 192 + u16 *x, u16 *y, u16 *z) 193 + { 194 + int err; 195 + u16 xm, ym, zm; 196 + 197 + /* configure Y bias for X channels */ 198 + err = mrstouch_ts_bias_set(tsdev->asr, MRST_YBIAS); 199 + if (err) 200 + goto ipc_error; 201 + 202 + msleep(WAIT_ADC_COMPLETION); 203 + 204 + /* read x+ and x- channels */ 205 + err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN10, x, &xm); 206 + if (err) 207 + goto ipc_error; 208 + 209 + /* configure x bias for y channels */ 210 + err = mrstouch_ts_bias_set(tsdev->asr, MRST_XBIAS); 211 + if (err) 212 + goto ipc_error; 213 + 214 + msleep(WAIT_ADC_COMPLETION); 215 + 216 + /* read y+ and y- channels */ 217 + err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN12, y, &ym); 218 + if (err) 219 + goto ipc_error; 220 + 221 + /* configure z bias for x and y channels */ 222 + err = mrstouch_ts_bias_set(tsdev->asr, MRST_ZBIAS); 223 + if (err) 224 + goto ipc_error; 225 + 226 + msleep(WAIT_ADC_COMPLETION); 227 + 228 + /* read z+ and z- channels */ 229 + err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN10, z, &zm); 230 + if (err) 231 + goto ipc_error; 232 + 233 + return 0; 234 + 235 + ipc_error: 236 + dev_err(tsdev->dev, "ipc error during adc read\n"); 237 + return err; 238 + } 239 + 240 + 241 + /*************************** Freescale Interface ************************/ 242 + 243 + static int mrstouch_fs_adc_read_prepare(struct mrstouch_dev *tsdev) 244 + { 245 + int err, count; 246 + u16 chan; 247 + u16 reg[5]; 248 + u8 data[5]; 249 + 250 + /* Stop the ADC */ 251 + err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x00, 0x02); 252 + if (err) 253 + goto ipc_error; 254 + 255 + chan = PMICADDR0 + tsdev->asr; 256 + 257 + /* Set X BIAS */ 258 + for (count = 0; count <= 3; count++) { 259 + reg[count] = chan++; 260 + data[count] = 0x2A; 261 + } 262 + reg[count] = chan++; /* Dummy */ 263 + data[count] = 0; 264 + 265 + err = intel_scu_ipc_writev(reg, data, 5); 266 + if (err) 267 + goto ipc_error; 268 + 269 + msleep(WAIT_ADC_COMPLETION); 270 + 271 + /* Set Y BIAS */ 272 + for (count = 0; count <= 3; count++) { 273 + reg[count] = chan++; 274 + data[count] = 0x4A; 275 + } 276 + reg[count] = chan++; /* Dummy */ 277 + data[count] = 0; 278 + 279 + err = intel_scu_ipc_writev(reg, data, 5); 280 + if (err) 281 + goto ipc_error; 282 + 283 + msleep(WAIT_ADC_COMPLETION); 284 + 285 + /* Set Z BIAS */ 286 + err = intel_scu_ipc_iowrite32(chan + 2, 0x8A8A8A8A); 287 + if (err) 288 + goto ipc_error; 289 + 290 + msleep(WAIT_ADC_COMPLETION); 291 + 292 + return 0; 293 + 294 + ipc_error: 295 + dev_err(tsdev->dev, "ipc error during %s\n", __func__); 296 + return err; 297 + } 298 + 299 + static int mrstouch_fs_adc_read(struct mrstouch_dev *tsdev, 300 + u16 *x, u16 *y, u16 *z) 301 + { 302 + int err; 303 + u16 result; 304 + u16 reg[4]; 305 + u8 data[4]; 306 + 307 + result = PMIC_REG_ADCSNS0H + tsdev->asr; 308 + 309 + reg[0] = result + 4; 310 + reg[1] = result + 5; 311 + reg[2] = result + 16; 312 + reg[3] = result + 17; 313 + 314 + err = intel_scu_ipc_readv(reg, data, 4); 315 + if (err) 316 + goto ipc_error; 317 + 318 + *x = data[0] << 3; /* Higher 7 bits */ 319 + *x |= data[1] & 0x7; /* Lower 3 bits */ 320 + *x &= 0x3FF; 321 + 322 + *y = data[2] << 3; /* Higher 7 bits */ 323 + *y |= data[3] & 0x7; /* Lower 3 bits */ 324 + *y &= 0x3FF; 325 + 326 + /* Read Z value */ 327 + reg[0] = result + 28; 328 + reg[1] = result + 29; 329 + 330 + err = intel_scu_ipc_readv(reg, data, 4); 331 + if (err) 332 + goto ipc_error; 333 + 334 + *z = data[0] << 3; /* Higher 7 bits */ 335 + *z |= data[1] & 0x7; /* Lower 3 bits */ 336 + *z &= 0x3FF; 337 + 338 + return 0; 339 + 340 + ipc_error: 341 + dev_err(tsdev->dev, "ipc error during %s\n", __func__); 342 + return err; 343 + } 344 + 345 + static int mrstouch_fs_adc_read_finish(struct mrstouch_dev *tsdev) 346 + { 347 + int err, count; 348 + u16 chan; 349 + u16 reg[5]; 350 + u8 data[5]; 351 + 352 + /* Clear all TS channels */ 353 + chan = PMICADDR0 + tsdev->asr; 354 + for (count = 0; count <= 4; count++) { 355 + reg[count] = chan++; 356 + data[count] = 0; 357 + } 358 + err = intel_scu_ipc_writev(reg, data, 5); 359 + if (err) 360 + goto ipc_error; 361 + 362 + for (count = 0; count <= 4; count++) { 363 + reg[count] = chan++; 364 + data[count] = 0; 365 + } 366 + err = intel_scu_ipc_writev(reg, data, 5); 367 + if (err) 368 + goto ipc_error; 369 + 370 + err = intel_scu_ipc_iowrite32(chan + 2, 0x00000000); 371 + if (err) 372 + goto ipc_error; 373 + 374 + /* Start ADC */ 375 + err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x02, 0x02); 376 + if (err) 377 + goto ipc_error; 378 + 379 + return 0; 380 + 381 + ipc_error: 382 + dev_err(tsdev->dev, "ipc error during %s\n", __func__); 383 + return err; 384 + } 385 + 386 + static void mrstouch_report_event(struct input_dev *input, 387 + unsigned int x, unsigned int y, unsigned int z) 388 + { 389 + if (z > MRST_PRESSURE_NOMINAL) { 390 + /* Pen touched, report button touch and coordinates */ 391 + input_report_key(input, BTN_TOUCH, 1); 392 + input_report_abs(input, ABS_X, x); 393 + input_report_abs(input, ABS_Y, y); 394 + } else { 395 + input_report_key(input, BTN_TOUCH, 0); 396 + } 397 + 398 + input_report_abs(input, ABS_PRESSURE, z); 399 + input_sync(input); 400 + } 401 + 402 + /* PENDET interrupt handler */ 403 + static irqreturn_t mrstouch_pendet_irq(int irq, void *dev_id) 404 + { 405 + struct mrstouch_dev *tsdev = dev_id; 406 + u16 x, y, z; 407 + 408 + /* 409 + * Should we lower thread priority? Probably not, since we are 410 + * not spinning but sleeping... 411 + */ 412 + 413 + if (tsdev->read_prepare(tsdev)) 414 + goto out; 415 + 416 + do { 417 + if (tsdev->read(tsdev, &x, &y, &z)) 418 + break; 419 + 420 + mrstouch_report_event(tsdev->input, x, y, z); 421 + } while (z > MRST_PRESSURE_NOMINAL); 422 + 423 + tsdev->read_finish(tsdev); 424 + 425 + out: 426 + return IRQ_HANDLED; 427 + } 428 + 429 + /* Utility to read PMIC ID */ 430 + static int __devinit mrstouch_read_pmic_id(uint *vendor, uint *rev) 431 + { 432 + int err; 433 + u8 r; 434 + 435 + err = intel_scu_ipc_ioread8(PMIC_REG_ID1, &r); 436 + if (err) 437 + return err; 438 + 439 + *vendor = r & 0x7; 440 + *rev = (r >> 3) & 0x7; 441 + 442 + return 0; 443 + } 444 + 445 + /* 446 + * Parse ADC channels to find end of the channel configured by other ADC user 447 + * NEC and MAXIM requires 4 channels and FreeScale needs 18 channels 448 + */ 449 + static int __devinit mrstouch_chan_parse(struct mrstouch_dev *tsdev) 450 + { 451 + int err, i, found; 452 + u8 r8; 453 + 454 + found = -1; 455 + 456 + for (i = 0; i < MRSTOUCH_MAX_CHANNELS; i++) { 457 + if (found >= 0) 458 + break; 459 + 460 + err = intel_scu_ipc_ioread8(PMICADDR0 + i, &r8); 461 + if (err) 462 + return err; 463 + 464 + if (r8 == END_OF_CHANNEL) { 465 + found = i; 466 + break; 467 + } 468 + } 469 + if (found < 0) 470 + return 0; 471 + 472 + if (tsdev->vendor == PMIC_VENDOR_FS) { 473 + if (found && found > (MRSTOUCH_MAX_CHANNELS - 18)) 474 + return -ENOSPC; 475 + } else { 476 + if (found && found > (MRSTOUCH_MAX_CHANNELS - 4)) 477 + return -ENOSPC; 478 + } 479 + return found; 480 + } 481 + 482 + 483 + /* 484 + * Writes touch screen channels to ADC address selection registers 485 + */ 486 + static int __devinit mrstouch_ts_chan_set(uint offset) 487 + { 488 + u16 chan; 489 + 490 + int ret, count; 491 + 492 + chan = PMICADDR0 + offset; 493 + for (count = 0; count <= 3; count++) { 494 + ret = intel_scu_ipc_iowrite8(chan++, MRST_TS_CHAN10 + count); 495 + if (ret) 496 + return ret; 497 + } 498 + return intel_scu_ipc_iowrite8(chan++, END_OF_CHANNEL); 499 + } 500 + 501 + /* Initialize ADC */ 502 + static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev) 503 + { 504 + int err, start; 505 + u8 ra, rm; 506 + 507 + err = mrstouch_read_pmic_id(&tsdev->vendor, &tsdev->rev); 508 + if (err) { 509 + dev_err(tsdev->dev, "Unable to read PMIC id\n"); 510 + return err; 511 + } 512 + 513 + switch (tsdev->vendor) { 514 + case PMIC_VENDOR_NEC: 515 + case PMIC_VENDOR_MAXIM: 516 + tsdev->read_prepare = mrstouch_nec_adc_read_prepare; 517 + tsdev->read = mrstouch_nec_adc_read; 518 + tsdev->read_finish = mrstouch_nec_adc_read_finish; 519 + break; 520 + 521 + case PMIC_VENDOR_FS: 522 + tsdev->read_prepare = mrstouch_fs_adc_read_prepare; 523 + tsdev->read = mrstouch_fs_adc_read; 524 + tsdev->read_finish = mrstouch_fs_adc_read_finish; 525 + break; 526 + 527 + default: 528 + dev_err(tsdev->dev, 529 + "Unsupported touchscreen: %d\n", tsdev->vendor); 530 + return -ENXIO; 531 + } 532 + 533 + start = mrstouch_chan_parse(tsdev); 534 + if (start < 0) { 535 + dev_err(tsdev->dev, "Unable to parse channels\n"); 536 + return start; 537 + } 538 + 539 + tsdev->asr = start; 540 + 541 + /* 542 + * ADC power on, start, enable PENDET and set loop delay 543 + * ADC loop delay is set to 4.5 ms approximately 544 + * Loop delay more than this results in jitter in adc readings 545 + * Setting loop delay to 0 (continous loop) in MAXIM stops PENDET 546 + * interrupt generation sometimes. 547 + */ 548 + 549 + if (tsdev->vendor == PMIC_VENDOR_FS) { 550 + ra = 0xE0 | ADC_LOOP_DELAY0; 551 + rm = 0x5; 552 + } else { 553 + /* NEC and MAXIm not consistent with loop delay 0 */ 554 + ra = 0xE0 | ADC_LOOP_DELAY1; 555 + rm = 0x0; 556 + 557 + /* configure touch screen channels */ 558 + err = mrstouch_ts_chan_set(tsdev->asr); 559 + if (err) 560 + return err; 561 + } 562 + 563 + err = intel_scu_ipc_update_register(PMIC_REG_ADCCNTL1, ra, 0xE7); 564 + if (err) 565 + return err; 566 + 567 + err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, rm, 0x03); 568 + if (err) 569 + return err; 570 + 571 + return 0; 572 + } 573 + 574 + 575 + /* Probe function for touch screen driver */ 576 + static int __devinit mrstouch_probe(struct platform_device *pdev) 577 + { 578 + struct mrstouch_dev *tsdev; 579 + struct input_dev *input; 580 + int err; 581 + int irq; 582 + 583 + irq = platform_get_irq(pdev, 0); 584 + if (irq < 0) { 585 + dev_err(&pdev->dev, "no interrupt assigned\n"); 586 + return -EINVAL; 587 + } 588 + 589 + tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL); 590 + input = input_allocate_device(); 591 + if (!tsdev || !input) { 592 + dev_err(&pdev->dev, "unable to allocate memory\n"); 593 + err = -ENOMEM; 594 + goto err_free_mem; 595 + } 596 + 597 + tsdev->dev = &pdev->dev; 598 + tsdev->input = input; 599 + tsdev->irq = irq; 600 + 601 + snprintf(tsdev->phys, sizeof(tsdev->phys), 602 + "%s/input0", dev_name(tsdev->dev)); 603 + 604 + err = mrstouch_adc_init(tsdev); 605 + if (err) { 606 + dev_err(&pdev->dev, "ADC initialization failed\n"); 607 + goto err_free_mem; 608 + } 609 + 610 + input->name = "mrst_touchscreen"; 611 + input->phys = tsdev->phys; 612 + input->dev.parent = tsdev->dev; 613 + 614 + input->id.vendor = tsdev->vendor; 615 + input->id.version = tsdev->rev; 616 + 617 + input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 618 + input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 619 + 620 + input_set_abs_params(tsdev->input, ABS_X, 621 + MRST_X_MIN, MRST_X_MAX, MRST_X_FUZZ, 0); 622 + input_set_abs_params(tsdev->input, ABS_Y, 623 + MRST_Y_MIN, MRST_Y_MAX, MRST_Y_FUZZ, 0); 624 + input_set_abs_params(tsdev->input, ABS_PRESSURE, 625 + MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0); 626 + 627 + err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq, 628 + 0, "mrstouch", tsdev); 629 + if (err) { 630 + dev_err(tsdev->dev, "unable to allocate irq\n"); 631 + goto err_free_mem; 632 + } 633 + 634 + err = input_register_device(tsdev->input); 635 + if (err) { 636 + dev_err(tsdev->dev, "unable to register input device\n"); 637 + goto err_free_irq; 638 + } 639 + 640 + platform_set_drvdata(pdev, tsdev); 641 + return 0; 642 + 643 + err_free_irq: 644 + free_irq(tsdev->irq, tsdev); 645 + err_free_mem: 646 + input_free_device(input); 647 + kfree(tsdev); 648 + return err; 649 + } 650 + 651 + static int __devexit mrstouch_remove(struct platform_device *pdev) 652 + { 653 + struct mrstouch_dev *tsdev = platform_get_drvdata(pdev); 654 + 655 + free_irq(tsdev->irq, tsdev); 656 + input_unregister_device(tsdev->input); 657 + kfree(tsdev); 658 + 659 + platform_set_drvdata(pdev, NULL); 660 + 661 + return 0; 662 + } 663 + 664 + static struct platform_driver mrstouch_driver = { 665 + .driver = { 666 + .name = "pmic_touch", 667 + .owner = THIS_MODULE, 668 + }, 669 + .probe = mrstouch_probe, 670 + .remove = __devexit_p(mrstouch_remove), 671 + }; 672 + 673 + static int __init mrstouch_init(void) 674 + { 675 + return platform_driver_register(&mrstouch_driver); 676 + } 677 + module_init(mrstouch_init); 678 + 679 + static void __exit mrstouch_exit(void) 680 + { 681 + platform_driver_unregister(&mrstouch_driver); 682 + } 683 + module_exit(mrstouch_exit); 684 + 685 + MODULE_AUTHOR("Sreedhara Murthy. D.S, sreedhara.ds@intel.com"); 686 + MODULE_DESCRIPTION("Intel Moorestown Resistive Touch Screen Driver"); 687 + MODULE_LICENSE("GPL");
+411
drivers/input/touchscreen/lpc32xx_ts.c
··· 1 + /* 2 + * LPC32xx built-in touchscreen driver 3 + * 4 + * Copyright (C) 2010 NXP Semiconductors 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/platform_device.h> 18 + #include <linux/init.h> 19 + #include <linux/input.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/module.h> 22 + #include <linux/clk.h> 23 + #include <linux/io.h> 24 + #include <linux/slab.h> 25 + 26 + /* 27 + * Touchscreen controller register offsets 28 + */ 29 + #define LPC32XX_TSC_STAT 0x00 30 + #define LPC32XX_TSC_SEL 0x04 31 + #define LPC32XX_TSC_CON 0x08 32 + #define LPC32XX_TSC_FIFO 0x0C 33 + #define LPC32XX_TSC_DTR 0x10 34 + #define LPC32XX_TSC_RTR 0x14 35 + #define LPC32XX_TSC_UTR 0x18 36 + #define LPC32XX_TSC_TTR 0x1C 37 + #define LPC32XX_TSC_DXP 0x20 38 + #define LPC32XX_TSC_MIN_X 0x24 39 + #define LPC32XX_TSC_MAX_X 0x28 40 + #define LPC32XX_TSC_MIN_Y 0x2C 41 + #define LPC32XX_TSC_MAX_Y 0x30 42 + #define LPC32XX_TSC_AUX_UTR 0x34 43 + #define LPC32XX_TSC_AUX_MIN 0x38 44 + #define LPC32XX_TSC_AUX_MAX 0x3C 45 + 46 + #define LPC32XX_TSC_STAT_FIFO_OVRRN (1 << 8) 47 + #define LPC32XX_TSC_STAT_FIFO_EMPTY (1 << 7) 48 + 49 + #define LPC32XX_TSC_SEL_DEFVAL 0x0284 50 + 51 + #define LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 (0x1 << 11) 52 + #define LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(s) ((10 - (s)) << 7) 53 + #define LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(s) ((10 - (s)) << 4) 54 + #define LPC32XX_TSC_ADCCON_POWER_UP (1 << 2) 55 + #define LPC32XX_TSC_ADCCON_AUTO_EN (1 << 0) 56 + 57 + #define LPC32XX_TSC_FIFO_TS_P_LEVEL (1 << 31) 58 + #define LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(x) (((x) & 0x03FF0000) >> 16) 59 + #define LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(y) ((y) & 0x000003FF) 60 + 61 + #define LPC32XX_TSC_ADCDAT_VALUE_MASK 0x000003FF 62 + 63 + #define LPC32XX_TSC_MIN_XY_VAL 0x0 64 + #define LPC32XX_TSC_MAX_XY_VAL 0x3FF 65 + 66 + #define MOD_NAME "ts-lpc32xx" 67 + 68 + #define tsc_readl(dev, reg) \ 69 + __raw_readl((dev)->tsc_base + (reg)) 70 + #define tsc_writel(dev, reg, val) \ 71 + __raw_writel((val), (dev)->tsc_base + (reg)) 72 + 73 + struct lpc32xx_tsc { 74 + struct input_dev *dev; 75 + void __iomem *tsc_base; 76 + int irq; 77 + struct clk *clk; 78 + }; 79 + 80 + static void lpc32xx_fifo_clear(struct lpc32xx_tsc *tsc) 81 + { 82 + while (!(tsc_readl(tsc, LPC32XX_TSC_STAT) & 83 + LPC32XX_TSC_STAT_FIFO_EMPTY)) 84 + tsc_readl(tsc, LPC32XX_TSC_FIFO); 85 + } 86 + 87 + static irqreturn_t lpc32xx_ts_interrupt(int irq, void *dev_id) 88 + { 89 + u32 tmp, rv[4], xs[4], ys[4]; 90 + int idx; 91 + struct lpc32xx_tsc *tsc = dev_id; 92 + struct input_dev *input = tsc->dev; 93 + 94 + tmp = tsc_readl(tsc, LPC32XX_TSC_STAT); 95 + 96 + if (tmp & LPC32XX_TSC_STAT_FIFO_OVRRN) { 97 + /* FIFO overflow - throw away samples */ 98 + lpc32xx_fifo_clear(tsc); 99 + return IRQ_HANDLED; 100 + } 101 + 102 + /* 103 + * Gather and normalize 4 samples. Pen-up events may have less 104 + * than 4 samples, but its ok to pop 4 and let the last sample 105 + * pen status check drop the samples. 106 + */ 107 + idx = 0; 108 + while (idx < 4 && 109 + !(tsc_readl(tsc, LPC32XX_TSC_STAT) & 110 + LPC32XX_TSC_STAT_FIFO_EMPTY)) { 111 + tmp = tsc_readl(tsc, LPC32XX_TSC_FIFO); 112 + xs[idx] = LPC32XX_TSC_ADCDAT_VALUE_MASK - 113 + LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(tmp); 114 + ys[idx] = LPC32XX_TSC_ADCDAT_VALUE_MASK - 115 + LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(tmp); 116 + rv[idx] = tmp; 117 + idx++; 118 + } 119 + 120 + /* Data is only valid if pen is still down in last sample */ 121 + if (!(rv[3] & LPC32XX_TSC_FIFO_TS_P_LEVEL) && idx == 4) { 122 + /* Use average of 2nd and 3rd sample for position */ 123 + input_report_abs(input, ABS_X, (xs[1] + xs[2]) / 2); 124 + input_report_abs(input, ABS_Y, (ys[1] + ys[2]) / 2); 125 + input_report_key(input, BTN_TOUCH, 1); 126 + } else { 127 + input_report_key(input, BTN_TOUCH, 0); 128 + } 129 + 130 + input_sync(input); 131 + 132 + return IRQ_HANDLED; 133 + } 134 + 135 + static void lpc32xx_stop_tsc(struct lpc32xx_tsc *tsc) 136 + { 137 + /* Disable auto mode */ 138 + tsc_writel(tsc, LPC32XX_TSC_CON, 139 + tsc_readl(tsc, LPC32XX_TSC_CON) & 140 + ~LPC32XX_TSC_ADCCON_AUTO_EN); 141 + 142 + clk_disable(tsc->clk); 143 + } 144 + 145 + static void lpc32xx_setup_tsc(struct lpc32xx_tsc *tsc) 146 + { 147 + u32 tmp; 148 + 149 + clk_enable(tsc->clk); 150 + 151 + tmp = tsc_readl(tsc, LPC32XX_TSC_CON) & ~LPC32XX_TSC_ADCCON_POWER_UP; 152 + 153 + /* Set the TSC FIFO depth to 4 samples @ 10-bits per sample (max) */ 154 + tmp = LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 | 155 + LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(10) | 156 + LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(10); 157 + tsc_writel(tsc, LPC32XX_TSC_CON, tmp); 158 + 159 + /* These values are all preset */ 160 + tsc_writel(tsc, LPC32XX_TSC_SEL, LPC32XX_TSC_SEL_DEFVAL); 161 + tsc_writel(tsc, LPC32XX_TSC_MIN_X, LPC32XX_TSC_MIN_XY_VAL); 162 + tsc_writel(tsc, LPC32XX_TSC_MAX_X, LPC32XX_TSC_MAX_XY_VAL); 163 + tsc_writel(tsc, LPC32XX_TSC_MIN_Y, LPC32XX_TSC_MIN_XY_VAL); 164 + tsc_writel(tsc, LPC32XX_TSC_MAX_Y, LPC32XX_TSC_MAX_XY_VAL); 165 + 166 + /* Aux support is not used */ 167 + tsc_writel(tsc, LPC32XX_TSC_AUX_UTR, 0); 168 + tsc_writel(tsc, LPC32XX_TSC_AUX_MIN, 0); 169 + tsc_writel(tsc, LPC32XX_TSC_AUX_MAX, 0); 170 + 171 + /* 172 + * Set sample rate to about 240Hz per X/Y pair. A single measurement 173 + * consists of 4 pairs which gives about a 60Hz sample rate based on 174 + * a stable 32768Hz clock source. Values are in clocks. 175 + * Rate is (32768 / (RTR + XCONV + RTR + YCONV + DXP + TTR + UTR) / 4 176 + */ 177 + tsc_writel(tsc, LPC32XX_TSC_RTR, 0x2); 178 + tsc_writel(tsc, LPC32XX_TSC_DTR, 0x2); 179 + tsc_writel(tsc, LPC32XX_TSC_TTR, 0x10); 180 + tsc_writel(tsc, LPC32XX_TSC_DXP, 0x4); 181 + tsc_writel(tsc, LPC32XX_TSC_UTR, 88); 182 + 183 + lpc32xx_fifo_clear(tsc); 184 + 185 + /* Enable automatic ts event capture */ 186 + tsc_writel(tsc, LPC32XX_TSC_CON, tmp | LPC32XX_TSC_ADCCON_AUTO_EN); 187 + } 188 + 189 + static int lpc32xx_ts_open(struct input_dev *dev) 190 + { 191 + struct lpc32xx_tsc *tsc = input_get_drvdata(dev); 192 + 193 + lpc32xx_setup_tsc(tsc); 194 + 195 + return 0; 196 + } 197 + 198 + static void lpc32xx_ts_close(struct input_dev *dev) 199 + { 200 + struct lpc32xx_tsc *tsc = input_get_drvdata(dev); 201 + 202 + lpc32xx_stop_tsc(tsc); 203 + } 204 + 205 + static int __devinit lpc32xx_ts_probe(struct platform_device *pdev) 206 + { 207 + struct lpc32xx_tsc *tsc; 208 + struct input_dev *input; 209 + struct resource *res; 210 + resource_size_t size; 211 + int irq; 212 + int error; 213 + 214 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 215 + if (!res) { 216 + dev_err(&pdev->dev, "Can't get memory resource\n"); 217 + return -ENOENT; 218 + } 219 + 220 + irq = platform_get_irq(pdev, 0); 221 + if (irq < 0) { 222 + dev_err(&pdev->dev, "Can't get interrupt resource\n"); 223 + return irq; 224 + } 225 + 226 + tsc = kzalloc(sizeof(*tsc), GFP_KERNEL); 227 + input = input_allocate_device(); 228 + if (!tsc || !input) { 229 + dev_err(&pdev->dev, "failed allocating memory\n"); 230 + error = -ENOMEM; 231 + goto err_free_mem; 232 + } 233 + 234 + tsc->dev = input; 235 + tsc->irq = irq; 236 + 237 + size = resource_size(res); 238 + 239 + if (!request_mem_region(res->start, size, pdev->name)) { 240 + dev_err(&pdev->dev, "TSC registers are not free\n"); 241 + error = -EBUSY; 242 + goto err_free_mem; 243 + } 244 + 245 + tsc->tsc_base = ioremap(res->start, size); 246 + if (!tsc->tsc_base) { 247 + dev_err(&pdev->dev, "Can't map memory\n"); 248 + error = -ENOMEM; 249 + goto err_release_mem; 250 + } 251 + 252 + tsc->clk = clk_get(&pdev->dev, NULL); 253 + if (IS_ERR(tsc->clk)) { 254 + dev_err(&pdev->dev, "failed getting clock\n"); 255 + error = PTR_ERR(tsc->clk); 256 + goto err_unmap; 257 + } 258 + 259 + input->name = MOD_NAME; 260 + input->phys = "lpc32xx/input0"; 261 + input->id.bustype = BUS_HOST; 262 + input->id.vendor = 0x0001; 263 + input->id.product = 0x0002; 264 + input->id.version = 0x0100; 265 + input->dev.parent = &pdev->dev; 266 + input->open = lpc32xx_ts_open; 267 + input->close = lpc32xx_ts_close; 268 + 269 + input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 270 + input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 271 + input_set_abs_params(input, ABS_X, LPC32XX_TSC_MIN_XY_VAL, 272 + LPC32XX_TSC_MAX_XY_VAL, 0, 0); 273 + input_set_abs_params(input, ABS_Y, LPC32XX_TSC_MIN_XY_VAL, 274 + LPC32XX_TSC_MAX_XY_VAL, 0, 0); 275 + 276 + input_set_drvdata(input, tsc); 277 + 278 + error = request_irq(tsc->irq, lpc32xx_ts_interrupt, 279 + IRQF_DISABLED, pdev->name, tsc); 280 + if (error) { 281 + dev_err(&pdev->dev, "failed requesting interrupt\n"); 282 + goto err_put_clock; 283 + } 284 + 285 + error = input_register_device(input); 286 + if (error) { 287 + dev_err(&pdev->dev, "failed registering input device\n"); 288 + goto err_free_irq; 289 + } 290 + 291 + platform_set_drvdata(pdev, tsc); 292 + device_init_wakeup(&pdev->dev, 1); 293 + 294 + return 0; 295 + 296 + err_free_irq: 297 + free_irq(tsc->irq, tsc); 298 + err_put_clock: 299 + clk_put(tsc->clk); 300 + err_unmap: 301 + iounmap(tsc->tsc_base); 302 + err_release_mem: 303 + release_mem_region(res->start, size); 304 + err_free_mem: 305 + input_free_device(input); 306 + kfree(tsc); 307 + 308 + return error; 309 + } 310 + 311 + static int __devexit lpc32xx_ts_remove(struct platform_device *pdev) 312 + { 313 + struct lpc32xx_tsc *tsc = platform_get_drvdata(pdev); 314 + struct resource *res; 315 + 316 + device_init_wakeup(&pdev->dev, 0); 317 + free_irq(tsc->irq, tsc); 318 + 319 + input_unregister_device(tsc->dev); 320 + 321 + clk_put(tsc->clk); 322 + 323 + iounmap(tsc->tsc_base); 324 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 325 + release_mem_region(res->start, resource_size(res)); 326 + 327 + kfree(tsc); 328 + 329 + return 0; 330 + } 331 + 332 + #ifdef CONFIG_PM 333 + static int lpc32xx_ts_suspend(struct device *dev) 334 + { 335 + struct lpc32xx_tsc *tsc = dev_get_drvdata(dev); 336 + struct input_dev *input = tsc->dev; 337 + 338 + /* 339 + * Suspend and resume can be called when the device hasn't been 340 + * enabled. If there are no users that have the device open, then 341 + * avoid calling the TSC stop and start functions as the TSC 342 + * isn't yet clocked. 343 + */ 344 + mutex_lock(&input->mutex); 345 + 346 + if (input->users) { 347 + if (device_may_wakeup(dev)) 348 + enable_irq_wake(tsc->irq); 349 + else 350 + lpc32xx_stop_tsc(tsc); 351 + } 352 + 353 + mutex_unlock(&input->mutex); 354 + 355 + return 0; 356 + } 357 + 358 + static int lpc32xx_ts_resume(struct device *dev) 359 + { 360 + struct lpc32xx_tsc *tsc = dev_get_drvdata(dev); 361 + struct input_dev *input = tsc->dev; 362 + 363 + mutex_lock(&input->mutex); 364 + 365 + if (input->users) { 366 + if (device_may_wakeup(dev)) 367 + disable_irq_wake(tsc->irq); 368 + else 369 + lpc32xx_setup_tsc(tsc); 370 + } 371 + 372 + mutex_unlock(&input->mutex); 373 + 374 + return 0; 375 + } 376 + 377 + static const struct dev_pm_ops lpc32xx_ts_pm_ops = { 378 + .suspend = lpc32xx_ts_suspend, 379 + .resume = lpc32xx_ts_resume, 380 + }; 381 + #define LPC32XX_TS_PM_OPS (&lpc32xx_ts_pm_ops) 382 + #else 383 + #define LPC32XX_TS_PM_OPS NULL 384 + #endif 385 + 386 + static struct platform_driver lpc32xx_ts_driver = { 387 + .probe = lpc32xx_ts_probe, 388 + .remove = __devexit_p(lpc32xx_ts_remove), 389 + .driver = { 390 + .name = MOD_NAME, 391 + .owner = THIS_MODULE, 392 + .pm = LPC32XX_TS_PM_OPS, 393 + }, 394 + }; 395 + 396 + static int __init lpc32xx_ts_init(void) 397 + { 398 + return platform_driver_register(&lpc32xx_ts_driver); 399 + } 400 + module_init(lpc32xx_ts_init); 401 + 402 + static void __exit lpc32xx_ts_exit(void) 403 + { 404 + platform_driver_unregister(&lpc32xx_ts_driver); 405 + } 406 + module_exit(lpc32xx_ts_exit); 407 + 408 + MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com"); 409 + MODULE_DESCRIPTION("LPC32XX TSC Driver"); 410 + MODULE_LICENSE("GPL"); 411 + MODULE_ALIAS("platform:lpc32xx_ts");
+1 -1
drivers/input/touchscreen/s3c2410_ts.c
··· 350 350 err_tcirq: 351 351 free_irq(ts.irq_tc, ts.input); 352 352 err_inputdev: 353 - input_unregister_device(ts.input); 353 + input_free_device(ts.input); 354 354 err_iomap: 355 355 iounmap(ts.io); 356 356 err_clk:
+7 -4
drivers/input/touchscreen/stmpe-ts.c
··· 268 268 struct stmpe_touch *ts; 269 269 struct input_dev *idev; 270 270 struct stmpe_ts_platform_data *ts_pdata = NULL; 271 - int ret = 0; 271 + int ret; 272 272 int ts_irq; 273 273 274 274 ts_irq = platform_get_irq_byname(pdev, "FIFO_TH"); ··· 276 276 return ts_irq; 277 277 278 278 ts = kzalloc(sizeof(*ts), GFP_KERNEL); 279 - if (!ts) 279 + if (!ts) { 280 + ret = -ENOMEM; 280 281 goto err_out; 282 + } 281 283 282 284 idev = input_allocate_device(); 283 - if (!idev) 285 + if (!idev) { 286 + ret = -ENOMEM; 284 287 goto err_free_ts; 288 + } 285 289 286 290 platform_set_drvdata(pdev, ts); 287 291 ts->stmpe = stmpe; ··· 365 361 platform_set_drvdata(pdev, NULL); 366 362 367 363 input_unregister_device(ts->idev); 368 - input_free_device(ts->idev); 369 364 370 365 kfree(ts); 371 366
+2 -1
drivers/input/touchscreen/tps6507x-ts.c
··· 335 335 dev_err(tsc->dev, "schedule failed"); 336 336 goto err2; 337 337 } 338 + platform_set_drvdata(pdev, tps6507x_dev); 338 339 339 340 return 0; 340 341 ··· 359 358 cancel_delayed_work_sync(&tsc->work); 360 359 destroy_workqueue(tsc->wq); 361 360 362 - input_free_device(input_dev); 361 + input_unregister_device(input_dev); 363 362 364 363 tps6507x_dev->ts = NULL; 365 364 kfree(tsc);
+1 -1
drivers/input/touchscreen/tsc2007.c
··· 265 265 const struct i2c_device_id *id) 266 266 { 267 267 struct tsc2007 *ts; 268 - struct tsc2007_platform_data *pdata = pdata = client->dev.platform_data; 268 + struct tsc2007_platform_data *pdata = client->dev.platform_data; 269 269 struct input_dev *input_dev; 270 270 int err; 271 271
+177 -8
drivers/input/touchscreen/wacom_w8001.c
··· 2 2 * Wacom W8001 penabled serial touchscreen driver 3 3 * 4 4 * Copyright (c) 2008 Jaya Kumar 5 + * Copyright (c) 2010 Red Hat, Inc. 5 6 * 6 7 * This file is subject to the terms and conditions of the GNU General Public 7 8 * License. See the file COPYING in the main directory of this archive for ··· 31 30 #define W8001_LEAD_BYTE 0x80 32 31 #define W8001_TAB_MASK 0x40 33 32 #define W8001_TAB_BYTE 0x40 33 + /* set in first byte of touch data packets */ 34 + #define W8001_TOUCH_MASK (0x10 | W8001_LEAD_MASK) 35 + #define W8001_TOUCH_BYTE (0x10 | W8001_LEAD_BYTE) 34 36 35 37 #define W8001_QUERY_PACKET 0x20 36 38 37 39 #define W8001_CMD_START '1' 38 40 #define W8001_CMD_QUERY '*' 41 + #define W8001_CMD_TOUCHQUERY '%' 42 + 43 + /* length of data packets in bytes, depends on device. */ 44 + #define W8001_PKTLEN_TOUCH93 5 45 + #define W8001_PKTLEN_TOUCH9A 7 46 + #define W8001_PKTLEN_TPCPEN 9 47 + #define W8001_PKTLEN_TPCCTL 11 /* control packet */ 48 + #define W8001_PKTLEN_TOUCH2FG 13 49 + 50 + #define MAX_TRACKING_ID 0xFF /* arbitrarily chosen */ 39 51 40 52 struct w8001_coord { 41 53 u8 rdy; ··· 60 46 u16 pen_pressure; 61 47 u8 tilt_x; 62 48 u8 tilt_y; 49 + }; 50 + 51 + /* touch query reply packet */ 52 + struct w8001_touch_query { 53 + u8 panel_res; 54 + u8 capacity_res; 55 + u8 sensor_id; 56 + u16 x; 57 + u16 y; 63 58 }; 64 59 65 60 /* ··· 85 62 unsigned char response[W8001_MAX_LENGTH]; 86 63 unsigned char data[W8001_MAX_LENGTH]; 87 64 char phys[32]; 65 + int type; 66 + unsigned int pktlen; 67 + int trkid[2]; 88 68 }; 89 69 90 70 static void parse_data(u8 *data, struct w8001_coord *coord) ··· 114 88 coord->tilt_y = data[8] & 0x7F; 115 89 } 116 90 91 + static void parse_touch(struct w8001 *w8001) 92 + { 93 + static int trkid; 94 + struct input_dev *dev = w8001->dev; 95 + unsigned char *data = w8001->data; 96 + int i; 97 + 98 + for (i = 0; i < 2; i++) { 99 + input_mt_slot(dev, i); 100 + 101 + if (data[0] & (1 << i)) { 102 + int x = (data[6 * i + 1] << 7) | (data[6 * i + 2]); 103 + int y = (data[6 * i + 3] << 7) | (data[6 * i + 4]); 104 + /* data[5,6] and [11,12] is finger capacity */ 105 + 106 + input_report_abs(dev, ABS_MT_POSITION_X, x); 107 + input_report_abs(dev, ABS_MT_POSITION_Y, y); 108 + input_report_abs(dev, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); 109 + if (w8001->trkid[i] < 0) 110 + w8001->trkid[i] = trkid++ & MAX_TRACKING_ID; 111 + } else { 112 + w8001->trkid[i] = -1; 113 + } 114 + input_report_abs(dev, ABS_MT_TRACKING_ID, w8001->trkid[i]); 115 + } 116 + 117 + input_sync(dev); 118 + } 119 + 120 + static void parse_touchquery(u8 *data, struct w8001_touch_query *query) 121 + { 122 + memset(query, 0, sizeof(*query)); 123 + 124 + query->panel_res = data[1]; 125 + query->sensor_id = data[2] & 0x7; 126 + query->capacity_res = data[7]; 127 + 128 + query->x = data[3] << 9; 129 + query->x |= data[4] << 2; 130 + query->x |= (data[2] >> 5) & 0x3; 131 + 132 + query->y = data[5] << 9; 133 + query->y |= data[6] << 2; 134 + query->y |= (data[2] >> 3) & 0x3; 135 + } 136 + 137 + static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord) 138 + { 139 + struct input_dev *dev = w8001->dev; 140 + 141 + /* 142 + * We have 1 bit for proximity (rdy) and 3 bits for tip, side, 143 + * side2/eraser. If rdy && f2 are set, this can be either pen + side2, 144 + * or eraser. assume 145 + * - if dev is already in proximity and f2 is toggled → pen + side2 146 + * - if dev comes into proximity with f2 set → eraser 147 + * If f2 disappears after assuming eraser, fake proximity out for 148 + * eraser and in for pen. 149 + */ 150 + 151 + if (!w8001->type) { 152 + w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 153 + } else if (w8001->type == BTN_TOOL_RUBBER) { 154 + if (!coord->f2) { 155 + input_report_abs(dev, ABS_PRESSURE, 0); 156 + input_report_key(dev, BTN_TOUCH, 0); 157 + input_report_key(dev, BTN_STYLUS, 0); 158 + input_report_key(dev, BTN_STYLUS2, 0); 159 + input_report_key(dev, BTN_TOOL_RUBBER, 0); 160 + input_sync(dev); 161 + w8001->type = BTN_TOOL_PEN; 162 + } 163 + } else { 164 + input_report_key(dev, BTN_STYLUS2, coord->f2); 165 + } 166 + 167 + input_report_abs(dev, ABS_X, coord->x); 168 + input_report_abs(dev, ABS_Y, coord->y); 169 + input_report_abs(dev, ABS_PRESSURE, coord->pen_pressure); 170 + input_report_key(dev, BTN_TOUCH, coord->tsw); 171 + input_report_key(dev, BTN_STYLUS, coord->f1); 172 + input_report_key(dev, w8001->type, coord->rdy); 173 + input_sync(dev); 174 + 175 + if (!coord->rdy) 176 + w8001->type = 0; 177 + } 178 + 117 179 static irqreturn_t w8001_interrupt(struct serio *serio, 118 180 unsigned char data, unsigned int flags) 119 181 { 120 182 struct w8001 *w8001 = serio_get_drvdata(serio); 121 - struct input_dev *dev = w8001->dev; 122 183 struct w8001_coord coord; 123 184 unsigned char tmp; 124 185 ··· 218 105 } 219 106 break; 220 107 221 - case 8: 108 + case W8001_PKTLEN_TOUCH93 - 1: 109 + case W8001_PKTLEN_TOUCH9A - 1: 110 + /* ignore one-finger touch packet. */ 111 + if (w8001->pktlen == w8001->idx) 112 + w8001->idx = 0; 113 + break; 114 + 115 + /* Pen coordinates packet */ 116 + case W8001_PKTLEN_TPCPEN - 1: 222 117 tmp = w8001->data[0] & W8001_TAB_MASK; 223 118 if (unlikely(tmp == W8001_TAB_BYTE)) 224 119 break; 225 120 121 + tmp = (w8001->data[0] & W8001_TOUCH_BYTE); 122 + if (tmp == W8001_TOUCH_BYTE) 123 + break; 124 + 226 125 w8001->idx = 0; 227 126 parse_data(w8001->data, &coord); 228 - input_report_abs(dev, ABS_X, coord.x); 229 - input_report_abs(dev, ABS_Y, coord.y); 230 - input_report_abs(dev, ABS_PRESSURE, coord.pen_pressure); 231 - input_report_key(dev, BTN_TOUCH, coord.tsw); 232 - input_sync(dev); 127 + report_pen_events(w8001, &coord); 233 128 break; 234 129 235 - case 10: 130 + /* control packet */ 131 + case W8001_PKTLEN_TPCCTL - 1: 132 + tmp = (w8001->data[0] & W8001_TOUCH_MASK); 133 + if (tmp == W8001_TOUCH_BYTE) 134 + break; 135 + 236 136 w8001->idx = 0; 237 137 memcpy(w8001->response, w8001->data, W8001_MAX_LENGTH); 238 138 w8001->response_type = W8001_QUERY_PACKET; 239 139 complete(&w8001->cmd_done); 140 + break; 141 + 142 + /* 2 finger touch packet */ 143 + case W8001_PKTLEN_TOUCH2FG - 1: 144 + w8001->idx = 0; 145 + parse_touch(w8001); 240 146 break; 241 147 } 242 148 ··· 299 167 input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0); 300 168 input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0); 301 169 170 + error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true); 171 + if (!error) { 172 + struct w8001_touch_query touch; 173 + 174 + parse_touchquery(w8001->response, &touch); 175 + 176 + switch (touch.sensor_id) { 177 + case 0: 178 + case 2: 179 + w8001->pktlen = W8001_PKTLEN_TOUCH93; 180 + break; 181 + case 1: 182 + case 3: 183 + case 4: 184 + w8001->pktlen = W8001_PKTLEN_TOUCH9A; 185 + break; 186 + case 5: 187 + w8001->pktlen = W8001_PKTLEN_TOUCH2FG; 188 + 189 + input_mt_create_slots(dev, 2); 190 + input_set_abs_params(dev, ABS_MT_TRACKING_ID, 191 + 0, MAX_TRACKING_ID, 0, 0); 192 + input_set_abs_params(dev, ABS_MT_POSITION_X, 193 + 0, touch.x, 0, 0); 194 + input_set_abs_params(dev, ABS_MT_POSITION_Y, 195 + 0, touch.y, 0, 0); 196 + input_set_abs_params(dev, ABS_MT_TOOL_TYPE, 197 + 0, 0, 0, 0); 198 + break; 199 + } 200 + } 201 + 302 202 return w8001_command(w8001, W8001_CMD_START, false); 303 203 } 304 204 ··· 372 208 w8001->serio = serio; 373 209 w8001->id = serio->id.id; 374 210 w8001->dev = input_dev; 211 + w8001->trkid[0] = w8001->trkid[1] = -1; 375 212 init_completion(&w8001->cmd_done); 376 213 snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys); 377 214 ··· 386 221 387 222 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 388 223 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 224 + input_dev->keybit[BIT_WORD(BTN_TOOL_PEN)] |= BIT_MASK(BTN_TOOL_PEN); 225 + input_dev->keybit[BIT_WORD(BTN_TOOL_RUBBER)] |= BIT_MASK(BTN_TOOL_RUBBER); 226 + input_dev->keybit[BIT_WORD(BTN_STYLUS)] |= BIT_MASK(BTN_STYLUS); 227 + input_dev->keybit[BIT_WORD(BTN_STYLUS2)] |= BIT_MASK(BTN_STYLUS2); 389 228 390 229 serio_set_drvdata(serio, w8001); 391 230 err = serio_open(serio, drv);
+14 -4
drivers/input/touchscreen/wm97xx-core.c
··· 125 125 { 126 126 int power_adc = 0, auxval; 127 127 u16 power = 0; 128 + int rc = 0; 129 + int timeout = 0; 128 130 129 131 /* get codec */ 130 132 mutex_lock(&wm->codec_mutex); ··· 145 143 146 144 /* Turn polling mode on to read AUX ADC */ 147 145 wm->pen_probably_down = 1; 148 - wm->codec->poll_sample(wm, adcsel, &auxval); 146 + 147 + while (rc != RC_VALID && timeout++ < 5) 148 + rc = wm->codec->poll_sample(wm, adcsel, &auxval); 149 149 150 150 if (power_adc) 151 151 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000); ··· 156 152 157 153 wm->pen_probably_down = 0; 158 154 155 + if (timeout >= 5) { 156 + dev_err(wm->dev, 157 + "timeout reading auxadc %d, disabling digitiser\n", 158 + adcsel); 159 + wm->codec->dig_enable(wm, false); 160 + } 161 + 159 162 mutex_unlock(&wm->codec_mutex); 160 - return auxval & 0xfff; 163 + return (rc == RC_VALID ? auxval & 0xfff : -EBUSY); 161 164 } 162 165 EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc); 163 166 ··· 695 684 touch_reg_err: 696 685 platform_device_put(wm->touch_dev); 697 686 touch_err: 698 - platform_device_unregister(wm->battery_dev); 699 - wm->battery_dev = NULL; 687 + platform_device_del(wm->battery_dev); 700 688 batt_reg_err: 701 689 platform_device_put(wm->battery_dev); 702 690 batt_err:
+263 -132
drivers/media/IR/ir-keytable.c
··· 25 25 #define IR_KEYPRESS_TIMEOUT 250 26 26 27 27 /** 28 + * ir_create_table() - initializes a scancode table 29 + * @rc_tab: the ir_scancode_table to initialize 30 + * @name: name to assign to the table 31 + * @ir_type: ir type to assign to the new table 32 + * @size: initial size of the table 33 + * @return: zero on success or a negative error code 34 + * 35 + * This routine will initialize the ir_scancode_table and will allocate 36 + * memory to hold at least the specified number elements. 37 + */ 38 + static int ir_create_table(struct ir_scancode_table *rc_tab, 39 + const char *name, u64 ir_type, size_t size) 40 + { 41 + rc_tab->name = name; 42 + rc_tab->ir_type = ir_type; 43 + rc_tab->alloc = roundup_pow_of_two(size * sizeof(struct ir_scancode)); 44 + rc_tab->size = rc_tab->alloc / sizeof(struct ir_scancode); 45 + rc_tab->scan = kmalloc(rc_tab->alloc, GFP_KERNEL); 46 + if (!rc_tab->scan) 47 + return -ENOMEM; 48 + 49 + IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n", 50 + rc_tab->size, rc_tab->alloc); 51 + return 0; 52 + } 53 + 54 + /** 55 + * ir_free_table() - frees memory allocated by a scancode table 56 + * @rc_tab: the table whose mappings need to be freed 57 + * 58 + * This routine will free memory alloctaed for key mappings used by given 59 + * scancode table. 60 + */ 61 + static void ir_free_table(struct ir_scancode_table *rc_tab) 62 + { 63 + rc_tab->size = 0; 64 + kfree(rc_tab->scan); 65 + rc_tab->scan = NULL; 66 + } 67 + 68 + /** 28 69 * ir_resize_table() - resizes a scancode table if necessary 29 70 * @rc_tab: the ir_scancode_table to resize 71 + * @gfp_flags: gfp flags to use when allocating memory 30 72 * @return: zero on success or a negative error code 31 73 * 32 74 * This routine will shrink the ir_scancode_table if it has lots of 33 75 * unused entries and grow it if it is full. 34 76 */ 35 - static int ir_resize_table(struct ir_scancode_table *rc_tab) 77 + static int ir_resize_table(struct ir_scancode_table *rc_tab, gfp_t gfp_flags) 36 78 { 37 79 unsigned int oldalloc = rc_tab->alloc; 38 80 unsigned int newalloc = oldalloc; ··· 99 57 if (newalloc == oldalloc) 100 58 return 0; 101 59 102 - newscan = kmalloc(newalloc, GFP_ATOMIC); 60 + newscan = kmalloc(newalloc, gfp_flags); 103 61 if (!newscan) { 104 62 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc); 105 63 return -ENOMEM; ··· 114 72 } 115 73 116 74 /** 117 - * ir_do_setkeycode() - internal function to set a keycode in the 118 - * scancode->keycode table 75 + * ir_update_mapping() - set a keycode in the scancode->keycode table 119 76 * @dev: the struct input_dev device descriptor 120 - * @rc_tab: the struct ir_scancode_table to set the keycode in 121 - * @scancode: the scancode for the ir command 122 - * @keycode: the keycode for the ir command 123 - * @resize: whether the keytable may be shrunk 124 - * @return: -EINVAL if the keycode could not be inserted, otherwise zero. 77 + * @rc_tab: scancode table to be adjusted 78 + * @index: index of the mapping that needs to be updated 79 + * @keycode: the desired keycode 80 + * @return: previous keycode assigned to the mapping 125 81 * 126 - * This routine is used internally to manipulate the scancode->keycode table. 127 - * The caller has to hold @rc_tab->lock. 82 + * This routine is used to update scancode->keycopde mapping at given 83 + * position. 128 84 */ 129 - static int ir_do_setkeycode(struct input_dev *dev, 130 - struct ir_scancode_table *rc_tab, 131 - unsigned scancode, unsigned keycode, 132 - bool resize) 85 + static unsigned int ir_update_mapping(struct input_dev *dev, 86 + struct ir_scancode_table *rc_tab, 87 + unsigned int index, 88 + unsigned int new_keycode) 89 + { 90 + int old_keycode = rc_tab->scan[index].keycode; 91 + int i; 92 + 93 + /* Did the user wish to remove the mapping? */ 94 + if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) { 95 + IR_dprintk(1, "#%d: Deleting scan 0x%04x\n", 96 + index, rc_tab->scan[index].scancode); 97 + rc_tab->len--; 98 + memmove(&rc_tab->scan[index], &rc_tab->scan[index+ 1], 99 + (rc_tab->len - index) * sizeof(struct ir_scancode)); 100 + } else { 101 + IR_dprintk(1, "#%d: %s scan 0x%04x with key 0x%04x\n", 102 + index, 103 + old_keycode == KEY_RESERVED ? "New" : "Replacing", 104 + rc_tab->scan[index].scancode, new_keycode); 105 + rc_tab->scan[index].keycode = new_keycode; 106 + __set_bit(new_keycode, dev->keybit); 107 + } 108 + 109 + if (old_keycode != KEY_RESERVED) { 110 + /* A previous mapping was updated... */ 111 + __clear_bit(old_keycode, dev->keybit); 112 + /* ... but another scancode might use the same keycode */ 113 + for (i = 0; i < rc_tab->len; i++) { 114 + if (rc_tab->scan[i].keycode == old_keycode) { 115 + __set_bit(old_keycode, dev->keybit); 116 + break; 117 + } 118 + } 119 + 120 + /* Possibly shrink the keytable, failure is not a problem */ 121 + ir_resize_table(rc_tab, GFP_ATOMIC); 122 + } 123 + 124 + return old_keycode; 125 + } 126 + 127 + /** 128 + * ir_locate_scancode() - set a keycode in the scancode->keycode table 129 + * @ir_dev: the struct ir_input_dev device descriptor 130 + * @rc_tab: scancode table to be searched 131 + * @scancode: the desired scancode 132 + * @resize: controls whether we allowed to resize the table to 133 + * accomodate not yet present scancodes 134 + * @return: index of the mapping containing scancode in question 135 + * or -1U in case of failure. 136 + * 137 + * This routine is used to locate given scancode in ir_scancode_table. 138 + * If scancode is not yet present the routine will allocate a new slot 139 + * for it. 140 + */ 141 + static unsigned int ir_establish_scancode(struct ir_input_dev *ir_dev, 142 + struct ir_scancode_table *rc_tab, 143 + unsigned int scancode, 144 + bool resize) 133 145 { 134 146 unsigned int i; 135 - int old_keycode = KEY_RESERVED; 136 - struct ir_input_dev *ir_dev = input_get_drvdata(dev); 137 147 138 148 /* 139 149 * Unfortunately, some hardware-based IR decoders don't provide ··· 194 100 * the provided IR with another one, it is needed to allow loading 195 101 * IR tables from other remotes. So, 196 102 */ 197 - if (ir_dev->props && ir_dev->props->scanmask) { 103 + if (ir_dev->props && ir_dev->props->scanmask) 198 104 scancode &= ir_dev->props->scanmask; 199 - } 200 105 201 106 /* First check if we already have a mapping for this ir command */ 202 107 for (i = 0; i < rc_tab->len; i++) { 108 + if (rc_tab->scan[i].scancode == scancode) 109 + return i; 110 + 203 111 /* Keytable is sorted from lowest to highest scancode */ 204 - if (rc_tab->scan[i].scancode > scancode) 112 + if (rc_tab->scan[i].scancode >= scancode) 205 113 break; 206 - else if (rc_tab->scan[i].scancode < scancode) 207 - continue; 208 - 209 - old_keycode = rc_tab->scan[i].keycode; 210 - rc_tab->scan[i].keycode = keycode; 211 - 212 - /* Did the user wish to remove the mapping? */ 213 - if (keycode == KEY_RESERVED || keycode == KEY_UNKNOWN) { 214 - IR_dprintk(1, "#%d: Deleting scan 0x%04x\n", 215 - i, scancode); 216 - rc_tab->len--; 217 - memmove(&rc_tab->scan[i], &rc_tab->scan[i + 1], 218 - (rc_tab->len - i) * sizeof(struct ir_scancode)); 219 - } 220 - 221 - /* Possibly shrink the keytable, failure is not a problem */ 222 - ir_resize_table(rc_tab); 223 - break; 224 114 } 225 115 226 - if (old_keycode == KEY_RESERVED && keycode != KEY_RESERVED) { 227 - /* No previous mapping found, we might need to grow the table */ 228 - if (resize && ir_resize_table(rc_tab)) 229 - return -ENOMEM; 116 + /* No previous mapping found, we might need to grow the table */ 117 + if (rc_tab->size == rc_tab->len) { 118 + if (!resize || ir_resize_table(rc_tab, GFP_ATOMIC)) 119 + return -1U; 120 + } 230 121 231 - IR_dprintk(1, "#%d: New scan 0x%04x with key 0x%04x\n", 232 - i, scancode, keycode); 233 - 234 - /* i is the proper index to insert our new keycode */ 122 + /* i is the proper index to insert our new keycode */ 123 + if (i < rc_tab->len) 235 124 memmove(&rc_tab->scan[i + 1], &rc_tab->scan[i], 236 125 (rc_tab->len - i) * sizeof(struct ir_scancode)); 237 - rc_tab->scan[i].scancode = scancode; 238 - rc_tab->scan[i].keycode = keycode; 239 - rc_tab->len++; 240 - set_bit(keycode, dev->keybit); 241 - } else { 242 - IR_dprintk(1, "#%d: Replacing scan 0x%04x with key 0x%04x\n", 243 - i, scancode, keycode); 244 - /* A previous mapping was updated... */ 245 - clear_bit(old_keycode, dev->keybit); 246 - /* ...but another scancode might use the same keycode */ 247 - for (i = 0; i < rc_tab->len; i++) { 248 - if (rc_tab->scan[i].keycode == old_keycode) { 249 - set_bit(old_keycode, dev->keybit); 250 - break; 251 - } 252 - } 253 - } 126 + rc_tab->scan[i].scancode = scancode; 127 + rc_tab->scan[i].keycode = KEY_RESERVED; 128 + rc_tab->len++; 254 129 255 - return 0; 130 + return i; 256 131 } 257 132 258 133 /** ··· 234 171 * This routine is used to handle evdev EVIOCSKEY ioctl. 235 172 */ 236 173 static int ir_setkeycode(struct input_dev *dev, 237 - unsigned int scancode, unsigned int keycode) 174 + const struct input_keymap_entry *ke, 175 + unsigned int *old_keycode) 238 176 { 239 - int rc; 240 - unsigned long flags; 241 177 struct ir_input_dev *ir_dev = input_get_drvdata(dev); 242 178 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 179 + unsigned int index; 180 + unsigned int scancode; 181 + int retval; 182 + unsigned long flags; 243 183 244 184 spin_lock_irqsave(&rc_tab->lock, flags); 245 - rc = ir_do_setkeycode(dev, rc_tab, scancode, keycode, true); 185 + 186 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) { 187 + index = ke->index; 188 + if (index >= rc_tab->len) { 189 + retval = -EINVAL; 190 + goto out; 191 + } 192 + } else { 193 + retval = input_scancode_to_scalar(ke, &scancode); 194 + if (retval) 195 + goto out; 196 + 197 + index = ir_establish_scancode(ir_dev, rc_tab, scancode, true); 198 + if (index >= rc_tab->len) { 199 + retval = -ENOMEM; 200 + goto out; 201 + } 202 + } 203 + 204 + *old_keycode = ir_update_mapping(dev, rc_tab, index, ke->keycode); 205 + 206 + out: 246 207 spin_unlock_irqrestore(&rc_tab->lock, flags); 247 - return rc; 208 + return retval; 248 209 } 249 210 250 211 /** ··· 276 189 * @dev: the struct input_dev device descriptor 277 190 * @to: the struct ir_scancode_table to copy entries to 278 191 * @from: the struct ir_scancode_table to copy entries from 279 - * @return: -EINVAL if all keycodes could not be inserted, otherwise zero. 192 + * @return: -ENOMEM if all keycodes could not be inserted, otherwise zero. 280 193 * 281 194 * This routine is used to handle table initialization. 282 195 */ 283 - static int ir_setkeytable(struct input_dev *dev, 284 - struct ir_scancode_table *to, 196 + static int ir_setkeytable(struct ir_input_dev *ir_dev, 285 197 const struct ir_scancode_table *from) 286 198 { 287 - struct ir_input_dev *ir_dev = input_get_drvdata(dev); 288 199 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 289 - unsigned long flags; 290 - unsigned int i; 291 - int rc = 0; 200 + unsigned int i, index; 201 + int rc; 292 202 293 - spin_lock_irqsave(&rc_tab->lock, flags); 203 + rc = ir_create_table(&ir_dev->rc_tab, 204 + from->name, from->ir_type, from->size); 205 + if (rc) 206 + return rc; 207 + 208 + IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n", 209 + rc_tab->size, rc_tab->alloc); 210 + 294 211 for (i = 0; i < from->size; i++) { 295 - rc = ir_do_setkeycode(dev, to, from->scan[i].scancode, 296 - from->scan[i].keycode, false); 297 - if (rc) 212 + index = ir_establish_scancode(ir_dev, rc_tab, 213 + from->scan[i].scancode, false); 214 + if (index >= rc_tab->len) { 215 + rc = -ENOMEM; 298 216 break; 217 + } 218 + 219 + ir_update_mapping(ir_dev->input_dev, rc_tab, index, 220 + from->scan[i].keycode); 299 221 } 300 - spin_unlock_irqrestore(&rc_tab->lock, flags); 222 + 223 + if (rc) 224 + ir_free_table(rc_tab); 225 + 301 226 return rc; 227 + } 228 + 229 + /** 230 + * ir_lookup_by_scancode() - locate mapping by scancode 231 + * @rc_tab: the &struct ir_scancode_table to search 232 + * @scancode: scancode to look for in the table 233 + * @return: index in the table, -1U if not found 234 + * 235 + * This routine performs binary search in RC keykeymap table for 236 + * given scancode. 237 + */ 238 + static unsigned int ir_lookup_by_scancode(const struct ir_scancode_table *rc_tab, 239 + unsigned int scancode) 240 + { 241 + unsigned int start = 0; 242 + unsigned int end = rc_tab->len - 1; 243 + unsigned int mid; 244 + 245 + while (start <= end) { 246 + mid = (start + end) / 2; 247 + if (rc_tab->scan[mid].scancode < scancode) 248 + start = mid + 1; 249 + else if (rc_tab->scan[mid].scancode > scancode) 250 + end = mid - 1; 251 + else 252 + return mid; 253 + } 254 + 255 + return -1U; 302 256 } 303 257 304 258 /** ··· 352 224 * This routine is used to handle evdev EVIOCGKEY ioctl. 353 225 */ 354 226 static int ir_getkeycode(struct input_dev *dev, 355 - unsigned int scancode, unsigned int *keycode) 227 + struct input_keymap_entry *ke) 356 228 { 357 - int start, end, mid; 358 - unsigned long flags; 359 - int key = KEY_RESERVED; 360 229 struct ir_input_dev *ir_dev = input_get_drvdata(dev); 361 230 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 231 + struct ir_scancode *entry; 232 + unsigned long flags; 233 + unsigned int index; 234 + unsigned int scancode; 235 + int retval; 362 236 363 237 spin_lock_irqsave(&rc_tab->lock, flags); 364 - start = 0; 365 - end = rc_tab->len - 1; 366 - while (start <= end) { 367 - mid = (start + end) / 2; 368 - if (rc_tab->scan[mid].scancode < scancode) 369 - start = mid + 1; 370 - else if (rc_tab->scan[mid].scancode > scancode) 371 - end = mid - 1; 372 - else { 373 - key = rc_tab->scan[mid].keycode; 374 - break; 375 - } 238 + 239 + if (ke->flags & INPUT_KEYMAP_BY_INDEX) { 240 + index = ke->index; 241 + } else { 242 + retval = input_scancode_to_scalar(ke, &scancode); 243 + if (retval) 244 + goto out; 245 + 246 + index = ir_lookup_by_scancode(rc_tab, scancode); 376 247 } 248 + 249 + if (index >= rc_tab->len) { 250 + if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) 251 + IR_dprintk(1, "unknown key for scancode 0x%04x\n", 252 + scancode); 253 + retval = -EINVAL; 254 + goto out; 255 + } 256 + 257 + entry = &rc_tab->scan[index]; 258 + 259 + ke->index = index; 260 + ke->keycode = entry->keycode; 261 + ke->len = sizeof(entry->scancode); 262 + memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode)); 263 + 264 + out: 377 265 spin_unlock_irqrestore(&rc_tab->lock, flags); 378 - 379 - if (key == KEY_RESERVED) 380 - IR_dprintk(1, "unknown key for scancode 0x%04x\n", 381 - scancode); 382 - 383 - *keycode = key; 384 - return 0; 266 + return retval; 385 267 } 386 268 387 269 /** ··· 406 268 */ 407 269 u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) 408 270 { 409 - int keycode; 271 + struct ir_input_dev *ir_dev = input_get_drvdata(dev); 272 + struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; 273 + unsigned int keycode; 274 + unsigned int index; 275 + unsigned long flags; 410 276 411 - ir_getkeycode(dev, scancode, &keycode); 277 + spin_lock_irqsave(&rc_tab->lock, flags); 278 + 279 + index = ir_lookup_by_scancode(rc_tab, scancode); 280 + keycode = index < rc_tab->len ? 281 + rc_tab->scan[index].keycode : KEY_RESERVED; 282 + 283 + spin_unlock_irqrestore(&rc_tab->lock, flags); 284 + 412 285 if (keycode != KEY_RESERVED) 413 286 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n", 414 287 dev->name, scancode, keycode); 288 + 415 289 return keycode; 416 290 } 417 291 EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); ··· 603 453 goto out_dev; 604 454 } 605 455 606 - input_dev->getkeycode = ir_getkeycode; 607 - input_dev->setkeycode = ir_setkeycode; 456 + input_dev->getkeycode_new = ir_getkeycode; 457 + input_dev->setkeycode_new = ir_setkeycode; 608 458 input_set_drvdata(input_dev, ir_dev); 609 459 ir_dev->input_dev = input_dev; 610 460 ··· 612 462 spin_lock_init(&ir_dev->keylock); 613 463 setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev); 614 464 615 - ir_dev->rc_tab.name = rc_tab->name; 616 - ir_dev->rc_tab.ir_type = rc_tab->ir_type; 617 - ir_dev->rc_tab.alloc = roundup_pow_of_two(rc_tab->size * 618 - sizeof(struct ir_scancode)); 619 - ir_dev->rc_tab.scan = kmalloc(ir_dev->rc_tab.alloc, GFP_KERNEL); 620 - ir_dev->rc_tab.size = ir_dev->rc_tab.alloc / sizeof(struct ir_scancode); 621 465 if (props) { 622 466 ir_dev->props = props; 623 467 if (props->open) ··· 620 476 input_dev->close = ir_close; 621 477 } 622 478 623 - if (!ir_dev->rc_tab.scan) { 624 - rc = -ENOMEM; 625 - goto out_name; 626 - } 627 - 628 - IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n", 629 - ir_dev->rc_tab.size, ir_dev->rc_tab.alloc); 630 - 631 479 set_bit(EV_KEY, input_dev->evbit); 632 480 set_bit(EV_REP, input_dev->evbit); 633 481 set_bit(EV_MSC, input_dev->evbit); 634 482 set_bit(MSC_SCAN, input_dev->mscbit); 635 483 636 - if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) { 637 - rc = -ENOMEM; 638 - goto out_table; 639 - } 484 + rc = ir_setkeytable(ir_dev, rc_tab); 485 + if (rc) 486 + goto out_name; 640 487 641 488 rc = ir_register_class(input_dev); 642 489 if (rc < 0) ··· 650 515 out_event: 651 516 ir_unregister_class(input_dev); 652 517 out_table: 653 - kfree(ir_dev->rc_tab.scan); 518 + ir_free_table(&ir_dev->rc_tab); 654 519 out_name: 655 520 kfree(ir_dev->driver_name); 656 521 out_dev: ··· 668 533 void ir_input_unregister(struct input_dev *input_dev) 669 534 { 670 535 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 671 - struct ir_scancode_table *rc_tab; 672 536 673 537 if (!ir_dev) 674 538 return; ··· 679 545 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) 680 546 ir_raw_event_unregister(input_dev); 681 547 682 - rc_tab = &ir_dev->rc_tab; 683 - rc_tab->size = 0; 684 - kfree(rc_tab->scan); 685 - rc_tab->scan = NULL; 548 + ir_free_table(&ir_dev->rc_tab); 686 549 687 550 ir_unregister_class(input_dev); 688 551
+20
drivers/mfd/ab8500-core.c
··· 338 338 }, 339 339 }; 340 340 341 + static struct resource ab8500_poweronkey_db_resources[] = { 342 + { 343 + .name = "ONKEY_DBF", 344 + .start = AB8500_INT_PON_KEY1DB_F, 345 + .end = AB8500_INT_PON_KEY1DB_F, 346 + .flags = IORESOURCE_IRQ, 347 + }, 348 + { 349 + .name = "ONKEY_DBR", 350 + .start = AB8500_INT_PON_KEY1DB_R, 351 + .end = AB8500_INT_PON_KEY1DB_R, 352 + .flags = IORESOURCE_IRQ, 353 + }, 354 + }; 355 + 341 356 static struct mfd_cell ab8500_devs[] = { 342 357 { 343 358 .name = "ab8500-gpadc", ··· 369 354 { .name = "ab8500-usb", }, 370 355 { .name = "ab8500-pwm", }, 371 356 { .name = "ab8500-regulator", }, 357 + { 358 + .name = "ab8500-poweron-key", 359 + .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources), 360 + .resources = ab8500_poweronkey_db_resources, 361 + }, 372 362 }; 373 363 374 364 int __devinit ab8500_init(struct ab8500 *ab8500)
-2
drivers/staging/Kconfig
··· 141 141 142 142 source "drivers/staging/xgifb/Kconfig" 143 143 144 - source "drivers/staging/mrst-touchscreen/Kconfig" 145 - 146 144 source "drivers/staging/msm/Kconfig" 147 145 148 146 source "drivers/staging/lirc/Kconfig"
-1
drivers/staging/Makefile
··· 52 52 obj-$(CONFIG_TI_ST) += ti-st/ 53 53 obj-$(CONFIG_ADIS16255) += adis16255/ 54 54 obj-$(CONFIG_FB_XGI) += xgifb/ 55 - obj-$(CONFIG_TOUCHSCREEN_MRSTOUCH) += mrst-touchscreen/ 56 55 obj-$(CONFIG_MSM_STAGING) += msm/ 57 56 obj-$(CONFIG_EASYCAP) += easycap/ 58 57 obj-$(CONFIG_SOLO6X10) += solo6x10/
-7
drivers/staging/mrst-touchscreen/Kconfig
··· 1 - config TOUCHSCREEN_INTEL_MID 2 - tristate "Intel MID platform resistive touchscreen" 3 - depends on INTEL_SCU_IPC 4 - default y 5 - help 6 - Say Y here if you have a Intel MID based touchscreen 7 - If unsure, say N.
-3
drivers/staging/mrst-touchscreen/Makefile
··· 1 - obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) := intel_mid_touch.o 2 - 3 -
-2
drivers/staging/mrst-touchscreen/TODO
··· 1 - - Move the driver to not think it is SPI (requires fixing some of the SFI 2 - and firmware side)
-864
drivers/staging/mrst-touchscreen/intel-mid-touch.c
··· 1 - /* 2 - * intel_mid_touch.c - Intel MID Resistive Touch Screen Driver 3 - * 4 - * Copyright (C) 2008 Intel Corp 5 - * 6 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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; version 2 of the License. 11 - * 12 - * This program is distributed in the hope that it will be useful, but 13 - * WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License along 18 - * with this program; ifnot, write to the Free Software Foundation, Inc., 19 - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 - * 21 - * Questions/Comments/Bug fixes to Sreedhara (sreedhara.ds@intel.com) 22 - * Ramesh Agarwal (ramesh.agarwal@intel.com) 23 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 - * 25 - * TODO: 26 - * kill off mrstouch_debug eventually 27 - * review conversion of r/m/w sequences 28 - * Replace interrupt mutex abuse 29 - * Kill of mrstouchdevp pointer 30 - * 31 - */ 32 - 33 - #include <linux/module.h> 34 - #include <linux/init.h> 35 - #include <linux/input.h> 36 - #include <linux/interrupt.h> 37 - #include <linux/err.h> 38 - #include <linux/param.h> 39 - #include <linux/spi/spi.h> 40 - #include <linux/irq.h> 41 - #include <linux/delay.h> 42 - #include <linux/kthread.h> 43 - #include <asm/intel_scu_ipc.h> 44 - 45 - 46 - #if defined(MRSTOUCH_DEBUG) 47 - #define mrstouch_debug(fmt, args...)\ 48 - do { \ 49 - printk(KERN_DEBUG "\n[MRSTOUCH(%d)] - ", __LINE__); \ 50 - printk(KERN_DEBUG fmt, ##args); \ 51 - } while (0); 52 - #else 53 - #define mrstouch_debug(fmt, args...) 54 - #endif 55 - 56 - /* PMIC Interrupt registers */ 57 - #define PMIC_REG_ID1 0x00 /*PMIC ID1 register */ 58 - 59 - /* PMIC Interrupt registers */ 60 - #define PMIC_REG_INT 0x04 /*PMIC interrupt register */ 61 - #define PMIC_REG_MINT 0x05 /*PMIC interrupt mask register */ 62 - 63 - /* ADC Interrupt registers */ 64 - #define PMIC_REG_ADCINT 0x5F /*ADC interrupt register */ 65 - #define PMIC_REG_MADCINT 0x60 /*ADC interrupt mask register */ 66 - 67 - /* ADC Control registers */ 68 - #define PMIC_REG_ADCCNTL1 0x61 /*ADC control register */ 69 - 70 - /* ADC Channel Selection registers */ 71 - #define PMICADDR0 0xA4 72 - #define END_OF_CHANNEL 0x1F 73 - 74 - /* ADC Result register */ 75 - #define PMIC_REG_ADCSNS0H 0x64 76 - 77 - /* ADC channels for touch screen */ 78 - #define MRST_TS_CHAN10 0xA /* Touch screen X+ connection */ 79 - #define MRST_TS_CHAN11 0xB /* Touch screen X- connection */ 80 - #define MRST_TS_CHAN12 0xC /* Touch screen Y+ connection */ 81 - #define MRST_TS_CHAN13 0xD /* Touch screen Y- connection */ 82 - 83 - /* Touch screen coordinate constants */ 84 - #define TOUCH_PRESSURE 50 85 - #define TOUCH_PRESSURE_FS 100 86 - 87 - #define XMOVE_LIMIT 5 88 - #define YMOVE_LIMIT 5 89 - #define XYMOVE_CNT 3 90 - 91 - #define MAX_10BIT ((1<<10)-1) 92 - 93 - /* Touch screen channel BIAS constants */ 94 - #define XBIAS 0x20 95 - #define YBIAS 0x40 96 - #define ZBIAS 0x80 97 - 98 - /* Touch screen coordinates */ 99 - #define MIN_X 10 100 - #define MAX_X 1024 101 - #define MIN_Y 10 102 - #define MAX_Y 1024 103 - #define WAIT_ADC_COMPLETION 10 104 - 105 - /* PMIC ADC round robin delays */ 106 - #define ADC_LOOP_DELAY0 0x0 /* Continuous loop */ 107 - #define ADC_LOOP_DELAY1 0x1 /* 4.5 ms approximate */ 108 - 109 - /* PMIC Vendor Identifiers */ 110 - #define PMIC_VENDOR_FS 0 /* PMIC vendor FreeScale */ 111 - #define PMIC_VENDOR_MAXIM 1 /* PMIC vendor MAXIM */ 112 - #define PMIC_VENDOR_NEC 2 /* PMIC vendor NEC */ 113 - #define MRSTOUCH_MAX_CHANNELS 32 /* Maximum ADC channels */ 114 - 115 - /* Touch screen device structure */ 116 - struct mrstouch_dev { 117 - struct spi_device *spi; /* SPI device associated with touch screen */ 118 - struct input_dev *input; /* input device for touchscreen*/ 119 - char phys[32]; /* Device name */ 120 - struct task_struct *pendet_thrd; /* PENDET interrupt handler */ 121 - struct mutex lock; /* Sync between interrupt and PENDET handler */ 122 - bool busy; /* Busy flag */ 123 - u16 asr; /* Address selection register */ 124 - int irq; /* Touch screen IRQ # */ 125 - uint vendor; /* PMIC vendor */ 126 - uint rev; /* PMIC revision */ 127 - bool suspended; /* Device suspended status */ 128 - bool disabled; /* Device disabled status */ 129 - u16 x; /* X coordinate */ 130 - u16 y; /* Y coordinate */ 131 - bool pendown; /* PEN position */ 132 - } ; 133 - 134 - 135 - /* Global Pointer to Touch screen device */ 136 - static struct mrstouch_dev *mrstouchdevp; 137 - 138 - /* Utility to read PMIC ID */ 139 - static int mrstouch_pmic_id(uint *vendor, uint *rev) 140 - { 141 - int err; 142 - u8 r; 143 - 144 - err = intel_scu_ipc_ioread8(PMIC_REG_ID1, &r); 145 - if (err) 146 - return err; 147 - 148 - *vendor = r & 0x7; 149 - *rev = (r >> 3) & 0x7; 150 - 151 - return 0; 152 - } 153 - 154 - /* 155 - * Parse ADC channels to find end of the channel configured by other ADC user 156 - * NEC and MAXIM requires 4 channels and FreeScale needs 18 channels 157 - */ 158 - static int mrstouch_chan_parse(struct mrstouch_dev *tsdev) 159 - { 160 - int err, i, j, found; 161 - u32 r32; 162 - 163 - found = -1; 164 - 165 - for (i = 0; i < MRSTOUCH_MAX_CHANNELS; i++) { 166 - if (found >= 0) 167 - break; 168 - 169 - err = intel_scu_ipc_ioread32(PMICADDR0, &r32); 170 - if (err) 171 - return err; 172 - 173 - for (j = 0; j < 32; j+= 8) { 174 - if (((r32 >> j) & 0xFF) == END_OF_CHANNEL) { 175 - found = i; 176 - break; 177 - } 178 - } 179 - } 180 - if (found < 0) 181 - return 0; 182 - 183 - if (tsdev->vendor == PMIC_VENDOR_FS) { 184 - if (found && found > (MRSTOUCH_MAX_CHANNELS - 18)) 185 - return -ENOSPC; 186 - } else { 187 - if (found && found > (MRSTOUCH_MAX_CHANNELS - 4)) 188 - return -ENOSPC; 189 - } 190 - return found; 191 - } 192 - 193 - /* Utility to enable/disable pendet. 194 - * pendet set to true enables PENDET interrupt 195 - * pendet set to false disables PENDET interrupt 196 - * Also clears RND mask bit 197 - */ 198 - static int pendet_enable(struct mrstouch_dev *tsdev, bool pendet) 199 - { 200 - u16 reg; 201 - u8 r; 202 - u8 pendet_enabled = 0; 203 - int retry = 0; 204 - int err; 205 - 206 - err = intel_scu_ipc_ioread16(PMIC_REG_MADCINT, &reg); 207 - if (err) 208 - return err; 209 - 210 - if (pendet) { 211 - reg &= ~0x0005; 212 - reg |= 0x2000; /* Enable pendet */ 213 - } else 214 - reg &= 0xDFFF; /* Disable pendet */ 215 - 216 - /* Set MADCINT and update ADCCNTL1 (next reg byte) */ 217 - err = intel_scu_ipc_iowrite16(PMIC_REG_MADCINT, reg); 218 - if (!pendet || err) 219 - return err; 220 - 221 - /* 222 - * Sometimes even after the register write succeeds 223 - * the PMIC register value is not updated. Retry few iterations 224 - * to enable pendet. 225 - */ 226 - 227 - err = intel_scu_ipc_ioread8(PMIC_REG_ADCCNTL1, &r); 228 - pendet_enabled = (r >> 5) & 0x01; 229 - 230 - retry = 0; 231 - while (!err && !pendet_enabled) { 232 - retry++; 233 - msleep(10); 234 - err = intel_scu_ipc_iowrite8(PMIC_REG_ADCCNTL1, reg >> 8); 235 - if (err) 236 - break; 237 - err = intel_scu_ipc_ioread8(PMIC_REG_ADCCNTL1, &r); 238 - if (err == 0) 239 - pendet_enabled = (r >> 5) & 0x01; 240 - if (retry >= 10) { 241 - dev_err(&tsdev->spi->dev, "Touch screen disabled.\n"); 242 - return -EIO; 243 - } 244 - } 245 - return 0; 246 - } 247 - 248 - /* To read PMIC ADC touch screen result 249 - * Reads ADC storage registers for higher 7 and lower 3 bits 250 - * converts the two readings to single value and turns off gain bit 251 - */ 252 - static int mrstouch_ts_chan_read(u16 offset, u16 chan, u16 *vp, u16 *vm) 253 - { 254 - int err; 255 - u16 result; 256 - u32 res; 257 - 258 - result = PMIC_REG_ADCSNS0H + offset; 259 - 260 - if (chan == MRST_TS_CHAN12) 261 - result += 4; 262 - 263 - err = intel_scu_ipc_ioread32(result, &res); 264 - if (err) 265 - return err; 266 - 267 - /* Mash the bits up */ 268 - 269 - *vp = (res & 0xFF) << 3; /* Highest 7 bits */ 270 - *vp |= (res >> 8) & 0x07; /* Lower 3 bits */ 271 - *vp &= 0x3FF; 272 - 273 - res >>= 16; 274 - 275 - *vm = (res & 0xFF) << 3; /* Highest 7 bits */ 276 - *vm |= (res >> 8) & 0x07; /* Lower 3 bits */ 277 - *vm &= 0x3FF; 278 - 279 - return 0; 280 - } 281 - 282 - /* To configure touch screen channels 283 - * Writes touch screen channels to ADC address selection registers 284 - */ 285 - static int mrstouch_ts_chan_set(uint offset) 286 - { 287 - int count; 288 - u16 chan; 289 - u16 reg[5]; 290 - u8 data[5]; 291 - 292 - chan = PMICADDR0 + offset; 293 - for (count = 0; count <= 3; count++) { 294 - reg[count] = chan++; 295 - data[count] = MRST_TS_CHAN10 + count; 296 - } 297 - reg[count] = chan; 298 - data[count] = END_OF_CHANNEL; 299 - 300 - return intel_scu_ipc_writev(reg, data, 5); 301 - } 302 - 303 - /* Initialize ADC */ 304 - static int mrstouch_adc_init(struct mrstouch_dev *tsdev) 305 - { 306 - int err, start; 307 - u8 ra, rm; 308 - 309 - err = mrstouch_pmic_id(&tsdev->vendor, &tsdev->rev); 310 - if (err) { 311 - dev_err(&tsdev->spi->dev, "Unable to read PMIC id\n"); 312 - return err; 313 - } 314 - 315 - start = mrstouch_chan_parse(tsdev); 316 - if (start < 0) { 317 - dev_err(&tsdev->spi->dev, "Unable to parse channels\n"); 318 - return start; 319 - } 320 - 321 - tsdev->asr = start; 322 - 323 - mrstouch_debug("Channel offset(%d): 0x%X\n", tsdev->asr, tsdev->vendor); 324 - 325 - /* ADC power on, start, enable PENDET and set loop delay 326 - * ADC loop delay is set to 4.5 ms approximately 327 - * Loop delay more than this results in jitter in adc readings 328 - * Setting loop delay to 0 (continous loop) in MAXIM stops PENDET 329 - * interrupt generation sometimes. 330 - */ 331 - 332 - if (tsdev->vendor == PMIC_VENDOR_FS) { 333 - ra = 0xE0 | ADC_LOOP_DELAY0; 334 - rm = 0x5; 335 - } else { 336 - /* NEC and MAXIm not consistent with loop delay 0 */ 337 - ra = 0xE0 | ADC_LOOP_DELAY1; 338 - rm = 0x0; 339 - 340 - /* configure touch screen channels */ 341 - err = mrstouch_ts_chan_set(tsdev->asr); 342 - if (err) 343 - return err; 344 - } 345 - err = intel_scu_ipc_update_register(PMIC_REG_ADCCNTL1, ra, 0xE7); 346 - if (err == 0) 347 - err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, rm, 0x03); 348 - return err; 349 - } 350 - 351 - /* Reports x,y coordinates to event subsystem */ 352 - static void mrstouch_report_xy(struct mrstouch_dev *tsdev, u16 x, u16 y, u16 z) 353 - { 354 - int xdiff, ydiff; 355 - 356 - if (tsdev->pendown && z <= TOUCH_PRESSURE) { 357 - /* Pen removed, report button release */ 358 - mrstouch_debug("BTN REL(%d)", z); 359 - input_report_key(tsdev->input, BTN_TOUCH, 0); 360 - tsdev->pendown = false; 361 - } 362 - 363 - xdiff = abs(x - tsdev->x); 364 - ydiff = abs(y - tsdev->y); 365 - 366 - /* 367 - if x and y values changes for XYMOVE_CNT readings it is considered 368 - as stylus is moving. This is required to differentiate between stylus 369 - movement and jitter 370 - */ 371 - if (x < MIN_X || x > MAX_X || y < MIN_Y || y > MAX_Y) { 372 - /* Spurious values, release button if touched and return */ 373 - if (tsdev->pendown) { 374 - mrstouch_debug("BTN REL(%d)", z); 375 - input_report_key(tsdev->input, BTN_TOUCH, 0); 376 - tsdev->pendown = false; 377 - } 378 - return; 379 - } else if (xdiff >= XMOVE_LIMIT || ydiff >= YMOVE_LIMIT) { 380 - tsdev->x = x; 381 - tsdev->y = y; 382 - 383 - input_report_abs(tsdev->input, ABS_X, x); 384 - input_report_abs(tsdev->input, ABS_Y, y); 385 - input_sync(tsdev->input); 386 - } 387 - 388 - 389 - if (!tsdev->pendown && z > TOUCH_PRESSURE) { 390 - /* Pen touched, report button touch */ 391 - mrstouch_debug("BTN TCH(%d, %d, %d)", x, y, z); 392 - input_report_key(tsdev->input, BTN_TOUCH, 1); 393 - tsdev->pendown = true; 394 - } 395 - } 396 - 397 - 398 - /* Utility to start ADC, used by freescale handler */ 399 - static int pendet_mask(void) 400 - { 401 - return intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x02, 0x02); 402 - } 403 - 404 - /* Utility to stop ADC, used by freescale handler */ 405 - static int pendet_umask(void) 406 - { 407 - return intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x00, 0x02); 408 - } 409 - 410 - /* Utility to read ADC, used by freescale handler */ 411 - static int mrstouch_pmic_fs_adc_read(struct mrstouch_dev *tsdev) 412 - { 413 - int err; 414 - u16 x, y, z, result; 415 - u16 reg[4]; 416 - u8 data[4]; 417 - 418 - result = PMIC_REG_ADCSNS0H + tsdev->asr; 419 - 420 - reg[0] = result + 4; 421 - reg[1] = result + 5; 422 - reg[2] = result + 16; 423 - reg[3] = result + 17; 424 - 425 - err = intel_scu_ipc_readv(reg, data, 4); 426 - if (err) 427 - goto ipc_error; 428 - 429 - x = data[0] << 3; /* Higher 7 bits */ 430 - x |= data[1] & 0x7; /* Lower 3 bits */ 431 - x &= 0x3FF; 432 - 433 - y = data[2] << 3; /* Higher 7 bits */ 434 - y |= data[3] & 0x7; /* Lower 3 bits */ 435 - y &= 0x3FF; 436 - 437 - /* Read Z value */ 438 - reg[0] = result + 28; 439 - reg[1] = result + 29; 440 - 441 - err = intel_scu_ipc_readv(reg, data, 4); 442 - if (err) 443 - goto ipc_error; 444 - 445 - z = data[0] << 3; /* Higher 7 bits */ 446 - z |= data[1] & 0x7; /* Lower 3 bits */ 447 - z &= 0x3FF; 448 - 449 - #if defined(MRSTOUCH_PRINT_XYZP) 450 - mrstouch_debug("X: %d, Y: %d, Z: %d", x, y, z); 451 - #endif 452 - 453 - if (z >= TOUCH_PRESSURE_FS) { 454 - mrstouch_report_xy(tsdev, x, y, TOUCH_PRESSURE - 1); /* Pen Removed */ 455 - return TOUCH_PRESSURE - 1; 456 - } else { 457 - mrstouch_report_xy(tsdev, x, y, TOUCH_PRESSURE + 1); /* Pen Touched */ 458 - return TOUCH_PRESSURE + 1; 459 - } 460 - 461 - return 0; 462 - 463 - ipc_error: 464 - dev_err(&tsdev->spi->dev, "ipc error during fs_adc read\n"); 465 - return err; 466 - } 467 - 468 - /* To handle free scale pmic pendet interrupt */ 469 - static int pmic0_pendet(void *dev_id) 470 - { 471 - int err, count; 472 - u16 chan; 473 - unsigned int touched; 474 - struct mrstouch_dev *tsdev = (struct mrstouch_dev *)dev_id; 475 - u16 reg[5]; 476 - u8 data[5]; 477 - 478 - chan = PMICADDR0 + tsdev->asr; 479 - 480 - /* Set X BIAS */ 481 - for (count = 0; count <= 3; count++) { 482 - reg[count] = chan++; 483 - data[count] = 0x2A; 484 - } 485 - reg[count] = chan++; /* Dummy */ 486 - data[count] = 0; 487 - 488 - err = intel_scu_ipc_writev(reg, data, 5); 489 - if (err) 490 - goto ipc_error; 491 - 492 - msleep(WAIT_ADC_COMPLETION); 493 - 494 - /* Set Y BIAS */ 495 - for (count = 0; count <= 3; count++) { 496 - reg[count] = chan++; 497 - data[count] = 0x4A; 498 - } 499 - reg[count] = chan++; /* Dummy */ 500 - data[count] = 0; 501 - 502 - err = intel_scu_ipc_writev(reg, data, 5); 503 - if (err) 504 - goto ipc_error; 505 - 506 - msleep(WAIT_ADC_COMPLETION); 507 - 508 - /* Set Z BIAS */ 509 - err = intel_scu_ipc_iowrite32(chan + 2, 0x8A8A8A8A); 510 - if (err) 511 - goto ipc_error; 512 - 513 - msleep(WAIT_ADC_COMPLETION); 514 - 515 - /*Read touch screen channels till pen removed 516 - * Freescale reports constant value of z for all points 517 - * z is high when screen is not touched and low when touched 518 - * Map high z value to not touched and low z value to pen touched 519 - */ 520 - touched = mrstouch_pmic_fs_adc_read(tsdev); 521 - while (touched > TOUCH_PRESSURE) { 522 - touched = mrstouch_pmic_fs_adc_read(tsdev); 523 - msleep(WAIT_ADC_COMPLETION); 524 - } 525 - 526 - /* Clear all TS channels */ 527 - chan = PMICADDR0 + tsdev->asr; 528 - for (count = 0; count <= 4; count++) { 529 - reg[count] = chan++; 530 - data[count] = 0; 531 - } 532 - err = intel_scu_ipc_writev(reg, data, 5); 533 - if (err) 534 - goto ipc_error; 535 - 536 - for (count = 0; count <= 4; count++) { 537 - reg[count] = chan++; 538 - data[count] = 0; 539 - } 540 - err = intel_scu_ipc_writev(reg, data, 5); 541 - if (err) 542 - goto ipc_error; 543 - 544 - err = intel_scu_ipc_iowrite32(chan + 2, 0x00000000); 545 - if (err) 546 - goto ipc_error; 547 - 548 - return 0; 549 - 550 - ipc_error: 551 - dev_err(&tsdev->spi->dev, "ipc error during pendet\n"); 552 - return err; 553 - } 554 - 555 - 556 - /* To enable X, Y and Z bias values 557 - * Enables YPYM for X channels and XPXM for Y channels 558 - */ 559 - static int mrstouch_ts_bias_set(uint offset, uint bias) 560 - { 561 - int count; 562 - u16 chan, start; 563 - u16 reg[4]; 564 - u8 data[4]; 565 - 566 - chan = PMICADDR0 + offset; 567 - start = MRST_TS_CHAN10; 568 - 569 - for (count = 0; count <= 3; count++) { 570 - reg[count] = chan++; 571 - data[count] = bias | (start + count); 572 - } 573 - return intel_scu_ipc_writev(reg, data, 4); 574 - } 575 - 576 - /* To read touch screen channel values */ 577 - static int mrstouch_adc_read(struct mrstouch_dev *tsdev) 578 - { 579 - int err; 580 - u16 xp, xm, yp, ym, zp, zm; 581 - 582 - /* configure Y bias for X channels */ 583 - err = mrstouch_ts_bias_set(tsdev->asr, YBIAS); 584 - if (err) 585 - goto ipc_error; 586 - 587 - msleep(WAIT_ADC_COMPLETION); 588 - 589 - /* read x+ and x- channels */ 590 - err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN10, &xp, &xm); 591 - if (err) 592 - goto ipc_error; 593 - 594 - /* configure x bias for y channels */ 595 - err = mrstouch_ts_bias_set(tsdev->asr, XBIAS); 596 - if (err) 597 - goto ipc_error; 598 - 599 - msleep(WAIT_ADC_COMPLETION); 600 - 601 - /* read y+ and y- channels */ 602 - err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN12, &yp, &ym); 603 - if (err) 604 - goto ipc_error; 605 - 606 - /* configure z bias for x and y channels */ 607 - err = mrstouch_ts_bias_set(tsdev->asr, ZBIAS); 608 - if (err) 609 - goto ipc_error; 610 - 611 - msleep(WAIT_ADC_COMPLETION); 612 - 613 - /* read z+ and z- channels */ 614 - err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN10, &zp, &zm); 615 - if (err) 616 - goto ipc_error; 617 - 618 - #if defined(MRSTOUCH_PRINT_XYZP) 619 - printk(KERN_INFO "X+: %d, Y+: %d, Z+: %d\n", xp, yp, zp); 620 - #endif 621 - 622 - #if defined(MRSTOUCH_PRINT_XYZM) 623 - printk(KERN_INFO "X-: %d, Y-: %d, Z-: %d\n", xm, ym, zm); 624 - #endif 625 - 626 - mrstouch_report_xy(tsdev, xp, yp, zp); /* report x and y to eventX */ 627 - 628 - return zp; 629 - 630 - ipc_error: 631 - dev_err(&tsdev->spi->dev, "ipc error during adc read\n"); 632 - return err; 633 - } 634 - 635 - /* PENDET interrupt handler function for NEC and MAXIM */ 636 - static void pmic12_pendet(void *data) 637 - { 638 - unsigned int touched; 639 - struct mrstouch_dev *tsdev = (struct mrstouch_dev *)data; 640 - 641 - /* read touch screen channels till pen removed */ 642 - do { 643 - touched = mrstouch_adc_read(tsdev); 644 - } while (touched > TOUCH_PRESSURE); 645 - } 646 - 647 - /* Handler to process PENDET interrupt */ 648 - int mrstouch_pendet(void *data) 649 - { 650 - struct mrstouch_dev *tsdev = (struct mrstouch_dev *)data; 651 - while (1) { 652 - /* Wait for PENDET interrupt */ 653 - if (mutex_lock_interruptible(&tsdev->lock)) { 654 - msleep(WAIT_ADC_COMPLETION); 655 - continue; 656 - } 657 - 658 - if (tsdev->busy) 659 - return 0; 660 - 661 - tsdev->busy = true; 662 - 663 - if (tsdev->vendor == PMIC_VENDOR_NEC || 664 - tsdev->vendor == PMIC_VENDOR_MAXIM) { 665 - /* PENDET must be disabled in NEC before reading ADC */ 666 - pendet_enable(tsdev,false); /* Disbale PENDET */ 667 - pmic12_pendet(tsdev); 668 - pendet_enable(tsdev, true); /*Enable PENDET */ 669 - } else if (tsdev->vendor == PMIC_VENDOR_FS) { 670 - pendet_umask(); /* Stop ADC */ 671 - pmic0_pendet(tsdev); 672 - pendet_mask(); /* Stop ADC */ 673 - } else 674 - dev_err(&tsdev->spi->dev, "Unsupported touchscreen: %d\n", 675 - tsdev->vendor); 676 - 677 - tsdev->busy = false; 678 - 679 - } 680 - return 0; 681 - } 682 - 683 - /* PENDET interrupt handler */ 684 - static irqreturn_t pendet_intr_handler(int irq, void *handle) 685 - { 686 - struct mrstouch_dev *tsdev = (struct mrstouch_dev *)handle; 687 - 688 - mutex_unlock(&tsdev->lock); 689 - return IRQ_HANDLED; 690 - } 691 - 692 - /* Intializes input device and registers with input subsystem */ 693 - static int ts_input_dev_init(struct mrstouch_dev *tsdev, struct spi_device *spi) 694 - { 695 - int err = 0; 696 - 697 - mrstouch_debug("%s", __func__); 698 - 699 - tsdev->input = input_allocate_device(); 700 - if (!tsdev->input) { 701 - dev_err(&tsdev->spi->dev, "Unable to allocate input device.\n"); 702 - return -EINVAL; 703 - } 704 - 705 - tsdev->input->name = "mrst_touchscreen"; 706 - snprintf(tsdev->phys, sizeof(tsdev->phys), 707 - "%s/input0", dev_name(&spi->dev)); 708 - tsdev->input->phys = tsdev->phys; 709 - tsdev->input->dev.parent = &spi->dev; 710 - 711 - tsdev->input->id.vendor = tsdev->vendor; 712 - tsdev->input->id.version = tsdev->rev; 713 - 714 - tsdev->input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 715 - tsdev->input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 716 - 717 - input_set_abs_params(tsdev->input, ABS_X, MIN_X, MIN_Y, 0, 0); 718 - input_set_abs_params(tsdev->input, ABS_Y, MIN_X, MIN_Y, 0, 0); 719 - 720 - err = input_register_device(tsdev->input); 721 - if (err) { 722 - dev_err(&tsdev->spi->dev, "unable to register input device\n"); 723 - input_free_device(tsdev->input); 724 - return err; 725 - } 726 - 727 - mrstouch_debug("%s", "mrstouch initialized"); 728 - 729 - return 0; 730 - 731 - } 732 - 733 - /* Probe function for touch screen driver */ 734 - static int __devinit mrstouch_probe(struct spi_device *mrstouch_spi) 735 - { 736 - int err; 737 - unsigned int myirq; 738 - struct mrstouch_dev *tsdev; 739 - 740 - mrstouch_debug("%s(%p)", __func__, mrstouch_spi); 741 - 742 - mrstouchdevp = NULL; 743 - myirq = mrstouch_spi->irq; 744 - 745 - if (!mrstouch_spi->irq) { 746 - dev_err(&mrstouch_spi->dev, "no interrupt assigned\n"); 747 - return -EINVAL; 748 - } 749 - 750 - tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL); 751 - if (!tsdev) { 752 - dev_err(&mrstouch_spi->dev, "unable to allocate memory\n"); 753 - return -ENOMEM; 754 - } 755 - 756 - tsdev->irq = myirq; 757 - mrstouchdevp = tsdev; 758 - 759 - err = mrstouch_adc_init(tsdev); 760 - if (err) { 761 - dev_err(&mrstouch_spi->dev, "ADC init failed\n"); 762 - goto mrstouch_err_free_mem; 763 - } 764 - 765 - dev_set_drvdata(&mrstouch_spi->dev, tsdev); 766 - tsdev->spi = mrstouch_spi; 767 - 768 - err = ts_input_dev_init(tsdev, mrstouch_spi); 769 - if (err) { 770 - dev_err(&tsdev->spi->dev, "ts_input_dev_init failed"); 771 - goto mrstouch_err_free_mem; 772 - } 773 - 774 - mutex_init(&tsdev->lock); 775 - mutex_lock(&tsdev->lock) 776 - 777 - mrstouch_debug("Requesting IRQ-%d", myirq); 778 - err = request_irq(myirq, pendet_intr_handler, 779 - 0, "mrstouch", tsdev); 780 - if (err) { 781 - dev_err(&tsdev->spi->dev, "unable to allocate irq\n"); 782 - goto mrstouch_err_free_mem; 783 - } 784 - 785 - tsdev->pendet_thrd = kthread_run(mrstouch_pendet, 786 - (void *)tsdev, "pendet handler"); 787 - if (IS_ERR(tsdev->pendet_thrd)) { 788 - dev_err(&tsdev->spi->dev, "kthread_run failed\n"); 789 - err = PTR_ERR(tsdev->pendet_thrd); 790 - goto mrstouch_err_free_mem; 791 - } 792 - mrstouch_debug("%s", "Driver initialized"); 793 - return 0; 794 - 795 - mrstouch_err_free_mem: 796 - kfree(tsdev); 797 - return err; 798 - } 799 - 800 - static int mrstouch_suspend(struct spi_device *spi, pm_message_t msg) 801 - { 802 - mrstouch_debug("%s", __func__); 803 - mrstouchdevp->suspended = 1; 804 - return 0; 805 - } 806 - 807 - static int mrstouch_resume(struct spi_device *spi) 808 - { 809 - mrstouch_debug("%s", __func__); 810 - mrstouchdevp->suspended = 0; 811 - return 0; 812 - } 813 - 814 - static int mrstouch_remove(struct spi_device *spi) 815 - { 816 - mrstouch_debug("%s", __func__); 817 - free_irq(mrstouchdevp->irq, mrstouchdevp); 818 - input_unregister_device(mrstouchdevp->input); 819 - input_free_device(mrstouchdevp->input); 820 - if (mrstouchdevp->pendet_thrd) 821 - kthread_stop(mrstouchdevp->pendet_thrd); 822 - kfree(mrstouchdevp); 823 - return 0; 824 - } 825 - 826 - static struct spi_driver mrstouch_driver = { 827 - .driver = { 828 - .name = "pmic_touch", 829 - .bus = &spi_bus_type, 830 - .owner = THIS_MODULE, 831 - }, 832 - .probe = mrstouch_probe, 833 - .suspend = mrstouch_suspend, 834 - .resume = mrstouch_resume, 835 - .remove = mrstouch_remove, 836 - }; 837 - 838 - static int __init mrstouch_module_init(void) 839 - { 840 - int err; 841 - 842 - mrstouch_debug("%s", __func__); 843 - err = spi_register_driver(&mrstouch_driver); 844 - if (err) { 845 - mrstouch_debug("%s(%d)", "SPI PENDET failed", err); 846 - return -1; 847 - } 848 - 849 - return 0; 850 - } 851 - 852 - static void __exit mrstouch_module_exit(void) 853 - { 854 - mrstouch_debug("%s", __func__); 855 - spi_unregister_driver(&mrstouch_driver); 856 - return; 857 - } 858 - 859 - module_init(mrstouch_module_init); 860 - module_exit(mrstouch_module_exit); 861 - 862 - MODULE_AUTHOR("Sreedhara Murthy. D.S, sreedhara.ds@intel.com"); 863 - MODULE_DESCRIPTION("Intel Moorestown Resistive Touch Screen Driver"); 864 - MODULE_LICENSE("GPL");
+1 -3
include/linux/gameport.h
··· 53 53 #define to_gameport_port(d) container_of(d, struct gameport, dev) 54 54 55 55 struct gameport_driver { 56 - 57 - void *private; 58 - char *description; 56 + const char *description; 59 57 60 58 int (*connect)(struct gameport *, struct gameport_driver *drv); 61 59 int (*reconnect)(struct gameport *);
+45 -12
include/linux/input.h
··· 34 34 * Protocol version. 35 35 */ 36 36 37 - #define EV_VERSION 0x010000 37 + #define EV_VERSION 0x010001 38 38 39 39 /* 40 40 * IOCTLs (0x00 - 0x7f) ··· 56 56 __s32 resolution; 57 57 }; 58 58 59 + /** 60 + * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls 61 + * @scancode: scancode represented in machine-endian form. 62 + * @len: length of the scancode that resides in @scancode buffer. 63 + * @index: index in the keymap, may be used instead of scancode 64 + * @flags: allows to specify how kernel should handle the request. For 65 + * example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel 66 + * should perform lookup in keymap by @index instead of @scancode 67 + * @keycode: key code assigned to this scancode 68 + * 69 + * The structure is used to retrieve and modify keymap data. Users have 70 + * option of performing lookup either by @scancode itself or by @index 71 + * in keymap entry. EVIOCGKEYCODE will also return scancode or index 72 + * (depending on which element was used to perform lookup). 73 + */ 74 + struct input_keymap_entry { 75 + #define INPUT_KEYMAP_BY_INDEX (1 << 0) 76 + __u8 flags; 77 + __u8 len; 78 + __u16 index; 79 + __u32 keycode; 80 + __u8 scancode[32]; 81 + }; 82 + 59 83 #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ 60 84 #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ 61 85 #define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ 62 86 #define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ 63 - #define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */ 64 - #define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */ 87 + 88 + #define EVIOCGKEYCODE _IOR('E', 0x04, struct input_keymap_entry) /* get keycode */ 89 + #define EVIOCSKEYCODE _IOW('E', 0x04, struct input_keymap_entry) /* set keycode */ 65 90 66 91 #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ 67 92 #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ 68 93 #define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */ 69 94 70 - #define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */ 95 + #define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global key state */ 71 96 #define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */ 72 97 #define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */ 73 98 #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */ 74 99 75 100 #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */ 76 - #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */ 77 - #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */ 101 + #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */ 102 + #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */ 78 103 79 104 #define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */ 80 105 #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ ··· 1113 1088 * @keycodemax: size of keycode table 1114 1089 * @keycodesize: size of elements in keycode table 1115 1090 * @keycode: map of scancodes to keycodes for this device 1091 + * @getkeycode: optional legacy method to retrieve current keymap. 1116 1092 * @setkeycode: optional method to alter current keymap, used to implement 1117 1093 * sparse keymaps. If not supplied default mechanism will be used. 1118 1094 * The method is being called while holding event_lock and thus must 1119 1095 * not sleep 1120 - * @getkeycode: optional method to retrieve current keymap. If not supplied 1121 - * default mechanism will be used. The method is being called while 1122 - * holding event_lock and thus must not sleep 1096 + * @getkeycode_new: transition method 1097 + * @setkeycode_new: transition method 1123 1098 * @ff: force feedback structure associated with the device if device 1124 1099 * supports force feedback effects 1125 1100 * @repeat_key: stores key code of the last key pressed; used to implement ··· 1193 1168 unsigned int keycodemax; 1194 1169 unsigned int keycodesize; 1195 1170 void *keycode; 1171 + 1196 1172 int (*setkeycode)(struct input_dev *dev, 1197 1173 unsigned int scancode, unsigned int keycode); 1198 1174 int (*getkeycode)(struct input_dev *dev, 1199 1175 unsigned int scancode, unsigned int *keycode); 1176 + int (*setkeycode_new)(struct input_dev *dev, 1177 + const struct input_keymap_entry *ke, 1178 + unsigned int *old_keycode); 1179 + int (*getkeycode_new)(struct input_dev *dev, 1180 + struct input_keymap_entry *ke); 1200 1181 1201 1182 struct ff_device *ff; 1202 1183 ··· 1509 1478 INPUT_GENERATE_ABS_ACCESSORS(flat, flat) 1510 1479 INPUT_GENERATE_ABS_ACCESSORS(res, resolution) 1511 1480 1512 - int input_get_keycode(struct input_dev *dev, 1513 - unsigned int scancode, unsigned int *keycode); 1481 + int input_scancode_to_scalar(const struct input_keymap_entry *ke, 1482 + unsigned int *scancode); 1483 + 1484 + int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke); 1514 1485 int input_set_keycode(struct input_dev *dev, 1515 - unsigned int scancode, unsigned int keycode); 1486 + const struct input_keymap_entry *ke); 1516 1487 1517 1488 extern struct class input_class; 1518 1489
+44
include/linux/input/bu21013.h
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson 4 + * License terms:GNU General Public License (GPL) version 2 5 + */ 6 + 7 + #ifndef _BU21013_H 8 + #define _BU21013_H 9 + 10 + /** 11 + * struct bu21013_platform_device - Handle the platform data 12 + * @cs_en: pointer to the cs enable function 13 + * @cs_dis: pointer to the cs disable function 14 + * @irq_read_val: pointer to read the pen irq value function 15 + * @x_max_res: xmax resolution 16 + * @y_max_res: ymax resolution 17 + * @touch_x_max: touch x max 18 + * @touch_y_max: touch y max 19 + * @cs_pin: chip select pin 20 + * @irq: irq pin 21 + * @ext_clk: external clock flag 22 + * @x_flip: x flip flag 23 + * @y_flip: y flip flag 24 + * @wakeup: wakeup flag 25 + * 26 + * This is used to handle the platform data 27 + */ 28 + struct bu21013_platform_device { 29 + int (*cs_en)(int reset_pin); 30 + int (*cs_dis)(int reset_pin); 31 + int (*irq_read_val)(void); 32 + int x_max_res; 33 + int y_max_res; 34 + int touch_x_max; 35 + int touch_y_max; 36 + unsigned int cs_pin; 37 + unsigned int irq; 38 + bool ext_clk; 39 + bool x_flip; 40 + bool y_flip; 41 + bool wakeup; 42 + }; 43 + 44 + #endif
+6 -4
include/linux/serio.h
··· 41 41 int (*start)(struct serio *); 42 42 void (*stop)(struct serio *); 43 43 44 - struct serio *parent, *child; 44 + struct serio *parent; 45 + struct list_head child_node; /* Entry in parent->children list */ 46 + struct list_head children; 45 47 unsigned int depth; /* level of nesting in serio hierarchy */ 46 48 47 49 struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock and serio->sem */ ··· 56 54 #define to_serio_port(d) container_of(d, struct serio, dev) 57 55 58 56 struct serio_driver { 59 - void *private; 60 - char *description; 57 + const char *description; 61 58 62 - struct serio_device_id *id_table; 59 + const struct serio_device_id *id_table; 63 60 bool manual_bind; 64 61 65 62 void (*write_wakeup)(struct serio *); ··· 198 197 #define SERIO_W8001 0x39 199 198 #define SERIO_DYNAPRO 0x3a 200 199 #define SERIO_HAMPSHIRE 0x3b 200 + #define SERIO_PS2MULT 0x3c 201 201 202 202 #endif
+1 -1
include/media/rc-map.h
··· 35 35 unsigned int len; /* Used number of entries */ 36 36 unsigned int alloc; /* Size of *scan in bytes */ 37 37 u64 ir_type; 38 - char *name; 38 + const char *name; 39 39 spinlock_t lock; 40 40 }; 41 41