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/arm_timer.h> |
| 36 | #include <asm/hardware/timer-sp.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 37 | #include <asm/hardware/cache-l2x0.h> |
| 38 | #include <asm/mach/arch.h> |
Rob Herring | 5253034 | 2012-10-27 15:38:22 -0500 | [diff] [blame] | 39 | #include <asm/mach/map.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 40 | #include <asm/mach/time.h> |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 41 | |
| 42 | #include "core.h" |
| 43 | #include "sysregs.h" |
| 44 | |
| 45 | void __iomem *sregs_base; |
Rob Herring | 7a2848d | 2012-10-25 12:13:47 -0500 | [diff] [blame] | 46 | void __iomem *scu_base_addr; |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 47 | |
| 48 | static void __init highbank_scu_map_io(void) |
| 49 | { |
| 50 | unsigned long base; |
| 51 | |
| 52 | /* Get SCU base */ |
| 53 | asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base)); |
| 54 | |
Rob Herring | 7a2848d | 2012-10-25 12:13:47 -0500 | [diff] [blame] | 55 | scu_base_addr = ioremap(base, SZ_4K); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 58 | #define HB_JUMP_TABLE_PHYS(cpu) (0x40 + (0x10 * (cpu))) |
| 59 | #define HB_JUMP_TABLE_VIRT(cpu) phys_to_virt(HB_JUMP_TABLE_PHYS(cpu)) |
| 60 | |
| 61 | void highbank_set_cpu_jump(int cpu, void *jump_addr) |
| 62 | { |
Rob Herring | 63fc137 | 2013-01-31 13:28:42 -0600 | [diff] [blame] | 63 | cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0); |
Rob Herring | adf55f7 | 2012-01-09 15:41:58 -0600 | [diff] [blame] | 64 | writel(virt_to_phys(jump_addr), HB_JUMP_TABLE_VIRT(cpu)); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 65 | __cpuc_flush_dcache_area(HB_JUMP_TABLE_VIRT(cpu), 16); |
| 66 | outer_clean_range(HB_JUMP_TABLE_PHYS(cpu), |
| 67 | HB_JUMP_TABLE_PHYS(cpu) + 15); |
| 68 | } |
| 69 | |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 70 | #ifdef CONFIG_CACHE_L2X0 |
| 71 | static void highbank_l2x0_disable(void) |
| 72 | { |
| 73 | /* Disable PL310 L2 Cache controller */ |
| 74 | highbank_smc1(0x102, 0x0); |
| 75 | } |
| 76 | #endif |
| 77 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 78 | static void __init highbank_init_irq(void) |
| 79 | { |
Rob Herring | 0529e315 | 2012-11-05 16:18:28 -0600 | [diff] [blame] | 80 | irqchip_init(); |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 81 | |
Rob Herring | 7a2848d | 2012-10-25 12:13:47 -0500 | [diff] [blame] | 82 | if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9")) |
| 83 | highbank_scu_map_io(); |
| 84 | |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 85 | #ifdef CONFIG_CACHE_L2X0 |
| 86 | /* Enable PL310 L2 Cache controller */ |
| 87 | highbank_smc1(0x102, 0x1); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 88 | l2x0_of_init(0, ~0UL); |
Rob Herring | 8e56130 | 2012-06-06 17:20:10 -0500 | [diff] [blame] | 89 | outer_cache.disable = highbank_l2x0_disable; |
| 90 | #endif |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Rob Herring | 8d4d9f5 | 2012-03-13 18:19:19 -0500 | [diff] [blame] | 93 | static struct clk_lookup lookup = { |
| 94 | .dev_id = "sp804", |
| 95 | .con_id = NULL, |
| 96 | }; |
| 97 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 98 | static void __init highbank_timer_init(void) |
| 99 | { |
| 100 | int irq; |
| 101 | struct device_node *np; |
| 102 | void __iomem *timer_base; |
| 103 | |
| 104 | /* Map system registers */ |
| 105 | np = of_find_compatible_node(NULL, NULL, "calxeda,hb-sregs"); |
| 106 | sregs_base = of_iomap(np, 0); |
| 107 | WARN_ON(!sregs_base); |
| 108 | |
| 109 | np = of_find_compatible_node(NULL, NULL, "arm,sp804"); |
| 110 | timer_base = of_iomap(np, 0); |
| 111 | WARN_ON(!timer_base); |
| 112 | irq = irq_of_parse_and_map(np, 0); |
| 113 | |
Prashant Gaikwad | d34bcde | 2013-01-04 12:30:55 +0530 | [diff] [blame] | 114 | of_clk_init(NULL); |
Rob Herring | 8d4d9f5 | 2012-03-13 18:19:19 -0500 | [diff] [blame] | 115 | lookup.clk = of_clk_get(np, 0); |
| 116 | clkdev_add(&lookup); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 117 | |
Rob Herring | f3b7cd2 | 2012-01-16 08:06:09 -0600 | [diff] [blame] | 118 | sp804_clocksource_and_sched_clock_init(timer_base + 0x20, "timer1"); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 119 | sp804_clockevents_init(timer_base, irq, "timer0"); |
Marc Zyngier | 7ac9b9e | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 120 | |
Rob Herring | da4a686 | 2013-02-06 21:17:47 -0600 | [diff] [blame] | 121 | clocksource_of_init(); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 124 | static void highbank_power_off(void) |
| 125 | { |
Rob Herring | c05ee88 | 2012-12-30 10:15:04 -0600 | [diff] [blame] | 126 | highbank_set_pwr_shutdown(); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 127 | |
| 128 | while (1) |
| 129 | cpu_do_idle(); |
| 130 | } |
| 131 | |
Rob Herring | 1dc737c | 2012-08-21 12:31:06 +0200 | [diff] [blame] | 132 | static int highbank_platform_notifier(struct notifier_block *nb, |
| 133 | unsigned long event, void *__dev) |
| 134 | { |
| 135 | struct resource *res; |
| 136 | int reg = -1; |
| 137 | struct device *dev = __dev; |
| 138 | |
| 139 | if (event != BUS_NOTIFY_ADD_DEVICE) |
| 140 | return NOTIFY_DONE; |
| 141 | |
| 142 | if (of_device_is_compatible(dev->of_node, "calxeda,hb-ahci")) |
| 143 | reg = 0xc; |
| 144 | else if (of_device_is_compatible(dev->of_node, "calxeda,hb-sdhci")) |
| 145 | reg = 0x18; |
| 146 | else if (of_device_is_compatible(dev->of_node, "arm,pl330")) |
| 147 | reg = 0x20; |
| 148 | else if (of_device_is_compatible(dev->of_node, "calxeda,hb-xgmac")) { |
| 149 | res = platform_get_resource(to_platform_device(dev), |
| 150 | IORESOURCE_MEM, 0); |
| 151 | if (res) { |
| 152 | if (res->start == 0xfff50000) |
| 153 | reg = 0; |
| 154 | else if (res->start == 0xfff51000) |
| 155 | reg = 4; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | if (reg < 0) |
| 160 | return NOTIFY_DONE; |
| 161 | |
| 162 | if (of_property_read_bool(dev->of_node, "dma-coherent")) { |
| 163 | writel(0xff31, sregs_base + reg); |
| 164 | set_dma_ops(dev, &arm_coherent_dma_ops); |
| 165 | } else |
| 166 | writel(0, sregs_base + reg); |
| 167 | |
| 168 | return NOTIFY_OK; |
| 169 | } |
| 170 | |
| 171 | static struct notifier_block highbank_amba_nb = { |
| 172 | .notifier_call = highbank_platform_notifier, |
| 173 | }; |
| 174 | |
| 175 | static struct notifier_block highbank_platform_nb = { |
| 176 | .notifier_call = highbank_platform_notifier, |
| 177 | }; |
| 178 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 179 | static void __init highbank_init(void) |
| 180 | { |
| 181 | pm_power_off = highbank_power_off; |
Rob Herring | a283580c | 2012-09-17 09:55:12 -0500 | [diff] [blame] | 182 | highbank_pm_init(); |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 183 | |
Rob Herring | 1dc737c | 2012-08-21 12:31:06 +0200 | [diff] [blame] | 184 | bus_register_notifier(&platform_bus_type, &highbank_platform_nb); |
| 185 | bus_register_notifier(&amba_bustype, &highbank_amba_nb); |
| 186 | |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 187 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 188 | } |
| 189 | |
| 190 | static const char *highbank_match[] __initconst = { |
| 191 | "calxeda,highbank", |
Rob Herring | e095c0d | 2012-10-25 12:19:52 -0500 | [diff] [blame] | 192 | "calxeda,ecx-2000", |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 193 | NULL, |
| 194 | }; |
| 195 | |
| 196 | DT_MACHINE_START(HIGHBANK, "Highbank") |
Marc Zyngier | 7ad71b6 | 2012-09-05 14:36:18 +0000 | [diff] [blame] | 197 | .smp = smp_ops(highbank_smp_ops), |
Rob Herring | 5253034 | 2012-10-27 15:38:22 -0500 | [diff] [blame] | 198 | .map_io = debug_ll_io_init, |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 199 | .init_irq = highbank_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 200 | .init_time = highbank_timer_init, |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 201 | .init_machine = highbank_init, |
| 202 | .dt_compat = highbank_match, |
Russell King | 00e9967 | 2011-11-05 11:16:05 +0000 | [diff] [blame] | 203 | .restart = highbank_restart, |
Rob Herring | 220e6cf | 2011-06-07 10:02:55 -0500 | [diff] [blame] | 204 | MACHINE_END |