Skip to contentSkip to conversation

ASoC: Intel: catpt: Code cleanup and renames

PATCH In review Cezary Rojewski 2 participants 10 messages Jul 29 – Jul 31

Subsystems (3)
lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

cover ASoC: Intel: catpt: Code cleanup and renames

Direct follow up to the cleanup from June [1] and fixes from May [2]. Patches 4/8 and 5/8 is what I actually started with, several years ago when doing first attempts in addressing the long-standing problem [3]. With these, it is easy for a developer to move between the driver and the firmware repository. A clear example of why naming is imporant.

Patches 2-8 carry no functional impact.
Patch 1/8 slightly alters the suspend procedure as explained in its commit message. From practical perspective though, 1/8 too has no real impact on the functional flow.

Changes found here reduce the code complexity slightly and rename a bunch of functions and variables.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/linux-sound/[email protected]/
[3]: https://lore.kernel.org/linux-sound/[email protected]/

Cezary Rojewski (8):
ASoC: Intel: catpt: Wrap the store firmware-context procedure
ASoC: Intel: catpt: Drop redundant else-if
ASoC: Intel: catpt: Drop redundant signature argument
ASoC: Intel: catpt: Rename module header struct
ASoC: Intel: catpt: Rename firmware loading functions
ASoC: Intel: catpt: Streamline wording of offset variables
ASoC: Intel: catpt: Streamline runtime-variables naming
ASoC: Intel: catpt: Streamline control-variables naming

 sound/soc/intel/catpt/core.h   |   4 +-
 sound/soc/intel/catpt/device.c |  33 +--------
 sound/soc/intel/catpt/loader.c | 131 ++++++++++++++++++++-------------
 sound/soc/intel/catpt/pcm.c    |  45 ++++++-----
 4 files changed, 105 insertions(+), 108 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

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

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.

---
 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(-)
sound/soc/intel/catpt/core.h +1 -3
index 3881164422b8..f68807c454c9 100644
@@ -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>
sound/soc/intel/catpt/device.c +3 -30
index b176aebea9d5..e36eea8b5408 100644
@@ -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);
 }
 
sound/soc/intel/catpt/loader.c +36 -3
index c577f2e17ddf..880f62896997 100644
@@ -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)
 {
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/8 ASoC: Intel: catpt: Drop redundant else-if

In reply to Cezary Rojewski

If the preceding if-statement ends with return,
there is no need for else-if.

---
 sound/soc/intel/catpt/loader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/intel/catpt/loader.c +2 -2
index 880f62896997..79742dceef53 100644
@@ -652,10 +652,10 @@ int catpt_boot_firmware(struct catpt_dev *cdev, bool restore)
 	if (!ret) {
 		dev_err(cdev->dev, "firmware ready timeout\n");
 		return -ETIMEDOUT;
+	}
 	/* Wake up does not mean FW is ready, an exception could occur. */
-	} else if (!cdev->ipc.ready) {
+	if (!cdev->ipc.ready)
 		return -EREMOTEIO;
-	}
 
 	/* update sram pg & clock once done booting */
 	catpt_dsp_update_srampge(cdev, &cdev->dram, cdev->spec->dram_mask);
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/8 ASoC: Intel: catpt: Drop redundant signature argument

In reply to Cezary Rojewski

Initial design assumed the mechanism could be reused for loading external modules with signatures differing from the Intel's constant. No users with such characteristics ever appeared rendering the 'signature' argument useless.

---
 sound/soc/intel/catpt/loader.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
sound/soc/intel/catpt/loader.c +3 -5
index 79742dceef53..775781489ded 100644
@@ -569,8 +569,7 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
 }
 
 static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
