blob: cafc3a7316a89c4948deaf4d51e7b53fa3cce1c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 card-es968.c - driver for ESS AudioDrive ES968 based soundcards.
4 Copyright (C) 1999 by Massimo Piccioni <dafastidio@libero.it>
5
6 Thanks to Pierfrancesco 'qM2' Passerini.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
24#include <linux/time.h>
25#include <linux/pnp.h>
26#include <linux/moduleparam.h>
27#include <sound/core.h>
28#include <sound/initval.h>
29#include <sound/sb.h>
30
31#define PFX "es968: "
32
33MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
34MODULE_DESCRIPTION("ESS AudioDrive ES968");
35MODULE_LICENSE("GPL");
36MODULE_SUPPORTED_DEVICE("{{ESS,AudioDrive ES968}}");
37
38static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
39static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
40static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
41static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
42static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
43static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
44
45module_param_array(index, int, NULL, 0444);
46MODULE_PARM_DESC(index, "Index value for es968 based soundcard.");
47module_param_array(id, charp, NULL, 0444);
48MODULE_PARM_DESC(id, "ID string for es968 based soundcard.");
49module_param_array(enable, bool, NULL, 0444);
50MODULE_PARM_DESC(enable, "Enable es968 based soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52struct snd_card_es968 {
53 struct pnp_dev *dev;
Takashi Iwai7a8fef12005-11-17 16:56:11 +010054 struct snd_sb *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
57static struct pnp_card_device_id snd_es968_pnpids[] = {
58 { .id = "ESS0968", .devs = { { "@@@0968" }, } },
59 { .id = "", } /* end */
60};
61
62MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids);
63
64#define DRIVER_NAME "snd-card-es968"
65
David Howells7d12e782006-10-05 14:55:46 +010066static irqreturn_t snd_card_es968_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Takashi Iwai029d64b2005-11-17 14:34:36 +010068 struct snd_sb *chip = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 if (chip->open & SB_OPEN_PCM) {
71 return snd_sb8dsp_interrupt(chip);
72 } else {
73 return snd_sb8dsp_midi_interrupt(chip);
74 }
75}
76
77static int __devinit snd_card_es968_pnp(int dev, struct snd_card_es968 *acard,
78 struct pnp_card_link *card,
79 const struct pnp_card_device_id *id)
80{
81 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 int err;
Rene Herman109c53f842007-11-30 17:59:25 +010083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +010085 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 pdev = acard->dev;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 err = pnp_activate_dev(pdev);
91 if (err < 0) {
92 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return err;
94 }
95 port[dev] = pnp_port_start(pdev, 0);
96 dma8[dev] = pnp_dma(pdev, 1);
97 irq[dev] = pnp_irq(pdev, 0);
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return 0;
100}
101
Bjorn Helgaas6a3a3a02006-03-27 01:17:14 -0800102static int __devinit snd_card_es968_probe(int dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 struct pnp_card_link *pcard,
104 const struct pnp_card_device_id *pid)
105{
106 int error;
Takashi Iwai029d64b2005-11-17 14:34:36 +0100107 struct snd_sb *chip;
108 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 struct snd_card_es968 *acard;
110
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100111 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
112 sizeof(struct snd_card_es968), &card);
113 if (error < 0)
114 return error;
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100115 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) {
117 snd_card_free(card);
118 return error;
119 }
120 snd_card_set_dev(card, &pcard->card->dev);
121
122 if ((error = snd_sbdsp_create(card, port[dev],
123 irq[dev],
124 snd_card_es968_interrupt,
125 dma8[dev],
126 -1,
127 SB_HW_AUTO, &chip)) < 0) {
128 snd_card_free(card);
129 return error;
130 }
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100131 acard->chip = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 if ((error = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
134 snd_card_free(card);
135 return error;
136 }
137
138 if ((error = snd_sbmixer_new(chip)) < 0) {
139 snd_card_free(card);
140 return error;
141 }
142
143 if ((error = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
144 snd_card_free(card);
145 return error;
146 }
147
148 strcpy(card->driver, "ES968");
149 strcpy(card->shortname, "ESS ES968");
150 sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
151 card->shortname, chip->name, chip->port, irq[dev], dma8[dev]);
152
153 if ((error = snd_card_register(card)) < 0) {
154 snd_card_free(card);
155 return error;
156 }
157 pnp_set_card_drvdata(pcard, card);
158 return 0;
159}
160
Bjorn Helgaas6a3a3a02006-03-27 01:17:14 -0800161static unsigned int __devinitdata es968_devices;
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static int __devinit snd_es968_pnp_detect(struct pnp_card_link *card,
164 const struct pnp_card_device_id *id)
165{
166 static int dev;
167 int res;
168
169 for ( ; dev < SNDRV_CARDS; dev++) {
170 if (!enable[dev])
171 continue;
172 res = snd_card_es968_probe(dev, card, id);
173 if (res < 0)
174 return res;
175 dev++;
Bjorn Helgaas6a3a3a02006-03-27 01:17:14 -0800176 es968_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return 0;
178 }
179 return -ENODEV;
180}
181
182static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard)
183{
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100184 snd_card_free(pnp_get_card_drvdata(pcard));
185 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100188#ifdef CONFIG_PM
189static int snd_es968_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
190{
191 struct snd_card *card = pnp_get_card_drvdata(pcard);
192 struct snd_card_es968 *acard = card->private_data;
193 struct snd_sb *chip = acard->chip;
194
195 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
196 snd_pcm_suspend_all(chip->pcm);
197 snd_sbmixer_suspend(chip);
198 return 0;
199}
200
201static int snd_es968_pnp_resume(struct pnp_card_link *pcard)
202{
203 struct snd_card *card = pnp_get_card_drvdata(pcard);
204 struct snd_card_es968 *acard = card->private_data;
205 struct snd_sb *chip = acard->chip;
206
207 snd_sbdsp_reset(chip);
208 snd_sbmixer_resume(chip);
209 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
210 return 0;
211}
212#endif
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214static struct pnp_card_driver es968_pnpc_driver = {
215 .flags = PNP_DRIVER_RES_DISABLE,
216 .name = "es968",
217 .id_table = snd_es968_pnpids,
218 .probe = snd_es968_pnp_detect,
219 .remove = __devexit_p(snd_es968_pnp_remove),
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100220#ifdef CONFIG_PM
221 .suspend = snd_es968_pnp_suspend,
222 .resume = snd_es968_pnp_resume,
223#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
226static int __init alsa_card_es968_init(void)
227{
Bjorn Helgaas6a3a3a02006-03-27 01:17:14 -0800228 int err = pnp_register_card_driver(&es968_pnpc_driver);
229 if (err)
230 return err;
231
232 if (!es968_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 pnp_unregister_card_driver(&es968_pnpc_driver);
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100234#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 snd_printk(KERN_ERR "no ES968 based soundcards found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#endif
Takashi Iwai7a8fef12005-11-17 16:56:11 +0100237 return -ENODEV;
238 }
239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
242static void __exit alsa_card_es968_exit(void)
243{
244 pnp_unregister_card_driver(&es968_pnpc_driver);
245}
246
247module_init(alsa_card_es968_init)
248module_exit(alsa_card_es968_exit)