diff mbox series

[v5,2/2] ASoC: cs35l41: Read System Name from ACPI _SUB to identify firmware

Message ID 20220630150135.1799535-3-sbinding@opensource.cirrus.com (mailing list archive)
State Superseded
Headers show
Series Read _SUB from ACPI to be able to identify firmware | expand

Commit Message

Stefan Binding June 30, 2022, 3:01 p.m. UTC
When 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.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
 sound/soc/codecs/cs35l41.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Pierre-Louis Bossart June 30, 2022, 6:35 p.m. UTC | #1
On 6/30/22 10:01, Stefan Binding wrote:
> When 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.

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'.
> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
> ---
>  sound/soc/codecs/cs35l41.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/sound/soc/codecs/cs35l41.c b/sound/soc/codecs/cs35l41.c
> index 8766e19d85f1..d70469686699 100644
> --- a/sound/soc/codecs/cs35l41.c
> +++ b/sound/soc/codecs/cs35l41.c
> @@ -6,6 +6,7 @@
>  //
>  // Author: David Rhodes <david.rhodes@cirrus.com>
>  
> +#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);

Typo: Subsystem

> +	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 June 30, 2022, 7:34 p.m. UTC | #2
On Thu, Jun 30, 2022 at 01:35:05PM -0500, Pierre-Louis Bossart wrote:

> 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?

Presumably the fallback would go into cs35l41_acpi_get_name()?
Pierre-Louis Bossart June 30, 2022, 7:50 p.m. UTC | #3
On 6/30/22 14:34, Mark Brown wrote:
> On Thu, Jun 30, 2022 at 01:35:05PM -0500, Pierre-Louis Bossart wrote:
> 
>> 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?
> 
> 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;
diff mbox series

Patch

diff --git a/sound/soc/codecs/cs35l41.c b/sound/soc/codecs/cs35l41.c
index 8766e19d85f1..d70469686699 100644
--- a/sound/soc/codecs/cs35l41.c
+++ b/sound/soc/codecs/cs35l41.c
@@ -6,6 +6,7 @@ 
 //
 // Author: David Rhodes <david.rhodes@cirrus.com>
 
+#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);