199b3d294SThomas Petazzoni /* 299b3d294SThomas Petazzoni * Device Tree support for Armada 370 and XP platforms. 399b3d294SThomas Petazzoni * 499b3d294SThomas Petazzoni * Copyright (C) 2012 Marvell 599b3d294SThomas Petazzoni * 699b3d294SThomas Petazzoni * Lior Amsalem <alior@marvell.com> 799b3d294SThomas Petazzoni * Gregory CLEMENT <gregory.clement@free-electrons.com> 899b3d294SThomas Petazzoni * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 999b3d294SThomas Petazzoni * 1099b3d294SThomas Petazzoni * This file is licensed under the terms of the GNU General Public 1199b3d294SThomas Petazzoni * License version 2. This program is licensed "as is" without any 1299b3d294SThomas Petazzoni * warranty of any kind, whether express or implied. 1399b3d294SThomas Petazzoni */ 1499b3d294SThomas Petazzoni 1599b3d294SThomas Petazzoni #include <linux/kernel.h> 1699b3d294SThomas Petazzoni #include <linux/init.h> 1799b3d294SThomas Petazzoni #include <linux/clk-provider.h> 1899b3d294SThomas Petazzoni #include <linux/of_address.h> 1999b3d294SThomas Petazzoni #include <linux/of_platform.h> 2099b3d294SThomas Petazzoni #include <linux/io.h> 2199b3d294SThomas Petazzoni #include <linux/clocksource.h> 2299b3d294SThomas Petazzoni #include <linux/dma-mapping.h> 2399b3d294SThomas Petazzoni #include <linux/mbus.h> 24ff050ad1SLinus Torvalds #include <linux/signal.h> 2599b3d294SThomas Petazzoni #include <linux/slab.h> 2699b3d294SThomas Petazzoni #include <asm/hardware/cache-l2x0.h> 2799b3d294SThomas Petazzoni #include <asm/mach/arch.h> 2899b3d294SThomas Petazzoni #include <asm/mach/map.h> 2999b3d294SThomas Petazzoni #include <asm/mach/time.h> 308e6ac203SThomas Petazzoni #include <asm/smp_scu.h> 3199b3d294SThomas Petazzoni #include "armada-370-xp.h" 3299b3d294SThomas Petazzoni #include "common.h" 3399b3d294SThomas Petazzoni #include "coherency.h" 3499b3d294SThomas Petazzoni #include "mvebu-soc-id.h" 3599b3d294SThomas Petazzoni 36ca4a6f87SThomas Petazzoni /* 378e6ac203SThomas Petazzoni * Enables the SCU when available. Obviously, this is only useful on 388e6ac203SThomas Petazzoni * Cortex-A based SOCs, not on PJ4B based ones. 398e6ac203SThomas Petazzoni */ 408e6ac203SThomas Petazzoni static void __init mvebu_scu_enable(void) 418e6ac203SThomas Petazzoni { 428e6ac203SThomas Petazzoni void __iomem *scu_base; 438e6ac203SThomas Petazzoni 448e6ac203SThomas Petazzoni struct device_node *np = 458e6ac203SThomas Petazzoni of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu"); 468e6ac203SThomas Petazzoni if (np) { 478e6ac203SThomas Petazzoni scu_base = of_iomap(np, 0); 488e6ac203SThomas Petazzoni scu_enable(scu_base); 498e6ac203SThomas Petazzoni of_node_put(np); 508e6ac203SThomas Petazzoni } 518e6ac203SThomas Petazzoni } 528e6ac203SThomas Petazzoni 538e6ac203SThomas Petazzoni /* 54ca4a6f87SThomas Petazzoni * Early versions of Armada 375 SoC have a bug where the BootROM 55ca4a6f87SThomas Petazzoni * leaves an external data abort pending. The kernel is hit by this 56ca4a6f87SThomas Petazzoni * data abort as soon as it enters userspace, because it unmasks the 57ca4a6f87SThomas Petazzoni * data aborts at this moment. We register a custom abort handler 58ca4a6f87SThomas Petazzoni * below to ignore the first data abort to work around this 59ca4a6f87SThomas Petazzoni * problem. 60ca4a6f87SThomas Petazzoni */ 61ca4a6f87SThomas Petazzoni static int armada_375_external_abort_wa(unsigned long addr, unsigned int fsr, 62ca4a6f87SThomas Petazzoni struct pt_regs *regs) 63ca4a6f87SThomas Petazzoni { 64ca4a6f87SThomas Petazzoni static int ignore_first; 65ca4a6f87SThomas Petazzoni 66ca4a6f87SThomas Petazzoni if (!ignore_first && fsr == 0x1406) { 67ca4a6f87SThomas Petazzoni ignore_first = 1; 68ca4a6f87SThomas Petazzoni return 0; 69ca4a6f87SThomas Petazzoni } 70ca4a6f87SThomas Petazzoni 71ca4a6f87SThomas Petazzoni return 1; 72ca4a6f87SThomas Petazzoni } 73ca4a6f87SThomas Petazzoni 7499b3d294SThomas Petazzoni static void __init mvebu_timer_and_clk_init(void) 7599b3d294SThomas Petazzoni { 7699b3d294SThomas Petazzoni of_clk_init(NULL); 7799b3d294SThomas Petazzoni clocksource_of_init(); 788e6ac203SThomas Petazzoni mvebu_scu_enable(); 7999b3d294SThomas Petazzoni coherency_init(); 805686a1e5SThomas Petazzoni BUG_ON(mvebu_mbus_dt_init(coherency_available())); 8199b3d294SThomas Petazzoni l2x0_of_init(0, ~0UL); 82ca4a6f87SThomas Petazzoni 83ca4a6f87SThomas Petazzoni if (of_machine_is_compatible("marvell,armada375")) 84ca4a6f87SThomas Petazzoni hook_fault_code(16 + 6, armada_375_external_abort_wa, SIGBUS, 0, 85ca4a6f87SThomas Petazzoni "imprecise external abort"); 8699b3d294SThomas Petazzoni } 8799b3d294SThomas Petazzoni 8899b3d294SThomas Petazzoni static void __init i2c_quirk(void) 8999b3d294SThomas Petazzoni { 9099b3d294SThomas Petazzoni struct device_node *np; 9199b3d294SThomas Petazzoni u32 dev, rev; 9299b3d294SThomas Petazzoni 9399b3d294SThomas Petazzoni /* 9499b3d294SThomas Petazzoni * Only revisons more recent than A0 support the offload 9599b3d294SThomas Petazzoni * mechanism. We can exit only if we are sure that we can 9699b3d294SThomas Petazzoni * get the SoC revision and it is more recent than A0. 9799b3d294SThomas Petazzoni */ 988eee0f81SGregory CLEMENT if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV) 9999b3d294SThomas Petazzoni return; 10099b3d294SThomas Petazzoni 10199b3d294SThomas Petazzoni for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") { 10299b3d294SThomas Petazzoni struct property *new_compat; 10399b3d294SThomas Petazzoni 10499b3d294SThomas Petazzoni new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL); 10599b3d294SThomas Petazzoni 10699b3d294SThomas Petazzoni new_compat->name = kstrdup("compatible", GFP_KERNEL); 10799b3d294SThomas Petazzoni new_compat->length = sizeof("marvell,mv78230-a0-i2c"); 10899b3d294SThomas Petazzoni new_compat->value = kstrdup("marvell,mv78230-a0-i2c", 10999b3d294SThomas Petazzoni GFP_KERNEL); 11099b3d294SThomas Petazzoni 11199b3d294SThomas Petazzoni of_update_property(np, new_compat); 11299b3d294SThomas Petazzoni } 11399b3d294SThomas Petazzoni return; 11499b3d294SThomas Petazzoni } 11599b3d294SThomas Petazzoni 116*5fd62066SEzequiel Garcia #define A375_Z1_THERMAL_FIXUP_OFFSET 0xc 117*5fd62066SEzequiel Garcia 118*5fd62066SEzequiel Garcia static void __init thermal_quirk(void) 119*5fd62066SEzequiel Garcia { 120*5fd62066SEzequiel Garcia struct device_node *np; 121*5fd62066SEzequiel Garcia u32 dev, rev; 122*5fd62066SEzequiel Garcia 123*5fd62066SEzequiel Garcia if (mvebu_get_soc_id(&dev, &rev) && rev > ARMADA_375_Z1_REV) 124*5fd62066SEzequiel Garcia return; 125*5fd62066SEzequiel Garcia 126*5fd62066SEzequiel Garcia for_each_compatible_node(np, NULL, "marvell,armada375-thermal") { 127*5fd62066SEzequiel Garcia struct property *prop; 128*5fd62066SEzequiel Garcia __be32 newval, *newprop, *oldprop; 129*5fd62066SEzequiel Garcia int len; 130*5fd62066SEzequiel Garcia 131*5fd62066SEzequiel Garcia /* 132*5fd62066SEzequiel Garcia * The register offset is at a wrong location. This quirk 133*5fd62066SEzequiel Garcia * creates a new reg property as a clone of the previous 134*5fd62066SEzequiel Garcia * one and corrects the offset. 135*5fd62066SEzequiel Garcia */ 136*5fd62066SEzequiel Garcia oldprop = (__be32 *)of_get_property(np, "reg", &len); 137*5fd62066SEzequiel Garcia if (!oldprop) 138*5fd62066SEzequiel Garcia continue; 139*5fd62066SEzequiel Garcia 140*5fd62066SEzequiel Garcia /* Create a duplicate of the 'reg' property */ 141*5fd62066SEzequiel Garcia prop = kzalloc(sizeof(*prop), GFP_KERNEL); 142*5fd62066SEzequiel Garcia prop->length = len; 143*5fd62066SEzequiel Garcia prop->name = kstrdup("reg", GFP_KERNEL); 144*5fd62066SEzequiel Garcia prop->value = kzalloc(len, GFP_KERNEL); 145*5fd62066SEzequiel Garcia memcpy(prop->value, oldprop, len); 146*5fd62066SEzequiel Garcia 147*5fd62066SEzequiel Garcia /* Fixup the register offset of the second entry */ 148*5fd62066SEzequiel Garcia oldprop += 2; 149*5fd62066SEzequiel Garcia newprop = (__be32 *)prop->value + 2; 150*5fd62066SEzequiel Garcia newval = cpu_to_be32(be32_to_cpu(*oldprop) - 151*5fd62066SEzequiel Garcia A375_Z1_THERMAL_FIXUP_OFFSET); 152*5fd62066SEzequiel Garcia *newprop = newval; 153*5fd62066SEzequiel Garcia of_update_property(np, prop); 154*5fd62066SEzequiel Garcia 155*5fd62066SEzequiel Garcia /* 156*5fd62066SEzequiel Garcia * The thermal controller needs some quirk too, so let's change 157*5fd62066SEzequiel Garcia * the compatible string to reflect this. 158*5fd62066SEzequiel Garcia */ 159*5fd62066SEzequiel Garcia prop = kzalloc(sizeof(*prop), GFP_KERNEL); 160*5fd62066SEzequiel Garcia prop->name = kstrdup("compatible", GFP_KERNEL); 161*5fd62066SEzequiel Garcia prop->length = sizeof("marvell,armada375-z1-thermal"); 162*5fd62066SEzequiel Garcia prop->value = kstrdup("marvell,armada375-z1-thermal", 163*5fd62066SEzequiel Garcia GFP_KERNEL); 164*5fd62066SEzequiel Garcia of_update_property(np, prop); 165*5fd62066SEzequiel Garcia } 166*5fd62066SEzequiel Garcia return; 167*5fd62066SEzequiel Garcia } 168*5fd62066SEzequiel Garcia 16999b3d294SThomas Petazzoni static void __init mvebu_dt_init(void) 17099b3d294SThomas Petazzoni { 17199b3d294SThomas Petazzoni if (of_machine_is_compatible("plathome,openblocks-ax3-4")) 17299b3d294SThomas Petazzoni i2c_quirk(); 173*5fd62066SEzequiel Garcia if (of_machine_is_compatible("marvell,a375-db")) 174*5fd62066SEzequiel Garcia thermal_quirk(); 175*5fd62066SEzequiel Garcia 17699b3d294SThomas Petazzoni of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 17799b3d294SThomas Petazzoni } 17899b3d294SThomas Petazzoni 17999b3d294SThomas Petazzoni static const char * const armada_370_xp_dt_compat[] = { 18099b3d294SThomas Petazzoni "marvell,armada-370-xp", 18199b3d294SThomas Petazzoni NULL, 18299b3d294SThomas Petazzoni }; 18399b3d294SThomas Petazzoni 184a017dbb6SThomas Petazzoni DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)") 18599b3d294SThomas Petazzoni .smp = smp_ops(armada_xp_smp_ops), 18699b3d294SThomas Petazzoni .init_machine = mvebu_dt_init, 18799b3d294SThomas Petazzoni .init_time = mvebu_timer_and_clk_init, 18899b3d294SThomas Petazzoni .restart = mvebu_restart, 18999b3d294SThomas Petazzoni .dt_compat = armada_370_xp_dt_compat, 19099b3d294SThomas Petazzoni MACHINE_END 191d3ce7f25SGregory CLEMENT 192d3ce7f25SGregory CLEMENT static const char * const armada_375_dt_compat[] = { 193d3ce7f25SGregory CLEMENT "marvell,armada375", 194d3ce7f25SGregory CLEMENT NULL, 195d3ce7f25SGregory CLEMENT }; 196d3ce7f25SGregory CLEMENT 197d3ce7f25SGregory CLEMENT DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)") 198d3ce7f25SGregory CLEMENT .init_time = mvebu_timer_and_clk_init, 199*5fd62066SEzequiel Garcia .init_machine = mvebu_dt_init, 200d3ce7f25SGregory CLEMENT .restart = mvebu_restart, 201d3ce7f25SGregory CLEMENT .dt_compat = armada_375_dt_compat, 202d3ce7f25SGregory CLEMENT MACHINE_END 2039aa30f1cSThomas Petazzoni 2049aa30f1cSThomas Petazzoni static const char * const armada_38x_dt_compat[] = { 2059aa30f1cSThomas Petazzoni "marvell,armada380", 2069aa30f1cSThomas Petazzoni "marvell,armada385", 2079aa30f1cSThomas Petazzoni NULL, 2089aa30f1cSThomas Petazzoni }; 2099aa30f1cSThomas Petazzoni 2109aa30f1cSThomas Petazzoni DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)") 2119aa30f1cSThomas Petazzoni .init_time = mvebu_timer_and_clk_init, 2129aa30f1cSThomas Petazzoni .restart = mvebu_restart, 2139aa30f1cSThomas Petazzoni .dt_compat = armada_38x_dt_compat, 2149aa30f1cSThomas Petazzoni MACHINE_END 215