Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Keystone2 based boards and SOC related code.
0004  *
0005  * Copyright 2013 Texas Instruments, Inc.
0006  *  Cyril Chemparathy <cyril@ti.com>
0007  *  Santosh Shilimkar <santosh.shillimkar@ti.com>
0008  */
0009 #include <linux/io.h>
0010 #include <linux/of.h>
0011 #include <linux/dma-map-ops.h>
0012 #include <linux/init.h>
0013 #include <linux/of_platform.h>
0014 #include <linux/of_address.h>
0015 #include <linux/memblock.h>
0016 
0017 #include <asm/setup.h>
0018 #include <asm/mach/map.h>
0019 #include <asm/mach/arch.h>
0020 #include <asm/mach/time.h>
0021 #include <asm/smp_plat.h>
0022 #include <asm/memory.h>
0023 
0024 #include "memory.h"
0025 
0026 #include "keystone.h"
0027 
0028 #ifdef CONFIG_ARM_LPAE
0029 static int keystone_platform_notifier(struct notifier_block *nb,
0030                       unsigned long event, void *data)
0031 {
0032     struct device *dev = data;
0033 
0034     if (event != BUS_NOTIFY_ADD_DEVICE)
0035         return NOTIFY_DONE;
0036 
0037     if (!dev)
0038         return NOTIFY_BAD;
0039 
0040     if (!dev->of_node) {
0041         int ret = dma_direct_set_offset(dev, KEYSTONE_HIGH_PHYS_START,
0042                         KEYSTONE_LOW_PHYS_START,
0043                         KEYSTONE_HIGH_PHYS_SIZE);
0044         dev_err(dev, "set dma_offset%08llx%s\n",
0045             KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START,
0046             ret ? " failed" : "");
0047     }
0048     return NOTIFY_OK;
0049 }
0050 
0051 static struct notifier_block platform_nb = {
0052     .notifier_call = keystone_platform_notifier,
0053 };
0054 #endif /* CONFIG_ARM_LPAE */
0055 
0056 static void __init keystone_init(void)
0057 {
0058 #ifdef CONFIG_ARM_LPAE
0059     if (PHYS_OFFSET >= KEYSTONE_HIGH_PHYS_START)
0060         bus_register_notifier(&platform_bus_type, &platform_nb);
0061 #endif
0062     keystone_pm_runtime_init();
0063 }
0064 
0065 static long long __init keystone_pv_fixup(void)
0066 {
0067     long long offset;
0068     u64 mem_start, mem_end;
0069 
0070     mem_start = memblock_start_of_DRAM();
0071     mem_end = memblock_end_of_DRAM();
0072 
0073     /* nothing to do if we are running out of the <32-bit space */
0074     if (mem_start >= KEYSTONE_LOW_PHYS_START &&
0075         mem_end   <= KEYSTONE_LOW_PHYS_END)
0076         return 0;
0077 
0078     if (mem_start < KEYSTONE_HIGH_PHYS_START ||
0079         mem_end   > KEYSTONE_HIGH_PHYS_END) {
0080         pr_crit("Invalid address space for memory (%08llx-%08llx)\n",
0081                 mem_start, mem_end);
0082         return 0;
0083     }
0084 
0085     offset = KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START;
0086 
0087     /* Populate the arch idmap hook */
0088     arch_phys_to_idmap_offset = -offset;
0089 
0090     return offset;
0091 }
0092 
0093 static const char *const keystone_match[] __initconst = {
0094     "ti,k2hk",
0095     "ti,k2e",
0096     "ti,k2l",
0097     "ti,k2g",
0098     "ti,keystone",
0099     NULL,
0100 };
0101 
0102 DT_MACHINE_START(KEYSTONE, "Keystone")
0103 #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE)
0104     .dma_zone_size  = SZ_2G,
0105 #endif
0106     .smp        = smp_ops(keystone_smp_ops),
0107     .init_machine   = keystone_init,
0108     .dt_compat  = keystone_match,
0109     .pv_fixup   = keystone_pv_fixup,
0110 MACHINE_END