1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2015 Freescale Semiconductor, Inc.
11 #include <asm/mach-imx/sys_proto.h>
13 static void enable_ca7_smp(void)
18 asm volatile ("mrc p15, 0, %0, c0, c0, 0\n\t" : "=r"(val));
22 /* Only set the SMP for Cortex A7 */
24 /* Read auxiliary control register */
25 asm volatile ("mrc p15, 0, %0, c1, c0, 1\n\t" : "=r"(val));
33 /* Write auxiliary control register */
34 asm volatile ("mcr p15, 0, %0, c1, c0, 1\n\t" : : "r"(val));
41 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
42 void enable_caches(void)
44 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
45 enum dcache_option option = DCACHE_WRITETHROUGH;
47 enum dcache_option option = DCACHE_WRITEBACK;
49 /* Avoid random hang when download by usb */
50 invalidate_dcache_all();
52 /* Set ACTLR.SMP bit for Cortex-A7 */
55 /* Enable D-cache. I-cache is already enabled in start.S */
58 /* Enable caching on OCRAM and ROM */
59 mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
62 mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
67 void enable_caches(void)
70 * Set ACTLR.SMP bit for Cortex-A7, even if the caches are
75 puts("WARNING: Caches not enabled\n");
79 #ifndef CONFIG_SYS_L2CACHE_OFF
80 #ifdef CONFIG_SYS_L2_PL310
81 #define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
82 void v7_outer_cache_enable(void)
84 struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
85 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
86 unsigned int val, cache_id;
90 * Must disable the L2 before changing the latency parameters
91 * and auxiliary control register.
93 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
96 * Set bit 22 in the auxiliary control register. If this bit
97 * is cleared, PL310 treats Normal Shared Non-cacheable
98 * accesses as Cacheable no-allocate.
100 setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
102 if (is_mx6sl() || is_mx6sll()) {
103 val = readl(&iomux->gpr[11]);
104 if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
105 /* L2 cache configured as OCRAM, reset it */
106 val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
107 writel(val, &iomux->gpr[11]);
111 writel(0x132, &pl310->pl310_tag_latency_ctrl);
112 writel(0x132, &pl310->pl310_data_latency_ctrl);
114 val = readl(&pl310->pl310_prefetch_ctrl);
116 /* Turn on the L2 I/D prefetch, double linefill */
117 /* Set prefetch offset with any value except 23 as per errata 765569 */
121 * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
122 * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL/SX/DQP
124 * But according to ARM PL310 errata: 752271
125 * ID: 752271: Double linefill feature can cause data corruption
126 * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
127 * Workaround: The only workaround to this erratum is to disable the
128 * double linefill feature. This is the default behavior.
130 cache_id = readl(&pl310->pl310_cache_id);
131 if (((cache_id & L2X0_CACHE_ID_PART_MASK) == L2X0_CACHE_ID_PART_L310)
132 && ((cache_id & L2X0_CACHE_ID_RTL_MASK) < L2X0_CACHE_ID_RTL_R3P2))
134 writel(val, &pl310->pl310_prefetch_ctrl);
136 val = readl(&pl310->pl310_power_ctrl);
137 val |= L2X0_DYNAMIC_CLK_GATING_EN;
138 val |= L2X0_STNDBY_MODE_EN;
139 writel(val, &pl310->pl310_power_ctrl);
141 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
144 void v7_outer_cache_disable(void)
146 struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
148 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
150 #endif /* !CONFIG_SYS_L2_PL310 */
151 #endif /* !CONFIG_SYS_L2CACHE_OFF */