cpu.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
  4. * (C) Copyright 2011
  5. * Xiangfu Liu <xiangfu@openmobilefree.net>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <netdev.h>
  28. #include <asm/mipsregs.h>
  29. #include <asm/cacheops.h>
  30. #include <asm/reboot.h>
  31. #include <asm/io.h>
  32. #include <asm/jz4740.h>
  33. #define cache_op(op, addr) \
  34. __asm__ __volatile__( \
  35. ".set push\n" \
  36. ".set noreorder\n" \
  37. ".set mips3\n" \
  38. "cache %0, %1\n" \
  39. ".set pop\n" \
  40. : \
  41. : "i" (op), "R" (*(unsigned char *)(addr)))
  42. void __attribute__((weak)) _machine_restart(void)
  43. {
  44. struct jz4740_wdt *wdt = (struct jz4740_wdt *)JZ4740_WDT_BASE;
  45. struct jz4740_tcu *tcu = (struct jz4740_tcu *)JZ4740_TCU_BASE;
  46. u16 tmp;
  47. /* wdt_select_extalclk() */
  48. tmp = readw(&wdt->tcsr);
  49. tmp &= ~(WDT_TCSR_EXT_EN | WDT_TCSR_RTC_EN | WDT_TCSR_PCK_EN);
  50. tmp |= WDT_TCSR_EXT_EN;
  51. writew(tmp, &wdt->tcsr);
  52. /* wdt_select_clk_div64() */
  53. tmp = readw(&wdt->tcsr);
  54. tmp &= ~WDT_TCSR_PRESCALE_MASK;
  55. tmp |= WDT_TCSR_PRESCALE64,
  56. writew(tmp, &wdt->tcsr);
  57. writew(100, &wdt->tdr); /* wdt_set_data(100) */
  58. writew(0, &wdt->tcnt); /* wdt_set_count(0); */
  59. writew(TCU_TSSR_WDTSC, &tcu->tscr); /* tcu_start_wdt_clock */
  60. writeb(readb(&wdt->tcer) | WDT_TCER_TCEN, &wdt->tcer); /* wdt start */
  61. while (1)
  62. ;
  63. }
  64. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  65. {
  66. _machine_restart();
  67. fprintf(stderr, "*** reset failed ***\n");
  68. return 0;
  69. }
  70. void flush_cache(ulong start_addr, ulong size)
  71. {
  72. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  73. unsigned long addr = start_addr & ~(lsize - 1);
  74. unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
  75. for (; addr <= aend; addr += lsize) {
  76. cache_op(Hit_Writeback_Inv_D, addr);
  77. cache_op(Hit_Invalidate_I, addr);
  78. }
  79. }
  80. void flush_dcache_range(ulong start_addr, ulong stop)
  81. {
  82. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  83. unsigned long addr = start_addr & ~(lsize - 1);
  84. unsigned long aend = (stop - 1) & ~(lsize - 1);
  85. for (; addr <= aend; addr += lsize)
  86. cache_op(Hit_Writeback_Inv_D, addr);
  87. }
  88. void invalidate_dcache_range(ulong start_addr, ulong stop)
  89. {
  90. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  91. unsigned long addr = start_addr & ~(lsize - 1);
  92. unsigned long aend = (stop - 1) & ~(lsize - 1);
  93. for (; addr <= aend; addr += lsize)
  94. cache_op(Hit_Invalidate_D, addr);
  95. }
  96. void flush_icache_all(void)
  97. {
  98. u32 addr, t = 0;
  99. __asm__ __volatile__("mtc0 $0, $28"); /* Clear Taglo */
  100. __asm__ __volatile__("mtc0 $0, $29"); /* Clear TagHi */
  101. for (addr = CKSEG0; addr < CKSEG0 + CONFIG_SYS_ICACHE_SIZE;
  102. addr += CONFIG_SYS_CACHELINE_SIZE) {
  103. cache_op(Index_Store_Tag_I, addr);
  104. }
  105. /* invalidate btb */
  106. __asm__ __volatile__(
  107. ".set mips32\n\t"
  108. "mfc0 %0, $16, 7\n\t"
  109. "nop\n\t"
  110. "ori %0,2\n\t"
  111. "mtc0 %0, $16, 7\n\t"
  112. ".set mips2\n\t"
  113. :
  114. : "r" (t));
  115. }
  116. void flush_dcache_all(void)
  117. {
  118. u32 addr;
  119. for (addr = CKSEG0; addr < CKSEG0 + CONFIG_SYS_DCACHE_SIZE;
  120. addr += CONFIG_SYS_CACHELINE_SIZE) {
  121. cache_op(Index_Writeback_Inv_D, addr);
  122. }
  123. __asm__ __volatile__("sync");
  124. }
  125. void flush_cache_all(void)
  126. {
  127. flush_dcache_all();
  128. flush_icache_all();
  129. }