All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deucher <alexdeucher@gmail.com>
To: broonie@kernel.org, airlied@gmail.com,
	dri-devel@lists.freedesktop.org, alsa-devel@alsa-project.org,
	maruthi.bayyavarapu@amd.com, rajeevkumar.linux@gmail.com
Cc: Alex Deucher <alexander.deucher@amd.com>,
	Maruthi Srinivas Bayyavarapu <Maruthi.Bayyavarapu@amd.com>,
	lgirdwood@gmail.com, perex@perex.cz
Subject: [PATCH 13/13] ASoC: AMD: Manage ACP 2.x SRAM banks power
Date: Fri,  4 Dec 2015 18:40:40 -0500	[thread overview]
Message-ID: <1449272440-8735-13-git-send-email-alexander.deucher@amd.com> (raw)
In-Reply-To: <1449272440-8735-1-git-send-email-alexander.deucher@amd.com>

From: Maruthi Srinivas Bayyavarapu <Maruthi.Bayyavarapu@amd.com>

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 <maruthi.bayyavarapu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 sound/soc/amd/acp-pcm-dma.c | 25 +++++++++++---
 sound/soc/amd/acp.c         | 81 ++++++++++++++++++++++++++++++++++++++++++++-
 sound/soc/amd/acp.h         |  3 +-
 3 files changed, 103 insertions(+), 6 deletions(-)

diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c
index 07a26e5..daba64a 100644
--- a/sound/soc/amd/acp-pcm-dma.c
+++ b/sound/soc/amd/acp-pcm-dma.c
@@ -133,6 +133,7 @@ static irqreturn_t dma_irq_handler(int irq, void *arg)
 
 static int acp_dma_open(struct snd_pcm_substream *substream)
 {
+	u32 bank;
 	int ret = 0;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_soc_pcm_runtime *prtd = substream->private_data;
@@ -166,10 +167,17 @@ static int acp_dma_open(struct snd_pcm_substream *substream)
 	if (!intr_data->play_stream && !intr_data->capture_stream)
 		acp_enable_external_interrupts(adata->acp_mmio, 1);
 
-	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_turnonoff_lower_sram_bank(intr_data->acp_mmio, bank,
+							true);
+	} else {
 		intr_data->capture_stream = substream;
+		for (bank = 5; bank <= 8; bank++)
+			acp_turnonoff_lower_sram_bank(intr_data->acp_mmio, bank,
+					true);
+	}
 
 	return 0;
 }
