From 8ae8dca6d4dd709c5c4909902c650f9780d113fb Mon Sep 17 00:00:00 2001 From: Anton Staaf Date: Mon, 22 Feb 2016 10:57:32 -0800 Subject: cr50: Switch from ALTERNATE to PINMUX macros Previously the g chip and cr50 board abused the ALTERNATE macro to encode the pinmux configuration. This switches them over to using a PINMUX macro that is designed for this purpose. Signed-off-by: Anton Staaf BRANCH=None BUG=None TEST=make buildall -j Change-Id: I5c1f70b7aa92d87cc105e672aa66aee7f267c9a2 Reviewed-on: https://chromium-review.googlesource.com/328823 Commit-Ready: Anton Staaf Tested-by: Anton Staaf Reviewed-by: Bill Richardson --- board/cr50/gpio.inc | 45 +++++++++++++++++++++++---------------------- chip/g/gpio.c | 23 +++++++++++++++++++---- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/board/cr50/gpio.inc b/board/cr50/gpio.inc index 740370de91..57c52446e5 100644 --- a/board/cr50/gpio.inc +++ b/board/cr50/gpio.inc @@ -30,34 +30,35 @@ GPIO(LED_7, PIN(0, 9), GPIO_OUT_LOW) /* Unimplemented signals which we need to emulate for now */ UNIMPLEMENTED(ENTERING_RW) -/* The Cr50 ARM core has no alternate functions, so we repurpose that - * macro to describe the PINMUX setup. The args are - * - * 1. The ARM core GPIO or SoC peripheral function to connect - * 2. The pinmux DIO pad to connect to - * 3. - * 4. MODULE_GPIO, to prevent being called by gpio_config_module() - * 5. flags to specify the direction if the GPIO isn't enough +/* + * If we are included by generic GPIO code that doesn't know about the PINMUX + * macro we need to provide an empty definition so that the invocations don't + * interfere with other GPIO processing. */ +#ifndef PINMUX +#define PINMUX(...) +#endif /* The serial port is one of the SoC peripheral functions */ -ALTERNATE(PIN_MASK(FUNC(UART0_TX), DIO(A0)), 0, MODULE_GPIO, DIO_OUTPUT) -ALTERNATE(PIN_MASK(FUNC(UART0_RX), DIO(A1)), 0, MODULE_GPIO, DIO_INPUT) +PINMUX(FUNC(UART0_TX), A0, DIO_OUTPUT) +PINMUX(FUNC(UART0_RX), A1, DIO_INPUT) /* Inputs */ -ALTERNATE(PIN_MASK(SW_N, DIO(M0)), 0, MODULE_GPIO, 0) -ALTERNATE(PIN_MASK(SW_S, DIO(M1)), 0, MODULE_GPIO, 0) -ALTERNATE(PIN_MASK(SW_W, DIO(M2)), 0, MODULE_GPIO, 0) -ALTERNATE(PIN_MASK(SW_E, DIO(M3)), 0, MODULE_GPIO, 0) +PINMUX(GPIO(SW_N), M0, 0) +PINMUX(GPIO(SW_S), M1, 0) +PINMUX(GPIO(SW_W), M2, 0) +PINMUX(GPIO(SW_E), M3, 0) /* Aliased Inputs, connected to the same pins */ -ALTERNATE(PIN_MASK(SW_N_, DIO(M0)), 0, MODULE_GPIO, 0) -ALTERNATE(PIN_MASK(SW_S_, DIO(M1)), 0, MODULE_GPIO, 0) -ALTERNATE(PIN_MASK(SW_W_, DIO(M2)), 0, MODULE_GPIO, 0) -ALTERNATE(PIN_MASK(SW_E_, DIO(M3)), 0, MODULE_GPIO, 0) +PINMUX(GPIO(SW_N_), M0, 0) +PINMUX(GPIO(SW_S_), M1, 0) +PINMUX(GPIO(SW_W_), M2, 0) +PINMUX(GPIO(SW_E_), M3, 0) /* Outputs - also mark as inputs so we can read back from the driven pin */ -ALTERNATE(PIN_MASK(LED_2, DIO(A9)), 0, MODULE_GPIO, DIO_INPUT) -ALTERNATE(PIN_MASK(LED_4, DIO(A11)), 0, MODULE_GPIO, DIO_INPUT) -ALTERNATE(PIN_MASK(LED_6, DIO(A13)), 0, MODULE_GPIO, DIO_INPUT) -ALTERNATE(PIN_MASK(LED_7, DIO(A14)), 0, MODULE_GPIO, DIO_INPUT) +PINMUX(GPIO(LED_2), A9, DIO_INPUT) +PINMUX(GPIO(LED_4), A11, DIO_INPUT) +PINMUX(GPIO(LED_6), A13, DIO_INPUT) +PINMUX(GPIO(LED_7), A14, DIO_INPUT) + +#undef PINMUX diff --git a/chip/g/gpio.c b/chip/g/gpio.c index 7695e859db..ad5f199215 100644 --- a/chip/g/gpio.c +++ b/chip/g/gpio.c @@ -84,9 +84,25 @@ void gpio_set_alternate_function(uint32_t port, uint32_t mask, int func) /* This HW feature is not present in the Cr50 ARM core */ } +struct pinmux { + uint32_t signal; + uint32_t dio; + uint16_t flags; +}; -static void connect_pinmux(uint32_t signal, uint32_t dio, uint16_t flags) +#define GPIO_GPIO(name) GPIO_##name +#define PINMUX(signal, dio, flags) {GPIO_##signal, DIO(dio), flags}, + +static const struct pinmux pinmux_list[] = { + #include "gpio.wrap" +}; + +static void connect_pinmux(struct pinmux const *p) { + uint32_t signal = p->signal; + uint32_t dio = p->dio; + uint16_t flags = p->flags; + if (flags & DIO_ENABLE_DIRECT_INPUT) { /* enable digital input for direct wired peripheral */ REG_WRITE_MLV(DIO_CTL_REG(dio), DIO_CTL_IE_MASK, @@ -142,7 +158,6 @@ int gpio_disable_interrupt(enum gpio_signal signal) void gpio_pre_init(void) { const struct gpio_info *g = gpio_list; - const struct gpio_alt_func *af = gpio_alt_funcs; int i; @@ -155,8 +170,8 @@ void gpio_pre_init(void) GC_PMU_PERICLKSET0_DGPIO1_CLK_LSB, 1); /* Set up the pinmux */ - for (i = 0; i < gpio_alt_funcs_count; i++, af++) - connect_pinmux(af->port, af->mask, af->flags); + for (i = 0; i < ARRAY_SIZE(pinmux_list); i++) + connect_pinmux(pinmux_list + i); /* Set up ARM core GPIOs */ for (i = 0; i < GPIO_COUNT; i++, g++) -- cgit v1.2.1