]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-kirkwood/board-dt.c
Merge remote-tracking branch 'mvebu/for-next'
[karo-tx-linux.git] / arch / arm / mach-kirkwood / board-dt.c
1 /*
2  * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
3  *
4  * arch/arm/mach-kirkwood/board-dt.c
5  *
6  * Flattened Device Tree board initialization
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/clk.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/io.h>
17 #include <linux/of.h>
18 #include <linux/of_address.h>
19 #include <linux/of_net.h>
20 #include <linux/of_platform.h>
21 #include <linux/clk-provider.h>
22 #include <linux/slab.h>
23 #include <asm/mach/arch.h>
24 #include <mach/bridge-regs.h>
25 #include <plat/common.h>
26 #include "common.h"
27
28 #define MV643XX_ETH_MAC_ADDR_LOW        0x0414
29 #define MV643XX_ETH_MAC_ADDR_HIGH       0x0418
30
31 static void __init kirkwood_dt_eth_fixup(void)
32 {
33         struct device_node *np;
34
35         /*
36          * The ethernet interfaces forget the MAC address assigned by u-boot
37          * if the clocks are turned off. Usually, u-boot on kirkwood boards
38          * has no DT support to properly set local-mac-address property.
39          * As a workaround, we get the MAC address from mv643xx_eth registers
40          * and update the port device node if no valid MAC address is set.
41          */
42         for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
43                 struct device_node *pnp = of_get_parent(np);
44                 struct clk *clk;
45                 struct property *pmac;
46                 void __iomem *io;
47                 u8 *macaddr;
48                 u32 reg;
49
50                 if (!pnp)
51                         continue;
52
53                 /* skip disabled nodes or nodes with valid MAC address*/
54                 if (!of_device_is_available(pnp) || of_get_mac_address(np))
55                         goto eth_fixup_skip;
56
57                 clk = of_clk_get(pnp, 0);
58                 if (IS_ERR(clk))
59                         goto eth_fixup_skip;
60
61                 io = of_iomap(pnp, 0);
62                 if (!io)
63                         goto eth_fixup_no_map;
64
65                 /* ensure port clock is not gated to not hang CPU */
66                 clk_prepare_enable(clk);
67
68                 /* store MAC address register contents in local-mac-address */
69                 pr_err(FW_INFO "%s: local-mac-address is not set\n",
70                        np->full_name);
71
72                 pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
73                 if (!pmac)
74                         goto eth_fixup_no_mem;
75
76                 pmac->value = pmac + 1;
77                 pmac->length = 6;
78                 pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
79                 if (!pmac->name) {
80                         kfree(pmac);
81                         goto eth_fixup_no_mem;
82                 }
83
84                 macaddr = pmac->value;
85                 reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
86                 macaddr[0] = (reg >> 24) & 0xff;
87                 macaddr[1] = (reg >> 16) & 0xff;
88                 macaddr[2] = (reg >> 8) & 0xff;
89                 macaddr[3] = reg & 0xff;
90
91                 reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
92                 macaddr[4] = (reg >> 8) & 0xff;
93                 macaddr[5] = reg & 0xff;
94
95                 of_update_property(np, pmac);
96
97 eth_fixup_no_mem:
98                 iounmap(io);
99                 clk_disable_unprepare(clk);
100 eth_fixup_no_map:
101                 clk_put(clk);
102 eth_fixup_skip:
103                 of_node_put(pnp);
104         }
105 }
106
107 static void __init kirkwood_dt_init(void)
108 {
109         pr_info("Kirkwood: %s, TCLK=%d.\n", kirkwood_id(), kirkwood_tclk);
110
111         /*
112          * Disable propagation of mbus errors to the CPU local bus,
113          * as this causes mbus errors (which can occur for example
114          * for PCI aborts) to throw CPU aborts, which we're not set
115          * up to deal with.
116          */
117         writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
118
119         BUG_ON(mvebu_mbus_dt_init());
120
121         kirkwood_l2_init();
122
123         kirkwood_cpufreq_init();
124         kirkwood_cpuidle_init();
125
126         kirkwood_pm_init();
127         kirkwood_dt_eth_fixup();
128
129 #ifdef CONFIG_KEXEC
130         kexec_reinit = kirkwood_enable_pcie;
131 #endif
132
133         if (of_machine_is_compatible("marvell,mv88f6281gtw-ge"))
134                 mv88f6281gtw_ge_init();
135
136         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
137 }
138
139 static const char * const kirkwood_dt_board_compat[] = {
140         "marvell,kirkwood",
141         NULL
142 };
143
144 DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
145         /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
146         .map_io         = kirkwood_map_io,
147         .init_machine   = kirkwood_dt_init,
148         .restart        = kirkwood_restart,
149         .dt_compat      = kirkwood_dt_board_compat,
150 MACHINE_END