]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/serial/serial-uclass.c
dm: serial: Put common code into separate functions
[karo-tx-uboot.git] / drivers / serial / serial-uclass.c
index d04104e74700108bf1df0cc232481336c6db1259..1a75950d19fa4c738f7f5c881da08561d416faf2 100644 (file)
@@ -25,6 +25,7 @@ struct udevice *cur_dev __attribute__ ((section(".data")));
 
 static void serial_find_console_or_panic(void)
 {
+#ifdef CONFIG_OF_CONTROL
        int node;
 
        /* Check for a chosen console */
@@ -44,7 +45,7 @@ static void serial_find_console_or_panic(void)
                        return;
                cur_dev = NULL;
        }
-
+#endif
        /*
         * Failing that, get the device with sequence number 0, or in extremis
         * just the first serial device we can find. But we insist on having
@@ -70,7 +71,7 @@ void serial_initialize(void)
        serial_find_console_or_panic();
 }
 
-void serial_putc(char ch)
+static void serial_putc_dev(struct udevice *dev, char ch)
 {
        struct dm_serial_ops *ops = serial_get_ops(cur_dev);
        int err;
@@ -82,6 +83,11 @@ void serial_putc(char ch)
                serial_putc('\r');
 }
 
+void serial_putc(char ch)
+{
+       serial_putc_dev(cur_dev, ch);
+}
+
 void serial_setbrg(void)
 {
        struct dm_serial_ops *ops = serial_get_ops(cur_dev);
@@ -106,28 +112,32 @@ int serial_tstc(void)
        return 1;
 }
 
-int serial_getc(void)
+static int serial_getc_dev(struct udevice *dev)
 {
-       struct dm_serial_ops *ops = serial_get_ops(cur_dev);
+       struct dm_serial_ops *ops = serial_get_ops(dev);
        int err;
 
        do {
-               err = ops->getc(cur_dev);
+               err = ops->getc(dev);
        } while (err == -EAGAIN);
 
        return err >= 0 ? err : 0;
 }
 
+int serial_getc(void)
+{
+       return serial_getc_dev(cur_dev);
+}
+
 void serial_stdio_init(void)
 {
 }
 
-void serial_stub_putc(struct stdio_dev *sdev, const char ch)
+static void serial_stub_putc(struct stdio_dev *sdev, const char ch)
 {
        struct udevice *dev = sdev->priv;
-       struct dm_serial_ops *ops = serial_get_ops(dev);
 
-       ops->putc(dev, ch);
+       serial_putc_dev(dev, ch);
 }
 
 void serial_stub_puts(struct stdio_dev *sdev, const char *str)
@@ -139,15 +149,8 @@ void serial_stub_puts(struct stdio_dev *sdev, const char *str)
 int serial_stub_getc(struct stdio_dev *sdev)
 {
        struct udevice *dev = sdev->priv;
-       struct dm_serial_ops *ops = serial_get_ops(dev);
-
-       int err;
-
-       do {
-               err = ops->getc(dev);
-       } while (err == -EAGAIN);
 
-       return err >= 0 ? err : 0;
+       return serial_getc_dev(dev);
 }
 
 int serial_stub_tstc(struct stdio_dev *sdev)
@@ -197,7 +200,7 @@ static int serial_pre_remove(struct udevice *dev)
 #ifdef CONFIG_SYS_STDIO_DEREGISTER
        struct serial_dev_priv *upriv = dev->uclass_priv;
 
-       if (stdio_deregister_dev(upriv->sdev))
+       if (stdio_deregister_dev(upriv->sdev, 0))
                return -EPERM;
 #endif