xref: /openbmc/linux/drivers/platform/x86/dell/dell-wmi-privacy.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
18af9fa37SPerry Yuan // SPDX-License-Identifier: GPL-2.0-only
28af9fa37SPerry Yuan /*
38af9fa37SPerry Yuan  * Dell privacy notification driver
48af9fa37SPerry Yuan  *
58af9fa37SPerry Yuan  * Copyright (C) 2021 Dell Inc. All Rights Reserved.
68af9fa37SPerry Yuan  */
78af9fa37SPerry Yuan 
88af9fa37SPerry Yuan #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
98af9fa37SPerry Yuan 
108af9fa37SPerry Yuan #include <linux/acpi.h>
118af9fa37SPerry Yuan #include <linux/bitops.h>
128af9fa37SPerry Yuan #include <linux/input.h>
138af9fa37SPerry Yuan #include <linux/input/sparse-keymap.h>
148af9fa37SPerry Yuan #include <linux/list.h>
158af9fa37SPerry Yuan #include <linux/leds.h>
168af9fa37SPerry Yuan #include <linux/module.h>
178af9fa37SPerry Yuan #include <linux/wmi.h>
188af9fa37SPerry Yuan 
198af9fa37SPerry Yuan #include "dell-wmi-privacy.h"
208af9fa37SPerry Yuan 
218af9fa37SPerry Yuan #define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919"
228af9fa37SPerry Yuan #define MICROPHONE_STATUS		BIT(0)
238af9fa37SPerry Yuan #define CAMERA_STATUS		        BIT(1)
248af9fa37SPerry Yuan #define DELL_PRIVACY_AUDIO_EVENT  0x1
258af9fa37SPerry Yuan #define DELL_PRIVACY_CAMERA_EVENT 0x2
268af9fa37SPerry Yuan #define led_to_priv(c)       container_of(c, struct privacy_wmi_data, cdev)
278af9fa37SPerry Yuan 
288af9fa37SPerry Yuan /*
298af9fa37SPerry Yuan  * The wmi_list is used to store the privacy_priv struct with mutex protecting
308af9fa37SPerry Yuan  */
318af9fa37SPerry Yuan static LIST_HEAD(wmi_list);
328af9fa37SPerry Yuan static DEFINE_MUTEX(list_mutex);
338af9fa37SPerry Yuan 
348af9fa37SPerry Yuan struct privacy_wmi_data {
358af9fa37SPerry Yuan 	struct input_dev *input_dev;
368af9fa37SPerry Yuan 	struct wmi_device *wdev;
378af9fa37SPerry Yuan 	struct list_head list;
388af9fa37SPerry Yuan 	struct led_classdev cdev;
398af9fa37SPerry Yuan 	u32 features_present;
408af9fa37SPerry Yuan 	u32 last_status;
418af9fa37SPerry Yuan };
428af9fa37SPerry Yuan 
438af9fa37SPerry Yuan /* DELL Privacy Type */
448af9fa37SPerry Yuan enum dell_hardware_privacy_type {
458af9fa37SPerry Yuan 	DELL_PRIVACY_TYPE_AUDIO = 0,
468af9fa37SPerry Yuan 	DELL_PRIVACY_TYPE_CAMERA,
478af9fa37SPerry Yuan 	DELL_PRIVACY_TYPE_SCREEN,
488af9fa37SPerry Yuan 	DELL_PRIVACY_TYPE_MAX,
498af9fa37SPerry Yuan };
508af9fa37SPerry Yuan 
518af9fa37SPerry Yuan static const char * const privacy_types[DELL_PRIVACY_TYPE_MAX] = {
528af9fa37SPerry Yuan 	[DELL_PRIVACY_TYPE_AUDIO] = "Microphone",
538af9fa37SPerry Yuan 	[DELL_PRIVACY_TYPE_CAMERA] = "Camera Shutter",
548af9fa37SPerry Yuan 	[DELL_PRIVACY_TYPE_SCREEN] = "ePrivacy Screen",
558af9fa37SPerry Yuan };
568af9fa37SPerry Yuan 
578af9fa37SPerry Yuan /*
588af9fa37SPerry Yuan  * Keymap for WMI privacy events of type 0x0012
598af9fa37SPerry Yuan  */
608af9fa37SPerry Yuan static const struct key_entry dell_wmi_keymap_type_0012[] = {
618af9fa37SPerry Yuan 	/* privacy mic mute */
628af9fa37SPerry Yuan 	{ KE_KEY, 0x0001, { KEY_MICMUTE } },
638af9fa37SPerry Yuan 	/* privacy camera mute */
641af7fef0SHans de Goede 	{ KE_VSW, 0x0002, { SW_CAMERA_LENS_COVER } },
658af9fa37SPerry Yuan 	{ KE_END, 0},
668af9fa37SPerry Yuan };
678af9fa37SPerry Yuan 
dell_privacy_has_mic_mute(void)688af9fa37SPerry Yuan bool dell_privacy_has_mic_mute(void)
698af9fa37SPerry Yuan {
708af9fa37SPerry Yuan 	struct privacy_wmi_data *priv;
718af9fa37SPerry Yuan 
728af9fa37SPerry Yuan 	mutex_lock(&list_mutex);
738af9fa37SPerry Yuan 	priv = list_first_entry_or_null(&wmi_list,
748af9fa37SPerry Yuan 			struct privacy_wmi_data,
758af9fa37SPerry Yuan 			list);
768af9fa37SPerry Yuan 	mutex_unlock(&list_mutex);
778af9fa37SPerry Yuan 
788af9fa37SPerry Yuan 	return priv && (priv->features_present & BIT(DELL_PRIVACY_TYPE_AUDIO));
798af9fa37SPerry Yuan }
808af9fa37SPerry Yuan EXPORT_SYMBOL_GPL(dell_privacy_has_mic_mute);
818af9fa37SPerry Yuan 
828af9fa37SPerry Yuan /*
838af9fa37SPerry Yuan  * The flow of privacy event:
848af9fa37SPerry Yuan  * 1) User presses key. HW does stuff with this key (timeout is started)
858af9fa37SPerry Yuan  * 2) WMI event is emitted from BIOS
868af9fa37SPerry Yuan  * 3) WMI event is received by dell-privacy
878af9fa37SPerry Yuan  * 4) KEY_MICMUTE emitted from dell-privacy
888af9fa37SPerry Yuan  * 5) Userland picks up key and modifies kcontrol for SW mute
898af9fa37SPerry Yuan  * 6) Codec kernel driver catches and calls ledtrig_audio_set which will call
908af9fa37SPerry Yuan  *    led_set_brightness() on the LED registered by dell_privacy_leds_setup()
918af9fa37SPerry Yuan  * 7) dell-privacy notifies EC, the timeout is cancelled and the HW mute activates.
928af9fa37SPerry Yuan  *    If the EC is not notified then the HW mic mute will activate when the timeout
938af9fa37SPerry Yuan  *    triggers, just a bit later than with the active ack.
948af9fa37SPerry Yuan  */
dell_privacy_process_event(int type,int code,int status)958af9fa37SPerry Yuan bool dell_privacy_process_event(int type, int code, int status)
968af9fa37SPerry Yuan {
978af9fa37SPerry Yuan 	struct privacy_wmi_data *priv;
988af9fa37SPerry Yuan 	const struct key_entry *key;
998af9fa37SPerry Yuan 	bool ret = false;
1008af9fa37SPerry Yuan 
1018af9fa37SPerry Yuan 	mutex_lock(&list_mutex);
1028af9fa37SPerry Yuan 	priv = list_first_entry_or_null(&wmi_list,
1038af9fa37SPerry Yuan 			struct privacy_wmi_data,
1048af9fa37SPerry Yuan 			list);
1058af9fa37SPerry Yuan 	if (!priv)
1068af9fa37SPerry Yuan 		goto error;
1078af9fa37SPerry Yuan 
1088af9fa37SPerry Yuan 	key = sparse_keymap_entry_from_scancode(priv->input_dev, (type << 16) | code);
1098af9fa37SPerry Yuan 	if (!key) {
1108af9fa37SPerry Yuan 		dev_warn(&priv->wdev->dev, "Unknown key with type 0x%04x and code 0x%04x pressed\n",
1118af9fa37SPerry Yuan 			type, code);
1128af9fa37SPerry Yuan 		goto error;
1138af9fa37SPerry Yuan 	}
1148af9fa37SPerry Yuan 	dev_dbg(&priv->wdev->dev, "Key with type 0x%04x and code 0x%04x pressed\n", type, code);
1158af9fa37SPerry Yuan 
1168af9fa37SPerry Yuan 	switch (code) {
1178af9fa37SPerry Yuan 	case DELL_PRIVACY_AUDIO_EVENT: /* Mic mute */
1188af9fa37SPerry Yuan 		priv->last_status = status;
1198af9fa37SPerry Yuan 		sparse_keymap_report_entry(priv->input_dev, key, 1, true);
1208af9fa37SPerry Yuan 		ret = true;
1218af9fa37SPerry Yuan 		break;
1221af7fef0SHans de Goede 	case DELL_PRIVACY_CAMERA_EVENT: /* Camera mute */
1231af7fef0SHans de Goede 		priv->last_status = status;
1241af7fef0SHans de Goede 		sparse_keymap_report_entry(priv->input_dev, key, !(status & CAMERA_STATUS), false);
1251af7fef0SHans de Goede 		ret = true;
1261af7fef0SHans de Goede 		break;
1278af9fa37SPerry Yuan 	default:
1288af9fa37SPerry Yuan 		dev_dbg(&priv->wdev->dev, "unknown event type 0x%04x 0x%04x\n", type, code);
1298af9fa37SPerry Yuan 	}
1308af9fa37SPerry Yuan 
1318af9fa37SPerry Yuan error:
1328af9fa37SPerry Yuan 	mutex_unlock(&list_mutex);
1338af9fa37SPerry Yuan 	return ret;
1348af9fa37SPerry Yuan }
1358af9fa37SPerry Yuan 
dell_privacy_supported_type_show(struct device * dev,struct device_attribute * attr,char * buf)1368af9fa37SPerry Yuan static ssize_t dell_privacy_supported_type_show(struct device *dev,
1378af9fa37SPerry Yuan 					struct device_attribute *attr,
1388af9fa37SPerry Yuan 					char *buf)
1398af9fa37SPerry Yuan {
1408af9fa37SPerry Yuan 	struct privacy_wmi_data *priv = dev_get_drvdata(dev);
1418af9fa37SPerry Yuan 	enum dell_hardware_privacy_type type;
1428af9fa37SPerry Yuan 	u32 privacy_list;
1438af9fa37SPerry Yuan 	int len = 0;
1448af9fa37SPerry Yuan 
1458af9fa37SPerry Yuan 	privacy_list = priv->features_present;
1468af9fa37SPerry Yuan 	for (type = DELL_PRIVACY_TYPE_AUDIO; type < DELL_PRIVACY_TYPE_MAX; type++) {
1478af9fa37SPerry Yuan 		if (privacy_list & BIT(type))
1488af9fa37SPerry Yuan 			len += sysfs_emit_at(buf, len, "[%s] [supported]\n", privacy_types[type]);
1498af9fa37SPerry Yuan 		else
1508af9fa37SPerry Yuan 			len += sysfs_emit_at(buf, len, "[%s] [unsupported]\n", privacy_types[type]);
1518af9fa37SPerry Yuan 	}
1528af9fa37SPerry Yuan 
1538af9fa37SPerry Yuan 	return len;
1548af9fa37SPerry Yuan }
1558af9fa37SPerry Yuan 
dell_privacy_current_state_show(struct device * dev,struct device_attribute * attr,char * buf)1568af9fa37SPerry Yuan static ssize_t dell_privacy_current_state_show(struct device *dev,
1578af9fa37SPerry Yuan 					struct device_attribute *attr,
1588af9fa37SPerry Yuan 					char *buf)
1598af9fa37SPerry Yuan {
1608af9fa37SPerry Yuan 	struct privacy_wmi_data *priv = dev_get_drvdata(dev);
1618af9fa37SPerry Yuan 	u32 privacy_supported = priv->features_present;
1628af9fa37SPerry Yuan 	enum dell_hardware_privacy_type type;
1638af9fa37SPerry Yuan 	u32 privacy_state = priv->last_status;
1648af9fa37SPerry Yuan 	int len = 0;
1658af9fa37SPerry Yuan 
1668af9fa37SPerry Yuan 	for (type = DELL_PRIVACY_TYPE_AUDIO; type < DELL_PRIVACY_TYPE_MAX; type++) {
1678af9fa37SPerry Yuan 		if (privacy_supported & BIT(type)) {
1688af9fa37SPerry Yuan 			if (privacy_state & BIT(type))
1698af9fa37SPerry Yuan 				len += sysfs_emit_at(buf, len, "[%s] [unmuted]\n", privacy_types[type]);
1708af9fa37SPerry Yuan 			else
1718af9fa37SPerry Yuan 				len += sysfs_emit_at(buf, len, "[%s] [muted]\n", privacy_types[type]);
1728af9fa37SPerry Yuan 		}
1738af9fa37SPerry Yuan 	}
1748af9fa37SPerry Yuan 
1758af9fa37SPerry Yuan 	return len;
1768af9fa37SPerry Yuan }
1778af9fa37SPerry Yuan 
1788af9fa37SPerry Yuan static DEVICE_ATTR_RO(dell_privacy_supported_type);
1798af9fa37SPerry Yuan static DEVICE_ATTR_RO(dell_privacy_current_state);
1808af9fa37SPerry Yuan 
1814b013353SGreg Kroah-Hartman static struct attribute *privacy_attrs[] = {
1828af9fa37SPerry Yuan 	&dev_attr_dell_privacy_supported_type.attr,
1838af9fa37SPerry Yuan 	&dev_attr_dell_privacy_current_state.attr,
1848af9fa37SPerry Yuan 	NULL,
1858af9fa37SPerry Yuan };
1864b013353SGreg Kroah-Hartman ATTRIBUTE_GROUPS(privacy);
1878af9fa37SPerry Yuan 
1888af9fa37SPerry Yuan /*
1898af9fa37SPerry Yuan  * Describes the Device State class exposed by BIOS which can be consumed by
1908af9fa37SPerry Yuan  * various applications interested in knowing the Privacy feature capabilities.
1918af9fa37SPerry Yuan  * class DeviceState
1928af9fa37SPerry Yuan  * {
1938af9fa37SPerry Yuan  *  [key, read] string InstanceName;
1948af9fa37SPerry Yuan  *  [read] boolean ReadOnly;
1958af9fa37SPerry Yuan  *
1968af9fa37SPerry Yuan  *  [WmiDataId(1), read] uint32 DevicesSupported;
1978af9fa37SPerry Yuan  *   0 - None; 0x1 - Microphone; 0x2 - Camera; 0x4 - ePrivacy  Screen
1988af9fa37SPerry Yuan  *
1998af9fa37SPerry Yuan  *  [WmiDataId(2), read] uint32 CurrentState;
2008af9fa37SPerry Yuan  *   0 - Off; 1 - On; Bit0 - Microphone; Bit1 - Camera; Bit2 - ePrivacyScreen
2018af9fa37SPerry Yuan  * };
2028af9fa37SPerry Yuan  */
get_current_status(struct wmi_device * wdev)2038af9fa37SPerry Yuan static int get_current_status(struct wmi_device *wdev)
2048af9fa37SPerry Yuan {
2058af9fa37SPerry Yuan 	struct privacy_wmi_data *priv = dev_get_drvdata(&wdev->dev);
2068af9fa37SPerry Yuan 	union acpi_object *obj_present;
2078af9fa37SPerry Yuan 	u32 *buffer;
2088af9fa37SPerry Yuan 	int ret = 0;
2098af9fa37SPerry Yuan 
2108af9fa37SPerry Yuan 	if (!priv) {
2118af9fa37SPerry Yuan 		dev_err(&wdev->dev, "dell privacy priv is NULL\n");
2128af9fa37SPerry Yuan 		return -EINVAL;
2138af9fa37SPerry Yuan 	}
2148af9fa37SPerry Yuan 	/* check privacy support features and device states */
2158af9fa37SPerry Yuan 	obj_present = wmidev_block_query(wdev, 0);
2168af9fa37SPerry Yuan 	if (!obj_present) {
2178af9fa37SPerry Yuan 		dev_err(&wdev->dev, "failed to read Binary MOF\n");
2188af9fa37SPerry Yuan 		return -EIO;
2198af9fa37SPerry Yuan 	}
2208af9fa37SPerry Yuan 
2218af9fa37SPerry Yuan 	if (obj_present->type != ACPI_TYPE_BUFFER) {
2228af9fa37SPerry Yuan 		dev_err(&wdev->dev, "Binary MOF is not a buffer!\n");
2238af9fa37SPerry Yuan 		ret = -EIO;
2248af9fa37SPerry Yuan 		goto obj_free;
2258af9fa37SPerry Yuan 	}
2268af9fa37SPerry Yuan 	/*  Although it's not technically a failure, this would lead to
2278af9fa37SPerry Yuan 	 *  unexpected behavior
2288af9fa37SPerry Yuan 	 */
2298af9fa37SPerry Yuan 	if (obj_present->buffer.length != 8) {
2308af9fa37SPerry Yuan 		dev_err(&wdev->dev, "Dell privacy buffer has unexpected length (%d)!\n",
2318af9fa37SPerry Yuan 				obj_present->buffer.length);
2328af9fa37SPerry Yuan 		ret = -EINVAL;
2338af9fa37SPerry Yuan 		goto obj_free;
2348af9fa37SPerry Yuan 	}
2358af9fa37SPerry Yuan 	buffer = (u32 *)obj_present->buffer.pointer;
2368af9fa37SPerry Yuan 	priv->features_present = buffer[0];
2378af9fa37SPerry Yuan 	priv->last_status = buffer[1];
2388af9fa37SPerry Yuan 
2398af9fa37SPerry Yuan obj_free:
2408af9fa37SPerry Yuan 	kfree(obj_present);
2418af9fa37SPerry Yuan 	return ret;
2428af9fa37SPerry Yuan }
2438af9fa37SPerry Yuan 
dell_privacy_micmute_led_set(struct led_classdev * led_cdev,enum led_brightness brightness)2448af9fa37SPerry Yuan static int dell_privacy_micmute_led_set(struct led_classdev *led_cdev,
2458af9fa37SPerry Yuan 					enum led_brightness brightness)
2468af9fa37SPerry Yuan {
2478af9fa37SPerry Yuan 	struct privacy_wmi_data *priv = led_to_priv(led_cdev);
2488af9fa37SPerry Yuan 	static char *acpi_method = (char *)"ECAK";
2498af9fa37SPerry Yuan 	acpi_status status;
2508af9fa37SPerry Yuan 	acpi_handle handle;
2518af9fa37SPerry Yuan 
2528af9fa37SPerry Yuan 	handle = ec_get_handle();
2538af9fa37SPerry Yuan 	if (!handle)
2548af9fa37SPerry Yuan 		return -EIO;
2558af9fa37SPerry Yuan 
2568af9fa37SPerry Yuan 	if (!acpi_has_method(handle, acpi_method))
2578af9fa37SPerry Yuan 		return -EIO;
2588af9fa37SPerry Yuan 
2598af9fa37SPerry Yuan 	status = acpi_evaluate_object(handle, acpi_method, NULL, NULL);
2608af9fa37SPerry Yuan 	if (ACPI_FAILURE(status)) {
2618af9fa37SPerry Yuan 		dev_err(&priv->wdev->dev, "Error setting privacy EC ack value: %s\n",
2628af9fa37SPerry Yuan 				acpi_format_exception(status));
2638af9fa37SPerry Yuan 		return -EIO;
2648af9fa37SPerry Yuan 	}
2658af9fa37SPerry Yuan 
2668af9fa37SPerry Yuan 	return 0;
2678af9fa37SPerry Yuan }
2688af9fa37SPerry Yuan 
2698af9fa37SPerry Yuan /*
2708af9fa37SPerry Yuan  * Pressing the mute key activates a time delayed circuit to physically cut
2718af9fa37SPerry Yuan  * off the mute. The LED is in the same circuit, so it reflects the true
2728af9fa37SPerry Yuan  * state of the HW mute.  The reason for the EC "ack" is so that software
2738af9fa37SPerry Yuan  * can first invoke a SW mute before the HW circuit is cut off.  Without SW
2748af9fa37SPerry Yuan  * cutting this off first does not affect the time delayed muting or status
2758af9fa37SPerry Yuan  * of the LED but there is a possibility of a "popping" noise.
2768af9fa37SPerry Yuan  *
2778af9fa37SPerry Yuan  * If the EC receives the SW ack, the circuit will be activated before the
2788af9fa37SPerry Yuan  * delay completed.
2798af9fa37SPerry Yuan  *
2808af9fa37SPerry Yuan  * Exposing as an LED device allows the codec drivers notification path to
2818af9fa37SPerry Yuan  * EC ACK to work
2828af9fa37SPerry Yuan  */
dell_privacy_leds_setup(struct device * dev)2838af9fa37SPerry Yuan static int dell_privacy_leds_setup(struct device *dev)
2848af9fa37SPerry Yuan {
2858af9fa37SPerry Yuan 	struct privacy_wmi_data *priv = dev_get_drvdata(dev);
2868af9fa37SPerry Yuan 
2878af9fa37SPerry Yuan 	priv->cdev.name = "dell-privacy::micmute";
2888af9fa37SPerry Yuan 	priv->cdev.max_brightness = 1;
2898af9fa37SPerry Yuan 	priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set;
2908af9fa37SPerry Yuan 	priv->cdev.default_trigger = "audio-micmute";
2918af9fa37SPerry Yuan 	priv->cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
2928af9fa37SPerry Yuan 	return devm_led_classdev_register(dev, &priv->cdev);
2938af9fa37SPerry Yuan }
2948af9fa37SPerry Yuan 
dell_privacy_wmi_probe(struct wmi_device * wdev,const void * context)2958af9fa37SPerry Yuan static int dell_privacy_wmi_probe(struct wmi_device *wdev, const void *context)
2968af9fa37SPerry Yuan {
2978af9fa37SPerry Yuan 	struct privacy_wmi_data *priv;
2988af9fa37SPerry Yuan 	struct key_entry *keymap;
299*6dc485f9SHans de Goede 	int ret, i, j;
3008af9fa37SPerry Yuan 
3018af9fa37SPerry Yuan 	ret = wmi_has_guid(DELL_PRIVACY_GUID);
3028af9fa37SPerry Yuan 	if (!ret)
3038af9fa37SPerry Yuan 		pr_debug("Unable to detect available Dell privacy devices!\n");
3048af9fa37SPerry Yuan 
3058af9fa37SPerry Yuan 	priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
3068af9fa37SPerry Yuan 	if (!priv)
3078af9fa37SPerry Yuan 		return -ENOMEM;
3088af9fa37SPerry Yuan 
3098af9fa37SPerry Yuan 	dev_set_drvdata(&wdev->dev, priv);
3108af9fa37SPerry Yuan 	priv->wdev = wdev;
3111af7fef0SHans de Goede 
3121af7fef0SHans de Goede 	ret = get_current_status(priv->wdev);
3131af7fef0SHans de Goede 	if (ret)
3141af7fef0SHans de Goede 		return ret;
3151af7fef0SHans de Goede 
3168af9fa37SPerry Yuan 	/* create evdev passing interface */
3178af9fa37SPerry Yuan 	priv->input_dev = devm_input_allocate_device(&wdev->dev);
3188af9fa37SPerry Yuan 	if (!priv->input_dev)
3198af9fa37SPerry Yuan 		return -ENOMEM;
3208af9fa37SPerry Yuan 
3218af9fa37SPerry Yuan 	/* remap the wmi keymap event to new keymap */
3228af9fa37SPerry Yuan 	keymap = kcalloc(ARRAY_SIZE(dell_wmi_keymap_type_0012),
3238af9fa37SPerry Yuan 			sizeof(struct key_entry), GFP_KERNEL);
3248af9fa37SPerry Yuan 	if (!keymap)
3258af9fa37SPerry Yuan 		return -ENOMEM;
3268af9fa37SPerry Yuan 
3278af9fa37SPerry Yuan 	/* remap the keymap code with Dell privacy key type 0x12 as prefix
3288af9fa37SPerry Yuan 	 * KEY_MICMUTE scancode will be reported as 0x120001
3298af9fa37SPerry Yuan 	 */
330*6dc485f9SHans de Goede 	for (i = 0, j = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0012); i++) {
331*6dc485f9SHans de Goede 		/*
332*6dc485f9SHans de Goede 		 * Unlike keys where only presses matter, userspace may act
333*6dc485f9SHans de Goede 		 * on switches in both of their positions. Only register
334*6dc485f9SHans de Goede 		 * SW_CAMERA_LENS_COVER if it is actually there.
335*6dc485f9SHans de Goede 		 */
336*6dc485f9SHans de Goede 		if (dell_wmi_keymap_type_0012[i].type == KE_VSW &&
337*6dc485f9SHans de Goede 		    dell_wmi_keymap_type_0012[i].sw.code == SW_CAMERA_LENS_COVER &&
338*6dc485f9SHans de Goede 		    !(priv->features_present & BIT(DELL_PRIVACY_TYPE_CAMERA)))
339*6dc485f9SHans de Goede 			continue;
340*6dc485f9SHans de Goede 
341*6dc485f9SHans de Goede 		keymap[j] = dell_wmi_keymap_type_0012[i];
342*6dc485f9SHans de Goede 		keymap[j].code |= (0x0012 << 16);
343*6dc485f9SHans de Goede 		j++;
3448af9fa37SPerry Yuan 	}
3458af9fa37SPerry Yuan 	ret = sparse_keymap_setup(priv->input_dev, keymap, NULL);
3468af9fa37SPerry Yuan 	kfree(keymap);
3478af9fa37SPerry Yuan 	if (ret)
3488af9fa37SPerry Yuan 		return ret;
3498af9fa37SPerry Yuan 
3508af9fa37SPerry Yuan 	priv->input_dev->dev.parent = &wdev->dev;
3518af9fa37SPerry Yuan 	priv->input_dev->name = "Dell Privacy Driver";
3528af9fa37SPerry Yuan 	priv->input_dev->id.bustype = BUS_HOST;
3538af9fa37SPerry Yuan 
3541af7fef0SHans de Goede 	/* Report initial camera-cover status */
3551af7fef0SHans de Goede 	if (priv->features_present & BIT(DELL_PRIVACY_TYPE_CAMERA))
3561af7fef0SHans de Goede 		input_report_switch(priv->input_dev, SW_CAMERA_LENS_COVER,
3571af7fef0SHans de Goede 				    !(priv->last_status & CAMERA_STATUS));
3588af9fa37SPerry Yuan 
3591af7fef0SHans de Goede 	ret = input_register_device(priv->input_dev);
3608af9fa37SPerry Yuan 	if (ret)
3618af9fa37SPerry Yuan 		return ret;
3628af9fa37SPerry Yuan 
3638af9fa37SPerry Yuan 	if (priv->features_present & BIT(DELL_PRIVACY_TYPE_AUDIO)) {
3648af9fa37SPerry Yuan 		ret = dell_privacy_leds_setup(&priv->wdev->dev);
3658af9fa37SPerry Yuan 		if (ret)
3668af9fa37SPerry Yuan 			return ret;
3678af9fa37SPerry Yuan 	}
3688af9fa37SPerry Yuan 	mutex_lock(&list_mutex);
3698af9fa37SPerry Yuan 	list_add_tail(&priv->list, &wmi_list);
3708af9fa37SPerry Yuan 	mutex_unlock(&list_mutex);
3718af9fa37SPerry Yuan 	return 0;
3728af9fa37SPerry Yuan }
3738af9fa37SPerry Yuan 
dell_privacy_wmi_remove(struct wmi_device * wdev)3748af9fa37SPerry Yuan static void dell_privacy_wmi_remove(struct wmi_device *wdev)
3758af9fa37SPerry Yuan {
3768af9fa37SPerry Yuan 	struct privacy_wmi_data *priv = dev_get_drvdata(&wdev->dev);
3778af9fa37SPerry Yuan 
3788af9fa37SPerry Yuan 	mutex_lock(&list_mutex);
3798af9fa37SPerry Yuan 	list_del(&priv->list);
3808af9fa37SPerry Yuan 	mutex_unlock(&list_mutex);
3818af9fa37SPerry Yuan }
3828af9fa37SPerry Yuan 
3838af9fa37SPerry Yuan static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = {
3848af9fa37SPerry Yuan 	{ .guid_string = DELL_PRIVACY_GUID },
3858af9fa37SPerry Yuan 	{ },
3868af9fa37SPerry Yuan };
3878af9fa37SPerry Yuan 
3888af9fa37SPerry Yuan static struct wmi_driver dell_privacy_wmi_driver = {
3898af9fa37SPerry Yuan 	.driver = {
3908af9fa37SPerry Yuan 		.name = "dell-privacy",
3914b013353SGreg Kroah-Hartman 		.dev_groups = privacy_groups,
3928af9fa37SPerry Yuan 	},
3938af9fa37SPerry Yuan 	.probe = dell_privacy_wmi_probe,
3948af9fa37SPerry Yuan 	.remove = dell_privacy_wmi_remove,
3958af9fa37SPerry Yuan 	.id_table = dell_wmi_privacy_wmi_id_table,
3968af9fa37SPerry Yuan };
3978af9fa37SPerry Yuan 
dell_privacy_register_driver(void)3988af9fa37SPerry Yuan int dell_privacy_register_driver(void)
3998af9fa37SPerry Yuan {
4008af9fa37SPerry Yuan 	return wmi_driver_register(&dell_privacy_wmi_driver);
4018af9fa37SPerry Yuan }
4028af9fa37SPerry Yuan 
dell_privacy_unregister_driver(void)4038af9fa37SPerry Yuan void dell_privacy_unregister_driver(void)
4048af9fa37SPerry Yuan {
4058af9fa37SPerry Yuan 	wmi_driver_unregister(&dell_privacy_wmi_driver);
4068af9fa37SPerry Yuan }
407