Skip to contentSkip to conversation

ASoC: SDCA: Add missing header includes

PATCH In review Charles Keepax 3 participants 9 messages Dec 20, 2024 – Jan 6, 2025

Subsystems (3)
lore
Share & tools
lore

Charles Keepax

author maintainer
#0 lore raw

PATCH 1/5 ASoC: SDCA: Add missing header includes

Several of the SDCA files don't include all the headers they use locally. These are included by the point of use through other headers, so it is not currently causing any issues. However, files should directly include things they directly use, so add the missing header includes.

---
 include/sound/sdca.h            | 3 +++
 include/sound/sdca_function.h   | 2 ++
 sound/soc/sdca/sdca_device.c    | 2 ++
 sound/soc/sdca/sdca_functions.c | 4 ++++
 4 files changed, 11 insertions(+)
include/sound/sdca.h +3 -0
index 7e138229e8f3..3eea1dfec16c 100644
@@ -9,6 +9,9 @@
 #ifndef __SDCA_H__
 #define __SDCA_H__
 
+#include <linux/types.h>
+#include <linux/kconfig.h>
+
 struct sdw_slave;
 
 #define SDCA_MAX_FUNCTION_COUNT 8
include/sound/sdca_function.h +2 -0
index a01eec86b9a6..6943df0851a9 100644
@@ -9,6 +9,8 @@
 #ifndef __SDCA_FUNCTION_H__
 #define __SDCA_FUNCTION_H__
 
+#include <linux/bits.h>
+
 /*
  * SDCA Function Types from SDCA specification v1.0a Section 5.1.2
  * all Function types not described are reserved
sound/soc/sdca/sdca_device.c +2 -0
index 80d663777eb5..b6399b773986 100644
@@ -7,6 +7,8 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/module.h>
+#include <linux/property.h>
 #include <linux/soundwire/sdw.h>
 #include <sound/sdca.h>
 #include <sound/sdca_function.h>
sound/soc/sdca/sdca_functions.c +4 -0
index 652865329968..1808e5e7dee2 100644
@@ -7,7 +7,11 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/property.h>
 #include <linux/soundwire/sdw.h>
+#include <linux/types.h>
 #include <sound/sdca.h>
 #include <sound/sdca_function.h>
 
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 2/5 ASoC: SDCA: Clean up error messages

All the error messages in the SDCA code manually print the function in the output, update these to use dev_fmt instead. Whilst making the changes tweak a couple of the error messages to make them a little shorter.

---
 sound/soc/sdca/sdca_functions.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
sound/soc/sdca/sdca_functions.c +10 -12
index 1808e5e7dee2..46aa874bb0aa 100644
@@ -6,6 +6,8 @@
  * https://www.mipi.org/mipi-sdca-v1-0-download
  */
 
+#define dev_fmt(fmt) "%s: " fmt, __func__
+
 #include <linux/acpi.h>
 #include <linux/device.h>
 #include <linux/module.h>
@@ -49,8 +51,8 @@ static int patch_sdca_function_type(struct device *dev,
 		function_type_patch = SDCA_FUNCTION_TYPE_HID;
 		break;
 	default:
-		dev_warn(dev, "%s: SDCA version %#x unsupported function type %d, skipped\n",
-			 __func__, interface_revision, *function_type);
+		dev_warn(dev, "SDCA version %#x invalid function type %d\n",
+			 interface_revision, *function_type);
 		return -EINVAL;
 	}
 
@@ -77,17 +79,14 @@ static int patch_sdca_function_type(struct device *dev,
 	case SDCA_FUNCTION_TYPE_SPEAKER_MIC:
 	case SDCA_FUNCTION_TYPE_RJ:
 	case SDCA_FUNCTION_TYPE_IMP_DEF:
-		dev_warn(dev, "%s: found unsupported SDCA function type %d, skipped\n",
-			 __func__, *function_type);
+		dev_warn(dev, "unsupported SDCA function type %d\n", *function_type);
 		return -EINVAL;
 	default:
-		dev_err(dev, "%s: found invalid SDCA function type %d, skipped\n",
-			__func__, *function_type);
+		dev_err(dev, "invalid SDCA function type %d\n", *function_type);
 		return -EINVAL;
 	}
 
-	dev_info(dev, "%s: found SDCA function %s (type %d)\n",
-		 __func__, *function_name, *function_type);
+	dev_info(dev, "SDCA function %s (type %d)\n", *function_name, *function_type);
 
 	return 0;
 }
