summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2020-07-01 01:17:42 -0700
committerFurquan Shaikh <furquan@google.com>2020-07-02 19:12:38 +0000
commit7245100cddbef2626cbc208b79c889f8ac642298 (patch)
treed154ce1a0703aeb4a423860f5afa80ea4b1d7d34
parent8c88ceca578d117ec7981d61b89580570e2dbab9 (diff)
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>
-rw-r--r--src/include/acpi/acpi_device.h160
1 files changed, 61 insertions, 99 deletions
diff --git a/src/include/acpi/acpi_device.h b/src/include/acpi/acpi_device.h
index 8cf36e344f..e01b6fd027 100644
--- a/src/include/acpi/acpi_device.h
+++ b/src/include/acpi/acpi_device.h
@@ -185,134 +185,96 @@ struct acpi_gpio {
enum acpi_gpio_polarity polarity;
};
-/* Basic output GPIO with default pull settings */
-#define ACPI_GPIO_OUTPUT_ACTIVE_HIGH(gpio) { \
+/* GpioIo-related macros */
+#define ACPI_GPIO_CFG(_gpio, _io_restrict, _polarity) { \
.type = ACPI_GPIO_TYPE_IO, \
.pull = ACPI_GPIO_PULL_DEFAULT, \
- .io_restrict = ACPI_GPIO_IO_RESTRICT_OUTPUT, \
- .polarity = ACPI_GPIO_ACTIVE_HIGH, \
+ .io_restrict = _io_restrict, \
+ .polarity = _polarity, \
.pin_count = 1, \
- .pins = { (gpio) } }
+ .pins = { (_gpio) } }
-#define ACPI_GPIO_OUTPUT_ACTIVE_LOW(gpio) { \
- .type = ACPI_GPIO_TYPE_IO, \
- .pull = ACPI_GPIO_PULL_DEFAULT, \
- .io_restrict = ACPI_GPIO_IO_RESTRICT_OUTPUT, \
- .polarity = ACPI_GPIO_ACTIVE_LOW, \
- .pin_count = 1, \
- .pins = { (gpio) } }
+/* Basic output GPIO with default pull settings */
+#define ACPI_GPIO_OUTPUT_CFG(gpio, polarity) \
+ ACPI_GPIO_CFG(gpio, ACPI_GPIO_IO_RESTRICT_OUTPUT, polarity)
+
+#define ACPI_GPIO_OUTPUT_ACTIVE_HIGH(gpio) \
+ ACPI_GPIO_OUTPUT_CFG(gpio, ACPI_GPIO_ACTIVE_HIGH)
+
+#define ACPI_GPIO_OUTPUT_ACTIVE_LOW(gpio) \
+ ACPI_GPIO_OUTPUT_CFG(gpio, ACPI_GPIO_ACTIVE_LOW)
/* Basic input GPIO with default pull settings */
-#define ACPI_GPIO_INPUT_ACTIVE_HIGH(gpio) { \
- .type = ACPI_GPIO_TYPE_IO, \
- .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_CFG(gpio, polarity) \
+ ACPI_GPIO_CFG(gpio, ACPI_GPIO_IO_RESTRICT_INPUT, polarity)
-#define ACPI_GPIO_INPUT_ACTIVE_LOW(gpio) { \
- .type = ACPI_GPIO_TYPE_IO, \
- .pull = ACPI_GPIO_PULL_DEFAULT, \
- .io_restrict = ACPI_GPIO_IO_RESTRICT_INPUT, \
- .polarity = ACPI_GPIO_ACTIVE_LOW, \
- .pin_count = 1, \
- .pins = { (gpio) } }
+#define ACPI_GPIO_INPUT_ACTIVE_HIGH(gpio) \
+ ACPI_GPIO_INPUT_CFG(gpio, ACPI_GPIO_ACTIVE_HIGH)
-/* Edge Triggered Active High GPIO interrupt */
-#define ACPI_GPIO_IRQ_EDGE_HIGH(gpio) { \
+#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, \
- .irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
- .irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
+ .irq.mode = _mode, \
+ .irq.polarity = _polarity, \
+ .irq.wake = _wake, \
.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 */
+#define ACPI_GPIO_IRQ_EDGE_HIGH(gpio) \
+ ACPI_GPIO_IRQ_EDGE(gpio, ACPI_IRQ_ACTIVE_HIGH)
/* Edge Triggered Active Low GPIO interrupt */
-#define ACPI_GPIO_IRQ_EDGE_LOW(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .pull = ACPI_GPIO_PULL_DEFAULT, \
- .irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
- .irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
- .pin_count = 1, \
- .pins = { (gpio) } }
+#define ACPI_GPIO_IRQ_EDGE_LOW(gpio) \
+ ACPI_GPIO_IRQ_EDGE(gpio, ACPI_IRQ_ACTIVE_LOW)
/* Edge Triggered Active Both GPIO interrupt */
-#define ACPI_GPIO_IRQ_EDGE_BOTH(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .pull = ACPI_GPIO_PULL_DEFAULT, \
- .irq.mode = ACPI_IRQ_EDGE_TRIGGERED, \
- .irq.polarity = ACPI_IRQ_ACTIVE_BOTH, \
- .pin_count = 1, \
- .pins = { (gpio) } }
+#define ACPI_GPIO_IRQ_EDGE_BOTH(gpio) \
+ ACPI_GPIO_IRQ_EDGE(gpio, ACPI_IRQ_ACTIVE_BOTH)
/* Edge Triggered Active High GPIO interrupt with wake */
-#define ACPI_GPIO_IRQ_EDGE_HIGH_WAKE(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .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) } }
+#define ACPI_GPIO_IRQ_EDGE_HIGH_WAKE(gpio) \
+ ACPI_GPIO_IRQ_EDGE_WAKE(gpio, ACPI_IRQ_ACTIVE_HIGH)
/* Edge Triggered Active Low GPIO interrupt with wake */
-#define ACPI_GPIO_IRQ_EDGE_LOW_WAKE(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .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) } }
+#define ACPI_GPIO_IRQ_EDGE_LOW_WAKE(gpio) \
+ ACPI_GPIO_IRQ_EDGE_WAKE(gpio, ACPI_IRQ_ACTIVE_LOW)
/* Edge Triggered Active Both GPIO interrupt with wake */
-#define ACPI_GPIO_IRQ_EDGE_BOTH_WAKE(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .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) } }
+#define ACPI_GPIO_IRQ_EDGE_BOTH_WAKE(gpio) \
+ ACPI_GPIO_IRQ_EDGE_WAKE(gpio, ACPI_IRQ_ACTIVE_BOTH)
/* Level Triggered Active High GPIO interrupt */
-#define ACPI_GPIO_IRQ_LEVEL_HIGH(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .pull = ACPI_GPIO_PULL_DEFAULT, \
- .irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
- .irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
- .pin_count = 1, \
- .pins = { (gpio) } }
+#define ACPI_GPIO_IRQ_LEVEL_HIGH(gpio) \
+ ACPI_GPIO_IRQ_LEVEL(gpio, ACPI_IRQ_ACTIVE_HIGH)
/* Level Triggered Active Low GPIO interrupt */
-#define ACPI_GPIO_IRQ_LEVEL_LOW(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .pull = ACPI_GPIO_PULL_DEFAULT, \
- .irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
- .irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
- .pin_count = 1, \
- .pins = { (gpio) } }
+#define ACPI_GPIO_IRQ_LEVEL_LOW(gpio) \
+ ACPI_GPIO_IRQ_LEVEL(gpio, ACPI_IRQ_ACTIVE_LOW)
/* Level Triggered Active High GPIO interrupt with wake */
-#define ACPI_GPIO_IRQ_LEVEL_HIGH_WAKE(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .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) } }
+#define ACPI_GPIO_IRQ_LEVEL_HIGH_WAKE(gpio) \
+ ACPI_GPIO_IRQ_LEVEL_WAKE(gpio, ACPI_IRQ_ACTIVE_HIGH)
/* Level Triggered Active Low GPIO interrupt with wake */
-#define ACPI_GPIO_IRQ_LEVEL_LOW_WAKE(gpio) { \
- .type = ACPI_GPIO_TYPE_INTERRUPT, \
- .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) } }
+#define ACPI_GPIO_IRQ_LEVEL_LOW_WAKE(gpio) \
+ ACPI_GPIO_IRQ_LEVEL_WAKE(gpio, ACPI_IRQ_ACTIVE_LOW)
/* Write GpioIo() or GpioInt() descriptor to SSDT AML output */
void acpi_device_write_gpio(const struct acpi_gpio *gpio);