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