aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2014-06-08 02:24:07 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-06-08 02:24:07 -0400
commita292241cccb7e20e8b997a9a44177e7c98141859 (patch)
treea0b0bb95e7dce3233a2d8b203f9e326cdec7a00e /drivers/input/keyboard
parentd49cb7aeebb974713f9f7ab2991352d3050b095b (diff)
parent68807a0c2015cb40df4869e16651f0ce5cc14d52 (diff)
Merge branch 'next' into for-linus
Prepare input updates for 3.16.
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/Kconfig13
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/adp5520-keys.c32
-rw-r--r--drivers/input/keyboard/clps711x-keypad.c2
-rw-r--r--drivers/input/keyboard/gpio_keys.c145
-rw-r--r--drivers/input/keyboard/gpio_keys_polled.c100
-rw-r--r--drivers/input/keyboard/imx_keypad.c2
-rw-r--r--drivers/input/keyboard/jornada680_kbd.c36
-rw-r--r--drivers/input/keyboard/mcs_touchkey.c2
-rw-r--r--drivers/input/keyboard/omap4-keypad.c32
-rw-r--r--drivers/input/keyboard/st-keyscan.c274
-rw-r--r--drivers/input/keyboard/tc3589x-keypad.c66
12 files changed, 462 insertions, 243 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index ffc7ad3a2c88..f7e79b481349 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -524,6 +524,17 @@ config KEYBOARD_STOWAWAY
524 To compile this driver as a module, choose M here: the 524 To compile this driver as a module, choose M here: the
525 module will be called stowaway. 525 module will be called stowaway.
526 526
527config KEYBOARD_ST_KEYSCAN
528 tristate "STMicroelectronics keyscan support"
529 depends on ARCH_STI || COMPILE_TEST
530 select INPUT_MATRIXKMAP
531 help
532 Say Y here if you want to use a keypad attached to the keyscan block
533 on some STMicroelectronics SoC devices.
534
535 To compile this driver as a module, choose M here: the
536 module will be called st-keyscan.
537
527config KEYBOARD_SUNKBD 538config KEYBOARD_SUNKBD
528 tristate "Sun Type 4 and Type 5 keyboard" 539 tristate "Sun Type 4 and Type 5 keyboard"
529 select SERIO 540 select SERIO
@@ -578,7 +589,7 @@ config KEYBOARD_OMAP
578 589
579config KEYBOARD_OMAP4 590config KEYBOARD_OMAP4
580 tristate "TI OMAP4+ keypad support" 591 tristate "TI OMAP4+ keypad support"
581 depends on ARCH_OMAP2PLUS 592 depends on OF || ARCH_OMAP2PLUS
582 select INPUT_MATRIXKMAP 593 select INPUT_MATRIXKMAP
583 help 594 help
584 Say Y here if you want to use the OMAP4+ keypad. 595 Say Y here if you want to use the OMAP4+ keypad.
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 11cff7b84b47..7504ae19049d 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
51obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o 51obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o
52obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o 52obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o
53obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 53obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
54obj-$(CONFIG_KEYBOARD_ST_KEYSCAN) += st-keyscan.o
54obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o 55obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
55obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o 56obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o
56obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o 57obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o
diff --git a/drivers/input/keyboard/adp5520-keys.c b/drivers/input/keyboard/adp5520-keys.c
index 4cc14c2fa7d5..7f4a8b58efc1 100644
--- a/drivers/input/keyboard/adp5520-keys.c
+++ b/drivers/input/keyboard/adp5520-keys.c
@@ -12,6 +12,7 @@
12#include <linux/input.h> 12#include <linux/input.h>
13#include <linux/mfd/adp5520.h> 13#include <linux/mfd/adp5520.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/device.h>
15 16
16struct adp5520_keys { 17struct adp5520_keys {
17 struct input_dev *input; 18 struct input_dev *input;
@@ -81,7 +82,7 @@ static int adp5520_keys_probe(struct platform_device *pdev)
81 return -EINVAL; 82 return -EINVAL;
82 } 83 }
83 84
84 if (pdata == NULL) { 85 if (!pdata) {
85 dev_err(&pdev->dev, "missing platform data\n"); 86 dev_err(&pdev->dev, "missing platform data\n");
86 return -EINVAL; 87 return -EINVAL;
87 } 88 }
@@ -89,17 +90,15 @@ static int adp5520_keys_probe(struct platform_device *pdev)
89 if (!(pdata->rows_en_mask && pdata->cols_en_mask)) 90 if (!(pdata->rows_en_mask && pdata->cols_en_mask))
90 return -EINVAL; 91 return -EINVAL;
91 92
92 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 93 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
93 if (dev == NULL) { 94 if (!dev) {
94 dev_err(&pdev->dev, "failed to alloc memory\n"); 95 dev_err(&pdev->dev, "failed to alloc memory\n");
95 return -ENOMEM; 96 return -ENOMEM;
96 } 97 }
97 98
98 input = input_allocate_device(); 99 input = devm_input_allocate_device(&pdev->dev);
99 if (!input) { 100 if (!input)
100 ret = -ENOMEM; 101 return -ENOMEM;
101 goto err;
102 }
103 102
104 dev->master = pdev->dev.parent; 103 dev->master = pdev->dev.parent;
105 dev->input = input; 104 dev->input = input;
@@ -135,7 +134,7 @@ static int adp5520_keys_probe(struct platform_device *pdev)
135 ret = input_register_device(input); 134 ret = input_register_device(input);
136 if (ret) { 135 if (ret) {
137 dev_err(&pdev->dev, "unable to register input device\n"); 136 dev_err(&pdev->dev, "unable to register input device\n");
138 goto err; 137 return ret;
139 } 138 }
140 139
141 en_mask = pdata->rows_en_mask | pdata->cols_en_mask; 140 en_mask = pdata->rows_en_mask | pdata->cols_en_mask;
@@ -157,8 +156,7 @@ static int adp5520_keys_probe(struct platform_device *pdev)
157 156
158 if (ret) { 157 if (ret) {
159 dev_err(&pdev->dev, "failed to write\n"); 158 dev_err(&pdev->dev, "failed to write\n");
160 ret = -EIO; 159 return -EIO;
161 goto err1;
162 } 160 }
163 161
164 dev->notifier.notifier_call = adp5520_keys_notifier; 162 dev->notifier.notifier_call = adp5520_keys_notifier;
@@ -166,19 +164,11 @@ static int adp5520_keys_probe(struct platform_device *pdev)
166 ADP5520_KP_IEN | ADP5520_KR_IEN); 164 ADP5520_KP_IEN | ADP5520_KR_IEN);
167 if (ret) { 165 if (ret) {
168 dev_err(&pdev->dev, "failed to register notifier\n"); 166 dev_err(&pdev->dev, "failed to register notifier\n");
169 goto err1; 167 return ret;
170 } 168 }
171 169
172 platform_set_drvdata(pdev, dev); 170 platform_set_drvdata(pdev, dev);
173 return 0; 171 return 0;
174
175err1:
176 input_unregister_device(input);
177 input = NULL;
178err:
179 input_free_device(input);
180 kfree(dev);
181 return ret;
182} 172}
183 173
184static int adp5520_keys_remove(struct platform_device *pdev) 174static int adp5520_keys_remove(struct platform_device *pdev)
@@ -188,8 +178,6 @@ static int adp5520_keys_remove(struct platform_device *pdev)
188 adp5520_unregister_notifier(dev->master, &dev->notifier, 178 adp5520_unregister_notifier(dev->master, &dev->notifier,
189 ADP5520_KP_IEN | ADP5520_KR_IEN); 179 ADP5520_KP_IEN | ADP5520_KR_IEN);
190 180
191 input_unregister_device(dev->input);
192 kfree(dev);
193 return 0; 181 return 0;
194} 182}
195 183
diff --git a/drivers/input/keyboard/clps711x-keypad.c b/drivers/input/keyboard/clps711x-keypad.c
index 3955aecee44b..552b65c6e6b0 100644
--- a/drivers/input/keyboard/clps711x-keypad.c
+++ b/drivers/input/keyboard/clps711x-keypad.c
@@ -185,7 +185,7 @@ static int clps711x_keypad_remove(struct platform_device *pdev)
185 return 0; 185 return 0;
186} 186}
187 187
188static struct of_device_id clps711x_keypad_of_match[] = { 188static const struct of_device_id clps711x_keypad_of_match[] = {
189 { .compatible = "cirrus,clps711x-keypad", }, 189 { .compatible = "cirrus,clps711x-keypad", },
190 { } 190 { }
191}; 191};
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 2db13246eb8e..8c98e97f8e41 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -424,6 +424,16 @@ out:
424 return IRQ_HANDLED; 424 return IRQ_HANDLED;
425} 425}
426 426
427static void gpio_keys_quiesce_key(void *data)
428{
429 struct gpio_button_data *bdata = data;
430
431 if (bdata->timer_debounce)
432 del_timer_sync(&bdata->timer);
433
434 cancel_work_sync(&bdata->work);
435}
436
427static int gpio_keys_setup_key(struct platform_device *pdev, 437static int gpio_keys_setup_key(struct platform_device *pdev,
428 struct input_dev *input, 438 struct input_dev *input,
429 struct gpio_button_data *bdata, 439 struct gpio_button_data *bdata,
@@ -433,7 +443,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
433 struct device *dev = &pdev->dev; 443 struct device *dev = &pdev->dev;
434 irq_handler_t isr; 444 irq_handler_t isr;
435 unsigned long irqflags; 445 unsigned long irqflags;
436 int irq, error; 446 int irq;
447 int error;
437 448
438 bdata->input = input; 449 bdata->input = input;
439 bdata->button = button; 450 bdata->button = button;
@@ -441,7 +452,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
441 452
442 if (gpio_is_valid(button->gpio)) { 453 if (gpio_is_valid(button->gpio)) {
443 454
444 error = gpio_request_one(button->gpio, GPIOF_IN, desc); 455 error = devm_gpio_request_one(&pdev->dev, button->gpio,
456 GPIOF_IN, desc);
445 if (error < 0) { 457 if (error < 0) {
446 dev_err(dev, "Failed to request GPIO %d, error %d\n", 458 dev_err(dev, "Failed to request GPIO %d, error %d\n",
447 button->gpio, error); 459 button->gpio, error);
@@ -463,7 +475,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
463 dev_err(dev, 475 dev_err(dev,
464 "Unable to get irq number for GPIO %d, error %d\n", 476 "Unable to get irq number for GPIO %d, error %d\n",
465 button->gpio, error); 477 button->gpio, error);
466 goto fail; 478 return error;
467 } 479 }
468 bdata->irq = irq; 480 bdata->irq = irq;
469 481
@@ -497,26 +509,33 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
497 input_set_capability(input, button->type ?: EV_KEY, button->code); 509 input_set_capability(input, button->type ?: EV_KEY, button->code);
498 510
499 /* 511 /*
512 * Install custom action to cancel debounce timer and
513 * workqueue item.
514 */
515 error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata);
516 if (error) {
517 dev_err(&pdev->dev,
518 "failed to register quiesce action, error: %d\n",
519 error);
520 return error;
521 }
522
523 /*
500 * If platform has specified that the button can be disabled, 524 * If platform has specified that the button can be disabled,
501 * we don't want it to share the interrupt line. 525 * we don't want it to share the interrupt line.
502 */ 526 */
503 if (!button->can_disable) 527 if (!button->can_disable)
504 irqflags |= IRQF_SHARED; 528 irqflags |= IRQF_SHARED;
505 529
506 error = request_any_context_irq(bdata->irq, isr, irqflags, desc, bdata); 530 error = devm_request_any_context_irq(&pdev->dev, bdata->irq,
531 isr, irqflags, desc, bdata);
507 if (error < 0) { 532 if (error < 0) {
508 dev_err(dev, "Unable to claim irq %d; error %d\n", 533 dev_err(dev, "Unable to claim irq %d; error %d\n",
509 bdata->irq, error); 534 bdata->irq, error);
510 goto fail; 535 return error;
511 } 536 }
512 537
513 return 0; 538 return 0;
514
515fail:
516 if (gpio_is_valid(button->gpio))
517 gpio_free(button->gpio);
518
519 return error;
520} 539}
521 540
522static void gpio_keys_report_state(struct gpio_keys_drvdata *ddata) 541static void gpio_keys_report_state(struct gpio_keys_drvdata *ddata)
@@ -578,23 +597,18 @@ gpio_keys_get_devtree_pdata(struct device *dev)
578 int i; 597 int i;
579 598
580 node = dev->of_node; 599 node = dev->of_node;
581 if (!node) { 600 if (!node)
582 error = -ENODEV; 601 return ERR_PTR(-ENODEV);
583 goto err_out;
584 }
585 602
586 nbuttons = of_get_child_count(node); 603 nbuttons = of_get_child_count(node);
587 if (nbuttons == 0) { 604 if (nbuttons == 0)
588 error = -ENODEV; 605 return ERR_PTR(-ENODEV);
589 goto err_out;
590 }
591 606
592 pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), 607 pdata = devm_kzalloc(dev,
593 GFP_KERNEL); 608 sizeof(*pdata) + nbuttons * sizeof(*button),
594 if (!pdata) { 609 GFP_KERNEL);
595 error = -ENOMEM; 610 if (!pdata)
596 goto err_out; 611 return ERR_PTR(-ENOMEM);
597 }
598 612
599 pdata->buttons = (struct gpio_keys_button *)(pdata + 1); 613 pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
600 pdata->nbuttons = nbuttons; 614 pdata->nbuttons = nbuttons;
@@ -619,7 +633,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
619 dev_err(dev, 633 dev_err(dev,
620 "Failed to get gpio flags, error: %d\n", 634 "Failed to get gpio flags, error: %d\n",
621 error); 635 error);
622 goto err_free_pdata; 636 return ERR_PTR(error);
623 } 637 }
624 638
625 button = &pdata->buttons[i++]; 639 button = &pdata->buttons[i++];
@@ -630,8 +644,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
630 if (of_property_read_u32(pp, "linux,code", &button->code)) { 644 if (of_property_read_u32(pp, "linux,code", &button->code)) {
631 dev_err(dev, "Button without keycode: 0x%x\n", 645 dev_err(dev, "Button without keycode: 0x%x\n",
632 button->gpio); 646 button->gpio);
633 error = -EINVAL; 647 return ERR_PTR(-EINVAL);
634 goto err_free_pdata;
635 } 648 }
636 649
637 button->desc = of_get_property(pp, "label", NULL); 650 button->desc = of_get_property(pp, "label", NULL);
@@ -646,20 +659,13 @@ gpio_keys_get_devtree_pdata(struct device *dev)
646 button->debounce_interval = 5; 659 button->debounce_interval = 5;
647 } 660 }
648 661
649 if (pdata->nbuttons == 0) { 662 if (pdata->nbuttons == 0)
650 error = -EINVAL; 663 return ERR_PTR(-EINVAL);
651 goto err_free_pdata;
652 }
653 664
654 return pdata; 665 return pdata;
655
656err_free_pdata:
657 kfree(pdata);
658err_out:
659 return ERR_PTR(error);
660} 666}
661 667
662static struct of_device_id gpio_keys_of_match[] = { 668static const struct of_device_id gpio_keys_of_match[] = {
663 { .compatible = "gpio-keys", }, 669 { .compatible = "gpio-keys", },
664 { }, 670 { },
665}; 671};
@@ -675,22 +681,13 @@ gpio_keys_get_devtree_pdata(struct device *dev)
675 681
676#endif 682#endif
677 683
678static void gpio_remove_key(struct gpio_button_data *bdata)
679{
680 free_irq(bdata->irq, bdata);
681 if (bdata->timer_debounce)
682 del_timer_sync(&bdata->timer);
683 cancel_work_sync(&bdata->work);
684 if (gpio_is_valid(bdata->button->gpio))
685 gpio_free(bdata->button->gpio);
686}
687
688static int gpio_keys_probe(struct platform_device *pdev) 684static int gpio_keys_probe(struct platform_device *pdev)
689{ 685{
690 struct device *dev = &pdev->dev; 686 struct device *dev = &pdev->dev;
691 const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); 687 const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
692 struct gpio_keys_drvdata *ddata; 688 struct gpio_keys_drvdata *ddata;
693 struct input_dev *input; 689 struct input_dev *input;
690 size_t size;
694 int i, error; 691 int i, error;
695 int wakeup = 0; 692 int wakeup = 0;
696 693
@@ -700,14 +697,18 @@ static int gpio_keys_probe(struct platform_device *pdev)
700 return PTR_ERR(pdata); 697 return PTR_ERR(pdata);
701 } 698 }
702 699
703 ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + 700 size = sizeof(struct gpio_keys_drvdata) +
704 pdata->nbuttons * sizeof(struct gpio_button_data), 701 pdata->nbuttons * sizeof(struct gpio_button_data);
705 GFP_KERNEL); 702 ddata = devm_kzalloc(dev, size, GFP_KERNEL);
706 input = input_allocate_device(); 703 if (!ddata) {
707 if (!ddata || !input) {
708 dev_err(dev, "failed to allocate state\n"); 704 dev_err(dev, "failed to allocate state\n");
709 error = -ENOMEM; 705 return -ENOMEM;
710 goto fail1; 706 }
707
708 input = devm_input_allocate_device(dev);
709 if (!input) {
710 dev_err(dev, "failed to allocate input device\n");
711 return -ENOMEM;
711 } 712 }
712 713
713 ddata->pdata = pdata; 714 ddata->pdata = pdata;
@@ -738,7 +739,7 @@ static int gpio_keys_probe(struct platform_device *pdev)
738 739
739 error = gpio_keys_setup_key(pdev, input, bdata, button); 740 error = gpio_keys_setup_key(pdev, input, bdata, button);
740 if (error) 741 if (error)
741 goto fail2; 742 return error;
742 743
743 if (button->wakeup) 744 if (button->wakeup)
744 wakeup = 1; 745 wakeup = 1;
@@ -748,57 +749,31 @@ static int gpio_keys_probe(struct platform_device *pdev)
748 if (error) { 749 if (error) {
749 dev_err(dev, "Unable to export keys/switches, error: %d\n", 750 dev_err(dev, "Unable to export keys/switches, error: %d\n",
750 error); 751 error);
751 goto fail2; 752 return error;
752 } 753 }
753 754
754 error = input_register_device(input); 755 error = input_register_device(input);
755 if (error) { 756 if (error) {
756 dev_err(dev, "Unable to register input device, error: %d\n", 757 dev_err(dev, "Unable to register input device, error: %d\n",
757 error); 758 error);
758 goto fail3; 759 goto err_remove_group;
759 } 760 }
760 761
761 device_init_wakeup(&pdev->dev, wakeup); 762 device_init_wakeup(&pdev->dev, wakeup);
762 763
763 return 0; 764 return 0;
764 765
765 fail3: 766err_remove_group:
766 sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); 767 sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
767 fail2:
768 while (--i >= 0)
769 gpio_remove_key(&ddata->data[i]);
770
771 fail1:
772 input_free_device(input);
773 kfree(ddata);
774 /* If we have no platform data, we allocated pdata dynamically. */
775 if (!dev_get_platdata(&pdev->dev))
776 kfree(pdata);
777
778 return error; 768 return error;
779} 769}
780 770
781static int gpio_keys_remove(struct platform_device *pdev) 771static int gpio_keys_remove(struct platform_device *pdev)
782{ 772{
783 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
784 struct input_dev *input = ddata->input;
785 int i;
786
787 sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); 773 sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
788 774
789 device_init_wakeup(&pdev->dev, 0); 775 device_init_wakeup(&pdev->dev, 0);
790 776
791 for (i = 0; i < ddata->pdata->nbuttons; i++)
792 gpio_remove_key(&ddata->data[i]);
793
794 input_unregister_device(input);
795
796 /* If we have no platform data, we allocated pdata dynamically. */
797 if (!dev_get_platdata(&pdev->dev))
798 kfree(ddata->pdata);
799
800 kfree(ddata);
801
802 return 0; 777 return 0;
803} 778}
804 779
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index e571e194ff84..432d36395f35 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -120,12 +120,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
120 if (nbuttons == 0) 120 if (nbuttons == 0)
121 return NULL; 121 return NULL;
122 122
123 pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), 123 pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * sizeof(*button),
124 GFP_KERNEL); 124 GFP_KERNEL);
125 if (!pdata) { 125 if (!pdata)
126 error = -ENOMEM; 126 return ERR_PTR(-ENOMEM);
127 goto err_out;
128 }
129 127
130 pdata->buttons = (struct gpio_keys_button *)(pdata + 1); 128 pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
131 pdata->nbuttons = nbuttons; 129 pdata->nbuttons = nbuttons;
@@ -151,7 +149,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
151 dev_err(dev, 149 dev_err(dev,
152 "Failed to get gpio flags, error: %d\n", 150 "Failed to get gpio flags, error: %d\n",
153 error); 151 error);
154 goto err_free_pdata; 152 return ERR_PTR(error);
155 } 153 }
156 154
157 button = &pdata->buttons[i++]; 155 button = &pdata->buttons[i++];
@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
162 if (of_property_read_u32(pp, "linux,code", &button->code)) { 160 if (of_property_read_u32(pp, "linux,code", &button->code)) {
163 dev_err(dev, "Button without keycode: 0x%x\n", 161 dev_err(dev, "Button without keycode: 0x%x\n",
164 button->gpio); 162 button->gpio);
165 error = -EINVAL; 163 return ERR_PTR(-EINVAL);
166 goto err_free_pdata;
167 } 164 }
168 165
169 button->desc = of_get_property(pp, "label", NULL); 166 button->desc = of_get_property(pp, "label", NULL);
@@ -178,20 +175,13 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
178 button->debounce_interval = 5; 175 button->debounce_interval = 5;
179 } 176 }
180 177
181 if (pdata->nbuttons == 0) { 178 if (pdata->nbuttons == 0)
182 error = -EINVAL; 179 return ERR_PTR(-EINVAL);
183 goto err_free_pdata;
184 }
185 180
186 return pdata; 181 return pdata;
187
188err_free_pdata:
189 kfree(pdata);
190err_out:
191 return ERR_PTR(error);
192} 182}
193 183
194static struct of_device_id gpio_keys_polled_of_match[] = { 184static const struct of_device_id gpio_keys_polled_of_match[] = {
195 { .compatible = "gpio-keys-polled", }, 185 { .compatible = "gpio-keys-polled", },
196 { }, 186 { },
197}; 187};
@@ -213,6 +203,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
213 struct gpio_keys_polled_dev *bdev; 203 struct gpio_keys_polled_dev *bdev;
214 struct input_polled_dev *poll_dev; 204 struct input_polled_dev *poll_dev;
215 struct input_dev *input; 205 struct input_dev *input;
206 size_t size;
216 int error; 207 int error;
217 int i; 208 int i;
218 209
@@ -228,24 +219,21 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
228 219
229 if (!pdata->poll_interval) { 220 if (!pdata->poll_interval) {
230 dev_err(dev, "missing poll_interval value\n"); 221 dev_err(dev, "missing poll_interval value\n");
231 error = -EINVAL; 222 return -EINVAL;
232 goto err_free_pdata;
233 } 223 }
234 224
235 bdev = kzalloc(sizeof(struct gpio_keys_polled_dev) + 225 size = sizeof(struct gpio_keys_polled_dev) +
236 pdata->nbuttons * sizeof(struct gpio_keys_button_data), 226 pdata->nbuttons * sizeof(struct gpio_keys_button_data);
237 GFP_KERNEL); 227 bdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
238 if (!bdev) { 228 if (!bdev) {
239 dev_err(dev, "no memory for private data\n"); 229 dev_err(dev, "no memory for private data\n");
240 error = -ENOMEM; 230 return -ENOMEM;
241 goto err_free_pdata;
242 } 231 }
243 232
244 poll_dev = input_allocate_polled_device(); 233 poll_dev = devm_input_allocate_polled_device(&pdev->dev);
245 if (!poll_dev) { 234 if (!poll_dev) {
246 dev_err(dev, "no memory for polled device\n"); 235 dev_err(dev, "no memory for polled device\n");
247 error = -ENOMEM; 236 return -ENOMEM;
248 goto err_free_bdev;
249 } 237 }
250 238
251 poll_dev->private = bdev; 239 poll_dev->private = bdev;
@@ -258,7 +246,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
258 246
259 input->name = pdev->name; 247 input->name = pdev->name;
260 input->phys = DRV_NAME"/input0"; 248 input->phys = DRV_NAME"/input0";
261 input->dev.parent = &pdev->dev;
262 249
263 input->id.bustype = BUS_HOST; 250 input->id.bustype = BUS_HOST;
264 input->id.vendor = 0x0001; 251 input->id.vendor = 0x0001;
@@ -277,16 +264,15 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
277 264
278 if (button->wakeup) { 265 if (button->wakeup) {
279 dev_err(dev, DRV_NAME " does not support wakeup\n"); 266 dev_err(dev, DRV_NAME " does not support wakeup\n");
280 error = -EINVAL; 267 return -EINVAL;
281 goto err_free_gpio;
282 } 268 }
283 269
284 error = gpio_request_one(gpio, GPIOF_IN, 270 error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN,
285 button->desc ?: DRV_NAME); 271 button->desc ? : DRV_NAME);
286 if (error) { 272 if (error) {
287 dev_err(dev, "unable to claim gpio %u, err=%d\n", 273 dev_err(dev, "unable to claim gpio %u, err=%d\n",
288 gpio, error); 274 gpio, error);
289 goto err_free_gpio; 275 return error;
290 } 276 }
291 277
292 bdata->can_sleep = gpio_cansleep(gpio); 278 bdata->can_sleep = gpio_cansleep(gpio);
@@ -306,7 +292,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
306 if (error) { 292 if (error) {
307 dev_err(dev, "unable to register polled device, err=%d\n", 293 dev_err(dev, "unable to register polled device, err=%d\n",
308 error); 294 error);
309 goto err_free_gpio; 295 return error;
310 } 296 }
311 297
312 /* report initial state of the buttons */ 298 /* report initial state of the buttons */
@@ -315,52 +301,10 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
315 &bdev->data[i]); 301 &bdev->data[i]);
316 302
317 return 0; 303 return 0;
318
319err_free_gpio:
320 while (--i >= 0)
321 gpio_free(pdata->buttons[i].gpio);
322
323 input_free_polled_device(poll_dev);
324
325err_free_bdev:
326 kfree(bdev);
327
328err_free_pdata:
329 /* If we have no platform_data, we allocated pdata dynamically. */
330 if (!dev_get_platdata(&pdev->dev))
331 kfree(pdata);
332
333 return error;
334}
335
336static int gpio_keys_polled_remove(struct platform_device *pdev)
337{
338 struct gpio_keys_polled_dev *bdev = platform_get_drvdata(pdev);
339 const struct gpio_keys_platform_data *pdata = bdev->pdata;
340 int i;
341
342 input_unregister_polled_device(bdev->poll_dev);
343
344 for (i = 0; i < pdata->nbuttons; i++)
345 gpio_free(pdata->buttons[i].gpio);
346
347 input_free_polled_device(bdev->poll_dev);
348
349 /*
350 * If we had no platform_data, we allocated pdata dynamically and
351 * must free it here.
352 */
353 if (!dev_get_platdata(&pdev->dev))
354 kfree(pdata);
355
356 kfree(bdev);
357
358 return 0;
359} 304}
360 305
361static struct platform_driver gpio_keys_polled_driver = { 306static struct platform_driver gpio_keys_polled_driver = {
362 .probe = gpio_keys_polled_probe, 307 .probe = gpio_keys_polled_probe,
363 .remove = gpio_keys_polled_remove,
364 .driver = { 308 .driver = {
365 .name = DRV_NAME, 309 .name = DRV_NAME,
366 .owner = THIS_MODULE, 310 .owner = THIS_MODULE,
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index 97ec33572e56..8280cb16260b 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -415,7 +415,7 @@ open_err:
415} 415}
416 416
417#ifdef CONFIG_OF 417#ifdef CONFIG_OF
418static struct of_device_id imx_keypad_of_match[] = { 418static const struct of_device_id imx_keypad_of_match[] = {
419 { .compatible = "fsl,imx21-kpp", }, 419 { .compatible = "fsl,imx21-kpp", },
420 { /* sentinel */ } 420 { /* sentinel */ }
421}; 421};
diff --git a/drivers/input/keyboard/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c
index 69b1f002ff52..0ba4428da24a 100644
--- a/drivers/input/keyboard/jornada680_kbd.c
+++ b/drivers/input/keyboard/jornada680_kbd.c
@@ -16,6 +16,7 @@
16 * published by the Free Software Foundation. 16 * published by the Free Software Foundation.
17 */ 17 */
18 18
19#include <linux/device.h>
19#include <linux/input.h> 20#include <linux/input.h>
20#include <linux/input-polldev.h> 21#include <linux/input-polldev.h>
21#include <linux/interrupt.h> 22#include <linux/interrupt.h>
@@ -185,14 +186,15 @@ static int jornada680kbd_probe(struct platform_device *pdev)
185 struct input_dev *input_dev; 186 struct input_dev *input_dev;
186 int i, error; 187 int i, error;
187 188
188 jornadakbd = kzalloc(sizeof(struct jornadakbd), GFP_KERNEL); 189 jornadakbd = devm_kzalloc(&pdev->dev, sizeof(struct jornadakbd),
190 GFP_KERNEL);
189 if (!jornadakbd) 191 if (!jornadakbd)
190 return -ENOMEM; 192 return -ENOMEM;
191 193
192 poll_dev = input_allocate_polled_device(); 194 poll_dev = devm_input_allocate_polled_device(&pdev->dev);
193 if (!poll_dev) { 195 if (!poll_dev) {
194 error = -ENOMEM; 196 dev_err(&pdev->dev, "failed to allocate polled input device\n");
195 goto failed; 197 return -ENOMEM;
196 } 198 }
197 199
198 platform_set_drvdata(pdev, jornadakbd); 200 platform_set_drvdata(pdev, jornadakbd);
@@ -224,27 +226,10 @@ static int jornada680kbd_probe(struct platform_device *pdev)
224 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 226 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
225 227
226 error = input_register_polled_device(jornadakbd->poll_dev); 228 error = input_register_polled_device(jornadakbd->poll_dev);
227 if (error) 229 if (error) {
228 goto failed; 230 dev_err(&pdev->dev, "failed to register polled input device\n");
229 231 return error;
230 return 0; 232 }
231
232 failed:
233 printk(KERN_ERR "Jornadakbd: failed to register driver, error: %d\n",
234 error);
235 input_free_polled_device(poll_dev);
236 kfree(jornadakbd);
237 return error;
238
239}
240
241static int jornada680kbd_remove(struct platform_device *pdev)
242{
243 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
244
245 input_unregister_polled_device(jornadakbd->poll_dev);
246 input_free_polled_device(jornadakbd->poll_dev);
247 kfree(jornadakbd);
248 233
249 return 0; 234 return 0;
250} 235}
@@ -255,7 +240,6 @@ static struct platform_driver jornada680kbd_driver = {
255 .owner = THIS_MODULE, 240 .owner = THIS_MODULE,
256 }, 241 },
257 .probe = jornada680kbd_probe, 242 .probe = jornada680kbd_probe,
258 .remove = jornada680kbd_remove,
259}; 243};
260module_platform_driver(jornada680kbd_driver); 244module_platform_driver(jornada680kbd_driver);
261 245
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 1da8e0b44b56..375b05ca8e2a 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -147,7 +147,7 @@ static int mcs_touchkey_probe(struct i2c_client *client,
147 } 147 }
148 dev_info(&client->dev, "Firmware version: %d\n", fw_ver); 148 dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
149 149
150 input_dev->name = "MELPAS MCS Touchkey"; 150 input_dev->name = "MELFAS MCS Touchkey";
151 input_dev->id.bustype = BUS_I2C; 151 input_dev->id.bustype = BUS_I2C;
152 input_dev->dev.parent = &client->dev; 152 input_dev->dev.parent = &client->dev;
153 input_dev->evbit[0] = BIT_MASK(EV_KEY); 153 input_dev->evbit[0] = BIT_MASK(EV_KEY);
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index 0400b3f2b4b9..024b7bdffe5b 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -28,11 +28,10 @@
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/input.h> 30#include <linux/input.h>
31#include <linux/input/matrix_keypad.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
32#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
33 34
34#include <linux/platform_data/omap4-keypad.h>
35
36/* OMAP4 registers */ 35/* OMAP4 registers */
37#define OMAP4_KBD_REVISION 0x00 36#define OMAP4_KBD_REVISION 0x00
38#define OMAP4_KBD_SYSCONFIG 0x10 37#define OMAP4_KBD_SYSCONFIG 0x10
@@ -218,7 +217,6 @@ static void omap4_keypad_close(struct input_dev *input)
218 pm_runtime_put_sync(input->dev.parent); 217 pm_runtime_put_sync(input->dev.parent);
219} 218}
220 219
221#ifdef CONFIG_OF
222static int omap4_keypad_parse_dt(struct device *dev, 220static int omap4_keypad_parse_dt(struct device *dev,
223 struct omap4_keypad *keypad_data) 221 struct omap4_keypad *keypad_data)
224{ 222{
@@ -235,20 +233,9 @@ static int omap4_keypad_parse_dt(struct device *dev,
235 233
236 return 0; 234 return 0;
237} 235}
238#else
239static inline int omap4_keypad_parse_dt(struct device *dev,
240 struct omap4_keypad *keypad_data)
241{
242 return -ENOSYS;
243}
244#endif
245 236
246static int omap4_keypad_probe(struct platform_device *pdev) 237static int omap4_keypad_probe(struct platform_device *pdev)
247{ 238{
248 const struct omap4_keypad_platform_data *pdata =
249 dev_get_platdata(&pdev->dev);
250 const struct matrix_keymap_data *keymap_data =
251 pdata ? pdata->keymap_data : NULL;
252 struct omap4_keypad *keypad_data; 239 struct omap4_keypad *keypad_data;
253 struct input_dev *input_dev; 240 struct input_dev *input_dev;
254 struct resource *res; 241 struct resource *res;
@@ -277,14 +264,9 @@ static int omap4_keypad_probe(struct platform_device *pdev)
277 264
278 keypad_data->irq = irq; 265 keypad_data->irq = irq;
279 266
280 if (pdata) { 267 error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
281 keypad_data->rows = pdata->rows; 268 if (error)
282 keypad_data->cols = pdata->cols; 269 return error;
283 } else {
284 error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
285 if (error)
286 return error;
287 }
288 270
289 res = request_mem_region(res->start, resource_size(res), pdev->name); 271 res = request_mem_region(res->start, resource_size(res), pdev->name);
290 if (!res) { 272 if (!res) {
@@ -363,7 +345,7 @@ static int omap4_keypad_probe(struct platform_device *pdev)
363 goto err_free_input; 345 goto err_free_input;
364 } 346 }
365 347
366 error = matrix_keypad_build_keymap(keymap_data, NULL, 348 error = matrix_keypad_build_keymap(NULL, NULL,
367 keypad_data->rows, keypad_data->cols, 349 keypad_data->rows, keypad_data->cols,
368 keypad_data->keymap, input_dev); 350 keypad_data->keymap, input_dev);
369 if (error) { 351 if (error) {
@@ -434,13 +416,11 @@ static int omap4_keypad_remove(struct platform_device *pdev)
434 return 0; 416 return 0;
435} 417}
436 418
437#ifdef CONFIG_OF
438static const struct of_device_id omap_keypad_dt_match[] = { 419static const struct of_device_id omap_keypad_dt_match[] = {
439 { .compatible = "ti,omap4-keypad" }, 420 { .compatible = "ti,omap4-keypad" },
440 {}, 421 {},
441}; 422};
442MODULE_DEVICE_TABLE(of, omap_keypad_dt_match); 423MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
443#endif
444 424
445#ifdef CONFIG_PM_SLEEP 425#ifdef CONFIG_PM_SLEEP
446static int omap4_keypad_suspend(struct device *dev) 426static int omap4_keypad_suspend(struct device *dev)
@@ -482,7 +462,7 @@ static struct platform_driver omap4_keypad_driver = {
482 .name = "omap4-keypad", 462 .name = "omap4-keypad",
483 .owner = THIS_MODULE, 463 .owner = THIS_MODULE,
484 .pm = &omap4_keypad_pm_ops, 464 .pm = &omap4_keypad_pm_ops,
485 .of_match_table = of_match_ptr(omap_keypad_dt_match), 465 .of_match_table = omap_keypad_dt_match,
486 }, 466 },
487}; 467};
488module_platform_driver(omap4_keypad_driver); 468module_platform_driver(omap4_keypad_driver);
diff --git a/drivers/input/keyboard/st-keyscan.c b/drivers/input/keyboard/st-keyscan.c
new file mode 100644
index 000000000000..758b48731415
--- /dev/null
+++ b/drivers/input/keyboard/st-keyscan.c
@@ -0,0 +1,274 @@
1/*
2 * STMicroelectronics Key Scanning driver
3 *
4 * Copyright (c) 2014 STMicroelectonics Ltd.
5 * Author: Stuart Menefy <stuart.menefy@st.com>
6 *
7 * Based on sh_keysc.c, copyright 2008 Magnus Damm
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
17#include <linux/clk.h>
18#include <linux/io.h>
19#include <linux/input/matrix_keypad.h>
20
21#define ST_KEYSCAN_MAXKEYS 16
22
23#define KEYSCAN_CONFIG_OFF 0x0
24#define KEYSCAN_CONFIG_ENABLE 0x1
25#define KEYSCAN_DEBOUNCE_TIME_OFF 0x4
26#define KEYSCAN_MATRIX_STATE_OFF 0x8
27#define KEYSCAN_MATRIX_DIM_OFF 0xc
28#define KEYSCAN_MATRIX_DIM_X_SHIFT 0x0
29#define KEYSCAN_MATRIX_DIM_Y_SHIFT 0x2
30
31struct st_keyscan {
32 void __iomem *base;
33 int irq;
34 struct clk *clk;
35 struct input_dev *input_dev;
36 unsigned long last_state;
37 unsigned int n_rows;
38 unsigned int n_cols;
39 unsigned int debounce_us;
40};
41
42static irqreturn_t keyscan_isr(int irq, void *dev_id)
43{
44 struct st_keyscan *keypad = dev_id;
45 unsigned short *keycode = keypad->input_dev->keycode;
46 unsigned long state, change;
47 int bit_nr;
48
49 state = readl(keypad->base + KEYSCAN_MATRIX_STATE_OFF) & 0xffff;
50 change = keypad->last_state ^ state;
51 keypad->last_state = state;
52
53 for_each_set_bit(bit_nr, &change, BITS_PER_LONG)
54 input_report_key(keypad->input_dev,
55 keycode[bit_nr], state & BIT(bit_nr));
56
57 input_sync(keypad->input_dev);
58
59 return IRQ_HANDLED;
60}
61
62static int keyscan_start(struct st_keyscan *keypad)
63{
64 int error;
65
66 error = clk_enable(keypad->clk);
67 if (error)
68 return error;
69
70 writel(keypad->debounce_us * (clk_get_rate(keypad->clk) / 1000000),
71 keypad->base + KEYSCAN_DEBOUNCE_TIME_OFF);
72
73 writel(((keypad->n_cols - 1) << KEYSCAN_MATRIX_DIM_X_SHIFT) |
74 ((keypad->n_rows - 1) << KEYSCAN_MATRIX_DIM_Y_SHIFT),
75 keypad->base + KEYSCAN_MATRIX_DIM_OFF);
76
77 writel(KEYSCAN_CONFIG_ENABLE, keypad->base + KEYSCAN_CONFIG_OFF);
78
79 return 0;
80}
81
82static void keyscan_stop(struct st_keyscan *keypad)
83{
84 writel(0, keypad->base + KEYSCAN_CONFIG_OFF);
85
86 clk_disable(keypad->clk);
87}
88
89static int keyscan_open(struct input_dev *dev)
90{
91 struct st_keyscan *keypad = input_get_drvdata(dev);
92
93 return keyscan_start(keypad);
94}
95
96static void keyscan_close(struct input_dev *dev)
97{
98 struct st_keyscan *keypad = input_get_drvdata(dev);
99
100 keyscan_stop(keypad);
101}
102
103static int keypad_matrix_key_parse_dt(struct st_keyscan *keypad_data)
104{
105 struct device *dev = keypad_data->input_dev->dev.parent;
106 struct device_node *np = dev->of_node;
107 int error;
108
109 error = matrix_keypad_parse_of_params(dev, &keypad_data->n_rows,
110 &keypad_data->n_cols);
111 if (error) {
112 dev_err(dev, "failed to parse keypad params\n");
113 return error;
114 }
115
116 of_property_read_u32(np, "st,debounce-us", &keypad_data->debounce_us);
117
118 dev_dbg(dev, "n_rows=%d n_col=%d debounce=%d\n",
119 keypad_data->n_rows, keypad_data->n_cols,
120 keypad_data->debounce_us);
121
122 return 0;
123}
124
125static int keyscan_probe(struct platform_device *pdev)
126{
127 struct st_keyscan *keypad_data;
128 struct input_dev *input_dev;
129 struct resource *res;
130 int error;
131
132 if (!pdev->dev.of_node) {
133 dev_err(&pdev->dev, "no DT data present\n");
134 return -EINVAL;
135 }
136
137 keypad_data = devm_kzalloc(&pdev->dev, sizeof(*keypad_data),
138 GFP_KERNEL);
139 if (!keypad_data)
140 return -ENOMEM;
141
142 input_dev = devm_input_allocate_device(&pdev->dev);
143 if (!input_dev) {
144 dev_err(&pdev->dev, "failed to allocate the input device\n");
145 return -ENOMEM;
146 }
147
148 input_dev->name = pdev->name;
149 input_dev->phys = "keyscan-keys/input0";
150 input_dev->dev.parent = &pdev->dev;
151 input_dev->open = keyscan_open;
152 input_dev->close = keyscan_close;
153
154 input_dev->id.bustype = BUS_HOST;
155
156 error = keypad_matrix_key_parse_dt(keypad_data);
157 if (error)
158 return error;
159
160 error = matrix_keypad_build_keymap(NULL, NULL,
161 keypad_data->n_rows,
162 keypad_data->n_cols,
163 NULL, input_dev);
164 if (error) {
165 dev_err(&pdev->dev, "failed to build keymap\n");
166 return error;
167 }
168
169 input_set_drvdata(input_dev, keypad_data);
170
171 keypad_data->input_dev = input_dev;
172
173 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
174 keypad_data->base = devm_ioremap_resource(&pdev->dev, res);
175 if (IS_ERR(keypad_data->base))
176 return PTR_ERR(keypad_data->base);
177
178 keypad_data->clk = devm_clk_get(&pdev->dev, NULL);
179 if (IS_ERR(keypad_data->clk)) {
180 dev_err(&pdev->dev, "cannot get clock\n");
181 return PTR_ERR(keypad_data->clk);
182 }
183
184 error = clk_enable(keypad_data->clk);
185 if (error) {
186 dev_err(&pdev->dev, "failed to enable clock\n");
187 return error;
188 }
189
190 keyscan_stop(keypad_data);
191
192 keypad_data->irq = platform_get_irq(pdev, 0);
193 if (keypad_data->irq < 0) {
194 dev_err(&pdev->dev, "no IRQ specified\n");
195 return -EINVAL;
196 }
197
198 error = devm_request_irq(&pdev->dev, keypad_data->irq, keyscan_isr, 0,
199 pdev->name, keypad_data);
200 if (error) {
201 dev_err(&pdev->dev, "failed to request IRQ\n");
202 return error;
203 }
204
205 error = input_register_device(input_dev);
206 if (error) {
207 dev_err(&pdev->dev, "failed to register input device\n");
208 return error;
209 }
210
211 platform_set_drvdata(pdev, keypad_data);
212
213 device_set_wakeup_capable(&pdev->dev, 1);
214
215 return 0;
216}
217
218static int keyscan_suspend(struct device *dev)
219{
220 struct platform_device *pdev = to_platform_device(dev);
221 struct st_keyscan *keypad = platform_get_drvdata(pdev);
222 struct input_dev *input = keypad->input_dev;
223
224 mutex_lock(&input->mutex);
225
226 if (device_may_wakeup(dev))
227 enable_irq_wake(keypad->irq);
228 else if (input->users)
229 keyscan_stop(keypad);
230
231 mutex_unlock(&input->mutex);
232 return 0;
233}
234
235static int keyscan_resume(struct device *dev)
236{
237 struct platform_device *pdev = to_platform_device(dev);
238 struct st_keyscan *keypad = platform_get_drvdata(pdev);
239 struct input_dev *input = keypad->input_dev;
240 int retval = 0;
241
242 mutex_lock(&input->mutex);
243
244 if (device_may_wakeup(dev))
245 disable_irq_wake(keypad->irq);
246 else if (input->users)
247 retval = keyscan_start(keypad);
248
249 mutex_unlock(&input->mutex);
250 return retval;
251}
252
253static SIMPLE_DEV_PM_OPS(keyscan_dev_pm_ops, keyscan_suspend, keyscan_resume);
254
255static const struct of_device_id keyscan_of_match[] = {
256 { .compatible = "st,sti-keyscan" },
257 { },
258};
259MODULE_DEVICE_TABLE(of, keyscan_of_match);
260
261static struct platform_driver keyscan_device_driver = {
262 .probe = keyscan_probe,
263 .driver = {
264 .name = "st-keyscan",
265 .pm = &keyscan_dev_pm_ops,
266 .of_match_table = of_match_ptr(keyscan_of_match),
267 }
268};
269
270module_platform_driver(keyscan_device_driver);
271
272MODULE_AUTHOR("Stuart Menefy <stuart.menefy@st.com>");
273MODULE_DESCRIPTION("STMicroelectronics keyscan device driver");
274MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c
index 74494a357522..ad7abae69078 100644
--- a/drivers/input/keyboard/tc3589x-keypad.c
+++ b/drivers/input/keyboard/tc3589x-keypad.c
@@ -296,6 +296,65 @@ static void tc3589x_keypad_close(struct input_dev *input)
296 tc3589x_keypad_disable(keypad); 296 tc3589x_keypad_disable(keypad);
297} 297}
298 298
299#ifdef CONFIG_OF
300static const struct tc3589x_keypad_platform_data *
301tc3589x_keypad_of_probe(struct device *dev)
302{
303 struct device_node *np = dev->of_node;
304 struct tc3589x_keypad_platform_data *plat;
305 u32 cols, rows;
306 u32 debounce_ms;
307 int proplen;
308
309 if (!np)
310 return ERR_PTR(-ENODEV);
311
312 plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);
313 if (!plat)
314 return ERR_PTR(-ENOMEM);
315
316 of_property_read_u32(np, "keypad,num-columns", &cols);
317 of_property_read_u32(np, "keypad,num-rows", &rows);
318 plat->kcol = (u8) cols;
319 plat->krow = (u8) rows;
320 if (!plat->krow || !plat->kcol ||
321 plat->krow > TC_KPD_ROWS || plat->kcol > TC_KPD_COLUMNS) {
322 dev_err(dev,
323 "keypad columns/rows not properly specified (%ux%u)\n",
324 plat->kcol, plat->krow);
325 return ERR_PTR(-EINVAL);
326 }
327
328 if (!of_get_property(np, "linux,keymap", &proplen)) {
329 dev_err(dev, "property linux,keymap not found\n");
330 return ERR_PTR(-ENOENT);
331 }
332
333 plat->no_autorepeat = of_property_read_bool(np, "linux,no-autorepeat");
334 plat->enable_wakeup = of_property_read_bool(np, "linux,wakeup");
335
336 /* The custom delay format is ms/16 */
337 of_property_read_u32(np, "debounce-delay-ms", &debounce_ms);
338 if (debounce_ms)
339 plat->debounce_period = debounce_ms * 16;
340 else
341 plat->debounce_period = TC_KPD_DEBOUNCE_PERIOD;
342
343 plat->settle_time = TC_KPD_SETTLE_TIME;
344 /* FIXME: should be property of the IRQ resource? */
345 plat->irqtype = IRQF_TRIGGER_FALLING;
346
347 return plat;
348}
349#else
350static inline const struct tc3589x_keypad_platform_data *
351tc3589x_keypad_of_probe(struct device *dev)
352{
353 return ERR_PTR(-ENODEV);
354}
355#endif
356
357
299static int tc3589x_keypad_probe(struct platform_device *pdev) 358static int tc3589x_keypad_probe(struct platform_device *pdev)
300{ 359{
301 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); 360 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
@@ -306,8 +365,11 @@ static int tc3589x_keypad_probe(struct platform_device *pdev)
306 365
307 plat = tc3589x->pdata->keypad; 366 plat = tc3589x->pdata->keypad;
308 if (!plat) { 367 if (!plat) {
309 dev_err(&pdev->dev, "invalid keypad platform data\n"); 368 plat = tc3589x_keypad_of_probe(&pdev->dev);
310 return -EINVAL; 369 if (IS_ERR(plat)) {
370 dev_err(&pdev->dev, "invalid keypad platform data\n");
371 return PTR_ERR(plat);
372 }
311 } 373 }
312 374
313 irq = platform_get_irq(pdev, 0); 375 irq = platform_get_irq(pdev, 0);