platform/x86: dell-privacy: Add support for Dell hardware privacy
PATCH v4 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.
---
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/Kconfig | 17 + drivers/platform/x86/Makefile | 4 +- drivers/platform/x86/dell-laptop.c | 26 +- drivers/platform/x86/dell-privacy-acpi.c | 164 +++++++++ drivers/platform/x86/dell-privacy-wmi.c | 340 ++++++++++++++++++ drivers/platform/x86/dell-privacy-wmi.h | 35 ++ drivers/platform/x86/dell-wmi.c | 29 +- 8 files changed, 631 insertions(+), 16 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell-privacy-acpi.c create mode 100644 drivers/platform/x86/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/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/Kconfig +17 -0
@@ -491,6 +491,23 @@ config DELL_WMI_LED This adds support for the Latitude 2100 and similar notebooks that have an external LED. +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. + config AMILO_RFKILL tristate "Fujitsu-Siemens Amilo rfkill support" depends on RFKILL
drivers/platform/x86/Makefile +3 -1
@@ -51,7 +51,9 @@ obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.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 # Fujitsu obj-$(CONFIG_AMILO_RFKILL) += amilo-rfkill.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o
drivers/platform/x86/dell-laptop.c +19 -7
@@ -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,10 +92,12 @@ 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" ); +static const struct dmi_system_id dell_device_table[]__initconst = { { .ident ="Dell laptop" ,
@@ -2205,11 +2209,17 @@ static int __init dell_init(void)dell_laptop_register_notifier (&dell_laptop_notifier);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; +dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { +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 +2267,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 +2289,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-privacy-acpi.c new file +164 -0
164 lines not on this page · raw message
drivers/platform/x86/dell-privacy-wmi.c new file +340 -0
340 lines not on this page · raw message
drivers/platform/x86/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-wmi.c +21 -8
@@ -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,10 +430,9 @@ 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 ]); + buffer_entry[2 ]);/* Extended data is currently ignored */ break ;case 0x0010 :/* Sequence of keys pressed */
@@ -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 30 lines
drivers/platform/x86/Makefile +3
-1@@ -51,7 +51,9 @@ obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.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 # Fujitsu obj-$(CONFIG_AMILO_RFKILL) += amilo-rfkill.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.odrivers/platform/x86/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;
drivers/platform/x86/dell-laptop.c static struct rfkill *wifi_rfkill; · line 100
Quoted 9 lines
drivers/platform/x86/dell-laptop.c +2
-0@@ -90,10 +92,12 @@ 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" ); +
spurious line change
drivers/platform/x86/dell-laptop.c static int __init dell_init(void) · line 2212
Quoted 13 lines
drivers/platform/x86/dell-laptop.c +1
-5static const struct dmi_system_id dell_device_table[]__initconst = { { .ident ="Dell laptop" ,@@ -2205,11 +2209,17 @@ static int __init dell_init(void)dell_laptop_register_notifier (&dell_laptop_notifier);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; +dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) {
not sure why you changed the alignment?
Quoted 43 lines
drivers/platform/x86/dell-laptop.c +39
-0+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) +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 ; + + 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-laptop.c static int __init dell_init(void)
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +10
-0+ } + +return 0 ; + +pdev_err: +platform_device_unregister (pdev); +pdrv_err: +kfree (privacy_acpi); +return err; +}
don't you need some sort of device_initcall() to load this module on startup?
Quoted 18 lines
drivers/platform/x86/dell-laptop.c +18
-0+void dell_privacy_process_event (int type,int code,int status) +{ +struct privacy_wmi_data *priv; +const struct key_entry *key; + +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); +if (!key) { +dev_dbg (&priv->wdev->dev,"Unknown key with type 0x%04x and code 0x%04x pressed\n" , + type, code); + goto error;
drivers/platform/x86/dell-laptop.c
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +10
-0+ } +switch (code) { +case DELL_PRIVACY_TYPE_AUDIO :/* Mic mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); +break ; +case DELL_PRIVACY_TYPE_CAMERA :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); +break ;
You are doing the same things twice, so group the two cases:
case DELL_PRIVACY_TYPE_AUDIO: /* Mic mute */ case DELL_PRIVACY_TYPE_CAMERA: /* Camera mute */ priv->last_status = status; sparse_keymap_report_entry(priv->input_dev, key, 1, true); break;
drivers/platform/x86/dell-laptop.c
Quoted 3 lines
drivers/platform/x86/dell-laptop.c +3
-0+default : +dev_dbg (&priv->wdev->dev,"unknown event type 0x%04x 0x%04x" , + type, code);
alignment?
Quoted 57 lines
drivers/platform/x86/dell-laptop.c +56
-0+ } +error: +mutex_unlock (&list_mutex); +} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); +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 */ + 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; + } +/* 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 ); +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" ); + goto err_free_keymap; + } +mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex); + +if (get_current_status (priv->wdev)) + goto err_free_input; + + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) + goto err_free_input; +
drivers/platform/x86/dell-laptop.c
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +10
-0+kfree (keymap); +return 0 ; + +err_free_input: +input_unregister_device (priv->input_dev); +err_free_keymap: + privacy_valid = -ENODEV ; +kfree (keymap); +err_free_dev: +input_free_device (priv->input_dev);
priv->input_dev is allocated with devm_, so why do you need to do anything with it? that seems like a miss.
Quoted 15 lines
drivers/platform/x86/dell-laptop.c +4
-0+return ret; +} +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);
drivers/platform/x86/dell-laptop.c static void dell_wmi_notify(struct wmi_device *wdev, · line 435
Quoted 8 lines
drivers/platform/x86/dell-laptop.c +1
-2@@ -427,10 +430,9 @@ 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 ]); + buffer_entry[2 ]);
keep the alignment?
Quoted 22 lines
drivers/platform/x86/dell-laptop.c +11
-0/* Extended data is currently ignored */ break ;case 0x0010 :/* Sequence of keys pressed */ @@ -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 ]);
Hello Pierre:
Quoted 52 lines
-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Monday, March 1, 2021 10:28 PM
To: Yuan, Perry; [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 v4 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
drivers/platform/x86/Makefile obj-$(CONFIG_DELL_WMI_DESCRIPTOR) +=
Quoted 6 lines
(quoted diff) +0
-0b/drivers/platform/x86/Makefile index
581475f59819..18c430456de7100644drivers/platform/x86/Makefile +0
-0@@ -51,7 +51,9 @@ obj-$(CONFIG_DELL_WMI_DESCRIPTOR) +=dell-wmi-descriptor.o
Quoted 30 lines
drivers/platform/x86/Makefile +3
-1obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.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 # Fujitsu obj-$(CONFIG_AMILO_RFKILL) += amilo-rfkill.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.odrivers/platform/x86/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,10 +92,12 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;
Quoted 7 lines
drivers/platform/x86/dell-laptop.c static struct rfkill *wifi_rfkill; · line 100
Quoted 5 lines
drivers/platform/x86/dell-laptop.c +1
-0module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models"); +spurious line change
I just want to make them separate with more space . If it cause concern, I will remote the line in V5.
Quoted 11 lines
drivers/platform/x86/dell-laptop.c static int __init dell_init(void) · line 2209
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +0
-0static const struct dmi_system_id dell_device_table[]__initconst = { {.ident = "Dell laptop",
drivers/platform/x86/dell-laptop.c +0
-2@@ -2205,11 +2209,17 @@ static int __init dell_init(void)dell_laptop_register_notifier (&dell_laptop_notifier); 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);
Quoted 8 lines
drivers/platform/x86/dell-laptop.c static int __init dell_init(void) · line 2210
Quoted 1 line
drivers/platform/x86/dell-laptop.c +0
-1- ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);drivers/platform/x86/dell-laptop.c static int __init dell_init(void)
Quoted 3 lines
drivers/platform/x86/dell-laptop.c +1
-2-if (ret <0 ) - goto fail_led; +dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE)) {not sure why you changed the alignment?
The previous alignment is a little not correct. So I adjust it
If it cause concern, will restore it to original shape.
Quoted 43 lines
drivers/platform/x86/dell-laptop.c static int __init dell_init(void)
Quoted 7 lines
drivers/platform/x86/dell-laptop.c +6
-0+if (!privacy_valid) + has_privacy = true; +else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =
ledtrig_audio_get(LED_AUDIO_MICMUTE);drivers/platform/x86/dell-laptop.c static int __init dell_init(void) · line 2219
Quoted 1 line
drivers/platform/x86/dell-laptop.c +1
-0+ ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);Quoted 22 lines
drivers/platform/x86/dell-laptop.c +18
-0+if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor) +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-laptop.c static int __init dell_init(void)
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +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);
Quoted 15 lines
drivers/platform/x86/dell-laptop.c
Quoted 13 lines
drivers/platform/x86/dell-laptop.c +13
-0+if (IS_ERR (pdev)) { + err =PTR_ERR (pdev); + goto pdev_err; + } + +return 0 ; + +pdev_err: +platform_device_unregister (pdev); +pdrv_err: +kfree (privacy_acpi); +return err; +}don't you need some sort of
device_initcall()to load this module on startup?
The driver dell_privacy_acpi_init will be called from dell-privacy-wmi.c , So this driver file will not start to register by itself . The whole driver init entry is controlled by dell-privacy-wmi.c
Quoted 18 lines
Quoted 4 lines
drivers/platform/x86/dell-laptop.c +3
-0+void dell_privacy_process_event (int type,int code,int status) { +struct privacy_wmi_data *priv; +const struct key_entry *key;drivers/platform/x86/dell-laptop.c
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +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-laptop.c
Quoted 2 lines
drivers/platform/x86/dell-laptop.c +2
-0+if (!key) { + dev_dbg(&priv->wdev->dev, "Unknown key with type 0x%04xand code 0x%04x pressed\n",
Quoted 14 lines
drivers/platform/x86/dell-laptop.c
Quoted 12 lines
drivers/platform/x86/dell-laptop.c +12
-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); +break ; +case DELL_PRIVACY_TYPE_CAMERA :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); +break ;You are doing the same things twice, so group the two cases:
In near future, I am going to add some different event handle codes for the Audio and Camera. Currently the Camera is just reporting the same event to user space like audio dose.
Quoted 7 lines
case DELL_PRIVACY_TYPE_AUDIO: /* Mic mute */ case DELL_PRIVACY_TYPE_CAMERA: /* Camera mute */ priv->last_status = status; sparse_keymap_report_entry(priv->input_dev, key, 1, true); break;
Quoted 6 lines
drivers/platform/x86/dell-laptop.c
Quoted 2 lines
drivers/platform/x86/dell-laptop.c +2
-0+default : + dev_dbg(&priv->wdev->dev, "unknown event type0x%04x 0x%04x",
drivers/platform/x86/dell-laptop.c
Quoted 1 line
drivers/platform/x86/dell-laptop.c +1
-0+ type, code);alignment?
Will fix it in V5
Quoted 56 lines
Quoted 45 lines
drivers/platform/x86/dell-laptop.c +43
-0+ } +error: +mutex_unlock (&list_mutex); +} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); +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 */ + 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; + } +/* 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 ); +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" );drivers/platform/x86/dell-laptop.c
Quoted 10 lines
drivers/platform/x86/dell-laptop.c +10
-0+ goto err_free_keymap; + } +mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex); + +if (get_current_status (priv->wdev)) + goto err_free_input; + + ret = devm_device_add_group(&wdev->dev,
&privacy_attribute_group);
Quoted 16 lines
drivers/platform/x86/dell-laptop.c
Quoted 13 lines
drivers/platform/x86/dell-laptop.c +13
-0+if (ret) + goto err_free_input; + +kfree (keymap); +return 0 ; + +err_free_input: +input_unregister_device (priv->input_dev); +err_free_keymap: + privacy_valid = -ENODEV ; +kfree (keymap); +err_free_dev: +input_free_device (priv->input_dev);
priv->input_devis allocated withdevm_, so why do you need to do anything with it? that seems like a miss.
YES, It dose not need to free the device memory, will fix this in V5
Quoted 19 lines
drivers/platform/x86/dell-laptop.c static void dell_wmi_notify(struct wmi_device
Quoted 8 lines
drivers/platform/x86/dell-laptop.c +3
-0+return ret; +} +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,
drivers/platform/x86/dell-laptop.c static void dell_wmi_notify(struct wmi_device
Quoted 8 lines
drivers/platform/x86/dell-laptop.c +1
-0u16 *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,10 +430,9 @@ static void dell_wmi_notify(struct wmi_device*wdev,
Quoted 1 line
Quoted 9 lines
drivers/platform/x86/dell-laptop.c
Quoted 7 lines
switch (buffer_entry[1]) {
case0x0000: /* One key pressed or event occurred */drivers/platform/x86/dell-laptop.c +1
-2-case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], - buffer_entry[2 ]); + buffer_entry[2 ]);keep the alignment?
Will check the line and fix it in V5
Quoted 26 lines
drivers/platform/x86/dell-laptop.c static void dell_wmi_notify(struct wmi_device
Quoted 5 lines
/* Extended data is currently ignored */ break;
case0x0010: /* Sequence of keys pressed */drivers/platform/x86/dell-laptop.c +0
-0@@ -439,6 +441,17 @@ static void dell_wmi_notify(struct wmi_device*wdev,
drivers/platform/x86/dell-laptop.c static void dell_wmi_notify(struct wmi_device · line 448
Quoted 8 lines
drivers/platform/x86/dell-laptop.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]);
drivers/platform/x86/dell-laptop.c static void dell_wmi_notify(struct wmi_device · line 451
Quoted 3 lines
drivers/platform/x86/dell-laptop.c +3
-0+ }else { +if (len >2 ) + dell_wmi_process_key(wdev,buffer_entry[1],
Quoted 7 lines
drivers/platform/x86/dell-laptop.c +3
-0+ buffer_entry[2]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
module_param(force_rfkill, bool, 0444); MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted
models");
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
spurious line change
I just want to make them separate with more space . If it cause concern, I will remote the line in V5.
it's fine to improve spaces/alignment, just do it in a separate patch.
Quoted 19 lines
Quoted 19 lines
drivers/platform/x86/dell-laptop.c static int __init dell_init(void) · line 2209
Quoted 11 lines
static const struct dmi_system_id dell_device_table[] __initconst = { { .ident = "Dell laptop",drivers/platform/x86/dell-laptop.c +0
-2@@ -2205,11 +2209,17 @@ static int __init dell_init(void)dell_laptop_register_notifier (&dell_laptop_notifier); 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);Review static int __init dell_init(void) · line 2210
Quoted 1 line
(quoted diff) +0
-1- ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);drivers/platform/x86/dell-laptop.c static int __init dell_init(void)
Quoted 3 lines
drivers/platform/x86/dell-laptop.c +1
-2-if (ret <0 ) - goto fail_led; +dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE)) {
Quoted 4 lines
Quoted 1 line
not sure why you changed the alignment?
The previous alignment is a little not correct. So I adjust it
If it cause concern, will restore it to original shape.
same here, use a different patch.
Hi Pierre:
Thanks for your review!
Quoted 32 lines · Pierre-Louis Bossart
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
module_param(force_rfkill, bool, 0444);MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models");Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
spurious line change
I just want to make them separate with more space . If it cause concern, I will remote the line in V5.
it's fine to improve spaces/alignment, just do it in a separate patch.
Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
static const struct
dmi_system_iddell_device_table[]__initconst= { {
.ident = "Dell laptop",drivers/platform/x86/dell-laptop.c +0
-0@@ -2205,11 +2209,17 @@ static int __init dell_init(void) dell_laptop_register_notifier(&dell_laptop_notifier);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);Quoted 1 line
- ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);Quoted 3 lines
- if (ret < 0)
- gotofail_led;
+
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE)) {
not sure why you changed the alignment?
The previous alignment is a little not correct. So I adjust it
If it cause concern, will restore it to original shape.same here, use a different patch.
As you suggested,I should add the alignment change in another patch. But if i keep the old alignment, the code will be very odd.
Seems like that I have to change the below code to new alignment in this patch.
if (dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE) &&
dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE)) { <<--- changed back
if (!privacy_valid)
has_privacy = true;
else
has_privacy = false;
if (!has_privacy) {
micmute_led_cdev.brightness <<----------- new alignment
...
}...
}
Quoted 5 lines
As you suggested,I should add the alignment change in another patch. But if i keep the old alignment, the code will be very odd.
Seems like that I have to change the below code to new alignment in this patch.
Quoted 12 lines
if (
dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE)&&
dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE)) { <<--- changed back if (!privacy_valid)
has_privacy= true;
else
has_privacy= false;
if (!has_privacy) {
micmute_led_cdev.brightness <<----------- new alignment
...
}
...
}
I don't get the point, sorry. The code above doesn't seem properly indented or there were spurious tab/spaces conversions?
Hi Pierre:
Quoted 35 lines
-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Monday, March 22, 2021 10:50 PM
To: Perry Yuan; Yuan, Perry; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; platform-driver- [email protected]
Subject: Re: [PATCH v4 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
Quoted 5 lines
As you suggested,I should add the alignment change in another patch. But if i keep the old alignment, the code will be very odd. Seems like that I have to change the below code to new alignment in this patch.
Quoted 13 lines
if (
dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE)&&
dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE)) { <<--- changed
back
if (!privacy_valid)
has_privacy= true;
else
has_privacy= false;
if (!has_privacy) {
micmute_led_cdev.brightness <<----------- new alignment
...
}
...
}
Quoted 2 lines
I don't get the point, sorry. The code above doesn't seem properly indented or there were spurious tab/spaces conversions?
Could you help to take a look the V5 patch ?
I recovery some part of original code alignment and add my new codes with new Tabs added Thank you !
Perry
Quoted 7 lines · Perry Yuan
drivers/platform/x86/Kconfig +0
-0@@ -491,6 +491,23 @@ config DELL_WMI_LED This adds support for the Latitude 2100 and similar notebooks that have an external LED.
drivers/platform/x86/Kconfig config DELL_WMI_LED · line 502
Quoted 10 lines
drivers/platform/x86/Kconfig +9
-0+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
The "help" keyword should be indented only with one tab. Drop the 2 additional spaces for it.
Quoted 7 lines
drivers/platform/x86/Kconfig +7
-0+ 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.
Signature · 1 line
~Randy