Skip to contentSkip to conversation

platform/x86: asus-wmi: support the disable camera LED on F10 of Zenbook 2023

PATCH Superseded Devin Bayer 3 participants 6 messages Jun 21, 2024 – Jun 24, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86: asus-wmi: support the disable camera LED on F10 of Zenbook 2023

Adds a sysfs entry for the LED on F10 above the crossed out camera icon on 2023 Zenbooks.

v2
- Changed name from platform::camera to asus::camera
- Separated patch from patchset

v1
- https://lore.kernel.org/platform-driver-x86/[email protected]/

---
 drivers/platform/x86/asus-wmi.c            | 36 ++++++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h |  2 ++
 2 files changed, 38 insertions(+)
drivers/platform/x86/asus-wmi.c +36 -0
index 3f07bbf809ef..20b7ed6a27b5 100644
@@ -73,6 +73,7 @@ module_param(fnlock_default, bool, 0444);
 #define NOTIFY_LID_FLIP_ROG		0xbd
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED	BIT(0)
+#define ASUS_WMI_DEVID_CAMERA_LED		0x00060079
 
 #define ASUS_MID_FAN_DESC		"mid_fan"
 #define ASUS_GPU_FAN_DESC		"gpu_fan"
@@ -227,6 +228,7 @@ struct asus_wmi {
 	struct led_classdev lightbar_led;
 	int lightbar_led_wk;
 	struct led_classdev micmute_led;
+	struct led_classdev camera_led;
 	struct workqueue_struct *led_workqueue;
 	struct work_struct tpd_led_work;
 	struct work_struct wlan_led_work;
@@ -1533,6 +1535,27 @@ static int micmute_led_set(struct led_classdev *led_cdev,
 	return err < 0 ? err : 0;
 }
 
+static enum led_brightness camera_led_get(struct led_classdev *led_cdev)
+{
+	struct asus_wmi *asus;
+	u32 result;
+
+	asus = container_of(led_cdev, struct asus_wmi, camera_led);
+	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CAMERA_LED, &result);
+
+	return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
+}
+
+static int camera_led_set(struct led_classdev *led_cdev,
+			   enum led_brightness brightness)
+{
+	int state = brightness != LED_OFF;
+	int err;
+
+	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_CAMERA_LED, state, NULL);
+	return err < 0 ? err : 0;
+}
+
 static void asus_wmi_led_exit(struct asus_wmi *asus)
 {
 	led_classdev_unregister(&asus->kbd_led);
@@ -1540,6 +1563,7 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)
 	led_classdev_unregister(&asus->wlan_led);
 	led_classdev_unregister(&asus->lightbar_led);
 	led_classdev_unregister(&asus->micmute_led);
+	led_classdev_unregister(&asus->camera_led);
 
 	if (asus->led_workqueue)
 		destroy_workqueue(asus->led_workqueue);
@@ -1631,6 +1655,18 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 			goto error;
 	}
 
+	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CAMERA_LED)) {
+		asus->camera_led.name = "asus::camera";
+		asus->camera_led.max_brightness = 1;
+		asus->camera_led.brightness_get = camera_led_get;
+		asus->camera_led.brightness_set_blocking = camera_led_set;
+
+		rv = led_classdev_register(&asus->platform_device->dev,
+						&asus->camera_led);
+		if (rv)
+			goto error;
+	}
+
 error:
 	if (rv)
 		asus_wmi_led_exit(asus);
include/linux/platform_data/x86/asus-wmi.h +2 -0
index ab1c7deff118..fb0b00f7d292 100644
@@ -50,6 +50,8 @@
 #define ASUS_WMI_DEVID_LED5		0x00020015
 #define ASUS_WMI_DEVID_LED6		0x00020016
 #define ASUS_WMI_DEVID_MICMUTE_LED		0x00040017
+#define ASUS_WMI_DEVID_CAMERA_LED_NEG		0x00060078
+#define ASUS_WMI_DEVID_CAMERA_LED		0x00060079
 
 /* Backlight and Brightness */
 #define ASUS_WMI_DEVID_ALS_ENABLE	0x00050001 /* Ambient Light Sensor */
Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 106 lines · Devin Bayer

