Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: kirkwood: retain MAC address for DT ethernet

Ethernet IP on Kirkwood SoCs loose their MAC address register content
if clock gated. To allow modular ethernet driver setups and gated clocks
also on non-DT capable bootloaders, we fixup port device nodes with no
valid MAC address property. This patch copies MAC address register
contents set up by bootloaders early, notably before ethernet clocks
are gated. While at it, also reorder call sequence in _dt_init.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Reviewed-by: Mike Turquette <mturquette@linaro.org>
Tested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>

authored by

Sebastian Hesselbarth and committed by
Jason Cooper
ebd7d3ab 3839c08d

+83 -2
+83 -2
arch/arm/mach-kirkwood/board-dt.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/init.h> 15 15 #include <linux/of.h> 16 + #include <linux/of_address.h> 17 + #include <linux/of_net.h> 16 18 #include <linux/of_platform.h> 17 19 #include <linux/clk-provider.h> 18 20 #include <linux/clocksource.h> ··· 60 58 clk_prepare_enable(clk); 61 59 } 62 60 61 + #define MV643XX_ETH_MAC_ADDR_LOW 0x0414 62 + #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418 63 + 64 + static void __init kirkwood_dt_eth_fixup(void) 65 + { 66 + struct device_node *np; 67 + 68 + /* 69 + * The ethernet interfaces forget the MAC address assigned by u-boot 70 + * if the clocks are turned off. Usually, u-boot on kirkwood boards 71 + * has no DT support to properly set local-mac-address property. 72 + * As a workaround, we get the MAC address from mv643xx_eth registers 73 + * and update the port device node if no valid MAC address is set. 74 + */ 75 + for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") { 76 + struct device_node *pnp = of_get_parent(np); 77 + struct clk *clk; 78 + struct property *pmac; 79 + void __iomem *io; 80 + u8 *macaddr; 81 + u32 reg; 82 + 83 + if (!pnp) 84 + continue; 85 + 86 + /* skip disabled nodes or nodes with valid MAC address*/ 87 + if (!of_device_is_available(pnp) || of_get_mac_address(np)) 88 + goto eth_fixup_skip; 89 + 90 + clk = of_clk_get(pnp, 0); 91 + if (IS_ERR(clk)) 92 + goto eth_fixup_skip; 93 + 94 + io = of_iomap(pnp, 0); 95 + if (!io) 96 + goto eth_fixup_no_map; 97 + 98 + /* ensure port clock is not gated to not hang CPU */ 99 + clk_prepare_enable(clk); 100 + 101 + /* store MAC address register contents in local-mac-address */ 102 + pr_err(FW_INFO "%s: local-mac-address is not set\n", 103 + np->full_name); 104 + 105 + pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL); 106 + if (!pmac) 107 + goto eth_fixup_no_mem; 108 + 109 + pmac->value = pmac + 1; 110 + pmac->length = 6; 111 + pmac->name = kstrdup("local-mac-address", GFP_KERNEL); 112 + if (!pmac->name) { 113 + kfree(pmac); 114 + goto eth_fixup_no_mem; 115 + } 116 + 117 + macaddr = pmac->value; 118 + reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH); 119 + macaddr[0] = (reg >> 24) & 0xff; 120 + macaddr[1] = (reg >> 16) & 0xff; 121 + macaddr[2] = (reg >> 8) & 0xff; 122 + macaddr[3] = reg & 0xff; 123 + 124 + reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW); 125 + macaddr[4] = (reg >> 8) & 0xff; 126 + macaddr[5] = reg & 0xff; 127 + 128 + of_update_property(np, pmac); 129 + 130 + eth_fixup_no_mem: 131 + iounmap(io); 132 + clk_disable_unprepare(clk); 133 + eth_fixup_no_map: 134 + clk_put(clk); 135 + eth_fixup_skip: 136 + of_node_put(pnp); 137 + } 138 + } 139 + 63 140 static void __init kirkwood_dt_time_init(void) 64 141 { 65 142 of_clk_init(NULL); ··· 163 82 kirkwood_l2_init(); 164 83 165 84 kirkwood_cpufreq_init(); 166 - 85 + kirkwood_cpuidle_init(); 167 86 /* Setup clocks for legacy devices */ 168 87 kirkwood_legacy_clk_init(); 169 88 170 89 kirkwood_pm_init(); 171 - kirkwood_cpuidle_init(); 90 + kirkwood_dt_eth_fixup(); 172 91 173 92 #ifdef CONFIG_KEXEC 174 93 kexec_reinit = kirkwood_enable_pcie;