Skip to contentSkip to conversation

ALSA: hda/tas2781: Add speaker id check for ASUS projects

PATCH Superseded Baojun Xu 3 participants 4 messages Nov 16, 2024 – Nov 18, 2024

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Baojun Xu

author maintainer
#0 lore raw

PATCH v5 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.

---
v5:
- Change length in strncmp(), use strlen().
v4:
- Change strncasecmp() to strncmp().
- Add error debug message print for "add driver gpio".
- Put error information (PTR_ERR) to ret for get gpio.
- Change %01d to %d in snprintf().
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 | 64 +++++++++++++++++++++++++++++----
 2 files changed, 61 insertions(+), 6 deletions(-)
include/sound/tas2781.h +3 -0
index 8cd6da0480b7..621ae485d3cb 100644
@@ -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 +58 -6

101 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

Le 16/11/2024 à 08:50, Baojun Xu a écrit :

Quoted 9 lines

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 6 lines
sound/pci/hda/tas2781_hda_i2c.c +6 -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.

Comments in this file are all /* */.
Why introduce // in many places?

CJ

sound/pci/hda/tas2781_hda_i2c.c static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid) · line 152

Quoted 6 lines
sound/pci/hda/tas2781_hda_i2c.c +6 -0
+	if (!strncmp(sub, TAS2781_ASUS_ID, strlen(TAS2781_ASUS_ID))) {
+		ret = devm_acpi_dev_add_driver_gpios(p->dev,
+			tas2781_speaker_id_gpios);
+		if (ret < 0)
+			dev_err(p->dev, "Failed to add driver gpio %d.\n",
+			ret);

ret should be indented below the ( to ease reading.

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");
+			ret = PTR_ERR(p->speaker_id);
+			goto err;
+		}
+	} else {
+		p->speaker_id = NULL;
+	}

...

#2 lore raw
In reply to Baojun Xu
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 147

Quoted 2 lines
sound/pci/hda/tas2781_hda_i2c.c +2 -0
+	// Speaker id was needed for ASUS projects.
+	if (!strncmp(sub, TAS2781_ASUS_ID, strlen(TAS2781_ASUS_ID))) {

Better approach is

	ret = sscanf(sub, "%04x%04x", &vid, &did);
	if (ret == 2 && vid == ASUS_ID) {
		... // matched to ASUS_ID
	} else {
		... // no match
	}

Alternatively it can be

	u32 subid;

	ret = kstrtou32(sub, 16, &subid);
	if (ret || upper_16_bits(subid) != ASUS_ID) {
		... // no match (as in previous 'else')
	} else {
		... // matched to ASUS_ID
	}

With it it will be clearer to see what's going on here.

With the above you can get rid of the custom constant and use PCI_VENDOR_ID_ASUSTEK directly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 8 lines · Andy Shevchenko
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.

...

Quoted 4 lines

sound/pci/hda/tas2781_hda_i2c.c static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid) · line 147

Quoted 2 lines
sound/pci/hda/tas2781_hda_i2c.c +2 -0
+	// Speaker id was needed for ASUS projects.
+	if (!strncmp(sub, TAS2781_ASUS_ID, strlen(TAS2781_ASUS_ID))) {

Better approach is

	u16 vid, did;
Quoted 22 lines
	ret = sscanf(sub, "%04x%04x", &vid, &did);
	if (ret == 2 && vid == ASUS_ID) {
		... // matched to ASUS_ID
	} else {
		... // no match
	}

Alternatively it can be

	u32 subid;

	ret = kstrtou32(sub, 16, &subid);
	if (ret || upper_16_bits(subid) != ASUS_ID) {
		... // no match (as in previous 'else')
	} else {
		... // matched to ASUS_ID
	}

With it it will be clearer to see what's going on here.

With the above you can get rid of the custom constant and use PCI_VENDOR_ID_ASUSTEK directly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko