]> git.sur5r.net Git - u-boot/blobdiff - drivers/serial/serial-uclass.c
dm: ns16550: Use an address instead of a pointer for the uart base
[u-boot] / drivers / serial / serial-uclass.c
index 1ac943f692882700701d990e3403276334b941b0..1983a3d55bde3850bcd7369e8a5a807260fcf4f5 100644 (file)
 #include <os.h>
 #include <serial.h>
 #include <stdio_dev.h>
+#include <watchdog.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 
+#include <ns16550.h>
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* The currently-selected console serial device */
@@ -71,7 +74,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;
@@ -83,6 +86,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);
@@ -107,28 +115,34 @@ 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);
+               if (err == -EAGAIN)
+                       WATCHDOG_RESET();
        } 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)
@@ -140,15 +154,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)
@@ -198,7 +205,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