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