Lines Matching +full:timeout +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-only
3 * HD-audio controller helpers
17 int timeout; in azx_clear_corbrp() local
19 for (timeout = 1000; timeout > 0; timeout--) { in azx_clear_corbrp()
24 if (timeout <= 0) in azx_clear_corbrp()
25 dev_err(bus->dev, "CORB reset timeout#1, CORBRP = %d\n", in azx_clear_corbrp()
29 for (timeout = 1000; timeout > 0; timeout--) { in azx_clear_corbrp()
34 if (timeout <= 0) in azx_clear_corbrp()
35 dev_err(bus->dev, "CORB reset timeout#2, CORBRP = %d\n", in azx_clear_corbrp()
40 * snd_hdac_bus_init_cmd_io - set up CORB/RIRB buffers
41 * @bus: HD-audio core bus
45 WARN_ON_ONCE(!bus->rb.area); in snd_hdac_bus_init_cmd_io()
47 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
49 bus->corb.addr = bus->rb.addr; in snd_hdac_bus_init_cmd_io()
50 bus->corb.buf = (__le32 *)bus->rb.area; in snd_hdac_bus_init_cmd_io()
51 snd_hdac_chip_writel(bus, CORBLBASE, (u32)bus->corb.addr); in snd_hdac_bus_init_cmd_io()
52 snd_hdac_chip_writel(bus, CORBUBASE, upper_32_bits(bus->corb.addr)); in snd_hdac_bus_init_cmd_io()
61 if (!bus->corbrp_self_clear) in snd_hdac_bus_init_cmd_io()
64 /* enable corb dma */ in snd_hdac_bus_init_cmd_io()
65 if (!bus->use_pio_for_commands) in snd_hdac_bus_init_cmd_io()
69 bus->rirb.addr = bus->rb.addr + 2048; in snd_hdac_bus_init_cmd_io()
70 bus->rirb.buf = (__le32 *)(bus->rb.area + 2048); in snd_hdac_bus_init_cmd_io()
71 bus->rirb.wp = bus->rirb.rp = 0; in snd_hdac_bus_init_cmd_io()
72 memset(bus->rirb.cmds, 0, sizeof(bus->rirb.cmds)); in snd_hdac_bus_init_cmd_io()
73 snd_hdac_chip_writel(bus, RIRBLBASE, (u32)bus->rirb.addr); in snd_hdac_bus_init_cmd_io()
74 snd_hdac_chip_writel(bus, RIRBUBASE, upper_32_bits(bus->rirb.addr)); in snd_hdac_bus_init_cmd_io()
82 /* enable rirb dma and response irq */ in snd_hdac_bus_init_cmd_io()
83 if (bus->not_use_interrupts) in snd_hdac_bus_init_cmd_io()
89 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
96 unsigned long timeout; in hdac_wait_for_cmd_dmas() local
98 timeout = jiffies + msecs_to_jiffies(100); in hdac_wait_for_cmd_dmas()
100 && time_before(jiffies, timeout)) in hdac_wait_for_cmd_dmas()
103 timeout = jiffies + msecs_to_jiffies(100); in hdac_wait_for_cmd_dmas()
105 && time_before(jiffies, timeout)) in hdac_wait_for_cmd_dmas()
110 * snd_hdac_bus_stop_cmd_io - clean up CORB/RIRB buffers
111 * @bus: HD-audio core bus
115 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
119 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
123 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
126 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
143 int timeout = 50; in snd_hdac_bus_wait_for_pio_response() local
145 while (timeout--) { in snd_hdac_bus_wait_for_pio_response()
149 bus->rirb.res[addr] = snd_hdac_chip_readl(bus, IR); in snd_hdac_bus_wait_for_pio_response()
155 dev_dbg_ratelimited(bus->dev, "get_response_pio timeout: IRS=%#x\n", in snd_hdac_bus_wait_for_pio_response()
158 bus->rirb.res[addr] = -1; in snd_hdac_bus_wait_for_pio_response()
160 return -EIO; in snd_hdac_bus_wait_for_pio_response()
164 * snd_hdac_bus_send_cmd_pio - send a command verb via Immediate Command
165 * @bus: HD-audio core bus
173 int timeout = 50; in snd_hdac_bus_send_cmd_pio() local
174 int ret = -EIO; in snd_hdac_bus_send_cmd_pio()
176 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_pio()
178 while (timeout--) { in snd_hdac_bus_send_cmd_pio()
193 dev_dbg_ratelimited(bus->dev, "send_cmd_pio timeout: IRS=%#x, val=%#x\n", in snd_hdac_bus_send_cmd_pio()
197 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_pio()
203 * snd_hdac_bus_get_response_pio - receive a response via Immediate Response
204 * @bus: HD-audio core bus
214 *res = bus->rirb.res[addr]; in snd_hdac_bus_get_response_pio()
220 * snd_hdac_bus_send_cmd_corb - send a command verb via CORB
221 * @bus: HD-audio core bus
231 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_corb()
233 bus->last_cmd[azx_command_addr(val)] = val; in snd_hdac_bus_send_cmd_corb()
239 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_corb()
240 return -EIO; in snd_hdac_bus_send_cmd_corb()
248 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_corb()
249 return -EAGAIN; in snd_hdac_bus_send_cmd_corb()
252 bus->rirb.cmds[addr]++; in snd_hdac_bus_send_cmd_corb()
253 bus->corb.buf[wp] = cpu_to_le32(val); in snd_hdac_bus_send_cmd_corb()
256 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_corb()
264 * snd_hdac_bus_update_rirb - retrieve RIRB entries
265 * @bus: HD-audio core bus
268 * The caller needs bus->reg_lock spinlock before calling this.
282 if (wp == bus->rirb.wp) in snd_hdac_bus_update_rirb()
284 bus->rirb.wp = wp; in snd_hdac_bus_update_rirb()
286 while (bus->rirb.rp != wp) { in snd_hdac_bus_update_rirb()
287 bus->rirb.rp++; in snd_hdac_bus_update_rirb()
288 bus->rirb.rp %= AZX_MAX_RIRB_ENTRIES; in snd_hdac_bus_update_rirb()
290 rp = bus->rirb.rp << 1; /* an RIRB entry is 8-bytes */ in snd_hdac_bus_update_rirb()
291 res_ex = le32_to_cpu(bus->rirb.buf[rp + 1]); in snd_hdac_bus_update_rirb()
292 res = le32_to_cpu(bus->rirb.buf[rp]); in snd_hdac_bus_update_rirb()
295 dev_err(bus->dev, in snd_hdac_bus_update_rirb()
297 res, res_ex, bus->rirb.rp, wp); in snd_hdac_bus_update_rirb()
301 else if (bus->rirb.cmds[addr]) { in snd_hdac_bus_update_rirb()
302 bus->rirb.res[addr] = res; in snd_hdac_bus_update_rirb()
303 bus->rirb.cmds[addr]--; in snd_hdac_bus_update_rirb()
304 if (!bus->rirb.cmds[addr] && in snd_hdac_bus_update_rirb()
305 waitqueue_active(&bus->rirb_wq)) in snd_hdac_bus_update_rirb()
306 wake_up(&bus->rirb_wq); in snd_hdac_bus_update_rirb()
308 dev_err_ratelimited(bus->dev, in snd_hdac_bus_update_rirb()
310 res, res_ex, bus->last_cmd[addr]); in snd_hdac_bus_update_rirb()
317 * snd_hdac_bus_get_response_rirb - receive a response via RIRB
318 * @bus: HD-audio core bus
327 unsigned long timeout; in snd_hdac_bus_get_response_rirb() local
333 timeout = jiffies + msecs_to_jiffies(1000); in snd_hdac_bus_get_response_rirb()
336 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_get_response_rirb()
337 if (!bus->polling_mode) in snd_hdac_bus_get_response_rirb()
338 prepare_to_wait(&bus->rirb_wq, &wait, in snd_hdac_bus_get_response_rirb()
340 if (bus->polling_mode) in snd_hdac_bus_get_response_rirb()
342 if (!bus->rirb.cmds[addr]) { in snd_hdac_bus_get_response_rirb()
344 *res = bus->rirb.res[addr]; /* the last value */ in snd_hdac_bus_get_response_rirb()
345 if (!bus->polling_mode) in snd_hdac_bus_get_response_rirb()
346 finish_wait(&bus->rirb_wq, &wait); in snd_hdac_bus_get_response_rirb()
347 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response_rirb()
350 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response_rirb()
351 if (time_after(jiffies, timeout)) in snd_hdac_bus_get_response_rirb()
354 if (!bus->polling_mode) { in snd_hdac_bus_get_response_rirb()
356 } else if (bus->needs_damn_long_delay || in snd_hdac_bus_get_response_rirb()
359 dev_dbg_ratelimited(bus->dev, in snd_hdac_bus_get_response_rirb()
361 bus->last_cmd[addr]); in snd_hdac_bus_get_response_rirb()
371 if (!bus->polling_mode) in snd_hdac_bus_get_response_rirb()
372 finish_wait(&bus->rirb_wq, &wait); in snd_hdac_bus_get_response_rirb()
374 return -EIO; in snd_hdac_bus_get_response_rirb()
378 * snd_hdac_bus_send_cmd - send a command verb via CORB or PIO
379 * @bus: HD-audio core bus
386 if (bus->use_pio_for_commands) in snd_hdac_bus_send_cmd()
394 * snd_hdac_bus_get_response - receive a response via RIRB or PIO
395 * @bus: HD-audio core bus
404 if (bus->use_pio_for_commands) in snd_hdac_bus_get_response()
413 * snd_hdac_bus_parse_capabilities - parse capability structure
430 dev_dbg(bus->dev, "Capability version: 0x%x\n", in snd_hdac_bus_parse_capabilities()
433 dev_dbg(bus->dev, "HDA capability ID: 0x%x\n", in snd_hdac_bus_parse_capabilities()
436 if (cur_cap == -1) { in snd_hdac_bus_parse_capabilities()
437 dev_dbg(bus->dev, "Invalid capability reg read\n"); in snd_hdac_bus_parse_capabilities()
443 dev_dbg(bus->dev, "Found ML capability\n"); in snd_hdac_bus_parse_capabilities()
444 bus->mlcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
448 dev_dbg(bus->dev, "Found GTS capability offset=%x\n", offset); in snd_hdac_bus_parse_capabilities()
449 bus->gtscap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
454 dev_dbg(bus->dev, "Found PP capability offset=%x\n", offset); in snd_hdac_bus_parse_capabilities()
455 bus->ppcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
460 dev_dbg(bus->dev, "Found SPB capability\n"); in snd_hdac_bus_parse_capabilities()
461 bus->spbcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
466 dev_dbg(bus->dev, "Found DRSM capability\n"); in snd_hdac_bus_parse_capabilities()
467 bus->drsmcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
471 dev_err(bus->dev, "Unknown capability %d\n", cur_cap); in snd_hdac_bus_parse_capabilities()
479 dev_err(bus->dev, "We exceeded HDAC capabilities!!!\n"); in snd_hdac_bus_parse_capabilities()
497 * snd_hdac_bus_enter_link_reset - enter link reset
498 * @bus: HD-audio core bus
504 unsigned long timeout; in snd_hdac_bus_enter_link_reset() local
509 timeout = jiffies + msecs_to_jiffies(100); in snd_hdac_bus_enter_link_reset()
511 time_before(jiffies, timeout)) in snd_hdac_bus_enter_link_reset()
517 * snd_hdac_bus_exit_link_reset - exit link reset
518 * @bus: HD-audio core bus
524 unsigned long timeout; in snd_hdac_bus_exit_link_reset() local
528 timeout = jiffies + msecs_to_jiffies(100); in snd_hdac_bus_exit_link_reset()
529 while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout)) in snd_hdac_bus_exit_link_reset()
561 dev_dbg(bus->dev, "controller not ready!\n"); in snd_hdac_bus_reset_link()
562 return -EBUSY; in snd_hdac_bus_reset_link()
566 if (!bus->codec_mask) { in snd_hdac_bus_reset_link()
567 bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS); in snd_hdac_bus_reset_link()
568 dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask); in snd_hdac_bus_reset_link()
575 /* enable interrupts */
578 /* enable controller CIE and GIE */ in azx_int_enable()
590 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_disable()
603 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_clear()
617 * snd_hdac_bus_init_chip - reset and start the controller registers
618 * @bus: HD-audio core bus
623 if (bus->chip_init) in snd_hdac_bus_init_chip()
635 /* enable interrupts after CORB/RIRB buffers are initialized above */ in snd_hdac_bus_init_chip()
639 if (bus->use_posbuf && bus->posbuf.addr) { in snd_hdac_bus_init_chip()
640 snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr); in snd_hdac_bus_init_chip()
641 snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr)); in snd_hdac_bus_init_chip()
644 bus->chip_init = true; in snd_hdac_bus_init_chip()
651 * snd_hdac_bus_stop_chip - disable the whole IRQ and I/Os
652 * @bus: HD-audio core bus
656 if (!bus->chip_init) in snd_hdac_bus_stop_chip()
667 if (bus->posbuf.addr) { in snd_hdac_bus_stop_chip()
672 bus->chip_init = false; in snd_hdac_bus_stop_chip()
677 * snd_hdac_bus_handle_stream_irq - interrupt handler for streams
678 * @bus: HD-audio core bus
692 list_for_each_entry(azx_dev, &bus->stream_list, list) { in snd_hdac_bus_handle_stream_irq()
693 if (status & azx_dev->sd_int_sta_mask) { in snd_hdac_bus_handle_stream_irq()
696 handled |= 1 << azx_dev->index; in snd_hdac_bus_handle_stream_irq()
697 if ((!azx_dev->substream && !azx_dev->cstream) || in snd_hdac_bus_handle_stream_irq()
698 !azx_dev->running || !(sd_status & SD_INT_COMPLETE)) in snd_hdac_bus_handle_stream_irq()
709 * snd_hdac_bus_alloc_stream_pages - allocate BDL and other buffers
710 * @bus: HD-audio core bus
719 int dma_type = bus->dma_type ? bus->dma_type : SNDRV_DMA_TYPE_DEV; in snd_hdac_bus_alloc_stream_pages()
722 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_alloc_stream_pages()
724 err = snd_dma_alloc_pages(dma_type, bus->dev, in snd_hdac_bus_alloc_stream_pages()
725 BDL_SIZE, &s->bdl); in snd_hdac_bus_alloc_stream_pages()
728 return -ENOMEM; in snd_hdac_bus_alloc_stream_pages()
732 return -EINVAL; in snd_hdac_bus_alloc_stream_pages()
734 err = snd_dma_alloc_pages(dma_type, bus->dev, in snd_hdac_bus_alloc_stream_pages()
735 num_streams * 8, &bus->posbuf); in snd_hdac_bus_alloc_stream_pages()
737 return -ENOMEM; in snd_hdac_bus_alloc_stream_pages()
738 list_for_each_entry(s, &bus->stream_list, list) in snd_hdac_bus_alloc_stream_pages()
739 s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8); in snd_hdac_bus_alloc_stream_pages()
742 return snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb); in snd_hdac_bus_alloc_stream_pages()
747 * snd_hdac_bus_free_stream_pages - release BDL and other buffers
748 * @bus: HD-audio core bus
754 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_free_stream_pages()
755 if (s->bdl.area) in snd_hdac_bus_free_stream_pages()
756 snd_dma_free_pages(&s->bdl); in snd_hdac_bus_free_stream_pages()
759 if (bus->rb.area) in snd_hdac_bus_free_stream_pages()
760 snd_dma_free_pages(&bus->rb); in snd_hdac_bus_free_stream_pages()
761 if (bus->posbuf.area) in snd_hdac_bus_free_stream_pages()
762 snd_dma_free_pages(&bus->posbuf); in snd_hdac_bus_free_stream_pages()
767 * snd_hdac_bus_link_power - power up/down codec link
768 * @codec: HD-audio device
769 * @enable: whether to power-up the link
771 void snd_hdac_bus_link_power(struct hdac_device *codec, bool enable) in snd_hdac_bus_link_power() argument
773 if (enable) in snd_hdac_bus_link_power()
774 set_bit(codec->addr, &codec->bus->codec_powered); in snd_hdac_bus_link_power()
776 clear_bit(codec->addr, &codec->bus->codec_powered); in snd_hdac_bus_link_power()