Skip to contentSkip to conversation

platform/x86: asus-wmi: support toggling POST sound

PATCH In review Luke D. Jones 2 participants 5 messages Mar 10, 2024 – Mar 20, 2024

Subsystems (2)
lore
Share & tools
lore

Luke D. Jones

author maintainer
#0 lore raw

PATCH 1/1 platform/x86: asus-wmi: support toggling POST sound

Add support for toggling the BIOS POST sound on some ASUS laptops.

---
 .../ABI/testing/sysfs-platform-asus-wmi       |  7 +++
 drivers/platform/x86/asus-wmi.c               | 54 +++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h    |  3 ++
 3 files changed, 64 insertions(+)
Documentation/ABI/testing/sysfs-platform-asus-wmi +7 -0
index e32b4f0ae15f..f3c53b7453f0 100644
@@ -194,3 +194,10 @@ Contact:	"Luke Jones" <[email protected]>
 Description:
 		Set the target temperature limit of the Nvidia dGPU:
 			* min=75, max=87
+
+What:		/sys/devices/platform/<platform>/boot_sound
+Date:		Jun 2023
+KernelVersion:	6.9
+Contact:	"Luke Jones" <[email protected]>
+Description:
+		Set if the BIOS POST sound is played on boot.
drivers/platform/x86/asus-wmi.c +54 -0

84 lines not on this page · raw message

include/linux/platform_data/x86/asus-wmi.h +3 -0
index 3e9a01467c67..3eb5cd6773ad 100644
@@ -137,6 +137,9 @@
 /* TUF laptop RGB power/state */
 #define ASUS_WMI_DEVID_TUF_RGB_STATE	0x00100057
 
+/* Bootup sound control */
+#define ASUS_WMI_DEVID_BOOT_SOUND	0x00130022
+
 /* DSTS masks */
 #define ASUS_WMI_DSTS_STATUS_BIT	0x00000001
 #define ASUS_WMI_DSTS_UNKNOWN_BIT	0x00000002
Signature · 1 line
2.44.0
maintainer
#1 lore raw
Quoted 60 lines · Luke D. Jones

Add support for toggling the BIOS POST sound on some ASUS laptops.

---
 .../ABI/testing/sysfs-platform-asus-wmi       |  7 +++
 drivers/platform/x86/asus-wmi.c               | 54 +++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h    |  3 ++
 3 files changed, 64 insertions(+)
Documentation/ABI/testing/sysfs-platform-asus-wmi +7 -0
index e32b4f0ae15f..f3c53b7453f0 100644
@@ -194,3 +194,10 @@ Contact:	"Luke Jones" <[email protected]>
 Description:
 		Set the target temperature limit of the Nvidia dGPU:
 			* min=75, max=87
+
+What:		/sys/devices/platform/<platform>/boot_sound
+Date:		Jun 2023
+KernelVersion:	6.9
+Contact:	"Luke Jones" <[email protected]>
+Description:
+		Set if the BIOS POST sound is played on boot.
drivers/platform/x86/asus-wmi.c +21 -0
index ca8c73c15fcc..26084e9846a1 100644
@@ -297,6 +297,7 @@ struct asus_wmi {
 	// The RSOC controls the maximum charging percentage.
 	bool battery_rsoc_available;
 
+	bool boot_sound_available;
 	bool panel_overdrive_available;
 	bool mini_led_mode_available;
 	u32 mini_led_dev_id;
@@ -2106,6 +2107,55 @@ static ssize_t panel_od_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(panel_od);
 
+/* Bootup sound ***************************************************************/
+
+static ssize_t boot_sound_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct asus_wmi *asus = dev_get_drvdata(dev);
+	int result;
+
+	result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_BOOT_SOUND);
+	if (result < 0)
+		return result;
+
+	return sysfs_emit(buf, "%d\n", result);
+}
+
+static ssize_t boot_sound_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	int result, err;

drivers/platform/x86/asus-wmi.c static ssize_t panel_od_store(struct device *dev, · line 2139

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10 -0
+	u32 snd;
+
+	struct asus_wmi *asus = dev_get_drvdata(dev);
+
+	result = kstrtou32(buf, 10, &snd);
+	if (result)
+		return result;
+
+	if (snd > 1)
+		return -EINVAL;

Why not just use kstrtobool()?

drivers/platform/x86/asus-wmi.c static ssize_t panel_od_store(struct device *dev, · line 2143

Quoted 4 lines
drivers/platform/x86/asus-wmi.c +4 -0
+
+	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BOOT_SOUND, snd, &result);
+
+	if (err) {

Don't leave empty lines between the call and its error handling.

Signature · 1 line
 i.
Quoted 58 lines
drivers/platform/x86/asus-wmi.c +19 -0
+		pr_warn("Failed to set boot sound: %d\n", err);
+		return err;
+	}
+
+	if (result > 1) {
+		pr_warn("Failed to set panel boot sound (result): 0x%x\n", result);
+		return -EIO;
+	}
+
+	sysfs_notify(&asus->platform_device->dev.kobj, NULL, "boot_sound");
+
+	return count;
+}
+static DEVICE_ATTR_RW(boot_sound);
+
 /* Mini-LED mode **************************************************************/
 static ssize_t mini_led_mode_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
