ASoC: SDCA: Add missing header includes
Subsystems (3)
Charles Keepax
maintainerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
Charles Keepax
maintainerPATCH 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
@@ -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
Charles Keepax
maintainerPATCH 3/5 ASoC: SDCA: Add bounds check for function address
In reply to Charles KeepaxSDCA 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
@@ -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
@@ -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
Charles Keepax
maintainerPATCH 4/5 ASoC: SDCA: Add missing function type names
In reply to Charles KeepaxIt 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
@@ -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
@@ -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
Pierre-Louis Bossart
reviewerRe: [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.
Signed-off-by Charles Keepax <[email protected]>--- 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@@ -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@@ -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
-2case 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
-0default :dev_err (dev,"invalid SDCA function type %d\n" , *function_type);return -EINVAL ;
Charles Keepax
maintainerRe: [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
Charles Keepax
maintainerPATCH 5/5 ASoC: SDCA: Split function type patching and function naming
In reply to Charles KeepaxCurrently, 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
@@ -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
Mark Brown
maintainerQuoted 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: 69dcf023f1f13ca9c2e9e8f30b9ec52ac0486c0aAll 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
Mark Brown
maintainerQuoted 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.