uncompress.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * arch/arm/mach-tegra/include/mach/uncompress.h
  3. *
  4. * Copyright (C) 2010 Google, Inc.
  5. * Copyright (C) 2011 Google, Inc.
  6. * Copyright (C) 2011-2012 NVIDIA CORPORATION. All Rights Reserved.
  7. *
  8. * Author:
  9. * Colin Cross <ccross@google.com>
  10. * Erik Gilling <konkers@google.com>
  11. * Doug Anderson <dianders@chromium.org>
  12. * Stephen Warren <swarren@nvidia.com>
  13. *
  14. * This software is licensed under the terms of the GNU General Public
  15. * License version 2, as published by the Free Software Foundation, and
  16. * may be copied, distributed, and modified under those terms.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. */
  24. #ifndef __MACH_TEGRA_UNCOMPRESS_H
  25. #define __MACH_TEGRA_UNCOMPRESS_H
  26. #include <linux/types.h>
  27. #include <linux/serial_reg.h>
  28. #include <mach/iomap.h>
  29. #include <mach/irammap.h>
  30. #define BIT(x) (1 << (x))
  31. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  32. #define DEBUG_UART_SHIFT 2
  33. volatile u8 *uart;
  34. static void putc(int c)
  35. {
  36. if (uart == NULL)
  37. return;
  38. while (!(uart[UART_LSR << DEBUG_UART_SHIFT] & UART_LSR_THRE))
  39. barrier();
  40. uart[UART_TX << DEBUG_UART_SHIFT] = c;
  41. }
  42. static inline void flush(void)
  43. {
  44. }
  45. static inline void save_uart_address(void)
  46. {
  47. u32 *buf = (u32 *)(TEGRA_IRAM_BASE + TEGRA_IRAM_DEBUG_UART_OFFSET);
  48. if (uart) {
  49. buf[0] = TEGRA_IRAM_DEBUG_UART_COOKIE;
  50. buf[1] = (u32)uart;
  51. } else
  52. buf[0] = 0;
  53. }
  54. /*
  55. * Setup before decompression. This is where we do UART selection for
  56. * earlyprintk and init the uart_base register.
  57. */
  58. static inline void arch_decomp_setup(void)
  59. {
  60. static const struct {
  61. u32 base;
  62. u32 reset_reg;
  63. u32 clock_reg;
  64. u32 bit;
  65. } uarts[] = {
  66. {
  67. TEGRA_UARTA_BASE,
  68. TEGRA_CLK_RESET_BASE + 0x04,
  69. TEGRA_CLK_RESET_BASE + 0x10,
  70. 6,
  71. },
  72. {
  73. TEGRA_UARTB_BASE,
  74. TEGRA_CLK_RESET_BASE + 0x04,
  75. TEGRA_CLK_RESET_BASE + 0x10,
  76. 7,
  77. },
  78. {
  79. TEGRA_UARTC_BASE,
  80. TEGRA_CLK_RESET_BASE + 0x08,
  81. TEGRA_CLK_RESET_BASE + 0x14,
  82. 23,
  83. },
  84. {
  85. TEGRA_UARTD_BASE,
  86. TEGRA_CLK_RESET_BASE + 0x0c,
  87. TEGRA_CLK_RESET_BASE + 0x18,
  88. 1,
  89. },
  90. {
  91. TEGRA_UARTE_BASE,
  92. TEGRA_CLK_RESET_BASE + 0x0c,
  93. TEGRA_CLK_RESET_BASE + 0x18,
  94. 2,
  95. },
  96. };
  97. int i;
  98. volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE;
  99. u32 chip, div;
  100. /*
  101. * Look for the first UART that:
  102. * a) Is not in reset.
  103. * b) Is clocked.
  104. * c) Has a 'D' in the scratchpad register.
  105. *
  106. * Note that on Tegra30, the first two conditions are required, since
  107. * if not true, accesses to the UART scratch register will hang.
  108. * Tegra20 doesn't have this issue.
  109. *
  110. * The intent is that the bootloader will tell the kernel which UART
  111. * to use by setting up those conditions. If nothing found, we'll fall
  112. * back to what's specified in TEGRA_DEBUG_UART_BASE.
  113. */
  114. for (i = 0; i < ARRAY_SIZE(uarts); i++) {
  115. if (*(u8 *)uarts[i].reset_reg & BIT(uarts[i].bit))
  116. continue;
  117. if (!(*(u8 *)uarts[i].clock_reg & BIT(uarts[i].bit)))
  118. continue;
  119. uart = (volatile u8 *)uarts[i].base;
  120. if (uart[UART_SCR << DEBUG_UART_SHIFT] != 'D')
  121. continue;
  122. break;
  123. }
  124. if (i == ARRAY_SIZE(uarts))
  125. uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE;
  126. save_uart_address();
  127. if (uart == NULL)
  128. return;
  129. chip = (apb_misc[0x804 / 4] >> 8) & 0xff;
  130. if (chip == 0x20)
  131. div = 0x0075;
  132. else
  133. div = 0x00dd;
  134. uart[UART_LCR << DEBUG_UART_SHIFT] |= UART_LCR_DLAB;
  135. uart[UART_DLL << DEBUG_UART_SHIFT] = div & 0xff;
  136. uart[UART_DLM << DEBUG_UART_SHIFT] = div >> 8;
  137. uart[UART_LCR << DEBUG_UART_SHIFT] = 3;
  138. }
  139. static inline void arch_decomp_wdog(void)
  140. {
  141. }
  142. #endif