Skip to content

Commit 00991e4

Browse files
akanisettifabiobaltieri
authored andcommitted
drivers: serial: ns16550: Moved PCIe probe to init function
Moved PCIe probe from configure function to init function because whenever uart_configure api is called MMIO address is getting updated. Signed-off-by: Anisetti Avinash Krishna <[email protected]>
1 parent 712dab4 commit 00991e4

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

drivers/serial/uart_ns16550.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -332,38 +332,12 @@ static int uart_ns16550_configure(const struct device *dev,
332332

333333
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
334334

335-
ARG_UNUSED(dev_data);
336-
ARG_UNUSED(dev_cfg);
337-
338335
#if defined(CONFIG_PINCTRL)
339336
if (dev_cfg->pincfg != NULL) {
340337
pinctrl_apply_state(dev_cfg->pincfg, PINCTRL_STATE_DEFAULT);
341338
}
342339
#endif
343340

344-
#ifndef CONFIG_UART_NS16550_ACCESS_IOPORT
345-
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
346-
if (dev_cfg->pcie) {
347-
struct pcie_bar mbar;
348-
349-
if (dev_cfg->pcie->bdf == PCIE_BDF_NONE) {
350-
ret = -EINVAL;
351-
goto out;
352-
}
353-
354-
pcie_probe_mbar(dev_cfg->pcie->bdf, 0, &mbar);
355-
pcie_set_cmd(dev_cfg->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true);
356-
357-
device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size,
358-
K_MEM_CACHE_NONE);
359-
} else
360-
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) */
361-
{
362-
/* Map directly from DTS */
363-
DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE);
364-
}
365-
#endif /* UART_NS15660_ACCESS_IOPORT */
366-
367341
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
368342
dev_data->iir_cache = 0U;
369343
#endif
@@ -524,17 +498,39 @@ static int uart_ns16550_config_get(const struct device *dev,
524498
static int uart_ns16550_init(const struct device *dev)
525499
{
526500
struct uart_ns16550_dev_data *data = dev->data;
501+
const struct uart_ns16550_device_config *dev_cfg = dev->config;
527502
int ret;
528503

504+
ARG_UNUSED(dev_cfg);
505+
506+
#ifndef CONFIG_UART_NS16550_ACCESS_IOPORT
507+
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
508+
if (dev_cfg->pcie) {
509+
struct pcie_bar mbar;
510+
511+
if (dev_cfg->pcie->bdf == PCIE_BDF_NONE) {
512+
return -EINVAL;
513+
}
514+
515+
pcie_probe_mbar(dev_cfg->pcie->bdf, 0, &mbar);
516+
pcie_set_cmd(dev_cfg->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true);
517+
518+
device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size,
519+
K_MEM_CACHE_NONE);
520+
} else
521+
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) */
522+
{
523+
/* Map directly from DTS */
524+
DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE);
525+
}
526+
#endif /* !UART_NS15660_ACCESS_IOPORT */
529527
ret = uart_ns16550_configure(dev, &data->uart_config);
530528
if (ret != 0) {
531529
return ret;
532530
}
533531

534532
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
535-
const struct uart_ns16550_device_config *config = dev->config;
536-
537-
config->irq_config_func(dev);
533+
dev_cfg->irq_config_func(dev);
538534
#endif
539535

540536
return 0;

0 commit comments

Comments
 (0)