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