platform/x86: dell-privacy: Add support for Dell hardware privacy
Subsystems (2)
PATCH v5 1/2 platform/x86: dell-privacy: Add support for Dell hardware privacy
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmits SW_CAMERA_LENS_COVER event while the camera lens shutter will be changed by EC & hw(hadware) control
*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4) KEY_MICMUTE emitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and calls ledtrig_audio_set, like this:
ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);
7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated.
---
v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format for Kconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* export privacy_valid to make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* add KEY_END to keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print in dev_dbg
* remove __set_bit for the report keys from probe.
* fix keymap leak
* add err_free_keymap in dell_privacy_wmi_probe
* wmi driver will be unregistered if privacy_acpi_init() fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
---
--- .../testing/sysfs-platform-dell-privacy-wmi | 32 ++ drivers/platform/x86/dell/Kconfig | 16 + drivers/platform/x86/dell/Makefile | 3 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-acpi.c | 164 +++++++++ drivers/platform/x86/dell/dell-privacy-wmi.c | 340 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 35 ++ drivers/platform/x86/dell/dell-wmi.c | 27 +- 8 files changed, 627 insertions(+), 13 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-acpi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.h
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +32 -0
@@ -0,0 +1,32 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported +Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supported + “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: + - 0 = Not Supported + - 1 = Supported + - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacy Screen + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state +Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities + There are three Bits for available states: + - 0 = Enabled + - 1 = Disabled + - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacyScreen +
drivers/platform/x86/dell/Kconfig +16 -0
@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided as + hardware button Ctrl+F4 and Ctrl+F9 hotkey. + + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELL
drivers/platform/x86/dell/Makefile +3 -0
@@ -19,3 +19,6 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy.o +dell-privacy-objs := dell-privacy-wmi.o \ + dell-privacy-acpi.o
drivers/platform/x86/dell/dell-laptop.c +17 -6
@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;
@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );
@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (!privacy_valid) + has_privacy = true; +else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)
@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:
@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);
drivers/platform/x86/dell/dell-privacy-acpi.c new file +164 -0
164 lines not on this page · raw message
drivers/platform/x86/dell/dell-privacy-wmi.c new file +340 -0
340 lines not on this page · raw message
drivers/platform/x86/dell/dell-privacy-wmi.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +extern int privacy_valid; +int dell_privacy_state (void ); +void dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +int privacy_valid = -ENODEV ; +static inline int dell_privacy_state (void ) +{ +return privacy_valid; +} + +static inline void dell_privacy_process_event (int type,int code,int status) +{} +#endif /* CONFIG_DELL_PRIVACY */ + +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void ); + +/* DELL Privacy Type */ +enum { +DELL_PRIVACY_TYPE_UNKNOWN =0x0 , +DELL_PRIVACY_TYPE_AUDIO , +DELL_PRIVACY_TYPE_CAMERA , +}; +#endif
drivers/platform/x86/dell/dell-wmi.c +20 -7
@@ -13,20 +13,22 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/kernel.h> -#include <linux/module.h> +#include <linux/acpi.h> +#include <linux/dmi.h> #include <linux/init.h> -#include <linux/slab.h> -#include <linux/types.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> -#include <linux/acpi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> #include <linux/string.h> -#include <linux/dmi.h> +#include <linux/types.h> #include <linux/wmi.h> #include <acpi/video.h> +#include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );
@@ -381,6 +383,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int err;if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);
@@ -427,7 +430,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);
@@ -439,6 +441,17 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + err =dell_privacy_state (); +if (err ==0 ) { +dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]); + }else { +if (len >2 ) +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);
Signature · 1 line
2.25.1
Quoted 13 lines · Perry Yuan
From: Perry Yuan <[email protected]>
drivers/platform/x86/dell/Kconfig +2
-0@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support"
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 218
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+ depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided as
better:
are provided as
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 219
Quoted 1 line
drivers/platform/x86/dell/Kconfig +1
-0+ hardware button Ctrl+F4 and Ctrl+F9 hotkey.
Does that say that Ctrl+F4 is a hardware button and that Ctrl+F9 is a hotkey?
If so, what's the difference? and why? Are they different hardware implementations? Does the user care?
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 223
Quoted 4 lines
drivers/platform/x86/dell/Kconfig +3
-0+ + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELL
thanks.
Signature · 1 line
~Randy
Hi Randy.
Quoted 44 lines
-----Original Message-----
From: Randy Dunlap <[email protected]>
Sent: Tuesday, March 23, 2021 1:15 AM
To: Yuan, Perry; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
Quoted 14 lines · Perry Yuan
From: Perry Yuan <[email protected]>
drivers/platform/x86/dell/Kconfig +2
-0@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support"drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 218
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+ depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided asbetter:
are provided as
Quoted 5 lines
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 219
Quoted 1 line
drivers/platform/x86/dell/Kconfig +1
-0+ hardware button Ctrl+F4 and Ctrl+F9 hotkey.Does that say that Ctrl+F4 is a hardware button and that Ctrl+F9 is a hotkey? If so, what's the difference? and why? Are they different hardware implementations? Does the user care?
They all use the Ctrl button,
Ctrl +F4 requires that the Ctrl button and F4 button are pressed at the same time. F9+ctrl also have the same meaning. They are belonging to same hardware privacy solution, just use different keys combination to activate different privacy function .
Quoted 8 lines
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 223
Quoted 5 lines
drivers/platform/x86/dell/Kconfig +3
-0+ + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLthanks.
--
~Randy
Minor comments below.
Quoted 10 lines · Perry Yuan
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmits
typo: emits
Quoted 2 lines
SW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & hw(hadware) control
typo: hardware
Quoted 8 lines
*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:
Quoted 4 lines
ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated.
what happens if there is timeout? You have an explicit description of the timer handling in the success case, but not what happens on a timeout...
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 3
Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +3
-0@@ -0,0 +1,32 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported +Date: Feb 2021 +KernelVersion: 5.12
5.13 now?
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+static int dell_privacy_micmute_led_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct privacy_acpi_priv *priv = privacy_acpi; + acpi_status status; + acpi_handle handle; + static char *acpi_method = (char *)"ECAK"; + + handle = ec_get_handle(); + if (!handle)
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 23
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ return -EIO; + if (!acpi_has_method(handle, acpi_method)) + return -EIO; + status = acpi_evaluate_object(handle, acpi_method, NULL, NULL); + if (ACPI_FAILURE(status)) { + dev_err(priv->dev, "Error setting privacy EC ack value: %s\n", + acpi_format_exception(status)); + return -EIO; + } + pr_debug("set dell privacy micmute ec ack event done\n");
can we use dev_dbg() here? Same for all occurrences of pr_debug and pr_err below, it's cleaner and easier to filter.
Quoted 19 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +19
-0+ return 0; +} + +static int dell_privacy_acpi_remove(struct platform_device *pdev) +{ + struct privacy_acpi_priv *priv = dev_get_drvdata(privacy_acpi->dev); + + led_classdev_unregister(&priv->cdev); + + return 0; +} +/* + * Pressing the mute key activates a time delayed circuit to physically cut + * off the mute. The LED is in the same circuit, so it reflects the true + * state of the HW mute. The reason for the EC "ack" is so that software + * can first invoke a SW mute before the HW circuit is cut off. Without SW + * cutting this off first does not affect the time delayed muting or status + * of the LED but there is a possibility of a "popping" noise. + *
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ * If the EC receives the SW ack, the circuit will be activated before the + * delay completed. + * + * Exposing as an LED device allows the codec drivers notification path to + * EC ACK to work + */ +static int dell_privacy_leds_setup(struct device *dev) +{ + struct privacy_acpi_priv *priv = dev_get_drvdata(dev); + int ret = 0;
useless init
Quoted 13 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +13
-0+ + priv->cdev.name = "dell-privacy::micmute"; + priv->cdev.max_brightness = 1; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger = "audio-micmute"; + priv->cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE); + ret = devm_led_classdev_register(dev, &priv->cdev); + if (ret) + return ret; + return 0; +} + +static int dell_privacy_acpi_probe(struct platform_device *pdev)
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+{ + int ret; + + platform_set_drvdata(pdev, privacy_acpi); + privacy_acpi->dev = &pdev->dev; + privacy_acpi->platform_device = pdev; + + ret = dell_privacy_leds_setup(&pdev->dev); + if (ret) + return -EIO;
any reason to hard-code -EIO, woud 'return ret' be enough?
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 13 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +13
-0+ + return 0; +} + +static struct platform_driver dell_privacy_platform_drv = { + .driver = { + .name = PRIVACY_PLATFORM_NAME, + }, + .probe = dell_privacy_acpi_probe, + .remove = dell_privacy_acpi_remove, +}; + +int __init dell_privacy_acpi_init(void)
is the __init necessary? You call this routine from another which already has this qualifier.
Quoted 22 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +22
-0+{ + int err; + struct platform_device *pdev; + + if (!wmi_has_guid(DELL_PRIVACY_GUID)) + return -ENODEV; + + privacy_acpi = kzalloc(sizeof(*privacy_acpi), GFP_KERNEL); + if (!privacy_acpi) + return -ENOMEM; + + err = platform_driver_register(&dell_privacy_platform_drv); + if (err) + goto pdrv_err; + + pdev = platform_device_register_simple( + PRIVACY_PLATFORM_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(pdev)) { + err = PTR_ERR(pdev); + goto pdev_err; + } +
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ return 0; + +pdev_err: + platform_device_unregister(pdev); +pdrv_err: + kfree(privacy_acpi); + return err; +} + +void __exit dell_privacy_acpi_exit(void)
is the __exit required here?
Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +11
-0+{ + struct platform_device *pdev = to_platform_device(privacy_acpi->dev); + + platform_device_unregister(pdev); + platform_driver_unregister(&dell_privacy_platform_drv); + kfree(privacy_acpi); +} + +MODULE_AUTHOR("Perry Yuan <[email protected]>"); +MODULE_DESCRIPTION("DELL Privacy ACPI Driver"); +MODULE_LICENSE("GPL");
Hi,
Quoted 1 line · Pierre-Louis Bossart
Minor comments below.
<snip<
Quoted 3 lines
Quoted 1 line
+int
__initdell_privacy_acpi_init(void)is the
__initnecessary? You call this routine from another which already has this qualifier.
Yes this is necessary, all functions which are only used during module_load / from the module's init function must be marked as __init so that the kernel can unload them after module loading is done.
I do wonder if this one should not be static though (I've not looked at this patch in detail yet).
Quoted 27 lines
Quoted 27 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +26
-0+{ + int err; + struct platform_device *pdev; + + if (!wmi_has_guid(DELL_PRIVACY_GUID)) + return -ENODEV; + + privacy_acpi = kzalloc(sizeof(*privacy_acpi), GFP_KERNEL); + if (!privacy_acpi) + return -ENOMEM; + + err = platform_driver_register(&dell_privacy_platform_drv); + if (err) + goto pdrv_err; + + pdev = platform_device_register_simple( + PRIVACY_PLATFORM_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(pdev)) { + err = PTR_ERR(pdev); + goto pdev_err; + } + + return 0; + +pdev_err: + platform_device_unregister(pdev);
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-acpi.c line 153
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +6
-0+pdrv_err: + kfree(privacy_acpi); + return err; +} + +void __exit dell_privacy_acpi_exit(void)is the
__exitrequired here?
Idem. Also static ?
Regards,
Hans
Quoted 14 lines
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +11
-0+{ + struct platform_device *pdev = to_platform_device(privacy_acpi->dev); + + platform_device_unregister(pdev); + platform_driver_unregister(&dell_privacy_platform_drv); + kfree(privacy_acpi); +} + +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("DELL Privacy ACPI Driver" ); +MODULE_LICENSE ("GPL" );
Hi,
Quoted 96 lines · Perry Yuan
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmitsSW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & hw(hadware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated.
Signed-off-by Perry Yuan <[email protected]>---
v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
------ .../testing/sysfs-platform-dell-privacy-wmi | 32 ++ drivers/platform/x86/dell/Kconfig | 16 + drivers/platform/x86/dell/Makefile | 3 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-acpi.c | 164 +++++++++ drivers/platform/x86/dell/dell-privacy-wmi.c | 340 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 35 ++ drivers/platform/x86/dell/dell-wmi.c | 27 +- 8 files changed, 627 insertions(+), 13 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-acpi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.hDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +18
-0@@ -0,0 +1,32 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported +Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supported + “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: + - 0 = Not Supported + - 1 = Supported + - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacy Screen + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state +Date: Feb 2021
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 28
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities + There are three Bits for available states: + - 0 = Enabled + - 1 = Disabled
What is the definition of enabled/disabled ? Does enabled mean that the device is enabled, or that the device is in privacy mode, so in case of the microphone it is actually disabled (muted) ?
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 32
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacyScreen +
Normally we would use strings for something like this and not direclty export a bitfield, this would also allow avoiding the enabled / disabled ambiguity
E.g. you could have the following:
# supported devices $ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported Microphone Mute Camera Shutter ePrivacyScreen
# All devices in privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state Microphone muted Camera Shutter closed ePrivacyScreen privacy-filter enabled
# All devices in non-privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state Microphone unmuted Camera Shutter open ePrivacyScreen privacy-filter disabled
You can easily do the bitfield -> string mapping in the kernel by having 3 string arrays (support, privacy_on, privacy_off) indexed by the bitfield indices.
Quoted 11 lines
drivers/platform/x86/dell/Kconfig +3
-0@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPI
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 219
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+ depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided as + hardware button Ctrl+F4 and Ctrl+F9 hotkey.
This suggests that that the driver implements the buttons, which is not the case. How about:
This driver provides integration with the "Dell Hardware Privacy" feature of Dell laptops.
Quoted 37 lines
drivers/platform/x86/dell/Kconfig +3
-0+ + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +3
-0@@ -19,3 +19,6 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy.o +dell-privacy-objs := dell-privacy-wmi.o \ + dell-privacy-acpi.odrivers/platform/x86/dell/dell-laptop.c +3
-0@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );
drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void) · line 2212
Quoted 8 lines
drivers/platform/x86/dell/dell-laptop.c +1
-4@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (!privacy_valid)
This privacy_valid variable is coming from another module, so you're adding
a "privacy_valid" symbol to the global kernel symbol namespace, even though this is dell specific. Please use the dell_privacy_present() function (see below) instead, so you get:
if (dell_privacy_present()) has_privacy = true; else has_privacy = false;
Which makes much more sense then "if (!privacy_valid) has_privacy = true;" which feels as if it is inverted to what it should be.
Quoted 68 lines
drivers/platform/x86/dell/dell-laptop.c +13
-2+ has_privacy = true; + else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-acpi.c new file +30
-0@@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bits.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define PRIVACY_PLATFORM_NAME "dell-privacy-acpi" +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" + +struct privacy_acpi_priv {
drivers/platform/x86/dell/dell-privacy-acpi.c line 40
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+struct device *dev; +struct platform_device *platform_device; +struct led_classdev cdev; +}; +static struct privacy_acpi_priv *privacy_acpi; + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_acpi_priv *priv = privacy_acpi;
Please use container_of on the passed in led_cdev here instead of relying on a global variable.
Quoted 92 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +92
-0+acpi_status status; +acpi_handle handle; +static char *acpi_method = (char *)"ECAK" ; + + handle =ec_get_handle (); +if (!handle) +return -EIO ; +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { +dev_err (priv->dev,"Error setting privacy EC ack value: %s\n" , +acpi_format_exception (status)); +return -EIO ; + } +pr_debug ("set dell privacy micmute ec ack event done\n" ); +return 0 ; +} + +static int dell_privacy_acpi_remove (struct platform_device *pdev) +{ +struct privacy_acpi_priv *priv =dev_get_drvdata (privacy_acpi->dev); + +led_classdev_unregister (&priv->cdev); + +return 0 ; +} +/* +* Pressing the mute key activates a time delayed circuit to physically cut +* off the mute. The LED is in the same circuit, so it reflects the true +* state of the HW mute. The reason for the EC "ack" is so that software +* can first invoke a SW mute before the HW circuit is cut off. Without SW +* cutting this off first does not affect the time delayed muting or status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) +{ +struct privacy_acpi_priv *priv =dev_get_drvdata (dev); +int ret =0 ; + + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ; +} + +static int dell_privacy_acpi_probe (struct platform_device *pdev) +{ +int ret; + +platform_set_drvdata (pdev, privacy_acpi); + privacy_acpi->dev = &pdev->dev; + privacy_acpi->platform_device = pdev; + + ret =dell_privacy_leds_setup (&pdev->dev); +if (ret) +return -EIO ; + +return 0 ; +} + +static struct platform_driver dell_privacy_platform_drv = { + .driver = { + .name =PRIVACY_PLATFORM_NAME , + }, + .probe = dell_privacy_acpi_probe, + .remove = dell_privacy_acpi_remove, +}; + +int __init dell_privacy_acpi_init (void ) +{ +int err; +struct platform_device *pdev; + +if (!wmi_has_guid (DELL_PRIVACY_GUID )) +return -ENODEV ; + + privacy_acpi =kzalloc (sizeof (*privacy_acpi),GFP_KERNEL ); +if (!privacy_acpi) +return -ENOMEM ; +
drivers/platform/x86/dell/dell-privacy-acpi.c line 142
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+ err =platform_driver_register (&dell_privacy_platform_drv); +if (err) + goto pdrv_err; + + pdev =platform_device_register_simple ( +PRIVACY_PLATFORM_NAME ,PLATFORM_DEVID_NONE ,NULL ,0 ); +if (IS_ERR (pdev)) { + err =PTR_ERR (pdev); + goto pdev_err; + }
So you're creating a platform_device here, from code called from the init_dell_privacy() function in dell-privacy-wmi.c, just so that the probe() function for that platform-device can register the led_classdev for the (alternative) mute LED.
Please just put the cdev struct inside struct privacy_wmi_data and call dell_privacy_leds_setup() with the wmi-dev as parameter from dell_privacy_wmi_probe and have the wmi-dev as the parent of the led_classdev.
This allows removing both the platform-driver and the instantiation of the platform-device.
After removing the unnecessary platfrom-dev/driver there will be so little left of dell-privacy-acpi.c, that what remains can and should just be folded into dell-privacy-wmi.c. At which point you're down to one file for the module which also simplifies the Makefile.
Quoted 52 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +22
-0+ +return 0 ; + +pdev_err: +platform_device_unregister (pdev); +pdrv_err: +kfree (privacy_acpi); +return err; +} + +void __exit dell_privacy_acpi_exit(void) +{ +struct platform_device *pdev =to_platform_device (privacy_acpi->dev); + +platform_device_unregister (pdev); +platform_driver_unregister (&dell_privacy_platform_drv); +kfree (privacy_acpi); +} + +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("DELL Privacy ACPI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.c new file +24
-0@@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" +#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define PRIVACY_SCREEN_STATUS BIT(2) + +/*
drivers/platform/x86/dell/dell-privacy-wmi.c line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* The wmi_list is used to store the privacy_priv struct with mutex protecting +*/ +static LIST_HEAD (wmi_list); +static DEFINE_MUTEX (list_mutex); +/* +* global privacy state for other modules to query if the privacy driver loaded successfully +* or no privacy WMI device was detected at initial probe phase +*/ +int privacy_valid = -EPROBE_DEFER ; +EXPORT_SYMBOL_GPL (privacy_valid);
None of the callers are interpreting the error-codes stored here. So this is really treated as a bool, and the info stored in the bool is already available inside the wmi_list-head. So just drop this.
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +u32 features_present; +u32 last_status; +}; + +/* +* Keymap for WMI privacy events of type 0x0012
drivers/platform/x86/dell/dell-privacy-wmi.c line 55
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+*/ +static const struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +int dell_privacy_state (void )
Please rename this to dell_privacy_present(), "state" is very generic / not descriptive and use list_first_entry_or_null(&wmi_list) as done in dell_privacy_process_event(), e.g.:
bool dell_privacy_present(void)
{
struct privacy_wmi_data *priv;
mutex_lock(&list_mutex);
priv = list_first_entry_or_null(&wmi_list,
struct privacy_wmi_data,
list);
mutex_unlock(&list_mutex);
return priv;
}Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+{ +return privacy_valid; +} +EXPORT_SYMBOL_GPL (dell_privacy_state); +/* +* The flow of privacy event: +* 1) User presses key. HW does stuff with this key (timeout is started) +* 2) WMI event is emitted from BIOS +* 3) WMI event is received by dell-privacy
drivers/platform/x86/dell/dell-privacy-wmi.c line 74
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* 4) KEY_MICMUTE emitted from dell-privacy +* 5) Userland picks up key and modifies kcontrol for SW mute +* 6) Codec kernel driver catches and calls ledtrig_audio_set defined by +* dell-privacy-acpi driver. +* codec driver will call like this to switch micmute led state. +* ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ? LED_ON :LED_OFF); +* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +void dell_privacy_process_event (int type,int code,int status)
Please make this return a bool, returning true when it has consumed the event and false when it did not consume the event. This will allow other 0x0012 0xXXXX codes to still be handled by the existing dell-wmi.c code for this.
drivers/platform/x86/dell/dell-privacy-wmi.c line 77
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+{ +struct privacy_wmi_data *priv; +const struct key_entry *key;
bool ret = false;
Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); + goto error; + }
drivers/platform/x86/dell/dell-privacy-wmi.c line 96
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ key =sparse_keymap_entry_from_scancode (priv->input_dev, (type <<16 ) | code); +if (!key) { +dev_dbg (&priv->wdev->dev,"Unknown key with type 0x%04x and code 0x%04x pressed\n" , + type, code); + goto error; + } +switch (code) { +case DELL_PRIVACY_TYPE_AUDIO :/* Mic mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);
ret = true;
drivers/platform/x86/dell/dell-privacy-wmi.c line 100
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+break ; +case DELL_PRIVACY_TYPE_CAMERA :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);
ret = true;
drivers/platform/x86/dell/dell-privacy-wmi.c line 101
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+break ;
These 2 cases are exactly the same, please merge them into a single case.
drivers/platform/x86/dell/dell-privacy-wmi.c line 108
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+default : +dev_dbg (&priv->wdev->dev,"unknown event type 0x%04x 0x%04x" , + type, code); + } + +error: +mutex_unlock (&list_mutex);
return ret;
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t devices_supported_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->features_present);
drivers/platform/x86/dell/dell-privacy-wmi.c line 128
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static ssize_t current_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->last_status); +}
Please change these to emit strings as discussed above (assuming you agree with my above proposal for this).
Quoted 58 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +58
-0+ +static DEVICE_ATTR_RO (devices_supported); +static DEVICE_ATTR_RO (current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_devices_supported.attr, + &dev_attr_current_state.attr, +NULL , +}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +}; + +/* +* Describes the Device State class exposed by BIOS which can be consumed by +* various applications interested in knowing the Privacy feature capabilities. +* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen +* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen +* }; +*/ + +static int get_current_status (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); +return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; + privacy_valid = ret; +return ret; + } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + privacy_valid = ret; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior +*/ +if (obj_present->buffer.length !=8 ) {
drivers/platform/x86/dell/dell-privacy-wmi.c line 196
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+dev_err (&wdev->dev,"Dell privacy buffer has unexpected length (%d)!\n" , + obj_present->buffer.length); + ret = -EINVAL ; + privacy_valid = ret; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ]; + privacy_valid =0 ;
As discussed, there is no need for the privacy_valid variable, remove all references to it here.
Quoted 19 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +19
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */
drivers/platform/x86/dell/dell-privacy-wmi.c line 225
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL ); +if (!keymap) { + ret = -ENOMEM ; + goto err_free_dev; + }
No need for the goto here just simplify this to:
if (!keymap) return -ENOMEM;
drivers/platform/x86/dell/dell-privacy-wmi.c line 233
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + } + ret =sparse_keymap_setup (priv->input_dev, keymap,NULL );
You're done with the keymap here, please put a single:
kfree(keymap);
Here before the if (ret), then you won't need any goto style cleanup anywhere in this function.
This also fixes not free-ing the keymap when sparse_keymap_setup() fails.
drivers/platform/x86/dell/dell-privacy-wmi.c line 240
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+if (ret) +return ret; + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; +if (input_register_device (priv->input_dev)) { +pr_debug ("input_register_device failed to register!\n" );
You're not setting ret here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 242
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ goto err_free_keymap; + }
No need for the pr_debug, the kernel will already complain if this fails. Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:
ret = input_register_device(priv->input_dev); if (ret) returm ret;
drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex);
Move this to directly above the return 0; below, see below.
drivers/platform/x86/dell/dell-privacy-wmi.c line 248
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ +if (get_current_status (priv->wdev)) + goto err_free_input;
You're again not setting ret here before the goto.
And you are returning with an error here after adding the device to the wmi_list, the list_add_tail call should be done last, directly above the return 0 call.
Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:
ret = get_current_status(priv->wdev); if (ret) return ret;
drivers/platform/x86/dell/dell-privacy-wmi.c line 252
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+ + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) + goto err_free_input;
Replace the goto err_free_input() with return ret;
drivers/platform/x86/dell/dell-privacy-wmi.c line 254
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ +kfree (keymap);
Drop this kfree() (already done above now).
Move the list_add_tail() here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+return 0 ; + +err_free_input: +input_unregister_device (priv->input_dev);
This is not necessary for an input_device allocated with devm_input_allocate_device(), which means that none of these error handling labels are necessary now, so this can all be removed.
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+err_free_keymap: + privacy_valid = -ENODEV ; +kfree (keymap); +err_free_dev: +return ret; +}
drivers/platform/x86/dell/dell-privacy-wmi.c line 274
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +static int dell_privacy_wmi_remove (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); + privacy_valid = -ENODEV ; +input_unregister_device (priv->input_dev);
The input_unregister is not necessary (and privacy_valid is gone too).
Quoted 17 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +17
-0+ +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, +};
drivers/platform/x86/dell/dell-privacy-wmi.c line 302
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +static int __init init_dell_privacy (void ) +{ +int ret; + + ret = wmi_has_guid(DELL_PRIVACY_GUID);> + if (!ret) { + privacy_valid = -ENODEV ; +pr_debug ("Unable to detect available Dell privacy devices: %d\n" , ret); +return privacy_valid; + }
This driver will only get modprobed if the GUID is present and when it is not present then loading the driver is a no-op so this can be checked.
drivers/platform/x86/dell/dell-privacy-wmi.c line 314
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+ + ret =wmi_driver_register (&dell_privacy_wmi_driver); +if (ret) { +pr_err ("failed to initialize privacy wmi driver: %d\n" , ret); +return ret; + } + + ret =dell_privacy_acpi_init (); +if (ret) { +pr_err ("failed to initialize privacy acpi driver: %d\n" , ret); + goto err_init; + }
And with the platform-device/driver removed this is not necessary too, which means ...
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ +return 0 ; + +err_init: +wmi_driver_unregister (&dell_privacy_wmi_driver); +return ret; +} + +static void dell_privacy_wmi_exit (void ) +{ +wmi_driver_unregister (&dell_privacy_wmi_driver);
drivers/platform/x86/dell/dell-privacy-wmi.c line 335
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static void __exit exit_dell_privacy(void) +{ +dell_privacy_wmi_exit (); +dell_privacy_acpi_exit (); +} + +module_init (init_dell_privacy); +module_exit (exit_dell_privacy);
That all of the init_dell_privacy / exit_dell_privacy stuff can be replaced with a single line:
module_wmi_driver(&dell_privacy_wmi_driver);
Quoted 13 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+ +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.h new file +2
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/*
drivers/platform/x86/dell/dell-privacy-wmi.h line 12
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +extern int privacy_valid;
Please remove this from the global kernel namespace (make it a static global inside the dell-privacy-wmi.c code).
drivers/platform/x86/dell/dell-privacy-wmi.h line 16
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +4
-0+int dell_privacy_state (void ); +void dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +int privacy_valid = -ENODEV ;
Drop this.
drivers/platform/x86/dell/dell-privacy-wmi.h line 19
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +3
-0+static inline int dell_privacy_state (void ) +{ +return privacy_valid;
And directly return -ENODEV here.
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+} + +static inline void dell_privacy_process_event (int type,int code,int status) +{} +#endif /* CONFIG_DELL_PRIVACY */
drivers/platform/x86/dell/dell-privacy-wmi.h line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+ +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void ); + +/* DELL Privacy Type */ +enum { +DELL_PRIVACY_TYPE_UNKNOWN =0x0 , +DELL_PRIVACY_TYPE_AUDIO , +DELL_PRIVACY_TYPE_CAMERA , +};
This enum is only used inside dell-privacy-wmi.c, please move it there.
drivers/platform/x86/dell/dell-privacy-wmi.h line 35
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif
With the platform-device/driver removal discussed above all this header file needs to do is defines the prototypes / stubs for 2 functions:
int dell_privacy_state(void);
void dell_privacy_process_event(int type, int code, int status);
I think it would be best to just add these to dell-smbios.h, rather then adding a new header just for these 2 prototypes / stubs.
Quoted 17 lines
drivers/platform/x86/dell/dell-wmi.c +2
-4@@ -13,20 +13,22 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/kernel.h> -#include <linux/module.h> +#include <linux/acpi.h> +#include <linux/dmi.h> #include <linux/init.h> -#include <linux/slab.h> -#include <linux/types.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h>
drivers/platform/x86/dell/dell-wmi.c line 28
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi.c +5
-2-#include <linux/acpi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> #include <linux/string.h> -#include <linux/dmi.h> +#include <linux/types.h> #include <linux/wmi.h> #include <acpi/video.h> +
Please split the changes sorting these includes alphabetically out into a separate cleanup patch.
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 386
Quoted 11 lines
drivers/platform/x86/dell/dell-wmi.c +2
-0#include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );@@ -381,6 +383,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int err;
Drop this.
Quoted 12 lines
drivers/platform/x86/dell/dell-wmi.c +0
-1if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);@@ -427,7 +430,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 448
Quoted 8 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0@@ -439,6 +441,17 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + err =dell_privacy_state (); +if (err ==0 ) { +dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]);
This needs a len > 4 check !
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 453
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0+ }else { +if (len >2 ) +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + }
Combined with the change to have dell_privacy_process_event() return a bool, this should look something like this:
if (len > 4 && dell_privacy_process_event(buffer_entry[1], buffer_entry[3], buffer_entry[4])) ; /* Handled by dell_privacy_process_event() */ else if (len > 2) dell_wmi_process_key(wdev, buffer_entry[1], buffer_entry[2]);
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 457
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +1
-0+break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);
Regards,
Hans
Hi,
Quoted 29 lines · Hans de Goede
Hi,
Quoted 26 lines · Perry Yuan
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmitsSW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & hw(hadware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated.
Signed-off-by Perry Yuan <[email protected]>
One last remark, I think that the dell_privacy_present() function which I suggested in my review should be renamed to:
dell_privacy_has_micmute() and then its return should check the micmute feature bit in priv->features_present and this new function should then be used in dell-laptop.c to determine it dell-laptop.c should register its own mic-mute led_classdev.
This way if a theoretical future laptop shows up where the micmute feature is not implemented by the privacy interface dell-laptop.c will still register the non-privacy mic-mute led_classdev.
Regards,
Hans
Quoted 1,067 lines
Quoted 70 lines
---
v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
------ .../testing/sysfs-platform-dell-privacy-wmi | 32 ++ drivers/platform/x86/dell/Kconfig | 16 + drivers/platform/x86/dell/Makefile | 3 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-acpi.c | 164 +++++++++ drivers/platform/x86/dell/dell-privacy-wmi.c | 340 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 35 ++ drivers/platform/x86/dell/dell-wmi.c | 27 +- 8 files changed, 627 insertions(+), 13 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-acpi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.hDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +18
-0@@ -0,0 +1,32 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported +Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supported + “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: + - 0 = Not Supported + - 1 = Supported + - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacy Screen + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state +Date: Feb 2021Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 28
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities + There are three Bits for available states: + - 0 = Enabled + - 1 = DisabledWhat is the definition of enabled/disabled ? Does enabled mean that the device is enabled, or that the device is in privacy mode, so in case of the microphone it is actually disabled (muted) ?
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 32
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacyScreen +Normally we would use strings for something like this and not direclty export a bitfield, this would also allow avoiding the enabled / disabled ambiguity
E.g. you could have the following:
# supported devices $ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported Microphone Mute Camera Shutter ePrivacyScreen# All devices in privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state Microphone muted Camera Shutter closed ePrivacyScreen privacy-filter enabled# All devices in non-privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state Microphone unmuted Camera Shutter open ePrivacyScreen privacy-filter disabledYou can easily do the bitfield -> string mapping in the kernel by having 3 string arrays (support,
privacy_on,privacy_off) indexed by the bitfield indices.Quoted 11 lines
drivers/platform/x86/dell/Kconfig +3
-0@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPIdrivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 219
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+ depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided as + hardware button Ctrl+F4 and Ctrl+F9 hotkey.This suggests that that the driver implements the buttons, which is not the case. How about:
This driver provides integration with the "Dell Hardware Privacy" feature of Dell laptops.
Quoted 37 lines
drivers/platform/x86/dell/Kconfig +3
-0+ + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +3
-0@@ -19,3 +19,6 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy.o +dell-privacy-objs := dell-privacy-wmi.o \ + dell-privacy-acpi.odrivers/platform/x86/dell/dell-laptop.c +3
-0@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void) · line 2212
Quoted 8 lines
drivers/platform/x86/dell/dell-laptop.c +1
-4@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (!privacy_valid)This
privacy_validvariable is coming from another module, so you're adding
a "privacy_valid" symbol to the global kernel symbol namespace, even though this is dell specific. Please use thedell_privacy_present()function (see below) instead, so you get:if (dell_privacy_present()) has_privacy = true; else has_privacy = false;Which makes much more sense then "if (!privacy_valid)
has_privacy= true;" which feels as if it is inverted to what it should be.Quoted 68 lines
drivers/platform/x86/dell/dell-laptop.c +13
-2+ has_privacy = true; + else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-acpi.c new file +30
-0@@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bits.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define PRIVACY_PLATFORM_NAME "dell-privacy-acpi" +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" + +struct privacy_acpi_priv {drivers/platform/x86/dell/dell-privacy-acpi.c line 40
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+struct device *dev; +struct platform_device *platform_device; +struct led_classdev cdev; +}; +static struct privacy_acpi_priv *privacy_acpi; + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_acpi_priv *priv = privacy_acpi;Please use
container_ofon the passed inled_cdevhere instead of relying on a global variable.Quoted 92 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +92
-0+acpi_status status; +acpi_handle handle; +static char *acpi_method = (char *)"ECAK" ; + + handle =ec_get_handle (); +if (!handle) +return -EIO ; +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { +dev_err (priv->dev,"Error setting privacy EC ack value: %s\n" , +acpi_format_exception (status)); +return -EIO ; + } +pr_debug ("set dell privacy micmute ec ack event done\n" ); +return 0 ; +} + +static int dell_privacy_acpi_remove (struct platform_device *pdev) +{ +struct privacy_acpi_priv *priv =dev_get_drvdata (privacy_acpi->dev); + +led_classdev_unregister (&priv->cdev); + +return 0 ; +} +/* +* Pressing the mute key activates a time delayed circuit to physically cut +* off the mute. The LED is in the same circuit, so it reflects the true +* state of the HW mute. The reason for the EC "ack" is so that software +* can first invoke a SW mute before the HW circuit is cut off. Without SW +* cutting this off first does not affect the time delayed muting or status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) +{ +struct privacy_acpi_priv *priv =dev_get_drvdata (dev); +int ret =0 ; + + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ; +} + +static int dell_privacy_acpi_probe (struct platform_device *pdev) +{ +int ret; + +platform_set_drvdata (pdev, privacy_acpi); + privacy_acpi->dev = &pdev->dev; + privacy_acpi->platform_device = pdev; + + ret =dell_privacy_leds_setup (&pdev->dev); +if (ret) +return -EIO ; + +return 0 ; +} + +static struct platform_driver dell_privacy_platform_drv = { + .driver = { + .name =PRIVACY_PLATFORM_NAME , + }, + .probe = dell_privacy_acpi_probe, + .remove = dell_privacy_acpi_remove, +}; + +int __init dell_privacy_acpi_init (void ) +{ +int err; +struct platform_device *pdev; + +if (!wmi_has_guid (DELL_PRIVACY_GUID )) +return -ENODEV ; + + privacy_acpi =kzalloc (sizeof (*privacy_acpi),GFP_KERNEL ); +if (!privacy_acpi) +return -ENOMEM ; +drivers/platform/x86/dell/dell-privacy-acpi.c line 142
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+ err =platform_driver_register (&dell_privacy_platform_drv); +if (err) + goto pdrv_err; + + pdev =platform_device_register_simple ( +PRIVACY_PLATFORM_NAME ,PLATFORM_DEVID_NONE ,NULL ,0 ); +if (IS_ERR (pdev)) { + err =PTR_ERR (pdev); + goto pdev_err; + }So you're creating a
platform_devicehere, from code called from theinit_dell_privacy()function indell-privacy-wmi.c, just so that theprobe()function for that platform-device can register theled_classdevfor the (alternative) mute LED.Please just put the cdev struct inside struct
privacy_wmi_dataand calldell_privacy_leds_setup()with the wmi-dev as parameter fromdell_privacy_wmi_probeand have the wmi-dev as the parent of theled_classdev.This allows removing both the platform-driver and the instantiation of the platform-device.
After removing the unnecessary platfrom-dev/driver there will be so little left of
dell-privacy-acpi.c, that what remains can and should just be folded intodell-privacy-wmi.c. At which point you're down to one file for the module which also simplifies theMakefile.Quoted 52 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +22
-0+ +return 0 ; + +pdev_err: +platform_device_unregister (pdev); +pdrv_err: +kfree (privacy_acpi); +return err; +} + +void __exit dell_privacy_acpi_exit(void) +{ +struct platform_device *pdev =to_platform_device (privacy_acpi->dev); + +platform_device_unregister (pdev); +platform_driver_unregister (&dell_privacy_platform_drv); +kfree (privacy_acpi); +} + +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("DELL Privacy ACPI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.c new file +24
-0@@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" +#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define PRIVACY_SCREEN_STATUS BIT(2) + +/* drivers/platform/x86/dell/dell-privacy-wmi.c line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* The wmi_list is used to store the privacy_priv struct with mutex protecting +*/ +static LIST_HEAD (wmi_list); +static DEFINE_MUTEX (list_mutex); +/* +* global privacy state for other modules to query if the privacy driver loaded successfully +* or no privacy WMI device was detected at initial probe phase +*/ +int privacy_valid = -EPROBE_DEFER ; +EXPORT_SYMBOL_GPL (privacy_valid);None of the callers are interpreting the error-codes stored here. So this is really treated as a bool, and the info stored in the bool is already available inside the wmi_list-head. So just drop this.
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +u32 features_present; +u32 last_status; +}; + +/* +* Keymap for WMI privacy events of type 0x0012 drivers/platform/x86/dell/dell-privacy-wmi.c line 55
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+*/ +static const struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +int dell_privacy_state (void )Please rename this to
dell_privacy_present(), "state" is very generic / not descriptive and uselist_first_entry_or_null(&wmi_list)as done indell_privacy_process_event(), e.g.:bool
dell_privacy_present(void){ struct privacy_wmi_data *priv; mutex_lock(&list_mutex); priv = list_first_entry_or_null(&wmi_list, struct privacy_wmi_data, list); mutex_unlock(&list_mutex); return priv; }Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+{ +return privacy_valid; +} +EXPORT_SYMBOL_GPL (dell_privacy_state); +/* +* The flow of privacy event: +* 1) User presses key. HW does stuff with this key (timeout is started) +* 2) WMI event is emitted from BIOS +* 3) WMI event is received by dell-privacy drivers/platform/x86/dell/dell-privacy-wmi.c line 74
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* 4) KEY_MICMUTE emitted from dell-privacy +* 5) Userland picks up key and modifies kcontrol for SW mute +* 6) Codec kernel driver catches and calls ledtrig_audio_set defined by +* dell-privacy-acpi driver. +* codec driver will call like this to switch micmute led state. +* ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ? LED_ON :LED_OFF); +* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +void dell_privacy_process_event (int type,int code,int status)Please make this return a bool, returning true when it has consumed the event and false when it did not consume the event. This will allow other
0x00120xXXXX codes to still be handled by the existingdell-wmi.ccode for this.drivers/platform/x86/dell/dell-privacy-wmi.c line 77
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+{ +struct privacy_wmi_data *priv; +const struct key_entry *key;bool ret = false;Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); + goto error; + }drivers/platform/x86/dell/dell-privacy-wmi.c line 96
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ key =sparse_keymap_entry_from_scancode (priv->input_dev, (type <<16 ) | code); +if (!key) { +dev_dbg (&priv->wdev->dev,"Unknown key with type 0x%04x and code 0x%04x pressed\n" , + type, code); + goto error; + } +switch (code) { +case DELL_PRIVACY_TYPE_AUDIO :/* Mic mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);ret = true;drivers/platform/x86/dell/dell-privacy-wmi.c line 100
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+break ; +case DELL_PRIVACY_TYPE_CAMERA :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);ret = true;drivers/platform/x86/dell/dell-privacy-wmi.c line 101
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+break ;These 2 cases are exactly the same, please merge them into a single case.
drivers/platform/x86/dell/dell-privacy-wmi.c line 108
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+default : +dev_dbg (&priv->wdev->dev,"unknown event type 0x%04x 0x%04x" , + type, code); + } + +error: +mutex_unlock (&list_mutex);return ret;Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t devices_supported_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->features_present);drivers/platform/x86/dell/dell-privacy-wmi.c line 128
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static ssize_t current_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->last_status); +}Please change these to emit strings as discussed above (assuming you agree with my above proposal for this).
Quoted 58 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +58
-0+ +static DEVICE_ATTR_RO (devices_supported); +static DEVICE_ATTR_RO (current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_devices_supported.attr, + &dev_attr_current_state.attr, +NULL , +}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +}; + +/* +* Describes the Device State class exposed by BIOS which can be consumed by +* various applications interested in knowing the Privacy feature capabilities. +* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen +* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen +* }; +*/ + +static int get_current_status (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); +return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; + privacy_valid = ret; +return ret; + } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + privacy_valid = ret; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior +*/ +if (obj_present->buffer.length !=8 ) {drivers/platform/x86/dell/dell-privacy-wmi.c line 196
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+dev_err (&wdev->dev,"Dell privacy buffer has unexpected length (%d)!\n" , + obj_present->buffer.length); + ret = -EINVAL ; + privacy_valid = ret; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ]; + privacy_valid =0 ;As discussed, there is no need for the
privacy_validvariable, remove all references to it here.Quoted 19 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +19
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ drivers/platform/x86/dell/dell-privacy-wmi.c line 225
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL ); +if (!keymap) { + ret = -ENOMEM ; + goto err_free_dev; + }No need for the goto here just simplify this to:
if (!keymap) return -ENOMEM;drivers/platform/x86/dell/dell-privacy-wmi.c line 233
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + } + ret =sparse_keymap_setup (priv->input_dev, keymap,NULL );You're done with the keymap here, please put a single:
kfree(keymap);Here before the if (ret), then you won't need any goto style cleanup anywhere in this function.
This also fixes not free-ing the keymap when
sparse_keymap_setup()fails.drivers/platform/x86/dell/dell-privacy-wmi.c line 240
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+if (ret) +return ret; + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; +if (input_register_device (priv->input_dev)) { +pr_debug ("input_register_device failed to register!\n" );You're not setting ret here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 242
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ goto err_free_keymap; + }No need for the
pr_debug, the kernel will already complain if this fails. Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:ret = input_register_device(priv->input_dev); if (ret) returm ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex);Move this to directly above the return 0; below, see below.
drivers/platform/x86/dell/dell-privacy-wmi.c line 248
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ +if (get_current_status (priv->wdev)) + goto err_free_input;You're again not setting ret here before the goto.
And you are returning with an error here after adding the device to the
wmi_list, thelist_add_tailcall should be done last, directly above the return 0 call.Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:
ret = get_current_status(priv->wdev); if (ret) return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 252
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+ + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) + goto err_free_input;Replace the goto
err_free_input()with return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 254
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ +kfree (keymap);Drop this
kfree()(already done above now).Move the
list_add_tail()here.drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+return 0 ; + +err_free_input: +input_unregister_device (priv->input_dev);This is not necessary for an
input_deviceallocated withdevm_input_allocate_device(), which means that none of these error handling labels are necessary now, so this can all be removed.Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+err_free_keymap: + privacy_valid = -ENODEV ; +kfree (keymap); +err_free_dev: +return ret; +}drivers/platform/x86/dell/dell-privacy-wmi.c line 274
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +static int dell_privacy_wmi_remove (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); + privacy_valid = -ENODEV ; +input_unregister_device (priv->input_dev);The
input_unregisteris not necessary (andprivacy_validis gone too).Quoted 17 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +17
-0+ +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, +};drivers/platform/x86/dell/dell-privacy-wmi.c line 302
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +static int __init init_dell_privacy (void ) +{ +int ret; + + ret = wmi_has_guid(DELL_PRIVACY_GUID);> + if (!ret) { + privacy_valid = -ENODEV ; +pr_debug ("Unable to detect available Dell privacy devices: %d\n" , ret); +return privacy_valid; + }This driver will only get modprobed if the GUID is present and when it is not present then loading the driver is a no-op so this can be checked.
drivers/platform/x86/dell/dell-privacy-wmi.c line 314
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+ + ret =wmi_driver_register (&dell_privacy_wmi_driver); +if (ret) { +pr_err ("failed to initialize privacy wmi driver: %d\n" , ret); +return ret; + } + + ret =dell_privacy_acpi_init (); +if (ret) { +pr_err ("failed to initialize privacy acpi driver: %d\n" , ret); + goto err_init; + }And with the platform-device/driver removed this is not necessary too, which means ...
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ +return 0 ; + +err_init: +wmi_driver_unregister (&dell_privacy_wmi_driver); +return ret; +} + +static void dell_privacy_wmi_exit (void ) +{ +wmi_driver_unregister (&dell_privacy_wmi_driver);drivers/platform/x86/dell/dell-privacy-wmi.c line 335
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static void __exit exit_dell_privacy(void) +{ +dell_privacy_wmi_exit (); +dell_privacy_acpi_exit (); +} + +module_init (init_dell_privacy); +module_exit (exit_dell_privacy);That all of the
init_dell_privacy/exit_dell_privacystuff can be replaced with a single line:
module_wmi_driver(&dell_privacy_wmi_driver);Quoted 13 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+ +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.h new file +2
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* drivers/platform/x86/dell/dell-privacy-wmi.h line 12
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +extern int privacy_valid;Please remove this from the global kernel namespace (make it a static global inside the
dell-privacy-wmi.ccode).drivers/platform/x86/dell/dell-privacy-wmi.h line 16
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +4
-0+int dell_privacy_state (void ); +void dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +int privacy_valid = -ENODEV ;Drop this.
drivers/platform/x86/dell/dell-privacy-wmi.h line 19
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +3
-0+static inline int dell_privacy_state (void ) +{ +return privacy_valid;And directly return
-ENODEVhere.Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+} + +static inline void dell_privacy_process_event (int type,int code,int status) +{} +#endif /* CONFIG_DELL_PRIVACY */ drivers/platform/x86/dell/dell-privacy-wmi.h line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+ +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void ); + +/* DELL Privacy Type */ +enum { +DELL_PRIVACY_TYPE_UNKNOWN =0x0 , +DELL_PRIVACY_TYPE_AUDIO , +DELL_PRIVACY_TYPE_CAMERA , +};This enum is only used inside
dell-privacy-wmi.c, please move it there.drivers/platform/x86/dell/dell-privacy-wmi.h line 35
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif With the platform-device/driver removal discussed above all this header file needs to do is defines the prototypes / stubs for 2 functions:
int
dell_privacy_state(void);
voiddell_privacy_process_event(int type, int code, int status);I think it would be best to just add these to
dell-smbios.h, rather then adding a new header just for these 2 prototypes / stubs.Quoted 17 lines
drivers/platform/x86/dell/dell-wmi.c +2
-4@@ -13,20 +13,22 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/kernel.h> -#include <linux/module.h> +#include <linux/acpi.h> +#include <linux/dmi.h> #include <linux/init.h> -#include <linux/slab.h> -#include <linux/types.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> drivers/platform/x86/dell/dell-wmi.c line 28
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi.c +5
-2-#include <linux/acpi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> #include <linux/string.h> -#include <linux/dmi.h> +#include <linux/types.h> #include <linux/wmi.h> #include <acpi/video.h> +Please split the changes sorting these includes alphabetically out into a separate cleanup patch.
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 386
Quoted 11 lines
drivers/platform/x86/dell/dell-wmi.c +2
-0#include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );@@ -381,6 +383,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int err;Drop this.
Quoted 12 lines
drivers/platform/x86/dell/dell-wmi.c +0
-1if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);@@ -427,7 +430,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 448
Quoted 8 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0@@ -439,6 +441,17 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + err =dell_privacy_state (); +if (err ==0 ) { +dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]);This needs a len > 4 check !
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 453
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0+ }else { +if (len >2 ) +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + }Combined with the change to have
dell_privacy_process_event()return a bool, this should look something like this:if (len > 4 && dell_privacy_process_event(buffer_entry[1], buffer_entry[3], buffer_entry[4])) ; /* Handled by dell_privacy_process_event() */ else if (len > 2) dell_wmi_process_key(wdev, buffer_entry[1], buffer_entry[2]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 457
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +1
-0+break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);Regards,
Hans
Hi Hans.
Quoted 70 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Wednesday, March 24, 2021 3:40 AM
To: Pierre-Louis Bossart; Yuan, Perry; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
Hi,
Quoted 1 line · Pierre-Louis Bossart
Minor comments below.
<snip<
Quoted 3 lines
Quoted 1 line
+int
__initdell_privacy_acpi_init(void)is the
__initnecessary? You call this routine from another which already hasthis qualifier.
Yes this is necessary, all functions which are only used during
module_load/ from the module's init function must be marked as__initso that the kernel can unload them after module loading is done.I do wonder if this one should not be static though (I've not looked at this patch in detail yet).
Quoted 27 lines
Quoted 27 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +26
-0+{ + int err; + struct platform_device *pdev; + + if (!wmi_has_guid(DELL_PRIVACY_GUID)) + return -ENODEV; + + privacy_acpi = kzalloc(sizeof(*privacy_acpi), GFP_KERNEL); + if (!privacy_acpi) + return -ENOMEM; + + err = platform_driver_register(&dell_privacy_platform_drv); + if (err) + goto pdrv_err; + + pdev = platform_device_register_simple( + PRIVACY_PLATFORM_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(pdev)) { + err = PTR_ERR(pdev); + goto pdev_err; + } + + return 0; + +pdev_err: + platform_device_unregister(pdev);Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-acpi.c line 153
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +6
-0+pdrv_err: + kfree(privacy_acpi); + return err; +} + +void __exit dell_privacy_acpi_exit(void)is the
__exitrequired here?
Quoted 6 lines
Idem. Also static ?
Regards,
Hans
If adding static to the function, I will be worried about that the init and exit cannot be called by another file .
Quoted 17 lines
Quoted 17 lines
Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +12
-0+{ + struct platform_device *pdev = +to_platform_device (privacy_acpi->dev); + + platform_device_unregister(pdev); + platform_driver_unregister(&dell_privacy_platform_drv); + kfree(privacy_acpi); +} + +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("DELL Privacy ACPI Driver" ); +MODULE_LICENSE ("GPL" );
Hi,
Quoted 72 lines · Perry
Hi Hans.
Quoted 70 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Wednesday, March 24, 2021 3:40 AM
To: Pierre-Louis Bossart; Yuan, Perry; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
Hi,
Quoted 1 line · Pierre-Louis Bossart
Minor comments below.
<snip<
Quoted 3 lines
Quoted 1 line
+int
__initdell_privacy_acpi_init(void)is the
__initnecessary? You call this routine from another which already hasthis qualifier.
Yes this is necessary, all functions which are only used during
module_load/ from the module's init function must be marked as__initso that the kernel can unload them after module loading is done.I do wonder if this one should not be static though (I've not looked at this patch in detail yet).
Quoted 35 lines
Quoted 23 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +22
-0+{ + int err; + struct platform_device *pdev; + + if (!wmi_has_guid(DELL_PRIVACY_GUID)) + return -ENODEV; + + privacy_acpi = kzalloc(sizeof(*privacy_acpi), GFP_KERNEL); + if (!privacy_acpi) + return -ENOMEM; + + err = platform_driver_register(&dell_privacy_platform_drv); + if (err) + goto pdrv_err; + + pdev = platform_device_register_simple( + PRIVACY_PLATFORM_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(pdev)) { + err = PTR_ERR(pdev); + goto pdev_err; + } +drivers/platform/x86/dell/dell-privacy-acpi.c line 153
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+ return 0; + +pdev_err: + platform_device_unregister(pdev); +pdrv_err: + kfree(privacy_acpi); + return err; +} + +void __exit dell_privacy_acpi_exit(void)is the
__exitrequired here?
Quoted 8 lines
Quoted 6 lines
Idem. Also static ?
Regards,
Hans
If adding static to the function, I will be worried about that the init and exit cannot be called by another file .
That is right, which is why I added the "?".
But this is no longer relevant after my detailed review of the patch, so lets discuss things further in the detailed review email-thread.
Regards,
Hans
Hi Hans.
Reviewing your feedback and working on next version below
Quoted 1,141 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Wednesday, March 24, 2021 7:19 PM
To: Yuan, Perry; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
Hi,
Quoted 80 lines · Perry Yuan
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmits
SW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & hw(hadware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated.
Signed-off-by Perry Yuan <[email protected]>---
v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
------ .../testing/sysfs-platform-dell-privacy-wmi | 32 ++ drivers/platform/x86/dell/Kconfig | 16 + drivers/platform/x86/dell/Makefile | 3 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-acpi.c | 164 +++++++++ drivers/platform/x86/dell/dell-privacy-wmi.c | 340 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 35 ++ drivers/platform/x86/dell/dell-wmi.c | 27 +- 8 files changed, 627 insertions(+), 13 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-acpi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.hDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +0
-0Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0@@ -0,0 +1,32 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 5 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +5
-0+Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices aresupported
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 7
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ “Dell Privacy” is a set of HW, FW, and SW features toenhance
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: + - 0 = Not Supported + - 1 = Supported + - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacy Screen + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0+Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which canbe
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 24
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ consumed by various applications interested in knowing thePrivacy
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 28
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ feature capabilities + There are three Bits for available states: + - 0 = Enabled + - 1 = DisabledWhat is the definition of enabled/disabled ? Does enabled mean that the device is enabled, or that the device is in privacy mode, so in case of the microphone it is actually disabled (muted) ?
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 32
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacyScreen +Normally we would use strings for something like this and not direclty export a bitfield, this would also allow avoiding the enabled / disabled ambiguity
E.g. you could have the following:
# supported devices $ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988- D3AB0A901919/devices_supported Microphone Mute Camera Shutter ePrivacyScreen# All devices in privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988- D3AB0A901919/current_state Microphone muted Camera Shutter closed ePrivacyScreen privacy-filter enabled# All devices in non-privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988- D3AB0A901919/current_state Microphone unmuted Camera Shutter open ePrivacyScreen privacy-filter disabledYou can easily do the bitfield -> string mapping in the kernel by having 3 string arrays (support,
privacy_on,privacy_off) indexed by the bitfield indices.Quoted 12 lines
drivers/platform/x86/dell/Kconfig +3
-0@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPIdrivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 219
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+ depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided as + hardware button Ctrl+F4 and Ctrl+F9 hotkey.This suggests that that the driver implements the buttons, which is not the case. How about:
This driver provides integration with the "Dell Hardware Privacy"
feature
of Dell laptops.drivers/platform/x86/dell/Makefile obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +3
-0+ + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +0
-0@@ -19,3 +19,6 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o
Quoted 29 lines
drivers/platform/x86/dell/Makefile +3
-0obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy.o +dell-privacy-objs := dell-privacy-wmi.o \ + dell-privacy-acpi.odrivers/platform/x86/dell/dell-laptop.c +2
-0@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill; static structrfkill
*bluetooth_rfkill; static struct rfkill*wwan_rfkill; static boolforce_rfkill;
+static boolhas_privacy;
module_param(force_rfkill, bool, 0444);MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models"); @@ -2206,10 +2209,16 @@ static int__initdell_init(void)drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void)
Quoted 3 lines
drivers/platform/x86/dell/dell-laptop.c +0
-1if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =
ledtrig_audio_get(LED_AUDIO_MICMUTE);drivers/platform/x86/dell/dell-laptop.c
Quoted 1 line
drivers/platform/x86/dell/dell-laptop.c +0
-1- ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void) · line 2212
Quoted 3 lines
drivers/platform/x86/dell/dell-laptop.c +1
-2-if (ret <0 ) - goto fail_led; +if (!privacy_valid)This
privacy_validvariable is coming from another module, so you're adding a "privacy_valid" symbol to the global kernel symbol namespace, even though this is dell specific. Please use thedell_privacy_present()function (see below) instead, so you get:if (dell_privacy_present()) has_privacy = true; else has_privacy = false;Which makes much more sense then "if (!privacy_valid)
has_privacy= true;" which feels as if it is inverted to what it should be.drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void)
Quoted 5 lines
drivers/platform/x86/dell/dell-laptop.c +5
-0+ has_privacy = true; + else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =
ledtrig_audio_get(LED_AUDIO_MICMUTE);drivers/platform/x86/dell/dell-laptop.c
Quoted 1 line
drivers/platform/x86/dell/dell-laptop.c +1
-0+ ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);Quoted 51 lines
drivers/platform/x86/dell/dell-laptop.c +7
-3+if (ret <0 ) + goto fail_led; + } } if (acpi_video_get_backlight_type() != acpi_backlight_vendor) @@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-acpi.c new file +18
-0@@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bits.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> drivers/platform/x86/dell/dell-privacy-acpi.c line 28
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define PRIVACY_PLATFORM_NAME "dell-privacy-acpi" +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919"
drivers/platform/x86/dell/dell-privacy-acpi.c line 40
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +12
-0+ +struct privacy_acpi_priv { +struct device *dev; +struct platform_device *platform_device; +struct led_classdev cdev; +}; +static struct privacy_acpi_priv *privacy_acpi; + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_acpi_priv *priv = privacy_acpi;Please use
container_ofon the passed inled_cdevhere instead of relying on a global variable.Quoted 91 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +91
-0+acpi_status status; +acpi_handle handle; +static char *acpi_method = (char *)"ECAK" ; + + handle =ec_get_handle (); +if (!handle) +return -EIO ; +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { +dev_err (priv->dev,"Error setting privacy EC ack value: %s\n" , +acpi_format_exception (status)); +return -EIO ; + } +pr_debug ("set dell privacy micmute ec ack event done\n" ); +return 0 ; +} + +static int dell_privacy_acpi_remove (struct platform_device *pdev) { +struct privacy_acpi_priv *priv =dev_get_drvdata (privacy_acpi->dev); + +led_classdev_unregister (&priv->cdev); + +return 0 ; +} +/* +* Pressing the mute key activates a time delayed circuit to +physically cut +* off the mute. The LED is in the same circuit, so it reflects the +true +* state of the HW mute. The reason for the EC "ack" is so that +software +* can first invoke a SW mute before the HW circuit is cut off. +Without SW +* cutting this off first does not affect the time delayed muting or +status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated +before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification +path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) { +struct privacy_acpi_priv *priv =dev_get_drvdata (dev); +int ret =0 ; + + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ; +} + +static int dell_privacy_acpi_probe (struct platform_device *pdev) { +int ret; + +platform_set_drvdata (pdev, privacy_acpi); + privacy_acpi->dev = &pdev->dev; + privacy_acpi->platform_device = pdev; + + ret =dell_privacy_leds_setup (&pdev->dev); +if (ret) +return -EIO ; + +return 0 ; +} + +static struct platform_driver dell_privacy_platform_drv = { + .driver = { + .name =PRIVACY_PLATFORM_NAME , + }, + .probe = dell_privacy_acpi_probe, + .remove = dell_privacy_acpi_remove, +}; + +int __init dell_privacy_acpi_init (void ) { +int err; +struct platform_device *pdev; + +if (!wmi_has_guid (DELL_PRIVACY_GUID )) +return -ENODEV ; +drivers/platform/x86/dell/dell-privacy-acpi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+ privacy_acpi =kzalloc (sizeof (*privacy_acpi),GFP_KERNEL ); +if (!privacy_acpi) +return -ENOMEM ; + + err =platform_driver_register (&dell_privacy_platform_drv); +if (err) + goto pdrv_err; + + pdev = platform_device_register_simple( + PRIVACY_PLATFORM_NAME,
PLATFORM_DEVID_NONE, NULL, 0);drivers/platform/x86/dell/dell-privacy-acpi.c line 142
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +4
-0+if (IS_ERR (pdev)) { + err =PTR_ERR (pdev); + goto pdev_err; + }So you're creating a
platform_devicehere, from code called from theinit_dell_privacy()function indell-privacy-wmi.c, just so that theprobe()function for that platform-device can register theled_classdevfor the (alternative) mute LED.Please just put the cdev struct inside struct
privacy_wmi_dataand calldell_privacy_leds_setup()with the wmi-dev as parameter fromdell_privacy_wmi_probeand have the wmi-dev as the parent of theled_classdev.This allows removing both the platform-driver and the instantiation of the platform-device.
After removing the unnecessary platfrom-dev/driver there will be so little left of
dell-privacy-acpi.c, that what remains can and should just be folded intodell-privacy-wmi.c. At which point you're down to one file for the module which also simplifies theMakefile.Quoted 49 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +22
-0+ +return 0 ; + +pdev_err: +platform_device_unregister (pdev); +pdrv_err: +kfree (privacy_acpi); +return err; +} + +void __exit dell_privacy_acpi_exit(void) { +struct platform_device *pdev = +to_platform_device (privacy_acpi->dev); + +platform_device_unregister (pdev); +platform_driver_unregister (&dell_privacy_platform_drv); +kfree (privacy_acpi); +} + +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("DELL Privacy ACPI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.c new file +20
-0@@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> #include <linux/list.h> +#include <linux/module.h> #include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" +#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define PRIVACY_SCREEN_STATUS BIT(2)drivers/platform/x86/dell/dell-privacy-wmi.c line 30
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +/* +* The wmi_list is used to store the privacy_priv struct with mutex +protecting */ static LIST_HEAD (wmi_list);static +DEFINE_MUTEX (list_mutex); +/* +* global privacy state for other modules to query if the privacy +driver loaded successfully +* or no privacy WMI device was detected at initial probe phase */ +int privacy_valid = -EPROBE_DEFER ;EXPORT_SYMBOL_GPL (privacy_valid);None of the callers are interpreting the error-codes stored here. So this is really treated as a bool, and the info stored in the bool is already available inside the wmi_list-head. So just drop this.
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +u32 features_present; +u32 last_status; +}; + +/* drivers/platform/x86/dell/dell-privacy-wmi.c line 55
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* Keymap for WMI privacy events of type 0x0012 */ static const +struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +int dell_privacy_state (void )Please rename this to
dell_privacy_present(), "state" is very generic / not descriptive and uselist_first_entry_or_null(&wmi_list)as done indell_privacy_process_event(), e.g.:bool
dell_privacy_present(void){ struct privacy_wmi_data *priv; mutex_lock(&list_mutex); priv = list_first_entry_or_null(&wmi_list, struct privacy_wmi_data, list); mutex_unlock(&list_mutex); return priv; }Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+{ +return privacy_valid; +} +EXPORT_SYMBOL_GPL (dell_privacy_state); +/* +* The flow of privacy event: drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ * 1) User presses key. HW does stuff with this key (timeout is +started) + * 2) WMI event is emitted from BIOS + * 3) WMI event is received by dell-privacy + * 4) KEY_MICMUTE emitted from dell-privacy + * 5) Userland picks up key and modifies kcontrol for SW mute + * 6) Codec kernel driver catches and calls ledtrig_audio_set defined by + * dell-privacy-acpi driver. + * codec driver will call like this to switch micmute led state. + * ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ?
LED_ON:LED_OFF);drivers/platform/x86/dell/dell-privacy-wmi.c line 74
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +void dell_privacy_process_event (int type,int code,int status)Please make this return a bool, returning true when it has consumed the event and false when it did not consume the event. This will allow other
0x00120xXXXX codes to still be handled by the existingdell-wmi.ccode for this.drivers/platform/x86/dell/dell-privacy-wmi.c line 77
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+{ +struct privacy_wmi_data *priv; +const struct key_entry *key;bool ret = false;drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); + goto error; + } + key = sparse_keymap_entry_from_scancode(priv->input_dev, (type<< 16) | code);
drivers/platform/x86/dell/dell-privacy-wmi.c line 85
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+if (!key) { + dev_dbg(&priv->wdev->dev, "Unknown key with type 0x%04xand code 0x%04x pressed\n",
drivers/platform/x86/dell/dell-privacy-wmi.c line 96
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+ type, code); + goto error; + } +switch (code) { +case DELL_PRIVACY_TYPE_AUDIO :/* Mic mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);ret = true;drivers/platform/x86/dell/dell-privacy-wmi.c line 100
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+break ; +case DELL_PRIVACY_TYPE_CAMERA :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);ret = true;drivers/platform/x86/dell/dell-privacy-wmi.c line 97
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+break ;These 2 cases are exactly the same, please merge them into a single case.
drivers/platform/x86/dell/dell-privacy-wmi.c line 99
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+default : + dev_dbg(&priv->wdev->dev, "unknown event type 0x%04x0x%04x",
drivers/platform/x86/dell/dell-privacy-wmi.c line 108
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+ type, code); + } + +error: +mutex_unlock (&list_mutex);return ret;Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t devices_supported_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev);drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +return sysfs_emit (buf,"%x\n" , priv->features_present); } + +static ssize_t current_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->last_status); }Please change these to emit strings as discussed above (assuming you agree with my above proposal for this).
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+ +static DEVICE_ATTR_RO (devices_supported); +static DEVICE_ATTR_RO (current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_devices_supported.attr, + &dev_attr_current_state.attr, +NULL ,drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +}; + +/* +* Describes the Device State class exposed by BIOS which can be +consumed by +* various applications interested in knowing the Privacy feature capabilities.
Quoted 31 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +31
-0+* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen +* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen +* }; +*/ + +static int get_current_status (struct wmi_device *wdev) { +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); +return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; + privacy_valid = ret; +return ret; + } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) {drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + privacy_valid = ret; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior +*/ +if (obj_present->buffer.length !=8 ) { + dev_err(&wdev->dev, "Dell privacy buffer has unexpectedlength (%d)!\n",
drivers/platform/x86/dell/dell-privacy-wmi.c line 196
Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ obj_present->buffer.length); + ret = -EINVAL ; + privacy_valid = ret; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ]; + privacy_valid =0 ;As discussed, there is no need for the
privacy_validvariable, remove all references to it here.Quoted 19 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +19
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const void +*context) { +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ drivers/platform/x86/dell/dell-privacy-wmi.c line 225
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL ); +if (!keymap) { + ret = -ENOMEM ; + goto err_free_dev; + }No need for the goto here just simplify this to:
if (!keymap) return -ENOMEM;drivers/platform/x86/dell/dell-privacy-wmi.c line 233
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + } + ret =sparse_keymap_setup (priv->input_dev, keymap,NULL );You're done with the keymap here, please put a single:
kfree(keymap);Here before the if (ret), then you won't need any goto style cleanup anywhere in this function.
This also fixes not free-ing the keymap when
sparse_keymap_setup()fails.drivers/platform/x86/dell/dell-privacy-wmi.c line 240
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+if (ret) +return ret; + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; +if (input_register_device (priv->input_dev)) { +pr_debug ("input_register_device failed to register!\n" );You're not setting ret here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 236
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ goto err_free_keymap; + }No need for the
pr_debug, the kernel will already complain if this fails. Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:ret = input_register_device(priv->input_dev); if (ret) returm ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex);Move this to directly above the return 0; below, see below.
drivers/platform/x86/dell/dell-privacy-wmi.c line 248
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ +if (get_current_status (priv->wdev)) + goto err_free_input;You're again not setting ret here before the goto.
And you are returning with an error here after adding the device to the
wmi_list, thelist_add_tailcall should be done last, directly above the return 0 call.Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:
ret = get_current_status(priv->wdev); if (ret) return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 244
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ + ret = devm_device_add_group(&wdev->dev,
&privacy_attribute_group);drivers/platform/x86/dell/dell-privacy-wmi.c line 246
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+if (ret) + goto err_free_input;Replace the goto
err_free_input()with return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 248
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ +kfree (keymap);Drop this
kfree()(already done above now).Move the
list_add_tail()here.drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+return 0 ; + +err_free_input: +input_unregister_device (priv->input_dev);This is not necessary for an
input_deviceallocated withdevm_input_allocate_device(), which means that none of these error handling labels are necessary now, so this can all be removed.Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+err_free_keymap: + privacy_valid = -ENODEV ; +kfree (keymap); +err_free_dev: +return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 274
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static int dell_privacy_wmi_remove (struct wmi_device *wdev) { +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); + privacy_valid = -ENODEV ; +input_unregister_device (priv->input_dev);The
input_unregisteris not necessary (andprivacy_validis gone too).Quoted 13 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +13
-0+ +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + },drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, }; + +static int __init init_dell_privacy (void ) { +int ret; + + ret = wmi_has_guid(DELL_PRIVACY_GUID);> + if (!ret) { + privacy_valid = -ENODEV ; + pr_debug("Unable to detect available Dell privacydevices: %d\n", ret);
drivers/platform/x86/dell/dell-privacy-wmi.c line 292
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+return privacy_valid; + }This driver will only get modprobed if the GUID is present and when it is not present then loading the driver is a no-op so this can be checked.
drivers/platform/x86/dell/dell-privacy-wmi.c line 314
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+ + ret =wmi_driver_register (&dell_privacy_wmi_driver); +if (ret) { +pr_err ("failed to initialize privacy wmi driver: %d\n" , ret); +return ret; + } + + ret =dell_privacy_acpi_init (); +if (ret) { +pr_err ("failed to initialize privacy acpi driver: %d\n" , ret); + goto err_init; + }And with the platform-device/driver removed this is not necessary too, which means ...
Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ +return 0 ; + +err_init: +wmi_driver_unregister (&dell_privacy_wmi_driver); +return ret; +} + +static void dell_privacy_wmi_exit (void ) {drivers/platform/x86/dell/dell-privacy-wmi.c line 335
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+wmi_driver_unregister (&dell_privacy_wmi_driver); +} + +static void __exit exit_dell_privacy(void) { +dell_privacy_wmi_exit (); +dell_privacy_acpi_exit (); +} + +module_init (init_dell_privacy); +module_exit (exit_dell_privacy);That all of the
init_dell_privacy/exit_dell_privacystuff can be replaced with a single line:
module_wmi_driver(&dell_privacy_wmi_driver);drivers/platform/x86/dell/dell-privacy-wmi.c line 339
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+ +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" );
MODULE_LICENSE("GPL");Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +2
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* drivers/platform/x86/dell/dell-privacy-wmi.h line 12
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +extern int privacy_valid;Please remove this from the global kernel namespace (make it a static global inside the
dell-privacy-wmi.ccode).drivers/platform/x86/dell/dell-privacy-wmi.h
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +3
-0+int dell_privacy_state (void ); +void dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ int privacy_valid = -ENODEV ;Drop this.
drivers/platform/x86/dell/dell-privacy-wmi.h line 17
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +2
-0+static inline int dell_privacy_state (void ) { +return privacy_valid;And directly return
-ENODEVhere.Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +4
-0+} + +static inline void dell_privacy_process_event (int type,int code,int +status) {}#endif /* CONFIG_DELL_PRIVACY */ drivers/platform/x86/dell/dell-privacy-wmi.h line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+ +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void ); + +/* DELL Privacy Type */ +enum { +DELL_PRIVACY_TYPE_UNKNOWN =0x0 , +DELL_PRIVACY_TYPE_AUDIO , +DELL_PRIVACY_TYPE_CAMERA , +};This enum is only used inside
dell-privacy-wmi.c, please move it there.drivers/platform/x86/dell/dell-privacy-wmi.h line 35
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif With the platform-device/driver removal discussed above all this header file needs to do is defines the prototypes / stubs for 2 functions:
int
dell_privacy_state(void);
voiddell_privacy_process_event(int type, int code, int status);I think it would be best to just add these to
dell-smbios.h, rather then adding a new header just for these 2 prototypes / stubs.Quoted 17 lines
drivers/platform/x86/dell/dell-wmi.c +2
-4@@ -13,20 +13,22 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/kernel.h> -#include <linux/module.h> +#include <linux/acpi.h> +#include <linux/dmi.h> #include <linux/init.h> -#include <linux/slab.h> -#include <linux/types.h> #include <linux/input.h> drivers/platform/x86/dell/dell-wmi.c line 28
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi.c +5
-1#include <linux/input/sparse-keymap.h> -#include <linux/acpi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> #include <linux/string.h> -#include <linux/dmi.h> +#include <linux/types.h> #include <linux/wmi.h> #include <acpi/video.h> +Please split the changes sorting these includes alphabetically out into a separate cleanup patch.
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi.c +1
-0#include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );
MODULE_AUTHOR("Pali Rohár <[email protected]>"); @@ -381,6 +383,7@@
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 386
Quoted 5 lines
static void dell_wmi_notify(struct
wmi_device*wdev,drivers/platform/x86/dell/dell-wmi.c +1
-0u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int err;Drop this.
drivers/platform/x86/dell/dell-wmi.c
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi.c +0
-0if (obj->type !=ACPI_TYPE_BUFFER ) { pr_warn("bad response type %x\n", obj->type); @@ -427,7+430,6 @@
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device
Quoted 9 lines
static void dell_wmi_notify(struct
wmi_device*wdev,drivers/platform/x86/dell/dell-wmi.c +0
-1switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);@@ -439,6 +441,17 @@ static void dell_wmi_notify(struct wmi_device*wdev,
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev,
Quoted 8 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + err =dell_privacy_state (); +if (err ==0 ) { + dell_privacy_process_event(buffer_entry[1], + buffer_entry[3],buffer_entry[4]);
This needs a len > 4 check !
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev,
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi.c +3
-0+ }else { +if (len >2 ) + dell_wmi_process_key(wdev,buffer_entry[1],
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 453
Quoted 2 lines
drivers/platform/x86/dell/dell-wmi.c +2
-0+ buffer_entry[2]); + }Combined with the change to have
dell_privacy_process_event()return a bool, this should look something like this:if (len > 4 &&
dell_privacy_process_event(buffer_entry[1], buffer_entry[3], buffer_entry[4]))
; /* Handled bydell_privacy_process_event()
*/
else if (len > 2)
dell_wmi_process_key(wdev, buffer_entry[1],
buffer_entry[2]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 457
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +1
-0+break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);Regards,
Hans
Hi Pierre
Thanks for your review .
I changed the patch and explain the review comments as below
(Maybe the mail format has problem, sent from one new system thunderbird :)
Quoted 14 lines · Pierre-Louis Bossart
Minor comments below.
Quoted 10 lines · Perry Yuan
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmits
Quoted 1 line
typo: emits
fixed
Quoted 5 lines
Quoted 3 lines
SW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & hw(hadware) controltypo: hardware
fixed
Quoted 13 lines
Quoted 12 lines
*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:
ledtrig_audio_set(LED_AUDIO_MICMUTE,
rt715->micmute_led?LED_ON:LED_OFF);
7) If "LED" is set to on dell-privacy notifies EC,
and timeout is cancelled, HW mic mute activated.
Quoted 2 lines
what happens if there is timeout? You have an explicit description of the timer handling in the success case, but not what happens on a timeout...
add more explicit description for timeout triggered case
7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled.
HW mic mute activated. If EC not notified,HW mic mute will also be
activated when timeout used up, it is just later than active ack
Quoted 4 lines
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +0
-1--- /dev/null
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
+++ b/Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0@@ -0,0 +1,32 @@ +What:
/sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supportedDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +2
-0+Date: Feb 2021 +KernelVersion: 5.125.13 now?
changed to 5.13
Quoted 15 lines
Quoted 15 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +14
-0+static int dell_privacy_micmute_led_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct privacy_acpi_priv *priv = privacy_acpi; + acpi_status status; + acpi_handle handle; + static char *acpi_method = (char *)"ECAK"; + + handle = ec_get_handle(); + if (!handle) + return -EIO; + if (!acpi_has_method(handle, acpi_method)) + return -EIO; + status = acpi_evaluate_object(handle, acpi_method, NULL, NULL);
Quoted 9 lines
Quoted 6 lines
+ if (
ACPI_FAILURE(status)) {
+ dev_err(priv->dev, "Error setting privacy EC ack value: %s\n", +acpi_format_exception(status));
+ return-EIO;
+ }
+pr_debug("set dell privacy micmute ec ack event done\n");can we use
dev_dbg()here? Same for all occurrences ofpr_debugandpr_errbelow, it's cleaner and easier to filter.
I changed some pr_xx to dev_xxx , but below code will be more complex to use dev_xxx to print the
log , because it need to get the priv->dev, but it is not registered at this time , I would prefer to keep use the pr_debug here. and some other cases where "priv->dev" cannot be used.
static int __init init_dell_privacy(void)
{
int ret;
ret = wmi_has_guid(DELL_PRIVACY_GUID);
if (!ret) {
privacy_valid = -ENODEV;
pr_debug("Unable to detect available Dell privacy devices: %d\n", ret); return privacy_valid;
}
Quoted 31 lines
Quoted 31 lines
+ return 0;
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +5
-0+} + +static int dell_privacy_acpi_remove(struct platform_device *pdev) +{ + struct privacy_acpi_priv *priv =
dev_get_drvdata(privacy_acpi->dev);Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +7
-0+ + led_classdev_unregister(&priv->cdev); + + return 0; +} +/* + * Pressing the mute key activates a time delayed circuit tophysically cut
+ * off the mute. The LED is in the same circuit, so it reflects the true
+ * state of the HW mute. The reason for the EC "ack" is so that software
+ * can first invoke a SW mute before the HW circuit is cut off. Without SW
+ * cutting this off first does not affect the time delayed muting or status
+ * of the LED but there is a possibility of a "popping" noise.
+ *
+ * If the EC receives the SW ack, the circuit will be activated before the
+ * delay completed.
+ *
+ * Exposing as an LED device allows the codec drivers notification path to
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
+ * EC ACK to work
+ */Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+static int dell_privacy_leds_setup(struct device *dev) +{ + struct privacy_acpi_priv *priv = dev_get_drvdata(dev); + int ret = 0;useless init
Sorry, I do not get this point .
int should be needed to return error code if devm_led_classdev_register failed.
Quoted 18 lines
Quoted 18 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +17
-0+ + priv->cdev.name = "dell-privacy::micmute"; + priv->cdev.max_brightness = 1; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger = "audio-micmute"; + priv->cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE); + ret = devm_led_classdev_register(dev, &priv->cdev); + if (ret) + return ret; + return 0; +} + +static int dell_privacy_acpi_probe(struct platform_device *pdev) +{ + int ret; + + platform_set_drvdata(pdev, privacy_acpi);
Quoted 10 lines
Quoted 6 lines
+
privacy_acpi->dev=&pdev->dev;
+privacy_acpi->platform_device= pdev;
+
+ ret =dell_privacy_leds_setup(&pdev->dev);
+ if (ret)
+ return-EIO;any reason to hard-code
-EIO, woud 'return ret' be enough?
fixed to use return ret
Quoted 7 lines
Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +7
-0+ + return 0; +} + +static struct platform_driver dell_privacy_platform_drv = { + .driver = { + .name = PRIVACY_PLATFORM_NAME,
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
+ },
+ .probe =dell_privacy_acpi_probe,
+ .remove =dell_privacy_acpi_remove,Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +3
-0+}; + +int __init dell_privacy_acpi_init(void)is the
__initnecessary? You call this routine from another which already has this qualifier.
Yes, I need to add this when driver loading and kernel will free __init section mem after driver registered.
Quoted 27 lines
Quoted 27 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +26
-0+{ + int err; + struct platform_device *pdev; + + if (!wmi_has_guid(DELL_PRIVACY_GUID)) + return -ENODEV; + + privacy_acpi = kzalloc(sizeof(*privacy_acpi), GFP_KERNEL); + if (!privacy_acpi) + return -ENOMEM; + + err = platform_driver_register(&dell_privacy_platform_drv); + if (err) + goto pdrv_err; + + pdev = platform_device_register_simple( + PRIVACY_PLATFORM_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(pdev)) { + err = PTR_ERR(pdev); + goto pdev_err; + } + + return 0; + +pdev_err: + platform_device_unregister(pdev);
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0+pdrv_err: + kfree(privacy_acpi); + return err; +} + +void __exit dell_privacy_acpi_exit(void)is the
__exitrequired here?
same reason as __init
Quoted 15 lines
Quoted 13 lines
+{
+ structplatform_device*pdev =to_platform_device(privacy_acpi->dev);Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +9
-0+ + platform_device_unregister(pdev); + platform_driver_unregister(&dell_privacy_platform_drv); + kfree(privacy_acpi); +} + +MODULE_AUTHOR("Perry Yuan <[email protected]>"); +MODULE_DESCRIPTION("DELL Privacy ACPI Driver"); +MODULE_LICENSE("GPL");
Hi Hans.
Thanks for your suggestion helping to improve the patch.
Quoted 40 lines · Hans de Goede
Hi,
Quoted 29 lines · Hans de Goede
Hi,
Quoted 26 lines · Perry Yuan
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emmitsSW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & hw(hadware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated.
Signed-off-by Perry Yuan <[email protected]>One last remark, I think that the
dell_privacy_present()function which I suggested in my review should be renamed to:
dell_privacy_has_micmute()and then its return should check the micmute feature bit inpriv->features_presentand this new function should then be used indell-laptop.cto determine itdell-laptop.cshould register its own mic-muteled_classdev.
Quoted 7 lines
This way if a theoretical future laptop shows up where the micmute feature is not implemented by the privacy interface
dell-laptop.cwill still register the non-privacy mic-muteled_classdev.Regards,
Hans
Yes, I rename the micmute checking function to dell_privacy_has_micmute.
and i rewrite it to simplify the micmute checking process.
I am doing some testing and drive other feedback to be finished.
Will post V6 soon for your confirm.
Perry.
Quoted 1,032 lines
Quoted 1,032 lines
Quoted 74 lines
---
v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
------ .../testing/sysfs-platform-dell-privacy-wmi | 32 ++ drivers/platform/x86/dell/Kconfig | 16 + drivers/platform/x86/dell/Makefile | 3 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-acpi.c | 164 +++++++++ drivers/platform/x86/dell/dell-privacy-wmi.c | 340 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 35 ++ drivers/platform/x86/dell/dell-wmi.c | 27 +- 8 files changed, 627 insertions(+), 13 deletions(-)create mode 100644
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmicreate mode 100644drivers/platform/x86/dell/dell-privacy-acpi.ccreate mode 100644drivers/platform/x86/dell/dell-privacy-wmi.ccreate mode 100644drivers/platform/x86/dell/dell-privacy-wmi.hDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +18
-0@@ -0,0 +1,32 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported +Date: Feb 2021 +KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supported + “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: + - 0 = Not Supported + - 1 = Supported + - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacy Screen + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state +Date: Feb 2021Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 28
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+KernelVersion: 5.12 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities + There are three Bits for available states: + - 0 = Enabled + - 1 = DisabledWhat is the definition of enabled/disabled ? Does enabled mean that the device is enabled, or that the device is in privacy mode, so in case of the microphone it is actually disabled (muted) ?
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 32
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ - Bit0 -> Microphone + - Bit1 -> Camera + - Bit2 -> ePrivacyScreen +Normally we would use strings for something like this and not direclty export a bitfield, this would also allow avoiding the enabled / disabled ambiguity
E.g. you could have the following:
# supported devices $ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/devices_supported Microphone Mute Camera Shutter ePrivacyScreen# All devices in privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state Microphone muted Camera Shutter closed ePrivacyScreen privacy-filter enabled# All devices in non-privacy mode:
$ cat /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/current_state Microphone unmuted Camera Shutter open ePrivacyScreen privacy-filter disabledYou can easily do the bitfield -> string mapping in the kernel by having 3 string arrays (support,
privacy_on,privacy_off) indexed by the bitfield indices.Quoted 11 lines
drivers/platform/x86/dell/Kconfig +3
-0@@ -204,4 +204,20 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPIdrivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN · line 219
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+ depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides support for the "Dell Hardware Privacy" feature + of Dell laptops. + Support for a micmute and camera mute privacy will be provided as + hardware button Ctrl+F4 and Ctrl+F9 hotkey.This suggests that that the driver implements the buttons, which is not the case. How about:
This driver provides integration with the "Dell Hardware Privacy" feature of Dell laptops.
Quoted 37 lines
drivers/platform/x86/dell/Kconfig +3
-0+ + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +3
-0@@ -19,3 +19,6 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy.o +dell-privacy-objs := dell-privacy-wmi.o \ + dell-privacy-acpi.odrivers/platform/x86/dell/dell-laptop.c +3
-0@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void) · line 2212
Quoted 8 lines
drivers/platform/x86/dell/dell-laptop.c +1
-4@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (!privacy_valid)This
privacy_validvariable is coming from another module, so you're adding
a "privacy_valid" symbol to the global kernel symbol namespace, even though this is dell specific. Please use thedell_privacy_present()function (see below) instead, so you get:if (dell_privacy_present()) has_privacy = true; else has_privacy = false;Which makes much more sense then "if (!privacy_valid)
has_privacy= true;" which feels as if it is inverted to what it should be.Quoted 68 lines
drivers/platform/x86/dell/dell-laptop.c +13
-2+ has_privacy = true; + else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-acpi.c new file +30
-0@@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bits.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define PRIVACY_PLATFORM_NAME "dell-privacy-acpi" +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" + +struct privacy_acpi_priv {drivers/platform/x86/dell/dell-privacy-acpi.c line 40
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+struct device *dev; +struct platform_device *platform_device; +struct led_classdev cdev; +}; +static struct privacy_acpi_priv *privacy_acpi; + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_acpi_priv *priv = privacy_acpi;Please use
container_ofon the passed inled_cdevhere instead of relying on a global variable.Quoted 92 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +92
-0+acpi_status status; +acpi_handle handle; +static char *acpi_method = (char *)"ECAK" ; + + handle =ec_get_handle (); +if (!handle) +return -EIO ; +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { +dev_err (priv->dev,"Error setting privacy EC ack value: %s\n" , +acpi_format_exception (status)); +return -EIO ; + } +pr_debug ("set dell privacy micmute ec ack event done\n" ); +return 0 ; +} + +static int dell_privacy_acpi_remove (struct platform_device *pdev) +{ +struct privacy_acpi_priv *priv =dev_get_drvdata (privacy_acpi->dev); + +led_classdev_unregister (&priv->cdev); + +return 0 ; +} +/* +* Pressing the mute key activates a time delayed circuit to physically cut +* off the mute. The LED is in the same circuit, so it reflects the true +* state of the HW mute. The reason for the EC "ack" is so that software +* can first invoke a SW mute before the HW circuit is cut off. Without SW +* cutting this off first does not affect the time delayed muting or status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) +{ +struct privacy_acpi_priv *priv =dev_get_drvdata (dev); +int ret =0 ; + + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ; +} + +static int dell_privacy_acpi_probe (struct platform_device *pdev) +{ +int ret; + +platform_set_drvdata (pdev, privacy_acpi); + privacy_acpi->dev = &pdev->dev; + privacy_acpi->platform_device = pdev; + + ret =dell_privacy_leds_setup (&pdev->dev); +if (ret) +return -EIO ; + +return 0 ; +} + +static struct platform_driver dell_privacy_platform_drv = { + .driver = { + .name =PRIVACY_PLATFORM_NAME , + }, + .probe = dell_privacy_acpi_probe, + .remove = dell_privacy_acpi_remove, +}; + +int __init dell_privacy_acpi_init (void ) +{ +int err; +struct platform_device *pdev; + +if (!wmi_has_guid (DELL_PRIVACY_GUID )) +return -ENODEV ; + + privacy_acpi =kzalloc (sizeof (*privacy_acpi),GFP_KERNEL ); +if (!privacy_acpi) +return -ENOMEM ; +drivers/platform/x86/dell/dell-privacy-acpi.c line 142
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +10
-0+ err =platform_driver_register (&dell_privacy_platform_drv); +if (err) + goto pdrv_err; + + pdev =platform_device_register_simple ( +PRIVACY_PLATFORM_NAME ,PLATFORM_DEVID_NONE ,NULL ,0 ); +if (IS_ERR (pdev)) { + err =PTR_ERR (pdev); + goto pdev_err; + }So you're creating a
platform_devicehere, from code called from theinit_dell_privacy()function indell-privacy-wmi.c, just so that theprobe()function for that platform-device can register theled_classdevfor the (alternative) mute LED.Please just put the cdev struct inside struct
privacy_wmi_dataand calldell_privacy_leds_setup()with the wmi-dev as parameter fromdell_privacy_wmi_probeand have the wmi-dev as the parent of theled_classdev.This allows removing both the platform-driver and the instantiation of the platform-device.
After removing the unnecessary platfrom-dev/driver there will be so little left of
dell-privacy-acpi.c, that what remains can and should just be folded intodell-privacy-wmi.c. At which point you're down to one file for the module which also simplifies theMakefile.Quoted 52 lines
drivers/platform/x86/dell/dell-privacy-acpi.c new file +22
-0+ +return 0 ; + +pdev_err: +platform_device_unregister (pdev); +pdrv_err: +kfree (privacy_acpi); +return err; +} + +void __exit dell_privacy_acpi_exit(void) +{ +struct platform_device *pdev =to_platform_device (privacy_acpi->dev); + +platform_device_unregister (pdev); +platform_driver_unregister (&dell_privacy_platform_drv); +kfree (privacy_acpi); +} + +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("DELL Privacy ACPI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.c new file +24
-0@@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" +#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define PRIVACY_SCREEN_STATUS BIT(2) + +/* drivers/platform/x86/dell/dell-privacy-wmi.c line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* The wmi_list is used to store the privacy_priv struct with mutex protecting +*/ +static LIST_HEAD (wmi_list); +static DEFINE_MUTEX (list_mutex); +/* +* global privacy state for other modules to query if the privacy driver loaded successfully +* or no privacy WMI device was detected at initial probe phase +*/ +int privacy_valid = -EPROBE_DEFER ; +EXPORT_SYMBOL_GPL (privacy_valid);None of the callers are interpreting the error-codes stored here. So this is really treated as a bool, and the info stored in the bool is already available inside the wmi_list-head. So just drop this.
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +u32 features_present; +u32 last_status; +}; + +/* +* Keymap for WMI privacy events of type 0x0012 drivers/platform/x86/dell/dell-privacy-wmi.c line 55
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+*/ +static const struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +int dell_privacy_state (void )Please rename this to
dell_privacy_present(), "state" is very generic / not descriptive and uselist_first_entry_or_null(&wmi_list)as done indell_privacy_process_event(), e.g.:bool
dell_privacy_present(void){ struct privacy_wmi_data *priv; mutex_lock(&list_mutex); priv = list_first_entry_or_null(&wmi_list, struct privacy_wmi_data, list); mutex_unlock(&list_mutex); return priv; }Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+{ +return privacy_valid; +} +EXPORT_SYMBOL_GPL (dell_privacy_state); +/* +* The flow of privacy event: +* 1) User presses key. HW does stuff with this key (timeout is started) +* 2) WMI event is emitted from BIOS +* 3) WMI event is received by dell-privacy drivers/platform/x86/dell/dell-privacy-wmi.c line 74
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* 4) KEY_MICMUTE emitted from dell-privacy +* 5) Userland picks up key and modifies kcontrol for SW mute +* 6) Codec kernel driver catches and calls ledtrig_audio_set defined by +* dell-privacy-acpi driver. +* codec driver will call like this to switch micmute led state. +* ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ? LED_ON :LED_OFF); +* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +void dell_privacy_process_event (int type,int code,int status)Please make this return a bool, returning true when it has consumed the event and false when it did not consume the event. This will allow other
0x00120xXXXX codes to still be handled by the existingdell-wmi.ccode for this.drivers/platform/x86/dell/dell-privacy-wmi.c line 77
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+{ +struct privacy_wmi_data *priv; +const struct key_entry *key;bool ret = false;Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); + goto error; + }drivers/platform/x86/dell/dell-privacy-wmi.c line 96
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ key =sparse_keymap_entry_from_scancode (priv->input_dev, (type <<16 ) | code); +if (!key) { +dev_dbg (&priv->wdev->dev,"Unknown key with type 0x%04x and code 0x%04x pressed\n" , + type, code); + goto error; + } +switch (code) { +case DELL_PRIVACY_TYPE_AUDIO :/* Mic mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);ret = true;drivers/platform/x86/dell/dell-privacy-wmi.c line 100
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+break ; +case DELL_PRIVACY_TYPE_CAMERA :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true);ret = true;drivers/platform/x86/dell/dell-privacy-wmi.c line 101
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+break ;These 2 cases are exactly the same, please merge them into a single case.
drivers/platform/x86/dell/dell-privacy-wmi.c line 108
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+default : +dev_dbg (&priv->wdev->dev,"unknown event type 0x%04x 0x%04x" , + type, code); + } + +error: +mutex_unlock (&list_mutex);return ret;Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t devices_supported_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->features_present);drivers/platform/x86/dell/dell-privacy-wmi.c line 128
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static ssize_t current_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%x\n" , priv->last_status); +}Please change these to emit strings as discussed above (assuming you agree with my above proposal for this).
Quoted 58 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +58
-0+ +static DEVICE_ATTR_RO (devices_supported); +static DEVICE_ATTR_RO (current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_devices_supported.attr, + &dev_attr_current_state.attr, +NULL , +}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +}; + +/* +* Describes the Device State class exposed by BIOS which can be consumed by +* various applications interested in knowing the Privacy feature capabilities. +* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen +* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen +* }; +*/ + +static int get_current_status (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" ); +return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; + privacy_valid = ret; +return ret; + } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + privacy_valid = ret; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior +*/ +if (obj_present->buffer.length !=8 ) {drivers/platform/x86/dell/dell-privacy-wmi.c line 196
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+dev_err (&wdev->dev,"Dell privacy buffer has unexpected length (%d)!\n" , + obj_present->buffer.length); + ret = -EINVAL ; + privacy_valid = ret; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ]; + privacy_valid =0 ;As discussed, there is no need for the
privacy_validvariable, remove all references to it here.Quoted 19 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +19
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ drivers/platform/x86/dell/dell-privacy-wmi.c line 225
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL ); +if (!keymap) { + ret = -ENOMEM ; + goto err_free_dev; + }No need for the goto here just simplify this to:
if (!keymap) return -ENOMEM;drivers/platform/x86/dell/dell-privacy-wmi.c line 233
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + } + ret =sparse_keymap_setup (priv->input_dev, keymap,NULL );You're done with the keymap here, please put a single:
kfree(keymap);Here before the if (ret), then you won't need any goto style cleanup anywhere in this function.
This also fixes not free-ing the keymap when
sparse_keymap_setup()fails.drivers/platform/x86/dell/dell-privacy-wmi.c line 240
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+if (ret) +return ret; + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; +if (input_register_device (priv->input_dev)) { +pr_debug ("input_register_device failed to register!\n" );You're not setting ret here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 242
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ goto err_free_keymap; + }No need for the
pr_debug, the kernel will already complain if this fails. Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:ret = input_register_device(priv->input_dev); if (ret) returm ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex);Move this to directly above the return 0; below, see below.
drivers/platform/x86/dell/dell-privacy-wmi.c line 248
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ +if (get_current_status (priv->wdev)) + goto err_free_input;You're again not setting ret here before the goto.
And you are returning with an error here after adding the device to the
wmi_list, thelist_add_tailcall should be done last, directly above the return 0 call.Also since all your resources are devm managed and we've already taken care of the keymap this can be simplified to:
ret = get_current_status(priv->wdev); if (ret) return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 252
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+ + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) + goto err_free_input;Replace the goto
err_free_input()with return ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 254
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+ +kfree (keymap);Drop this
kfree()(already done above now).Move the
list_add_tail()here.drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+return 0 ; + +err_free_input: +input_unregister_device (priv->input_dev);This is not necessary for an
input_deviceallocated withdevm_input_allocate_device(), which means that none of these error handling labels are necessary now, so this can all be removed.Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+err_free_keymap: + privacy_valid = -ENODEV ; +kfree (keymap); +err_free_dev: +return ret; +}drivers/platform/x86/dell/dell-privacy-wmi.c line 274
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +static int dell_privacy_wmi_remove (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); + privacy_valid = -ENODEV ; +input_unregister_device (priv->input_dev);The
input_unregisteris not necessary (andprivacy_validis gone too).Quoted 17 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +17
-0+ +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, +};drivers/platform/x86/dell/dell-privacy-wmi.c line 302
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +static int __init init_dell_privacy (void ) +{ +int ret; + + ret = wmi_has_guid(DELL_PRIVACY_GUID);> + if (!ret) { + privacy_valid = -ENODEV ; +pr_debug ("Unable to detect available Dell privacy devices: %d\n" , ret); +return privacy_valid; + }This driver will only get modprobed if the GUID is present and when it is not present then loading the driver is a no-op so this can be checked.
drivers/platform/x86/dell/dell-privacy-wmi.c line 314
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+ + ret =wmi_driver_register (&dell_privacy_wmi_driver); +if (ret) { +pr_err ("failed to initialize privacy wmi driver: %d\n" , ret); +return ret; + } + + ret =dell_privacy_acpi_init (); +if (ret) { +pr_err ("failed to initialize privacy acpi driver: %d\n" , ret); + goto err_init; + }And with the platform-device/driver removed this is not necessary too, which means ...
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ +return 0 ; + +err_init: +wmi_driver_unregister (&dell_privacy_wmi_driver); +return ret; +} + +static void dell_privacy_wmi_exit (void ) +{ +wmi_driver_unregister (&dell_privacy_wmi_driver);drivers/platform/x86/dell/dell-privacy-wmi.c line 335
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+} + +static void __exit exit_dell_privacy(void) +{ +dell_privacy_wmi_exit (); +dell_privacy_acpi_exit (); +} + +module_init (init_dell_privacy); +module_exit (exit_dell_privacy);That all of the
init_dell_privacy/exit_dell_privacystuff can be replaced with a single line:
module_wmi_driver(&dell_privacy_wmi_driver);Quoted 13 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+ +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.h new file +2
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* drivers/platform/x86/dell/dell-privacy-wmi.h line 12
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +extern int privacy_valid;Please remove this from the global kernel namespace (make it a static global inside the
dell-privacy-wmi.ccode).drivers/platform/x86/dell/dell-privacy-wmi.h line 16
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +4
-0+int dell_privacy_state (void ); +void dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +int privacy_valid = -ENODEV ;Drop this.
drivers/platform/x86/dell/dell-privacy-wmi.h line 19
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +3
-0+static inline int dell_privacy_state (void ) +{ +return privacy_valid;And directly return
-ENODEVhere.Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+} + +static inline void dell_privacy_process_event (int type,int code,int status) +{} +#endif /* CONFIG_DELL_PRIVACY */ drivers/platform/x86/dell/dell-privacy-wmi.h line 34
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+ +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void ); + +/* DELL Privacy Type */ +enum { +DELL_PRIVACY_TYPE_UNKNOWN =0x0 , +DELL_PRIVACY_TYPE_AUDIO , +DELL_PRIVACY_TYPE_CAMERA , +};This enum is only used inside
dell-privacy-wmi.c, please move it there.drivers/platform/x86/dell/dell-privacy-wmi.h line 35
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif With the platform-device/driver removal discussed above all this header file needs to do is defines the prototypes / stubs for 2 functions:
int
dell_privacy_state(void);
voiddell_privacy_process_event(int type, int code, int status);I think it would be best to just add these to
dell-smbios.h, rather then adding a new header just for these 2 prototypes / stubs.Quoted 17 lines
drivers/platform/x86/dell/dell-wmi.c +2
-4@@ -13,20 +13,22 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/kernel.h> -#include <linux/module.h> +#include <linux/acpi.h> +#include <linux/dmi.h> #include <linux/init.h> -#include <linux/slab.h> -#include <linux/types.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> drivers/platform/x86/dell/dell-wmi.c line 28
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi.c +5
-2-#include <linux/acpi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> #include <linux/string.h> -#include <linux/dmi.h> +#include <linux/types.h> #include <linux/wmi.h> #include <acpi/video.h> +Please split the changes sorting these includes alphabetically out into a separate cleanup patch.
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 386
Quoted 11 lines
drivers/platform/x86/dell/dell-wmi.c +2
-0#include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );@@ -381,6 +383,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int err;Drop this.
Quoted 12 lines
drivers/platform/x86/dell/dell-wmi.c +0
-1if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);@@ -427,7 +430,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 448
Quoted 8 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0@@ -439,6 +441,17 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + err =dell_privacy_state (); +if (err ==0 ) { +dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]);This needs a len > 4 check !
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 453
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +5
-0+ }else { +if (len >2 ) +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + }Combined with the change to have
dell_privacy_process_event()return a bool, this should look something like this:if (len > 4 && dell_privacy_process_event(buffer_entry[1], buffer_entry[3], buffer_entry[4])) ; /* Handled by dell_privacy_process_event() */ else if (len > 2) dell_wmi_process_key(wdev, buffer_entry[1], buffer_entry[2]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 457
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi.c +1
-0+break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);Regards,
Hans