@@ -4196,6 +4246,7 @@ static struct attribute *platform_attributes[] = {
 	&dev_attr_ppt_platform_sppt.attr,
 	&dev_attr_nv_dynamic_boost.attr,
 	&dev_attr_nv_temp_target.attr,
+	&dev_attr_boot_sound.attr,
 	&dev_attr_panel_od.attr,
 	&dev_attr_mini_led_mode.attr,
 	&dev_attr_available_mini_led_mode.attr,
@@ -4248,6 +4299,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 		ok = asus->nv_dyn_boost_available;
 	else if (attr == &dev_attr_nv_temp_target.attr)
 		ok = asus->nv_temp_tgt_available;
+	else if (attr == &dev_attr_boot_sound.attr)
+		ok = asus->boot_sound_available;
 	else if (attr == &dev_attr_panel_od.attr)
 		ok = asus->panel_overdrive_available;
 	else if (attr == &dev_attr_mini_led_mode.attr)
@@ -4519,6 +4572,7 @@ static int asus_wmi_add(struct platform_device *pdev)
 	asus->ppt_plat_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PLAT_SPPT);
 	asus->nv_dyn_boost_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_DYN_BOOST);
 	asus->nv_temp_tgt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_THERM_TARGET);
+	asus->boot_sound_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_BOOT_SOUND);
 	asus->panel_overdrive_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD);
 	asus->ally_mcu_usb_switch = acpi_has_method(NULL, ASUS_USB0_PWR_EC0_CSEE)
 						&& dmi_match(DMI_BOARD_NAME, "RC71L");
include/linux/platform_data/x86/asus-wmi.h +3 -0
index 3e9a01467c67..3eb5cd6773ad 100644
@@ -137,6 +137,9 @@
 /* TUF laptop RGB power/state */
 #define ASUS_WMI_DEVID_TUF_RGB_STATE	0x00100057
 
+/* Bootup sound control */
+#define ASUS_WMI_DEVID_BOOT_SOUND	0x00130022
+
 /* DSTS masks */
 #define ASUS_WMI_DSTS_STATUS_BIT	0x00000001
 #define ASUS_WMI_DSTS_UNKNOWN_BIT	0x00000002
author maintainer
#2 lore raw
Quoted 66 lines · Ilpo Järvinen
Quoted 64 lines · Luke D. Jones

Add support for toggling the BIOS POST sound on some ASUS laptops.

---
 .../ABI/testing/sysfs-platform-asus-wmi       |  7 +++
 drivers/platform/x86/asus-wmi.c               | 54 +++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h    |  3 ++
 3 files changed, 64 insertions(+)
Documentation/ABI/testing/sysfs-platform-asus-wmi +7 -0
index e32b4f0ae15f..f3c53b7453f0 100644
@@ -194,3 +194,10 @@ Contact: "Luke Jones" <[email protected]>
 Description:
 Set the target temperature limit of the Nvidia dGPU:
 * min=75, max=87
