cpu.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * (C) Copyright 2008 Texas Insturments
  3. *
  4. * (C) Copyright 2002
  5. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  6. * Marius Groeger <mgroeger@sysgo.de>
  7. *
  8. * (C) Copyright 2002
  9. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. /*
  30. * CPU specific code
  31. */
  32. #include <common.h>
  33. #include <command.h>
  34. #include <asm/arch/sys_proto.h>
  35. #include <asm/system.h>
  36. #ifdef CONFIG_USE_IRQ
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #endif
  39. #ifndef CONFIG_L2_OFF
  40. void l2cache_disable(void);
  41. #endif
  42. static void cache_flush(void);
  43. static void cp_delay(void)
  44. {
  45. /* Many OMAP regs need at least 2 nops */
  46. asm("nop");
  47. asm("nop");
  48. }
  49. int cpu_init(void)
  50. {
  51. /*
  52. * setup up stacks if necessary
  53. */
  54. #ifdef CONFIG_USE_IRQ
  55. IRQ_STACK_START =
  56. _armboot_start - CONFIG_SYS_MALLOC_LEN - CONFIG_SYS_GBL_DATA_SIZE - 4;
  57. FIQ_STACK_START = IRQ_STACK_START - CONFIG_STACKSIZE_IRQ;
  58. #endif
  59. return 0;
  60. }
  61. int cleanup_before_linux(void)
  62. {
  63. unsigned int i;
  64. /*
  65. * this function is called just before we call linux
  66. * it prepares the processor for linux
  67. *
  68. * we turn off caches etc ...
  69. */
  70. disable_interrupts();
  71. /* turn off I/D-cache */
  72. icache_disable();
  73. dcache_disable();
  74. /* invalidate I-cache */
  75. cache_flush();
  76. #ifndef CONFIG_L2_OFF
  77. /* turn off L2 cache */
  78. l2cache_disable();
  79. /* invalidate L2 cache also */
  80. v7_flush_dcache_all(get_device_type());
  81. #endif
  82. i = 0;
  83. /* mem barrier to sync up things */
  84. asm("mcr p15, 0, %0, c7, c10, 4": :"r"(i));
  85. #ifndef CONFIG_L2_OFF
  86. l2cache_enable();
  87. #endif
  88. return 0;
  89. }
  90. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  91. {
  92. disable_interrupts();
  93. reset_cpu(0);
  94. /* NOTREACHED */
  95. return 0;
  96. }
  97. void icache_enable(void)
  98. {
  99. ulong reg;
  100. reg = get_cr(); /* get control reg. */
  101. cp_delay();
  102. set_cr(reg | CR_I);
  103. }
  104. void icache_disable(void)
  105. {
  106. ulong reg;
  107. reg = get_cr();
  108. cp_delay();
  109. set_cr(reg & ~CR_I);
  110. }
  111. void dcache_disable (void)
  112. {
  113. ulong reg;
  114. reg = get_cr ();
  115. cp_delay ();
  116. set_cr (reg & ~CR_C);
  117. }
  118. void l2cache_enable()
  119. {
  120. unsigned long i;
  121. volatile unsigned int j;
  122. /* ES2 onwards we can disable/enable L2 ourselves */
  123. if (get_cpu_rev() == CPU_3430_ES2) {
  124. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  125. __asm__ __volatile__("orr %0, %0, #0x2":"=r"(i));
  126. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  127. } else {
  128. /* Save r0, r12 and restore them after usage */
  129. __asm__ __volatile__("mov %0, r12":"=r"(j));
  130. __asm__ __volatile__("mov %0, r0":"=r"(i));
  131. /*
  132. * GP Device ROM code API usage here
  133. * r12 = AUXCR Write function and r0 value
  134. */
  135. __asm__ __volatile__("mov r12, #0x3");
  136. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  137. __asm__ __volatile__("orr r0, r0, #0x2");
  138. /* SMI instruction to call ROM Code API */
  139. __asm__ __volatile__(".word 0xE1600070");
  140. __asm__ __volatile__("mov r0, %0":"=r"(i));
  141. __asm__ __volatile__("mov r12, %0":"=r"(j));
  142. }
  143. }
  144. void l2cache_disable()
  145. {
  146. unsigned long i;
  147. volatile unsigned int j;
  148. /* ES2 onwards we can disable/enable L2 ourselves */
  149. if (get_cpu_rev() == CPU_3430_ES2) {
  150. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  151. __asm__ __volatile__("bic %0, %0, #0x2":"=r"(i));
  152. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  153. } else {
  154. /* Save r0, r12 and restore them after usage */
  155. __asm__ __volatile__("mov %0, r12":"=r"(j));
  156. __asm__ __volatile__("mov %0, r0":"=r"(i));
  157. /*
  158. * GP Device ROM code API usage here
  159. * r12 = AUXCR Write function and r0 value
  160. */
  161. __asm__ __volatile__("mov r12, #0x3");
  162. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  163. __asm__ __volatile__("bic r0, r0, #0x2");
  164. /* SMI instruction to call ROM Code API */
  165. __asm__ __volatile__(".word 0xE1600070");
  166. __asm__ __volatile__("mov r0, %0":"=r"(i));
  167. __asm__ __volatile__("mov r12, %0":"=r"(j));
  168. }
  169. }
  170. int icache_status(void)
  171. {
  172. return (get_cr() & CR_I) != 0;
  173. }
  174. static void cache_flush(void)
  175. {
  176. asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
  177. }