0001-x86-serial-ns16550-Allow-the-UART-to-be-silently-dis.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. From 13263cb35e8fc82f15aad2c1091f2b05342fbe0f Mon Sep 17 00:00:00 2001
  2. From: Simon Glass <sjg@chromium.org>
  3. Date: Wed, 1 Nov 2023 12:04:42 -0600
  4. Subject: [PATCH 1/1] x86: serial: ns16550: Allow the UART to be silently
  5. disabled
  6. U-Boot normally requires a UART. When booting from coreboot it is
  7. sometimes just not available, e.g. when no sysinfo or DBG2 information
  8. is provided.
  9. In this case we need to continue running, since the display can be used.
  10. Add a flag to disable serial for this case.
  11. This allows U-Boot to start up and operation from the display, instead
  12. of hanging on start-up.
  13. This could perhaps be hidden behind a Kconfig option to reduce code
  14. size.
  15. Signed-off-by: Simon Glass <sjg@chromium.org>
  16. ---
  17. drivers/serial/ns16550.c | 17 +++++++++++++++--
  18. drivers/serial/serial_coreboot.c | 1 +
  19. include/ns16550.h | 1 +
  20. 3 files changed, 17 insertions(+), 2 deletions(-)
  21. diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
  22. index 6fcb5b523a..891124fc62 100644
  23. --- a/drivers/serial/ns16550.c
  24. +++ b/drivers/serial/ns16550.c
  25. @@ -384,6 +384,8 @@ static int ns16550_serial_putc(struct udevice *dev, const char ch)
  26. {
  27. struct ns16550 *const com_port = dev_get_priv(dev);
  28. + if (com_port->plat->flags & NS16550_FLAG_DISABLE)
  29. + return 0;
  30. if (!(serial_in(&com_port->lsr) & UART_LSR_THRE))
  31. return -EAGAIN;
  32. serial_out(ch, &com_port->thr);
  33. @@ -404,6 +406,9 @@ static int ns16550_serial_pending(struct udevice *dev, bool input)
  34. {
  35. struct ns16550 *const com_port = dev_get_priv(dev);
  36. + if (com_port->plat->flags & NS16550_FLAG_DISABLE)
  37. + return 0;
  38. +
  39. if (input)
  40. return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0;
  41. else
  42. @@ -414,6 +419,9 @@ static int ns16550_serial_getc(struct udevice *dev)
  43. {
  44. struct ns16550 *const com_port = dev_get_priv(dev);
  45. + if (com_port->plat->flags & NS16550_FLAG_DISABLE)
  46. + return 0;
  47. +
  48. if (!(serial_in(&com_port->lsr) & UART_LSR_DR))
  49. return -EAGAIN;
  50. @@ -428,7 +436,8 @@ static int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
  51. clock_divisor = ns16550_calc_divisor(com_port, plat->clock, baudrate);
  52. - ns16550_setbrg(com_port, clock_divisor);
  53. + if (!(plat->flags & NS16550_FLAG_DISABLE))
  54. + ns16550_setbrg(com_port, clock_divisor);
  55. return 0;
  56. }
  57. @@ -441,6 +450,9 @@ static int ns16550_serial_setconfig(struct udevice *dev, uint serial_config)
  58. uint bits = SERIAL_GET_BITS(serial_config);
  59. uint stop = SERIAL_GET_STOP(serial_config);
  60. + if (com_port->plat->flags & NS16550_FLAG_DISABLE)
  61. + return 0;
  62. +
  63. /*
  64. * only parity config is implemented, check if other serial settings
  65. * are the default one.
  66. @@ -533,7 +545,8 @@ int ns16550_serial_probe(struct udevice *dev)
  67. reset_deassert_bulk(&reset_bulk);
  68. com_port->plat = dev_get_plat(dev);
  69. - ns16550_init(com_port, -1);
  70. + if (!(plat->flags & NS16550_FLAG_DISABLE))
  71. + ns16550_init(com_port, -1);
  72. return 0;
  73. }
  74. diff --git a/drivers/serial/serial_coreboot.c b/drivers/serial/serial_coreboot.c
  75. index b1f69f6998..a885809abd 100644
  76. --- a/drivers/serial/serial_coreboot.c
  77. +++ b/drivers/serial/serial_coreboot.c
  78. @@ -119,6 +119,7 @@ static int coreboot_of_to_plat(struct udevice *dev)
  79. * there is no UART, which may panic. So stay silent and
  80. * pray that the video console will work.
  81. */
  82. + plat->flags |= NS16550_FLAG_DISABLE;
  83. log_debug("Cannot detect UART\n");
  84. }
  85. diff --git a/include/ns16550.h b/include/ns16550.h
  86. index 7f48130008..3c4f3e7539 100644
  87. --- a/include/ns16550.h
  88. +++ b/include/ns16550.h
  89. @@ -52,6 +52,7 @@ enum ns16550_flags {
  90. NS16550_FLAG_IO = 1 << 0, /* Use I/O access (else mem-mapped) */
  91. NS16550_FLAG_ENDIAN = 1 << 1, /* Use out_le/be_32() */
  92. NS16550_FLAG_BE = 1 << 2, /* Big-endian access (else little) */
  93. + NS16550_FLAG_DISABLE = BIT(3), /* No output or input */
  94. };
  95. /**
  96. --
  97. 2.39.5