drivers/platform/chrome/chromeos_acpi.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/chromeos_acpi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/chromeos_acpi.c- Extension
.c- Size
- 8346 bytes
- Lines
- 287
- 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/platform_device.hlinux/kernel.hlinux/list.hlinux/module.h
Detected Declarations
function chromeos_acpi_handle_packagefunction chromeos_acpi_evaluate_methodfunction parse_attr_namefunction chromeos_first_level_attr_showfunction get_gpio_pkg_numfunction chromeos_acpi_device_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* ChromeOS specific ACPI extensions
*
* Copyright 2022 Google LLC
*
* This driver attaches to the ChromeOS ACPI device and then exports the
* values reported by the ACPI in a sysfs directory. All values are
* presented in the string form (numbers as decimal values) and can be
* accessed as the contents of the appropriate read only files in the
* sysfs directory tree.
*/
#include <linux/acpi.h>
#include <linux/platform_device.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#define ACPI_ATTR_NAME_LEN 4
#define DEV_ATTR(_var, _name) \
static struct device_attribute dev_attr_##_var = \
__ATTR(_name, 0444, chromeos_first_level_attr_show, NULL);
#define GPIO_ATTR_GROUP(_group, _name, _num) \
static umode_t attr_is_visible_gpio_##_num(struct kobject *kobj, \
struct attribute *attr, int n) \
{ \
if (_num < chromeos_acpi_gpio_groups) \
return attr->mode; \
return 0; \
} \
static ssize_t chromeos_attr_show_gpio_##_num(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
char name[ACPI_ATTR_NAME_LEN + 1]; \
int ret, num; \
\
ret = parse_attr_name(attr->attr.name, name, &num); \
if (ret) \
return ret; \
return chromeos_acpi_evaluate_method(dev, _num, num, name, buf); \
} \
static struct device_attribute dev_attr_0_##_group = \
__ATTR(GPIO.0, 0444, chromeos_attr_show_gpio_##_num, NULL); \
static struct device_attribute dev_attr_1_##_group = \
__ATTR(GPIO.1, 0444, chromeos_attr_show_gpio_##_num, NULL); \
static struct device_attribute dev_attr_2_##_group = \
__ATTR(GPIO.2, 0444, chromeos_attr_show_gpio_##_num, NULL); \
static struct device_attribute dev_attr_3_##_group = \
__ATTR(GPIO.3, 0444, chromeos_attr_show_gpio_##_num, NULL); \
\
static struct attribute *attrs_##_group[] = { \
&dev_attr_0_##_group.attr, \
&dev_attr_1_##_group.attr, \
&dev_attr_2_##_group.attr, \
&dev_attr_3_##_group.attr, \
NULL \
}; \
static const struct attribute_group attr_group_##_group = { \
.name = _name, \
.is_visible = attr_is_visible_gpio_##_num, \
.attrs = attrs_##_group, \
};
static unsigned int chromeos_acpi_gpio_groups;
/* Parse the ACPI package and return the data related to that attribute */
static int chromeos_acpi_handle_package(struct device *dev, union acpi_object *obj,
int pkg_num, int sub_pkg_num, char *name, char *buf)
{
union acpi_object *element = obj->package.elements;
if (pkg_num >= obj->package.count)
return -EINVAL;
element += pkg_num;
if (element->type == ACPI_TYPE_PACKAGE) {
if (sub_pkg_num >= element->package.count)
return -EINVAL;
/* select sub element inside this package */
element = element->package.elements;
element += sub_pkg_num;
}
switch (element->type) {
case ACPI_TYPE_INTEGER:
return sysfs_emit(buf, "%d\n", (int)element->integer.value);
case ACPI_TYPE_STRING:
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/platform_device.h`, `linux/kernel.h`, `linux/list.h`, `linux/module.h`.
- Detected declarations: `function chromeos_acpi_handle_package`, `function chromeos_acpi_evaluate_method`, `function parse_attr_name`, `function chromeos_first_level_attr_show`, `function get_gpio_pkg_num`, `function chromeos_acpi_device_probe`.
- 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.