From ba9c0dc80d5bd365c468e60981239de160d6ac4c Mon Sep 17 00:00:00 2001
From: Daniel Baluta <daniel.baluta@nxp.com>
Date: Wed, 3 Oct 2018 16:45:57 +0300
Subject: [PATCH] MLK-18497-13: ASoC: fsl: dsp: Skip SDRAM section update if fw
 is already loaded

If the DSP firmware binary is already loaded it is wrong to update
SDRAM located sections because we will overwrite and data stored there.

This makes suspend/resume work.

Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
(cherry picked from commit 48ea0209f27808ee922f44b27bdcd332f0e3b4f5)
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
Signed-off-by: Srikanth Krishnakar <Srikanth_Krishnakar@mentor.com>
---
 sound/soc/fsl/fsl_dsp.c       | 12 ++++++++----
 sound/soc/fsl/fsl_dsp_proxy.h |  1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/sound/soc/fsl/fsl_dsp.c b/sound/soc/fsl/fsl_dsp.c
index 5080d11ca30336..85989799fe312e 100644
--- a/sound/soc/fsl/fsl_dsp.c
+++ b/sound/soc/fsl/fsl_dsp.c
@@ -369,6 +369,7 @@ int fsl_dsp_open_func(struct fsl_dsp *dsp_priv, struct xf_client *client)
 	atomic_set(&client->vm_use, 0);
 
 	client->global = (void *)dsp_priv;
+	dsp_priv->proxy.is_loaded = 0;
 
 	pm_runtime_get_sync(dev);
 
@@ -688,10 +689,12 @@ static void dsp_load_firmware(const struct firmware *fw, void *context)
 				(!strcmp(&strtab[shdr->sh_name], ".data"))   ||
 				(!strcmp(&strtab[shdr->sh_name], ".bss"))
 			) {
-				memcpy_dsp((void *)(dsp_priv->sdram_vir_addr
-				  + (sh_addr - dsp_priv->sdram_phys_addr)),
-				  (const void *)image,
-				  shdr->sh_size);
+				if (!dsp_priv->proxy.is_loaded) {
+					memcpy_dsp((void *)(dsp_priv->sdram_vir_addr
+				  	+ (sh_addr - dsp_priv->sdram_phys_addr)),
+				  	(const void *)image,
+				  	shdr->sh_size);
+				}
 			} else {
 				memcpy_dsp((void *)(dsp_priv->regs +
 						(sh_addr - dsp_priv->paddr)),
@@ -704,6 +707,7 @@ static void dsp_load_firmware(const struct firmware *fw, void *context)
 	/* start the core */
 	sc_pm_cpu_start(dsp_priv->dsp_ipcHandle,
 					SC_R_DSP, true, dsp_priv->iram);
+	dsp_priv->proxy.is_loaded = 1;
 }
 
 /* Initialization of the MU code. */
diff --git a/sound/soc/fsl/fsl_dsp_proxy.h b/sound/soc/fsl/fsl_dsp_proxy.h
index 3f2caeefaa5102..440cafb9bd16e6 100644
--- a/sound/soc/fsl/fsl_dsp_proxy.h
+++ b/sound/soc/fsl/fsl_dsp_proxy.h
@@ -299,6 +299,7 @@ struct xf_proxy {
 
 	struct completion	cmd_complete;
 	int			is_ready;
+	int			is_loaded;
 
 	/* ...internal lock */
 	spinlock_t              lock;
-- 
GitLab