Adds a sysfs entry for the LED on F10 above the crossed out camera icon on 2023 Zenbooks.

v2
- Changed name from platform::camera to asus::camera
- Separated patch from patchset

v1
- https://lore.kernel.org/platform-driver-x86/[email protected]/

---
drivers/platform/x86/asus-wmi.c | 36 ++++++++++++++++++++++
include/linux/platform_data/x86/asus-wmi.h | 2 ++

2 files changed, 38 insertions(+)
drivers/platform/x86/asus-wmi.c +36 -0
index 3f07bbf809ef..20b7ed6a27b5 100644
@@ -73,6 +73,7 @@ module_param(fnlock_default, bool, 0444);
 #define NOTIFY_LID_FLIP_ROG 0xbd
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
+#define ASUS_WMI_DEVID_CAMERA_LED 0x00060079
 
 #define ASUS_MID_FAN_DESC "mid_fan"
 #define ASUS_GPU_FAN_DESC "gpu_fan"
@@ -227,6 +228,7 @@ struct asus_wmi {
 struct led_classdev lightbar_led;
 int lightbar_led_wk;
 struct led_classdev micmute_led;
+ struct led_classdev camera_led;
 struct workqueue_struct *led_workqueue;
 struct work_struct tpd_led_work;
 struct work_struct wlan_led_work;
@@ -1533,6 +1535,27 @@ static int micmute_led_set(struct led_classdev *led_cdev,
 return err < 0 ? err : 0;
 }
 
+static enum led_brightness camera_led_get(struct led_classdev *led_cdev)
+{
+ struct asus_wmi *asus;
+ u32 result;
+
+ asus = container_of(led_cdev, struct asus_wmi, camera_led);
+ asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CAMERA_LED, &result);
+
+ return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
+}
+
+static int camera_led_set(struct led_classdev *led_cdev,
+    enum led_brightness brightness)
+{
+ int state = brightness != LED_OFF;
+ int err;
+
+ err = asus_wmi_set_devstate(ASUS_WMI_DEVID_CAMERA_LED, state, NULL);
+ return err < 0 ? err : 0;
+}
+
 static void asus_wmi_led_exit(struct asus_wmi *asus)
 {
 led_classdev_unregister(&asus->kbd_led);
@@ -1540,6 +1563,7 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)
 led_classdev_unregister(&asus->wlan_led);
 led_classdev_unregister(&asus->lightbar_led);
 led_classdev_unregister(&asus->micmute_led);
+ led_classdev_unregister(&asus->camera_led);
 
 if (asus->led_workqueue)
 destroy_workqueue(asus->led_workqueue);
@@ -1631,6 +1655,18 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 goto error;
 }
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CAMERA_LED)) {
+ asus->camera_led.name = "asus::camera";
+ asus->camera_led.max_brightness = 1;
+ asus->camera_led.brightness_get = camera_led_get;
+ asus->camera_led.brightness_set_blocking = camera_led_set;
+
+ rv = led_classdev_register(&asus->platform_device->dev,
+ &asus->camera_led);
+ if (rv)
+ goto error;
+ }
+

error:
if (rv)
asus_wmi_led_exit(asus);

include/linux/platform_data/x86/asus-wmi.h +2 -0
index ab1c7deff118..fb0b00f7d292 100644
@@ -50,6 +50,8 @@
 #define ASUS_WMI_DEVID_LED5 0x00020015
 #define ASUS_WMI_DEVID_LED6 0x00020016
 #define ASUS_WMI_DEVID_MICMUTE_LED 0x00040017
+#define ASUS_WMI_DEVID_CAMERA_LED_NEG 0x00060078
+#define ASUS_WMI_DEVID_CAMERA_LED 0x00060079
 
 /* Backlight and Brightness */
 #define ASUS_WMI_DEVID_ALS_ENABLE 0x00050001 /* Ambient Light Sensor */
Signature · 1 line
2.45.2

If Hans and Ilpo have no other comments regarding the written C code:

maintainer
#2 lore raw
Quoted 110 lines · Luke Jones
Quoted 106 lines · Devin Bayer

