Skip to contentSkip to conversation

intel-hid: support 5 array button

PATCH Superseded Alex Hung 5 participants 18 messages Jan 26, 2017 – Feb 17, 2017 x86 platform drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Alex Hung

author
#0 lore raw

PATCH v2 1/1 intel-hid: support 5 array button

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

This patch was tested on a Dell Latitude 7280.

---
 drivers/platform/x86/intel-hid.c | 107 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/platform/x86/intel-hid.c +102 -5
index cb3ab2b..6e796a5 100644
@@ -1,5 +1,5 @@
 /*
- *  Intel HID event driver for Windows 8
+ *  Intel HID event & 5 button array driver
  *
  *  Copyright (C) 2015 Alex Hung <[email protected]>
  *  Copyright (C) 2015 Andrew Lutomirski <[email protected]>
@@ -57,8 +57,24 @@ static const struct key_entry intel_hid_keymap[] = {
 	{ KE_END },
 };
 
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};
+
 struct intel_hid_priv {
 	struct input_dev *input_dev;
+	struct input_dev *array;
 };
 
 static int intel_hid_set_enable(struct device *device, int enable)
@@ -78,15 +94,43 @@ static int intel_hid_set_enable(struct device *device, int enable)
 	return 0;
 }
 
+static void intel_button_array_enable(struct device *device, int enable)
+{
+	struct intel_hid_priv *priv = dev_get_drvdata(device);
+	acpi_handle handle = ACPI_HANDLE(device);
+	unsigned long long button_cap;
+	acpi_status status;
+
+	if (!priv->array)
+		return;
+
+	/* Query supported platform features */
+	status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap);
+	if (ACPI_FAILURE(status)) {
+		dev_warn(device, "failed to get button capability\n");
+		return;
+	}
+
+	/* Enable|disable features - power button is always enabled */
+	status = acpi_execute_simple_method(handle, "BTNE",
+					    enable ? button_cap : 1);
+	if (ACPI_FAILURE(status))
+		dev_warn(device, "failed to set button capability\n");
+}
+
 static int intel_hid_pl_suspend_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 0);
+	intel_button_array_enable(device, 0);
+
 	return 0;
 }
 
 static int intel_hid_pl_resume_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 1);
+	intel_button_array_enable(device, 1);
+
 	return 0;
 }
 
@@ -126,11 +170,43 @@ static int intel_hid_input_setup(struct platform_device *device)
 	return ret;
 }
 
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+	int ret;
+
+	/* Setup input device for 5 button array */
+	priv->array = input_allocate_device();
+	if (!priv->array)
+		return -ENOMEM;
+
+	ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+	if (ret)
+		goto err_free_array_device;
+
+	priv->array->dev.parent = &device->dev;
+	priv->array->name = "Intel HID 5 button array";
+	priv->array->id.bustype = BUS_HOST;
+
+	ret = input_register_device(priv->array);
+	if (ret)
+		goto err_free_array_device;
+
+	return 0;
+
+err_free_array_device:
+	input_free_device(priv->array);
+	return ret;
+}
+
 static void intel_hid_input_destroy(struct platform_device *device)
 {
 	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
 
 	input_unregister_device(priv->input_dev);
+
+	if (priv->array)
+		input_unregister_device(priv->array);
 }
 
 static void notify_handler(acpi_handle handle, u32 event, void *context)
@@ -140,10 +216,11 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 	unsigned long long ev_index;
 	acpi_status status;
 
-	/* The platform spec only defines one event code: 0xC0. */
+	/* 0xC0 is for HID events, other values are for 5 button array */
 	if (event != 0xc0) {
-		dev_warn(&device->dev, "received unknown event (0x%x)\n",
-			 event);
+		if (!priv->array ||
+		    !sparse_keymap_report_event(priv->array, event, 1, true))
+			dev_info(&device->dev, "unknown event 0x%x\n", event);
 		return;
 	}
 
@@ -161,8 +238,8 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 static int intel_hid_probe(struct platform_device *device)
 {
 	acpi_handle handle = ACPI_HANDLE(&device->dev);
+	unsigned long long event_cap, mode;
 	struct intel_hid_priv *priv;
-	unsigned long long mode;
 	acpi_status status;
 	int err;
 
@@ -193,6 +270,15 @@ static int intel_hid_probe(struct platform_device *device)
 		return err;
 	}
 
