cpu.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. void l2cache_enable()
  85. {
  86. unsigned long i;
  87. volatile unsigned int j;
  88. /* ES2 onwards we can disable/enable L2 ourselves */
  89. if (get_cpu_rev() == CPU_3430_ES2) {
  90. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  91. __asm__ __volatile__("orr %0, %0, #0x2":"=r"(i));
  92. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  93. } else {
  94. /* Save r0, r12 and restore them after usage */
  95. __asm__ __volatile__("mov %0, r12":"=r"(j));
  96. __asm__ __volatile__("mov %0, r0":"=r"(i));
  97. /*
  98. * GP Device ROM code API usage here
  99. * r12 = AUXCR Write function and r0 value
  100. */
  101. __asm__ __volatile__("mov r12, #0x3");
  102. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  103. __asm__ __volatile__("orr r0, r0, #0x2");
  104. /* SMI instruction to call ROM Code API */
  105. __asm__ __volatile__(".word 0xE1600070");
  106. __asm__ __volatile__("mov r0, %0":"=r"(i));
  107. __asm__ __volatile__("mov r12, %0":"=r"(j));
  108. }
  109. }
  110. void l2cache_disable()
  111. {
  112. unsigned long i;
  113. volatile unsigned int j;
  114. /* ES2 onwards we can disable/enable L2 ourselves */
  115. if (get_cpu_rev() == CPU_3430_ES2) {
  116. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  117. __asm__ __volatile__("bic %0, %0, #0x2":"=r"(i));
  118. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  119. } else {
  120. /* Save r0, r12 and restore them after usage */
  121. __asm__ __volatile__("mov %0, r12":"=r"(j));
  122. __asm__ __volatile__("mov %0, r0":"=r"(i));
  123. /*
  124. * GP Device ROM code API usage here
  125. * r12 = AUXCR Write function and r0 value
  126. */
  127. __asm__ __volatile__("mov r12, #0x3");
  128. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  129. __asm__ __volatile__("bic r0, r0, #0x2");
  130. /* SMI instruction to call ROM Code API */
  131. __asm__ __volatile__(".word 0xE1600070");
  132. __asm__ __volatile__("mov r0, %0":"=r"(i));
  133. __asm__ __volatile__("mov r12, %0":"=r"(j));
  134. }
  135. }
  136. static void cache_flush(void)
  137. {
  138. asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
  139. }