1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Keystone2 based boards and SOC related code. 4 * 5 * Copyright 2013 Texas Instruments, Inc. 6 * Cyril Chemparathy <cyril@ti.com> 7 * Santosh Shilimkar <santosh.shillimkar@ti.com> 8 */ 9 #include <linux/io.h> 10 #include <linux/of.h> 11 #include <linux/dma-map-ops.h> 12 #include <linux/init.h> 13 #include <linux/of_platform.h> 14 #include <linux/of_address.h> 15 #include <linux/memblock.h> 16 17 #include <asm/setup.h> 18 #include <asm/mach/map.h> 19 #include <asm/mach/arch.h> 20 #include <asm/mach/time.h> 21 #include <asm/page.h> 22 23 #include "memory.h" 24 25 #include "keystone.h" 26 27 #ifdef CONFIG_ARM_LPAE 28 static int keystone_platform_notifier(struct notifier_block *nb, 29 unsigned long event, void *data) 30 { 31 struct device *dev = data; 32 33 if (event != BUS_NOTIFY_ADD_DEVICE) 34 return NOTIFY_DONE; 35 36 if (!dev) 37 return NOTIFY_BAD; 38 39 if (!dev->of_node) { 40 int ret = dma_direct_set_offset(dev, KEYSTONE_HIGH_PHYS_START, 41 KEYSTONE_LOW_PHYS_START, 42 KEYSTONE_HIGH_PHYS_SIZE); 43 dev_err(dev, "set dma_offset%08llx%s\n", 44 KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START, 45 ret ? " failed" : ""); 46 } 47 return NOTIFY_OK; 48 } 49 50 static struct notifier_block platform_nb = { 51 .notifier_call = keystone_platform_notifier, 52 }; 53 #endif /* CONFIG_ARM_LPAE */ 54 55 static void __init keystone_init(void) 56 { 57 #ifdef CONFIG_ARM_LPAE 58 if (PHYS_OFFSET >= KEYSTONE_HIGH_PHYS_START) 59 bus_register_notifier(&platform_bus_type, &platform_nb); 60 #endif 61 keystone_pm_runtime_init(); 62 } 63 64 static long long __init keystone_pv_fixup(void) 65 { 66 long long offset; 67 u64 mem_start, mem_end; 68 69 mem_start = memblock_start_of_DRAM(); 70 mem_end = memblock_end_of_DRAM(); 71 72 /* nothing to do if we are running out of the <32-bit space */ 73 if (mem_start >= KEYSTONE_LOW_PHYS_START && 74 mem_end <= KEYSTONE_LOW_PHYS_END) 75 return 0; 76 77 if (mem_start < KEYSTONE_HIGH_PHYS_START || 78 mem_end > KEYSTONE_HIGH_PHYS_END) { 79 pr_crit("Invalid address space for memory (%08llx-%08llx)\n", 80 mem_start, mem_end); 81 return 0; 82 } 83 84 offset = KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START; 85 86 /* Populate the arch idmap hook */ 87 arch_phys_to_idmap_offset = -offset; 88 89 return offset; 90 } 91 92 static const char *const keystone_match[] __initconst = { 93 "ti,k2hk", 94 "ti,k2e", 95 "ti,k2l", 96 "ti,k2g", 97 "ti,keystone", 98 NULL, 99 }; 100 101 DT_MACHINE_START(KEYSTONE, "Keystone") 102 #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE) 103 .dma_zone_size = SZ_2G, 104 #endif 105 .init_machine = keystone_init, 106 .dt_compat = keystone_match, 107 .pv_fixup = keystone_pv_fixup, 108 MACHINE_END 109