@@ -201,6 +209,7 @@ static int acp_dma_hw_params(struct snd_pcm_substream *substream,
 	pg = virt_to_page(substream->dma_buffer.area);
 
 	if (pg != NULL) {
+		acp_turnonoff_lower_sram_bank(rtd->acp_mmio, 0, true);
 		/* Save for runtime private data */
 		rtd->pg = pg;
 		rtd->order = get_order(size);
@@ -364,6 +373,7 @@ static int acp_dma_new(struct snd_soc_pcm_runtime *rtd)
 
 static int acp_dma_close(struct snd_pcm_substream *substream)
 {
+	u32 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;
@@ -371,10 +381,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_turnonoff_lower_sram_bank(adata->acp_mmio, bank,
+							false);
+	} else {
 		adata->capture_stream = NULL;
+		for (bank = 5; bank <= 8; bank++)
+			acp_turnonoff_lower_sram_bank(adata->acp_mmio, bank,
+							false);
+	}
 
 	/* Disable ACP irq, when the current stream is being closed and
 	 * another stream is also not active.
diff --git a/sound/soc/amd/acp.c b/sound/soc/amd/acp.c
index 0d59be4..ed3f83f 100644
--- a/sound/soc/amd/acp.c
+++ b/sound/soc/amd/acp.c
@@ -462,10 +462,79 @@ int acp_dma_stop(void __iomem *acp_mmio, u8 ch_num)
 	return 0;
 }
 
+void acp_turnonoff_lower_sram_bank(void __iomem *acp_mmio, u16 bank,
+					bool turnon)
+{
+	u32 val;
+
+	val = acp_reg_read(acp_mmio, mmACP_MEM_SHUT_DOWN_REQ_LO);
+	if (val & (1 << bank)) {
+		/* bank is in off state */
+		if (turnon == true)
+			/* request to on */
+			val &= ~(1 << bank);
+		else
+			/* request to off */
+			return;
+	} else {
+		/* bank is in on state */
+		if (turnon == false)
+			/* request to off */
+			val |= 1 << bank;
+		else
+			/* request to on */
+			return;
+	}
+	 acp_reg_write(val, acp_mmio,
+				   mmACP_MEM_SHUT_DOWN_REQ_LO);
+	/* If ACP_MEM_SHUT_DOWN_STS_LO is 0xFFFFFFFF, then
+	 * shutdown sequence is complete.
+	 */
+	 while (acp_reg_read(acp_mmio,
+				      mmACP_MEM_SHUT_DOWN_STS_LO)
+				      != 0xFFFFFFFF)
+		cpu_relax();
+}
+
+void acp_turnonoff_higher_sram_bank(void __iomem *acp_mmio, u16 bank,
+					bool turnon)
+{
+	u32 val;
+
+	bank -= 32;
+	val = acp_reg_read(acp_mmio, mmACP_MEM_SHUT_DOWN_REQ_HI);
+	if (val & (1 << bank)) {
+		/* bank is in off state */
+		if (turnon == true)
+			/* request to on */
+			val &= ~(1 << bank);
+		else
+			/* request to off */
+			return;
+	} else {
+		/* bank is in on state */
+		if (turnon == false)
+			/* request to off */
+			val |= 1 << bank;
+		else
+			/* request to on */
+			return;
+	}
+	 acp_reg_write(val, acp_mmio,
+				   mmACP_MEM_SHUT_DOWN_REQ_HI);
+	/* If ACP_MEM_SHUT_DOWN_STS_LO is 0xFFFFFFFF, then
+	 * shutdown sequence is complete.
+	 */
+	 while (acp_reg_read(acp_mmio,
+				      mmACP_MEM_SHUT_DOWN_STS_HI)
+				      != 0x0000FFFF)
+		cpu_relax();
+}
+
 /* Initialize and bring ACP hardware to default state. */
 int acp_init(void __iomem *acp_mmio)
 {
-	u32 val;
+	u32 val, bank;
 	u32 count;
 
 	/* Assert Soft reset of ACP */
@@ -527,6 +596,16 @@ 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_turnonoff_lower_sram_bank(acp_mmio, bank, false);
+
+	for (bank = 32; bank < 48; bank++)
+		acp_turnonoff_higher_sram_bank(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
diff --git a/sound/soc/amd/acp.h b/sound/soc/amd/acp.h
index 53c30ea..a2f3762 100644
--- a/sound/soc/amd/acp.h
+++ b/sound/soc/amd/acp.h
@@ -135,5 +135,6 @@ extern void acp_enable_external_interrupts(void __iomem *acp_mmio,
 extern u32 acp_get_intr_flag(void __iomem *acp_mmio);
 extern u16 get_dscr_idx(void __iomem *acp_mmio, int direction);
 extern void acp_ext_stat_clear_dmaioc(void __iomem *acp_mmio, u8 ch_num);
-
+extern void acp_turnonoff_lower_sram_bank(void __iomem *acp_mmio, u16 bank,
+					bool turnon);
 #endif /*__ACP_HW_H */
-- 
1.8.3.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2015-12-04 23:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-04 23:40 [PATCH 00/13] Add ASoC support for AMD APUs [v5] Alex Deucher
2015-12-04 23:40 ` [PATCH 01/13] drm/amdgpu/cgs: add an interface to access PCI resources Alex Deucher
2015-12-04 23:40 ` [PATCH 02/13] drm/amdgpu: add irq domain support Alex Deucher
2015-12-04 23:40 ` [PATCH 03/13] ASoC: dwc: add runtime suspend/resume functionality Alex Deucher
2015-12-07 19:54   ` Applied "ASoC: dwc: add runtime suspend/resume functionality" to the asoc tree Mark Brown
2015-12-04 23:40 ` [PATCH 04/13] ASoC: dwc: add quirk for different register offset Alex Deucher
2015-12-07 19:54   ` Applied "ASoC: dwc: add quirk for different register offset" to the asoc tree Mark Brown
2015-12-04 23:40 ` [PATCH 05/13] ASoC: dwc: reconfigure dwc in 'resume' from 'suspend' Alex Deucher
2015-12-07 19:54   ` Applied "ASoC: dwc: reconfigure dwc in 'resume' from 'suspend'" to the asoc tree Mark Brown
2015-12-04 23:40 ` [PATCH 06/13] PM / Domains: export symbols to add/remove devices from genpd Alex Deucher
2015-12-18 11:25   ` Mark Brown
2015-12-04 23:40 ` [PATCH 07/13] drm/amd: add ACP driver support Alex Deucher
2015-12-04 23:40 ` [PATCH 08/13] drm/amd: add pm domain for ACP IP sub blocks Alex Deucher
2015-12-04 23:40 ` [PATCH 10/13] ASoC: AMD: add ACP 2.x IP DMA abstraction layer Alex Deucher
2015-12-18 11:22   ` Mark Brown
2015-12-04 23:40 ` [PATCH 11/13] ASoC: AMD: add AMD ASoC ACP 2.x DMA driver Alex Deucher
2015-12-18 12:04   ` Mark Brown
2015-12-04 23:40 ` [PATCH 12/13] ASoC: AMD: add pm ops Alex Deucher
2015-12-04 23:40 ` Alex Deucher [this message]
2015-12-18 12:08   ` [PATCH 13/13] ASoC: AMD: Manage ACP 2.x SRAM banks power Mark Brown
2015-12-18 12:09 ` [PATCH 00/13] Add ASoC support for AMD APUs [v5] Mark Brown
2015-12-21 19:08 ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1449272440-8735-13-git-send-email-alexander.deucher@amd.com \
    --to=alexdeucher@gmail.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lgirdwood@gmail.com \
    --cc=maruthi.bayyavarapu@amd.com \
    --cc=perex@perex.cz \
    --cc=rajeevkumar.linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.