uncompress.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. static const struct {
  55. u32 base;
  56. u32 reset_reg;
  57. u32 clock_reg;
  58. u32 bit;
  59. } uarts[] = {
  60. {
  61. TEGRA_UARTA_BASE,
  62. TEGRA_CLK_RESET_BASE + 0x04,
  63. TEGRA_CLK_RESET_BASE + 0x10,
  64. 6,
  65. },
  66. {
  67. TEGRA_UARTB_BASE,
  68. TEGRA_CLK_RESET_BASE + 0x04,
  69. TEGRA_CLK_RESET_BASE + 0x10,
  70. 7,
  71. },
  72. {
  73. TEGRA_UARTC_BASE,
  74. TEGRA_CLK_RESET_BASE + 0x08,
  75. TEGRA_CLK_RESET_BASE + 0x14,
  76. 23,
  77. },
  78. {
  79. TEGRA_UARTD_BASE,
  80. TEGRA_CLK_RESET_BASE + 0x0c,
  81. TEGRA_CLK_RESET_BASE + 0x18,
  82. 1,
  83. },
  84. {
  85. TEGRA_UARTE_BASE,
  86. TEGRA_CLK_RESET_BASE + 0x0c,
  87. TEGRA_CLK_RESET_BASE + 0x18,
  88. 2,
  89. },
  90. };
  91. static inline bool uart_clocked(int i)
  92. {
  93. if (*(u8 *)uarts[i].reset_reg & BIT(uarts[i].bit))
  94. return false;
  95. if (!(*(u8 *)uarts[i].clock_reg & BIT(uarts[i].bit)))
  96. return false;
  97. return true;
  98. }
  99. #ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA
  100. int auto_odmdata(void)
  101. {
  102. volatile u32 *pmc = (volatile u32 *)TEGRA_PMC_BASE;
  103. u32 odmdata = pmc[0xa0 / 4];
  104. /*
  105. * Bits 19:18 are the console type: 0=default, 1=none, 2==DCC, 3==UART
  106. * Some boards apparently swap the last two values, but we don't have
  107. * any way of catering for that here, so we just accept either. If this
  108. * doesn't make sense for your board, just don't enable this feature.
  109. *
  110. * Bits 17:15 indicate the UART to use, 0/1/2/3/4 are UART A/B/C/D/E.
  111. */
  112. switch ((odmdata >> 18) & 3) {
  113. case 2:
  114. case 3:
  115. break;
  116. default:
  117. return -1;
  118. }
  119. return (odmdata >> 15) & 7;
  120. }
  121. #endif
  122. #ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_SCRATCH
  123. int auto_scratch(void)
  124. {
  125. int i;
  126. /*
  127. * Look for the first UART that:
  128. * a) Is not in reset.
  129. * b) Is clocked.
  130. * c) Has a 'D' in the scratchpad register.
  131. *
  132. * Note that on Tegra30, the first two conditions are required, since
  133. * if not true, accesses to the UART scratch register will hang.
  134. * Tegra20 doesn't have this issue.
  135. *
  136. * The intent is that the bootloader will tell the kernel which UART
  137. * to use by setting up those conditions. If nothing found, we'll fall
  138. * back to what's specified in TEGRA_DEBUG_UART_BASE.
  139. */
  140. for (i = 0; i < ARRAY_SIZE(uarts); i++) {
  141. if (!uart_clocked(i))
  142. continue;
  143. uart = (volatile u8 *)uarts[i].base;
  144. if (uart[UART_SCR << DEBUG_UART_SHIFT] != 'D')
  145. continue;
  146. return i;
  147. }
  148. return -1;
  149. }
  150. #endif
  151. /*
  152. * Setup before decompression. This is where we do UART selection for
  153. * earlyprintk and init the uart_base register.
  154. */
  155. static inline void arch_decomp_setup(void)
  156. {
  157. int uart_id, auto_uart_id;
  158. volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE;
  159. u32 chip, div;
  160. #if defined(CONFIG_TEGRA_DEBUG_UARTA)
  161. uart_id = 0;
  162. #elif defined(CONFIG_TEGRA_DEBUG_UARTB)
  163. uart_id = 1;
  164. #elif defined(CONFIG_TEGRA_DEBUG_UARTC)
  165. uart_id = 2;
  166. #elif defined(CONFIG_TEGRA_DEBUG_UARTD)
  167. uart_id = 3;
  168. #elif defined(CONFIG_TEGRA_DEBUG_UARTE)
  169. uart_id = 4;
  170. #else
  171. uart_id = -1;
  172. #endif
  173. #if defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  174. auto_uart_id = auto_odmdata();
  175. #elif defined(CONFIG_TEGRA_DEBUG_UART_AUTO_SCRATCH)
  176. auto_uart_id = auto_scratch();
  177. #else
  178. auto_uart_id = -1;
  179. #endif
  180. if (auto_uart_id != -1)
  181. uart_id = auto_uart_id;
  182. if (uart_id < 0 || uart_id >= ARRAY_SIZE(uarts) ||
  183. !uart_clocked(uart_id))
  184. uart = NULL;
  185. else
  186. uart = (volatile u8 *)uarts[uart_id].base;
  187. save_uart_address();
  188. if (uart == NULL)
  189. return;
  190. chip = (apb_misc[0x804 / 4] >> 8) & 0xff;
  191. if (chip == 0x20)
  192. div = 0x0075;
  193. else
  194. div = 0x00dd;
  195. uart[UART_LCR << DEBUG_UART_SHIFT] |= UART_LCR_DLAB;
  196. uart[UART_DLL << DEBUG_UART_SHIFT] = div & 0xff;
  197. uart[UART_DLM << DEBUG_UART_SHIFT] = div >> 8;
  198. uart[UART_LCR << DEBUG_UART_SHIFT] = 3;
  199. }
  200. static inline void arch_decomp_wdog(void)
  201. {
  202. }
  203. #endif