blob: 4ebbd78db3a4e8cff1a3c265a79afd62f387c1c8 [file] [log] [blame]
Mike Frysinger3c1fbd52008-11-18 17:48:22 +08001/*
2 * Blackfin cache control code (simpler control-style functions)
3 *
Mike Frysingerea426e62009-09-14 19:42:26 +00004 * Copyright 2004-2009 Analog Devices Inc.
Mike Frysinger3c1fbd52008-11-18 17:48:22 +08005 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
Mike Frysingerea426e62009-09-14 19:42:26 +000011#include <linux/init.h>
Mike Frysinger3c1fbd52008-11-18 17:48:22 +080012#include <asm/blackfin.h>
Mike Frysingerea426e62009-09-14 19:42:26 +000013#include <asm/cplbinit.h>
Mike Frysinger3c1fbd52008-11-18 17:48:22 +080014
15/* Invalidate the Entire Data cache by
16 * clearing DMC[1:0] bits
17 */
18void blackfin_invalidate_entire_dcache(void)
19{
20 u32 dmem = bfin_read_DMEM_CONTROL();
Mike Frysinger3c1fbd52008-11-18 17:48:22 +080021 bfin_write_DMEM_CONTROL(dmem & ~0xc);
22 SSYNC();
23 bfin_write_DMEM_CONTROL(dmem);
24 SSYNC();
25}
Sonic Zhang47e9ded2009-06-10 08:57:08 +000026
27/* Invalidate the Entire Instruction cache by
28 * clearing IMC bit
29 */
30void blackfin_invalidate_entire_icache(void)
31{
32 u32 imem = bfin_read_IMEM_CONTROL();
33 bfin_write_IMEM_CONTROL(imem & ~0x4);
34 SSYNC();
35 bfin_write_IMEM_CONTROL(imem);
36 SSYNC();
37}
38
Mike Frysingerea426e62009-09-14 19:42:26 +000039#if defined(CONFIG_BFIN_ICACHE) || defined(CONFIG_BFIN_DCACHE)
40
41static void
42bfin_cache_init(struct cplb_entry *cplb_tbl, unsigned long cplb_addr,
43 unsigned long cplb_data, unsigned long mem_control,
44 unsigned long mem_mask)
45{
46 int i;
47
48 for (i = 0; i < MAX_CPLBS; i++) {
49 bfin_write32(cplb_addr + i * 4, cplb_tbl[i].addr);
50 bfin_write32(cplb_data + i * 4, cplb_tbl[i].data);
51 }
52
53 _enable_cplb(mem_control, mem_mask);
54}
55
56#ifdef CONFIG_BFIN_ICACHE
57void __cpuinit bfin_icache_init(struct cplb_entry *icplb_tbl)
58{
59 bfin_cache_init(icplb_tbl, ICPLB_ADDR0, ICPLB_DATA0, IMEM_CONTROL,
60 (IMC | ENICPLB));
61}
62#endif
63
64#ifdef CONFIG_BFIN_DCACHE
65void __cpuinit bfin_dcache_init(struct cplb_entry *dcplb_tbl)
66{
67 /*
68 * Anomaly notes:
69 * 05000287 - We implement workaround #2 - Change the DMEM_CONTROL
70 * register, so that the port preferences for DAG0 and DAG1 are set
71 * to port B
72 */
73 bfin_cache_init(dcplb_tbl, DCPLB_ADDR0, DCPLB_DATA0, DMEM_CONTROL,
74 (DMEM_CNTR | PORT_PREF0 | (ANOMALY_05000287 ? PORT_PREF1 : 0)));
75}
76#endif
77
78#endif