@@ -105,7 +104,7 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
 	int ret;
 
 	if (sdca_data->num_functions >= SDCA_MAX_FUNCTION_COUNT) {
-		dev_err(dev, "%s: maximum number of functions exceeded\n", __func__);
+		dev_err(dev, "maximum number of functions exceeded\n");
 		return -EINVAL;
 	}
 
@@ -119,7 +118,7 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
 		return ret;
 
 	if (!addr) {
-		dev_err(dev, "%s: no addr\n", __func__);
+		dev_err(dev, "no addr\n");
 		return -ENODEV;
 	}
 
@@ -144,8 +143,7 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
 	fwnode_handle_put(control5);
 
 	if (ret < 0) {
-		dev_err(dev, "%s: the function type can only be determined from ACPI information\n",
-			__func__);
+		dev_err(dev, "function type only supported as DisCo constant\n");
 		return ret;
 	}
 
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 3/5 ASoC: SDCA: Add bounds check for function address

In reply to Charles Keepax

SDCA only supports 3-bits for the function address, but the ACPI value is 64-bits. Update the code that parses this to do a bounds check and error out on invalid addresses. Currently, an invalid address would truncate to the bottom 3-bits when used and thus use a likely incorrect address. With the bounds check, it is also now safe to shrink the size of the adr member of sdca_function_desc to a u8 and rearrange the struct members to pack better with the new size of adr.

---
 include/sound/sdca.h            | 4 ++--
 sound/soc/sdca/sdca_functions.c | 9 ++-------
 2 files changed, 4 insertions(+), 9 deletions(-)
include/sound/sdca.h +2 -2
index 3eea1dfec16c..973252d0adac 100644
@@ -23,9 +23,9 @@ struct sdw_slave;
  * @name: human-readable string
  */
 struct sdca_function_desc {
-	u64 adr;
-	u32 type;
 	const char *name;
+	u32 type;
+	u8 adr;
 };
 
 /**
sound/soc/sdca/sdca_functions.c +2 -7
index 46aa874bb0aa..a69fdb9c8b15 100644
@@ -108,17 +108,12 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
 		return -EINVAL;
 	}
 
-	/*
-	 * The number of functions cannot exceed 8, we could use
-	 * acpi_get_local_address() but the value is stored as u64 so
-	 * we might as well avoid casts and intermediate levels
-	 */
 	ret = acpi_get_local_u64_address(adev->handle, &addr);
 	if (ret < 0)
 		return ret;
 
