2 * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
4 * arch/arm/mach-kirkwood/board-dt.c
6 * Flattened Device Tree board initialization
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.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
16 #include <linux/of_address.h>
17 #include <linux/of_net.h>
18 #include <linux/of_platform.h>
19 #include <linux/clk-provider.h>
20 #include <linux/clocksource.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/irqchip.h>
23 #include <linux/kexec.h>
24 #include <asm/mach/arch.h>
25 #include <asm/mach/map.h>
26 #include <mach/bridge-regs.h>
27 #include <linux/platform_data/usb-ehci-orion.h>
29 #include <plat/common.h>
33 * There are still devices that doesn't know about DT yet. Get clock
34 * gates here and add a clock lookup alias, so that old platform
38 static void __init kirkwood_legacy_clk_init(void)
41 struct device_node *np = of_find_compatible_node(
42 NULL, NULL, "marvell,kirkwood-gating-clock");
43 struct of_phandle_args clkspec;
47 clkspec.args_count = 1;
50 * The ethernet interfaces forget the MAC address assigned by
51 * u-boot if the clocks are turned off. Until proper DT support
52 * is available we always enable them for now.
54 clkspec.args[0] = CGC_BIT_GE0;
55 clk = of_clk_get_from_provider(&clkspec);
56 clk_prepare_enable(clk);
58 clkspec.args[0] = CGC_BIT_GE1;
59 clk = of_clk_get_from_provider(&clkspec);
60 clk_prepare_enable(clk);
63 #define MV643XX_ETH_MAC_ADDR_LOW 0x0414
64 #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
66 static void __init kirkwood_dt_eth_fixup(void)
68 struct device_node *np;
71 * The ethernet interfaces forget the MAC address assigned by u-boot
72 * if the clocks are turned off. Usually, u-boot on kirkwood boards
73 * has no DT support to properly set local-mac-address property.
74 * As a workaround, we get the MAC address from mv643xx_eth registers
75 * and update the port device node if no valid MAC address is set.
77 for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
78 struct device_node *pnp = of_get_parent(np);
80 struct property *pmac;
88 /* skip disabled nodes or nodes with valid MAC address*/
89 if (!of_device_is_available(pnp) || of_get_mac_address(np))
92 clk = of_clk_get(pnp, 0);
96 io = of_iomap(pnp, 0);
98 goto eth_fixup_no_map;
100 /* ensure port clock is not gated to not hang CPU */
101 clk_prepare_enable(clk);
103 /* store MAC address register contents in local-mac-address */
104 pr_err(FW_INFO "%s: local-mac-address is not set\n",
107 pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
109 goto eth_fixup_no_mem;
111 pmac->value = pmac + 1;
113 pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
116 goto eth_fixup_no_mem;
119 macaddr = pmac->value;
120 reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
121 macaddr[0] = (reg >> 24) & 0xff;
122 macaddr[1] = (reg >> 16) & 0xff;
123 macaddr[2] = (reg >> 8) & 0xff;
124 macaddr[3] = reg & 0xff;
126 reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
127 macaddr[4] = (reg >> 8) & 0xff;
128 macaddr[5] = reg & 0xff;
130 of_update_property(np, pmac);
134 clk_disable_unprepare(clk);
142 static void __init kirkwood_dt_time_init(void)
145 clocksource_of_init();
148 static void __init kirkwood_dt_init(void)
150 pr_info("Kirkwood: %s, TCLK=%d.\n", kirkwood_id(), kirkwood_tclk);
153 * Disable propagation of mbus errors to the CPU local bus,
154 * as this causes mbus errors (which can occur for example
155 * for PCI aborts) to throw CPU aborts, which we're not set
158 writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
160 BUG_ON(mvebu_mbus_dt_init());
161 kirkwood_setup_wins();
165 kirkwood_cpufreq_init();
166 kirkwood_cpuidle_init();
167 /* Setup clocks for legacy devices */
168 kirkwood_legacy_clk_init();
171 kirkwood_dt_eth_fixup();
174 kexec_reinit = kirkwood_enable_pcie;
177 if (of_machine_is_compatible("marvell,mv88f6281gtw-ge"))
178 mv88f6281gtw_ge_init();
180 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
183 static const char * const kirkwood_dt_board_compat[] = {
188 DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
189 /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
190 .map_io = kirkwood_map_io,
191 .init_time = kirkwood_dt_time_init,
192 .init_machine = kirkwood_dt_init,
193 .restart = kirkwood_restart,
194 .dt_compat = kirkwood_dt_board_compat,