serial.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * serial.h - common serial defines for early debug and serial driver.
  3. * any functions defined here must be always_inline since
  4. * initcode cannot have function calls.
  5. *
  6. * Copyright (c) 2004-2011 Analog Devices Inc.
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #ifndef __BFIN_CPU_SERIAL_H__
  11. #define __BFIN_CPU_SERIAL_H__
  12. #include <asm/blackfin.h>
  13. #include <asm/portmux.h>
  14. #ifndef CONFIG_UART_CONSOLE
  15. # define CONFIG_UART_CONSOLE 0
  16. #endif
  17. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  18. # define BFIN_DEBUG_EARLY_SERIAL 1
  19. #else
  20. # define BFIN_DEBUG_EARLY_SERIAL 0
  21. #endif
  22. #if defined(__ADSPBF60x__)
  23. # define BFIN_UART_HW_VER 4
  24. #elif defined(__ADSPBF50x__) || defined(__ADSPBF54x__)
  25. # define BFIN_UART_HW_VER 2
  26. #else
  27. # define BFIN_UART_HW_VER 1
  28. #endif
  29. #define __PASTE_UART(num, pfx, sfx) pfx##num##_##sfx
  30. #define _PASTE_UART(num, pfx, sfx) __PASTE_UART(num, pfx, sfx)
  31. #define _P_UART(n, pin) _PASTE_UART(n, P_UART, pin)
  32. #define P_UART(pin) _P_UART(CONFIG_UART_CONSOLE, pin)
  33. #define pUART ((volatile struct bfin_mmr_serial *)uart_base)
  34. #ifndef __ASSEMBLY__
  35. __attribute__((always_inline))
  36. static inline void serial_do_portmux(void);
  37. #endif
  38. #if BFIN_UART_HW_VER < 4
  39. # include "serial1.h"
  40. #else
  41. # include "serial4.h"
  42. #endif
  43. #ifndef __ASSEMBLY__
  44. __attribute__((always_inline))
  45. static inline void serial_do_portmux(void)
  46. {
  47. if (!BFIN_DEBUG_EARLY_SERIAL) {
  48. const unsigned short pins[] = { P_UART(RX), P_UART(TX), 0, };
  49. peripheral_request_list(pins, "bfin-uart");
  50. return;
  51. }
  52. serial_early_do_portmux();
  53. }
  54. #ifndef BFIN_IN_INITCODE
  55. __attribute__((always_inline))
  56. static inline void serial_early_puts(const char *s)
  57. {
  58. if (BFIN_DEBUG_EARLY_SERIAL) {
  59. serial_puts("Early: ");
  60. serial_puts(s);
  61. }
  62. }
  63. #endif
  64. #else
  65. .macro serial_early_init
  66. #if defined(CONFIG_DEBUG_EARLY_SERIAL) && !defined(CONFIG_UART_MEM)
  67. call __serial_early_init;
  68. #endif
  69. .endm
  70. .macro serial_early_set_baud
  71. #if defined(CONFIG_DEBUG_EARLY_SERIAL) && !defined(CONFIG_UART_MEM)
  72. R0.L = LO(CONFIG_BAUDRATE);
  73. R0.H = HI(CONFIG_BAUDRATE);
  74. call __serial_early_set_baud;
  75. #endif
  76. .endm
  77. #if CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_BYPASS
  78. #define update_serial_early_string_addr \
  79. R1.L = _start; \
  80. R1.H = _start; \
  81. R0 = R0 - R1; \
  82. R1.L = 0; \
  83. R1.H = 0x2000; \
  84. R0 = R0 + R1;
  85. #else
  86. #define update_serial_early_string_addr
  87. #endif
  88. /* Since we embed the string right into our .text section, we need
  89. * to find its address. We do this by getting our PC and adding 2
  90. * bytes (which is the length of the jump instruction). Then we
  91. * pass this address to serial_puts().
  92. */
  93. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  94. # define serial_early_puts(str) \
  95. .section .rodata; \
  96. 7: \
  97. .ascii "Early:"; \
  98. .ascii __FILE__; \
  99. .ascii ": "; \
  100. .ascii str; \
  101. .asciz "\n"; \
  102. .previous; \
  103. R0.L = 7b; \
  104. R0.H = 7b; \
  105. update_serial_early_string_addr \
  106. call _uart_early_puts;
  107. #else
  108. # define serial_early_puts(str)
  109. #endif
  110. #endif
  111. #endif