cpu.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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, <garyj@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. #ifndef CONFIG_L2_OFF
  37. void l2cache_disable(void);
  38. #endif
  39. static void cache_flush(void);
  40. int cpu_init(void)
  41. {
  42. return 0;
  43. }
  44. int cleanup_before_linux(void)
  45. {
  46. unsigned int i;
  47. /*
  48. * this function is called just before we call linux
  49. * it prepares the processor for linux
  50. *
  51. * we turn off caches etc ...
  52. */
  53. disable_interrupts();
  54. /* turn off I/D-cache */
  55. icache_disable();
  56. dcache_disable();
  57. /* invalidate I-cache */
  58. cache_flush();
  59. #ifndef CONFIG_L2_OFF
  60. /* turn off L2 cache */
  61. l2cache_disable();
  62. /* invalidate L2 cache also */
  63. v7_flush_dcache_all(get_device_type());
  64. #endif
  65. i = 0;
  66. /* mem barrier to sync up things */
  67. asm("mcr p15, 0, %0, c7, c10, 4": :"r"(i));
  68. #ifndef CONFIG_L2_OFF
  69. l2cache_enable();
  70. #endif
  71. return 0;
  72. }
  73. void l2cache_enable()
  74. {
  75. unsigned long i;
  76. volatile unsigned int j;
  77. /* ES2 onwards we can disable/enable L2 ourselves */
  78. if (get_cpu_rev() >= CPU_3XX_ES20) {
  79. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  80. __asm__ __volatile__("orr %0, %0, #0x2":"=r"(i));
  81. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  82. } else {
  83. /* Save r0, r12 and restore them after usage */
  84. __asm__ __volatile__("mov %0, r12":"=r"(j));
  85. __asm__ __volatile__("mov %0, r0":"=r"(i));
  86. /*
  87. * GP Device ROM code API usage here
  88. * r12 = AUXCR Write function and r0 value
  89. */
  90. __asm__ __volatile__("mov r12, #0x3");
  91. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  92. __asm__ __volatile__("orr r0, r0, #0x2");
  93. /* SMI instruction to call ROM Code API */
  94. __asm__ __volatile__(".word 0xE1600070");
  95. __asm__ __volatile__("mov r0, %0":"=r"(i));
  96. __asm__ __volatile__("mov r12, %0":"=r"(j));
  97. }
  98. }
  99. void l2cache_disable()
  100. {
  101. unsigned long i;
  102. volatile unsigned int j;
  103. /* ES2 onwards we can disable/enable L2 ourselves */
  104. if (get_cpu_rev() >= CPU_3XX_ES20) {
  105. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  106. __asm__ __volatile__("bic %0, %0, #0x2":"=r"(i));
  107. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  108. } else {
  109. /* Save r0, r12 and restore them after usage */
  110. __asm__ __volatile__("mov %0, r12":"=r"(j));
  111. __asm__ __volatile__("mov %0, r0":"=r"(i));
  112. /*
  113. * GP Device ROM code API usage here
  114. * r12 = AUXCR Write function and r0 value
  115. */
  116. __asm__ __volatile__("mov r12, #0x3");
  117. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  118. __asm__ __volatile__("bic r0, r0, #0x2");
  119. /* SMI instruction to call ROM Code API */
  120. __asm__ __volatile__(".word 0xE1600070");
  121. __asm__ __volatile__("mov r0, %0":"=r"(i));
  122. __asm__ __volatile__("mov r12, %0":"=r"(j));
  123. }
  124. }
  125. static void cache_flush(void)
  126. {
  127. asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
  128. }