Lines Matching refs:cl

60 void hda_cldma_fill(struct hda_cldma *cl)  in hda_cldma_fill()  argument
64 if (cl->remaining > cl->buffer_size) in hda_cldma_fill()
65 size = cl->buffer_size; in hda_cldma_fill()
67 size = cl->remaining; in hda_cldma_fill()
69 offset = snd_hdac_stream_readl(cl, CL_SD_SPIB); in hda_cldma_fill()
70 if (offset + size > cl->buffer_size) { in hda_cldma_fill()
73 ss = cl->buffer_size - offset; in hda_cldma_fill()
74 memcpy(cl->dmab_data.area + offset, cl->position, ss); in hda_cldma_fill()
77 cl->position += ss; in hda_cldma_fill()
78 cl->remaining -= ss; in hda_cldma_fill()
81 memcpy(cl->dmab_data.area + offset, cl->position, size); in hda_cldma_fill()
82 cl->position += size; in hda_cldma_fill()
83 cl->remaining -= size; in hda_cldma_fill()
85 snd_hdac_stream_writel(cl, CL_SD_SPIB, offset + size); in hda_cldma_fill()
90 struct hda_cldma *cl = container_of(work, struct hda_cldma, memcpy_work.work); in cldma_memcpy_work() local
93 ret = hda_cldma_start(cl); in cldma_memcpy_work()
95 dev_err(cl->dev, "cldma set RUN failed: %d\n", ret); in cldma_memcpy_work()
100 ret = wait_for_completion_timeout(&cl->completion, in cldma_memcpy_work()
103 dev_err(cl->dev, "cldma IOC timeout\n"); in cldma_memcpy_work()
107 if (!(cl->sd_status & SD_INT_COMPLETE)) { in cldma_memcpy_work()
108 dev_err(cl->dev, "cldma transfer error, SD status: 0x%08x\n", in cldma_memcpy_work()
109 cl->sd_status); in cldma_memcpy_work()
113 if (!cl->remaining) in cldma_memcpy_work()
116 reinit_completion(&cl->completion); in cldma_memcpy_work()
117 hda_cldma_fill(cl); in cldma_memcpy_work()
119 snd_hdac_adsp_updatel(cl, AVS_ADSP_REG_ADSPIC, AVS_ADSP_ADSPIC_CLDMA, in cldma_memcpy_work()
124 void hda_cldma_transfer(struct hda_cldma *cl, unsigned long start_delay) in hda_cldma_transfer() argument
126 if (!cl->remaining) in hda_cldma_transfer()
129 reinit_completion(&cl->completion); in hda_cldma_transfer()
131 hda_cldma_fill(cl); in hda_cldma_transfer()
133 schedule_delayed_work(&cl->memcpy_work, start_delay); in hda_cldma_transfer()
136 int hda_cldma_start(struct hda_cldma *cl) in hda_cldma_start() argument
141 snd_hdac_adsp_updatel(cl, AVS_ADSP_REG_ADSPIC, AVS_ADSP_ADSPIC_CLDMA, in hda_cldma_start()
143 snd_hdac_stream_updateb(cl, SD_CTL, SD_INT_MASK | SD_CTL_DMA_START, in hda_cldma_start()
147 return snd_hdac_stream_readb_poll(cl, SD_CTL, reg, reg & SD_CTL_DMA_START, in hda_cldma_start()
151 int hda_cldma_stop(struct hda_cldma *cl) in hda_cldma_stop() argument
157 snd_hdac_adsp_updatel(cl, AVS_ADSP_REG_ADSPIC, AVS_ADSP_ADSPIC_CLDMA, 0); in hda_cldma_stop()
158 snd_hdac_stream_updateb(cl, SD_CTL, SD_INT_MASK | SD_CTL_DMA_START, 0); in hda_cldma_stop()
161 ret = snd_hdac_stream_readb_poll(cl, SD_CTL, reg, !(reg & SD_CTL_DMA_START), in hda_cldma_stop()
163 cancel_delayed_work_sync(&cl->memcpy_work); in hda_cldma_stop()
168 int hda_cldma_reset(struct hda_cldma *cl) in hda_cldma_reset() argument
173 ret = hda_cldma_stop(cl); in hda_cldma_reset()
175 dev_err(cl->dev, "cldma stop failed: %d\n", ret); in hda_cldma_reset()
179 snd_hdac_stream_updateb(cl, SD_CTL, SD_CTL_STREAM_RESET, SD_CTL_STREAM_RESET); in hda_cldma_reset()
180 ret = snd_hdac_stream_readb_poll(cl, SD_CTL, reg, (reg & SD_CTL_STREAM_RESET), in hda_cldma_reset()
183 dev_err(cl->dev, "cldma set SRST failed: %d\n", ret); in hda_cldma_reset()
187 snd_hdac_stream_updateb(cl, SD_CTL, SD_CTL_STREAM_RESET, 0); in hda_cldma_reset()
188 ret = snd_hdac_stream_readb_poll(cl, SD_CTL, reg, !(reg & SD_CTL_STREAM_RESET), in hda_cldma_reset()
191 dev_err(cl->dev, "cldma unset SRST failed: %d\n", ret); in hda_cldma_reset()
198 void hda_cldma_set_data(struct hda_cldma *cl, void *data, unsigned int size) in hda_cldma_set_data() argument
201 cl->position = data; in hda_cldma_set_data()
202 cl->remaining = size; in hda_cldma_set_data()
205 static void cldma_setup_bdle(struct hda_cldma *cl, u32 bdle_size) in cldma_setup_bdle() argument
207 struct snd_dma_buffer *dmab = &cl->dmab_data; in cldma_setup_bdle()
208 __le32 *bdl = (__le32 *)cl->dmab_bdl.area; in cldma_setup_bdle()
209 int remaining = cl->buffer_size; in cldma_setup_bdle()
212 cl->num_periods = 0; in cldma_setup_bdle()
230 cl->num_periods++; in cldma_setup_bdle()
234 void hda_cldma_setup(struct hda_cldma *cl) in hda_cldma_setup() argument
236 dma_addr_t bdl_addr = cl->dmab_bdl.addr; in hda_cldma_setup()
238 cldma_setup_bdle(cl, cl->buffer_size / 2); in hda_cldma_setup()
240 snd_hdac_stream_writel(cl, SD_BDLPL, AZX_SD_BDLPL_BDLPLBA(lower_32_bits(bdl_addr))); in hda_cldma_setup()
241 snd_hdac_stream_writel(cl, SD_BDLPU, upper_32_bits(bdl_addr)); in hda_cldma_setup()
243 snd_hdac_stream_writel(cl, SD_CBL, cl->buffer_size); in hda_cldma_setup()
244 snd_hdac_stream_writeb(cl, SD_LVI, cl->num_periods - 1); in hda_cldma_setup()
246 snd_hdac_stream_updatel(cl, SD_CTL, AZX_SD_CTL_STRM_MASK, AZX_SD_CTL_STRM(cl)); in hda_cldma_setup()
248 snd_hdac_stream_writel(cl, CL_SPBFCTL, 1); in hda_cldma_setup()
253 struct hda_cldma *cl = dev_id; in cldma_irq_handler() local
256 adspis = snd_hdac_adsp_readl(cl, AVS_ADSP_REG_ADSPIS); in cldma_irq_handler()
262 cl->sd_status = snd_hdac_stream_readb(cl, SD_STS); in cldma_irq_handler()
263 dev_warn(cl->dev, "%s sd_status: 0x%08x\n", __func__, cl->sd_status); in cldma_irq_handler()
266 snd_hdac_adsp_updatel(cl, AVS_ADSP_REG_ADSPIC, AVS_ADSP_ADSPIC_CLDMA, 0); in cldma_irq_handler()
268 complete(&cl->completion); in cldma_irq_handler()
273 int hda_cldma_init(struct hda_cldma *cl, struct hdac_bus *bus, void __iomem *dsp_ba, in hda_cldma_init() argument
279 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, bus->dev, buffer_size, &cl->dmab_data); in hda_cldma_init()
283 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, bus->dev, BDL_SIZE, &cl->dmab_bdl); in hda_cldma_init()
287 cl->dev = bus->dev; in hda_cldma_init()
288 cl->bus = bus; in hda_cldma_init()
289 cl->dsp_ba = dsp_ba; in hda_cldma_init()
290 cl->buffer_size = buffer_size; in hda_cldma_init()
291 cl->sd_addr = dsp_ba + AZX_CL_SD_BASE; in hda_cldma_init()
293 ret = pci_request_irq(pci, 0, cldma_irq_handler, NULL, cl, "CLDMA"); in hda_cldma_init()
295 dev_err(cl->dev, "Failed to request CLDMA IRQ handler: %d\n", ret); in hda_cldma_init()
302 snd_dma_free_pages(&cl->dmab_bdl); in hda_cldma_init()
304 snd_dma_free_pages(&cl->dmab_data); in hda_cldma_init()
309 void hda_cldma_free(struct hda_cldma *cl) in hda_cldma_free() argument
311 struct pci_dev *pci = to_pci_dev(cl->dev); in hda_cldma_free()
313 pci_free_irq(pci, 0, cl); in hda_cldma_free()
314 snd_dma_free_pages(&cl->dmab_data); in hda_cldma_free()
315 snd_dma_free_pages(&cl->dmab_bdl); in hda_cldma_free()