2 * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
4 * arch/arm/mach-kirkwood/board-dt.c
6 * Flattened Device Tree board initialization
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.
13 #include <linux/clk.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
17 #include <linux/of_address.h>
18 #include <linux/of_net.h>
19 #include <linux/of_platform.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/irqchip.h>
22 #include <asm/hardware/cache-feroceon-l2.h>
23 #include <asm/mach/arch.h>
24 #include <asm/mach/map.h>
25 #include <mach/bridge-regs.h>
26 #include <plat/common.h>
27 #include <plat/pcie.h>
30 static struct map_desc kirkwood_io_desc
[] __initdata
= {
32 .virtual = (unsigned long) KIRKWOOD_REGS_VIRT_BASE
,
33 .pfn
= __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE
),
34 .length
= KIRKWOOD_REGS_SIZE
,
39 static void __init
kirkwood_map_io(void)
41 iotable_init(kirkwood_io_desc
, ARRAY_SIZE(kirkwood_io_desc
));
44 static struct resource kirkwood_cpufreq_resources
[] = {
46 .start
= CPU_CONTROL_PHYS
,
47 .end
= CPU_CONTROL_PHYS
+ 3,
48 .flags
= IORESOURCE_MEM
,
52 static struct platform_device kirkwood_cpufreq_device
= {
53 .name
= "kirkwood-cpufreq",
55 .num_resources
= ARRAY_SIZE(kirkwood_cpufreq_resources
),
56 .resource
= kirkwood_cpufreq_resources
,
59 static void __init
kirkwood_cpufreq_init(void)
61 platform_device_register(&kirkwood_cpufreq_device
);
64 static struct resource kirkwood_cpuidle_resource
[] = {
66 .flags
= IORESOURCE_MEM
,
67 .start
= DDR_OPERATION_BASE
,
68 .end
= DDR_OPERATION_BASE
+ 3,
72 static struct platform_device kirkwood_cpuidle
= {
73 .name
= "kirkwood_cpuidle",
75 .resource
= kirkwood_cpuidle_resource
,
79 static void __init
kirkwood_cpuidle_init(void)
81 platform_device_register(&kirkwood_cpuidle
);
84 /* Temporary here since mach-mvebu has a function we can use */
85 static void kirkwood_restart(enum reboot_mode mode
, const char *cmd
)
88 * Enable soft reset to assert RSTOUTn.
90 writel(SOFT_RESET_OUT_EN
, RSTOUTn_MASK
);
95 writel(SOFT_RESET
, SYSTEM_SOFT_RESET
);
101 #define MV643XX_ETH_MAC_ADDR_LOW 0x0414
102 #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
104 static void __init
kirkwood_dt_eth_fixup(void)
106 struct device_node
*np
;
109 * The ethernet interfaces forget the MAC address assigned by u-boot
110 * if the clocks are turned off. Usually, u-boot on kirkwood boards
111 * has no DT support to properly set local-mac-address property.
112 * As a workaround, we get the MAC address from mv643xx_eth registers
113 * and update the port device node if no valid MAC address is set.
115 for_each_compatible_node(np
, NULL
, "marvell,kirkwood-eth-port") {
116 struct device_node
*pnp
= of_get_parent(np
);
118 struct property
*pmac
;
126 /* skip disabled nodes or nodes with valid MAC address*/
127 if (!of_device_is_available(pnp
) || of_get_mac_address(np
))
130 clk
= of_clk_get(pnp
, 0);
134 io
= of_iomap(pnp
, 0);
136 goto eth_fixup_no_map
;
138 /* ensure port clock is not gated to not hang CPU */
139 clk_prepare_enable(clk
);
141 /* store MAC address register contents in local-mac-address */
142 pr_err(FW_INFO
"%s: local-mac-address is not set\n",
145 pmac
= kzalloc(sizeof(*pmac
) + 6, GFP_KERNEL
);
147 goto eth_fixup_no_mem
;
149 pmac
->value
= pmac
+ 1;
151 pmac
->name
= kstrdup("local-mac-address", GFP_KERNEL
);
154 goto eth_fixup_no_mem
;
157 macaddr
= pmac
->value
;
158 reg
= readl(io
+ MV643XX_ETH_MAC_ADDR_HIGH
);
159 macaddr
[0] = (reg
>> 24) & 0xff;
160 macaddr
[1] = (reg
>> 16) & 0xff;
161 macaddr
[2] = (reg
>> 8) & 0xff;
162 macaddr
[3] = reg
& 0xff;
164 reg
= readl(io
+ MV643XX_ETH_MAC_ADDR_LOW
);
165 macaddr
[4] = (reg
>> 8) & 0xff;
166 macaddr
[5] = reg
& 0xff;
168 of_update_property(np
, pmac
);
172 clk_disable_unprepare(clk
);
181 * Disable propagation of mbus errors to the CPU local bus, as this
182 * causes mbus errors (which can occur for example for PCI aborts) to
183 * throw CPU aborts, which we're not set up to deal with.
185 static void __init
kirkwood_disable_mbus_error_propagation(void)
187 void __iomem
*cpu_config
;
189 cpu_config
= ioremap(CPU_CONFIG_PHYS
, 4);
190 writel(readl(cpu_config
) & ~CPU_CONFIG_ERROR_PROP
, cpu_config
);
194 static void __init
kirkwood_dt_init(void)
196 kirkwood_disable_mbus_error_propagation();
198 BUG_ON(mvebu_mbus_dt_init(false));
200 #ifdef CONFIG_CACHE_FEROCEON_L2
203 kirkwood_cpufreq_init();
204 kirkwood_cpuidle_init();
207 kirkwood_dt_eth_fixup();
209 of_platform_populate(NULL
, of_default_bus_match_table
, NULL
, NULL
);
212 static const char * const kirkwood_dt_board_compat
[] = {
217 DT_MACHINE_START(KIRKWOOD_DT
, "Marvell Kirkwood (Flattened Device Tree)")
218 /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
219 .map_io
= kirkwood_map_io
,
220 .init_machine
= kirkwood_dt_init
,
221 .restart
= kirkwood_restart
,
222 .dt_compat
= kirkwood_dt_board_compat
,