+
+What: /sys/devices/platform/<platform>/boot_sound
+Date: Jun 2023
+KernelVersion: 6.9
+Contact: "Luke Jones" <[email protected]>
+Description:
+ Set if the BIOS POST sound is played on boot.
drivers/platform/x86/asus-wmi.c +25 -0
index ca8c73c15fcc..26084e9846a1 100644
@@ -297,6 +297,7 @@ struct asus_wmi {
 // The RSOC controls the maximum charging percentage.
 bool battery_rsoc_available;
 
+ bool boot_sound_available;
 bool panel_overdrive_available;
 bool mini_led_mode_available;
 u32 mini_led_dev_id;
@@ -2106,6 +2107,55 @@ static ssize_t panel_od_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(panel_od);
 
+/* Bootup sound ***************************************************************/
+
+static ssize_t boot_sound_show(struct device *dev,
+      struct device_attribute *attr, char *buf)
+{
+ struct asus_wmi *asus = dev_get_drvdata(dev);
+ int result;
+
+ result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_BOOT_SOUND);
+ if (result < 0)
+ return result;
+
+ return sysfs_emit(buf, "%d\n", result);
+}
+
+static ssize_t boot_sound_store(struct device *dev,
+       struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+ int result, err;
+ u32 snd;
+
+ struct asus_wmi *asus = dev_get_drvdata(dev);
+
Quoted 8 lines

drivers/platform/x86/asus-wmi.c static ssize_t panel_od_store(struct device *dev, · line 2139

Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6 -0
+ result = kstrtou32(buf, 10, &snd);
+ if (result)
+ return result;
+
+ if (snd > 1)
+ return -EINVAL;

Why not just use kstrtobool()?

Consistency with other methods mostly. Plus the possibility that asus might do something like add different sounds. I'll change it if a revert back to kstrtou32 later doesn't break things.

Quoted 7 lines

drivers/platform/x86/asus-wmi.c static ssize_t panel_od_store(struct device *dev, · line 2143

Quoted 5 lines
drivers/platform/x86/asus-wmi.c +4 -0
+
+ err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BOOT_SOUND, snd, &result);
+
+ if (err) {

Don't leave empty lines between the call and its error handling.

Got it, thanks.
If there is nothing else I'll submit new version.

Quoted 63 lines
Signature · 2 lines
-- 
i.
Quoted 58 lines
drivers/platform/x86/asus-wmi.c +19 -0
+ pr_warn("Failed to set boot sound: %d\n", err);
+ return err;
+ }
+
+ if (result > 1) {
+ pr_warn("Failed to set panel boot sound (result): 0x%x\n", result);
+ return -EIO;
+ }
+
+ sysfs_notify(&asus->platform_device->dev.kobj, NULL, "boot_sound");
+
+ return count;
+}
+static DEVICE_ATTR_RW(boot_sound);
+
 /* Mini-LED mode **************************************************************/
 static ssize_t mini_led_mode_show(struct device *dev,
    struct device_attribute *attr, char *buf)
@@ -4196,6 +4246,7 @@ static struct attribute *platform_attributes[] = {
 &dev_attr_ppt_platform_sppt.attr,
 &dev_attr_nv_dynamic_boost.attr,
 &dev_attr_nv_temp_target.attr,
+ &dev_attr_boot_sound.attr,
 &dev_attr_panel_od.attr,
 &dev_attr_mini_led_mode.attr,
 &dev_attr_available_mini_led_mode.attr,
@@ -4248,6 +4299,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 ok = asus->nv_dyn_boost_available;
 else if (attr == &dev_attr_nv_temp_target.attr)
 ok = asus->nv_temp_tgt_available;
+ else if (attr == &dev_attr_boot_sound.attr)
+ ok = asus->boot_sound_available;
 else if (attr == &dev_attr_panel_od.attr)
 ok = asus->panel_overdrive_available;
 else if (attr == &dev_attr_mini_led_mode.attr)
@@ -4519,6 +4572,7 @@ static int asus_wmi_add(struct platform_device *pdev)
 asus->ppt_plat_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PLAT_SPPT);
 asus->nv_dyn_boost_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_DYN_BOOST);
 asus->nv_temp_tgt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_THERM_TARGET);
+ asus->boot_sound_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_BOOT_SOUND);
 asus->panel_overdrive_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD);
 asus->ally_mcu_usb_switch = acpi_has_method(NULL, ASUS_USB0_PWR_EC0_CSEE)
 && dmi_match(DMI_BOARD_NAME, "RC71L");
include/linux/platform_data/x86/asus-wmi.h +3 -0
index 3e9a01467c67..3eb5cd6773ad 100644
@@ -137,6 +137,9 @@
 /* TUF laptop RGB power/state */
 #define ASUS_WMI_DEVID_TUF_RGB_STATE 0x00100057
 
+/* Bootup sound control */
+#define ASUS_WMI_DEVID_BOOT_SOUND 0x00130022
+
 /* DSTS masks */
 #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
 #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
maintainer
#3 lore raw
Quoted 65 lines · Luke Jones
Quoted 55 lines · Ilpo Järvinen
Quoted 53 lines · Luke D. Jones

Add support for toggling the BIOS POST sound on some ASUS laptops.

---
 .../ABI/testing/sysfs-platform-asus-wmi       |  7 +++
 drivers/platform/x86/asus-wmi.c               | 54 +++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h    |  3 ++
 3 files changed, 64 insertions(+)
Documentation/ABI/testing/sysfs-platform-asus-wmi +31 -0
index e32b4f0ae15f..f3c53b7453f0 100644
@@ -194,3 +194,10 @@ Contact: "Luke Jones" <[email protected]>
 Description:
 Set the target temperature limit of the Nvidia dGPU:
 * min=75, max=87
+
+What: /sys/devices/platform/<platform>/boot_sound
+Date: Jun 2023
+KernelVersion: 6.9
+Contact: "Luke Jones" <[email protected]>
+Description:
+ Set if the BIOS POST sound is played on boot.
@@ -2106,6 +2107,55 @@ static ssize_t panel_od_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(panel_od);
 
