1 // SPDX-License-Identifier: GPL-2.0
2 // Driver to detect Tablet Mode for ChromeOS convertible.
4 // Copyright (C) 2017 Google, Inc.
5 // Author: Gwendal Grignou <gwendal@chromium.org>
7 // On Chromebook using ACPI, this device listens for notification
8 // from GOOG0006 and issue method TBMC to retrieve the status.
10 // GOOG0006 issues the notification when it receives EC_HOST_EVENT_MODE_CHANGE
12 // Method TBMC reads EC_ACPI_MEM_DEVICE_ORIENTATION byte from the shared
15 #include <linux/acpi.h>
16 #include <linux/input.h>
18 #include <linux/module.h>
19 #include <linux/printk.h>
21 #define DRV_NAME "chromeos_tbmc"
22 #define ACPI_DRV_NAME "GOOG0006"
24 static int chromeos_tbmc_query_switch(struct acpi_device
*adev
,
25 struct input_dev
*idev
)
27 unsigned long long state
;
30 status
= acpi_evaluate_integer(adev
->handle
, "TBMC", NULL
, &state
);
31 if (ACPI_FAILURE(status
))
34 /* input layer checks if event is redundant */
35 input_report_switch(idev
, SW_TABLET_MODE
, state
);
41 static __maybe_unused
int chromeos_tbmc_resume(struct device
*dev
)
43 struct acpi_device
*adev
= to_acpi_device(dev
);
45 return chromeos_tbmc_query_switch(adev
, adev
->driver_data
);
48 static void chromeos_tbmc_notify(struct acpi_device
*adev
, u32 event
)
50 acpi_pm_wakeup_event(&adev
->dev
);
53 chromeos_tbmc_query_switch(adev
, adev
->driver_data
);
56 dev_err(&adev
->dev
, "Unexpected event: 0x%08X\n", event
);
60 static int chromeos_tbmc_open(struct input_dev
*idev
)
62 struct acpi_device
*adev
= input_get_drvdata(idev
);
64 return chromeos_tbmc_query_switch(adev
, idev
);
67 static int chromeos_tbmc_add(struct acpi_device
*adev
)
69 struct input_dev
*idev
;
70 struct device
*dev
= &adev
->dev
;
73 idev
= devm_input_allocate_device(dev
);
77 idev
->name
= "Tablet Mode Switch";
78 idev
->phys
= acpi_device_hid(adev
);
80 idev
->id
.bustype
= BUS_HOST
;
83 idev
->open
= chromeos_tbmc_open
;
85 input_set_drvdata(idev
, adev
);
86 adev
->driver_data
= idev
;
88 input_set_capability(idev
, EV_SW
, SW_TABLET_MODE
);
89 ret
= input_register_device(idev
);
91 dev_err(dev
, "cannot register input device\n");
94 device_init_wakeup(dev
, true);
98 static const struct acpi_device_id chromeos_tbmc_acpi_device_ids
[] = {
102 MODULE_DEVICE_TABLE(acpi
, chromeos_tbmc_acpi_device_ids
);
104 static SIMPLE_DEV_PM_OPS(chromeos_tbmc_pm_ops
, NULL
,
105 chromeos_tbmc_resume
);
107 static struct acpi_driver chromeos_tbmc_driver
= {
110 .ids
= chromeos_tbmc_acpi_device_ids
,
112 .add
= chromeos_tbmc_add
,
113 .notify
= chromeos_tbmc_notify
,
115 .drv
.pm
= &chromeos_tbmc_pm_ops
,
118 module_acpi_driver(chromeos_tbmc_driver
);
120 MODULE_LICENSE("GPL v2");
121 MODULE_DESCRIPTION("ChromeOS ACPI tablet switch driver");