acpi_device: Add helper macros for setting acpi_gpio fields

This change adds helper macros for initializing acpi_gpio fields
for GpioIo/GpioInt objects. This allows dropping some redundant code
for each macro to set the structure fields.

Change-Id: Id0a655468759ed3035c6c1e8770e37f1275e344e
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/42967
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Furquan Shaikh
2020-07-01 01:17:42 -07:00
parent 8c88ceca57
commit 7245100cdd

View File

@@ -185,134 +185,96 @@ struct acpi_gpio {
enum acpi_gpio_polarity polarity; enum acpi_gpio_polarity polarity;
}; };
/* Basic output GPIO with default pull settings */ /* GpioIo-related macros */
#define ACPI_GPIO_OUTPUT_ACTIVE_HIGH(gpio) { \ #define ACPI_GPIO_CFG(_gpio, _io_restrict, _polarity) { \
.type = ACPI_GPIO_TYPE_IO, \ .type = ACPI_GPIO_TYPE_IO, \
.pull = ACPI_GPIO_PULL_DEFAULT, \ .pull = ACPI_GPIO_PULL_DEFAULT, \
.io_restrict = ACPI_GPIO_IO_RESTRICT_OUTPUT, \ .io_restrict = _io_restrict, \
.polarity = ACPI_GPIO_ACTIVE_HIGH, \ .polarity = _polarity, \
.pin_count = 1, \ .pin_count = 1, \
.pins = { (gpio) } } .pins = { (_gpio) } }
#define ACPI_GPIO_OUTPUT_ACTIVE_LOW(gpio) { \ /* Basic output GPIO with default pull settings */
.type = ACPI_GPIO_TYPE_IO, \ #define ACPI_GPIO_OUTPUT_CFG(gpio, polarity) \
.pull = ACPI_GPIO_PULL_DEFAULT, \ ACPI_GPIO_CFG(gpio, ACPI_GPIO_IO_RESTRICT_OUTPUT, polarity)
.io_restrict = ACPI_GPIO_IO_RESTRICT_OUTPUT, \
.polarity = ACPI_GPIO_ACTIVE_LOW, \ #define ACPI_GPIO_OUTPUT_ACTIVE_HIGH(gpio) \
.pin_count = 1, \ ACPI_GPIO_OUTPUT_CFG(gpio, ACPI_GPIO_ACTIVE_HIGH)
.pins = { (gpio) } }
#define ACPI_GPIO_OUTPUT_ACTIVE_LOW(gpio) \
ACPI_GPIO_OUTPUT_CFG(gpio, ACPI_GPIO_ACTIVE_LOW)
/* Basic input GPIO with default pull settings */ /* Basic input GPIO with default pull settings */
#define ACPI_GPIO_INPUT_ACTIVE_HIGH(gpio) { \ #define ACPI_GPIO_INPUT_CFG(gpio, polarity) \
.type = ACPI_GPIO_TYPE_IO, \ ACPI_GPIO_CFG(gpio, ACPI_GPIO_IO_RESTRICT_INPUT, polarity)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.io_restrict = ACPI_GPIO_IO_RESTRICT_INPUT, \
.polarity = ACPI_GPIO_ACTIVE_HIGH, \
.pin_count = 1, \
.pins = { (gpio) } }
#define ACPI_GPIO_INPUT_ACTIVE_LOW(gpio) { \ #define ACPI_GPIO_INPUT_ACTIVE_HIGH(gpio) \
.type = ACPI_GPIO_TYPE_IO, \ ACPI_GPIO_INPUT_CFG(gpio, ACPI_GPIO_ACTIVE_HIGH)
#define ACPI_GPIO_INPUT_ACTIVE_LOW(gpio) \
ACPI_GPIO_INPUT_CFG(gpio, ACPI_GPIO_ACTIVE_LOW)
/* GpioInt-related macros */
#define ACPI_GPIO_IRQ_CFG(_gpio, _mode, _polarity, _wake) { \
.type = ACPI_GPIO_TYPE_INTERRUPT, \
.pull = ACPI_GPIO_PULL_DEFAULT, \ .pull = ACPI_GPIO_PULL_DEFAULT, \
.io_restrict = ACPI_GPIO_IO_RESTRICT_INPUT, \ .irq.mode = _mode, \
.polarity = ACPI_GPIO_ACTIVE_LOW, \ .irq.polarity = _polarity, \
.irq.wake = _wake, \
.pin_count = 1, \ .pin_count = 1, \
.pins = { (gpio) } } .pins = { (_gpio) } }
#define ACPI_GPIO_IRQ_EDGE(gpio, polarity) \
ACPI_GPIO_IRQ_CFG(gpio, ACPI_IRQ_EDGE_TRIGGERED, polarity, 0)
#define ACPI_GPIO_IRQ_EDGE_WAKE(gpio, polarity) \
ACPI_GPIO_IRQ_CFG(gpio, ACPI_IRQ_EDGE_TRIGGERED, polarity, ACPI_IRQ_WAKE)
#define ACPI_GPIO_IRQ_LEVEL(gpio, polarity) \
ACPI_GPIO_IRQ_CFG(gpio, ACPI_IRQ_LEVEL_TRIGGERED, polarity, 0)
#define ACPI_GPIO_IRQ_LEVEL_WAKE(gpio, polarity) \
ACPI_GPIO_IRQ_CFG(gpio, ACPI_IRQ_LEVEL_TRIGGERED, polarity, ACPI_IRQ_WAKE)
/* Edge Triggered Active High GPIO interrupt */ /* Edge Triggered Active High GPIO interrupt */
#define ACPI_GPIO_IRQ_EDGE_HIGH(gpio) { \ #define ACPI_GPIO_IRQ_EDGE_HIGH(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_EDGE(gpio, ACPI_IRQ_ACTIVE_HIGH)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Edge Triggered Active Low GPIO interrupt */ /* Edge Triggered Active Low GPIO interrupt */
#define ACPI_GPIO_IRQ_EDGE_LOW(gpio) { \ #define ACPI_GPIO_IRQ_EDGE_LOW(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_EDGE(gpio, ACPI_IRQ_ACTIVE_LOW)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Edge Triggered Active Both GPIO interrupt */ /* Edge Triggered Active Both GPIO interrupt */
#define ACPI_GPIO_IRQ_EDGE_BOTH(gpio) { \ #define ACPI_GPIO_IRQ_EDGE_BOTH(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_EDGE(gpio, ACPI_IRQ_ACTIVE_BOTH)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_BOTH, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Edge Triggered Active High GPIO interrupt with wake */ /* Edge Triggered Active High GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_EDGE_HIGH_WAKE(gpio) { \ #define ACPI_GPIO_IRQ_EDGE_HIGH_WAKE(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_EDGE_WAKE(gpio, ACPI_IRQ_ACTIVE_HIGH)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Edge Triggered Active Low GPIO interrupt with wake */ /* Edge Triggered Active Low GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_EDGE_LOW_WAKE(gpio) { \ #define ACPI_GPIO_IRQ_EDGE_LOW_WAKE(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_EDGE_WAKE(gpio, ACPI_IRQ_ACTIVE_LOW)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Edge Triggered Active Both GPIO interrupt with wake */ /* Edge Triggered Active Both GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_EDGE_BOTH_WAKE(gpio) { \ #define ACPI_GPIO_IRQ_EDGE_BOTH_WAKE(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_EDGE_WAKE(gpio, ACPI_IRQ_ACTIVE_BOTH)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_BOTH, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Level Triggered Active High GPIO interrupt */ /* Level Triggered Active High GPIO interrupt */
#define ACPI_GPIO_IRQ_LEVEL_HIGH(gpio) { \ #define ACPI_GPIO_IRQ_LEVEL_HIGH(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_LEVEL(gpio, ACPI_IRQ_ACTIVE_HIGH)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Level Triggered Active Low GPIO interrupt */ /* Level Triggered Active Low GPIO interrupt */
#define ACPI_GPIO_IRQ_LEVEL_LOW(gpio) { \ #define ACPI_GPIO_IRQ_LEVEL_LOW(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_LEVEL(gpio, ACPI_IRQ_ACTIVE_LOW)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Level Triggered Active High GPIO interrupt with wake */ /* Level Triggered Active High GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_LEVEL_HIGH_WAKE(gpio) { \ #define ACPI_GPIO_IRQ_LEVEL_HIGH_WAKE(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_LEVEL_WAKE(gpio, ACPI_IRQ_ACTIVE_HIGH)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Level Triggered Active Low GPIO interrupt with wake */ /* Level Triggered Active Low GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_LEVEL_LOW_WAKE(gpio) { \ #define ACPI_GPIO_IRQ_LEVEL_LOW_WAKE(gpio) \
.type = ACPI_GPIO_TYPE_INTERRUPT, \ ACPI_GPIO_IRQ_LEVEL_WAKE(gpio, ACPI_IRQ_ACTIVE_LOW)
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }
/* Write GpioIo() or GpioInt() descriptor to SSDT AML output */ /* Write GpioIo() or GpioInt() descriptor to SSDT AML output */
void acpi_device_write_gpio(const struct acpi_gpio *gpio); void acpi_device_write_gpio(const struct acpi_gpio *gpio);