Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 8 | */ |
| 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 | |
| 29 | void __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 Vasut | 309c07c | 2012-08-12 16:53:35 +0200 | [diff] [blame] | 49 | writel(TCU_TSSR_WDTSC, &tcu->tscr); /* tcu_start_wdt_clock */ |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 50 | writeb(readb(&wdt->tcer) | WDT_TCER_TCEN, &wdt->tcer); /* wdt start */ |
| 51 | |
| 52 | while (1) |
| 53 | ; |
| 54 | } |
| 55 | |
| 56 | int 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 | |
| 64 | void 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 Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 71 | cache_op(HIT_WRITEBACK_INV_D, addr); |
| 72 | cache_op(HIT_INVALIDATE_I, addr); |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | void 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 Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 83 | cache_op(HIT_WRITEBACK_INV_D, addr); |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void 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 Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 93 | cache_op(HIT_INVALIDATE_D, addr); |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void 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 Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 105 | cache_op(INDEX_STORE_TAG_I, addr); |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 106 | } |
| 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 | |
| 120 | void 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 Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 126 | cache_op(INDEX_WRITEBACK_INV_D, addr); |
Xiangfu Liu | 2f46d42 | 2011-10-12 12:24:06 +0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | __asm__ __volatile__("sync"); |
| 130 | } |
| 131 | |
| 132 | void flush_cache_all(void) |
| 133 | { |
| 134 | flush_dcache_all(); |
| 135 | flush_icache_all(); |
| 136 | } |