Re: [PATCH v7 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy

2021-04-13 Thread Hans de Goede
Hi,

On 4/12/21 11:19 AM, Perry Yuan wrote:
> From: Perry Yuan 
> 
> 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 emits
> SW_CAMERA_LENS_COVER event while the camera lens shutter will be
> changed by EC & HW(hardware) 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. If EC not notified, HW mic mute will also be
>activated when timeout used up, it is just later than active ack
> 
> Signed-off-by: Perry Yuan 
> ---
> v5 -> v6:
> * addressed feedback from Hans
> * addressed feedback from Pierre
> * optimize some debug format with dev_dbg()
> * remove platform driver,combined privacy acpi driver into single wmi
>   driver file
> * optimize sysfs interface with string added to be more clearly reading
> * remove unused function and clear header file

Thank you, almost there. A few small remarks inline.

> 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   |  55 +++
>  drivers/platform/x86/dell/Kconfig |  14 +
>  drivers/platform/x86/dell/Makefile|   1 +
>  drivers/platform/x86/dell/dell-laptop.c   |  23 +-
>  drivers/platform/x86/dell/dell-privacy-wmi.c  | 394 ++
>  drivers/platform/x86/dell/dell-privacy-wmi.h  |  23 +
>  drivers/platform/x86/dell/dell-wmi.c  |   8 +-
>  7 files changed, 511 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
>  create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c
>  create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.h
> 
> diff --git a/Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi 
> b/Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
> new file mode 100644
> index ..7f9e18705861
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
> @@ -0,0 +1,55 @@
> +What:
> /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type
> +Date:Apr 2021
> +KernelVersion:   5.13
> +Contact: "perry.y...@dell.com>"
> +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:
> +Attributes:
> + Microphone Mute:
> + Identifies the local microphone can be muted by 
> hardware, no applications
> + is available to capture system mic sound
> +
> + Camera Shutter:
> + Identifies camera shutter controlled by 
> hardware, which is a micromechanical
> + shutter assembly that is built onto the camera 

RE: [PATCH v7 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy

2021-04-12 Thread Yuan, Perry
Hi ,
> -Original Message-
> From: Amadeusz Sławiński 
> Sent: 2021年4月12日 18:40
> To: Yuan, Perry; po...@protonmail.com; pierre-
> louis.boss...@linux.intel.com; oder_ch...@realtek.com; pe...@perex.cz;
> ti...@suse.com; hdego...@redhat.com; mgr...@linux.intel.com
> Cc: alsa-de...@alsa-project.org; linux-kernel@vger.kernel.org;
> lgirdw...@gmail.com; platform-driver-...@vger.kernel.org;
> broo...@kernel.org; Dell Client Kernel; mario.limoncie...@outlook.com
> Subject: Re: [PATCH v7 1/2] platform/x86: dell-privacy: Add support for Dell
> hardware privacy
> 
> 
> [EXTERNAL EMAIL]
> 
> On 4/12/2021 11:19 AM, Perry Yuan wrote:
> > From: Perry Yuan 
> >
> 
> (...)
> 
> > diff --git a/drivers/platform/x86/dell/dell-laptop.c
> > b/drivers/platform/x86/dell/dell-laptop.c
> > index 70edc5bb3a14..e7ffc0b81208 100644
> > --- a/drivers/platform/x86/dell/dell-laptop.c
> > +++ b/drivers/platform/x86/dell/dell-laptop.c
> > @@ -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 (dell_privacy_present())
> > +   has_privacy = true;
> > +   else
> > +   has_privacy = false;
> 
> Bit, of nitpicking, but you can write above shorter:
> has_privacy = dell_privacy_present();

Good point, changed the code as you suggested.
Thank you.
Perry.


Re: [PATCH v7 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy

2021-04-12 Thread Amadeusz Sławiński

On 4/12/2021 11:19 AM, Perry Yuan wrote:

From: Perry Yuan 



(...)


diff --git a/drivers/platform/x86/dell/dell-laptop.c 
b/drivers/platform/x86/dell/dell-laptop.c
index 70edc5bb3a14..e7ffc0b81208 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -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 (dell_privacy_present())
+   has_privacy = true;
+   else
+   has_privacy = false;


Bit, of nitpicking, but you can write above shorter:
has_privacy = dell_privacy_present();