18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * arch/arm/mach-spear13xx/spear13xx.c
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * SPEAr13XX machines common source file
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2012 ST Microelectronics
78c2ecf20Sopenharmony_ci * Viresh Kumar <vireshk@kernel.org>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
108c2ecf20Sopenharmony_ci * License version 2. This program is licensed "as is" without any
118c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define pr_fmt(fmt) "SPEAr13xx: " fmt
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/amba/pl022.h>
178c2ecf20Sopenharmony_ci#include <linux/clk.h>
188c2ecf20Sopenharmony_ci#include <linux/clocksource.h>
198c2ecf20Sopenharmony_ci#include <linux/err.h>
208c2ecf20Sopenharmony_ci#include <linux/of.h>
218c2ecf20Sopenharmony_ci#include <asm/hardware/cache-l2x0.h>
228c2ecf20Sopenharmony_ci#include <asm/mach/map.h>
238c2ecf20Sopenharmony_ci#include <mach/spear.h>
248c2ecf20Sopenharmony_ci#include "generic.h"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_civoid __init spear13xx_l2x0_init(void)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	/*
298c2ecf20Sopenharmony_ci	 * 512KB (64KB/way), 8-way associativity, parity supported
308c2ecf20Sopenharmony_ci	 *
318c2ecf20Sopenharmony_ci	 * FIXME: 9th bit, of Auxillary Controller register must be set
328c2ecf20Sopenharmony_ci	 * for some spear13xx devices for stable L2 operation.
338c2ecf20Sopenharmony_ci	 *
348c2ecf20Sopenharmony_ci	 * Enable Early BRESP, L2 prefetch for Instruction and Data,
358c2ecf20Sopenharmony_ci	 * write alloc and 'Full line of zero' options
368c2ecf20Sopenharmony_ci	 *
378c2ecf20Sopenharmony_ci	 */
388c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_CACHE_L2X0))
398c2ecf20Sopenharmony_ci		return;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	writel_relaxed(0x06, VA_L2CC_BASE + L310_PREFETCH_CTRL);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	/*
448c2ecf20Sopenharmony_ci	 * Program following latencies in order to make
458c2ecf20Sopenharmony_ci	 * SPEAr1340 work at 600 MHz
468c2ecf20Sopenharmony_ci	 */
478c2ecf20Sopenharmony_ci	writel_relaxed(0x221, VA_L2CC_BASE + L310_TAG_LATENCY_CTRL);
488c2ecf20Sopenharmony_ci	writel_relaxed(0x441, VA_L2CC_BASE + L310_DATA_LATENCY_CTRL);
498c2ecf20Sopenharmony_ci	l2x0_init(VA_L2CC_BASE, 0x30a00001, 0xfe0fffff);
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/*
538c2ecf20Sopenharmony_ci * Following will create 16MB static virtual/physical mappings
548c2ecf20Sopenharmony_ci * PHYSICAL		VIRTUAL
558c2ecf20Sopenharmony_ci * 0xB3000000		0xF9000000
568c2ecf20Sopenharmony_ci * 0xE0000000		0xFD000000
578c2ecf20Sopenharmony_ci * 0xEC000000		0xFC000000
588c2ecf20Sopenharmony_ci * 0xED000000		0xFB000000
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_cistatic struct map_desc spear13xx_io_desc[] __initdata = {
618c2ecf20Sopenharmony_ci	{
628c2ecf20Sopenharmony_ci		.virtual	= (unsigned long)VA_PERIP_GRP2_BASE,
638c2ecf20Sopenharmony_ci		.pfn		= __phys_to_pfn(PERIP_GRP2_BASE),
648c2ecf20Sopenharmony_ci		.length		= SZ_16M,
658c2ecf20Sopenharmony_ci		.type		= MT_DEVICE
668c2ecf20Sopenharmony_ci	}, {
678c2ecf20Sopenharmony_ci		.virtual	= (unsigned long)VA_PERIP_GRP1_BASE,
688c2ecf20Sopenharmony_ci		.pfn		= __phys_to_pfn(PERIP_GRP1_BASE),
698c2ecf20Sopenharmony_ci		.length		= SZ_16M,
708c2ecf20Sopenharmony_ci		.type		= MT_DEVICE
718c2ecf20Sopenharmony_ci	}, {
728c2ecf20Sopenharmony_ci		.virtual	= (unsigned long)VA_A9SM_AND_MPMC_BASE,
738c2ecf20Sopenharmony_ci		.pfn		= __phys_to_pfn(A9SM_AND_MPMC_BASE),
748c2ecf20Sopenharmony_ci		.length		= SZ_16M,
758c2ecf20Sopenharmony_ci		.type		= MT_DEVICE
768c2ecf20Sopenharmony_ci	}, {
778c2ecf20Sopenharmony_ci		.virtual	= (unsigned long)VA_L2CC_BASE,
788c2ecf20Sopenharmony_ci		.pfn		= __phys_to_pfn(L2CC_BASE),
798c2ecf20Sopenharmony_ci		.length		= SZ_4K,
808c2ecf20Sopenharmony_ci		.type		= MT_DEVICE
818c2ecf20Sopenharmony_ci	},
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* This will create static memory mapping for selected devices */
858c2ecf20Sopenharmony_civoid __init spear13xx_map_io(void)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	iotable_init(spear13xx_io_desc, ARRAY_SIZE(spear13xx_io_desc));
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic void __init spear13xx_clk_init(void)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	if (of_machine_is_compatible("st,spear1310"))
938c2ecf20Sopenharmony_ci		spear1310_clk_init(VA_MISC_BASE, VA_SPEAR1310_RAS_BASE);
948c2ecf20Sopenharmony_ci	else if (of_machine_is_compatible("st,spear1340"))
958c2ecf20Sopenharmony_ci		spear1340_clk_init(VA_MISC_BASE);
968c2ecf20Sopenharmony_ci	else
978c2ecf20Sopenharmony_ci		pr_err("%s: Unknown machine\n", __func__);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_civoid __init spear13xx_timer_init(void)
1018c2ecf20Sopenharmony_ci{
1028c2ecf20Sopenharmony_ci	char pclk_name[] = "osc_24m_clk";
1038c2ecf20Sopenharmony_ci	struct clk *gpt_clk, *pclk;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	spear13xx_clk_init();
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/* get the system timer clock */
1088c2ecf20Sopenharmony_ci	gpt_clk = clk_get_sys("gpt0", NULL);
1098c2ecf20Sopenharmony_ci	if (IS_ERR(gpt_clk)) {
1108c2ecf20Sopenharmony_ci		pr_err("%s:couldn't get clk for gpt\n", __func__);
1118c2ecf20Sopenharmony_ci		BUG();
1128c2ecf20Sopenharmony_ci	}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	/* get the suitable parent clock for timer*/
1158c2ecf20Sopenharmony_ci	pclk = clk_get(NULL, pclk_name);
1168c2ecf20Sopenharmony_ci	if (IS_ERR(pclk)) {
1178c2ecf20Sopenharmony_ci		pr_err("%s:couldn't get %s as parent for gpt\n", __func__,
1188c2ecf20Sopenharmony_ci				pclk_name);
1198c2ecf20Sopenharmony_ci		BUG();
1208c2ecf20Sopenharmony_ci	}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	clk_set_parent(gpt_clk, pclk);
1238c2ecf20Sopenharmony_ci	clk_put(gpt_clk);
1248c2ecf20Sopenharmony_ci	clk_put(pclk);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	spear_setup_of_timer();
1278c2ecf20Sopenharmony_ci	timer_probe();
1288c2ecf20Sopenharmony_ci}
129