diff --git a/drivers/pinctrl/pinctrl_gecko.c b/drivers/pinctrl/pinctrl_gecko.c index 530044f753d..d801ced94bb 100644 --- a/drivers/pinctrl/pinctrl_gecko.c +++ b/drivers/pinctrl/pinctrl_gecko.c @@ -10,12 +10,17 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg) { -#ifdef CONFIG_UART_GECKO - struct soc_gpio_pin rxpin = {0}; - struct soc_gpio_pin txpin = {0}; USART_TypeDef *base = (USART_TypeDef *)reg; - uint8_t loc; int usart_num = USART_NUM(base); + uint8_t loc; + +#ifdef CONFIG_SPI_GECKO + struct soc_gpio_pin spi_pin_cfg = {0, 0, 0, 0}; +#endif /* CONFIG_SPI_GECKO */ + +#ifdef CONFIG_UART_GECKO + struct soc_gpio_pin rxpin = {0, 0, 0, 0}; + struct soc_gpio_pin txpin = {0, 0, 0, 0}; #endif /* CONFIG_UART_GECKO */ for (uint8_t i = 0U; i < pin_cnt; i++) { @@ -27,7 +32,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp rxpin.mode = gpioModeInput; rxpin.out = 1; GPIO_PinModeSet(rxpin.port, rxpin.pin, rxpin.mode, - rxpin.out); + rxpin.out); break; case GECKO_FUN_UART_TX: txpin.port = GECKO_GET_PORT(pins[i]); @@ -35,12 +40,12 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp txpin.mode = gpioModePushPull; txpin.out = 1; GPIO_PinModeSet(txpin.port, txpin.pin, txpin.mode, - txpin.out); + txpin.out); break; case GECKO_FUN_UART_LOC: loc = GECKO_GET_LOC(pins[i]); #ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION - /* For SOCs with configurable pin locations (set in SOC Kconfig) */ + /* For SOCs with configurable pin_cfg locations (set in SOC Kconfig) */ base->ROUTEPEN = USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN; base->ROUTELOC0 = (loc << _USART_ROUTELOC0_TXLOC_SHIFT) | (loc << _USART_ROUTELOC0_RXLOC_SHIFT); @@ -94,9 +99,46 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp #endif /* UART_GECKO_HW_FLOW_CONTROL */ break; #endif /* CONFIG_UART_GECKO */ +#ifdef CONFIG_SPI_GECKO + case GECKO_FUN_SPI_SCK: + spi_pin_cfg.port = GECKO_GET_PORT(pins[i]); + spi_pin_cfg.pin = GECKO_GET_PIN(pins[i]); + spi_pin_cfg.mode = gpioModePushPull; + spi_pin_cfg.out = 1; + GPIO->USARTROUTE[usart_num].ROUTEEN |= GPIO_USART_ROUTEEN_CLKPEN; + GPIO->USARTROUTE[usart_num].CLKROUTE = + (spi_pin_cfg.pin << _GPIO_USART_CLKROUTE_PIN_SHIFT) | + (spi_pin_cfg.port << _GPIO_USART_CLKROUTE_PORT_SHIFT); + break; + case GECKO_FUN_SPI_MOSI: + spi_pin_cfg.port = GECKO_GET_PORT(pins[i]); + spi_pin_cfg.pin = GECKO_GET_PIN(pins[i]); + spi_pin_cfg.mode = gpioModePushPull; + spi_pin_cfg.out = 1; + GPIO->USARTROUTE[usart_num].ROUTEEN |= GPIO_USART_ROUTEEN_TXPEN; + GPIO->USARTROUTE[usart_num].TXROUTE = + (spi_pin_cfg.pin << _GPIO_USART_TXROUTE_PIN_SHIFT) | + (spi_pin_cfg.port << _GPIO_USART_TXROUTE_PORT_SHIFT); + break; + case GECKO_FUN_SPI_MISO: + spi_pin_cfg.port = GECKO_GET_PORT(pins[i]); + spi_pin_cfg.pin = GECKO_GET_PIN(pins[i]); + spi_pin_cfg.mode = gpioModeInput; + spi_pin_cfg.out = 1; + GPIO->USARTROUTE[usart_num].ROUTEEN |= GPIO_USART_ROUTEEN_RXPEN; + GPIO->USARTROUTE[usart_num].RXROUTE = + (spi_pin_cfg.pin << _GPIO_USART_RXROUTE_PIN_SHIFT) | + (spi_pin_cfg.port << _GPIO_USART_RXROUTE_PORT_SHIFT); + break; +#endif /* CONFIG_SPI_GECKO */ + default: return -ENOTSUP; } +#ifdef CONFIG_SPI_GECKO + GPIO_PinModeSet(spi_pin_cfg.port, spi_pin_cfg.pin, + spi_pin_cfg.mode, spi_pin_cfg.out); +#endif /* CONFIG_SPI_GECKO */ } return 0; diff --git a/dts/bindings/spi/silabs,gecko-spi-usart.yaml b/dts/bindings/spi/silabs,gecko-spi-usart.yaml index 6e6c624424a..d46459902e5 100644 --- a/dts/bindings/spi/silabs,gecko-spi-usart.yaml +++ b/dts/bindings/spi/silabs,gecko-spi-usart.yaml @@ -2,7 +2,7 @@ description: GECKO USART SPI compatible: "silabs,gecko-spi-usart" -include: spi-controller.yaml +include: [spi-controller.yaml, pinctrl-device.yaml] properties: reg: @@ -21,15 +21,12 @@ properties: location-rx: type: array - required: true description: RX pin configuration defined as location-tx: type: array - required: true description: TX pin configuration defined as location-clk: type: array - required: true description: CLK pin configuration defined as diff --git a/include/zephyr/dt-bindings/pinctrl/gecko-pinctrl.h b/include/zephyr/dt-bindings/pinctrl/gecko-pinctrl.h index 9eae1c945f9..5498ca036fb 100644 --- a/include/zephyr/dt-bindings/pinctrl/gecko-pinctrl.h +++ b/include/zephyr/dt-bindings/pinctrl/gecko-pinctrl.h @@ -61,6 +61,11 @@ /** UART LOCATION */ #define GECKO_FUN_UART_LOC 4U +#define GECKO_FUN_SPI_MISO 5U +#define GECKO_FUN_SPI_MOSI 6U +#define GECKO_FUN_SPI_CSN 7U +#define GECKO_FUN_SPI_SCK 8U + /** @} */ /**