Lines Matching +full:convert +full:- +full:sample +full:- +full:format

1 // SPDX-License-Identifier: GPL-2.0-only
22 #include "dw-hdmi-audio.h"
24 #define DRIVER_NAME "dw-hdmi-ahb-audio"
86 * allocation bits. Note that we can't do channel remapping here -
89 * Mappings for alsa-lib pcm/surround*.conf files:
145 * Convert to hardware format: The userspace buffer contains IEC958 samples,
157 u32 *src = dw->buf_src + offset; in dw_hdmi_reformat_iec958()
158 u32 *dst = dw->buf_dst + offset; in dw_hdmi_reformat_iec958()
159 u32 *end = dw->buf_src + offset + bytes; in dw_hdmi_reformat_iec958()
162 u32 b, sample = *src++; in dw_hdmi_reformat_iec958() local
164 b = (sample & 8) << (28 - 3); in dw_hdmi_reformat_iec958()
166 sample >>= 4; in dw_hdmi_reformat_iec958()
168 *dst++ = sample | b; in dw_hdmi_reformat_iec958()
172 static u32 parity(u32 sample) in parity() argument
174 sample ^= sample >> 16; in parity()
175 sample ^= sample >> 8; in parity()
176 sample ^= sample >> 4; in parity()
177 sample ^= sample >> 2; in parity()
178 sample ^= sample >> 1; in parity()
179 return (sample & 1) << 27; in parity()
185 u32 *src = dw->buf_src + offset; in dw_hdmi_reformat_s24()
186 u32 *dst = dw->buf_dst + offset; in dw_hdmi_reformat_s24()
187 u32 *end = dw->buf_src + offset + bytes; in dw_hdmi_reformat_s24()
193 cs = dw->cs[dw->iec_offset++]; in dw_hdmi_reformat_s24()
194 if (dw->iec_offset >= 192) in dw_hdmi_reformat_s24()
195 dw->iec_offset = 0; in dw_hdmi_reformat_s24()
197 i = dw->channels; in dw_hdmi_reformat_s24()
199 u32 sample = *src++; in dw_hdmi_reformat_s24() local
201 sample &= ~0xff000000; in dw_hdmi_reformat_s24()
202 sample |= *cs++ << 24; in dw_hdmi_reformat_s24()
203 sample |= parity(sample & ~0xf8000000); in dw_hdmi_reformat_s24()
205 *dst++ = sample; in dw_hdmi_reformat_s24()
206 } while (--i); in dw_hdmi_reformat_s24()
218 memset(dw->cs, 0, sizeof(dw->cs)); in dw_hdmi_create_cs()
228 dw->cs[i * 8 + j][ch] = (c & 1) << 2; in dw_hdmi_create_cs()
231 dw->cs[0][0] |= BIT(4); in dw_hdmi_create_cs()
236 void __iomem *base = dw->data.base; in dw_hdmi_start_dma()
237 unsigned offset = dw->buf_offset; in dw_hdmi_start_dma()
238 unsigned period = dw->buf_period; in dw_hdmi_start_dma()
241 dw->reformat(dw, offset, period); in dw_hdmi_start_dma()
247 start = dw->buf_addr + offset; in dw_hdmi_start_dma()
248 stop = start + period - 1; in dw_hdmi_start_dma()
258 if (offset >= dw->buf_size) in dw_hdmi_start_dma()
260 dw->buf_offset = offset; in dw_hdmi_start_dma()
266 writeb_relaxed(~0, dw->data.base + HDMI_AHB_DMA_MASK); in dw_hdmi_stop_dma()
267 writeb_relaxed(HDMI_AHB_DMA_STOP_STOP, dw->data.base + HDMI_AHB_DMA_STOP); in dw_hdmi_stop_dma()
276 stat = readb_relaxed(dw->data.base + HDMI_IH_AHBDMAAUD_STAT0); in snd_dw_hdmi_irq()
280 writeb_relaxed(stat, dw->data.base + HDMI_IH_AHBDMAAUD_STAT0); in snd_dw_hdmi_irq()
282 substream = dw->substream; in snd_dw_hdmi_irq()
286 spin_lock(&dw->lock); in snd_dw_hdmi_irq()
287 if (dw->substream) in snd_dw_hdmi_irq()
289 spin_unlock(&dw->lock); in snd_dw_hdmi_irq()
321 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_open()
322 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_open()
323 void __iomem *base = dw->data.base; in dw_hdmi_open()
327 runtime->hw = dw_hdmi_hw; in dw_hdmi_open()
329 eld = dw->data.get_eld(dw->data.hdmi); in dw_hdmi_open()
348 0, substream->dma_buffer.bytes); in dw_hdmi_open()
364 ret = request_irq(dw->data.irq, snd_dw_hdmi_irq, IRQF_SHARED, in dw_hdmi_open()
365 "dw-hdmi-audio", dw); in dw_hdmi_open()
369 /* Un-mute done interrupt */ in dw_hdmi_open()
379 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_close()
383 dw->data.base + HDMI_IH_MUTE_AHBDMAAUD_STAT0); in dw_hdmi_close()
385 free_irq(dw->data.irq, dw); in dw_hdmi_close()
392 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_hw_free()
394 vfree(runtime->dma_area); in dw_hdmi_hw_free()
395 runtime->dma_area = NULL; in dw_hdmi_hw_free()
402 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_hw_params()
406 if (runtime->dma_area) { in dw_hdmi_hw_params()
407 if (runtime->dma_bytes >= size) in dw_hdmi_hw_params()
409 vfree(runtime->dma_area); in dw_hdmi_hw_params()
411 runtime->dma_area = vzalloc(size); in dw_hdmi_hw_params()
412 if (!runtime->dma_area) in dw_hdmi_hw_params()
413 return -ENOMEM; in dw_hdmi_hw_params()
414 runtime->dma_bytes = size; in dw_hdmi_hw_params()
421 return vmalloc_to_page(substream->runtime->dma_area + offset); in dw_hdmi_get_page()
426 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_prepare()
427 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_prepare()
431 switch (dw->revision) { in dw_hdmi_prepare()
435 if (runtime->channels == 2) in dw_hdmi_prepare()
447 return -EINVAL; in dw_hdmi_prepare()
450 dw_hdmi_set_sample_rate(dw->data.hdmi, runtime->rate); in dw_hdmi_prepare()
453 runtime->hw.fifo_size = threshold * 32; in dw_hdmi_prepare()
456 conf1 = default_hdmi_channel_config[runtime->channels - 2].conf1; in dw_hdmi_prepare()
457 ca = default_hdmi_channel_config[runtime->channels - 2].ca; in dw_hdmi_prepare()
459 writeb_relaxed(threshold, dw->data.base + HDMI_AHB_DMA_THRSLD); in dw_hdmi_prepare()
460 writeb_relaxed(conf0, dw->data.base + HDMI_AHB_DMA_CONF0); in dw_hdmi_prepare()
461 writeb_relaxed(conf1, dw->data.base + HDMI_AHB_DMA_CONF1); in dw_hdmi_prepare()
463 dw_hdmi_set_channel_count(dw->data.hdmi, runtime->channels); in dw_hdmi_prepare()
464 dw_hdmi_set_channel_allocation(dw->data.hdmi, ca); in dw_hdmi_prepare()
466 switch (runtime->format) { in dw_hdmi_prepare()
468 dw->reformat = dw_hdmi_reformat_iec958; in dw_hdmi_prepare()
472 dw->reformat = dw_hdmi_reformat_s24; in dw_hdmi_prepare()
475 dw->iec_offset = 0; in dw_hdmi_prepare()
476 dw->channels = runtime->channels; in dw_hdmi_prepare()
477 dw->buf_src = runtime->dma_area; in dw_hdmi_prepare()
478 dw->buf_dst = substream->dma_buffer.area; in dw_hdmi_prepare()
479 dw->buf_addr = substream->dma_buffer.addr; in dw_hdmi_prepare()
480 dw->buf_period = snd_pcm_lib_period_bytes(substream); in dw_hdmi_prepare()
481 dw->buf_size = snd_pcm_lib_buffer_bytes(substream); in dw_hdmi_prepare()
488 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_trigger()
494 spin_lock_irqsave(&dw->lock, flags); in dw_hdmi_trigger()
495 dw->buf_offset = 0; in dw_hdmi_trigger()
496 dw->substream = substream; in dw_hdmi_trigger()
498 dw_hdmi_audio_enable(dw->data.hdmi); in dw_hdmi_trigger()
499 spin_unlock_irqrestore(&dw->lock, flags); in dw_hdmi_trigger()
500 substream->runtime->delay = substream->runtime->period_size; in dw_hdmi_trigger()
504 spin_lock_irqsave(&dw->lock, flags); in dw_hdmi_trigger()
505 dw->substream = NULL; in dw_hdmi_trigger()
507 dw_hdmi_audio_disable(dw->data.hdmi); in dw_hdmi_trigger()
508 spin_unlock_irqrestore(&dw->lock, flags); in dw_hdmi_trigger()
512 ret = -EINVAL; in dw_hdmi_trigger()
521 struct snd_pcm_runtime *runtime = substream->runtime; in dw_hdmi_pointer()
522 struct snd_dw_hdmi *dw = substream->private_data; in dw_hdmi_pointer()
526 * reading the 32-bit DMA position using 8-bit reads is racy. in dw_hdmi_pointer()
528 return bytes_to_frames(runtime, dw->buf_offset); in dw_hdmi_pointer()
545 const struct dw_hdmi_audio_data *data = pdev->dev.platform_data; in snd_dw_hdmi_probe()
546 struct device *dev = pdev->dev.parent; in snd_dw_hdmi_probe()
554 data->base + HDMI_IH_MUTE_AHBDMAAUD_STAT0); in snd_dw_hdmi_probe()
555 revision = readb_relaxed(data->base + HDMI_REVISION_ID); in snd_dw_hdmi_probe()
557 dev_err(dev, "dw-hdmi-audio: unknown revision 0x%02x\n", in snd_dw_hdmi_probe()
559 return -ENXIO; in snd_dw_hdmi_probe()
567 strscpy(card->driver, DRIVER_NAME, sizeof(card->driver)); in snd_dw_hdmi_probe()
568 strscpy(card->shortname, "DW-HDMI", sizeof(card->shortname)); in snd_dw_hdmi_probe()
569 snprintf(card->longname, sizeof(card->longname), in snd_dw_hdmi_probe()
570 "%s rev 0x%02x, irq %d", card->shortname, revision, in snd_dw_hdmi_probe()
571 data->irq); in snd_dw_hdmi_probe()
573 dw = card->private_data; in snd_dw_hdmi_probe()
574 dw->card = card; in snd_dw_hdmi_probe()
575 dw->data = *data; in snd_dw_hdmi_probe()
576 dw->revision = revision; in snd_dw_hdmi_probe()
578 spin_lock_init(&dw->lock); in snd_dw_hdmi_probe()
584 dw->pcm = pcm; in snd_dw_hdmi_probe()
585 pcm->private_data = dw; in snd_dw_hdmi_probe()
586 strscpy(pcm->name, DRIVER_NAME, sizeof(pcm->name)); in snd_dw_hdmi_probe()
590 * To support 8-channel 96kHz audio reliably, we need 512k in snd_dw_hdmi_probe()
613 snd_card_free(dw->card); in snd_dw_hdmi_remove()
625 snd_power_change_state(dw->card, SNDRV_CTL_POWER_D3cold); in snd_dw_hdmi_suspend()
634 snd_power_change_state(dw->card, SNDRV_CTL_POWER_D0); in snd_dw_hdmi_resume()