Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010-2011 Calxeda, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | #include <linux/clk.h> |
| 17 | #include <linux/clkdev.h> |
Rob Herring | 0583fe4 | 2013-04-10 18:27:51 -0500 | [diff] [blame] | 18 | #include <linux/clocksource.h> |
Rob Herring | 1dc737c | 2012-08-21 12:31:06 +0200 | [diff] [blame] | 19 | #include <linux/dma-mapping.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 20 | #include <linux/io.h> |
| 21 | #include <linux/irq.h> |
Rob Herring | 0529e315 | 2012-11-05 16:18:28 -0600 | [diff] [blame] | 22 | #include <linux/irqchip.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 23 | #include <linux/irqdomain.h> |
| 24 | #include <linux/of.h> |
| 25 | #include <linux/of_irq.h> |
| 26 | #include <linux/of_platform.h> |
| 27 | #include <linux/of_address.h> |
Will Deacon | bf14fc5 | 2011-06-06 12:35:46 +0100 | [diff] [blame] | 28 | #include <linux/smp.h> |
Rob Herring | 1dc737c | 2012-08-21 12:31:06 +0200 | [diff] [blame] | 29 | #include <linux/amba/bus.h> |
Prashant Gaikwad | d34bcde | 2013-01-04 12:30:55 +0530 | [diff] [blame] | 30 | #include <linux/clk-provider.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 31 | |
| 32 | #include <asm/cacheflush.h> |
Rob Herring | 63fc137 | 2013-01-31 13:28:42 -0600 | [diff] [blame] | 33 | #include <asm/cputype.h> |
Will Deacon | eb50439 | 2012-01-20 12:01:12 +0100 | [diff] [blame] | 34 | #include <asm/smp_plat.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 35 | #include <asm/hardware/cache-l2x0.h> |
| 36 | #include <asm/mach/arch.h> |
Rob Herring | 5253034 | 2012-10-27 15:38:22 -0500 | [diff] [blame] | 37 | #include <asm/mach/map.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 38 | #include <asm/mach/time.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 39 | |
| 40 | #include "core.h" |
| 41 | #include "sysregs.h" |
| 42 | |
| 43 | void __iomem *sregs_base; |
Rob Herring | 7a2848d | 2012-10-25 12:13:47 -0500 | [diff] [blame] | 44 | void __iomem *scu_base_addr; |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 45 | |
| 46 | static void __init highbank_scu_map_io(void) |
| 47 | { |
| 48 | unsigned long base; |
| 49 | |
| 50 | /* Get SCU base */ |
| 51 | asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base)); |
| 52 | |
Rob Herring | 7a2848d | 2012-10-25 12:13:47 -0500 | [diff] [blame] | 53 | scu_base_addr = ioremap(base, SZ_4K); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 56 | #define HB_JUMP_TABLE_PHYS(cpu) (0x40 + (0x10 * (cpu))) |
| 57 | #define HB_JUMP_TABLE_VIRT(cpu) phys_to_virt(HB_JUMP_TABLE_PHYS(cpu)) |
| 58 | |
| 59 | void highbank_set_cpu_jump(int cpu, void *jump_addr) |
| 60 | { |
Rob Herring | 63fc137 | 2013-01-31 13:28:42 -0600 | [diff] [blame] | 61 | cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0); |
Rob Herring | adf55f7 | 2012-01-09 15:41:58 -0600 | [diff] [blame] | 62 | writel(virt_to_phys(jump_addr), HB_JUMP_TABLE_VIRT(cpu)); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 63 | __cpuc_flush_dcache_area(HB_JUMP_TABLE_VIRT(cpu), 16); |
| 64 | outer_clean_range(HB_JUMP_TABLE_PHYS(cpu), |
| 65 | HB_JUMP_TABLE_PHYS(cpu) + 15); |
| 66 | } |
| 67 | |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 68 | #ifdef CONFIG_CACHE_L2X0 |
| 69 | static void highbank_l2x0_disable(void) |
| 70 | { |
| 71 | /* Disable PL310 L2 Cache controller */ |
| 72 | highbank_smc1(0x102, 0x0); |
| 73 | } |
| 74 | #endif |
| 75 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 76 | static void __init highbank_init_irq(void) |
| 77 | { |
Rob Herring | 0529e315 | 2012-11-05 16:18:28 -0600 | [diff] [blame] | 78 | irqchip_init(); |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 79 | |
Rob Herring | 7a2848d | 2012-10-25 12:13:47 -0500 | [diff] [blame] | 80 | if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9")) |
| 81 | highbank_scu_map_io(); |
| 82 | |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 83 | #ifdef CONFIG_CACHE_L2X0 |
| 84 | /* Enable PL310 L2 Cache controller */ |
| 85 | highbank_smc1(0x102, 0x1); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 86 | l2x0_of_init(0, ~0UL); |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 87 | outer_cache.disable = highbank_l2x0_disable; |
| 88 | #endif |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void __init highbank_timer_init(void) |
| 92 | { |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 93 | struct device_node *np; |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 94 | |
| 95 | /* Map system registers */ |
| 96 | np = of_find_compatible_node(NULL, NULL, "calxeda,hb-sregs"); |
| 97 | sregs_base = of_iomap(np, 0); |
| 98 | WARN_ON(!sregs_base); |
| 99 | |
Prashant Gaikwad | d34bcde | 2013-01-04 12:30:55 +0530 | [diff] [blame] | 100 | of_clk_init(NULL); |
Marc Zyngier | 7ac9b9e | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 101 | |
Rob Herring | da4a686 | 2013-02-06 21:17:47 -0600 | [diff] [blame] | 102 | clocksource_of_init(); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 103 | } |
| 104 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 105 | static void highbank_power_off(void) |
| 106 | { |
Rob Herring | c05ee88 | 2012-12-30 10:15:04 -0600 | [diff] [blame] | 107 | highbank_set_pwr_shutdown(); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 108 | |
| 109 | while (1) |
| 110 | cpu_do_idle(); |
| 111 | } |
| 112 | |
Rob Herring | 1dc737c | 2012-08-21 12:31:06 +0200 | [diff] [blame] | 113 | static int highbank_platform_notifier(struct notifier_block *nb, |
| 114 | unsigned long event, void *__dev) |
| 115 | { |
| 116 | struct resource *res; |
| 117 | int reg = -1; |
| 118 | struct device *dev = __dev; |
| 119 | |
| 120 | if (event != BUS_NOTIFY_ADD_DEVICE) |
| 121 | return NOTIFY_DONE; |
| 122 | |
| 123 | if (of_device_is_compatible(dev->of_node, "calxeda,hb-ahci")) |
| 124 | reg = 0xc; |
| 125 | else if (of_device_is_compatible(dev->of_node, "calxeda,hb-sdhci")) |
| 126 | reg = 0x18; |
| 127 | else if (of_device_is_compatible(dev->of_node, "arm,pl330")) |
| 128 | reg = 0x20; |
| 129 | else if (of_device_is_compatible(dev->of_node, "calxeda,hb-xgmac")) { |
| 130 | res = platform_get_resource(to_platform_device(dev), |
| 131 | IORESOURCE_MEM, 0); |
| 132 | if (res) { |
| 133 | if (res->start == 0xfff50000) |
| 134 | reg = 0; |
| 135 | else if (res->start == 0xfff51000) |
| 136 | reg = 4; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if (reg < 0) |
| 141 | return NOTIFY_DONE; |
| 142 | |
| 143 | if (of_property_read_bool(dev->of_node, "dma-coherent")) { |
| 144 | writel(0xff31, sregs_base + reg); |
| 145 | set_dma_ops(dev, &arm_coherent_dma_ops); |
| 146 | } else |
| 147 | writel(0, sregs_base + reg); |
| 148 | |
| 149 | return NOTIFY_OK; |
| 150 | } |
| 151 | |
| 152 | static struct notifier_block highbank_amba_nb = { |
| 153 | .notifier_call = highbank_platform_notifier, |
| 154 | }; |
| 155 | |
| 156 | static struct notifier_block highbank_platform_nb = { |
| 157 | .notifier_call = highbank_platform_notifier, |
| 158 | }; |
| 159 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 160 | static void __init highbank_init(void) |
| 161 | { |
| 162 | pm_power_off = highbank_power_off; |
Rob Herring | a283580c | 2012-09-17 09:55:12 -0500 | [diff] [blame] | 163 | highbank_pm_init(); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 164 | |
Rob Herring | 1dc737c | 2012-08-21 12:31:06 +0200 | [diff] [blame] | 165 | bus_register_notifier(&platform_bus_type, &highbank_platform_nb); |
| 166 | bus_register_notifier(&amba_bustype, &highbank_amba_nb); |
| 167 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 168 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 169 | } |
| 170 | |
| 171 | static const char *highbank_match[] __initconst = { |
| 172 | "calxeda,highbank", |
Rob Herring | e095c0d | 2012-10-25 12:19:52 -0500 | [diff] [blame] | 173 | "calxeda,ecx-2000", |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 174 | NULL, |
| 175 | }; |
| 176 | |
| 177 | DT_MACHINE_START(HIGHBANK, "Highbank") |
Marc Zyngier | 7ad71b6 | 2012-09-05 14:36:18 +0000 | [diff] [blame] | 178 | .smp = smp_ops(highbank_smp_ops), |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 179 | .init_irq = highbank_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 180 | .init_time = highbank_timer_init, |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 181 | .init_machine = highbank_init, |
| 182 | .dt_compat = highbank_match, |
Russell King | 00e9967 | 2011-11-05 11:16:05 +0000 | [diff] [blame] | 183 | .restart = highbank_restart, |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 184 | MACHINE_END |