Skip to content

Commit c394159

Browse files
qzeddtor
authored andcommitted
Input: soc_button_array - add support for newer surface devices
Power and volume button support for 5th and 6th generation Microsoft Surface devices via soc_button_array. Note that these devices use the same MSHW0040 device as on the Surface Pro 4, however the implementation is different (GPIOs vs. ACPI notifications). Thus some checking is required to ensure we only load this driver on the correct devices. Signed-off-by: Maximilian Luz <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 64dd243 commit c394159

File tree

2 files changed

+96
-15
lines changed

2 files changed

+96
-15
lines changed

drivers/input/misc/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ config INPUT_IDEAPAD_SLIDEBAR
813813

814814
config INPUT_SOC_BUTTON_ARRAY
815815
tristate "Windows-compatible SoC Button Array"
816-
depends on KEYBOARD_GPIO
816+
depends on KEYBOARD_GPIO && ACPI
817817
help
818-
Say Y here if you have a SoC-based tablet that originally
819-
runs Windows 8.
818+
Say Y here if you have a SoC-based tablet that originally runs
819+
Windows 8 or a Microsoft Surface Book 2, Pro 5, Laptop 1 or later.
820820

821821
To compile this driver as a module, choose M here: the
822822
module will be called soc_button_array.

drivers/input/misc/soc_button_array.c

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ struct soc_button_info {
2525
bool wakeup;
2626
};
2727

28+
struct soc_device_data {
29+
const struct soc_button_info *button_info;
30+
int (*check)(struct device *dev);
31+
};
32+
2833
/*
2934
* Some of the buttons like volume up/down are auto repeat, while others
3035
* are not. To support both, we register two platform devices, and put
@@ -87,8 +92,13 @@ soc_button_device_create(struct platform_device *pdev,
8792
continue;
8893

8994
gpio = soc_button_lookup_gpio(&pdev->dev, info->acpi_index);
90-
if (!gpio_is_valid(gpio))
95+
if (gpio < 0 && gpio != -ENOENT) {
96+
error = gpio;
97+
goto err_free_mem;
98+
} else if (!gpio_is_valid(gpio)) {
99+
/* Skip GPIO if not present */
91100
continue;
101+
}
92102

