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 | f07cb6a0 | 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 | f07cb6a0 | 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 unsigned long keystone_dma_pfn_offset __read_mostly; |
| 31 | |
| 32 | static int keystone_platform_notifier(struct notifier_block *nb, |
| 33 | unsigned long event, void *data) |
| 34 | { |
| 35 | struct device *dev = data; |
| 36 | |
| 37 | if (event != BUS_NOTIFY_ADD_DEVICE) |
| 38 | return NOTIFY_DONE; |
| 39 | |
| 40 | if (!dev) |
| 41 | return NOTIFY_BAD; |
| 42 | |
| 43 | if (!dev->of_node) { |
| 44 | dev->dma_pfn_offset = keystone_dma_pfn_offset; |
| 45 | dev_err(dev, "set dma_pfn_offset%08lx\n", |
| 46 | dev->dma_pfn_offset); |
| 47 | } |
| 48 | return NOTIFY_OK; |
| 49 | } |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 50 | |
Russell King | 30b5f4d | 2015-04-04 11:30:04 +0100 | [diff] [blame] | 51 | static struct notifier_block platform_nb = { |
| 52 | .notifier_call = keystone_platform_notifier, |
| 53 | }; |
| 54 | |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 55 | static void __init keystone_init(void) |
| 56 | { |
Russell King | 30b5f4d | 2015-04-04 11:30:04 +0100 | [diff] [blame] | 57 | if (PHYS_OFFSET >= KEYSTONE_HIGH_PHYS_START) { |
| 58 | keystone_dma_pfn_offset = PFN_DOWN(KEYSTONE_HIGH_PHYS_START - |
| 59 | KEYSTONE_LOW_PHYS_START); |
Santosh Shilimkar | 14f3791 | 2014-02-24 17:32:59 +0200 | [diff] [blame] | 60 | bus_register_notifier(&platform_bus_type, &platform_nb); |
Russell King | 30b5f4d | 2015-04-04 11:30:04 +0100 | [diff] [blame] | 61 | } |
| 62 | keystone_pm_runtime_init(); |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 63 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 64 | } |
| 65 | |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 66 | static phys_addr_t keystone_virt_to_idmap(unsigned long x) |
| 67 | { |
| 68 | return (phys_addr_t)(x) - CONFIG_PAGE_OFFSET + KEYSTONE_LOW_PHYS_START; |
| 69 | } |
| 70 | |
Russell King | c0b759d | 2015-04-04 10:01:10 +0100 | [diff] [blame] | 71 | static long long __init keystone_pv_fixup(void) |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 72 | { |
Russell King | c8ca2b4 | 2015-04-04 09:53:38 +0100 | [diff] [blame] | 73 | long long offset; |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 74 | phys_addr_t mem_start, mem_end; |
| 75 | |
Santosh Shilimkar | bbea06f | 2014-06-05 15:22:52 -0400 | [diff] [blame] | 76 | mem_start = memblock_start_of_DRAM(); |
| 77 | mem_end = memblock_end_of_DRAM(); |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 78 | |
| 79 | /* nothing to do if we are running out of the <32-bit space */ |
| 80 | if (mem_start >= KEYSTONE_LOW_PHYS_START && |
| 81 | mem_end <= KEYSTONE_LOW_PHYS_END) |
Russell King | c8ca2b4 | 2015-04-04 09:53:38 +0100 | [diff] [blame] | 82 | return 0; |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 83 | |
| 84 | if (mem_start < KEYSTONE_HIGH_PHYS_START || |
| 85 | mem_end > KEYSTONE_HIGH_PHYS_END) { |
| 86 | pr_crit("Invalid address space for memory (%08llx-%08llx)\n", |
Russell King | c8ca2b4 | 2015-04-04 09:53:38 +0100 | [diff] [blame] | 87 | (u64)mem_start, (u64)mem_end); |
| 88 | return 0; |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Russell King | c8ca2b4 | 2015-04-04 09:53:38 +0100 | [diff] [blame] | 91 | offset = KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START; |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 92 | |
| 93 | /* Populate the arch idmap hook */ |
| 94 | arch_virt_to_idmap = keystone_virt_to_idmap; |
| 95 | |
Russell King | c8ca2b4 | 2015-04-04 09:53:38 +0100 | [diff] [blame] | 96 | return offset; |
Santosh Shilimkar | 5eb3da7 | 2013-06-13 19:24:39 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Uwe Kleine-König | 543c504 | 2015-02-18 21:01:45 +0100 | [diff] [blame] | 99 | static const char *const keystone_match[] __initconst = { |
Nishanth Menon | 01cf228 | 2015-10-03 17:02:56 -0700 | [diff] [blame] | 100 | "ti,k2hk", |
| 101 | "ti,k2e", |
| 102 | "ti,k2l", |
Ivan Khoronzhuk | 3babe30 | 2014-03-20 17:00:27 -0400 | [diff] [blame] | 103 | "ti,keystone", |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 104 | NULL, |
| 105 | }; |
| 106 | |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 107 | DT_MACHINE_START(KEYSTONE, "Keystone") |
Santosh Shilimkar | df595a9 | 2013-11-23 16:58:03 -0500 | [diff] [blame] | 108 | #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE) |
| 109 | .dma_zone_size = SZ_2G, |
| 110 | #endif |
Santosh Shilimkar | f07cb6a0 | 2013-06-10 12:20:17 -0400 | [diff] [blame] | 111 | .smp = smp_ops(keystone_smp_ops), |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 112 | .init_machine = keystone_init, |
| 113 | .dt_compat = keystone_match, |
Russell King | c0b759d | 2015-04-04 10:01:10 +0100 | [diff] [blame] | 114 | .pv_fixup = keystone_pv_fixup, |
Santosh Shilimkar | 828989a | 2013-06-10 11:27:13 -0400 | [diff] [blame] | 115 | MACHINE_END |