+	/* Setup 5 button array */
+	status = acpi_evaluate_integer(handle, "HEBC", NULL, &event_cap);
+	if (ACPI_SUCCESS(status) && (event_cap & 0x20000)) {
+		dev_info(&device->dev, "platform supports 5 button array\n");
+		err = intel_button_array_input_setup(device);
+		if (err)
+			pr_err("Failed to setup Intel 5 button array hotkeys\n");
+	}
+
 	status = acpi_install_notify_handler(handle,
 					     ACPI_DEVICE_NOTIFY,
 					     notify_handler,
@@ -206,6 +292,16 @@ static int intel_hid_probe(struct platform_device *device)
 	if (err)
 		goto err_remove_notify;
 
+	if (priv->array) {
+		intel_button_array_enable(&device->dev, 1);
+
+		/* Call button load method to enable HID power button */
+		status = acpi_evaluate_object(handle, "BTNL", NULL, NULL);
+		if (ACPI_FAILURE(status))
+			dev_warn(&device->dev,
+				 "failed to enable HID power button\n");
+	}
+
 	return 0;
 
 err_remove_notify:
@@ -224,6 +320,7 @@ static int intel_hid_remove(struct platform_device *device)
 	acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
 	intel_hid_input_destroy(device);
 	intel_hid_set_enable(&device->dev, 0);
+	intel_button_array_enable(&device->dev, 0);
 
 	/*
 	 * Even if we failed to shut off the event stream, we can still
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 2 lines

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially,

Personally, I would drop the word "especially". It seems redundant.

Quoted 25 lines

support for this feature is required to fix power button on some recent systems.

This patch was tested on a Dell Latitude 7280.

---
 drivers/platform/x86/intel-hid.c | 107 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/platform/x86/intel-hid.c +1 -1
index cb3ab2b..6e796a5 100644
@@ -1,5 +1,5 @@
 /*
- *  Intel HID event driver for Windows 8
+ *  Intel HID event & 5 button array driver
  *
  *  Copyright (C) 2015 Alex Hung <[email protected]>
  *  Copyright (C) 2015 Andrew Lutomirski <[email protected]>
@@ -57,8 +57,24 @@ static const struct key_entry intel_hid_keymap[] = {
 	{ KE_END },
 };
 

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 69

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */

Comments in the last two lines are now misaligned with the rest.

Other than these two nitpicks (which IMHO are not worth a v3):

Quoted 168 lines
drivers/platform/x86/intel-hid.c +91 -4
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};
+
 struct intel_hid_priv {
 	struct input_dev *input_dev;
+	struct input_dev *array;
 };
 
 static int intel_hid_set_enable(struct device *device, int enable)
@@ -78,15 +94,43 @@ static int intel_hid_set_enable(struct device *device, int enable)
 	return 0;
 }
 
+static void intel_button_array_enable(struct device *device, int enable)
+{
+	struct intel_hid_priv *priv = dev_get_drvdata(device);
+	acpi_handle handle = ACPI_HANDLE(device);
+	unsigned long long button_cap;
+	acpi_status status;
+
+	if (!priv->array)
+		return;
+
+	/* Query supported platform features */
+	status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap);
+	if (ACPI_FAILURE(status)) {
+		dev_warn(device, "failed to get button capability\n");
+		return;
+	}
+
+	/* Enable|disable features - power button is always enabled */
+	status = acpi_execute_simple_method(handle, "BTNE",
+					    enable ? button_cap : 1);
+	if (ACPI_FAILURE(status))
+		dev_warn(device, "failed to set button capability\n");
+}
+
 static int intel_hid_pl_suspend_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 0);
+	intel_button_array_enable(device, 0);
+
 	return 0;
 }
 
 static int intel_hid_pl_resume_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 1);
+	intel_button_array_enable(device, 1);
+
 	return 0;
 }
 
@@ -126,11 +170,43 @@ static int intel_hid_input_setup(struct platform_device *device)
 	return ret;
 }
 
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+	int ret;
+
+	/* Setup input device for 5 button array */
+	priv->array = input_allocate_device();
+	if (!priv->array)
+		return -ENOMEM;
+
+	ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+	if (ret)
+		goto err_free_array_device;
+
+	priv->array->dev.parent = &device->dev;
+	priv->array->name = "Intel HID 5 button array";
+	priv->array->id.bustype = BUS_HOST;
+
+	ret = input_register_device(priv->array);
+	if (ret)
+		goto err_free_array_device;
+
+	return 0;
+
+err_free_array_device:
+	input_free_device(priv->array);
+	return ret;
+}
+
 static void intel_hid_input_destroy(struct platform_device *device)
 {
 	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
 
 	input_unregister_device(priv->input_dev);
+
+	if (priv->array)
+		input_unregister_device(priv->array);
 }
 
 static void notify_handler(acpi_handle handle, u32 event, void *context)
@@ -140,10 +216,11 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 	unsigned long long ev_index;
 	acpi_status status;
 
-	/* The platform spec only defines one event code: 0xC0. */
+	/* 0xC0 is for HID events, other values are for 5 button array */
 	if (event != 0xc0) {
-		dev_warn(&device->dev, "received unknown event (0x%x)\n",
-			 event);
+		if (!priv->array ||
+		    !sparse_keymap_report_event(priv->array, event, 1, true))
+			dev_info(&device->dev, "unknown event 0x%x\n", event);
 		return;
 	}
 
@@ -161,8 +238,8 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 static int intel_hid_probe(struct platform_device *device)
 {
 	acpi_handle handle = ACPI_HANDLE(&device->dev);
+	unsigned long long event_cap, mode;
 	struct intel_hid_priv *priv;
-	unsigned long long mode;
 	acpi_status status;
 	int err;
 
@@ -193,6 +270,15 @@ static int intel_hid_probe(struct platform_device *device)
 		return err;
 	}
 
