diff options
author | Robert Jarzmik <robert.jarzmik@free.fr> | 2017-09-13 15:37:16 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-09-19 12:04:54 -0400 |
commit | c72f61e7407335dfa5fe5947827777b1429cd883 (patch) | |
tree | b785c776b547766e1ffb868ebf2ab57189300769 | |
parent | 2bd6bf03f4c1c59381d62c61d03f6cc3fe71f66e (diff) |
Input: wm97xx: split out touchscreen registering
wm97xx-core does several things in it initialization :
- touchscreen input device setup
- battery device creation
As the wm97xx is actually a multi-function device handling an audio
codec, a touchscreen, a gpio block and an ADC, reshape the probing to
isolate what is truly input/touchscreen specific from the remaining
part.
This is only code shuffling, there is no functional change.
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/input/touchscreen/wm97xx-core.c | 196 |
1 files changed, 115 insertions, 81 deletions
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c index c9d1c91e1887..39869ffdc4fa 100644 --- a/drivers/input/touchscreen/wm97xx-core.c +++ b/drivers/input/touchscreen/wm97xx-core.c | |||
@@ -581,27 +581,85 @@ static void wm97xx_ts_input_close(struct input_dev *idev) | |||
581 | wm->codec->acc_enable(wm, 0); | 581 | wm->codec->acc_enable(wm, 0); |
582 | } | 582 | } |
583 | 583 | ||
584 | static int wm97xx_probe(struct device *dev) | 584 | static int wm97xx_register_touch(struct wm97xx *wm) |
585 | { | 585 | { |
586 | struct wm97xx *wm; | 586 | struct wm97xx_pdata *pdata = dev_get_platdata(wm->dev); |
587 | struct wm97xx_pdata *pdata = dev_get_platdata(dev); | 587 | int ret; |
588 | int ret = 0, id = 0; | ||
589 | 588 | ||
590 | wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL); | 589 | wm->input_dev = devm_input_allocate_device(wm->dev); |
591 | if (!wm) | 590 | if (wm->input_dev == NULL) |
592 | return -ENOMEM; | 591 | return -ENOMEM; |
593 | mutex_init(&wm->codec_mutex); | ||
594 | 592 | ||
595 | wm->dev = dev; | 593 | /* set up touch configuration */ |
596 | dev_set_drvdata(dev, wm); | 594 | wm->input_dev->name = "wm97xx touchscreen"; |
597 | wm->ac97 = to_ac97_t(dev); | 595 | wm->input_dev->phys = "wm97xx"; |
596 | wm->input_dev->open = wm97xx_ts_input_open; | ||
597 | wm->input_dev->close = wm97xx_ts_input_close; | ||
598 | |||
599 | __set_bit(EV_ABS, wm->input_dev->evbit); | ||
600 | __set_bit(EV_KEY, wm->input_dev->evbit); | ||
601 | __set_bit(BTN_TOUCH, wm->input_dev->keybit); | ||
602 | |||
603 | input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1], | ||
604 | abs_x[2], 0); | ||
605 | input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1], | ||
606 | abs_y[2], 0); | ||
607 | input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1], | ||
608 | abs_p[2], 0); | ||
609 | |||
610 | input_set_drvdata(wm->input_dev, wm); | ||
611 | wm->input_dev->dev.parent = wm->dev; | ||
612 | |||
613 | ret = input_register_device(wm->input_dev); | ||
614 | if (ret) | ||
615 | return ret; | ||
616 | |||
617 | /* | ||
618 | * register our extended touch device (for machine specific | ||
619 | * extensions) | ||
620 | */ | ||
621 | wm->touch_dev = platform_device_alloc("wm97xx-touch", -1); | ||
622 | if (!wm->touch_dev) { | ||
623 | ret = -ENOMEM; | ||
624 | goto touch_err; | ||
625 | } | ||
626 | platform_set_drvdata(wm->touch_dev, wm); | ||
627 | wm->touch_dev->dev.parent = wm->dev; | ||
628 | wm->touch_dev->dev.platform_data = pdata; | ||
629 | ret = platform_device_add(wm->touch_dev); | ||
630 | if (ret < 0) | ||
631 | goto touch_reg_err; | ||
632 | |||
633 | return 0; | ||
634 | touch_reg_err: | ||
635 | platform_device_put(wm->touch_dev); | ||
636 | touch_err: | ||
637 | input_unregister_device(wm->input_dev); | ||
638 | wm->input_dev = NULL; | ||
639 | |||
640 | return ret; | ||
641 | } | ||
642 | |||
643 | static void wm97xx_unregister_touch(struct wm97xx *wm) | ||
644 | { | ||
645 | platform_device_unregister(wm->touch_dev); | ||
646 | input_unregister_device(wm->input_dev); | ||
647 | wm->input_dev = NULL; | ||
648 | } | ||
649 | |||
650 | static int _wm97xx_probe(struct wm97xx *wm) | ||
651 | { | ||
652 | int id = 0; | ||
653 | |||
654 | mutex_init(&wm->codec_mutex); | ||
655 | dev_set_drvdata(wm->dev, wm); | ||
598 | 656 | ||
599 | /* check that we have a supported codec */ | 657 | /* check that we have a supported codec */ |
600 | id = wm97xx_reg_read(wm, AC97_VENDOR_ID1); | 658 | id = wm97xx_reg_read(wm, AC97_VENDOR_ID1); |
601 | if (id != WM97XX_ID1) { | 659 | if (id != WM97XX_ID1) { |
602 | dev_err(dev, "Device with vendor %04x is not a wm97xx\n", id); | 660 | dev_err(wm->dev, |
603 | ret = -ENODEV; | 661 | "Device with vendor %04x is not a wm97xx\n", id); |
604 | goto alloc_err; | 662 | return -ENODEV; |
605 | } | 663 | } |
606 | 664 | ||
607 | wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); | 665 | wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); |
@@ -629,8 +687,7 @@ static int wm97xx_probe(struct device *dev) | |||
629 | default: | 687 | default: |
630 | dev_err(wm->dev, "Support for wm97%02x not compiled in.\n", | 688 | dev_err(wm->dev, "Support for wm97%02x not compiled in.\n", |
631 | wm->id & 0xff); | 689 | wm->id & 0xff); |
632 | ret = -ENODEV; | 690 | return -ENODEV; |
633 | goto alloc_err; | ||
634 | } | 691 | } |
635 | 692 | ||
636 | /* set up physical characteristics */ | 693 | /* set up physical characteristics */ |
@@ -644,79 +701,58 @@ static int wm97xx_probe(struct device *dev) | |||
644 | wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); | 701 | wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); |
645 | wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); | 702 | wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); |
646 | 703 | ||
647 | wm->input_dev = input_allocate_device(); | 704 | return wm97xx_register_touch(wm); |
648 | if (wm->input_dev == NULL) { | 705 | } |
649 | ret = -ENOMEM; | ||
650 | goto alloc_err; | ||
651 | } | ||
652 | |||
653 | /* set up touch configuration */ | ||
654 | wm->input_dev->name = "wm97xx touchscreen"; | ||
655 | wm->input_dev->phys = "wm97xx"; | ||
656 | wm->input_dev->open = wm97xx_ts_input_open; | ||
657 | wm->input_dev->close = wm97xx_ts_input_close; | ||
658 | |||
659 | __set_bit(EV_ABS, wm->input_dev->evbit); | ||
660 | __set_bit(EV_KEY, wm->input_dev->evbit); | ||
661 | __set_bit(BTN_TOUCH, wm->input_dev->keybit); | ||
662 | |||
663 | input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1], | ||
664 | abs_x[2], 0); | ||
665 | input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1], | ||
666 | abs_y[2], 0); | ||
667 | input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1], | ||
668 | abs_p[2], 0); | ||
669 | 706 | ||
670 | input_set_drvdata(wm->input_dev, wm); | 707 | static void wm97xx_remove_battery(struct wm97xx *wm) |
671 | wm->input_dev->dev.parent = dev; | 708 | { |
709 | platform_device_unregister(wm->battery_dev); | ||
710 | } | ||
672 | 711 | ||
673 | ret = input_register_device(wm->input_dev); | 712 | static int wm97xx_add_battery(struct wm97xx *wm, |
674 | if (ret < 0) | 713 | struct wm97xx_batt_pdata *pdata) |
675 | goto dev_alloc_err; | 714 | { |
715 | int ret; | ||
676 | 716 | ||
677 | /* register our battery device */ | ||
678 | wm->battery_dev = platform_device_alloc("wm97xx-battery", -1); | 717 | wm->battery_dev = platform_device_alloc("wm97xx-battery", -1); |
679 | if (!wm->battery_dev) { | 718 | if (!wm->battery_dev) |
680 | ret = -ENOMEM; | 719 | return -ENOMEM; |
681 | goto batt_err; | 720 | |
682 | } | ||
683 | platform_set_drvdata(wm->battery_dev, wm); | 721 | platform_set_drvdata(wm->battery_dev, wm); |
684 | wm->battery_dev->dev.parent = dev; | 722 | wm->battery_dev->dev.parent = wm->dev; |
685 | wm->battery_dev->dev.platform_data = pdata ? pdata->batt_pdata : NULL; | 723 | wm->battery_dev->dev.platform_data = pdata; |
686 | ret = platform_device_add(wm->battery_dev); | 724 | ret = platform_device_add(wm->battery_dev); |
687 | if (ret < 0) | 725 | if (ret) |
688 | goto batt_reg_err; | 726 | platform_device_put(wm->battery_dev); |
689 | 727 | ||
690 | /* register our extended touch device (for machine specific | 728 | return ret; |
691 | * extensions) */ | 729 | } |
692 | wm->touch_dev = platform_device_alloc("wm97xx-touch", -1); | 730 | |
693 | if (!wm->touch_dev) { | 731 | static int wm97xx_probe(struct device *dev) |
694 | ret = -ENOMEM; | 732 | { |
695 | goto touch_err; | 733 | struct wm97xx *wm; |
696 | } | 734 | int ret; |
697 | platform_set_drvdata(wm->touch_dev, wm); | 735 | struct wm97xx_pdata *pdata = dev_get_platdata(dev); |
698 | wm->touch_dev->dev.parent = dev; | 736 | |
699 | wm->touch_dev->dev.platform_data = pdata; | 737 | wm = devm_kzalloc(dev, sizeof(struct wm97xx), GFP_KERNEL); |
700 | ret = platform_device_add(wm->touch_dev); | 738 | if (!wm) |
739 | return -ENOMEM; | ||
740 | |||
741 | wm->dev = dev; | ||
742 | wm->ac97 = to_ac97_t(dev); | ||
743 | |||
744 | ret = _wm97xx_probe(wm); | ||
745 | if (ret) | ||
746 | return ret; | ||
747 | |||
748 | ret = wm97xx_add_battery(wm, pdata ? pdata->batt_pdata : NULL); | ||
701 | if (ret < 0) | 749 | if (ret < 0) |
702 | goto touch_reg_err; | 750 | goto batt_err; |
703 | 751 | ||
704 | return ret; | 752 | return ret; |
705 | 753 | ||
706 | touch_reg_err: | 754 | batt_err: |
707 | platform_device_put(wm->touch_dev); | 755 | wm97xx_unregister_touch(wm); |
708 | touch_err: | ||
709 | platform_device_del(wm->battery_dev); | ||
710 | batt_reg_err: | ||
711 | platform_device_put(wm->battery_dev); | ||
712 | batt_err: | ||
713 | input_unregister_device(wm->input_dev); | ||
714 | wm->input_dev = NULL; | ||
715 | dev_alloc_err: | ||
716 | input_free_device(wm->input_dev); | ||
717 | alloc_err: | ||
718 | kfree(wm); | ||
719 | |||
720 | return ret; | 756 | return ret; |
721 | } | 757 | } |
722 | 758 | ||
@@ -724,10 +760,8 @@ static int wm97xx_remove(struct device *dev) | |||
724 | { | 760 | { |
725 | struct wm97xx *wm = dev_get_drvdata(dev); | 761 | struct wm97xx *wm = dev_get_drvdata(dev); |
726 | 762 | ||
727 | platform_device_unregister(wm->battery_dev); | 763 | wm97xx_remove_battery(wm); |
728 | platform_device_unregister(wm->touch_dev); | 764 | wm97xx_unregister_touch(wm); |
729 | input_unregister_device(wm->input_dev); | ||
730 | kfree(wm); | ||
731 | 765 | ||
732 | return 0; | 766 | return 0; |
733 | } | 767 | } |