From 4ebc940b39b6a43de9d1fa74653321cd6fdb4d3a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 7 Jul 2020 13:11:47 -0600 Subject: acpi: Support generation of a GPIO/irq for a device Some devices use interrupts but some use GPIOs. Since these are fully specified in the device tree we can automatically produce the correct ACPI descriptor for a device. Add a function to handle this. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner Reviewed-by: Bin Meng --- lib/acpi/acpi_device.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'lib/acpi') diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c index bbe1cfc57ad..c93af2e5837 100644 --- a/lib/acpi/acpi_device.c +++ b/lib/acpi/acpi_device.c @@ -354,5 +354,34 @@ int acpi_device_write_gpio_desc(struct acpi_ctx *ctx, if (ret < 0) return log_msg_ret("gpio", ret); - return 0; + return ret; +} + +int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx, + struct udevice *dev, const char *prop) +{ + struct irq req_irq; + int pin; + int ret; + + ret = irq_get_by_index(dev, 0, &req_irq); + if (!ret) { + ret = acpi_device_write_interrupt_irq(ctx, &req_irq); + if (ret < 0) + return log_msg_ret("irq", ret); + pin = ret; + } else { + struct gpio_desc req_gpio; + + ret = gpio_request_by_name(dev, prop, 0, &req_gpio, + GPIOD_IS_IN); + if (ret) + return log_msg_ret("no gpio", ret); + ret = acpi_device_write_gpio_desc(ctx, &req_gpio); + if (ret < 0) + return log_msg_ret("gpio", ret); + pin = ret; + } + + return pin; } -- cgit v1.2.3