Adds a sysfs entry for the LED on F10 above the crossed out camera icon on 2023 Zenbooks.

v2
- Changed name from platform::camera to asus::camera
- Separated patch from patchset

v1
- https://lore.kernel.org/platform-driver-x86/[email protected]/

---
drivers/platform/x86/asus-wmi.c | 36 ++++++++++++++++++++++
include/linux/platform_data/x86/asus-wmi.h | 2 ++

2 files changed, 38 insertions(+)
drivers/platform/x86/asus-wmi.c +36 -0
index 3f07bbf809ef..20b7ed6a27b5 100644
@@ -73,6 +73,7 @@ module_param(fnlock_default, bool, 0444);
 #define NOTIFY_LID_FLIP_ROG 0xbd
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
+#define ASUS_WMI_DEVID_CAMERA_LED 0x00060079
 
 #define ASUS_MID_FAN_DESC "mid_fan"
 #define ASUS_GPU_FAN_DESC "gpu_fan"
@@ -227,6 +228,7 @@ struct asus_wmi {
 struct led_classdev lightbar_led;
 int lightbar_led_wk;
 struct led_classdev micmute_led;
+ struct led_classdev camera_led;
 struct workqueue_struct *led_workqueue;
 struct work_struct tpd_led_work;
 struct work_struct wlan_led_work;
@@ -1533,6 +1535,27 @@ static int micmute_led_set(struct led_classdev *led_cdev,
 return err < 0 ? err : 0;
 }
 
+static enum led_brightness camera_led_get(struct led_classdev *led_cdev)
+{
+ struct asus_wmi *asus;
+ u32 result;
+
+ asus = container_of(led_cdev, struct asus_wmi, camera_led);
+ asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CAMERA_LED, &result);
+
+ return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
+}
+
+static int camera_led_set(struct led_classdev *led_cdev,
+    enum led_brightness brightness)
+{
+ int state = brightness != LED_OFF;
+ int err;
+
+ err = asus_wmi_set_devstate(ASUS_WMI_DEVID_CAMERA_LED, state, NULL);
+ return err < 0 ? err : 0;
+}
+
 static void asus_wmi_led_exit(struct asus_wmi *asus)
 {
 led_classdev_unregister(&asus->kbd_led);
@@ -1540,6 +1563,7 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)
 led_classdev_unregister(&asus->wlan_led);
 led_classdev_unregister(&asus->lightbar_led);
 led_classdev_unregister(&asus->micmute_led);
+ led_classdev_unregister(&asus->camera_led);
 
 if (asus->led_workqueue)
 destroy_workqueue(asus->led_workqueue);
@@ -1631,6 +1655,18 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 goto error;
 }
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CAMERA_LED)) {
+ asus->camera_led.name = "asus::camera";
+ asus->camera_led.max_brightness = 1;
+ asus->camera_led.brightness_get = camera_led_get;
+ asus->camera_led.brightness_set_blocking = camera_led_set;
+
+ rv = led_classdev_register(&asus->platform_device->dev,
+ &asus->camera_led);
+ if (rv)
+ goto error;
+ }
+

error:
if (rv)
asus_wmi_led_exit(asus);

include/linux/platform_data/x86/asus-wmi.h +2 -0
index ab1c7deff118..fb0b00f7d292 100644
@@ -50,6 +50,8 @@
 #define ASUS_WMI_DEVID_LED5 0x00020015
 #define ASUS_WMI_DEVID_LED6 0x00020016
 #define ASUS_WMI_DEVID_MICMUTE_LED 0x00040017
+#define ASUS_WMI_DEVID_CAMERA_LED_NEG 0x00060078
+#define ASUS_WMI_DEVID_CAMERA_LED 0x00060079
 
 /* Backlight and Brightness */
 #define ASUS_WMI_DEVID_ALS_ENABLE 0x00050001 /* Ambient Light Sensor */
Signature · 1 line
2.45.2

If Hans and Ilpo have no other comments regarding the written C code:

Quoted 1 line

Luke,

As I've seen you use S-o-b tag a few times like this, do you actually mean
Reviewed-by: tag which tells you've looked through the change and think it's good/useful for the kernel?