-			    const char *name, const char *signature,
-			    bool restore)
+			    const char *name, bool restore)
 {
 	struct catpt_fw_hdr *fw;
 	struct firmware *img;
@@ -583,7 +582,7 @@ static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
 		return ret;
 
 	fw = (struct catpt_fw_hdr *)img->data;
-	if (strncmp(fw->signature, signature, FW_SIGNATURE_SIZE)) {
+	if (strncmp(fw->signature, FW_SIGNATURE, FW_SIGNATURE_SIZE)) {
 		dev_err(cdev->dev, "firmware signature mismatch\n");
 		ret = -EINVAL;
 		goto release_fw;
@@ -617,8 +616,7 @@ static int catpt_load_images(struct catpt_dev *cdev, bool restore)
 	if (IS_ERR(chan))
 		return PTR_ERR(chan);
 
-	ret = catpt_load_image(cdev, chan, cdev->spec->fw_name,
-			       FW_SIGNATURE, restore);
+	ret = catpt_load_image(cdev, chan, cdev->spec->fw_name, restore);
 	if (ret)
 		goto release_dma_chan;
 
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 4/8 ASoC: Intel: catpt: Rename module header struct

In reply to Cezary Rojewski

Goal is to match the name of its equivalent on the firmware side.

---
 sound/soc/intel/catpt/loader.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/intel/catpt/loader.c +8 -8
index 775781489ded..06c8b043e292 100644
@@ -26,7 +26,7 @@ struct catpt_fw_hdr {
 	u32 reserved[4];
 } __packed;
 
-struct catpt_fw_mod_hdr {
+struct catpt_fw_module_hdr {
 	char signature[FW_SIGNATURE_SIZE];
 	u32 mod_size;
 	u32 blocks;
@@ -357,7 +357,7 @@ static int catpt_load_block(struct catpt_dev *cdev,
 
 static int catpt_restore_basefw(struct catpt_dev *cdev,
 				struct dma_chan *chan, dma_addr_t paddr,
-				struct catpt_fw_mod_hdr *basefw)
+				struct catpt_fw_module_hdr *basefw)
 {
 	u32 offset = sizeof(*basefw);
 	int ret, i;
@@ -400,7 +400,7 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 
 static int catpt_restore_module(struct catpt_dev *cdev,
 				struct dma_chan *chan, dma_addr_t paddr,
-				struct catpt_fw_mod_hdr *mod)
+				struct catpt_fw_module_hdr *mod)
 {
 	u32 offset = sizeof(*mod);
 	int i;
@@ -441,7 +441,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
 
 static int catpt_load_module(struct catpt_dev *cdev,
 			     struct dma_chan *chan, dma_addr_t paddr,
-			     struct catpt_fw_mod_hdr *mod)
+			     struct catpt_fw_module_hdr *mod)
 {
 	struct catpt_module_type *type;
 	u32 offset = sizeof(*mod);
@@ -497,10 +497,10 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
 			     fw, sizeof(*fw), false);
 
 	for (i = 0; i < fw->modules; i++) {
-		struct catpt_fw_mod_hdr *mod;
+		struct catpt_fw_module_hdr *mod;
 		int ret;
 
-		mod = (struct catpt_fw_mod_hdr *)((u8 *)fw + offset);
+		mod = (struct catpt_fw_module_hdr *)((u8 *)fw + offset);
 		if (strncmp(fw->signature, mod->signature,
 			    FW_SIGNATURE_SIZE)) {
 			dev_err(cdev->dev, "module signature mismatch\n");
@@ -543,10 +543,10 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
 			     fw, sizeof(*fw), false);
 
 	for (i = 0; i < fw->modules; i++) {
-		struct catpt_fw_mod_hdr *mod;
+		struct catpt_fw_module_hdr *mod;
 		int ret;
 
-		mod = (struct catpt_fw_mod_hdr *)((u8 *)fw + offset);
+		mod = (struct catpt_fw_module_hdr *)((u8 *)fw + offset);
 		if (strncmp(fw->signature, mod->signature,
 			    FW_SIGNATURE_SIZE)) {
 			dev_err(cdev->dev, "module signature mismatch\n");
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH 5/8 ASoC: Intel: catpt: Rename firmware loading functions

In reply to Cezary Rojewski

To make the firmware loading proceduce easier to understand, especially around restoring DRAM context, rename the following:

catpt_load_images -> catpt_request_dma_load_firmware
catpt_load_image -> catpt_request_load_firmware
catpt_restore_fwimage -> catpt_restore_dram_rodata
catpt_restore_memdumps -> catpt_restore_dram_data
catpt_store_memdumps -> catpt_store_dram_data

For the exact same reason, update a number of comments related to the subject.

---
 sound/soc/intel/catpt/loader.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
sound/soc/intel/catpt/loader.c +16 -16
index 06c8b043e292..274af8fb8828 100644
@@ -138,7 +138,7 @@ static int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *ch
 	return 0;
 }
 
-static int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
+static int catpt_store_dram_data(struct catpt_dev *cdev, struct dma_chan *chan)
 {
 	int i;
 
@@ -184,7 +184,7 @@ int catpt_store_firmware_context(struct catpt_dev *cdev)
 	if (ret)
 		goto exit;
 
-	ret = catpt_store_memdumps(cdev, chan);
+	ret = catpt_store_dram_data(cdev, chan);
 	if (ret) {
 		dev_err(cdev->dev, "store memdumps failed: %d\n", ret);
 		goto exit;
@@ -232,7 +232,7 @@ catpt_restore_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
 	return 0;
 }
 
-static int catpt_restore_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
+static int catpt_restore_dram_data(struct catpt_dev *cdev, struct dma_chan *chan)
 {
 	int i;
 
@@ -267,9 +267,9 @@ static int catpt_restore_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
 	return 0;
 }
 
-static int catpt_restore_fwimage(struct catpt_dev *cdev,
-				 struct dma_chan *chan, dma_addr_t paddr,
-				 struct catpt_fw_block_hdr *blk)
+static int catpt_restore_dram_rodata(struct catpt_dev *cdev,
+				     struct dma_chan *chan, dma_addr_t paddr,
+				     struct catpt_fw_block_hdr *blk)
 {
 	struct resource r1 = {};
 	int i;
@@ -365,7 +365,7 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 	print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
 			     basefw, sizeof(*basefw), false);
 
-	/* restore basefw image */
+	/* Restore IRAM and .rodata for DRAM based on the firmware image. */
 	for (i = 0; i < basefw->blocks; i++) {
 		struct catpt_fw_block_hdr *blk;
 
@@ -377,8 +377,8 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 					       blk, false);
 			break;
 		default:
-			ret = catpt_restore_fwimage(cdev, chan, paddr + offset,
-						    blk);
+			ret = catpt_restore_dram_rodata(cdev, chan, paddr + offset,
+							blk);
 			break;
 		}
 
@@ -390,8 +390,8 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 		offset += sizeof(*blk) + blk->size;
 	}
 
-	/* then proceed with memory dumps */
-	ret = catpt_restore_memdumps(cdev, chan);
+	/* Then proceed with DRAM .data saved before D3. */
+	ret = catpt_restore_dram_data(cdev, chan);
 	if (ret)
 		dev_err(cdev->dev, "restore memdumps failed: %d\n", ret);
 
@@ -568,8 +568,8 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
 	return 0;
 }
 
-static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
-			    const char *name, bool restore)
+static int catpt_request_load_firmware(struct catpt_dev *cdev, struct dma_chan *chan,
+				       const char *name, bool restore)
 {
 	struct catpt_fw_hdr *fw;
 	struct firmware *img;
@@ -607,7 +607,7 @@ static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
 	return ret;
 }
 
-static int catpt_load_images(struct catpt_dev *cdev, bool restore)
+static int catpt_request_dma_load_firmware(struct catpt_dev *cdev, bool restore)
 {
 	struct dma_chan *chan;
 	int ret;
@@ -616,7 +616,7 @@ static int catpt_load_images(struct catpt_dev *cdev, bool restore)
 	if (IS_ERR(chan))
 		return PTR_ERR(chan);
 
-	ret = catpt_load_image(cdev, chan, cdev->spec->fw_name, restore);
+	ret = catpt_request_load_firmware(cdev, chan, cdev->spec->fw_name, restore);
 	if (ret)
 		goto release_dma_chan;
 
@@ -636,7 +636,7 @@ int catpt_boot_firmware(struct catpt_dev *cdev, bool restore)
 
 	catpt_dsp_stall(cdev, true);
 
-	ret = catpt_load_images(cdev, restore);
+	ret = catpt_request_dma_load_firmware(cdev, restore);
 	if (ret) {
 		dev_err(cdev->dev, "load binaries failed: %d\n", ret);
 		return ret;
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH 6/8 ASoC: Intel: catpt: Streamline wording of offset variables

In reply to Cezary Rojewski

Two words represent is currently: 'offset' and 'off'. Be cohesive and use one instead.

---
 sound/soc/intel/catpt/loader.c | 48 ++++++++++++++++------------------
 1 file changed, 22 insertions(+), 26 deletions(-)
sound/soc/intel/catpt/loader.c +22 -26
index 274af8fb8828..e7ba9e1e60ae 100644
@@ -359,7 +359,7 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 				struct dma_chan *chan, dma_addr_t paddr,
 				struct catpt_fw_module_hdr *basefw)
 {
-	u32 offset = sizeof(*basefw);
+	u32 off = sizeof(*basefw);
 	int ret, i;
 
 	print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@@ -369,16 +369,14 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 	for (i = 0; i < basefw->blocks; i++) {
 		struct catpt_fw_block_hdr *blk;
 
-		blk = (struct catpt_fw_block_hdr *)((u8 *)basefw + offset);
+		blk = (struct catpt_fw_block_hdr *)((u8 *)basefw + off);
 
 		switch (blk->ram_type) {
 		case CATPT_RAM_TYPE_IRAM:
-			ret = catpt_load_block(cdev, chan, paddr + offset,
-					       blk, false);
+			ret = catpt_load_block(cdev, chan, paddr + off, blk, false);
 			break;
 		default:
-			ret = catpt_restore_dram_rodata(cdev, chan, paddr + offset,
-							blk);
+			ret = catpt_restore_dram_rodata(cdev, chan, paddr + off, blk);
 			break;
 		}
 
@@ -387,7 +385,7 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
 			return ret;
 		}
 
-		offset += sizeof(*blk) + blk->size;
+		off += sizeof(*blk) + blk->size;
 	}
 
 	/* Then proceed with DRAM .data saved before D3. */
@@ -402,7 +400,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
 				struct dma_chan *chan, dma_addr_t paddr,
 				struct catpt_fw_module_hdr *mod)
 {
-	u32 offset = sizeof(*mod);
+	u32 off = sizeof(*mod);
 	int i;
 
 	print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@@ -412,7 +410,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
 		struct catpt_fw_block_hdr *blk;
 		int ret;
 
-		blk = (struct catpt_fw_block_hdr *)((u8 *)mod + offset);
+		blk = (struct catpt_fw_block_hdr *)((u8 *)mod + off);
 
 		switch (blk->ram_type) {
 		case CATPT_RAM_TYPE_INSTANCE:
@@ -423,7 +421,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
 					ALIGN(blk->size, 4));
 			break;
 		default:
-			ret = catpt_load_block(cdev, chan, paddr + offset,
+			ret = catpt_load_block(cdev, chan, paddr + off,
 					       blk, false);
 			break;
 		}
@@ -433,7 +431,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
 			return ret;
 		}
 
-		offset += sizeof(*blk) + blk->size;
+		off += sizeof(*blk) + blk->size;
 	}
 
 	return 0;
@@ -444,7 +442,7 @@ static int catpt_load_module(struct catpt_dev *cdev,
 			     struct catpt_fw_module_hdr *mod)
 {
 	struct catpt_module_type *type;
-	u32 offset = sizeof(*mod);
+	u32 off = sizeof(*mod);
 	int i;
 
 	print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@@ -456,9 +454,9 @@ static int catpt_load_module(struct catpt_dev *cdev,
 		struct catpt_fw_block_hdr *blk;
 		int ret;
 
-		blk = (struct catpt_fw_block_hdr *)((u8 *)mod + offset);
+		blk = (struct catpt_fw_block_hdr *)((u8 *)mod + off);
 
-		ret = catpt_load_block(cdev, chan, paddr + offset, blk, true);
+		ret = catpt_load_block(cdev, chan, paddr + off, blk, true);
 		if (ret) {
 			dev_err(cdev->dev, "load block failed: %d\n", ret);
 			return ret;
@@ -473,7 +471,7 @@ static int catpt_load_module(struct catpt_dev *cdev,
 			type->state_size = blk->size;
 		}
 
-		offset += sizeof(*blk) + blk->size;
+		off += sizeof(*blk) + blk->size;
 	}
 
 	/* init module type static info */
@@ -490,7 +488,7 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
 				  struct dma_chan *chan, dma_addr_t paddr,
 				  struct catpt_fw_hdr *fw)
 {
-	u32 offset = sizeof(*fw);
+	u32 off = sizeof(*fw);
 	int i;
 
 	print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@@ -500,7 +498,7 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
 		struct catpt_fw_module_hdr *mod;
 		int ret;
 
-		mod = (struct catpt_fw_module_hdr *)((u8 *)fw + offset);
+		mod = (struct catpt_fw_module_hdr *)((u8 *)fw + off);
 		if (strncmp(fw->signature, mod->signature,
 			    FW_SIGNATURE_SIZE)) {
 			dev_err(cdev->dev, "module signature mismatch\n");
@@ -512,12 +510,10 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
 
 		switch (mod->module_id) {
 		case CATPT_MODID_BASE_FW:
-			ret = catpt_restore_basefw(cdev, chan, paddr + offset,
-						   mod);
+			ret = catpt_restore_basefw(cdev, chan, paddr + off, mod);
 			break;
 		default:
-			ret = catpt_restore_module(cdev, chan, paddr + offset,
-						   mod);
+			ret = catpt_restore_module(cdev, chan, paddr + off, mod);
 			break;
 		}
 
@@ -526,7 +522,7 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
 			return ret;
 		}
 
-		offset += sizeof(*mod) + mod->mod_size;
+		off += sizeof(*mod) + mod->mod_size;
 	}
 
 	return 0;
@@ -536,7 +532,7 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
 			       struct dma_chan *chan, dma_addr_t paddr,
 			       struct catpt_fw_hdr *fw)
 {
-	u32 offset = sizeof(*fw);
+	u32 off = sizeof(*fw);
 	int i;
 
 	print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@@ -546,7 +542,7 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
 		struct catpt_fw_module_hdr *mod;
 		int ret;
 
-		mod = (struct catpt_fw_module_hdr *)((u8 *)fw + offset);
+		mod = (struct catpt_fw_module_hdr *)((u8 *)fw + off);
 		if (strncmp(fw->signature, mod->signature,
 			    FW_SIGNATURE_SIZE)) {
 			dev_err(cdev->dev, "module signature mismatch\n");
@@ -556,13 +552,13 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
 		if (mod->module_id > CATPT_MODID_LAST)
 			return -EINVAL;
 
-		ret = catpt_load_module(cdev, chan, paddr + offset, mod);
+		ret = catpt_load_module(cdev, chan, paddr + off, mod);
 		if (ret) {
 			dev_err(cdev->dev, "load module failed: %d\n", ret);
 			return ret;
 		}
 
-		offset += sizeof(*mod) + mod->mod_size;
+		off += sizeof(*mod) + mod->mod_size;
 	}
 
 	return 0;
Signature · 1 line
2.34.1
author maintainer
#7 lore raw

PATCH 7/8 ASoC: Intel: catpt: Streamline runtime-variables naming

In reply to Cezary Rojewski

Mimic naming pattern commonly found in the ASoC code:

- 'rtd' in case of struct snd_soc_pcm_runtime
- 'runtime' in case of struct snd_pcm_runtime

---
 sound/soc/intel/catpt/pcm.c | 42 ++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
sound/soc/intel/catpt/pcm.c +21 -21
index 8fb0efb67eb1..12a5226cf12c 100644
@@ -75,8 +75,8 @@ static struct catpt_stream_template *catpt_topology[] = {
 static struct catpt_stream_template *
 catpt_get_stream_template(struct snd_pcm_substream *substream)
 {
-	struct snd_soc_pcm_runtime *rtm = snd_soc_substream_to_rtd(substream);
-	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtm, 0);
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
 	enum catpt_stream_type type;
 
 	type = cpu_dai->driver->id;
@@ -159,11 +159,11 @@ static void catpt_stream_read_position(struct catpt_dev *cdev,
 static void catpt_arrange_page_table(struct snd_pcm_substream *substream,
 				     struct snd_dma_buffer *pgtbl)
 {
-	struct snd_pcm_runtime *rtm = substream->runtime;
+	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_dma_buffer *databuf = snd_pcm_get_dma_buf(substream);
 	int i, pages;
 
-	pages = snd_sgbuf_aligned_pages(rtm->dma_bytes);
+	pages = snd_sgbuf_aligned_pages(runtime->dma_bytes);
 
 	for (i = 0; i < pages; i++) {
 		u32 pfn, offset;
@@ -386,7 +386,7 @@ static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
 			       struct snd_pcm_hw_params *params,
 			       struct snd_soc_dai *dai)
 {
-	struct snd_pcm_runtime *rtm = substream->runtime;
+	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_dma_buffer *dmab;
 	struct catpt_stream_runtime *stream;
 	struct catpt_audio_format afmt;
@@ -412,8 +412,8 @@ static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
 
 	memset(&rinfo, 0, sizeof(rinfo));
 	rinfo.page_table_addr = stream->pgtbl.addr;
-	rinfo.num_pages = DIV_ROUND_UP(rtm->dma_bytes, PAGE_SIZE);
-	rinfo.size = rtm->dma_bytes;
+	rinfo.num_pages = DIV_ROUND_UP(runtime->dma_bytes, PAGE_SIZE);
+	rinfo.size = runtime->dma_bytes;
 	rinfo.offset = 0;
 	rinfo.ring_first_page_pfn = PFN_DOWN(snd_sgbuf_get_addr(dmab, 0));
 
@@ -544,11 +544,11 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
 				  struct catpt_notify_position *pos)
 {
 	struct snd_pcm_substream *substream = stream->substream;
-	struct snd_pcm_runtime *r = substream->runtime;
+	struct snd_pcm_runtime *runtime = substream->runtime;
 	snd_pcm_uframes_t dsppos, newpos;
 	int ret;
 
-	dsppos = bytes_to_frames(r, pos->stream_position);
+	dsppos = bytes_to_frames(runtime, pos->stream_position);
 
 	if (!stream->prepared)
 		goto exit;
@@ -556,8 +556,8 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
 	if (stream->template->type != CATPT_STRM_TYPE_RENDER)
 		goto exit;
 
-	if (dsppos >= r->buffer_size / 2)
-		newpos = r->buffer_size / 2;
+	if (dsppos >= runtime->buffer_size / 2)
+		newpos = runtime->buffer_size / 2;
 	else
 		newpos = 0;
 	/*
@@ -565,7 +565,7 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
 	 * (buffer half consumed) update wp to allow stream progression.
 	 */
 	ret = catpt_ipc_set_write_pos(cdev, stream->info.stream_hw_id,
-				      frames_to_bytes(r, newpos),
+				      frames_to_bytes(runtime, newpos),
 				      false, false);
 	if (ret) {
 		dev_err(cdev->dev, "update position for stream %d failed: %d\n",
@@ -600,11 +600,11 @@ static const struct snd_pcm_hardware catpt_pcm_hardware = {
 };
 
 static int catpt_component_pcm_new(struct snd_soc_component *component,
-				   struct snd_soc_pcm_runtime *rtm)
+				   struct snd_soc_pcm_runtime *rtd)
 {
 	struct catpt_dev *cdev = dev_get_drvdata(component->dev);
 
-	snd_pcm_set_managed_buffer_all(rtm->pcm, SNDRV_DMA_TYPE_DEV_SG,
+	snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV_SG,
 				       cdev->dev,
 				       catpt_pcm_hardware.buffer_bytes_max,
 				       catpt_pcm_hardware.buffer_bytes_max);
@@ -615,9 +615,9 @@ static int catpt_component_pcm_new(struct snd_soc_component *component,
 static int catpt_component_open(struct snd_soc_component *component,
 				struct snd_pcm_substream *substream)
 {
-	struct snd_soc_pcm_runtime *rtm = snd_soc_substream_to_rtd(substream);
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
 
-	if (!rtm->dai_link->no_pcm)
+	if (!rtd->dai_link->no_pcm)
 		snd_soc_set_runtime_hwparams(substream, &catpt_pcm_hardware);
 	return 0;
 }
@@ -626,13 +626,13 @@ static snd_pcm_uframes_t
 catpt_component_pointer(struct snd_soc_component *component,
 			struct snd_pcm_substream *substream)
 {
-	struct snd_soc_pcm_runtime *rtm = snd_soc_substream_to_rtd(substream);
-	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtm, 0);
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
 	struct catpt_stream_runtime *stream;
 	struct catpt_dev *cdev = dev_get_drvdata(component->dev);
 	u32 pos;
 
-	if (rtm->dai_link->no_pcm)
+	if (rtd->dai_link->no_pcm)
 		return 0;
 
 	stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
@@ -650,10 +650,10 @@ static const struct snd_soc_dai_ops catpt_fe_dai_ops = {
 	.trigger = catpt_dai_trigger,
 };
 
-static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm,
+static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtd,
 			     struct snd_soc_dai *dai)
 {
-	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtm, 0);
+	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
 	struct catpt_ssp_device_format devfmt;
 	struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
 	int ret;
Signature · 1 line
2.34.1
author maintainer
#8 lore raw

PATCH 8/8 ASoC: Intel: catpt: Streamline control-variables naming

In reply to Cezary Rojewski

Two naming patterns exist currently in the code:
'kcontrol' and 'kctl'. Pick one and stick with it.

---
 sound/soc/intel/catpt/pcm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/catpt/pcm.c +1 -2
index 12a5226cf12c..f23c580ba051 100644
@@ -871,8 +871,7 @@ static int catpt_set_dspvol(struct catpt_dev *cdev, u8 stream_id, long *ctlvol)
 	return CATPT_IPC_RET(ret);
 }
 
-static int catpt_volume_info(struct snd_kcontrol *kcontrol,
-			     struct snd_ctl_elem_info *uinfo)
+static int catpt_volume_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
 {
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 	uinfo->count = CATPT_CHANNELS_MAX;
Signature · 1 line
2.34.1
maintainer
#9 lore raw
In reply to Cezary Rojewski
Quoted 9 lines · Cezary Rojewski

ASoC: Intel: catpt: Code cleanup and renames

Direct follow up to the cleanup from June [1] and fixes from May [2]. Patches 4/8 and 5/8 is what I actually started with, several years ago when doing first attempts in addressing the long-standing problem [3]. With these, it is easy for a developer to move between the driver and the firmware repository. A clear example of why naming is imporant.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.3

Thanks!

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

      https://git.kernel.org/broonie/sound/c/abc7daad426e
[2/8] ASoC: Intel: catpt: Drop redundant else-if
      https://git.kernel.org/broonie/sound/c/05d3ba625802
[3/8] ASoC: Intel: catpt: Drop redundant signature argument
      https://git.kernel.org/broonie/sound/c/f6c65bf0acc9
[4/8] ASoC: Intel: catpt: Rename module header struct
      https://git.kernel.org/broonie/sound/c/71d1229972e2
[5/8] ASoC: Intel: catpt: Rename firmware loading functions
      https://git.kernel.org/broonie/sound/c/e692a538a421
[6/8] ASoC: Intel: catpt: Streamline wording of offset variables
      https://git.kernel.org/broonie/sound/c/ae6540c4909a
[7/8] ASoC: Intel: catpt: Streamline runtime-variables naming
      https://git.kernel.org/broonie/sound/c/a0acf55be734
[8/8] ASoC: Intel: catpt: Streamline control-variables naming
      https://git.kernel.org/broonie/sound/c/4075b9d256ef

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark