Lines Matching +full:bus +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0-only
3 * HD-audio controller helpers
15 static void azx_clear_corbrp(struct hdac_bus *bus) in azx_clear_corbrp() argument
19 for (timeout = 1000; timeout > 0; timeout--) { in azx_clear_corbrp()
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()
29 for (timeout = 1000; timeout > 0; timeout--) { 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()
40 * snd_hdac_bus_init_cmd_io - set up CORB/RIRB buffers
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 snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN); in snd_hdac_bus_init_cmd_io()
68 bus->rirb.addr = bus->rb.addr + 2048; in snd_hdac_bus_init_cmd_io()
69 bus->rirb.buf = (__le32 *)(bus->rb.area + 2048); in snd_hdac_bus_init_cmd_io()
70 bus->rirb.wp = bus->rirb.rp = 0; in snd_hdac_bus_init_cmd_io()
71 memset(bus->rirb.cmds, 0, sizeof(bus->rirb.cmds)); in snd_hdac_bus_init_cmd_io()
72 snd_hdac_chip_writel(bus, RIRBLBASE, (u32)bus->rirb.addr); in snd_hdac_bus_init_cmd_io()
73 snd_hdac_chip_writel(bus, RIRBUBASE, upper_32_bits(bus->rirb.addr)); in snd_hdac_bus_init_cmd_io()
76 snd_hdac_chip_writeb(bus, RIRBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
78 snd_hdac_chip_writew(bus, RIRBWP, AZX_RIRBWP_RST); in snd_hdac_bus_init_cmd_io()
80 snd_hdac_chip_writew(bus, RINTCNT, 1); in snd_hdac_bus_init_cmd_io()
82 snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN); in snd_hdac_bus_init_cmd_io()
84 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, AZX_GCTL_UNSOL); in snd_hdac_bus_init_cmd_io()
85 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
90 static void hdac_wait_for_cmd_dmas(struct hdac_bus *bus) in hdac_wait_for_cmd_dmas() argument
95 while ((snd_hdac_chip_readb(bus, RIRBCTL) & AZX_RBCTL_DMA_EN) in hdac_wait_for_cmd_dmas()
100 while ((snd_hdac_chip_readb(bus, CORBCTL) & AZX_CORBCTL_RUN) in hdac_wait_for_cmd_dmas()
106 * snd_hdac_bus_stop_cmd_io - clean up CORB/RIRB buffers
107 * @bus: HD-audio core bus
109 void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_stop_cmd_io() argument
111 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
113 snd_hdac_chip_writeb(bus, RIRBCTL, 0); in snd_hdac_bus_stop_cmd_io()
114 snd_hdac_chip_writeb(bus, CORBCTL, 0); in snd_hdac_bus_stop_cmd_io()
115 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
117 hdac_wait_for_cmd_dmas(bus); in snd_hdac_bus_stop_cmd_io()
119 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
121 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0); in snd_hdac_bus_stop_cmd_io()
122 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
128 unsigned int addr = cmd >> 28; in azx_command_addr() local
130 if (snd_BUG_ON(addr >= HDA_MAX_CODECS)) in azx_command_addr()
131 addr = 0; in azx_command_addr()
132 return addr; in azx_command_addr()
136 * snd_hdac_bus_send_cmd - send a command verb via CORB
137 * @bus: HD-audio core bus
142 int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val) in snd_hdac_bus_send_cmd() argument
144 unsigned int addr = azx_command_addr(val); in snd_hdac_bus_send_cmd() local
147 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
149 bus->last_cmd[azx_command_addr(val)] = val; in snd_hdac_bus_send_cmd()
152 wp = snd_hdac_chip_readw(bus, CORBWP); in snd_hdac_bus_send_cmd()
155 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
156 return -EIO; in snd_hdac_bus_send_cmd()
161 rp = snd_hdac_chip_readw(bus, CORBRP); in snd_hdac_bus_send_cmd()
164 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
165 return -EAGAIN; in snd_hdac_bus_send_cmd()
168 bus->rirb.cmds[addr]++; in snd_hdac_bus_send_cmd()
169 bus->corb.buf[wp] = cpu_to_le32(val); in snd_hdac_bus_send_cmd()
170 snd_hdac_chip_writew(bus, CORBWP, wp); in snd_hdac_bus_send_cmd()
172 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
181 * snd_hdac_bus_update_rirb - retrieve RIRB entries
182 * @bus: HD-audio core bus
185 * The caller needs bus->reg_lock spinlock before calling this.
187 void snd_hdac_bus_update_rirb(struct hdac_bus *bus) in snd_hdac_bus_update_rirb() argument
190 unsigned int addr; in snd_hdac_bus_update_rirb() local
193 wp = snd_hdac_chip_readw(bus, RIRBWP); in snd_hdac_bus_update_rirb()
199 if (wp == bus->rirb.wp) in snd_hdac_bus_update_rirb()
201 bus->rirb.wp = wp; in snd_hdac_bus_update_rirb()
203 while (bus->rirb.rp != wp) { in snd_hdac_bus_update_rirb()
204 bus->rirb.rp++; in snd_hdac_bus_update_rirb()
205 bus->rirb.rp %= AZX_MAX_RIRB_ENTRIES; in snd_hdac_bus_update_rirb()
207 rp = bus->rirb.rp << 1; /* an RIRB entry is 8-bytes */ in snd_hdac_bus_update_rirb()
208 res_ex = le32_to_cpu(bus->rirb.buf[rp + 1]); in snd_hdac_bus_update_rirb()
209 res = le32_to_cpu(bus->rirb.buf[rp]); in snd_hdac_bus_update_rirb()
210 addr = res_ex & 0xf; in snd_hdac_bus_update_rirb()
211 if (addr >= HDA_MAX_CODECS) { in snd_hdac_bus_update_rirb()
212 dev_err(bus->dev, in snd_hdac_bus_update_rirb()
214 res, res_ex, bus->rirb.rp, wp); in snd_hdac_bus_update_rirb()
217 snd_hdac_bus_queue_event(bus, res, res_ex); in snd_hdac_bus_update_rirb()
218 else if (bus->rirb.cmds[addr]) { in snd_hdac_bus_update_rirb()
219 bus->rirb.res[addr] = res; in snd_hdac_bus_update_rirb()
220 bus->rirb.cmds[addr]--; in snd_hdac_bus_update_rirb()
221 if (!bus->rirb.cmds[addr] && in snd_hdac_bus_update_rirb()
222 waitqueue_active(&bus->rirb_wq)) in snd_hdac_bus_update_rirb()
223 wake_up(&bus->rirb_wq); in snd_hdac_bus_update_rirb()
225 dev_err_ratelimited(bus->dev, in snd_hdac_bus_update_rirb()
227 res, res_ex, bus->last_cmd[addr]); in snd_hdac_bus_update_rirb()
234 * snd_hdac_bus_get_response - receive a response via RIRB
235 * @bus: HD-audio core bus
236 * @addr: codec address
241 int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, in snd_hdac_bus_get_response() argument
253 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
254 if (!bus->polling_mode) in snd_hdac_bus_get_response()
255 prepare_to_wait(&bus->rirb_wq, &wait, in snd_hdac_bus_get_response()
257 if (bus->polling_mode) in snd_hdac_bus_get_response()
258 snd_hdac_bus_update_rirb(bus); in snd_hdac_bus_get_response()
259 if (!bus->rirb.cmds[addr]) { in snd_hdac_bus_get_response()
261 *res = bus->rirb.res[addr]; /* the last value */ in snd_hdac_bus_get_response()
262 if (!bus->polling_mode) in snd_hdac_bus_get_response()
263 finish_wait(&bus->rirb_wq, &wait); in snd_hdac_bus_get_response()
264 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
267 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
271 if (!bus->polling_mode) { in snd_hdac_bus_get_response()
273 } else if (bus->needs_damn_long_delay || in snd_hdac_bus_get_response()
276 dev_dbg_ratelimited(bus->dev, in snd_hdac_bus_get_response()
278 bus->last_cmd[addr]); in snd_hdac_bus_get_response()
288 if (!bus->polling_mode) in snd_hdac_bus_get_response()
289 finish_wait(&bus->rirb_wq, &wait); in snd_hdac_bus_get_response()
291 return -EIO; in snd_hdac_bus_get_response()
297 * snd_hdac_bus_parse_capabilities - parse capability structure
298 * @bus: the pointer to bus object
302 int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus) in snd_hdac_bus_parse_capabilities() argument
308 offset = snd_hdac_chip_readw(bus, LLCH); in snd_hdac_bus_parse_capabilities()
312 cur_cap = _snd_hdac_chip_readl(bus, offset); in snd_hdac_bus_parse_capabilities()
314 dev_dbg(bus->dev, "Capability version: 0x%x\n", in snd_hdac_bus_parse_capabilities()
317 dev_dbg(bus->dev, "HDA capability ID: 0x%x\n", in snd_hdac_bus_parse_capabilities()
320 if (cur_cap == -1) { in snd_hdac_bus_parse_capabilities()
321 dev_dbg(bus->dev, "Invalid capability reg read\n"); in snd_hdac_bus_parse_capabilities()
327 dev_dbg(bus->dev, "Found ML capability\n"); in snd_hdac_bus_parse_capabilities()
328 bus->mlcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
332 dev_dbg(bus->dev, "Found GTS capability offset=%x\n", offset); in snd_hdac_bus_parse_capabilities()
333 bus->gtscap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
338 dev_dbg(bus->dev, "Found PP capability offset=%x\n", offset); in snd_hdac_bus_parse_capabilities()
339 bus->ppcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
344 dev_dbg(bus->dev, "Found SPB capability\n"); in snd_hdac_bus_parse_capabilities()
345 bus->spbcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
350 dev_dbg(bus->dev, "Found DRSM capability\n"); in snd_hdac_bus_parse_capabilities()
351 bus->drsmcap = bus->remap_addr + offset; in snd_hdac_bus_parse_capabilities()
355 dev_err(bus->dev, "Unknown capability %d\n", cur_cap); in snd_hdac_bus_parse_capabilities()
363 dev_err(bus->dev, "We exceeded HDAC capabilities!!!\n"); in snd_hdac_bus_parse_capabilities()
381 * snd_hdac_bus_enter_link_reset - enter link reset
382 * @bus: HD-audio core bus
386 void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus) in snd_hdac_bus_enter_link_reset() argument
391 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, 0); in snd_hdac_bus_enter_link_reset()
394 while ((snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) && in snd_hdac_bus_enter_link_reset()
401 * snd_hdac_bus_exit_link_reset - exit link reset
402 * @bus: HD-audio core bus
406 void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus) in snd_hdac_bus_exit_link_reset() argument
410 snd_hdac_chip_updateb(bus, GCTL, AZX_GCTL_RESET, AZX_GCTL_RESET); in snd_hdac_bus_exit_link_reset()
413 while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout)) in snd_hdac_bus_exit_link_reset()
419 int snd_hdac_bus_reset_link(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_reset_link() argument
425 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in snd_hdac_bus_reset_link()
428 snd_hdac_bus_enter_link_reset(bus); in snd_hdac_bus_reset_link()
436 snd_hdac_bus_exit_link_reset(bus); in snd_hdac_bus_reset_link()
443 if (!snd_hdac_chip_readb(bus, GCTL)) { in snd_hdac_bus_reset_link()
444 dev_dbg(bus->dev, "controller not ready!\n"); in snd_hdac_bus_reset_link()
445 return -EBUSY; in snd_hdac_bus_reset_link()
449 if (!bus->codec_mask) { in snd_hdac_bus_reset_link()
450 bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS); in snd_hdac_bus_reset_link()
451 dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask); in snd_hdac_bus_reset_link()
459 static void azx_int_enable(struct hdac_bus *bus) in azx_int_enable() argument
462 snd_hdac_chip_updatel(bus, INTCTL, in azx_int_enable()
468 static void azx_int_disable(struct hdac_bus *bus) in azx_int_disable() argument
473 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_disable()
477 snd_hdac_chip_writeb(bus, INTCTL, 0); in azx_int_disable()
480 snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN, 0); in azx_int_disable()
484 static void azx_int_clear(struct hdac_bus *bus) in azx_int_clear() argument
489 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_clear()
493 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in azx_int_clear()
496 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK); in azx_int_clear()
499 snd_hdac_chip_writel(bus, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM); in azx_int_clear()
503 * snd_hdac_bus_init_chip - reset and start the controller registers
504 * @bus: HD-audio core bus
507 bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_init_chip() argument
509 if (bus->chip_init) in snd_hdac_bus_init_chip()
513 snd_hdac_bus_reset_link(bus, full_reset); in snd_hdac_bus_init_chip()
516 azx_int_clear(bus); in snd_hdac_bus_init_chip()
519 snd_hdac_bus_init_cmd_io(bus); in snd_hdac_bus_init_chip()
522 azx_int_enable(bus); in snd_hdac_bus_init_chip()
525 if (bus->use_posbuf && bus->posbuf.addr) { in snd_hdac_bus_init_chip()
526 snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr); in snd_hdac_bus_init_chip()
527 snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr)); in snd_hdac_bus_init_chip()
530 bus->chip_init = true; in snd_hdac_bus_init_chip()
537 * snd_hdac_bus_stop_chip - disable the whole IRQ and I/Os
538 * @bus: HD-audio core bus
540 void snd_hdac_bus_stop_chip(struct hdac_bus *bus) in snd_hdac_bus_stop_chip() argument
542 if (!bus->chip_init) in snd_hdac_bus_stop_chip()
546 azx_int_disable(bus); in snd_hdac_bus_stop_chip()
547 azx_int_clear(bus); in snd_hdac_bus_stop_chip()
550 snd_hdac_bus_stop_cmd_io(bus); in snd_hdac_bus_stop_chip()
553 if (bus->posbuf.addr) { in snd_hdac_bus_stop_chip()
554 snd_hdac_chip_writel(bus, DPLBASE, 0); in snd_hdac_bus_stop_chip()
555 snd_hdac_chip_writel(bus, DPUBASE, 0); in snd_hdac_bus_stop_chip()
558 bus->chip_init = false; in snd_hdac_bus_stop_chip()
563 * snd_hdac_bus_handle_stream_irq - interrupt handler for streams
564 * @bus: HD-audio core bus
570 int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, in snd_hdac_bus_handle_stream_irq() argument
578 list_for_each_entry(azx_dev, &bus->stream_list, list) { in snd_hdac_bus_handle_stream_irq()
579 if (status & azx_dev->sd_int_sta_mask) { in snd_hdac_bus_handle_stream_irq()
582 handled |= 1 << azx_dev->index; in snd_hdac_bus_handle_stream_irq()
583 if (!azx_dev->substream || !azx_dev->running || in snd_hdac_bus_handle_stream_irq()
587 ack(bus, azx_dev); in snd_hdac_bus_handle_stream_irq()
595 * snd_hdac_bus_alloc_stream_pages - allocate BDL and other buffers
596 * @bus: HD-audio core bus
601 int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_alloc_stream_pages() argument
605 int dma_type = bus->dma_type ? bus->dma_type : SNDRV_DMA_TYPE_DEV; in snd_hdac_bus_alloc_stream_pages()
608 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_alloc_stream_pages()
610 err = snd_dma_alloc_pages(dma_type, bus->dev, in snd_hdac_bus_alloc_stream_pages()
611 BDL_SIZE, &s->bdl); in snd_hdac_bus_alloc_stream_pages()
614 return -ENOMEM; in snd_hdac_bus_alloc_stream_pages()
618 return -EINVAL; in snd_hdac_bus_alloc_stream_pages()
620 err = snd_dma_alloc_pages(dma_type, bus->dev, in snd_hdac_bus_alloc_stream_pages()
621 num_streams * 8, &bus->posbuf); in snd_hdac_bus_alloc_stream_pages()
623 return -ENOMEM; in snd_hdac_bus_alloc_stream_pages()
624 list_for_each_entry(s, &bus->stream_list, list) in snd_hdac_bus_alloc_stream_pages()
625 s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8); in snd_hdac_bus_alloc_stream_pages()
628 return snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb); in snd_hdac_bus_alloc_stream_pages()
633 * snd_hdac_bus_free_stream_pages - release BDL and other buffers
634 * @bus: HD-audio core bus
636 void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_free_stream_pages() argument
640 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_free_stream_pages()
641 if (s->bdl.area) in snd_hdac_bus_free_stream_pages()
642 snd_dma_free_pages(&s->bdl); in snd_hdac_bus_free_stream_pages()
645 if (bus->rb.area) in snd_hdac_bus_free_stream_pages()
646 snd_dma_free_pages(&bus->rb); in snd_hdac_bus_free_stream_pages()
647 if (bus->posbuf.area) in snd_hdac_bus_free_stream_pages()
648 snd_dma_free_pages(&bus->posbuf); in snd_hdac_bus_free_stream_pages()