blob: 1fdaa32bb087c251b11e54f1ae4fa46af321622e [file] [log] [blame]
Xiangfu Liu2f46d422011-10-12 12:24:06 +08001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4 * (C) Copyright 2011
5 * Xiangfu Liu <xiangfu@openmobilefree.net>
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Xiangfu Liu2f46d422011-10-12 12:24:06 +08008 */
9
10#include <common.h>
11#include <command.h>
12#include <netdev.h>
13#include <asm/mipsregs.h>
14#include <asm/cacheops.h>
15#include <asm/reboot.h>
16#include <asm/io.h>
17#include <asm/jz4740.h>
18
19#define cache_op(op, addr) \
20 __asm__ __volatile__( \
21 ".set push\n" \
22 ".set noreorder\n" \
23 ".set mips3\n" \
24 "cache %0, %1\n" \
25 ".set pop\n" \
26 : \
27 : "i" (op), "R" (*(unsigned char *)(addr)))
28
29void __attribute__((weak)) _machine_restart(void)
30{
31 struct jz4740_wdt *wdt = (struct jz4740_wdt *)JZ4740_WDT_BASE;
32 struct jz4740_tcu *tcu = (struct jz4740_tcu *)JZ4740_TCU_BASE;
33 u16 tmp;
34
35 /* wdt_select_extalclk() */
36 tmp = readw(&wdt->tcsr);
37 tmp &= ~(WDT_TCSR_EXT_EN | WDT_TCSR_RTC_EN | WDT_TCSR_PCK_EN);
38 tmp |= WDT_TCSR_EXT_EN;
39 writew(tmp, &wdt->tcsr);
40
41 /* wdt_select_clk_div64() */
42 tmp = readw(&wdt->tcsr);
43 tmp &= ~WDT_TCSR_PRESCALE_MASK;
44 tmp |= WDT_TCSR_PRESCALE64,
45 writew(tmp, &wdt->tcsr);
46
47 writew(100, &wdt->tdr); /* wdt_set_data(100) */
48 writew(0, &wdt->tcnt); /* wdt_set_count(0); */
Marek Vasut309c07c2012-08-12 16:53:35 +020049 writel(TCU_TSSR_WDTSC, &tcu->tscr); /* tcu_start_wdt_clock */
Xiangfu Liu2f46d422011-10-12 12:24:06 +080050 writeb(readb(&wdt->tcer) | WDT_TCER_TCEN, &wdt->tcer); /* wdt start */
51
52 while (1)
53 ;
54}
55
56int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
57{
58 _machine_restart();
59
60 fprintf(stderr, "*** reset failed ***\n");
61 return 0;
62}
63
64void flush_cache(ulong start_addr, ulong size)
65{
66 unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
67 unsigned long addr = start_addr & ~(lsize - 1);
68 unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
69
70 for (; addr <= aend; addr += lsize) {
Zhi-zhou Zhang724f6182012-10-16 15:02:08 +020071 cache_op(HIT_WRITEBACK_INV_D, addr);
72 cache_op(HIT_INVALIDATE_I, addr);
Xiangfu Liu2f46d422011-10-12 12:24:06 +080073 }
74}
75
76void flush_dcache_range(ulong start_addr, ulong stop)
77{
78 unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
79 unsigned long addr = start_addr & ~(lsize - 1);
80 unsigned long aend = (stop - 1) & ~(lsize - 1);
81
82 for (; addr <= aend; addr += lsize)
Zhi-zhou Zhang724f6182012-10-16 15:02:08 +020083 cache_op(HIT_WRITEBACK_INV_D, addr);
Xiangfu Liu2f46d422011-10-12 12:24:06 +080084}
85
86void invalidate_dcache_range(ulong start_addr, ulong stop)
87{
88 unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
89 unsigned long addr = start_addr & ~(lsize - 1);
90 unsigned long aend = (stop - 1) & ~(lsize - 1);
91
92 for (; addr <= aend; addr += lsize)
Zhi-zhou Zhang724f6182012-10-16 15:02:08 +020093 cache_op(HIT_INVALIDATE_D, addr);
Xiangfu Liu2f46d422011-10-12 12:24:06 +080094}
95
96void flush_icache_all(void)
97{
98 u32 addr, t = 0;
99
100 __asm__ __volatile__("mtc0 $0, $28"); /* Clear Taglo */
101 __asm__ __volatile__("mtc0 $0, $29"); /* Clear TagHi */
102
103 for (addr = CKSEG0; addr < CKSEG0 + CONFIG_SYS_ICACHE_SIZE;
104 addr += CONFIG_SYS_CACHELINE_SIZE) {
Zhi-zhou Zhang724f6182012-10-16 15:02:08 +0200105 cache_op(INDEX_STORE_TAG_I, addr);
Xiangfu Liu2f46d422011-10-12 12:24:06 +0800106 }
107
108 /* invalidate btb */
109 __asm__ __volatile__(
110 ".set mips32\n\t"
111 "mfc0 %0, $16, 7\n\t"
112 "nop\n\t"
113 "ori %0,2\n\t"
114 "mtc0 %0, $16, 7\n\t"
115 ".set mips2\n\t"
116 :
117 : "r" (t));
118}
119
120void flush_dcache_all(void)
121{
122 u32 addr;
123
124 for (addr = CKSEG0; addr < CKSEG0 + CONFIG_SYS_DCACHE_SIZE;
125 addr += CONFIG_SYS_CACHELINE_SIZE) {
Zhi-zhou Zhang724f6182012-10-16 15:02:08 +0200126 cache_op(INDEX_WRITEBACK_INV_D, addr);
Xiangfu Liu2f46d422011-10-12 12:24:06 +0800127 }
128
129 __asm__ __volatile__("sync");
130}
131
132void flush_cache_all(void)
133{
134 flush_dcache_all();
135 flush_icache_all();
136}