From patchwork Mon May 11 21:01:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541733 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 946FB139F for ; Mon, 11 May 2020 21:02:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8665224964 for ; Mon, 11 May 2020 21:02:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732322AbgEKVBm (ORCPT ); Mon, 11 May 2020 17:01:42 -0400 Received: from v6.sk ([167.172.42.174]:52550 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732313AbgEKVBl (ORCPT ); Mon, 11 May 2020 17:01:41 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id B7D67610CF; Mon, 11 May 2020 21:01:38 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 01/11] ASoC: mmp-sspa: Flip SNDRV_PCM_FMTBIT_S24_3LE on Date: Mon, 11 May 2020 23:01:24 +0200 Message-Id: <20200511210134.1224532-2-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The hw_params() callback handles the 3-byte format, not SNDRV_PCM_FMTBIT_S24_LE. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 3548a2634a63..1ca6afe464c4 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -362,7 +362,7 @@ static int mmp_sspa_probe(struct snd_soc_dai *dai) #define MMP_SSPA_RATES SNDRV_PCM_RATE_8000_192000 #define MMP_SSPA_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ SNDRV_PCM_FMTBIT_S16_LE | \ - SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S24_3LE | \ SNDRV_PCM_FMTBIT_S32_LE) static const struct snd_soc_dai_ops mmp_sspa_dai_ops = { From patchwork Mon May 11 21:01:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57114159A for ; Mon, 11 May 2020 21:02:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4744A2078A for ; Mon, 11 May 2020 21:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728544AbgEKVCi (ORCPT ); Mon, 11 May 2020 17:02:38 -0400 Received: from v6.sk ([167.172.42.174]:52562 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729143AbgEKVBm (ORCPT ); Mon, 11 May 2020 17:01:42 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 48001610D0; Mon, 11 May 2020 21:01:40 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 02/11] ASoC: mmp-sspa: Drop S20_3LE case Date: Mon, 11 May 2020 23:01:25 +0200 Message-Id: <20200511210134.1224532-3-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org It does nothing, because the corresponding bit s not flipped on in .formats and the audio SRAM DMA engine is not able to handle 20-bit transfers anyway. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 1ca6afe464c4..90a9bc81be80 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -275,9 +275,6 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, case SNDRV_PCM_FORMAT_S16_LE: sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_16_BITS); break; - case SNDRV_PCM_FORMAT_S20_3LE: - sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_20_BITS); - break; case SNDRV_PCM_FORMAT_S24_3LE: sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_24_BITS); break; From patchwork Mon May 11 21:01:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541719 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDD70159A for ; Mon, 11 May 2020 21:02:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE9A52078A for ; Mon, 11 May 2020 21:02:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732013AbgEKVC2 (ORCPT ); Mon, 11 May 2020 17:02:28 -0400 Received: from v6.sk ([167.172.42.174]:52574 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732080AbgEKVBn (ORCPT ); Mon, 11 May 2020 17:01:43 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id B093E610D1; Mon, 11 May 2020 21:01:41 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 03/11] ASoC: mmp-sspa: A trivial typo fix Date: Mon, 11 May 2020 23:01:26 +0200 Message-Id: <20200511210134.1224532-4-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org "Transmit", not "Tansmit". Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/pxa/mmp-sspa.h b/sound/soc/pxa/mmp-sspa.h index 7d1b7c7325df..611063a7af68 100644 --- a/sound/soc/pxa/mmp-sspa.h +++ b/sound/soc/pxa/mmp-sspa.h @@ -38,7 +38,7 @@ #define SSPA_CTL_XFRLEN2(x) ((x) << 24) /* Transmit Frame Length in Phase 2 */ #define SSPA_CTL_XWDLEN2_MASK (7 << 21) #define SSPA_CTL_XWDLEN2(x) ((x) << 21) /* Transmit Word Length in Phase 2 */ -#define SSPA_CTL_XDATDLY(x) ((x) << 19) /* Tansmit Data Delay */ +#define SSPA_CTL_XDATDLY(x) ((x) << 19) /* Transmit Data Delay */ #define SSPA_CTL_XSSZ2_MASK (7 << 16) #define SSPA_CTL_XSSZ2(x) ((x) << 16) /* Transmit Sample Audio Size */ #define SSPA_CTL_XFRLEN1_MASK (7 << 8) From patchwork Mon May 11 21:01:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92B8B159A for ; Mon, 11 May 2020 21:02:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8291E20836 for ; Mon, 11 May 2020 21:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732341AbgEKVBp (ORCPT ); Mon, 11 May 2020 17:01:45 -0400 Received: from v6.sk ([167.172.42.174]:52586 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732333AbgEKVBp (ORCPT ); Mon, 11 May 2020 17:01:45 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 37505610CF; Mon, 11 May 2020 21:01:43 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 04/11] ASoC: mmp-sspa: Get rid of dma_params and phys_base Date: Mon, 11 May 2020 23:01:27 +0200 Message-Id: <20200511210134.1224532-5-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org This makes things simpler. There's no reason not to just embed the struct snd_dmaengine_dai_dma_data in struct sspa_priv and do away with an unnecessary kmalloc(). While at that, we can initialize the snd_dmaengine_dai_dma_data structures earlier. Let's also stop offsetting the source/destination of the DMA transfer by phys_base. Firstly, it's never set and is always zero. Secondly, the hardware actually ignores it, at least on a MMP2 and MMP3. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 90a9bc81be80..421ffa9fa7b1 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -29,7 +29,8 @@ */ struct sspa_priv { struct ssp_device *sspa; - struct snd_dmaengine_dai_dma_data *dma_params; + struct snd_dmaengine_dai_dma_data playback_dma_data; + struct snd_dmaengine_dai_dma_data capture_dma_data; struct clk *audio_clk; struct clk *sysclk; int dai_fmt; @@ -250,11 +251,8 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(dai); struct ssp_device *sspa = sspa_priv->sspa; - struct snd_dmaengine_dai_dma_data *dma_params; u32 sspa_ctrl; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -293,11 +291,6 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, mmp_sspa_write_reg(sspa, SSPA_RXFIFO_UL, 0x0); } - dma_params = &sspa_priv->dma_params[substream->stream]; - dma_params->addr = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? - (sspa->phys_base + SSPA_TXD) : - (sspa->phys_base + SSPA_RXD); - snd_soc_dai_set_dma_data(cpu_dai, substream, dma_params); return 0; } @@ -351,6 +344,10 @@ static int mmp_sspa_probe(struct snd_soc_dai *dai) { struct sspa_priv *priv = dev_get_drvdata(dai->dev); + snd_soc_dai_init_dma_data(dai, + &priv->playback_dma_data, + &priv->capture_dma_data); + snd_soc_dai_set_drvdata(dai, priv); return 0; @@ -407,12 +404,6 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) if (priv->sspa == NULL) return -ENOMEM; - priv->dma_params = devm_kcalloc(&pdev->dev, - 2, sizeof(struct snd_dmaengine_dai_dma_data), - GFP_KERNEL); - if (priv->dma_params == NULL) - return -ENOMEM; - priv->sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->sspa->mmio_base)) return PTR_ERR(priv->sspa->mmio_base); @@ -434,6 +425,10 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) priv->dai_fmt = (unsigned int) -1; platform_set_drvdata(pdev, priv); + /* You know, these addresses are actually ignored. */ + priv->playback_dma_data.addr = SSPA_TXD; + priv->capture_dma_data.addr = SSPA_RXD; + return devm_snd_soc_register_component(&pdev->dev, &mmp_sspa_component, &mmp_sspa_dai, 1); } From patchwork Mon May 11 21:01:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E77B159A for ; Mon, 11 May 2020 21:01:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E4AB24974 for ; Mon, 11 May 2020 21:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732355AbgEKVBr (ORCPT ); Mon, 11 May 2020 17:01:47 -0400 Received: from v6.sk ([167.172.42.174]:52574 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732339AbgEKVBq (ORCPT ); Mon, 11 May 2020 17:01:46 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id BA2E6610D2; Mon, 11 May 2020 21:01:44 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 05/11] ASoC: mmp-sspa: Add support for soc-generic-dmaengine-pcm Date: Mon, 11 May 2020 23:01:28 +0200 Message-Id: <20200511210134.1224532-6-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org This makes the driver usable with the mmp_tdma drier via soc-generic-dmaengine-pcm. This is conditionalized on DT node (support for DT is added by a later patch). A custom mmap callback that creates a NC mapping is used instead of the default WC one, because with write-combining some bytes don't seem to make it through for reasons unknown to me. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 421ffa9fa7b1..6e4b63d0c589 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -386,8 +386,54 @@ static struct snd_soc_dai_driver mmp_sspa_dai = { .ops = &mmp_sspa_dai_ops, }; +#define MMP_PCM_INFO (SNDRV_PCM_INFO_MMAP | \ + SNDRV_PCM_INFO_MMAP_VALID | \ + SNDRV_PCM_INFO_INTERLEAVED | \ + SNDRV_PCM_INFO_PAUSE | \ + SNDRV_PCM_INFO_RESUME | \ + SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) + +static const struct snd_pcm_hardware mmp_pcm_hardware[] = { + { + .info = MMP_PCM_INFO, + .period_bytes_min = 1024, + .period_bytes_max = 2048, + .periods_min = 2, + .periods_max = 32, + .buffer_bytes_max = 4096, + .fifo_size = 32, + }, + { + .info = MMP_PCM_INFO, + .period_bytes_min = 1024, + .period_bytes_max = 2048, + .periods_min = 2, + .periods_max = 32, + .buffer_bytes_max = 4096, + .fifo_size = 32, + }, +}; + +static const struct snd_dmaengine_pcm_config mmp_pcm_config = { + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, + .pcm_hardware = mmp_pcm_hardware, + .prealloc_buffer_size = 4096, +}; + +static int mmp_pcm_mmap(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + struct vm_area_struct *vma) +{ + vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + return remap_pfn_range(vma, vma->vm_start, + substream->dma_buffer.addr >> PAGE_SHIFT, + vma->vm_end - vma->vm_start, vma->vm_page_prot); +} + static const struct snd_soc_component_driver mmp_sspa_component = { .name = "mmp-sspa", + .mmap = mmp_pcm_mmap, }; static int asoc_mmp_sspa_probe(struct platform_device *pdev) @@ -425,10 +471,21 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) priv->dai_fmt = (unsigned int) -1; platform_set_drvdata(pdev, priv); + priv->playback_dma_data.maxburst = 4; + priv->capture_dma_data.maxburst = 4; /* You know, these addresses are actually ignored. */ priv->playback_dma_data.addr = SSPA_TXD; priv->capture_dma_data.addr = SSPA_RXD; + if (pdev->dev.of_node) { + int ret; + + ret = devm_snd_dmaengine_pcm_register(&pdev->dev, + &mmp_pcm_config, 0); + if (ret) + return ret; + } + return devm_snd_soc_register_component(&pdev->dev, &mmp_sspa_component, &mmp_sspa_dai, 1); } From patchwork Mon May 11 21:01:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541709 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F75C139F for ; Mon, 11 May 2020 21:02:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B158208DB for ; Mon, 11 May 2020 21:02:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732360AbgEKVBt (ORCPT ); Mon, 11 May 2020 17:01:49 -0400 Received: from v6.sk ([167.172.42.174]:52586 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732346AbgEKVBs (ORCPT ); Mon, 11 May 2020 17:01:48 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 524CE610D3; Mon, 11 May 2020 21:01:46 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 06/11] ASoC: mmp-sspa: Remove the embedded struct ssp_device Date: Mon, 11 May 2020 23:01:29 +0200 Message-Id: <20200511210134.1224532-7-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The "serial port" it represents is actually a SPI controller -- it's not clear why would the audio serial interface embed it. We're only using the mmio_base and clk fields. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 129 ++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 69 deletions(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 6e4b63d0c589..7a706b1d2588 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -28,26 +27,27 @@ * SSPA audio private data */ struct sspa_priv { - struct ssp_device *sspa; + void __iomem *mmio_base; struct snd_dmaengine_dai_dma_data playback_dma_data; struct snd_dmaengine_dai_dma_data capture_dma_data; + struct clk *clk; struct clk *audio_clk; struct clk *sysclk; int dai_fmt; int running_cnt; }; -static void mmp_sspa_write_reg(struct ssp_device *sspa, u32 reg, u32 val) +static void mmp_sspa_write_reg(struct sspa_priv *sspa, u32 reg, u32 val) { __raw_writel(val, sspa->mmio_base + reg); } -static u32 mmp_sspa_read_reg(struct ssp_device *sspa, u32 reg) +static u32 mmp_sspa_read_reg(struct sspa_priv *sspa, u32 reg) { return __raw_readl(sspa->mmio_base + reg); } -static void mmp_sspa_tx_enable(struct ssp_device *sspa) +static void mmp_sspa_tx_enable(struct sspa_priv *sspa) { unsigned int sspa_sp; @@ -57,7 +57,7 @@ static void mmp_sspa_tx_enable(struct ssp_device *sspa) mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); } -static void mmp_sspa_tx_disable(struct ssp_device *sspa) +static void mmp_sspa_tx_disable(struct sspa_priv *sspa) { unsigned int sspa_sp; @@ -67,7 +67,7 @@ static void mmp_sspa_tx_disable(struct ssp_device *sspa) mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); } -static void mmp_sspa_rx_enable(struct ssp_device *sspa) +static void mmp_sspa_rx_enable(struct sspa_priv *sspa) { unsigned int sspa_sp; @@ -77,7 +77,7 @@ static void mmp_sspa_rx_enable(struct ssp_device *sspa) mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); } -static void mmp_sspa_rx_disable(struct ssp_device *sspa) +static void mmp_sspa_rx_disable(struct sspa_priv *sspa) { unsigned int sspa_sp; @@ -90,10 +90,10 @@ static void mmp_sspa_rx_disable(struct ssp_device *sspa) static int mmp_sspa_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sspa_priv *priv = snd_soc_dai_get_drvdata(dai); + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); - clk_enable(priv->sysclk); - clk_enable(priv->sspa->clk); + clk_enable(sspa->sysclk); + clk_enable(sspa->clk); return 0; } @@ -101,10 +101,10 @@ static int mmp_sspa_startup(struct snd_pcm_substream *substream, static void mmp_sspa_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sspa_priv *priv = snd_soc_dai_get_drvdata(dai); + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); - clk_disable(priv->sspa->clk); - clk_disable(priv->sysclk); + clk_disable(sspa->clk); + clk_disable(sspa->sysclk); } @@ -114,12 +114,12 @@ static void mmp_sspa_shutdown(struct snd_pcm_substream *substream, static int mmp_sspa_set_dai_sysclk(struct snd_soc_dai *cpu_dai, int clk_id, unsigned int freq, int dir) { - struct sspa_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai); int ret = 0; switch (clk_id) { case MMP_SSPA_CLK_AUDIO: - ret = clk_set_rate(priv->audio_clk, freq); + ret = clk_set_rate(sspa->audio_clk, freq); if (ret) return ret; break; @@ -138,17 +138,17 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id, int source, unsigned int freq_in, unsigned int freq_out) { - struct sspa_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai); int ret = 0; switch (pll_id) { case MMP_SYSCLK: - ret = clk_set_rate(priv->sysclk, freq_out); + ret = clk_set_rate(sspa->sysclk, freq_out); if (ret) return ret; break; case MMP_SSPA_CLK: - ret = clk_set_rate(priv->sspa->clk, freq_out); + ret = clk_set_rate(sspa->clk, freq_out); if (ret) return ret; break; @@ -167,18 +167,17 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id, static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) { - struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(cpu_dai); - struct ssp_device *sspa = sspa_priv->sspa; + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai); u32 sspa_sp, sspa_ctrl; /* check if we need to change anything at all */ - if (sspa_priv->dai_fmt == fmt) + if (sspa->dai_fmt == fmt) return 0; /* we can only change the settings if the port is not in use */ if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) || (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) { - dev_err(sspa->dev, + dev_err(cpu_dai->dev, "can't change hardware dai format: stream is in use\n"); return -EINVAL; } @@ -239,7 +238,7 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai, * we have to defer some things until hw_params() where we * know parameters like the sample size. */ - sspa_priv->dai_fmt = fmt; + sspa->dai_fmt = fmt; return 0; } @@ -251,8 +250,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(dai); - struct ssp_device *sspa = sspa_priv->sspa; + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); u32 sspa_ctrl; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -297,8 +295,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, static int mmp_sspa_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { - struct sspa_priv *sspa_priv = snd_soc_dai_get_drvdata(dai); - struct ssp_device *sspa = sspa_priv->sspa; + struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); int ret = 0; switch (cmd) { @@ -311,25 +308,25 @@ static int mmp_sspa_trigger(struct snd_pcm_substream *substream, int cmd, * enabled or not; if has been enabled by another * stream, do not enable again. */ - if (!sspa_priv->running_cnt) + if (!sspa->running_cnt) mmp_sspa_rx_enable(sspa); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) mmp_sspa_tx_enable(sspa); - sspa_priv->running_cnt++; + sspa->running_cnt++; break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: - sspa_priv->running_cnt--; + sspa->running_cnt--; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) mmp_sspa_tx_disable(sspa); /* have no capture stream, disable rx port */ - if (!sspa_priv->running_cnt) + if (!sspa->running_cnt) mmp_sspa_rx_disable(sspa); break; @@ -342,15 +339,14 @@ static int mmp_sspa_trigger(struct snd_pcm_substream *substream, int cmd, static int mmp_sspa_probe(struct snd_soc_dai *dai) { - struct sspa_priv *priv = dev_get_drvdata(dai->dev); + struct sspa_priv *sspa = dev_get_drvdata(dai->dev); snd_soc_dai_init_dma_data(dai, - &priv->playback_dma_data, - &priv->capture_dma_data); + &sspa->playback_dma_data, + &sspa->capture_dma_data); - snd_soc_dai_set_drvdata(dai, priv); + snd_soc_dai_set_drvdata(dai, sspa); return 0; - } #define MMP_SSPA_RATES SNDRV_PCM_RATE_8000_192000 @@ -438,44 +434,39 @@ static const struct snd_soc_component_driver mmp_sspa_component = { static int asoc_mmp_sspa_probe(struct platform_device *pdev) { - struct sspa_priv *priv; + struct sspa_priv *sspa; - priv = devm_kzalloc(&pdev->dev, + sspa = devm_kzalloc(&pdev->dev, sizeof(struct sspa_priv), GFP_KERNEL); - if (!priv) + if (!sspa) return -ENOMEM; - priv->sspa = devm_kzalloc(&pdev->dev, - sizeof(struct ssp_device), GFP_KERNEL); - if (priv->sspa == NULL) - return -ENOMEM; + sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(sspa->mmio_base)) + return PTR_ERR(sspa->mmio_base); - priv->sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(priv->sspa->mmio_base)) - return PTR_ERR(priv->sspa->mmio_base); + sspa->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(sspa->clk)) + return PTR_ERR(sspa->clk); - priv->sspa->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(priv->sspa->clk)) - return PTR_ERR(priv->sspa->clk); + sspa->audio_clk = clk_get(NULL, "mmp-audio"); + if (IS_ERR(sspa->audio_clk)) + return PTR_ERR(sspa->audio_clk); - priv->audio_clk = clk_get(NULL, "mmp-audio"); - if (IS_ERR(priv->audio_clk)) - return PTR_ERR(priv->audio_clk); - - priv->sysclk = clk_get(NULL, "mmp-sysclk"); - if (IS_ERR(priv->sysclk)) { - clk_put(priv->audio_clk); - return PTR_ERR(priv->sysclk); + sspa->sysclk = clk_get(NULL, "mmp-sysclk"); + if (IS_ERR(sspa->sysclk)) { + clk_put(sspa->audio_clk); + return PTR_ERR(sspa->sysclk); } - clk_enable(priv->audio_clk); - priv->dai_fmt = (unsigned int) -1; - platform_set_drvdata(pdev, priv); + clk_enable(sspa->audio_clk); + sspa->dai_fmt = (unsigned int) -1; + platform_set_drvdata(pdev, sspa); - priv->playback_dma_data.maxburst = 4; - priv->capture_dma_data.maxburst = 4; + sspa->playback_dma_data.maxburst = 4; + sspa->capture_dma_data.maxburst = 4; /* You know, these addresses are actually ignored. */ - priv->playback_dma_data.addr = SSPA_TXD; - priv->capture_dma_data.addr = SSPA_RXD; + sspa->playback_dma_data.addr = SSPA_TXD; + sspa->capture_dma_data.addr = SSPA_RXD; if (pdev->dev.of_node) { int ret; @@ -492,11 +483,11 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) static int asoc_mmp_sspa_remove(struct platform_device *pdev) { - struct sspa_priv *priv = platform_get_drvdata(pdev); + struct sspa_priv *sspa = platform_get_drvdata(pdev); - clk_disable(priv->audio_clk); - clk_put(priv->audio_clk); - clk_put(priv->sysclk); + clk_disable(sspa->audio_clk); + clk_put(sspa->audio_clk); + clk_put(sspa->sysclk); return 0; } From patchwork Mon May 11 21:01:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541713 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52BA0139F for ; Mon, 11 May 2020 21:02:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43C27208DB for ; Mon, 11 May 2020 21:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731523AbgEKVCP (ORCPT ); Mon, 11 May 2020 17:02:15 -0400 Received: from v6.sk ([167.172.42.174]:52574 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732356AbgEKVBt (ORCPT ); Mon, 11 May 2020 17:01:49 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id D4555610D2; Mon, 11 May 2020 21:01:47 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 07/11] ASoC: mmp-sspa: Prepare/unprepare the clocks Date: Mon, 11 May 2020 23:01:30 +0200 Message-Id: <20200511210134.1224532-8-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The driver enables the clocks without preparing them and disables without unpreparing afterwards. Fix that. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 7a706b1d2588..a66e594b1072 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -92,8 +92,8 @@ static int mmp_sspa_startup(struct snd_pcm_substream *substream, { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); - clk_enable(sspa->sysclk); - clk_enable(sspa->clk); + clk_prepare_enable(sspa->sysclk); + clk_prepare_enable(sspa->clk); return 0; } @@ -103,8 +103,8 @@ static void mmp_sspa_shutdown(struct snd_pcm_substream *substream, { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); - clk_disable(sspa->clk); - clk_disable(sspa->sysclk); + clk_disable_unprepare(sspa->clk); + clk_disable_unprepare(sspa->sysclk); } @@ -458,7 +458,7 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) clk_put(sspa->audio_clk); return PTR_ERR(sspa->sysclk); } - clk_enable(sspa->audio_clk); + clk_prepare_enable(sspa->audio_clk); sspa->dai_fmt = (unsigned int) -1; platform_set_drvdata(pdev, sspa); @@ -485,7 +485,7 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev) { struct sspa_priv *sspa = platform_get_drvdata(pdev); - clk_disable(sspa->audio_clk); + clk_disable_unprepare(sspa->audio_clk); clk_put(sspa->audio_clk); clk_put(sspa->sysclk); return 0; From patchwork Mon May 11 21:01:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541707 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F161139F for ; Mon, 11 May 2020 21:02:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B37C208DB for ; Mon, 11 May 2020 21:02:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731876AbgEKVCJ (ORCPT ); Mon, 11 May 2020 17:02:09 -0400 Received: from v6.sk ([167.172.42.174]:52586 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732365AbgEKVBv (ORCPT ); Mon, 11 May 2020 17:01:51 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 7BAB9610D4; Mon, 11 May 2020 21:01:49 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 08/11] ASoC: mmp-sspa: Add support for the runtime power management Date: Mon, 11 May 2020 23:01:31 +0200 Message-Id: <20200511210134.1224532-9-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Only turn on the Audio island when it's in use. This requires keeping track of control register contents instead of reloading them back from hardware, because they're lost when the power is off. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 126 ++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index a66e594b1072..9cb17c4fb0c8 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -33,8 +34,9 @@ struct sspa_priv { struct clk *clk; struct clk *audio_clk; struct clk *sysclk; - int dai_fmt; int running_cnt; + u32 sp; + u32 ctrl; }; static void mmp_sspa_write_reg(struct sspa_priv *sspa, u32 reg, u32 val) @@ -49,9 +51,9 @@ static u32 mmp_sspa_read_reg(struct sspa_priv *sspa, u32 reg) static void mmp_sspa_tx_enable(struct sspa_priv *sspa) { - unsigned int sspa_sp; + unsigned int sspa_sp = sspa->sp; - sspa_sp = mmp_sspa_read_reg(sspa, SSPA_TXSP); + sspa_sp &= ~SSPA_SP_MSL; sspa_sp |= SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); @@ -59,9 +61,9 @@ static void mmp_sspa_tx_enable(struct sspa_priv *sspa) static void mmp_sspa_tx_disable(struct sspa_priv *sspa) { - unsigned int sspa_sp; + unsigned int sspa_sp = sspa->sp; - sspa_sp = mmp_sspa_read_reg(sspa, SSPA_TXSP); + sspa_sp &= ~SSPA_SP_MSL; sspa_sp &= ~SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); @@ -69,9 +71,8 @@ static void mmp_sspa_tx_disable(struct sspa_priv *sspa) static void mmp_sspa_rx_enable(struct sspa_priv *sspa) { - unsigned int sspa_sp; + unsigned int sspa_sp = sspa->sp; - sspa_sp = mmp_sspa_read_reg(sspa, SSPA_RXSP); sspa_sp |= SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); @@ -79,9 +80,8 @@ static void mmp_sspa_rx_enable(struct sspa_priv *sspa) static void mmp_sspa_rx_disable(struct sspa_priv *sspa) { - unsigned int sspa_sp; + unsigned int sspa_sp = sspa->sp; - sspa_sp = mmp_sspa_read_reg(sspa, SSPA_RXSP); sspa_sp &= ~SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); @@ -160,35 +160,20 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id, } /* - * Set up the sspa dai format. The sspa port must be inactive - * before calling this function as the physical - * interface format is changed. + * Set up the sspa dai format. */ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai); - u32 sspa_sp, sspa_ctrl; - - /* check if we need to change anything at all */ - if (sspa->dai_fmt == fmt) - return 0; - - /* we can only change the settings if the port is not in use */ - if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) || - (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) { - dev_err(cpu_dai->dev, - "can't change hardware dai format: stream is in use\n"); - return -EINVAL; - } /* reset port settings */ - sspa_sp = SSPA_SP_WEN | SSPA_SP_S_RST | SSPA_SP_FFLUSH; - sspa_ctrl = 0; + sspa->sp = SSPA_SP_WEN | SSPA_SP_S_RST | SSPA_SP_FFLUSH; + sspa->ctrl = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: - sspa_sp |= SSPA_SP_MSL; + sspa->sp |= SSPA_SP_MSL; break; case SND_SOC_DAIFMT_CBM_CFM: break; @@ -198,7 +183,7 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai, switch (fmt & SND_SOC_DAIFMT_INV_MASK) { case SND_SOC_DAIFMT_NB_NF: - sspa_sp |= SSPA_SP_FSP; + sspa->sp |= SSPA_SP_FSP; break; default: return -EINVAL; @@ -206,39 +191,18 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai, switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: - sspa_sp |= SSPA_TXSP_FPER(63); - sspa_sp |= SSPA_SP_FWID(31); - sspa_ctrl |= SSPA_CTL_XDATDLY(1); + sspa->sp |= SSPA_TXSP_FPER(63); + sspa->sp |= SSPA_SP_FWID(31); + sspa->ctrl |= SSPA_CTL_XDATDLY(1); break; default: return -EINVAL; } - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); - mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); - - sspa_sp &= ~(SSPA_SP_S_RST | SSPA_SP_FFLUSH); - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); - mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); - - /* - * FIXME: hw issue, for the tx serial port, - * can not config the master/slave mode; - * so must clean this bit. - * The master/slave mode has been set in the - * rx port. - */ - sspa_sp &= ~SSPA_SP_MSL; - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); - - mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa_ctrl); - mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa_ctrl); - /* Since we are configuring the timings for the format by hand * we have to defer some things until hw_params() where we * know parameters like the sample size. */ - sspa->dai_fmt = fmt; return 0; } @@ -251,12 +215,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); - u32 sspa_ctrl; - - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - sspa_ctrl = mmp_sspa_read_reg(sspa, SSPA_TXCTL); - else - sspa_ctrl = mmp_sspa_read_reg(sspa, SSPA_RXCTL); + u32 sspa_ctrl = sspa->ctrl; sspa_ctrl &= ~SSPA_CTL_XFRLEN1_MASK; sspa_ctrl |= SSPA_CTL_XFRLEN1(params_channels(params) - 1); @@ -427,9 +386,55 @@ static int mmp_pcm_mmap(struct snd_soc_component *component, vma->vm_end - vma->vm_start, vma->vm_page_prot); } +static int mmp_sspa_open(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct sspa_priv *sspa = snd_soc_component_get_drvdata(component); + + pm_runtime_get_sync(component->dev); + + /* we can only change the settings if the port is not in use */ + if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) || + (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) { + dev_err(component->dev, + "can't change hardware dai format: stream is in use\n"); + return -EBUSY; + } + + mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp); + mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp); + + sspa->sp &= ~(SSPA_SP_S_RST | SSPA_SP_FFLUSH); + mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp); + mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp); + + /* + * FIXME: hw issue, for the tx serial port, + * can not config the master/slave mode; + * so must clean this bit. + * The master/slave mode has been set in the + * rx port. + */ + mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp & ~SSPA_SP_MSL); + + mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa->ctrl); + mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa->ctrl); + + return 0; +} + +static int mmp_sspa_close(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + pm_runtime_put_sync(component->dev); + return 0; +} + static const struct snd_soc_component_driver mmp_sspa_component = { .name = "mmp-sspa", .mmap = mmp_pcm_mmap, + .open = mmp_sspa_open, + .close = mmp_sspa_close, }; static int asoc_mmp_sspa_probe(struct platform_device *pdev) @@ -458,8 +463,8 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) clk_put(sspa->audio_clk); return PTR_ERR(sspa->sysclk); } + pm_runtime_enable(&pdev->dev); clk_prepare_enable(sspa->audio_clk); - sspa->dai_fmt = (unsigned int) -1; platform_set_drvdata(pdev, sspa); sspa->playback_dma_data.maxburst = 4; @@ -486,6 +491,7 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev) struct sspa_priv *sspa = platform_get_drvdata(pdev); clk_disable_unprepare(sspa->audio_clk); + pm_runtime_disable(&pdev->dev); clk_put(sspa->audio_clk); clk_put(sspa->sysclk); return 0; From patchwork Mon May 11 21:01:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541699 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 300DC15AB for ; Mon, 11 May 2020 21:01:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FF1724978 for ; Mon, 11 May 2020 21:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732346AbgEKVBy (ORCPT ); Mon, 11 May 2020 17:01:54 -0400 Received: from v6.sk ([167.172.42.174]:52638 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732371AbgEKVBw (ORCPT ); Mon, 11 May 2020 17:01:52 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 1ACDF610D5; Mon, 11 May 2020 21:01:51 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 09/11] ASoC: mmp-sspa: Set appropriate bus format for given bit width Date: Mon, 11 May 2020 23:01:32 +0200 Message-Id: <20200511210134.1224532-10-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The values set by set_dai_fmt() and hw_params() seem to be tailored only for 32-bit formats. Negotiate the correct ones in hw_params() callback instead. This was essentially copied from the OLPC kernel driver and tested to fix wrong audio output for non-32bit formats. The documentation is not available. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/mmp-sspa.c | 40 ++++++++++++++++++++++++++++------------ sound/soc/pxa/mmp-sspa.h | 2 ++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 9cb17c4fb0c8..86277471974a 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -191,8 +191,6 @@ static int mmp_sspa_set_dai_fmt(struct snd_soc_dai *cpu_dai, switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: - sspa->sp |= SSPA_TXSP_FPER(63); - sspa->sp |= SSPA_SP_FWID(31); sspa->ctrl |= SSPA_CTL_XDATDLY(1); break; default: @@ -216,30 +214,48 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); u32 sspa_ctrl = sspa->ctrl; - - sspa_ctrl &= ~SSPA_CTL_XFRLEN1_MASK; - sspa_ctrl |= SSPA_CTL_XFRLEN1(params_channels(params) - 1); - sspa_ctrl &= ~SSPA_CTL_XWDLEN1_MASK; - sspa_ctrl |= SSPA_CTL_XWDLEN1(SSPA_CTL_32_BITS); - sspa_ctrl &= ~SSPA_CTL_XSSZ1_MASK; + int bits; + int bitval; switch (params_format(params)) { case SNDRV_PCM_FORMAT_S8: - sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_8_BITS); + bits = 8; + bitval = SSPA_CTL_8_BITS; break; case SNDRV_PCM_FORMAT_S16_LE: - sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_16_BITS); + bits = 16; + bitval = SSPA_CTL_16_BITS; break; case SNDRV_PCM_FORMAT_S24_3LE: - sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_24_BITS); + bits = 24; + bitval = SSPA_CTL_24_BITS; break; case SNDRV_PCM_FORMAT_S32_LE: - sspa_ctrl |= SSPA_CTL_XSSZ1(SSPA_CTL_32_BITS); + bits = 32; + bitval = SSPA_CTL_32_BITS; break; default: return -EINVAL; } + if (params_channels(params) == 2) + sspa_ctrl |= SSPA_CTL_XPH; + + sspa_ctrl &= ~SSPA_CTL_XWDLEN1_MASK; + sspa_ctrl |= SSPA_CTL_XWDLEN1(bitval); + + sspa_ctrl &= ~SSPA_CTL_XSSZ1_MASK; + sspa_ctrl |= SSPA_CTL_XSSZ1(bitval); + + sspa_ctrl &= ~SSPA_CTL_XSSZ2_MASK; + sspa_ctrl |= SSPA_CTL_XSSZ2(bitval); + + sspa->sp &= ~SSPA_SP_FWID_MASK; + sspa->sp |= SSPA_SP_FWID(bits - 1); + + sspa->sp &= ~SSPA_TXSP_FPER_MASK; + sspa->sp |= SSPA_TXSP_FPER(bits * 2 - 1); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa_ctrl); mmp_sspa_write_reg(sspa, SSPA_TXFIFO_LL, 0x1); diff --git a/sound/soc/pxa/mmp-sspa.h b/sound/soc/pxa/mmp-sspa.h index 611063a7af68..328969b57ad1 100644 --- a/sound/soc/pxa/mmp-sspa.h +++ b/sound/soc/pxa/mmp-sspa.h @@ -63,7 +63,9 @@ #define SSPA_SP_FFLUSH (1 << 2) /* FIFO Flush */ #define SSPA_SP_S_RST (1 << 1) /* Active High Reset Signal */ #define SSPA_SP_S_EN (1 << 0) /* Serial Clock Domain Enable */ +#define SSPA_SP_FWID_MASK (0x3f << 20) #define SSPA_SP_FWID(x) ((x) << 20) /* Frame-Sync Width */ +#define SSPA_TXSP_FPER_MASK (0x3f << 4) #define SSPA_TXSP_FPER(x) ((x) << 4) /* Frame-Sync Active */ /* sspa clock sources */ From patchwork Mon May 11 21:01:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541703 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3968139F for ; Mon, 11 May 2020 21:02:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D37AC24960 for ; Mon, 11 May 2020 21:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729904AbgEKVB6 (ORCPT ); Mon, 11 May 2020 17:01:58 -0400 Received: from v6.sk ([167.172.42.174]:52586 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732376AbgEKVBy (ORCPT ); Mon, 11 May 2020 17:01:54 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 9506C610D4; Mon, 11 May 2020 21:01:52 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 10/11] dt-bindings: sound: Add Marvell MMP SSPA binding Date: Mon, 11 May 2020 23:01:33 +0200 Message-Id: <20200511210134.1224532-11-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Add binding documentation for the audio serial port interface (I2S) on Marvell MMP SoCs. Signed-off-by: Lubomir Rintel Reviewed-by: Rob Herring --- .../bindings/sound/marvell,mmp-sspa.yaml | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml diff --git a/Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml b/Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml new file mode 100644 index 000000000000..6d20a24a2ae9 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/marvell,mmp-sspa.yaml @@ -0,0 +1,122 @@ +# SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/marvell,mmp-sspa.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Marvel SSPA Digital Audio Interface Bindings + +maintainers: + - Lubomir Rintel + +properties: + $nodename: + pattern: "^audio-controller(@.*)?$" + + compatible: + const: marvell,mmp-sspa + + reg: + items: + - description: RX block + - description: TX block + + interrupts: + maxItems: 1 + + clocks: + items: + - description: Clock for the Audio block + - description: I2S bit clock + + clock-names: + items: + - const: audio + - const: bitclk + + power-domains: + maxItems: 1 + + '#sound-dai-cells': + const: 0 + + dmas: + items: + - description: TX DMA Channel + - description: RX DMA Channel + + dma-names: + items: + - const: tx + - const: rx + + port: + type: object + + properties: + endpoint: + type: object + + properties: + remote-endpoint: true + + frame-master: + type: boolean + description: SoC generates the frame clock + + bitclock-master: + type: boolean + description: SoC generates the bit clock + + dai-format: + $ref: /schemas/types.yaml#/definitions/string + description: The digital audio format + const: i2s + + required: + - remote-endpoint + + required: + - endpoint + + additionalProperties: false + +required: + - "#sound-dai-cells" + - compatible + - reg + - interrupts + - clocks + - clock-names + - dmas + - dma-names + - port + +additionalProperties: false + +examples: + - | + #include + + audio-controller@d42a0c00 { + compatible = "marvell,mmp-sspa"; + reg = <0xd42a0c00 0x30>, + <0xd42a0c80 0x30>; + interrupts = <2>; + clock-names = "audio", "bitclk"; + clocks = <&soc_clocks 127>, + <&audio_clk 1>; + #sound-dai-cells = <0>; + dmas = <&adma0 0>, <&adma0 1>; + dma-names = "tx", "rx"; + port { + endpoint { + remote-endpoint = <&rt5631_0>; + frame-master; + bitclock-master; + dai-format = "i2s"; + }; + }; + }; + +... From patchwork Mon May 11 21:01:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 11541723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFD8E159A for ; Mon, 11 May 2020 21:02:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B19DE20836 for ; Mon, 11 May 2020 21:02:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732415AbgEKVC2 (ORCPT ); Mon, 11 May 2020 17:02:28 -0400 Received: from v6.sk ([167.172.42.174]:52682 "EHLO v6.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728544AbgEKVC2 (ORCPT ); Mon, 11 May 2020 17:02:28 -0400 Received: from localhost (v6.sk [IPv6:::1]) by v6.sk (Postfix) with ESMTP id 2ED03610D6; Mon, 11 May 2020 21:01:54 +0000 (UTC) From: Lubomir Rintel To: Liam Girdwood Cc: Mark Brown , Michael Turquette , Stephen Boyd , Rob Herring , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Lubomir Rintel Subject: [PATCH 11/11] ASoC: mmp-sspa: Add Device Tree support Date: Mon, 11 May 2020 23:01:34 +0200 Message-Id: <20200511210134.1224532-12-lkundrak@v3.sk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200511210134.1224532-1-lkundrak@v3.sk> References: <20200511210134.1224532-1-lkundrak@v3.sk> MIME-Version: 1.0 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org This makes it possible to select CONFIG_SND_MMP_SOC_SSPA directly, as opposed to via CONFIG_SND_MMP_SOC, and for the driver to bind to a device tree node. That makes the driver useful on Device Tree based systems, with audio-graph-card or simple-card. The aforementioned card drivers control the master clock themselves and don't call the set_dai_sysclk() or set_dai_pll(), thus the respective handlers don't serve any purpose anymore. Instead, they return early and the hw_params() handler sets the appropriate bitclk itself. The register range is split into two -- for the RX block and for the TX block. On a MMP2 there are two pairs of them; the first one has the clock controller in the middle, while the second just has a hole: 0xd42a0c00 - 0xd42a0c30 RX1 0xd42a0c30 - 0xd42a0c40 Clocks 0xd42a0c80 - 0xd42a0cb0 TX1 0xd42a0d00 - 0xd42a0d30 RX2 0xd42a0d80 - 0xd42a0cb0 TX2 For this reason, mmp_sspa_write_reg() and mmp_sspa_read_reg() are replaced with direct calls to I/O routines. Tested on a MMP2-based OLPC XO-1.75 laptop with rt5631 coded, mmp_tdma DMA engine and MMP2 clock controller glued together with audio-graph-card. Signed-off-by: Lubomir Rintel --- sound/soc/pxa/Kconfig | 20 +++--- sound/soc/pxa/mmp-sspa.c | 139 ++++++++++++++++++++++++++------------- sound/soc/pxa/mmp-sspa.h | 28 +++----- 3 files changed, 113 insertions(+), 74 deletions(-) diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig index d4c0f580a565..7ad2fd7e653b 100644 --- a/sound/soc/pxa/Kconfig +++ b/sound/soc/pxa/Kconfig @@ -9,14 +9,8 @@ config SND_PXA2XX_SOC to select the audio interfaces to support below. config SND_MMP_SOC - bool "Soc Audio for Marvell MMP chips" - depends on ARCH_MMP + bool select MMP_SRAM - select SND_SOC_GENERIC_DMAENGINE_PCM - select SND_ARM - help - Say Y if you want to add support for codecs attached to - the MMP SSPA interface. config SND_PXA2XX_AC97 tristate @@ -39,7 +33,13 @@ config SND_PXA_SOC_SSP select SND_PXA2XX_LIB config SND_MMP_SOC_SSPA - tristate + tristate "SoC Audio via MMP SSPA ports" + depends on ARCH_MMP + select SND_SOC_GENERIC_DMAENGINE_PCM + select SND_ARM + help + Say Y if you want to add support for codecs attached to + the MMP SSPA interface. config SND_PXA2XX_SOC_CORGI tristate "SoC Audio support for Sharp Zaurus SL-C7x0" @@ -232,8 +232,8 @@ config SND_PXA2XX_SOC_IMOTE2 config SND_MMP_SOC_BROWNSTONE tristate "SoC Audio support for Marvell Brownstone" - depends on SND_MMP_SOC && MACH_BROWNSTONE && I2C - select SND_MMP_SOC_SSPA + depends on SND_MMP_SOC_SSPA && MACH_BROWNSTONE && I2C + select SND_MMP_SOC select MFD_WM8994 select SND_SOC_WM8994 help diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index 86277471974a..b0accd49c89d 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -28,27 +28,20 @@ * SSPA audio private data */ struct sspa_priv { - void __iomem *mmio_base; + void __iomem *tx_base; + void __iomem *rx_base; + struct snd_dmaengine_dai_dma_data playback_dma_data; struct snd_dmaengine_dai_dma_data capture_dma_data; struct clk *clk; struct clk *audio_clk; struct clk *sysclk; + int running_cnt; u32 sp; u32 ctrl; }; -static void mmp_sspa_write_reg(struct sspa_priv *sspa, u32 reg, u32 val) -{ - __raw_writel(val, sspa->mmio_base + reg); -} - -static u32 mmp_sspa_read_reg(struct sspa_priv *sspa, u32 reg) -{ - return __raw_readl(sspa->mmio_base + reg); -} - static void mmp_sspa_tx_enable(struct sspa_priv *sspa) { unsigned int sspa_sp = sspa->sp; @@ -56,7 +49,7 @@ static void mmp_sspa_tx_enable(struct sspa_priv *sspa) sspa_sp &= ~SSPA_SP_MSL; sspa_sp |= SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); + __raw_writel(sspa_sp, sspa->tx_base + SSPA_SP); } static void mmp_sspa_tx_disable(struct sspa_priv *sspa) @@ -66,7 +59,7 @@ static void mmp_sspa_tx_disable(struct sspa_priv *sspa) sspa_sp &= ~SSPA_SP_MSL; sspa_sp &= ~SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa_sp); + __raw_writel(sspa_sp, sspa->tx_base + SSPA_SP); } static void mmp_sspa_rx_enable(struct sspa_priv *sspa) @@ -75,7 +68,7 @@ static void mmp_sspa_rx_enable(struct sspa_priv *sspa) sspa_sp |= SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; - mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); + __raw_writel(sspa_sp, sspa->rx_base + SSPA_SP); } static void mmp_sspa_rx_disable(struct sspa_priv *sspa) @@ -84,7 +77,7 @@ static void mmp_sspa_rx_disable(struct sspa_priv *sspa) sspa_sp &= ~SSPA_SP_S_EN; sspa_sp |= SSPA_SP_WEN; - mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa_sp); + __raw_writel(sspa_sp, sspa->rx_base + SSPA_SP); } static int mmp_sspa_startup(struct snd_pcm_substream *substream, @@ -105,7 +98,6 @@ static void mmp_sspa_shutdown(struct snd_pcm_substream *substream, clk_disable_unprepare(sspa->clk); clk_disable_unprepare(sspa->sysclk); - } /* @@ -115,8 +107,12 @@ static int mmp_sspa_set_dai_sysclk(struct snd_soc_dai *cpu_dai, int clk_id, unsigned int freq, int dir) { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai); + struct device *dev = cpu_dai->component->dev; int ret = 0; + if (dev->of_node) + return -ENOTSUPP; + switch (clk_id) { case MMP_SSPA_CLK_AUDIO: ret = clk_set_rate(sspa->audio_clk, freq); @@ -139,8 +135,12 @@ static int mmp_sspa_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id, unsigned int freq_out) { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(cpu_dai); + struct device *dev = cpu_dai->component->dev; int ret = 0; + if (dev->of_node) + return -ENOTSUPP; + switch (pll_id) { case MMP_SYSCLK: ret = clk_set_rate(sspa->sysclk, freq_out); @@ -213,6 +213,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct sspa_priv *sspa = snd_soc_dai_get_drvdata(dai); + struct device *dev = dai->component->dev; u32 sspa_ctrl = sspa->ctrl; int bits; int bitval; @@ -238,7 +239,7 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - if (params_channels(params) == 2) + if (dev->of_node || params_channels(params) == 2) sspa_ctrl |= SSPA_CTL_XPH; sspa_ctrl &= ~SSPA_CTL_XWDLEN1_MASK; @@ -256,12 +257,17 @@ static int mmp_sspa_hw_params(struct snd_pcm_substream *substream, sspa->sp &= ~SSPA_TXSP_FPER_MASK; sspa->sp |= SSPA_TXSP_FPER(bits * 2 - 1); + if (dev->of_node) { + clk_set_rate(sspa->clk, params_rate(params) * + params_channels(params) * bits); + } + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa_ctrl); - mmp_sspa_write_reg(sspa, SSPA_TXFIFO_LL, 0x1); + __raw_writel(sspa_ctrl, sspa->tx_base + SSPA_CTL); + __raw_writel(0x1, sspa->tx_base + SSPA_FIFO_UL); } else { - mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa_ctrl); - mmp_sspa_write_reg(sspa, SSPA_RXFIFO_UL, 0x0); + __raw_writel(sspa_ctrl, sspa->rx_base + SSPA_CTL); + __raw_writel(0x0, sspa->rx_base + SSPA_FIFO_UL); } return 0; @@ -410,19 +416,19 @@ static int mmp_sspa_open(struct snd_soc_component *component, pm_runtime_get_sync(component->dev); /* we can only change the settings if the port is not in use */ - if ((mmp_sspa_read_reg(sspa, SSPA_TXSP) & SSPA_SP_S_EN) || - (mmp_sspa_read_reg(sspa, SSPA_RXSP) & SSPA_SP_S_EN)) { + if ((__raw_readl(sspa->tx_base + SSPA_SP) & SSPA_SP_S_EN) || + (__raw_readl(sspa->rx_base + SSPA_SP) & SSPA_SP_S_EN)) { dev_err(component->dev, "can't change hardware dai format: stream is in use\n"); return -EBUSY; } - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp); - mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp); + __raw_writel(sspa->sp, sspa->tx_base + SSPA_SP); + __raw_writel(sspa->sp, sspa->rx_base + SSPA_SP); sspa->sp &= ~(SSPA_SP_S_RST | SSPA_SP_FFLUSH); - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp); - mmp_sspa_write_reg(sspa, SSPA_RXSP, sspa->sp); + __raw_writel(sspa->sp, sspa->tx_base + SSPA_SP); + __raw_writel(sspa->sp, sspa->rx_base + SSPA_SP); /* * FIXME: hw issue, for the tx serial port, @@ -431,10 +437,10 @@ static int mmp_sspa_open(struct snd_soc_component *component, * The master/slave mode has been set in the * rx port. */ - mmp_sspa_write_reg(sspa, SSPA_TXSP, sspa->sp & ~SSPA_SP_MSL); + __raw_writel(sspa->sp & ~SSPA_SP_MSL, sspa->tx_base + SSPA_SP); - mmp_sspa_write_reg(sspa, SSPA_TXCTL, sspa->ctrl); - mmp_sspa_write_reg(sspa, SSPA_RXCTL, sspa->ctrl); + __raw_writel(sspa->ctrl, sspa->tx_base + SSPA_CTL); + __raw_writel(sspa->ctrl, sspa->rx_base + SSPA_CTL); return 0; } @@ -462,22 +468,51 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) if (!sspa) return -ENOMEM; - sspa->mmio_base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(sspa->mmio_base)) - return PTR_ERR(sspa->mmio_base); + if (pdev->dev.of_node) { + sspa->rx_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(sspa->rx_base)) + return PTR_ERR(sspa->rx_base); - sspa->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(sspa->clk)) - return PTR_ERR(sspa->clk); + sspa->tx_base = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(sspa->tx_base)) + return PTR_ERR(sspa->tx_base); - sspa->audio_clk = clk_get(NULL, "mmp-audio"); - if (IS_ERR(sspa->audio_clk)) - return PTR_ERR(sspa->audio_clk); + sspa->clk = devm_clk_get(&pdev->dev, "bitclk"); + if (IS_ERR(sspa->clk)) + return PTR_ERR(sspa->clk); - sspa->sysclk = clk_get(NULL, "mmp-sysclk"); - if (IS_ERR(sspa->sysclk)) { - clk_put(sspa->audio_clk); - return PTR_ERR(sspa->sysclk); + sspa->audio_clk = devm_clk_get(&pdev->dev, "audio"); + if (IS_ERR(sspa->audio_clk)) + return PTR_ERR(sspa->audio_clk); + } else { + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (res == NULL) + return -ENODEV; + + sspa->rx_base = devm_ioremap(&pdev->dev, res->start, 0x30); + if (IS_ERR(sspa->rx_base)) + return PTR_ERR(sspa->rx_base); + + sspa->tx_base = devm_ioremap(&pdev->dev, + res->start + 0x80, 0x30); + if (IS_ERR(sspa->tx_base)) + return PTR_ERR(sspa->tx_base); + + sspa->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(sspa->clk)) + return PTR_ERR(sspa->clk); + + sspa->audio_clk = clk_get(NULL, "mmp-audio"); + if (IS_ERR(sspa->audio_clk)) + return PTR_ERR(sspa->audio_clk); + + sspa->sysclk = clk_get(NULL, "mmp-sysclk"); + if (IS_ERR(sspa->sysclk)) { + clk_put(sspa->audio_clk); + return PTR_ERR(sspa->sysclk); + } } pm_runtime_enable(&pdev->dev); clk_prepare_enable(sspa->audio_clk); @@ -486,8 +521,8 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) sspa->playback_dma_data.maxburst = 4; sspa->capture_dma_data.maxburst = 4; /* You know, these addresses are actually ignored. */ - sspa->playback_dma_data.addr = SSPA_TXD; - sspa->capture_dma_data.addr = SSPA_RXD; + sspa->capture_dma_data.addr = SSPA_D; + sspa->playback_dma_data.addr = 0x80 + SSPA_D; if (pdev->dev.of_node) { int ret; @@ -508,14 +543,28 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev) clk_disable_unprepare(sspa->audio_clk); pm_runtime_disable(&pdev->dev); + + if (pdev->dev.of_node) + return 0; + clk_put(sspa->audio_clk); clk_put(sspa->sysclk); return 0; } +#ifdef CONFIG_OF +static const struct of_device_id mmp_sspa_of_match[] = { + { .compatible = "marvell,mmp-sspa" }, + {}, +}; + +MODULE_DEVICE_TABLE(of, mmp_sspa_of_match); +#endif + static struct platform_driver asoc_mmp_sspa_driver = { .driver = { .name = "mmp-sspa-dai", + .of_match_table = of_match_ptr(mmp_sspa_of_match), }, .probe = asoc_mmp_sspa_probe, .remove = asoc_mmp_sspa_remove, diff --git a/sound/soc/pxa/mmp-sspa.h b/sound/soc/pxa/mmp-sspa.h index 328969b57ad1..938ef2f667e3 100644 --- a/sound/soc/pxa/mmp-sspa.h +++ b/sound/soc/pxa/mmp-sspa.h @@ -10,25 +10,15 @@ /* * SSPA Registers */ -#define SSPA_RXD (0x00) -#define SSPA_RXID (0x04) -#define SSPA_RXCTL (0x08) -#define SSPA_RXSP (0x0c) -#define SSPA_RXFIFO_UL (0x10) -#define SSPA_RXINT_MASK (0x14) -#define SSPA_RXC (0x18) -#define SSPA_RXFIFO_NOFS (0x1c) -#define SSPA_RXFIFO_SIZE (0x20) - -#define SSPA_TXD (0x80) -#define SSPA_TXID (0x84) -#define SSPA_TXCTL (0x88) -#define SSPA_TXSP (0x8c) -#define SSPA_TXFIFO_LL (0x90) -#define SSPA_TXINT_MASK (0x94) -#define SSPA_TXC (0x98) -#define SSPA_TXFIFO_NOFS (0x9c) -#define SSPA_TXFIFO_SIZE (0xa0) +#define SSPA_D (0x00) +#define SSPA_ID (0x04) +#define SSPA_CTL (0x08) +#define SSPA_SP (0x0c) +#define SSPA_FIFO_UL (0x10) +#define SSPA_INT_MASK (0x14) +#define SSPA_C (0x18) +#define SSPA_FIFO_NOFS (0x1c) +#define SSPA_FIFO_SIZE (0x20) /* SSPA Control Register */ #define SSPA_CTL_XPH (1 << 31) /* Read Phase */