+	/* Setup 5 button array */
+	status = acpi_evaluate_integer(handle, "HEBC", NULL, &event_cap);
+	if (ACPI_SUCCESS(status) && (event_cap & 0x20000)) {
+		dev_info(&device->dev, "platform supports 5 button array\n");
+		err = intel_button_array_input_setup(device);
+		if (err)
+			pr_err("Failed to setup Intel 5 button array hotkeys\n");
+	}
+
 	status = acpi_install_notify_handler(handle,
 					     ACPI_DEVICE_NOTIFY,
 					     notify_handler,
@@ -206,6 +292,16 @@ static int intel_hid_probe(struct platform_device *device)
 	if (err)
 		goto err_remove_notify;
 
+	if (priv->array) {
+		intel_button_array_enable(&device->dev, 1);
+
+		/* Call button load method to enable HID power button */
+		status = acpi_evaluate_object(handle, "BTNL", NULL, NULL);
+		if (ACPI_FAILURE(status))
+			dev_warn(&device->dev,
+				 "failed to enable HID power button\n");
+	}
+
 	return 0;
 
 err_remove_notify:
@@ -224,6 +320,7 @@ static int intel_hid_remove(struct platform_device *device)
 	acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
 	intel_hid_input_destroy(device);
 	intel_hid_set_enable(&device->dev, 0);
+	intel_button_array_enable(&device->dev, 0);
 
 	/*
 	 * Even if we failed to shut off the event stream, we can still
Signature · 1 line
2.7.4
Signature · 2 lines
Best regards,
Michał Kępień
#2 lore raw
In reply to Alex Hung
Quoted 6 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

This patch was tested on a Dell Latitude 7280.

Hi Alex,

Minor nit below (no need to resend, but a pair of follow-up cleanups would be nice).

Queued to testing.

Quoted 2 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

Quoted 41 lines
---
 drivers/platform/x86/intel-hid.c | 107 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/platform/x86/intel-hid.c +17 -1
index cb3ab2b..6e796a5 100644
@@ -1,5 +1,5 @@
 /*
- *  Intel HID event driver for Windows 8
+ *  Intel HID event & 5 button array driver
  *
  *  Copyright (C) 2015 Alex Hung <[email protected]>
  *  Copyright (C) 2015 Andrew Lutomirski <[email protected]>
@@ -57,8 +57,24 @@ static const struct key_entry intel_hid_keymap[] = {
 	{ KE_END },
 };
 
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};
+
 struct intel_hid_priv {
 	struct input_dev *input_dev;
+	struct input_dev *array;
 };
 
 static int intel_hid_set_enable(struct device *device, int enable)

drivers/platform/x86/intel-hid.c static int intel_hid_set_enable(struct device *device, int enable) · line 98

Quoted 5 lines
drivers/platform/x86/intel-hid.c +2 -0
@@ -78,15 +94,43 @@ static int intel_hid_set_enable(struct device *device, int enable)
 	return 0;
 }
 
+static void intel_button_array_enable(struct device *device, int enable)
+{

As enable is always explicitly passed and is used solely as a boolean value, it would preferable for both this and the previous usage above to define it as a bool. Being self-consistent is important however, so please consider this for a cleanup as a separate patch.

Quoted 59 lines
drivers/platform/x86/intel-hid.c +43 -0
+	struct intel_hid_priv *priv = dev_get_drvdata(device);
+	acpi_handle handle = ACPI_HANDLE(device);
+	unsigned long long button_cap;
+	acpi_status status;
+
+	if (!priv->array)
+		return;
+
+	/* Query supported platform features */
+	status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap);
+	if (ACPI_FAILURE(status)) {
+		dev_warn(device, "failed to get button capability\n");
+		return;
+	}
+
+	/* Enable|disable features - power button is always enabled */
+	status = acpi_execute_simple_method(handle, "BTNE",
+					    enable ? button_cap : 1);
+	if (ACPI_FAILURE(status))
+		dev_warn(device, "failed to set button capability\n");
+}
+
 static int intel_hid_pl_suspend_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 0);
+	intel_button_array_enable(device, 0);
+
 	return 0;
 }
 
 static int intel_hid_pl_resume_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 1);
+	intel_button_array_enable(device, 1);
+
 	return 0;
 }
 
@@ -126,11 +170,43 @@ static int intel_hid_input_setup(struct platform_device *device)
 	return ret;
 }
 
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+	int ret;
+
+	/* Setup input device for 5 button array */
+	priv->array = input_allocate_device();
+	if (!priv->array)
+		return -ENOMEM;
+
+	ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+	if (ret)
+		goto err_free_array_device;
+
+	priv->array->dev.parent = &device->dev;
+	priv->array->name = "Intel HID 5 button array";
+	priv->array->id.bustype = BUS_HOST;

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+
+	ret = input_register_device(priv->array);
+	if (ret)
+		goto err_free_array_device;
+
+	return 0;
+
+err_free_array_device:
+	input_free_device(priv->array);
+	return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

	 input_free_device(priv->array);

return ret;

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

This follows the previous nit - it's self consistent, but a follow-on cleanup patch would be worthwhile.

Thanks Alex, I've queued this to testing and it will go to for-next unless the CI, Pali, or a user reports a problem. Appreciate all your effort on this one.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#3 lore raw

Apologies, this time with Pali's correct email address (aliases fail).

Quoted 165 lines · Alex Hung
Quoted 6 lines

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

This patch was tested on a Dell Latitude 7280.

Hi Alex,

Minor nit below (no need to resend, but a pair of follow-up cleanups would be nice).

