Read _SUB from ACPI to be able to identify firmware
Subsystems (4)
v5 cover Read _SUB from ACPI to be able to identify firmware
CS35L41 has a DSP which is able to run firmware, as well as a tuning file. Different systems may want to use different firmwares and tuning files, and some firmwares/tunings may not be compatible with other systems. To allow a system to select the correct fimware/tuning, we can read an _SUB from the ACPI. This _SUB can then be used to uniquely identify the system in the firmware/tuning file name.
Add a helper function which reads the _SUB, so this can be used by other parts in the future.
Add support inside the CS35L41 ASoC driver to read this _SUB, and save it appropriately.
Changes since v4:
- Rename function
Changes since v3:
- Fix 32 bit format string warning
Changes since v2:
- Fix error in function prototype
Changes since v1:
- Add length validation for SSID String
- Rename API
- Allocate memory inside API
- Use ACPI_HANDLE macro instead of ACPI_COMPANION
- Improve error handling
Stefan Binding (2):
ACPI: utils: Add api to read _SUB from ACPI
ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware
drivers/acpi/utils.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ sound/soc/codecs/cs35l41.c | 24 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
Signature · 1 line
2.25.1
PATCH v5 1/2 ACPI: utils: Add api to read _SUB from ACPI
Add a wrapper function to read the _SUB string from ACPI.
--- drivers/acpi/utils.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 44 insertions(+)
drivers/acpi/utils.c +38 -0
@@ -291,6 +291,44 @@ int acpi_get_local_address(acpi_handle handle, u32 *addr) }EXPORT_SYMBOL (acpi_get_local_address); +#define ACPI_MAX_SUB_BUF_SIZE 9 + +const char *acpi_get_subsystem_id (acpi_handle handle) +{ +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj; +acpi_status status; +const char *sub; + + status =acpi_evaluate_object (handle,METHOD_NAME__SUB ,NULL , &buffer); +if (ACPI_FAILURE (status)) { +acpi_handle_debug (handle,"Reading ACPI _SUB failed: %#x\n" , status); +return ERR_PTR (-ENODATA ); + } + + obj = buffer.pointer; +if (obj->type ==ACPI_TYPE_STRING ) { +if (strlen (obj->string.pointer) <ACPI_MAX_SUB_BUF_SIZE && +strlen (obj->string.pointer) >0 ) { + sub =kstrdup (obj->string.pointer,GFP_KERNEL ); +if (!sub) + sub =ERR_PTR (-ENOMEM ); + }else { +acpi_handle_err (handle,"ACPI _SUB Length %zu is Invalid\n" , +strlen (obj->string.pointer)); + sub =ERR_PTR (-EINVAL ); + } + }else { +acpi_handle_warn (handle,"Warning ACPI _SUB did not return a string\n" ); + sub =ERR_PTR (-EINVAL ); + } + +acpi_os_free (buffer.pointer); + +return sub; +} +EXPORT_SYMBOL_GPL (acpi_get_subsystem_id); + acpi_status acpi_evaluate_reference(acpi_handle handle, acpi_string pathname,
include/linux/acpi.h +6 -0
@@ -762,6 +762,7 @@ static inline u64 acpi_arch_get_root_pointer(void)#endif int acpi_get_local_address (acpi_handle handle,u32 *addr); +const char *acpi_get_subsystem_id (acpi_handle handle);#else /* !CONFIG_ACPI */
@@ -1023,6 +1024,11 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr)return -ENODEV ; } +static inline const char *acpi_get_subsystem_id (acpi_handle handle) +{ +return ERR_PTR (-ENODEV ); +} +static inline int acpi_register_wakeup_handler (int wake_irq,bool (*wakeup)(void *context),void *context) {
Signature · 1 line
2.25.1
Rafael J. Wysocki
maintainerRe: [PATCH v5 1/2] ACPI: utils: Add api to read _SUB from ACPI
Quoted 29 lines · Stefan Binding
Add a wrapper function to read the
_SUBstring from ACPI.Signed-off-by Stefan Binding <[email protected]>--- drivers/acpi/utils.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 44 insertions(+)drivers/acpi/utils.c +12
-0@@ -291,6 +291,44 @@ int acpi_get_local_address(acpi_handle handle, u32 *addr) }EXPORT_SYMBOL (acpi_get_local_address); +#define ACPI_MAX_SUB_BUF_SIZE 9 + +const char *acpi_get_subsystem_id (acpi_handle handle) +{ +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj; +acpi_status status; +const char *sub; + + status =acpi_evaluate_object (handle,METHOD_NAME__SUB ,NULL , &buffer); +if (ACPI_FAILURE (status)) { +acpi_handle_debug (handle,"Reading ACPI _SUB failed: %#x\n" , status);
drivers/acpi/utils.c int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 315
Quoted 10 lines
drivers/acpi/utils.c +10
-0+return ERR_PTR (-ENODATA ); + } + + obj = buffer.pointer; +if (obj->type ==ACPI_TYPE_STRING ) { +if (strlen (obj->string.pointer) <ACPI_MAX_SUB_BUF_SIZE && +strlen (obj->string.pointer) >0 ) { + sub =kstrdup (obj->string.pointer,GFP_KERNEL ); +if (!sub) + sub =ERR_PTR (-ENOMEM );
The error codes below are somewhat questionable.
drivers/acpi/utils.c int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 319
Quoted 4 lines
drivers/acpi/utils.c +4
-0+ }else { +acpi_handle_err (handle,"ACPI _SUB Length %zu is Invalid\n" , +strlen (obj->string.pointer)); + sub =ERR_PTR (-EINVAL );
This is as good as failure, so why not use -ENODATA here?
drivers/acpi/utils.c int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 323
Quoted 4 lines
drivers/acpi/utils.c +4
-0+ } + }else { +acpi_handle_warn (handle,"Warning ACPI _SUB did not return a string\n" ); + sub =ERR_PTR (-EINVAL );
Likewise.
Quoted 38 lines
drivers/acpi/utils.c +8
-0+ } + +acpi_os_free (buffer.pointer); + +return sub; +} +EXPORT_SYMBOL_GPL (acpi_get_subsystem_id); + acpi_status acpi_evaluate_reference(acpi_handle handle, acpi_string pathname,include/linux/acpi.h +6
-1@@ -762,6 +762,7 @@ static inline u64 acpi_arch_get_root_pointer(void)#endif int acpi_get_local_address (acpi_handle handle,u32 *addr); +const char *acpi_get_subsystem_id (acpi_handle handle);#else /* !CONFIG_ACPI */ @@ -1023,6 +1024,11 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr)return -ENODEV ; } +static inline const char *acpi_get_subsystem_id (acpi_handle handle) +{ +return ERR_PTR (-ENODEV ); +} +static inline int acpi_register_wakeup_handler (int wake_irq,bool (*wakeup)(void *context),void *context) { --2.25.1
Re: [PATCH v5 1/2] ACPI: utils: Add api to read _SUB from ACPI
In reply to Stefan BindingQuoted 2 lines · Stefan Binding
Add a wrapper function to read the
_SUBstring from ACPI.
...
drivers/acpi/utils.c int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 318
Quoted 9 lines
drivers/acpi/utils.c +9
-0+if (obj->type ==ACPI_TYPE_STRING ) { +if (strlen (obj->string.pointer) <ACPI_MAX_SUB_BUF_SIZE && +strlen (obj->string.pointer) >0 ) { + sub =kstrdup (obj->string.pointer,GFP_KERNEL ); +if (!sub) + sub =ERR_PTR (-ENOMEM ); + }else { +acpi_handle_err (handle,"ACPI _SUB Length %zu is Invalid\n" , +strlen (obj->string.pointer));
Three times to evaluate strlen()... Can we do better, please?
Quoted 6 lines
drivers/acpi/utils.c +6
-0+ sub =ERR_PTR (-EINVAL ); + } + }else { +acpi_handle_warn (handle,"Warning ACPI _SUB did not return a string\n" ); + sub =ERR_PTR (-EINVAL ); + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v5 2/2 ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware
In reply to Stefan BindingWhen loading firmware, wm_adsp uses a number of parameters to determine the path of the firmware and tuning files to load. One of these parameters is system_name.
Add support in cs35l41 to read this system name from the ACPI _SUB ID in order to uniquely identify the firmware and tuning mapped to a particular system.
--- sound/soc/codecs/cs35l41.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
sound/soc/codecs/cs35l41.c +24 -0
@@ -6,6 +6,7 @@// // Author: David Rhodes <[email protected]> +#include <linux/acpi.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/init.h>
@@ -1142,6 +1143,24 @@ static int cs35l41_dsp_init(struct cs35l41_private *cs35l41)return ret; } +static int cs35l41_acpi_get_name (struct cs35l41_private *cs35l41) +{ +acpi_handle handle =ACPI_HANDLE (cs35l41->dev); +const char *sub; + +/* If there is no ACPI_HANDLE, there is no ACPI for this system, return 0 */ +if (!handle) +return 0 ; + + sub =acpi_get_subsystem_id (handle); +if (IS_ERR (sub)) +return PTR_ERR (sub); + + cs35l41->dsp.system_name = sub; +dev_dbg (cs35l41->dev,"Susystem ID: %s\n" , cs35l41->dsp.system_name); +return 0 ; +} +int cs35l41_probe (struct cs35l41_private *cs35l41,const struct cs35l41_hw_cfg *hw_cfg) {u32 regid, reg_revid, i, mtl_revid, int_status, chipid_match;
@@ -1270,6 +1289,10 @@ int cs35l41_probe(struct cs35l41_private *cs35l41, const struct cs35l41_hw_cfg * goto err; } + ret =cs35l41_acpi_get_name (cs35l41); +if (ret <0 ) + goto err; + ret =cs35l41_dsp_init (cs35l41);if (ret <0 ) goto err;
@@ -1316,6 +1339,7 @@ void cs35l41_remove(struct cs35l41_private *cs35l41)pm_runtime_disable (cs35l41->dev);regmap_write (cs35l41->regmap,CS35L41_IRQ1_MASK1 ,0xFFFFFFFF ); +kfree (cs35l41->dsp.system_name);wm_adsp2_remove (&cs35l41->dsp);cs35l41_safe_reset (cs35l41->regmap, cs35l41->hw_cfg.bst_type);
Signature · 1 line
2.25.1
Re: [PATCH v5 2/2] ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware
Quoted 6 lines · Stefan Binding
When loading firmware,
wm_adspuses a number of parameters to determine the path of the firmware and tuning files to load. One of these parameters issystem_name.
Add support in cs35l41 to read this system name from the ACPI_SUBID in order to uniquely identify the firmware and tuning mapped to a particular system.
It's my understanding that the _SUB method is optional, not required. It may be wise to plan for a fallback, e.g to use DMI quirks or other identifiers, no?
If it's used quite widely, then it may be a good thing to add to 'alsa-info'.
Quoted 26 lines
Signed-off-by Stefan Binding <[email protected]>--- sound/soc/codecs/cs35l41.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)sound/soc/codecs/cs35l41.c +6
-0@@ -6,6 +6,7 @@// // Author: David Rhodes <[email protected]> +#include <linux/acpi.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/init.h> @@ -1142,6 +1143,24 @@ static int cs35l41_dsp_init(struct cs35l41_private *cs35l41)return ret; } +static int cs35l41_acpi_get_name (struct cs35l41_private *cs35l41) +{ +acpi_handle handle =ACPI_HANDLE (cs35l41->dev); +const char *sub; +
sound/soc/codecs/cs35l41.c static int cs35l41_dsp_init(struct cs35l41_private *cs35l41) · line 1160
Quoted 10 lines
sound/soc/codecs/cs35l41.c +10
-0+/* If there is no ACPI_HANDLE, there is no ACPI for this system, return 0 */ +if (!handle) +return 0 ; + + sub =acpi_get_subsystem_id (handle); +if (IS_ERR (sub)) +return PTR_ERR (sub); + + cs35l41->dsp.system_name = sub; +dev_dbg (cs35l41->dev,"Susystem ID: %s\n" , cs35l41->dsp.system_name);
Typo: Subsystem
Quoted 25 lines
sound/soc/codecs/cs35l41.c +8
-0+return 0 ; +} +int cs35l41_probe (struct cs35l41_private *cs35l41,const struct cs35l41_hw_cfg *hw_cfg) {u32 regid, reg_revid, i, mtl_revid, int_status, chipid_match;@@ -1270,6 +1289,10 @@ int cs35l41_probe(struct cs35l41_private *cs35l41, const struct cs35l41_hw_cfg * goto err; } + ret =cs35l41_acpi_get_name (cs35l41); +if (ret <0 ) + goto err; + ret =cs35l41_dsp_init (cs35l41);if (ret <0 ) goto err;@@ -1316,6 +1339,7 @@ void cs35l41_remove(struct cs35l41_private *cs35l41)pm_runtime_disable (cs35l41->dev);regmap_write (cs35l41->regmap,CS35L41_IRQ1_MASK1 ,0xFFFFFFFF ); +kfree (cs35l41->dsp.system_name);wm_adsp2_remove (&cs35l41->dsp);cs35l41_safe_reset (cs35l41->regmap, cs35l41->hw_cfg.bst_type);
Mark Brown
maintainerRe: [PATCH v5 2/2] ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware
Quoted 3 lines · Pierre-Louis Bossart
It's my understanding that the
_SUBmethod is optional, not required. It may be wise to plan for a fallback, e.g to use DMI quirks or other identifiers, no?
Presumably the fallback would go into cs35l41_acpi_get_name()?
Re: [PATCH v5 2/2] ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware
Quoted 7 lines · Mark Brown
Quoted 3 lines · Pierre-Louis Bossart
It's my understanding that the
_SUBmethod is optional, not required. It may be wise to plan for a fallback, e.g to use DMI quirks or other identifiers, no?Presumably the fallback would go into
cs35l41_acpi_get_name()?
That's what I had in mind, if this _SUB does not exist then you could use something else instead of returning -ENODATA;
+ sub = acpi_get_subsystem_id(handle);
+ if (IS_ERR(sub))
+ return PTR_ERR(sub);
+
+ cs35l41->dsp.system_name = sub;