S-o-b relates to authorship of the code in the patch (and should be there right from the submission, not added like this).

Signature · 1 line
 i.
maintainer Reviewed-by
#3 lore raw
Quoted 114 lines · Ilpo Järvinen
Quoted 110 lines · Luke Jones
Quoted 106 lines · Devin Bayer

Adds a sysfs entry for the LED on F10 above the crossed out camera icon on 2023 Zenbooks.

v2
- Changed name from platform::camera to asus::camera
- Separated patch from patchset

v1
- https://lore.kernel.org/platform-driver-x86/[email protected]/

---
drivers/platform/x86/asus-wmi.c | 36 ++++++++++++++++++++++
include/linux/platform_data/x86/asus-wmi.h | 2 ++

2 files changed, 38 insertions(+)
drivers/platform/x86/asus-wmi.c +36 -0
index 3f07bbf809ef..20b7ed6a27b5 100644
@@ -73,6 +73,7 @@ module_param(fnlock_default, bool, 0444);
 #define NOTIFY_LID_FLIP_ROG 0xbd
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
+#define ASUS_WMI_DEVID_CAMERA_LED 0x00060079
 
 #define ASUS_MID_FAN_DESC "mid_fan"
 #define ASUS_GPU_FAN_DESC "gpu_fan"
@@ -227,6 +228,7 @@ struct asus_wmi {
 struct led_classdev lightbar_led;
 int lightbar_led_wk;
 struct led_classdev micmute_led;
+ struct led_classdev camera_led;
 struct workqueue_struct *led_workqueue;
 struct work_struct tpd_led_work;
 struct work_struct wlan_led_work;
@@ -1533,6 +1535,27 @@ static int micmute_led_set(struct led_classdev *led_cdev,
 return err < 0 ? err : 0;
 }
 
+static enum led_brightness camera_led_get(struct led_classdev *led_cdev)
+{
+ struct asus_wmi *asus;
+ u32 result;
+
+ asus = container_of(led_cdev, struct asus_wmi, camera_led);
+ asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CAMERA_LED, &result);
+
+ return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
+}
+
+static int camera_led_set(struct led_classdev *led_cdev,
+    enum led_brightness brightness)
+{
+ int state = brightness != LED_OFF;
+ int err;
+
+ err = asus_wmi_set_devstate(ASUS_WMI_DEVID_CAMERA_LED, state, NULL);
+ return err < 0 ? err : 0;
+}
+
 static void asus_wmi_led_exit(struct asus_wmi *asus)
 {
 led_classdev_unregister(&asus->kbd_led);
@@ -1540,6 +1563,7 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)
 led_classdev_unregister(&asus->wlan_led);
 led_classdev_unregister(&asus->lightbar_led);
 led_classdev_unregister(&asus->micmute_led);
+ led_classdev_unregister(&asus->camera_led);
 
 if (asus->led_workqueue)
 destroy_workqueue(asus->led_workqueue);
@@ -1631,6 +1655,18 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 goto error;
 }
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CAMERA_LED)) {
+ asus->camera_led.name = "asus::camera";
+ asus->camera_led.max_brightness = 1;
+ asus->camera_led.brightness_get = camera_led_get;
+ asus->camera_led.brightness_set_blocking = camera_led_set;
+
+ rv = led_classdev_register(&asus->platform_device->dev,
+ &asus->camera_led);
+ if (rv)
+ goto error;
+ }
+

error:
if (rv)
asus_wmi_led_exit(asus);

include/linux/platform_data/x86/asus-wmi.h +2 -0
index ab1c7deff118..fb0b00f7d292 100644
@@ -50,6 +50,8 @@
 #define ASUS_WMI_DEVID_LED5 0x00020015
 #define ASUS_WMI_DEVID_LED6 0x00020016
 #define ASUS_WMI_DEVID_MICMUTE_LED 0x00040017
+#define ASUS_WMI_DEVID_CAMERA_LED_NEG 0x00060078
+#define ASUS_WMI_DEVID_CAMERA_LED 0x00060079
 
 /* Backlight and Brightness */
 #define ASUS_WMI_DEVID_ALS_ENABLE 0x00050001 /* Ambient Light Sensor */
