cpu.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. int cpu_init(void)
  44. {
  45. /*
  46. * setup up stacks if necessary
  47. */
  48. #ifdef CONFIG_USE_IRQ
  49. IRQ_STACK_START =
  50. _armboot_start - CONFIG_SYS_MALLOC_LEN - CONFIG_SYS_GBL_DATA_SIZE - 4;
  51. FIQ_STACK_START = IRQ_STACK_START - CONFIG_STACKSIZE_IRQ;
  52. #endif
  53. return 0;
  54. }
  55. int cleanup_before_linux(void)
  56. {
  57. unsigned int i;
  58. /*
  59. * this function is called just before we call linux
  60. * it prepares the processor for linux
  61. *
  62. * we turn off caches etc ...
  63. */
  64. disable_interrupts();
  65. /* turn off I/D-cache */
  66. icache_disable();
  67. dcache_disable();
  68. /* invalidate I-cache */
  69. cache_flush();
  70. #ifndef CONFIG_L2_OFF
  71. /* turn off L2 cache */
  72. l2cache_disable();
  73. /* invalidate L2 cache also */
  74. v7_flush_dcache_all(get_device_type());
  75. #endif
  76. i = 0;
  77. /* mem barrier to sync up things */
  78. asm("mcr p15, 0, %0, c7, c10, 4": :"r"(i));
  79. #ifndef CONFIG_L2_OFF
  80. l2cache_enable();
  81. #endif
  82. return 0;
  83. }
  84. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  85. {
  86. disable_interrupts();
  87. reset_cpu(0);
  88. /* NOTREACHED */
  89. return 0;
  90. }
  91. void l2cache_enable()
  92. {
  93. unsigned long i;
  94. volatile unsigned int j;
  95. /* ES2 onwards we can disable/enable L2 ourselves */
  96. if (get_cpu_rev() == CPU_3430_ES2) {
  97. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  98. __asm__ __volatile__("orr %0, %0, #0x2":"=r"(i));
  99. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  100. } else {
  101. /* Save r0, r12 and restore them after usage */
  102. __asm__ __volatile__("mov %0, r12":"=r"(j));
  103. __asm__ __volatile__("mov %0, r0":"=r"(i));
  104. /*
  105. * GP Device ROM code API usage here
  106. * r12 = AUXCR Write function and r0 value
  107. */
  108. __asm__ __volatile__("mov r12, #0x3");
  109. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  110. __asm__ __volatile__("orr r0, r0, #0x2");
  111. /* SMI instruction to call ROM Code API */
  112. __asm__ __volatile__(".word 0xE1600070");
  113. __asm__ __volatile__("mov r0, %0":"=r"(i));
  114. __asm__ __volatile__("mov r12, %0":"=r"(j));
  115. }
  116. }
  117. void l2cache_disable()
  118. {
  119. unsigned long i;
  120. volatile unsigned int j;
  121. /* ES2 onwards we can disable/enable L2 ourselves */
  122. if (get_cpu_rev() == CPU_3430_ES2) {
  123. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  124. __asm__ __volatile__("bic %0, %0, #0x2":"=r"(i));
  125. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  126. } else {
  127. /* Save r0, r12 and restore them after usage */
  128. __asm__ __volatile__("mov %0, r12":"=r"(j));
  129. __asm__ __volatile__("mov %0, r0":"=r"(i));
  130. /*
  131. * GP Device ROM code API usage here
  132. * r12 = AUXCR Write function and r0 value
  133. */
  134. __asm__ __volatile__("mov r12, #0x3");
  135. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  136. __asm__ __volatile__("bic r0, r0, #0x2");
  137. /* SMI instruction to call ROM Code API */
  138. __asm__ __volatile__(".word 0xE1600070");
  139. __asm__ __volatile__("mov r0, %0":"=r"(i));
  140. __asm__ __volatile__("mov r12, %0":"=r"(j));
  141. }
  142. }
  143. static void cache_flush(void)
  144. {
  145. asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
  146. }