diff options
author | Alek Du <alek.du@intel.com> | 2010-09-01 01:57:30 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-09-01 22:43:15 -0400 |
commit | 36466a1b4585f9a24d5920ff90aa73e3803745cd (patch) | |
tree | 4dba0e6188e88db20b9648b376e637fbb41fee9e | |
parent | 95b7127c1141bddd3cff30415c7d6e656f335a35 (diff) |
Staging: mrst-touchscreen - register platform interface
AC: Reworked to merge with upstream input device work from Dmitry et al.
Signed-off-by: Alek Du <alek.du@intel.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r-- | drivers/staging/mrst-touchscreen/intel-mid-touch.c | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/drivers/staging/mrst-touchscreen/intel-mid-touch.c b/drivers/staging/mrst-touchscreen/intel-mid-touch.c index be7ba7b47591..9333b9e09598 100644 --- a/drivers/staging/mrst-touchscreen/intel-mid-touch.c +++ b/drivers/staging/mrst-touchscreen/intel-mid-touch.c | |||
@@ -32,7 +32,8 @@ | |||
32 | #include <linux/interrupt.h> | 32 | #include <linux/interrupt.h> |
33 | #include <linux/err.h> | 33 | #include <linux/err.h> |
34 | #include <linux/param.h> | 34 | #include <linux/param.h> |
35 | #include <linux/spi/spi.h> | 35 | #include <linux/slab.h> |
36 | #include <linux/platform_device.h> | ||
36 | #include <linux/irq.h> | 37 | #include <linux/irq.h> |
37 | #include <linux/delay.h> | 38 | #include <linux/delay.h> |
38 | #include <asm/intel_scu_ipc.h> | 39 | #include <asm/intel_scu_ipc.h> |
@@ -94,7 +95,7 @@ | |||
94 | 95 | ||
95 | /* Touch screen device structure */ | 96 | /* Touch screen device structure */ |
96 | struct mrstouch_dev { | 97 | struct mrstouch_dev { |
97 | struct spi_device *spi; | 98 | struct device *dev; /* device associated with touch screen */ |
98 | struct input_dev *input; | 99 | struct input_dev *input; |
99 | char phys[32]; | 100 | char phys[32]; |
100 | u16 asr; /* Address selection register */ | 101 | u16 asr; /* Address selection register */ |
@@ -162,7 +163,7 @@ static int mrstouch_nec_adc_read_finish(struct mrstouch_dev *tsdev) | |||
162 | 163 | ||
163 | if (!pendet_enabled) { | 164 | if (!pendet_enabled) { |
164 | if (++retry >= 10) { | 165 | if (++retry >= 10) { |
165 | dev_err(&tsdev->spi->dev, | 166 | dev_err(tsdev->dev, |
166 | "Touch screen disabled.\n"); | 167 | "Touch screen disabled.\n"); |
167 | return -EIO; | 168 | return -EIO; |
168 | } | 169 | } |
@@ -282,7 +283,7 @@ static int mrstouch_nec_adc_read(struct mrstouch_dev *tsdev, | |||
282 | return 0; | 283 | return 0; |
283 | 284 | ||
284 | ipc_error: | 285 | ipc_error: |
285 | dev_err(&tsdev->spi->dev, "ipc error during adc read\n"); | 286 | dev_err(tsdev->dev, "ipc error during adc read\n"); |
286 | return err; | 287 | return err; |
287 | } | 288 | } |
288 | 289 | ||
@@ -341,7 +342,7 @@ static int mrstouch_fs_adc_read_prepare(struct mrstouch_dev *tsdev) | |||
341 | return 0; | 342 | return 0; |
342 | 343 | ||
343 | ipc_error: | 344 | ipc_error: |
344 | dev_err(&tsdev->spi->dev, "ipc error during %s\n", __func__); | 345 | dev_err(tsdev->dev, "ipc error during %s\n", __func__); |
345 | return err; | 346 | return err; |
346 | } | 347 | } |
347 | 348 | ||
@@ -387,7 +388,7 @@ static int mrstouch_fs_adc_read(struct mrstouch_dev *tsdev, | |||
387 | return 0; | 388 | return 0; |
388 | 389 | ||
389 | ipc_error: | 390 | ipc_error: |
390 | dev_err(&tsdev->spi->dev, "ipc error during %s\n", __func__); | 391 | dev_err(tsdev->dev, "ipc error during %s\n", __func__); |
391 | return err; | 392 | return err; |
392 | } | 393 | } |
393 | 394 | ||
@@ -428,7 +429,7 @@ static int mrstouch_fs_adc_read_finish(struct mrstouch_dev *tsdev) | |||
428 | return 0; | 429 | return 0; |
429 | 430 | ||
430 | ipc_error: | 431 | ipc_error: |
431 | dev_err(&tsdev->spi->dev, "ipc error during %s\n", __func__); | 432 | dev_err(tsdev->dev, "ipc error during %s\n", __func__); |
432 | return err; | 433 | return err; |
433 | } | 434 | } |
434 | 435 | ||
@@ -560,7 +561,7 @@ static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev) | |||
560 | 561 | ||
561 | err = mrstouch_read_pmic_id(&tsdev->vendor, &tsdev->rev); | 562 | err = mrstouch_read_pmic_id(&tsdev->vendor, &tsdev->rev); |
562 | if (err) { | 563 | if (err) { |
563 | dev_err(&tsdev->spi->dev, "Unable to read PMIC id\n"); | 564 | dev_err(tsdev->dev, "Unable to read PMIC id\n"); |
564 | return err; | 565 | return err; |
565 | } | 566 | } |
566 | 567 | ||
@@ -579,14 +580,14 @@ static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev) | |||
579 | break; | 580 | break; |
580 | 581 | ||
581 | default: | 582 | default: |
582 | dev_err(&tsdev->spi->dev, | 583 | dev_err(tsdev->dev, |
583 | "Unsupported touchscreen: %d\n", tsdev->vendor); | 584 | "Unsupported touchscreen: %d\n", tsdev->vendor); |
584 | return -ENXIO; | 585 | return -ENXIO; |
585 | } | 586 | } |
586 | 587 | ||
587 | start = mrstouch_chan_parse(tsdev); | 588 | start = mrstouch_chan_parse(tsdev); |
588 | if (start < 0) { | 589 | if (start < 0) { |
589 | dev_err(&tsdev->spi->dev, "Unable to parse channels\n"); | 590 | dev_err(tsdev->dev, "Unable to parse channels\n"); |
590 | return start; | 591 | return start; |
591 | } | 592 | } |
592 | 593 | ||
@@ -627,41 +628,43 @@ static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev) | |||
627 | 628 | ||
628 | 629 | ||
629 | /* Probe function for touch screen driver */ | 630 | /* Probe function for touch screen driver */ |
630 | static int __devinit mrstouch_probe(struct spi_device *spi) | 631 | static int __devinit mrstouch_probe(struct platform_device *pdev) |
631 | { | 632 | { |
632 | struct mrstouch_dev *tsdev; | 633 | struct mrstouch_dev *tsdev; |
633 | struct input_dev *input; | 634 | struct input_dev *input; |
634 | int err; | 635 | int err; |
636 | int irq; | ||
635 | 637 | ||
636 | if (!spi->irq) { | 638 | irq = platform_get_irq(pdev, 0); |
637 | dev_err(&spi->dev, "no interrupt assigned\n"); | 639 | if (irq < 0) { |
640 | dev_err(&pdev->dev, "no interrupt assigned\n"); | ||
638 | return -EINVAL; | 641 | return -EINVAL; |
639 | } | 642 | } |
640 | 643 | ||
641 | tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL); | 644 | tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL); |
642 | input = input_allocate_device(); | 645 | input = input_allocate_device(); |
643 | if (!tsdev || !input) { | 646 | if (!tsdev || !input) { |
644 | dev_err(&spi->dev, "unable to allocate memory\n"); | 647 | dev_err(&pdev->dev, "unable to allocate memory\n"); |
645 | err = -ENOMEM; | 648 | err = -ENOMEM; |
646 | goto err_free_mem; | 649 | goto err_free_mem; |
647 | } | 650 | } |
648 | 651 | ||
649 | tsdev->spi = spi; | 652 | tsdev->dev = &pdev->dev; |
650 | tsdev->input = input; | 653 | tsdev->input = input; |
651 | tsdev->irq = spi->irq; | 654 | tsdev->irq = irq; |
652 | 655 | ||
653 | snprintf(tsdev->phys, sizeof(tsdev->phys), | 656 | snprintf(tsdev->phys, sizeof(tsdev->phys), |
654 | "%s/input0", dev_name(&spi->dev)); | 657 | "%s/input0", dev_name(tsdev->dev)); |
655 | 658 | ||
656 | err = mrstouch_adc_init(tsdev); | 659 | err = mrstouch_adc_init(tsdev); |
657 | if (err) { | 660 | if (err) { |
658 | dev_err(&spi->dev, "ADC initialization failed\n"); | 661 | dev_err(&pdev->dev, "ADC initialization failed\n"); |
659 | goto err_free_mem; | 662 | goto err_free_mem; |
660 | } | 663 | } |
661 | 664 | ||
662 | input->name = "mrst_touchscreen"; | 665 | input->name = "mrst_touchscreen"; |
663 | input->phys = tsdev->phys; | 666 | input->phys = tsdev->phys; |
664 | input->dev.parent = &spi->dev; | 667 | input->dev.parent = tsdev->dev; |
665 | 668 | ||
666 | input->id.vendor = tsdev->vendor; | 669 | input->id.vendor = tsdev->vendor; |
667 | input->id.version = tsdev->rev; | 670 | input->id.version = tsdev->rev; |
@@ -679,17 +682,17 @@ static int __devinit mrstouch_probe(struct spi_device *spi) | |||
679 | err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq, | 682 | err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq, |
680 | 0, "mrstouch", tsdev); | 683 | 0, "mrstouch", tsdev); |
681 | if (err) { | 684 | if (err) { |
682 | dev_err(&tsdev->spi->dev, "unable to allocate irq\n"); | 685 | dev_err(tsdev->dev, "unable to allocate irq\n"); |
683 | goto err_free_mem; | 686 | goto err_free_mem; |
684 | } | 687 | } |
685 | 688 | ||
686 | err = input_register_device(tsdev->input); | 689 | err = input_register_device(tsdev->input); |
687 | if (err) { | 690 | if (err) { |
688 | dev_err(&tsdev->spi->dev, "unable to register input device\n"); | 691 | dev_err(tsdev->dev, "unable to register input device\n"); |
689 | goto err_free_irq; | 692 | goto err_free_irq; |
690 | } | 693 | } |
691 | 694 | ||
692 | spi_set_drvdata(spi, tsdev); | 695 | platform_set_drvdata(pdev, tsdev); |
693 | return 0; | 696 | return 0; |
694 | 697 | ||
695 | err_free_irq: | 698 | err_free_irq: |
@@ -700,38 +703,37 @@ err_free_mem: | |||
700 | return err; | 703 | return err; |
701 | } | 704 | } |
702 | 705 | ||
703 | static int __devexit mrstouch_remove(struct spi_device *spi) | 706 | static int __devexit mrstouch_remove(struct platform_device *pdev) |
704 | { | 707 | { |
705 | struct mrstouch_dev *tsdev = spi_get_drvdata(spi); | 708 | struct mrstouch_dev *tsdev = platform_get_drvdata(pdev); |
706 | 709 | ||
707 | free_irq(tsdev->irq, tsdev); | 710 | free_irq(tsdev->irq, tsdev); |
708 | input_unregister_device(tsdev->input); | 711 | input_unregister_device(tsdev->input); |
709 | kfree(tsdev); | 712 | kfree(tsdev); |
710 | 713 | ||
711 | spi_set_drvdata(spi, NULL); | 714 | platform_set_drvdata(pdev, NULL); |
712 | 715 | ||
713 | return 0; | 716 | return 0; |
714 | } | 717 | } |
715 | 718 | ||
716 | static struct spi_driver mrstouch_driver = { | 719 | static struct platform_driver mrstouch_driver = { |
717 | .driver = { | 720 | .driver = { |
718 | .name = "pmic_touch", | 721 | .name = "pmic_touch", |
719 | .bus = &spi_bus_type, | 722 | .owner = THIS_MODULE, |
720 | .owner = THIS_MODULE, | ||
721 | }, | 723 | }, |
722 | .probe = mrstouch_probe, | 724 | .probe = mrstouch_probe, |
723 | .remove = __devexit_p(mrstouch_remove), | 725 | .remove = __devexit_p(mrstouch_remove), |
724 | }; | 726 | }; |
725 | 727 | ||
726 | static int __init mrstouch_init(void) | 728 | static int __init mrstouch_init(void) |
727 | { | 729 | { |
728 | return spi_register_driver(&mrstouch_driver); | 730 | return platform_driver_register(&mrstouch_driver); |
729 | } | 731 | } |
730 | module_init(mrstouch_init); | 732 | module_init(mrstouch_init); |
731 | 733 | ||
732 | static void __exit mrstouch_exit(void) | 734 | static void __exit mrstouch_exit(void) |
733 | { | 735 | { |
734 | spi_unregister_driver(&mrstouch_driver); | 736 | platform_driver_unregister(&mrstouch_driver); |
735 | } | 737 | } |
736 | module_exit(mrstouch_exit); | 738 | module_exit(mrstouch_exit); |
737 | 739 | ||