]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-kirkwood/board-dt.c
Merge tag 'highbank-for-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/robh...
[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/kernel.h>
14 #include <linux/init.h>
15 #include <linux/of.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>
28 #include <plat/irq.h>
29 #include <plat/common.h>
30 #include "common.h"
31
32 /*
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
35  * devices still work.
36 */
37
38 static void __init kirkwood_legacy_clk_init(void)
39 {
40
41         struct device_node *np = of_find_compatible_node(
42                 NULL, NULL, "marvell,kirkwood-gating-clock");
43         struct of_phandle_args clkspec;
44         struct clk *clk;
45
46         clkspec.np = np;
47         clkspec.args_count = 1;
48
49         /*
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.
53          */
54         clkspec.args[0] = CGC_BIT_GE0;
55         clk = of_clk_get_from_provider(&clkspec);
56         clk_prepare_enable(clk);
57
58         clkspec.args[0] = CGC_BIT_GE1;
59         clk = of_clk_get_from_provider(&clkspec);
60         clk_prepare_enable(clk);
61 }
62
63 #define MV643XX_ETH_MAC_ADDR_LOW        0x0414
64 #define MV643XX_ETH_MAC_ADDR_HIGH       0x0418
65
66 static void __init kirkwood_dt_eth_fixup(void)
67 {
68         struct device_node *np;
69
70         /*
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.
76          */
77         for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
78                 struct device_node *pnp = of_get_parent(np);
79                 struct clk *clk;
80                 struct property *pmac;
81                 void __iomem *io;
82                 u8 *macaddr;
83                 u32 reg;
84
85                 if (!pnp)
86                         continue;
87
88                 /* skip disabled nodes or nodes with valid MAC address*/
89                 if (!of_device_is_available(pnp) || of_get_mac_address(np))
90                         goto eth_fixup_skip;
91
92                 clk = of_clk_get(pnp, 0);
93                 if (IS_ERR(clk))
94                         goto eth_fixup_skip;
95
96                 io = of_iomap(pnp, 0);
97                 if (!io)
98                         goto eth_fixup_no_map;
99
100                 /* ensure port clock is not gated to not hang CPU */
101                 clk_prepare_enable(clk);
102
103                 /* store MAC address register contents in local-mac-address */
104                 pr_err(FW_INFO "%s: local-mac-address is not set\n",
105                        np->full_name);
106
107                 pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
108                 if (!pmac)
109                         goto eth_fixup_no_mem;
110
111                 pmac->value = pmac + 1;
112                 pmac->length = 6;
113                 pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
114                 if (!pmac->name) {
115                         kfree(pmac);
116                         goto eth_fixup_no_mem;
117                 }
118
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;
125
126                 reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
127                 macaddr[4] = (reg >> 8) & 0xff;
128                 macaddr[5] = reg & 0xff;
129
130                 of_update_property(np, pmac);
131
132 eth_fixup_no_mem:
133                 iounmap(io);
134                 clk_disable_unprepare(clk);
135 eth_fixup_no_map:
136                 clk_put(clk);
137 eth_fixup_skip:
138                 of_node_put(pnp);
139         }
140 }
141
142 static void __init kirkwood_dt_time_init(void)
143 {
144         of_clk_init(NULL);
145         clocksource_of_init();
146 }
147
148 static void __init kirkwood_dt_init(void)
149 {
150         pr_info("Kirkwood: %s, TCLK=%d.\n", kirkwood_id(), kirkwood_tclk);
151
152         /*
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
156          * up to deal with.
157          */
158         writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
159
160         BUG_ON(mvebu_mbus_dt_init());
161         kirkwood_setup_wins();
162
163         kirkwood_l2_init();
164
165         kirkwood_cpufreq_init();
166         kirkwood_cpuidle_init();
167         /* Setup clocks for legacy devices */
168         kirkwood_legacy_clk_init();
169
170         kirkwood_pm_init();
171         kirkwood_dt_eth_fixup();
172
173 #ifdef CONFIG_KEXEC
174         kexec_reinit = kirkwood_enable_pcie;
175 #endif
176
177         if (of_machine_is_compatible("marvell,mv88f6281gtw-ge"))
178                 mv88f6281gtw_ge_init();
179
180         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
181 }
182
183 static const char * const kirkwood_dt_board_compat[] = {
184         "marvell,kirkwood",
185         NULL
186 };
187
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,
195 MACHINE_END