X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fserial%2Fserial-uclass.c;h=71f1a5cb91024e9fc473e2a5e61f0deb82efd3c1;hb=256d83cd6d8caf345ffba414a0f77f30d68caf8a;hp=fd010cac4286261da1b4aa8a52bd729cc653d81c;hpb=dd0204e48d05f41480743a798b94d5484b664639;p=u-boot diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index fd010cac42..71f1a5cb91 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -11,9 +11,12 @@ #include #include #include +#include #include #include +#include + DECLARE_GLOBAL_DATA_PTR; /* The currently-selected console serial device */ @@ -47,13 +50,22 @@ static void serial_find_console_or_panic(void) } #endif /* + * Try to use CONFIG_CONS_INDEX if available (it is numbered from 1!). + * * 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 * a console (even if it is silent). */ - if (uclass_get_device_by_seq(UCLASS_SERIAL, 0, &cur_dev) && +#ifdef CONFIG_CONS_INDEX +#define INDEX (CONFIG_CONS_INDEX - 1) +#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"); +#undef INDEX } /* Called prior to relocation */ @@ -71,95 +83,98 @@ void serial_initialize(void) serial_find_console_or_panic(); } -void serial_putc(char ch) +static void _serial_putc(struct udevice *dev, char ch) { - struct dm_serial_ops *ops = serial_get_ops(cur_dev); + struct dm_serial_ops *ops = serial_get_ops(dev); int err; do { - err = ops->putc(cur_dev, ch); + err = ops->putc(dev, ch); } while (err == -EAGAIN); if (ch == '\n') - serial_putc('\r'); + _serial_putc(dev, '\r'); } -void serial_setbrg(void) +static void _serial_puts(struct udevice *dev, const char *str) { - struct dm_serial_ops *ops = serial_get_ops(cur_dev); - - if (ops->setbrg) - ops->setbrg(cur_dev, gd->baudrate); + while (*str) + _serial_putc(dev, *str++); } -void serial_puts(const char *str) +static int _serial_getc(struct udevice *dev) { - while (*str) - serial_putc(*str++); + struct dm_serial_ops *ops = serial_get_ops(dev); + int err; + + do { + err = ops->getc(dev); + if (err == -EAGAIN) + WATCHDOG_RESET(); + } while (err == -EAGAIN); + + return err >= 0 ? err : 0; } -int serial_tstc(void) +static int _serial_tstc(struct udevice *dev) { - struct dm_serial_ops *ops = serial_get_ops(cur_dev); + struct dm_serial_ops *ops = serial_get_ops(dev); if (ops->pending) - return ops->pending(cur_dev, true); + return ops->pending(dev, true); return 1; } +void serial_putc(char ch) +{ + _serial_putc(cur_dev, ch); +} + +void serial_puts(const char *str) +{ + _serial_puts(cur_dev, str); +} + int serial_getc(void) { - struct dm_serial_ops *ops = serial_get_ops(cur_dev); - int err; + return _serial_getc(cur_dev); +} - do { - err = ops->getc(cur_dev); - } while (err == -EAGAIN); +int serial_tstc(void) +{ + return _serial_tstc(cur_dev); +} - return err >= 0 ? err : 0; +void serial_setbrg(void) +{ + struct dm_serial_ops *ops = serial_get_ops(cur_dev); + + if (ops->setbrg) + ops->setbrg(cur_dev, gd->baudrate); } 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(sdev->priv, ch); } void serial_stub_puts(struct stdio_dev *sdev, const char *str) { - while (*str) - serial_stub_putc(sdev, *str++); + _serial_puts(sdev->priv, 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(sdev->priv); } int serial_stub_tstc(struct stdio_dev *sdev) { - struct udevice *dev = sdev->priv; - struct dm_serial_ops *ops = serial_get_ops(dev); - - if (ops->pending) - return ops->pending(dev, true); - - return 1; + return _serial_tstc(sdev->priv); } static int serial_post_probe(struct udevice *dev) @@ -198,7 +213,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), 0) + if (stdio_deregister_dev(upriv->sdev, 0)) return -EPERM; #endif