Lines Matching +full:dw +full:- +full:hdmi
1 // SPDX-License-Identifier: GPL-2.0-only
3 * DesignWare HDMI audio driver
5 * Written and tested against the Designware HDMI Tx found in iMX6.
21 #include "dw-hdmi-audio.h"
23 #define DRIVER_NAME "dw-hdmi-ahb-audio"
84 * The default mapping of ALSA channels to HDMI channels and speaker
85 * allocation bits. Note that we can't do channel remapping here -
88 * Mappings for alsa-lib pcm/surround*.conf files:
93 * Our mapping from ALSA channel to CEA686D speaker name and HDMI channel:
153 static void dw_hdmi_reformat_iec958(struct snd_dw_hdmi *dw, in dw_hdmi_reformat_iec958() argument
156 u32 *src = dw->buf_src + offset; in dw_hdmi_reformat_iec958()
157 u32 *dst = dw->buf_dst + offset; in dw_hdmi_reformat_iec958()
158 u32 *end = dw->buf_src + offset + bytes; in dw_hdmi_reformat_iec958()
163 b = (sample & 8) << (28 - 3); in dw_hdmi_reformat_iec958()
181 static void dw_hdmi_reformat_s24(struct snd_dw_hdmi *dw, in dw_hdmi_reformat_s24() argument
184 u32 *src = dw->buf_src + offset; in dw_hdmi_reformat_s24()
185 u32 *dst = dw->buf_dst + offset; in dw_hdmi_reformat_s24()
186 u32 *end = dw->buf_src + offset + bytes; in dw_hdmi_reformat_s24()
192 cs = dw->cs[dw->iec_offset++]; in dw_hdmi_reformat_s24()
193 if (dw->iec_offset >= 192) in dw_hdmi_reformat_s24()
194 dw->iec_offset = 0; in dw_hdmi_reformat_s24()
196 i = dw->channels; in dw_hdmi_reformat_s24()
205 } while (--i); in dw_hdmi_reformat_s24()
209 static void dw_hdmi_create_cs(struct snd_dw_hdmi *dw, in dw_hdmi_create_cs() argument
217 memset(dw->cs, 0, sizeof(dw->cs)); in dw_hdmi_create_cs()
227 dw->cs[i * 8 + j][ch] = (c & 1) << 2; in dw_hdmi_create_cs()
230 dw->cs[0][0] |= BIT(4); in dw_hdmi_create_cs()
233 static void dw_hdmi_start_dma(struct snd_dw_hdmi *dw) in dw_hdmi_start_dma() argument
235 void __iomem *base = dw->data.base; in dw_hdmi_start_dma()
236 unsigned offset = dw->buf_offset; in dw_hdmi_start_dma()
237 unsigned period = dw->buf_period; in dw_hdmi_start_dma()
240 dw->reformat(dw, offset, period); in dw_hdmi_start_dma()
246 start = dw->buf_addr + offset; in dw_hdmi_start_dma()
247 stop = start + period - 1; in dw_hdmi_start_dma()
257 if (offset >= dw->buf_size) in dw_hdmi_start_dma()
259 dw->buf_offset = offset; in dw_hdmi_start_dma()
262 static void dw_hdmi_stop_dma(struct snd_dw_hdmi *dw) in dw_hdmi_stop_dma() argument
265 writeb_relaxed(~0, dw->data.base + HDMI_AHB_DMA_MASK); in dw_hdmi_stop_dma()
266 writeb_relaxed(HDMI_AHB_DMA_STOP_STOP, dw->data.base + HDMI_AHB_DMA_STOP); in dw_hdmi_stop_dma()
271 struct snd_dw_hdmi *dw = data; in snd_dw_hdmi_irq() local
275 stat = readb_relaxed(dw->data.base + HDMI_IH_AHBDMAAUD_STAT0); in snd_dw_hdmi_irq()
279 writeb_relaxed(stat, dw->data.base + HDMI_IH_AHBDMAAUD_STAT0); in snd_dw_hdmi_irq()
281 substream = dw->substream; in snd_dw_hdmi_irq()
285 spin_lock(&dw->lock); in snd_dw_hdmi_irq()
286 if (dw->substream) in snd_dw_hdmi_irq()
287 dw_hdmi_start_dma(dw); in snd_dw_hdmi_irq()
288 spin_unlock(&dw->lock); in snd_dw_hdmi_irq()
320 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_open()
321 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_open() local
322 void __iomem *base = dw->data.base; in dw_hdmi_open()
326 runtime->hw = dw_hdmi_hw; in dw_hdmi_open()
328 eld = dw->data.get_eld(dw->data.hdmi); in dw_hdmi_open()
347 0, substream->dma_buffer.bytes); in dw_hdmi_open()
363 ret = request_irq(dw->data.irq, snd_dw_hdmi_irq, IRQF_SHARED, in dw_hdmi_open()
364 "dw-hdmi-audio", dw); in dw_hdmi_open()
368 /* Un-mute done interrupt */ in dw_hdmi_open()
378 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_close() local
382 dw->data.base + HDMI_IH_MUTE_AHBDMAAUD_STAT0); in dw_hdmi_close()
384 free_irq(dw->data.irq, dw); in dw_hdmi_close()
404 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_prepare()
405 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_prepare() local
409 switch (dw->revision) { in dw_hdmi_prepare()
413 if (runtime->channels == 2) in dw_hdmi_prepare()
425 return -EINVAL; in dw_hdmi_prepare()
428 dw_hdmi_set_sample_rate(dw->data.hdmi, runtime->rate); in dw_hdmi_prepare()
431 runtime->hw.fifo_size = threshold * 32; in dw_hdmi_prepare()
434 conf1 = default_hdmi_channel_config[runtime->channels - 2].conf1; in dw_hdmi_prepare()
435 ca = default_hdmi_channel_config[runtime->channels - 2].ca; in dw_hdmi_prepare()
437 writeb_relaxed(threshold, dw->data.base + HDMI_AHB_DMA_THRSLD); in dw_hdmi_prepare()
438 writeb_relaxed(conf0, dw->data.base + HDMI_AHB_DMA_CONF0); in dw_hdmi_prepare()
439 writeb_relaxed(conf1, dw->data.base + HDMI_AHB_DMA_CONF1); in dw_hdmi_prepare()
441 dw_hdmi_set_channel_count(dw->data.hdmi, runtime->channels); in dw_hdmi_prepare()
442 dw_hdmi_set_channel_allocation(dw->data.hdmi, ca); in dw_hdmi_prepare()
444 switch (runtime->format) { in dw_hdmi_prepare()
446 dw->reformat = dw_hdmi_reformat_iec958; in dw_hdmi_prepare()
449 dw_hdmi_create_cs(dw, runtime); in dw_hdmi_prepare()
450 dw->reformat = dw_hdmi_reformat_s24; in dw_hdmi_prepare()
453 dw->iec_offset = 0; in dw_hdmi_prepare()
454 dw->channels = runtime->channels; in dw_hdmi_prepare()
455 dw->buf_src = runtime->dma_area; in dw_hdmi_prepare()
456 dw->buf_dst = substream->dma_buffer.area; in dw_hdmi_prepare()
457 dw->buf_addr = substream->dma_buffer.addr; in dw_hdmi_prepare()
458 dw->buf_period = snd_pcm_lib_period_bytes(substream); in dw_hdmi_prepare()
459 dw->buf_size = snd_pcm_lib_buffer_bytes(substream); in dw_hdmi_prepare()
466 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_trigger() local
472 spin_lock_irqsave(&dw->lock, flags); in dw_hdmi_trigger()
473 dw->buf_offset = 0; in dw_hdmi_trigger()
474 dw->substream = substream; in dw_hdmi_trigger()
475 dw_hdmi_start_dma(dw); in dw_hdmi_trigger()
476 dw_hdmi_audio_enable(dw->data.hdmi); in dw_hdmi_trigger()
477 spin_unlock_irqrestore(&dw->lock, flags); in dw_hdmi_trigger()
478 substream->runtime->delay = substream->runtime->period_size; in dw_hdmi_trigger()
482 spin_lock_irqsave(&dw->lock, flags); in dw_hdmi_trigger()
483 dw->substream = NULL; in dw_hdmi_trigger()
484 dw_hdmi_stop_dma(dw); in dw_hdmi_trigger()
485 dw_hdmi_audio_disable(dw->data.hdmi); in dw_hdmi_trigger()
486 spin_unlock_irqrestore(&dw->lock, flags); in dw_hdmi_trigger()
490 ret = -EINVAL; in dw_hdmi_trigger()
499 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_pointer()
500 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_pointer() local
504 * reading the 32-bit DMA position using 8-bit reads is racy. in dw_hdmi_pointer()
506 return bytes_to_frames(runtime, dw->buf_offset); in dw_hdmi_pointer()
523 const struct dw_hdmi_audio_data *data = pdev->dev.platform_data; in snd_dw_hdmi_probe()
524 struct device *dev = pdev->dev.parent; in snd_dw_hdmi_probe()
525 struct snd_dw_hdmi *dw; in snd_dw_hdmi_probe() local
532 data->base + HDMI_IH_MUTE_AHBDMAAUD_STAT0); in snd_dw_hdmi_probe()
533 revision = readb_relaxed(data->base + HDMI_REVISION_ID); in snd_dw_hdmi_probe()
535 dev_err(dev, "dw-hdmi-audio: unknown revision 0x%02x\n", in snd_dw_hdmi_probe()
537 return -ENXIO; in snd_dw_hdmi_probe()
545 strscpy(card->driver, DRIVER_NAME, sizeof(card->driver)); in snd_dw_hdmi_probe()
546 strscpy(card->shortname, "DW-HDMI", sizeof(card->shortname)); in snd_dw_hdmi_probe()
547 snprintf(card->longname, sizeof(card->longname), in snd_dw_hdmi_probe()
548 "%s rev 0x%02x, irq %d", card->shortname, revision, in snd_dw_hdmi_probe()
549 data->irq); in snd_dw_hdmi_probe()
551 dw = card->private_data; in snd_dw_hdmi_probe()
552 dw->card = card; in snd_dw_hdmi_probe()
553 dw->data = *data; in snd_dw_hdmi_probe()
554 dw->revision = revision; in snd_dw_hdmi_probe()
556 spin_lock_init(&dw->lock); in snd_dw_hdmi_probe()
558 ret = snd_pcm_new(card, "DW HDMI", 0, 1, 0, &pcm); in snd_dw_hdmi_probe()
562 dw->pcm = pcm; in snd_dw_hdmi_probe()
563 pcm->private_data = dw; in snd_dw_hdmi_probe()
564 strscpy(pcm->name, DRIVER_NAME, sizeof(pcm->name)); in snd_dw_hdmi_probe()
568 * To support 8-channel 96kHz audio reliably, we need 512k in snd_dw_hdmi_probe()
578 platform_set_drvdata(pdev, dw); in snd_dw_hdmi_probe()
589 struct snd_dw_hdmi *dw = platform_get_drvdata(pdev); in snd_dw_hdmi_remove() local
591 snd_card_free(dw->card); in snd_dw_hdmi_remove()
601 struct snd_dw_hdmi *dw = dev_get_drvdata(dev); in snd_dw_hdmi_suspend() local
603 snd_power_change_state(dw->card, SNDRV_CTL_POWER_D3cold); in snd_dw_hdmi_suspend()
610 struct snd_dw_hdmi *dw = dev_get_drvdata(dev); in snd_dw_hdmi_resume() local
612 snd_power_change_state(dw->card, SNDRV_CTL_POWER_D0); in snd_dw_hdmi_resume()
636 MODULE_DESCRIPTION("Synopsis Designware HDMI AHB ALSA interface");