Commit | Line | Data |
---|---|---|
ba5a37e5 AL |
1 | /* |
2 | * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net> | |
3 | * | |
4 | * arch/arm/mach-mvebu/kirkwood.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> | |
c3f08d0d | 16 | #include <linux/mbus.h> |
ba5a37e5 AL |
17 | #include <linux/of.h> |
18 | #include <linux/of_address.h> | |
19 | #include <linux/of_net.h> | |
20 | #include <linux/of_platform.h> | |
c3f08d0d | 21 | #include <linux/slab.h> |
ba5a37e5 AL |
22 | #include <asm/hardware/cache-feroceon-l2.h> |
23 | #include <asm/mach/arch.h> | |
24 | #include <asm/mach/map.h> | |
c3f08d0d | 25 | #include "kirkwood.h" |
ba5a37e5 | 26 | #include "kirkwood-pm.h" |
ba0ae312 | 27 | #include "common.h" |
b02b6438 | 28 | #include "board.h" |
ba5a37e5 AL |
29 | |
30 | static struct resource kirkwood_cpufreq_resources[] = { | |
31 | [0] = { | |
32 | .start = CPU_CONTROL_PHYS, | |
33 | .end = CPU_CONTROL_PHYS + 3, | |
34 | .flags = IORESOURCE_MEM, | |
35 | }, | |
36 | }; | |
37 | ||
38 | static struct platform_device kirkwood_cpufreq_device = { | |
39 | .name = "kirkwood-cpufreq", | |
40 | .id = -1, | |
41 | .num_resources = ARRAY_SIZE(kirkwood_cpufreq_resources), | |
42 | .resource = kirkwood_cpufreq_resources, | |
43 | }; | |
44 | ||
45 | static void __init kirkwood_cpufreq_init(void) | |
46 | { | |
47 | platform_device_register(&kirkwood_cpufreq_device); | |
48 | } | |
49 | ||
50 | static struct resource kirkwood_cpuidle_resource[] = { | |
51 | { | |
52 | .flags = IORESOURCE_MEM, | |
53 | .start = DDR_OPERATION_BASE, | |
54 | .end = DDR_OPERATION_BASE + 3, | |
55 | }, | |
56 | }; | |
57 | ||
58 | static struct platform_device kirkwood_cpuidle = { | |
59 | .name = "kirkwood_cpuidle", | |
60 | .id = -1, | |
61 | .resource = kirkwood_cpuidle_resource, | |
62 | .num_resources = 1, | |
63 | }; | |
64 | ||
65 | static void __init kirkwood_cpuidle_init(void) | |
66 | { | |
67 | platform_device_register(&kirkwood_cpuidle); | |
68 | } | |
69 | ||
ba5a37e5 AL |
70 | #define MV643XX_ETH_MAC_ADDR_LOW 0x0414 |
71 | #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418 | |
72 | ||
73 | static void __init kirkwood_dt_eth_fixup(void) | |
74 | { | |
75 | struct device_node *np; | |
76 | ||
77 | /* | |
78 | * The ethernet interfaces forget the MAC address assigned by u-boot | |
79 | * if the clocks are turned off. Usually, u-boot on kirkwood boards | |
80 | * has no DT support to properly set local-mac-address property. | |
81 | * As a workaround, we get the MAC address from mv643xx_eth registers | |
82 | * and update the port device node if no valid MAC address is set. | |
83 | */ | |
84 | for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") { | |
85 | struct device_node *pnp = of_get_parent(np); | |
86 | struct clk *clk; | |
87 | struct property *pmac; | |
88 | void __iomem *io; | |
89 | u8 *macaddr; | |
90 | u32 reg; | |
91 | ||
92 | if (!pnp) | |
93 | continue; | |
94 | ||
95 | /* skip disabled nodes or nodes with valid MAC address*/ | |
96 | if (!of_device_is_available(pnp) || of_get_mac_address(np)) | |
97 | goto eth_fixup_skip; | |
98 | ||
99 | clk = of_clk_get(pnp, 0); | |
100 | if (IS_ERR(clk)) | |
101 | goto eth_fixup_skip; | |
102 | ||
103 | io = of_iomap(pnp, 0); | |
104 | if (!io) | |
105 | goto eth_fixup_no_map; | |
106 | ||
107 | /* ensure port clock is not gated to not hang CPU */ | |
108 | clk_prepare_enable(clk); | |
109 | ||
110 | /* store MAC address register contents in local-mac-address */ | |
111 | pr_err(FW_INFO "%s: local-mac-address is not set\n", | |
112 | np->full_name); | |
113 | ||
114 | pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL); | |
115 | if (!pmac) | |
116 | goto eth_fixup_no_mem; | |
117 | ||
118 | pmac->value = pmac + 1; | |
119 | pmac->length = 6; | |
120 | pmac->name = kstrdup("local-mac-address", GFP_KERNEL); | |
121 | if (!pmac->name) { | |
122 | kfree(pmac); | |
123 | goto eth_fixup_no_mem; | |
124 | } | |
125 | ||
126 | macaddr = pmac->value; | |
127 | reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH); | |
128 | macaddr[0] = (reg >> 24) & 0xff; | |
129 | macaddr[1] = (reg >> 16) & 0xff; | |
130 | macaddr[2] = (reg >> 8) & 0xff; | |
131 | macaddr[3] = reg & 0xff; | |
132 | ||
133 | reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW); | |
134 | macaddr[4] = (reg >> 8) & 0xff; | |
135 | macaddr[5] = reg & 0xff; | |
136 | ||
137 | of_update_property(np, pmac); | |
138 | ||
139 | eth_fixup_no_mem: | |
140 | iounmap(io); | |
141 | clk_disable_unprepare(clk); | |
142 | eth_fixup_no_map: | |
143 | clk_put(clk); | |
144 | eth_fixup_skip: | |
145 | of_node_put(pnp); | |
146 | } | |
147 | } | |
148 | ||
149 | /* | |
150 | * Disable propagation of mbus errors to the CPU local bus, as this | |
151 | * causes mbus errors (which can occur for example for PCI aborts) to | |
152 | * throw CPU aborts, which we're not set up to deal with. | |
153 | */ | |
154 | void kirkwood_disable_mbus_error_propagation(void) | |
155 | { | |
156 | void __iomem *cpu_config; | |
157 | ||
158 | cpu_config = ioremap(CPU_CONFIG_PHYS, 4); | |
159 | writel(readl(cpu_config) & ~CPU_CONFIG_ERROR_PROP, cpu_config); | |
160 | } | |
161 | ||
b02b6438 AL |
162 | static struct of_dev_auxdata auxdata[] __initdata = { |
163 | OF_DEV_AUXDATA("marvell,kirkwood-audio", 0xf10a0000, | |
164 | "mvebu-audio", NULL), | |
165 | { /* sentinel */ } | |
166 | }; | |
ba5a37e5 AL |
167 | |
168 | static void __init kirkwood_dt_init(void) | |
169 | { | |
170 | kirkwood_disable_mbus_error_propagation(); | |
171 | ||
5686a1e5 | 172 | BUG_ON(mvebu_mbus_dt_init(false)); |
ba5a37e5 AL |
173 | |
174 | #ifdef CONFIG_CACHE_FEROCEON_L2 | |
175 | feroceon_of_init(); | |
176 | #endif | |
177 | kirkwood_cpufreq_init(); | |
178 | kirkwood_cpuidle_init(); | |
179 | ||
180 | kirkwood_pm_init(); | |
181 | kirkwood_dt_eth_fixup(); | |
182 | ||
55fc8302 AL |
183 | if (of_machine_is_compatible("lacie,netxbig")) |
184 | netxbig_init(); | |
185 | ||
b02b6438 | 186 | of_platform_populate(NULL, of_default_bus_match_table, auxdata, NULL); |
ba5a37e5 AL |
187 | } |
188 | ||
189 | static const char * const kirkwood_dt_board_compat[] = { | |
190 | "marvell,kirkwood", | |
191 | NULL | |
192 | }; | |
193 | ||
194 | DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)") | |
195 | /* Maintainer: Jason Cooper <jason@lakedaemon.net> */ | |
196 | .init_machine = kirkwood_dt_init, | |
ba0ae312 | 197 | .restart = mvebu_restart, |
ba5a37e5 AL |
198 | .dt_compat = kirkwood_dt_board_compat, |
199 | MACHINE_END |