From 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4 Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Mon, 11 Dec 2023 02:46:07 +0000 Subject: [PATCH] add audio --- kernel/sound/soc/rockchip/rockchip_multi_dais_pcm.c | 86 +++++++++++++++++++++++++------------------ 1 files changed, 50 insertions(+), 36 deletions(-) diff --git a/kernel/sound/soc/rockchip/rockchip_multi_dais_pcm.c b/kernel/sound/soc/rockchip/rockchip_multi_dais_pcm.c index c057fa8..d69395f 100644 --- a/kernel/sound/soc/rockchip/rockchip_multi_dais_pcm.c +++ b/kernel/sound/soc/rockchip/rockchip_multi_dais_pcm.c @@ -330,7 +330,8 @@ } #endif -static int snd_dmaengine_mpcm_trigger(struct snd_pcm_substream *substream, int cmd) +static int snd_dmaengine_mpcm_trigger(struct snd_soc_component *component, + struct snd_pcm_substream *substream, int cmd) { struct dmaengine_mpcm_runtime_data *prtd = substream_to_prtd(substream); struct snd_pcm_runtime *runtime = substream->runtime; @@ -377,12 +378,10 @@ return 0; } -static int dmaengine_mpcm_hw_params(struct snd_pcm_substream *substream, +static int dmaengine_mpcm_hw_params(struct snd_soc_component *component, + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component = - snd_soc_rtdcom_lookup(rtd, SND_DMAENGINE_MPCM_DRV_NAME); struct dmaengine_mpcm *pcm = soc_component_to_mpcm(component); struct dma_chan *chan; struct snd_dmaengine_dai_dma_data *dma_data; @@ -420,18 +419,22 @@ sz = snd_pcm_format_size(format, maps[i]); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { chan = pcm->tx_chans[i]; +#ifdef CONFIG_NO_GKI if (sz) { slave_config.src_interlace_size = frame_bytes - sz; if (slave_config.src_interlace_size) slave_config.dst_maxburst = sz / slave_config.dst_addr_width; } +#endif } else { chan = pcm->rx_chans[i]; +#ifdef CONFIG_NO_GKI if (sz) { slave_config.dst_interlace_size = frame_bytes - sz; if (slave_config.dst_interlace_size) slave_config.src_maxburst = sz / slave_config.src_addr_width; } +#endif } if (!chan) continue; @@ -515,11 +518,9 @@ return snd_soc_set_runtime_hwparams(substream, &hw); } -static int dmaengine_mpcm_open(struct snd_pcm_substream *substream) +static int dmaengine_mpcm_open(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component = - snd_soc_rtdcom_lookup(rtd, SND_DMAENGINE_MPCM_DRV_NAME); struct dmaengine_mpcm *pcm = soc_component_to_mpcm(component); struct dmaengine_mpcm_runtime_data *prtd; int ret, i; @@ -554,16 +555,13 @@ return 0; } -static int dmaengine_mpcm_new(struct snd_soc_pcm_runtime *rtd) +static int dmaengine_mpcm_new(struct snd_soc_component *component, struct snd_soc_pcm_runtime *rtd) { - struct snd_soc_component *component = - snd_soc_rtdcom_lookup(rtd, SND_DMAENGINE_MPCM_DRV_NAME); struct dmaengine_mpcm *pcm = soc_component_to_mpcm(component); struct snd_pcm_substream *substream; size_t prealloc_buffer_size; size_t max_buffer_size; unsigned int i; - int ret; prealloc_buffer_size = 512 * 1024; max_buffer_size = SIZE_MAX; @@ -573,19 +571,18 @@ if (!substream) continue; - ret = snd_pcm_lib_preallocate_pages(substream, - SNDRV_DMA_TYPE_DEV_IRAM, - dmaengine_dma_dev(pcm, substream), - prealloc_buffer_size, - max_buffer_size); - if (ret) - return ret; + snd_pcm_lib_preallocate_pages(substream, + SNDRV_DMA_TYPE_DEV_IRAM, + dmaengine_dma_dev(pcm, substream), + prealloc_buffer_size, + max_buffer_size); } return 0; } -static snd_pcm_uframes_t dmaengine_mpcm_pointer(struct snd_pcm_substream *substream) +static snd_pcm_uframes_t dmaengine_mpcm_pointer(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { struct dmaengine_mpcm_runtime_data *prtd = substream_to_prtd(substream); struct snd_pcm_runtime *runtime = substream->runtime; @@ -601,6 +598,9 @@ pos = buf_size - state.residue; frames = bytes_to_frames(substream->runtime, pos); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + return frames; + #ifdef CONFIG_SND_SOC_ROCKCHIP_VAD if (prtd->vpos) frames = bytes_to_frames(substream->runtime, prtd->vpos); @@ -620,7 +620,21 @@ return frames; } -static int dmaengine_mpcm_close(struct snd_pcm_substream *substream) +static int dmaengine_mpcm_ioctl(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + unsigned int cmd, void *arg) +{ + return snd_pcm_lib_ioctl(substream, cmd, arg); +} + +static int dmaengine_mpcm_hw_free(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + return snd_pcm_lib_free_pages(substream); +} + +static int dmaengine_mpcm_close(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { struct dmaengine_mpcm_runtime_data *prtd = substream_to_prtd(substream); @@ -629,21 +643,17 @@ return 0; } -static const struct snd_pcm_ops dmaengine_mpcm_ops = { - .open = dmaengine_mpcm_open, - .close = dmaengine_mpcm_close, - .ioctl = snd_pcm_lib_ioctl, - .hw_params = dmaengine_mpcm_hw_params, - .hw_free = snd_pcm_lib_free_pages, - .trigger = snd_dmaengine_mpcm_trigger, - .pointer = dmaengine_mpcm_pointer, -}; - static const struct snd_soc_component_driver dmaengine_mpcm_platform = { .name = SND_DMAENGINE_MPCM_DRV_NAME, .probe_order = SND_SOC_COMP_ORDER_LATE, - .ops = &dmaengine_mpcm_ops, - .pcm_new = dmaengine_mpcm_new, + .pcm_construct = dmaengine_mpcm_new, + .open = dmaengine_mpcm_open, + .close = dmaengine_mpcm_close, + .ioctl = dmaengine_mpcm_ioctl, + .hw_params = dmaengine_mpcm_hw_params, + .hw_free = dmaengine_mpcm_hw_free, + .trigger = snd_dmaengine_mpcm_trigger, + .pointer = dmaengine_mpcm_pointer, }; static void dmaengine_mpcm_release_chan(struct dmaengine_mpcm *pcm) @@ -693,8 +703,12 @@ } } - ret = snd_soc_add_component(dev, &pcm->component, - &dmaengine_mpcm_platform, NULL, 0); + ret = snd_soc_component_initialize(&pcm->component, &dmaengine_mpcm_platform, + dev); + if (ret) + goto err_free_dma; + + ret = snd_soc_add_component(&pcm->component, NULL, 0); if (ret) goto err_free_dma; -- Gitblit v1.6.2