Tim Wawrzynczak has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/35073 )
Change subject: drivers/generic: Add new driver for power resource pseudo-device ......................................................................
drivers/generic: Add new driver for power resource pseudo-device
There is some duplication of fields dealing with ACPI power resources (see drivers/i2c/generic.c, also used by drivers/i2c/hid, as well as drivers/spi/acpi). This CL creates a new driver for this pseudo-device.
This patch allows a new style of dealing with power resources in the device tree:
device pci 00.0 chip drivers/generic/power_resource register "enable_gpio" = "ACPI_GPIO_OUTPUT_ACTIVE_LOW(GPP_A1)" device generic 0 on chip drivers/i2c/generic register ... end end end end
and then the power resource driver does most of the work. This should make it easier to support other drivers requiring ACPI power resources in the future (see the diff in the two changed here).
Change-Id: Id9d66fedd342eb5359d90d9778c515e7aa2de1d7 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/drivers/generic/power_resource/Kconfig A src/drivers/generic/power_resource/Makefile.inc A src/drivers/generic/power_resource/chip.h A src/drivers/generic/power_resource/power_resource.c 4 files changed, 128 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/73/35073/1
diff --git a/src/drivers/generic/power_resource/Kconfig b/src/drivers/generic/power_resource/Kconfig new file mode 100644 index 0000000..447edb9 --- /dev/null +++ b/src/drivers/generic/power_resource/Kconfig @@ -0,0 +1,5 @@ +# TODO: once everything is moved to the new power resource structure, +# those drivers that use it should auto-select this config option +config DRIVERS_GENERIC_POWER_RESOURCE + bool + depends on HAVE_ACPI_TABLES diff --git a/src/drivers/generic/power_resource/Makefile.inc b/src/drivers/generic/power_resource/Makefile.inc new file mode 100644 index 0000000..2120ef1 --- /dev/null +++ b/src/drivers/generic/power_resource/Makefile.inc @@ -0,0 +1 @@ +ramstage-$(CONFIG_DRIVERS_GENERIC_POWER_RESOURCE) += power_resource.c diff --git a/src/drivers/generic/power_resource/chip.h b/src/drivers/generic/power_resource/chip.h new file mode 100644 index 0000000..e698296 --- /dev/null +++ b/src/drivers/generic/power_resource/chip.h @@ -0,0 +1,47 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Google LLC. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * 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. + */ + +#ifndef __GENERIC_POWER_RESOURCE_CHIP_H__ +#define __GENERIC_POWER_RESOURCE_CHIP_H__ + +#include <device/device.h> +#include <arch/acpi_device.h> + +extern struct chip_operations drivers_generic_power_resource_ops; + +struct drivers_generic_power_resource_config { + /* GPIO used to take device out of reset or to put it into reset. */ + struct acpi_gpio reset_gpio; + /* Delay to be inserted after device is taken out of reset. */ + unsigned int reset_delay_ms; + /* Delay to be inserted after device is put into reset. */ + unsigned int reset_off_delay_ms; + /* GPIO used to enable device. */ + struct acpi_gpio enable_gpio; + /* Delay to be inserted after device is enabled. */ + unsigned int enable_delay_ms; + /* Delay to be inserted after device is disabled. */ + unsigned int enable_off_delay_ms; + /* GPIO used to stop operation of device. */ + struct acpi_gpio stop_gpio; + /* Delay to be inserted after disabling stop. */ + unsigned int stop_delay_ms; + /* Delay to be inserted after enabling stop. */ + unsigned int stop_off_delay_ms; + /* ACPI device name */ + char acpi_name[5]; +}; + +#endif /* __GENERIC_POWER_RESOURCE_CHIP_H__ */ diff --git a/src/drivers/generic/power_resource/power_resource.c b/src/drivers/generic/power_resource/power_resource.c new file mode 100644 index 0000000..d08c1a2 --- /dev/null +++ b/src/drivers/generic/power_resource/power_resource.c @@ -0,0 +1,75 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Google LLC. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * 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. + */ + +#include <device/device.h> +#include <device/path.h> +#include <console/console.h> +#include <string.h> +#include "chip.h" + +static void power_resource_fill_ssdt(struct device *dev) +{ + bool ret; + struct drivers_generic_power_resource_config *config = dev->chip_info; + const struct acpi_power_res_params power_res_params = { + &config->reset_gpio, + config->reset_delay_ms, + config->reset_off_delay_ms, + &config->enable_gpio, + config->enable_delay_ms, + config->enable_off_delay_ms, + &config->stop_gpio, + config->stop_delay_ms, + config->stop_off_delay_ms + }; + + ret = acpi_declare_scoped_power_resource(acpi_device_scope(dev), + acpi_device_name(dev), + &power_res_params); + if (!ret) + printk(BIOS_ERR, "Failed to add power resource %s\n", + acpi_device_name(dev)); + +} + +static const char *power_resource_acpi_name(const struct device *dev) +{ + static unsigned int count; + struct drivers_generic_power_resource_config *config = dev->chip_info; + + if (config->acpi_name[0] == '\0') + snprintf(config->acpi_name, sizeof(config->acpi_name), "PR%02X", count++); + + return config->acpi_name; +} + +static struct device_operations power_resource_ops = { + .read_resources = DEVICE_NOOP, + .set_resources = DEVICE_NOOP, + .enable_resources = DEVICE_NOOP, + .scan_bus = scan_generic_bus, + .acpi_name = power_resource_acpi_name, + .acpi_fill_ssdt_generator = power_resource_fill_ssdt +}; + +static void power_resource_enable(struct device *dev) +{ + dev->ops = &power_resource_ops; +} + +struct chip_operations drivers_generic_power_resource_ops = { + CHIP_NAME("Power Resource") + .enable_dev = power_resource_enable +};