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/clk.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
17 #include <linux/of_address.h>
18 #include <linux/of_net.h>
19 #include <linux/of_platform.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/irqchip.h>
22 #include <linux/kexec.h>
23 #include <asm/mach/arch.h>
24 #include <mach/bridge-regs.h>
25 #include <plat/common.h>
29 #define MV643XX_ETH_MAC_ADDR_LOW 0x0414
30 #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
32 static void __init kirkwood_dt_eth_fixup(void)
34 struct device_node *np;
37 * The ethernet interfaces forget the MAC address assigned by u-boot
38 * if the clocks are turned off. Usually, u-boot on kirkwood boards
39 * has no DT support to properly set local-mac-address property.
40 * As a workaround, we get the MAC address from mv643xx_eth registers
41 * and update the port device node if no valid MAC address is set.
43 for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
44 struct device_node *pnp = of_get_parent(np);
46 struct property *pmac;
54 /* skip disabled nodes or nodes with valid MAC address*/
55 if (!of_device_is_available(pnp) || of_get_mac_address(np))
58 clk = of_clk_get(pnp, 0);
62 io = of_iomap(pnp, 0);
64 goto eth_fixup_no_map;
66 /* ensure port clock is not gated to not hang CPU */
67 clk_prepare_enable(clk);
69 /* store MAC address register contents in local-mac-address */
70 pr_err(FW_INFO "%s: local-mac-address is not set\n",
73 pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
75 goto eth_fixup_no_mem;
77 pmac->value = pmac + 1;
79 pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
82 goto eth_fixup_no_mem;
85 macaddr = pmac->value;
86 reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
87 macaddr[0] = (reg >> 24) & 0xff;
88 macaddr[1] = (reg >> 16) & 0xff;
89 macaddr[2] = (reg >> 8) & 0xff;
90 macaddr[3] = reg & 0xff;
92 reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
93 macaddr[4] = (reg >> 8) & 0xff;
94 macaddr[5] = reg & 0xff;
96 of_update_property(np, pmac);
100 clk_disable_unprepare(clk);
108 static void __init kirkwood_dt_init(void)
110 pr_info("Kirkwood: %s.\n", kirkwood_id());
113 * Disable propagation of mbus errors to the CPU local bus,
114 * as this causes mbus errors (which can occur for example
115 * for PCI aborts) to throw CPU aborts, which we're not set
118 writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
120 BUG_ON(mvebu_mbus_dt_init());
124 kirkwood_cpufreq_init();
125 kirkwood_cpuidle_init();
128 kirkwood_dt_eth_fixup();
131 kexec_reinit = kirkwood_enable_pcie;
134 if (of_machine_is_compatible("marvell,mv88f6281gtw-ge"))
135 mv88f6281gtw_ge_init();
137 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
140 static const char * const kirkwood_dt_board_compat[] = {
145 DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
146 /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
147 .map_io = kirkwood_map_io,
148 .init_machine = kirkwood_dt_init,
149 .restart = kirkwood_restart,
150 .dt_compat = kirkwood_dt_board_compat,