2019-01-22 13:43:10 +00:00
|
|
|
From 89c23ec802fc765915d628ac7a354d92a561dd52 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Day <jake@ninebysix.com>
|
|
|
|
Date: Tue, 22 Jan 2019 08:37:15 -0500
|
|
|
|
Subject: [PATCH 03/11] buttons
|
2018-09-20 20:50:36 +00:00
|
|
|
|
|
|
|
---
|
2019-01-06 15:14:33 +00:00
|
|
|
drivers/input/misc/soc_button_array.c | 84 +++++++++++++++++++++--
|
|
|
|
drivers/platform/x86/surfacepro3_button.c | 36 ++++++++++
|
|
|
|
2 files changed, 114 insertions(+), 6 deletions(-)
|
2018-09-20 20:50:36 +00:00
|
|
|
|
|
|
|
diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c
|
2019-01-06 15:14:33 +00:00
|
|
|
index 23520df7650f..1ea239ff426d 100644
|
2018-09-20 20:50:36 +00:00
|
|
|
--- a/drivers/input/misc/soc_button_array.c
|
|
|
|
+++ b/drivers/input/misc/soc_button_array.c
|
2019-01-06 15:14:33 +00:00
|
|
|
@@ -29,12 +29,24 @@ struct soc_button_info {
|
2018-09-20 20:50:36 +00:00
|
|
|
bool wakeup;
|
|
|
|
};
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
+struct soc_device_data {
|
|
|
|
+ /* Button info, may be NULL. */
|
|
|
|
+ struct soc_button_info *button_info;
|
|
|
|
+ /* Special device check function, may be NULL. */
|
|
|
|
+ int (*check)(struct device *);
|
2018-09-09 17:54:26 +00:00
|
|
|
+};
|
|
|
|
+
|
2018-09-20 20:50:36 +00:00
|
|
|
/*
|
|
|
|
* Some of the buttons like volume up/down are auto repeat, while others
|
|
|
|
* are not. To support both, we register two platform devices, and put
|
|
|
|
* buttons into them based on whether the key should be auto repeat.
|
|
|
|
*/
|
|
|
|
-#define BUTTON_TYPES 2
|
2019-01-06 15:14:33 +00:00
|
|
|
+#define BUTTON_TYPES 2
|
|
|
|
+
|
|
|
|
+#define MSHW0040_DSM_REVISION 0x01
|
|
|
|
+#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision
|
|
|
|
+static const guid_t MSHW0040_DSM_UUID =
|
|
|
|
+ GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65, 0x49, 0x80, 0x35);
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
struct soc_button_data {
|
|
|
|
struct platform_device *children[BUTTON_TYPES];
|
2019-01-06 15:14:33 +00:00
|
|
|
@@ -310,6 +322,7 @@ static int soc_button_probe(struct platform_device *pdev)
|
2018-09-20 20:50:36 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
const struct acpi_device_id *id;
|
|
|
|
+ struct soc_device_data *device_data;
|
|
|
|
struct soc_button_info *button_info;
|
|
|
|
struct soc_button_data *priv;
|
|
|
|
struct platform_device *pd;
|
2019-01-06 15:14:33 +00:00
|
|
|
@@ -320,12 +333,20 @@ static int soc_button_probe(struct platform_device *pdev)
|
2018-09-20 20:50:36 +00:00
|
|
|
if (!id)
|
|
|
|
return -ENODEV;
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
- if (!id->driver_data) {
|
|
|
|
+ device_data = (struct soc_device_data *)id->driver_data;
|
|
|
|
+ if (device_data && device_data->check) {
|
|
|
|
+ // device dependent check, required for MSHW0040
|
|
|
|
+ error = device_data->check(dev);
|
|
|
|
+ if (error != 0)
|
|
|
|
+ return error;
|
|
|
|
+ }
|
2018-09-09 17:54:26 +00:00
|
|
|
+
|
2018-09-20 20:50:36 +00:00
|
|
|
+ if (device_data && device_data->button_info) {
|
|
|
|
+ button_info = (struct soc_button_info *)device_data->button_info;
|
|
|
|
+ } else {
|
|
|
|
button_info = soc_button_get_button_info(dev);
|
|
|
|
if (IS_ERR(button_info))
|
|
|
|
return PTR_ERR(button_info);
|
|
|
|
- } else {
|
|
|
|
- button_info = (struct soc_button_info *)id->driver_data;
|
|
|
|
}
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
error = gpiod_count(dev, NULL);
|
2019-01-06 15:14:33 +00:00
|
|
|
@@ -357,7 +378,7 @@ static int soc_button_probe(struct platform_device *pdev)
|
2018-09-20 20:50:36 +00:00
|
|
|
if (!priv->children[0] && !priv->children[1])
|
|
|
|
return -ENODEV;
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
- if (!id->driver_data)
|
|
|
|
+ if (!device_data || !device_data->button_info)
|
|
|
|
devm_kfree(dev, button_info);
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
return 0;
|
2019-01-06 15:14:33 +00:00
|
|
|
@@ -377,9 +398,60 @@ static struct soc_button_info soc_button_PNP0C40[] = {
|
2018-09-20 20:50:36 +00:00
|
|
|
{ }
|
|
|
|
};
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-20 20:50:36 +00:00
|
|
|
+static struct soc_device_data soc_device_PNP0C40 = {
|
|
|
|
+ .button_info = soc_button_PNP0C40,
|
|
|
|
+ .check = NULL,
|
2018-09-09 17:54:26 +00:00
|
|
|
+};
|
|
|
|
+
|
|
|
|
+/*
|
2018-09-20 20:50:36 +00:00
|
|
|
+ * Special device check for Surface Book 2 and Surface Pro (2017).
|
|
|
|
+ * Both, the Surface Pro 4 (surfacepro3_button.c) and the above mentioned
|
|
|
|
+ * devices use MSHW0040 for power and volume buttons, however the way they
|
|
|
|
+ * have to be addressed differs. Make sure that we only load this drivers
|
2019-01-06 15:14:33 +00:00
|
|
|
+ * for the correct devices by checking the OEM Platform Revision provided by
|
|
|
|
+ * the _DSM method.
|
2018-09-09 17:54:26 +00:00
|
|
|
+ */
|
2018-09-20 20:50:36 +00:00
|
|
|
+static int soc_device_check_MSHW0040(struct device *dev)
|
2018-09-09 17:54:26 +00:00
|
|
|
+{
|
2019-01-06 15:14:33 +00:00
|
|
|
+ acpi_handle handle = ACPI_HANDLE(dev);
|
|
|
|
+ union acpi_object *result;
|
|
|
|
+ u64 oem_platform_rev = 0;
|
|
|
|
+
|
|
|
|
+ // get OEM board revision
|
|
|
|
+ result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID, MSHW0040_DSM_REVISION,
|
|
|
|
+ MSHW0040_DSM_GET_OMPR, NULL, ACPI_TYPE_INTEGER);
|
|
|
|
+
|
|
|
|
+ if (result) {
|
|
|
|
+ oem_platform_rev = result->integer.value;
|
|
|
|
+ ACPI_FREE(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dev_dbg(dev, "OEM Platform Revision %llu\n", oem_platform_rev);
|
2018-09-09 17:54:26 +00:00
|
|
|
+
|
2019-01-06 15:14:33 +00:00
|
|
|
+ return oem_platform_rev > 0 ? 0 : -ENODEV;
|
2018-09-09 17:54:26 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/*
|
2018-09-20 20:50:36 +00:00
|
|
|
+ * Button infos for Microsoft Surface Book 2 and Surface Pro (2017).
|
|
|
|
+ * Extracted from DSDT.
|
2018-09-09 17:54:26 +00:00
|
|
|
+ */
|
|
|
|
+static struct soc_button_info soc_button_MSHW0040[] = {
|
2018-09-20 20:50:36 +00:00
|
|
|
+ { "power", 0, EV_KEY, KEY_POWER, false, true },
|
|
|
|
+ { "volume_up", 2, EV_KEY, KEY_VOLUMEUP, true, false },
|
|
|
|
+ { "volume_down", 4, EV_KEY, KEY_VOLUMEDOWN, true, false },
|
2018-09-09 17:54:26 +00:00
|
|
|
+ { }
|
|
|
|
+};
|
|
|
|
+
|
2018-09-20 20:50:36 +00:00
|
|
|
+static struct soc_device_data soc_device_MSHW0040 = {
|
|
|
|
+ .button_info = soc_button_MSHW0040,
|
|
|
|
+ .check = soc_device_check_MSHW0040,
|
2018-09-09 17:54:26 +00:00
|
|
|
+};
|
|
|
|
+
|
2018-09-20 20:50:36 +00:00
|
|
|
static const struct acpi_device_id soc_button_acpi_match[] = {
|
|
|
|
- { "PNP0C40", (unsigned long)soc_button_PNP0C40 },
|
|
|
|
+ { "PNP0C40", (unsigned long)&soc_device_PNP0C40 },
|
|
|
|
{ "ACPI0011", 0 },
|
|
|
|
+ /* Microsoft Surface Book 2 and Surface Pro (2017) */
|
|
|
|
+ { "MSHW0040", (unsigned long)&soc_device_MSHW0040 },
|
|
|
|
{ }
|
|
|
|
};
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2018-09-09 17:54:26 +00:00
|
|
|
diff --git a/drivers/platform/x86/surfacepro3_button.c b/drivers/platform/x86/surfacepro3_button.c
|
2019-01-06 15:14:33 +00:00
|
|
|
index 1b491690ce07..b8f9c91873c7 100644
|
2018-09-09 17:54:26 +00:00
|
|
|
--- a/drivers/platform/x86/surfacepro3_button.c
|
|
|
|
+++ b/drivers/platform/x86/surfacepro3_button.c
|
2019-01-06 15:14:33 +00:00
|
|
|
@@ -24,6 +24,12 @@
|
2018-09-09 17:54:26 +00:00
|
|
|
#define SURFACE_BUTTON_OBJ_NAME "VGBI"
|
|
|
|
#define SURFACE_BUTTON_DEVICE_NAME "Surface Pro 3/4 Buttons"
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2019-01-06 15:14:33 +00:00
|
|
|
+#define MSHW0040_DSM_REVISION 0x01
|
|
|
|
+#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision
|
|
|
|
+static const guid_t MSHW0040_DSM_UUID =
|
|
|
|
+ GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65, 0x49, 0x80, 0x35);
|
|
|
|
+
|
|
|
|
+
|
2018-09-09 17:54:26 +00:00
|
|
|
#define SURFACE_BUTTON_NOTIFY_TABLET_MODE 0xc8
|
2019-01-06 15:14:33 +00:00
|
|
|
|
|
|
|
#define SURFACE_BUTTON_NOTIFY_PRESS_POWER 0xc6
|
|
|
|
@@ -146,6 +152,32 @@ static int surface_button_resume(struct device *dev)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Surface Pro 4 and Surface Book 2 / Surface Pro 2017 use the same device
|
|
|
|
+ * ID (MSHW0040) for the power/volume buttons. Make sure this is the right
|
|
|
|
+ * device by checking for the _DSM method and OEM Platform Revision.
|
|
|
|
+ */
|
|
|
|
+static int surface_button_check_MSHW0040(struct device *dev)
|
|
|
|
+{
|
|
|
|
+ acpi_handle handle = ACPI_HANDLE(dev);
|
|
|
|
+ union acpi_object *result;
|
|
|
|
+ u64 oem_platform_rev = 0;
|
|
|
|
+
|
|
|
|
+ // get OEM board revision
|
|
|
|
+ result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID, MSHW0040_DSM_REVISION,
|
|
|
|
+ MSHW0040_DSM_GET_OMPR, NULL, ACPI_TYPE_INTEGER);
|
|
|
|
+
|
|
|
|
+ if (result) {
|
|
|
|
+ oem_platform_rev = result->integer.value;
|
|
|
|
+ ACPI_FREE(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dev_dbg(dev, "OEM Platform Revision %llu\n", oem_platform_rev);
|
|
|
|
+
|
|
|
|
+ return oem_platform_rev == 0 ? 0 : -ENODEV;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
static int surface_button_add(struct acpi_device *device)
|
|
|
|
{
|
|
|
|
struct surface_button *button;
|
|
|
|
@@ -158,6 +190,10 @@ static int surface_button_add(struct acpi_device *device)
|
2018-09-09 17:54:26 +00:00
|
|
|
strlen(SURFACE_BUTTON_OBJ_NAME)))
|
|
|
|
return -ENODEV;
|
2018-10-28 12:52:45 +00:00
|
|
|
|
2019-01-06 15:14:33 +00:00
|
|
|
+ error = surface_button_check_MSHW0040(&device->dev);
|
|
|
|
+ if (error)
|
|
|
|
+ return error;
|
2018-09-09 17:54:26 +00:00
|
|
|
+
|
|
|
|
button = kzalloc(sizeof(struct surface_button), GFP_KERNEL);
|
|
|
|
if (!button)
|
|
|
|
return -ENOMEM;
|
2018-10-28 12:52:45 +00:00
|
|
|
--
|
2019-01-22 13:43:10 +00:00
|
|
|
2.17.1
|
2018-09-20 20:50:36 +00:00
|
|
|
|