Lines Matching full:chip

73 static int corb_send_verb(struct lola *chip, unsigned int nid,  in corb_send_verb()  argument
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()
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()
102 static void lola_queue_unsol_event(struct lola *chip, unsigned int res, in lola_queue_unsol_event() argument
105 lola_update_ext_clock_freq(chip, res); in lola_queue_unsol_event()
109 static void lola_update_rirb(struct lola *chip) in lola_update_rirb() argument
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()
127 lola_queue_unsol_event(chip, res, res_ex); 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()
137 static int rirb_get_response(struct lola *chip, unsigned int *val, in rirb_get_response() argument
145 if (chip->polling_mode) { in rirb_get_response()
146 spin_lock_irq(&chip->reg_lock); in rirb_get_response()
147 lola_update_rirb(chip); 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()
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()
181 int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb, in lola_codec_write() argument
186 return corb_send_verb(chip, nid, verb, data, extdata); in lola_codec_write()
190 int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb, in lola_codec_read() argument
198 err = corb_send_verb(chip, nid, verb, data, extdata); in lola_codec_read()
201 err = rirb_get_response(chip, val, extval); in lola_codec_read()
206 int lola_codec_flush(struct lola *chip) in lola_codec_flush() argument
209 return rirb_get_response(chip, &tmp, NULL); in lola_codec_flush()
217 struct lola *chip = dev_id; in lola_interrupt() local
223 spin_lock(&chip->reg_lock); in lola_interrupt()
228 status = lola_readl(chip, BAR1, DINTSTS); in lola_interrupt()
232 in_sts = lola_readl(chip, BAR1, DIINTSTS); in lola_interrupt()
233 out_sts = lola_readl(chip, BAR1, DOINTSTS); in lola_interrupt()
236 for (i = 0; in_sts && i < chip->pcm[CAPT].num_streams; i++) { in lola_interrupt()
240 reg = lola_dsd_read(chip, i, STS); in lola_interrupt()
246 lola_dsd_write(chip, i, STS, reg); in lola_interrupt()
250 for (i = 0; out_sts && i < chip->pcm[PLAY].num_streams; i++) { in lola_interrupt()
254 reg = lola_dsd_read(chip, i + MAX_STREAM_IN_COUNT, STS); in lola_interrupt()
259 lola_dsd_write(chip, i + MAX_STREAM_IN_COUNT, STS, reg); in lola_interrupt()
264 rbsts = lola_readb(chip, BAR0, RIRBSTS); in lola_interrupt()
267 lola_writeb(chip, BAR0, RIRBSTS, rbsts); in lola_interrupt()
268 rbsts = lola_readb(chip, BAR0, CORBSTS); in lola_interrupt()
271 lola_writeb(chip, BAR0, CORBSTS, rbsts); in lola_interrupt()
273 lola_update_rirb(chip); in lola_interrupt()
278 lola_writel(chip, BAR1, DINTSTS, 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()
295 static int reset_controller(struct lola *chip) in reset_controller() argument
297 unsigned int gctl = lola_readl(chip, BAR0, GCTL); in reset_controller()
302 lola_writel(chip, BAR1, BOARD_MODE, 0); in reset_controller()
306 chip->cold_reset = 1; in reset_controller()
307 lola_writel(chip, BAR0, GCTL, LOLA_GCTL_RESET); in reset_controller()
311 gctl = lola_readl(chip, BAR0, GCTL); in reset_controller()
316 dev_err(chip->card->dev, "cannot reset controller\n"); in reset_controller()
322 static void lola_irq_enable(struct lola *chip) in lola_irq_enable() argument
327 val = (1 << chip->pcm[PLAY].num_streams) - 1; in lola_irq_enable()
328 lola_writel(chip, BAR1, DOINTCTL, val); in lola_irq_enable()
329 val = (1 << chip->pcm[CAPT].num_streams) - 1; in lola_irq_enable()
330 lola_writel(chip, BAR1, DIINTCTL, val); in lola_irq_enable()
335 lola_writel(chip, BAR1, DINTCTL, val); in lola_irq_enable()
338 static void lola_irq_disable(struct lola *chip) in lola_irq_disable() argument
340 lola_writel(chip, BAR1, DINTCTL, 0); in lola_irq_disable()
341 lola_writel(chip, BAR1, DIINTCTL, 0); in lola_irq_disable()
342 lola_writel(chip, BAR1, DOINTCTL, 0); in lola_irq_disable()
345 static int setup_corb_rirb(struct lola *chip) in setup_corb_rirb() argument
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()
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()
361 lola_writeb(chip, BAR0, RIRBCTL, 0); in setup_corb_rirb()
362 lola_writeb(chip, BAR0, CORBCTL, 0); in setup_corb_rirb()
366 if (!lola_readb(chip, BAR0, RIRBCTL) && in setup_corb_rirb()
367 !lola_readb(chip, BAR0, CORBCTL)) 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()
376 lola_writeb(chip, BAR0, CORBSIZE, 0x02); in setup_corb_rirb()
378 lola_writew(chip, BAR0, CORBWP, 0); in setup_corb_rirb()
380 lola_writew(chip, BAR0, CORBRP, LOLA_RBRWP_CLR); in setup_corb_rirb()
382 lola_writeb(chip, BAR0, CORBCTL, LOLA_RBCTL_DMA_EN); in setup_corb_rirb()
384 tmp = lola_readb(chip, BAR0, CORBSTS) & LOLA_CORB_INT_MASK; in setup_corb_rirb()
386 lola_writeb(chip, BAR0, CORBSTS, tmp); 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()
393 lola_writeb(chip, BAR0, RIRBSIZE, 0x02); in setup_corb_rirb()
395 lola_writew(chip, BAR0, RIRBWP, LOLA_RBRWP_CLR); in setup_corb_rirb()
397 lola_writew(chip, BAR0, RINTCNT, 1); in setup_corb_rirb()
399 lola_writeb(chip, BAR0, RIRBCTL, LOLA_RBCTL_DMA_EN | LOLA_RBCTL_IRQ_EN); in setup_corb_rirb()
401 tmp = lola_readb(chip, BAR0, RIRBSTS) & LOLA_RIRB_INT_MASK; in setup_corb_rirb()
403 lola_writeb(chip, BAR0, RIRBSTS, tmp); in setup_corb_rirb()
404 chip->rirb.rp = chip->rirb.cmds = 0; in setup_corb_rirb()
409 static void stop_corb_rirb(struct lola *chip) in stop_corb_rirb() argument
412 lola_writeb(chip, BAR0, RIRBCTL, 0); in stop_corb_rirb()
413 lola_writeb(chip, BAR0, CORBCTL, 0); in stop_corb_rirb()
416 static void lola_reset_setups(struct lola *chip) in lola_reset_setups() argument
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()
423 lola_enable_clock_events(chip); in lola_reset_setups()
425 lola_setup_all_analog_gains(chip, CAPT, false); /* input, update */ in lola_reset_setups()
427 lola_set_src_config(chip, chip->input_src_mask, false); in lola_reset_setups()
429 lola_setup_all_analog_gains(chip, PLAY, false); /* output, update */ in lola_reset_setups()
432 static int lola_parse_tree(struct lola *chip) in lola_parse_tree() argument
437 err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val); in lola_parse_tree()
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()
448 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val); 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()
458 err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val); 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()
477 err = lola_init_pcm(chip, CAPT, &nid); in lola_parse_tree()
480 err = lola_init_pcm(chip, PLAY, &nid); in lola_parse_tree()
484 err = lola_init_pins(chip, CAPT, &nid); in lola_parse_tree()
487 err = lola_init_pins(chip, PLAY, &nid); in lola_parse_tree()
491 if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) { in lola_parse_tree()
492 err = lola_init_clock_widget(chip, nid); in lola_parse_tree()
497 if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) { in lola_parse_tree()
498 err = lola_init_mixer_widget(chip, nid); in lola_parse_tree()
505 err = lola_enable_clock_events(chip); in lola_parse_tree()
512 if (!chip->cold_reset) { in lola_parse_tree()
513 lola_reset_setups(chip); 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()
524 static void lola_stop_hw(struct lola *chip) in lola_stop_hw() argument
526 stop_corb_rirb(chip); in lola_stop_hw()
527 lola_irq_disable(chip); in lola_stop_hw()
532 struct lola *chip = card->private_data; in lola_free() local
534 if (chip->initialized) in lola_free()
535 lola_stop_hw(chip); in lola_free()
536 lola_free_mixer(chip); in lola_free()
541 struct lola *chip = card->private_data; in lola_create() local
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()
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()
594 err = reset_controller(chip); in lola_create()
599 KBUILD_MODNAME, chip)) { in lola_create()
600 dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq); in lola_create()
603 chip->irq = pci->irq; in lola_create()
604 card->sync_irq = chip->irq; in lola_create()
606 dever = lola_readl(chip, BAR1, DEVER); 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()
623 err = setup_corb_rirb(chip); in lola_create()
631 card->shortname, chip->bar[0].addr, chip->irq); in lola_create()
634 lola_irq_enable(chip); in lola_create()
636 chip->initialized = 1; in lola_create()
645 struct lola *chip; in __lola_probe() local
656 sizeof(*chip), &card); in __lola_probe()
661 chip = card->private_data; in __lola_probe()
667 err = lola_parse_tree(chip); in __lola_probe()
671 err = lola_create_pcm(chip); in __lola_probe()
675 err = lola_create_mixer(chip); in __lola_probe()
679 lola_proc_debug_new(chip); in __lola_probe()