18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * OMAP4 specific common source file. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2010 Texas Instruments, Inc. 68c2ecf20Sopenharmony_ci * Author: 78c2ecf20Sopenharmony_ci * Santosh Shilimkar <santosh.shilimkar@ti.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/io.h> 138c2ecf20Sopenharmony_ci#include <linux/irq.h> 148c2ecf20Sopenharmony_ci#include <linux/irqchip.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include <linux/memblock.h> 178c2ecf20Sopenharmony_ci#include <linux/of_irq.h> 188c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 198c2ecf20Sopenharmony_ci#include <linux/export.h> 208c2ecf20Sopenharmony_ci#include <linux/irqchip/arm-gic.h> 218c2ecf20Sopenharmony_ci#include <linux/of_address.h> 228c2ecf20Sopenharmony_ci#include <linux/reboot.h> 238c2ecf20Sopenharmony_ci#include <linux/genalloc.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include <asm/hardware/cache-l2x0.h> 268c2ecf20Sopenharmony_ci#include <asm/mach/map.h> 278c2ecf20Sopenharmony_ci#include <asm/memblock.h> 288c2ecf20Sopenharmony_ci#include <asm/smp_twd.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include "omap-wakeupgen.h" 318c2ecf20Sopenharmony_ci#include "soc.h" 328c2ecf20Sopenharmony_ci#include "iomap.h" 338c2ecf20Sopenharmony_ci#include "common.h" 348c2ecf20Sopenharmony_ci#include "prminst44xx.h" 358c2ecf20Sopenharmony_ci#include "prcm_mpu44xx.h" 368c2ecf20Sopenharmony_ci#include "omap4-sar-layout.h" 378c2ecf20Sopenharmony_ci#include "omap-secure.h" 388c2ecf20Sopenharmony_ci#include "sram.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#ifdef CONFIG_CACHE_L2X0 418c2ecf20Sopenharmony_cistatic void __iomem *l2cache_base; 428c2ecf20Sopenharmony_ci#endif 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic void __iomem *sar_ram_base; 458c2ecf20Sopenharmony_cistatic void __iomem *gic_dist_base_addr; 468c2ecf20Sopenharmony_cistatic void __iomem *twd_base; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define IRQ_LOCALTIMER 29 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#ifdef CONFIG_OMAP_INTERCONNECT_BARRIER 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* Used to implement memory barrier on DRAM path */ 538c2ecf20Sopenharmony_ci#define OMAP4_DRAM_BARRIER_VA 0xfe600000 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic void __iomem *dram_sync, *sram_sync; 568c2ecf20Sopenharmony_cistatic phys_addr_t dram_sync_paddr; 578c2ecf20Sopenharmony_cistatic u32 dram_sync_size; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* 608c2ecf20Sopenharmony_ci * The OMAP4 bus structure contains asynchronous bridges which can buffer 618c2ecf20Sopenharmony_ci * data writes from the MPU. These asynchronous bridges can be found on 628c2ecf20Sopenharmony_ci * paths between the MPU to EMIF, and the MPU to L3 interconnects. 638c2ecf20Sopenharmony_ci * 648c2ecf20Sopenharmony_ci * We need to be careful about re-ordering which can happen as a result 658c2ecf20Sopenharmony_ci * of different accesses being performed via different paths, and 668c2ecf20Sopenharmony_ci * therefore different asynchronous bridges. 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* 708c2ecf20Sopenharmony_ci * OMAP4 interconnect barrier which is called for each mb() and wmb(). 718c2ecf20Sopenharmony_ci * This is to ensure that normal paths to DRAM (normal memory, cacheable 728c2ecf20Sopenharmony_ci * accesses) are properly synchronised with writes to DMA coherent memory 738c2ecf20Sopenharmony_ci * (normal memory, uncacheable) and device writes. 748c2ecf20Sopenharmony_ci * 758c2ecf20Sopenharmony_ci * The mb() and wmb() barriers only operate only on the MPU->MA->EMIF 768c2ecf20Sopenharmony_ci * path, as we need to ensure that data is visible to other system 778c2ecf20Sopenharmony_ci * masters prior to writes to those system masters being seen. 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * Note: the SRAM path is not synchronised via mb() and wmb(). 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_cistatic void omap4_mb(void) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci if (dram_sync) 848c2ecf20Sopenharmony_ci writel_relaxed(0, dram_sync); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* 888c2ecf20Sopenharmony_ci * OMAP4 Errata i688 - asynchronous bridge corruption when entering WFI. 898c2ecf20Sopenharmony_ci * 908c2ecf20Sopenharmony_ci * If a data is stalled inside asynchronous bridge because of back 918c2ecf20Sopenharmony_ci * pressure, it may be accepted multiple times, creating pointer 928c2ecf20Sopenharmony_ci * misalignment that will corrupt next transfers on that data path until 938c2ecf20Sopenharmony_ci * next reset of the system. No recovery procedure once the issue is hit, 948c2ecf20Sopenharmony_ci * the path remains consistently broken. 958c2ecf20Sopenharmony_ci * 968c2ecf20Sopenharmony_ci * Async bridges can be found on paths between MPU to EMIF and MPU to L3 978c2ecf20Sopenharmony_ci * interconnects. 988c2ecf20Sopenharmony_ci * 998c2ecf20Sopenharmony_ci * This situation can happen only when the idle is initiated by a Master 1008c2ecf20Sopenharmony_ci * Request Disconnection (which is trigged by software when executing WFI 1018c2ecf20Sopenharmony_ci * on the CPU). 1028c2ecf20Sopenharmony_ci * 1038c2ecf20Sopenharmony_ci * The work-around for this errata needs all the initiators connected 1048c2ecf20Sopenharmony_ci * through an async bridge to ensure that data path is properly drained 1058c2ecf20Sopenharmony_ci * before issuing WFI. This condition will be met if one Strongly ordered 1068c2ecf20Sopenharmony_ci * access is performed to the target right before executing the WFI. 1078c2ecf20Sopenharmony_ci * 1088c2ecf20Sopenharmony_ci * In MPU case, L3 T2ASYNC FIFO and DDR T2ASYNC FIFO needs to be drained. 1098c2ecf20Sopenharmony_ci * IO barrier ensure that there is no synchronisation loss on initiators 1108c2ecf20Sopenharmony_ci * operating on both interconnect port simultaneously. 1118c2ecf20Sopenharmony_ci * 1128c2ecf20Sopenharmony_ci * This is a stronger version of the OMAP4 memory barrier below, and 1138c2ecf20Sopenharmony_ci * operates on both the MPU->MA->EMIF path but also the MPU->OCP path 1148c2ecf20Sopenharmony_ci * as well, and is necessary prior to executing a WFI. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_civoid omap_interconnect_sync(void) 1178c2ecf20Sopenharmony_ci{ 1188c2ecf20Sopenharmony_ci if (dram_sync && sram_sync) { 1198c2ecf20Sopenharmony_ci writel_relaxed(readl_relaxed(dram_sync), dram_sync); 1208c2ecf20Sopenharmony_ci writel_relaxed(readl_relaxed(sram_sync), sram_sync); 1218c2ecf20Sopenharmony_ci isb(); 1228c2ecf20Sopenharmony_ci } 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic int __init omap4_sram_init(void) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci struct device_node *np; 1288c2ecf20Sopenharmony_ci struct gen_pool *sram_pool; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci if (!soc_is_omap44xx() && !soc_is_omap54xx()) 1318c2ecf20Sopenharmony_ci return 0; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci np = of_find_compatible_node(NULL, NULL, "ti,omap4-mpu"); 1348c2ecf20Sopenharmony_ci if (!np) 1358c2ecf20Sopenharmony_ci pr_warn("%s:Unable to allocate sram needed to handle errata I688\n", 1368c2ecf20Sopenharmony_ci __func__); 1378c2ecf20Sopenharmony_ci sram_pool = of_gen_pool_get(np, "sram", 0); 1388c2ecf20Sopenharmony_ci if (!sram_pool) 1398c2ecf20Sopenharmony_ci pr_warn("%s:Unable to get sram pool needed to handle errata I688\n", 1408c2ecf20Sopenharmony_ci __func__); 1418c2ecf20Sopenharmony_ci else 1428c2ecf20Sopenharmony_ci sram_sync = (void *)gen_pool_alloc(sram_pool, PAGE_SIZE); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci return 0; 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ciomap_arch_initcall(omap4_sram_init); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* Steal one page physical memory for barrier implementation */ 1498c2ecf20Sopenharmony_civoid __init omap_barrier_reserve_memblock(void) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci dram_sync_size = ALIGN(PAGE_SIZE, SZ_1M); 1528c2ecf20Sopenharmony_ci dram_sync_paddr = arm_memblock_steal(dram_sync_size, SZ_1M); 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_civoid __init omap_barriers_init(void) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci struct map_desc dram_io_desc[1]; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA; 1608c2ecf20Sopenharmony_ci dram_io_desc[0].pfn = __phys_to_pfn(dram_sync_paddr); 1618c2ecf20Sopenharmony_ci dram_io_desc[0].length = dram_sync_size; 1628c2ecf20Sopenharmony_ci dram_io_desc[0].type = MT_MEMORY_RW_SO; 1638c2ecf20Sopenharmony_ci iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc)); 1648c2ecf20Sopenharmony_ci dram_sync = (void __iomem *) dram_io_desc[0].virtual; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci pr_info("OMAP4: Map %pa to %p for dram barrier\n", 1678c2ecf20Sopenharmony_ci &dram_sync_paddr, dram_sync); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci soc_mb = omap4_mb; 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#endif 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_civoid gic_dist_disable(void) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci if (gic_dist_base_addr) 1778c2ecf20Sopenharmony_ci writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL); 1788c2ecf20Sopenharmony_ci} 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_civoid gic_dist_enable(void) 1818c2ecf20Sopenharmony_ci{ 1828c2ecf20Sopenharmony_ci if (gic_dist_base_addr) 1838c2ecf20Sopenharmony_ci writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL); 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cibool gic_dist_disabled(void) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1); 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_civoid gic_timer_retrigger(void) 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci u32 twd_int = readl_relaxed(twd_base + TWD_TIMER_INTSTAT); 1948c2ecf20Sopenharmony_ci u32 gic_int = readl_relaxed(gic_dist_base_addr + GIC_DIST_PENDING_SET); 1958c2ecf20Sopenharmony_ci u32 twd_ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) { 1988c2ecf20Sopenharmony_ci /* 1998c2ecf20Sopenharmony_ci * The local timer interrupt got lost while the distributor was 2008c2ecf20Sopenharmony_ci * disabled. Ack the pending interrupt, and retrigger it. 2018c2ecf20Sopenharmony_ci */ 2028c2ecf20Sopenharmony_ci pr_warn("%s: lost localtimer interrupt\n", __func__); 2038c2ecf20Sopenharmony_ci writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT); 2048c2ecf20Sopenharmony_ci if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) { 2058c2ecf20Sopenharmony_ci writel_relaxed(1, twd_base + TWD_TIMER_COUNTER); 2068c2ecf20Sopenharmony_ci twd_ctrl |= TWD_TIMER_CONTROL_ENABLE; 2078c2ecf20Sopenharmony_ci writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL); 2088c2ecf20Sopenharmony_ci } 2098c2ecf20Sopenharmony_ci } 2108c2ecf20Sopenharmony_ci} 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#ifdef CONFIG_CACHE_L2X0 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_civoid __iomem *omap4_get_l2cache_base(void) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci return l2cache_base; 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_civoid omap4_l2c310_write_sec(unsigned long val, unsigned reg) 2208c2ecf20Sopenharmony_ci{ 2218c2ecf20Sopenharmony_ci unsigned smc_op; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci switch (reg) { 2248c2ecf20Sopenharmony_ci case L2X0_CTRL: 2258c2ecf20Sopenharmony_ci smc_op = OMAP4_MON_L2X0_CTRL_INDEX; 2268c2ecf20Sopenharmony_ci break; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci case L2X0_AUX_CTRL: 2298c2ecf20Sopenharmony_ci smc_op = OMAP4_MON_L2X0_AUXCTRL_INDEX; 2308c2ecf20Sopenharmony_ci break; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci case L2X0_DEBUG_CTRL: 2338c2ecf20Sopenharmony_ci smc_op = OMAP4_MON_L2X0_DBG_CTRL_INDEX; 2348c2ecf20Sopenharmony_ci break; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci case L310_PREFETCH_CTRL: 2378c2ecf20Sopenharmony_ci smc_op = OMAP4_MON_L2X0_PREFETCH_INDEX; 2388c2ecf20Sopenharmony_ci break; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci case L310_POWER_CTRL: 2418c2ecf20Sopenharmony_ci pr_info_once("OMAP L2C310: ROM does not support power control setting\n"); 2428c2ecf20Sopenharmony_ci return; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci default: 2458c2ecf20Sopenharmony_ci WARN_ONCE(1, "OMAP L2C310: ignoring write to reg 0x%x\n", reg); 2468c2ecf20Sopenharmony_ci return; 2478c2ecf20Sopenharmony_ci } 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci omap_smc1(smc_op, val); 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ciint __init omap_l2_cache_init(void) 2538c2ecf20Sopenharmony_ci{ 2548c2ecf20Sopenharmony_ci /* Static mapping, never released */ 2558c2ecf20Sopenharmony_ci l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K); 2568c2ecf20Sopenharmony_ci if (WARN_ON(!l2cache_base)) 2578c2ecf20Sopenharmony_ci return -ENOMEM; 2588c2ecf20Sopenharmony_ci return 0; 2598c2ecf20Sopenharmony_ci} 2608c2ecf20Sopenharmony_ci#endif 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_civoid __iomem *omap4_get_sar_ram_base(void) 2638c2ecf20Sopenharmony_ci{ 2648c2ecf20Sopenharmony_ci return sar_ram_base; 2658c2ecf20Sopenharmony_ci} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci/* 2688c2ecf20Sopenharmony_ci * SAR RAM used to save and restore the HW context in low power modes. 2698c2ecf20Sopenharmony_ci * Note that we need to initialize this very early for kexec. See 2708c2ecf20Sopenharmony_ci * omap4_mpuss_early_init(). 2718c2ecf20Sopenharmony_ci */ 2728c2ecf20Sopenharmony_civoid __init omap4_sar_ram_init(void) 2738c2ecf20Sopenharmony_ci{ 2748c2ecf20Sopenharmony_ci unsigned long sar_base; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* 2778c2ecf20Sopenharmony_ci * To avoid code running on other OMAPs in 2788c2ecf20Sopenharmony_ci * multi-omap builds 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_ci if (cpu_is_omap44xx()) 2818c2ecf20Sopenharmony_ci sar_base = OMAP44XX_SAR_RAM_BASE; 2828c2ecf20Sopenharmony_ci else if (soc_is_omap54xx()) 2838c2ecf20Sopenharmony_ci sar_base = OMAP54XX_SAR_RAM_BASE; 2848c2ecf20Sopenharmony_ci else 2858c2ecf20Sopenharmony_ci return; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci /* Static mapping, never released */ 2888c2ecf20Sopenharmony_ci sar_ram_base = ioremap(sar_base, SZ_16K); 2898c2ecf20Sopenharmony_ci if (WARN_ON(!sar_ram_base)) 2908c2ecf20Sopenharmony_ci return; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic const struct of_device_id intc_match[] = { 2948c2ecf20Sopenharmony_ci { .compatible = "ti,omap4-wugen-mpu", }, 2958c2ecf20Sopenharmony_ci { .compatible = "ti,omap5-wugen-mpu", }, 2968c2ecf20Sopenharmony_ci { }, 2978c2ecf20Sopenharmony_ci}; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_cistatic struct device_node *intc_node; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_civoid __init omap_gic_of_init(void) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci struct device_node *np; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci intc_node = of_find_matching_node(NULL, intc_match); 3068c2ecf20Sopenharmony_ci if (WARN_ON(!intc_node)) { 3078c2ecf20Sopenharmony_ci pr_err("No WUGEN found in DT, system will misbehave.\n"); 3088c2ecf20Sopenharmony_ci pr_err("UPDATE YOUR DEVICE TREE!\n"); 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */ 3128c2ecf20Sopenharmony_ci if (!cpu_is_omap446x()) 3138c2ecf20Sopenharmony_ci goto skip_errata_init; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic"); 3168c2ecf20Sopenharmony_ci gic_dist_base_addr = of_iomap(np, 0); 3178c2ecf20Sopenharmony_ci of_node_put(np); 3188c2ecf20Sopenharmony_ci WARN_ON(!gic_dist_base_addr); 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer"); 3218c2ecf20Sopenharmony_ci twd_base = of_iomap(np, 0); 3228c2ecf20Sopenharmony_ci of_node_put(np); 3238c2ecf20Sopenharmony_ci WARN_ON(!twd_base); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ciskip_errata_init: 3268c2ecf20Sopenharmony_ci irqchip_init(); 3278c2ecf20Sopenharmony_ci} 328