+/* Bootup sound ***************************************************************/
+
+static ssize_t boot_sound_show(struct device *dev,
+      struct device_attribute *attr, char *buf)
+{
+ struct asus_wmi *asus = dev_get_drvdata(dev);
+ int result;
+
+ result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_BOOT_SOUND);
+ if (result < 0)
+ return result;
+
+ return sysfs_emit(buf, "%d\n", result);
+}
+
+static ssize_t boot_sound_store(struct device *dev,
+       struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+ int result, err;
+ u32 snd;
+
+ struct asus_wmi *asus = dev_get_drvdata(dev);
+
Quoted 8 lines

Documentation/ABI/testing/sysfs-platform-asus-wmi static ssize_t panel_od_store(struct device *dev, · line 2139

Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-asus-wmi +6 -0
+ result = kstrtou32(buf, 10, &snd);
+ if (result)
+ return result;
+
+ if (snd > 1)
+ return -EINVAL;

Why not just use kstrtobool()?

Quoted 3 lines

Consistency with other methods mostly. Plus the possibility that asus might do something like add different sounds. I'll change it if a revert back to kstrtou32 later doesn't break things.

Hi Luke,

I'd tend to think it's not the most likely scenario. But if they still do something like that, the code could do both kstrtou32() and kstrtobool() to keep the sysfs interface backwards compatible.

But it isn't end of the world for me if you want to keep it as kstrtou32().

Annoyingly the other kstrtou32()s may not be easily converted over to kstrtobool() because u32 formatting accepts 16-based values too such as 0x0. Perhaps hex format wouldn't be used by anyone but the risk is still there and the benefits are not that high.

Signature · 1 line
 i.
author maintainer
#4 lore raw
Quoted 76 lines · Ilpo Järvinen
Quoted 65 lines · Luke Jones
Quoted 55 lines · Ilpo Järvinen
Quoted 53 lines · Luke D. Jones

Add support for toggling the BIOS POST sound on some ASUS laptops.

---
 .../ABI/testing/sysfs-platform-asus-wmi       |  7 +++
 drivers/platform/x86/asus-wmi.c               | 54 +++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h    |  3 ++
 3 files changed, 64 insertions(+)
Documentation/ABI/testing/sysfs-platform-asus-wmi +31 -0
index e32b4f0ae15f..f3c53b7453f0 100644
@@ -194,3 +194,10 @@ Contact: "Luke Jones" <[email protected]>
 Description:
 Set the target temperature limit of the Nvidia dGPU:
 * min=75, max=87
+
+What: /sys/devices/platform/<platform>/boot_sound
+Date: Jun 2023
+KernelVersion: 6.9
+Contact: "Luke Jones" <[email protected]>
+Description:
+ Set if the BIOS POST sound is played on boot.
@@ -2106,6 +2107,55 @@ static ssize_t panel_od_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(panel_od);
 
+/* Bootup sound ***************************************************************/
+
+static ssize_t boot_sound_show(struct device *dev,
+      struct device_attribute *attr, char *buf)
+{
+ struct asus_wmi *asus = dev_get_drvdata(dev);
+ int result;
+
+ result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_BOOT_SOUND);
+ if (result < 0)
+ return result;
+
+ return sysfs_emit(buf, "%d\n", result);
+}
+
+static ssize_t boot_sound_store(struct device *dev,
+       struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+ int result, err;
+ u32 snd;
+
+ struct asus_wmi *asus = dev_get_drvdata(dev);
+
Quoted 8 lines

Documentation/ABI/testing/sysfs-platform-asus-wmi static ssize_t panel_od_store(struct device *dev, · line 2139

Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-asus-wmi +6 -0
+ result = kstrtou32(buf, 10, &snd);
+ if (result)
+ return result;
+
+ if (snd > 1)
+ return -EINVAL;

Why not just use kstrtobool()?

Quoted 3 lines

Consistency with other methods mostly. Plus the possibility that asus might do something like add different sounds. I'll change it if a revert back to kstrtou32 later doesn't break things.

Hi Luke,

I'd tend to think it's not the most likely scenario. But if they still do something like that, the code could do both kstrtou32() and kstrtobool() to keep the sysfs interface backwards compatible.

Quoted 7 lines

But it isn't end of the world for me if you want to keep it as kstrtou32().

Annoyingly the other kstrtou32()s may not be easily converted over to kstrtobool() because u32 formatting accepts 16-based values too such as 0x0. Perhaps hex format wouldn't be used by anyone but the risk is still there and the benefits are not that high.

Understood, yeah. I suppose one of the reasons I preferred using kstrtou32 in the first place was no need for casting when making the WMI call. Plus all the other code I've written here is similar to this (you might notice that a large chunk of what is in asus-wmi now is from me).