Lines Matching +full:wp +full:- +full:controller

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for Digigram Lola PCI-e boards
11 #include <linux/dma-mapping.h>
34 /* Lola-specific options */
40 [0 ... (SNDRV_CARDS - 1)] = LOLA_GRANULARITY_MAX
45 [0 ... (SNDRV_CARDS - 1) ] = 16000
70 * pseudo-codec read/write via CORB/RIRB
78 int ret = -EIO; in corb_send_verb()
80 chip->last_cmd_nid = nid; in corb_send_verb()
81 chip->last_verb = verb; in corb_send_verb()
82 chip->last_data = data; in corb_send_verb()
83 chip->last_extdata = extdata; in corb_send_verb()
86 spin_lock_irqsave(&chip->reg_lock, flags); in corb_send_verb()
87 if (chip->rirb.cmds < LOLA_CORB_ENTRIES - 1) { in corb_send_verb()
88 unsigned int wp = chip->corb.wp + 1; in corb_send_verb() local
89 wp %= LOLA_CORB_ENTRIES; in corb_send_verb()
90 chip->corb.wp = wp; in corb_send_verb()
91 chip->corb.buf[wp * 2] = cpu_to_le32(data); in corb_send_verb()
92 chip->corb.buf[wp * 2 + 1] = cpu_to_le32(extdata); in corb_send_verb()
93 lola_writew(chip, BAR0, CORBWP, wp); in corb_send_verb()
94 chip->rirb.cmds++; in corb_send_verb()
98 spin_unlock_irqrestore(&chip->reg_lock, flags); in corb_send_verb()
108 /* retrieve RIRB entry - called from interrupt handler */
111 unsigned int rp, wp; in lola_update_rirb() local
114 wp = lola_readw(chip, BAR0, RIRBWP); in lola_update_rirb()
115 if (wp == chip->rirb.wp) in lola_update_rirb()
117 chip->rirb.wp = wp; in lola_update_rirb()
119 while (chip->rirb.rp != wp) { in lola_update_rirb()
120 chip->rirb.rp++; in lola_update_rirb()
121 chip->rirb.rp %= LOLA_CORB_ENTRIES; in lola_update_rirb()
123 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ in lola_update_rirb()
124 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); in lola_update_rirb()
125 res = le32_to_cpu(chip->rirb.buf[rp]); in lola_update_rirb()
128 else if (chip->rirb.cmds) { in lola_update_rirb()
129 chip->res = res; in lola_update_rirb()
130 chip->res_ex = res_ex; in lola_update_rirb()
132 chip->rirb.cmds--; in lola_update_rirb()
145 if (chip->polling_mode) { in rirb_get_response()
146 spin_lock_irq(&chip->reg_lock); in rirb_get_response()
148 spin_unlock_irq(&chip->reg_lock); in rirb_get_response()
150 if (!chip->rirb.cmds) { in rirb_get_response()
151 *val = chip->res; in rirb_get_response()
153 *extval = chip->res_ex; in rirb_get_response()
155 chip->res, chip->res_ex); in rirb_get_response()
156 if (chip->res_ex & LOLA_RIRB_EX_ERROR) { in rirb_get_response()
157 dev_warn(chip->card->dev, "RIRB ERROR: " in rirb_get_response()
159 chip->last_cmd_nid, in rirb_get_response()
160 chip->last_verb, chip->last_data, in rirb_get_response()
161 chip->last_extdata); in rirb_get_response()
162 return -EIO; in rirb_get_response()
171 dev_warn(chip->card->dev, "RIRB response error\n"); in rirb_get_response()
172 if (!chip->polling_mode) { in rirb_get_response()
173 dev_warn(chip->card->dev, "switching to polling mode\n"); in rirb_get_response()
174 chip->polling_mode = 1; in rirb_get_response()
177 return -EIO; in rirb_get_response()
223 spin_lock(&chip->reg_lock); in lola_interrupt()
229 if (!status || status == -1) in lola_interrupt()
236 for (i = 0; in_sts && i < chip->pcm[CAPT].num_streams; i++) { in lola_interrupt()
250 for (i = 0; out_sts && i < chip->pcm[PLAY].num_streams; i++) { in lola_interrupt()
283 spin_unlock(&chip->reg_lock); in lola_interrupt()
285 lola_pcm_update(chip, &chip->pcm[CAPT], notify_ins); in lola_interrupt()
286 lola_pcm_update(chip, &chip->pcm[PLAY], notify_outs); in lola_interrupt()
293 * controller
306 chip->cold_reset = 1; in reset_controller()
316 dev_err(chip->card->dev, "cannot reset controller\n"); in reset_controller()
317 return -EIO; in reset_controller()
327 val = (1 << chip->pcm[PLAY].num_streams) - 1; in lola_irq_enable()
329 val = (1 << chip->pcm[CAPT].num_streams) - 1; in lola_irq_enable()
350 chip->rb = snd_devm_alloc_pages(&chip->pci->dev, SNDRV_DMA_TYPE_DEV, in setup_corb_rirb()
352 if (!chip->rb) in setup_corb_rirb()
353 return -ENOMEM; in setup_corb_rirb()
355 chip->corb.addr = chip->rb->addr; in setup_corb_rirb()
356 chip->corb.buf = (__le32 *)chip->rb->area; in setup_corb_rirb()
357 chip->rirb.addr = chip->rb->addr + 2048; in setup_corb_rirb()
358 chip->rirb.buf = (__le32 *)(chip->rb->area + 2048); in setup_corb_rirb()
373 lola_writel(chip, BAR0, CORBLBASE, (u32)chip->corb.addr); in setup_corb_rirb()
374 lola_writel(chip, BAR0, CORBUBASE, upper_32_bits(chip->corb.addr)); in setup_corb_rirb()
387 chip->corb.wp = 0; in setup_corb_rirb()
390 lola_writel(chip, BAR0, RIRBLBASE, (u32)chip->rirb.addr); in setup_corb_rirb()
391 lola_writel(chip, BAR0, RIRBUBASE, upper_32_bits(chip->rirb.addr)); in setup_corb_rirb()
404 chip->rirb.rp = chip->rirb.cmds = 0; in setup_corb_rirb()
419 lola_set_granularity(chip, chip->granularity, true); in lola_reset_setups()
421 lola_set_clock_index(chip, chip->clock.cur_index); in lola_reset_setups()
427 lola_set_src_config(chip, chip->input_src_mask, false); in lola_reset_setups()
439 dev_err(chip->card->dev, "Can't read VENDOR_ID\n"); in lola_parse_tree()
444 dev_err(chip->card->dev, "Unknown codec vendor 0x%x\n", val); in lola_parse_tree()
445 return -EINVAL; in lola_parse_tree()
450 dev_err(chip->card->dev, "Can't read FUNCTION_TYPE\n"); in lola_parse_tree()
454 dev_err(chip->card->dev, "Unknown function type %d\n", val); in lola_parse_tree()
455 return -EINVAL; in lola_parse_tree()
460 dev_err(chip->card->dev, "Can't read SPECCAPS\n"); in lola_parse_tree()
463 chip->lola_caps = val; in lola_parse_tree()
464 chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps); in lola_parse_tree()
465 chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps); in lola_parse_tree()
466 dev_dbg(chip->card->dev, "speccaps=0x%x, pins in=%d, out=%d\n", in lola_parse_tree()
467 chip->lola_caps, in lola_parse_tree()
468 chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins); in lola_parse_tree()
470 if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT || in lola_parse_tree()
471 chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) { in lola_parse_tree()
472 dev_err(chip->card->dev, "Invalid Lola-spec caps 0x%x\n", val); in lola_parse_tree()
473 return -EINVAL; in lola_parse_tree()
491 if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) { in lola_parse_tree()
497 if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) { in lola_parse_tree()
512 if (!chip->cold_reset) { in lola_parse_tree()
514 chip->cold_reset = 1; in lola_parse_tree()
517 if (chip->granularity != LOLA_GRANULARITY_MIN) in lola_parse_tree()
518 lola_set_granularity(chip, chip->granularity, true); in lola_parse_tree()
532 struct lola *chip = card->private_data; in lola_free()
534 if (chip->initialized) in lola_free()
541 struct lola *chip = card->private_data; in lola_create()
549 spin_lock_init(&chip->reg_lock); in lola_create()
550 mutex_init(&chip->open_mutex); in lola_create()
551 chip->card = card; in lola_create()
552 chip->pci = pci; in lola_create()
553 chip->irq = -1; in lola_create()
554 card->private_free = lola_free; in lola_create()
556 chip->granularity = granularity[dev]; in lola_create()
557 switch (chip->granularity) { in lola_create()
559 chip->sample_rate_max = 48000; in lola_create()
562 chip->sample_rate_max = 96000; in lola_create()
565 chip->sample_rate_max = 192000; in lola_create()
568 dev_warn(chip->card->dev, in lola_create()
570 chip->granularity, LOLA_GRANULARITY_MAX); in lola_create()
571 chip->granularity = LOLA_GRANULARITY_MAX; in lola_create()
572 chip->sample_rate_max = 192000; in lola_create()
575 chip->sample_rate_min = sample_rate_min[dev]; in lola_create()
576 if (chip->sample_rate_min > chip->sample_rate_max) { in lola_create()
577 dev_warn(chip->card->dev, in lola_create()
579 chip->sample_rate_min); in lola_create()
580 chip->sample_rate_min = 16000; in lola_create()
587 chip->bar[0].addr = pci_resource_start(pci, 0); in lola_create()
588 chip->bar[0].remap_addr = pcim_iomap_table(pci)[0]; in lola_create()
589 chip->bar[1].addr = pci_resource_start(pci, 2); in lola_create()
590 chip->bar[1].remap_addr = pcim_iomap_table(pci)[2]; in lola_create()
598 if (devm_request_irq(&pci->dev, pci->irq, lola_interrupt, IRQF_SHARED, in lola_create()
600 dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq); in lola_create()
601 return -EBUSY; in lola_create()
603 chip->irq = pci->irq; in lola_create()
604 card->sync_irq = chip->irq; in lola_create()
607 chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff; in lola_create()
608 chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff; in lola_create()
609 chip->version = (dever >> 24) & 0xff; in lola_create()
610 dev_dbg(chip->card->dev, "streams in=%d, out=%d, version=0x%x\n", in lola_create()
611 chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams, in lola_create()
612 chip->version); in lola_create()
615 if (chip->pcm[CAPT].num_streams > MAX_STREAM_IN_COUNT || in lola_create()
616 chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT || in lola_create()
617 (!chip->pcm[CAPT].num_streams && in lola_create()
618 !chip->pcm[PLAY].num_streams)) { in lola_create()
619 dev_err(chip->card->dev, "invalid DEVER = %x\n", dever); in lola_create()
620 return -EINVAL; in lola_create()
627 strcpy(card->driver, "Lola"); in lola_create()
628 strscpy(card->shortname, "Digigram Lola", sizeof(card->shortname)); in lola_create()
629 snprintf(card->longname, sizeof(card->longname), in lola_create()
631 card->shortname, chip->bar[0].addr, chip->irq); in lola_create()
632 strcpy(card->mixername, card->shortname); in lola_create()
636 chip->initialized = 1; in lola_create()
649 return -ENODEV; in __lola_probe()
652 return -ENOENT; in __lola_probe()
655 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, in __lola_probe()
658 dev_err(&pci->dev, "Error creating card!\n"); in __lola_probe()
661 chip = card->private_data; in __lola_probe()
693 return snd_card_free_on_error(&pci->dev, __lola_probe(pci, pci_id)); in lola_probe()