Skip to content

Commit f1d3011

Browse files
lpawelczMaureenHelm
authored andcommitted
drivers: spi: gecko: add support for pinctrl configuration
This commit adds support for pinctrl configuration in the Gecko SPI driver. Signed-off-by: Pawel Czarnecki <[email protected]>
1 parent eb4a0ae commit f1d3011

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

drivers/spi/spi_gecko.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ LOG_MODULE_REGISTER(spi_gecko);
2121

2222
#include <stdbool.h>
2323

24+
#ifdef CONFIG_PINCTRL
25+
#include <zephyr/drivers/pinctrl.h>
26+
#else
2427
#ifndef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
2528
#error "Individual pin location support is required"
2629
#endif
30+
#endif /* CONFIG_PINCTRL */
31+
2732

2833
#define CLOCK_USART(id) _CONCAT(cmuClock_USART, id)
2934

@@ -38,12 +43,16 @@ struct spi_gecko_data {
3843
struct spi_gecko_config {
3944
USART_TypeDef *base;
4045
CMU_Clock_TypeDef clock;
46+
#ifdef CONFIG_PINCTRL
47+
const struct pinctrl_dev_config *pcfg;
48+
#else
4149
struct soc_gpio_pin pin_rx;
4250
struct soc_gpio_pin pin_tx;
4351
struct soc_gpio_pin pin_clk;
4452
uint8_t loc_rx;
4553
uint8_t loc_tx;
4654
uint8_t loc_clk;
55+
#endif /* CONFIG_PINCTRL */
4756
};
4857

4958

@@ -184,6 +193,7 @@ static void spi_gecko_xfer(const struct device *dev,
184193
spi_context_complete(ctx, dev, 0);
185194
}
186195

196+
#ifndef CONFIG_PINCTRL
187197
static void spi_gecko_init_pins(const struct device *dev)
188198
{
189199
const struct spi_gecko_config *config = dev->config;
@@ -208,6 +218,7 @@ static void spi_gecko_init_pins(const struct device *dev)
208218
config->base->ROUTEPEN = USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN |
209219
USART_ROUTEPEN_CLKPEN;
210220
}
221+
#endif /* !CONFIG_PINCTRL */
211222

212223

213224
/* API Functions */
@@ -241,8 +252,15 @@ static int spi_gecko_init(const struct device *dev)
241252
/* Init USART */
242253
USART_InitSync(config->base, &usartInit);
243254

255+
#ifdef CONFIG_PINCTRL
256+
err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
257+
if (err < 0) {
258+
return err;
259+
}
260+
#else
244261
/* Initialize USART pins */
245262
spi_gecko_init_pins(dev);
263+
#endif /* CONFIG_PINCTRL */
246264

247265
err = spi_context_cs_configure_all(&data->ctx);
248266
if (err < 0) {
@@ -300,6 +318,29 @@ static struct spi_driver_api spi_gecko_api = {
300318
.release = spi_gecko_release,
301319
};
302320

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
303344
#define SPI_INIT2(n, usart) \
304345
static struct spi_gecko_data spi_gecko_data_##n = { \
305346
SPI_CONTEXT_INIT_LOCK(spi_gecko_data_##n, ctx), \
@@ -331,6 +372,7 @@ static struct spi_driver_api spi_gecko_api = {
331372
POST_KERNEL, \
332373
CONFIG_SPI_INIT_PRIORITY, \
333374
&spi_gecko_api);
375+
#endif /* CONFIG_PINCTRL */
334376

335377
#define SPI_ID(n) DT_INST_PROP(n, peripheral_id)
336378

0 commit comments

Comments
 (0)