From 31912b61a7c19515f5f5decae8ccad7b8e42f4cf Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Tue, 10 Dec 2013 14:58:03 -0800 Subject: crossystem: add GpioChipset sturcture for x86 Up until recently the x86 systems had a single contiguous set of gpio numbers exported through /sys/class/gpio as /sys/class/gpiochip values. BayTrail systems have 3 sets of gpio numbers. Therefore, there needs to be a translation/look-up function based on chipset. The existing chipsets have a 1:1 mapping, but this patch lays the ground- work for chipset-specific translation. BUG=chrome-os-partner:24324 BUG=chrome-os-partner:24440 BUG=chrome-os-partner:24408 BRANCH=None TEST=Built. Ran on Rambi. Change-Id: I32bcd975aea421f86a0220ee30332f48fe727656 Signed-off-by: Aaron Durbin Reviewed-on: https://chromium-review.googlesource.com/179512 Reviewed-by: Duncan Laurie --- host/arch/x86/lib/crossystem_arch.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index bc899a2b..922dc649 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -499,7 +499,7 @@ static char* ReadPlatformFamilyString(char* dest, int size) { * we look for a directory named /sys/class/gpio/gpiochip/. If there's not * exactly one match for that, we're SOL. */ -static int FindGpioChipOffset(int *offset) { +static int FindGpioChipOffset(int *gpio_num, int *offset) { DIR *dir; struct dirent *ent; int match = 0; @@ -520,6 +520,30 @@ static int FindGpioChipOffset(int *offset) { } +struct GpioChipset { + const char *name; + int (*ChipOffsetAndGpioNumber)(int *gpio_num, int *chip_offset); +}; + +static const struct GpioChipset chipsets_supported[] = { + { "NM10", FindGpioChipOffset }, + { "CougarPoint", FindGpioChipOffset }, + { "PantherPoint", FindGpioChipOffset }, + { "LynxPoint", FindGpioChipOffset }, + { NULL }, +}; + +static const struct GpioChipset *FindChipset(const char *name) { + const struct GpioChipset *chipset = &chipsets_supported[0]; + + while (chipset->name != NULL) { + if (!strcmp(name, chipset->name)) + return chipset; + chipset++; + } + return NULL; +} + /* Read a GPIO of the specified signal type (see ACPI GPIO SignalType). * * Returns 1 if the signal is asserted, 0 if not asserted, or -1 if error. */ @@ -532,6 +556,7 @@ static int ReadGpio(int signal_type) { int controller_offset = 0; char controller_name[128]; int value; + const struct GpioChipset *chipset; /* Scan GPIO.* to find a matching signal type */ for (index = 0; ; index++) { @@ -555,14 +580,12 @@ static int ReadGpio(int signal_type) { snprintf(name, sizeof(name), "%s.%d/GPIO.3", ACPI_GPIO_PATH, index); if (!ReadFileString(controller_name, sizeof(controller_name), name)) return -1; - if ((0 != strcmp(controller_name, "NM10")) && - (0 != strcmp(controller_name, "CougarPoint")) && - (0 != strcmp(controller_name, "PantherPoint")) && - (0 != strcmp(controller_name, "LynxPoint"))) + chipset = FindChipset(controller_name); + if (chipset == NULL) return -1; /* Modify GPIO number by driver's offset */ - if (!FindGpioChipOffset(&controller_offset)) + if (!chipset->ChipOffsetAndGpioNumber(&controller_num, &controller_offset)) return -1; controller_offset += controller_num; -- cgit v1.2.1