[PATCH 1/8] ASoC: Intel: catpt: Wrap the store firmware-context procedure

Cezary Rojewski <[email protected]>
Newsgroups gmane.linux.sound
Message-ID <[email protected]>
All store/restore firmware operations are located in the loader.c file.
All except the "store firmware context" procedure which is manually
called during the runtime suspend, device.c file.

Adding a wrapper alters functional flow slightly - DMA channel is
requested after the DXSTATE IPC rather than before it but this has no
real impact on the procedure.

At the same time, such approach limits number of symbols exposed in the
core.h file and improves code cohesiveness: all catpt_dma_xxx()
definitions in dsp.c, all their usages in loader.c.

Signed-off-by: Cezary Rojewski <[email protected]>
---
 sound/soc/intel/catpt/core.h   |  4 +---
 sound/soc/intel/catpt/device.c | 33 +++-------------------------
 sound/soc/intel/catpt/loader.c | 39 +++++++++++++++++++++++++++++++---
 3 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/sound/soc/intel/catpt/core.h b/sound/soc/intel/catpt/core.h
index 3881164422b8..f68807c454c9 100644
--- a/sound/soc/intel/catpt/core.h
+++ b/sound/soc/intel/catpt/core.h
@@ -139,9 +139,7 @@ int catpt_dsp_send_msg(struct catpt_dev *cdev, struct catpt_ipc_msg request,
 
 int catpt_first_boot_firmware(struct catpt_dev *cdev);
 int catpt_boot_firmware(struct catpt_dev *cdev, bool restore);
-int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan);
-int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan);
-int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan);
+int catpt_store_firmware_context(struct catpt_dev *cdev);
 int catpt_coredump(struct catpt_dev *cdev);
 
 #include <sound/memalloc.h>
diff --git a/sound/soc/intel/catpt/device.c b/sound/soc/intel/catpt/device.c
index b176aebea9d5..e36eea8b5408 100644
--- a/sound/soc/intel/catpt/device.c
+++ b/sound/soc/intel/catpt/device.c
@@ -28,44 +28,17 @@
 static int catpt_do_suspend(struct device *dev)
 {
 	struct catpt_dev *cdev = dev_get_drvdata(dev);
-	struct dma_chan *chan;
 	int ret;
 
-	chan = catpt_dma_request_config_chan(cdev);
-	if (IS_ERR(chan))
-		return PTR_ERR(chan);
-
 	memset(&cdev->dx_ctx, 0, sizeof(cdev->dx_ctx));
 	ret = catpt_ipc_enter_dxstate(cdev, CATPT_DX_STATE_D3, &cdev->dx_ctx);
-	if (ret) {
-		ret = CATPT_IPC_RET(ret);
-		goto release_dma_chan;
-	}
-
-	ret = catpt_dsp_stall(cdev, true);
-	if (ret)
-		goto release_dma_chan;
-
-	ret = catpt_store_memdumps(cdev, chan);
-	if (ret) {
-		dev_err(cdev->dev, "store memdumps failed: %d\n", ret);
-		goto release_dma_chan;
-	}
-
-	ret = catpt_store_module_states(cdev, chan);
-	if (ret) {
-		dev_err(cdev->dev, "store module states failed: %d\n", ret);
-		goto release_dma_chan;
-	}
-
-	ret = catpt_store_streams_context(cdev, chan);
 	if (ret)
-		dev_err(cdev->dev, "store streams ctx failed: %d\n", ret);
+		return CATPT_IPC_RET(ret);
 
-release_dma_chan:
-	dma_release_channel(chan);
+	ret = catpt_store_firmware_context(cdev);
 	if (ret)
 		return ret;
+
 	return catpt_dsp_power_down(cdev);
 }
 
diff --git a/sound/soc/intel/catpt/loader.c b/sound/soc/intel/catpt/loader.c
index c577f2e17ddf..880f62896997 100644
--- a/sound/soc/intel/catpt/loader.c
+++ b/sound/soc/intel/catpt/loader.c
@@ -81,7 +81,7 @@ catpt_request_region(struct resource *root, resource_size_t size)
 	return __request_region(root, addr, size, NULL, 0);
 }
 
-int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
+static int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
 {
 	struct catpt_stream_runtime *stream;
 
@@ -108,7 +108,7 @@ int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
 	return 0;
 }
 
-int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan)
+static int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan)
 {
 	int i;
 
@@ -138,7 +138,7 @@ int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan)
 	return 0;
 }
 
-int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
+static int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
 {
 	int i;
 
@@ -171,6 +171,39 @@ int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
 	return 0;
 }
 
+int catpt_store_firmware_context(struct catpt_dev *cdev)
+{
+	struct dma_chan *chan;
+	int ret;
+
+	chan = catpt_dma_request_config_chan(cdev);
+	if (IS_ERR(chan))
+		return PTR_ERR(chan);
+
+	ret = catpt_dsp_stall(cdev, true);
+	if (ret)
+		goto exit;
+
+	ret = catpt_store_memdumps(cdev, chan);
+	if (ret) {
+		dev_err(cdev->dev, "store memdumps failed: %d\n", ret);
+		goto exit;
+	}
+
+	ret = catpt_store_module_states(cdev, chan);
+	if (ret) {
+		dev_err(cdev->dev, "store module states failed: %d\n", ret);
+		goto exit;
+	}
+
+	ret = catpt_store_streams_context(cdev, chan);
+	if (ret)
+		dev_err(cdev->dev, "store streams ctx failed: %d\n", ret);
+exit:
+	dma_release_channel(chan);
+	return ret;
+}
+
 static int
 catpt_restore_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
 {
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.