Signature · 1 line
2.45.2

If Hans and Ilpo have no other comments regarding the written C code:

Quoted 1 line
Quoted 8 lines

Luke,

As I've seen you use S-o-b tag a few times like this, do you actually mean
Reviewed-by: tag which tells you've looked through the change and think it's good/useful for the kernel?

S-o-b relates to authorship of the code in the patch (and should be there right from the submission, not added like this).

I do. Yes. It's been a tough couple of months.

Quoted 4 lines
Signature · 1 line
i.
maintainer
#4 lore raw
In reply to Devin Bayer
Quoted 1 line · Devin Bayer

Adds a sysfs entry for the LED on F10 above the crossed out camera icon on 2023 Zenbooks.

Please wrap paragraphs at 72 characters.

Quoted 29 lines

v2
- Changed name from platform::camera to asus::camera
- Separated patch from patchset

v1
- https://lore.kernel.org/platform-driver-x86/[email protected]/

---
 drivers/platform/x86/asus-wmi.c            | 36 ++++++++++++++++++++++
 include/linux/platform_data/x86/asus-wmi.h |  2 ++
 2 files changed, 38 insertions(+)
drivers/platform/x86/asus-wmi.c +1 -0
index 3f07bbf809ef..20b7ed6a27b5 100644
@@ -73,6 +73,7 @@ module_param(fnlock_default, bool, 0444);
 #define NOTIFY_LID_FLIP_ROG		0xbd
 
 #define ASUS_WMI_FNLOCK_BIOS_DISABLED	BIT(0)
+#define ASUS_WMI_DEVID_CAMERA_LED		0x00060079
 
include/linux/platform_data/x86/asus-wmi.h +0 -0
index ab1c7deff118..fb0b00f7d292 100644

include/linux/platform_data/x86/asus-wmi.h line 53

Quoted 4 lines
include/linux/platform_data/x86/asus-wmi.h +1 -0
@@ -50,6 +50,8 @@
 #define ASUS_WMI_DEVID_LED5		0x00020015
 #define ASUS_WMI_DEVID_LED6		0x00020016
 #define ASUS_WMI_DEVID_MICMUTE_LED		0x00040017
+#define ASUS_WMI_DEVID_CAMERA_LED_NEG		0x00060078

This is not used?

include/linux/platform_data/x86/asus-wmi.h line 54

Quoted 1 line
include/linux/platform_data/x86/asus-wmi.h +1 -0
+#define ASUS_WMI_DEVID_CAMERA_LED		0x00060079

Why is ASUS_WMI_DEVID_CAMERA_LED added here and into the .c file?

Signature · 1 line
 i.
#5 lore raw
Quoted 6 lines · Ilpo Järvinen
Quoted 2 lines · Devin Bayer

Adds a sysfs entry for the LED on F10 above the crossed out camera icon on 2023 Zenbooks.

Please wrap paragraphs at 72 characters.

OK.

Quoted 9 lines

include/linux/platform_data/x86/asus-wmi.h line 53

Quoted 7 lines
include/linux/platform_data/x86/asus-wmi.h +1 -0
@@ -50,6 +50,8 @@
 #define ASUS_WMI_DEVID_LED5		0x00020015
 #define ASUS_WMI_DEVID_LED6		0x00020016
 #define ASUS_WMI_DEVID_MICMUTE_LED		0x00040017
+#define ASUS_WMI_DEVID_CAMERA_LED_NEG		0x00060078

This is not used?

No, it does the same as CAMERA_LED but the values are opposite. I thought it would just be useful as documentation of the WMI functions.

Should I remove it?

Quoted 3 lines

include/linux/platform_data/x86/asus-wmi.h line 54

Quoted 1 line
include/linux/platform_data/x86/asus-wmi.h +1 -0
+#define ASUS_WMI_DEVID_CAMERA_LED		0x00060079

Why is ASUS_WMI_DEVID_CAMERA_LED added here and into the .c file?

That was a mistake, I used it for testing.

~ Dev