serial.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  67. call _serial_initialize;
  68. #endif
  69. .endm
  70. .macro serial_early_set_baud
  71. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  72. R0.L = LO(CONFIG_BAUDRATE);
  73. R0.H = HI(CONFIG_BAUDRATE);
  74. call _serial_set_baud;
  75. #endif
  76. .endm
  77. /* Since we embed the string right into our .text section, we need
  78. * to find its address. We do this by getting our PC and adding 2
  79. * bytes (which is the length of the jump instruction). Then we
  80. * pass this address to serial_puts().
  81. */
  82. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  83. # define serial_early_puts(str) \
  84. .section .rodata; \
  85. 7: \
  86. .ascii "Early:"; \
  87. .ascii __FILE__; \
  88. .ascii ": "; \
  89. .ascii str; \
  90. .asciz "\n"; \
  91. .previous; \
  92. R0.L = 7b; \
  93. R0.H = 7b; \
  94. call _serial_puts;
  95. #else
  96. # define serial_early_puts(str)
  97. #endif
  98. #endif
  99. #endif