@@ -21,9 +21,14 @@ LOG_MODULE_REGISTER(spi_gecko);
21
21
22
22
#include <stdbool.h>
23
23
24
+ #ifdef CONFIG_PINCTRL
25
+ #include <zephyr/drivers/pinctrl.h>
26
+ #else
24
27
#ifndef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
25
28
#error "Individual pin location support is required"
26
29
#endif
30
+ #endif /* CONFIG_PINCTRL */
31
+
27
32
28
33
#define CLOCK_USART (id ) _CONCAT(cmuClock_USART, id)
29
34
@@ -38,12 +43,16 @@ struct spi_gecko_data {
38
43
struct spi_gecko_config {
39
44
USART_TypeDef * base ;
40
45
CMU_Clock_TypeDef clock ;
46
+ #ifdef CONFIG_PINCTRL
47
+ const struct pinctrl_dev_config * pcfg ;
48
+ #else
41
49
struct soc_gpio_pin pin_rx ;
42
50
struct soc_gpio_pin pin_tx ;
43
51
struct soc_gpio_pin pin_clk ;
44
52
uint8_t loc_rx ;
45
53
uint8_t loc_tx ;
46
54
uint8_t loc_clk ;
55
+ #endif /* CONFIG_PINCTRL */
47
56
};
48
57
49
58
@@ -184,6 +193,7 @@ static void spi_gecko_xfer(const struct device *dev,
184
193
spi_context_complete (ctx , dev , 0 );
185
194
}
186
195
196
+ #ifndef CONFIG_PINCTRL
187
197
static void spi_gecko_init_pins (const struct device * dev )
188
198
{
189
199
const struct spi_gecko_config * config = dev -> config ;
@@ -208,6 +218,7 @@ static void spi_gecko_init_pins(const struct device *dev)
208
218
config -> base -> ROUTEPEN = USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN |
209
219
USART_ROUTEPEN_CLKPEN ;
210
220
}
221
+ #endif /* !CONFIG_PINCTRL */
211
222
212
223
213
224
/* API Functions */
@@ -241,8 +252,15 @@ static int spi_gecko_init(const struct device *dev)
241
252
/* Init USART */
242
253
USART_InitSync (config -> base , & usartInit );
243
254
255
+ #ifdef CONFIG_PINCTRL
256
+ err = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_DEFAULT );
257
+ if (err < 0 ) {
258
+ return err ;
259
+ }
260
+ #else
244
261
/* Initialize USART pins */
245
262
spi_gecko_init_pins (dev );
263
+ #endif /* CONFIG_PINCTRL */
246
264
247
265
err = spi_context_cs_configure_all (& data -> ctx );
248
266
if (err < 0 ) {
@@ -300,6 +318,29 @@ static struct spi_driver_api spi_gecko_api = {
300
318
.release = spi_gecko_release ,
301
319
};
302
320
321
+ #ifdef CONFIG_PINCTRL
322
+ #define SPI_INIT2 (n , usart ) \
323
+ PINCTRL_DT_INST_DEFINE(n); \
324
+ static struct spi_gecko_data spi_gecko_data_##n = { \
325
+ SPI_CONTEXT_INIT_LOCK(spi_gecko_data_##n, ctx), \
326
+ SPI_CONTEXT_INIT_SYNC(spi_gecko_data_##n, ctx), \
327
+ SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \
328
+ }; \
329
+ static struct spi_gecko_config spi_gecko_cfg_##n = { \
330
+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
331
+ .base = (USART_TypeDef *) \
332
+ DT_INST_REG_ADDR(n), \
333
+ .clock = CLOCK_USART(usart) \
334
+ }; \
335
+ DEVICE_DT_INST_DEFINE(n, \
336
+ spi_gecko_init, \
337
+ NULL, \
338
+ &spi_gecko_data_##n, \
339
+ &spi_gecko_cfg_##n, \
340
+ POST_KERNEL, \
341
+ CONFIG_SPI_INIT_PRIORITY, \
342
+ &spi_gecko_api);
343
+ #else
303
344
#define SPI_INIT2 (n , usart ) \
304
345
static struct spi_gecko_data spi_gecko_data_##n = { \
305
346
SPI_CONTEXT_INIT_LOCK(spi_gecko_data_##n, ctx), \
@@ -331,6 +372,7 @@ static struct spi_driver_api spi_gecko_api = {
331
372
POST_KERNEL, \
332
373
CONFIG_SPI_INIT_PRIORITY, \
333
374
&spi_gecko_api);
375
+ #endif /* CONFIG_PINCTRL */
334
376
335
377
#define SPI_ID (n ) DT_INST_PROP(n, peripheral_id)
336
378
0 commit comments