blob: 0aa88105d46e5423c1d98d29ca0f65ab7968f143 [file] [log] [blame]
Andrew Lunnba5a37e2014-02-22 20:14:57 +01001/*
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>
Andrew Lunnc3f08d02014-02-22 20:15:03 +010016#include <linux/mbus.h>
Andrew Lunnba5a37e2014-02-22 20:14:57 +010017#include <linux/of.h>
18#include <linux/of_address.h>
19#include <linux/of_net.h>
20#include <linux/of_platform.h>
Andrew Lunnc3f08d02014-02-22 20:15:03 +010021#include <linux/slab.h>
Andrew Lunnba5a37e2014-02-22 20:14:57 +010022#include <asm/hardware/cache-feroceon-l2.h>
23#include <asm/mach/arch.h>
24#include <asm/mach/map.h>
Andrew Lunnc3f08d02014-02-22 20:15:03 +010025#include "kirkwood.h"
Andrew Lunnba5a37e2014-02-22 20:14:57 +010026#include "kirkwood-pm.h"
Andrew Lunnba0ae312014-02-22 20:14:58 +010027#include "common.h"
Andrew Lunnba5a37e2014-02-22 20:14:57 +010028
29static struct resource kirkwood_cpufreq_resources[] = {
30 [0] = {
31 .start = CPU_CONTROL_PHYS,
32 .end = CPU_CONTROL_PHYS + 3,
33 .flags = IORESOURCE_MEM,
34 },
35};
36
37static struct platform_device kirkwood_cpufreq_device = {
38 .name = "kirkwood-cpufreq",
39 .id = -1,
40 .num_resources = ARRAY_SIZE(kirkwood_cpufreq_resources),
41 .resource = kirkwood_cpufreq_resources,
42};
43
44static void __init kirkwood_cpufreq_init(void)
45{
46 platform_device_register(&kirkwood_cpufreq_device);
47}
48
49static struct resource kirkwood_cpuidle_resource[] = {
50 {
51 .flags = IORESOURCE_MEM,
52 .start = DDR_OPERATION_BASE,
53 .end = DDR_OPERATION_BASE + 3,
54 },
55};
56
57static struct platform_device kirkwood_cpuidle = {
58 .name = "kirkwood_cpuidle",
59 .id = -1,
60 .resource = kirkwood_cpuidle_resource,
61 .num_resources = 1,
62};
63
64static void __init kirkwood_cpuidle_init(void)
65{
66 platform_device_register(&kirkwood_cpuidle);
67}
68
Andrew Lunnba5a37e2014-02-22 20:14:57 +010069#define MV643XX_ETH_MAC_ADDR_LOW 0x0414
70#define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
71
72static void __init kirkwood_dt_eth_fixup(void)
73{
74 struct device_node *np;
75
76 /*
77 * The ethernet interfaces forget the MAC address assigned by u-boot
78 * if the clocks are turned off. Usually, u-boot on kirkwood boards
79 * has no DT support to properly set local-mac-address property.
80 * As a workaround, we get the MAC address from mv643xx_eth registers
81 * and update the port device node if no valid MAC address is set.
82 */
83 for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
84 struct device_node *pnp = of_get_parent(np);
85 struct clk *clk;
86 struct property *pmac;
87 void __iomem *io;
88 u8 *macaddr;
89 u32 reg;
90
91 if (!pnp)
92 continue;
93
94 /* skip disabled nodes or nodes with valid MAC address*/
95 if (!of_device_is_available(pnp) || of_get_mac_address(np))
96 goto eth_fixup_skip;
97
98 clk = of_clk_get(pnp, 0);
99 if (IS_ERR(clk))
100 goto eth_fixup_skip;
101
102 io = of_iomap(pnp, 0);
103 if (!io)
104 goto eth_fixup_no_map;
105
106 /* ensure port clock is not gated to not hang CPU */
107 clk_prepare_enable(clk);
108
109 /* store MAC address register contents in local-mac-address */
Rob Herringa8e65e02017-07-21 14:28:32 -0500110 pr_err(FW_INFO "%pOF: local-mac-address is not set\n", np);
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100111
112 pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
113 if (!pmac)
114 goto eth_fixup_no_mem;
115
116 pmac->value = pmac + 1;
117 pmac->length = 6;
118 pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
119 if (!pmac->name) {
120 kfree(pmac);
121 goto eth_fixup_no_mem;
122 }
123
124 macaddr = pmac->value;
125 reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
126 macaddr[0] = (reg >> 24) & 0xff;
127 macaddr[1] = (reg >> 16) & 0xff;
128 macaddr[2] = (reg >> 8) & 0xff;
129 macaddr[3] = reg & 0xff;
130
131 reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
132 macaddr[4] = (reg >> 8) & 0xff;
133 macaddr[5] = reg & 0xff;
134
135 of_update_property(np, pmac);
136
137eth_fixup_no_mem:
138 iounmap(io);
139 clk_disable_unprepare(clk);
140eth_fixup_no_map:
141 clk_put(clk);
142eth_fixup_skip:
143 of_node_put(pnp);
144 }
145}
146
147/*
148 * Disable propagation of mbus errors to the CPU local bus, as this
149 * causes mbus errors (which can occur for example for PCI aborts) to
150 * throw CPU aborts, which we're not set up to deal with.
151 */
Ben Dooks15b10c62016-06-09 12:52:25 +0100152static void kirkwood_disable_mbus_error_propagation(void)
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100153{
154 void __iomem *cpu_config;
155
156 cpu_config = ioremap(CPU_CONFIG_PHYS, 4);
157 writel(readl(cpu_config) & ~CPU_CONFIG_ERROR_PROP, cpu_config);
158}
159
Andrew Lunnb02b6432014-02-25 18:34:01 +0100160static struct of_dev_auxdata auxdata[] __initdata = {
161 OF_DEV_AUXDATA("marvell,kirkwood-audio", 0xf10a0000,
162 "mvebu-audio", NULL),
163 { /* sentinel */ }
164};
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100165
166static void __init kirkwood_dt_init(void)
167{
168 kirkwood_disable_mbus_error_propagation();
169
Thomas Petazzoni5686a1e2014-04-14 15:47:01 +0200170 BUG_ON(mvebu_mbus_dt_init(false));
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100171
172#ifdef CONFIG_CACHE_FEROCEON_L2
173 feroceon_of_init();
174#endif
175 kirkwood_cpufreq_init();
176 kirkwood_cpuidle_init();
177
178 kirkwood_pm_init();
179 kirkwood_dt_eth_fixup();
180
Kefeng Wang435ebcb2016-06-01 14:53:05 +0800181 of_platform_default_populate(NULL, auxdata, NULL);
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100182}
183
Thomas Petazzonibc2d7a52015-03-03 15:40:56 +0100184static const char * const kirkwood_dt_board_compat[] __initconst = {
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100185 "marvell,kirkwood",
186 NULL
187};
188
189DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
190 /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
191 .init_machine = kirkwood_dt_init,
Andrew Lunnba0ae312014-02-22 20:14:58 +0100192 .restart = mvebu_restart,
Andrew Lunnba5a37e2014-02-22 20:14:57 +0100193 .dt_compat = kirkwood_dt_board_compat,
194MACHINE_END