Lines Matching full:bus

14 static void azx_clear_corbrp(struct hdac_bus *bus)  in azx_clear_corbrp()  argument
19 if (snd_hdac_chip_readw(bus, CORBRP) & AZX_CORBRP_RST) in azx_clear_corbrp()
24 dev_err(bus->dev, "CORB reset timeout#1, CORBRP = %d\n", in azx_clear_corbrp()
25 snd_hdac_chip_readw(bus, CORBRP)); in azx_clear_corbrp()
27 snd_hdac_chip_writew(bus, CORBRP, 0); in azx_clear_corbrp()
29 if (snd_hdac_chip_readw(bus, CORBRP) == 0) in azx_clear_corbrp()
34 dev_err(bus->dev, "CORB reset timeout#2, CORBRP = %d\n", in azx_clear_corbrp()
35 snd_hdac_chip_readw(bus, CORBRP)); in azx_clear_corbrp()
40 * @bus: HD-audio core bus
42 void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_init_cmd_io() argument
44 WARN_ON_ONCE(!bus->rb.area); in snd_hdac_bus_init_cmd_io()
46 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
48 bus->corb.addr = bus->rb.addr; in snd_hdac_bus_init_cmd_io()
49 bus->corb.buf = (__le32 *)bus->rb.area; in snd_hdac_bus_init_cmd_io()
50 snd_hdac_chip_writel(bus, CORBLBASE, (u32)bus->corb.addr); in snd_hdac_bus_init_cmd_io()
51 snd_hdac_chip_writel(bus, CORBUBASE, upper_32_bits(bus->corb.addr)); in snd_hdac_bus_init_cmd_io()
54 snd_hdac_chip_writeb(bus, CORBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
56 snd_hdac_chip_writew(bus, CORBWP, 0); in snd_hdac_bus_init_cmd_io()
59 snd_hdac_chip_writew(bus, CORBRP, AZX_CORBRP_RST); in snd_hdac_bus_init_cmd_io()
60 if (!bus->corbrp_self_clear) in snd_hdac_bus_init_cmd_io()
61 azx_clear_corbrp(bus); in snd_hdac_bus_init_cmd_io()
64 snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN); in snd_hdac_bus_init_cmd_io()
67 bus->rirb.addr = bus->rb.addr + 2048; in snd_hdac_bus_init_cmd_io()
68 bus->rirb.buf = (__le32 *)(bus->rb.area + 2048); in snd_hdac_bus_init_cmd_io()
69 bus->rirb.wp = bus->rirb.rp = 0; in snd_hdac_bus_init_cmd_io()
70 memset(bus->rirb.cmds, 0, sizeof(bus->rirb.cmds)); in snd_hdac_bus_init_cmd_io()
71 snd_hdac_chip_writel(bus, RIRBLBASE, (u32)bus->rirb.addr); in snd_hdac_bus_init_cmd_io()
72 snd_hdac_chip_writel(bus, RIRBUBASE, upper_32_bits(bus->rirb.addr)); in snd_hdac_bus_init_cmd_io()
75 snd_hdac_chip_writeb(bus, RIRBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
77 snd_hdac_chip_writew(bus, RIRBWP, AZX_RIRBWP_RST); in snd_hdac_bus_init_cmd_io()
79 snd_hdac_chip_writew(bus, RINTCNT, 1); in snd_hdac_bus_init_cmd_io()
81 snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN); in snd_hdac_bus_init_cmd_io()
83 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, AZX_GCTL_UNSOL); in snd_hdac_bus_init_cmd_io()
84 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
89 static void hdac_wait_for_cmd_dmas(struct hdac_bus *bus) in hdac_wait_for_cmd_dmas() argument
94 while ((snd_hdac_chip_readb(bus, RIRBCTL) & AZX_RBCTL_DMA_EN) in hdac_wait_for_cmd_dmas()
99 while ((snd_hdac_chip_readb(bus, CORBCTL) & AZX_CORBCTL_RUN) in hdac_wait_for_cmd_dmas()
106 * @bus: HD-audio core bus
108 void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_stop_cmd_io() argument
110 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
112 snd_hdac_chip_writeb(bus, RIRBCTL, 0); in snd_hdac_bus_stop_cmd_io()
113 snd_hdac_chip_writeb(bus, CORBCTL, 0); in snd_hdac_bus_stop_cmd_io()
114 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
116 hdac_wait_for_cmd_dmas(bus); in snd_hdac_bus_stop_cmd_io()
118 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
120 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0); in snd_hdac_bus_stop_cmd_io()
121 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
136 * @bus: HD-audio core bus
141 int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val) in snd_hdac_bus_send_cmd() argument
146 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
148 bus->last_cmd[azx_command_addr(val)] = val; in snd_hdac_bus_send_cmd()
151 wp = snd_hdac_chip_readw(bus, CORBWP); in snd_hdac_bus_send_cmd()
154 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
160 rp = snd_hdac_chip_readw(bus, CORBRP); in snd_hdac_bus_send_cmd()
163 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
167 bus->rirb.cmds[addr]++; in snd_hdac_bus_send_cmd()
168 bus->corb.buf[wp] = cpu_to_le32(val); in snd_hdac_bus_send_cmd()
169 snd_hdac_chip_writew(bus, CORBWP, wp); in snd_hdac_bus_send_cmd()
171 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
181 * @bus: HD-audio core bus
185 void snd_hdac_bus_update_rirb(struct hdac_bus *bus) in snd_hdac_bus_update_rirb() argument
191 wp = snd_hdac_chip_readw(bus, RIRBWP); in snd_hdac_bus_update_rirb()
197 if (wp == bus->rirb.wp) in snd_hdac_bus_update_rirb()
199 bus->rirb.wp = wp; in snd_hdac_bus_update_rirb()
201 while (bus->rirb.rp != wp) { in snd_hdac_bus_update_rirb()
202 bus->rirb.rp++; in snd_hdac_bus_update_rirb()
203 bus->rirb.rp %= AZX_MAX_RIRB_ENTRIES; in snd_hdac_bus_update_rirb()
205 rp = bus->rirb.rp << 1; /* an RIRB entry is 8-bytes */ in snd_hdac_bus_update_rirb()
206 res_ex = le32_to_cpu(bus->rirb.buf[rp + 1]); in snd_hdac_bus_update_rirb()
207 res = le32_to_cpu(bus->rirb.buf[rp]); in snd_hdac_bus_update_rirb()
210 dev_err(bus->dev, in snd_hdac_bus_update_rirb()
212 res, res_ex, bus->rirb.rp, wp); in snd_hdac_bus_update_rirb()
215 snd_hdac_bus_queue_event(bus, res, res_ex); in snd_hdac_bus_update_rirb()
216 else if (bus->rirb.cmds[addr]) { in snd_hdac_bus_update_rirb()
217 bus->rirb.res[addr] = res; in snd_hdac_bus_update_rirb()
218 bus->rirb.cmds[addr]--; in snd_hdac_bus_update_rirb()
220 dev_err_ratelimited(bus->dev, in snd_hdac_bus_update_rirb()
222 res, res_ex, bus->last_cmd[addr]); in snd_hdac_bus_update_rirb()
230 * @bus: HD-audio core bus
236 int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, in snd_hdac_bus_get_response() argument
245 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
246 if (bus->polling_mode) in snd_hdac_bus_get_response()
247 snd_hdac_bus_update_rirb(bus); in snd_hdac_bus_get_response()
248 if (!bus->rirb.cmds[addr]) { in snd_hdac_bus_get_response()
250 *res = bus->rirb.res[addr]; /* the last value */ in snd_hdac_bus_get_response()
251 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
254 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
272 * @bus: the pointer to bus object
276 int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus) in snd_hdac_bus_parse_capabilities() argument
282 offset = snd_hdac_chip_readw(bus, LLCH); in snd_hdac_bus_parse_capabilities()
286 cur_cap = _snd_hdac_chip_readl(bus, offset); in snd_hdac_bus_parse_capabilities()
288 dev_dbg(bus->dev, "Capability version: 0x%x\n", in snd_hdac_bus_parse_capabilities()
291 dev_dbg(bus->dev, "HDA capability ID: 0x%x\n", in snd_hdac_bus_parse_capabilities()
295 dev_dbg(bus->dev, "Invalid capability reg read\n"); in snd_hdac_bus_parse_capabilities()
301 dev_dbg(bus->dev, "Found ML capability\n"); in snd_hdac_bus_parse_capabilities()
302 bus->mlcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
306 dev_dbg(bus->dev, "Found GTS capability offset=%x\n", offset); in snd_hdac_bus_parse_capabilities()
307 bus->gtscap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
312 dev_dbg(bus->dev, "Found PP capability offset=%x\n", offset); in snd_hdac_bus_parse_capabilities()
313 bus->ppcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
318 dev_dbg(bus->dev, "Found SPB capability\n"); in snd_hdac_bus_parse_capabilities()
319 bus->spbcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
324 dev_dbg(bus->dev, "Found DRSM capability\n"); in snd_hdac_bus_parse_capabilities()
325 bus->drsmcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
329 dev_err(bus->dev, "Unknown capability %d\n", cur_cap); in snd_hdac_bus_parse_capabilities()
337 dev_err(bus->dev, "We exceeded HDAC capabilities!!!\n"); in snd_hdac_bus_parse_capabilities()
356 * @bus: HD-audio core bus
360 void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus) in snd_hdac_bus_enter_link_reset() argument
365 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, 0); in snd_hdac_bus_enter_link_reset()
368 while ((snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) && in snd_hdac_bus_enter_link_reset()
376 * @bus: HD-audio core bus
380 void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus) in snd_hdac_bus_exit_link_reset() argument
384 snd_hdac_chip_updateb(bus, GCTL, AZX_GCTL_RESET, AZX_GCTL_RESET); in snd_hdac_bus_exit_link_reset()
387 while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout)) in snd_hdac_bus_exit_link_reset()
393 int snd_hdac_bus_reset_link(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_reset_link() argument
399 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in snd_hdac_bus_reset_link()
402 snd_hdac_bus_enter_link_reset(bus); in snd_hdac_bus_reset_link()
410 snd_hdac_bus_exit_link_reset(bus); in snd_hdac_bus_reset_link()
417 if (!snd_hdac_chip_readb(bus, GCTL)) { in snd_hdac_bus_reset_link()
418 dev_dbg(bus->dev, "controller not ready!\n"); in snd_hdac_bus_reset_link()
423 if (!bus->codec_mask) { in snd_hdac_bus_reset_link()
424 bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS); in snd_hdac_bus_reset_link()
425 dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask); in snd_hdac_bus_reset_link()
433 static void azx_int_enable(struct hdac_bus *bus) in azx_int_enable() argument
436 snd_hdac_chip_updatel(bus, INTCTL, in azx_int_enable()
442 static void azx_int_disable(struct hdac_bus *bus) in azx_int_disable() argument
447 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_disable()
451 snd_hdac_chip_writeb(bus, INTCTL, 0); in azx_int_disable()
454 snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN, 0); in azx_int_disable()
458 static void azx_int_clear(struct hdac_bus *bus) in azx_int_clear() argument
463 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_clear()
467 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in azx_int_clear()
470 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK); in azx_int_clear()
473 snd_hdac_chip_writel(bus, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM); in azx_int_clear()
478 * @bus: HD-audio core bus
481 bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_init_chip() argument
483 if (bus->chip_init) in snd_hdac_bus_init_chip()
487 snd_hdac_bus_reset_link(bus, full_reset); in snd_hdac_bus_init_chip()
490 azx_int_clear(bus); in snd_hdac_bus_init_chip()
493 snd_hdac_bus_init_cmd_io(bus); in snd_hdac_bus_init_chip()
496 azx_int_enable(bus); in snd_hdac_bus_init_chip()
499 if (bus->use_posbuf && bus->posbuf.addr) { in snd_hdac_bus_init_chip()
500 snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr); in snd_hdac_bus_init_chip()
501 snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr)); in snd_hdac_bus_init_chip()
504 bus->chip_init = true; in snd_hdac_bus_init_chip()
511 * @bus: HD-audio core bus
513 void snd_hdac_bus_stop_chip(struct hdac_bus *bus) in snd_hdac_bus_stop_chip() argument
515 if (!bus->chip_init) in snd_hdac_bus_stop_chip()
519 azx_int_disable(bus); in snd_hdac_bus_stop_chip()
520 azx_int_clear(bus); in snd_hdac_bus_stop_chip()
523 snd_hdac_bus_stop_cmd_io(bus); in snd_hdac_bus_stop_chip()
526 if (bus->posbuf.addr) { in snd_hdac_bus_stop_chip()
527 snd_hdac_chip_writel(bus, DPLBASE, 0); in snd_hdac_bus_stop_chip()
528 snd_hdac_chip_writel(bus, DPUBASE, 0); in snd_hdac_bus_stop_chip()
531 bus->chip_init = false; in snd_hdac_bus_stop_chip()
537 * @bus: HD-audio core bus
543 int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, in snd_hdac_bus_handle_stream_irq() argument
551 list_for_each_entry(azx_dev, &bus->stream_list, list) { in snd_hdac_bus_handle_stream_irq()
560 ack(bus, azx_dev); in snd_hdac_bus_handle_stream_irq()
569 * @bus: HD-audio core bus
574 int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_alloc_stream_pages() argument
578 int dma_type = bus->dma_type ? bus->dma_type : SNDRV_DMA_TYPE_DEV; in snd_hdac_bus_alloc_stream_pages()
581 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_alloc_stream_pages()
583 err = snd_dma_alloc_pages(dma_type, bus->dev, in snd_hdac_bus_alloc_stream_pages()
593 err = snd_dma_alloc_pages(dma_type, bus->dev, in snd_hdac_bus_alloc_stream_pages()
594 num_streams * 8, &bus->posbuf); in snd_hdac_bus_alloc_stream_pages()
597 list_for_each_entry(s, &bus->stream_list, list) in snd_hdac_bus_alloc_stream_pages()
598 s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8); in snd_hdac_bus_alloc_stream_pages()
601 return snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb); in snd_hdac_bus_alloc_stream_pages()
607 * @bus: HD-audio core bus
609 void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_free_stream_pages() argument
613 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_free_stream_pages()
618 if (bus->rb.area) in snd_hdac_bus_free_stream_pages()
619 snd_dma_free_pages(&bus->rb); in snd_hdac_bus_free_stream_pages()
620 if (bus->posbuf.area) in snd_hdac_bus_free_stream_pages()
621 snd_dma_free_pages(&bus->posbuf); in snd_hdac_bus_free_stream_pages()