drivers/platform/chrome/chromeos_tbmc.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/chromeos_tbmc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/chromeos_tbmc.c- Extension
.c- Size
- 3574 bytes
- Lines
- 143
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/acpi.hlinux/input.hlinux/io.hlinux/module.hlinux/platform_device.hlinux/printk.h
Detected Declarations
function chromeos_tbmc_query_switchfunction chromeos_tbmc_resumefunction chromeos_tbmc_notifyfunction chromeos_tbmc_openfunction chromeos_tbmc_probefunction chromeos_tbmc_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
// Driver to detect Tablet Mode for ChromeOS convertible.
//
// Copyright (C) 2017 Google, Inc.
// Author: Gwendal Grignou <gwendal@chromium.org>
//
// 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 <linux/acpi.h>
#include <linux/input.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/printk.h>
#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, &state);
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)
{
return chromeos_tbmc_query_switch(ACPI_COMPANION(dev), dev_get_drvdata(dev));
}
static void chromeos_tbmc_notify(acpi_handle handle, u32 event, void *data)
{
struct device *dev = data;
acpi_pm_wakeup_event(dev);
switch (event) {
case 0x80:
chromeos_tbmc_query_switch(ACPI_COMPANION(dev), dev_get_drvdata(dev));
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_probe(struct platform_device *pdev)
{
struct input_dev *idev;
struct device *dev = &pdev->dev;
struct acpi_device *adev;
int ret;
adev = ACPI_COMPANION(dev);
if (!adev)
return -ENODEV;
idev = devm_input_allocate_device(dev);
if (!idev)
return -ENOMEM;
idev->name = "Tablet Mode Switch";
idev->phys = acpi_device_hid(adev);
idev->id.bustype = BUS_HOST;
idev->id.version = 1;
idev->id.product = 0;
idev->open = chromeos_tbmc_open;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/input.h`, `linux/io.h`, `linux/module.h`, `linux/platform_device.h`, `linux/printk.h`.
- Detected declarations: `function chromeos_tbmc_query_switch`, `function chromeos_tbmc_resume`, `function chromeos_tbmc_notify`, `function chromeos_tbmc_open`, `function chromeos_tbmc_probe`, `function chromeos_tbmc_remove`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.