18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Device Tree support for MStar/Sigmastar Armv7 SoCs 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2020 thingy.jp 68c2ecf20Sopenharmony_ci * Author: Daniel Palmer <daniel@thingy.jp> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <asm/mach/arch.h> 118c2ecf20Sopenharmony_ci#include <asm/mach/map.h> 128c2ecf20Sopenharmony_ci#include <linux/of.h> 138c2ecf20Sopenharmony_ci#include <linux/of_address.h> 148c2ecf20Sopenharmony_ci#include <linux/io.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* 178c2ecf20Sopenharmony_ci * In the u-boot code the area these registers are in is 188c2ecf20Sopenharmony_ci * called "L3 bridge" and there are register descriptions 198c2ecf20Sopenharmony_ci * for something in the same area called "AXI". 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * It's not exactly known what this is but the vendor code 228c2ecf20Sopenharmony_ci * for both u-boot and linux share calls to "flush the miu pipe". 238c2ecf20Sopenharmony_ci * This seems to be to force pending CPU writes to memory so that 248c2ecf20Sopenharmony_ci * the state is right before DMA capable devices try to read 258c2ecf20Sopenharmony_ci * descriptors and data the CPU has prepared. Without doing this 268c2ecf20Sopenharmony_ci * ethernet doesn't work reliably for example. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define MSTARV7_L3BRIDGE_FLUSH 0x14 308c2ecf20Sopenharmony_ci#define MSTARV7_L3BRIDGE_STATUS 0x40 318c2ecf20Sopenharmony_ci#define MSTARV7_L3BRIDGE_FLUSH_TRIGGER BIT(0) 328c2ecf20Sopenharmony_ci#define MSTARV7_L3BRIDGE_STATUS_DONE BIT(12) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic void __iomem *l3bridge; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic const char * const mstarv7_board_dt_compat[] __initconst = { 378c2ecf20Sopenharmony_ci "mstar,infinity", 388c2ecf20Sopenharmony_ci "mstar,infinity3", 398c2ecf20Sopenharmony_ci "mstar,mercury5", 408c2ecf20Sopenharmony_ci NULL, 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * This may need locking to deal with situations where an interrupt 458c2ecf20Sopenharmony_ci * happens while we are in here and mb() gets called by the interrupt handler. 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci * The vendor code did have a spin lock but it doesn't seem to be needed and 488c2ecf20Sopenharmony_ci * removing it hasn't caused any side effects so far. 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * [writel|readl]_relaxed have to be used here because otherwise 518c2ecf20Sopenharmony_ci * we'd end up right back in here. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_cistatic void mstarv7_mb(void) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci /* toggle the flush miu pipe fire bit */ 568c2ecf20Sopenharmony_ci writel_relaxed(0, l3bridge + MSTARV7_L3BRIDGE_FLUSH); 578c2ecf20Sopenharmony_ci writel_relaxed(MSTARV7_L3BRIDGE_FLUSH_TRIGGER, l3bridge 588c2ecf20Sopenharmony_ci + MSTARV7_L3BRIDGE_FLUSH); 598c2ecf20Sopenharmony_ci while (!(readl_relaxed(l3bridge + MSTARV7_L3BRIDGE_STATUS) 608c2ecf20Sopenharmony_ci & MSTARV7_L3BRIDGE_STATUS_DONE)) { 618c2ecf20Sopenharmony_ci /* wait for flush to complete */ 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic void __init mstarv7_init(void) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci struct device_node *np; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci np = of_find_compatible_node(NULL, NULL, "mstar,l3bridge"); 708c2ecf20Sopenharmony_ci l3bridge = of_iomap(np, 0); 718c2ecf20Sopenharmony_ci if (l3bridge) 728c2ecf20Sopenharmony_ci soc_mb = mstarv7_mb; 738c2ecf20Sopenharmony_ci else 748c2ecf20Sopenharmony_ci pr_warn("Failed to install memory barrier, DMA will be broken!\n"); 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciDT_MACHINE_START(MSTARV7_DT, "MStar/Sigmastar Armv7 (Device Tree)") 788c2ecf20Sopenharmony_ci .dt_compat = mstarv7_board_dt_compat, 798c2ecf20Sopenharmony_ci .init_machine = mstarv7_init, 808c2ecf20Sopenharmony_ciMACHINE_END 81