uncompress.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * arch/arm/mach-at91/include/mach/uncompress.h
  3. *
  4. * Copyright (C) 2003 SAN People
  5. * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __ASM_ARCH_UNCOMPRESS_H
  22. #define __ASM_ARCH_UNCOMPRESS_H
  23. #include <linux/io.h>
  24. #include <linux/atmel_serial.h>
  25. #include <mach/hardware.h>
  26. #include <mach/at91_dbgu.h>
  27. #include <mach/cpu.h>
  28. void __iomem *at91_uart;
  29. #if !defined(CONFIG_ARCH_AT91X40)
  30. static const u32 uarts_rm9200[] = {
  31. AT91_BASE_DBGU0,
  32. AT91RM9200_BASE_US0,
  33. AT91RM9200_BASE_US1,
  34. AT91RM9200_BASE_US2,
  35. AT91RM9200_BASE_US3,
  36. 0,
  37. };
  38. static const u32 uarts_sam9260[] = {
  39. AT91_BASE_DBGU0,
  40. AT91SAM9260_BASE_US0,
  41. AT91SAM9260_BASE_US1,
  42. AT91SAM9260_BASE_US2,
  43. AT91SAM9260_BASE_US3,
  44. AT91SAM9260_BASE_US4,
  45. AT91SAM9260_BASE_US5,
  46. 0,
  47. };
  48. static const u32 uarts_sam9261[] = {
  49. AT91_BASE_DBGU0,
  50. AT91SAM9261_BASE_US0,
  51. AT91SAM9261_BASE_US1,
  52. AT91SAM9261_BASE_US2,
  53. 0,
  54. };
  55. static const u32 uarts_sam9263[] = {
  56. AT91_BASE_DBGU1,
  57. AT91SAM9263_BASE_US0,
  58. AT91SAM9263_BASE_US1,
  59. AT91SAM9263_BASE_US2,
  60. 0,
  61. };
  62. static const u32 uarts_sam9g45[] = {
  63. AT91_BASE_DBGU1,
  64. AT91SAM9G45_BASE_US0,
  65. AT91SAM9G45_BASE_US1,
  66. AT91SAM9G45_BASE_US2,
  67. AT91SAM9G45_BASE_US3,
  68. 0,
  69. };
  70. static const u32 uarts_sam9rl[] = {
  71. AT91_BASE_DBGU0,
  72. AT91SAM9RL_BASE_US0,
  73. AT91SAM9RL_BASE_US1,
  74. AT91SAM9RL_BASE_US2,
  75. AT91SAM9RL_BASE_US3,
  76. 0,
  77. };
  78. static const u32 uarts_sam9x5[] = {
  79. AT91_BASE_DBGU0,
  80. AT91SAM9X5_BASE_USART0,
  81. AT91SAM9X5_BASE_USART1,
  82. AT91SAM9X5_BASE_USART2,
  83. 0,
  84. };
  85. static inline const u32* decomp_soc_detect(void __iomem *dbgu_base)
  86. {
  87. u32 cidr, socid;
  88. cidr = __raw_readl(dbgu_base + AT91_DBGU_CIDR);
  89. socid = cidr & ~AT91_CIDR_VERSION;
  90. switch (socid) {
  91. case ARCH_ID_AT91RM9200:
  92. return uarts_rm9200;
  93. case ARCH_ID_AT91SAM9G20:
  94. case ARCH_ID_AT91SAM9260:
  95. return uarts_sam9260;
  96. case ARCH_ID_AT91SAM9261:
  97. return uarts_sam9261;
  98. case ARCH_ID_AT91SAM9263:
  99. return uarts_sam9263;
  100. case ARCH_ID_AT91SAM9G45:
  101. return uarts_sam9g45;
  102. case ARCH_ID_AT91SAM9RL64:
  103. return uarts_sam9rl;
  104. case ARCH_ID_AT91SAM9X5:
  105. return uarts_sam9x5;
  106. }
  107. /* at91sam9g10 */
  108. if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
  109. return uarts_sam9261;
  110. }
  111. /* at91sam9xe */
  112. else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
  113. return uarts_sam9260;
  114. }
  115. return NULL;
  116. }
  117. static inline void arch_decomp_setup(void)
  118. {
  119. int i = 0;
  120. const u32* usarts;
  121. usarts = decomp_soc_detect((void __iomem *)AT91_BASE_DBGU0);
  122. if (!usarts)
  123. usarts = decomp_soc_detect((void __iomem *)AT91_BASE_DBGU1);
  124. if (!usarts) {
  125. at91_uart = NULL;
  126. return;
  127. }
  128. do {
  129. /* physical address */
  130. at91_uart = (void __iomem *)usarts[i];
  131. if (__raw_readl(at91_uart + ATMEL_US_BRGR))
  132. return;
  133. i++;
  134. } while (usarts[i]);
  135. at91_uart = NULL;
  136. }
  137. #else
  138. static inline void arch_decomp_setup(void)
  139. {
  140. at91_uart = NULL;
  141. }
  142. #endif
  143. /*
  144. * The following code assumes the serial port has already been
  145. * initialized by the bootloader. If you didn't setup a port in
  146. * your bootloader then nothing will appear (which might be desired).
  147. *
  148. * This does not append a newline
  149. */
  150. static void putc(int c)
  151. {
  152. if (!at91_uart)
  153. return;
  154. while (!(__raw_readl(at91_uart + ATMEL_US_CSR) & ATMEL_US_TXRDY))
  155. barrier();
  156. __raw_writel(c, at91_uart + ATMEL_US_THR);
  157. }
  158. static inline void flush(void)
  159. {
  160. if (!at91_uart)
  161. return;
  162. /* wait for transmission to complete */
  163. while (!(__raw_readl(at91_uart + ATMEL_US_CSR) & ATMEL_US_TXEMPTY))
  164. barrier();
  165. }
  166. #endif