Skip to content

Commit 04ec6d7

Browse files
lpawelczMaureenHelm
authored andcommitted
dts: spi: silabs: make peripheral-id property optional
This commit makes the peripheral-id property optional and removes it's usage from the Gecko SPI driver. Signed-off-by: Pawel Czarnecki <[email protected]>
1 parent a994852 commit 04ec6d7

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

drivers/spi/spi_gecko.c

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,46 @@ LOG_MODULE_REGISTER(spi_gecko);
2929
#endif
3030
#endif /* CONFIG_PINCTRL */
3131

32-
32+
#if DT_NODE_HAS_PROP(n, peripheral_id)
3333
#define CLOCK_USART(id) _CONCAT(cmuClock_USART, id)
34+
#define GET_GECKO_USART_CLOCK(n) CLOCK_USART(DT_INST_PROP(n, peripheral_id))
35+
#else
36+
#if (USART_COUNT <= 2)
37+
#define CLOCK_USART(ref) (((ref) == USART0) ? cmuClock_USART0 \
38+
: ((ref) == USART1) ? cmuClock_USART1 \
39+
: -1)
40+
#elif (USART_COUNT == 3)
41+
#define CLOCK_USART(ref) (((ref) == USART0) ? cmuClock_USART0 \
42+
: ((ref) == USART1) ? cmuClock_USART1 \
43+
: ((ref) == USART2) ? cmuClock_USART2 \
44+
: -1)
45+
#elif (USART_COUNT == 4)
46+
#define CLOCK_USART(ref) (((ref) == USART0) ? cmuClock_USART0 \
47+
: ((ref) == USART1) ? cmuClock_USART1 \
48+
: ((ref) == USART2) ? cmuClock_USART2 \
49+
: ((ref) == USART3) ? cmuClock_USART3 \
50+
: -1)
51+
#elif (USART_COUNT == 5)
52+
#define CLOCK_USART(ref) (((ref) == USART0) ? cmuClock_USART0 \
53+
: ((ref) == USART1) ? cmuClock_USART1 \
54+
: ((ref) == USART2) ? cmuClock_USART2 \
55+
: ((ref) == USART3) ? cmuClock_USART3 \
56+
: ((ref) == USART4) ? cmuClock_USART4 \
57+
: -1)
58+
#elif (USART_COUNT == 6)
59+
#define CLOCK_USART(ref) (((ref) == USART0) ? cmuClock_USART0 \
60+
: ((ref) == USART1) ? cmuClock_USART1 \
61+
: ((ref) == USART2) ? cmuClock_USART2 \
62+
: ((ref) == USART3) ? cmuClock_USART3 \
63+
: ((ref) == USART4) ? cmuClock_USART4 \
64+
: ((ref) == USART5) ? cmuClock_USART5 \
65+
: -1)
66+
#else
67+
#error "Undefined number of USARTs."
68+
#endif /* USART_COUNT */
69+
#define GET_GECKO_USART_CLOCK(id) CLOCK_USART((USART_TypeDef *)DT_INST_REG_ADDR(id))
70+
#endif /* DT_NODE_HAS_PROP(n, peripheral_id) */
71+
3472

3573
#define SPI_WORD_SIZE 8
3674

@@ -328,7 +366,7 @@ static struct spi_driver_api spi_gecko_api = {
328366
};
329367

330368
#ifdef CONFIG_PINCTRL
331-
#define SPI_INIT2(n, usart) \
369+
#define SPI_INIT(n) \
332370
PINCTRL_DT_INST_DEFINE(n); \
333371
static struct spi_gecko_data spi_gecko_data_##n = { \
334372
SPI_CONTEXT_INIT_LOCK(spi_gecko_data_##n, ctx), \
@@ -339,7 +377,7 @@ static struct spi_driver_api spi_gecko_api = {
339377
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
340378
.base = (USART_TypeDef *) \
341379
DT_INST_REG_ADDR(n), \
342-
.clock = CLOCK_USART(usart) \
380+
.clock = GET_GECKO_USART_CLOCK(n) \
343381
}; \
344382
DEVICE_DT_INST_DEFINE(n, \
345383
spi_gecko_init, \
@@ -350,7 +388,7 @@ static struct spi_driver_api spi_gecko_api = {
350388
CONFIG_SPI_INIT_PRIORITY, \
351389
&spi_gecko_api);
352390
#else
353-
#define SPI_INIT2(n, usart) \
391+
#define SPI_INIT(n) \
354392
static struct spi_gecko_data spi_gecko_data_##n = { \
355393
SPI_CONTEXT_INIT_LOCK(spi_gecko_data_##n, ctx), \
356394
SPI_CONTEXT_INIT_SYNC(spi_gecko_data_##n, ctx), \
@@ -359,7 +397,7 @@ static struct spi_driver_api spi_gecko_api = {
359397
static struct spi_gecko_config spi_gecko_cfg_##n = { \
360398
.base = (USART_TypeDef *) \
361399
DT_INST_REG_ADDR(n), \
362-
.clock = CLOCK_USART(usart), \
400+
.clock = GET_GECKO_USART_CLOCK(n), \
363401
.pin_rx = { DT_INST_PROP_BY_IDX(n, location_rx, 1), \
364402
DT_INST_PROP_BY_IDX(n, location_rx, 2), \
365403
gpioModeInput, 1}, \
@@ -383,8 +421,4 @@ static struct spi_driver_api spi_gecko_api = {
383421
&spi_gecko_api);
384422
#endif /* CONFIG_PINCTRL */
385423

386-
#define SPI_ID(n) DT_INST_PROP(n, peripheral_id)
387-
388-
#define SPI_INIT(n) SPI_INIT2(n, SPI_ID(n))
389-
390424
DT_INST_FOREACH_STATUS_OKAY(SPI_INIT)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ properties:
1313

1414
peripheral-id:
1515
type: int
16-
required: true
1716
description: peripheral ID
1817

1918
# Note: Not all SoC series support setting individual pin location. If this

0 commit comments

Comments
 (0)