blob: a60594250335289bc26a401fbe6b6dc377f86a5c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Adrian Alonso74094512015-09-02 13:54:14 -05002/*
3 * Copyright 2015 Freescale Semiconductor, Inc.
Adrian Alonso74094512015-09-02 13:54:14 -05004 */
5
6#include <common.h>
7#include <asm/armv7.h>
8#include <asm/pl310.h>
9#include <asm/io.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020010#include <asm/mach-imx/sys_proto.h>
Adrian Alonso74094512015-09-02 13:54:14 -050011
Ye Li73265002018-05-14 09:44:29 -030012static void enable_ca7_smp(void)
13{
14 u32 val;
15
16 /* Read MIDR */
17 asm volatile ("mrc p15, 0, %0, c0, c0, 0\n\t" : "=r"(val));
18 val = (val >> 4);
19 val &= 0xf;
20
21 /* Only set the SMP for Cortex A7 */
22 if (val == 0x7) {
23 /* Read auxiliary control register */
24 asm volatile ("mrc p15, 0, %0, c1, c0, 1\n\t" : "=r"(val));
25
26 if (val & (1 << 6))
27 return;
28
29 /* Enable SMP */
30 val |= (1 << 6);
31
32 /* Write auxiliary control register */
33 asm volatile ("mcr p15, 0, %0, c1, c0, 1\n\t" : : "r"(val));
34
35 DSB;
36 ISB;
37 }
38}
39
Trevor Woerner43ec7e02019-05-03 09:41:00 -040040#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Adrian Alonso74094512015-09-02 13:54:14 -050041void enable_caches(void)
42{
43#if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
44 enum dcache_option option = DCACHE_WRITETHROUGH;
45#else
46 enum dcache_option option = DCACHE_WRITEBACK;
47#endif
48 /* Avoid random hang when download by usb */
49 invalidate_dcache_all();
50
Ye Li73265002018-05-14 09:44:29 -030051 /* Set ACTLR.SMP bit for Cortex-A7 */
52 enable_ca7_smp();
53
Adrian Alonso74094512015-09-02 13:54:14 -050054 /* Enable D-cache. I-cache is already enabled in start.S */
55 dcache_enable();
56
57 /* Enable caching on OCRAM and ROM */
58 mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
59 ROMCP_ARB_END_ADDR,
60 option);
61 mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
62 IRAM_SIZE,
63 option);
64}
Ye Li73265002018-05-14 09:44:29 -030065#else
66void enable_caches(void)
67{
68 /*
69 * Set ACTLR.SMP bit for Cortex-A7, even if the caches are
70 * disabled by u-boot
71 */
72 enable_ca7_smp();
73
74 puts("WARNING: Caches not enabled\n");
75}
Adrian Alonso74094512015-09-02 13:54:14 -050076#endif
77
78#ifndef CONFIG_SYS_L2CACHE_OFF
79#ifdef CONFIG_SYS_L2_PL310
80#define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
81void v7_outer_cache_enable(void)
82{
83 struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
Peng Fan9ace3de2016-12-11 19:24:30 +080084 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Ye Lida8485b2019-01-07 09:29:21 +000085 unsigned int val, cache_id;
Adrian Alonso74094512015-09-02 13:54:14 -050086
87
88 /*
Peng Fan36e9ac92016-05-04 15:27:50 +080089 * Must disable the L2 before changing the latency parameters
90 * and auxiliary control register.
91 */
92 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
93
94 /*
Adrian Alonso74094512015-09-02 13:54:14 -050095 * Set bit 22 in the auxiliary control register. If this bit
96 * is cleared, PL310 treats Normal Shared Non-cacheable
97 * accesses as Cacheable no-allocate.
98 */
99 setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
100
Peng Fan9ace3de2016-12-11 19:24:30 +0800101 if (is_mx6sl() || is_mx6sll()) {
102 val = readl(&iomux->gpr[11]);
103 if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
104 /* L2 cache configured as OCRAM, reset it */
105 val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
106 writel(val, &iomux->gpr[11]);
107 }
Adrian Alonso74094512015-09-02 13:54:14 -0500108 }
Adrian Alonso74094512015-09-02 13:54:14 -0500109
Adrian Alonso74094512015-09-02 13:54:14 -0500110 writel(0x132, &pl310->pl310_tag_latency_ctrl);
111 writel(0x132, &pl310->pl310_data_latency_ctrl);
112
113 val = readl(&pl310->pl310_prefetch_ctrl);
114
Ye Lida8485b2019-01-07 09:29:21 +0000115 /* Turn on the L2 I/D prefetch, double linefill */
116 /* Set prefetch offset with any value except 23 as per errata 765569 */
117 val |= 0x7000000f;
Adrian Alonso74094512015-09-02 13:54:14 -0500118
119 /*
120 * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
Ye Lida8485b2019-01-07 09:29:21 +0000121 * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL/SX/DQP
122 * is r3p2.
Adrian Alonso74094512015-09-02 13:54:14 -0500123 * But according to ARM PL310 errata: 752271
124 * ID: 752271: Double linefill feature can cause data corruption
125 * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
126 * Workaround: The only workaround to this erratum is to disable the
127 * double linefill feature. This is the default behavior.
128 */
Ye Lida8485b2019-01-07 09:29:21 +0000129 cache_id = readl(&pl310->pl310_cache_id);
130 if (((cache_id & L2X0_CACHE_ID_PART_MASK) == L2X0_CACHE_ID_PART_L310)
131 && ((cache_id & L2X0_CACHE_ID_RTL_MASK) < L2X0_CACHE_ID_RTL_R3P2))
132 val &= ~(1 << 30);
Adrian Alonso74094512015-09-02 13:54:14 -0500133 writel(val, &pl310->pl310_prefetch_ctrl);
134
135 val = readl(&pl310->pl310_power_ctrl);
136 val |= L2X0_DYNAMIC_CLK_GATING_EN;
137 val |= L2X0_STNDBY_MODE_EN;
138 writel(val, &pl310->pl310_power_ctrl);
139
140 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
141}
142
143void v7_outer_cache_disable(void)
144{
145 struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
146
147 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
148}
149#endif /* !CONFIG_SYS_L2_PL310 */
150#endif /* !CONFIG_SYS_L2CACHE_OFF */