Skip to content

Commit 0da7e06

Browse files
SgrrZhfcarlescufi
authored andcommitted
driver: uart: pl011_sbsa: refine creating device instance
Create pl011_sbsa device instance via the DT_INST_FOREACH_STATUS_OKAY macro. Signed-off-by: Huifeng Zhang <[email protected]>
1 parent 9da9c90 commit 0da7e06

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

drivers/serial/Kconfig.pl011

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
menuconfig UART_PL011
55
bool "ARM PL011 UART Driver"
66
default y
7-
depends on DT_HAS_ARM_PL011_ENABLED
7+
depends on DT_HAS_ARM_PL011_ENABLED || DT_HAS_ARM_SBSA_UART_ENABLED
88
select SERIAL_HAS_DRIVER
99
select SERIAL_SUPPORT_INTERRUPT
1010
help
@@ -14,6 +14,7 @@ if UART_PL011
1414

1515
config UART_PL011_SBSA
1616
bool "SBSA UART"
17+
default y if DT_HAS_ARM_SBSA_UART_ENABLED
1718
help
1819
Enable SBSA mode for PL011 driver. SBSA stands for
1920
Server Based System Architecture. This specification

drivers/serial/uart_pl011.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -519,38 +519,39 @@ DT_INST_FOREACH_STATUS_OKAY(PL011_INIT)
519519
#define DT_DRV_COMPAT SBSA_COMPAT
520520

521521
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
522-
static void pl011_irq_config_func_sbsa(const struct device *dev);
522+
#define PL011_SBSA_CONFIG_PORT(n) \
523+
static void pl011_irq_config_func_sbsa_##n(const struct device *dev) \
524+
{ \
525+
DT_INST_FOREACH_PROP_ELEM(n, interrupt_names, \
526+
PL011_IRQ_CONFIG_FUNC_BODY) \
527+
}; \
528+
\
529+
static struct pl011_config pl011_cfg_sbsa_##n = { \
530+
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(n)), \
531+
.irq_config_func = pl011_irq_config_func_sbsa_##n, \
532+
};
533+
#else
534+
#define PL011_SBSA_CONFIG_PORT(n) \
535+
static struct pl011_config pl011_cfg_sbsa_##n = { \
536+
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(n)), \
537+
};
523538
#endif
524539

525-
static struct pl011_config pl011_cfg_sbsa = {
526-
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(0)),
527-
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
528-
.irq_config_func = pl011_irq_config_func_sbsa,
529-
#endif
530-
};
531-
532-
static struct pl011_data pl011_data_sbsa = {
533-
.sbsa = true,
534-
};
535-
536-
DEVICE_DT_INST_DEFINE(0,
537-
&pl011_init,
538-
NULL,
539-
&pl011_data_sbsa,
540-
&pl011_cfg_sbsa, PRE_KERNEL_1,
541-
CONFIG_SERIAL_INIT_PRIORITY,
542-
&pl011_driver_api);
540+
#define PL011_SBSA_INIT(n) \
541+
PL011_SBSA_CONFIG_PORT(n) \
542+
\
543+
static struct pl011_data pl011_data_sbsa_##n = { \
544+
.sbsa = true, \
545+
}; \
546+
\
547+
DEVICE_DT_INST_DEFINE(n, &pl011_init, \
548+
NULL, \
549+
&pl011_data_sbsa_##n, \
550+
&pl011_cfg_sbsa_##n, \
551+
PRE_KERNEL_1, \
552+
CONFIG_SERIAL_INIT_PRIORITY, \
553+
&pl011_driver_api);
543554

544-
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
545-
static void pl011_irq_config_func_sbsa(const struct device *dev)
546-
{
547-
IRQ_CONNECT(DT_INST_IRQN(0),
548-
DT_INST_IRQ(0, priority),
549-
pl011_isr,
550-
DEVICE_GET(pl011_sbsa),
551-
0);
552-
irq_enable(DT_INST_IRQN(0));
553-
}
554-
#endif
555+
DT_INST_FOREACH_STATUS_OKAY(PL011_SBSA_INIT)
555556

556557
#endif /* CONFIG_UART_PL011_SBSA */

0 commit comments

Comments
 (0)