Lines Matching refs:bus

13 static void azx_clear_corbrp(struct hdac_bus *bus)  in azx_clear_corbrp()  argument
18 if (snd_hdac_chip_readw(bus, CORBRP) & AZX_CORBRP_RST) in azx_clear_corbrp()
23 dev_err(bus->dev, "CORB reset timeout#1, CORBRP = %d\n", in azx_clear_corbrp()
24 snd_hdac_chip_readw(bus, CORBRP)); in azx_clear_corbrp()
26 snd_hdac_chip_writew(bus, CORBRP, 0); in azx_clear_corbrp()
28 if (snd_hdac_chip_readw(bus, CORBRP) == 0) in azx_clear_corbrp()
33 dev_err(bus->dev, "CORB reset timeout#2, CORBRP = %d\n", in azx_clear_corbrp()
34 snd_hdac_chip_readw(bus, CORBRP)); in azx_clear_corbrp()
41 void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_init_cmd_io() argument
43 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
45 bus->corb.addr = bus->rb.addr; in snd_hdac_bus_init_cmd_io()
46 bus->corb.buf = (__le32 *)bus->rb.area; in snd_hdac_bus_init_cmd_io()
47 snd_hdac_chip_writel(bus, CORBLBASE, (u32)bus->corb.addr); in snd_hdac_bus_init_cmd_io()
48 snd_hdac_chip_writel(bus, CORBUBASE, upper_32_bits(bus->corb.addr)); in snd_hdac_bus_init_cmd_io()
51 snd_hdac_chip_writeb(bus, CORBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
53 snd_hdac_chip_writew(bus, CORBWP, 0); in snd_hdac_bus_init_cmd_io()
56 snd_hdac_chip_writew(bus, CORBRP, AZX_CORBRP_RST); in snd_hdac_bus_init_cmd_io()
57 if (!bus->corbrp_self_clear) in snd_hdac_bus_init_cmd_io()
58 azx_clear_corbrp(bus); in snd_hdac_bus_init_cmd_io()
61 snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN); in snd_hdac_bus_init_cmd_io()
64 bus->rirb.addr = bus->rb.addr + 2048; in snd_hdac_bus_init_cmd_io()
65 bus->rirb.buf = (__le32 *)(bus->rb.area + 2048); in snd_hdac_bus_init_cmd_io()
66 bus->rirb.wp = bus->rirb.rp = 0; in snd_hdac_bus_init_cmd_io()
67 memset(bus->rirb.cmds, 0, sizeof(bus->rirb.cmds)); in snd_hdac_bus_init_cmd_io()
68 snd_hdac_chip_writel(bus, RIRBLBASE, (u32)bus->rirb.addr); in snd_hdac_bus_init_cmd_io()
69 snd_hdac_chip_writel(bus, RIRBUBASE, upper_32_bits(bus->rirb.addr)); in snd_hdac_bus_init_cmd_io()
72 snd_hdac_chip_writeb(bus, RIRBSIZE, 0x02); in snd_hdac_bus_init_cmd_io()
74 snd_hdac_chip_writew(bus, RIRBWP, AZX_RIRBWP_RST); in snd_hdac_bus_init_cmd_io()
76 snd_hdac_chip_writew(bus, RINTCNT, 1); in snd_hdac_bus_init_cmd_io()
78 snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN); in snd_hdac_bus_init_cmd_io()
79 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_init_cmd_io()
87 void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus) in snd_hdac_bus_stop_cmd_io() argument
89 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
91 snd_hdac_chip_writeb(bus, RIRBCTL, 0); in snd_hdac_bus_stop_cmd_io()
92 snd_hdac_chip_writeb(bus, CORBCTL, 0); in snd_hdac_bus_stop_cmd_io()
94 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0); in snd_hdac_bus_stop_cmd_io()
95 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_stop_cmd_io()
115 int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val) in snd_hdac_bus_send_cmd() argument
120 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
122 bus->last_cmd[azx_command_addr(val)] = val; in snd_hdac_bus_send_cmd()
125 wp = snd_hdac_chip_readw(bus, CORBWP); in snd_hdac_bus_send_cmd()
128 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
134 rp = snd_hdac_chip_readw(bus, CORBRP); in snd_hdac_bus_send_cmd()
137 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
141 bus->rirb.cmds[addr]++; in snd_hdac_bus_send_cmd()
142 bus->corb.buf[wp] = cpu_to_le32(val); in snd_hdac_bus_send_cmd()
143 snd_hdac_chip_writew(bus, CORBWP, wp); in snd_hdac_bus_send_cmd()
145 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_send_cmd()
159 void snd_hdac_bus_update_rirb(struct hdac_bus *bus) in snd_hdac_bus_update_rirb() argument
165 wp = snd_hdac_chip_readw(bus, RIRBWP); in snd_hdac_bus_update_rirb()
171 if (wp == bus->rirb.wp) in snd_hdac_bus_update_rirb()
173 bus->rirb.wp = wp; in snd_hdac_bus_update_rirb()
175 while (bus->rirb.rp != wp) { in snd_hdac_bus_update_rirb()
176 bus->rirb.rp++; in snd_hdac_bus_update_rirb()
177 bus->rirb.rp %= AZX_MAX_RIRB_ENTRIES; in snd_hdac_bus_update_rirb()
179 rp = bus->rirb.rp << 1; /* an RIRB entry is 8-bytes */ in snd_hdac_bus_update_rirb()
180 res_ex = le32_to_cpu(bus->rirb.buf[rp + 1]); in snd_hdac_bus_update_rirb()
181 res = le32_to_cpu(bus->rirb.buf[rp]); in snd_hdac_bus_update_rirb()
184 dev_err(bus->dev, in snd_hdac_bus_update_rirb()
186 res, res_ex, bus->rirb.rp, wp); in snd_hdac_bus_update_rirb()
189 snd_hdac_bus_queue_event(bus, res, res_ex); in snd_hdac_bus_update_rirb()
190 else if (bus->rirb.cmds[addr]) { in snd_hdac_bus_update_rirb()
191 bus->rirb.res[addr] = res; in snd_hdac_bus_update_rirb()
192 bus->rirb.cmds[addr]--; in snd_hdac_bus_update_rirb()
194 dev_err_ratelimited(bus->dev, in snd_hdac_bus_update_rirb()
196 res, res_ex, bus->last_cmd[addr]); in snd_hdac_bus_update_rirb()
210 int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, in snd_hdac_bus_get_response() argument
219 spin_lock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
220 if (!bus->rirb.cmds[addr]) { in snd_hdac_bus_get_response()
222 *res = bus->rirb.res[addr]; /* the last value */ in snd_hdac_bus_get_response()
223 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
226 spin_unlock_irq(&bus->reg_lock); in snd_hdac_bus_get_response()
251 void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus) in snd_hdac_bus_enter_link_reset() argument
256 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, 0); in snd_hdac_bus_enter_link_reset()
259 while ((snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) && in snd_hdac_bus_enter_link_reset()
271 void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus) in snd_hdac_bus_exit_link_reset() argument
275 snd_hdac_chip_updateb(bus, GCTL, 0, AZX_GCTL_RESET); in snd_hdac_bus_exit_link_reset()
278 while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout)) in snd_hdac_bus_exit_link_reset()
284 static int azx_reset(struct hdac_bus *bus, bool full_reset) in azx_reset() argument
290 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in azx_reset()
293 snd_hdac_bus_enter_link_reset(bus); in azx_reset()
301 snd_hdac_bus_exit_link_reset(bus); in azx_reset()
308 if (!snd_hdac_chip_readb(bus, GCTL)) { in azx_reset()
309 dev_dbg(bus->dev, "azx_reset: controller not ready!\n"); in azx_reset()
314 snd_hdac_chip_updatel(bus, GCTL, 0, AZX_GCTL_UNSOL); in azx_reset()
317 if (!bus->codec_mask) { in azx_reset()
318 bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS); in azx_reset()
319 dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask); in azx_reset()
326 static void azx_int_enable(struct hdac_bus *bus) in azx_int_enable() argument
329 snd_hdac_chip_updatel(bus, INTCTL, 0, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN); in azx_int_enable()
333 static void azx_int_disable(struct hdac_bus *bus) in azx_int_disable() argument
338 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_disable()
342 snd_hdac_chip_writeb(bus, INTCTL, 0); in azx_int_disable()
345 snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN, 0); in azx_int_disable()
349 static void azx_int_clear(struct hdac_bus *bus) in azx_int_clear() argument
354 list_for_each_entry(azx_dev, &bus->stream_list, list) in azx_int_clear()
358 snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); in azx_int_clear()
361 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK); in azx_int_clear()
364 snd_hdac_chip_writel(bus, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM); in azx_int_clear()
372 bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset) in snd_hdac_bus_init_chip() argument
374 if (bus->chip_init) in snd_hdac_bus_init_chip()
378 azx_reset(bus, full_reset); in snd_hdac_bus_init_chip()
381 azx_int_clear(bus); in snd_hdac_bus_init_chip()
382 azx_int_enable(bus); in snd_hdac_bus_init_chip()
385 snd_hdac_bus_init_cmd_io(bus); in snd_hdac_bus_init_chip()
388 if (bus->use_posbuf && bus->posbuf.addr) { in snd_hdac_bus_init_chip()
389 snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr); in snd_hdac_bus_init_chip()
390 snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr)); in snd_hdac_bus_init_chip()
393 bus->chip_init = true; in snd_hdac_bus_init_chip()
402 void snd_hdac_bus_stop_chip(struct hdac_bus *bus) in snd_hdac_bus_stop_chip() argument
404 if (!bus->chip_init) in snd_hdac_bus_stop_chip()
408 azx_int_disable(bus); in snd_hdac_bus_stop_chip()
409 azx_int_clear(bus); in snd_hdac_bus_stop_chip()
412 snd_hdac_bus_stop_cmd_io(bus); in snd_hdac_bus_stop_chip()
415 if (bus->posbuf.addr) { in snd_hdac_bus_stop_chip()
416 snd_hdac_chip_writel(bus, DPLBASE, 0); in snd_hdac_bus_stop_chip()
417 snd_hdac_chip_writel(bus, DPUBASE, 0); in snd_hdac_bus_stop_chip()
420 bus->chip_init = false; in snd_hdac_bus_stop_chip()
430 void snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, in snd_hdac_bus_handle_stream_irq() argument
437 list_for_each_entry(azx_dev, &bus->stream_list, list) { in snd_hdac_bus_handle_stream_irq()
445 ack(bus, azx_dev); in snd_hdac_bus_handle_stream_irq()
458 int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_alloc_stream_pages() argument
464 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_alloc_stream_pages()
466 err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, in snd_hdac_bus_alloc_stream_pages()
476 err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, in snd_hdac_bus_alloc_stream_pages()
477 num_streams * 8, &bus->posbuf); in snd_hdac_bus_alloc_stream_pages()
480 list_for_each_entry(s, &bus->stream_list, list) in snd_hdac_bus_alloc_stream_pages()
481 s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8); in snd_hdac_bus_alloc_stream_pages()
484 return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, in snd_hdac_bus_alloc_stream_pages()
485 PAGE_SIZE, &bus->rb); in snd_hdac_bus_alloc_stream_pages()
493 void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) in snd_hdac_bus_free_stream_pages() argument
497 list_for_each_entry(s, &bus->stream_list, list) { in snd_hdac_bus_free_stream_pages()
499 bus->io_ops->dma_free_pages(bus, &s->bdl); in snd_hdac_bus_free_stream_pages()
502 if (bus->rb.area) in snd_hdac_bus_free_stream_pages()
503 bus->io_ops->dma_free_pages(bus, &bus->rb); in snd_hdac_bus_free_stream_pages()
504 if (bus->posbuf.area) in snd_hdac_bus_free_stream_pages()
505 bus->io_ops->dma_free_pages(bus, &bus->posbuf); in snd_hdac_bus_free_stream_pages()