aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorRene Herman <rene.herman@gmail.com>2007-02-19 07:01:45 -0500
committerJaroslav Kysela <perex@suse.cz>2007-05-11 10:55:39 -0400
commit019608b6379fcc3ba7f4db51540e509e93f4ab3c (patch)
tree08c94255a271616f3ed12c9d8178baabec65a2d8 /sound
parent07e038b349f8fadf0b5c100dc9c3cab47327a244 (diff)
[ALSA] es1688 - code clean-up
Seperate out the legacy probing into its own function, improving readability. Signed-off-by: Rene Herman <rene.herman@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound')
-rw-r--r--sound/isa/es1688/es1688.c86
1 files changed, 50 insertions, 36 deletions
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
index f7d0c5fab5d9..edc398712e8b 100644
--- a/sound/isa/es1688/es1688.c
+++ b/sound/isa/es1688/es1688.c
@@ -77,13 +77,48 @@ static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
77 return enable[n]; 77 return enable[n];
78} 78}
79 79
80static int __devinit snd_es1688_probe(struct device *dev, unsigned int n) 80static int __devinit snd_es1688_legacy_create(struct snd_card *card,
81 struct device *dev, unsigned int n, struct snd_es1688 **rchip)
81{ 82{
82 static unsigned long possible_ports[] = {0x220, 0x240, 0x260}; 83 static long possible_ports[] = {0x220, 0x240, 0x260};
83 static int possible_irqs[] = {5, 9, 10, 7, -1}; 84 static int possible_irqs[] = {5, 9, 10, 7, -1};
84 static int possible_dmas[] = {1, 3, 0, -1}; 85 static int possible_dmas[] = {1, 3, 0, -1};
85 int i, xirq, xdma;
86 86
87 int i, error;
88
89 if (irq[n] == SNDRV_AUTO_IRQ) {
90 irq[n] = snd_legacy_find_free_irq(possible_irqs);
91 if (irq[n] < 0) {
92 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n",
93 dev->bus_id);
94 return -EBUSY;
95 }
96 }
97 if (dma8[n] == SNDRV_AUTO_DMA) {
98 dma8[n] = snd_legacy_find_free_dma(possible_dmas);
99 if (dma8[n] < 0) {
100 snd_printk(KERN_ERR "%s: unable to find a free DMA\n",
101 dev->bus_id);
102 return -EBUSY;
103 }
104 }
105
106 if (port[n] != SNDRV_AUTO_PORT)
107 return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
108 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
109
110 i = 0;
111 do {
112 port[n] = possible_ports[i];
113 error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
114 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
115 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
116
117 return error;
118}
119
120static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
121{
87 struct snd_card *card; 122 struct snd_card *card;
88 struct snd_es1688 *chip; 123 struct snd_es1688 *chip;
89 struct snd_opl3 *opl3; 124 struct snd_opl3 *opl3;
@@ -94,33 +129,7 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
94 if (!card) 129 if (!card)
95 return -EINVAL; 130 return -EINVAL;
96 131
97 error = -EBUSY; 132 error = snd_es1688_legacy_create(card, dev, n, &chip);
98
99 xirq = irq[n];
100 if (xirq == SNDRV_AUTO_IRQ) {
101 xirq = snd_legacy_find_free_irq(possible_irqs);
102 if (xirq < 0) {
103 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n", dev->bus_id);
104 goto out;
105 }
106 }
107
108 xdma = dma8[n];
109 if (xdma == SNDRV_AUTO_DMA) {
110 xdma = snd_legacy_find_free_dma(possible_dmas);
111 if (xdma < 0) {
112 snd_printk(KERN_ERR "%s: unable to find a free DMA\n", dev->bus_id);
113 goto out;
114 }
115 }
116
117 if (port[n] == SNDRV_AUTO_PORT)
118 for (i = 0; i < ARRAY_SIZE(possible_ports) && error < 0; i++)
119 error = snd_es1688_create(card, possible_ports[i], mpu_port[n],
120 xirq, mpu_irq[n], xdma, ES1688_HW_AUTO, &chip);
121 else
122 error = snd_es1688_create(card, port[n], mpu_port[n],
123 xirq, mpu_irq[n], xdma, ES1688_HW_AUTO, &chip);
124 if (error < 0) 133 if (error < 0)
125 goto out; 134 goto out;
126 135
@@ -134,19 +143,24 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
134 143
135 strcpy(card->driver, "ES1688"); 144 strcpy(card->driver, "ES1688");
136 strcpy(card->shortname, pcm->name); 145 strcpy(card->shortname, pcm->name);
137 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma); 146 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
147 chip->port, chip->irq, chip->dma8);
138 148
139 if (snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) 149 if (snd_opl3_create(card, chip->port, chip->port + 2,
140 printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n", dev->bus_id, chip->port); 150 OPL3_HW_OPL3, 0, &opl3) < 0)
151 printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n",
152 dev->bus_id, chip->port);
141 else { 153 else {
142 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); 154 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
143 if (error < 0) 155 if (error < 0)
144 goto out; 156 goto out;
145 } 157 }
146 158
147 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ && chip->mpu_port > 0) { 159 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
148 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, chip->mpu_port, 160 chip->mpu_port > 0) {
149 0, mpu_irq[n], IRQF_DISABLED, NULL); 161 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
162 chip->mpu_port, 0,
163 mpu_irq[n], IRQF_DISABLED, NULL);
150 if (error < 0) 164 if (error < 0)
151 goto out; 165 goto out;
152 } 166 }