Queued to testing.

Quoted 2 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

Quoted 41 lines
---
 drivers/platform/x86/intel-hid.c | 107 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/platform/x86/intel-hid.c +17 -1
index cb3ab2b..6e796a5 100644
@@ -1,5 +1,5 @@
 /*
- *  Intel HID event driver for Windows 8
+ *  Intel HID event & 5 button array driver
  *
  *  Copyright (C) 2015 Alex Hung <[email protected]>
  *  Copyright (C) 2015 Andrew Lutomirski <[email protected]>
@@ -57,8 +57,24 @@ static const struct key_entry intel_hid_keymap[] = {
 	{ KE_END },
 };
 
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};
+
 struct intel_hid_priv {
 	struct input_dev *input_dev;
+	struct input_dev *array;
 };
 
 static int intel_hid_set_enable(struct device *device, int enable)

drivers/platform/x86/intel-hid.c static int intel_hid_set_enable(struct device *device, int enable) · line 98

Quoted 5 lines
drivers/platform/x86/intel-hid.c +2 -0
@@ -78,15 +94,43 @@ static int intel_hid_set_enable(struct device *device, int enable)
 	return 0;
 }
 
+static void intel_button_array_enable(struct device *device, int enable)
+{

As enable is always explicitly passed and is used solely as a boolean value, it would preferable for both this and the previous usage above to define it as a bool. Being self-consistent is important however, so please consider this for a cleanup as a separate patch.

Quoted 59 lines
drivers/platform/x86/intel-hid.c +43 -0
+	struct intel_hid_priv *priv = dev_get_drvdata(device);
+	acpi_handle handle = ACPI_HANDLE(device);
+	unsigned long long button_cap;
+	acpi_status status;
+
+	if (!priv->array)
+		return;
+
+	/* Query supported platform features */
+	status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap);
+	if (ACPI_FAILURE(status)) {
+		dev_warn(device, "failed to get button capability\n");
+		return;
+	}
+
+	/* Enable|disable features - power button is always enabled */
+	status = acpi_execute_simple_method(handle, "BTNE",
+					    enable ? button_cap : 1);
+	if (ACPI_FAILURE(status))
+		dev_warn(device, "failed to set button capability\n");
+}
+
 static int intel_hid_pl_suspend_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 0);
+	intel_button_array_enable(device, 0);
+
 	return 0;
 }
 
 static int intel_hid_pl_resume_handler(struct device *device)
 {
 	intel_hid_set_enable(device, 1);
+	intel_button_array_enable(device, 1);
+
 	return 0;
 }
 
@@ -126,11 +170,43 @@ static int intel_hid_input_setup(struct platform_device *device)
 	return ret;
 }
 
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+	int ret;
+
+	/* Setup input device for 5 button array */
+	priv->array = input_allocate_device();
+	if (!priv->array)
+		return -ENOMEM;
+
+	ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+	if (ret)
+		goto err_free_array_device;
+
+	priv->array->dev.parent = &device->dev;
+	priv->array->name = "Intel HID 5 button array";
+	priv->array->id.bustype = BUS_HOST;

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+
+	ret = input_register_device(priv->array);
+	if (ret)
+		goto err_free_array_device;
+
+	return 0;
+
+err_free_array_device:
+	input_free_device(priv->array);
+	return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

	 input_free_device(priv->array);

return ret;

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

This follows the previous nit - it's self consistent, but a follow-on cleanup patch would be worthwhile.

Thanks Alex, I've queued this to testing and it will go to for-next unless the CI, Pali, or a user reports a problem. Appreciate all your effort on this one.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#4 lore raw

Hi!

Quoted 2 lines · On Saturday 04 February 2017 02:26:05 Darren Hart wrote:

Apologies, this time with Pali's correct email address (aliases fail).

...

Quoted 3 lines
Quoted 3 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

I do not have Dell machine which uses intel-hid.ko so I cannot test this patch. And obviously as it is not loaded it cannot break machines which do not use intel-hid.ko.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/intel-hid.c +6 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
Quoted 8 lines
Quoted 8 lines

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 73

Quoted 8 lines
drivers/platform/x86/intel-hid.c +8 -0
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};

This looks suspicious. Why are all release events ignored?

Signature · 2 lines
Pali Rohár
[email protected]
#5 lore raw
Quoted 14 lines

Hi!

Quoted 2 lines · On Saturday 04 February 2017 02:26:05 Darren Hart wrote:

Apologies, this time with Pali's correct email address (aliases fail).

...

Quoted 3 lines
Quoted 3 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

I do not have Dell machine which uses intel-hid.ko so I cannot test this patch. And obviously as it is not loaded it cannot break machines which do not use intel-hid.ko.

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/intel-hid.c +6 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
Quoted 8 lines
Quoted 8 lines

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 73

Quoted 8 lines
drivers/platform/x86/intel-hid.c +8 -0
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};

This looks suspicious. Why are all release events ignored?

I also do not have a Dell machine that makes use of this driver, but my understanding is that calling sparse_keymap_report_event() with autorelease set to true makes release events irrelevant and simplifies implementation. Though each release event still needs a KE_IGNORE entry in the keymap so that superfluous KEY_UNKNOWN events are suppressed.

