imx_uart_console.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <console_macros.S>
  9. #include <assert_macros.S>
  10. #include "imx_uart.h"
  11. #define URXD 0x0 /* Receiver Register */
  12. #define UTXD 0x40 /* Transmitter Register */
  13. #define USR2 0x98 /* UART Status Register 2 */
  14. #define UTS 0xb4 /* UART Test Register (mx31) */
  15. #define URXD_RX_DATA (0xFF)
  16. .globl console_imx_uart_register
  17. .globl console_imx_uart_init
  18. .globl console_imx_uart_putc
  19. .globl console_imx_uart_getc
  20. .globl console_imx_uart_flush
  21. func console_imx_uart_register
  22. mov x7, x30
  23. mov x6, x3
  24. cbz x6, register_fail
  25. str x0, [x6, #CONSOLE_T_BASE]
  26. bl console_imx_uart_init
  27. cbz x0, register_fail
  28. mov x0, x6
  29. mov x30, x7
  30. finish_console_register imx_uart putc=1, getc=ENABLE_CONSOLE_GETC, flush=1
  31. register_fail:
  32. ret x7
  33. endfunc console_imx_uart_register
  34. func console_imx_uart_init
  35. mov w0, #1
  36. ret
  37. endfunc console_imx_uart_init
  38. func console_imx_uart_putc
  39. ldr x1, [x1, #CONSOLE_T_BASE]
  40. cbz x1, putc_error
  41. /* Prepare '\r' to '\n' */
  42. cmp w0, #0xA
  43. b.ne 2f
  44. 1:
  45. /* Check if the transmit FIFO is full */
  46. ldr w2, [x1, #UTS]
  47. tbnz w2, #4, 1b
  48. mov w2, #0xD
  49. str w2, [x1, #UTXD]
  50. 2:
  51. /* Check if the transmit FIFO is full */
  52. ldr w2, [x1, #UTS]
  53. tbnz w2, #4, 2b
  54. str w0, [x1, #UTXD]
  55. ret
  56. putc_error:
  57. mov w0, #-1
  58. ret
  59. endfunc console_imx_uart_putc
  60. func console_imx_uart_getc
  61. ldr x0, [x0, #CONSOLE_T_BASE]
  62. cbz x0, getc_error
  63. 1:
  64. ldr w1, [x0, #UTS]
  65. tbnz w1, #5, 1b
  66. ldr w1, [x0, #URXD]
  67. and w0, w1, #URXD_RX_DATA
  68. ret
  69. getc_error:
  70. mov w0, #-1
  71. ret
  72. endfunc console_imx_uart_getc
  73. func console_imx_uart_flush
  74. ldr x0, [x0, #CONSOLE_T_BASE]
  75. cbz x0, flush_exit
  76. 1:
  77. /* Wait for the transmit complete bit */
  78. ldr w1, [x0, #USR2]
  79. tbz w1, #3, 1b
  80. flush_exit:
  81. ret
  82. endfunc console_imx_uart_flush