xref: /openbmc/linux/arch/arm/mach-spear/spear13xx.c (revision 0fdebc5e)
1*0fdebc5eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2a7ed099fSArnd Bergmann /*
3a7ed099fSArnd Bergmann  * arch/arm/mach-spear13xx/spear13xx.c
4a7ed099fSArnd Bergmann  *
5a7ed099fSArnd Bergmann  * SPEAr13XX machines common source file
6a7ed099fSArnd Bergmann  *
7a7ed099fSArnd Bergmann  * Copyright (C) 2012 ST Microelectronics
8da89947bSViresh Kumar  * Viresh Kumar <vireshk@kernel.org>
9a7ed099fSArnd Bergmann  */
10a7ed099fSArnd Bergmann 
11a7ed099fSArnd Bergmann #define pr_fmt(fmt) "SPEAr13xx: " fmt
12a7ed099fSArnd Bergmann 
13a7ed099fSArnd Bergmann #include <linux/amba/pl022.h>
14a7ed099fSArnd Bergmann #include <linux/clk.h>
15f2ad937bSLee Jones #include <linux/clk/spear.h>
16442a33ebSArnd Bergmann #include <linux/clocksource.h>
17a7ed099fSArnd Bergmann #include <linux/err.h>
18a7ed099fSArnd Bergmann #include <linux/of.h>
19a7ed099fSArnd Bergmann #include <asm/hardware/cache-l2x0.h>
20a7ed099fSArnd Bergmann #include <asm/mach/map.h>
21c164620aSArnd Bergmann #include "spear.h"
22442a33ebSArnd Bergmann #include "generic.h"
23a7ed099fSArnd Bergmann 
spear13xx_l2x0_init(void)24a7ed099fSArnd Bergmann void __init spear13xx_l2x0_init(void)
25a7ed099fSArnd Bergmann {
26a7ed099fSArnd Bergmann 	/*
27a7ed099fSArnd Bergmann 	 * 512KB (64KB/way), 8-way associativity, parity supported
28a7ed099fSArnd Bergmann 	 *
29339ac71bSJulia Lawall 	 * FIXME: 9th bit, of Auxiliary Controller register must be set
30a7ed099fSArnd Bergmann 	 * for some spear13xx devices for stable L2 operation.
31a7ed099fSArnd Bergmann 	 *
32a7ed099fSArnd Bergmann 	 * Enable Early BRESP, L2 prefetch for Instruction and Data,
33a7ed099fSArnd Bergmann 	 * write alloc and 'Full line of zero' options
34a7ed099fSArnd Bergmann 	 *
35a7ed099fSArnd Bergmann 	 */
365497e7b8SOlof Johansson 	if (!IS_ENABLED(CONFIG_CACHE_L2X0))
375497e7b8SOlof Johansson 		return;
38a7ed099fSArnd Bergmann 
391a5a954cSRussell King 	writel_relaxed(0x06, VA_L2CC_BASE + L310_PREFETCH_CTRL);
40a7ed099fSArnd Bergmann 
41a7ed099fSArnd Bergmann 	/*
42a7ed099fSArnd Bergmann 	 * Program following latencies in order to make
43a7ed099fSArnd Bergmann 	 * SPEAr1340 work at 600 MHz
44a7ed099fSArnd Bergmann 	 */
451a5a954cSRussell King 	writel_relaxed(0x221, VA_L2CC_BASE + L310_TAG_LATENCY_CTRL);
461a5a954cSRussell King 	writel_relaxed(0x441, VA_L2CC_BASE + L310_DATA_LATENCY_CTRL);
47adf4b00eSRussell King 	l2x0_init(VA_L2CC_BASE, 0x30a00001, 0xfe0fffff);
48a7ed099fSArnd Bergmann }
49a7ed099fSArnd Bergmann 
50a7ed099fSArnd Bergmann /*
51a7ed099fSArnd Bergmann  * Following will create 16MB static virtual/physical mappings
52a7ed099fSArnd Bergmann  * PHYSICAL		VIRTUAL
5336c5c90dSPratyush Anand  * 0xB3000000		0xF9000000
54a7ed099fSArnd Bergmann  * 0xE0000000		0xFD000000
55a7ed099fSArnd Bergmann  * 0xEC000000		0xFC000000
56a7ed099fSArnd Bergmann  * 0xED000000		0xFB000000
57a7ed099fSArnd Bergmann  */
583da1d7b1SSachin Kamat static struct map_desc spear13xx_io_desc[] __initdata = {
59a7ed099fSArnd Bergmann 	{
60a7ed099fSArnd Bergmann 		.virtual	= (unsigned long)VA_PERIP_GRP2_BASE,
61a7ed099fSArnd Bergmann 		.pfn		= __phys_to_pfn(PERIP_GRP2_BASE),
62a7ed099fSArnd Bergmann 		.length		= SZ_16M,
63a7ed099fSArnd Bergmann 		.type		= MT_DEVICE
64a7ed099fSArnd Bergmann 	}, {
65a7ed099fSArnd Bergmann 		.virtual	= (unsigned long)VA_PERIP_GRP1_BASE,
66a7ed099fSArnd Bergmann 		.pfn		= __phys_to_pfn(PERIP_GRP1_BASE),
67a7ed099fSArnd Bergmann 		.length		= SZ_16M,
68a7ed099fSArnd Bergmann 		.type		= MT_DEVICE
69a7ed099fSArnd Bergmann 	}, {
70a7ed099fSArnd Bergmann 		.virtual	= (unsigned long)VA_A9SM_AND_MPMC_BASE,
71a7ed099fSArnd Bergmann 		.pfn		= __phys_to_pfn(A9SM_AND_MPMC_BASE),
72a7ed099fSArnd Bergmann 		.length		= SZ_16M,
73a7ed099fSArnd Bergmann 		.type		= MT_DEVICE
74a7ed099fSArnd Bergmann 	}, {
75a7ed099fSArnd Bergmann 		.virtual	= (unsigned long)VA_L2CC_BASE,
76a7ed099fSArnd Bergmann 		.pfn		= __phys_to_pfn(L2CC_BASE),
77a7ed099fSArnd Bergmann 		.length		= SZ_4K,
78a7ed099fSArnd Bergmann 		.type		= MT_DEVICE
79a7ed099fSArnd Bergmann 	},
80a7ed099fSArnd Bergmann };
81a7ed099fSArnd Bergmann 
82a7ed099fSArnd Bergmann /* This will create static memory mapping for selected devices */
spear13xx_map_io(void)83a7ed099fSArnd Bergmann void __init spear13xx_map_io(void)
84a7ed099fSArnd Bergmann {
85a7ed099fSArnd Bergmann 	iotable_init(spear13xx_io_desc, ARRAY_SIZE(spear13xx_io_desc));
86a7ed099fSArnd Bergmann }
87a7ed099fSArnd Bergmann 
spear13xx_clk_init(void)88a7ed099fSArnd Bergmann static void __init spear13xx_clk_init(void)
89a7ed099fSArnd Bergmann {
90a7ed099fSArnd Bergmann 	if (of_machine_is_compatible("st,spear1310"))
91d9909ebeSArnd Bergmann 		spear1310_clk_init(VA_MISC_BASE, VA_SPEAR1310_RAS_BASE);
92a7ed099fSArnd Bergmann 	else if (of_machine_is_compatible("st,spear1340"))
93d9909ebeSArnd Bergmann 		spear1340_clk_init(VA_MISC_BASE);
94a7ed099fSArnd Bergmann 	else
95a7ed099fSArnd Bergmann 		pr_err("%s: Unknown machine\n", __func__);
96a7ed099fSArnd Bergmann }
97a7ed099fSArnd Bergmann 
spear13xx_timer_init(void)98a7ed099fSArnd Bergmann void __init spear13xx_timer_init(void)
99a7ed099fSArnd Bergmann {
100a7ed099fSArnd Bergmann 	char pclk_name[] = "osc_24m_clk";
101a7ed099fSArnd Bergmann 	struct clk *gpt_clk, *pclk;
102a7ed099fSArnd Bergmann 
103a7ed099fSArnd Bergmann 	spear13xx_clk_init();
104a7ed099fSArnd Bergmann 
105a7ed099fSArnd Bergmann 	/* get the system timer clock */
106a7ed099fSArnd Bergmann 	gpt_clk = clk_get_sys("gpt0", NULL);
107a7ed099fSArnd Bergmann 	if (IS_ERR(gpt_clk)) {
108a7ed099fSArnd Bergmann 		pr_err("%s:couldn't get clk for gpt\n", __func__);
109a7ed099fSArnd Bergmann 		BUG();
110a7ed099fSArnd Bergmann 	}
111a7ed099fSArnd Bergmann 
112a7ed099fSArnd Bergmann 	/* get the suitable parent clock for timer*/
113a7ed099fSArnd Bergmann 	pclk = clk_get(NULL, pclk_name);
114a7ed099fSArnd Bergmann 	if (IS_ERR(pclk)) {
115a7ed099fSArnd Bergmann 		pr_err("%s:couldn't get %s as parent for gpt\n", __func__,
116a7ed099fSArnd Bergmann 				pclk_name);
117a7ed099fSArnd Bergmann 		BUG();
118a7ed099fSArnd Bergmann 	}
119a7ed099fSArnd Bergmann 
120a7ed099fSArnd Bergmann 	clk_set_parent(gpt_clk, pclk);
121a7ed099fSArnd Bergmann 	clk_put(gpt_clk);
122a7ed099fSArnd Bergmann 	clk_put(pclk);
123a7ed099fSArnd Bergmann 
124a7ed099fSArnd Bergmann 	spear_setup_of_timer();
125ba5d08c0SDaniel Lezcano 	timer_probe();
126a7ed099fSArnd Bergmann }
127