-	if (!addr) {
-		dev_err(dev, "no addr\n");
+	if (!addr || addr > 0x7) {
+		dev_err(dev, "invalid addr: 0x%llx\n", addr);
 		return -ENODEV;
 	}
 
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH 4/5 ASoC: SDCA: Add missing function type names

In reply to Charles Keepax

It is not helpful to error out on some SDCA function types, we might as well report the correct name and let the driver core simply not bind a driver to those functions for which the code lacks support. Also given no functions currently have support, it seems odd to select some as unsupported.

---
 include/sound/sdca_function.h   |  1 +
 sound/soc/sdca/sdca_functions.c | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
include/sound/sdca_function.h +1 -0
index 6943df0851a9..89e42db6d591 100644
@@ -42,6 +42,7 @@ enum sdca_function_type {
 #define	SDCA_FUNCTION_TYPE_RJ_NAME		"RJ"
 #define	SDCA_FUNCTION_TYPE_SIMPLE_NAME		"SimpleJack"
 #define	SDCA_FUNCTION_TYPE_HID_NAME		"HID"
+#define	SDCA_FUNCTION_TYPE_IMP_DEF_NAME		"ImplementationDefined"
 
 enum sdca_entity0_controls {
 	SDCA_CONTROL_ENTITY_0_COMMIT_GROUP_MASK		= 0x01,
sound/soc/sdca/sdca_functions.c +10 -2
index a69fdb9c8b15..400763e056fa 100644
@@ -75,12 +75,20 @@ static int patch_sdca_function_type(struct device *dev,
 		*function_name = SDCA_FUNCTION_TYPE_HID_NAME;
 		break;
 	case SDCA_FUNCTION_TYPE_SIMPLE_AMP:
+		*function_name = SDCA_FUNCTION_TYPE_SIMPLE_AMP_NAME;
+		break;
 	case SDCA_FUNCTION_TYPE_SIMPLE_MIC:
+		*function_name = SDCA_FUNCTION_TYPE_SIMPLE_MIC_NAME;
+		break;
 	case SDCA_FUNCTION_TYPE_SPEAKER_MIC:
+		*function_name = SDCA_FUNCTION_TYPE_SPEAKER_MIC_NAME;
+		break;
 	case SDCA_FUNCTION_TYPE_RJ:
+		*function_name = SDCA_FUNCTION_TYPE_RJ_NAME;
+		break;
 	case SDCA_FUNCTION_TYPE_IMP_DEF:
-		dev_warn(dev, "unsupported SDCA function type %d\n", *function_type);
-		return -EINVAL;
+		*function_name = SDCA_FUNCTION_TYPE_IMP_DEF_NAME;
+		break;
 	default:
 		dev_err(dev, "invalid SDCA function type %d\n", *function_type);
 		return -EINVAL;
Signature · 1 line
2.39.5
#4 lore raw

Re: [PATCH 4/5] ASoC: SDCA: Add missing function type names

Quoted 33 lines · Charles Keepax

It is not helpful to error out on some SDCA function types, we might as well report the correct name and let the driver core simply not bind a driver to those functions for which the code lacks support. Also given no functions currently have support, it seems odd to select some as unsupported.

---
  include/sound/sdca_function.h   |  1 +
  sound/soc/sdca/sdca_functions.c | 12 ++++++++++--
  2 files changed, 11 insertions(+), 2 deletions(-)
include/sound/sdca_function.h +1 -0
index 6943df0851a9..89e42db6d591 100644
@@ -42,6 +42,7 @@ enum sdca_function_type {
  #define	SDCA_FUNCTION_TYPE_RJ_NAME		"RJ"
  #define	SDCA_FUNCTION_TYPE_SIMPLE_NAME		"SimpleJack"
  #define	SDCA_FUNCTION_TYPE_HID_NAME		"HID"
+#define	SDCA_FUNCTION_TYPE_IMP_DEF_NAME		"ImplementationDefined"
 
  enum sdca_entity0_controls {
  	SDCA_CONTROL_ENTITY_0_COMMIT_GROUP_MASK		= 0x01,
sound/soc/sdca/sdca_functions.c +1 -0
index a69fdb9c8b15..400763e056fa 100644
@@ -75,12 +75,20 @@ static int patch_sdca_function_type(struct device *dev,
  		*function_name = SDCA_FUNCTION_TYPE_HID_NAME;
  		break;
  	case SDCA_FUNCTION_TYPE_SIMPLE_AMP:
+		*function_name = SDCA_FUNCTION_TYPE_SIMPLE_AMP_NAME;

sound/soc/sdca/sdca_functions.c static int patch_sdca_function_type(struct device *dev, · line 88

Quoted 10 lines
sound/soc/sdca/sdca_functions.c +7 -0
+		break;
  	case SDCA_FUNCTION_TYPE_SIMPLE_MIC:
+		*function_name = SDCA_FUNCTION_TYPE_SIMPLE_MIC_NAME;
+		break;
  	case SDCA_FUNCTION_TYPE_SPEAKER_MIC:
+		*function_name = SDCA_FUNCTION_TYPE_SPEAKER_MIC_NAME;
+		break;
  	case SDCA_FUNCTION_TYPE_RJ:
+		*function_name = SDCA_FUNCTION_TYPE_RJ_NAME;
+		break;

the changes above are fine...

sound/soc/sdca/sdca_functions.c static int patch_sdca_function_type(struct device *dev, · line 91

Quoted 5 lines
sound/soc/sdca/sdca_functions.c +2 -2
  	case SDCA_FUNCTION_TYPE_IMP_DEF:
-		dev_warn(dev, "unsupported SDCA function type %d\n", *function_type);
-		return -EINVAL;
+		*function_name = SDCA_FUNCTION_TYPE_IMP_DEF_NAME;
+		break;

but this one is controversial. We really have no idea what to do in this case. There could be completely different 'imp-def' functions that require different drivers. I don't know how the entire binding mechanism would work. Probably best to err on the side of throwing a 'not supported' error?

Quoted 3 lines
sound/soc/sdca/sdca_functions.c +0 -0
  	default:
  		dev_err(dev, "invalid SDCA function type %d\n", *function_type);
  		return -EINVAL;
author maintainer
#5 lore raw

Re: [PATCH 4/5] ASoC: SDCA: Add missing function type names

Quoted 12 lines · Pierre-Louis Bossart

sound/soc/sdca/sdca_functions.c static int patch_sdca_function_type(struct device *dev, · line 91

Quoted 5 lines · Charles Keepax

case SDCA_FUNCTION_TYPE_IMP_DEF:

sound/soc/sdca/sdca_functions.c +2 -2
-		dev_warn(dev, "unsupported SDCA function type %d\n", *function_type);
-		return -EINVAL;
+		*function_name = SDCA_FUNCTION_TYPE_IMP_DEF_NAME;
+		break;

but this one is controversial. We really have no idea what to do in this case. There could be completely different 'imp-def' functions that require different drivers. I don't know how the entire binding mechanism would work. Probably best to err on the side of throwing a 'not supported' error?

I would certainly agree with you that a generic class driver implementation would not bind against an imp def function, but I see no reason to prevent custom driver implementations from being able to access this function. They will be creating the parent auxilary stuff and can bind whatever they like to this imp def function.

Thanks,
Charles

author maintainer
#6 lore raw

PATCH 5/5 ASoC: SDCA: Split function type patching and function naming

In reply to Charles Keepax

Currently, patch_sdca_function_type() both patches the function type for older SDCA revisions, and reports the name of the function. In general it is cleaner to have a single function only do a single task, so split these operations into two separate functions.

---
 sound/soc/sdca/sdca_functions.c | 117 +++++++++++++++-----------------
 1 file changed, 53 insertions(+), 64 deletions(-)
sound/soc/sdca/sdca_functions.c +53 -64
index 400763e056fa..38071bc838b9 100644
@@ -17,86 +17,64 @@
 #include <sound/sdca.h>
 #include <sound/sdca_function.h>
 
-static int patch_sdca_function_type(struct device *dev,
-				    u32 interface_revision,
-				    u32 *function_type,
-				    const char **function_name)
+static int patch_sdca_function_type(u32 interface_revision, u32 *function_type)
 {
-	unsigned long function_type_patch = 0;
-
 	/*
 	 * Unfortunately early SDCA specifications used different indices for Functions,
 	 * for backwards compatibility we have to reorder the values found
 	 */
-	if (interface_revision >= 0x0801)
-		goto skip_early_draft_order;
-
-	switch (*function_type) {
-	case 1:
-		function_type_patch = SDCA_FUNCTION_TYPE_SMART_AMP;
-		break;
-	case 2:
-		function_type_patch = SDCA_FUNCTION_TYPE_SMART_MIC;
-		break;
-	case 3:
-		function_type_patch = SDCA_FUNCTION_TYPE_SPEAKER_MIC;
-		break;
-	case 4:
-		function_type_patch = SDCA_FUNCTION_TYPE_UAJ;
-		break;
-	case 5:
-		function_type_patch = SDCA_FUNCTION_TYPE_RJ;
-		break;
-	case 6:
-		function_type_patch = SDCA_FUNCTION_TYPE_HID;
-		break;
-	default:
-		dev_warn(dev, "SDCA version %#x invalid function type %d\n",
-			 interface_revision, *function_type);
-		return -EINVAL;
+	if (interface_revision < 0x0801) {
+		switch (*function_type) {
+		case 1:
+			*function_type = SDCA_FUNCTION_TYPE_SMART_AMP;
+			break;
+		case 2:
+			*function_type = SDCA_FUNCTION_TYPE_SMART_MIC;
+			break;
+		case 3:
+			*function_type = SDCA_FUNCTION_TYPE_SPEAKER_MIC;
+			break;
+		case 4:
+			*function_type = SDCA_FUNCTION_TYPE_UAJ;
+			break;
+		case 5:
+			*function_type = SDCA_FUNCTION_TYPE_RJ;
+			break;
+		case 6:
+			*function_type = SDCA_FUNCTION_TYPE_HID;
+			break;
+		default:
+			return -EINVAL;
+		}
 	}
 
-skip_early_draft_order:
-	if (function_type_patch)
-		*function_type = function_type_patch;
+	return 0;
+}
 
-	/* now double-check the values */
-	switch (*function_type) {
+static const char *get_sdca_function_name(u32 function_type)
+{
+	switch (function_type) {
 	case SDCA_FUNCTION_TYPE_SMART_AMP:
-		*function_name = SDCA_FUNCTION_TYPE_SMART_AMP_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_SMART_AMP_NAME;
 	case SDCA_FUNCTION_TYPE_SMART_MIC:
-		*function_name = SDCA_FUNCTION_TYPE_SMART_MIC_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_SMART_MIC_NAME;
 	case SDCA_FUNCTION_TYPE_UAJ:
-		*function_name = SDCA_FUNCTION_TYPE_UAJ_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_UAJ_NAME;
 	case SDCA_FUNCTION_TYPE_HID:
-		*function_name = SDCA_FUNCTION_TYPE_HID_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_HID_NAME;
 	case SDCA_FUNCTION_TYPE_SIMPLE_AMP:
-		*function_name = SDCA_FUNCTION_TYPE_SIMPLE_AMP_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_SIMPLE_AMP_NAME;
 	case SDCA_FUNCTION_TYPE_SIMPLE_MIC:
-		*function_name = SDCA_FUNCTION_TYPE_SIMPLE_MIC_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_SIMPLE_MIC_NAME;
 	case SDCA_FUNCTION_TYPE_SPEAKER_MIC:
-		*function_name = SDCA_FUNCTION_TYPE_SPEAKER_MIC_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_SPEAKER_MIC_NAME;
 	case SDCA_FUNCTION_TYPE_RJ:
-		*function_name = SDCA_FUNCTION_TYPE_RJ_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_RJ_NAME;
 	case SDCA_FUNCTION_TYPE_IMP_DEF:
-		*function_name = SDCA_FUNCTION_TYPE_IMP_DEF_NAME;
-		break;
+		return SDCA_FUNCTION_TYPE_IMP_DEF_NAME;
 	default:
-		dev_err(dev, "invalid SDCA function type %d\n", *function_type);
-		return -EINVAL;
+		return NULL;
 	}
-
-	dev_info(dev, "SDCA function %s (type %d)\n", *function_name, *function_type);
-
-	return 0;
 }
 
 static int find_sdca_function(struct acpi_device *adev, void *data)
@@ -150,10 +128,21 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
 		return ret;
 	}
 
-	ret = patch_sdca_function_type(dev, sdca_data->interface_revision,
-				       &function_type, &function_name);
-	if (ret < 0)
+	ret = patch_sdca_function_type(sdca_data->interface_revision, &function_type);
+	if (ret < 0) {
+		dev_err(dev, "SDCA version %#x invalid function type %d\n",
+			sdca_data->interface_revision, function_type);
 		return ret;
+	}
+
+	function_name = get_sdca_function_name(function_type);
+	if (!function_name) {
+		dev_err(dev, "invalid SDCA function type %d\n", function_type);
+		return -EINVAL;
+	}
+
+	dev_info(dev, "SDCA function %s (type %d) at 0x%llx\n",
+		 function_name, function_type, addr);
 
 	/* store results */
 	func_index = sdca_data->num_functions;
Signature · 1 line
2.39.5
maintainer
#7 lore raw
In reply to Charles Keepax
Quoted 8 lines · Charles Keepax

Several of the SDCA files don't include all the headers they use locally. These are included by the point of use through other headers, so it is not currently causing any issues. However, files should directly include things they directly use, so add the missing header includes.

[...]

Applied to

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

Thanks!

[1/5] ASoC: SDCA: Add missing header includes

      commit: deb015208f7be9a62cb68dd8337d075b1829ee1d
[2/5] ASoC: SDCA: Clean up error messages
      commit: 935cd06bfad4b715195befaf527a2d4fd36361d9
[3/5] ASoC: SDCA: Add bounds check for function address
      commit: c36297b1bd6e52a75a8ed75eb5dbf35c50402398
[4/5] ASoC: SDCA: Add missing function type names
      commit: c1ed5eb13f39b0058670bc2b1e251a040c306868
[5/5] ASoC: SDCA: Split function type patching and function naming
      commit: 69dcf023f1f13ca9c2e9e8f30b9ec52ac0486c0a

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

maintainer
#8 lore raw
In reply to Charles Keepax
Quoted 5 lines · Charles Keepax

Several of the SDCA files don't include all the headers they use locally. These are included by the point of use through other headers, so it is not currently causing any issues. However, files should directly include things they directly use, so add the missing header includes.

As mentioned in submitting-patches.rst when submitting a patch series you should supply a cover letter for that patch series which describes the overall content of the series. This helps people understand what they are looking at and how things fit together.