Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Keystone2 based boards and SOC related code. |
| 3 | * |
| 4 | * Copyright 2013 Texas Instruments, Inc. |
| 5 | * Cyril Chemparathy <cyril@ti.com> |
| 6 | * Santosh Shilimkar <santosh.shillimkar@ti.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | */ |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/of.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/of_platform.h> |
| 16 | #include <linux/of_address.h> |
Santosh Shilimkar | bbea06f | 2014-06-05 15:22:52 -0400 | [diff] [blame] | 17 | #include <linux/memblock.h> |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 18 | |
| 19 | #include <asm/setup.h> |
| 20 | #include <asm/mach/map.h> |
| 21 | #include <asm/mach/arch.h> |
| 22 | #include <asm/mach/time.h> |
Santosh Shilimkar | f07cb6a | 2013-06-10 12:20:17 -0400 | [diff] [blame] | 23 | #include <asm/smp_plat.h> |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 24 | #include <asm/memory.h> |
| 25 | |
| 26 | #include "memory.h" |
Santosh Shilimkar | f07cb6a | 2013-06-10 12:20:17 -0400 | [diff] [blame] | 27 | |
| 28 | #include "keystone.h" |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 29 | |
Santosh Shilimkar | 14f3791 | 2014-02-24 17:32:59 +0200 | [diff] [blame] | 30 | static struct notifier_block platform_nb; |
| 31 | static unsigned long keystone_dma_pfn_offset __read_mostly; |
| 32 | |
| 33 | static int keystone_platform_notifier(struct notifier_block *nb, |
| 34 | unsigned long event, void *data) |
| 35 | { |
| 36 | struct device *dev = data; |
| 37 | |
| 38 | if (event != BUS_NOTIFY_ADD_DEVICE) |
| 39 | return NOTIFY_DONE; |
| 40 | |
| 41 | if (!dev) |
| 42 | return NOTIFY_BAD; |
| 43 | |
| 44 | if (!dev->of_node) { |
| 45 | dev->dma_pfn_offset = keystone_dma_pfn_offset; |
| 46 | dev_err(dev, "set dma_pfn_offset%08lx\n", |
| 47 | dev->dma_pfn_offset); |
| 48 | } |
| 49 | return NOTIFY_OK; |
| 50 | } |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 51 | |
| 52 | static void __init keystone_init(void) |
| 53 | { |
Santosh Shilimkar | 8308a78 | 2013-11-23 17:08:03 -0500 | [diff] [blame] | 54 | keystone_pm_runtime_init(); |
Santosh Shilimkar | 14f3791 | 2014-02-24 17:32:59 +0200 | [diff] [blame] | 55 | if (platform_nb.notifier_call) |
| 56 | bus_register_notifier(&platform_bus_type, &platform_nb); |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 57 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 58 | } |
| 59 | |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 60 | static phys_addr_t keystone_virt_to_idmap(unsigned long x) |
| 61 | { |
| 62 | return (phys_addr_t)(x) - CONFIG_PAGE_OFFSET + KEYSTONE_LOW_PHYS_START; |
| 63 | } |
| 64 | |
| 65 | static void __init keystone_init_meminfo(void) |
| 66 | { |
| 67 | bool lpae = IS_ENABLED(CONFIG_ARM_LPAE); |
| 68 | bool pvpatch = IS_ENABLED(CONFIG_ARM_PATCH_PHYS_VIRT); |
| 69 | phys_addr_t offset = PHYS_OFFSET - KEYSTONE_LOW_PHYS_START; |
| 70 | phys_addr_t mem_start, mem_end; |
| 71 | |
Santosh Shilimkar | bbea06f | 2014-06-05 15:22:52 -0400 | [diff] [blame] | 72 | mem_start = memblock_start_of_DRAM(); |
| 73 | mem_end = memblock_end_of_DRAM(); |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 74 | |
| 75 | /* nothing to do if we are running out of the <32-bit space */ |
| 76 | if (mem_start >= KEYSTONE_LOW_PHYS_START && |
| 77 | mem_end <= KEYSTONE_LOW_PHYS_END) |
| 78 | return; |
| 79 | |
| 80 | if (!lpae || !pvpatch) { |
| 81 | pr_crit("Enable %s%s%s to run outside 32-bit space\n", |
| 82 | !lpae ? __stringify(CONFIG_ARM_LPAE) : "", |
| 83 | (!lpae && !pvpatch) ? " and " : "", |
| 84 | !pvpatch ? __stringify(CONFIG_ARM_PATCH_PHYS_VIRT) : ""); |
| 85 | } |
| 86 | |
| 87 | if (mem_start < KEYSTONE_HIGH_PHYS_START || |
| 88 | mem_end > KEYSTONE_HIGH_PHYS_END) { |
| 89 | pr_crit("Invalid address space for memory (%08llx-%08llx)\n", |
| 90 | (u64)mem_start, (u64)mem_end); |
| 91 | } |
| 92 | |
| 93 | offset += KEYSTONE_HIGH_PHYS_START; |
| 94 | __pv_phys_pfn_offset = PFN_DOWN(offset); |
| 95 | __pv_offset = (offset - PAGE_OFFSET); |
| 96 | |
| 97 | /* Populate the arch idmap hook */ |
| 98 | arch_virt_to_idmap = keystone_virt_to_idmap; |
Santosh Shilimkar | 14f3791 | 2014-02-24 17:32:59 +0200 | [diff] [blame] | 99 | platform_nb.notifier_call = keystone_platform_notifier; |
| 100 | keystone_dma_pfn_offset = PFN_DOWN(KEYSTONE_HIGH_PHYS_START - |
| 101 | KEYSTONE_LOW_PHYS_START); |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 102 | |
| 103 | pr_info("Switching to high address space at 0x%llx\n", (u64)offset); |
| 104 | } |
| 105 | |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 106 | static const char *keystone_match[] __initconst = { |
Ivan Khoronzhuk | 3babe30 | 2014-03-20 17:00:27 -0400 | [diff] [blame] | 107 | "ti,keystone", |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 108 | NULL, |
| 109 | }; |
| 110 | |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 111 | DT_MACHINE_START(KEYSTONE, "Keystone") |
Santosh Shilimkar | df595a9 | 2013-11-23 16:58:03 -0500 | [diff] [blame] | 112 | #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE) |
| 113 | .dma_zone_size = SZ_2G, |
| 114 | #endif |
Santosh Shilimkar | f07cb6a | 2013-06-10 12:20:17 -0400 | [diff] [blame] | 115 | .smp = smp_ops(keystone_smp_ops), |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 116 | .init_machine = keystone_init, |
| 117 | .dt_compat = keystone_match, |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 118 | .init_meminfo = keystone_init_meminfo, |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 119 | MACHINE_END |