93103
gpio_keys[n_buttons].type = info->event_type;
94104
gpio_keys[n_buttons].code = info->event_code;
@@ -309,23 +319,26 @@ static int soc_button_remove(struct platform_device *pdev)
309319
static int soc_button_probe(struct platform_device *pdev)
310320
{
311321
struct device *dev = &pdev->dev;
312-
const struct acpi_device_id *id;
313-
struct soc_button_info *button_info;
322+
const struct soc_device_data *device_data;
323+
const struct soc_button_info *button_info;
314324
struct soc_button_data *priv;
315325
struct platform_device *pd;
316326
int i;
317327
int error;
318328

319-
id = acpi_match_device(dev->driver->acpi_match_table, dev);
320-
if (!id)
321-
return -ENODEV;
329+
device_data = acpi_device_get_match_data(dev);
330+
if (device_data && device_data->check) {
331+
error = device_data->check(dev);
332+
if (error)
333+
return error;
334+
}
322335

323-
if (!id->driver_data) {
336+
if (device_data && device_data->button_info) {
337+
button_info = device_data->button_info;
338+
} else {
324339
button_info = soc_button_get_button_info(dev);
325340
if (IS_ERR(button_info))
326341
return PTR_ERR(button_info);
327-
} else {
328-
button_info = (struct soc_button_info *)id->driver_data;
329342
}
330343

331344
error = gpiod_count(dev, NULL);
@@ -357,7 +370,7 @@ static int soc_button_probe(struct platform_device *pdev)
357370
if (!priv->children[0] && !priv->children[1])
358371
return -ENODEV;
359372

360-
if (!id->driver_data)
373+
if (!device_data || !device_data->button_info)
361374
devm_kfree(dev, button_info);
362375

363376
return 0;
@@ -368,7 +381,7 @@ static int soc_button_probe(struct platform_device *pdev)
368381
* is defined in section 2.8.7.2 of "Windows ACPI Design Guide for SoC
369382
* Platforms"
370383
*/
371-
static struct soc_button_info soc_button_PNP0C40[] = {
384+
static const struct soc_button_info soc_button_PNP0C40[] = {
372385
{ "power", 0, EV_KEY, KEY_POWER, false, true },
373386
{ "home", 1, EV_KEY, KEY_LEFTMETA, false, true },
374387
{ "volume_up", 2, EV_KEY, KEY_VOLUMEUP, true, false },
@@ -377,9 +390,77 @@ static struct soc_button_info soc_button_PNP0C40[] = {
377390
{ }
378391
};
379392

393+
static const struct soc_device_data soc_device_PNP0C40 = {
394+
.button_info = soc_button_PNP0C40,
395+
};
396+
397+
/*
398+
* Special device check for Surface Book 2 and Surface Pro (2017).
399+
* Both, the Surface Pro 4 (surfacepro3_button.c) and the above mentioned
400+
* devices use MSHW0040 for power and volume buttons, however the way they
401+
* have to be addressed differs. Make sure that we only load this drivers
402+
* for the correct devices by checking the OEM Platform Revision provided by
403+
* the _DSM method.
404+
*/
405+
#define MSHW0040_DSM_REVISION 0x01
406+
#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision
407+
static const guid_t MSHW0040_DSM_UUID =
408+
GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65,
409+
0x49, 0x80, 0x35);
410+
411+
static int soc_device_check_MSHW0040(struct device *dev)
412+
{
413+
acpi_handle handle = ACPI_HANDLE(dev);
414+
union acpi_object *result;
415+
u64 oem_platform_rev = 0; // valid revisions are nonzero
416+
417+
// get OEM platform revision
418+
result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID,
419+
MSHW0040_DSM_REVISION,
420+
MSHW0040_DSM_GET_OMPR, NULL,
421+
ACPI_TYPE_INTEGER);
422+
423+
if (result) {
424+
oem_platform_rev = result->integer.value;
425+
ACPI_FREE(result);
426+
}
427+
428+
/*
429+
* If the revision is zero here, the _DSM evaluation has failed. This
430+
* indicates that we have a Pro 4 or Book 1 and this driver should not
431+
* be used.
432+
*/
433+
if (oem_platform_rev == 0)
434+
return -ENODEV;
435+
436+
dev_dbg(dev, "OEM Platform Revision %llu\n", oem_platform_rev);
437+
438+
return 0;
439+
}
440+
441+
/*
442+
* Button infos for Microsoft Surface Book 2 and Surface Pro (2017).
443+
* Obtained from DSDT/testing.
444+
*/
445+
static const struct soc_button_info soc_button_MSHW0040[] = {
446+
{ "power", 0, EV_KEY, KEY_POWER, false, true },
447+
{ "volume_up", 2, EV_KEY, KEY_VOLUMEUP, true, false },
448+
{ "volume_down", 4, EV_KEY, KEY_VOLUMEDOWN, true, false },
449+
{ }
450+
};
451+
452+
static const struct soc_device_data soc_device_MSHW0040 = {
453+
.button_info = soc_button_MSHW0040,
454+
.check = soc_device_check_MSHW0040,
455+
};
456+
380457
static const struct acpi_device_id soc_button_acpi_match[] = {
381-
{ "PNP0C40", (unsigned long)soc_button_PNP0C40 },
458+
{ "PNP0C40", (unsigned long)&soc_device_PNP0C40 },
382459
{ "ACPI0011", 0 },
460+
461+
/* Microsoft Surface Devices (5th and 6th generation) */
462+
{ "MSHW0040", (unsigned long)&soc_device_MSHW0040 },
463+
383464
{ }
384465
};
385466

0 commit comments

Comments
 (0)