18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Device Tree support for Armada 370 and XP platforms. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2012 Marvell 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Lior Amsalem <alior@marvell.com> 78c2ecf20Sopenharmony_ci * Gregory CLEMENT <gregory.clement@free-electrons.com> 88c2ecf20Sopenharmony_ci * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public 118c2ecf20Sopenharmony_ci * License version 2. This program is licensed "as is" without any 128c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied. 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/kernel.h> 168c2ecf20Sopenharmony_ci#include <linux/init.h> 178c2ecf20Sopenharmony_ci#include <linux/of_address.h> 188c2ecf20Sopenharmony_ci#include <linux/of_fdt.h> 198c2ecf20Sopenharmony_ci#include <linux/io.h> 208c2ecf20Sopenharmony_ci#include <linux/clocksource.h> 218c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 228c2ecf20Sopenharmony_ci#include <linux/memblock.h> 238c2ecf20Sopenharmony_ci#include <linux/mbus.h> 248c2ecf20Sopenharmony_ci#include <linux/slab.h> 258c2ecf20Sopenharmony_ci#include <linux/irqchip.h> 268c2ecf20Sopenharmony_ci#include <asm/hardware/cache-l2x0.h> 278c2ecf20Sopenharmony_ci#include <asm/mach/arch.h> 288c2ecf20Sopenharmony_ci#include <asm/mach/map.h> 298c2ecf20Sopenharmony_ci#include <asm/mach/time.h> 308c2ecf20Sopenharmony_ci#include <asm/smp_scu.h> 318c2ecf20Sopenharmony_ci#include "armada-370-xp.h" 328c2ecf20Sopenharmony_ci#include "common.h" 338c2ecf20Sopenharmony_ci#include "coherency.h" 348c2ecf20Sopenharmony_ci#include "mvebu-soc-id.h" 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic void __iomem *scu_base; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* 398c2ecf20Sopenharmony_ci * Enables the SCU when available. Obviously, this is only useful on 408c2ecf20Sopenharmony_ci * Cortex-A based SOCs, not on PJ4B based ones. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_cistatic void __init mvebu_scu_enable(void) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci struct device_node *np = 458c2ecf20Sopenharmony_ci of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu"); 468c2ecf20Sopenharmony_ci if (np) { 478c2ecf20Sopenharmony_ci scu_base = of_iomap(np, 0); 488c2ecf20Sopenharmony_ci scu_enable(scu_base); 498c2ecf20Sopenharmony_ci of_node_put(np); 508c2ecf20Sopenharmony_ci } 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_civoid __iomem *mvebu_get_scu_base(void) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci return scu_base; 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * When returning from suspend, the platform goes through the 608c2ecf20Sopenharmony_ci * bootloader, which executes its DDR3 training code. This code has 618c2ecf20Sopenharmony_ci * the unfortunate idea of using the first 10 KB of each DRAM bank to 628c2ecf20Sopenharmony_ci * exercise the RAM and calculate the optimal timings. Therefore, this 638c2ecf20Sopenharmony_ci * area of RAM is overwritten, and shouldn't be used by the kernel if 648c2ecf20Sopenharmony_ci * suspend/resume is supported. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#ifdef CONFIG_SUSPEND 688c2ecf20Sopenharmony_ci#define MVEBU_DDR_TRAINING_AREA_SZ (10 * SZ_1K) 698c2ecf20Sopenharmony_cistatic int __init mvebu_scan_mem(unsigned long node, const char *uname, 708c2ecf20Sopenharmony_ci int depth, void *data) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci const char *type = of_get_flat_dt_prop(node, "device_type", NULL); 738c2ecf20Sopenharmony_ci const __be32 *reg, *endp; 748c2ecf20Sopenharmony_ci int l; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci if (type == NULL || strcmp(type, "memory")) 778c2ecf20Sopenharmony_ci return 0; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); 808c2ecf20Sopenharmony_ci if (reg == NULL) 818c2ecf20Sopenharmony_ci reg = of_get_flat_dt_prop(node, "reg", &l); 828c2ecf20Sopenharmony_ci if (reg == NULL) 838c2ecf20Sopenharmony_ci return 0; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci endp = reg + (l / sizeof(__be32)); 868c2ecf20Sopenharmony_ci while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { 878c2ecf20Sopenharmony_ci u64 base, size; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci base = dt_mem_next_cell(dt_root_addr_cells, ®); 908c2ecf20Sopenharmony_ci size = dt_mem_next_cell(dt_root_size_cells, ®); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci memblock_reserve(base, MVEBU_DDR_TRAINING_AREA_SZ); 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci return 0; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic void __init mvebu_memblock_reserve(void) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci of_scan_flat_dt(mvebu_scan_mem, NULL); 1018c2ecf20Sopenharmony_ci} 1028c2ecf20Sopenharmony_ci#else 1038c2ecf20Sopenharmony_cistatic void __init mvebu_memblock_reserve(void) {} 1048c2ecf20Sopenharmony_ci#endif 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic void __init mvebu_init_irq(void) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci irqchip_init(); 1098c2ecf20Sopenharmony_ci mvebu_scu_enable(); 1108c2ecf20Sopenharmony_ci coherency_init(); 1118c2ecf20Sopenharmony_ci BUG_ON(mvebu_mbus_dt_init(coherency_available())); 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic void __init i2c_quirk(void) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci struct device_node *np; 1178c2ecf20Sopenharmony_ci u32 dev, rev; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci /* 1208c2ecf20Sopenharmony_ci * Only revisons more recent than A0 support the offload 1218c2ecf20Sopenharmony_ci * mechanism. We can exit only if we are sure that we can 1228c2ecf20Sopenharmony_ci * get the SoC revision and it is more recent than A0. 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV) 1258c2ecf20Sopenharmony_ci return; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") { 1288c2ecf20Sopenharmony_ci struct property *new_compat; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci new_compat->name = kstrdup("compatible", GFP_KERNEL); 1338c2ecf20Sopenharmony_ci new_compat->length = sizeof("marvell,mv78230-a0-i2c"); 1348c2ecf20Sopenharmony_ci new_compat->value = kstrdup("marvell,mv78230-a0-i2c", 1358c2ecf20Sopenharmony_ci GFP_KERNEL); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci of_update_property(np, new_compat); 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic void __init mvebu_dt_init(void) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci if (of_machine_is_compatible("marvell,armadaxp")) 1448c2ecf20Sopenharmony_ci i2c_quirk(); 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic void __init armada_370_xp_dt_fixup(void) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1508c2ecf20Sopenharmony_ci smp_set_ops(smp_ops(armada_xp_smp_ops)); 1518c2ecf20Sopenharmony_ci#endif 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic const char * const armada_370_xp_dt_compat[] __initconst = { 1558c2ecf20Sopenharmony_ci "marvell,armada-370-xp", 1568c2ecf20Sopenharmony_ci NULL, 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciDT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)") 1608c2ecf20Sopenharmony_ci .l2c_aux_val = 0, 1618c2ecf20Sopenharmony_ci .l2c_aux_mask = ~0, 1628c2ecf20Sopenharmony_ci .init_machine = mvebu_dt_init, 1638c2ecf20Sopenharmony_ci .init_irq = mvebu_init_irq, 1648c2ecf20Sopenharmony_ci .restart = mvebu_restart, 1658c2ecf20Sopenharmony_ci .reserve = mvebu_memblock_reserve, 1668c2ecf20Sopenharmony_ci .dt_compat = armada_370_xp_dt_compat, 1678c2ecf20Sopenharmony_ci .dt_fixup = armada_370_xp_dt_fixup, 1688c2ecf20Sopenharmony_ciMACHINE_END 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic const char * const armada_375_dt_compat[] __initconst = { 1718c2ecf20Sopenharmony_ci "marvell,armada375", 1728c2ecf20Sopenharmony_ci NULL, 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ciDT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)") 1768c2ecf20Sopenharmony_ci .l2c_aux_val = 0, 1778c2ecf20Sopenharmony_ci .l2c_aux_mask = ~0, 1788c2ecf20Sopenharmony_ci .init_irq = mvebu_init_irq, 1798c2ecf20Sopenharmony_ci .init_machine = mvebu_dt_init, 1808c2ecf20Sopenharmony_ci .restart = mvebu_restart, 1818c2ecf20Sopenharmony_ci .dt_compat = armada_375_dt_compat, 1828c2ecf20Sopenharmony_ciMACHINE_END 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic const char * const armada_38x_dt_compat[] __initconst = { 1858c2ecf20Sopenharmony_ci "marvell,armada380", 1868c2ecf20Sopenharmony_ci "marvell,armada385", 1878c2ecf20Sopenharmony_ci NULL, 1888c2ecf20Sopenharmony_ci}; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciDT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)") 1918c2ecf20Sopenharmony_ci .l2c_aux_val = 0, 1928c2ecf20Sopenharmony_ci .l2c_aux_mask = ~0, 1938c2ecf20Sopenharmony_ci .init_irq = mvebu_init_irq, 1948c2ecf20Sopenharmony_ci .restart = mvebu_restart, 1958c2ecf20Sopenharmony_ci .dt_compat = armada_38x_dt_compat, 1968c2ecf20Sopenharmony_ciMACHINE_END 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic const char * const armada_39x_dt_compat[] __initconst = { 1998c2ecf20Sopenharmony_ci "marvell,armada390", 2008c2ecf20Sopenharmony_ci "marvell,armada398", 2018c2ecf20Sopenharmony_ci NULL, 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ciDT_MACHINE_START(ARMADA_39X_DT, "Marvell Armada 39x (Device Tree)") 2058c2ecf20Sopenharmony_ci .l2c_aux_val = 0, 2068c2ecf20Sopenharmony_ci .l2c_aux_mask = ~0, 2078c2ecf20Sopenharmony_ci .init_irq = mvebu_init_irq, 2088c2ecf20Sopenharmony_ci .restart = mvebu_restart, 2098c2ecf20Sopenharmony_ci .dt_compat = armada_39x_dt_compat, 2108c2ecf20Sopenharmony_ciMACHINE_END 211