blob: 9caa4fe95913c672a6b874c5b8b8d573294ae857 [file] [log] [blame]
Jason Cooper3d468b62012-02-27 16:07:13 +00001/*
2 * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
3 *
4 * arch/arm/mach-kirkwood/board-dt.c
5 *
Jason Cooper6fa6b872012-03-15 00:52:31 +00006 * Flattened Device Tree board initialization
Jason Cooper3d468b62012-02-27 16:07:13 +00007 *
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 Cooper3d468b62012-02-27 16:07:13 +000015#include <linux/of.h>
Sebastian Hesselbarthebd7d3a2013-10-07 22:25:11 +020016#include <linux/of_address.h>
17#include <linux/of_net.h>
Jason Cooper3d468b62012-02-27 16:07:13 +000018#include <linux/of_platform.h>
Andrew Lunn1611f872012-11-17 15:22:28 +010019#include <linux/clk-provider.h>
Sebastian Hesselbarth2326f042013-07-02 15:15:07 +020020#include <linux/dma-mapping.h>
21#include <linux/irqchip.h>
Ian Campbella7ac56d2012-04-29 14:40:42 +010022#include <linux/kexec.h>
Jason Cooper3d468b62012-02-27 16:07:13 +000023#include <asm/mach/arch.h>
Jason Cooper2b45e052012-02-29 17:39:08 +000024#include <asm/mach/map.h>
Jason Cooper2b45e052012-02-29 17:39:08 +000025#include <mach/bridge-regs.h>
Andrew Lunn1611f872012-11-17 15:22:28 +010026#include <linux/platform_data/usb-ehci-orion.h>
Andrew Lunn278b45b2012-06-27 13:40:04 +020027#include <plat/irq.h>
Andrew Lunn1611f872012-11-17 15:22:28 +010028#include <plat/common.h>
Jason Cooper3d468b62012-02-27 16:07:13 +000029#include "common.h"
Jason Cooper3d468b62012-02-27 16:07:13 +000030
Andrew Lunn1611f872012-11-17 15:22:28 +010031/*
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
37static 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 Lunn1611f872012-11-17 15:22:28 +010042 struct of_phandle_args clkspec;
Sebastian Hesselbarth7bf5b402013-01-30 21:29:58 +010043 struct clk *clk;
Andrew Lunn1611f872012-11-17 15:22:28 +010044
45 clkspec.np = np;
46 clkspec.args_count = 1;
47
Sebastian Hesselbarth7bf5b402013-01-30 21:29:58 +010048 /*
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 Hesselbarth7bf5b402013-01-30 21:29:58 +010055 clk_prepare_enable(clk);
56
57 clkspec.args[0] = CGC_BIT_GE1;
58 clk = of_clk_get_from_provider(&clkspec);
Sebastian Hesselbarth7bf5b402013-01-30 21:29:58 +010059 clk_prepare_enable(clk);
Andrew Lunn1611f872012-11-17 15:22:28 +010060}
61
Sebastian Hesselbarthebd7d3a2013-10-07 22:25:11 +020062#define MV643XX_ETH_MAC_ADDR_LOW 0x0414
63#define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
64
65static 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
131eth_fixup_no_mem:
132 iounmap(io);
133 clk_disable_unprepare(clk);
134eth_fixup_no_map:
135 clk_put(clk);
136eth_fixup_skip:
137 of_node_put(pnp);
138 }
139}
140
Jason Cooper3d468b62012-02-27 16:07:13 +0000141static void __init kirkwood_dt_init(void)
142{
Jason Cooper2b45e052012-02-29 17:39:08 +0000143 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 Garcia0789d0b2013-07-26 10:18:01 -0300153 BUG_ON(mvebu_mbus_dt_init());
Jason Cooper2b45e052012-02-29 17:39:08 +0000154
Jason Cooper2b45e052012-02-29 17:39:08 +0000155 kirkwood_l2_init();
Jason Cooper2b45e052012-02-29 17:39:08 +0000156
Andrew Lunn0e2ee0c2013-01-27 11:07:23 +0100157 kirkwood_cpufreq_init();
Sebastian Hesselbarthebd7d3a2013-10-07 22:25:11 +0200158 kirkwood_cpuidle_init();
Sebastian Hesselbarth2326f042013-07-02 15:15:07 +0200159 /* Setup clocks for legacy devices */
160 kirkwood_legacy_clk_init();
Jason Cooper2b45e052012-02-29 17:39:08 +0000161
Ezequiel Garciae1cb3672013-08-22 12:49:07 -0300162 kirkwood_pm_init();
Sebastian Hesselbarthebd7d3a2013-10-07 22:25:11 +0200163 kirkwood_dt_eth_fixup();
Andrew Lunn9cfc94e2013-01-09 13:22:15 +0100164
Jason Cooper2b45e052012-02-29 17:39:08 +0000165#ifdef CONFIG_KEXEC
166 kexec_reinit = kirkwood_enable_pcie;
167#endif
Jason Cooper3d468b62012-02-27 16:07:13 +0000168
Thomas Petazzoni37ae08c2013-08-01 17:07:32 +0200169 if (of_machine_is_compatible("marvell,mv88f6281gtw-ge"))
170 mv88f6281gtw_ge_init();
Jason Cooper767fc1e2012-10-22 02:15:35 +0000171
Thomas Petazzoni32077922013-05-15 16:04:59 +0200172 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
Jason Cooper3d468b62012-02-27 16:07:13 +0000173}
174
Andrew Lunn98adf932012-10-20 13:23:16 +0200175static const char * const kirkwood_dt_board_compat[] = {
Sebastian Hesselbartha977e182013-07-03 18:57:51 +0200176 "marvell,kirkwood",
Jason Cooper3d468b62012-02-27 16:07:13 +0000177 NULL
178};
179
180DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
181 /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
182 .map_io = kirkwood_map_io,
Jason Cooper3d468b62012-02-27 16:07:13 +0000183 .init_machine = kirkwood_dt_init,
184 .restart = kirkwood_restart,
185 .dt_compat = kirkwood_dt_board_compat,
186MACHINE_END