pci: Do not skip legacy IDE device configuration
[oweals/u-boot.git] / drivers / serial / serial-uclass.c
index cd5324cfa3b398b4fe3d6ccf4d8984d900777d56..b8c2f482288913475af367869b0ab086e6fd5943 100644 (file)
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 
-#include <ns16550.h>
-
 DECLARE_GLOBAL_DATA_PTR;
 
-/* The currently-selected console serial device */
-struct udevice *cur_dev __attribute__ ((section(".data")));
-
 /*
  * Table with supported baudrates (defined in config_xyz.h)
  */
@@ -34,25 +29,30 @@ static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE;
 
 static void serial_find_console_or_panic(void)
 {
+       struct udevice *dev;
+
 #ifdef CONFIG_OF_CONTROL
        int node;
 
        /* Check for a chosen console */
        node = fdtdec_get_chosen_node(gd->fdt_blob, "stdout-path");
        if (node < 0)
-               node = fdtdec_get_alias_node(gd->fdt_blob, "console");
-       if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, &cur_dev))
+               node = fdt_path_offset(gd->fdt_blob, "console");
+       if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, &dev)) {
+               gd->cur_serial_dev = dev;
                return;
+       }
 
        /*
         * If the console is not marked to be bound before relocation, bind
         * it anyway.
         */
        if (node > 0 &&
-           !lists_bind_fdt(gd->dm_root, gd->fdt_blob, node, &cur_dev)) {
-               if (!device_probe(cur_dev))
+           !lists_bind_fdt(gd->dm_root, gd->fdt_blob, node, &dev)) {
+               if (!device_probe(dev)) {
+                       gd->cur_serial_dev = dev;
                        return;
-               cur_dev = NULL;
+               }
        }
 #endif
        /*
@@ -67,11 +67,12 @@ static void serial_find_console_or_panic(void)
 #else
 #define INDEX 0
 #endif
-       if (uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &cur_dev) &&
-           uclass_get_device(UCLASS_SERIAL, INDEX, &cur_dev) &&
-           (uclass_first_device(UCLASS_SERIAL, &cur_dev) || !cur_dev))
-               panic("No serial driver found");
+       if (uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) &&
+           uclass_get_device(UCLASS_SERIAL, INDEX, &dev) &&
+           (uclass_first_device(UCLASS_SERIAL, &dev) || !dev))
+               panic_str("No serial driver found");
 #undef INDEX
+       gd->cur_serial_dev = dev;
 }
 
 /* Called prior to relocation */
@@ -133,30 +134,30 @@ static int _serial_tstc(struct udevice *dev)
 
 void serial_putc(char ch)
 {
-       _serial_putc(cur_dev, ch);
+       _serial_putc(gd->cur_serial_dev, ch);
 }
 
 void serial_puts(const char *str)
 {
-       _serial_puts(cur_dev, str);
+       _serial_puts(gd->cur_serial_dev, str);
 }
 
 int serial_getc(void)
 {
-       return _serial_getc(cur_dev);
+       return _serial_getc(gd->cur_serial_dev);
 }
 
 int serial_tstc(void)
 {
-       return _serial_tstc(cur_dev);
+       return _serial_tstc(gd->cur_serial_dev);
 }
 
 void serial_setbrg(void)
 {
-       struct dm_serial_ops *ops = serial_get_ops(cur_dev);
+       struct dm_serial_ops *ops = serial_get_ops(gd->cur_serial_dev);
 
        if (ops->setbrg)
-               ops->setbrg(cur_dev, gd->baudrate);
+               ops->setbrg(gd->cur_serial_dev, gd->baudrate);
 }
 
 void serial_stdio_init(void)
@@ -250,11 +251,27 @@ static int serial_post_probe(struct udevice *dev)
 {
        struct dm_serial_ops *ops = serial_get_ops(dev);
 #ifdef CONFIG_DM_STDIO
-       struct serial_dev_priv *upriv = dev->uclass_priv;
+       struct serial_dev_priv *upriv = dev_get_uclass_priv(dev);
        struct stdio_dev sdev;
 #endif
        int ret;
 
+#if defined(CONFIG_NEEDS_MANUAL_RELOC)
+       if (ops->setbrg)
+               ops->setbrg += gd->reloc_off;
+       if (ops->getc)
+               ops->getc += gd->reloc_off;
+       if (ops->putc)
+               ops->putc += gd->reloc_off;
+       if (ops->pending)
+               ops->pending += gd->reloc_off;
+       if (ops->clear)
+               ops->clear += gd->reloc_off;
+#if CONFIG_POST & CONFIG_SYS_POST_UART
+       if (ops->loop)
+               ops->loop += gd->reloc_off
+#endif
+#endif
        /* Set the baud rate */
        if (ops->setbrg) {
                ret = ops->setbrg(dev, gd->baudrate);
@@ -282,7 +299,7 @@ static int serial_post_probe(struct udevice *dev)
 static int serial_pre_remove(struct udevice *dev)
 {
 #ifdef CONFIG_SYS_STDIO_DEREGISTER
-       struct serial_dev_priv *upriv = dev->uclass_priv;
+       struct serial_dev_priv *upriv = dev_get_uclass_priv(dev);
 
        if (stdio_deregister_dev(upriv->sdev, 0))
                return -EPERM;
@@ -294,6 +311,7 @@ static int serial_pre_remove(struct udevice *dev)
 UCLASS_DRIVER(serial) = {
        .id             = UCLASS_SERIAL,
        .name           = "serial",
+       .flags          = DM_UC_FLAG_SEQ_ALIAS,
        .post_probe     = serial_post_probe,
        .pre_remove     = serial_pre_remove,
        .per_device_auto_alloc_size = sizeof(struct serial_dev_priv),