Re: [PATCH v2] platform: chrome: Add Tablet Switch ACPI driver
Hi Gwendal, Overall, this looks good to me, but please make sure this is based on upstream, and not the ChromeOS kernel trees. On 01/30/2017 11:30 AM, Gwendal Grignou wrote: > Add a kernel driver for GOOG0006, an ACPI driver reporting an event when > the tablet switch status changes. > > On an ACPI based convertible chromebook check evtest display tablet mode > switch changes: > Available devices: > .. > /dev/input/event3: Tablet Mode Switch > .. > Testing ... (interrupt to exit) > Event: time 1484879712.604360, type 5 (EV_SW), code 1 (SW_TABLET_MODE), > value 1 > Event: time 1484879712.604360, -- SYN_REPORT > Event: time 1484879715.132228, type 5 (EV_SW), code 1 (SW_TABLET_MODE), > value 0 > Event: time 1484879715.132228, -- SYN_REPORT > ... > Check state is updated at resume time when different from suspend time. > > Change-Id: Ie51d426de68770fad8eeb83aaab9abe8d69e84a2 Strip off the gerrit Change-Id: as it is meaningless upstream. Thanks! Benson -- Benson Leung Senior Software Engineer Chrome OS Kernel Google Inc. ble...@google.com Chromium OS Project ble...@chromium.org signature.asc Description: OpenPGP digital signature
Re: [PATCH v2] platform: chrome: Add Tablet Switch ACPI driver
Hi Gwendal, Overall, this looks good to me, but please make sure this is based on upstream, and not the ChromeOS kernel trees. On 01/30/2017 11:30 AM, Gwendal Grignou wrote: > Add a kernel driver for GOOG0006, an ACPI driver reporting an event when > the tablet switch status changes. > > On an ACPI based convertible chromebook check evtest display tablet mode > switch changes: > Available devices: > .. > /dev/input/event3: Tablet Mode Switch > .. > Testing ... (interrupt to exit) > Event: time 1484879712.604360, type 5 (EV_SW), code 1 (SW_TABLET_MODE), > value 1 > Event: time 1484879712.604360, -- SYN_REPORT > Event: time 1484879715.132228, type 5 (EV_SW), code 1 (SW_TABLET_MODE), > value 0 > Event: time 1484879715.132228, -- SYN_REPORT > ... > Check state is updated at resume time when different from suspend time. > > Change-Id: Ie51d426de68770fad8eeb83aaab9abe8d69e84a2 Strip off the gerrit Change-Id: as it is meaningless upstream. Thanks! Benson -- Benson Leung Senior Software Engineer Chrome OS Kernel Google Inc. ble...@google.com Chromium OS Project ble...@chromium.org signature.asc Description: OpenPGP digital signature
[PATCH v2] platform: chrome: Add Tablet Switch ACPI driver
Add a kernel driver for GOOG0006, an ACPI driver reporting an event when the tablet switch status changes. On an ACPI based convertible chromebook check evtest display tablet mode switch changes: Available devices: .. /dev/input/event3: Tablet Mode Switch .. Testing ... (interrupt to exit) Event: time 1484879712.604360, type 5 (EV_SW), code 1 (SW_TABLET_MODE), value 1 Event: time 1484879712.604360, -- SYN_REPORT Event: time 1484879715.132228, type 5 (EV_SW), code 1 (SW_TABLET_MODE), value 0 Event: time 1484879715.132228, -- SYN_REPORT ... Check state is updated at resume time when different from suspend time. Change-Id: Ie51d426de68770fad8eeb83aaab9abe8d69e84a2 Signed-off-by: Gwendal Grignou--- drivers/platform/chrome/Kconfig | 10 +++ drivers/platform/chrome/Makefile| 1 + drivers/platform/chrome/chromeos_tbmc.c | 128 3 files changed, 139 insertions(+) create mode 100644 drivers/platform/chrome/chromeos_tbmc.c diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 348f7859c85f..ef54f6c52886 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -55,6 +55,16 @@ config CHROMEOS_PSTORE If you have a supported Chromebook, choose Y or M here. The module will be called chromeos_pstore. +config CHROMEOS_TBMC + tristate "ChromeOS Tablet Switch Controller" + depends on ACPI + ---help--- + This option adds a driver for the tablet switch on + select Chrome OS systems. + + To compile this driver as a module, choose M here: the + module will be called chromeos_tbmc. + config CHROMEOS_VBC_EC bool depends on CHROMEOS diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index fa28d0b1a697..a2a2e17a6ae4 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -3,4 +3,5 @@ obj-$(CONFIG_CHROMEOS) += chromeos.o obj-$(CONFIG_CHROMEOS_OF_FIRMWARE) += chromeos_arm.o obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o +obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o obj-$(CONFIG_CHROMEOS_VBC_EC) += chromeos_vbc_ec.o diff --git a/drivers/platform/chrome/chromeos_tbmc.c b/drivers/platform/chrome/chromeos_tbmc.c new file mode 100644 index ..c87e53319dae --- /dev/null +++ b/drivers/platform/chrome/chromeos_tbmc.c @@ -0,0 +1,128 @@ +/* + * chromeos_tbmc - Driver to detect Tablet Mode for ChromeOS convertible. + * + * Copyright 2017 Google, Inc + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * On Chromebook using ACPI, this device listens for notification + * from GOOG0006 and issue method TBMC to retrieve the status. + * + * GOOG0006 issues the notification when it receives EC_HOST_EVENT_MODE_CHANGE + * from the EC. + * Method TBMC reads EC_ACPI_MEM_DEVICE_ORIENTATION byte from the shared + * memory region. + */ + +#include +#include +#include +#include +#include + +#define DRV_NAME "chromeos_tbmc" +#define ACPI_DRV_NAME "GOOG0006" + +static int chromeos_tbmc_query_switch(struct acpi_device *adev, +struct input_dev *idev) +{ + unsigned long long state; + acpi_status status; + + status = acpi_evaluate_integer(adev->handle, "TBMC", NULL, ); + if (ACPI_FAILURE(status)) + return -ENODEV; + + /* input layer checks if event is redundant */ + input_report_switch(idev, SW_TABLET_MODE, state); + input_sync(idev); + + return 0; +} + +static __maybe_unused int chromeos_tbmc_resume(struct device *dev) +{ + struct acpi_device *adev = to_acpi_device(dev); + + return chromeos_tbmc_query_switch(adev, adev->driver_data); +} + +static void chromeos_tbmc_notify(struct acpi_device *adev, u32 event) +{ + switch (event) { + case 0x80: + chromeos_tbmc_query_switch(adev, adev->driver_data); + break; + default: + dev_err(>dev, "Unexpected event: 0x%08X\n", event); + } +} + +static int chromeos_tbmc_open(struct input_dev *idev) +{ + struct acpi_device *adev = input_get_drvdata(idev); + + return chromeos_tbmc_query_switch(adev, idev); +} + +static int chromeos_tbmc_add(struct acpi_device *adev) +{ + struct input_dev *idev; + struct device *dev = >dev; + int ret; + + idev = devm_input_allocate_device(dev); +
[PATCH v2] platform: chrome: Add Tablet Switch ACPI driver
Add a kernel driver for GOOG0006, an ACPI driver reporting an event when the tablet switch status changes. On an ACPI based convertible chromebook check evtest display tablet mode switch changes: Available devices: .. /dev/input/event3: Tablet Mode Switch .. Testing ... (interrupt to exit) Event: time 1484879712.604360, type 5 (EV_SW), code 1 (SW_TABLET_MODE), value 1 Event: time 1484879712.604360, -- SYN_REPORT Event: time 1484879715.132228, type 5 (EV_SW), code 1 (SW_TABLET_MODE), value 0 Event: time 1484879715.132228, -- SYN_REPORT ... Check state is updated at resume time when different from suspend time. Change-Id: Ie51d426de68770fad8eeb83aaab9abe8d69e84a2 Signed-off-by: Gwendal Grignou --- drivers/platform/chrome/Kconfig | 10 +++ drivers/platform/chrome/Makefile| 1 + drivers/platform/chrome/chromeos_tbmc.c | 128 3 files changed, 139 insertions(+) create mode 100644 drivers/platform/chrome/chromeos_tbmc.c diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 348f7859c85f..ef54f6c52886 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -55,6 +55,16 @@ config CHROMEOS_PSTORE If you have a supported Chromebook, choose Y or M here. The module will be called chromeos_pstore. +config CHROMEOS_TBMC + tristate "ChromeOS Tablet Switch Controller" + depends on ACPI + ---help--- + This option adds a driver for the tablet switch on + select Chrome OS systems. + + To compile this driver as a module, choose M here: the + module will be called chromeos_tbmc. + config CHROMEOS_VBC_EC bool depends on CHROMEOS diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index fa28d0b1a697..a2a2e17a6ae4 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -3,4 +3,5 @@ obj-$(CONFIG_CHROMEOS) += chromeos.o obj-$(CONFIG_CHROMEOS_OF_FIRMWARE) += chromeos_arm.o obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o +obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o obj-$(CONFIG_CHROMEOS_VBC_EC) += chromeos_vbc_ec.o diff --git a/drivers/platform/chrome/chromeos_tbmc.c b/drivers/platform/chrome/chromeos_tbmc.c new file mode 100644 index ..c87e53319dae --- /dev/null +++ b/drivers/platform/chrome/chromeos_tbmc.c @@ -0,0 +1,128 @@ +/* + * chromeos_tbmc - Driver to detect Tablet Mode for ChromeOS convertible. + * + * Copyright 2017 Google, Inc + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * On Chromebook using ACPI, this device listens for notification + * from GOOG0006 and issue method TBMC to retrieve the status. + * + * GOOG0006 issues the notification when it receives EC_HOST_EVENT_MODE_CHANGE + * from the EC. + * Method TBMC reads EC_ACPI_MEM_DEVICE_ORIENTATION byte from the shared + * memory region. + */ + +#include +#include +#include +#include +#include + +#define DRV_NAME "chromeos_tbmc" +#define ACPI_DRV_NAME "GOOG0006" + +static int chromeos_tbmc_query_switch(struct acpi_device *adev, +struct input_dev *idev) +{ + unsigned long long state; + acpi_status status; + + status = acpi_evaluate_integer(adev->handle, "TBMC", NULL, ); + if (ACPI_FAILURE(status)) + return -ENODEV; + + /* input layer checks if event is redundant */ + input_report_switch(idev, SW_TABLET_MODE, state); + input_sync(idev); + + return 0; +} + +static __maybe_unused int chromeos_tbmc_resume(struct device *dev) +{ + struct acpi_device *adev = to_acpi_device(dev); + + return chromeos_tbmc_query_switch(adev, adev->driver_data); +} + +static void chromeos_tbmc_notify(struct acpi_device *adev, u32 event) +{ + switch (event) { + case 0x80: + chromeos_tbmc_query_switch(adev, adev->driver_data); + break; + default: + dev_err(>dev, "Unexpected event: 0x%08X\n", event); + } +} + +static int chromeos_tbmc_open(struct input_dev *idev) +{ + struct acpi_device *adev = input_get_drvdata(idev); + + return chromeos_tbmc_query_switch(adev, idev); +} + +static int chromeos_tbmc_add(struct acpi_device *adev) +{ + struct input_dev *idev; + struct device *dev = >dev; + int ret; + + idev = devm_input_allocate_device(dev); + if (!idev) +