Skip to content

Commit eb4a0ae

Browse files
lpawelczMaureenHelm
authored andcommitted
drivers: pinctrl: silabs: add spi handling
This commit adds pinctrl configuration for SPI on USART. Signed-off-by: Pawel Czarnecki <[email protected]>
1 parent fef2bb0 commit eb4a0ae

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

drivers/pinctrl/pinctrl_gecko.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010

1111
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
1212
{
13-
#ifdef CONFIG_UART_GECKO
14-
struct soc_gpio_pin rxpin = {0};
15-
struct soc_gpio_pin txpin = {0};
1613
USART_TypeDef *base = (USART_TypeDef *)reg;
17-
uint8_t loc;
1814
int usart_num = USART_NUM(base);
15+
uint8_t loc;
16+
17+
#ifdef CONFIG_SPI_GECKO
18+
struct soc_gpio_pin spi_pin_cfg = {0, 0, 0, 0};
19+
#endif /* CONFIG_SPI_GECKO */
20+
21+
#ifdef CONFIG_UART_GECKO
22+
struct soc_gpio_pin rxpin = {0, 0, 0, 0};
23+
struct soc_gpio_pin txpin = {0, 0, 0, 0};
1924
#endif /* CONFIG_UART_GECKO */
2025

2126
for (uint8_t i = 0U; i < pin_cnt; i++) {
@@ -27,20 +32,20 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
2732
rxpin.mode = gpioModeInput;
2833
rxpin.out = 1;
2934
GPIO_PinModeSet(rxpin.port, rxpin.pin, rxpin.mode,
30-
rxpin.out);
35+
rxpin.out);
3136
break;
3237
case GECKO_FUN_UART_TX:
3338
txpin.port = GECKO_GET_PORT(pins[i]);
3439
txpin.pin = GECKO_GET_PIN(pins[i]);
3540
txpin.mode = gpioModePushPull;
3641
txpin.out = 1;
3742
GPIO_PinModeSet(txpin.port, txpin.pin, txpin.mode,
38-
txpin.out);
43+
txpin.out);
3944
break;
4045
case GECKO_FUN_UART_LOC:
4146
loc = GECKO_GET_LOC(pins[i]);
4247
#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
43-
/* For SOCs with configurable pin locations (set in SOC Kconfig) */
48+
/* For SOCs with configurable pin_cfg locations (set in SOC Kconfig) */
4449
base->ROUTEPEN = USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN;
4550
base->ROUTELOC0 = (loc << _USART_ROUTELOC0_TXLOC_SHIFT) |
4651
(loc << _USART_ROUTELOC0_RXLOC_SHIFT);
@@ -94,9 +99,46 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
9499
#endif /* UART_GECKO_HW_FLOW_CONTROL */
95100
break;
96101
#endif /* CONFIG_UART_GECKO */
102+
#ifdef CONFIG_SPI_GECKO
103+
case GECKO_FUN_SPI_SCK:
104+
spi_pin_cfg.port = GECKO_GET_PORT(pins[i]);
105+
spi_pin_cfg.pin = GECKO_GET_PIN(pins[i]);
106+
spi_pin_cfg.mode = gpioModePushPull;
107+
spi_pin_cfg.out = 1;
108+
GPIO->USARTROUTE[usart_num].ROUTEEN |= GPIO_USART_ROUTEEN_CLKPEN;
109+
GPIO->USARTROUTE[usart_num].CLKROUTE =
110+
(spi_pin_cfg.pin << _GPIO_USART_CLKROUTE_PIN_SHIFT) |
111+
(spi_pin_cfg.port << _GPIO_USART_CLKROUTE_PORT_SHIFT);
112+
break;
113+
case GECKO_FUN_SPI_MOSI:
114+
spi_pin_cfg.port = GECKO_GET_PORT(pins[i]);
115+
spi_pin_cfg.pin = GECKO_GET_PIN(pins[i]);
116+
spi_pin_cfg.mode = gpioModePushPull;
117+
spi_pin_cfg.out = 1;
118+
GPIO->USARTROUTE[usart_num].ROUTEEN |= GPIO_USART_ROUTEEN_TXPEN;
119+
GPIO->USARTROUTE[usart_num].TXROUTE =
120+
(spi_pin_cfg.pin << _GPIO_USART_TXROUTE_PIN_SHIFT) |
121+
(spi_pin_cfg.port << _GPIO_USART_TXROUTE_PORT_SHIFT);
122+
break;
123+
case GECKO_FUN_SPI_MISO:
124+
spi_pin_cfg.port = GECKO_GET_PORT(pins[i]);
125+
spi_pin_cfg.pin = GECKO_GET_PIN(pins[i]);
126+
spi_pin_cfg.mode = gpioModeInput;
127+
spi_pin_cfg.out = 1;
128+
GPIO->USARTROUTE[usart_num].ROUTEEN |= GPIO_USART_ROUTEEN_RXPEN;
129+
GPIO->USARTROUTE[usart_num].RXROUTE =
130+
(spi_pin_cfg.pin << _GPIO_USART_RXROUTE_PIN_SHIFT) |
131+
(spi_pin_cfg.port << _GPIO_USART_RXROUTE_PORT_SHIFT);
132+
break;
133+
#endif /* CONFIG_SPI_GECKO */
134+
97135
default:
98136
return -ENOTSUP;
99137
}
138+
#ifdef CONFIG_SPI_GECKO
139+
GPIO_PinModeSet(spi_pin_cfg.port, spi_pin_cfg.pin,
140+
spi_pin_cfg.mode, spi_pin_cfg.out);
141+
#endif /* CONFIG_SPI_GECKO */
100142
}
101143

102144
return 0;

dts/bindings/spi/silabs,gecko-spi-usart.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ description: GECKO USART SPI
22

33
compatible: "silabs,gecko-spi-usart"
44

5-
include: spi-controller.yaml
5+
include: [spi-controller.yaml, pinctrl-device.yaml]
66

77
properties:
88
reg:
@@ -21,15 +21,12 @@ properties:
2121

2222
location-rx:
2323
type: array
24-
required: true
2524
description: RX pin configuration defined as <location port pin>
2625

2726
location-tx:
2827
type: array
29-
required: true
3028
description: TX pin configuration defined as <location port pin>
3129

3230
location-clk:
3331
type: array
34-
required: true
3532
description: CLK pin configuration defined as <location port pin>

include/zephyr/dt-bindings/pinctrl/gecko-pinctrl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
/** UART LOCATION */
6262
#define GECKO_FUN_UART_LOC 4U
6363

64+
#define GECKO_FUN_SPI_MISO 5U
65+
#define GECKO_FUN_SPI_MOSI 6U
66+
#define GECKO_FUN_SPI_CSN 7U
67+
#define GECKO_FUN_SPI_SCK 8U
68+
6469
/** @} */
6570

6671
/**

0 commit comments

Comments
 (0)