ALSA: lola - Changes in proc file
[deliverable/linux.git] / sound / pci / lola / lola.c
CommitLineData
d43f3010
TI
1/*
2 * Support for Digigram Lola PCI-e boards
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/moduleparam.h>
24#include <linux/dma-mapping.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/slab.h>
28#include <linux/pci.h>
29#include <sound/core.h>
30#include <sound/control.h>
31#include <sound/pcm.h>
32#include <sound/initval.h>
33#include "lola.h"
34
35static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
36static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
37static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
38
39module_param_array(index, int, NULL, 0444);
40MODULE_PARM_DESC(index, "Index value for Digigram Lola driver.");
41module_param_array(id, charp, NULL, 0444);
42MODULE_PARM_DESC(id, "ID string for Digigram Lola driver.");
43module_param_array(enable, bool, NULL, 0444);
44MODULE_PARM_DESC(enable, "Enable Digigram Lola driver.");
45
46MODULE_LICENSE("GPL");
47MODULE_SUPPORTED_DEVICE("{{Digigram, Lola}}");
48MODULE_DESCRIPTION("Digigram Lola driver");
49MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
50
51#ifdef CONFIG_SND_DEBUG_VERBOSE
52static int debug;
53module_param(debug, int, 0644);
54#define verbose_debug(fmt, args...) \
55 do { if (debug > 1) printk(KERN_DEBUG SFX fmt, ##args); } while (0)
56#else
57#define verbose_debug(fmt, args...)
58#endif
59
60/*
61 * pseudo-codec read/write via CORB/RIRB
62 */
63
64static int corb_send_verb(struct lola *chip, unsigned int nid,
65 unsigned int verb, unsigned int data,
66 unsigned int extdata)
67{
68 unsigned long flags;
69 int ret = -EIO;
70
71 chip->last_cmd_nid = nid;
72 chip->last_verb = verb;
73 chip->last_data = data;
74 chip->last_extdata = extdata;
75 data |= (nid << 20) | (verb << 8);
76 spin_lock_irqsave(&chip->reg_lock, flags);
77 if (chip->rirb.cmds < LOLA_CORB_ENTRIES - 1) {
78 unsigned int wp = chip->corb.wp + 1;
79 wp %= LOLA_CORB_ENTRIES;
80 chip->corb.wp = wp;
81 chip->corb.buf[wp * 2] = cpu_to_le32(data);
82 chip->corb.buf[wp * 2 + 1] = cpu_to_le32(extdata);
83 lola_writew(chip, BAR0, CORBWP, wp);
84 chip->rirb.cmds++;
85 smp_wmb();
86 ret = 0;
87 }
88 spin_unlock_irqrestore(&chip->reg_lock, flags);
89 return ret;
90}
91
92static void lola_queue_unsol_event(struct lola *chip, unsigned int res,
93 unsigned int res_ex)
94{
95 lola_update_ext_clock_freq(chip, res);
96}
97
98/* retrieve RIRB entry - called from interrupt handler */
99static void lola_update_rirb(struct lola *chip)
100{
101 unsigned int rp, wp;
102 u32 res, res_ex;
103
104 wp = lola_readw(chip, BAR0, RIRBWP);
105 if (wp == chip->rirb.wp)
106 return;
107 chip->rirb.wp = wp;
108
109 while (chip->rirb.rp != wp) {
110 chip->rirb.rp++;
111 chip->rirb.rp %= LOLA_CORB_ENTRIES;
112
113 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
114 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
115 res = le32_to_cpu(chip->rirb.buf[rp]);
116 if (res_ex & LOLA_RIRB_EX_UNSOL_EV)
117 lola_queue_unsol_event(chip, res, res_ex);
118 else if (chip->rirb.cmds) {
119 chip->res = res;
120 chip->res_ex = res_ex;
121 smp_wmb();
122 chip->rirb.cmds--;
123 }
124 }
125}
126
127static int rirb_get_response(struct lola *chip, unsigned int *val,
128 unsigned int *extval)
129{
130 unsigned long timeout;
131
132 timeout = jiffies + msecs_to_jiffies(1000);
133 for (;;) {
134 if (!chip->rirb.cmds) {
135 *val = chip->res;
136 if (extval)
137 *extval = chip->res_ex;
138 verbose_debug("get_response: %x, %x\n",
139 chip->res, chip->res_ex);
140 if (chip->res_ex & LOLA_RIRB_EX_ERROR) {
141 printk(KERN_WARNING SFX "RIRB ERROR: "
142 "NID=%x, verb=%x, data=%x, ext=%x\n",
143 chip->last_cmd_nid,
144 chip->last_verb, chip->last_data,
145 chip->last_extdata);
146 return -EIO;
147 }
148 return 0;
149 }
150 if (time_after(jiffies, timeout))
151 break;
152 udelay(20);
153 cond_resched();
154 lola_update_rirb(chip);
155 }
156 printk(KERN_WARNING SFX "RIRB response error\n");
157 return -EIO;
158}
159
160/* aynchronous write of a codec verb with data */
161int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,
162 unsigned int data, unsigned int extdata)
163{
164 verbose_debug("codec_write NID=%x, verb=%x, data=%x, ext=%x\n",
165 nid, verb, data, extdata);
166 return corb_send_verb(chip, nid, verb, data, extdata);
167}
168
169/* write a codec verb with data and read the returned status */
170int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,
171 unsigned int data, unsigned int extdata,
172 unsigned int *val, unsigned int *extval)
173{
174 int err;
175
176 verbose_debug("codec_read NID=%x, verb=%x, data=%x, ext=%x\n",
177 nid, verb, data, extdata);
178 err = corb_send_verb(chip, nid, verb, data, extdata);
179 if (err < 0)
180 return err;
181 err = rirb_get_response(chip, val, extval);
182 return err;
183}
184
185/* flush all pending codec writes */
186int lola_codec_flush(struct lola *chip)
187{
188 unsigned int tmp;
189 return rirb_get_response(chip, &tmp, NULL);
190}
191
192/*
193 * interrupt handler
194 */
195static irqreturn_t lola_interrupt(int irq, void *dev_id)
196{
197 struct lola *chip = dev_id;
198 unsigned int notify_ins, notify_outs, error_ins, error_outs;
199 int handled = 0;
200 int i;
201
202 notify_ins = notify_outs = error_ins = error_outs = 0;
203 spin_lock(&chip->reg_lock);
204 for (;;) {
205 unsigned int status, in_sts, out_sts;
206 unsigned int reg;
207
208 status = lola_readl(chip, BAR1, DINTSTS);
209 if (!status || status == -1)
210 break;
211
212 in_sts = lola_readl(chip, BAR1, DIINTSTS);
213 out_sts = lola_readl(chip, BAR1, DOINTSTS);
214
215 /* clear Input Interrupts */
216 for (i = 0; in_sts && i < chip->pcm[CAPT].num_streams; i++) {
217 if (!(in_sts & (1 << i)))
218 continue;
219 in_sts &= ~(1 << i);
220 reg = lola_dsd_read(chip, i, STS);
221 if (reg & LOLA_DSD_STS_DESE) /* error */
222 error_ins |= (1 << i);
223 if (reg & LOLA_DSD_STS_BCIS) /* notify */
224 notify_ins |= (1 << i);
225 /* clear */
226 lola_dsd_write(chip, i, STS, reg);
227 }
228
229 /* clear Output Interrupts */
230 for (i = 0; out_sts && i < chip->pcm[PLAY].num_streams; i++) {
231 if (!(out_sts & (1 << i)))
232 continue;
233 out_sts &= ~(1 << i);
234 reg = lola_dsd_read(chip, i + MAX_STREAM_IN_COUNT, STS);
235 if (reg & LOLA_DSD_STS_DESE) /* error */
236 error_outs |= (1 << i);
237 if (reg & LOLA_DSD_STS_BCIS) /* notify */
238 notify_outs |= (1 << i);
239 lola_dsd_write(chip, i + MAX_STREAM_IN_COUNT, STS, reg);
240 }
241
242 if (status & LOLA_DINT_CTRL) {
243 unsigned char rbsts; /* ring status is byte access */
244 rbsts = lola_readb(chip, BAR0, RIRBSTS);
245 rbsts &= LOLA_RIRB_INT_MASK;
246 if (rbsts)
247 lola_writeb(chip, BAR0, RIRBSTS, rbsts);
248 rbsts = lola_readb(chip, BAR0, CORBSTS);
249 rbsts &= LOLA_CORB_INT_MASK;
250 if (rbsts)
251 lola_writeb(chip, BAR0, CORBSTS, rbsts);
252
253 lola_update_rirb(chip);
254 }
255
256 if (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)) {
257 /* clear global fifo error interrupt */
258 lola_writel(chip, BAR1, DINTSTS,
259 (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)));
260 }
261 handled = 1;
262 }
263 spin_unlock(&chip->reg_lock);
264
265 lola_pcm_update(chip, &chip->pcm[CAPT], notify_ins);
266 lola_pcm_update(chip, &chip->pcm[PLAY], notify_outs);
267
268 return IRQ_RETVAL(handled);
269}
270
271
272/*
273 * controller
274 */
275static int reset_controller(struct lola *chip)
276{
277 unsigned int gctl = lola_readl(chip, BAR0, GCTL);
278 unsigned long end_time;
279
280 if (gctl) {
281 /* to be sure */
282 lola_writel(chip, BAR1, BOARD_MODE, 0);
283 return 0;
284 }
285
286 chip->cold_reset = 1;
287 lola_writel(chip, BAR0, GCTL, LOLA_GCTL_RESET);
288 end_time = jiffies + msecs_to_jiffies(200);
289 do {
290 msleep(1);
291 gctl = lola_readl(chip, BAR0, GCTL);
292 if (gctl)
293 break;
294 } while (time_before(jiffies, end_time));
295 if (!gctl) {
296 printk(KERN_ERR SFX "cannot reset controller\n");
297 return -EIO;
298 }
299 return 0;
300}
301
302static void lola_irq_enable(struct lola *chip)
303{
304 unsigned int val;
305
306 /* enalbe all I/O streams */
307 val = (1 << chip->pcm[PLAY].num_streams) - 1;
308 lola_writel(chip, BAR1, DOINTCTL, val);
309 val = (1 << chip->pcm[CAPT].num_streams) - 1;
310 lola_writel(chip, BAR1, DIINTCTL, val);
311
312 /* enable global irqs */
313 val = LOLA_DINT_GLOBAL | LOLA_DINT_CTRL | LOLA_DINT_FIFOERR |
314 LOLA_DINT_MUERR;
315 lola_writel(chip, BAR1, DINTCTL, val);
316}
317
318static void lola_irq_disable(struct lola *chip)
319{
320 lola_writel(chip, BAR1, DINTCTL, 0);
321 lola_writel(chip, BAR1, DIINTCTL, 0);
322 lola_writel(chip, BAR1, DOINTCTL, 0);
323}
324
325static int setup_corb_rirb(struct lola *chip)
326{
327 int err;
328 unsigned char tmp;
329 unsigned long end_time;
330
331 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
332 snd_dma_pci_data(chip->pci),
333 PAGE_SIZE, &chip->rb);
334 if (err < 0)
335 return err;
336
337 chip->corb.addr = chip->rb.addr;
338 chip->corb.buf = (u32 *)chip->rb.area;
339 chip->rirb.addr = chip->rb.addr + 2048;
340 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
341 lola_writel(chip, BAR0, CORBLBASE, (u32)chip->corb.addr);
342 lola_writel(chip, BAR0, CORBUBASE, upper_32_bits(chip->corb.addr));
343
344 /* disable ringbuffer DMAs */
345 lola_writeb(chip, BAR0, RIRBCTL, 0);
346 lola_writeb(chip, BAR0, CORBCTL, 0);
347
348 end_time = jiffies + msecs_to_jiffies(200);
349 do {
350 if (!lola_readb(chip, BAR0, RIRBCTL) &&
351 !lola_readb(chip, BAR0, CORBCTL))
352 break;
353 msleep(1);
354 } while (time_before(jiffies, end_time));
355
356 /* CORB set up */
357 lola_writel(chip, BAR0, CORBLBASE, (u32)chip->corb.addr);
358 lola_writel(chip, BAR0, CORBUBASE, upper_32_bits(chip->corb.addr));
359 /* set the corb size to 256 entries */
360 lola_writeb(chip, BAR0, CORBSIZE, 0x02);
361 /* set the corb write pointer to 0 */
362 lola_writew(chip, BAR0, CORBWP, 0);
363 /* reset the corb hw read pointer */
364 lola_writew(chip, BAR0, CORBRP, LOLA_RBRWP_CLR);
365 /* enable corb dma */
366 lola_writeb(chip, BAR0, CORBCTL, LOLA_RBCTL_DMA_EN);
367 /* clear flags if set */
368 tmp = lola_readb(chip, BAR0, CORBSTS) & LOLA_CORB_INT_MASK;
369 if (tmp)
370 lola_writeb(chip, BAR0, CORBSTS, tmp);
371 chip->corb.wp = 0;
372
373 /* RIRB set up */
374 lola_writel(chip, BAR0, RIRBLBASE, (u32)chip->rirb.addr);
375 lola_writel(chip, BAR0, RIRBUBASE, upper_32_bits(chip->rirb.addr));
376 /* set the rirb size to 256 entries */
377 lola_writeb(chip, BAR0, RIRBSIZE, 0x02);
378 /* reset the rirb hw write pointer */
379 lola_writew(chip, BAR0, RIRBWP, LOLA_RBRWP_CLR);
380 /* set N=1, get RIRB response interrupt for new entry */
381 lola_writew(chip, BAR0, RINTCNT, 1);
382 /* enable rirb dma and response irq */
383 lola_writeb(chip, BAR0, RIRBCTL, LOLA_RBCTL_DMA_EN | LOLA_RBCTL_IRQ_EN);
384 /* clear flags if set */
385 tmp = lola_readb(chip, BAR0, RIRBSTS) & LOLA_RIRB_INT_MASK;
386 if (tmp)
387 lola_writeb(chip, BAR0, RIRBSTS, tmp);
388 chip->rirb.rp = chip->rirb.cmds = 0;
389
390 return 0;
391}
392
393static void stop_corb_rirb(struct lola *chip)
394{
395 /* disable ringbuffer DMAs */
396 lola_writeb(chip, BAR0, RIRBCTL, 0);
397 lola_writeb(chip, BAR0, CORBCTL, 0);
398}
399
400static void lola_reset_setups(struct lola *chip)
401{
402 /* update the granularity */
403 lola_set_granularity(chip, chip->granularity, true);
404 /* update the sample clock */
405 lola_set_clock_index(chip, chip->clock.cur_index);
406 /* enable unsolicited events of the clock widget */
407 lola_enable_clock_events(chip);
408 /* update the analog gains */
409 lola_setup_all_analog_gains(chip, CAPT, false); /* input, update */
410 /* update SRC configuration if applicable */
411 lola_set_src_config(chip, chip->input_src_mask, false);
412 /* update the analog outputs */
413 lola_setup_all_analog_gains(chip, PLAY, false); /* output, update */
414}
415
416static int lola_parse_tree(struct lola *chip)
417{
418 unsigned int val;
419 int nid, err;
420
421 err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
422 if (err < 0) {
423 printk(KERN_ERR SFX "Can't read VENDOR_ID\n");
424 return err;
425 }
426 val >>= 16;
427 if (val != 0x1369) {
428 printk(KERN_ERR SFX "Unknown codec vendor 0x%x\n", val);
429 return -EINVAL;
430 }
431
432 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
433 if (err < 0) {
434 printk(KERN_ERR SFX "Can't read FUNCTION_TYPE for 0x%x\n", nid);
435 return err;
436 }
437 if (val != 1) {
438 printk(KERN_ERR SFX "Unknown function type %d\n", val);
439 return -EINVAL;
440 }
441
442 err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
443 if (err < 0) {
444 printk(KERN_ERR SFX "Can't read SPECCAPS\n");
445 return err;
446 }
447 chip->lola_caps = val;
448 chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps);
449 chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps);
450 snd_printd(SFX "speccaps=0x%x, pins in=%d, out=%d\n",
451 chip->lola_caps,
452 chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
453
454 if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT ||
455 chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) {
456 printk(KERN_ERR SFX "Invalid Lola-spec caps 0x%x\n", val);
457 return -EINVAL;
458 }
459
460 nid = 0x02;
461 err = lola_init_pcm(chip, CAPT, &nid);
462 if (err < 0)
463 return err;
464 err = lola_init_pcm(chip, PLAY, &nid);
465 if (err < 0)
466 return err;
467
468 err = lola_init_pins(chip, CAPT, &nid);
469 if (err < 0)
470 return err;
471 err = lola_init_pins(chip, PLAY, &nid);
472 if (err < 0)
473 return err;
474
475 if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
476 err = lola_init_clock_widget(chip, nid);
477 if (err < 0)
478 return err;
479 nid++;
480 }
481 if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
482 err = lola_init_mixer_widget(chip, nid);
483 if (err < 0)
484 return err;
485 nid++;
486 }
487
488 /* enable unsolicited events of the clock widget */
489 err = lola_enable_clock_events(chip);
490 if (err < 0)
491 return err;
492
493 /* if last ResetController was not a ColdReset, we don't know
494 * the state of the card; initialize here again
495 */
496 if (!chip->cold_reset) {
497 lola_reset_setups(chip);
498 chip->cold_reset = 1;
499 }
500
501 return 0;
502}
503
504static void lola_stop_hw(struct lola *chip)
505{
506 stop_corb_rirb(chip);
507 lola_irq_disable(chip);
508}
509
510static void lola_free(struct lola *chip)
511{
512 if (chip->initialized)
513 lola_stop_hw(chip);
514 lola_free_pcm(chip);
515 lola_free_mixer(chip);
516 if (chip->irq >= 0)
517 free_irq(chip->irq, (void *)chip);
518 if (chip->bar[0].remap_addr)
519 iounmap(chip->bar[0].remap_addr);
520 if (chip->bar[1].remap_addr)
521 iounmap(chip->bar[1].remap_addr);
522 if (chip->rb.area)
523 snd_dma_free_pages(&chip->rb);
524 pci_release_regions(chip->pci);
525 pci_disable_device(chip->pci);
526 kfree(chip);
527}
528
529static int lola_dev_free(struct snd_device *device)
530{
531 lola_free(device->device_data);
532 return 0;
533}
534
535static int __devinit lola_create(struct snd_card *card, struct pci_dev *pci,
536 struct lola **rchip)
537{
538 struct lola *chip;
539 int err;
540 unsigned int dever;
541 static struct snd_device_ops ops = {
542 .dev_free = lola_dev_free,
543 };
544
545 *rchip = NULL;
546
547 err = pci_enable_device(pci);
548 if (err < 0)
549 return err;
550
551 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
552 if (!chip) {
553 snd_printk(KERN_ERR SFX "cannot allocate chip\n");
554 pci_disable_device(pci);
555 return -ENOMEM;
556 }
557
558 spin_lock_init(&chip->reg_lock);
559 mutex_init(&chip->open_mutex);
560 chip->card = card;
561 chip->pci = pci;
562 chip->irq = -1;
563
564 chip->sample_rate_min = 48000;
565 chip->granularity = LOLA_GRANULARITY_MIN;
566
567 err = pci_request_regions(pci, DRVNAME);
568 if (err < 0) {
569 kfree(chip);
570 pci_disable_device(pci);
571 return err;
572 }
573
574 chip->bar[0].addr = pci_resource_start(pci, 0);
575 chip->bar[0].remap_addr = pci_ioremap_bar(pci, 0);
576 chip->bar[1].addr = pci_resource_start(pci, 2);
577 chip->bar[1].remap_addr = pci_ioremap_bar(pci, 2);
578 if (!chip->bar[0].remap_addr || !chip->bar[1].remap_addr) {
579 snd_printk(KERN_ERR SFX "ioremap error\n");
580 err = -ENXIO;
581 goto errout;
582 }
583
584 pci_set_master(pci);
585
586 err = reset_controller(chip);
587 if (err < 0)
588 goto errout;
589
590 if (request_irq(pci->irq, lola_interrupt, IRQF_SHARED,
591 DRVNAME, chip)) {
592 printk(KERN_ERR SFX "unable to grab IRQ %d\n", pci->irq);
593 err = -EBUSY;
594 goto errout;
595 }
596 chip->irq = pci->irq;
597 synchronize_irq(chip->irq);
598
599 dever = lola_readl(chip, BAR1, DEVER);
600 chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff;
601 chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff;
602 chip->version = (dever >> 24) & 0xff;
603 snd_printd(SFX "streams in=%d, out=%d, version=0x%x\n",
604 chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams,
605 chip->version);
606
607 /* Test LOLA_BAR1_DEVER */
608 if (chip->pcm[CAPT].num_streams > MAX_STREAM_IN_COUNT ||
609 chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT ||
610 (!chip->pcm[CAPT].num_streams &&
611 !chip->pcm[PLAY].num_streams)) {
612 printk(KERN_ERR SFX "invalid DEVER = %x\n", dever);
613 err = -EINVAL;
614 goto errout;
615 }
616
617 err = setup_corb_rirb(chip);
618 if (err < 0)
619 goto errout;
620
621 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
622 if (err < 0) {
623 snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
624 goto errout;
625 }
626
627 strcpy(card->driver, "Lola");
628 strlcpy(card->shortname, "Digigram Lola", sizeof(card->shortname));
629 snprintf(card->longname, sizeof(card->longname),
630 "%s at 0x%lx irq %i",
631 card->shortname, chip->bar[0].addr, chip->irq);
632 strcpy(card->mixername, card->shortname);
633
634 lola_irq_enable(chip);
635
636 chip->initialized = 1;
637 *rchip = chip;
638 return 0;
639
640 errout:
641 lola_free(chip);
642 return err;
643}
644
645static int __devinit lola_probe(struct pci_dev *pci,
646 const struct pci_device_id *pci_id)
647{
648 static int dev;
649 struct snd_card *card;
650 struct lola *chip;
651 int err;
652
653 if (dev >= SNDRV_CARDS)
654 return -ENODEV;
655 if (!enable[dev]) {
656 dev++;
657 return -ENOENT;
658 }
659
660 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
661 if (err < 0) {
662 snd_printk(KERN_ERR SFX "Error creating card!\n");
663 return err;
664 }
665
666 snd_card_set_dev(card, &pci->dev);
667
668 err = lola_create(card, pci, &chip);
669 if (err < 0)
670 goto out_free;
671 card->private_data = chip;
672
673 err = lola_parse_tree(chip);
674 if (err < 0)
675 goto out_free;
676
677 err = lola_create_pcm(chip);
678 if (err < 0)
679 goto out_free;
680
681 err = lola_create_mixer(chip);
682 if (err < 0)
683 goto out_free;
684
685 lola_proc_debug_new(chip);
686
687 err = snd_card_register(card);
688 if (err < 0)
689 goto out_free;
690
691 pci_set_drvdata(pci, card);
692 dev++;
693 return err;
694out_free:
695 snd_card_free(card);
696 return err;
697}
698
699static void __devexit lola_remove(struct pci_dev *pci)
700{
701 snd_card_free(pci_get_drvdata(pci));
702 pci_set_drvdata(pci, NULL);
703}
704
705/* PCI IDs */
706static DEFINE_PCI_DEVICE_TABLE(lola_ids) = {
707 { PCI_VDEVICE(DIGIGRAM, 0x0001) },
708 { 0, }
709};
710MODULE_DEVICE_TABLE(pci, lola_ids);
711
712/* pci_driver definition */
713static struct pci_driver driver = {
714 .name = DRVNAME,
715 .id_table = lola_ids,
716 .probe = lola_probe,
717 .remove = __devexit_p(lola_remove),
718};
719
720static int __init alsa_card_lola_init(void)
721{
722 return pci_register_driver(&driver);
723}
724
725static void __exit alsa_card_lola_exit(void)
726{
727 pci_unregister_driver(&driver);
728}
729
730module_init(alsa_card_lola_init)
731module_exit(alsa_card_lola_exit)
This page took 0.05065 seconds and 5 git commands to generate.