ALSA: hda/tas2781: Add speaker id check for ASUS projects
Subsystems (2)
Baojun Xu
maintainerPATCH v2 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.
---
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 | 62 +++++++++++++++++++++++++++++---- 2 files changed, 59 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 +56 -6
107 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 7 lines
sound/pci/hda/tas2781_hda_i2c.c +7
-0+ sub =acpi_get_subsystem_id (ACPI_HANDLE (physdev)); +if (IS_ERR (sub)) { +dev_err (p->dev,"Failed to get SUBSYS ID.\n" ); + goto err; + } +// Speaker id was needed for ASUS projects. +if (strstr (sub,TAS2781_ASUS_ID )) {
strstr() is wrong. You can get 1043 in the middle of the bigger number, or even text.
sound/pci/hda/tas2781_hda_i2c.c static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
Quoted 6 lines
sound/pci/hda/tas2781_hda_i2c.c +5
-0+ ret =devm_acpi_dev_add_driver_gpios (p->dev, + tas2781_speaker_id_gpios); +if (ret) { +dev_err (p->dev,"Unable to add GPIO.\n" ); + goto err;
No need. If this fails, the below most likely fail as well.
Quoted 9 lines
sound/pci/hda/tas2781_hda_i2c.c +9
-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" ); + goto err; + } + }else { + p->speaker_id =NULL ; + }
...
sound/pci/hda/tas2781_hda_i2c.c static void tasdev_fw_ready(const struct firmware *fmw, void *context) · line 688
Quoted 4 lines
sound/pci/hda/tas2781_hda_i2c.c +4
-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 || spk_id >1 ) {
When "> 1" is possible? Isn't it a dead code?
sound/pci/hda/tas2781_hda_i2c.c static void tasdev_fw_ready(const struct firmware *fmw, void *context) · line 693
Quoted 5 lines
sound/pci/hda/tas2781_hda_i2c.c +5
-0+// Speaker id is not valid, use default. +dev_dbg (tas_priv->dev,"Wrong spk_id = %d\n" , spk_id); + spk_id =0 ; + } + scnprintf(tas_priv->coef_binaryname,
Why 'c' variant? You do not check the return value anyway. So, what's the point?
sound/pci/hda/tas2781_hda_i2c.c static void tasdev_fw_ready(const struct firmware *fmw, void *context) · line 699
Quoted 6 lines
sound/pci/hda/tas2781_hda_i2c.c +6
-0+sizeof (tas_priv->coef_binaryname), +"TAS2XXX%04X%01d.bin" , +lower_16_bits (codec->core.subsystem_id), + spk_id); + }else { + scnprintf(tas_priv->coef_binaryname,
Ditto.
Quoted 4 lines
sound/pci/hda/tas2781_hda_i2c.c +4
-0+sizeof (tas_priv->coef_binaryname), +"TAS2XXX%04X.bin" , + lower_16_bits(codec->core.subsystem_id)); + }
...
sound/pci/hda/tas2781_hda_i2c.c static int tas2781_hda_i2c_probe(struct i2c_client *clt) · line 849
Quoted 8 lines
sound/pci/hda/tas2781_hda_i2c.c +0
-1@@ -793,7 +844,6 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)const char *device_name;int ret; - tas_hda =devm_kzalloc (&clt->dev,sizeof (*tas_hda),GFP_KERNEL );if (!tas_hda)return -ENOMEM ;
Stray change.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
sound/pci/hda/tas2781_hda_i2c.c static void tasdev_fw_ready(const struct firmware *fmw, void *context) · line 693
Quoted 5 lines · Baojun Xu
sound/pci/hda/tas2781_hda_i2c.c +5
-0+// Speaker id is not valid, use default. +dev_dbg (tas_priv->dev,"Wrong spk_id = %d\n" , spk_id); + spk_id =0 ; + } + scnprintf(tas_priv->coef_binaryname,Why 'c' variant? You do not check the return value anyway. So, what's the point?
There is a difference between snprintf() and scnprintf(). With W=1, the compiler (at least the recent gcc version) will warn you when the string truncation may happen in the former case while not complaining for the latter.
So, when the truncation is intentional and acceptable (that's certainly most cases), the use of scnprintf() will result in less warnings.
Takashi
Quoted 3 lines · Takashi Iwai
Quoted 1 line · Andy Shevchenko
On Fri, Oct 18, 2024 at 03:11:18PM +0800, Baojun Xu wrote:
...
Quoted 8 lines
Quoted 7 lines
sound/pci/hda/tas2781_hda_i2c.c static void tasdev_fw_ready(const struct firmware *fmw, void *context) · line 693
Quoted 5 lines
sound/pci/hda/tas2781_hda_i2c.c +5
-0+// Speaker id is not valid, use default. +dev_dbg (tas_priv->dev,"Wrong spk_id = %d\n" , spk_id); + spk_id =0 ; + } + scnprintf(tas_priv->coef_binaryname,Why 'c' variant? You do not check the return value anyway. So, what's the point?
Quoted 7 lines
There is a difference between
snprintf()andscnprintf(). With W=1, the compiler (at least the recent gcc version) will warn you when the string truncation may happen in the former case while not complaining for the latter.
So, when the truncation is intentional and acceptable (that's certainly most cases), the use ofscnprintf()will result in less warnings.
Yes, which is a papering over the potential problem, right? I agree that in this case it might be not critical or even practical to check for an error, but in general the whole lot of s*nprintf() should be used with this is in mind.
Signature · 2 lines
With Best Regards, Andy Shevchenko