summaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2013-05-01 11:47:44 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-05-01 11:47:44 -0400
commitbf61c8840efe60fd8f91446860b63338fb424158 (patch)
tree7a71832407a4f0d6346db773343f4c3ae2257b19 /drivers/input
parent5846115b30f3a881e542c8bfde59a699c1c13740 (diff)
parent0c6a61657da78098472fd0eb71cc01f2387fa1bb (diff)
Merge branch 'next' into for-linus
Prepare first set of updates for 3.10 merge window.
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/input-mt.c10
-rw-r--r--drivers/input/joystick/analog.c2
-rw-r--r--drivers/input/keyboard/Kconfig3
-rw-r--r--drivers/input/keyboard/amikbd.c14
-rw-r--r--drivers/input/keyboard/davinci_keyscan.c12
-rw-r--r--drivers/input/keyboard/imx_keypad.c77
-rw-r--r--drivers/input/keyboard/matrix_keypad.c8
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c12
-rw-r--r--drivers/input/keyboard/spear-keyboard.c8
-rw-r--r--drivers/input/keyboard/tca8418_keypad.c2
-rw-r--r--drivers/input/keyboard/tegra-kbc.c91
-rw-r--r--drivers/input/misc/Kconfig20
-rw-r--r--drivers/input/misc/Makefile2
-rw-r--r--drivers/input/misc/ad714x-i2c.c2
-rw-r--r--drivers/input/misc/ad714x-spi.c2
-rw-r--r--drivers/input/misc/adxl34x-i2c.c2
-rw-r--r--drivers/input/misc/adxl34x-spi.c8
-rw-r--r--drivers/input/misc/arizona-haptics.c255
-rw-r--r--drivers/input/misc/atlas_btns.c2
-rw-r--r--drivers/input/misc/da9052_onkey.c22
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c15
-rw-r--r--drivers/input/misc/ims-pcu.c1901
-rw-r--r--drivers/input/misc/max8925_onkey.c3
-rw-r--r--drivers/input/misc/mma8450.c6
-rw-r--r--drivers/input/misc/twl4030-pwrbutton.c12
-rw-r--r--drivers/input/mouse/alps.c12
-rw-r--r--drivers/input/mouse/amimouse.c14
-rw-r--r--drivers/input/mouse/trackpoint.c249
-rw-r--r--drivers/input/mouse/trackpoint.h4
-rw-r--r--drivers/input/serio/Kconfig13
-rw-r--r--drivers/input/serio/Makefile1
-rw-r--r--drivers/input/serio/apbps2.c228
-rw-r--r--drivers/input/serio/arc_ps2.c21
-rw-r--r--drivers/input/serio/at32psif.c13
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h9
-rw-r--r--drivers/input/serio/q40kbd.c13
-rw-r--r--drivers/input/touchscreen/Kconfig6
-rw-r--r--drivers/input/touchscreen/Makefile2
-rw-r--r--drivers/input/touchscreen/ad7877.c10
-rw-r--r--drivers/input/touchscreen/ads7846.c4
-rw-r--r--drivers/input/touchscreen/atmel-wm97xx.c12
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c68
-rw-r--r--drivers/input/touchscreen/atmel_tsadcc.c2
-rw-r--r--drivers/input/touchscreen/auo-pixcir-ts.c226
-rw-r--r--drivers/input/touchscreen/da9052_tsi.c59
-rw-r--r--drivers/input/touchscreen/edt-ft5x06.c3
-rw-r--r--drivers/input/touchscreen/eeti_ts.c3
-rw-r--r--drivers/input/touchscreen/mc13783_ts.c12
-rw-r--r--drivers/input/touchscreen/st1232.c77
-rw-r--r--drivers/input/touchscreen/ti_am335x_tsc.c398
-rw-r--r--drivers/input/touchscreen/ti_tscadc.c486
-rw-r--r--drivers/input/touchscreen/wm9712.c28
-rw-r--r--drivers/input/touchscreen/wm97xx-core.c11
53 files changed, 3472 insertions, 1003 deletions
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index 53eaf89f2db5..d398f1321f14 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -79,6 +79,8 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
79 } 79 }
80 if (flags & INPUT_MT_DIRECT) 80 if (flags & INPUT_MT_DIRECT)
81 __set_bit(INPUT_PROP_DIRECT, dev->propbit); 81 __set_bit(INPUT_PROP_DIRECT, dev->propbit);
82 if (flags & INPUT_MT_SEMI_MT)
83 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
82 if (flags & INPUT_MT_TRACK) { 84 if (flags & INPUT_MT_TRACK) {
83 unsigned int n2 = num_slots * num_slots; 85 unsigned int n2 = num_slots * num_slots;
84 mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL); 86 mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL);
@@ -246,20 +248,24 @@ void input_mt_sync_frame(struct input_dev *dev)
246{ 248{
247 struct input_mt *mt = dev->mt; 249 struct input_mt *mt = dev->mt;
248 struct input_mt_slot *s; 250 struct input_mt_slot *s;
251 bool use_count = false;
249 252
250 if (!mt) 253 if (!mt)
251 return; 254 return;
252 255
253 if (mt->flags & INPUT_MT_DROP_UNUSED) { 256 if (mt->flags & INPUT_MT_DROP_UNUSED) {
254 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) { 257 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
255 if (s->frame == mt->frame) 258 if (input_mt_is_used(mt, s))
256 continue; 259 continue;
257 input_mt_slot(dev, s - mt->slots); 260 input_mt_slot(dev, s - mt->slots);
258 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); 261 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
259 } 262 }
260 } 263 }
261 264
262 input_mt_report_pointer_emulation(dev, (mt->flags & INPUT_MT_POINTER)); 265 if ((mt->flags & INPUT_MT_POINTER) && !(mt->flags & INPUT_MT_SEMI_MT))
266 use_count = true;
267
268 input_mt_report_pointer_emulation(dev, use_count);
263 269
264 mt->frame++; 270 mt->frame++;
265} 271}
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 358cd7ee905b..7cd74e29cbc8 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -162,7 +162,7 @@ static unsigned int get_time_pit(void)
162#define GET_TIME(x) do { x = get_cycles(); } while (0) 162#define GET_TIME(x) do { x = get_cycles(); } while (0)
163#define DELTA(x,y) ((y)-(x)) 163#define DELTA(x,y) ((y)-(x))
164#define TIME_NAME "PCC" 164#define TIME_NAME "PCC"
165#elif defined(CONFIG_MN10300) 165#elif defined(CONFIG_MN10300) || defined(CONFIG_TILE)
166#define GET_TIME(x) do { x = get_cycles(); } while (0) 166#define GET_TIME(x) do { x = get_cycles(); } while (0)
167#define DELTA(x, y) ((x) - (y)) 167#define DELTA(x, y) ((x) - (y))
168#define TIME_NAME "TSC" 168#define TIME_NAME "TSC"
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 992137cf3a64..ac0500667000 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -409,7 +409,7 @@ config KEYBOARD_NEWTON
409 409
410config KEYBOARD_NOMADIK 410config KEYBOARD_NOMADIK
411 tristate "ST-Ericsson Nomadik SKE keyboard" 411 tristate "ST-Ericsson Nomadik SKE keyboard"
412 depends on PLAT_NOMADIK 412 depends on (ARCH_NOMADIK || ARCH_U8500)
413 select INPUT_MATRIXKMAP 413 select INPUT_MATRIXKMAP
414 help 414 help
415 Say Y here if you want to use a keypad provided on the SKE controller 415 Say Y here if you want to use a keypad provided on the SKE controller
@@ -554,6 +554,7 @@ config KEYBOARD_OMAP
554 554
555config KEYBOARD_OMAP4 555config KEYBOARD_OMAP4
556 tristate "TI OMAP4+ keypad support" 556 tristate "TI OMAP4+ keypad support"
557 depends on ARCH_OMAP2PLUS
557 select INPUT_MATRIXKMAP 558 select INPUT_MATRIXKMAP
558 help 559 help
559 Say Y here if you want to use the OMAP4+ keypad. 560 Say Y here if you want to use the OMAP4+ keypad.
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 79172af164f2..ba0b36f7daea 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -260,18 +260,6 @@ static struct platform_driver amikbd_driver = {
260 }, 260 },
261}; 261};
262 262
263static int __init amikbd_init(void) 263module_platform_driver_probe(amikbd_driver, amikbd_probe);
264{
265 return platform_driver_probe(&amikbd_driver, amikbd_probe);
266}
267
268module_init(amikbd_init);
269
270static void __exit amikbd_exit(void)
271{
272 platform_driver_unregister(&amikbd_driver);
273}
274
275module_exit(amikbd_exit);
276 264
277MODULE_ALIAS("platform:amiga-keyboard"); 265MODULE_ALIAS("platform:amiga-keyboard");
diff --git a/drivers/input/keyboard/davinci_keyscan.c b/drivers/input/keyboard/davinci_keyscan.c
index 4e4e453ea15e..829753702b62 100644
--- a/drivers/input/keyboard/davinci_keyscan.c
+++ b/drivers/input/keyboard/davinci_keyscan.c
@@ -329,17 +329,7 @@ static struct platform_driver davinci_ks_driver = {
329 .remove = davinci_ks_remove, 329 .remove = davinci_ks_remove,
330}; 330};
331 331
332static int __init davinci_ks_init(void) 332module_platform_driver_probe(davinci_ks_driver, davinci_ks_probe);
333{
334 return platform_driver_probe(&davinci_ks_driver, davinci_ks_probe);
335}
336module_init(davinci_ks_init);
337
338static void __exit davinci_ks_exit(void)
339{
340 platform_driver_unregister(&davinci_ks_driver);
341}
342module_exit(davinci_ks_exit);
343 333
344MODULE_AUTHOR("Miguel Aguilar"); 334MODULE_AUTHOR("Miguel Aguilar");
345MODULE_DESCRIPTION("Texas Instruments DaVinci Key Scan Driver"); 335MODULE_DESCRIPTION("Texas Instruments DaVinci Key Scan Driver");
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index 98f9113251d2..03c8cc5cb6c1 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -448,24 +448,17 @@ static int imx_keypad_probe(struct platform_device *pdev)
448 return -EINVAL; 448 return -EINVAL;
449 } 449 }
450 450
451 res = request_mem_region(res->start, resource_size(res), pdev->name); 451 input_dev = devm_input_allocate_device(&pdev->dev);
452 if (res == NULL) {
453 dev_err(&pdev->dev, "failed to request I/O memory\n");
454 return -EBUSY;
455 }
456
457 input_dev = input_allocate_device();
458 if (!input_dev) { 452 if (!input_dev) {
459 dev_err(&pdev->dev, "failed to allocate the input device\n"); 453 dev_err(&pdev->dev, "failed to allocate the input device\n");
460 error = -ENOMEM; 454 return -ENOMEM;
461 goto failed_rel_mem;
462 } 455 }
463 456
464 keypad = kzalloc(sizeof(struct imx_keypad), GFP_KERNEL); 457 keypad = devm_kzalloc(&pdev->dev, sizeof(struct imx_keypad),
458 GFP_KERNEL);
465 if (!keypad) { 459 if (!keypad) {
466 dev_err(&pdev->dev, "not enough memory for driver data\n"); 460 dev_err(&pdev->dev, "not enough memory for driver data\n");
467 error = -ENOMEM; 461 return -ENOMEM;
468 goto failed_free_input;
469 } 462 }
470 463
471 keypad->input_dev = input_dev; 464 keypad->input_dev = input_dev;
@@ -475,18 +468,14 @@ static int imx_keypad_probe(struct platform_device *pdev)
475 setup_timer(&keypad->check_matrix_timer, 468 setup_timer(&keypad->check_matrix_timer,
476 imx_keypad_check_for_events, (unsigned long) keypad); 469 imx_keypad_check_for_events, (unsigned long) keypad);
477 470
478 keypad->mmio_base = ioremap(res->start, resource_size(res)); 471 keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res);
479 if (keypad->mmio_base == NULL) { 472 if (IS_ERR(keypad->mmio_base))
480 dev_err(&pdev->dev, "failed to remap I/O memory\n"); 473 return PTR_ERR(keypad->mmio_base);
481 error = -ENOMEM;
482 goto failed_free_priv;
483 }
484 474
485 keypad->clk = clk_get(&pdev->dev, NULL); 475 keypad->clk = devm_clk_get(&pdev->dev, NULL);
486 if (IS_ERR(keypad->clk)) { 476 if (IS_ERR(keypad->clk)) {
487 dev_err(&pdev->dev, "failed to get keypad clock\n"); 477 dev_err(&pdev->dev, "failed to get keypad clock\n");
488 error = PTR_ERR(keypad->clk); 478 return PTR_ERR(keypad->clk);
489 goto failed_unmap;
490 } 479 }
491 480
492 /* Init the Input device */ 481 /* Init the Input device */
@@ -502,7 +491,7 @@ static int imx_keypad_probe(struct platform_device *pdev)
502 keypad->keycodes, input_dev); 491 keypad->keycodes, input_dev);
503 if (error) { 492 if (error) {
504 dev_err(&pdev->dev, "failed to build keymap\n"); 493 dev_err(&pdev->dev, "failed to build keymap\n");
505 goto failed_clock_put; 494 return error;
506 } 495 }
507 496
508 /* Search for rows and cols enabled */ 497 /* Search for rows and cols enabled */
@@ -527,61 +516,24 @@ static int imx_keypad_probe(struct platform_device *pdev)
527 imx_keypad_inhibit(keypad); 516 imx_keypad_inhibit(keypad);
528 clk_disable_unprepare(keypad->clk); 517 clk_disable_unprepare(keypad->clk);
529 518
530 error = request_irq(irq, imx_keypad_irq_handler, 0, 519 error = devm_request_irq(&pdev->dev, irq, imx_keypad_irq_handler, 0,
531 pdev->name, keypad); 520 pdev->name, keypad);
532 if (error) { 521 if (error) {
533 dev_err(&pdev->dev, "failed to request IRQ\n"); 522 dev_err(&pdev->dev, "failed to request IRQ\n");
534 goto failed_clock_put; 523 return error;
535 } 524 }
536 525
537 /* Register the input device */ 526 /* Register the input device */
538 error = input_register_device(input_dev); 527 error = input_register_device(input_dev);
539 if (error) { 528 if (error) {
540 dev_err(&pdev->dev, "failed to register input device\n"); 529 dev_err(&pdev->dev, "failed to register input device\n");
541 goto failed_free_irq; 530 return error;
542 } 531 }
543 532
544 platform_set_drvdata(pdev, keypad); 533 platform_set_drvdata(pdev, keypad);
545 device_init_wakeup(&pdev->dev, 1); 534 device_init_wakeup(&pdev->dev, 1);
546 535
547 return 0; 536 return 0;
548
549failed_free_irq:
550 free_irq(irq, pdev);
551failed_clock_put:
552 clk_put(keypad->clk);
553failed_unmap:
554 iounmap(keypad->mmio_base);
555failed_free_priv:
556 kfree(keypad);
557failed_free_input:
558 input_free_device(input_dev);
559failed_rel_mem:
560 release_mem_region(res->start, resource_size(res));
561 return error;
562}
563
564static int imx_keypad_remove(struct platform_device *pdev)
565{
566 struct imx_keypad *keypad = platform_get_drvdata(pdev);
567 struct resource *res;
568
569 dev_dbg(&pdev->dev, ">%s\n", __func__);
570
571 platform_set_drvdata(pdev, NULL);
572
573 input_unregister_device(keypad->input_dev);
574
575 free_irq(keypad->irq, keypad);
576 clk_put(keypad->clk);
577
578 iounmap(keypad->mmio_base);
579 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
580 release_mem_region(res->start, resource_size(res));
581
582 kfree(keypad);
583
584 return 0;
585} 537}
586 538
587#ifdef CONFIG_PM_SLEEP 539#ifdef CONFIG_PM_SLEEP
@@ -640,7 +592,6 @@ static struct platform_driver imx_keypad_driver = {
640 .of_match_table = of_match_ptr(imx_keypad_of_match), 592 .of_match_table = of_match_ptr(imx_keypad_of_match),
641 }, 593 },
642 .probe = imx_keypad_probe, 594 .probe = imx_keypad_probe,
643 .remove = imx_keypad_remove,
644}; 595};
645module_platform_driver(imx_keypad_driver); 596module_platform_driver(imx_keypad_driver);
646 597
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index f4ff0dda7597..71d77192ac1e 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -403,7 +403,7 @@ matrix_keypad_parse_dt(struct device *dev)
403 struct matrix_keypad_platform_data *pdata; 403 struct matrix_keypad_platform_data *pdata;
404 struct device_node *np = dev->of_node; 404 struct device_node *np = dev->of_node;
405 unsigned int *gpios; 405 unsigned int *gpios;
406 int i; 406 int i, nrow, ncol;
407 407
408 if (!np) { 408 if (!np) {
409 dev_err(dev, "device lacks DT data\n"); 409 dev_err(dev, "device lacks DT data\n");
@@ -416,9 +416,9 @@ matrix_keypad_parse_dt(struct device *dev)
416 return ERR_PTR(-ENOMEM); 416 return ERR_PTR(-ENOMEM);
417 } 417 }
418 418
419 pdata->num_row_gpios = of_gpio_named_count(np, "row-gpios"); 419 pdata->num_row_gpios = nrow = of_gpio_named_count(np, "row-gpios");
420 pdata->num_col_gpios = of_gpio_named_count(np, "col-gpios"); 420 pdata->num_col_gpios = ncol = of_gpio_named_count(np, "col-gpios");
421 if (!pdata->num_row_gpios || !pdata->num_col_gpios) { 421 if (nrow <= 0 || ncol <= 0) {
422 dev_err(dev, "number of keypad rows/columns not specified\n"); 422 dev_err(dev, "number of keypad rows/columns not specified\n");
423 return ERR_PTR(-EINVAL); 423 return ERR_PTR(-EINVAL);
424 } 424 }
diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c
index 0e6a8151fee3..c7d505cce72f 100644
--- a/drivers/input/keyboard/nomadik-ske-keypad.c
+++ b/drivers/input/keyboard/nomadik-ske-keypad.c
@@ -430,17 +430,7 @@ static struct platform_driver ske_keypad_driver = {
430 .remove = ske_keypad_remove, 430 .remove = ske_keypad_remove,
431}; 431};
432 432
433static int __init ske_keypad_init(void) 433module_platform_driver_probe(ske_keypad_driver, ske_keypad_probe);
434{
435 return platform_driver_probe(&ske_keypad_driver, ske_keypad_probe);
436}
437module_init(ske_keypad_init);
438
439static void __exit ske_keypad_exit(void)
440{
441 platform_driver_unregister(&ske_keypad_driver);
442}
443module_exit(ske_keypad_exit);
444 434
445MODULE_LICENSE("GPL v2"); 435MODULE_LICENSE("GPL v2");
446MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>"); 436MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>");
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 695d237417d6..cb1e8f614631 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -228,11 +228,9 @@ static int spear_kbd_probe(struct platform_device *pdev)
228 kbd->suspended_rate = pdata->suspended_rate; 228 kbd->suspended_rate = pdata->suspended_rate;
229 } 229 }
230 230
231 kbd->io_base = devm_request_and_ioremap(&pdev->dev, res); 231 kbd->io_base = devm_ioremap_resource(&pdev->dev, res);
232 if (!kbd->io_base) { 232 if (IS_ERR(kbd->io_base))
233 dev_err(&pdev->dev, "request-ioremap failed for kbd_region\n"); 233 return PTR_ERR(kbd->io_base);
234 return -ENOMEM;
235 }
236 234
237 kbd->clk = devm_clk_get(&pdev->dev, NULL); 235 kbd->clk = devm_clk_get(&pdev->dev, NULL);
238 if (IS_ERR(kbd->clk)) 236 if (IS_ERR(kbd->clk))
diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c
index 50e9c5e195e1..a34cc6714e5b 100644
--- a/drivers/input/keyboard/tca8418_keypad.c
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -384,7 +384,7 @@ static const struct i2c_device_id tca8418_id[] = {
384MODULE_DEVICE_TABLE(i2c, tca8418_id); 384MODULE_DEVICE_TABLE(i2c, tca8418_id);
385 385
386#ifdef CONFIG_OF 386#ifdef CONFIG_OF
387static const struct of_device_id tca8418_dt_ids[] __devinitconst = { 387static const struct of_device_id tca8418_dt_ids[] = {
388 { .compatible = "ti,tca8418", }, 388 { .compatible = "ti,tca8418", },
389 { } 389 { }
390}; 390};
diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
index d89e7d392d1e..b46142f78ef2 100644
--- a/drivers/input/keyboard/tegra-kbc.c
+++ b/drivers/input/keyboard/tegra-kbc.c
@@ -27,17 +27,19 @@
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/of_device.h>
30#include <linux/clk.h> 31#include <linux/clk.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
32#include <linux/input/matrix_keypad.h> 33#include <linux/input/matrix_keypad.h>
33#include <mach/clk.h> 34#include <linux/clk/tegra.h>
35#include <linux/err.h>
34 36
35#define KBC_MAX_GPIO 24
36#define KBC_MAX_KPENT 8 37#define KBC_MAX_KPENT 8
37 38
38#define KBC_MAX_ROW 16 39/* Maximum row/column supported by Tegra KBC yet is 16x8 */
39#define KBC_MAX_COL 8 40#define KBC_MAX_GPIO 24
40#define KBC_MAX_KEY (KBC_MAX_ROW * KBC_MAX_COL) 41/* Maximum keys supported by Tegra KBC yet is 16 x 8*/
42#define KBC_MAX_KEY (16 * 8)
41 43
42#define KBC_MAX_DEBOUNCE_CNT 0x3ffu 44#define KBC_MAX_DEBOUNCE_CNT 0x3ffu
43 45
@@ -80,6 +82,12 @@ enum tegra_pin_type {
80 PIN_CFG_ROW, 82 PIN_CFG_ROW,
81}; 83};
82 84
85/* Tegra KBC hw support */
86struct tegra_kbc_hw_support {
87 int max_rows;
88 int max_columns;
89};
90
83struct tegra_kbc_pin_cfg { 91struct tegra_kbc_pin_cfg {
84 enum tegra_pin_type type; 92 enum tegra_pin_type type;
85 unsigned char num; 93 unsigned char num;
@@ -108,6 +116,9 @@ struct tegra_kbc {
108 u32 wakeup_key; 116 u32 wakeup_key;
109 struct timer_list timer; 117 struct timer_list timer;
110 struct clk *clk; 118 struct clk *clk;
119 const struct tegra_kbc_hw_support *hw_support;
120 int max_keys;
121 int num_rows_and_columns;
111}; 122};
112 123
113static void tegra_kbc_report_released_keys(struct input_dev *input, 124static void tegra_kbc_report_released_keys(struct input_dev *input,
@@ -204,11 +215,11 @@ static void tegra_kbc_report_keys(struct tegra_kbc *kbc)
204 215
205 /* 216 /*
206 * If the platform uses Fn keymaps, translate keys on a Fn keypress. 217 * If the platform uses Fn keymaps, translate keys on a Fn keypress.
207 * Function keycodes are KBC_MAX_KEY apart from the plain keycodes. 218 * Function keycodes are max_keys apart from the plain keycodes.
208 */ 219 */
209 if (fn_keypress) { 220 if (fn_keypress) {
210 for (i = 0; i < num_down; i++) { 221 for (i = 0; i < num_down; i++) {
211 scancodes[i] += KBC_MAX_KEY; 222 scancodes[i] += kbc->max_keys;
212 keycodes[i] = kbc->keycode[scancodes[i]]; 223 keycodes[i] = kbc->keycode[scancodes[i]];
213 } 224 }
214 } 225 }
@@ -315,7 +326,7 @@ static void tegra_kbc_setup_wakekeys(struct tegra_kbc *kbc, bool filter)
315 /* Either mask all keys or none. */ 326 /* Either mask all keys or none. */
316 rst_val = (filter && !kbc->wakeup) ? ~0 : 0; 327 rst_val = (filter && !kbc->wakeup) ? ~0 : 0;
317 328
318 for (i = 0; i < KBC_MAX_ROW; i++) 329 for (i = 0; i < kbc->hw_support->max_rows; i++)
319 writel(rst_val, kbc->mmio + KBC_ROW0_MASK_0 + i * 4); 330 writel(rst_val, kbc->mmio + KBC_ROW0_MASK_0 + i * 4);
320} 331}
321 332
@@ -452,7 +463,7 @@ static bool tegra_kbc_check_pin_cfg(const struct tegra_kbc *kbc,
452 463
453 switch (pin_cfg->type) { 464 switch (pin_cfg->type) {
454 case PIN_CFG_ROW: 465 case PIN_CFG_ROW:
455 if (pin_cfg->num >= KBC_MAX_ROW) { 466 if (pin_cfg->num >= kbc->hw_support->max_rows) {
456 dev_err(kbc->dev, 467 dev_err(kbc->dev,
457 "pin_cfg[%d]: invalid row number %d\n", 468 "pin_cfg[%d]: invalid row number %d\n",
458 i, pin_cfg->num); 469 i, pin_cfg->num);
@@ -462,7 +473,7 @@ static bool tegra_kbc_check_pin_cfg(const struct tegra_kbc *kbc,
462 break; 473 break;
463 474
464 case PIN_CFG_COL: 475 case PIN_CFG_COL:
465 if (pin_cfg->num >= KBC_MAX_COL) { 476 if (pin_cfg->num >= kbc->hw_support->max_columns) {
466 dev_err(kbc->dev, 477 dev_err(kbc->dev,
467 "pin_cfg[%d]: invalid column number %d\n", 478 "pin_cfg[%d]: invalid column number %d\n",
468 i, pin_cfg->num); 479 i, pin_cfg->num);
@@ -520,6 +531,18 @@ static int tegra_kbc_parse_dt(struct tegra_kbc *kbc)
520 } 531 }
521 num_cols = proplen / sizeof(u32); 532 num_cols = proplen / sizeof(u32);
522 533
534 if (num_rows > kbc->hw_support->max_rows) {
535 dev_err(kbc->dev,
536 "Number of rows is more than supported by hardware\n");
537 return -EINVAL;
538 }
539
540 if (num_cols > kbc->hw_support->max_columns) {
541 dev_err(kbc->dev,
542 "Number of cols is more than supported by hardware\n");
543 return -EINVAL;
544 }
545
523 if (!of_get_property(np, "linux,keymap", &proplen)) { 546 if (!of_get_property(np, "linux,keymap", &proplen)) {
524 dev_err(kbc->dev, "property linux,keymap not found\n"); 547 dev_err(kbc->dev, "property linux,keymap not found\n");
525 return -ENOENT; 548 return -ENOENT;
@@ -532,7 +555,7 @@ static int tegra_kbc_parse_dt(struct tegra_kbc *kbc)
532 } 555 }
533 556
534 /* Set all pins as non-configured */ 557 /* Set all pins as non-configured */
535 for (i = 0; i < KBC_MAX_GPIO; i++) 558 for (i = 0; i < kbc->num_rows_and_columns; i++)
536 kbc->pin_cfg[i].type = PIN_CFG_IGNORE; 559 kbc->pin_cfg[i].type = PIN_CFG_IGNORE;
537 560
538 ret = of_property_read_u32_array(np, "nvidia,kbc-row-pins", 561 ret = of_property_read_u32_array(np, "nvidia,kbc-row-pins",
@@ -562,6 +585,24 @@ static int tegra_kbc_parse_dt(struct tegra_kbc *kbc)
562 return 0; 585 return 0;
563} 586}
564 587
588static const struct tegra_kbc_hw_support tegra20_kbc_hw_support = {
589 .max_rows = 16,
590 .max_columns = 8,
591};
592
593static const struct tegra_kbc_hw_support tegra11_kbc_hw_support = {
594 .max_rows = 11,
595 .max_columns = 8,
596};
597
598static const struct of_device_id tegra_kbc_of_match[] = {
599 { .compatible = "nvidia,tegra114-kbc", .data = &tegra11_kbc_hw_support},
600 { .compatible = "nvidia,tegra30-kbc", .data = &tegra20_kbc_hw_support},
601 { .compatible = "nvidia,tegra20-kbc", .data = &tegra20_kbc_hw_support},
602 { },
603};
604MODULE_DEVICE_TABLE(of, tegra_kbc_of_match);
605
565static int tegra_kbc_probe(struct platform_device *pdev) 606static int tegra_kbc_probe(struct platform_device *pdev)
566{ 607{
567 struct tegra_kbc *kbc; 608 struct tegra_kbc *kbc;
@@ -570,7 +611,10 @@ static int tegra_kbc_probe(struct platform_device *pdev)
570 int num_rows = 0; 611 int num_rows = 0;
571 unsigned int debounce_cnt; 612 unsigned int debounce_cnt;
572 unsigned int scan_time_rows; 613 unsigned int scan_time_rows;
573 unsigned int keymap_rows = KBC_MAX_KEY; 614 unsigned int keymap_rows;
615 const struct of_device_id *match;
616
617 match = of_match_device(of_match_ptr(tegra_kbc_of_match), &pdev->dev);
574 618
575 kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); 619 kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL);
576 if (!kbc) { 620 if (!kbc) {
@@ -579,6 +623,12 @@ static int tegra_kbc_probe(struct platform_device *pdev)
579 } 623 }
580 624
581 kbc->dev = &pdev->dev; 625 kbc->dev = &pdev->dev;
626 kbc->hw_support = match->data;
627 kbc->max_keys = kbc->hw_support->max_rows *
628 kbc->hw_support->max_columns;
629 kbc->num_rows_and_columns = kbc->hw_support->max_rows +
630 kbc->hw_support->max_columns;
631 keymap_rows = kbc->max_keys;
582 spin_lock_init(&kbc->lock); 632 spin_lock_init(&kbc->lock);
583 633
584 err = tegra_kbc_parse_dt(kbc); 634 err = tegra_kbc_parse_dt(kbc);
@@ -608,11 +658,9 @@ static int tegra_kbc_probe(struct platform_device *pdev)
608 658
609 setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc); 659 setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc);
610 660
611 kbc->mmio = devm_request_and_ioremap(&pdev->dev, res); 661 kbc->mmio = devm_ioremap_resource(&pdev->dev, res);
612 if (!kbc->mmio) { 662 if (IS_ERR(kbc->mmio))
613 dev_err(&pdev->dev, "Cannot request memregion/iomap address\n"); 663 return PTR_ERR(kbc->mmio);
614 return -EBUSY;
615 }
616 664
617 kbc->clk = devm_clk_get(&pdev->dev, NULL); 665 kbc->clk = devm_clk_get(&pdev->dev, NULL);
618 if (IS_ERR(kbc->clk)) { 666 if (IS_ERR(kbc->clk)) {
@@ -641,7 +689,8 @@ static int tegra_kbc_probe(struct platform_device *pdev)
641 keymap_rows *= 2; 689 keymap_rows *= 2;
642 690
643 err = matrix_keypad_build_keymap(kbc->keymap_data, NULL, 691 err = matrix_keypad_build_keymap(kbc->keymap_data, NULL,
644 keymap_rows, KBC_MAX_COL, 692 keymap_rows,
693 kbc->hw_support->max_columns,
645 kbc->keycode, kbc->idev); 694 kbc->keycode, kbc->idev);
646 if (err) { 695 if (err) {
647 dev_err(&pdev->dev, "failed to setup keymap\n"); 696 dev_err(&pdev->dev, "failed to setup keymap\n");
@@ -767,12 +816,6 @@ static int tegra_kbc_resume(struct device *dev)
767 816
768static SIMPLE_DEV_PM_OPS(tegra_kbc_pm_ops, tegra_kbc_suspend, tegra_kbc_resume); 817static SIMPLE_DEV_PM_OPS(tegra_kbc_pm_ops, tegra_kbc_suspend, tegra_kbc_resume);
769 818
770static const struct of_device_id tegra_kbc_of_match[] = {
771 { .compatible = "nvidia,tegra20-kbc", },
772 { },
773};
774MODULE_DEVICE_TABLE(of, tegra_kbc_of_match);
775
776static struct platform_driver tegra_kbc_driver = { 819static struct platform_driver tegra_kbc_driver = {
777 .probe = tegra_kbc_probe, 820 .probe = tegra_kbc_probe,
778 .driver = { 821 .driver = {
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 2a1647ef5610..af80928a46b4 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -72,6 +72,16 @@ config INPUT_AD714X_SPI
72 To compile this driver as a module, choose M here: the 72 To compile this driver as a module, choose M here: the
73 module will be called ad714x-spi. 73 module will be called ad714x-spi.
74 74
75config INPUT_ARIZONA_HAPTICS
76 tristate "Arizona haptics support"
77 depends on MFD_ARIZONA && SND_SOC
78 select INPUT_FF_MEMLESS
79 help
80 Say Y to enable support for the haptics module in Arizona CODECs.
81
82 To compile this driver as a module, choose M here: the
83 module will be called arizona-haptics.
84
75config INPUT_BMA150 85config INPUT_BMA150
76 tristate "BMA150/SMB380 acceleration sensor support" 86 tristate "BMA150/SMB380 acceleration sensor support"
77 depends on I2C 87 depends on I2C
@@ -580,6 +590,16 @@ config INPUT_ADXL34X_SPI
580 To compile this driver as a module, choose M here: the 590 To compile this driver as a module, choose M here: the
581 module will be called adxl34x-spi. 591 module will be called adxl34x-spi.
582 592
593config INPUT_IMS_PCU
594 tristate "IMS Passenger Control Unit driver"
595 depends on USB
596 depends on LEDS_CLASS
597 help
598 Say Y here if you have system with IMS Rave Passenger Control Unit.
599
600 To compile this driver as a module, choose M here: the module will be
601 called ims_pcu.
602
583config INPUT_CMA3000 603config INPUT_CMA3000
584 tristate "VTI CMA3000 Tri-axis accelerometer" 604 tristate "VTI CMA3000 Tri-axis accelerometer"
585 help 605 help
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 1f874afeea6a..d7fc17f11d77 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_INPUT_ADXL34X) += adxl34x.o
14obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o 14obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o
15obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o 15obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o
16obj-$(CONFIG_INPUT_APANEL) += apanel.o 16obj-$(CONFIG_INPUT_APANEL) += apanel.o
17obj-$(CONFIG_INPUT_ARIZONA_HAPTICS) += arizona-haptics.o
17obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o 18obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
18obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o 19obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o
19obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o 20obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o
@@ -28,6 +29,7 @@ obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o
28obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o 29obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o
29obj-$(CONFIG_INPUT_GPIO_TILT_POLLED) += gpio_tilt_polled.o 30obj-$(CONFIG_INPUT_GPIO_TILT_POLLED) += gpio_tilt_polled.o
30obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o 31obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
32obj-$(CONFIG_INPUT_IMS_PCU) += ims-pcu.o
31obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o 33obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o
32obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o 34obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o
33obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o 35obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c
index 29d2064c26f2..e0f522516ef5 100644
--- a/drivers/input/misc/ad714x-i2c.c
+++ b/drivers/input/misc/ad714x-i2c.c
@@ -13,7 +13,7 @@
13#include <linux/pm.h> 13#include <linux/pm.h>
14#include "ad714x.h" 14#include "ad714x.h"
15 15
16#ifdef CONFIG_PM 16#ifdef CONFIG_PM_SLEEP
17static int ad714x_i2c_suspend(struct device *dev) 17static int ad714x_i2c_suspend(struct device *dev)
18{ 18{
19 return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev))); 19 return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev)));
diff --git a/drivers/input/misc/ad714x-spi.c b/drivers/input/misc/ad714x-spi.c
index bdccca42d138..61891486067c 100644
--- a/drivers/input/misc/ad714x-spi.c
+++ b/drivers/input/misc/ad714x-spi.c
@@ -16,7 +16,7 @@
16#define AD714x_SPI_CMD_PREFIX 0xE000 /* bits 15:11 */ 16#define AD714x_SPI_CMD_PREFIX 0xE000 /* bits 15:11 */
17#define AD714x_SPI_READ BIT(10) 17#define AD714x_SPI_READ BIT(10)
18 18
19#ifdef CONFIG_PM 19#ifdef CONFIG_PM_SLEEP
20static int ad714x_spi_suspend(struct device *dev) 20static int ad714x_spi_suspend(struct device *dev)
21{ 21{
22 return ad714x_disable(spi_get_drvdata(to_spi_device(dev))); 22 return ad714x_disable(spi_get_drvdata(to_spi_device(dev)));
diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c
index 535dda48cace..416f47ddcc90 100644
--- a/drivers/input/misc/adxl34x-i2c.c
+++ b/drivers/input/misc/adxl34x-i2c.c
@@ -105,7 +105,7 @@ static int adxl34x_i2c_remove(struct i2c_client *client)
105 return adxl34x_remove(ac); 105 return adxl34x_remove(ac);
106} 106}
107 107
108#ifdef CONFIG_PM 108#ifdef CONFIG_PM_SLEEP
109static int adxl34x_i2c_suspend(struct device *dev) 109static int adxl34x_i2c_suspend(struct device *dev)
110{ 110{
111 struct i2c_client *client = to_i2c_client(dev); 111 struct i2c_client *client = to_i2c_client(dev);
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c
index ad5f40d37e48..76dc0679d3b1 100644
--- a/drivers/input/misc/adxl34x-spi.c
+++ b/drivers/input/misc/adxl34x-spi.c
@@ -89,16 +89,16 @@ static int adxl34x_spi_probe(struct spi_device *spi)
89 89
90static int adxl34x_spi_remove(struct spi_device *spi) 90static int adxl34x_spi_remove(struct spi_device *spi)
91{ 91{
92 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 92 struct adxl34x *ac = spi_get_drvdata(spi);
93 93
94 return adxl34x_remove(ac); 94 return adxl34x_remove(ac);
95} 95}
96 96
97#ifdef CONFIG_PM 97#ifdef CONFIG_PM_SLEEP
98static int adxl34x_spi_suspend(struct device *dev) 98static int adxl34x_spi_suspend(struct device *dev)
99{ 99{
100 struct spi_device *spi = to_spi_device(dev); 100 struct spi_device *spi = to_spi_device(dev);
101 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 101 struct adxl34x *ac = spi_get_drvdata(spi);
102 102
103 adxl34x_suspend(ac); 103 adxl34x_suspend(ac);
104 104
@@ -108,7 +108,7 @@ static int adxl34x_spi_suspend(struct device *dev)
108static int adxl34x_spi_resume(struct device *dev) 108static int adxl34x_spi_resume(struct device *dev)
109{ 109{
110 struct spi_device *spi = to_spi_device(dev); 110 struct spi_device *spi = to_spi_device(dev);
111 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 111 struct adxl34x *ac = spi_get_drvdata(spi);
112 112
113 adxl34x_resume(ac); 113 adxl34x_resume(ac);
114 114
diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c
new file mode 100644
index 000000000000..7a04f54ef961
--- /dev/null
+++ b/drivers/input/misc/arizona-haptics.c
@@ -0,0 +1,255 @@
1/*
2 * Arizona haptics driver
3 *
4 * Copyright 2012 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/input.h>
16#include <linux/slab.h>
17
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20
21#include <linux/mfd/arizona/core.h>
22#include <linux/mfd/arizona/pdata.h>
23#include <linux/mfd/arizona/registers.h>
24
25struct arizona_haptics {
26 struct arizona *arizona;
27 struct input_dev *input_dev;
28 struct work_struct work;
29
30 struct mutex mutex;
31 u8 intensity;
32};
33
34static void arizona_haptics_work(struct work_struct *work)
35{
36 struct arizona_haptics *haptics = container_of(work,
37 struct arizona_haptics,
38 work);
39 struct arizona *arizona = haptics->arizona;
40 struct mutex *dapm_mutex = &arizona->dapm->card->dapm_mutex;
41 int ret;
42
43 if (!haptics->arizona->dapm) {
44 dev_err(arizona->dev, "No DAPM context\n");
45 return;
46 }
47
48 if (haptics->intensity) {
49 ret = regmap_update_bits(arizona->regmap,
50 ARIZONA_HAPTICS_PHASE_2_INTENSITY,
51 ARIZONA_PHASE2_INTENSITY_MASK,
52 haptics->intensity);
53 if (ret != 0) {
54 dev_err(arizona->dev, "Failed to set intensity: %d\n",
55 ret);
56 return;
57 }
58
59 /* This enable sequence will be a noop if already enabled */
60 ret = regmap_update_bits(arizona->regmap,
61 ARIZONA_HAPTICS_CONTROL_1,
62 ARIZONA_HAP_CTRL_MASK,
63 1 << ARIZONA_HAP_CTRL_SHIFT);
64 if (ret != 0) {
65 dev_err(arizona->dev, "Failed to start haptics: %d\n",
66 ret);
67 return;
68 }
69
70 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
71
72 ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS");
73 if (ret != 0) {
74 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
75 ret);
76 mutex_unlock(dapm_mutex);
77 return;
78 }
79
80 ret = snd_soc_dapm_sync(arizona->dapm);
81 if (ret != 0) {
82 dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
83 ret);
84 mutex_unlock(dapm_mutex);
85 return;
86 }
87
88 mutex_unlock(dapm_mutex);
89
90 } else {
91 /* This disable sequence will be a noop if already enabled */
92 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
93
94 ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS");
95 if (ret != 0) {
96 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
97 ret);
98 mutex_unlock(dapm_mutex);
99 return;
100 }
101
102 ret = snd_soc_dapm_sync(arizona->dapm);
103 if (ret != 0) {
104 dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
105 ret);
106 mutex_unlock(dapm_mutex);
107 return;
108 }
109
110 mutex_unlock(dapm_mutex);
111
112 ret = regmap_update_bits(arizona->regmap,
113 ARIZONA_HAPTICS_CONTROL_1,
114 ARIZONA_HAP_CTRL_MASK,
115 1 << ARIZONA_HAP_CTRL_SHIFT);
116 if (ret != 0) {
117 dev_err(arizona->dev, "Failed to stop haptics: %d\n",
118 ret);
119 return;
120 }
121 }
122}
123
124static int arizona_haptics_play(struct input_dev *input, void *data,
125 struct ff_effect *effect)
126{
127 struct arizona_haptics *haptics = input_get_drvdata(input);
128 struct arizona *arizona = haptics->arizona;
129
130 if (!arizona->dapm) {
131 dev_err(arizona->dev, "No DAPM context\n");
132 return -EBUSY;
133 }
134
135 if (effect->u.rumble.strong_magnitude) {
136 /* Scale the magnitude into the range the device supports */
137 if (arizona->pdata.hap_act) {
138 haptics->intensity =
139 effect->u.rumble.strong_magnitude >> 9;
140 if (effect->direction < 0x8000)
141 haptics->intensity += 0x7f;
142 } else {
143 haptics->intensity =
144 effect->u.rumble.strong_magnitude >> 8;
145 }
146 } else {
147 haptics->intensity = 0;
148 }
149
150 schedule_work(&haptics->work);
151
152 return 0;
153}
154
155static void arizona_haptics_close(struct input_dev *input)
156{
157 struct arizona_haptics *haptics = input_get_drvdata(input);
158 struct mutex *dapm_mutex = &haptics->arizona->dapm->card->dapm_mutex;
159
160 cancel_work_sync(&haptics->work);
161
162 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
163
164 if (haptics->arizona->dapm)
165 snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS");
166
167 mutex_unlock(dapm_mutex);
168}
169
170static int arizona_haptics_probe(struct platform_device *pdev)
171{
172 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
173 struct arizona_haptics *haptics;
174 int ret;
175
176 haptics = devm_kzalloc(&pdev->dev, sizeof(*haptics), GFP_KERNEL);
177 if (!haptics)
178 return -ENOMEM;
179
180 haptics->arizona = arizona;
181
182 ret = regmap_update_bits(arizona->regmap, ARIZONA_HAPTICS_CONTROL_1,
183 ARIZONA_HAP_ACT, arizona->pdata.hap_act);
184 if (ret != 0) {
185 dev_err(arizona->dev, "Failed to set haptics actuator: %d\n",
186 ret);
187 return ret;
188 }
189
190 INIT_WORK(&haptics->work, arizona_haptics_work);
191
192 haptics->input_dev = input_allocate_device();
193 if (haptics->input_dev == NULL) {
194 dev_err(arizona->dev, "Failed to allocate input device\n");
195 return -ENOMEM;
196 }
197
198 input_set_drvdata(haptics->input_dev, haptics);
199
200 haptics->input_dev->name = "arizona:haptics";
201 haptics->input_dev->dev.parent = pdev->dev.parent;
202 haptics->input_dev->close = arizona_haptics_close;
203 __set_bit(FF_RUMBLE, haptics->input_dev->ffbit);
204
205 ret = input_ff_create_memless(haptics->input_dev, NULL,
206 arizona_haptics_play);
207 if (ret < 0) {
208 dev_err(arizona->dev, "input_ff_create_memless() failed: %d\n",
209 ret);
210 goto err_ialloc;
211 }
212
213 ret = input_register_device(haptics->input_dev);
214 if (ret < 0) {
215 dev_err(arizona->dev, "couldn't register input device: %d\n",
216 ret);
217 goto err_iff;
218 }
219
220 platform_set_drvdata(pdev, haptics);
221
222 return 0;
223
224err_iff:
225 if (haptics->input_dev)
226 input_ff_destroy(haptics->input_dev);
227err_ialloc:
228 input_free_device(haptics->input_dev);
229
230 return ret;
231}
232
233static int arizona_haptics_remove(struct platform_device *pdev)
234{
235 struct arizona_haptics *haptics = platform_get_drvdata(pdev);
236
237 input_unregister_device(haptics->input_dev);
238
239 return 0;
240}
241
242static struct platform_driver arizona_haptics_driver = {
243 .probe = arizona_haptics_probe,
244 .remove = arizona_haptics_remove,
245 .driver = {
246 .name = "arizona-haptics",
247 .owner = THIS_MODULE,
248 },
249};
250module_platform_driver(arizona_haptics_driver);
251
252MODULE_ALIAS("platform:arizona-haptics");
253MODULE_DESCRIPTION("Arizona haptics driver");
254MODULE_LICENSE("GPL");
255MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
index 26f13131639a..5d4402365a52 100644
--- a/drivers/input/misc/atlas_btns.c
+++ b/drivers/input/misc/atlas_btns.c
@@ -121,7 +121,7 @@ static int atlas_acpi_button_add(struct acpi_device *device)
121 return err; 121 return err;
122} 122}
123 123
124static int atlas_acpi_button_remove(struct acpi_device *device, int type) 124static int atlas_acpi_button_remove(struct acpi_device *device)
125{ 125{
126 acpi_status status; 126 acpi_status status;
127 127
diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
index 630c1ce4980a..020569a499f2 100644
--- a/drivers/input/misc/da9052_onkey.c
+++ b/drivers/input/misc/da9052_onkey.c
@@ -24,7 +24,6 @@ struct da9052_onkey {
24 struct da9052 *da9052; 24 struct da9052 *da9052;
25 struct input_dev *input; 25 struct input_dev *input;
26 struct delayed_work work; 26 struct delayed_work work;
27 unsigned int irq;
28}; 27};
29 28
30static void da9052_onkey_query(struct da9052_onkey *onkey) 29static void da9052_onkey_query(struct da9052_onkey *onkey)
@@ -76,7 +75,6 @@ static int da9052_onkey_probe(struct platform_device *pdev)
76 struct da9052 *da9052 = dev_get_drvdata(pdev->dev.parent); 75 struct da9052 *da9052 = dev_get_drvdata(pdev->dev.parent);
77 struct da9052_onkey *onkey; 76 struct da9052_onkey *onkey;
78 struct input_dev *input_dev; 77 struct input_dev *input_dev;
79 int irq;
80 int error; 78 int error;
81 79
82 if (!da9052) { 80 if (!da9052) {
@@ -84,13 +82,6 @@ static int da9052_onkey_probe(struct platform_device *pdev)
84 return -EINVAL; 82 return -EINVAL;
85 } 83 }
86 84
87 irq = platform_get_irq_byname(pdev, "ONKEY");
88 if (irq < 0) {
89 dev_err(&pdev->dev,
90 "Failed to get an IRQ for input device, %d\n", irq);
91 return -EINVAL;
92 }
93
94 onkey = kzalloc(sizeof(*onkey), GFP_KERNEL); 85 onkey = kzalloc(sizeof(*onkey), GFP_KERNEL);
95 input_dev = input_allocate_device(); 86 input_dev = input_allocate_device();
96 if (!onkey || !input_dev) { 87 if (!onkey || !input_dev) {
@@ -101,7 +92,6 @@ static int da9052_onkey_probe(struct platform_device *pdev)
101 92
102 onkey->input = input_dev; 93 onkey->input = input_dev;
103 onkey->da9052 = da9052; 94 onkey->da9052 = da9052;
104 onkey->irq = irq;
105 INIT_DELAYED_WORK(&onkey->work, da9052_onkey_work); 95 INIT_DELAYED_WORK(&onkey->work, da9052_onkey_work);
106 96
107 input_dev->name = "da9052-onkey"; 97 input_dev->name = "da9052-onkey";
@@ -111,13 +101,11 @@ static int da9052_onkey_probe(struct platform_device *pdev)
111 input_dev->evbit[0] = BIT_MASK(EV_KEY); 101 input_dev->evbit[0] = BIT_MASK(EV_KEY);
112 __set_bit(KEY_POWER, input_dev->keybit); 102 __set_bit(KEY_POWER, input_dev->keybit);
113 103
114 error = request_threaded_irq(onkey->irq, NULL, da9052_onkey_irq, 104 error = da9052_request_irq(onkey->da9052, DA9052_IRQ_NONKEY, "ONKEY",
115 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 105 da9052_onkey_irq, onkey);
116 "ONKEY", onkey);
117 if (error < 0) { 106 if (error < 0) {
118 dev_err(onkey->da9052->dev, 107 dev_err(onkey->da9052->dev,
119 "Failed to register ONKEY IRQ %d, error = %d\n", 108 "Failed to register ONKEY IRQ: %d\n", error);
120 onkey->irq, error);
121 goto err_free_mem; 109 goto err_free_mem;
122 } 110 }
123 111
@@ -132,7 +120,7 @@ static int da9052_onkey_probe(struct platform_device *pdev)
132 return 0; 120 return 0;
133 121
134err_free_irq: 122err_free_irq:
135 free_irq(onkey->irq, onkey); 123 da9052_free_irq(onkey->da9052, DA9052_IRQ_NONKEY, onkey);
136 cancel_delayed_work_sync(&onkey->work); 124 cancel_delayed_work_sync(&onkey->work);
137err_free_mem: 125err_free_mem:
138 input_free_device(input_dev); 126 input_free_device(input_dev);
@@ -145,7 +133,7 @@ static int da9052_onkey_remove(struct platform_device *pdev)
145{ 133{
146 struct da9052_onkey *onkey = platform_get_drvdata(pdev); 134 struct da9052_onkey *onkey = platform_get_drvdata(pdev);
147 135
148 free_irq(onkey->irq, onkey); 136 da9052_free_irq(onkey->da9052, DA9052_IRQ_NONKEY, onkey);
149 cancel_delayed_work_sync(&onkey->work); 137 cancel_delayed_work_sync(&onkey->work);
150 138
151 input_unregister_device(onkey->input); 139 input_unregister_device(onkey->input);
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index 0b4f54265f62..2e3334b8f82d 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -109,7 +109,9 @@ static int hp_sdc_rtc_do_read_bbrtc (struct rtc_time *rtctm)
109 109
110 if (hp_sdc_enqueue_transaction(&t)) return -1; 110 if (hp_sdc_enqueue_transaction(&t)) return -1;
111 111
112 down_interruptible(&tsem); /* Put ourselves to sleep for results. */ 112 /* Put ourselves to sleep for results. */
113 if (WARN_ON(down_interruptible(&tsem)))
114 return -1;
113 115
114 /* Check for nonpresence of BBRTC */ 116 /* Check for nonpresence of BBRTC */
115 if (!((tseq[83] | tseq[90] | tseq[69] | tseq[76] | 117 if (!((tseq[83] | tseq[90] | tseq[69] | tseq[76] |
@@ -176,11 +178,16 @@ static int64_t hp_sdc_rtc_read_i8042timer (uint8_t loadcmd, int numreg)
176 t.seq = tseq; 178 t.seq = tseq;
177 t.act.semaphore = &i8042tregs; 179 t.act.semaphore = &i8042tregs;
178 180
179 down_interruptible(&i8042tregs); /* Sleep if output regs in use. */ 181 /* Sleep if output regs in use. */
182 if (WARN_ON(down_interruptible(&i8042tregs)))
183 return -1;
180 184
181 if (hp_sdc_enqueue_transaction(&t)) return -1; 185 if (hp_sdc_enqueue_transaction(&t)) return -1;
182 186
183 down_interruptible(&i8042tregs); /* Sleep until results come back. */ 187 /* Sleep until results come back. */
188 if (WARN_ON(down_interruptible(&i8042tregs)))
189 return -1;
190
184 up(&i8042tregs); 191 up(&i8042tregs);
185 192
186 return (tseq[5] | 193 return (tseq[5] |
@@ -276,6 +283,7 @@ static inline int hp_sdc_rtc_read_ct(struct timeval *res) {
276} 283}
277 284
278 285
286#if 0 /* not used yet */
279/* Set the i8042 real-time clock */ 287/* Set the i8042 real-time clock */
280static int hp_sdc_rtc_set_rt (struct timeval *setto) 288static int hp_sdc_rtc_set_rt (struct timeval *setto)
281{ 289{
@@ -386,6 +394,7 @@ static int hp_sdc_rtc_set_i8042timer (struct timeval *setto, uint8_t setcmd)
386 } 394 }
387 return 0; 395 return 0;
388} 396}
397#endif
389 398
390static ssize_t hp_sdc_rtc_read(struct file *file, char __user *buf, 399static ssize_t hp_sdc_rtc_read(struct file *file, char __user *buf,
391 size_t count, loff_t *ppos) { 400 size_t count, loff_t *ppos) {
diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
new file mode 100644
index 000000000000..e204f26b0011
--- /dev/null
+++ b/drivers/input/misc/ims-pcu.c
@@ -0,0 +1,1901 @@
1/*
2 * Driver for IMS Passenger Control Unit Devices
3 *
4 * Copyright (C) 2013 The IMS Company
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 version 2
8 * as published by the Free Software Foundation.
9 */
10
11#include <linux/completion.h>
12#include <linux/device.h>
13#include <linux/firmware.h>
14#include <linux/ihex.h>
15#include <linux/input.h>
16#include <linux/kernel.h>
17#include <linux/leds.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/types.h>
21#include <linux/usb/input.h>
22#include <linux/usb/cdc.h>
23#include <asm/unaligned.h>
24
25#define IMS_PCU_KEYMAP_LEN 32
26
27struct ims_pcu_buttons {
28 struct input_dev *input;
29 char name[32];
30 char phys[32];
31 unsigned short keymap[IMS_PCU_KEYMAP_LEN];
32};
33
34struct ims_pcu_gamepad {
35 struct input_dev *input;
36 char name[32];
37 char phys[32];
38};
39
40struct ims_pcu_backlight {
41 struct led_classdev cdev;
42 struct work_struct work;
43 enum led_brightness desired_brightness;
44 char name[32];
45};
46
47#define IMS_PCU_PART_NUMBER_LEN 15
48#define IMS_PCU_SERIAL_NUMBER_LEN 8
49#define IMS_PCU_DOM_LEN 8
50#define IMS_PCU_FW_VERSION_LEN (9 + 1)
51#define IMS_PCU_BL_VERSION_LEN (9 + 1)
52#define IMS_PCU_BL_RESET_REASON_LEN (2 + 1)
53
54#define IMS_PCU_BUF_SIZE 128
55
56struct ims_pcu {
57 struct usb_device *udev;
58 struct device *dev; /* control interface's device, used for logging */
59
60 unsigned int device_no;
61
62 bool bootloader_mode;
63
64 char part_number[IMS_PCU_PART_NUMBER_LEN];
65 char serial_number[IMS_PCU_SERIAL_NUMBER_LEN];
66 char date_of_manufacturing[IMS_PCU_DOM_LEN];
67 char fw_version[IMS_PCU_FW_VERSION_LEN];
68 char bl_version[IMS_PCU_BL_VERSION_LEN];
69 char reset_reason[IMS_PCU_BL_RESET_REASON_LEN];
70 int update_firmware_status;
71
72 struct usb_interface *ctrl_intf;
73
74 struct usb_endpoint_descriptor *ep_ctrl;
75 struct urb *urb_ctrl;
76 u8 *urb_ctrl_buf;
77 dma_addr_t ctrl_dma;
78 size_t max_ctrl_size;
79
80 struct usb_interface *data_intf;
81
82 struct usb_endpoint_descriptor *ep_in;
83 struct urb *urb_in;
84 u8 *urb_in_buf;
85 dma_addr_t read_dma;
86 size_t max_in_size;
87
88 struct usb_endpoint_descriptor *ep_out;
89 u8 *urb_out_buf;
90 size_t max_out_size;
91
92 u8 read_buf[IMS_PCU_BUF_SIZE];
93 u8 read_pos;
94 u8 check_sum;
95 bool have_stx;
96 bool have_dle;
97
98 u8 cmd_buf[IMS_PCU_BUF_SIZE];
99 u8 ack_id;
100 u8 expected_response;
101 u8 cmd_buf_len;
102 struct completion cmd_done;
103 struct mutex cmd_mutex;
104
105 u32 fw_start_addr;
106 u32 fw_end_addr;
107 struct completion async_firmware_done;
108
109 struct ims_pcu_buttons buttons;
110 struct ims_pcu_gamepad *gamepad;
111 struct ims_pcu_backlight backlight;
112
113 bool setup_complete; /* Input and LED devices have been created */
114};
115
116
117/*********************************************************************
118 * Buttons Input device support *
119 *********************************************************************/
120
121static const unsigned short ims_pcu_keymap_1[] = {
122 [1] = KEY_ATTENDANT_OFF,
123 [2] = KEY_ATTENDANT_ON,
124 [3] = KEY_LIGHTS_TOGGLE,
125 [4] = KEY_VOLUMEUP,
126 [5] = KEY_VOLUMEDOWN,
127 [6] = KEY_INFO,
128};
129
130static const unsigned short ims_pcu_keymap_2[] = {
131 [4] = KEY_VOLUMEUP,
132 [5] = KEY_VOLUMEDOWN,
133 [6] = KEY_INFO,
134};
135
136static const unsigned short ims_pcu_keymap_3[] = {
137 [1] = KEY_HOMEPAGE,
138 [2] = KEY_ATTENDANT_TOGGLE,
139 [3] = KEY_LIGHTS_TOGGLE,
140 [4] = KEY_VOLUMEUP,
141 [5] = KEY_VOLUMEDOWN,
142 [6] = KEY_DISPLAYTOGGLE,
143 [18] = KEY_PLAYPAUSE,
144};
145
146static const unsigned short ims_pcu_keymap_4[] = {
147 [1] = KEY_ATTENDANT_OFF,
148 [2] = KEY_ATTENDANT_ON,
149 [3] = KEY_LIGHTS_TOGGLE,
150 [4] = KEY_VOLUMEUP,
151 [5] = KEY_VOLUMEDOWN,
152 [6] = KEY_INFO,
153 [18] = KEY_PLAYPAUSE,
154};
155
156static const unsigned short ims_pcu_keymap_5[] = {
157 [1] = KEY_ATTENDANT_OFF,
158 [2] = KEY_ATTENDANT_ON,
159 [3] = KEY_LIGHTS_TOGGLE,
160};
161
162struct ims_pcu_device_info {
163 const unsigned short *keymap;
164 size_t keymap_len;
165 bool has_gamepad;
166};
167
168#define IMS_PCU_DEVINFO(_n, _gamepad) \
169 [_n] = { \
170 .keymap = ims_pcu_keymap_##_n, \
171 .keymap_len = ARRAY_SIZE(ims_pcu_keymap_##_n), \
172 .has_gamepad = _gamepad, \
173 }
174
175static const struct ims_pcu_device_info ims_pcu_device_info[] = {
176 IMS_PCU_DEVINFO(1, true),
177 IMS_PCU_DEVINFO(2, true),
178 IMS_PCU_DEVINFO(3, true),
179 IMS_PCU_DEVINFO(4, true),
180 IMS_PCU_DEVINFO(5, false),
181};
182
183static void ims_pcu_buttons_report(struct ims_pcu *pcu, u32 data)
184{
185 struct ims_pcu_buttons *buttons = &pcu->buttons;
186 struct input_dev *input = buttons->input;
187 int i;
188
189 for (i = 0; i < 32; i++) {
190 unsigned short keycode = buttons->keymap[i];
191
192 if (keycode != KEY_RESERVED)
193 input_report_key(input, keycode, data & (1UL << i));
194 }
195
196 input_sync(input);
197}
198
199static int ims_pcu_setup_buttons(struct ims_pcu *pcu,
200 const unsigned short *keymap,
201 size_t keymap_len)
202{
203 struct ims_pcu_buttons *buttons = &pcu->buttons;
204 struct input_dev *input;
205 int i;
206 int error;
207
208 input = input_allocate_device();
209 if (!input) {
210 dev_err(pcu->dev,
211 "Not enough memory for input input device\n");
212 return -ENOMEM;
213 }
214
215 snprintf(buttons->name, sizeof(buttons->name),
216 "IMS PCU#%d Button Interface", pcu->device_no);
217
218 usb_make_path(pcu->udev, buttons->phys, sizeof(buttons->phys));
219 strlcat(buttons->phys, "/input0", sizeof(buttons->phys));
220
221 memcpy(buttons->keymap, keymap, sizeof(*keymap) * keymap_len);
222
223 input->name = buttons->name;
224 input->phys = buttons->phys;
225 usb_to_input_id(pcu->udev, &input->id);
226 input->dev.parent = &pcu->ctrl_intf->dev;
227
228 input->keycode = buttons->keymap;
229 input->keycodemax = ARRAY_SIZE(buttons->keymap);
230 input->keycodesize = sizeof(buttons->keymap[0]);
231
232 __set_bit(EV_KEY, input->evbit);
233 for (i = 0; i < IMS_PCU_KEYMAP_LEN; i++)
234 __set_bit(buttons->keymap[i], input->keybit);
235 __clear_bit(KEY_RESERVED, input->keybit);
236
237 error = input_register_device(input);
238 if (error) {
239 dev_err(pcu->dev,
240 "Failed to register buttons input device: %d\n",
241 error);
242 input_free_device(input);
243 return error;
244 }
245
246 buttons->input = input;
247 return 0;
248}
249
250static void ims_pcu_destroy_buttons(struct ims_pcu *pcu)
251{
252 struct ims_pcu_buttons *buttons = &pcu->buttons;
253
254 input_unregister_device(buttons->input);
255}
256
257
258/*********************************************************************
259 * Gamepad Input device support *
260 *********************************************************************/
261
262static void ims_pcu_gamepad_report(struct ims_pcu *pcu, u32 data)
263{
264 struct ims_pcu_gamepad *gamepad = pcu->gamepad;
265 struct input_dev *input = gamepad->input;
266 int x, y;
267
268 x = !!(data & (1 << 14)) - !!(data & (1 << 13));
269 y = !!(data & (1 << 12)) - !!(data & (1 << 11));
270
271 input_report_abs(input, ABS_X, x);
272 input_report_abs(input, ABS_Y, y);
273
274 input_report_key(input, BTN_A, data & (1 << 7));
275 input_report_key(input, BTN_B, data & (1 << 8));
276 input_report_key(input, BTN_X, data & (1 << 9));
277 input_report_key(input, BTN_Y, data & (1 << 10));
278 input_report_key(input, BTN_START, data & (1 << 15));
279 input_report_key(input, BTN_SELECT, data & (1 << 16));
280
281 input_sync(input);
282}
283
284static int ims_pcu_setup_gamepad(struct ims_pcu *pcu)
285{
286 struct ims_pcu_gamepad *gamepad;
287 struct input_dev *input;
288 int error;
289
290 gamepad = kzalloc(sizeof(struct ims_pcu_gamepad), GFP_KERNEL);
291 input = input_allocate_device();
292 if (!gamepad || !input) {
293 dev_err(pcu->dev,
294 "Not enough memory for gamepad device\n");
295 error = -ENOMEM;
296 goto err_free_mem;
297 }
298
299 gamepad->input = input;
300
301 snprintf(gamepad->name, sizeof(gamepad->name),
302 "IMS PCU#%d Gamepad Interface", pcu->device_no);
303
304 usb_make_path(pcu->udev, gamepad->phys, sizeof(gamepad->phys));
305 strlcat(gamepad->phys, "/input1", sizeof(gamepad->phys));
306
307 input->name = gamepad->name;
308 input->phys = gamepad->phys;
309 usb_to_input_id(pcu->udev, &input->id);
310 input->dev.parent = &pcu->ctrl_intf->dev;
311
312 __set_bit(EV_KEY, input->evbit);
313 __set_bit(BTN_A, input->keybit);
314 __set_bit(BTN_B, input->keybit);
315 __set_bit(BTN_X, input->keybit);
316 __set_bit(BTN_Y, input->keybit);
317 __set_bit(BTN_START, input->keybit);
318 __set_bit(BTN_SELECT, input->keybit);
319
320 __set_bit(EV_ABS, input->evbit);
321 input_set_abs_params(input, ABS_X, -1, 1, 0, 0);
322 input_set_abs_params(input, ABS_Y, -1, 1, 0, 0);
323
324 error = input_register_device(input);
325 if (error) {
326 dev_err(pcu->dev,
327 "Failed to register gamepad input device: %d\n",
328 error);
329 goto err_free_mem;
330 }
331
332 pcu->gamepad = gamepad;
333 return 0;
334
335err_free_mem:
336 input_free_device(input);
337 kfree(gamepad);
338 return -ENOMEM;
339}
340
341static void ims_pcu_destroy_gamepad(struct ims_pcu *pcu)
342{
343 struct ims_pcu_gamepad *gamepad = pcu->gamepad;
344
345 input_unregister_device(gamepad->input);
346 kfree(gamepad);
347}
348
349
350/*********************************************************************
351 * PCU Communication protocol handling *
352 *********************************************************************/
353
354#define IMS_PCU_PROTOCOL_STX 0x02
355#define IMS_PCU_PROTOCOL_ETX 0x03
356#define IMS_PCU_PROTOCOL_DLE 0x10
357
358/* PCU commands */
359#define IMS_PCU_CMD_STATUS 0xa0
360#define IMS_PCU_CMD_PCU_RESET 0xa1
361#define IMS_PCU_CMD_RESET_REASON 0xa2
362#define IMS_PCU_CMD_SEND_BUTTONS 0xa3
363#define IMS_PCU_CMD_JUMP_TO_BTLDR 0xa4
364#define IMS_PCU_CMD_GET_INFO 0xa5
365#define IMS_PCU_CMD_SET_BRIGHTNESS 0xa6
366#define IMS_PCU_CMD_EEPROM 0xa7
367#define IMS_PCU_CMD_GET_FW_VERSION 0xa8
368#define IMS_PCU_CMD_GET_BL_VERSION 0xa9
369#define IMS_PCU_CMD_SET_INFO 0xab
370#define IMS_PCU_CMD_GET_BRIGHTNESS 0xac
371#define IMS_PCU_CMD_GET_DEVICE_ID 0xae
372#define IMS_PCU_CMD_SPECIAL_INFO 0xb0
373#define IMS_PCU_CMD_BOOTLOADER 0xb1 /* Pass data to bootloader */
374
375/* PCU responses */
376#define IMS_PCU_RSP_STATUS 0xc0
377#define IMS_PCU_RSP_PCU_RESET 0 /* Originally 0xc1 */
378#define IMS_PCU_RSP_RESET_REASON 0xc2
379#define IMS_PCU_RSP_SEND_BUTTONS 0xc3
380#define IMS_PCU_RSP_JUMP_TO_BTLDR 0 /* Originally 0xc4 */
381#define IMS_PCU_RSP_GET_INFO 0xc5
382#define IMS_PCU_RSP_SET_BRIGHTNESS 0xc6
383#define IMS_PCU_RSP_EEPROM 0xc7
384#define IMS_PCU_RSP_GET_FW_VERSION 0xc8
385#define IMS_PCU_RSP_GET_BL_VERSION 0xc9
386#define IMS_PCU_RSP_SET_INFO 0xcb
387#define IMS_PCU_RSP_GET_BRIGHTNESS 0xcc
388#define IMS_PCU_RSP_CMD_INVALID 0xcd
389#define IMS_PCU_RSP_GET_DEVICE_ID 0xce
390#define IMS_PCU_RSP_SPECIAL_INFO 0xd0
391#define IMS_PCU_RSP_BOOTLOADER 0xd1 /* Bootloader response */
392
393#define IMS_PCU_RSP_EVNT_BUTTONS 0xe0 /* Unsolicited, button state */
394#define IMS_PCU_GAMEPAD_MASK 0x0001ff80UL /* Bits 7 through 16 */
395
396
397#define IMS_PCU_MIN_PACKET_LEN 3
398#define IMS_PCU_DATA_OFFSET 2
399
400#define IMS_PCU_CMD_WRITE_TIMEOUT 100 /* msec */
401#define IMS_PCU_CMD_RESPONSE_TIMEOUT 500 /* msec */
402
403static void ims_pcu_report_events(struct ims_pcu *pcu)
404{
405 u32 data = get_unaligned_be32(&pcu->read_buf[3]);
406
407 ims_pcu_buttons_report(pcu, data & ~IMS_PCU_GAMEPAD_MASK);
408 if (pcu->gamepad)
409 ims_pcu_gamepad_report(pcu, data);
410}
411
412static void ims_pcu_handle_response(struct ims_pcu *pcu)
413{
414 switch (pcu->read_buf[0]) {
415 case IMS_PCU_RSP_EVNT_BUTTONS:
416 if (likely(pcu->setup_complete))
417 ims_pcu_report_events(pcu);
418 break;
419
420 default:
421 /*
422 * See if we got command completion.
423 * If both the sequence and response code match save
424 * the data and signal completion.
425 */
426 if (pcu->read_buf[0] == pcu->expected_response &&
427 pcu->read_buf[1] == pcu->ack_id - 1) {
428
429 memcpy(pcu->cmd_buf, pcu->read_buf, pcu->read_pos);
430 pcu->cmd_buf_len = pcu->read_pos;
431 complete(&pcu->cmd_done);
432 }
433 break;
434 }
435}
436
437static void ims_pcu_process_data(struct ims_pcu *pcu, struct urb *urb)
438{
439 int i;
440
441 for (i = 0; i < urb->actual_length; i++) {
442 u8 data = pcu->urb_in_buf[i];
443
444 /* Skip everything until we get Start Xmit */
445 if (!pcu->have_stx && data != IMS_PCU_PROTOCOL_STX)
446 continue;
447
448 if (pcu->have_dle) {
449 pcu->have_dle = false;
450 pcu->read_buf[pcu->read_pos++] = data;
451 pcu->check_sum += data;
452 continue;
453 }
454
455 switch (data) {
456 case IMS_PCU_PROTOCOL_STX:
457 if (pcu->have_stx)
458 dev_warn(pcu->dev,
459 "Unexpected STX at byte %d, discarding old data\n",
460 pcu->read_pos);
461 pcu->have_stx = true;
462 pcu->have_dle = false;
463 pcu->read_pos = 0;
464 pcu->check_sum = 0;
465 break;
466
467 case IMS_PCU_PROTOCOL_DLE:
468 pcu->have_dle = true;
469 break;
470
471 case IMS_PCU_PROTOCOL_ETX:
472 if (pcu->read_pos < IMS_PCU_MIN_PACKET_LEN) {
473 dev_warn(pcu->dev,
474 "Short packet received (%d bytes), ignoring\n",
475 pcu->read_pos);
476 } else if (pcu->check_sum != 0) {
477 dev_warn(pcu->dev,
478 "Invalid checksum in packet (%d bytes), ignoring\n",
479 pcu->read_pos);
480 } else {
481 ims_pcu_handle_response(pcu);
482 }
483
484 pcu->have_stx = false;
485 pcu->have_dle = false;
486 pcu->read_pos = 0;
487 break;
488
489 default:
490 pcu->read_buf[pcu->read_pos++] = data;
491 pcu->check_sum += data;
492 break;
493 }
494 }
495}
496
497static bool ims_pcu_byte_needs_escape(u8 byte)
498{
499 return byte == IMS_PCU_PROTOCOL_STX ||
500 byte == IMS_PCU_PROTOCOL_ETX ||
501 byte == IMS_PCU_PROTOCOL_DLE;
502}
503
504static int ims_pcu_send_cmd_chunk(struct ims_pcu *pcu,
505 u8 command, int chunk, int len)
506{
507 int error;
508
509 error = usb_bulk_msg(pcu->udev,
510 usb_sndbulkpipe(pcu->udev,
511 pcu->ep_out->bEndpointAddress),
512 pcu->urb_out_buf, len,
513 NULL, IMS_PCU_CMD_WRITE_TIMEOUT);
514 if (error < 0) {
515 dev_dbg(pcu->dev,
516 "Sending 0x%02x command failed at chunk %d: %d\n",
517 command, chunk, error);
518 return error;
519 }
520
521 return 0;
522}
523
524static int ims_pcu_send_command(struct ims_pcu *pcu,
525 u8 command, const u8 *data, int len)
526{
527 int count = 0;
528 int chunk = 0;
529 int delta;
530 int i;
531 int error;
532 u8 csum = 0;
533 u8 ack_id;
534
535 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_STX;
536
537 /* We know the command need not be escaped */
538 pcu->urb_out_buf[count++] = command;
539 csum += command;
540
541 ack_id = pcu->ack_id++;
542 if (ack_id == 0xff)
543 ack_id = pcu->ack_id++;
544
545 if (ims_pcu_byte_needs_escape(ack_id))
546 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_DLE;
547
548 pcu->urb_out_buf[count++] = ack_id;
549 csum += ack_id;
550
551 for (i = 0; i < len; i++) {
552
553 delta = ims_pcu_byte_needs_escape(data[i]) ? 2 : 1;
554 if (count + delta >= pcu->max_out_size) {
555 error = ims_pcu_send_cmd_chunk(pcu, command,
556 ++chunk, count);
557 if (error)
558 return error;
559
560 count = 0;
561 }
562
563 if (delta == 2)
564 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_DLE;
565
566 pcu->urb_out_buf[count++] = data[i];
567 csum += data[i];
568 }
569
570 csum = 1 + ~csum;
571
572 delta = ims_pcu_byte_needs_escape(csum) ? 3 : 2;
573 if (count + delta >= pcu->max_out_size) {
574 error = ims_pcu_send_cmd_chunk(pcu, command, ++chunk, count);
575 if (error)
576 return error;
577
578 count = 0;
579 }
580
581 if (delta == 3)
582 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_DLE;
583
584 pcu->urb_out_buf[count++] = csum;
585 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_ETX;
586
587 return ims_pcu_send_cmd_chunk(pcu, command, ++chunk, count);
588}
589
590static int __ims_pcu_execute_command(struct ims_pcu *pcu,
591 u8 command, const void *data, size_t len,
592 u8 expected_response, int response_time)
593{
594 int error;
595
596 pcu->expected_response = expected_response;
597 init_completion(&pcu->cmd_done);
598
599 error = ims_pcu_send_command(pcu, command, data, len);
600 if (error)
601 return error;
602
603 if (expected_response &&
604 !wait_for_completion_timeout(&pcu->cmd_done,
605 msecs_to_jiffies(response_time))) {
606 dev_dbg(pcu->dev, "Command 0x%02x timed out\n", command);
607 return -ETIMEDOUT;
608 }
609
610 return 0;
611}
612
613#define ims_pcu_execute_command(pcu, code, data, len) \
614 __ims_pcu_execute_command(pcu, \
615 IMS_PCU_CMD_##code, data, len, \
616 IMS_PCU_RSP_##code, \
617 IMS_PCU_CMD_RESPONSE_TIMEOUT)
618
619#define ims_pcu_execute_query(pcu, code) \
620 ims_pcu_execute_command(pcu, code, NULL, 0)
621
622/* Bootloader commands */
623#define IMS_PCU_BL_CMD_QUERY_DEVICE 0xa1
624#define IMS_PCU_BL_CMD_UNLOCK_CONFIG 0xa2
625#define IMS_PCU_BL_CMD_ERASE_APP 0xa3
626#define IMS_PCU_BL_CMD_PROGRAM_DEVICE 0xa4
627#define IMS_PCU_BL_CMD_PROGRAM_COMPLETE 0xa5
628#define IMS_PCU_BL_CMD_READ_APP 0xa6
629#define IMS_PCU_BL_CMD_RESET_DEVICE 0xa7
630#define IMS_PCU_BL_CMD_LAUNCH_APP 0xa8
631
632/* Bootloader commands */
633#define IMS_PCU_BL_RSP_QUERY_DEVICE 0xc1
634#define IMS_PCU_BL_RSP_UNLOCK_CONFIG 0xc2
635#define IMS_PCU_BL_RSP_ERASE_APP 0xc3
636#define IMS_PCU_BL_RSP_PROGRAM_DEVICE 0xc4
637#define IMS_PCU_BL_RSP_PROGRAM_COMPLETE 0xc5
638#define IMS_PCU_BL_RSP_READ_APP 0xc6
639#define IMS_PCU_BL_RSP_RESET_DEVICE 0 /* originally 0xa7 */
640#define IMS_PCU_BL_RSP_LAUNCH_APP 0 /* originally 0xa8 */
641
642#define IMS_PCU_BL_DATA_OFFSET 3
643
644static int __ims_pcu_execute_bl_command(struct ims_pcu *pcu,
645 u8 command, const void *data, size_t len,
646 u8 expected_response, int response_time)
647{
648 int error;
649
650 pcu->cmd_buf[0] = command;
651 if (data)
652 memcpy(&pcu->cmd_buf[1], data, len);
653
654 error = __ims_pcu_execute_command(pcu,
655 IMS_PCU_CMD_BOOTLOADER, pcu->cmd_buf, len + 1,
656 expected_response ? IMS_PCU_RSP_BOOTLOADER : 0,
657 response_time);
658 if (error) {
659 dev_err(pcu->dev,
660 "Failure when sending 0x%02x command to bootloader, error: %d\n",
661 pcu->cmd_buf[0], error);
662 return error;
663 }
664
665 if (expected_response && pcu->cmd_buf[2] != expected_response) {
666 dev_err(pcu->dev,
667 "Unexpected response from bootloader: 0x%02x, wanted 0x%02x\n",
668 pcu->cmd_buf[2], expected_response);
669 return -EINVAL;
670 }
671
672 return 0;
673}
674
675#define ims_pcu_execute_bl_command(pcu, code, data, len, timeout) \
676 __ims_pcu_execute_bl_command(pcu, \
677 IMS_PCU_BL_CMD_##code, data, len, \
678 IMS_PCU_BL_RSP_##code, timeout) \
679
680#define IMS_PCU_INFO_PART_OFFSET 2
681#define IMS_PCU_INFO_DOM_OFFSET 17
682#define IMS_PCU_INFO_SERIAL_OFFSET 25
683
684#define IMS_PCU_SET_INFO_SIZE 31
685
686static int ims_pcu_get_info(struct ims_pcu *pcu)
687{
688 int error;
689
690 error = ims_pcu_execute_query(pcu, GET_INFO);
691 if (error) {
692 dev_err(pcu->dev,
693 "GET_INFO command failed, error: %d\n", error);
694 return error;
695 }
696
697 memcpy(pcu->part_number,
698 &pcu->cmd_buf[IMS_PCU_INFO_PART_OFFSET],
699 sizeof(pcu->part_number));
700 memcpy(pcu->date_of_manufacturing,
701 &pcu->cmd_buf[IMS_PCU_INFO_DOM_OFFSET],
702 sizeof(pcu->date_of_manufacturing));
703 memcpy(pcu->serial_number,
704 &pcu->cmd_buf[IMS_PCU_INFO_SERIAL_OFFSET],
705 sizeof(pcu->serial_number));
706
707 return 0;
708}
709
710static int ims_pcu_set_info(struct ims_pcu *pcu)
711{
712 int error;
713
714 memcpy(&pcu->cmd_buf[IMS_PCU_INFO_PART_OFFSET],
715 pcu->part_number, sizeof(pcu->part_number));
716 memcpy(&pcu->cmd_buf[IMS_PCU_INFO_DOM_OFFSET],
717 pcu->date_of_manufacturing, sizeof(pcu->date_of_manufacturing));
718 memcpy(&pcu->cmd_buf[IMS_PCU_INFO_SERIAL_OFFSET],
719 pcu->serial_number, sizeof(pcu->serial_number));
720
721 error = ims_pcu_execute_command(pcu, SET_INFO,
722 &pcu->cmd_buf[IMS_PCU_DATA_OFFSET],
723 IMS_PCU_SET_INFO_SIZE);
724 if (error) {
725 dev_err(pcu->dev,
726 "Failed to update device information, error: %d\n",
727 error);
728 return error;
729 }
730
731 return 0;
732}
733
734static int ims_pcu_switch_to_bootloader(struct ims_pcu *pcu)
735{
736 int error;
737
738 /* Execute jump to the bootoloader */
739 error = ims_pcu_execute_command(pcu, JUMP_TO_BTLDR, NULL, 0);
740 if (error) {
741 dev_err(pcu->dev,
742 "Failure when sending JUMP TO BOOLTLOADER command, error: %d\n",
743 error);
744 return error;
745 }
746
747 return 0;
748}
749
750/*********************************************************************
751 * Firmware Update handling *
752 *********************************************************************/
753
754#define IMS_PCU_FIRMWARE_NAME "imspcu.fw"
755
756struct ims_pcu_flash_fmt {
757 __le32 addr;
758 u8 len;
759 u8 data[];
760};
761
762static unsigned int ims_pcu_count_fw_records(const struct firmware *fw)
763{
764 const struct ihex_binrec *rec = (const struct ihex_binrec *)fw->data;
765 unsigned int count = 0;
766
767 while (rec) {
768 count++;
769 rec = ihex_next_binrec(rec);
770 }
771
772 return count;
773}
774
775static int ims_pcu_verify_block(struct ims_pcu *pcu,
776 u32 addr, u8 len, const u8 *data)
777{
778 struct ims_pcu_flash_fmt *fragment;
779 int error;
780
781 fragment = (void *)&pcu->cmd_buf[1];
782 put_unaligned_le32(addr, &fragment->addr);
783 fragment->len = len;
784
785 error = ims_pcu_execute_bl_command(pcu, READ_APP, NULL, 5,
786 IMS_PCU_CMD_RESPONSE_TIMEOUT);
787 if (error) {
788 dev_err(pcu->dev,
789 "Failed to retrieve block at 0x%08x, len %d, error: %d\n",
790 addr, len, error);
791 return error;
792 }
793
794 fragment = (void *)&pcu->cmd_buf[IMS_PCU_BL_DATA_OFFSET];
795 if (get_unaligned_le32(&fragment->addr) != addr ||
796 fragment->len != len) {
797 dev_err(pcu->dev,
798 "Wrong block when retrieving 0x%08x (0x%08x), len %d (%d)\n",
799 addr, get_unaligned_le32(&fragment->addr),
800 len, fragment->len);
801 return -EINVAL;
802 }
803
804 if (memcmp(fragment->data, data, len)) {
805 dev_err(pcu->dev,
806 "Mismatch in block at 0x%08x, len %d\n",
807 addr, len);
808 return -EINVAL;
809 }
810
811 return 0;
812}
813
814static int ims_pcu_flash_firmware(struct ims_pcu *pcu,
815 const struct firmware *fw,
816 unsigned int n_fw_records)
817{
818 const struct ihex_binrec *rec = (const struct ihex_binrec *)fw->data;
819 struct ims_pcu_flash_fmt *fragment;
820 unsigned int count = 0;
821 u32 addr;
822 u8 len;
823 int error;
824
825 error = ims_pcu_execute_bl_command(pcu, ERASE_APP, NULL, 0, 2000);
826 if (error) {
827 dev_err(pcu->dev,
828 "Failed to erase application image, error: %d\n",
829 error);
830 return error;
831 }
832
833 while (rec) {
834 /*
835 * The firmware format is messed up for some reason.
836 * The address twice that of what is needed for some
837 * reason and we end up overwriting half of the data
838 * with the next record.
839 */
840 addr = be32_to_cpu(rec->addr) / 2;
841 len = be16_to_cpu(rec->len);
842
843 fragment = (void *)&pcu->cmd_buf[1];
844 put_unaligned_le32(addr, &fragment->addr);
845 fragment->len = len;
846 memcpy(fragment->data, rec->data, len);
847
848 error = ims_pcu_execute_bl_command(pcu, PROGRAM_DEVICE,
849 NULL, len + 5,
850 IMS_PCU_CMD_RESPONSE_TIMEOUT);
851 if (error) {
852 dev_err(pcu->dev,
853 "Failed to write block at 0x%08x, len %d, error: %d\n",
854 addr, len, error);
855 return error;
856 }
857
858 if (addr >= pcu->fw_start_addr && addr < pcu->fw_end_addr) {
859 error = ims_pcu_verify_block(pcu, addr, len, rec->data);
860 if (error)
861 return error;
862 }
863
864 count++;
865 pcu->update_firmware_status = (count * 100) / n_fw_records;
866
867 rec = ihex_next_binrec(rec);
868 }
869
870 error = ims_pcu_execute_bl_command(pcu, PROGRAM_COMPLETE,
871 NULL, 0, 2000);
872 if (error)
873 dev_err(pcu->dev,
874 "Failed to send PROGRAM_COMPLETE, error: %d\n",
875 error);
876
877 return 0;
878}
879
880static int ims_pcu_handle_firmware_update(struct ims_pcu *pcu,
881 const struct firmware *fw)
882{
883 unsigned int n_fw_records;
884 int retval;
885
886 dev_info(pcu->dev, "Updating firmware %s, size: %zu\n",
887 IMS_PCU_FIRMWARE_NAME, fw->size);
888
889 n_fw_records = ims_pcu_count_fw_records(fw);
890
891 retval = ims_pcu_flash_firmware(pcu, fw, n_fw_records);
892 if (retval)
893 goto out;
894
895 retval = ims_pcu_execute_bl_command(pcu, LAUNCH_APP, NULL, 0, 0);
896 if (retval)
897 dev_err(pcu->dev,
898 "Failed to start application image, error: %d\n",
899 retval);
900
901out:
902 pcu->update_firmware_status = retval;
903 sysfs_notify(&pcu->dev->kobj, NULL, "update_firmware_status");
904 return retval;
905}
906
907static void ims_pcu_process_async_firmware(const struct firmware *fw,
908 void *context)
909{
910 struct ims_pcu *pcu = context;
911 int error;
912
913 if (!fw) {
914 dev_err(pcu->dev, "Failed to get firmware %s\n",
915 IMS_PCU_FIRMWARE_NAME);
916 goto out;
917 }
918
919 error = ihex_validate_fw(fw);
920 if (error) {
921 dev_err(pcu->dev, "Firmware %s is invalid\n",
922 IMS_PCU_FIRMWARE_NAME);
923 goto out;
924 }
925
926 mutex_lock(&pcu->cmd_mutex);
927 ims_pcu_handle_firmware_update(pcu, fw);
928 mutex_unlock(&pcu->cmd_mutex);
929
930 release_firmware(fw);
931
932out:
933 complete(&pcu->async_firmware_done);
934}
935
936/*********************************************************************
937 * Backlight LED device support *
938 *********************************************************************/
939
940#define IMS_PCU_MAX_BRIGHTNESS 31998
941
942static void ims_pcu_backlight_work(struct work_struct *work)
943{
944 struct ims_pcu_backlight *backlight =
945 container_of(work, struct ims_pcu_backlight, work);
946 struct ims_pcu *pcu =
947 container_of(backlight, struct ims_pcu, backlight);
948 int desired_brightness = backlight->desired_brightness;
949 __le16 br_val = cpu_to_le16(desired_brightness);
950 int error;
951
952 mutex_lock(&pcu->cmd_mutex);
953
954 error = ims_pcu_execute_command(pcu, SET_BRIGHTNESS,
955 &br_val, sizeof(br_val));
956 if (error && error != -ENODEV)
957 dev_warn(pcu->dev,
958 "Failed to set desired brightness %u, error: %d\n",
959 desired_brightness, error);
960
961 mutex_unlock(&pcu->cmd_mutex);
962}
963
964static void ims_pcu_backlight_set_brightness(struct led_classdev *cdev,
965 enum led_brightness value)
966{
967 struct ims_pcu_backlight *backlight =
968 container_of(cdev, struct ims_pcu_backlight, cdev);
969
970 backlight->desired_brightness = value;
971 schedule_work(&backlight->work);
972}
973
974static enum led_brightness
975ims_pcu_backlight_get_brightness(struct led_classdev *cdev)
976{
977 struct ims_pcu_backlight *backlight =
978 container_of(cdev, struct ims_pcu_backlight, cdev);
979 struct ims_pcu *pcu =
980 container_of(backlight, struct ims_pcu, backlight);
981 int brightness;
982 int error;
983
984 mutex_lock(&pcu->cmd_mutex);
985
986 error = ims_pcu_execute_query(pcu, GET_BRIGHTNESS);
987 if (error) {
988 dev_warn(pcu->dev,
989 "Failed to get current brightness, error: %d\n",
990 error);
991 /* Assume the LED is OFF */
992 brightness = LED_OFF;
993 } else {
994 brightness =
995 get_unaligned_le16(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET]);
996 }
997
998 mutex_unlock(&pcu->cmd_mutex);
999
1000 return brightness;
1001}
1002
1003static int ims_pcu_setup_backlight(struct ims_pcu *pcu)
1004{
1005 struct ims_pcu_backlight *backlight = &pcu->backlight;
1006 int error;
1007
1008 INIT_WORK(&backlight->work, ims_pcu_backlight_work);
1009 snprintf(backlight->name, sizeof(backlight->name),
1010 "pcu%d::kbd_backlight", pcu->device_no);
1011
1012 backlight->cdev.name = backlight->name;
1013 backlight->cdev.max_brightness = IMS_PCU_MAX_BRIGHTNESS;
1014 backlight->cdev.brightness_get = ims_pcu_backlight_get_brightness;
1015 backlight->cdev.brightness_set = ims_pcu_backlight_set_brightness;
1016
1017 error = led_classdev_register(pcu->dev, &backlight->cdev);
1018 if (error) {
1019 dev_err(pcu->dev,
1020 "Failed to register backlight LED device, error: %d\n",
1021 error);
1022 return error;
1023 }
1024
1025 return 0;
1026}
1027
1028static void ims_pcu_destroy_backlight(struct ims_pcu *pcu)
1029{
1030 struct ims_pcu_backlight *backlight = &pcu->backlight;
1031
1032 led_classdev_unregister(&backlight->cdev);
1033 cancel_work_sync(&backlight->work);
1034}
1035
1036
1037/*********************************************************************
1038 * Sysfs attributes handling *
1039 *********************************************************************/
1040
1041struct ims_pcu_attribute {
1042 struct device_attribute dattr;
1043 size_t field_offset;
1044 int field_length;
1045};
1046
1047static ssize_t ims_pcu_attribute_show(struct device *dev,
1048 struct device_attribute *dattr,
1049 char *buf)
1050{
1051 struct usb_interface *intf = to_usb_interface(dev);
1052 struct ims_pcu *pcu = usb_get_intfdata(intf);
1053 struct ims_pcu_attribute *attr =
1054 container_of(dattr, struct ims_pcu_attribute, dattr);
1055 char *field = (char *)pcu + attr->field_offset;
1056
1057 return scnprintf(buf, PAGE_SIZE, "%.*s\n", attr->field_length, field);
1058}
1059
1060static ssize_t ims_pcu_attribute_store(struct device *dev,
1061 struct device_attribute *dattr,
1062 const char *buf, size_t count)
1063{
1064
1065 struct usb_interface *intf = to_usb_interface(dev);
1066 struct ims_pcu *pcu = usb_get_intfdata(intf);
1067 struct ims_pcu_attribute *attr =
1068 container_of(dattr, struct ims_pcu_attribute, dattr);
1069 char *field = (char *)pcu + attr->field_offset;
1070 size_t data_len;
1071 int error;
1072
1073 if (count > attr->field_length)
1074 return -EINVAL;
1075
1076 data_len = strnlen(buf, attr->field_length);
1077 if (data_len > attr->field_length)
1078 return -EINVAL;
1079
1080 error = mutex_lock_interruptible(&pcu->cmd_mutex);
1081 if (error)
1082 return error;
1083
1084 memset(field, 0, attr->field_length);
1085 memcpy(field, buf, data_len);
1086
1087 error = ims_pcu_set_info(pcu);
1088
1089 /*
1090 * Even if update failed, let's fetch the info again as we just
1091 * clobbered one of the fields.
1092 */
1093 ims_pcu_get_info(pcu);
1094
1095 mutex_unlock(&pcu->cmd_mutex);
1096
1097 return error < 0 ? error : count;
1098}
1099
1100#define IMS_PCU_ATTR(_field, _mode) \
1101struct ims_pcu_attribute ims_pcu_attr_##_field = { \
1102 .dattr = __ATTR(_field, _mode, \
1103 ims_pcu_attribute_show, \
1104 ims_pcu_attribute_store), \
1105 .field_offset = offsetof(struct ims_pcu, _field), \
1106 .field_length = sizeof(((struct ims_pcu *)NULL)->_field), \
1107}
1108
1109#define IMS_PCU_RO_ATTR(_field) \
1110 IMS_PCU_ATTR(_field, S_IRUGO)
1111#define IMS_PCU_RW_ATTR(_field) \
1112 IMS_PCU_ATTR(_field, S_IRUGO | S_IWUSR)
1113
1114static IMS_PCU_RW_ATTR(part_number);
1115static IMS_PCU_RW_ATTR(serial_number);
1116static IMS_PCU_RW_ATTR(date_of_manufacturing);
1117
1118static IMS_PCU_RO_ATTR(fw_version);
1119static IMS_PCU_RO_ATTR(bl_version);
1120static IMS_PCU_RO_ATTR(reset_reason);
1121
1122static ssize_t ims_pcu_reset_device(struct device *dev,
1123 struct device_attribute *dattr,
1124 const char *buf, size_t count)
1125{
1126 static const u8 reset_byte = 1;
1127 struct usb_interface *intf = to_usb_interface(dev);
1128 struct ims_pcu *pcu = usb_get_intfdata(intf);
1129 int value;
1130 int error;
1131
1132 error = kstrtoint(buf, 0, &value);
1133 if (error)
1134 return error;
1135
1136 if (value != 1)
1137 return -EINVAL;
1138
1139 dev_info(pcu->dev, "Attempting to reset device\n");
1140
1141 error = ims_pcu_execute_command(pcu, PCU_RESET, &reset_byte, 1);
1142 if (error) {
1143 dev_info(pcu->dev,
1144 "Failed to reset device, error: %d\n",
1145 error);
1146 return error;
1147 }
1148
1149 return count;
1150}
1151
1152static DEVICE_ATTR(reset_device, S_IWUSR, NULL, ims_pcu_reset_device);
1153
1154static ssize_t ims_pcu_update_firmware_store(struct device *dev,
1155 struct device_attribute *dattr,
1156 const char *buf, size_t count)
1157{
1158 struct usb_interface *intf = to_usb_interface(dev);
1159 struct ims_pcu *pcu = usb_get_intfdata(intf);
1160 const struct firmware *fw = NULL;
1161 int value;
1162 int error;
1163
1164 error = kstrtoint(buf, 0, &value);
1165 if (error)
1166 return error;
1167
1168 if (value != 1)
1169 return -EINVAL;
1170
1171 error = mutex_lock_interruptible(&pcu->cmd_mutex);
1172 if (error)
1173 return error;
1174
1175 error = request_ihex_firmware(&fw, IMS_PCU_FIRMWARE_NAME, pcu->dev);
1176 if (error) {
1177 dev_err(pcu->dev, "Failed to request firmware %s, error: %d\n",
1178 IMS_PCU_FIRMWARE_NAME, error);
1179 goto out;
1180 }
1181
1182 /*
1183 * If we are already in bootloader mode we can proceed with
1184 * flashing the firmware.
1185 *
1186 * If we are in application mode, then we need to switch into
1187 * bootloader mode, which will cause the device to disconnect
1188 * and reconnect as different device.
1189 */
1190 if (pcu->bootloader_mode)
1191 error = ims_pcu_handle_firmware_update(pcu, fw);
1192 else
1193 error = ims_pcu_switch_to_bootloader(pcu);
1194
1195 release_firmware(fw);
1196
1197out:
1198 mutex_unlock(&pcu->cmd_mutex);
1199 return error ?: count;
1200}
1201
1202static DEVICE_ATTR(update_firmware, S_IWUSR,
1203 NULL, ims_pcu_update_firmware_store);
1204
1205static ssize_t
1206ims_pcu_update_firmware_status_show(struct device *dev,
1207 struct device_attribute *dattr,
1208 char *buf)
1209{
1210 struct usb_interface *intf = to_usb_interface(dev);
1211 struct ims_pcu *pcu = usb_get_intfdata(intf);
1212
1213 return scnprintf(buf, PAGE_SIZE, "%d\n", pcu->update_firmware_status);
1214}
1215
1216static DEVICE_ATTR(update_firmware_status, S_IRUGO,
1217 ims_pcu_update_firmware_status_show, NULL);
1218
1219static struct attribute *ims_pcu_attrs[] = {
1220 &ims_pcu_attr_part_number.dattr.attr,
1221 &ims_pcu_attr_serial_number.dattr.attr,
1222 &ims_pcu_attr_date_of_manufacturing.dattr.attr,
1223 &ims_pcu_attr_fw_version.dattr.attr,
1224 &ims_pcu_attr_bl_version.dattr.attr,
1225 &ims_pcu_attr_reset_reason.dattr.attr,
1226 &dev_attr_reset_device.attr,
1227 &dev_attr_update_firmware.attr,
1228 &dev_attr_update_firmware_status.attr,
1229 NULL
1230};
1231
1232static umode_t ims_pcu_is_attr_visible(struct kobject *kobj,
1233 struct attribute *attr, int n)
1234{
1235 struct device *dev = container_of(kobj, struct device, kobj);
1236 struct usb_interface *intf = to_usb_interface(dev);
1237 struct ims_pcu *pcu = usb_get_intfdata(intf);
1238 umode_t mode = attr->mode;
1239
1240 if (pcu->bootloader_mode) {
1241 if (attr != &dev_attr_update_firmware_status.attr &&
1242 attr != &dev_attr_update_firmware.attr &&
1243 attr != &dev_attr_reset_device.attr) {
1244 mode = 0;
1245 }
1246 } else {
1247 if (attr == &dev_attr_update_firmware_status.attr)
1248 mode = 0;
1249 }
1250
1251 return mode;
1252}
1253
1254static struct attribute_group ims_pcu_attr_group = {
1255 .is_visible = ims_pcu_is_attr_visible,
1256 .attrs = ims_pcu_attrs,
1257};
1258
1259static void ims_pcu_irq(struct urb *urb)
1260{
1261 struct ims_pcu *pcu = urb->context;
1262 int retval, status;
1263
1264 status = urb->status;
1265
1266 switch (status) {
1267 case 0:
1268 /* success */
1269 break;
1270 case -ECONNRESET:
1271 case -ENOENT:
1272 case -ESHUTDOWN:
1273 /* this urb is terminated, clean up */
1274 dev_dbg(pcu->dev, "%s - urb shutting down with status: %d\n",
1275 __func__, status);
1276 return;
1277 default:
1278 dev_dbg(pcu->dev, "%s - nonzero urb status received: %d\n",
1279 __func__, status);
1280 goto exit;
1281 }
1282
1283 dev_dbg(pcu->dev, "%s: received %d: %*ph\n", __func__,
1284 urb->actual_length, urb->actual_length, pcu->urb_in_buf);
1285
1286 if (urb == pcu->urb_in)
1287 ims_pcu_process_data(pcu, urb);
1288
1289exit:
1290 retval = usb_submit_urb(urb, GFP_ATOMIC);
1291 if (retval && retval != -ENODEV)
1292 dev_err(pcu->dev, "%s - usb_submit_urb failed with result %d\n",
1293 __func__, retval);
1294}
1295
1296static int ims_pcu_buffers_alloc(struct ims_pcu *pcu)
1297{
1298 int error;
1299
1300 pcu->urb_in_buf = usb_alloc_coherent(pcu->udev, pcu->max_in_size,
1301 GFP_KERNEL, &pcu->read_dma);
1302 if (!pcu->urb_in_buf) {
1303 dev_err(pcu->dev,
1304 "Failed to allocate memory for read buffer\n");
1305 return -ENOMEM;
1306 }
1307
1308 pcu->urb_in = usb_alloc_urb(0, GFP_KERNEL);
1309 if (!pcu->urb_in) {
1310 dev_err(pcu->dev, "Failed to allocate input URB\n");
1311 error = -ENOMEM;
1312 goto err_free_urb_in_buf;
1313 }
1314
1315 pcu->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1316 pcu->urb_in->transfer_dma = pcu->read_dma;
1317
1318 usb_fill_bulk_urb(pcu->urb_in, pcu->udev,
1319 usb_rcvbulkpipe(pcu->udev,
1320 pcu->ep_in->bEndpointAddress),
1321 pcu->urb_in_buf, pcu->max_in_size,
1322 ims_pcu_irq, pcu);
1323
1324 /*
1325 * We are using usb_bulk_msg() for sending so there is no point
1326 * in allocating memory with usb_alloc_coherent().
1327 */
1328 pcu->urb_out_buf = kmalloc(pcu->max_out_size, GFP_KERNEL);
1329 if (!pcu->urb_out_buf) {
1330 dev_err(pcu->dev, "Failed to allocate memory for write buffer\n");
1331 error = -ENOMEM;
1332 goto err_free_in_urb;
1333 }
1334
1335 pcu->urb_ctrl_buf = usb_alloc_coherent(pcu->udev, pcu->max_ctrl_size,
1336 GFP_KERNEL, &pcu->ctrl_dma);
1337 if (!pcu->urb_ctrl_buf) {
1338 dev_err(pcu->dev,
1339 "Failed to allocate memory for read buffer\n");
1340 goto err_free_urb_out_buf;
1341 }
1342
1343 pcu->urb_ctrl = usb_alloc_urb(0, GFP_KERNEL);
1344 if (!pcu->urb_ctrl) {
1345 dev_err(pcu->dev, "Failed to allocate input URB\n");
1346 error = -ENOMEM;
1347 goto err_free_urb_ctrl_buf;
1348 }
1349
1350 pcu->urb_ctrl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1351 pcu->urb_ctrl->transfer_dma = pcu->ctrl_dma;
1352
1353 usb_fill_int_urb(pcu->urb_ctrl, pcu->udev,
1354 usb_rcvintpipe(pcu->udev,
1355 pcu->ep_ctrl->bEndpointAddress),
1356 pcu->urb_ctrl_buf, pcu->max_ctrl_size,
1357 ims_pcu_irq, pcu, pcu->ep_ctrl->bInterval);
1358
1359 return 0;
1360
1361err_free_urb_ctrl_buf:
1362 usb_free_coherent(pcu->udev, pcu->max_ctrl_size,
1363 pcu->urb_ctrl_buf, pcu->ctrl_dma);
1364err_free_urb_out_buf:
1365 kfree(pcu->urb_out_buf);
1366err_free_in_urb:
1367 usb_free_urb(pcu->urb_in);
1368err_free_urb_in_buf:
1369 usb_free_coherent(pcu->udev, pcu->max_in_size,
1370 pcu->urb_in_buf, pcu->read_dma);
1371 return error;
1372}
1373
1374static void ims_pcu_buffers_free(struct ims_pcu *pcu)
1375{
1376 usb_kill_urb(pcu->urb_in);
1377 usb_free_urb(pcu->urb_in);
1378
1379 usb_free_coherent(pcu->udev, pcu->max_out_size,
1380 pcu->urb_in_buf, pcu->read_dma);
1381
1382 kfree(pcu->urb_out_buf);
1383
1384 usb_kill_urb(pcu->urb_ctrl);
1385 usb_free_urb(pcu->urb_ctrl);
1386
1387 usb_free_coherent(pcu->udev, pcu->max_ctrl_size,
1388 pcu->urb_ctrl_buf, pcu->ctrl_dma);
1389}
1390
1391static const struct usb_cdc_union_desc *
1392ims_pcu_get_cdc_union_desc(struct usb_interface *intf)
1393{
1394 const void *buf = intf->altsetting->extra;
1395 size_t buflen = intf->altsetting->extralen;
1396 struct usb_cdc_union_desc *union_desc;
1397
1398 if (!buf) {
1399 dev_err(&intf->dev, "Missing descriptor data\n");
1400 return NULL;
1401 }
1402
1403 if (!buflen) {
1404 dev_err(&intf->dev, "Zero length descriptor\n");
1405 return NULL;
1406 }
1407
1408 while (buflen > 0) {
1409 union_desc = (struct usb_cdc_union_desc *)buf;
1410
1411 if (union_desc->bDescriptorType == USB_DT_CS_INTERFACE &&
1412 union_desc->bDescriptorSubType == USB_CDC_UNION_TYPE) {
1413 dev_dbg(&intf->dev, "Found union header\n");
1414 return union_desc;
1415 }
1416
1417 buflen -= union_desc->bLength;
1418 buf += union_desc->bLength;
1419 }
1420
1421 dev_err(&intf->dev, "Missing CDC union descriptor\n");
1422 return NULL;
1423}
1424
1425static int ims_pcu_parse_cdc_data(struct usb_interface *intf, struct ims_pcu *pcu)
1426{
1427 const struct usb_cdc_union_desc *union_desc;
1428 struct usb_host_interface *alt;
1429
1430 union_desc = ims_pcu_get_cdc_union_desc(intf);
1431 if (!union_desc)
1432 return -EINVAL;
1433
1434 pcu->ctrl_intf = usb_ifnum_to_if(pcu->udev,
1435 union_desc->bMasterInterface0);
1436
1437 alt = pcu->ctrl_intf->cur_altsetting;
1438 pcu->ep_ctrl = &alt->endpoint[0].desc;
1439 pcu->max_ctrl_size = usb_endpoint_maxp(pcu->ep_ctrl);
1440
1441 pcu->data_intf = usb_ifnum_to_if(pcu->udev,
1442 union_desc->bSlaveInterface0);
1443
1444 alt = pcu->data_intf->cur_altsetting;
1445 if (alt->desc.bNumEndpoints != 2) {
1446 dev_err(pcu->dev,
1447 "Incorrect number of endpoints on data interface (%d)\n",
1448 alt->desc.bNumEndpoints);
1449 return -EINVAL;
1450 }
1451
1452 pcu->ep_out = &alt->endpoint[0].desc;
1453 if (!usb_endpoint_is_bulk_out(pcu->ep_out)) {
1454 dev_err(pcu->dev,
1455 "First endpoint on data interface is not BULK OUT\n");
1456 return -EINVAL;
1457 }
1458
1459 pcu->max_out_size = usb_endpoint_maxp(pcu->ep_out);
1460 if (pcu->max_out_size < 8) {
1461 dev_err(pcu->dev,
1462 "Max OUT packet size is too small (%zd)\n",
1463 pcu->max_out_size);
1464 return -EINVAL;
1465 }
1466
1467 pcu->ep_in = &alt->endpoint[1].desc;
1468 if (!usb_endpoint_is_bulk_in(pcu->ep_in)) {
1469 dev_err(pcu->dev,
1470 "Second endpoint on data interface is not BULK IN\n");
1471 return -EINVAL;
1472 }
1473
1474 pcu->max_in_size = usb_endpoint_maxp(pcu->ep_in);
1475 if (pcu->max_in_size < 8) {
1476 dev_err(pcu->dev,
1477 "Max IN packet size is too small (%zd)\n",
1478 pcu->max_in_size);
1479 return -EINVAL;
1480 }
1481
1482 return 0;
1483}
1484
1485static int ims_pcu_start_io(struct ims_pcu *pcu)
1486{
1487 int error;
1488
1489 error = usb_submit_urb(pcu->urb_ctrl, GFP_KERNEL);
1490 if (error) {
1491 dev_err(pcu->dev,
1492 "Failed to start control IO - usb_submit_urb failed with result: %d\n",
1493 error);
1494 return -EIO;
1495 }
1496
1497 error = usb_submit_urb(pcu->urb_in, GFP_KERNEL);
1498 if (error) {
1499 dev_err(pcu->dev,
1500 "Failed to start IO - usb_submit_urb failed with result: %d\n",
1501 error);
1502 usb_kill_urb(pcu->urb_ctrl);
1503 return -EIO;
1504 }
1505
1506 return 0;
1507}
1508
1509static void ims_pcu_stop_io(struct ims_pcu *pcu)
1510{
1511 usb_kill_urb(pcu->urb_in);
1512 usb_kill_urb(pcu->urb_ctrl);
1513}
1514
1515static int ims_pcu_line_setup(struct ims_pcu *pcu)
1516{
1517 struct usb_host_interface *interface = pcu->ctrl_intf->cur_altsetting;
1518 struct usb_cdc_line_coding *line = (void *)pcu->cmd_buf;
1519 int error;
1520
1521 memset(line, 0, sizeof(*line));
1522 line->dwDTERate = cpu_to_le32(57600);
1523 line->bDataBits = 8;
1524
1525 error = usb_control_msg(pcu->udev, usb_sndctrlpipe(pcu->udev, 0),
1526 USB_CDC_REQ_SET_LINE_CODING,
1527 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1528 0, interface->desc.bInterfaceNumber,
1529 line, sizeof(struct usb_cdc_line_coding),
1530 5000);
1531 if (error < 0) {
1532 dev_err(pcu->dev, "Failed to set line coding, error: %d\n",
1533 error);
1534 return error;
1535 }
1536
1537 error = usb_control_msg(pcu->udev, usb_sndctrlpipe(pcu->udev, 0),
1538 USB_CDC_REQ_SET_CONTROL_LINE_STATE,
1539 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1540 0x03, interface->desc.bInterfaceNumber,
1541 NULL, 0, 5000);
1542 if (error < 0) {
1543 dev_err(pcu->dev, "Failed to set line state, error: %d\n",
1544 error);
1545 return error;
1546 }
1547
1548 return 0;
1549}
1550
1551static int ims_pcu_get_device_info(struct ims_pcu *pcu)
1552{
1553 int error;
1554
1555 error = ims_pcu_get_info(pcu);
1556 if (error)
1557 return error;
1558
1559 error = ims_pcu_execute_query(pcu, GET_FW_VERSION);
1560 if (error) {
1561 dev_err(pcu->dev,
1562 "GET_FW_VERSION command failed, error: %d\n", error);
1563 return error;
1564 }
1565
1566 snprintf(pcu->fw_version, sizeof(pcu->fw_version),
1567 "%02d%02d%02d%02d.%c%c",
1568 pcu->cmd_buf[2], pcu->cmd_buf[3], pcu->cmd_buf[4], pcu->cmd_buf[5],
1569 pcu->cmd_buf[6], pcu->cmd_buf[7]);
1570
1571 error = ims_pcu_execute_query(pcu, GET_BL_VERSION);
1572 if (error) {
1573 dev_err(pcu->dev,
1574 "GET_BL_VERSION command failed, error: %d\n", error);
1575 return error;
1576 }
1577
1578 snprintf(pcu->bl_version, sizeof(pcu->bl_version),
1579 "%02d%02d%02d%02d.%c%c",
1580 pcu->cmd_buf[2], pcu->cmd_buf[3], pcu->cmd_buf[4], pcu->cmd_buf[5],
1581 pcu->cmd_buf[6], pcu->cmd_buf[7]);
1582
1583 error = ims_pcu_execute_query(pcu, RESET_REASON);
1584 if (error) {
1585 dev_err(pcu->dev,
1586 "RESET_REASON command failed, error: %d\n", error);
1587 return error;
1588 }
1589
1590 snprintf(pcu->reset_reason, sizeof(pcu->reset_reason),
1591 "%02x", pcu->cmd_buf[IMS_PCU_DATA_OFFSET]);
1592
1593 dev_dbg(pcu->dev,
1594 "P/N: %s, MD: %s, S/N: %s, FW: %s, BL: %s, RR: %s\n",
1595 pcu->part_number,
1596 pcu->date_of_manufacturing,
1597 pcu->serial_number,
1598 pcu->fw_version,
1599 pcu->bl_version,
1600 pcu->reset_reason);
1601
1602 return 0;
1603}
1604
1605static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
1606{
1607 int error;
1608
1609 error = ims_pcu_execute_query(pcu, GET_DEVICE_ID);
1610 if (error) {
1611 dev_err(pcu->dev,
1612 "GET_DEVICE_ID command failed, error: %d\n", error);
1613 return error;
1614 }
1615
1616 *device_id = pcu->cmd_buf[IMS_PCU_DATA_OFFSET];
1617 dev_dbg(pcu->dev, "Detected device ID: %d\n", *device_id);
1618
1619 return 0;
1620}
1621
1622static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
1623{
1624 static atomic_t device_no = ATOMIC_INIT(0);
1625
1626 const struct ims_pcu_device_info *info;
1627 u8 device_id;
1628 int error;
1629
1630 error = ims_pcu_get_device_info(pcu);
1631 if (error) {
1632 /* Device does not respond to basic queries, hopeless */
1633 return error;
1634 }
1635
1636 error = ims_pcu_identify_type(pcu, &device_id);
1637 if (error) {
1638 dev_err(pcu->dev,
1639 "Failed to identify device, error: %d\n", error);
1640 /*
1641 * Do not signal error, but do not create input nor
1642 * backlight devices either, let userspace figure this
1643 * out (flash a new firmware?).
1644 */
1645 return 0;
1646 }
1647
1648 if (device_id >= ARRAY_SIZE(ims_pcu_device_info) ||
1649 !ims_pcu_device_info[device_id].keymap) {
1650 dev_err(pcu->dev, "Device ID %d is not valid\n", device_id);
1651 /* Same as above, punt to userspace */
1652 return 0;
1653 }
1654
1655 /* Device appears to be operable, complete initialization */
1656 pcu->device_no = atomic_inc_return(&device_no) - 1;
1657
1658 error = ims_pcu_setup_backlight(pcu);
1659 if (error)
1660 return error;
1661
1662 info = &ims_pcu_device_info[device_id];
1663 error = ims_pcu_setup_buttons(pcu, info->keymap, info->keymap_len);
1664 if (error)
1665 goto err_destroy_backlight;
1666
1667 if (info->has_gamepad) {
1668 error = ims_pcu_setup_gamepad(pcu);
1669 if (error)
1670 goto err_destroy_buttons;
1671 }
1672
1673 pcu->setup_complete = true;
1674
1675 return 0;
1676
1677err_destroy_backlight:
1678 ims_pcu_destroy_backlight(pcu);
1679err_destroy_buttons:
1680 ims_pcu_destroy_buttons(pcu);
1681 return error;
1682}
1683
1684static void ims_pcu_destroy_application_mode(struct ims_pcu *pcu)
1685{
1686 if (pcu->setup_complete) {
1687 pcu->setup_complete = false;
1688 mb(); /* make sure flag setting is not reordered */
1689
1690 if (pcu->gamepad)
1691 ims_pcu_destroy_gamepad(pcu);
1692 ims_pcu_destroy_buttons(pcu);
1693 ims_pcu_destroy_backlight(pcu);
1694 }
1695}
1696
1697static int ims_pcu_init_bootloader_mode(struct ims_pcu *pcu)
1698{
1699 int error;
1700
1701 error = ims_pcu_execute_bl_command(pcu, QUERY_DEVICE, NULL, 0,
1702 IMS_PCU_CMD_RESPONSE_TIMEOUT);
1703 if (error) {
1704 dev_err(pcu->dev, "Bootloader does not respond, aborting\n");
1705 return error;
1706 }
1707
1708 pcu->fw_start_addr =
1709 get_unaligned_le32(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET + 11]);
1710 pcu->fw_end_addr =
1711 get_unaligned_le32(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET + 15]);
1712
1713 dev_info(pcu->dev,
1714 "Device is in bootloader mode (addr 0x%08x-0x%08x), requesting firmware\n",
1715 pcu->fw_start_addr, pcu->fw_end_addr);
1716
1717 error = request_firmware_nowait(THIS_MODULE, true,
1718 IMS_PCU_FIRMWARE_NAME,
1719 pcu->dev, GFP_KERNEL, pcu,
1720 ims_pcu_process_async_firmware);
1721 if (error) {
1722 /* This error is not fatal, let userspace have another chance */
1723 complete(&pcu->async_firmware_done);
1724 }
1725
1726 return 0;
1727}
1728
1729static void ims_pcu_destroy_bootloader_mode(struct ims_pcu *pcu)
1730{
1731 /* Make sure our initial firmware request has completed */
1732 wait_for_completion(&pcu->async_firmware_done);
1733}
1734
1735#define IMS_PCU_APPLICATION_MODE 0
1736#define IMS_PCU_BOOTLOADER_MODE 1
1737
1738static struct usb_driver ims_pcu_driver;
1739
1740static int ims_pcu_probe(struct usb_interface *intf,
1741 const struct usb_device_id *id)
1742{
1743 struct usb_device *udev = interface_to_usbdev(intf);
1744 struct ims_pcu *pcu;
1745 int error;
1746
1747 pcu = kzalloc(sizeof(struct ims_pcu), GFP_KERNEL);
1748 if (!pcu)
1749 return -ENOMEM;
1750
1751 pcu->dev = &intf->dev;
1752 pcu->udev = udev;
1753 pcu->bootloader_mode = id->driver_info == IMS_PCU_BOOTLOADER_MODE;
1754 mutex_init(&pcu->cmd_mutex);
1755 init_completion(&pcu->cmd_done);
1756 init_completion(&pcu->async_firmware_done);
1757
1758 error = ims_pcu_parse_cdc_data(intf, pcu);
1759 if (error)
1760 goto err_free_mem;
1761
1762 error = usb_driver_claim_interface(&ims_pcu_driver,
1763 pcu->data_intf, pcu);
1764 if (error) {
1765 dev_err(&intf->dev,
1766 "Unable to claim corresponding data interface: %d\n",
1767 error);
1768 goto err_free_mem;
1769 }
1770
1771 usb_set_intfdata(pcu->ctrl_intf, pcu);
1772 usb_set_intfdata(pcu->data_intf, pcu);
1773
1774 error = ims_pcu_buffers_alloc(pcu);
1775 if (error)
1776 goto err_unclaim_intf;
1777
1778 error = ims_pcu_start_io(pcu);
1779 if (error)
1780 goto err_free_buffers;
1781
1782 error = ims_pcu_line_setup(pcu);
1783 if (error)
1784 goto err_stop_io;
1785
1786 error = sysfs_create_group(&intf->dev.kobj, &ims_pcu_attr_group);
1787 if (error)
1788 goto err_stop_io;
1789
1790 error = pcu->bootloader_mode ?
1791 ims_pcu_init_bootloader_mode(pcu) :
1792 ims_pcu_init_application_mode(pcu);
1793 if (error)
1794 goto err_remove_sysfs;
1795
1796 return 0;
1797
1798err_remove_sysfs:
1799 sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group);
1800err_stop_io:
1801 ims_pcu_stop_io(pcu);
1802err_free_buffers:
1803 ims_pcu_buffers_free(pcu);
1804err_unclaim_intf:
1805 usb_driver_release_interface(&ims_pcu_driver, pcu->data_intf);
1806err_free_mem:
1807 kfree(pcu);
1808 return error;
1809}
1810
1811static void ims_pcu_disconnect(struct usb_interface *intf)
1812{
1813 struct ims_pcu *pcu = usb_get_intfdata(intf);
1814 struct usb_host_interface *alt = intf->cur_altsetting;
1815
1816 usb_set_intfdata(intf, NULL);
1817
1818 /*
1819 * See if we are dealing with control or data interface. The cleanup
1820 * happens when we unbind primary (control) interface.
1821 */
1822 if (alt->desc.bInterfaceClass != USB_CLASS_COMM)
1823 return;
1824
1825 sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group);
1826
1827 ims_pcu_stop_io(pcu);
1828
1829 if (pcu->bootloader_mode)
1830 ims_pcu_destroy_bootloader_mode(pcu);
1831 else
1832 ims_pcu_destroy_application_mode(pcu);
1833
1834 ims_pcu_buffers_free(pcu);
1835 kfree(pcu);
1836}
1837
1838#ifdef CONFIG_PM
1839static int ims_pcu_suspend(struct usb_interface *intf,
1840 pm_message_t message)
1841{
1842 struct ims_pcu *pcu = usb_get_intfdata(intf);
1843 struct usb_host_interface *alt = intf->cur_altsetting;
1844
1845 if (alt->desc.bInterfaceClass == USB_CLASS_COMM)
1846 ims_pcu_stop_io(pcu);
1847
1848 return 0;
1849}
1850
1851static int ims_pcu_resume(struct usb_interface *intf)
1852{
1853 struct ims_pcu *pcu = usb_get_intfdata(intf);
1854 struct usb_host_interface *alt = intf->cur_altsetting;
1855 int retval = 0;
1856
1857 if (alt->desc.bInterfaceClass == USB_CLASS_COMM) {
1858 retval = ims_pcu_start_io(pcu);
1859 if (retval == 0)
1860 retval = ims_pcu_line_setup(pcu);
1861 }
1862
1863 return retval;
1864}
1865#endif
1866
1867static const struct usb_device_id ims_pcu_id_table[] = {
1868 {
1869 USB_DEVICE_AND_INTERFACE_INFO(0x04d8, 0x0082,
1870 USB_CLASS_COMM,
1871 USB_CDC_SUBCLASS_ACM,
1872 USB_CDC_ACM_PROTO_AT_V25TER),
1873 .driver_info = IMS_PCU_APPLICATION_MODE,
1874 },
1875 {
1876 USB_DEVICE_AND_INTERFACE_INFO(0x04d8, 0x0083,
1877 USB_CLASS_COMM,
1878 USB_CDC_SUBCLASS_ACM,
1879 USB_CDC_ACM_PROTO_AT_V25TER),
1880 .driver_info = IMS_PCU_BOOTLOADER_MODE,
1881 },
1882 { }
1883};
1884
1885static struct usb_driver ims_pcu_driver = {
1886 .name = "ims_pcu",
1887 .id_table = ims_pcu_id_table,
1888 .probe = ims_pcu_probe,
1889 .disconnect = ims_pcu_disconnect,
1890#ifdef CONFIG_PM
1891 .suspend = ims_pcu_suspend,
1892 .resume = ims_pcu_resume,
1893 .reset_resume = ims_pcu_resume,
1894#endif
1895};
1896
1897module_usb_driver(ims_pcu_driver);
1898
1899MODULE_DESCRIPTION("IMS Passenger Control Unit driver");
1900MODULE_AUTHOR("Dmitry Torokhov <dmitry.torokhov@gmail.com>");
1901MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c
index 369a39de4ff3..f9179b2585a9 100644
--- a/drivers/input/misc/max8925_onkey.c
+++ b/drivers/input/misc/max8925_onkey.c
@@ -100,9 +100,6 @@ static int max8925_onkey_probe(struct platform_device *pdev)
100 input->dev.parent = &pdev->dev; 100 input->dev.parent = &pdev->dev;
101 input_set_capability(input, EV_KEY, KEY_POWER); 101 input_set_capability(input, EV_KEY, KEY_POWER);
102 102
103 irq[0] += chip->irq_base;
104 irq[1] += chip->irq_base;
105
106 error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler, 103 error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler,
107 IRQF_ONESHOT, "onkey-down", info); 104 IRQF_ONESHOT, "onkey-down", info);
108 if (error < 0) { 105 if (error < 0) {
diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 480557f14f23..f3309696d053 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -123,9 +123,9 @@ static void mma8450_poll(struct input_polled_dev *dev)
123 if (ret < 0) 123 if (ret < 0)
124 return; 124 return;
125 125
126 x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf); 126 x = ((int)(s8)buf[1] << 4) | (buf[0] & 0xf);
127 y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf); 127 y = ((int)(s8)buf[3] << 4) | (buf[2] & 0xf);
128 z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf); 128 z = ((int)(s8)buf[5] << 4) | (buf[4] & 0xf);
129 129
130 input_report_abs(dev->input, ABS_X, x); 130 input_report_abs(dev->input, ABS_X, x);
131 input_report_abs(dev->input, ABS_Y, y); 131 input_report_abs(dev->input, ABS_Y, y);
diff --git a/drivers/input/misc/twl4030-pwrbutton.c b/drivers/input/misc/twl4030-pwrbutton.c
index 27c2bc8aa890..b9a05fda03e4 100644
--- a/drivers/input/misc/twl4030-pwrbutton.c
+++ b/drivers/input/misc/twl4030-pwrbutton.c
@@ -114,18 +114,8 @@ static struct platform_driver twl4030_pwrbutton_driver = {
114 }, 114 },
115}; 115};
116 116
117static int __init twl4030_pwrbutton_init(void) 117module_platform_driver_probe(twl4030_pwrbutton_driver,
118{
119 return platform_driver_probe(&twl4030_pwrbutton_driver,
120 twl4030_pwrbutton_probe); 118 twl4030_pwrbutton_probe);
121}
122module_init(twl4030_pwrbutton_init);
123
124static void __exit twl4030_pwrbutton_exit(void)
125{
126 platform_driver_unregister(&twl4030_pwrbutton_driver);
127}
128module_exit(twl4030_pwrbutton_exit);
129 119
130MODULE_ALIAS("platform:twl4030_pwrbutton"); 120MODULE_ALIAS("platform:twl4030_pwrbutton");
131MODULE_DESCRIPTION("Triton2 Power Button"); 121MODULE_DESCRIPTION("Triton2 Power Button");
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 0238e0e14335..7c5d72a6a26a 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1013,8 +1013,8 @@ static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
1013 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) 1013 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1014 return -EIO; 1014 return -EIO;
1015 1015
1016 psmouse_dbg(psmouse, "%2.2X report: %2.2x %2.2x %2.2x\n", 1016 psmouse_dbg(psmouse, "%2.2X report: %3ph\n",
1017 repeated_command, param[0], param[1], param[2]); 1017 repeated_command, param);
1018 return 0; 1018 return 0;
1019} 1019}
1020 1020
@@ -1274,9 +1274,7 @@ static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
1274 psmouse_warn(psmouse, "trackstick E7 report failed\n"); 1274 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1275 ret = -ENODEV; 1275 ret = -ENODEV;
1276 } else { 1276 } else {
1277 psmouse_dbg(psmouse, 1277 psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param);
1278 "trackstick E7 report: %2.2x %2.2x %2.2x\n",
1279 param[0], param[1], param[2]);
1280 1278
1281 /* 1279 /*
1282 * Not sure what this does, but it is absolutely 1280 * Not sure what this does, but it is absolutely
@@ -1323,6 +1321,7 @@ static int alps_hw_init_v3(struct psmouse *psmouse)
1323 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE); 1321 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE);
1324 if (reg_val == -EIO) 1322 if (reg_val == -EIO)
1325 goto error; 1323 goto error;
1324
1326 if (reg_val == 0 && 1325 if (reg_val == 0 &&
1327 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO) 1326 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO)
1328 goto error; 1327 goto error;
@@ -1676,8 +1675,7 @@ static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
1676 } 1675 }
1677 1676
1678 psmouse_info(psmouse, 1677 psmouse_info(psmouse,
1679 "Unknown ALPS touchpad: E7=%2.2x %2.2x %2.2x, EC=%2.2x %2.2x %2.2x\n", 1678 "Unknown ALPS touchpad: E7=%3ph, EC=%3ph\n", e7, ec);
1680 e7[0], e7[1], e7[2], ec[0], ec[1], ec[2]);
1681 1679
1682 return -EINVAL; 1680 return -EINVAL;
1683} 1681}
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index 5fa99341a39d..b55d5af217a7 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -146,18 +146,6 @@ static struct platform_driver amimouse_driver = {
146 }, 146 },
147}; 147};
148 148
149static int __init amimouse_init(void) 149module_platform_driver_probe(amimouse_driver, amimouse_probe);
150{
151 return platform_driver_probe(&amimouse_driver, amimouse_probe);
152}
153
154module_init(amimouse_init);
155
156static void __exit amimouse_exit(void)
157{
158 platform_driver_unregister(&amimouse_driver);
159}
160
161module_exit(amimouse_exit);
162 150
163MODULE_ALIAS("platform:amiga-mouse"); 151MODULE_ALIAS("platform:amiga-mouse");
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index f3102494237d..ca843b6cf6bd 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -20,9 +20,34 @@
20#include "trackpoint.h" 20#include "trackpoint.h"
21 21
22/* 22/*
23 * Power-on Reset: Resets all trackpoint parameters, including RAM values,
24 * to defaults.
25 * Returns zero on success, non-zero on failure.
26 */
27static int trackpoint_power_on_reset(struct ps2dev *ps2dev)
28{
29 unsigned char results[2];
30 int tries = 0;
31
32 /* Issue POR command, and repeat up to once if 0xFC00 received */
33 do {
34 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
35 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 2, TP_POR)))
36 return -1;
37 } while (results[0] == 0xFC && results[1] == 0x00 && ++tries < 2);
38
39 /* Check for success response -- 0xAA00 */
40 if (results[0] != 0xAA || results[1] != 0x00)
41 return -1;
42
43 return 0;
44}
45
46/*
23 * Device IO: read, write and toggle bit 47 * Device IO: read, write and toggle bit
24 */ 48 */
25static int trackpoint_read(struct ps2dev *ps2dev, unsigned char loc, unsigned char *results) 49static int trackpoint_read(struct ps2dev *ps2dev,
50 unsigned char loc, unsigned char *results)
26{ 51{
27 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 52 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
28 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) { 53 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) {
@@ -32,7 +57,8 @@ static int trackpoint_read(struct ps2dev *ps2dev, unsigned char loc, unsigned ch
32 return 0; 57 return 0;
33} 58}
34 59
35static int trackpoint_write(struct ps2dev *ps2dev, unsigned char loc, unsigned char val) 60static int trackpoint_write(struct ps2dev *ps2dev,
61 unsigned char loc, unsigned char val)
36{ 62{
37 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 63 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
38 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) || 64 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) ||
@@ -44,7 +70,8 @@ static int trackpoint_write(struct ps2dev *ps2dev, unsigned char loc, unsigned c
44 return 0; 70 return 0;
45} 71}
46 72
47static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsigned char mask) 73static int trackpoint_toggle_bit(struct ps2dev *ps2dev,
74 unsigned char loc, unsigned char mask)
48{ 75{
49 /* Bad things will happen if the loc param isn't in this range */ 76 /* Bad things will happen if the loc param isn't in this range */
50 if (loc < 0x20 || loc >= 0x2F) 77 if (loc < 0x20 || loc >= 0x2F)
@@ -60,6 +87,18 @@ static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsig
60 return 0; 87 return 0;
61} 88}
62 89
90static int trackpoint_update_bit(struct ps2dev *ps2dev, unsigned char loc,
91 unsigned char mask, unsigned char value)
92{
93 int retval = 0;
94 unsigned char data;
95
96 trackpoint_read(ps2dev, loc, &data);
97 if (((data & mask) == mask) != !!value)
98 retval = trackpoint_toggle_bit(ps2dev, loc, mask);
99
100 return retval;
101}
63 102
64/* 103/*
65 * Trackpoint-specific attributes 104 * Trackpoint-specific attributes
@@ -69,6 +108,7 @@ struct trackpoint_attr_data {
69 unsigned char command; 108 unsigned char command;
70 unsigned char mask; 109 unsigned char mask;
71 unsigned char inverted; 110 unsigned char inverted;
111 unsigned char power_on_default;
72}; 112};
73 113
74static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, void *data, char *buf) 114static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, void *data, char *buf)
@@ -102,10 +142,11 @@ static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
102 return count; 142 return count;
103} 143}
104 144
105#define TRACKPOINT_INT_ATTR(_name, _command) \ 145#define TRACKPOINT_INT_ATTR(_name, _command, _default) \
106 static struct trackpoint_attr_data trackpoint_attr_##_name = { \ 146 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
107 .field_offset = offsetof(struct trackpoint_data, _name), \ 147 .field_offset = offsetof(struct trackpoint_data, _name), \
108 .command = _command, \ 148 .command = _command, \
149 .power_on_default = _default, \
109 }; \ 150 }; \
110 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \ 151 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
111 &trackpoint_attr_##_name, \ 152 &trackpoint_attr_##_name, \
@@ -139,31 +180,60 @@ static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
139} 180}
140 181
141 182
142#define TRACKPOINT_BIT_ATTR(_name, _command, _mask, _inv) \ 183#define TRACKPOINT_BIT_ATTR(_name, _command, _mask, _inv, _default) \
143 static struct trackpoint_attr_data trackpoint_attr_##_name = { \ 184static struct trackpoint_attr_data trackpoint_attr_##_name = { \
144 .field_offset = offsetof(struct trackpoint_data, _name), \ 185 .field_offset = offsetof(struct trackpoint_data, \
145 .command = _command, \ 186 _name), \
146 .mask = _mask, \ 187 .command = _command, \
147 .inverted = _inv, \ 188 .mask = _mask, \
148 }; \ 189 .inverted = _inv, \
149 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \ 190 .power_on_default = _default, \
150 &trackpoint_attr_##_name, \ 191 }; \
151 trackpoint_show_int_attr, trackpoint_set_bit_attr) 192PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
152 193 &trackpoint_attr_##_name, \
153TRACKPOINT_INT_ATTR(sensitivity, TP_SENS); 194 trackpoint_show_int_attr, trackpoint_set_bit_attr)
154TRACKPOINT_INT_ATTR(speed, TP_SPEED); 195
155TRACKPOINT_INT_ATTR(inertia, TP_INERTIA); 196#define TRACKPOINT_UPDATE_BIT(_psmouse, _tp, _name) \
156TRACKPOINT_INT_ATTR(reach, TP_REACH); 197do { \
157TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS); 198 struct trackpoint_attr_data *_attr = &trackpoint_attr_##_name; \
158TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG); 199 \
159TRACKPOINT_INT_ATTR(thresh, TP_THRESH); 200 trackpoint_update_bit(&_psmouse->ps2dev, \
160TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH); 201 _attr->command, _attr->mask, _tp->_name); \
161TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME); 202} while (0)
162TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV); 203
163 204#define TRACKPOINT_UPDATE(_power_on, _psmouse, _tp, _name) \
164TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON, 0); 205do { \
165TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK, 0); 206 if (!_power_on || \
166TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV, 1); 207 _tp->_name != trackpoint_attr_##_name.power_on_default) { \
208 if (!trackpoint_attr_##_name.mask) \
209 trackpoint_write(&_psmouse->ps2dev, \
210 trackpoint_attr_##_name.command, \
211 _tp->_name); \
212 else \
213 TRACKPOINT_UPDATE_BIT(_psmouse, _tp, _name); \
214 } \
215} while (0)
216
217#define TRACKPOINT_SET_POWER_ON_DEFAULT(_tp, _name) \
218 (_tp->_name = trackpoint_attr_##_name.power_on_default)
219
220TRACKPOINT_INT_ATTR(sensitivity, TP_SENS, TP_DEF_SENS);
221TRACKPOINT_INT_ATTR(speed, TP_SPEED, TP_DEF_SPEED);
222TRACKPOINT_INT_ATTR(inertia, TP_INERTIA, TP_DEF_INERTIA);
223TRACKPOINT_INT_ATTR(reach, TP_REACH, TP_DEF_REACH);
224TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS, TP_DEF_DRAGHYS);
225TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG, TP_DEF_MINDRAG);
226TRACKPOINT_INT_ATTR(thresh, TP_THRESH, TP_DEF_THRESH);
227TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH, TP_DEF_UP_THRESH);
228TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME, TP_DEF_Z_TIME);
229TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV, TP_DEF_JENKS_CURV);
230
231TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON, 0,
232 TP_DEF_PTSON);
233TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK, 0,
234 TP_DEF_SKIPBACK);
235TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV, 1,
236 TP_DEF_EXT_DEV);
167 237
168static struct attribute *trackpoint_attrs[] = { 238static struct attribute *trackpoint_attrs[] = {
169 &psmouse_attr_sensitivity.dattr.attr, 239 &psmouse_attr_sensitivity.dattr.attr,
@@ -202,73 +272,72 @@ static int trackpoint_start_protocol(struct psmouse *psmouse, unsigned char *fir
202 return 0; 272 return 0;
203} 273}
204 274
205static int trackpoint_sync(struct psmouse *psmouse) 275/*
276 * Write parameters to trackpad.
277 * in_power_on_state: Set to true if TP is in default / power-on state (ex. if
278 * power-on reset was run). If so, values will only be
279 * written to TP if they differ from power-on default.
280 */
281static int trackpoint_sync(struct psmouse *psmouse, bool in_power_on_state)
206{ 282{
207 struct trackpoint_data *tp = psmouse->private; 283 struct trackpoint_data *tp = psmouse->private;
208 unsigned char toggle;
209
210 /* Disable features that may make device unusable with this driver */
211 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle);
212 if (toggle & TP_MASK_TWOHAND)
213 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, TP_MASK_TWOHAND);
214
215 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, &toggle);
216 if (toggle & TP_MASK_SOURCE_TAG)
217 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, TP_MASK_SOURCE_TAG);
218
219 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle);
220 if (toggle & TP_MASK_MB)
221 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB);
222
223 /* Push the config to the device */
224 trackpoint_write(&psmouse->ps2dev, TP_SENS, tp->sensitivity);
225 trackpoint_write(&psmouse->ps2dev, TP_INERTIA, tp->inertia);
226 trackpoint_write(&psmouse->ps2dev, TP_SPEED, tp->speed);
227
228 trackpoint_write(&psmouse->ps2dev, TP_REACH, tp->reach);
229 trackpoint_write(&psmouse->ps2dev, TP_DRAGHYS, tp->draghys);
230 trackpoint_write(&psmouse->ps2dev, TP_MINDRAG, tp->mindrag);
231
232 trackpoint_write(&psmouse->ps2dev, TP_THRESH, tp->thresh);
233 trackpoint_write(&psmouse->ps2dev, TP_UP_THRESH, tp->upthresh);
234 284
235 trackpoint_write(&psmouse->ps2dev, TP_Z_TIME, tp->ztime); 285 if (!in_power_on_state) {
236 trackpoint_write(&psmouse->ps2dev, TP_JENKS_CURV, tp->jenks); 286 /*
287 * Disable features that may make device unusable
288 * with this driver.
289 */
290 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND,
291 TP_MASK_TWOHAND, TP_DEF_TWOHAND);
237 292
238 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_PTSON, &toggle); 293 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG,
239 if (((toggle & TP_MASK_PTSON) == TP_MASK_PTSON) != tp->press_to_select) 294 TP_MASK_SOURCE_TAG, TP_DEF_SOURCE_TAG);
240 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_PTSON, TP_MASK_PTSON);
241 295
242 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, &toggle); 296 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_MB,
243 if (((toggle & TP_MASK_SKIPBACK) == TP_MASK_SKIPBACK) != tp->skipback) 297 TP_MASK_MB, TP_DEF_MB);
244 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); 298 }
245 299
246 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, &toggle); 300 /*
247 if (((toggle & TP_MASK_EXT_DEV) == TP_MASK_EXT_DEV) != tp->ext_dev) 301 * These properties can be changed in this driver. Only
248 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); 302 * configure them if the values are non-default or if the TP is in
303 * an unknown state.
304 */
305 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, sensitivity);
306 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, inertia);
307 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, speed);
308 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, reach);
309 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, draghys);
310 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, mindrag);
311 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, thresh);
312 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, upthresh);
313 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, ztime);
314 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, jenks);
315
316 /* toggles */
317 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, press_to_select);
318 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, skipback);
319 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, ext_dev);
249 320
250 return 0; 321 return 0;
251} 322}
252 323
253static void trackpoint_defaults(struct trackpoint_data *tp) 324static void trackpoint_defaults(struct trackpoint_data *tp)
254{ 325{
255 tp->press_to_select = TP_DEF_PTSON; 326 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, sensitivity);
256 tp->sensitivity = TP_DEF_SENS; 327 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, speed);
257 tp->speed = TP_DEF_SPEED; 328 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, reach);
258 tp->reach = TP_DEF_REACH; 329 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, draghys);
259 330 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, mindrag);
260 tp->draghys = TP_DEF_DRAGHYS; 331 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, thresh);
261 tp->mindrag = TP_DEF_MINDRAG; 332 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, upthresh);
262 333 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, ztime);
263 tp->thresh = TP_DEF_THRESH; 334 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, jenks);
264 tp->upthresh = TP_DEF_UP_THRESH; 335 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, inertia);
265 336
266 tp->ztime = TP_DEF_Z_TIME; 337 /* toggles */
267 tp->jenks = TP_DEF_JENKS_CURV; 338 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, press_to_select);
268 339 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, skipback);
269 tp->inertia = TP_DEF_INERTIA; 340 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, ext_dev);
270 tp->skipback = TP_DEF_SKIPBACK;
271 tp->ext_dev = TP_DEF_EXT_DEV;
272} 341}
273 342
274static void trackpoint_disconnect(struct psmouse *psmouse) 343static void trackpoint_disconnect(struct psmouse *psmouse)
@@ -281,10 +350,13 @@ static void trackpoint_disconnect(struct psmouse *psmouse)
281 350
282static int trackpoint_reconnect(struct psmouse *psmouse) 351static int trackpoint_reconnect(struct psmouse *psmouse)
283{ 352{
353 int reset_fail;
354
284 if (trackpoint_start_protocol(psmouse, NULL)) 355 if (trackpoint_start_protocol(psmouse, NULL))
285 return -1; 356 return -1;
286 357
287 if (trackpoint_sync(psmouse)) 358 reset_fail = trackpoint_power_on_reset(&psmouse->ps2dev);
359 if (trackpoint_sync(psmouse, !reset_fail))
288 return -1; 360 return -1;
289 361
290 return 0; 362 return 0;
@@ -322,7 +394,12 @@ int trackpoint_detect(struct psmouse *psmouse, bool set_properties)
322 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 394 __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
323 395
324 trackpoint_defaults(psmouse->private); 396 trackpoint_defaults(psmouse->private);
325 trackpoint_sync(psmouse); 397
398 error = trackpoint_power_on_reset(&psmouse->ps2dev);
399
400 /* Write defaults to TP only if reset fails. */
401 if (error)
402 trackpoint_sync(psmouse, false);
326 403
327 error = sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group); 404 error = sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group);
328 if (error) { 405 if (error) {
diff --git a/drivers/input/mouse/trackpoint.h b/drivers/input/mouse/trackpoint.h
index e558a7096618..ecd0547964a5 100644
--- a/drivers/input/mouse/trackpoint.h
+++ b/drivers/input/mouse/trackpoint.h
@@ -126,6 +126,8 @@
126#define TP_DEF_PTSON 0x00 126#define TP_DEF_PTSON 0x00
127#define TP_DEF_SKIPBACK 0x00 127#define TP_DEF_SKIPBACK 0x00
128#define TP_DEF_EXT_DEV 0x00 /* 0 means enabled */ 128#define TP_DEF_EXT_DEV 0x00 /* 0 means enabled */
129#define TP_DEF_TWOHAND 0x00
130#define TP_DEF_SOURCE_TAG 0x00
129 131
130#define MAKE_PS2_CMD(params, results, cmd) ((params<<12) | (results<<8) | (cmd)) 132#define MAKE_PS2_CMD(params, results, cmd) ((params<<12) | (results<<8) | (cmd))
131 133
@@ -136,9 +138,9 @@ struct trackpoint_data
136 unsigned char thresh, upthresh; 138 unsigned char thresh, upthresh;
137 unsigned char ztime, jenks; 139 unsigned char ztime, jenks;
138 140
141 /* toggles */
139 unsigned char press_to_select; 142 unsigned char press_to_select;
140 unsigned char skipback; 143 unsigned char skipback;
141
142 unsigned char ext_dev; 144 unsigned char ext_dev;
143}; 145};
144 146
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index 560c243bfcaf..aebfe3ecb945 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -22,7 +22,7 @@ config SERIO_I8042
22 tristate "i8042 PC Keyboard controller" if EXPERT || !X86 22 tristate "i8042 PC Keyboard controller" if EXPERT || !X86
23 default y 23 default y
24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && \ 24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && \
25 (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN 25 (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN && !S390
26 help 26 help
27 i8042 is the chip over which the standard AT keyboard and PS/2 27 i8042 is the chip over which the standard AT keyboard and PS/2
28 mouse are connected to the computer. If you use these devices, 28 mouse are connected to the computer. If you use these devices,
@@ -36,6 +36,7 @@ config SERIO_I8042
36config SERIO_SERPORT 36config SERIO_SERPORT
37 tristate "Serial port line discipline" 37 tristate "Serial port line discipline"
38 default y 38 default y
39 depends on TTY
39 help 40 help
40 Say Y here if you plan to use an input device (mouse, joystick, 41 Say Y here if you plan to use an input device (mouse, joystick,
41 tablet, 6dof) that communicates over the RS232 serial (COM) port. 42 tablet, 6dof) that communicates over the RS232 serial (COM) port.
@@ -244,4 +245,14 @@ config SERIO_ARC_PS2
244 To compile this driver as a module, choose M here; the module 245 To compile this driver as a module, choose M here; the module
245 will be called arc_ps2. 246 will be called arc_ps2.
246 247
248config SERIO_APBPS2
249 tristate "GRLIB APBPS2 PS/2 keyboard/mouse controller"
250 depends on OF
251 help
252 Say Y here if you want support for GRLIB APBPS2 peripherals used
253 to connect to PS/2 keyboard and/or mouse.
254
255 To compile this driver as a module, choose M here: the module will
256 be called apbps2.
257
247endif 258endif
diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile
index 4b0c8f84f1c1..8edb36c2cdb4 100644
--- a/drivers/input/serio/Makefile
+++ b/drivers/input/serio/Makefile
@@ -26,3 +26,4 @@ obj-$(CONFIG_SERIO_AMS_DELTA) += ams_delta_serio.o
26obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o 26obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o
27obj-$(CONFIG_SERIO_ALTERA_PS2) += altera_ps2.o 27obj-$(CONFIG_SERIO_ALTERA_PS2) += altera_ps2.o
28obj-$(CONFIG_SERIO_ARC_PS2) += arc_ps2.o 28obj-$(CONFIG_SERIO_ARC_PS2) += arc_ps2.o
29obj-$(CONFIG_SERIO_APBPS2) += apbps2.o
diff --git a/drivers/input/serio/apbps2.c b/drivers/input/serio/apbps2.c
new file mode 100644
index 000000000000..17e01a807ddc
--- /dev/null
+++ b/drivers/input/serio/apbps2.c
@@ -0,0 +1,228 @@
1/*
2 * Copyright (C) 2013 Aeroflex Gaisler
3 *
4 * This driver supports the APBPS2 PS/2 core available in the GRLIB
5 * VHDL IP core library.
6 *
7 * Full documentation of the APBPS2 core can be found here:
8 * http://www.gaisler.com/products/grlib/grip.pdf
9 *
10 * See "Documentation/devicetree/bindings/input/ps2keyb-mouse-apbps2.txt" for
11 * information on open firmware properties.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * Contributors: Daniel Hellstrom <daniel@gaisler.com>
19 */
20#include <linux/platform_device.h>
21#include <linux/of_device.h>
22#include <linux/module.h>
23#include <linux/serio.h>
24#include <linux/errno.h>
25#include <linux/interrupt.h>
26#include <linux/of_irq.h>
27#include <linux/device.h>
28#include <linux/delay.h>
29#include <linux/err.h>
30#include <linux/slab.h>
31#include <linux/string.h>
32#include <linux/kernel.h>
33#include <linux/io.h>
34
35struct apbps2_regs {
36 u32 __iomem data; /* 0x00 */
37 u32 __iomem status; /* 0x04 */
38 u32 __iomem ctrl; /* 0x08 */
39 u32 __iomem reload; /* 0x0c */
40};
41
42#define APBPS2_STATUS_DR (1<<0)
43#define APBPS2_STATUS_PE (1<<1)
44#define APBPS2_STATUS_FE (1<<2)
45#define APBPS2_STATUS_KI (1<<3)
46#define APBPS2_STATUS_RF (1<<4)
47#define APBPS2_STATUS_TF (1<<5)
48#define APBPS2_STATUS_TCNT (0x1f<<22)
49#define APBPS2_STATUS_RCNT (0x1f<<27)
50
51#define APBPS2_CTRL_RE (1<<0)
52#define APBPS2_CTRL_TE (1<<1)
53#define APBPS2_CTRL_RI (1<<2)
54#define APBPS2_CTRL_TI (1<<3)
55
56struct apbps2_priv {
57 struct serio *io;
58 struct apbps2_regs *regs;
59};
60
61static int apbps2_idx;
62
63static irqreturn_t apbps2_isr(int irq, void *dev_id)
64{
65 struct apbps2_priv *priv = dev_id;
66 unsigned long status, data, rxflags;
67 irqreturn_t ret = IRQ_NONE;
68
69 while ((status = ioread32be(&priv->regs->status)) & APBPS2_STATUS_DR) {
70 data = ioread32be(&priv->regs->data);
71 rxflags = (status & APBPS2_STATUS_PE) ? SERIO_PARITY : 0;
72 rxflags |= (status & APBPS2_STATUS_FE) ? SERIO_FRAME : 0;
73
74 /* clear error bits? */
75 if (rxflags)
76 iowrite32be(0, &priv->regs->status);
77
78 serio_interrupt(priv->io, data, rxflags);
79
80 ret = IRQ_HANDLED;
81 }
82
83 return ret;
84}
85
86static int apbps2_write(struct serio *io, unsigned char val)
87{
88 struct apbps2_priv *priv = io->port_data;
89 unsigned int tleft = 10000; /* timeout in 100ms */
90
91 /* delay until PS/2 controller has room for more chars */
92 while ((ioread32be(&priv->regs->status) & APBPS2_STATUS_TF) && tleft--)
93 udelay(10);
94
95 if ((ioread32be(&priv->regs->status) & APBPS2_STATUS_TF) == 0) {
96 iowrite32be(val, &priv->regs->data);
97
98 iowrite32be(APBPS2_CTRL_RE | APBPS2_CTRL_RI | APBPS2_CTRL_TE,
99 &priv->regs->ctrl);
100 return 0;
101 }
102
103 return -ETIMEDOUT;
104}
105
106static int apbps2_open(struct serio *io)
107{
108 struct apbps2_priv *priv = io->port_data;
109 int limit;
110 unsigned long tmp;
111
112 /* clear error flags */
113 iowrite32be(0, &priv->regs->status);
114
115 /* Clear old data if available (unlikely) */
116 limit = 1024;
117 while ((ioread32be(&priv->regs->status) & APBPS2_STATUS_DR) && --limit)
118 tmp = ioread32be(&priv->regs->data);
119
120 /* Enable reciever and it's interrupt */
121 iowrite32be(APBPS2_CTRL_RE | APBPS2_CTRL_RI, &priv->regs->ctrl);
122
123 return 0;
124}
125
126static void apbps2_close(struct serio *io)
127{
128 struct apbps2_priv *priv = io->port_data;
129
130 /* stop interrupts at PS/2 HW level */
131 iowrite32be(0, &priv->regs->ctrl);
132}
133
134/* Initialize one APBPS2 PS/2 core */
135static int apbps2_of_probe(struct platform_device *ofdev)
136{
137 struct apbps2_priv *priv;
138 int irq, err;
139 u32 freq_hz;
140 struct resource *res;
141
142 priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL);
143 if (!priv) {
144 dev_err(&ofdev->dev, "memory allocation failed\n");
145 return -ENOMEM;
146 }
147
148 /* Find Device Address */
149 res = platform_get_resource(ofdev, IORESOURCE_MEM, 0);
150 priv->regs = devm_ioremap_resource(&ofdev->dev, res);
151 if (IS_ERR(priv->regs))
152 return PTR_ERR(priv->regs);
153
154 /* Reset hardware, disable interrupt */
155 iowrite32be(0, &priv->regs->ctrl);
156
157 /* IRQ */
158 irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
159 err = devm_request_irq(&ofdev->dev, irq, apbps2_isr,
160 IRQF_SHARED, "apbps2", priv);
161 if (err) {
162 dev_err(&ofdev->dev, "request IRQ%d failed\n", irq);
163 return err;
164 }
165
166 /* Get core frequency */
167 if (of_property_read_u32(ofdev->dev.of_node, "freq", &freq_hz)) {
168 dev_err(&ofdev->dev, "unable to get core frequency\n");
169 return -EINVAL;
170 }
171
172 /* Set reload register to core freq in kHz/10 */
173 iowrite32be(freq_hz / 10000, &priv->regs->reload);
174
175 priv->io = kzalloc(sizeof(struct serio), GFP_KERNEL);
176 if (!priv->io)
177 return -ENOMEM;
178
179 priv->io->id.type = SERIO_8042;
180 priv->io->open = apbps2_open;
181 priv->io->close = apbps2_close;
182 priv->io->write = apbps2_write;
183 priv->io->port_data = priv;
184 strlcpy(priv->io->name, "APBPS2 PS/2", sizeof(priv->io->name));
185 snprintf(priv->io->phys, sizeof(priv->io->phys),
186 "apbps2_%d", apbps2_idx++);
187
188 dev_info(&ofdev->dev, "irq = %d, base = 0x%p\n", irq, priv->regs);
189
190 serio_register_port(priv->io);
191
192 platform_set_drvdata(ofdev, priv);
193
194 return 0;
195}
196
197static int apbps2_of_remove(struct platform_device *of_dev)
198{
199 struct apbps2_priv *priv = platform_get_drvdata(of_dev);
200
201 serio_unregister_port(priv->io);
202
203 return 0;
204}
205
206static struct of_device_id apbps2_of_match[] = {
207 { .name = "GAISLER_APBPS2", },
208 { .name = "01_060", },
209 {}
210};
211
212MODULE_DEVICE_TABLE(of, apbps2_of_match);
213
214static struct platform_driver apbps2_of_driver = {
215 .driver = {
216 .name = "grlib-apbps2",
217 .owner = THIS_MODULE,
218 .of_match_table = apbps2_of_match,
219 },
220 .probe = apbps2_of_probe,
221 .remove = apbps2_of_remove,
222};
223
224module_platform_driver(apbps2_of_driver);
225
226MODULE_AUTHOR("Aeroflex Gaisler AB.");
227MODULE_DESCRIPTION("GRLIB APBPS2 PS/2 serial I/O");
228MODULE_LICENSE("GPL");
diff --git a/drivers/input/serio/arc_ps2.c b/drivers/input/serio/arc_ps2.c
index b571eb3e4efc..3fb7727c8ea5 100644
--- a/drivers/input/serio/arc_ps2.c
+++ b/drivers/input/serio/arc_ps2.c
@@ -8,11 +8,13 @@
8 * Driver is originally developed by Pavel Sokolov <psokolov@synopsys.com> 8 * Driver is originally developed by Pavel Sokolov <psokolov@synopsys.com>
9 */ 9 */
10 10
11#include <linux/err.h>
11#include <linux/module.h> 12#include <linux/module.h>
12#include <linux/interrupt.h> 13#include <linux/interrupt.h>
13#include <linux/input.h> 14#include <linux/input.h>
14#include <linux/serio.h> 15#include <linux/serio.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/of.h>
16#include <linux/io.h> 18#include <linux/io.h>
17#include <linux/kernel.h> 19#include <linux/kernel.h>
18#include <linux/slab.h> 20#include <linux/slab.h>
@@ -206,9 +208,9 @@ static int arc_ps2_probe(struct platform_device *pdev)
206 return -ENOMEM; 208 return -ENOMEM;
207 } 209 }
208 210
209 arc_ps2->addr = devm_request_and_ioremap(&pdev->dev, res); 211 arc_ps2->addr = devm_ioremap_resource(&pdev->dev, res);
210 if (!arc_ps2->addr) 212 if (IS_ERR(arc_ps2->addr))
211 return -EBUSY; 213 return PTR_ERR(arc_ps2->addr);
212 214
213 dev_info(&pdev->dev, "irq = %d, address = 0x%p, ports = %i\n", 215 dev_info(&pdev->dev, "irq = %d, address = 0x%p, ports = %i\n",
214 irq, arc_ps2->addr, ARC_PS2_PORTS); 216 irq, arc_ps2->addr, ARC_PS2_PORTS);
@@ -258,10 +260,19 @@ static int arc_ps2_remove(struct platform_device *pdev)
258 return 0; 260 return 0;
259} 261}
260 262
263#ifdef CONFIG_OF
264static const struct of_device_id arc_ps2_match[] = {
265 { .compatible = "snps,arc_ps2" },
266 { },
267};
268MODULE_DEVICE_TABLE(of, arc_ps2_match);
269#endif
270
261static struct platform_driver arc_ps2_driver = { 271static struct platform_driver arc_ps2_driver = {
262 .driver = { 272 .driver = {
263 .name = "arc_ps2", 273 .name = "arc_ps2",
264 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
275 .of_match_table = of_match_ptr(arc_ps2_match),
265 }, 276 },
266 .probe = arc_ps2_probe, 277 .probe = arc_ps2_probe,
267 .remove = arc_ps2_remove, 278 .remove = arc_ps2_remove,
diff --git a/drivers/input/serio/at32psif.c b/drivers/input/serio/at32psif.c
index 36e799c31f5e..190ce35af7df 100644
--- a/drivers/input/serio/at32psif.c
+++ b/drivers/input/serio/at32psif.c
@@ -359,18 +359,7 @@ static struct platform_driver psif_driver = {
359 }, 359 },
360}; 360};
361 361
362static int __init psif_init(void) 362module_platform_driver_probe(psif_driver, psif_probe);
363{
364 return platform_driver_probe(&psif_driver, psif_probe);
365}
366
367static void __exit psif_exit(void)
368{
369 platform_driver_unregister(&psif_driver);
370}
371
372module_init(psif_init);
373module_exit(psif_exit);
374 363
375MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>"); 364MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
376MODULE_DESCRIPTION("Atmel AVR32 PSIF PS/2 driver"); 365MODULE_DESCRIPTION("Atmel AVR32 PSIF PS/2 driver");
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index d6cc77a53c7e..5f306f79da0c 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -921,6 +921,7 @@ static int __init i8042_platform_init(void)
921 int retval; 921 int retval;
922 922
923#ifdef CONFIG_X86 923#ifdef CONFIG_X86
924 u8 a20_on = 0xdf;
924 /* Just return if pre-detection shows no i8042 controller exist */ 925 /* Just return if pre-detection shows no i8042 controller exist */
925 if (!x86_platform.i8042_detect()) 926 if (!x86_platform.i8042_detect())
926 return -ENODEV; 927 return -ENODEV;
@@ -960,6 +961,14 @@ static int __init i8042_platform_init(void)
960 961
961 if (dmi_check_system(i8042_dmi_dritek_table)) 962 if (dmi_check_system(i8042_dmi_dritek_table))
962 i8042_dritek = true; 963 i8042_dritek = true;
964
965 /*
966 * A20 was already enabled during early kernel init. But some buggy
967 * BIOSes (in MSI Laptops) require A20 to be enabled using 8042 to
968 * resume from S3. So we do it here and hope that nothing breaks.
969 */
970 i8042_command(&a20_on, 0x10d1);
971 i8042_command(NULL, 0x00ff); /* Null command for SMM firmware */
963#endif /* CONFIG_X86 */ 972#endif /* CONFIG_X86 */
964 973
965 return retval; 974 return retval;
diff --git a/drivers/input/serio/q40kbd.c b/drivers/input/serio/q40kbd.c
index 70fe542839fb..436a3433f8e5 100644
--- a/drivers/input/serio/q40kbd.c
+++ b/drivers/input/serio/q40kbd.c
@@ -193,15 +193,4 @@ static struct platform_driver q40kbd_driver = {
193 .remove = q40kbd_remove, 193 .remove = q40kbd_remove,
194}; 194};
195 195
196static int __init q40kbd_init(void) 196module_platform_driver_probe(q40kbd_driver, q40kbd_probe);
197{
198 return platform_driver_probe(&q40kbd_driver, q40kbd_probe);
199}
200
201static void __exit q40kbd_exit(void)
202{
203 platform_driver_unregister(&q40kbd_driver);
204}
205
206module_init(q40kbd_init);
207module_exit(q40kbd_exit);
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9a647ee1136a..f9a5fd89bc02 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -517,9 +517,9 @@ config TOUCHSCREEN_TOUCHWIN
517 To compile this driver as a module, choose M here: the 517 To compile this driver as a module, choose M here: the
518 module will be called touchwin. 518 module will be called touchwin.
519 519
520config TOUCHSCREEN_TI_TSCADC 520config TOUCHSCREEN_TI_AM335X_TSC
521 tristate "TI Touchscreen Interface" 521 tristate "TI Touchscreen Interface"
522 depends on ARCH_OMAP2PLUS 522 depends on MFD_TI_AM335X_TSCADC
523 help 523 help
524 Say Y here if you have 4/5/8 wire touchscreen controller 524 Say Y here if you have 4/5/8 wire touchscreen controller
525 to be connected to the ADC controller on your TI AM335x SoC. 525 to be connected to the ADC controller on your TI AM335x SoC.
@@ -527,7 +527,7 @@ config TOUCHSCREEN_TI_TSCADC
527 If unsure, say N. 527 If unsure, say N.
528 528
529 To compile this driver as a module, choose M here: the 529 To compile this driver as a module, choose M here: the
530 module will be called ti_tscadc. 530 module will be called ti_am335x_tsc.
531 531
532config TOUCHSCREEN_ATMEL_TSADCC 532config TOUCHSCREEN_ATMEL_TSADCC
533 tristate "Atmel Touchscreen Interface" 533 tristate "Atmel Touchscreen Interface"
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 5f949c0bf82f..6bfbeab67c9f 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -51,7 +51,7 @@ obj-$(CONFIG_TOUCHSCREEN_PIXCIR) += pixcir_i2c_ts.o
51obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o 51obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o
52obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o 52obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o
53obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o 53obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o
54obj-$(CONFIG_TOUCHSCREEN_TI_TSCADC) += ti_tscadc.o 54obj-$(CONFIG_TOUCHSCREEN_TI_AM335X_TSC) += ti_am335x_tsc.o
55obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o 55obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o
56obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o 56obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
57obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 57obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index 23fa829b869d..f3a174a83c82 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -273,7 +273,7 @@ static int ad7877_write(struct spi_device *spi, u16 reg, u16 val)
273 273
274static int ad7877_read_adc(struct spi_device *spi, unsigned command) 274static int ad7877_read_adc(struct spi_device *spi, unsigned command)
275{ 275{
276 struct ad7877 *ts = dev_get_drvdata(&spi->dev); 276 struct ad7877 *ts = spi_get_drvdata(spi);
277 struct ser_req *req; 277 struct ser_req *req;
278 int status; 278 int status;
279 int sample; 279 int sample;
@@ -720,7 +720,7 @@ static int ad7877_probe(struct spi_device *spi)
720 goto err_free_mem; 720 goto err_free_mem;
721 } 721 }
722 722
723 dev_set_drvdata(&spi->dev, ts); 723 spi_set_drvdata(spi, ts);
724 ts->spi = spi; 724 ts->spi = spi;
725 ts->input = input_dev; 725 ts->input = input_dev;
726 726
@@ -806,13 +806,13 @@ err_free_irq:
806err_free_mem: 806err_free_mem:
807 input_free_device(input_dev); 807 input_free_device(input_dev);
808 kfree(ts); 808 kfree(ts);
809 dev_set_drvdata(&spi->dev, NULL); 809 spi_set_drvdata(spi, NULL);
810 return err; 810 return err;
811} 811}
812 812
813static int ad7877_remove(struct spi_device *spi) 813static int ad7877_remove(struct spi_device *spi)
814{ 814{
815 struct ad7877 *ts = dev_get_drvdata(&spi->dev); 815 struct ad7877 *ts = spi_get_drvdata(spi);
816 816
817 sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); 817 sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
818 818
@@ -823,7 +823,7 @@ static int ad7877_remove(struct spi_device *spi)
823 kfree(ts); 823 kfree(ts);
824 824
825 dev_dbg(&spi->dev, "unregistered touchscreen\n"); 825 dev_dbg(&spi->dev, "unregistered touchscreen\n");
826 dev_set_drvdata(&spi->dev, NULL); 826 spi_set_drvdata(spi, NULL);
827 827
828 return 0; 828 return 0;
829} 829}
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 434c3df250ca..84ccf140c1bb 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -1245,7 +1245,7 @@ static int ads7846_probe(struct spi_device *spi)
1245 goto err_free_mem; 1245 goto err_free_mem;
1246 } 1246 }
1247 1247
1248 dev_set_drvdata(&spi->dev, ts); 1248 spi_set_drvdata(spi, ts);
1249 1249
1250 ts->packet = packet; 1250 ts->packet = packet;
1251 ts->spi = spi; 1251 ts->spi = spi;
@@ -1397,7 +1397,7 @@ static int ads7846_probe(struct spi_device *spi)
1397 1397
1398static int ads7846_remove(struct spi_device *spi) 1398static int ads7846_remove(struct spi_device *spi)
1399{ 1399{
1400 struct ads7846 *ts = dev_get_drvdata(&spi->dev); 1400 struct ads7846 *ts = spi_get_drvdata(spi);
1401 1401
1402 device_init_wakeup(&spi->dev, false); 1402 device_init_wakeup(&spi->dev, false);
1403 1403
diff --git a/drivers/input/touchscreen/atmel-wm97xx.c b/drivers/input/touchscreen/atmel-wm97xx.c
index c5c2dbb93869..2c1e46b7e45b 100644
--- a/drivers/input/touchscreen/atmel-wm97xx.c
+++ b/drivers/input/touchscreen/atmel-wm97xx.c
@@ -432,17 +432,7 @@ static struct platform_driver atmel_wm97xx_driver = {
432 }, 432 },
433}; 433};
434 434
435static int __init atmel_wm97xx_init(void) 435module_platform_driver_probe(atmel_wm97xx_driver, atmel_wm97xx_probe);
436{
437 return platform_driver_probe(&atmel_wm97xx_driver, atmel_wm97xx_probe);
438}
439module_init(atmel_wm97xx_init);
440
441static void __exit atmel_wm97xx_exit(void)
442{
443 platform_driver_unregister(&atmel_wm97xx_driver);
444}
445module_exit(atmel_wm97xx_exit);
446 436
447MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>"); 437MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
448MODULE_DESCRIPTION("wm97xx continuous touch driver for Atmel AT91 and AVR32"); 438MODULE_DESCRIPTION("wm97xx continuous touch driver for Atmel AT91 and AVR32");
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index d04f810cb1dd..59aa24002c7b 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -176,11 +176,17 @@
176/* Define for MXT_GEN_COMMAND_T6 */ 176/* Define for MXT_GEN_COMMAND_T6 */
177#define MXT_BOOT_VALUE 0xa5 177#define MXT_BOOT_VALUE 0xa5
178#define MXT_BACKUP_VALUE 0x55 178#define MXT_BACKUP_VALUE 0x55
179#define MXT_BACKUP_TIME 25 /* msec */ 179#define MXT_BACKUP_TIME 50 /* msec */
180#define MXT_RESET_TIME 65 /* msec */ 180#define MXT_RESET_TIME 200 /* msec */
181 181
182#define MXT_FWRESET_TIME 175 /* msec */ 182#define MXT_FWRESET_TIME 175 /* msec */
183 183
184/* MXT_SPT_GPIOPWM_T19 field */
185#define MXT_GPIO0_MASK 0x04
186#define MXT_GPIO1_MASK 0x08
187#define MXT_GPIO2_MASK 0x10
188#define MXT_GPIO3_MASK 0x20
189
184/* Command to unlock bootloader */ 190/* Command to unlock bootloader */
185#define MXT_UNLOCK_CMD_MSB 0xaa 191#define MXT_UNLOCK_CMD_MSB 0xaa
186#define MXT_UNLOCK_CMD_LSB 0xdc 192#define MXT_UNLOCK_CMD_LSB 0xdc
@@ -212,6 +218,8 @@
212/* Touchscreen absolute values */ 218/* Touchscreen absolute values */
213#define MXT_MAX_AREA 0xff 219#define MXT_MAX_AREA 0xff
214 220
221#define MXT_PIXELS_PER_MM 20
222
215struct mxt_info { 223struct mxt_info {
216 u8 family_id; 224 u8 family_id;
217 u8 variant_id; 225 u8 variant_id;
@@ -243,6 +251,8 @@ struct mxt_data {
243 const struct mxt_platform_data *pdata; 251 const struct mxt_platform_data *pdata;
244 struct mxt_object *object_table; 252 struct mxt_object *object_table;
245 struct mxt_info info; 253 struct mxt_info info;
254 bool is_tp;
255
246 unsigned int irq; 256 unsigned int irq;
247 unsigned int max_x; 257 unsigned int max_x;
248 unsigned int max_y; 258 unsigned int max_y;
@@ -251,6 +261,7 @@ struct mxt_data {
251 u8 T6_reportid; 261 u8 T6_reportid;
252 u8 T9_reportid_min; 262 u8 T9_reportid_min;
253 u8 T9_reportid_max; 263 u8 T9_reportid_max;
264 u8 T19_reportid;
254}; 265};
255 266
256static bool mxt_object_readable(unsigned int type) 267static bool mxt_object_readable(unsigned int type)
@@ -502,6 +513,21 @@ static int mxt_write_object(struct mxt_data *data,
502 return mxt_write_reg(data->client, reg + offset, val); 513 return mxt_write_reg(data->client, reg + offset, val);
503} 514}
504 515
516static void mxt_input_button(struct mxt_data *data, struct mxt_message *message)
517{
518 struct input_dev *input = data->input_dev;
519 bool button;
520 int i;
521
522 /* Active-low switch */
523 for (i = 0; i < MXT_NUM_GPIO; i++) {
524 if (data->pdata->key_map[i] == KEY_RESERVED)
525 continue;
526 button = !(message->message[0] & MXT_GPIO0_MASK << i);
527 input_report_key(input, data->pdata->key_map[i], button);
528 }
529}
530
505static void mxt_input_touchevent(struct mxt_data *data, 531static void mxt_input_touchevent(struct mxt_data *data,
506 struct mxt_message *message, int id) 532 struct mxt_message *message, int id)
507{ 533{
@@ -585,6 +611,9 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
585 int id = reportid - data->T9_reportid_min; 611 int id = reportid - data->T9_reportid_min;
586 mxt_input_touchevent(data, &message, id); 612 mxt_input_touchevent(data, &message, id);
587 update_input = true; 613 update_input = true;
614 } else if (message.reportid == data->T19_reportid) {
615 mxt_input_button(data, &message);
616 update_input = true;
588 } else { 617 } else {
589 mxt_dump_message(dev, &message); 618 mxt_dump_message(dev, &message);
590 } 619 }
@@ -764,6 +793,9 @@ static int mxt_get_object_table(struct mxt_data *data)
764 data->T9_reportid_min = min_id; 793 data->T9_reportid_min = min_id;
765 data->T9_reportid_max = max_id; 794 data->T9_reportid_max = max_id;
766 break; 795 break;
796 case MXT_SPT_GPIOPWM_T19:
797 data->T19_reportid = min_id;
798 break;
767 } 799 }
768 } 800 }
769 801
@@ -777,7 +809,7 @@ static void mxt_free_object_table(struct mxt_data *data)
777 data->T6_reportid = 0; 809 data->T6_reportid = 0;
778 data->T9_reportid_min = 0; 810 data->T9_reportid_min = 0;
779 data->T9_reportid_max = 0; 811 data->T9_reportid_max = 0;
780 812 data->T19_reportid = 0;
781} 813}
782 814
783static int mxt_initialize(struct mxt_data *data) 815static int mxt_initialize(struct mxt_data *data)
@@ -1115,9 +1147,13 @@ static int mxt_probe(struct i2c_client *client,
1115 goto err_free_mem; 1147 goto err_free_mem;
1116 } 1148 }
1117 1149
1118 input_dev->name = "Atmel maXTouch Touchscreen"; 1150 data->is_tp = pdata && pdata->is_tp;
1151
1152 input_dev->name = (data->is_tp) ? "Atmel maXTouch Touchpad" :
1153 "Atmel maXTouch Touchscreen";
1119 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", 1154 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1120 client->adapter->nr, client->addr); 1155 client->adapter->nr, client->addr);
1156
1121 input_dev->phys = data->phys; 1157 input_dev->phys = data->phys;
1122 1158
1123 input_dev->id.bustype = BUS_I2C; 1159 input_dev->id.bustype = BUS_I2C;
@@ -1140,6 +1176,29 @@ static int mxt_probe(struct i2c_client *client,
1140 __set_bit(EV_KEY, input_dev->evbit); 1176 __set_bit(EV_KEY, input_dev->evbit);
1141 __set_bit(BTN_TOUCH, input_dev->keybit); 1177 __set_bit(BTN_TOUCH, input_dev->keybit);
1142 1178
1179 if (data->is_tp) {
1180 int i;
1181 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1182 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
1183
1184 for (i = 0; i < MXT_NUM_GPIO; i++)
1185 if (pdata->key_map[i] != KEY_RESERVED)
1186 __set_bit(pdata->key_map[i], input_dev->keybit);
1187
1188 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
1189 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
1190 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
1191 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
1192 __set_bit(BTN_TOOL_QUINTTAP, input_dev->keybit);
1193
1194 input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM);
1195 input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM);
1196 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
1197 MXT_PIXELS_PER_MM);
1198 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
1199 MXT_PIXELS_PER_MM);
1200 }
1201
1143 /* For single touch */ 1202 /* For single touch */
1144 input_set_abs_params(input_dev, ABS_X, 1203 input_set_abs_params(input_dev, ABS_X,
1145 0, data->max_x, 0, 0); 1204 0, data->max_x, 0, 0);
@@ -1258,6 +1317,7 @@ static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1258static const struct i2c_device_id mxt_id[] = { 1317static const struct i2c_device_id mxt_id[] = {
1259 { "qt602240_ts", 0 }, 1318 { "qt602240_ts", 0 },
1260 { "atmel_mxt_ts", 0 }, 1319 { "atmel_mxt_ts", 0 },
1320 { "atmel_mxt_tp", 0 },
1261 { "mXT224", 0 }, 1321 { "mXT224", 0 },
1262 { } 1322 { }
1263}; 1323};
diff --git a/drivers/input/touchscreen/atmel_tsadcc.c b/drivers/input/touchscreen/atmel_tsadcc.c
index 55092d1c5cb9..95f6785a94b0 100644
--- a/drivers/input/touchscreen/atmel_tsadcc.c
+++ b/drivers/input/touchscreen/atmel_tsadcc.c
@@ -22,7 +22,7 @@
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <mach/board.h> 25#include <linux/platform_data/atmel.h>
26#include <mach/cpu.h> 26#include <mach/cpu.h>
27 27
28/* Register definitions based on AT91SAM9RL64 preliminary draft datasheet */ 28/* Register definitions based on AT91SAM9RL64 preliminary draft datasheet */
diff --git a/drivers/input/touchscreen/auo-pixcir-ts.c b/drivers/input/touchscreen/auo-pixcir-ts.c
index c6e19a96348e..d3f9f6b0f9b7 100644
--- a/drivers/input/touchscreen/auo-pixcir-ts.c
+++ b/drivers/input/touchscreen/auo-pixcir-ts.c
@@ -31,6 +31,8 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/gpio.h> 32#include <linux/gpio.h>
33#include <linux/input/auo-pixcir-ts.h> 33#include <linux/input/auo-pixcir-ts.h>
34#include <linux/of.h>
35#include <linux/of_gpio.h>
34 36
35/* 37/*
36 * Coordinate calculation: 38 * Coordinate calculation:
@@ -111,6 +113,7 @@
111struct auo_pixcir_ts { 113struct auo_pixcir_ts {
112 struct i2c_client *client; 114 struct i2c_client *client;
113 struct input_dev *input; 115 struct input_dev *input;
116 const struct auo_pixcir_ts_platdata *pdata;
114 char phys[32]; 117 char phys[32];
115 118
116 /* special handling for touch_indicate interupt mode */ 119 /* special handling for touch_indicate interupt mode */
@@ -132,7 +135,7 @@ static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,
132 struct auo_point_t *point) 135 struct auo_point_t *point)
133{ 136{
134 struct i2c_client *client = ts->client; 137 struct i2c_client *client = ts->client;
135 const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; 138 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
136 uint8_t raw_coord[8]; 139 uint8_t raw_coord[8];
137 uint8_t raw_area[4]; 140 uint8_t raw_area[4];
138 int i, ret; 141 int i, ret;
@@ -178,8 +181,7 @@ static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,
178static irqreturn_t auo_pixcir_interrupt(int irq, void *dev_id) 181static irqreturn_t auo_pixcir_interrupt(int irq, void *dev_id)
179{ 182{
180 struct auo_pixcir_ts *ts = dev_id; 183 struct auo_pixcir_ts *ts = dev_id;
181 struct i2c_client *client = ts->client; 184 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
182 const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data;
183 struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS]; 185 struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS];
184 int i; 186 int i;
185 int ret; 187 int ret;
@@ -290,7 +292,7 @@ static int auo_pixcir_int_config(struct auo_pixcir_ts *ts,
290 int int_setting) 292 int int_setting)
291{ 293{
292 struct i2c_client *client = ts->client; 294 struct i2c_client *client = ts->client;
293 struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; 295 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
294 int ret; 296 int ret;
295 297
296 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING); 298 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
@@ -479,53 +481,105 @@ unlock:
479} 481}
480#endif 482#endif
481 483
482static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops, auo_pixcir_suspend, 484static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
483 auo_pixcir_resume); 485 auo_pixcir_suspend, auo_pixcir_resume);
486
487#ifdef CONFIG_OF
488static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
489{
490 struct auo_pixcir_ts_platdata *pdata;
491 struct device_node *np = dev->of_node;
492
493 if (!np)
494 return ERR_PTR(-ENOENT);
495
496 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
497 if (!pdata) {
498 dev_err(dev, "failed to allocate platform data\n");
499 return ERR_PTR(-ENOMEM);
500 }
501
502 pdata->gpio_int = of_get_gpio(np, 0);
503 if (!gpio_is_valid(pdata->gpio_int)) {
504 dev_err(dev, "failed to get interrupt gpio\n");
505 return ERR_PTR(-EINVAL);
506 }
507
508 pdata->gpio_rst = of_get_gpio(np, 1);
509 if (!gpio_is_valid(pdata->gpio_rst)) {
510 dev_err(dev, "failed to get reset gpio\n");
511 return ERR_PTR(-EINVAL);
512 }
513
514 if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
515 dev_err(dev, "failed to get x-size property\n");
516 return ERR_PTR(-EINVAL);
517 }
518
519 if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
520 dev_err(dev, "failed to get y-size property\n");
521 return ERR_PTR(-EINVAL);
522 }
523
524 /* default to asserting the interrupt when the screen is touched */
525 pdata->int_setting = AUO_PIXCIR_INT_TOUCH_IND;
526
527 return pdata;
528}
529#else
530static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
531{
532 return ERR_PTR(-EINVAL);
533}
534#endif
535
536static void auo_pixcir_reset(void *data)
537{
538 struct auo_pixcir_ts *ts = data;
539
540 gpio_set_value(ts->pdata->gpio_rst, 0);
541}
484 542
485static int auo_pixcir_probe(struct i2c_client *client, 543static int auo_pixcir_probe(struct i2c_client *client,
486 const struct i2c_device_id *id) 544 const struct i2c_device_id *id)
487{ 545{
488 const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; 546 const struct auo_pixcir_ts_platdata *pdata;
489 struct auo_pixcir_ts *ts; 547 struct auo_pixcir_ts *ts;
490 struct input_dev *input_dev; 548 struct input_dev *input_dev;
491 int ret; 549 int version;
492 550 int error;
493 if (!pdata) 551
494 return -EINVAL; 552 pdata = dev_get_platdata(&client->dev);
553 if (!pdata) {
554 pdata = auo_pixcir_parse_dt(&client->dev);
555 if (IS_ERR(pdata))
556 return PTR_ERR(pdata);
557 }
495 558
496 ts = kzalloc(sizeof(struct auo_pixcir_ts), GFP_KERNEL); 559 ts = devm_kzalloc(&client->dev,
560 sizeof(struct auo_pixcir_ts), GFP_KERNEL);
497 if (!ts) 561 if (!ts)
498 return -ENOMEM; 562 return -ENOMEM;
499 563
500 ret = gpio_request(pdata->gpio_int, "auo_pixcir_ts_int"); 564 input_dev = devm_input_allocate_device(&client->dev);
501 if (ret) { 565 if (!input_dev) {
502 dev_err(&client->dev, "request of gpio %d failed, %d\n", 566 dev_err(&client->dev, "could not allocate input device\n");
503 pdata->gpio_int, ret); 567 return -ENOMEM;
504 goto err_gpio_int;
505 } 568 }
506 569
507 if (pdata->init_hw) 570 ts->pdata = pdata;
508 pdata->init_hw(client);
509
510 ts->client = client; 571 ts->client = client;
572 ts->input = input_dev;
511 ts->touch_ind_mode = 0; 573 ts->touch_ind_mode = 0;
574 ts->stopped = true;
512 init_waitqueue_head(&ts->wait); 575 init_waitqueue_head(&ts->wait);
513 576
514 snprintf(ts->phys, sizeof(ts->phys), 577 snprintf(ts->phys, sizeof(ts->phys),
515 "%s/input0", dev_name(&client->dev)); 578 "%s/input0", dev_name(&client->dev));
516 579
517 input_dev = input_allocate_device();
518 if (!input_dev) {
519 dev_err(&client->dev, "could not allocate input device\n");
520 goto err_input_alloc;
521 }
522
523 ts->input = input_dev;
524
525 input_dev->name = "AUO-Pixcir touchscreen"; 580 input_dev->name = "AUO-Pixcir touchscreen";
526 input_dev->phys = ts->phys; 581 input_dev->phys = ts->phys;
527 input_dev->id.bustype = BUS_I2C; 582 input_dev->id.bustype = BUS_I2C;
528 input_dev->dev.parent = &client->dev;
529 583
530 input_dev->open = auo_pixcir_input_open; 584 input_dev->open = auo_pixcir_input_open;
531 input_dev->close = auo_pixcir_input_close; 585 input_dev->close = auo_pixcir_input_close;
@@ -550,70 +604,70 @@ static int auo_pixcir_probe(struct i2c_client *client,
550 AUO_PIXCIR_MAX_AREA, 0, 0); 604 AUO_PIXCIR_MAX_AREA, 0, 0);
551 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0); 605 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
552 606
553 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
554 if (ret < 0)
555 goto err_fw_vers;
556 dev_info(&client->dev, "firmware version 0x%X\n", ret);
557
558 ret = auo_pixcir_int_config(ts, pdata->int_setting);
559 if (ret)
560 goto err_fw_vers;
561
562 input_set_drvdata(ts->input, ts); 607 input_set_drvdata(ts->input, ts);
563 ts->stopped = true;
564 608
565 ret = request_threaded_irq(client->irq, NULL, auo_pixcir_interrupt, 609 error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
566 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 610 GPIOF_DIR_IN, "auo_pixcir_ts_int");
567 input_dev->name, ts); 611 if (error) {
568 if (ret) { 612 dev_err(&client->dev, "request of gpio %d failed, %d\n",
569 dev_err(&client->dev, "irq %d requested failed\n", client->irq); 613 pdata->gpio_int, error);
570 goto err_fw_vers; 614 return error;
571 } 615 }
572 616
573 /* stop device and put it into deep sleep until it is opened */ 617 error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
574 ret = auo_pixcir_stop(ts); 618 GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
575 if (ret < 0) 619 "auo_pixcir_ts_rst");
576 goto err_input_register; 620 if (error) {
577 621 dev_err(&client->dev, "request of gpio %d failed, %d\n",
578 ret = input_register_device(input_dev); 622 pdata->gpio_rst, error);
579 if (ret) { 623 return error;
580 dev_err(&client->dev, "could not register input device\n");
581 goto err_input_register;
582 } 624 }
583 625
584 i2c_set_clientdata(client, ts); 626 error = devm_add_action(&client->dev, auo_pixcir_reset, ts);
585 627 if (error) {
586 return 0; 628 auo_pixcir_reset(ts);
629 dev_err(&client->dev, "failed to register reset action, %d\n",
630 error);
631 return error;
632 }
587 633
588err_input_register: 634 msleep(200);
589 free_irq(client->irq, ts);
590err_fw_vers:
591 input_free_device(input_dev);
592err_input_alloc:
593 if (pdata->exit_hw)
594 pdata->exit_hw(client);
595 gpio_free(pdata->gpio_int);
596err_gpio_int:
597 kfree(ts);
598 635
599 return ret; 636 version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
600} 637 if (version < 0) {
601 638 error = version;
602static int auo_pixcir_remove(struct i2c_client *client) 639 return error;
603{ 640 }
604 struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
605 const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data;
606 641
607 free_irq(client->irq, ts); 642 dev_info(&client->dev, "firmware version 0x%X\n", version);
608 643
609 input_unregister_device(ts->input); 644 error = auo_pixcir_int_config(ts, pdata->int_setting);
645 if (error)
646 return error;
610 647
611 if (pdata->exit_hw) 648 error = devm_request_threaded_irq(&client->dev, client->irq,
612 pdata->exit_hw(client); 649 NULL, auo_pixcir_interrupt,
650 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
651 input_dev->name, ts);
652 if (error) {
653 dev_err(&client->dev, "irq %d requested failed, %d\n",
654 client->irq, error);
655 return error;
656 }
613 657
614 gpio_free(pdata->gpio_int); 658 /* stop device and put it into deep sleep until it is opened */
659 error = auo_pixcir_stop(ts);
660 if (error)
661 return error;
662
663 error = input_register_device(input_dev);
664 if (error) {
665 dev_err(&client->dev, "could not register input device, %d\n",
666 error);
667 return error;
668 }
615 669
616 kfree(ts); 670 i2c_set_clientdata(client, ts);
617 671
618 return 0; 672 return 0;
619} 673}
@@ -624,14 +678,22 @@ static const struct i2c_device_id auo_pixcir_idtable[] = {
624}; 678};
625MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable); 679MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable);
626 680
681#ifdef CONFIG_OF
682static struct of_device_id auo_pixcir_ts_dt_idtable[] = {
683 { .compatible = "auo,auo_pixcir_ts" },
684 {},
685};
686MODULE_DEVICE_TABLE(of, auo_pixcir_ts_dt_idtable);
687#endif
688
627static struct i2c_driver auo_pixcir_driver = { 689static struct i2c_driver auo_pixcir_driver = {
628 .driver = { 690 .driver = {
629 .owner = THIS_MODULE, 691 .owner = THIS_MODULE,
630 .name = "auo_pixcir_ts", 692 .name = "auo_pixcir_ts",
631 .pm = &auo_pixcir_pm_ops, 693 .pm = &auo_pixcir_pm_ops,
694 .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
632 }, 695 },
633 .probe = auo_pixcir_probe, 696 .probe = auo_pixcir_probe,
634 .remove = auo_pixcir_remove,
635 .id_table = auo_pixcir_idtable, 697 .id_table = auo_pixcir_idtable,
636}; 698};
637 699
diff --git a/drivers/input/touchscreen/da9052_tsi.c b/drivers/input/touchscreen/da9052_tsi.c
index 303966ffe1e8..8f561e22bdd4 100644
--- a/drivers/input/touchscreen/da9052_tsi.c
+++ b/drivers/input/touchscreen/da9052_tsi.c
@@ -27,8 +27,6 @@ struct da9052_tsi {
27 struct input_dev *dev; 27 struct input_dev *dev;
28 struct delayed_work ts_pen_work; 28 struct delayed_work ts_pen_work;
29 struct mutex mutex; 29 struct mutex mutex;
30 unsigned int irq_pendwn;
31 unsigned int irq_datardy;
32 bool stopped; 30 bool stopped;
33 bool adc_on; 31 bool adc_on;
34}; 32};
@@ -45,8 +43,8 @@ static irqreturn_t da9052_ts_pendwn_irq(int irq, void *data)
45 43
46 if (!tsi->stopped) { 44 if (!tsi->stopped) {
47 /* Mask PEN_DOWN event and unmask TSI_READY event */ 45 /* Mask PEN_DOWN event and unmask TSI_READY event */
48 disable_irq_nosync(tsi->irq_pendwn); 46 da9052_disable_irq_nosync(tsi->da9052, DA9052_IRQ_PENDOWN);
49 enable_irq(tsi->irq_datardy); 47 da9052_enable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
50 48
51 da9052_ts_adc_toggle(tsi, true); 49 da9052_ts_adc_toggle(tsi, true);
52 50
@@ -137,8 +135,8 @@ static void da9052_ts_pen_work(struct work_struct *work)
137 return; 135 return;
138 136
139 /* Mask TSI_READY event and unmask PEN_DOWN event */ 137 /* Mask TSI_READY event and unmask PEN_DOWN event */
140 disable_irq(tsi->irq_datardy); 138 da9052_disable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
141 enable_irq(tsi->irq_pendwn); 139 da9052_enable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
142 } 140 }
143 } 141 }
144} 142}
@@ -197,7 +195,7 @@ static int da9052_ts_input_open(struct input_dev *input_dev)
197 mb(); 195 mb();
198 196
199 /* Unmask PEN_DOWN event */ 197 /* Unmask PEN_DOWN event */
200 enable_irq(tsi->irq_pendwn); 198 da9052_enable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
201 199
202 /* Enable Pen Detect Circuit */ 200 /* Enable Pen Detect Circuit */
203 return da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG, 201 return da9052_reg_update(tsi->da9052, DA9052_TSI_CONT_A_REG,
@@ -210,11 +208,11 @@ static void da9052_ts_input_close(struct input_dev *input_dev)
210 208
211 tsi->stopped = true; 209 tsi->stopped = true;
212 mb(); 210 mb();
213 disable_irq(tsi->irq_pendwn); 211 da9052_disable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
214 cancel_delayed_work_sync(&tsi->ts_pen_work); 212 cancel_delayed_work_sync(&tsi->ts_pen_work);
215 213
216 if (tsi->adc_on) { 214 if (tsi->adc_on) {
217 disable_irq(tsi->irq_datardy); 215 da9052_disable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
218 da9052_ts_adc_toggle(tsi, false); 216 da9052_ts_adc_toggle(tsi, false);
219 217
220 /* 218 /*
@@ -222,7 +220,7 @@ static void da9052_ts_input_close(struct input_dev *input_dev)
222 * twice and we need to enable it to keep enable/disable 220 * twice and we need to enable it to keep enable/disable
223 * counter balanced. IRQ is still off though. 221 * counter balanced. IRQ is still off though.
224 */ 222 */
225 enable_irq(tsi->irq_pendwn); 223 da9052_enable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
226 } 224 }
227 225
228 /* Disable Pen Detect Circuit */ 226 /* Disable Pen Detect Circuit */
@@ -234,21 +232,12 @@ static int da9052_ts_probe(struct platform_device *pdev)
234 struct da9052 *da9052; 232 struct da9052 *da9052;
235 struct da9052_tsi *tsi; 233 struct da9052_tsi *tsi;
236 struct input_dev *input_dev; 234 struct input_dev *input_dev;
237 int irq_pendwn;
238 int irq_datardy;
239 int error; 235 int error;
240 236
241 da9052 = dev_get_drvdata(pdev->dev.parent); 237 da9052 = dev_get_drvdata(pdev->dev.parent);
242 if (!da9052) 238 if (!da9052)
243 return -EINVAL; 239 return -EINVAL;
244 240
245 irq_pendwn = platform_get_irq_byname(pdev, "PENDWN");
246 irq_datardy = platform_get_irq_byname(pdev, "TSIRDY");
247 if (irq_pendwn < 0 || irq_datardy < 0) {
248 dev_err(da9052->dev, "Unable to determine device interrupts\n");
249 return -ENXIO;
250 }
251
252 tsi = kzalloc(sizeof(struct da9052_tsi), GFP_KERNEL); 241 tsi = kzalloc(sizeof(struct da9052_tsi), GFP_KERNEL);
253 input_dev = input_allocate_device(); 242 input_dev = input_allocate_device();
254 if (!tsi || !input_dev) { 243 if (!tsi || !input_dev) {
@@ -258,8 +247,6 @@ static int da9052_ts_probe(struct platform_device *pdev)
258 247
259 tsi->da9052 = da9052; 248 tsi->da9052 = da9052;
260 tsi->dev = input_dev; 249 tsi->dev = input_dev;
261 tsi->irq_pendwn = da9052->irq_base + irq_pendwn;
262 tsi->irq_datardy = da9052->irq_base + irq_datardy;
263 tsi->stopped = true; 250 tsi->stopped = true;
264 INIT_DELAYED_WORK(&tsi->ts_pen_work, da9052_ts_pen_work); 251 INIT_DELAYED_WORK(&tsi->ts_pen_work, da9052_ts_pen_work);
265 252
@@ -287,31 +274,25 @@ static int da9052_ts_probe(struct platform_device *pdev)
287 /* Disable ADC */ 274 /* Disable ADC */
288 da9052_ts_adc_toggle(tsi, false); 275 da9052_ts_adc_toggle(tsi, false);
289 276
290 error = request_threaded_irq(tsi->irq_pendwn, 277 error = da9052_request_irq(tsi->da9052, DA9052_IRQ_PENDOWN,
291 NULL, da9052_ts_pendwn_irq, 278 "pendown-irq", da9052_ts_pendwn_irq, tsi);
292 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
293 "PENDWN", tsi);
294 if (error) { 279 if (error) {
295 dev_err(tsi->da9052->dev, 280 dev_err(tsi->da9052->dev,
296 "Failed to register PENDWN IRQ %d, error = %d\n", 281 "Failed to register PENDWN IRQ: %d\n", error);
297 tsi->irq_pendwn, error);
298 goto err_free_mem; 282 goto err_free_mem;
299 } 283 }
300 284
301 error = request_threaded_irq(tsi->irq_datardy, 285 error = da9052_request_irq(tsi->da9052, DA9052_IRQ_TSIREADY,
302 NULL, da9052_ts_datardy_irq, 286 "tsiready-irq", da9052_ts_datardy_irq, tsi);
303 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
304 "TSIRDY", tsi);
305 if (error) { 287 if (error) {
306 dev_err(tsi->da9052->dev, 288 dev_err(tsi->da9052->dev,
307 "Failed to register TSIRDY IRQ %d, error = %d\n", 289 "Failed to register TSIRDY IRQ :%d\n", error);
308 tsi->irq_datardy, error);
309 goto err_free_pendwn_irq; 290 goto err_free_pendwn_irq;
310 } 291 }
311 292
312 /* Mask PEN_DOWN and TSI_READY events */ 293 /* Mask PEN_DOWN and TSI_READY events */
313 disable_irq(tsi->irq_pendwn); 294 da9052_disable_irq(tsi->da9052, DA9052_IRQ_PENDOWN);
314 disable_irq(tsi->irq_datardy); 295 da9052_disable_irq(tsi->da9052, DA9052_IRQ_TSIREADY);
315 296
316 error = da9052_configure_tsi(tsi); 297 error = da9052_configure_tsi(tsi);
317 if (error) 298 if (error)
@@ -326,9 +307,9 @@ static int da9052_ts_probe(struct platform_device *pdev)
326 return 0; 307 return 0;
327 308
328err_free_datardy_irq: 309err_free_datardy_irq:
329 free_irq(tsi->irq_datardy, tsi); 310 da9052_free_irq(tsi->da9052, DA9052_IRQ_TSIREADY, tsi);
330err_free_pendwn_irq: 311err_free_pendwn_irq:
331 free_irq(tsi->irq_pendwn, tsi); 312 da9052_free_irq(tsi->da9052, DA9052_IRQ_PENDOWN, tsi);
332err_free_mem: 313err_free_mem:
333 kfree(tsi); 314 kfree(tsi);
334 input_free_device(input_dev); 315 input_free_device(input_dev);
@@ -342,8 +323,8 @@ static int da9052_ts_remove(struct platform_device *pdev)
342 323
343 da9052_reg_write(tsi->da9052, DA9052_LDO9_REG, 0x19); 324 da9052_reg_write(tsi->da9052, DA9052_LDO9_REG, 0x19);
344 325
345 free_irq(tsi->irq_pendwn, tsi); 326 da9052_free_irq(tsi->da9052, DA9052_IRQ_TSIREADY, tsi);
346 free_irq(tsi->irq_datardy, tsi); 327 da9052_free_irq(tsi->da9052, DA9052_IRQ_PENDOWN, tsi);
347 328
348 input_unregister_device(tsi->dev); 329 input_unregister_device(tsi->dev);
349 kfree(tsi); 330 kfree(tsi);
diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index a9170157b442..83fa1b15a97f 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -440,8 +440,7 @@ static int edt_ft5x06_work_mode(struct edt_ft5x06_ts_data *tsdata)
440 return -EIO; 440 return -EIO;
441 } 441 }
442 442
443 if (tsdata->raw_buffer) 443 kfree(tsdata->raw_buffer);
444 kfree(tsdata->raw_buffer);
445 tsdata->raw_buffer = NULL; 444 tsdata->raw_buffer = NULL;
446 445
447 /* restore parameters */ 446 /* restore parameters */
diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c
index 55255a940072..8fe5086c8d2e 100644
--- a/drivers/input/touchscreen/eeti_ts.c
+++ b/drivers/input/touchscreen/eeti_ts.c
@@ -206,8 +206,7 @@ static int eeti_ts_probe(struct i2c_client *client,
206 if (err < 0) 206 if (err < 0)
207 goto err1; 207 goto err1;
208 208
209 if (pdata) 209 priv->irq_active_high = pdata->irq_active_high;
210 priv->irq_active_high = pdata->irq_active_high;
211 210
212 irq_flags = priv->irq_active_high ? 211 irq_flags = priv->irq_active_high ?
213 IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; 212 IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
diff --git a/drivers/input/touchscreen/mc13783_ts.c b/drivers/input/touchscreen/mc13783_ts.c
index 02103b6abb39..89308fe38752 100644
--- a/drivers/input/touchscreen/mc13783_ts.c
+++ b/drivers/input/touchscreen/mc13783_ts.c
@@ -250,17 +250,7 @@ static struct platform_driver mc13783_ts_driver = {
250 }, 250 },
251}; 251};
252 252
253static int __init mc13783_ts_init(void) 253module_platform_driver_probe(mc13783_ts_driver, mc13783_ts_probe);
254{
255 return platform_driver_probe(&mc13783_ts_driver, &mc13783_ts_probe);
256}
257module_init(mc13783_ts_init);
258
259static void __exit mc13783_ts_exit(void)
260{
261 platform_driver_unregister(&mc13783_ts_driver);
262}
263module_exit(mc13783_ts_exit);
264 254
265MODULE_DESCRIPTION("MC13783 input touchscreen driver"); 255MODULE_DESCRIPTION("MC13783 input touchscreen driver");
266MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 256MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index d9d05e222428..1740a2496371 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -19,13 +19,16 @@
19 */ 19 */
20 20
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/gpio.h>
22#include <linux/i2c.h> 23#include <linux/i2c.h>
23#include <linux/input.h> 24#include <linux/input.h>
24#include <linux/interrupt.h> 25#include <linux/interrupt.h>
25#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/of_gpio.h>
26#include <linux/pm_qos.h> 28#include <linux/pm_qos.h>
27#include <linux/slab.h> 29#include <linux/slab.h>
28#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/platform_data/st1232_pdata.h>
29 32
30#define ST1232_TS_NAME "st1232-ts" 33#define ST1232_TS_NAME "st1232-ts"
31 34
@@ -48,6 +51,7 @@ struct st1232_ts_data {
48 struct input_dev *input_dev; 51 struct input_dev *input_dev;
49 struct st1232_ts_finger finger[MAX_FINGERS]; 52 struct st1232_ts_finger finger[MAX_FINGERS];
50 struct dev_pm_qos_request low_latency_req; 53 struct dev_pm_qos_request low_latency_req;
54 int reset_gpio;
51}; 55};
52 56
53static int st1232_ts_read_data(struct st1232_ts_data *ts) 57static int st1232_ts_read_data(struct st1232_ts_data *ts)
@@ -139,10 +143,17 @@ end:
139 return IRQ_HANDLED; 143 return IRQ_HANDLED;
140} 144}
141 145
146static void st1232_ts_power(struct st1232_ts_data *ts, bool poweron)
147{
148 if (gpio_is_valid(ts->reset_gpio))
149 gpio_direction_output(ts->reset_gpio, poweron);
150}
151
142static int st1232_ts_probe(struct i2c_client *client, 152static int st1232_ts_probe(struct i2c_client *client,
143 const struct i2c_device_id *id) 153 const struct i2c_device_id *id)
144{ 154{
145 struct st1232_ts_data *ts; 155 struct st1232_ts_data *ts;
156 struct st1232_pdata *pdata = client->dev.platform_data;
146 struct input_dev *input_dev; 157 struct input_dev *input_dev;
147 int error; 158 int error;
148 159
@@ -156,17 +167,36 @@ static int st1232_ts_probe(struct i2c_client *client,
156 return -EINVAL; 167 return -EINVAL;
157 } 168 }
158 169
170 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
171 if (!ts)
172 return -ENOMEM;
159 173
160 ts = kzalloc(sizeof(struct st1232_ts_data), GFP_KERNEL); 174 input_dev = devm_input_allocate_device(&client->dev);
161 input_dev = input_allocate_device(); 175 if (!input_dev)
162 if (!ts || !input_dev) { 176 return -ENOMEM;
163 error = -ENOMEM;
164 goto err_free_mem;
165 }
166 177
167 ts->client = client; 178 ts->client = client;
168 ts->input_dev = input_dev; 179 ts->input_dev = input_dev;
169 180
181 if (pdata)
182 ts->reset_gpio = pdata->reset_gpio;
183 else if (client->dev.of_node)
184 ts->reset_gpio = of_get_gpio(client->dev.of_node, 0);
185 else
186 ts->reset_gpio = -ENODEV;
187
188 if (gpio_is_valid(ts->reset_gpio)) {
189 error = devm_gpio_request(&client->dev, ts->reset_gpio, NULL);
190 if (error) {
191 dev_err(&client->dev,
192 "Unable to request GPIO pin %d.\n",
193 ts->reset_gpio);
194 return error;
195 }
196 }
197
198 st1232_ts_power(ts, true);
199
170 input_dev->name = "st1232-touchscreen"; 200 input_dev->name = "st1232-touchscreen";
171 input_dev->id.bustype = BUS_I2C; 201 input_dev->id.bustype = BUS_I2C;
172 input_dev->dev.parent = &client->dev; 202 input_dev->dev.parent = &client->dev;
@@ -179,31 +209,26 @@ static int st1232_ts_probe(struct i2c_client *client,
179 input_set_abs_params(input_dev, ABS_MT_POSITION_X, MIN_X, MAX_X, 0, 0); 209 input_set_abs_params(input_dev, ABS_MT_POSITION_X, MIN_X, MAX_X, 0, 0);
180 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, MIN_Y, MAX_Y, 0, 0); 210 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, MIN_Y, MAX_Y, 0, 0);
181 211
182 error = request_threaded_irq(client->irq, NULL, st1232_ts_irq_handler, 212 error = devm_request_threaded_irq(&client->dev, client->irq,
183 IRQF_ONESHOT, client->name, ts); 213 NULL, st1232_ts_irq_handler,
214 IRQF_ONESHOT,
215 client->name, ts);
184 if (error) { 216 if (error) {
185 dev_err(&client->dev, "Failed to register interrupt\n"); 217 dev_err(&client->dev, "Failed to register interrupt\n");
186 goto err_free_mem; 218 return error;
187 } 219 }
188 220
189 error = input_register_device(ts->input_dev); 221 error = input_register_device(ts->input_dev);
190 if (error) { 222 if (error) {
191 dev_err(&client->dev, "Unable to register %s input device\n", 223 dev_err(&client->dev, "Unable to register %s input device\n",
192 input_dev->name); 224 input_dev->name);
193 goto err_free_irq; 225 return error;
194 } 226 }
195 227
196 i2c_set_clientdata(client, ts); 228 i2c_set_clientdata(client, ts);
197 device_init_wakeup(&client->dev, 1); 229 device_init_wakeup(&client->dev, 1);
198 230
199 return 0; 231 return 0;
200
201err_free_irq:
202 free_irq(client->irq, ts);
203err_free_mem:
204 input_free_device(input_dev);
205 kfree(ts);
206 return error;
207} 232}
208 233
209static int st1232_ts_remove(struct i2c_client *client) 234static int st1232_ts_remove(struct i2c_client *client)
@@ -211,9 +236,7 @@ static int st1232_ts_remove(struct i2c_client *client)
211 struct st1232_ts_data *ts = i2c_get_clientdata(client); 236 struct st1232_ts_data *ts = i2c_get_clientdata(client);
212 237
213 device_init_wakeup(&client->dev, 0); 238 device_init_wakeup(&client->dev, 0);
214 free_irq(client->irq, ts); 239 st1232_ts_power(ts, false);
215 input_unregister_device(ts->input_dev);
216 kfree(ts);
217 240
218 return 0; 241 return 0;
219} 242}
@@ -222,11 +245,14 @@ static int st1232_ts_remove(struct i2c_client *client)
222static int st1232_ts_suspend(struct device *dev) 245static int st1232_ts_suspend(struct device *dev)
223{ 246{
224 struct i2c_client *client = to_i2c_client(dev); 247 struct i2c_client *client = to_i2c_client(dev);
248 struct st1232_ts_data *ts = i2c_get_clientdata(client);
225 249
226 if (device_may_wakeup(&client->dev)) 250 if (device_may_wakeup(&client->dev)) {
227 enable_irq_wake(client->irq); 251 enable_irq_wake(client->irq);
228 else 252 } else {
229 disable_irq(client->irq); 253 disable_irq(client->irq);
254 st1232_ts_power(ts, false);
255 }
230 256
231 return 0; 257 return 0;
232} 258}
@@ -234,11 +260,14 @@ static int st1232_ts_suspend(struct device *dev)
234static int st1232_ts_resume(struct device *dev) 260static int st1232_ts_resume(struct device *dev)
235{ 261{
236 struct i2c_client *client = to_i2c_client(dev); 262 struct i2c_client *client = to_i2c_client(dev);
263 struct st1232_ts_data *ts = i2c_get_clientdata(client);
237 264
238 if (device_may_wakeup(&client->dev)) 265 if (device_may_wakeup(&client->dev)) {
239 disable_irq_wake(client->irq); 266 disable_irq_wake(client->irq);
240 else 267 } else {
268 st1232_ts_power(ts, true);
241 enable_irq(client->irq); 269 enable_irq(client->irq);
270 }
242 271
243 return 0; 272 return 0;
244} 273}
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
new file mode 100644
index 000000000000..51e7b87827a4
--- /dev/null
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -0,0 +1,398 @@
1/*
2 * TI Touch Screen driver
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/err.h>
20#include <linux/module.h>
21#include <linux/input.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/clk.h>
25#include <linux/platform_device.h>
26#include <linux/io.h>
27#include <linux/input/ti_am335x_tsc.h>
28#include <linux/delay.h>
29
30#include <linux/mfd/ti_am335x_tscadc.h>
31
32#define ADCFSM_STEPID 0x10
33#define SEQ_SETTLE 275
34#define MAX_12BIT ((1 << 12) - 1)
35
36struct titsc {
37 struct input_dev *input;
38 struct ti_tscadc_dev *mfd_tscadc;
39 unsigned int irq;
40 unsigned int wires;
41 unsigned int x_plate_resistance;
42 bool pen_down;
43 int steps_to_configure;
44};
45
46static unsigned int titsc_readl(struct titsc *ts, unsigned int reg)
47{
48 return readl(ts->mfd_tscadc->tscadc_base + reg);
49}
50
51static void titsc_writel(struct titsc *tsc, unsigned int reg,
52 unsigned int val)
53{
54 writel(val, tsc->mfd_tscadc->tscadc_base + reg);
55}
56
57static void titsc_step_config(struct titsc *ts_dev)
58{
59 unsigned int config;
60 int i, total_steps;
61
62 /* Configure the Step registers */
63 total_steps = 2 * ts_dev->steps_to_configure;
64
65 config = STEPCONFIG_MODE_HWSYNC |
66 STEPCONFIG_AVG_16 | STEPCONFIG_XPP;
67 switch (ts_dev->wires) {
68 case 4:
69 config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN;
70 break;
71 case 5:
72 config |= STEPCONFIG_YNN |
73 STEPCONFIG_INP_AN4 | STEPCONFIG_XNN |
74 STEPCONFIG_YPP;
75 break;
76 case 8:
77 config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN;
78 break;
79 }
80
81 for (i = 1; i <= ts_dev->steps_to_configure; i++) {
82 titsc_writel(ts_dev, REG_STEPCONFIG(i), config);
83 titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY);
84 }
85
86 config = 0;
87 config = STEPCONFIG_MODE_HWSYNC |
88 STEPCONFIG_AVG_16 | STEPCONFIG_YNN |
89 STEPCONFIG_INM_ADCREFM | STEPCONFIG_FIFO1;
90 switch (ts_dev->wires) {
91 case 4:
92 config |= STEPCONFIG_YPP;
93 break;
94 case 5:
95 config |= STEPCONFIG_XPP | STEPCONFIG_INP_AN4 |
96 STEPCONFIG_XNP | STEPCONFIG_YPN;
97 break;
98 case 8:
99 config |= STEPCONFIG_YPP;
100 break;
101 }
102
103 for (i = (ts_dev->steps_to_configure + 1); i <= total_steps; i++) {
104 titsc_writel(ts_dev, REG_STEPCONFIG(i), config);
105 titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY);
106 }
107
108 config = 0;
109 /* Charge step configuration */
110 config = STEPCONFIG_XPP | STEPCONFIG_YNN |
111 STEPCHARGE_RFP_XPUL | STEPCHARGE_RFM_XNUR |
112 STEPCHARGE_INM_AN1 | STEPCHARGE_INP_AN1;
113
114 titsc_writel(ts_dev, REG_CHARGECONFIG, config);
115 titsc_writel(ts_dev, REG_CHARGEDELAY, CHARGEDLY_OPENDLY);
116
117 config = 0;
118 /* Configure to calculate pressure */
119 config = STEPCONFIG_MODE_HWSYNC |
120 STEPCONFIG_AVG_16 | STEPCONFIG_YPP |
121 STEPCONFIG_XNN | STEPCONFIG_INM_ADCREFM;
122 titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 1), config);
123 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 1),
124 STEPCONFIG_OPENDLY);
125
126 config |= STEPCONFIG_INP_AN3 | STEPCONFIG_FIFO1;
127 titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 2), config);
128 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2),
129 STEPCONFIG_OPENDLY);
130
131 titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC);
132}
133
134static void titsc_read_coordinates(struct titsc *ts_dev,
135 unsigned int *x, unsigned int *y)
136{
137 unsigned int fifocount = titsc_readl(ts_dev, REG_FIFO0CNT);
138 unsigned int prev_val_x = ~0, prev_val_y = ~0;
139 unsigned int prev_diff_x = ~0, prev_diff_y = ~0;
140 unsigned int read, diff;
141 unsigned int i, channel;
142
143 /*
144 * Delta filter is used to remove large variations in sampled
145 * values from ADC. The filter tries to predict where the next
146 * coordinate could be. This is done by taking a previous
147 * coordinate and subtracting it form current one. Further the
148 * algorithm compares the difference with that of a present value,
149 * if true the value is reported to the sub system.
150 */
151 for (i = 0; i < fifocount - 1; i++) {
152 read = titsc_readl(ts_dev, REG_FIFO0);
153 channel = read & 0xf0000;
154 channel = channel >> 0x10;
155 if ((channel >= 0) && (channel < ts_dev->steps_to_configure)) {
156 read &= 0xfff;
157 diff = abs(read - prev_val_x);
158 if (diff < prev_diff_x) {
159 prev_diff_x = diff;
160 *x = read;
161 }
162 prev_val_x = read;
163 }
164
165 read = titsc_readl(ts_dev, REG_FIFO1);
166 channel = read & 0xf0000;
167 channel = channel >> 0x10;
168 if ((channel >= ts_dev->steps_to_configure) &&
169 (channel < (2 * ts_dev->steps_to_configure - 1))) {
170 read &= 0xfff;
171 diff = abs(read - prev_val_y);
172 if (diff < prev_diff_y) {
173 prev_diff_y = diff;
174 *y = read;
175 }
176 prev_val_y = read;
177 }
178 }
179}
180
181static irqreturn_t titsc_irq(int irq, void *dev)
182{
183 struct titsc *ts_dev = dev;
184 struct input_dev *input_dev = ts_dev->input;
185 unsigned int status, irqclr = 0;
186 unsigned int x = 0, y = 0;
187 unsigned int z1, z2, z;
188 unsigned int fsm;
189 unsigned int fifo1count, fifo0count;
190 int i;
191
192 status = titsc_readl(ts_dev, REG_IRQSTATUS);
193 if (status & IRQENB_FIFO0THRES) {
194 titsc_read_coordinates(ts_dev, &x, &y);
195
196 z1 = titsc_readl(ts_dev, REG_FIFO0) & 0xfff;
197 z2 = titsc_readl(ts_dev, REG_FIFO1) & 0xfff;
198
199 fifo1count = titsc_readl(ts_dev, REG_FIFO1CNT);
200 for (i = 0; i < fifo1count; i++)
201 titsc_readl(ts_dev, REG_FIFO1);
202
203 fifo0count = titsc_readl(ts_dev, REG_FIFO0CNT);
204 for (i = 0; i < fifo0count; i++)
205 titsc_readl(ts_dev, REG_FIFO0);
206
207 if (ts_dev->pen_down && z1 != 0 && z2 != 0) {
208 /*
209 * Calculate pressure using formula
210 * Resistance(touch) = x plate resistance *
211 * x postion/4096 * ((z2 / z1) - 1)
212 */
213 z = z2 - z1;
214 z *= x;
215 z *= ts_dev->x_plate_resistance;
216 z /= z1;
217 z = (z + 2047) >> 12;
218
219 if (z <= MAX_12BIT) {
220 input_report_abs(input_dev, ABS_X, x);
221 input_report_abs(input_dev, ABS_Y, y);
222 input_report_abs(input_dev, ABS_PRESSURE, z);
223 input_report_key(input_dev, BTN_TOUCH, 1);
224 input_sync(input_dev);
225 }
226 }
227 irqclr |= IRQENB_FIFO0THRES;
228 }
229
230 /*
231 * Time for sequencer to settle, to read
232 * correct state of the sequencer.
233 */
234 udelay(SEQ_SETTLE);
235
236 status = titsc_readl(ts_dev, REG_RAWIRQSTATUS);
237 if (status & IRQENB_PENUP) {
238 /* Pen up event */
239 fsm = titsc_readl(ts_dev, REG_ADCFSM);
240 if (fsm == ADCFSM_STEPID) {
241 ts_dev->pen_down = false;
242 input_report_key(input_dev, BTN_TOUCH, 0);
243 input_report_abs(input_dev, ABS_PRESSURE, 0);
244 input_sync(input_dev);
245 } else {
246 ts_dev->pen_down = true;
247 }
248 irqclr |= IRQENB_PENUP;
249 }
250
251 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr);
252
253 titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC);
254 return IRQ_HANDLED;
255}
256
257/*
258 * The functions for inserting/removing driver as a module.
259 */
260
261static int titsc_probe(struct platform_device *pdev)
262{
263 struct titsc *ts_dev;
264 struct input_dev *input_dev;
265 struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data;
266 struct mfd_tscadc_board *pdata;
267 int err;
268
269 pdata = tscadc_dev->dev->platform_data;
270
271 if (!pdata) {
272 dev_err(&pdev->dev, "Could not find platform data\n");
273 return -EINVAL;
274 }
275
276 /* Allocate memory for device */
277 ts_dev = kzalloc(sizeof(struct titsc), GFP_KERNEL);
278 input_dev = input_allocate_device();
279 if (!ts_dev || !input_dev) {
280 dev_err(&pdev->dev, "failed to allocate memory.\n");
281 err = -ENOMEM;
282 goto err_free_mem;
283 }
284
285 tscadc_dev->tsc = ts_dev;
286 ts_dev->mfd_tscadc = tscadc_dev;
287 ts_dev->input = input_dev;
288 ts_dev->irq = tscadc_dev->irq;
289 ts_dev->wires = pdata->tsc_init->wires;
290 ts_dev->x_plate_resistance = pdata->tsc_init->x_plate_resistance;
291 ts_dev->steps_to_configure = pdata->tsc_init->steps_to_configure;
292
293 err = request_irq(ts_dev->irq, titsc_irq,
294 0, pdev->dev.driver->name, ts_dev);
295 if (err) {
296 dev_err(&pdev->dev, "failed to allocate irq.\n");
297 goto err_free_mem;
298 }
299
300 titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
301 titsc_step_config(ts_dev);
302 titsc_writel(ts_dev, REG_FIFO0THR, ts_dev->steps_to_configure);
303
304 input_dev->name = "ti-tsc";
305 input_dev->dev.parent = &pdev->dev;
306
307 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
308 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
309
310 input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, 0, 0);
311 input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, 0, 0);
312 input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT, 0, 0);
313
314 /* register to the input system */
315 err = input_register_device(input_dev);
316 if (err)
317 goto err_free_irq;
318
319 platform_set_drvdata(pdev, ts_dev);
320 return 0;
321
322err_free_irq:
323 free_irq(ts_dev->irq, ts_dev);
324err_free_mem:
325 input_free_device(input_dev);
326 kfree(ts_dev);
327 return err;
328}
329
330static int titsc_remove(struct platform_device *pdev)
331{
332 struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data;
333 struct titsc *ts_dev = tscadc_dev->tsc;
334
335 free_irq(ts_dev->irq, ts_dev);
336
337 input_unregister_device(ts_dev->input);
338
339 platform_set_drvdata(pdev, NULL);
340 kfree(ts_dev);
341 return 0;
342}
343
344#ifdef CONFIG_PM
345static int titsc_suspend(struct device *dev)
346{
347 struct ti_tscadc_dev *tscadc_dev = dev->platform_data;
348 struct titsc *ts_dev = tscadc_dev->tsc;
349 unsigned int idle;
350
351 if (device_may_wakeup(tscadc_dev->dev)) {
352 idle = titsc_readl(ts_dev, REG_IRQENABLE);
353 titsc_writel(ts_dev, REG_IRQENABLE,
354 (idle | IRQENB_HW_PEN));
355 titsc_writel(ts_dev, REG_IRQWAKEUP, IRQWKUP_ENB);
356 }
357 return 0;
358}
359
360static int titsc_resume(struct device *dev)
361{
362 struct ti_tscadc_dev *tscadc_dev = dev->platform_data;
363 struct titsc *ts_dev = tscadc_dev->tsc;
364
365 if (device_may_wakeup(tscadc_dev->dev)) {
366 titsc_writel(ts_dev, REG_IRQWAKEUP,
367 0x00);
368 titsc_writel(ts_dev, REG_IRQCLR, IRQENB_HW_PEN);
369 }
370 titsc_step_config(ts_dev);
371 titsc_writel(ts_dev, REG_FIFO0THR,
372 ts_dev->steps_to_configure);
373 return 0;
374}
375
376static const struct dev_pm_ops titsc_pm_ops = {
377 .suspend = titsc_suspend,
378 .resume = titsc_resume,
379};
380#define TITSC_PM_OPS (&titsc_pm_ops)
381#else
382#define TITSC_PM_OPS NULL
383#endif
384
385static struct platform_driver ti_tsc_driver = {
386 .probe = titsc_probe,
387 .remove = titsc_remove,
388 .driver = {
389 .name = "tsc",
390 .owner = THIS_MODULE,
391 .pm = TITSC_PM_OPS,
392 },
393};
394module_platform_driver(ti_tsc_driver);
395
396MODULE_DESCRIPTION("TI touchscreen controller driver");
397MODULE_AUTHOR("Rachna Patil <rachna@ti.com>");
398MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/ti_tscadc.c b/drivers/input/touchscreen/ti_tscadc.c
deleted file mode 100644
index bcedf2e7468c..000000000000
--- a/drivers/input/touchscreen/ti_tscadc.c
+++ /dev/null
@@ -1,486 +0,0 @@
1/*
2 * TI Touch Screen driver
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/err.h>
20#include <linux/module.h>
21#include <linux/input.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/clk.h>
25#include <linux/platform_device.h>
26#include <linux/io.h>
27#include <linux/input/ti_tscadc.h>
28#include <linux/delay.h>
29
30#define REG_IRQEOI 0x020
31#define REG_RAWIRQSTATUS 0x024
32#define REG_IRQSTATUS 0x028
33#define REG_IRQENABLE 0x02C
34#define REG_IRQWAKEUP 0x034
35#define REG_CTRL 0x040
36#define REG_ADCFSM 0x044
37#define REG_CLKDIV 0x04C
38#define REG_SE 0x054
39#define REG_IDLECONFIG 0x058
40#define REG_CHARGECONFIG 0x05C
41#define REG_CHARGEDELAY 0x060
42#define REG_STEPCONFIG(n) (0x64 + ((n - 1) * 8))
43#define REG_STEPDELAY(n) (0x68 + ((n - 1) * 8))
44#define REG_STEPCONFIG13 0x0C4
45#define REG_STEPDELAY13 0x0C8
46#define REG_STEPCONFIG14 0x0CC
47#define REG_STEPDELAY14 0x0D0
48#define REG_FIFO0CNT 0xE4
49#define REG_FIFO1THR 0xF4
50#define REG_FIFO0 0x100
51#define REG_FIFO1 0x200
52
53/* Register Bitfields */
54#define IRQWKUP_ENB BIT(0)
55#define STPENB_STEPENB 0x7FFF
56#define IRQENB_FIFO1THRES BIT(5)
57#define IRQENB_PENUP BIT(9)
58#define STEPCONFIG_MODE_HWSYNC 0x2
59#define STEPCONFIG_SAMPLES_AVG (1 << 4)
60#define STEPCONFIG_XPP (1 << 5)
61#define STEPCONFIG_XNN (1 << 6)
62#define STEPCONFIG_YPP (1 << 7)
63#define STEPCONFIG_YNN (1 << 8)
64#define STEPCONFIG_XNP (1 << 9)
65#define STEPCONFIG_YPN (1 << 10)
66#define STEPCONFIG_INM (1 << 18)
67#define STEPCONFIG_INP (1 << 20)
68#define STEPCONFIG_INP_5 (1 << 21)
69#define STEPCONFIG_FIFO1 (1 << 26)
70#define STEPCONFIG_OPENDLY 0xff
71#define STEPCONFIG_Z1 (3 << 19)
72#define STEPIDLE_INP (1 << 22)
73#define STEPCHARGE_RFP (1 << 12)
74#define STEPCHARGE_INM (1 << 15)
75#define STEPCHARGE_INP (1 << 19)
76#define STEPCHARGE_RFM (1 << 23)
77#define STEPCHARGE_DELAY 0x1
78#define CNTRLREG_TSCSSENB (1 << 0)
79#define CNTRLREG_STEPID (1 << 1)
80#define CNTRLREG_STEPCONFIGWRT (1 << 2)
81#define CNTRLREG_4WIRE (1 << 5)
82#define CNTRLREG_5WIRE (1 << 6)
83#define CNTRLREG_8WIRE (3 << 5)
84#define CNTRLREG_TSCENB (1 << 7)
85#define ADCFSM_STEPID 0x10
86
87#define SEQ_SETTLE 275
88#define ADC_CLK 3000000
89#define MAX_12BIT ((1 << 12) - 1)
90#define TSCADC_DELTA_X 15
91#define TSCADC_DELTA_Y 15
92
93struct tscadc {
94 struct input_dev *input;
95 struct clk *tsc_ick;
96 void __iomem *tsc_base;
97 unsigned int irq;
98 unsigned int wires;
99 unsigned int x_plate_resistance;
100 bool pen_down;
101};
102
103static unsigned int tscadc_readl(struct tscadc *ts, unsigned int reg)
104{
105 return readl(ts->tsc_base + reg);
106}
107
108static void tscadc_writel(struct tscadc *tsc, unsigned int reg,
109 unsigned int val)
110{
111 writel(val, tsc->tsc_base + reg);
112}
113
114static void tscadc_step_config(struct tscadc *ts_dev)
115{
116 unsigned int config;
117 int i;
118
119 /* Configure the Step registers */
120
121 config = STEPCONFIG_MODE_HWSYNC |
122 STEPCONFIG_SAMPLES_AVG | STEPCONFIG_XPP;
123 switch (ts_dev->wires) {
124 case 4:
125 config |= STEPCONFIG_INP | STEPCONFIG_XNN;
126 break;
127 case 5:
128 config |= STEPCONFIG_YNN |
129 STEPCONFIG_INP_5 | STEPCONFIG_XNN |
130 STEPCONFIG_YPP;
131 break;
132 case 8:
133 config |= STEPCONFIG_INP | STEPCONFIG_XNN;
134 break;
135 }
136
137 for (i = 1; i < 7; i++) {
138 tscadc_writel(ts_dev, REG_STEPCONFIG(i), config);
139 tscadc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY);
140 }
141
142 config = 0;
143 config = STEPCONFIG_MODE_HWSYNC |
144 STEPCONFIG_SAMPLES_AVG | STEPCONFIG_YNN |
145 STEPCONFIG_INM | STEPCONFIG_FIFO1;
146 switch (ts_dev->wires) {
147 case 4:
148 config |= STEPCONFIG_YPP;
149 break;
150 case 5:
151 config |= STEPCONFIG_XPP | STEPCONFIG_INP_5 |
152 STEPCONFIG_XNP | STEPCONFIG_YPN;
153 break;
154 case 8:
155 config |= STEPCONFIG_YPP;
156 break;
157 }
158
159 for (i = 7; i < 13; i++) {
160 tscadc_writel(ts_dev, REG_STEPCONFIG(i), config);
161 tscadc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY);
162 }
163
164 config = 0;
165 /* Charge step configuration */
166 config = STEPCONFIG_XPP | STEPCONFIG_YNN |
167 STEPCHARGE_RFP | STEPCHARGE_RFM |
168 STEPCHARGE_INM | STEPCHARGE_INP;
169
170 tscadc_writel(ts_dev, REG_CHARGECONFIG, config);
171 tscadc_writel(ts_dev, REG_CHARGEDELAY, STEPCHARGE_DELAY);
172
173 config = 0;
174 /* Configure to calculate pressure */
175 config = STEPCONFIG_MODE_HWSYNC |
176 STEPCONFIG_SAMPLES_AVG | STEPCONFIG_YPP |
177 STEPCONFIG_XNN | STEPCONFIG_INM;
178 tscadc_writel(ts_dev, REG_STEPCONFIG13, config);
179 tscadc_writel(ts_dev, REG_STEPDELAY13, STEPCONFIG_OPENDLY);
180
181 config |= STEPCONFIG_Z1 | STEPCONFIG_FIFO1;
182 tscadc_writel(ts_dev, REG_STEPCONFIG14, config);
183 tscadc_writel(ts_dev, REG_STEPDELAY14, STEPCONFIG_OPENDLY);
184
185 tscadc_writel(ts_dev, REG_SE, STPENB_STEPENB);
186}
187
188static void tscadc_idle_config(struct tscadc *ts_config)
189{
190 unsigned int idleconfig;
191
192 idleconfig = STEPCONFIG_YNN |
193 STEPCONFIG_INM |
194 STEPCONFIG_YPN | STEPIDLE_INP;
195 tscadc_writel(ts_config, REG_IDLECONFIG, idleconfig);
196}
197
198static void tscadc_read_coordinates(struct tscadc *ts_dev,
199 unsigned int *x, unsigned int *y)
200{
201 unsigned int fifocount = tscadc_readl(ts_dev, REG_FIFO0CNT);
202 unsigned int prev_val_x = ~0, prev_val_y = ~0;
203 unsigned int prev_diff_x = ~0, prev_diff_y = ~0;
204 unsigned int read, diff;
205 unsigned int i;
206
207 /*
208 * Delta filter is used to remove large variations in sampled
209 * values from ADC. The filter tries to predict where the next
210 * coordinate could be. This is done by taking a previous
211 * coordinate and subtracting it form current one. Further the
212 * algorithm compares the difference with that of a present value,
213 * if true the value is reported to the sub system.
214 */
215 for (i = 0; i < fifocount - 1; i++) {
216 read = tscadc_readl(ts_dev, REG_FIFO0) & 0xfff;
217 diff = abs(read - prev_val_x);
218 if (diff < prev_diff_x) {
219 prev_diff_x = diff;
220 *x = read;
221 }
222 prev_val_x = read;
223
224 read = tscadc_readl(ts_dev, REG_FIFO1) & 0xfff;
225 diff = abs(read - prev_val_y);
226 if (diff < prev_diff_y) {
227 prev_diff_y = diff;
228 *y = read;
229 }
230 prev_val_y = read;
231 }
232}
233
234static irqreturn_t tscadc_irq(int irq, void *dev)
235{
236 struct tscadc *ts_dev = dev;
237 struct input_dev *input_dev = ts_dev->input;
238 unsigned int status, irqclr = 0;
239 unsigned int x = 0, y = 0;
240 unsigned int z1, z2, z;
241 unsigned int fsm;
242
243 status = tscadc_readl(ts_dev, REG_IRQSTATUS);
244 if (status & IRQENB_FIFO1THRES) {
245 tscadc_read_coordinates(ts_dev, &x, &y);
246
247 z1 = tscadc_readl(ts_dev, REG_FIFO0) & 0xfff;
248 z2 = tscadc_readl(ts_dev, REG_FIFO1) & 0xfff;
249
250 if (ts_dev->pen_down && z1 != 0 && z2 != 0) {
251 /*
252 * Calculate pressure using formula
253 * Resistance(touch) = x plate resistance *
254 * x postion/4096 * ((z2 / z1) - 1)
255 */
256 z = z2 - z1;
257 z *= x;
258 z *= ts_dev->x_plate_resistance;
259 z /= z1;
260 z = (z + 2047) >> 12;
261
262 if (z <= MAX_12BIT) {
263 input_report_abs(input_dev, ABS_X, x);
264 input_report_abs(input_dev, ABS_Y, y);
265 input_report_abs(input_dev, ABS_PRESSURE, z);
266 input_report_key(input_dev, BTN_TOUCH, 1);
267 input_sync(input_dev);
268 }
269 }
270 irqclr |= IRQENB_FIFO1THRES;
271 }
272
273 /*
274 * Time for sequencer to settle, to read
275 * correct state of the sequencer.
276 */
277 udelay(SEQ_SETTLE);
278
279 status = tscadc_readl(ts_dev, REG_RAWIRQSTATUS);
280 if (status & IRQENB_PENUP) {
281 /* Pen up event */
282 fsm = tscadc_readl(ts_dev, REG_ADCFSM);
283 if (fsm == ADCFSM_STEPID) {
284 ts_dev->pen_down = false;
285 input_report_key(input_dev, BTN_TOUCH, 0);
286 input_report_abs(input_dev, ABS_PRESSURE, 0);
287 input_sync(input_dev);
288 } else {
289 ts_dev->pen_down = true;
290 }
291 irqclr |= IRQENB_PENUP;
292 }
293
294 tscadc_writel(ts_dev, REG_IRQSTATUS, irqclr);
295 /* check pending interrupts */
296 tscadc_writel(ts_dev, REG_IRQEOI, 0x0);
297
298 tscadc_writel(ts_dev, REG_SE, STPENB_STEPENB);
299 return IRQ_HANDLED;
300}
301
302/*
303 * The functions for inserting/removing driver as a module.
304 */
305
306static int tscadc_probe(struct platform_device *pdev)
307{
308 const struct tsc_data *pdata = pdev->dev.platform_data;
309 struct resource *res;
310 struct tscadc *ts_dev;
311 struct input_dev *input_dev;
312 struct clk *clk;
313 int err;
314 int clk_value, ctrl, irq;
315
316 if (!pdata) {
317 dev_err(&pdev->dev, "missing platform data.\n");
318 return -EINVAL;
319 }
320
321 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
322 if (!res) {
323 dev_err(&pdev->dev, "no memory resource defined.\n");
324 return -EINVAL;
325 }
326
327 irq = platform_get_irq(pdev, 0);
328 if (irq < 0) {
329 dev_err(&pdev->dev, "no irq ID is specified.\n");
330 return -EINVAL;
331 }
332
333 /* Allocate memory for device */
334 ts_dev = kzalloc(sizeof(struct tscadc), GFP_KERNEL);
335 input_dev = input_allocate_device();
336 if (!ts_dev || !input_dev) {
337 dev_err(&pdev->dev, "failed to allocate memory.\n");
338 err = -ENOMEM;
339 goto err_free_mem;
340 }
341
342 ts_dev->input = input_dev;
343 ts_dev->irq = irq;
344 ts_dev->wires = pdata->wires;
345 ts_dev->x_plate_resistance = pdata->x_plate_resistance;
346
347 res = request_mem_region(res->start, resource_size(res), pdev->name);
348 if (!res) {
349 dev_err(&pdev->dev, "failed to reserve registers.\n");
350 err = -EBUSY;
351 goto err_free_mem;
352 }
353
354 ts_dev->tsc_base = ioremap(res->start, resource_size(res));
355 if (!ts_dev->tsc_base) {
356 dev_err(&pdev->dev, "failed to map registers.\n");
357 err = -ENOMEM;
358 goto err_release_mem_region;
359 }
360
361 err = request_irq(ts_dev->irq, tscadc_irq,
362 0, pdev->dev.driver->name, ts_dev);
363 if (err) {
364 dev_err(&pdev->dev, "failed to allocate irq.\n");
365 goto err_unmap_regs;
366 }
367
368 ts_dev->tsc_ick = clk_get(&pdev->dev, "adc_tsc_ick");
369 if (IS_ERR(ts_dev->tsc_ick)) {
370 dev_err(&pdev->dev, "failed to get TSC ick\n");
371 goto err_free_irq;
372 }
373 clk_enable(ts_dev->tsc_ick);
374
375 clk = clk_get(&pdev->dev, "adc_tsc_fck");
376 if (IS_ERR(clk)) {
377 dev_err(&pdev->dev, "failed to get TSC fck\n");
378 err = PTR_ERR(clk);
379 goto err_disable_clk;
380 }
381
382 clk_value = clk_get_rate(clk) / ADC_CLK;
383 clk_put(clk);
384
385 if (clk_value < 7) {
386 dev_err(&pdev->dev, "clock input less than min clock requirement\n");
387 goto err_disable_clk;
388 }
389 /* CLKDIV needs to be configured to the value minus 1 */
390 tscadc_writel(ts_dev, REG_CLKDIV, clk_value - 1);
391
392 /* Enable wake-up of the SoC using touchscreen */
393 tscadc_writel(ts_dev, REG_IRQWAKEUP, IRQWKUP_ENB);
394
395 ctrl = CNTRLREG_STEPCONFIGWRT |
396 CNTRLREG_TSCENB |
397 CNTRLREG_STEPID;
398 switch (ts_dev->wires) {
399 case 4:
400 ctrl |= CNTRLREG_4WIRE;
401 break;
402 case 5:
403 ctrl |= CNTRLREG_5WIRE;
404 break;
405 case 8:
406 ctrl |= CNTRLREG_8WIRE;
407 break;
408 }
409 tscadc_writel(ts_dev, REG_CTRL, ctrl);
410
411 tscadc_idle_config(ts_dev);
412 tscadc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO1THRES);
413 tscadc_step_config(ts_dev);
414 tscadc_writel(ts_dev, REG_FIFO1THR, 6);
415
416 ctrl |= CNTRLREG_TSCSSENB;
417 tscadc_writel(ts_dev, REG_CTRL, ctrl);
418
419 input_dev->name = "ti-tsc-adc";
420 input_dev->dev.parent = &pdev->dev;
421
422 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
423 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
424
425 input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, 0, 0);
426 input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, 0, 0);
427 input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT, 0, 0);
428
429 /* register to the input system */
430 err = input_register_device(input_dev);
431 if (err)
432 goto err_disable_clk;
433
434 platform_set_drvdata(pdev, ts_dev);
435 return 0;
436
437err_disable_clk:
438 clk_disable(ts_dev->tsc_ick);
439 clk_put(ts_dev->tsc_ick);
440err_free_irq:
441 free_irq(ts_dev->irq, ts_dev);
442err_unmap_regs:
443 iounmap(ts_dev->tsc_base);
444err_release_mem_region:
445 release_mem_region(res->start, resource_size(res));
446err_free_mem:
447 input_free_device(input_dev);
448 kfree(ts_dev);
449 return err;
450}
451
452static int __devexit tscadc_remove(struct platform_device *pdev)
453{
454 struct tscadc *ts_dev = platform_get_drvdata(pdev);
455 struct resource *res;
456
457 free_irq(ts_dev->irq, ts_dev);
458
459 input_unregister_device(ts_dev->input);
460
461 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
462 iounmap(ts_dev->tsc_base);
463 release_mem_region(res->start, resource_size(res));
464
465 clk_disable(ts_dev->tsc_ick);
466 clk_put(ts_dev->tsc_ick);
467
468 kfree(ts_dev);
469
470 platform_set_drvdata(pdev, NULL);
471 return 0;
472}
473
474static struct platform_driver ti_tsc_driver = {
475 .probe = tscadc_probe,
476 .remove = __devexit_p(tscadc_remove),
477 .driver = {
478 .name = "tsc",
479 .owner = THIS_MODULE,
480 },
481};
482module_platform_driver(ti_tsc_driver);
483
484MODULE_DESCRIPTION("TI touchscreen controller driver");
485MODULE_AUTHOR("Rachna Patil <rachna@ti.com>");
486MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
index 6e743e3dfda4..16b52115c27f 100644
--- a/drivers/input/touchscreen/wm9712.c
+++ b/drivers/input/touchscreen/wm9712.c
@@ -162,14 +162,14 @@ static void wm9712_phy_init(struct wm97xx *wm)
162 if (rpu) { 162 if (rpu) {
163 dig2 &= 0xffc0; 163 dig2 &= 0xffc0;
164 dig2 |= WM9712_RPU(rpu); 164 dig2 |= WM9712_RPU(rpu);
165 dev_dbg(wm->dev, "setting pen detect pull-up to %d Ohms", 165 dev_dbg(wm->dev, "setting pen detect pull-up to %d Ohms\n",
166 64000 / rpu); 166 64000 / rpu);
167 } 167 }
168 168
169 /* WM9712 five wire */ 169 /* WM9712 five wire */
170 if (five_wire) { 170 if (five_wire) {
171 dig2 |= WM9712_45W; 171 dig2 |= WM9712_45W;
172 dev_dbg(wm->dev, "setting 5-wire touchscreen mode."); 172 dev_dbg(wm->dev, "setting 5-wire touchscreen mode.\n");
173 173
174 if (pil) { 174 if (pil) {
175 dev_warn(wm->dev, "pressure measurement is not " 175 dev_warn(wm->dev, "pressure measurement is not "
@@ -182,21 +182,21 @@ static void wm9712_phy_init(struct wm97xx *wm)
182 if (pil == 2) { 182 if (pil == 2) {
183 dig2 |= WM9712_PIL; 183 dig2 |= WM9712_PIL;
184 dev_dbg(wm->dev, 184 dev_dbg(wm->dev,
185 "setting pressure measurement current to 400uA."); 185 "setting pressure measurement current to 400uA.\n");
186 } else if (pil) 186 } else if (pil)
187 dev_dbg(wm->dev, 187 dev_dbg(wm->dev,
188 "setting pressure measurement current to 200uA."); 188 "setting pressure measurement current to 200uA.\n");
189 if (!pil) 189 if (!pil)
190 pressure = 0; 190 pressure = 0;
191 191
192 /* polling mode sample settling delay */ 192 /* polling mode sample settling delay */
193 if (delay < 0 || delay > 15) { 193 if (delay < 0 || delay > 15) {
194 dev_dbg(wm->dev, "supplied delay out of range."); 194 dev_dbg(wm->dev, "supplied delay out of range.\n");
195 delay = 4; 195 delay = 4;
196 } 196 }
197 dig1 &= 0xff0f; 197 dig1 &= 0xff0f;
198 dig1 |= WM97XX_DELAY(delay); 198 dig1 |= WM97XX_DELAY(delay);
199 dev_dbg(wm->dev, "setting adc sample delay to %d u Secs.", 199 dev_dbg(wm->dev, "setting adc sample delay to %d u Secs.\n",
200 delay_table[delay]); 200 delay_table[delay]);
201 201
202 /* mask */ 202 /* mask */
@@ -285,7 +285,7 @@ static int wm9712_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
285 if (is_pden(wm)) 285 if (is_pden(wm))
286 wm->pen_probably_down = 0; 286 wm->pen_probably_down = 0;
287 else 287 else
288 dev_dbg(wm->dev, "adc sample timeout"); 288 dev_dbg(wm->dev, "adc sample timeout\n");
289 return RC_PENUP; 289 return RC_PENUP;
290 } 290 }
291 291
@@ -295,15 +295,19 @@ static int wm9712_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
295 295
296 /* check we have correct sample */ 296 /* check we have correct sample */
297 if ((*sample ^ adcsel) & WM97XX_ADCSEL_MASK) { 297 if ((*sample ^ adcsel) & WM97XX_ADCSEL_MASK) {
298 dev_dbg(wm->dev, "adc wrong sample, wanted %x got %x", 298 dev_dbg(wm->dev, "adc wrong sample, wanted %x got %x\n",
299 adcsel & WM97XX_ADCSEL_MASK, 299 adcsel & WM97XX_ADCSEL_MASK,
300 *sample & WM97XX_ADCSEL_MASK); 300 *sample & WM97XX_ADCSEL_MASK);
301 return RC_PENUP; 301 return RC_AGAIN;
302 } 302 }
303 303
304 if (wants_pen && !(*sample & WM97XX_PEN_DOWN)) { 304 if (wants_pen && !(*sample & WM97XX_PEN_DOWN)) {
305 wm->pen_probably_down = 0; 305 /* Sometimes it reads a wrong value the first time. */
306 return RC_PENUP; 306 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
307 if (!(*sample & WM97XX_PEN_DOWN)) {
308 wm->pen_probably_down = 0;
309 return RC_PENUP;
310 }
307 } 311 }
308 312
309 return RC_VALID; 313 return RC_VALID;
@@ -345,7 +349,7 @@ static int wm9712_poll_coord(struct wm97xx *wm, struct wm97xx_data *data)
345 if (is_pden(wm)) 349 if (is_pden(wm))
346 wm->pen_probably_down = 0; 350 wm->pen_probably_down = 0;
347 else 351 else
348 dev_dbg(wm->dev, "adc sample timeout"); 352 dev_dbg(wm->dev, "adc sample timeout\n");
349 return RC_PENUP; 353 return RC_PENUP;
350 } 354 }
351 355
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
index 5dbe73af2f8f..7e45c9f6e6b7 100644
--- a/drivers/input/touchscreen/wm97xx-core.c
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -442,6 +442,16 @@ static int wm97xx_read_samples(struct wm97xx *wm)
442 "pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n", 442 "pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n",
443 data.x >> 12, data.x & 0xfff, data.y >> 12, 443 data.x >> 12, data.x & 0xfff, data.y >> 12,
444 data.y & 0xfff, data.p >> 12, data.p & 0xfff); 444 data.y & 0xfff, data.p >> 12, data.p & 0xfff);
445
446 if (abs_x[0] > (data.x & 0xfff) ||
447 abs_x[1] < (data.x & 0xfff) ||
448 abs_y[0] > (data.y & 0xfff) ||
449 abs_y[1] < (data.y & 0xfff)) {
450 dev_dbg(wm->dev, "Measurement out of range, dropping it\n");
451 rc = RC_AGAIN;
452 goto out;
453 }
454
445 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); 455 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
446 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff); 456 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
447 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff); 457 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
@@ -455,6 +465,7 @@ static int wm97xx_read_samples(struct wm97xx *wm)
455 wm->ts_reader_interval = wm->ts_reader_min_interval; 465 wm->ts_reader_interval = wm->ts_reader_min_interval;
456 } 466 }
457 467
468out:
458 mutex_unlock(&wm->codec_mutex); 469 mutex_unlock(&wm->codec_mutex);
459 return rc; 470 return rc;
460} 471}