From patchwork Thu May 28 02:11:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Wang X-Patchwork-Id: 1299343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49XWRz4cHQz9sSm; Thu, 28 May 2020 12:12:31 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1je81y-0004Qm-Pw; Thu, 28 May 2020 02:12:26 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1je81h-0004DF-V2 for kernel-team@lists.ubuntu.com; Thu, 28 May 2020 02:12:10 +0000 Received: from [114.254.40.70] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1je81f-0006ul-Mw for kernel-team@lists.ubuntu.com; Thu, 28 May 2020 02:12:08 +0000 From: Hui Wang To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 18/19] UBUNTU: SAUCE: ASoC: amd: adapt to kernel-5.4 API Date: Thu, 28 May 2020 10:11:02 +0800 Message-Id: <20200528021121.28987-19-hui.wang@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200528021121.28987-1-hui.wang@canonical.com> References: <20200528021121.28987-1-hui.wang@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1881046 This amd renoir driver is for kernel-5.8, after backporting to kernel-5.4, need to do some change according to API in the kernel-5.4, otherwise there will be building errors and runtime errors. Signed-off-by: Hui Wang --- sound/soc/amd/renoir/acp3x-pdm-dma.c | 70 +++++++++++++++++++--------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/sound/soc/amd/renoir/acp3x-pdm-dma.c b/sound/soc/amd/renoir/acp3x-pdm-dma.c index 623dfd3ea705..a823c4d726ff 100644 --- a/sound/soc/amd/renoir/acp3x-pdm-dma.c +++ b/sound/soc/amd/renoir/acp3x-pdm-dma.c @@ -201,12 +201,14 @@ static void config_acp_dma(struct pdm_stream_instance *rtd, int direction) } } -static int acp_pdm_dma_open(struct snd_soc_component *component, - struct snd_pcm_substream *substream) +static int acp_pdm_dma_open(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; struct pdm_dev_data *adata; struct pdm_stream_instance *pdm_data; + struct snd_soc_pcm_runtime *prtd = substream->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, + DRV_NAME); int ret; runtime = substream->runtime; @@ -236,24 +238,34 @@ static int acp_pdm_dma_open(struct snd_soc_component *component, return ret; } -static int acp_pdm_dma_hw_params(struct snd_soc_component *component, - struct snd_pcm_substream *substream, +static int acp_pdm_dma_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct pdm_stream_instance *rtd; size_t size, period_bytes; + int status; rtd = substream->runtime->private_data; if (!rtd) return -EINVAL; + size = params_buffer_bytes(params); period_bytes = params_period_bytes(params); - rtd->dma_addr = substream->dma_buffer.addr; - rtd->num_pages = (PAGE_ALIGN(size) >> PAGE_SHIFT); - config_acp_dma(rtd, substream->stream); - init_pdm_ring_buffer(MEM_WINDOW_START, size, period_bytes, - rtd->acp_base); - return 0; + status = snd_pcm_lib_malloc_pages(substream, size); + if (status < 0) + return status; + memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); + if (substream->dma_buffer.area) { + rtd->dma_addr = substream->dma_buffer.addr; + rtd->num_pages = (PAGE_ALIGN(size) >> PAGE_SHIFT); + config_acp_dma(rtd, substream->stream); + init_pdm_ring_buffer(MEM_WINDOW_START, size, period_bytes, + rtd->acp_base); + status = 0; + } else + status = -ENOMEM; + + return status; } static u64 acp_pdm_get_byte_count(struct pdm_stream_instance *rtd, @@ -270,8 +282,7 @@ static u64 acp_pdm_get_byte_count(struct pdm_stream_instance *rtd, return byte_count.bytescount; } -static snd_pcm_uframes_t acp_pdm_dma_pointer(struct snd_soc_component *comp, - struct snd_pcm_substream *stream) +static snd_pcm_uframes_t acp_pdm_dma_pointer(struct snd_pcm_substream *stream) { struct pdm_stream_instance *rtd; u32 pos, buffersize; @@ -287,26 +298,29 @@ static snd_pcm_uframes_t acp_pdm_dma_pointer(struct snd_soc_component *comp, return bytes_to_frames(stream->runtime, pos); } -static int acp_pdm_dma_new(struct snd_soc_component *component, - struct snd_soc_pcm_runtime *rtd) +static int acp_pdm_dma_new(struct snd_soc_pcm_runtime *rtd) { + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, + DRV_NAME); struct device *parent = component->dev->parent; - snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, + snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, parent, MIN_BUFFER, MAX_BUFFER); + return 0; } -static int acp_pdm_dma_mmap(struct snd_soc_component *component, - struct snd_pcm_substream *substream, +static int acp_pdm_dma_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma) { return snd_pcm_lib_default_mmap(substream, vma); } -static int acp_pdm_dma_close(struct snd_soc_component *component, - struct snd_pcm_substream *substream) +static int acp_pdm_dma_close(struct snd_pcm_substream *substream) { + struct snd_soc_pcm_runtime *prtd = substream->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, + DRV_NAME); struct pdm_dev_data *adata = dev_get_drvdata(component->dev); disable_pdm_interrupts(adata->acp_base); @@ -329,6 +343,7 @@ static int acp_pdm_dai_hw_params(struct snd_pcm_substream *substream, default: return -EINVAL; } + rn_writel(ch_mask, rtd->acp_base + ACP_WOV_PDM_NO_OF_CHANNELS); rn_writel(PDM_DECIMATION_FACTOR, rtd->acp_base + ACP_WOV_PDM_DECIMATION_FACTOR); @@ -368,6 +383,11 @@ static int acp_pdm_dai_trigger(struct snd_pcm_substream *substream, return ret; } +static int acp_pdm_dma_hw_free(struct snd_pcm_substream *substream) +{ + return snd_pcm_lib_free_pages(substream); +} + static struct snd_soc_dai_ops acp_pdm_dai_ops = { .hw_params = acp_pdm_dai_hw_params, .trigger = acp_pdm_dai_trigger, @@ -386,14 +406,20 @@ static struct snd_soc_dai_driver acp_pdm_dai_driver = { .ops = &acp_pdm_dai_ops, }; -static const struct snd_soc_component_driver acp_pdm_component = { - .name = DRV_NAME, +static const struct snd_pcm_ops acp_pdm_ops = { .open = acp_pdm_dma_open, .close = acp_pdm_dma_close, .hw_params = acp_pdm_dma_hw_params, + .hw_free = acp_pdm_dma_hw_free, .pointer = acp_pdm_dma_pointer, .mmap = acp_pdm_dma_mmap, - .pcm_construct = acp_pdm_dma_new, +}; + +static const struct snd_soc_component_driver acp_pdm_component = { + .name = DRV_NAME, + .ops = &acp_pdm_ops, + .pcm_new = acp_pdm_dma_new, + }; static int acp_pdm_audio_probe(struct platform_device *pdev)