|
| 1 | +/* |
| 2 | + * Copyright 2018 Foundries.io Ltd |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <init.h> |
| 8 | +#include <drivers/pinmux.h> |
| 9 | +#include <drivers/gpio.h> |
| 10 | +#include <fsl_port.h> |
| 11 | + |
| 12 | +#ifdef CONFIG_BT_CTLR_DEBUG_PINS |
| 13 | +struct device *vega_debug_portb; |
| 14 | +struct device *vega_debug_portc; |
| 15 | +struct device *vega_debug_portd; |
| 16 | +#endif |
| 17 | + |
| 18 | +static int rv32m1_vega_pinmux_init(struct device *dev) |
| 19 | +{ |
| 20 | + ARG_UNUSED(dev); |
| 21 | + |
| 22 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(porta), okay) |
| 23 | + __unused struct device *porta = |
| 24 | + device_get_binding(DT_LABEL(DT_NODELABEL(porta))); |
| 25 | +#endif |
| 26 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(portb), okay) |
| 27 | + __unused struct device *portb = |
| 28 | + device_get_binding(DT_LABEL(DT_NODELABEL(portb))); |
| 29 | +#endif |
| 30 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(portc), okay) |
| 31 | + __unused struct device *portc = |
| 32 | + device_get_binding(DT_LABEL(DT_NODELABEL(portc))); |
| 33 | +#endif |
| 34 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(portd), okay) |
| 35 | + __unused struct device *portd = |
| 36 | + device_get_binding(DT_LABEL(DT_NODELABEL(portd))); |
| 37 | +#endif |
| 38 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(porte), okay) |
| 39 | + __unused struct device *porte = |
| 40 | + device_get_binding(DT_LABEL(DT_NODELABEL(porte))); |
| 41 | +#endif |
| 42 | + |
| 43 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) && CONFIG_SERIAL |
| 44 | + /* LPUART0 RX, TX */ |
| 45 | + pinmux_pin_set(portc, 7, PORT_PCR_MUX(kPORT_MuxAlt3)); |
| 46 | + pinmux_pin_set(portc, 8, PORT_PCR_MUX(kPORT_MuxAlt3)); |
| 47 | +#endif |
| 48 | + |
| 49 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart1), okay) && CONFIG_SERIAL |
| 50 | + /* LPUART1 RX, TX */ |
| 51 | + pinmux_pin_set(portc, 29, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 52 | + pinmux_pin_set(portc, 30, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 53 | +#endif |
| 54 | + |
| 55 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c0), okay) && CONFIG_I2C |
| 56 | + /* LPI2C0 SCL, SDA - Arduino header */ |
| 57 | + pinmux_pin_set(portc, 10, PORT_PCR_MUX(kPORT_MuxAlt4)); |
| 58 | + pinmux_pin_set(portc, 9, PORT_PCR_MUX(kPORT_MuxAlt4)); |
| 59 | +#endif |
| 60 | + |
| 61 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c3), okay) && CONFIG_I2C |
| 62 | + /* LPI2C3 SCL, SDA - FXOS8700 */ |
| 63 | + pinmux_pin_set(porte, 30, PORT_PCR_MUX(kPORT_MuxAlt3)); |
| 64 | + pinmux_pin_set(porte, 29, PORT_PCR_MUX(kPORT_MuxAlt3)); |
| 65 | +#endif |
| 66 | + |
| 67 | + /* FXOS8700 INT1, INT2, RST */ |
| 68 | + pinmux_pin_set(porte, 1, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 69 | + pinmux_pin_set(porte, 22, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 70 | + pinmux_pin_set(porte, 27, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 71 | + |
| 72 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi0), okay) && CONFIG_SPI |
| 73 | + /* LPSPI0 SCK, SOUT, PCS2, SIN */ |
| 74 | + pinmux_pin_set(portb, 4, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 75 | + pinmux_pin_set(portb, 5, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 76 | + pinmux_pin_set(portb, 6, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 77 | + pinmux_pin_set(portb, 7, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 78 | +#endif |
| 79 | + |
| 80 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi1), okay) && CONFIG_SPI |
| 81 | + /* LPSPI1 SCK, SIN, SOUT, CS */ |
| 82 | + pinmux_pin_set(portb, 20, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 83 | + pinmux_pin_set(portb, 21, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 84 | + pinmux_pin_set(portb, 24, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 85 | + pinmux_pin_set(portb, 22, PORT_PCR_MUX(kPORT_MuxAlt2)); |
| 86 | +#endif |
| 87 | + |
| 88 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(tpm2), okay) && CONFIG_PWM |
| 89 | + /* RGB LEDs as PWM */ |
| 90 | + pinmux_pin_set(porta, 22, PORT_PCR_MUX(kPORT_MuxAlt6)); |
| 91 | + pinmux_pin_set(porta, 23, PORT_PCR_MUX(kPORT_MuxAlt6)); |
| 92 | + pinmux_pin_set(porta, 24, PORT_PCR_MUX(kPORT_MuxAlt6)); |
| 93 | +#else |
| 94 | + /* RGB LEDs as GPIO */ |
| 95 | + pinmux_pin_set(porta, 22, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 96 | + pinmux_pin_set(porta, 23, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 97 | + pinmux_pin_set(porta, 24, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 98 | +#endif |
| 99 | + |
| 100 | +#ifdef CONFIG_BT_CTLR_DEBUG_PINS |
| 101 | + |
| 102 | + pinmux_pin_set(portb, 29, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 103 | + |
| 104 | + pinmux_pin_set(portc, 28, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 105 | + pinmux_pin_set(portc, 29, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 106 | + pinmux_pin_set(portc, 30, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 107 | + |
| 108 | + pinmux_pin_set(portd, 0, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 109 | + pinmux_pin_set(portd, 1, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 110 | + pinmux_pin_set(portd, 2, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 111 | + pinmux_pin_set(portd, 3, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 112 | + pinmux_pin_set(portd, 4, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 113 | + pinmux_pin_set(portd, 5, PORT_PCR_MUX(kPORT_MuxAsGpio)); |
| 114 | + |
| 115 | + struct device *gpio_dev = |
| 116 | + device_get_binding(DT_LABEL(DT_NODELABEL(gpiob))); |
| 117 | + |
| 118 | + gpio_pin_configure(gpio_dev, 29, GPIO_OUTPUT); |
| 119 | + |
| 120 | + gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpioc))); |
| 121 | + gpio_pin_configure(gpio_dev, 28, GPIO_OUTPUT); |
| 122 | + gpio_pin_configure(gpio_dev, 29, GPIO_OUTPUT); |
| 123 | + gpio_pin_configure(gpio_dev, 30, GPIO_OUTPUT); |
| 124 | + |
| 125 | + gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpiod))); |
| 126 | + gpio_pin_configure(gpio_dev, 0, GPIO_OUTPUT); |
| 127 | + gpio_pin_configure(gpio_dev, 1, GPIO_OUTPUT); |
| 128 | + gpio_pin_configure(gpio_dev, 2, GPIO_OUTPUT); |
| 129 | + gpio_pin_configure(gpio_dev, 3, GPIO_OUTPUT); |
| 130 | + gpio_pin_configure(gpio_dev, 4, GPIO_OUTPUT); |
| 131 | + gpio_pin_configure(gpio_dev, 5, GPIO_OUTPUT); |
| 132 | +#endif |
| 133 | + |
| 134 | + return 0; |
| 135 | +} |
| 136 | + |
| 137 | +SYS_INIT(rv32m1_vega_pinmux_init, PRE_KERNEL_1, CONFIG_PINMUX_INIT_PRIORITY); |
0 commit comments