xref: /freebsd/sys/arm/mv/armadaxp/armadaxp.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
116694521SOleksandr Tymoshenko /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3af3dc4a7SPedro F. Giffuni  *
416694521SOleksandr Tymoshenko  * Copyright (c) 2011 Semihalf.
516694521SOleksandr Tymoshenko  * All rights reserved.
616694521SOleksandr Tymoshenko  *
716694521SOleksandr Tymoshenko  * Redistribution and use in source and binary forms, with or without
816694521SOleksandr Tymoshenko  * modification, are permitted provided that the following conditions
916694521SOleksandr Tymoshenko  * are met:
1016694521SOleksandr Tymoshenko  * 1. Redistributions of source code must retain the above copyright
1116694521SOleksandr Tymoshenko  *    notice, this list of conditions and the following disclaimer.
1216694521SOleksandr Tymoshenko  * 2. Redistributions in binary form must reproduce the above copyright
1316694521SOleksandr Tymoshenko  *    notice, this list of conditions and the following disclaimer in the
1416694521SOleksandr Tymoshenko  *    documentation and/or other materials provided with the distribution.
1516694521SOleksandr Tymoshenko  *
1616694521SOleksandr Tymoshenko  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1716694521SOleksandr Tymoshenko  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1816694521SOleksandr Tymoshenko  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1916694521SOleksandr Tymoshenko  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2016694521SOleksandr Tymoshenko  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2116694521SOleksandr Tymoshenko  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2216694521SOleksandr Tymoshenko  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2316694521SOleksandr Tymoshenko  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2416694521SOleksandr Tymoshenko  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2516694521SOleksandr Tymoshenko  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2616694521SOleksandr Tymoshenko  * SUCH DAMAGE.
2716694521SOleksandr Tymoshenko  *
2816694521SOleksandr Tymoshenko  * From: FreeBSD: src/sys/arm/mv/kirkwood/sheevaplug.c,v 1.2 2010/06/13 13:28:53
2916694521SOleksandr Tymoshenko  */
3016694521SOleksandr Tymoshenko 
3116694521SOleksandr Tymoshenko #include <sys/param.h>
3216694521SOleksandr Tymoshenko #include <sys/systm.h>
3316694521SOleksandr Tymoshenko #include <sys/bus.h>
3416694521SOleksandr Tymoshenko 
35d65cdf4bSGrzegorz Bernacki #include <machine/armreg.h>
36cb5ce014SAndrew Turner #include <machine/bus.h>
37cb5ce014SAndrew Turner #include <machine/cpu.h>
3816694521SOleksandr Tymoshenko 
393a1f2172SGrzegorz Bernacki #include <arm/mv/mvwin.h>
4016694521SOleksandr Tymoshenko #include <arm/mv/mvreg.h>
4116694521SOleksandr Tymoshenko #include <arm/mv/mvvar.h>
4216694521SOleksandr Tymoshenko 
4316694521SOleksandr Tymoshenko #include <dev/ofw/openfirm.h>
4416694521SOleksandr Tymoshenko 
4516694521SOleksandr Tymoshenko #include <machine/fdt.h>
4616694521SOleksandr Tymoshenko 
47d65cdf4bSGrzegorz Bernacki #define CPU_FREQ_FIELD(sar)	(((0x01 & (sar >> 52)) << 3) | \
48d65cdf4bSGrzegorz Bernacki 				    (0x07 & (sar >> 21)))
49d65cdf4bSGrzegorz Bernacki #define FAB_FREQ_FIELD(sar)	(((0x01 & (sar >> 51)) << 4) | \
50d65cdf4bSGrzegorz Bernacki 				    (0x0F & (sar >> 24)))
51d65cdf4bSGrzegorz Bernacki 
52d65cdf4bSGrzegorz Bernacki static uint32_t count_l2clk(void);
535c39c3ffSGrzegorz Bernacki void armadaxp_l2_init(void);
545c39c3ffSGrzegorz Bernacki void armadaxp_init_coher_fabric(void);
555c39c3ffSGrzegorz Bernacki int platform_get_ncpus(void);
560a57279bSMarcin Wojtas static uint64_t get_sar_value_armadaxp(void);
57d65cdf4bSGrzegorz Bernacki 
583a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_BASE		(MV_BASE + 0x8000)
593a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_CTRL		0x100
603a1f2172SGrzegorz Bernacki #define L2_ENABLE			(1 << 0)
613a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_AUX_CTRL		0x104
623a1f2172SGrzegorz Bernacki #define L2_WBWT_MODE_MASK		(3 << 0)
633a1f2172SGrzegorz Bernacki #define L2_WBWT_MODE_PAGE		0
643a1f2172SGrzegorz Bernacki #define L2_WBWT_MODE_WB			1
653a1f2172SGrzegorz Bernacki #define L2_WBWT_MODE_WT			2
663a1f2172SGrzegorz Bernacki #define L2_REP_STRAT_MASK		(3 << 27)
673a1f2172SGrzegorz Bernacki #define L2_REP_STRAT_LSFR		(1 << 27)
683a1f2172SGrzegorz Bernacki #define L2_REP_STRAT_SEMIPLRU		(3 << 27)
693a1f2172SGrzegorz Bernacki 
703a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_CNTR_CTRL		0x200
713a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_CNTR_CONF(x)	(0x204 + (x) * 0xc)
723a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_CNTR2_VAL_LOW	(0x208 + (x) * 0xc)
733a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_CNTR2_VAL_HI	(0x20c + (x) * 0xc)
743a1f2172SGrzegorz Bernacki 
753a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_INT_CAUSE		0x220
763a1f2172SGrzegorz Bernacki 
773a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_SYNC_BARRIER	0x700
783a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_INV_WAY		0x778
793a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_CLEAN_WAY		0x7BC
803a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_FLUSH_PHYS		0x7F0
813a1f2172SGrzegorz Bernacki #define ARMADAXP_L2_FLUSH_WAY		0x7FC
823a1f2172SGrzegorz Bernacki 
835c39c3ffSGrzegorz Bernacki #define MV_COHERENCY_FABRIC_BASE	(MV_MBUS_BRIDGE_BASE + 0x200)
845c39c3ffSGrzegorz Bernacki #define COHER_FABRIC_CTRL		0x00
855c39c3ffSGrzegorz Bernacki #define COHER_FABRIC_CONF		0x04
865c39c3ffSGrzegorz Bernacki #define COHER_FABRIC_CFU		0x28
875c39c3ffSGrzegorz Bernacki #define COHER_FABRIC_CIB_CTRL		0x80
883a1f2172SGrzegorz Bernacki 
89d65cdf4bSGrzegorz Bernacki struct vco_freq_ratio {
90d65cdf4bSGrzegorz Bernacki 	uint8_t	vco_cpu;	/* VCO to CLK0(CPU) clock ratio */
91d65cdf4bSGrzegorz Bernacki 	uint8_t	vco_l2c;	/* VCO to NB(L2 cache) clock ratio */
92d65cdf4bSGrzegorz Bernacki 	uint8_t	vco_hcl;	/* VCO to HCLK(DDR controller) clock ratio */
93d65cdf4bSGrzegorz Bernacki 	uint8_t	vco_ddr;	/* VCO to DR(DDR memory) clock ratio */
94d65cdf4bSGrzegorz Bernacki };
95d65cdf4bSGrzegorz Bernacki 
96d65cdf4bSGrzegorz Bernacki static struct vco_freq_ratio freq_conf_table[] = {
97d65cdf4bSGrzegorz Bernacki /*00*/	{ 1, 1,	 4,  2 },
98d65cdf4bSGrzegorz Bernacki /*01*/	{ 1, 2,	 2,  2 },
99d65cdf4bSGrzegorz Bernacki /*02*/	{ 2, 2,	 6,  3 },
100d65cdf4bSGrzegorz Bernacki /*03*/	{ 2, 2,	 3,  3 },
101d65cdf4bSGrzegorz Bernacki /*04*/	{ 1, 2,	 3,  3 },
102d65cdf4bSGrzegorz Bernacki /*05*/	{ 1, 2,	 4,  2 },
103d65cdf4bSGrzegorz Bernacki /*06*/	{ 1, 1,	 2,  2 },
104d65cdf4bSGrzegorz Bernacki /*07*/	{ 2, 3,	 6,  6 },
105d65cdf4bSGrzegorz Bernacki /*08*/	{ 2, 3,	 5,  5 },
106d65cdf4bSGrzegorz Bernacki /*09*/	{ 1, 2,	 6,  3 },
107d65cdf4bSGrzegorz Bernacki /*10*/	{ 2, 4,	10,  5 },
108d65cdf4bSGrzegorz Bernacki /*11*/	{ 1, 3,	 6,  6 },
109d65cdf4bSGrzegorz Bernacki /*12*/	{ 1, 2,	 5,  5 },
110d65cdf4bSGrzegorz Bernacki /*13*/	{ 1, 3,	 6,  3 },
111d65cdf4bSGrzegorz Bernacki /*14*/	{ 1, 2,	 5,  5 },
112d65cdf4bSGrzegorz Bernacki /*15*/	{ 2, 2,	 5,  5 },
113d65cdf4bSGrzegorz Bernacki /*16*/	{ 1, 1,	 3,  3 },
114d65cdf4bSGrzegorz Bernacki /*17*/	{ 2, 5,	10, 10 },
115d65cdf4bSGrzegorz Bernacki /*18*/	{ 1, 3,	 8,  4 },
116d65cdf4bSGrzegorz Bernacki /*19*/	{ 1, 1,	 2,  1 },
117d65cdf4bSGrzegorz Bernacki /*20*/	{ 2, 3,	 6,  3 },
118d65cdf4bSGrzegorz Bernacki /*21*/	{ 1, 2,	 8,  4 },
119d65cdf4bSGrzegorz Bernacki /*22*/	{ 2, 5,	10,  5 }
120d65cdf4bSGrzegorz Bernacki };
121d65cdf4bSGrzegorz Bernacki 
122d65cdf4bSGrzegorz Bernacki static uint16_t	cpu_clock_table[] = {
123d65cdf4bSGrzegorz Bernacki     1000, 1066, 1200, 1333, 1500, 1666, 1800, 2000, 600,  667,  800,  1600,
124d65cdf4bSGrzegorz Bernacki     2133, 2200, 2400 };
125d65cdf4bSGrzegorz Bernacki 
1260a57279bSMarcin Wojtas static uint64_t
get_sar_value_armadaxp(void)1270a57279bSMarcin Wojtas get_sar_value_armadaxp(void)
1280a57279bSMarcin Wojtas {
1290a57279bSMarcin Wojtas 	uint32_t sar_low, sar_high;
1300a57279bSMarcin Wojtas 
1310a57279bSMarcin Wojtas 	sar_high = bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE,
1320a57279bSMarcin Wojtas 	    SAMPLE_AT_RESET_HI);
1330a57279bSMarcin Wojtas 	sar_low = bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE,
1340a57279bSMarcin Wojtas 	    SAMPLE_AT_RESET_LO);
1350a57279bSMarcin Wojtas 	return (((uint64_t)sar_high << 32) | sar_low);
1360a57279bSMarcin Wojtas }
1370a57279bSMarcin Wojtas 
13816694521SOleksandr Tymoshenko uint32_t
get_tclk_armadaxp(void)139526de79bSMarcin Wojtas get_tclk_armadaxp(void)
14016694521SOleksandr Tymoshenko {
141d65cdf4bSGrzegorz Bernacki  	uint32_t cputype;
14216694521SOleksandr Tymoshenko 
143cb5ce014SAndrew Turner 	cputype = cp15_midr_get();
144d65cdf4bSGrzegorz Bernacki 	cputype &= CPU_ID_CPU_MASK;
145d65cdf4bSGrzegorz Bernacki 
146d65cdf4bSGrzegorz Bernacki 	if (cputype == CPU_ID_MV88SV584X_V7)
147d65cdf4bSGrzegorz Bernacki 		return (TCLK_250MHZ);
148d65cdf4bSGrzegorz Bernacki 	else
14916694521SOleksandr Tymoshenko 		return (TCLK_200MHZ);
15016694521SOleksandr Tymoshenko }
15116694521SOleksandr Tymoshenko 
15211a6a330SZbigniew Bodek uint32_t
get_cpu_freq_armadaxp(void)153526de79bSMarcin Wojtas get_cpu_freq_armadaxp(void)
15411a6a330SZbigniew Bodek {
15511a6a330SZbigniew Bodek 
15611a6a330SZbigniew Bodek 	return (0);
15711a6a330SZbigniew Bodek }
15811a6a330SZbigniew Bodek 
159d65cdf4bSGrzegorz Bernacki static uint32_t
count_l2clk(void)160d65cdf4bSGrzegorz Bernacki count_l2clk(void)
161d65cdf4bSGrzegorz Bernacki {
162d65cdf4bSGrzegorz Bernacki 	uint64_t sar_reg;
163d65cdf4bSGrzegorz Bernacki 	uint32_t freq_vco, freq_l2clk;
164d65cdf4bSGrzegorz Bernacki 	uint8_t  sar_cpu_freq, sar_fab_freq, array_size;
165d65cdf4bSGrzegorz Bernacki 
166d65cdf4bSGrzegorz Bernacki 	/* Get value of the SAR register and process it */
1670a57279bSMarcin Wojtas 	sar_reg = get_sar_value_armadaxp();
168d65cdf4bSGrzegorz Bernacki 	sar_cpu_freq = CPU_FREQ_FIELD(sar_reg);
169d65cdf4bSGrzegorz Bernacki 	sar_fab_freq = FAB_FREQ_FIELD(sar_reg);
170d65cdf4bSGrzegorz Bernacki 
171d65cdf4bSGrzegorz Bernacki 	/* Check if CPU frequency field has correct value */
17233495e5dSPedro F. Giffuni 	array_size = nitems(cpu_clock_table);
173d65cdf4bSGrzegorz Bernacki 	if (sar_cpu_freq >= array_size)
174d65cdf4bSGrzegorz Bernacki 		panic("Reserved value in cpu frequency configuration field: "
175d65cdf4bSGrzegorz Bernacki 		    "%d", sar_cpu_freq);
176d65cdf4bSGrzegorz Bernacki 
177d65cdf4bSGrzegorz Bernacki 	/* Check if fabric frequency field has correct value */
17833495e5dSPedro F. Giffuni 	array_size = nitems(freq_conf_table);
179d65cdf4bSGrzegorz Bernacki 	if (sar_fab_freq >= array_size)
180d65cdf4bSGrzegorz Bernacki 		panic("Reserved value in fabric frequency configuration field: "
181d65cdf4bSGrzegorz Bernacki 		    "%d", sar_fab_freq);
182d65cdf4bSGrzegorz Bernacki 
183d65cdf4bSGrzegorz Bernacki 	/* Get CPU clock frequency */
184d65cdf4bSGrzegorz Bernacki 	freq_vco = cpu_clock_table[sar_cpu_freq] *
185d65cdf4bSGrzegorz Bernacki 	    freq_conf_table[sar_fab_freq].vco_cpu;
186d65cdf4bSGrzegorz Bernacki 
187d65cdf4bSGrzegorz Bernacki 	/* Get L2CLK clock frequency */
188d65cdf4bSGrzegorz Bernacki 	freq_l2clk = freq_vco / freq_conf_table[sar_fab_freq].vco_l2c;
189d65cdf4bSGrzegorz Bernacki 
190d65cdf4bSGrzegorz Bernacki 	/* Round L2CLK value to integer MHz */
191d65cdf4bSGrzegorz Bernacki 	if (((freq_vco % freq_conf_table[sar_fab_freq].vco_l2c) * 10 /
192d65cdf4bSGrzegorz Bernacki 	    freq_conf_table[sar_fab_freq].vco_l2c) >= 5)
193d65cdf4bSGrzegorz Bernacki 		freq_l2clk++;
194d65cdf4bSGrzegorz Bernacki 
195d65cdf4bSGrzegorz Bernacki 	return (freq_l2clk * 1000000);
196d65cdf4bSGrzegorz Bernacki }
197d65cdf4bSGrzegorz Bernacki 
19816694521SOleksandr Tymoshenko uint32_t
get_l2clk(void)19916694521SOleksandr Tymoshenko get_l2clk(void)
20016694521SOleksandr Tymoshenko {
201d65cdf4bSGrzegorz Bernacki 	static uint32_t	l2clk_freq = 0;
20216694521SOleksandr Tymoshenko 
203d65cdf4bSGrzegorz Bernacki 	/* If get_l2clk is called first time get L2CLK value from register */
204d65cdf4bSGrzegorz Bernacki 	if (l2clk_freq == 0)
205d65cdf4bSGrzegorz Bernacki 		l2clk_freq = count_l2clk();
206d65cdf4bSGrzegorz Bernacki 
207d65cdf4bSGrzegorz Bernacki 	return (l2clk_freq);
20816694521SOleksandr Tymoshenko }
20916694521SOleksandr Tymoshenko 
2105c39c3ffSGrzegorz Bernacki static uint32_t
read_coher_fabric(uint32_t reg)2115c39c3ffSGrzegorz Bernacki read_coher_fabric(uint32_t reg)
2125c39c3ffSGrzegorz Bernacki {
2135c39c3ffSGrzegorz Bernacki 
2145c39c3ffSGrzegorz Bernacki 	return (bus_space_read_4(fdtbus_bs_tag, MV_COHERENCY_FABRIC_BASE, reg));
2155c39c3ffSGrzegorz Bernacki }
2165c39c3ffSGrzegorz Bernacki 
2175c39c3ffSGrzegorz Bernacki static void
write_coher_fabric(uint32_t reg,uint32_t val)2185c39c3ffSGrzegorz Bernacki write_coher_fabric(uint32_t reg, uint32_t val)
2195c39c3ffSGrzegorz Bernacki {
2205c39c3ffSGrzegorz Bernacki 
2215c39c3ffSGrzegorz Bernacki 	bus_space_write_4(fdtbus_bs_tag, MV_COHERENCY_FABRIC_BASE, reg, val);
2225c39c3ffSGrzegorz Bernacki }
2235c39c3ffSGrzegorz Bernacki 
2245c39c3ffSGrzegorz Bernacki int
platform_get_ncpus(void)2255c39c3ffSGrzegorz Bernacki platform_get_ncpus(void)
2265c39c3ffSGrzegorz Bernacki {
2275c39c3ffSGrzegorz Bernacki #if !defined(SMP)
2285c39c3ffSGrzegorz Bernacki 	return (1);
2295c39c3ffSGrzegorz Bernacki #else
2305c39c3ffSGrzegorz Bernacki 	return ((read_coher_fabric(COHER_FABRIC_CONF) & 0xf) + 1);
2315c39c3ffSGrzegorz Bernacki #endif
2325c39c3ffSGrzegorz Bernacki }
2335c39c3ffSGrzegorz Bernacki 
2345c39c3ffSGrzegorz Bernacki void
armadaxp_init_coher_fabric(void)2355c39c3ffSGrzegorz Bernacki armadaxp_init_coher_fabric(void)
2365c39c3ffSGrzegorz Bernacki {
2375c39c3ffSGrzegorz Bernacki 	uint32_t val, cpus, mask;
2385c39c3ffSGrzegorz Bernacki 
2395c39c3ffSGrzegorz Bernacki 	cpus = platform_get_ncpus();
2405c39c3ffSGrzegorz Bernacki 	mask = (1 << cpus) - 1;
2415c39c3ffSGrzegorz Bernacki 	val = read_coher_fabric(COHER_FABRIC_CTRL);
2425c39c3ffSGrzegorz Bernacki 	val |= (mask << 24);
2435c39c3ffSGrzegorz Bernacki 	write_coher_fabric(COHER_FABRIC_CTRL, val);
2445c39c3ffSGrzegorz Bernacki 
2455c39c3ffSGrzegorz Bernacki 	val = read_coher_fabric(COHER_FABRIC_CONF);
2465c39c3ffSGrzegorz Bernacki 	val |= (mask << 24);
2475c39c3ffSGrzegorz Bernacki 	val |= (1 << 15);
2485c39c3ffSGrzegorz Bernacki 	write_coher_fabric(COHER_FABRIC_CONF, val);
2495c39c3ffSGrzegorz Bernacki }
2503a1f2172SGrzegorz Bernacki 
2513a1f2172SGrzegorz Bernacki #define ALL_WAYS	0xffffffff
2523a1f2172SGrzegorz Bernacki 
2533a1f2172SGrzegorz Bernacki /* L2 cache configuration registers */
2543a1f2172SGrzegorz Bernacki static uint32_t
read_l2_cache(uint32_t reg)2553a1f2172SGrzegorz Bernacki read_l2_cache(uint32_t reg)
2563a1f2172SGrzegorz Bernacki {
2573a1f2172SGrzegorz Bernacki 
2583a1f2172SGrzegorz Bernacki 	return (bus_space_read_4(fdtbus_bs_tag, ARMADAXP_L2_BASE, reg));
2593a1f2172SGrzegorz Bernacki }
2603a1f2172SGrzegorz Bernacki 
2613a1f2172SGrzegorz Bernacki static void
write_l2_cache(uint32_t reg,uint32_t val)2623a1f2172SGrzegorz Bernacki write_l2_cache(uint32_t reg, uint32_t val)
2633a1f2172SGrzegorz Bernacki {
2643a1f2172SGrzegorz Bernacki 
2653a1f2172SGrzegorz Bernacki 	bus_space_write_4(fdtbus_bs_tag, ARMADAXP_L2_BASE, reg, val);
2663a1f2172SGrzegorz Bernacki }
2673a1f2172SGrzegorz Bernacki 
2685c39c3ffSGrzegorz Bernacki static void
armadaxp_l2_idcache_inv_all(void)2693a1f2172SGrzegorz Bernacki armadaxp_l2_idcache_inv_all(void)
2703a1f2172SGrzegorz Bernacki {
2713a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_INV_WAY, ALL_WAYS);
2723a1f2172SGrzegorz Bernacki }
2733a1f2172SGrzegorz Bernacki 
2743a1f2172SGrzegorz Bernacki void
armadaxp_l2_init(void)2753a1f2172SGrzegorz Bernacki armadaxp_l2_init(void)
2763a1f2172SGrzegorz Bernacki {
2773a1f2172SGrzegorz Bernacki 	u_int32_t reg;
2783a1f2172SGrzegorz Bernacki 
2793a1f2172SGrzegorz Bernacki 	/* Set L2 policy */
2803a1f2172SGrzegorz Bernacki 	reg = read_l2_cache(ARMADAXP_L2_AUX_CTRL);
2813a1f2172SGrzegorz Bernacki 	reg &= ~(L2_WBWT_MODE_MASK);
2823a1f2172SGrzegorz Bernacki 	reg &= ~(L2_REP_STRAT_MASK);
2833a1f2172SGrzegorz Bernacki 	reg |= L2_REP_STRAT_SEMIPLRU;
2843a1f2172SGrzegorz Bernacki 	reg |= L2_WBWT_MODE_WT;
2853a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_AUX_CTRL, reg);
2863a1f2172SGrzegorz Bernacki 
2873a1f2172SGrzegorz Bernacki 	/* Invalidate l2 cache */
2883a1f2172SGrzegorz Bernacki 	armadaxp_l2_idcache_inv_all();
2893a1f2172SGrzegorz Bernacki 
2903a1f2172SGrzegorz Bernacki 	/* Clear pending L2 interrupts */
2913a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_INT_CAUSE, 0x1ff);
2923a1f2172SGrzegorz Bernacki 
2933a1f2172SGrzegorz Bernacki 	/* Enable l2 cache */
2943a1f2172SGrzegorz Bernacki 	reg = read_l2_cache(ARMADAXP_L2_CTRL);
2953a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_CTRL, reg | L2_ENABLE);
2963a1f2172SGrzegorz Bernacki 
2973a1f2172SGrzegorz Bernacki 	/*
2983a1f2172SGrzegorz Bernacki 	 * For debug purposes
2993a1f2172SGrzegorz Bernacki 	 * Configure and enable counter
3003a1f2172SGrzegorz Bernacki 	 */
3013a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_CNTR_CONF(0), 0xf0000 | (4 << 2));
3023a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_CNTR_CONF(1), 0xf0000 | (2 << 2));
3033a1f2172SGrzegorz Bernacki 	write_l2_cache(ARMADAXP_L2_CNTR_CTRL, 0x303);
3043a1f2172SGrzegorz Bernacki 
3053a1f2172SGrzegorz Bernacki 	/*
3063a1f2172SGrzegorz Bernacki 	 * Enable Cache maintenance operation propagation in coherency fabric
3073a1f2172SGrzegorz Bernacki 	 * Change point of coherency and point of unification to DRAM.
3083a1f2172SGrzegorz Bernacki 	 */
3095c39c3ffSGrzegorz Bernacki 	reg = read_coher_fabric(COHER_FABRIC_CFU);
3103a1f2172SGrzegorz Bernacki 	reg |= (1 << 17) | (1 << 18);
3115c39c3ffSGrzegorz Bernacki 	write_coher_fabric(COHER_FABRIC_CFU, reg);
3125c39c3ffSGrzegorz Bernacki 
3135c39c3ffSGrzegorz Bernacki 	/* Coherent IO Bridge initialization */
3145c39c3ffSGrzegorz Bernacki 	reg = read_coher_fabric(COHER_FABRIC_CIB_CTRL);
3155c39c3ffSGrzegorz Bernacki 	reg &= ~(7 << 16);
3165c39c3ffSGrzegorz Bernacki 	reg |= (7 << 16);
3175c39c3ffSGrzegorz Bernacki 	write_coher_fabric(COHER_FABRIC_CIB_CTRL, reg);
3183a1f2172SGrzegorz Bernacki }
319