Lines Matching full:bus

15 static void azx_clear_corbrp(struct hdac_bus *bus)  in azx_clear_corbrp()  argument
20 if (snd_hdac_chip_readw(bus, CORBRP) & AZX_CORBRP_RST) in azx_clear_corbrp()
25 dev_err(bus->dev, "CORB reset timeout#1, CORBRP = %d\n", in azx_clear_corbrp()
26 snd_hdac_chip_readw(bus, CORBRP)); in azx_clear_corbrp()
28 snd_hdac_chip_writew(bus, CORBRP, 0); in azx_clear_corbrp()
30 if (snd_hdac_chip_readw(bus, CORBRP) == 0) in azx_clear_corbrp()
35 dev_err(bus->dev, "CORB reset timeout#2, CORBRP = %d\n", in azx_clear_corbrp()
36 snd_hdac_chip_readw(bus, CORBRP)); in azx_clear_corbrp()
41 * @bus: HD-audio core bus
43 void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_init_cmd_io() argument
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()
55 snd_hdac_chip_writeb(bus, CORBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
57 snd_hdac_chip_writew(bus, CORBWP, 0); in snd_hdac_bus_init_cmd_io()
60 snd_hdac_chip_writew(bus, CORBRP, AZX_CORBRP_RST); in snd_hdac_bus_init_cmd_io()
61 if (!bus->corbrp_self_clear) in snd_hdac_bus_init_cmd_io()
62 azx_clear_corbrp(bus); in snd_hdac_bus_init_cmd_io()
65 if (!bus->use_pio_for_commands) in snd_hdac_bus_init_cmd_io()
66 snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN); 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()
77 snd_hdac_chip_writeb(bus, RIRBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
79 snd_hdac_chip_writew(bus, RIRBWP, AZX_RIRBWP_RST); in snd_hdac_bus_init_cmd_io()
81 snd_hdac_chip_writew(bus, RINTCNT, 1); in snd_hdac_bus_init_cmd_io()
83 if (bus->not_use_interrupts) in snd_hdac_bus_init_cmd_io()
84 snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN); in snd_hdac_bus_init_cmd_io()
86 snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN); in snd_hdac_bus_init_cmd_io()
88 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, AZX_GCTL_UNSOL); in snd_hdac_bus_init_cmd_io()
89 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
94 static void hdac_wait_for_cmd_dmas(struct hdac_bus *bus) in hdac_wait_for_cmd_dmas() argument
99 while ((snd_hdac_chip_readb(bus, RIRBCTL) & AZX_RBCTL_DMA_EN) in hdac_wait_for_cmd_dmas()
104 while ((snd_hdac_chip_readb(bus, CORBCTL) & AZX_CORBCTL_RUN) in hdac_wait_for_cmd_dmas()
111 * @bus: HD-audio core bus
113 void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_stop_cmd_io() argument
115 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
117 snd_hdac_chip_writeb(bus, RIRBCTL, 0); in snd_hdac_bus_stop_cmd_io()
118 snd_hdac_chip_writeb(bus, CORBCTL, 0); in snd_hdac_bus_stop_cmd_io()
119 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
121 hdac_wait_for_cmd_dmas(bus); in snd_hdac_bus_stop_cmd_io()
123 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
125 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0); in snd_hdac_bus_stop_cmd_io()
126 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
140 static int snd_hdac_bus_wait_for_pio_response(struct hdac_bus *bus, in snd_hdac_bus_wait_for_pio_response() argument
147 if (snd_hdac_chip_readw(bus, IRS) & AZX_IRS_VALID) { 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()
156 snd_hdac_chip_readw(bus, IRS)); in snd_hdac_bus_wait_for_pio_response()
158 bus->rirb.res[addr] = -1; in snd_hdac_bus_wait_for_pio_response()
165 * @bus: HD-audio core bus
170 static int snd_hdac_bus_send_cmd_pio(struct hdac_bus *bus, unsigned int val) in snd_hdac_bus_send_cmd_pio() argument
176 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_pio()
180 if (!((snd_hdac_chip_readw(bus, IRS) & AZX_IRS_BUSY))) { in snd_hdac_bus_send_cmd_pio()
182 snd_hdac_chip_updatew(bus, IRS, AZX_IRS_VALID, AZX_IRS_VALID); in snd_hdac_bus_send_cmd_pio()
183 snd_hdac_chip_writel(bus, IC, val); in snd_hdac_bus_send_cmd_pio()
185 snd_hdac_chip_updatew(bus, IRS, AZX_IRS_BUSY, AZX_IRS_BUSY); in snd_hdac_bus_send_cmd_pio()
187 ret = snd_hdac_bus_wait_for_pio_response(bus, addr); 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()
194 snd_hdac_chip_readw(bus, IRS), val); in snd_hdac_bus_send_cmd_pio()
197 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_pio()
204 * @bus: HD-audio core bus
210 static int snd_hdac_bus_get_response_pio(struct hdac_bus *bus, in snd_hdac_bus_get_response_pio() argument
214 *res = bus->rirb.res[addr]; in snd_hdac_bus_get_response_pio()
221 * @bus: HD-audio core bus
226 static int snd_hdac_bus_send_cmd_corb(struct hdac_bus *bus, unsigned int val) in snd_hdac_bus_send_cmd_corb() argument
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()
236 wp = snd_hdac_chip_readw(bus, CORBWP); in snd_hdac_bus_send_cmd_corb()
239 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_corb()
245 rp = snd_hdac_chip_readw(bus, CORBRP); in snd_hdac_bus_send_cmd_corb()
248 spin_unlock_irq(&bus->reg_lock); 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()
254 snd_hdac_chip_writew(bus, CORBWP, wp); in snd_hdac_bus_send_cmd_corb()
256 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd_corb()
265 * @bus: HD-audio core bus
268 * The caller needs bus->reg_lock spinlock before calling this.
270 void snd_hdac_bus_update_rirb(struct hdac_bus *bus) in snd_hdac_bus_update_rirb() argument
276 wp = snd_hdac_chip_readw(bus, RIRBWP); in snd_hdac_bus_update_rirb()
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()
300 snd_hdac_bus_queue_event(bus, res, res_ex); 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()
318 * @bus: HD-audio core bus
324 static int snd_hdac_bus_get_response_rirb(struct hdac_bus *bus, in snd_hdac_bus_get_response_rirb() argument
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()
341 snd_hdac_bus_update_rirb(bus); 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()
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()
379 * @bus: HD-audio core bus
384 int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val) in snd_hdac_bus_send_cmd() argument
386 if (bus->use_pio_for_commands) in snd_hdac_bus_send_cmd()
387 return snd_hdac_bus_send_cmd_pio(bus, val); in snd_hdac_bus_send_cmd()
389 return snd_hdac_bus_send_cmd_corb(bus, val); in snd_hdac_bus_send_cmd()
395 * @bus: HD-audio core bus
401 int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, in snd_hdac_bus_get_response() argument
404 if (bus->use_pio_for_commands) in snd_hdac_bus_get_response()
405 return snd_hdac_bus_get_response_pio(bus, addr, res); in snd_hdac_bus_get_response()
407 return snd_hdac_bus_get_response_rirb(bus, addr, res); in snd_hdac_bus_get_response()
414 * @bus: the pointer to bus object
418 int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus) in snd_hdac_bus_parse_capabilities() argument
424 offset = snd_hdac_chip_readw(bus, LLCH); in snd_hdac_bus_parse_capabilities()
428 cur_cap = _snd_hdac_chip_readl(bus, offset); in snd_hdac_bus_parse_capabilities()
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()
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()
498 * @bus: HD-audio core bus
502 void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus) in snd_hdac_bus_enter_link_reset() argument
507 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, 0); in snd_hdac_bus_enter_link_reset()
510 while ((snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) && in snd_hdac_bus_enter_link_reset()
518 * @bus: HD-audio core bus
522 void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus) in snd_hdac_bus_exit_link_reset() argument
526 snd_hdac_chip_updateb(bus, GCTL, AZX_GCTL_RESET, AZX_GCTL_RESET); 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()
535 int snd_hdac_bus_reset_link(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_reset_link() argument
541 if (snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) in snd_hdac_bus_reset_link()
542 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in snd_hdac_bus_reset_link()
545 snd_hdac_bus_enter_link_reset(bus); in snd_hdac_bus_reset_link()
553 snd_hdac_bus_exit_link_reset(bus); in snd_hdac_bus_reset_link()
560 if (!snd_hdac_chip_readb(bus, GCTL)) { in snd_hdac_bus_reset_link()
561 dev_dbg(bus->dev, "controller not ready!\n"); 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()
576 static void azx_int_enable(struct hdac_bus *bus) in azx_int_enable() argument
579 snd_hdac_chip_updatel(bus, INTCTL, in azx_int_enable()
585 static void azx_int_disable(struct hdac_bus *bus) in azx_int_disable() argument
590 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_disable()
594 snd_hdac_chip_writel(bus, INTCTL, 0); in azx_int_disable()
598 static void azx_int_clear(struct hdac_bus *bus) in azx_int_clear() argument
603 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_clear()
607 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in azx_int_clear()
610 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK); in azx_int_clear()
613 snd_hdac_chip_writel(bus, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM); in azx_int_clear()
618 * @bus: HD-audio core bus
621 bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_init_chip() argument
623 if (bus->chip_init) in snd_hdac_bus_init_chip()
627 snd_hdac_bus_reset_link(bus, full_reset); in snd_hdac_bus_init_chip()
630 azx_int_clear(bus); in snd_hdac_bus_init_chip()
633 snd_hdac_bus_init_cmd_io(bus); in snd_hdac_bus_init_chip()
636 azx_int_enable(bus); 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()
652 * @bus: HD-audio core bus
654 void snd_hdac_bus_stop_chip(struct hdac_bus *bus) in snd_hdac_bus_stop_chip() argument
656 if (!bus->chip_init) in snd_hdac_bus_stop_chip()
660 azx_int_disable(bus); in snd_hdac_bus_stop_chip()
661 azx_int_clear(bus); in snd_hdac_bus_stop_chip()
664 snd_hdac_bus_stop_cmd_io(bus); in snd_hdac_bus_stop_chip()
667 if (bus->posbuf.addr) { in snd_hdac_bus_stop_chip()
668 snd_hdac_chip_writel(bus, DPLBASE, 0); in snd_hdac_bus_stop_chip()
669 snd_hdac_chip_writel(bus, DPUBASE, 0); in snd_hdac_bus_stop_chip()
672 bus->chip_init = false; in snd_hdac_bus_stop_chip()
678 * @bus: HD-audio core bus
684 int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, in snd_hdac_bus_handle_stream_irq() argument
692 list_for_each_entry(azx_dev, &bus->stream_list, list) { in snd_hdac_bus_handle_stream_irq()
701 ack(bus, azx_dev); in snd_hdac_bus_handle_stream_irq()
710 * @bus: HD-audio core bus
715 int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_alloc_stream_pages() argument
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()
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()
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()
748 * @bus: HD-audio core bus
750 void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_free_stream_pages() argument
754 list_for_each_entry(s, &bus->stream_list, list) { 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()
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()