summaryrefslogtreecommitdiffstats
path: root/sound/drivers
diff options
context:
space:
mode:
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>2016-02-17 07:56:27 -0500
committerTakashi Iwai <tiwai@suse.de>2016-02-18 05:19:15 -0500
commite6a1b7e88046055989b8b59c1d648fda4e606f34 (patch)
tree13970d9a80a924e72b279e550b550b098357b23a /sound/drivers
parentcbaaee80e1518573f3ef8809187340b094da583c (diff)
ALSA: portman2x4 - use new parport device model
Modify portman driver to use the new parallel port device model. The advantage of using the device model is that the device gets binded to the hardware, we get the feature of hotplug, we can bind/unbind the driver at runtime. The changes are in the way the driver gets registered with the parallel port subsystem and the temporary device to probe portman card is removed and portman_probe() is used in the probe callback. Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/drivers')
-rw-r--r--sound/drivers/portman2x4.c93
1 files changed, 42 insertions, 51 deletions
diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
index 464385a480e4..362533fceec7 100644
--- a/sound/drivers/portman2x4.c
+++ b/sound/drivers/portman2x4.c
@@ -83,8 +83,6 @@ struct portman {
83 struct snd_card *card; 83 struct snd_card *card;
84 struct snd_rawmidi *rmidi; 84 struct snd_rawmidi *rmidi;
85 struct pardevice *pardev; 85 struct pardevice *pardev;
86 int pardev_claimed;
87
88 int open_count; 86 int open_count;
89 int mode[PORTMAN_NUM_INPUT_PORTS]; 87 int mode[PORTMAN_NUM_INPUT_PORTS];
90 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS]; 88 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
@@ -648,30 +646,6 @@ static void snd_portman_interrupt(void *userdata)
648 spin_unlock(&pm->reg_lock); 646 spin_unlock(&pm->reg_lock);
649} 647}
650 648
651static int snd_portman_probe_port(struct parport *p)
652{
653 struct pardevice *pardev;
654 int res;
655
656 pardev = parport_register_device(p, DRIVER_NAME,
657 NULL, NULL, NULL,
658 0, NULL);
659 if (!pardev)
660 return -EIO;
661
662 if (parport_claim(pardev)) {
663 parport_unregister_device(pardev);
664 return -EIO;
665 }
666
667 res = portman_probe(p);
668
669 parport_release(pardev);
670 parport_unregister_device(pardev);
671
672 return res ? -EIO : 0;
673}
674
675static void snd_portman_attach(struct parport *p) 649static void snd_portman_attach(struct parport *p)
676{ 650{
677 struct platform_device *device; 651 struct platform_device *device;
@@ -705,10 +679,20 @@ static void snd_portman_detach(struct parport *p)
705 /* nothing to do here */ 679 /* nothing to do here */
706} 680}
707 681
682static int snd_portman_dev_probe(struct pardevice *pardev)
683{
684 if (strcmp(pardev->name, DRIVER_NAME))
685 return -ENODEV;
686
687 return 0;
688}
689
708static struct parport_driver portman_parport_driver = { 690static struct parport_driver portman_parport_driver = {
709 .name = "portman2x4", 691 .name = "portman2x4",
710 .attach = snd_portman_attach, 692 .probe = snd_portman_dev_probe,
711 .detach = snd_portman_detach 693 .match_port = snd_portman_attach,
694 .detach = snd_portman_detach,
695 .devmodel = true,
712}; 696};
713 697
714/********************************************************************* 698/*********************************************************************
@@ -720,8 +704,7 @@ static void snd_portman_card_private_free(struct snd_card *card)
720 struct pardevice *pardev = pm->pardev; 704 struct pardevice *pardev = pm->pardev;
721 705
722 if (pardev) { 706 if (pardev) {
723 if (pm->pardev_claimed) 707 parport_release(pardev);
724 parport_release(pardev);
725 parport_unregister_device(pardev); 708 parport_unregister_device(pardev);
726 } 709 }
727 710
@@ -736,6 +719,12 @@ static int snd_portman_probe(struct platform_device *pdev)
736 struct snd_card *card = NULL; 719 struct snd_card *card = NULL;
737 struct portman *pm = NULL; 720 struct portman *pm = NULL;
738 int err; 721 int err;
722 struct pardev_cb portman_cb = {
723 .preempt = NULL,
724 .wakeup = NULL,
725 .irq_func = snd_portman_interrupt, /* ISR */
726 .flags = PARPORT_DEV_EXCL, /* flags */
727 };
739 728
740 p = platform_get_drvdata(pdev); 729 p = platform_get_drvdata(pdev);
741 platform_set_drvdata(pdev, NULL); 730 platform_set_drvdata(pdev, NULL);
@@ -745,9 +734,6 @@ static int snd_portman_probe(struct platform_device *pdev)
745 if (!enable[dev]) 734 if (!enable[dev])
746 return -ENOENT; 735 return -ENOENT;
747 736
748 if ((err = snd_portman_probe_port(p)) < 0)
749 return err;
750
751 err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE, 737 err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE,
752 0, &card); 738 0, &card);
753 if (err < 0) { 739 if (err < 0) {
@@ -759,23 +745,32 @@ static int snd_portman_probe(struct platform_device *pdev)
759 sprintf(card->longname, "%s at 0x%lx, irq %i", 745 sprintf(card->longname, "%s at 0x%lx, irq %i",
760 card->shortname, p->base, p->irq); 746 card->shortname, p->base, p->irq);
761 747
762 pardev = parport_register_device(p, /* port */ 748 portman_cb.private = card; /* private */
763 DRIVER_NAME, /* name */ 749 pardev = parport_register_dev_model(p, /* port */
764 NULL, /* preempt */ 750 DRIVER_NAME, /* name */
765 NULL, /* wakeup */ 751 &portman_cb, /* callbacks */
766 snd_portman_interrupt, /* ISR */ 752 pdev->id); /* device number */
767 PARPORT_DEV_EXCL, /* flags */
768 (void *)card); /* private */
769 if (pardev == NULL) { 753 if (pardev == NULL) {
770 snd_printd("Cannot register pardevice\n"); 754 snd_printd("Cannot register pardevice\n");
771 err = -EIO; 755 err = -EIO;
772 goto __err; 756 goto __err;
773 } 757 }
774 758
759 /* claim parport */
760 if (parport_claim(pardev)) {
761 snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base);
762 err = -EIO;
763 goto free_pardev;
764 }
765 err = portman_probe(p);
766 if (err) {
767 err = -EIO;
768 goto release_pardev;
769 }
770
775 if ((err = portman_create(card, pardev, &pm)) < 0) { 771 if ((err = portman_create(card, pardev, &pm)) < 0) {
776 snd_printd("Cannot create main component\n"); 772 snd_printd("Cannot create main component\n");
777 parport_unregister_device(pardev); 773 goto release_pardev;
778 goto __err;
779 } 774 }
780 card->private_data = pm; 775 card->private_data = pm;
781 card->private_free = snd_portman_card_private_free; 776 card->private_free = snd_portman_card_private_free;
@@ -785,14 +780,6 @@ static int snd_portman_probe(struct platform_device *pdev)
785 goto __err; 780 goto __err;
786 } 781 }
787 782
788 /* claim parport */
789 if (parport_claim(pardev)) {
790 snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base);
791 err = -EIO;
792 goto __err;
793 }
794 pm->pardev_claimed = 1;
795
796 /* init device */ 783 /* init device */
797 if ((err = portman_device_init(pm)) < 0) 784 if ((err = portman_device_init(pm)) < 0)
798 goto __err; 785 goto __err;
@@ -808,6 +795,10 @@ static int snd_portman_probe(struct platform_device *pdev)
808 snd_printk(KERN_INFO "Portman 2x4 on 0x%lx\n", p->base); 795 snd_printk(KERN_INFO "Portman 2x4 on 0x%lx\n", p->base);
809 return 0; 796 return 0;
810 797
798release_pardev:
799 parport_release(pardev);
800free_pardev:
801 parport_unregister_device(pardev);
811__err: 802__err:
812 snd_card_free(card); 803 snd_card_free(card);
813 return err; 804 return err;