[ALSA] sound/isa: kill pnp_resource_change
[linux-2.6.git] / sound / isa / dt019x.c
1
2 /*
3     dt019x.c - driver for Diamond Technologies DT-0197H based soundcards.
4     Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it>
5
6     Generalised for soundcards based on DT-0196 and ALS-007 chips 
7     by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22 */
23
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/wait.h>
27 #include <linux/pnp.h>
28 #include <linux/moduleparam.h>
29 #include <sound/core.h>
30 #include <sound/initval.h>
31 #include <sound/mpu401.h>
32 #include <sound/opl3.h>
33 #include <sound/sb.h>
34
35 #define PFX "dt019x: "
36
37 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
38 MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
39 MODULE_LICENSE("GPL");
40 MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
41                "{Avance Logic ALS-007}}");
42
43 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
44 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
45 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;  /* Enable this card */
46 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* PnP setup */
47 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
48 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
49 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* PnP setup */
50 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* PnP setup */
51 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* PnP setup */
52
53 module_param_array(index, int, NULL, 0444);
54 MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
55 module_param_array(id, charp, NULL, 0444);
56 MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
57 module_param_array(enable, bool, NULL, 0444);
58 MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
59
60 struct snd_card_dt019x {
61         struct pnp_dev *dev;
62         struct pnp_dev *devmpu;
63         struct pnp_dev *devopl;
64         struct snd_sb *chip;
65 };
66
67 static struct pnp_card_device_id snd_dt019x_pnpids[] = {
68         /* DT197A30 */
69         { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
70         /* DT0196 / ALS-007 */
71         { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
72         { .id = "",  }
73 };
74
75 MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
76
77
78 #define DRIVER_NAME     "snd-card-dt019x"
79
80
81 static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
82                                          struct pnp_card_link *card,
83                                          const struct pnp_card_device_id *pid)
84 {
85         struct pnp_dev *pdev;
86         int err;
87
88         acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
89         if (acard->dev == NULL)
90                 return -ENODEV;
91
92         acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
93         acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
94
95         pdev = acard->dev;
96
97         err = pnp_activate_dev(pdev);
98         if (err < 0) {
99                 snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
100                 return err;
101         }
102
103         port[dev] = pnp_port_start(pdev, 0);
104         dma8[dev] = pnp_dma(pdev, 0);
105         irq[dev] = pnp_irq(pdev, 0);
106         snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
107                         port[dev],irq[dev],dma8[dev]);
108
109         pdev = acard->devmpu;
110         if (pdev != NULL) {
111                 err = pnp_activate_dev(pdev);
112                 if (err < 0) {
113                         pnp_release_card_device(pdev);
114                         snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
115                         goto __mpu_error;
116                 }
117                 mpu_port[dev] = pnp_port_start(pdev, 0);
118                 mpu_irq[dev] = pnp_irq(pdev, 0);
119                 snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
120                                 mpu_port[dev],mpu_irq[dev]);
121         } else {
122         __mpu_error:
123                 acard->devmpu = NULL;
124                 mpu_port[dev] = -1;
125         }
126
127         pdev = acard->devopl;
128         if (pdev != NULL) {
129                 err = pnp_activate_dev(pdev);
130                 if (err < 0) {
131                         pnp_release_card_device(pdev);
132                         snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
133                         goto __fm_error;
134                 }
135                 fm_port[dev] = pnp_port_start(pdev, 0);
136                 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
137         } else {
138         __fm_error:
139                 acard->devopl = NULL;
140                 fm_port[dev] = -1;
141         }
142
143         return 0;
144 }
145
146 static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
147 {
148         int error;
149         struct snd_sb *chip;
150         struct snd_card *card;
151         struct snd_card_dt019x *acard;
152         struct snd_opl3 *opl3;
153
154         if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
155                                  sizeof(struct snd_card_dt019x))) == NULL)
156                 return -ENOMEM;
157         acard = card->private_data;
158
159         snd_card_set_dev(card, &pcard->card->dev);
160         if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
161                 snd_card_free(card);
162                 return error;
163         }
164
165         if ((error = snd_sbdsp_create(card, port[dev],
166                                       irq[dev],
167                                       snd_sb16dsp_interrupt,
168                                       dma8[dev],
169                                       -1,
170                                       SB_HW_DT019X,
171                                       &chip)) < 0) {
172                 snd_card_free(card);
173                 return error;
174         }
175         acard->chip = chip;
176
177         strcpy(card->driver, "DT-019X");
178         strcpy(card->shortname, "Diamond Tech. DT-019X");
179         sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
180                 card->shortname, chip->name, chip->port,
181                 irq[dev], dma8[dev]);
182
183         if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
184                 snd_card_free(card);
185                 return error;
186         }
187         if ((error = snd_sbmixer_new(chip)) < 0) {
188                 snd_card_free(card);
189                 return error;
190         }
191
192         if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
193                 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
194                         mpu_irq[dev] = -1;
195                 if (snd_mpu401_uart_new(card, 0,
196 /*                                      MPU401_HW_SB,*/
197                                         MPU401_HW_MPU401,
198                                         mpu_port[dev], 0,
199                                         mpu_irq[dev],
200                                         mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
201                                         NULL) < 0)
202                         snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
203         }
204
205         if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
206                 if (snd_opl3_create(card,
207                                     fm_port[dev],
208                                     fm_port[dev] + 2,
209                                     OPL3_HW_AUTO, 0, &opl3) < 0) {
210                         snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
211                                    fm_port[dev], fm_port[dev] + 2);
212                 } else {
213                         if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
214                                 snd_card_free(card);
215                                 return error;
216                         }
217                         if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
218                                 snd_card_free(card);
219                                 return error;
220                         }
221                 }
222         }
223
224         if ((error = snd_card_register(card)) < 0) {
225                 snd_card_free(card);
226                 return error;
227         }
228         pnp_set_card_drvdata(pcard, card);
229         return 0;
230 }
231
232 static unsigned int __devinitdata dt019x_devices;
233
234 static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
235                                           const struct pnp_card_device_id *pid)
236 {
237         static int dev;
238         int res;
239
240         for ( ; dev < SNDRV_CARDS; dev++) {
241                 if (!enable[dev])
242                         continue;
243                 res = snd_card_dt019x_probe(dev, card, pid);
244                 if (res < 0)
245                         return res;
246                 dev++;
247                 dt019x_devices++;
248                 return 0;
249         }
250         return -ENODEV;
251 }
252
253 static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
254 {
255         snd_card_free(pnp_get_card_drvdata(pcard));
256         pnp_set_card_drvdata(pcard, NULL);
257 }
258
259 #ifdef CONFIG_PM
260 static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
261 {
262         struct snd_card *card = pnp_get_card_drvdata(pcard);
263         struct snd_card_dt019x *acard = card->private_data;
264         struct snd_sb *chip = acard->chip;
265
266         snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
267         snd_pcm_suspend_all(chip->pcm);
268         snd_sbmixer_suspend(chip);
269         return 0;
270 }
271
272 static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard)
273 {
274         struct snd_card *card = pnp_get_card_drvdata(pcard);
275         struct snd_card_dt019x *acard = card->private_data;
276         struct snd_sb *chip = acard->chip;
277
278         snd_sbdsp_reset(chip);
279         snd_sbmixer_resume(chip);
280         snd_power_change_state(card, SNDRV_CTL_POWER_D0);
281         return 0;
282 }
283 #endif
284
285 static struct pnp_card_driver dt019x_pnpc_driver = {
286         .flags          = PNP_DRIVER_RES_DISABLE,
287         .name           = "dt019x",
288         .id_table       = snd_dt019x_pnpids,
289         .probe          = snd_dt019x_pnp_probe,
290         .remove         = __devexit_p(snd_dt019x_pnp_remove),
291 #ifdef CONFIG_PM
292         .suspend        = snd_dt019x_pnp_suspend,
293         .resume         = snd_dt019x_pnp_resume,
294 #endif
295 };
296
297 static int __init alsa_card_dt019x_init(void)
298 {
299         int err;
300
301         err = pnp_register_card_driver(&dt019x_pnpc_driver);
302         if (err)
303                 return err;
304
305         if (!dt019x_devices) {
306                 pnp_unregister_card_driver(&dt019x_pnpc_driver);
307 #ifdef MODULE
308                 snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
309 #endif
310                 return -ENODEV;
311         }
312         return 0;
313 }
314
315 static void __exit alsa_card_dt019x_exit(void)
316 {
317         pnp_unregister_card_driver(&dt019x_pnpc_driver);
318 }
319
320 module_init(alsa_card_dt019x_init)
321 module_exit(alsa_card_dt019x_exit)