From patchwork Wed Dec 23 19:01:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 7913871 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5D8A4BEEE5 for ; Wed, 23 Dec 2015 19:05:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A64F205F9 for ; Wed, 23 Dec 2015 19:05:04 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id DCAAB20532 for ; Wed, 23 Dec 2015 19:05:02 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 58A73266825; Wed, 23 Dec 2015 20:05:01 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id BDA862665F8; Wed, 23 Dec 2015 20:01:49 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id C836E2665E4; Wed, 23 Dec 2015 20:01:46 +0100 (CET) Received: from mail-qg0-f43.google.com (mail-qg0-f43.google.com [209.85.192.43]) by alsa0.perex.cz (Postfix) with ESMTP id B2946266583 for ; Wed, 23 Dec 2015 20:01:29 +0100 (CET) Received: by mail-qg0-f43.google.com with SMTP id k90so160034320qge.0 for ; Wed, 23 Dec 2015 11:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X8xj89DilzqebfJr95/Xhyq2cPXCzYH8rAmoo/otilc=; b=ak8YDoX8EyiHKinbSqE90JdOz1FpkBUeH9c/GivSpmMR5q/JAXuCCvnZl0iOEUqBwf x9KVnfz/p8hT48KuLvXfJAe0AUKrCa7i1QDqyXF7LUbaX7sxaoKHAxKlFK+bhrodIryw xHyehlhkA7Pn/H94K38o60h4YEIXRoNekqjswQd4qUfjaHXB+QMA7CjqhFr3VGbzis/9 MuaTF10TwC1SpMF+/EWbpFhGqopsx8RcaRN0ltrfHJ/+9ESj+dBkdXNDkbv0rLSSija7 yXC5apXPCSWItxj0kv9XaXM2stgI8LhBvPDEhrvBUNDzZNQ/S94tb3tC1Qa6nNAExpFU 60PA== X-Received: by 10.140.105.36 with SMTP id b33mr42697245qgf.94.1450897289192; Wed, 23 Dec 2015 11:01:29 -0800 (PST) Received: from cm.localdomain (static-74-96-105-49.washdc.fios.verizon.net. [74.96.105.49]) by smtp.gmail.com with ESMTPSA id p19sm18566797qgp.9.2015.12.23.11.01.28 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 23 Dec 2015 11:01:28 -0800 (PST) From: Alex Deucher X-Google-Original-From: Alex Deucher To: airlied@gmail.com, dri-devel@lists.freedesktop.org, broonie@kernel.org, alsa-devel@alsa-project.org, maruthi.bayyavarapu@amd.com, rajeevkumar.linux@gmail.com Date: Wed, 23 Dec 2015 14:01:15 -0500 Message-Id: <1450897275-17152-8-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1450897275-17152-1-git-send-email-alexander.deucher@amd.com> References: <1450897275-17152-1-git-send-email-alexander.deucher@amd.com> Cc: tiwai@suse.de, Alex Deucher , Maruthi Srinivas Bayyavarapu , lgirdwood@gmail.com Subject: [alsa-devel] [PATCH 8/8] ASoC: AMD: Manage ACP 2.x SRAM banks power X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Maruthi Srinivas Bayyavarapu ACP SRAM banks gets turned on when ACP is powered on. Not all banks are used for playback/capture. So, power on required banks during audio device open and power off during audio device close. Signed-off-by: Maruthi Bayyavarapu Reviewed-by: Alex Deucher Signed-off-by: Alex Deucher --- v2: Changes: 1. Clean up sram bank handling to clarify operation 2. Add timeout to loop sound/soc/amd/acp-pcm-dma.c | 90 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c index a45e910..7af0b04 100644 --- a/sound/soc/amd/acp-pcm-dma.c +++ b/sound/soc/amd/acp-pcm-dma.c @@ -375,9 +375,57 @@ static int acp_dma_stop(void __iomem *acp_mmio, u8 ch_num) return 0; } +static void acp_set_sram_bank_state(void __iomem *acp_mmio, u16 bank, + bool power_on) +{ + u32 val, req_reg, sts_reg, sts_reg_mask; + u32 loops = 1000; + + if (bank < 32) { + req_reg = mmACP_MEM_SHUT_DOWN_REQ_LO; + sts_reg = mmACP_MEM_SHUT_DOWN_STS_LO; + sts_reg_mask = 0xFFFFFFFF; + + } else { + bank -= 32; + req_reg = mmACP_MEM_SHUT_DOWN_REQ_HI; + sts_reg = mmACP_MEM_SHUT_DOWN_STS_HI; + sts_reg_mask = 0x0000FFFF; + } + + val = acp_reg_read(acp_mmio, req_reg); + if (val & (1 << bank)) { + /* bank is in off state */ + if (power_on == true) + /* request to on */ + val &= ~(1 << bank); + else + /* request to off */ + return; + } else { + /* bank is in on state */ + if (power_on == false) + /* request to off */ + val |= 1 << bank; + else + /* request to on */ + return; + } + acp_reg_write(val, acp_mmio, req_reg); + + while (acp_reg_read(acp_mmio, sts_reg) != sts_reg_mask) { + if (!loops--) { + pr_err("ACP SRAM bank %d state change failed\n", bank); + break; + } + cpu_relax(); + } +} + /* Initialize and bring ACP hardware to default state. */ static int acp_init(void __iomem *acp_mmio) { + u16 bank; u32 val, count, sram_pte_offset; /* Assert Soft reset of ACP */ @@ -445,6 +493,16 @@ static int acp_init(void __iomem *acp_mmio) acp_reg_write(ACP_EXTERNAL_INTR_CNTL__DMAIOCMask_MASK, acp_mmio, mmACP_EXTERNAL_INTR_CNTL); + /* When ACP_TILE_P1 is turned on, all SRAM banks get turned on. + * Now, turn off all of them. This can't be done in 'poweron' of + * ACP pm domain, as this requires ACP to be initialized. + */ + for (bank = 1; bank < 32; bank++) + acp_set_sram_bank_state(acp_mmio, bank, false); + + for (bank = 32; bank < 48; bank++) + acp_set_sram_bank_state(acp_mmio, bank, false); + /* Designware I2S driver requries proper capabilities * from mmACP_I2SMICSP_COMP_PARAM_1 register. The register * reports playback and capture capabilities though the @@ -569,6 +627,7 @@ static irqreturn_t dma_irq_handler(int irq, void *arg) static int acp_dma_open(struct snd_pcm_substream *substream) { + u16 bank; int ret = 0; struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *prtd = substream->private_data; @@ -602,10 +661,17 @@ static int acp_dma_open(struct snd_pcm_substream *substream) if (!intr_data->play_stream && !intr_data->capture_stream) acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { intr_data->play_stream = substream; - else + for (bank = 1; bank <= 4; bank++) + acp_set_sram_bank_state(intr_data->acp_mmio, bank, + true); + } else { intr_data->capture_stream = substream; + for (bank = 5; bank <= 8; bank++) + acp_set_sram_bank_state(intr_data->acp_mmio, bank, + true); + } return 0; } @@ -637,6 +703,7 @@ static int acp_dma_hw_params(struct snd_pcm_substream *substream, pg = virt_to_page(substream->dma_buffer.area); if (pg != NULL) { + acp_set_sram_bank_state(rtd->acp_mmio, 0, true); /* Save for runtime private data */ rtd->pg = pg; rtd->order = get_order(size); @@ -812,6 +879,7 @@ static int acp_dma_new(struct snd_soc_pcm_runtime *rtd) static int acp_dma_close(struct snd_pcm_substream *substream) { + u16 bank; struct snd_pcm_runtime *runtime = substream->runtime; struct audio_substream_data *rtd = runtime->private_data; struct snd_soc_pcm_runtime *prtd = substream->private_data; @@ -819,10 +887,17 @@ static int acp_dma_close(struct snd_pcm_substream *substream) kfree(rtd); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { adata->play_stream = NULL; - else + for (bank = 1; bank <= 4; bank++) + acp_set_sram_bank_state(adata->acp_mmio, bank, + false); + } else { adata->capture_stream = NULL; + for (bank = 5; bank <= 8; bank++) + acp_set_sram_bank_state(adata->acp_mmio, bank, + false); + } /* Disable ACP irq, when the current stream is being closed and * another stream is also not active. @@ -916,6 +991,7 @@ static int acp_audio_remove(struct platform_device *pdev) static int acp_pcm_resume(struct device *dev) { + u16 bank; struct snd_pcm_substream *stream; struct snd_pcm_runtime *rtd; struct audio_substream_data *sdata; @@ -927,6 +1003,9 @@ static int acp_pcm_resume(struct device *dev) rtd = stream ? stream->runtime : NULL; if (rtd != NULL) { /* Resume playback stream from a suspended state */ + for (bank = 1; bank <= 4; bank++) + acp_set_sram_bank_state(adata->acp_mmio, bank, + true); sdata = rtd->private_data; config_acp_dma(adata->acp_mmio, sdata); } @@ -935,6 +1014,9 @@ static int acp_pcm_resume(struct device *dev) rtd = stream ? stream->runtime : NULL; if (rtd != NULL) { /* Resume capture stream from a suspended state */ + for (bank = 5; bank <= 8; bank++) + acp_set_sram_bank_state(adata->acp_mmio, bank, + true); sdata = rtd->private_data; config_acp_dma(adata->acp_mmio, sdata); }