3 card-als100.c - driver for Avance Logic ALS100 based soundcards.
4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
5 Copyright (C) 1999-2002 by Massimo Piccioni <dafastidio@libero.it>
7 Thanks to Pierfrancesco 'qM2' Passerini.
9 Generalised for soundcards based on DT-0196 and ALS-007 chips
10 by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/init.h>
28 #include <linux/wait.h>
29 #include <linux/time.h>
30 #include <linux/pnp.h>
31 #include <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/initval.h>
34 #include <sound/mpu401.h>
35 #include <sound/opl3.h>
38 #define PFX "als100: "
40 MODULE_DESCRIPTION("Avance Logic ALS007/ALS1X0");
41 MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
42 "{Avance Logic ALS-007}}"
43 "{{Avance Logic,ALS100 - PRO16PNP},"
44 "{Avance Logic,ALS110},"
45 "{Avance Logic,ALS120},"
46 "{Avance Logic,ALS200},"
48 "{Digimate,3D Sound},"
49 "{Avance Logic,ALS120},"
52 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
53 MODULE_LICENSE("GPL");
55 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
56 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
57 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
; /* Enable this card */
58 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
59 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
60 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
61 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* PnP setup */
62 static int mpu_irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* PnP setup */
63 static int dma8
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* PnP setup */
64 static int dma16
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* PnP setup */
66 module_param_array(index
, int, NULL
, 0444);
67 MODULE_PARM_DESC(index
, "Index value for Avance Logic based soundcard.");
68 module_param_array(id
, charp
, NULL
, 0444);
69 MODULE_PARM_DESC(id
, "ID string for Avance Logic based soundcard.");
70 module_param_array(enable
, bool, NULL
, 0444);
71 MODULE_PARM_DESC(enable
, "Enable Avance Logic based soundcard.");
73 MODULE_ALIAS("snd-dt019x");
75 struct snd_card_als100
{
77 struct pnp_dev
*devmpu
;
78 struct pnp_dev
*devopl
;
82 static struct pnp_card_device_id snd_als100_pnpids
[] = {
85 .devs
= { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
86 .driver_data
= SB_HW_DT019X
},
87 /* DT0196 / ALS-007 */
89 .devs
= { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
90 .driver_data
= SB_HW_DT019X
},
91 /* ALS100 - PRO16PNP */
93 .devs
= { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
94 .driver_data
= SB_HW_ALS100
},
95 /* ALS110 - MF1000 - Digimate 3D Sound */
97 .devs
= { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } },
98 .driver_data
= SB_HW_ALS100
},
101 .devs
= { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
102 .driver_data
= SB_HW_ALS100
},
105 .devs
= { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } },
106 .driver_data
= SB_HW_ALS100
},
109 .devs
= { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } },
110 .driver_data
= SB_HW_ALS100
},
113 .devs
= { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
114 .driver_data
= SB_HW_ALS100
},
115 { .id
= "" } /* end */
118 MODULE_DEVICE_TABLE(pnp_card
, snd_als100_pnpids
);
120 static int __devinit
snd_card_als100_pnp(int dev
, struct snd_card_als100
*acard
,
121 struct pnp_card_link
*card
,
122 const struct pnp_card_device_id
*id
)
124 struct pnp_dev
*pdev
;
127 acard
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
128 if (acard
->dev
== NULL
)
131 acard
->devmpu
= pnp_request_card_device(card
, id
->devs
[1].id
, acard
->dev
);
132 acard
->devopl
= pnp_request_card_device(card
, id
->devs
[2].id
, acard
->dev
);
136 err
= pnp_activate_dev(pdev
);
138 snd_printk(KERN_ERR PFX
"AUDIO pnp configure failure\n");
141 port
[dev
] = pnp_port_start(pdev
, 0);
142 if (id
->driver_data
== SB_HW_DT019X
)
143 dma8
[dev
] = pnp_dma(pdev
, 0);
145 dma8
[dev
] = pnp_dma(pdev
, 1);
146 dma16
[dev
] = pnp_dma(pdev
, 0);
148 irq
[dev
] = pnp_irq(pdev
, 0);
150 pdev
= acard
->devmpu
;
152 err
= pnp_activate_dev(pdev
);
155 mpu_port
[dev
] = pnp_port_start(pdev
, 0);
156 mpu_irq
[dev
] = pnp_irq(pdev
, 0);
160 pnp_release_card_device(pdev
);
161 snd_printk(KERN_ERR PFX
"MPU401 pnp configure failure, skipping\n");
163 acard
->devmpu
= NULL
;
167 pdev
= acard
->devopl
;
169 err
= pnp_activate_dev(pdev
);
172 fm_port
[dev
] = pnp_port_start(pdev
, 0);
176 pnp_release_card_device(pdev
);
177 snd_printk(KERN_ERR PFX
"OPL3 pnp configure failure, skipping\n");
179 acard
->devopl
= NULL
;
186 static int __devinit
snd_card_als100_probe(int dev
,
187 struct pnp_card_link
*pcard
,
188 const struct pnp_card_device_id
*pid
)
192 struct snd_card
*card
;
193 struct snd_card_als100
*acard
;
194 struct snd_opl3
*opl3
;
196 error
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
197 sizeof(struct snd_card_als100
), &card
);
200 acard
= card
->private_data
;
202 if ((error
= snd_card_als100_pnp(dev
, acard
, pcard
, pid
))) {
206 snd_card_set_dev(card
, &pcard
->card
->dev
);
208 if (pid
->driver_data
== SB_HW_DT019X
)
211 error
= snd_sbdsp_create(card
, port
[dev
], irq
[dev
],
212 snd_sb16dsp_interrupt
,
213 dma8
[dev
], dma16
[dev
],
222 if (pid
->driver_data
== SB_HW_DT019X
) {
223 strcpy(card
->driver
, "DT-019X");
224 strcpy(card
->shortname
, "Diamond Tech. DT-019X");
225 sprintf(card
->longname
, "%s, %s at 0x%lx, irq %d, dma %d",
226 card
->shortname
, chip
->name
, chip
->port
,
227 irq
[dev
], dma8
[dev
]);
229 strcpy(card
->driver
, "ALS100");
230 strcpy(card
->shortname
, "Avance Logic ALS100");
231 sprintf(card
->longname
, "%s, %s at 0x%lx, irq %d, dma %d&%d",
232 card
->shortname
, chip
->name
, chip
->port
,
233 irq
[dev
], dma8
[dev
], dma16
[dev
]);
236 if ((error
= snd_sb16dsp_pcm(chip
, 0, NULL
)) < 0) {
241 if ((error
= snd_sbmixer_new(chip
)) < 0) {
246 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
247 int mpu_type
= MPU401_HW_ALS100
;
249 if (mpu_irq
[dev
] == SNDRV_AUTO_IRQ
)
252 if (pid
->driver_data
== SB_HW_DT019X
)
253 mpu_type
= MPU401_HW_MPU401
;
255 if (snd_mpu401_uart_new(card
, 0,
260 snd_printk(KERN_ERR PFX
"no MPU-401 device at 0x%lx\n", mpu_port
[dev
]);
263 if (fm_port
[dev
] > 0 && fm_port
[dev
] != SNDRV_AUTO_PORT
) {
264 if (snd_opl3_create(card
,
265 fm_port
[dev
], fm_port
[dev
] + 2,
266 OPL3_HW_AUTO
, 0, &opl3
) < 0) {
267 snd_printk(KERN_ERR PFX
"no OPL device at 0x%lx-0x%lx\n",
268 fm_port
[dev
], fm_port
[dev
] + 2);
270 if ((error
= snd_opl3_timer_new(opl3
, 0, 1)) < 0) {
274 if ((error
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
)) < 0) {
281 if ((error
= snd_card_register(card
)) < 0) {
285 pnp_set_card_drvdata(pcard
, card
);
289 static unsigned int __devinitdata als100_devices
;
291 static int __devinit
snd_als100_pnp_detect(struct pnp_card_link
*card
,
292 const struct pnp_card_device_id
*id
)
297 for ( ; dev
< SNDRV_CARDS
; dev
++) {
300 res
= snd_card_als100_probe(dev
, card
, id
);
310 static void __devexit
snd_als100_pnp_remove(struct pnp_card_link
* pcard
)
312 snd_card_free(pnp_get_card_drvdata(pcard
));
313 pnp_set_card_drvdata(pcard
, NULL
);
317 static int snd_als100_pnp_suspend(struct pnp_card_link
*pcard
, pm_message_t state
)
319 struct snd_card
*card
= pnp_get_card_drvdata(pcard
);
320 struct snd_card_als100
*acard
= card
->private_data
;
321 struct snd_sb
*chip
= acard
->chip
;
323 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
324 snd_pcm_suspend_all(chip
->pcm
);
325 snd_sbmixer_suspend(chip
);
329 static int snd_als100_pnp_resume(struct pnp_card_link
*pcard
)
331 struct snd_card
*card
= pnp_get_card_drvdata(pcard
);
332 struct snd_card_als100
*acard
= card
->private_data
;
333 struct snd_sb
*chip
= acard
->chip
;
335 snd_sbdsp_reset(chip
);
336 snd_sbmixer_resume(chip
);
337 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
342 static struct pnp_card_driver als100_pnpc_driver
= {
343 .flags
= PNP_DRIVER_RES_DISABLE
,
345 .id_table
= snd_als100_pnpids
,
346 .probe
= snd_als100_pnp_detect
,
347 .remove
= __devexit_p(snd_als100_pnp_remove
),
349 .suspend
= snd_als100_pnp_suspend
,
350 .resume
= snd_als100_pnp_resume
,
354 static int __init
alsa_card_als100_init(void)
358 err
= pnp_register_card_driver(&als100_pnpc_driver
);
362 if (!als100_devices
) {
363 pnp_unregister_card_driver(&als100_pnpc_driver
);
365 snd_printk(KERN_ERR
"no Avance Logic based soundcards found\n");
372 static void __exit
alsa_card_als100_exit(void)
374 pnp_unregister_card_driver(&als100_pnpc_driver
);
377 module_init(alsa_card_als100_init
)
378 module_exit(alsa_card_als100_exit
)