Signature · 2 lines
Best regards,
Michał Kępień
#6 lore raw
Quoted 31 lines · On Wednesday 08 February 2017 08:21:46 Michał Kępień wrote:
Quoted 14 lines

Hi!

Quoted 2 lines · On Saturday 04 February 2017 02:26:05 Darren Hart wrote:

Apologies, this time with Pali's correct email address (aliases fail).

...

Quoted 3 lines
Quoted 3 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

I do not have Dell machine which uses intel-hid.ko so I cannot test this patch. And obviously as it is not loaded it cannot break machines which do not use intel-hid.ko.

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/intel-hid.c +6 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+	{ KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+	{ KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
Quoted 8 lines
Quoted 8 lines

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 73

Quoted 8 lines
drivers/platform/x86/intel-hid.c +8 -0
+	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },	             /* Release */
+	{ KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+	{ KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+	{ KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+	{ KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+	{ KE_END },
+};

This looks suspicious. Why are all release events ignored?

Quoted 5 lines

I also do not have a Dell machine that makes use of this driver, but my understanding is that calling sparse_keymap_report_event() with autorelease set to true makes release events irrelevant and simplifies implementation. Though each release event still needs a KE_IGNORE entry in the keymap so that superfluous KEY_UNKNOWN events are suppressed.

Right, but that means if ACPI/WMI/firmware provides correct information when key was pressed and when released we should use it. It allow userspace e.g. measure how long was key pressed or similar thing...

Signature · 2 lines
Pali Rohár
[email protected]
author
#7 lore raw
Quoted 32 lines · Pali Rohár
Quoted 31 lines · On Wednesday 08 February 2017 08:21:46 Michał Kępień wrote:
Quoted 30 lines

Hi!

Quoted 2 lines · On Saturday 04 February 2017 02:26:05 Darren Hart wrote:

Apologies, this time with Pali's correct email address (aliases fail).

...

Quoted 3 lines
Quoted 3 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

I do not have Dell machine which uses intel-hid.ko so I cannot test this patch. And obviously as it is not loaded it cannot break machines which do not use intel-hid.ko.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/intel-hid.c +6 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+     { KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+     { KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+     { KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+     { KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
Quoted 8 lines
Quoted 8 lines

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 73

Quoted 8 lines
drivers/platform/x86/intel-hid.c +8 -0
+     { KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+     { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },              /* Release */
+     { KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+     { KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+     { KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+     { KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+     { KE_END },
+};

This looks suspicious. Why are all release events ignored?

Quoted 5 lines
Quoted 5 lines

I also do not have a Dell machine that makes use of this driver, but my understanding is that calling sparse_keymap_report_event() with autorelease set to true makes release events irrelevant and simplifies implementation. Though each release event still needs a KE_IGNORE entry in the keymap so that superfluous KEY_UNKNOWN events are suppressed.

Thanks Michał, this was indeed my intention.

Quoted 4 lines

Right, but that means if ACPI/WMI/firmware provides correct information when key was pressed and when released we should use it. It allow userspace e.g. measure how long was key pressed or similar thing...

Pali,

The systems I tested generate a press event followed by a release event immediately, so the results will be the same for them.

However, future ACPI implementation may not be the same and I will fix this in a following patch. Thanks for pointing this out.

Quoted 4 lines

--
Pali Rohár
[email protected]

Signature · 2 lines
Cheers,
Alex Hung
#8 lore raw
Quoted 42 lines · On Wednesday 08 February 2017 17:05:13 Alex Hung wrote:
Quoted 32 lines · Pali Rohár
Quoted 31 lines · On Wednesday 08 February 2017 08:21:46 Michał Kępień wrote:
Quoted 30 lines

Hi!

Quoted 2 lines · On Saturday 04 February 2017 02:26:05 Darren Hart wrote:

Apologies, this time with Pali's correct email address (aliases fail).

...

Quoted 3 lines
Quoted 3 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

I do not have Dell machine which uses intel-hid.ko so I cannot test this patch. And obviously as it is not loaded it cannot break machines which do not use intel-hid.ko.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+     { KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+     { KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+     { KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+     { KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+     { KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+     { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },              /* Release */
+     { KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+     { KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+     { KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+     { KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+     { KE_END },
+};

This looks suspicious. Why are all release events ignored?

Quoted 5 lines
Quoted 5 lines

I also do not have a Dell machine that makes use of this driver, but my understanding is that calling sparse_keymap_report_event() with autorelease set to true makes release events irrelevant and simplifies implementation. Though each release event still needs a KE_IGNORE entry in the keymap so that superfluous KEY_UNKNOWN events are suppressed.

Thanks Michał, this was indeed my intention.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

Right, but that means if ACPI/WMI/firmware provides correct information when key was pressed and when released we should use it. It allow userspace e.g. measure how long was key pressed or similar thing...

Pali,

The systems I tested generate a press event followed by a release event immediately, so the results will be the same for them.

Ok, in this case release events can be "simulated" by kernel as your current code is doing it. That is fine.

Quoted 2 lines

However, future ACPI implementation may not be the same and I will fix this in a following patch. Thanks for pointing this out.

If you think that this will be really changes in ACPI/firmware for new machines (or upcoming BIOS/firmware update), then it make sense to use release events from firmware.

Signature · 2 lines
Pali Rohár
[email protected]
#9 lore raw
In reply to Darren Hart
Quoted 37 lines · Darren Hart
Quoted 22 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

drivers/platform/x86/intel-hid.c +17 -0
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+     struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+     int ret;
+
+     /* Setup input device for 5 button array */
+     priv->array = input_allocate_device();
+     if (!priv->array)
+             return -ENOMEM;
+
+     ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+     if (ret)
+             goto err_free_array_device;
+
+     priv->array->dev.parent = &device->dev;
+     priv->array->name = "Intel HID 5 button array";
+     priv->array->id.bustype = BUS_HOST;

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+
+     ret = input_register_device(priv->array);
+     if (ret)
+             goto err_free_array_device;
+
+     return 0;
+
+err_free_array_device:
+     input_free_device(priv->array);
+     return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

Quoted 7 lines

out:
if (ret)

         input_free_device(priv->array);

return ret;

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

Darren, if I didn't miss anything the function is purely used in ->probe() path and thus devm_ version of input_allocate_device() would make this error path gone.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw
Quoted 43 lines · Andy Shevchenko
Quoted 42 lines · Darren Hart
Quoted 22 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

drivers/platform/x86/intel-hid.c +17 -0
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+     struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+     int ret;
+
+     /* Setup input device for 5 button array */
+     priv->array = input_allocate_device();
+     if (!priv->array)
+             return -ENOMEM;
+
+     ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+     if (ret)
+             goto err_free_array_device;
+
+     priv->array->dev.parent = &device->dev;
+     priv->array->name = "Intel HID 5 button array";
+     priv->array->id.bustype = BUS_HOST;

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+
+     ret = input_register_device(priv->array);
+     if (ret)
+             goto err_free_array_device;
+
+     return 0;
+
+err_free_array_device:
+     input_free_device(priv->array);
+     return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

         input_free_device(priv->array);

return ret;

Quoted 6 lines
Quoted 2 lines

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

Darren, if I didn't miss anything the function is purely used in ->probe() path and thus devm_ version of input_allocate_device() would make this error path gone.

Hi Andy,

These are optional input devices for the driver, so if I understand the semantics of devm_ correctly, the input device would remain allocated until such time as the driver is unloaded or if it fails to bind - which for systems with intel-hid, but no 5 button array, the unused input device would remain allocated until system shutdown.

Alex, is that correct?

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
author
#11 lore raw
Quoted 53 lines · Darren Hart
Quoted 43 lines · Andy Shevchenko
Quoted 42 lines · Darren Hart
Quoted 22 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

drivers/platform/x86/intel-hid.c +17 -0
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+     struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+     int ret;
+
+     /* Setup input device for 5 button array */
+     priv->array = input_allocate_device();
+     if (!priv->array)
+             return -ENOMEM;
+
+     ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+     if (ret)
+             goto err_free_array_device;
+
+     priv->array->dev.parent = &device->dev;
+     priv->array->name = "Intel HID 5 button array";
+     priv->array->id.bustype = BUS_HOST;

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+
+     ret = input_register_device(priv->array);
+     if (ret)
+             goto err_free_array_device;
+
+     return 0;
+
+err_free_array_device:
+     input_free_device(priv->array);
+     return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

         input_free_device(priv->array);

return ret;

Quoted 6 lines
Quoted 2 lines

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

Darren, if I didn't miss anything the function is purely used in ->probe() path and thus devm_ version of input_allocate_device() would make this error path gone.

Hi Andy,

Quoted 7 lines

These are optional input devices for the driver, so if I understand the semantics of devm_ correctly, the input device would remain allocated until such time as the driver is unloaded or if it fails to bind - which for systems with intel-hid, but no 5 button array, the unused input device would remain allocated until system shutdown.

Alex, is that correct?

Yes, the input device will be only allocated if 5 button array is supported. Previous firmware that does not support 5 button array won't be affected.

Quoted 4 lines

--
Darren Hart
Intel Open Source Technology Center

Signature · 2 lines
Cheers,
Alex Hung
#12 lore raw
Quoted 40 lines · Alex Hung
Quoted 39 lines · Darren Hart
Quoted 25 lines · Andy Shevchenko
Quoted 24 lines · Darren Hart
Quoted 5 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 9 lines
drivers/platform/x86/intel-hid.c +9 -0
+     ret = input_register_device(priv->array);
+     if (ret)
+             goto err_free_array_device;
+
+     return 0;
+
+err_free_array_device:
+     input_free_device(priv->array);
+     return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

         input_free_device(priv->array);

return ret;

Quoted 6 lines
Quoted 2 lines

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

Darren, if I didn't miss anything the function is purely used in ->probe() path and thus devm_ version of input_allocate_device() would make this error path gone.

These are optional input devices for the driver, so if I understand the semantics of devm_ correctly, the input device would remain allocated until such time as the driver is unloaded or if it fails to bind - which for systems with intel-hid, but no 5 button array, the unused input device would remain allocated until system shutdown.

Quoted 5 lines
Quoted 1 line

Alex, is that correct?

Yes, the input device will be only allocated if 5 button array is supported. Previous firmware that does not support 5 button array won't be affected.

I guess there is a misunderstanding.

From code I see that
1. input_allocate_device() is called only at ->probe() and only for devices that *have* 5 button HID array.
2. Time of live of allocated device is until device driver unbound or unloaded.

From the above I conclude that using devm_input_allocate_device() will reduce burden on error path w/o affecting functionality.

If I;m correct, please, use devm_*() variant.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw
Quoted 47 lines · Andy Shevchenko
Quoted 40 lines · Alex Hung
Quoted 39 lines · Darren Hart
Quoted 25 lines · Andy Shevchenko
Quoted 24 lines · Darren Hart
Quoted 5 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 9 lines
drivers/platform/x86/intel-hid.c +9 -0
+     ret = input_register_device(priv->array);
+     if (ret)
+             goto err_free_array_device;
+
+     return 0;
+
+err_free_array_device:
+     input_free_device(priv->array);
+     return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

         input_free_device(priv->array);

return ret;

Quoted 6 lines
Quoted 2 lines

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

Darren, if I didn't miss anything the function is purely used in ->probe() path and thus devm_ version of input_allocate_device() would make this error path gone.

These are optional input devices for the driver, so if I understand the semantics of devm_ correctly, the input device would remain allocated until such time as the driver is unloaded or if it fails to bind - which for systems with intel-hid, but no 5 button array, the unused input device would remain allocated until system shutdown.

Quoted 5 lines
Quoted 1 line

Alex, is that correct?

Yes, the input device will be only allocated if 5 button array is supported. Previous firmware that does not support 5 button array won't be affected.

Quoted 6 lines

I guess there is a misunderstanding.

Quoted 1 line

From code I see that

1. input_allocate_device() is called only at ->probe() and only for devices that *have* 5 button HID array.
2. Time of live of allocated device is until device driver unbound or unloaded.

It's not critical, and I've applied v3. But, my point was that the driver will not become unbound or unloaded just because the 5 button array input_setup fails at some point, such as with the keymap_setup. In this case, if devm is used and keymap_setup fails, the driver will remain loaded without 5 button array support, and the input device will remain allocated, but unused.

The error path is definitely cleaner using devm, but it can leave an unused input device allocated in error cases - although, perhaps such a situation is rare enough that the advantages of devm make it the better choice.

So, I'm fine with the v3 Alex sent using devm.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
author
#14 lore raw
In reply to Darren Hart
Quoted 151 lines · Darren Hart
Quoted 6 lines · Alex Hung

New firmwares include a feature called 5 button array that supports super key, volume up/down, rotation lock and power button. Especially, support for this feature is required to fix power button on some recent systems.

This patch was tested on a Dell Latitude 7280.

Hi Alex,

Minor nit below (no need to resend, but a pair of follow-up cleanups would be nice).

Queued to testing.

Quoted 2 lines

Pali, would you care to offer a review or some testing to verify no unexpected conflicts with the other dell drivers?

Quoted 41 lines
---
 drivers/platform/x86/intel-hid.c | 107 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/platform/x86/intel-hid.c +17 -1
index cb3ab2b..6e796a5 100644
@@ -1,5 +1,5 @@
 /*
- *  Intel HID event driver for Windows 8
+ *  Intel HID event & 5 button array driver
  *
  *  Copyright (C) 2015 Alex Hung <[email protected]>
  *  Copyright (C) 2015 Andrew Lutomirski <[email protected]>
@@ -57,8 +57,24 @@ static const struct key_entry intel_hid_keymap[] = {
      { KE_END },
 };
 
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+     { KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */
+     { KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+     { KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+     { KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
+     { KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+     { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },              /* Release */
+     { KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+     { KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */
+     { KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+     { KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+     { KE_END },
+};
+
 struct intel_hid_priv {
      struct input_dev *input_dev;
+     struct input_dev *array;
 };
 
 static int intel_hid_set_enable(struct device *device, int enable)

drivers/platform/x86/intel-hid.c static int intel_hid_set_enable(struct device *device, int enable) · line 98

Quoted 5 lines
drivers/platform/x86/intel-hid.c +2 -0
@@ -78,15 +94,43 @@ static int intel_hid_set_enable(struct device *device, int enable)
      return 0;
 }
 
+static void intel_button_array_enable(struct device *device, int enable)
+{

As enable is always explicitly passed and is used solely as a boolean value, it would preferable for both this and the previous usage above to define it as a bool. Being self-consistent is important however, so please consider this for a cleanup as a separate patch.

Quoted 59 lines
drivers/platform/x86/intel-hid.c +43 -0
+     struct intel_hid_priv *priv = dev_get_drvdata(device);
+     acpi_handle handle = ACPI_HANDLE(device);
+     unsigned long long button_cap;
+     acpi_status status;
+
+     if (!priv->array)
+             return;
+
+     /* Query supported platform features */
+     status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap);
+     if (ACPI_FAILURE(status)) {
+             dev_warn(device, "failed to get button capability\n");
+             return;
+     }
+
+     /* Enable|disable features - power button is always enabled */
+     status = acpi_execute_simple_method(handle, "BTNE",
+                                         enable ? button_cap : 1);
+     if (ACPI_FAILURE(status))
+             dev_warn(device, "failed to set button capability\n");
+}
+
 static int intel_hid_pl_suspend_handler(struct device *device)
 {
      intel_hid_set_enable(device, 0);
+     intel_button_array_enable(device, 0);
+
      return 0;
 }
 
 static int intel_hid_pl_resume_handler(struct device *device)
 {
      intel_hid_set_enable(device, 1);
+     intel_button_array_enable(device, 1);
+
      return 0;
 }
 
@@ -126,11 +170,43 @@ static int intel_hid_input_setup(struct platform_device *device)
      return ret;
 }
 
+static int intel_button_array_input_setup(struct platform_device *device)
+{
+     struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+     int ret;
+
+     /* Setup input device for 5 button array */
+     priv->array = input_allocate_device();
+     if (!priv->array)
+             return -ENOMEM;
+
+     ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
+     if (ret)
+             goto err_free_array_device;
+
+     priv->array->dev.parent = &device->dev;
+     priv->array->name = "Intel HID 5 button array";
+     priv->array->id.bustype = BUS_HOST;

drivers/platform/x86/intel-hid.c static int intel_hid_input_setup(struct platform_device *device) · line 199

Quoted 10 lines
drivers/platform/x86/intel-hid.c +10 -0
+
+     ret = input_register_device(priv->array);
+     if (ret)
+             goto err_free_array_device;
+
+     return 0;
+
+err_free_array_device:
+     input_free_device(priv->array);
+     return ret;

This return path is more complex than it could be, since you test for ret before return anyway:

out:
if (ret)

         input_free_device(priv->array);

return ret;

Quoted 8 lines

There is no need for a second return point that I can see. Same for the hid_input_setup function. We can remove 8 lines.

This follows the previous nit - it's self consistent, but a follow-on cleanup patch would be worthwhile.

Thanks Alex, I've queued this to testing and it will go to for-next unless the CI, Pali, or a user reports a problem. Appreciate all your effort on this one.

Thanks for the review. I will send another patch to address all comments later.

Quoted 4 lines

--
Darren Hart
Intel Open Source Technology Center

Signature · 2 lines
Cheers,
Alex Hung
#15 lore raw
Quoted 4 lines
Quoted 2 lines

Thanks Alex, I've queued this to testing and it will go to for-next unless the CI, Pali, or a user reports a problem. Appreciate all your effort on this one.

Thanks for the review. I will send another patch to address all comments later.

Alex, I have only just now noticed one more really trivial issue: a space is missing in each keymap entry before the first right curly bracket:

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 62

Quoted 3 lines
drivers/platform/x86/intel-hid.c +3 -0
+/* 5 button array notification value. */
+static const struct key_entry intel_array_keymap[] = {
+       { KE_KEY,    0xC2, { KEY_LEFTMETA} },                /* Press */

{ KE_KEY, 0xC2, { KEY_LEFTMETA } },

                                 ^

etc.

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 69

Quoted 7 lines
drivers/platform/x86/intel-hid.c +7 -0
+       { KE_IGNORE, 0xC3, { KEY_LEFTMETA} },                /* Release */
+       { KE_KEY,    0xC4, { KEY_VOLUMEUP} },                /* Press */
+       { KE_IGNORE, 0xC5, { KEY_VOLUMEUP} },                /* Release */
+       { KE_KEY,    0xC6, { KEY_VOLUMEDOWN} },              /* Press */
+       { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN} },              /* Release */
+       { KE_SW,     0xC8, { .sw = {SW_ROTATE_LOCK, 1} } },   /* Press */
+       { KE_SW,     0xC9, { .sw = {SW_ROTATE_LOCK, 0} } },   /* Release */

For these two lines, I would personally insert a space next to each of the innermost curly brackets, like this:

{ KE_SW, 0xC9, { .sw = { SW_ROTATE_LOCK, 0 } } },

drivers/platform/x86/intel-hid.c static const struct key_entry intel_hid_keymap[] = { · line 73

Quoted 4 lines
drivers/platform/x86/intel-hid.c +4 -0
+       { KE_KEY,    0xCE, { KEY_POWER} },                   /* Press */
+       { KE_IGNORE, 0xCF, { KEY_POWER} },                   /* Release */
+       { KE_END },
+};

To avoid churn, perhaps the maintainers could do this for you while moving this patch to for-next? Or we can simply ignore this, as I said this is just a minor annoyance.

Signature · 2 lines
Best regards,
Michał Kępień
#16 lore raw
Quoted 5 lines · Michał Kępień
Quoted 1 line

Thanks for the review. I will send another patch to address all comments later.

To avoid churn, perhaps the maintainers could do this for you while moving this patch to for-next? Or we can simply ignore this, as I said this is just a minor annoyance.

I would like to see simplification due to use of devm_input_allocate_device().

Alex, can you send v3 addressing latest comments? If you feel follow up patch would be better, please tell us.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#17 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 5 lines · Michał Kępień
Quoted 1 line

Thanks for the review. I will send another patch to address all comments later.

To avoid churn, perhaps the maintainers could do this for you while moving this patch to for-next? Or we can simply ignore this, as I said this is just a minor annoyance.

I would like to see simplification due to use of devm_input_allocate_device().

Alex, can you send v3 addressing latest comments? If you feel follow up patch would be better, please tell us.

Okay, I will send V3 shortly.

Quoted 4 lines

--
With Best Regards,
Andy Shevchenko

Signature · 2 lines
Cheers,
Alex Hung