diff options
author | Krzysztof Helt <krzysztof.h1@wp.pl> | 2010-05-09 14:35:44 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2010-05-10 03:48:59 -0400 |
commit | 396fa8272601c3d488cb8391c3962a7ee552afd0 (patch) | |
tree | 6ef9af15019a00f6a81243c458ca792247a07869 /sound/isa/es1688 | |
parent | 02a2ad40295fc8862457b469b3b698d8ece3c72a (diff) |
ALSA: es1688: allocate snd_es1688 structure as a part of snd_card structure
Allocate the snd_es1688 during the snd_card allocation.
This allows to remove the card pointer from the snd_es1688 structure.
Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/isa/es1688')
-rw-r--r-- | sound/isa/es1688/es1688.c | 23 | ||||
-rw-r--r-- | sound/isa/es1688/es1688_lib.c | 44 |
2 files changed, 27 insertions, 40 deletions
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c index 07df201ed8fa..281679493fb4 100644 --- a/sound/isa/es1688/es1688.c +++ b/sound/isa/es1688/es1688.c | |||
@@ -79,8 +79,8 @@ static int __devinit snd_es1688_match(struct device *dev, unsigned int n) | |||
79 | return enable[n]; | 79 | return enable[n]; |
80 | } | 80 | } |
81 | 81 | ||
82 | static int __devinit snd_es1688_legacy_create(struct snd_card *card, | 82 | static int __devinit snd_es1688_legacy_create(struct snd_card *card, |
83 | struct device *dev, unsigned int n, struct snd_es1688 **rchip) | 83 | struct snd_es1688 *chip, struct device *dev, unsigned int n) |
84 | { | 84 | { |
85 | static long possible_ports[] = {0x220, 0x240, 0x260}; | 85 | static long possible_ports[] = {0x220, 0x240, 0x260}; |
86 | static int possible_irqs[] = {5, 9, 10, 7, -1}; | 86 | static int possible_irqs[] = {5, 9, 10, 7, -1}; |
@@ -104,14 +104,14 @@ static int __devinit snd_es1688_legacy_create(struct snd_card *card, | |||
104 | } | 104 | } |
105 | 105 | ||
106 | if (port[n] != SNDRV_AUTO_PORT) | 106 | if (port[n] != SNDRV_AUTO_PORT) |
107 | return snd_es1688_create(card, port[n], mpu_port[n], irq[n], | 107 | return snd_es1688_create(card, chip, port[n], mpu_port[n], |
108 | mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip); | 108 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
109 | 109 | ||
110 | i = 0; | 110 | i = 0; |
111 | do { | 111 | do { |
112 | port[n] = possible_ports[i]; | 112 | port[n] = possible_ports[i]; |
113 | error = snd_es1688_create(card, port[n], mpu_port[n], irq[n], | 113 | error = snd_es1688_create(card, chip, port[n], mpu_port[n], |
114 | mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip); | 114 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
115 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); | 115 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); |
116 | 116 | ||
117 | return error; | 117 | return error; |
@@ -125,19 +125,22 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n) | |||
125 | struct snd_pcm *pcm; | 125 | struct snd_pcm *pcm; |
126 | int error; | 126 | int error; |
127 | 127 | ||
128 | error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); | 128 | error = snd_card_create(index[n], id[n], THIS_MODULE, |
129 | sizeof(struct snd_es1688), &card); | ||
129 | if (error < 0) | 130 | if (error < 0) |
130 | return error; | 131 | return error; |
131 | 132 | ||
132 | error = snd_es1688_legacy_create(card, dev, n, &chip); | 133 | chip = card->private_data; |
134 | |||
135 | error = snd_es1688_legacy_create(card, chip, dev, n); | ||
133 | if (error < 0) | 136 | if (error < 0) |
134 | goto out; | 137 | goto out; |
135 | 138 | ||
136 | error = snd_es1688_pcm(chip, 0, &pcm); | 139 | error = snd_es1688_pcm(card, chip, 0, &pcm); |
137 | if (error < 0) | 140 | if (error < 0) |
138 | goto out; | 141 | goto out; |
139 | 142 | ||
140 | error = snd_es1688_mixer(chip); | 143 | error = snd_es1688_mixer(card, chip); |
141 | if (error < 0) | 144 | if (error < 0) |
142 | goto out; | 145 | goto out; |
143 | 146 | ||
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c index c76bb00c9d15..fdd440417bf0 100644 --- a/sound/isa/es1688/es1688_lib.c +++ b/sound/isa/es1688/es1688_lib.c | |||
@@ -620,7 +620,6 @@ static int snd_es1688_free(struct snd_es1688 *chip) | |||
620 | disable_dma(chip->dma8); | 620 | disable_dma(chip->dma8); |
621 | free_dma(chip->dma8); | 621 | free_dma(chip->dma8); |
622 | } | 622 | } |
623 | kfree(chip); | ||
624 | return 0; | 623 | return 0; |
625 | } | 624 | } |
626 | 625 | ||
@@ -638,23 +637,20 @@ static const char *snd_es1688_chip_id(struct snd_es1688 *chip) | |||
638 | } | 637 | } |
639 | 638 | ||
640 | int snd_es1688_create(struct snd_card *card, | 639 | int snd_es1688_create(struct snd_card *card, |
640 | struct snd_es1688 *chip, | ||
641 | unsigned long port, | 641 | unsigned long port, |
642 | unsigned long mpu_port, | 642 | unsigned long mpu_port, |
643 | int irq, | 643 | int irq, |
644 | int mpu_irq, | 644 | int mpu_irq, |
645 | int dma8, | 645 | int dma8, |
646 | unsigned short hardware, | 646 | unsigned short hardware) |
647 | struct snd_es1688 **rchip) | ||
648 | { | 647 | { |
649 | static struct snd_device_ops ops = { | 648 | static struct snd_device_ops ops = { |
650 | .dev_free = snd_es1688_dev_free, | 649 | .dev_free = snd_es1688_dev_free, |
651 | }; | 650 | }; |
652 | 651 | ||
653 | struct snd_es1688 *chip; | ||
654 | int err; | 652 | int err; |
655 | 653 | ||
656 | *rchip = NULL; | ||
657 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
658 | if (chip == NULL) | 654 | if (chip == NULL) |
659 | return -ENOMEM; | 655 | return -ENOMEM; |
660 | chip->irq = -1; | 656 | chip->irq = -1; |
@@ -662,25 +658,21 @@ int snd_es1688_create(struct snd_card *card, | |||
662 | 658 | ||
663 | if ((chip->res_port = request_region(port + 4, 12, "ES1688")) == NULL) { | 659 | if ((chip->res_port = request_region(port + 4, 12, "ES1688")) == NULL) { |
664 | snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4); | 660 | snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4); |
665 | snd_es1688_free(chip); | ||
666 | return -EBUSY; | 661 | return -EBUSY; |
667 | } | 662 | } |
668 | if (request_irq(irq, snd_es1688_interrupt, IRQF_DISABLED, "ES1688", (void *) chip)) { | 663 | if (request_irq(irq, snd_es1688_interrupt, IRQF_DISABLED, "ES1688", (void *) chip)) { |
669 | snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq); | 664 | snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq); |
670 | snd_es1688_free(chip); | ||
671 | return -EBUSY; | 665 | return -EBUSY; |
672 | } | 666 | } |
673 | chip->irq = irq; | 667 | chip->irq = irq; |
674 | if (request_dma(dma8, "ES1688")) { | 668 | if (request_dma(dma8, "ES1688")) { |
675 | snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8); | 669 | snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8); |
676 | snd_es1688_free(chip); | ||
677 | return -EBUSY; | 670 | return -EBUSY; |
678 | } | 671 | } |
679 | chip->dma8 = dma8; | 672 | chip->dma8 = dma8; |
680 | 673 | ||
681 | spin_lock_init(&chip->reg_lock); | 674 | spin_lock_init(&chip->reg_lock); |
682 | spin_lock_init(&chip->mixer_lock); | 675 | spin_lock_init(&chip->mixer_lock); |
683 | chip->card = card; | ||
684 | chip->port = port; | 676 | chip->port = port; |
685 | mpu_port &= ~0x000f; | 677 | mpu_port &= ~0x000f; |
686 | if (mpu_port < 0x300 || mpu_port > 0x330) | 678 | if (mpu_port < 0x300 || mpu_port > 0x330) |
@@ -689,23 +681,16 @@ int snd_es1688_create(struct snd_card *card, | |||
689 | chip->mpu_irq = mpu_irq; | 681 | chip->mpu_irq = mpu_irq; |
690 | chip->hardware = hardware; | 682 | chip->hardware = hardware; |
691 | 683 | ||
692 | if ((err = snd_es1688_probe(chip)) < 0) { | 684 | err = snd_es1688_probe(chip); |
693 | snd_es1688_free(chip); | 685 | if (err < 0) |
694 | return err; | 686 | return err; |
695 | } | ||
696 | if ((err = snd_es1688_init(chip, 1)) < 0) { | ||
697 | snd_es1688_free(chip); | ||
698 | return err; | ||
699 | } | ||
700 | 687 | ||
701 | /* Register device */ | 688 | err = snd_es1688_init(chip, 1); |
702 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { | 689 | if (err < 0) |
703 | snd_es1688_free(chip); | ||
704 | return err; | 690 | return err; |
705 | } | ||
706 | 691 | ||
707 | *rchip = chip; | 692 | /* Register device */ |
708 | return 0; | 693 | return snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
709 | } | 694 | } |
710 | 695 | ||
711 | static struct snd_pcm_ops snd_es1688_playback_ops = { | 696 | static struct snd_pcm_ops snd_es1688_playback_ops = { |
@@ -730,12 +715,14 @@ static struct snd_pcm_ops snd_es1688_capture_ops = { | |||
730 | .pointer = snd_es1688_capture_pointer, | 715 | .pointer = snd_es1688_capture_pointer, |
731 | }; | 716 | }; |
732 | 717 | ||
733 | int snd_es1688_pcm(struct snd_es1688 * chip, int device, struct snd_pcm ** rpcm) | 718 | int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip, |
719 | int device, struct snd_pcm **rpcm) | ||
734 | { | 720 | { |
735 | struct snd_pcm *pcm; | 721 | struct snd_pcm *pcm; |
736 | int err; | 722 | int err; |
737 | 723 | ||
738 | if ((err = snd_pcm_new(chip->card, "ESx688", device, 1, 1, &pcm)) < 0) | 724 | err = snd_pcm_new(card, "ESx688", device, 1, 1, &pcm); |
725 | if (err < 0) | ||
739 | return err; | 726 | return err; |
740 | 727 | ||
741 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops); | 728 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops); |
@@ -1009,18 +996,15 @@ static unsigned char snd_es1688_init_table[][2] = { | |||
1009 | { ES1688_REC_DEV, 0x17 } | 996 | { ES1688_REC_DEV, 0x17 } |
1010 | }; | 997 | }; |
1011 | 998 | ||
1012 | int snd_es1688_mixer(struct snd_es1688 *chip) | 999 | int snd_es1688_mixer(struct snd_card *card, struct snd_es1688 *chip) |
1013 | { | 1000 | { |
1014 | struct snd_card *card; | ||
1015 | unsigned int idx; | 1001 | unsigned int idx; |
1016 | int err; | 1002 | int err; |
1017 | unsigned char reg, val; | 1003 | unsigned char reg, val; |
1018 | 1004 | ||
1019 | if (snd_BUG_ON(!chip || !chip->card)) | 1005 | if (snd_BUG_ON(!chip || !card)) |
1020 | return -EINVAL; | 1006 | return -EINVAL; |
1021 | 1007 | ||
1022 | card = chip->card; | ||
1023 | |||
1024 | strcpy(card->mixername, snd_es1688_chip_id(chip)); | 1008 | strcpy(card->mixername, snd_es1688_chip_id(chip)); |
1025 | 1009 | ||
1026 | for (idx = 0; idx < ARRAY_SIZE(snd_es1688_controls); idx++) { | 1010 | for (idx = 0; idx < ARRAY_SIZE(snd_es1688_controls); idx++) { |