Skip to content

Commit

Permalink
drivers: spi: gecko: add new driver for SPI communication via EUSART
Browse files Browse the repository at this point in the history
Added a new driver to support SPI communication via EUSART. Since the
Silabs EFR32MG24 family SoCs have only one USART, EUSART support is
necessary for implementing SPI functionality.

Signed-off-by: Teresa Zepeda Ventura <[email protected]>
  • Loading branch information
Terezvent committed Oct 10, 2024
1 parent bc7579e commit 97c58e7
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 5 deletions.
55 changes: 53 additions & 2 deletions drivers/pinctrl/pinctrl_gecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
(void)base;
#endif /*USART_COUNT > 1*/

#ifdef CONFIG_SPI_GECKO_EUSART
EUSART_TypeDef *ebase = (EUSART_TypeDef *)reg;
int eusart_num = EUSART_NUM(ebase);
#endif

#endif

#ifdef CONFIG_I2C_GECKO
Expand Down Expand Up @@ -171,7 +176,53 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
#endif /* CONFIG_SOC_FAMILY_SILABS_S1 */
#endif /* CONFIG_UART_GECKO */

#ifdef CONFIG_SPI_GECKO
#ifdef CONFIG_SPI_GECKO_EUSART
case GECKO_FUN_SPI_SCK:
pin_config.mode = gpioModePushPull;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].SCLKROUTE =
(pin_config.port << _GPIO_EUSART_SCLKROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_SCLKROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[eusart_num].ROUTEEN |= GPIO_EUSART_ROUTEEN_SCLKPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;

case GECKO_FUN_SPI_CSN:
pin_config.mode = gpioModePushPull;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].CSROUTE =
(pin_config.port << _GPIO_EUSART_CSROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_CSROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[eusart_num].ROUTEEN |= GPIO_EUSART_ROUTEEN_CSPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;

case GECKO_FUN_SPI_MOSI:
pin_config.mode = gpioModePushPull;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].TXROUTE =
(pin_config.port << _GPIO_EUSART_TXROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_TXROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[eusart_num].ROUTEEN |= GPIO_EUSART_ROUTEEN_TXPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;

case GECKO_FUN_SPI_MISO:
pin_config.mode = gpioModeInput;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].RXROUTE =
(pin_config.port << _GPIO_EUSART_RXROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_RXROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[EUSART_NUM(EUSART1)].ROUTEEN |= GPIO_EUSART_ROUTEEN_RXPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;
#endif /*CONFIG_SPI_GECKO_EUSART*/

#ifdef CONFIG_SPI_GECKO_USART
#ifdef CONFIG_SOC_FAMILY_SILABS_S1
case GECKO_FUN_SPIM_SCK:
pin_config.mode = gpioModePushPull;
Expand Down Expand Up @@ -287,7 +338,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
pin_config.out);
break;
#endif /* CONFIG_SOC_FAMILY_SILABS_S1 */
#endif /* CONFIG_SPI_GECKO */
#endif /* CONFIG_SPI_GECKO_USART */

#ifdef CONFIG_I2C_GECKO
case GECKO_FUN_I2C_SDA:
Expand Down
3 changes: 2 additions & 1 deletion drivers/spi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ zephyr_library_sources_ifdef(CONFIG_SPI_LITEX spi_litex.c)
zephyr_library_sources_ifdef(CONFIG_SPI_LITEX_LITESPI spi_litex_litespi.c)
zephyr_library_sources_ifdef(CONFIG_SPI_OC_SIMPLE spi_oc_simple.c)
zephyr_library_sources_ifdef(CONFIG_SPI_XEC_QMSPI spi_xec_qmspi.c)
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO spi_gecko.c)
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO_USART spi_gecko_usart.c)
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO_EUSART spi_gecko_eusart.c)
zephyr_library_sources_ifdef(CONFIG_SPI_XLNX_AXI_QUADSPI spi_xlnx_axi_quadspi.c)
zephyr_library_sources_ifdef(CONFIG_ESP32_SPIM spi_esp32_spim.c)
zephyr_library_sources_ifdef(CONFIG_SPI_TEST spi_test.c)
Expand Down
4 changes: 3 additions & 1 deletion drivers/spi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ source "drivers/spi/Kconfig.oc_simple"

source "drivers/spi/Kconfig.xec_qmspi"

source "drivers/spi/Kconfig.gecko"
source "drivers/spi/Kconfig.gecko_usart"

source "drivers/spi/Kconfig.gecko_eusart"

source "drivers/spi/Kconfig.xlnx"

Expand Down
13 changes: 13 additions & 0 deletions drivers/spi/Kconfig.gecko_eusart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gecko SPI configuration option

# Copyright (c) 2024 Daikin Comfort Technologies North America, Inc.
# SPDX-License-Identifier: Apache-2.0

config SPI_GECKO_EUSART
bool "Gecko EUSART SPI controller driver"
default y
depends on DT_HAS_SILABS_GECKO_SPI_EUSART_ENABLED
depends on GPIO
select SOC_GECKO_EUSART
help
Enable the EUSART SPI peripherals on Gecko
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (c) 2019 Christian Taedcke <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config SPI_GECKO
config SPI_GECKO_USART
bool "Gecko SPI controller driver"
default y
depends on DT_HAS_SILABS_GECKO_SPI_USART_ENABLED
Expand Down
Loading

0 comments on commit 97c58e7

Please sign in to comment.