// 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>
/* Parse the ACPI package and return the data related to that attribute */ staticint 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: return sysfs_emit(buf, "%s\n", element->string.pointer); case ACPI_TYPE_BUFFER:
{ int i, r, at, room_left; constint byte_per_line = 16;
at = 0;
room_left = PAGE_SIZE - 1; for (i = 0; i < element->buffer.length && room_left; i += byte_per_line) {
r = hex_dump_to_buffer(element->buffer.pointer + i,
element->buffer.length - i,
byte_per_line, 1, buf + at, room_left, false); if (r > room_left) goto truncating;
at += r;
room_left -= r;
r = sysfs_emit_at(buf, at, "\n"); if (!r) goto truncating;
at += r;
room_left -= r;
}
/* * Every platform can have a different number of GPIO attribute groups. * Define upper limit groups. At run time, the platform decides to show * the present number of groups only, others are hidden.
*/
GPIO_ATTR_GROUP(gpio0, "GPIO.0", 0)
GPIO_ATTR_GROUP(gpio1, "GPIO.1", 1)
GPIO_ATTR_GROUP(gpio2, "GPIO.2", 2)
GPIO_ATTR_GROUP(gpio3, "GPIO.3", 3)
GPIO_ATTR_GROUP(gpio4, "GPIO.4", 4)
GPIO_ATTR_GROUP(gpio5, "GPIO.5", 5)
GPIO_ATTR_GROUP(gpio6, "GPIO.6", 6)
GPIO_ATTR_GROUP(gpio7, "GPIO.7", 7)
/* * If the platform has more GPIO attribute groups than the number of * groups this driver supports, give out a warning message.
*/ if (chromeos_acpi_gpio_groups > ARRAY_SIZE(chromeos_acpi_all_groups) - 2)
dev_warn(&pdev->dev, "Only %zu GPIO attr groups supported by the driver out of total %u.\n",
ARRAY_SIZE(chromeos_acpi_all_groups) - 2, chromeos_acpi_gpio_groups); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.