diff options
author | Dave Kleikamp <shaggy@austin.ibm.com> | 2006-01-24 15:34:47 -0500 |
---|---|---|
committer | Dave Kleikamp <shaggy@austin.ibm.com> | 2006-01-24 15:34:47 -0500 |
commit | 0a0fc0ddbe732779366ab6b1b879f62195e65967 (patch) | |
tree | 7b42490a676cf39ae0691b6859ecf7fd410f229b /sound/isa/sb/sb8.c | |
parent | 4d5dbd0945d9e0833dd7964a3d6ee33157f7cc7a (diff) | |
parent | 3ee68c4af3fd7228c1be63254b9f884614f9ebb2 (diff) |
Merge with /home/shaggy/git/linus-clean/
Diffstat (limited to 'sound/isa/sb/sb8.c')
-rw-r--r-- | sound/isa/sb/sb8.c | 176 |
1 files changed, 124 insertions, 52 deletions
diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c index 0bc0a3afdabc..60ee79cd14a3 100644 --- a/sound/isa/sb/sb8.c +++ b/sound/isa/sb/sb8.c | |||
@@ -21,13 +21,14 @@ | |||
21 | 21 | ||
22 | #include <sound/driver.h> | 22 | #include <sound/driver.h> |
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/err.h> | ||
25 | #include <linux/platform_device.h> | ||
24 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
25 | #include <linux/ioport.h> | 27 | #include <linux/ioport.h> |
26 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
27 | #include <sound/core.h> | 29 | #include <sound/core.h> |
28 | #include <sound/sb.h> | 30 | #include <sound/sb.h> |
29 | #include <sound/opl3.h> | 31 | #include <sound/opl3.h> |
30 | #define SNDRV_LEGACY_AUTO_PROBE | ||
31 | #include <sound/initval.h> | 32 | #include <sound/initval.h> |
32 | 33 | ||
33 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | 34 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
@@ -55,15 +56,16 @@ MODULE_PARM_DESC(irq, "IRQ # for SB8 driver."); | |||
55 | module_param_array(dma8, int, NULL, 0444); | 56 | module_param_array(dma8, int, NULL, 0444); |
56 | MODULE_PARM_DESC(dma8, "8-bit DMA # for SB8 driver."); | 57 | MODULE_PARM_DESC(dma8, "8-bit DMA # for SB8 driver."); |
57 | 58 | ||
59 | static struct platform_device *devices[SNDRV_CARDS]; | ||
60 | |||
58 | struct snd_sb8 { | 61 | struct snd_sb8 { |
59 | struct resource *fm_res; /* used to block FM i/o region for legacy cards */ | 62 | struct resource *fm_res; /* used to block FM i/o region for legacy cards */ |
63 | struct snd_sb *chip; | ||
60 | }; | 64 | }; |
61 | 65 | ||
62 | static snd_card_t *snd_sb8_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; | ||
63 | |||
64 | static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id, struct pt_regs *regs) | 66 | static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
65 | { | 67 | { |
66 | sb_t *chip = dev_id; | 68 | struct snd_sb *chip = dev_id; |
67 | 69 | ||
68 | if (chip->open & SB_OPEN_PCM) { | 70 | if (chip->open & SB_OPEN_PCM) { |
69 | return snd_sb8dsp_interrupt(chip); | 71 | return snd_sb8dsp_interrupt(chip); |
@@ -72,7 +74,7 @@ static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id, struct pt_regs *regs | |||
72 | } | 74 | } |
73 | } | 75 | } |
74 | 76 | ||
75 | static void snd_sb8_free(snd_card_t *card) | 77 | static void snd_sb8_free(struct snd_card *card) |
76 | { | 78 | { |
77 | struct snd_sb8 *acard = (struct snd_sb8 *)card->private_data; | 79 | struct snd_sb8 *acard = (struct snd_sb8 *)card->private_data; |
78 | 80 | ||
@@ -81,32 +83,57 @@ static void snd_sb8_free(snd_card_t *card) | |||
81 | release_and_free_resource(acard->fm_res); | 83 | release_and_free_resource(acard->fm_res); |
82 | } | 84 | } |
83 | 85 | ||
84 | static int __init snd_sb8_probe(int dev) | 86 | static int __init snd_sb8_probe(struct platform_device *pdev) |
85 | { | 87 | { |
86 | sb_t *chip; | 88 | int dev = pdev->id; |
87 | snd_card_t *card; | 89 | struct snd_sb *chip; |
90 | struct snd_card *card; | ||
88 | struct snd_sb8 *acard; | 91 | struct snd_sb8 *acard; |
89 | opl3_t *opl3; | 92 | struct snd_opl3 *opl3; |
90 | int err; | 93 | int err; |
91 | 94 | ||
92 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, | 95 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
93 | sizeof(struct snd_sb8)); | 96 | sizeof(struct snd_sb8)); |
94 | if (card == NULL) | 97 | if (card == NULL) |
95 | return -ENOMEM; | 98 | return -ENOMEM; |
96 | acard = (struct snd_sb8 *)card->private_data; | 99 | acard = card->private_data; |
97 | card->private_free = snd_sb8_free; | 100 | card->private_free = snd_sb8_free; |
98 | 101 | ||
99 | /* block the 0x388 port to avoid PnP conflicts */ | 102 | /* block the 0x388 port to avoid PnP conflicts */ |
100 | acard->fm_res = request_region(0x388, 4, "SoundBlaster FM"); | 103 | acard->fm_res = request_region(0x388, 4, "SoundBlaster FM"); |
101 | 104 | ||
102 | if ((err = snd_sbdsp_create(card, port[dev], irq[dev], | 105 | if (port[dev] != SNDRV_AUTO_PORT) { |
103 | snd_sb8_interrupt, | 106 | if ((err = snd_sbdsp_create(card, port[dev], irq[dev], |
104 | dma8[dev], | 107 | snd_sb8_interrupt, |
105 | -1, | 108 | dma8[dev], |
106 | SB_HW_AUTO, | 109 | -1, |
107 | &chip)) < 0) | 110 | SB_HW_AUTO, |
108 | goto _err; | 111 | &chip)) < 0) |
109 | 112 | goto _err; | |
113 | } else { | ||
114 | /* auto-probe legacy ports */ | ||
115 | static unsigned long possible_ports[] = { | ||
116 | 0x220, 0x240, 0x260, | ||
117 | }; | ||
118 | int i; | ||
119 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { | ||
120 | err = snd_sbdsp_create(card, possible_ports[i], | ||
121 | irq[dev], | ||
122 | snd_sb8_interrupt, | ||
123 | dma8[dev], | ||
124 | -1, | ||
125 | SB_HW_AUTO, | ||
126 | &chip); | ||
127 | if (err >= 0) { | ||
128 | port[dev] = possible_ports[i]; | ||
129 | break; | ||
130 | } | ||
131 | } | ||
132 | if (i >= ARRAY_SIZE(possible_ports)) | ||
133 | goto _err; | ||
134 | } | ||
135 | acard->chip = chip; | ||
136 | |||
110 | if (chip->hardware >= SB_HW_16) { | 137 | if (chip->hardware >= SB_HW_16) { |
111 | if (chip->hardware == SB_HW_ALS100) | 138 | if (chip->hardware == SB_HW_ALS100) |
112 | snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n", | 139 | snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n", |
@@ -153,13 +180,12 @@ static int __init snd_sb8_probe(int dev) | |||
153 | chip->port, | 180 | chip->port, |
154 | irq[dev], dma8[dev]); | 181 | irq[dev], dma8[dev]); |
155 | 182 | ||
156 | if ((err = snd_card_set_generic_dev(card)) < 0) | 183 | snd_card_set_dev(card, &pdev->dev); |
157 | goto _err; | ||
158 | 184 | ||
159 | if ((err = snd_card_register(card)) < 0) | 185 | if ((err = snd_card_register(card)) < 0) |
160 | goto _err; | 186 | goto _err; |
161 | 187 | ||
162 | snd_sb8_cards[dev] = card; | 188 | platform_set_drvdata(pdev, card); |
163 | return 0; | 189 | return 0; |
164 | 190 | ||
165 | _err: | 191 | _err: |
@@ -167,53 +193,99 @@ static int __init snd_sb8_probe(int dev) | |||
167 | return err; | 193 | return err; |
168 | } | 194 | } |
169 | 195 | ||
170 | static int __init snd_card_sb8_legacy_auto_probe(unsigned long xport) | 196 | static int snd_sb8_remove(struct platform_device *pdev) |
197 | { | ||
198 | snd_card_free(platform_get_drvdata(pdev)); | ||
199 | platform_set_drvdata(pdev, NULL); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | #ifdef CONFIG_PM | ||
204 | static int snd_sb8_suspend(struct platform_device *dev, pm_message_t state) | ||
205 | { | ||
206 | struct snd_card *card = platform_get_drvdata(dev); | ||
207 | struct snd_sb8 *acard = card->private_data; | ||
208 | struct snd_sb *chip = acard->chip; | ||
209 | |||
210 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | ||
211 | snd_pcm_suspend_all(chip->pcm); | ||
212 | snd_sbmixer_suspend(chip); | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | static int snd_sb8_resume(struct platform_device *dev) | ||
217 | { | ||
218 | struct snd_card *card = platform_get_drvdata(dev); | ||
219 | struct snd_sb8 *acard = card->private_data; | ||
220 | struct snd_sb *chip = acard->chip; | ||
221 | |||
222 | snd_sbdsp_reset(chip); | ||
223 | snd_sbmixer_resume(chip); | ||
224 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | ||
225 | return 0; | ||
226 | } | ||
227 | #endif | ||
228 | |||
229 | #define SND_SB8_DRIVER "snd_sb8" | ||
230 | |||
231 | static struct platform_driver snd_sb8_driver = { | ||
232 | .probe = snd_sb8_probe, | ||
233 | .remove = snd_sb8_remove, | ||
234 | #ifdef CONFIG_PM | ||
235 | .suspend = snd_sb8_suspend, | ||
236 | .resume = snd_sb8_resume, | ||
237 | #endif | ||
238 | .driver = { | ||
239 | .name = SND_SB8_DRIVER | ||
240 | }, | ||
241 | }; | ||
242 | |||
243 | static void __init_or_module snd_sb8_unregister_all(void) | ||
171 | { | 244 | { |
172 | static int dev; | 245 | int i; |
173 | int res; | 246 | |
174 | 247 | for (i = 0; i < ARRAY_SIZE(devices); ++i) | |
175 | for ( ; dev < SNDRV_CARDS; dev++) { | 248 | platform_device_unregister(devices[i]); |
176 | if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT) | 249 | platform_driver_unregister(&snd_sb8_driver); |
177 | continue; | ||
178 | port[dev] = xport; | ||
179 | res = snd_sb8_probe(dev); | ||
180 | if (res < 0) | ||
181 | port[dev] = SNDRV_AUTO_PORT; | ||
182 | return res; | ||
183 | } | ||
184 | return -ENODEV; | ||
185 | } | 250 | } |
186 | 251 | ||
187 | static int __init alsa_card_sb8_init(void) | 252 | static int __init alsa_card_sb8_init(void) |
188 | { | 253 | { |
189 | static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1}; | 254 | int i, cards, err; |
190 | int dev, cards, i; | 255 | |
191 | 256 | err = platform_driver_register(&snd_sb8_driver); | |
192 | for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) { | 257 | if (err < 0) |
193 | if (port[dev] == SNDRV_AUTO_PORT) | 258 | return err; |
194 | continue; | 259 | |
195 | if (snd_sb8_probe(dev) >= 0) | 260 | cards = 0; |
196 | cards++; | 261 | for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { |
262 | struct platform_device *device; | ||
263 | device = platform_device_register_simple(SND_SB8_DRIVER, | ||
264 | i, NULL, 0); | ||
265 | if (IS_ERR(device)) { | ||
266 | err = PTR_ERR(device); | ||
267 | goto errout; | ||
268 | } | ||
269 | devices[i] = device; | ||
270 | cards++; | ||
197 | } | 271 | } |
198 | i = snd_legacy_auto_probe(possible_ports, snd_card_sb8_legacy_auto_probe); | ||
199 | if (i > 0) | ||
200 | cards += i; | ||
201 | |||
202 | if (!cards) { | 272 | if (!cards) { |
203 | #ifdef MODULE | 273 | #ifdef MODULE |
204 | snd_printk(KERN_ERR "Sound Blaster soundcard not found or device busy\n"); | 274 | snd_printk(KERN_ERR "Sound Blaster soundcard not found or device busy\n"); |
205 | #endif | 275 | #endif |
206 | return -ENODEV; | 276 | err = -ENODEV; |
277 | goto errout; | ||
207 | } | 278 | } |
208 | return 0; | 279 | return 0; |
280 | |||
281 | errout: | ||
282 | snd_sb8_unregister_all(); | ||
283 | return err; | ||
209 | } | 284 | } |
210 | 285 | ||
211 | static void __exit alsa_card_sb8_exit(void) | 286 | static void __exit alsa_card_sb8_exit(void) |
212 | { | 287 | { |
213 | int idx; | 288 | snd_sb8_unregister_all(); |
214 | |||
215 | for (idx = 0; idx < SNDRV_CARDS; idx++) | ||
216 | snd_card_free(snd_sb8_cards[idx]); | ||
217 | } | 289 | } |
218 | 290 | ||
219 | module_init(alsa_card_sb8_init) | 291 | module_init(alsa_card_sb8_init) |