From 4367daae204ed04f4d1e759dd94a23fefd6e8752 Mon Sep 17 00:00:00 2001 From: Ivy Jian Date: Mon, 7 Jul 2025 09:53:30 +0800 Subject: [PATCH] drivers/spi: Add option to generate proper PowerResource _STA The _STA method of drivers/spi PowerResource currently always returns true. To allow generating _STA that returns the device's actual power state, this CL adds a new boolean option `use_gpio_for_status` to the `drivers_spi_acpi_config` struct, and propagates the value to `acpi_power_res_params` to reuse the feature implemented for acpi/device in [1]. [1] https://review.coreboot.org/c/coreboot/+/55027 BUG=b:428793056 TEST=Dump SSDT on kinmen with use_gpio_for_status=true Scope (\_SB.PCI0.SPI0) { Device (CRFP) { ... ... PowerResource (PR00, 0x00, 0x0000) { Method (_STA, 0, Serialized) // _STA: Status { 0x5D = \_SB.PCI0.GTXS /* External reference */ Local0 If (!Local0) { Return (Zero) } 0x27 = \_SB.PCI0.GTXS /* External reference */ Local0 Local0 ^= One If (Local0) { Return (Zero) } Return (One) } Method (_ON, 0, Serialized) // _ON_: Power On { Local0 = _STA () If ((Local0 == One)) { Return (Zero) } \_SB.PCI0.CTXS (0x27) \_SB.PCI0.STXS (0x5D) Sleep (0x03) \_SB.PCI0.STXS (0x27) } Method (_OFF, 0, Serialized) // _OFF: Power Off { \_SB.PCI0.CTXS (0x27) \_SB.PCI0.CTXS (0x5D) } } } } Change-Id: I9591957f2db66081ffe447f91afd6655835d8feb Signed-off-by: Ivy Jian Reviewed-on: https://review.coreboot.org/c/coreboot/+/88337 Tested-by: build bot (Jenkins) Reviewed-by: Subrata Banik --- src/drivers/spi/acpi/acpi.c | 3 ++- src/drivers/spi/acpi/chip.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/drivers/spi/acpi/acpi.c b/src/drivers/spi/acpi/acpi.c index bd3f89a857..be049173b6 100644 --- a/src/drivers/spi/acpi/acpi.c +++ b/src/drivers/spi/acpi/acpi.c @@ -166,7 +166,8 @@ static void spi_acpi_fill_ssdt_generator(const struct device *dev) config->enable_off_delay_ms, &config->stop_gpio, config->stop_delay_ms, - config->stop_off_delay_ms + config->stop_off_delay_ms, + config->use_gpio_for_status }; acpi_device_add_power_res(&power_res_params); } diff --git a/src/drivers/spi/acpi/chip.h b/src/drivers/spi/acpi/chip.h index b7b39f7c3a..54c5cadd52 100644 --- a/src/drivers/spi/acpi/chip.h +++ b/src/drivers/spi/acpi/chip.h @@ -47,6 +47,12 @@ struct drivers_spi_acpi_config { /* Generic properties for exporting device-specific data to the OS */ struct acpi_dp property_list[MAX_GENERIC_PROPERTY_LIST]; unsigned int property_count; + + /* Write a _STA method that uses the state of the GPIOs to determine if + * the PowerResource is ON or OFF. If this is false, the _STA method + * will always return ON. + */ + bool use_gpio_for_status; }; #endif /* __SPI_ACPI_CHIP_H__ */