1 // SPDX-License-Identifier: GPL-2.0
2 // Driver to detect Tablet Mode for ChromeOS convertible.
4 // Copyright (C) 2017 Google, Inc.
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)
52 chromeos_tbmc_query_switch(adev, adev->driver_data);
55 dev_err(&adev->dev, "Unexpected event: 0x%08X\n", event);
59 static int chromeos_tbmc_open(struct input_dev *idev)
61 struct acpi_device *adev = input_get_drvdata(idev);
63 return chromeos_tbmc_query_switch(adev, idev);
66 static int chromeos_tbmc_add(struct acpi_device *adev)
68 struct input_dev *idev;
69 struct device *dev = &adev->dev;
72 idev = devm_input_allocate_device(dev);
76 idev->name = "Tablet Mode Switch";
77 idev->phys = acpi_device_hid(adev);
79 idev->id.bustype = BUS_HOST;
82 idev->open = chromeos_tbmc_open;
84 input_set_drvdata(idev, adev);
85 adev->driver_data = idev;
87 input_set_capability(idev, EV_SW, SW_TABLET_MODE);
88 ret = input_register_device(idev);
90 dev_err(dev, "cannot register input device\n");
96 static const struct acpi_device_id chromeos_tbmc_acpi_device_ids[] = {
100 MODULE_DEVICE_TABLE(acpi, chromeos_tbmc_acpi_device_ids);
102 static SIMPLE_DEV_PM_OPS(chromeos_tbmc_pm_ops, NULL,
103 chromeos_tbmc_resume);
105 static struct acpi_driver chromeos_tbmc_driver = {
108 .ids = chromeos_tbmc_acpi_device_ids,
110 .add = chromeos_tbmc_add,
111 .notify = chromeos_tbmc_notify,
113 .drv.pm = &chromeos_tbmc_pm_ops,
116 module_acpi_driver(chromeos_tbmc_driver);
118 MODULE_LICENSE("GPL v2");
119 MODULE_DESCRIPTION("ChromeOS ACPI tablet switch driver");