xref: /linux/arch/arm/mach-highbank/highbank.c (revision 0529e315bbda5d502c93df2cfafba9bb337fbdf4)
1220e6cf7SRob Herring /*
2220e6cf7SRob Herring  * Copyright 2010-2011 Calxeda, Inc.
3220e6cf7SRob Herring  *
4220e6cf7SRob Herring  * This program is free software; you can redistribute it and/or modify it
5220e6cf7SRob Herring  * under the terms and conditions of the GNU General Public License,
6220e6cf7SRob Herring  * version 2, as published by the Free Software Foundation.
7220e6cf7SRob Herring  *
8220e6cf7SRob Herring  * This program is distributed in the hope it will be useful, but WITHOUT
9220e6cf7SRob Herring  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10220e6cf7SRob Herring  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11220e6cf7SRob Herring  * more details.
12220e6cf7SRob Herring  *
13220e6cf7SRob Herring  * You should have received a copy of the GNU General Public License along with
14220e6cf7SRob Herring  * this program.  If not, see <http://www.gnu.org/licenses/>.
15220e6cf7SRob Herring  */
16220e6cf7SRob Herring #include <linux/clk.h>
17220e6cf7SRob Herring #include <linux/clkdev.h>
181dc737c4SRob Herring #include <linux/dma-mapping.h>
19220e6cf7SRob Herring #include <linux/io.h>
20220e6cf7SRob Herring #include <linux/irq.h>
21*0529e315SRob Herring #include <linux/irqchip.h>
22220e6cf7SRob Herring #include <linux/irqdomain.h>
23220e6cf7SRob Herring #include <linux/of.h>
24220e6cf7SRob Herring #include <linux/of_irq.h>
25220e6cf7SRob Herring #include <linux/of_platform.h>
26220e6cf7SRob Herring #include <linux/of_address.h>
27bf14fc54SWill Deacon #include <linux/smp.h>
281dc737c4SRob Herring #include <linux/amba/bus.h>
29220e6cf7SRob Herring 
30e095c0d1SRob Herring #include <asm/arch_timer.h>
31220e6cf7SRob Herring #include <asm/cacheflush.h>
32eb50439bSWill Deacon #include <asm/smp_plat.h>
337ac9b9ebSMarc Zyngier #include <asm/smp_twd.h>
34220e6cf7SRob Herring #include <asm/hardware/arm_timer.h>
35220e6cf7SRob Herring #include <asm/hardware/timer-sp.h>
36220e6cf7SRob Herring #include <asm/hardware/cache-l2x0.h>
37220e6cf7SRob Herring #include <asm/mach/arch.h>
3852530343SRob Herring #include <asm/mach/map.h>
39220e6cf7SRob Herring #include <asm/mach/time.h>
40220e6cf7SRob Herring 
41220e6cf7SRob Herring #include "core.h"
42220e6cf7SRob Herring #include "sysregs.h"
43220e6cf7SRob Herring 
44220e6cf7SRob Herring void __iomem *sregs_base;
457a2848d3SRob Herring void __iomem *scu_base_addr;
46220e6cf7SRob Herring 
47220e6cf7SRob Herring static void __init highbank_scu_map_io(void)
48220e6cf7SRob Herring {
49220e6cf7SRob Herring 	unsigned long base;
50220e6cf7SRob Herring 
51220e6cf7SRob Herring 	/* Get SCU base */
52220e6cf7SRob Herring 	asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));
53220e6cf7SRob Herring 
547a2848d3SRob Herring 	scu_base_addr = ioremap(base, SZ_4K);
55220e6cf7SRob Herring }
56220e6cf7SRob Herring 
57220e6cf7SRob Herring #define HB_JUMP_TABLE_PHYS(cpu)		(0x40 + (0x10 * (cpu)))
58220e6cf7SRob Herring #define HB_JUMP_TABLE_VIRT(cpu)		phys_to_virt(HB_JUMP_TABLE_PHYS(cpu))
59220e6cf7SRob Herring 
60220e6cf7SRob Herring void highbank_set_cpu_jump(int cpu, void *jump_addr)
61220e6cf7SRob Herring {
62bf14fc54SWill Deacon 	cpu = cpu_logical_map(cpu);
63adf55f7fSRob Herring 	writel(virt_to_phys(jump_addr), HB_JUMP_TABLE_VIRT(cpu));
64220e6cf7SRob Herring 	__cpuc_flush_dcache_area(HB_JUMP_TABLE_VIRT(cpu), 16);
65220e6cf7SRob Herring 	outer_clean_range(HB_JUMP_TABLE_PHYS(cpu),
66220e6cf7SRob Herring 			  HB_JUMP_TABLE_PHYS(cpu) + 15);
67220e6cf7SRob Herring }
68220e6cf7SRob Herring 
698e56130dSRob Herring #ifdef CONFIG_CACHE_L2X0
708e56130dSRob Herring static void highbank_l2x0_disable(void)
718e56130dSRob Herring {
728e56130dSRob Herring 	/* Disable PL310 L2 Cache controller */
738e56130dSRob Herring 	highbank_smc1(0x102, 0x0);
748e56130dSRob Herring }
758e56130dSRob Herring #endif
768e56130dSRob Herring 
77220e6cf7SRob Herring static void __init highbank_init_irq(void)
78220e6cf7SRob Herring {
79*0529e315SRob Herring 	irqchip_init();
808e56130dSRob Herring 
817a2848d3SRob Herring 	if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9"))
827a2848d3SRob Herring 		highbank_scu_map_io();
837a2848d3SRob Herring 
848e56130dSRob Herring #ifdef CONFIG_CACHE_L2X0
858e56130dSRob Herring 	/* Enable PL310 L2 Cache controller */
868e56130dSRob Herring 	highbank_smc1(0x102, 0x1);
87220e6cf7SRob Herring 	l2x0_of_init(0, ~0UL);
888e56130dSRob Herring 	outer_cache.disable = highbank_l2x0_disable;
898e56130dSRob Herring #endif
90220e6cf7SRob Herring }
91220e6cf7SRob Herring 
928d4d9f52SRob Herring static struct clk_lookup lookup = {
938d4d9f52SRob Herring 	.dev_id = "sp804",
948d4d9f52SRob Herring 	.con_id = NULL,
958d4d9f52SRob Herring };
968d4d9f52SRob Herring 
97220e6cf7SRob Herring static void __init highbank_timer_init(void)
98220e6cf7SRob Herring {
99220e6cf7SRob Herring 	int irq;
100220e6cf7SRob Herring 	struct device_node *np;
101220e6cf7SRob Herring 	void __iomem *timer_base;
102220e6cf7SRob Herring 
103220e6cf7SRob Herring 	/* Map system registers */
104220e6cf7SRob Herring 	np = of_find_compatible_node(NULL, NULL, "calxeda,hb-sregs");
105220e6cf7SRob Herring 	sregs_base = of_iomap(np, 0);
106220e6cf7SRob Herring 	WARN_ON(!sregs_base);
107220e6cf7SRob Herring 
108220e6cf7SRob Herring 	np = of_find_compatible_node(NULL, NULL, "arm,sp804");
109220e6cf7SRob Herring 	timer_base = of_iomap(np, 0);
110220e6cf7SRob Herring 	WARN_ON(!timer_base);
111220e6cf7SRob Herring 	irq = irq_of_parse_and_map(np, 0);
112220e6cf7SRob Herring 
113220e6cf7SRob Herring 	highbank_clocks_init();
1148d4d9f52SRob Herring 	lookup.clk = of_clk_get(np, 0);
1158d4d9f52SRob Herring 	clkdev_add(&lookup);
116220e6cf7SRob Herring 
117f3b7cd2aSRob Herring 	sp804_clocksource_and_sched_clock_init(timer_base + 0x20, "timer1");
118220e6cf7SRob Herring 	sp804_clockevents_init(timer_base, irq, "timer0");
1197ac9b9ebSMarc Zyngier 
1207ac9b9ebSMarc Zyngier 	twd_local_timer_of_register();
121e095c0d1SRob Herring 
122e095c0d1SRob Herring 	arch_timer_of_register();
123e095c0d1SRob Herring 	arch_timer_sched_clock_init();
124220e6cf7SRob Herring }
125220e6cf7SRob Herring 
126220e6cf7SRob Herring static struct sys_timer highbank_timer = {
127220e6cf7SRob Herring 	.init = highbank_timer_init,
128220e6cf7SRob Herring };
129220e6cf7SRob Herring 
130220e6cf7SRob Herring static void highbank_power_off(void)
131220e6cf7SRob Herring {
132c05ee88fSRob Herring 	highbank_set_pwr_shutdown();
133220e6cf7SRob Herring 
134220e6cf7SRob Herring 	while (1)
135220e6cf7SRob Herring 		cpu_do_idle();
136220e6cf7SRob Herring }
137220e6cf7SRob Herring 
1381dc737c4SRob Herring static int highbank_platform_notifier(struct notifier_block *nb,
1391dc737c4SRob Herring 				  unsigned long event, void *__dev)
1401dc737c4SRob Herring {
1411dc737c4SRob Herring 	struct resource *res;
1421dc737c4SRob Herring 	int reg = -1;
1431dc737c4SRob Herring 	struct device *dev = __dev;
1441dc737c4SRob Herring 
1451dc737c4SRob Herring 	if (event != BUS_NOTIFY_ADD_DEVICE)
1461dc737c4SRob Herring 		return NOTIFY_DONE;
1471dc737c4SRob Herring 
1481dc737c4SRob Herring 	if (of_device_is_compatible(dev->of_node, "calxeda,hb-ahci"))
1491dc737c4SRob Herring 		reg = 0xc;
1501dc737c4SRob Herring 	else if (of_device_is_compatible(dev->of_node, "calxeda,hb-sdhci"))
1511dc737c4SRob Herring 		reg = 0x18;
1521dc737c4SRob Herring 	else if (of_device_is_compatible(dev->of_node, "arm,pl330"))
1531dc737c4SRob Herring 		reg = 0x20;
1541dc737c4SRob Herring 	else if (of_device_is_compatible(dev->of_node, "calxeda,hb-xgmac")) {
1551dc737c4SRob Herring 		res = platform_get_resource(to_platform_device(dev),
1561dc737c4SRob Herring 					    IORESOURCE_MEM, 0);
1571dc737c4SRob Herring 		if (res) {
1581dc737c4SRob Herring 			if (res->start == 0xfff50000)
1591dc737c4SRob Herring 				reg = 0;
1601dc737c4SRob Herring 			else if (res->start == 0xfff51000)
1611dc737c4SRob Herring 				reg = 4;
1621dc737c4SRob Herring 		}
1631dc737c4SRob Herring 	}
1641dc737c4SRob Herring 
1651dc737c4SRob Herring 	if (reg < 0)
1661dc737c4SRob Herring 		return NOTIFY_DONE;
1671dc737c4SRob Herring 
1681dc737c4SRob Herring 	if (of_property_read_bool(dev->of_node, "dma-coherent")) {
1691dc737c4SRob Herring 		writel(0xff31, sregs_base + reg);
1701dc737c4SRob Herring 		set_dma_ops(dev, &arm_coherent_dma_ops);
1711dc737c4SRob Herring 	} else
1721dc737c4SRob Herring 		writel(0, sregs_base + reg);
1731dc737c4SRob Herring 
1741dc737c4SRob Herring 	return NOTIFY_OK;
1751dc737c4SRob Herring }
1761dc737c4SRob Herring 
1771dc737c4SRob Herring static struct notifier_block highbank_amba_nb = {
1781dc737c4SRob Herring 	.notifier_call = highbank_platform_notifier,
1791dc737c4SRob Herring };
1801dc737c4SRob Herring 
1811dc737c4SRob Herring static struct notifier_block highbank_platform_nb = {
1821dc737c4SRob Herring 	.notifier_call = highbank_platform_notifier,
1831dc737c4SRob Herring };
1841dc737c4SRob Herring 
185220e6cf7SRob Herring static void __init highbank_init(void)
186220e6cf7SRob Herring {
187220e6cf7SRob Herring 	pm_power_off = highbank_power_off;
188a283580cSRob Herring 	highbank_pm_init();
189220e6cf7SRob Herring 
1901dc737c4SRob Herring 	bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
1911dc737c4SRob Herring 	bus_register_notifier(&amba_bustype, &highbank_amba_nb);
1921dc737c4SRob Herring 
193220e6cf7SRob Herring 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
194220e6cf7SRob Herring }
195220e6cf7SRob Herring 
196220e6cf7SRob Herring static const char *highbank_match[] __initconst = {
197220e6cf7SRob Herring 	"calxeda,highbank",
198e095c0d1SRob Herring 	"calxeda,ecx-2000",
199220e6cf7SRob Herring 	NULL,
200220e6cf7SRob Herring };
201220e6cf7SRob Herring 
202220e6cf7SRob Herring DT_MACHINE_START(HIGHBANK, "Highbank")
2037ad71b61SMarc Zyngier 	.smp		= smp_ops(highbank_smp_ops),
20452530343SRob Herring 	.map_io		= debug_ll_io_init,
205220e6cf7SRob Herring 	.init_irq	= highbank_init_irq,
206220e6cf7SRob Herring 	.timer		= &highbank_timer,
207220e6cf7SRob Herring 	.init_machine	= highbank_init,
208220e6cf7SRob Herring 	.dt_compat	= highbank_match,
20900e9967eSRussell King 	.restart	= highbank_restart,
210220e6cf7SRob Herring MACHINE_END
211