summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2014-07-14 15:33:29 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-07-17 00:39:52 +0000
commit7746b32e17571b0e0cbdcbd101787b742d35c825 (patch)
tree5b4374d93630dda800996687239aac5cec681dc7 /include
parent1e73a1ba06b7879de3b03c7cefec9135bf73fcf5 (diff)
downloadchrome-ec-7746b32e17571b0e0cbdcbd101787b742d35c825.tar.gz
GPIO: Move definition of alternate functions to gpio.inc
This is a straightforward conversion of existing tables into X-Macro style definitions for the GPIO alternate functions. This change in itself, is not particularly powerful, but having all GPIO settings in a single file makes a board easier to understand. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=none TEST=make buildall -j Followed by manual testing of interrupt on change and UART functionality on STM32F0 based discovery board. Change-Id: Ib7f1f014f4bd289d7c0ac3100470ba2dc71ca579 Reviewed-on: https://chromium-review.googlesource.com/207987 Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/gpio.wrap20
-rw-r--r--include/gpio_list.h13
2 files changed, 32 insertions, 1 deletions
diff --git a/include/gpio.wrap b/include/gpio.wrap
index 941d97ac67..cf4fbb319a 100644
--- a/include/gpio.wrap
+++ b/include/gpio.wrap
@@ -16,7 +16,24 @@
* parameters are passed on to the gpio_info directly.
*/
#ifndef GPIO
-#define GPIO(name, port, pin, function, signal)
+#define GPIO(name, port, pin, flags, signal)
+#endif
+
+/*
+ * The ALTERNATE macro is used associate a GPIO with an alternate function.
+ *
+ * Alternate functions allow hardware peripherals access to GPIO pins.
+ * Modules use gpio_config_module to enable and disable the alternate functions
+ * of GPIOs assigned to that module. So if the module parameter is MODULE_UART
+ * then when the uart_init function is called the GPIO will be switched to its
+ * alternate function mode. The function parameter is chip/variant specific
+ * and will usually need to be looked up in the datasheet. The flags parameter
+ * has the same meaning as in the GPIO macro above. This macro can assign
+ * multiple pins on the same port to a module, the second parameter is the
+ * bitmask of pins to be assigned.
+ */
+#ifndef ALTERNATE
+#define ALTERNATE(port, mask, function, module, flags)
#endif
/*
@@ -44,4 +61,5 @@
* Once the gpio.inc file has been included these macros are no longer needed.
*/
#undef GPIO
+#undef ALTERNATE
#undef UNIMPLEMENTED
diff --git a/include/gpio_list.h b/include/gpio_list.h
index 6d41fb9115..9077c17fd2 100644
--- a/include/gpio_list.h
+++ b/include/gpio_list.h
@@ -15,3 +15,16 @@ const struct gpio_info gpio_list[] = {
};
BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
+
+/*
+ * Construct the gpio_alt_funcs array. This array is used by gpio_config_module
+ * to enable and disable GPIO alternate functions on a module by module basis.
+ */
+#define ALTERNATE(port, mask, function, module, flags) \
+ {GPIO_##port, mask, function, module, flags},
+
+const struct gpio_alt_func gpio_alt_funcs[] = {
+ #include "gpio.wrap"
+};
+
+const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs);