uncompress.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "../../iomap.h"
  29. #define BIT(x) (1 << (x))
  30. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  31. #define DEBUG_UART_SHIFT 2
  32. volatile u8 *uart;
  33. static void putc(int c)
  34. {
  35. if (uart == NULL)
  36. return;
  37. while (!(uart[UART_LSR << DEBUG_UART_SHIFT] & UART_LSR_THRE))
  38. barrier();
  39. uart[UART_TX << DEBUG_UART_SHIFT] = c;
  40. }
  41. static inline void flush(void)
  42. {
  43. }
  44. static const struct {
  45. u32 base;
  46. u32 reset_reg;
  47. u32 clock_reg;
  48. u32 bit;
  49. } uarts[] = {
  50. {
  51. TEGRA_UARTA_BASE,
  52. TEGRA_CLK_RESET_BASE + 0x04,
  53. TEGRA_CLK_RESET_BASE + 0x10,
  54. 6,
  55. },
  56. {
  57. TEGRA_UARTB_BASE,
  58. TEGRA_CLK_RESET_BASE + 0x04,
  59. TEGRA_CLK_RESET_BASE + 0x10,
  60. 7,
  61. },
  62. {
  63. TEGRA_UARTC_BASE,
  64. TEGRA_CLK_RESET_BASE + 0x08,
  65. TEGRA_CLK_RESET_BASE + 0x14,
  66. 23,
  67. },
  68. {
  69. TEGRA_UARTD_BASE,
  70. TEGRA_CLK_RESET_BASE + 0x0c,
  71. TEGRA_CLK_RESET_BASE + 0x18,
  72. 1,
  73. },
  74. {
  75. TEGRA_UARTE_BASE,
  76. TEGRA_CLK_RESET_BASE + 0x0c,
  77. TEGRA_CLK_RESET_BASE + 0x18,
  78. 2,
  79. },
  80. };
  81. static inline bool uart_clocked(int i)
  82. {
  83. if (*(u8 *)uarts[i].reset_reg & BIT(uarts[i].bit))
  84. return false;
  85. if (!(*(u8 *)uarts[i].clock_reg & BIT(uarts[i].bit)))
  86. return false;
  87. return true;
  88. }
  89. #ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA
  90. int auto_odmdata(void)
  91. {
  92. volatile u32 *pmc = (volatile u32 *)TEGRA_PMC_BASE;
  93. u32 odmdata = pmc[0xa0 / 4];
  94. /*
  95. * Bits 19:18 are the console type: 0=default, 1=none, 2==DCC, 3==UART
  96. * Some boards apparently swap the last two values, but we don't have
  97. * any way of catering for that here, so we just accept either. If this
  98. * doesn't make sense for your board, just don't enable this feature.
  99. *
  100. * Bits 17:15 indicate the UART to use, 0/1/2/3/4 are UART A/B/C/D/E.
  101. */
  102. switch ((odmdata >> 18) & 3) {
  103. case 2:
  104. case 3:
  105. break;
  106. default:
  107. return -1;
  108. }
  109. return (odmdata >> 15) & 7;
  110. }
  111. #endif
  112. /*
  113. * Setup before decompression. This is where we do UART selection for
  114. * earlyprintk and init the uart_base register.
  115. */
  116. static inline void arch_decomp_setup(void)
  117. {
  118. int uart_id;
  119. volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE;
  120. u32 chip, div;
  121. #if defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  122. uart_id = auto_odmdata();
  123. #elif defined(CONFIG_TEGRA_DEBUG_UARTA)
  124. uart_id = 0;
  125. #elif defined(CONFIG_TEGRA_DEBUG_UARTB)
  126. uart_id = 1;
  127. #elif defined(CONFIG_TEGRA_DEBUG_UARTC)
  128. uart_id = 2;
  129. #elif defined(CONFIG_TEGRA_DEBUG_UARTD)
  130. uart_id = 3;
  131. #elif defined(CONFIG_TEGRA_DEBUG_UARTE)
  132. uart_id = 4;
  133. #endif
  134. if (uart_id < 0 || uart_id >= ARRAY_SIZE(uarts) ||
  135. !uart_clocked(uart_id))
  136. uart = NULL;
  137. else
  138. uart = (volatile u8 *)uarts[uart_id].base;
  139. if (uart == NULL)
  140. return;
  141. chip = (apb_misc[0x804 / 4] >> 8) & 0xff;
  142. if (chip == 0x20)
  143. div = 0x0075;
  144. else
  145. div = 0x00dd;
  146. uart[UART_LCR << DEBUG_UART_SHIFT] |= UART_LCR_DLAB;
  147. uart[UART_DLL << DEBUG_UART_SHIFT] = div & 0xff;
  148. uart[UART_DLM << DEBUG_UART_SHIFT] = div >> 8;
  149. uart[UART_LCR << DEBUG_UART_SHIFT] = 3;
  150. }
  151. static inline void arch_decomp_wdog(void)
  152. {
  153. }
  154. #endif