1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <sound/core.h>
22#include <linux/slab.h>
23#include <linux/moduleparam.h>
24#include <pcmcia/ciscode.h>
25#include <pcmcia/cisreg.h>
26#include "pdaudiocf.h"
27#include <sound/initval.h>
28#include <linux/init.h>
29
30
31
32
33#define CARD_NAME "PDAudio-CF"
34
35MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
36MODULE_DESCRIPTION("Sound Core " CARD_NAME);
37MODULE_LICENSE("GPL");
38MODULE_SUPPORTED_DEVICE("{{Sound Core," CARD_NAME "}}");
39
40static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
41static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
42static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
43
44module_param_array(index, int, NULL, 0444);
45MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
46module_param_array(id, charp, NULL, 0444);
47MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
48module_param_array(enable, bool, NULL, 0444);
49MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
50
51
52
53
54static struct snd_card *card_list[SNDRV_CARDS];
55
56
57
58
59static int pdacf_config(struct pcmcia_device *link);
60static void snd_pdacf_detach(struct pcmcia_device *p_dev);
61
62static void pdacf_release(struct pcmcia_device *link)
63{
64 pcmcia_disable_device(link);
65}
66
67
68
69
70static int snd_pdacf_free(struct snd_pdacf *pdacf)
71{
72 struct pcmcia_device *link = pdacf->p_dev;
73
74 pdacf_release(link);
75
76 card_list[pdacf->index] = NULL;
77 pdacf->card = NULL;
78
79 kfree(pdacf);
80 return 0;
81}
82
83static int snd_pdacf_dev_free(struct snd_device *device)
84{
85 struct snd_pdacf *chip = device->device_data;
86 return snd_pdacf_free(chip);
87}
88
89
90
91
92static int snd_pdacf_probe(struct pcmcia_device *link)
93{
94 int i;
95 struct snd_pdacf *pdacf;
96 struct snd_card *card;
97 static struct snd_device_ops ops = {
98 .dev_free = snd_pdacf_dev_free,
99 };
100
101 snd_printdd(KERN_DEBUG "pdacf_attach called\n");
102
103 for (i = 0; i < SNDRV_CARDS; i++) {
104 if (! card_list[i])
105 break;
106 }
107 if (i >= SNDRV_CARDS) {
108 snd_printk(KERN_ERR "pdacf: too many cards found\n");
109 return -EINVAL;
110 }
111 if (! enable[i])
112 return -ENODEV;
113
114
115 card = snd_card_new(index[i], id[i], THIS_MODULE, 0);
116 if (card == NULL) {
117 snd_printk(KERN_ERR "pdacf: cannot create a card instance\n");
118 return -ENOMEM;
119 }
120
121 pdacf = snd_pdacf_create(card);
122 if (! pdacf)
123 return -EIO;
124
125 if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops) < 0) {
126 kfree(pdacf);
127 snd_card_free(card);
128 return -ENODEV;
129 }
130
131 snd_card_set_dev(card, &handle_to_dev(link));
132
133 pdacf->index = i;
134 card_list[i] = card;
135
136 pdacf->p_dev = link;
137 link->priv = pdacf;
138
139 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
140 link->io.NumPorts1 = 16;
141
142 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT | IRQ_FORCED_PULSE;
143
144
145 link->irq.IRQInfo1 = 0 ;
146 link->irq.Handler = pdacf_interrupt;
147 link->irq.Instance = pdacf;
148 link->conf.Attributes = CONF_ENABLE_IRQ;
149 link->conf.IntType = INT_MEMORY_AND_IO;
150 link->conf.ConfigIndex = 1;
151 link->conf.Present = PRESENT_OPTION;
152
153 return pdacf_config(link);
154}
155
156
157
158
159
160
161
162
163
164
165
166
167static int snd_pdacf_assign_resources(struct snd_pdacf *pdacf, int port, int irq)
168{
169 int err;
170 struct snd_card *card = pdacf->card;
171
172 snd_printdd(KERN_DEBUG "pdacf assign resources: port = 0x%x, irq = %d\n", port, irq);
173 pdacf->port = port;
174 pdacf->irq = irq;
175 pdacf->chip_status |= PDAUDIOCF_STAT_IS_CONFIGURED;
176
177 err = snd_pdacf_ak4117_create(pdacf);
178 if (err < 0)
179 return err;
180
181 strcpy(card->driver, "PDAudio-CF");
182 sprintf(card->shortname, "Core Sound %s", card->driver);
183 sprintf(card->longname, "%s at 0x%x, irq %i",
184 card->shortname, port, irq);
185
186 err = snd_pdacf_pcm_new(pdacf);
187 if (err < 0)
188 return err;
189
190 if ((err = snd_card_register(card)) < 0)
191 return err;
192
193 return 0;
194}
195
196
197
198
199
200static void snd_pdacf_detach(struct pcmcia_device *link)
201{
202 struct snd_pdacf *chip = link->priv;
203
204 snd_printdd(KERN_DEBUG "pdacf_detach called\n");
205
206 if (chip->chip_status & PDAUDIOCF_STAT_IS_CONFIGURED)
207 snd_pdacf_powerdown(chip);
208 chip->chip_status |= PDAUDIOCF_STAT_IS_STALE;
209 snd_card_disconnect(chip->card);
210 snd_card_free_when_closed(chip->card);
211}
212
213
214
215
216
217#define CS_CHECK(fn, ret) \
218do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
219
220static int pdacf_config(struct pcmcia_device *link)
221{
222 struct snd_pdacf *pdacf = link->priv;
223 int last_fn, last_ret;
224
225 snd_printdd(KERN_DEBUG "pdacf_config called\n");
226 link->conf.ConfigIndex = 0x5;
227
228 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
229 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
230 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
231
232 if (snd_pdacf_assign_resources(pdacf, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
233 goto failed;
234
235 link->dev_node = &pdacf->node;
236 return 0;
237
238cs_failed:
239 cs_error(link, last_fn, last_ret);
240failed:
241 pcmcia_disable_device(link);
242 return -ENODEV;
243}
244
245#ifdef CONFIG_PM
246
247static int pdacf_suspend(struct pcmcia_device *link)
248{
249 struct snd_pdacf *chip = link->priv;
250
251 snd_printdd(KERN_DEBUG "SUSPEND\n");
252 if (chip) {
253 snd_printdd(KERN_DEBUG "snd_pdacf_suspend calling\n");
254 snd_pdacf_suspend(chip, PMSG_SUSPEND);
255 }
256
257 return 0;
258}
259
260static int pdacf_resume(struct pcmcia_device *link)
261{
262 struct snd_pdacf *chip = link->priv;
263
264 snd_printdd(KERN_DEBUG "RESUME\n");
265 if (pcmcia_dev_present(link)) {
266 if (chip) {
267 snd_printdd(KERN_DEBUG "calling snd_pdacf_resume\n");
268 snd_pdacf_resume(chip);
269 }
270 }
271 snd_printdd(KERN_DEBUG "resume done!\n");
272
273 return 0;
274}
275
276#endif
277
278
279
280
281static struct pcmcia_device_id snd_pdacf_ids[] = {
282
283 PCMCIA_DEVICE_PROD_ID12("Core Sound","PDAudio-CF",0x396d19d2,0x71717b49),
284 PCMCIA_DEVICE_NULL
285};
286MODULE_DEVICE_TABLE(pcmcia, snd_pdacf_ids);
287
288static struct pcmcia_driver pdacf_cs_driver = {
289 .owner = THIS_MODULE,
290 .drv = {
291 .name = "snd-pdaudiocf",
292 },
293 .probe = snd_pdacf_probe,
294 .remove = snd_pdacf_detach,
295 .id_table = snd_pdacf_ids,
296#ifdef CONFIG_PM
297 .suspend = pdacf_suspend,
298 .resume = pdacf_resume,
299#endif
300
301};
302
303static int __init init_pdacf(void)
304{
305 return pcmcia_register_driver(&pdacf_cs_driver);
306}
307
308static void __exit exit_pdacf(void)
309{
310 pcmcia_unregister_driver(&pdacf_cs_driver);
311}
312
313module_init(init_pdacf);
314module_exit(exit_pdacf);
315