Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net> |
| 3 | * |
| 4 | * arch/arm/mach-kirkwood/board-dt.c |
| 5 | * |
Jason Cooper | 6fa6b87 | 2012-03-15 00:52:31 +0000 | [diff] [blame] | 6 | * Flattened Device Tree board initialization |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public |
| 9 | * License version 2. This program is licensed "as is" without any |
| 10 | * warranty of any kind, whether express or implied. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 15 | #include <linux/of.h> |
Sebastian Hesselbarth | ebd7d3a | 2013-10-07 22:25:11 +0200 | [diff] [blame] | 16 | #include <linux/of_address.h> |
| 17 | #include <linux/of_net.h> |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 18 | #include <linux/of_platform.h> |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 19 | #include <linux/clk-provider.h> |
Sebastian Hesselbarth | 2326f04 | 2013-07-02 15:15:07 +0200 | [diff] [blame] | 20 | #include <linux/dma-mapping.h> |
| 21 | #include <linux/irqchip.h> |
Ian Campbell | a7ac56d | 2012-04-29 14:40:42 +0100 | [diff] [blame] | 22 | #include <linux/kexec.h> |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 23 | #include <asm/mach/arch.h> |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 24 | #include <asm/mach/map.h> |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 25 | #include <mach/bridge-regs.h> |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 26 | #include <linux/platform_data/usb-ehci-orion.h> |
Andrew Lunn | 278b45b | 2012-06-27 13:40:04 +0200 | [diff] [blame] | 27 | #include <plat/irq.h> |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 28 | #include <plat/common.h> |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 29 | #include "common.h" |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 30 | |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 31 | /* |
| 32 | * There are still devices that doesn't know about DT yet. Get clock |
| 33 | * gates here and add a clock lookup alias, so that old platform |
| 34 | * devices still work. |
| 35 | */ |
| 36 | |
| 37 | static void __init kirkwood_legacy_clk_init(void) |
| 38 | { |
| 39 | |
| 40 | struct device_node *np = of_find_compatible_node( |
| 41 | NULL, NULL, "marvell,kirkwood-gating-clock"); |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 42 | struct of_phandle_args clkspec; |
Sebastian Hesselbarth | 7bf5b40 | 2013-01-30 21:29:58 +0100 | [diff] [blame] | 43 | struct clk *clk; |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 44 | |
| 45 | clkspec.np = np; |
| 46 | clkspec.args_count = 1; |
| 47 | |
Sebastian Hesselbarth | 7bf5b40 | 2013-01-30 21:29:58 +0100 | [diff] [blame] | 48 | /* |
| 49 | * The ethernet interfaces forget the MAC address assigned by |
| 50 | * u-boot if the clocks are turned off. Until proper DT support |
| 51 | * is available we always enable them for now. |
| 52 | */ |
| 53 | clkspec.args[0] = CGC_BIT_GE0; |
| 54 | clk = of_clk_get_from_provider(&clkspec); |
Sebastian Hesselbarth | 7bf5b40 | 2013-01-30 21:29:58 +0100 | [diff] [blame] | 55 | clk_prepare_enable(clk); |
| 56 | |
| 57 | clkspec.args[0] = CGC_BIT_GE1; |
| 58 | clk = of_clk_get_from_provider(&clkspec); |
Sebastian Hesselbarth | 7bf5b40 | 2013-01-30 21:29:58 +0100 | [diff] [blame] | 59 | clk_prepare_enable(clk); |
Andrew Lunn | 1611f87 | 2012-11-17 15:22:28 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Sebastian Hesselbarth | ebd7d3a | 2013-10-07 22:25:11 +0200 | [diff] [blame] | 62 | #define MV643XX_ETH_MAC_ADDR_LOW 0x0414 |
| 63 | #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418 |
| 64 | |
| 65 | static void __init kirkwood_dt_eth_fixup(void) |
| 66 | { |
| 67 | struct device_node *np; |
| 68 | |
| 69 | /* |
| 70 | * The ethernet interfaces forget the MAC address assigned by u-boot |
| 71 | * if the clocks are turned off. Usually, u-boot on kirkwood boards |
| 72 | * has no DT support to properly set local-mac-address property. |
| 73 | * As a workaround, we get the MAC address from mv643xx_eth registers |
| 74 | * and update the port device node if no valid MAC address is set. |
| 75 | */ |
| 76 | for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") { |
| 77 | struct device_node *pnp = of_get_parent(np); |
| 78 | struct clk *clk; |
| 79 | struct property *pmac; |
| 80 | void __iomem *io; |
| 81 | u8 *macaddr; |
| 82 | u32 reg; |
| 83 | |
| 84 | if (!pnp) |
| 85 | continue; |
| 86 | |
| 87 | /* skip disabled nodes or nodes with valid MAC address*/ |
| 88 | if (!of_device_is_available(pnp) || of_get_mac_address(np)) |
| 89 | goto eth_fixup_skip; |
| 90 | |
| 91 | clk = of_clk_get(pnp, 0); |
| 92 | if (IS_ERR(clk)) |
| 93 | goto eth_fixup_skip; |
| 94 | |
| 95 | io = of_iomap(pnp, 0); |
| 96 | if (!io) |
| 97 | goto eth_fixup_no_map; |
| 98 | |
| 99 | /* ensure port clock is not gated to not hang CPU */ |
| 100 | clk_prepare_enable(clk); |
| 101 | |
| 102 | /* store MAC address register contents in local-mac-address */ |
| 103 | pr_err(FW_INFO "%s: local-mac-address is not set\n", |
| 104 | np->full_name); |
| 105 | |
| 106 | pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL); |
| 107 | if (!pmac) |
| 108 | goto eth_fixup_no_mem; |
| 109 | |
| 110 | pmac->value = pmac + 1; |
| 111 | pmac->length = 6; |
| 112 | pmac->name = kstrdup("local-mac-address", GFP_KERNEL); |
| 113 | if (!pmac->name) { |
| 114 | kfree(pmac); |
| 115 | goto eth_fixup_no_mem; |
| 116 | } |
| 117 | |
| 118 | macaddr = pmac->value; |
| 119 | reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH); |
| 120 | macaddr[0] = (reg >> 24) & 0xff; |
| 121 | macaddr[1] = (reg >> 16) & 0xff; |
| 122 | macaddr[2] = (reg >> 8) & 0xff; |
| 123 | macaddr[3] = reg & 0xff; |
| 124 | |
| 125 | reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW); |
| 126 | macaddr[4] = (reg >> 8) & 0xff; |
| 127 | macaddr[5] = reg & 0xff; |
| 128 | |
| 129 | of_update_property(np, pmac); |
| 130 | |
| 131 | eth_fixup_no_mem: |
| 132 | iounmap(io); |
| 133 | clk_disable_unprepare(clk); |
| 134 | eth_fixup_no_map: |
| 135 | clk_put(clk); |
| 136 | eth_fixup_skip: |
| 137 | of_node_put(pnp); |
| 138 | } |
| 139 | } |
| 140 | |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 141 | static void __init kirkwood_dt_init(void) |
| 142 | { |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 143 | pr_info("Kirkwood: %s, TCLK=%d.\n", kirkwood_id(), kirkwood_tclk); |
| 144 | |
| 145 | /* |
| 146 | * Disable propagation of mbus errors to the CPU local bus, |
| 147 | * as this causes mbus errors (which can occur for example |
| 148 | * for PCI aborts) to throw CPU aborts, which we're not set |
| 149 | * up to deal with. |
| 150 | */ |
| 151 | writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG); |
| 152 | |
Ezequiel Garcia | 0789d0b | 2013-07-26 10:18:01 -0300 | [diff] [blame] | 153 | BUG_ON(mvebu_mbus_dt_init()); |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 154 | |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 155 | kirkwood_l2_init(); |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 156 | |
Andrew Lunn | 0e2ee0c | 2013-01-27 11:07:23 +0100 | [diff] [blame] | 157 | kirkwood_cpufreq_init(); |
Sebastian Hesselbarth | ebd7d3a | 2013-10-07 22:25:11 +0200 | [diff] [blame] | 158 | kirkwood_cpuidle_init(); |
Sebastian Hesselbarth | 2326f04 | 2013-07-02 15:15:07 +0200 | [diff] [blame] | 159 | /* Setup clocks for legacy devices */ |
| 160 | kirkwood_legacy_clk_init(); |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 161 | |
Ezequiel Garcia | e1cb367 | 2013-08-22 12:49:07 -0300 | [diff] [blame] | 162 | kirkwood_pm_init(); |
Sebastian Hesselbarth | ebd7d3a | 2013-10-07 22:25:11 +0200 | [diff] [blame] | 163 | kirkwood_dt_eth_fixup(); |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 164 | |
Jason Cooper | 2b45e05 | 2012-02-29 17:39:08 +0000 | [diff] [blame] | 165 | #ifdef CONFIG_KEXEC |
| 166 | kexec_reinit = kirkwood_enable_pcie; |
| 167 | #endif |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 168 | |
Thomas Petazzoni | 37ae08c | 2013-08-01 17:07:32 +0200 | [diff] [blame] | 169 | if (of_machine_is_compatible("marvell,mv88f6281gtw-ge")) |
| 170 | mv88f6281gtw_ge_init(); |
Jason Cooper | 767fc1e | 2012-10-22 02:15:35 +0000 | [diff] [blame] | 171 | |
Thomas Petazzoni | 3207792 | 2013-05-15 16:04:59 +0200 | [diff] [blame] | 172 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Andrew Lunn | 98adf93 | 2012-10-20 13:23:16 +0200 | [diff] [blame] | 175 | static const char * const kirkwood_dt_board_compat[] = { |
Sebastian Hesselbarth | a977e18 | 2013-07-03 18:57:51 +0200 | [diff] [blame] | 176 | "marvell,kirkwood", |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 177 | NULL |
| 178 | }; |
| 179 | |
| 180 | DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)") |
| 181 | /* Maintainer: Jason Cooper <jason@lakedaemon.net> */ |
| 182 | .map_io = kirkwood_map_io, |
Jason Cooper | 3d468b6 | 2012-02-27 16:07:13 +0000 | [diff] [blame] | 183 | .init_machine = kirkwood_dt_init, |
| 184 | .restart = kirkwood_restart, |
| 185 | .dt_compat = kirkwood_dt_board_compat, |
| 186 | MACHINE_END |