ALSA: hda/tas2781: Add speaker id check for ASUS projects
Subsystems (2)
Baojun Xu
maintainerPATCH v3 1/1 ALSA: hda/tas2781: Add speaker id check for ASUS projects
Add speaker id check by gpio in ACPI for ASUS projects.
In other vendors, speaker id was checked by BIOS, and was applied in last bit of subsys id, so we can load corresponding firmware binary file for its speaker by subsys id.
But in ASUS project, the firmware binary name will be appended an extra number to tell the speakers from different vendors. And this single digit come from gpio level of speaker id in BIOS.
---
v3:
- Change strstr() to strncasecmp() for compare subsystem id.
- Remove result check after devm_acpi_dev_add_driver_gpios().
- Remove spk_id > 1 check, as result of gpiod_get_value(), must be 0 or 1, or negative if error happend.
- Change scnprintf() to snprintf(), as didn't care the length.
- Remove changes which not relative current patch.
v2:
- Change ASUS id from 0x10430000 to "1043".
- Move gpio setting to tas2781_read_acpi() from probe.
- Remove interrupt gpio in acpi_gpio_mapping.
- Add sub and physdev in tas2781_read_acpi() for subsys id read.
- Add debug log for get acpi resource failed.
- Return error if get resource or subsys id failed.
- Return error if get gpio fail for speaker id with ASUS projects.
- Change fixed buffer lengh to sizeof().
- Change bits calculator to lower_16_bits().
- Remove unnecessary empty line in tas2781_hda_i2c_probe().
--- include/sound/tas2781.h | 3 ++ sound/pci/hda/tas2781_hda_i2c.c | 60 +++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 6 deletions(-)
include/sound/tas2781.h +3 -0
@@ -107,6 +107,8 @@#define TASDEVICE_CMD_DELAY 0x3#define TASDEVICE_CMD_FIELD_W 0x4 +#define TAS2781_ASUS_ID "1043" +enum audio_device {TAS2563 ,TAS2781 ,
@@ -156,6 +158,7 @@ struct tasdevice_priv {struct tasdevice_rca rcabin;struct calidata cali_data;struct tasdevice_fw *fmw; +struct gpio_desc *speaker_id;struct gpio_desc *reset;struct mutex codec_lock;struct regmap *regmap;
sound/pci/hda/tas2781_hda_i2c.c +54 -6
98 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 7 lines · Baojun Xu
Add speaker id check by gpio in ACPI for ASUS projects.
In other vendors, speaker id was checked by BIOS, and was applied in last bit of subsys id, so we can load corresponding firmware binary file for its speaker by subsys id.
But in ASUS project, the firmware binary name will be appended an extra number to tell the speakers from different vendors. And this single digit come from gpio level of speaker id in BIOS.
...
sound/pci/hda/tas2781_hda_i2c.c static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid) · line 146
Quoted 2 lines
sound/pci/hda/tas2781_hda_i2c.c +2
-0+// Speaker id was needed for ASUS projects. +if (!strncasecmp (sub,TAS2781_ASUS_ID ,sizeof (TAS2781_ASUS_ID ))) {
Why "case"? Just use strcmp() since the second one is constant and you use it's length.
sound/pci/hda/tas2781_hda_i2c.c static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid) · line 148
Quoted 2 lines
sound/pci/hda/tas2781_hda_i2c.c +2
-0+devm_acpi_dev_add_driver_gpios (p->dev, + tas2781_speaker_id_gpios);
I don't know why you completely removed the check, I would leave a debug message on the error path to give a clue to the user if it fails here. See how other driver do with this.
Something like
ret = devm_acpi_dev_add_driver_gpios(p->dev, tas2781_speaker_id_gpios); if (ret) dev_dbg(...);
sound/pci/hda/tas2781_hda_i2c.c static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid) · line 151
Quoted 3 lines
sound/pci/hda/tas2781_hda_i2c.c +3
-0+ p->speaker_id =devm_gpiod_get (p->dev,"speakerid" ,GPIOD_IN ); +if (IS_ERR (p->speaker_id)) { +dev_err (p->dev,"Failed to get Speaker id.\n" );
Wrong value in ret, right?
Quoted 19 lines
sound/pci/hda/tas2781_hda_i2c.c +7
-0+ goto err; + } + }else { + p->speaker_id =NULL ; + }acpi_dev_free_resource_list (&resources);strscpy (p->dev_name, hid,sizeof (p->dev_name)); +put_device (physdev);acpi_dev_put (adev);return 0 ; err:dev_err (p->dev,"read acpi error, ret: %d\n" , ret); +put_device (physdev);acpi_dev_put (adev);return ret;
...
sound/pci/hda/tas2781_hda_i2c.c static void tasdev_fw_ready(const struct firmware *fmw, void *context) · line 691
Quoted 11 lines
sound/pci/hda/tas2781_hda_i2c.c +11
-0+if (tas_priv->speaker_id !=NULL ) { +// Speaker id need to be checked for ASUS only. + spk_id =gpiod_get_value (tas_priv->speaker_id); +if (spk_id <0 ) { +// Speaker id is not valid, use default. +dev_dbg (tas_priv->dev,"Wrong spk_id = %d\n" , spk_id); + spk_id =0 ; + } + snprintf(tas_priv->coef_binaryname, + sizeof(tas_priv->coef_binaryname), + "TAS2XXX%04X%01d.bin",
%01d makes a little sense. Just use %d.
Quoted 8 lines
sound/pci/hda/tas2781_hda_i2c.c +8
-0+lower_16_bits (codec->core.subsystem_id), + spk_id); + }else { +snprintf (tas_priv->coef_binaryname, +sizeof (tas_priv->coef_binaryname), +"TAS2XXX%04X.bin" , +lower_16_bits (codec->core.subsystem_id)); + }
Signature · 2 lines
With Best Regards, Andy Shevchenko