]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/isa/es1688/es1688.c
[ALSA] es1688 - Use platform_device
[linux-2.6-omap-h63xx.git] / sound / isa / es1688 / es1688.c
1 /*
2  *  Driver for generic ESS AudioDrive ESx688 soundcards
3  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/err.h>
25 #include <linux/platform_device.h>
26 #include <linux/time.h>
27 #include <linux/wait.h>
28 #include <linux/moduleparam.h>
29 #include <asm/dma.h>
30 #include <sound/core.h>
31 #include <sound/es1688.h>
32 #include <sound/mpu401.h>
33 #include <sound/opl3.h>
34 #define SNDRV_LEGACY_FIND_FREE_IRQ
35 #define SNDRV_LEGACY_FIND_FREE_DMA
36 #include <sound/initval.h>
37
38 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
39 MODULE_DESCRIPTION("ESS ESx688 AudioDrive");
40 MODULE_LICENSE("GPL");
41 MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
42                 "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
43                 "{ESS,ES688 AudioDrive,pnp:ESS6881},"
44                 "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
45
46 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
47 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
48 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;  /* Enable this card */
49 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* 0x220,0x240,0x260 */
50 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
51 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* 5,7,9,10 */
52 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* 5,7,9,10 */
53 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* 0,1,3 */
54
55 module_param_array(index, int, NULL, 0444);
56 MODULE_PARM_DESC(index, "Index value for ESx688 soundcard.");
57 module_param_array(id, charp, NULL, 0444);
58 MODULE_PARM_DESC(id, "ID string for ESx688 soundcard.");
59 module_param_array(enable, bool, NULL, 0444);
60 MODULE_PARM_DESC(enable, "Enable ESx688 soundcard.");
61 module_param_array(port, long, NULL, 0444);
62 MODULE_PARM_DESC(port, "Port # for ESx688 driver.");
63 module_param_array(mpu_port, long, NULL, 0444);
64 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ESx688 driver.");
65 module_param_array(irq, int, NULL, 0444);
66 MODULE_PARM_DESC(irq, "IRQ # for ESx688 driver.");
67 module_param_array(mpu_irq, int, NULL, 0444);
68 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver.");
69 module_param_array(dma8, int, NULL, 0444);
70 MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver.");
71
72 #define PFX     "es1688: "
73
74 static int __init snd_es1688_probe(struct platform_device *pdev)
75 {
76         int dev = pdev->id;
77         static int possible_irqs[] = {5, 9, 10, 7, -1};
78         static int possible_dmas[] = {1, 3, 0, -1};
79         int xirq, xdma, xmpu_irq;
80         struct snd_card *card;
81         struct snd_es1688 *chip;
82         struct snd_opl3 *opl3;
83         struct snd_pcm *pcm;
84         int err;
85
86         card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
87         if (card == NULL)
88                 return -ENOMEM;
89
90         xirq = irq[dev];
91         if (xirq == SNDRV_AUTO_IRQ) {
92                 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
93                         snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
94                         err = -EBUSY;
95                         goto _err;
96                 }
97         }
98         xmpu_irq = mpu_irq[dev];
99         xdma = dma8[dev];
100         if (xdma == SNDRV_AUTO_DMA) {
101                 if ((xdma = snd_legacy_find_free_dma(possible_dmas)) < 0) {
102                         snd_printk(KERN_ERR PFX "unable to find a free DMA\n");
103                         err = -EBUSY;
104                         goto _err;
105                 }
106         }
107
108         if (port[dev] != SNDRV_AUTO_PORT) {
109                 if ((err = snd_es1688_create(card, port[dev], mpu_port[dev],
110                                              xirq, xmpu_irq, xdma,
111                                              ES1688_HW_AUTO, &chip)) < 0)
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_es1688_create(card, possible_ports[i],
121                                                 mpu_port[dev],
122                                                 xirq, xmpu_irq, xdma,
123                                                 ES1688_HW_AUTO, &chip);
124                         if (err >= 0) {
125                                 port[dev] = possible_ports[i];
126                                 break;
127                         }
128                 }
129                 if (i >= ARRAY_SIZE(possible_ports))
130                         goto _err;
131         }
132
133         if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0)
134                 goto _err;
135
136         if ((err = snd_es1688_mixer(chip)) < 0)
137                 goto _err;
138
139         strcpy(card->driver, "ES1688");
140         strcpy(card->shortname, pcm->name);
141         sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma);
142
143         if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) {
144                 printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->port);
145         } else {
146                 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
147                         goto _err;
148         }
149
150         if (xmpu_irq >= 0 && xmpu_irq != SNDRV_AUTO_IRQ && chip->mpu_port > 0) {
151                 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
152                                                chip->mpu_port, 0,
153                                                xmpu_irq,
154                                                SA_INTERRUPT,
155                                                NULL)) < 0)
156                         goto _err;
157         }
158
159         snd_card_set_dev(card, &pdev->dev);
160
161         if ((err = snd_card_register(card)) < 0)
162                 goto _err;
163
164         platform_set_drvdata(pdev, card);
165         return 0;
166
167  _err:
168         snd_card_free(card);
169         return err;
170 }
171
172 static int snd_es1688_remove(struct platform_device *devptr)
173 {
174         snd_card_free(platform_get_drvdata(devptr));
175         platform_set_drvdata(devptr, NULL);
176         return 0;
177 }
178
179 #define ES1688_DRIVER   "snd_es1688"
180
181 static struct platform_driver snd_es1688_driver = {
182         .probe          = snd_es1688_probe,
183         .remove         = snd_es1688_remove,
184         /* FIXME: suspend/resume */
185         .driver         = {
186                 .name   = ES1688_DRIVER
187         },
188 };
189
190 static int __init alsa_card_es1688_init(void)
191 {
192         int i, cards, err;
193
194         err = platform_driver_register(&snd_es1688_driver);
195         if (err < 0)
196                 return err;
197
198         cards = 0;
199         for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
200                 struct platform_device *device;
201                 device = platform_device_register_simple(ES1688_DRIVER,
202                                                          i, NULL, 0);
203                 if (IS_ERR(device)) {
204                         err = PTR_ERR(device);
205                         goto errout;
206                 }
207                 cards++;
208         }
209         if (!cards) {
210 #ifdef MODULE
211                 printk(KERN_ERR "ESS AudioDrive ES1688 soundcard not found or device busy\n");
212 #endif
213                 err = -ENODEV;
214                 goto errout;
215         }
216         return 0;
217
218  errout:
219         platform_driver_unregister(&snd_es1688_driver);
220         return err;
221 }
222
223 static void __exit alsa_card_es1688_exit(void)
224 {
225         platform_driver_unregister(&snd_es1688_driver);
226 }
227
228 module_init(alsa_card_es1688_init)
229 module_exit(alsa_card_es1688_exit)