From patchwork Wed May 22 20:04:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Hesselbarth X-Patchwork-Id: 2603441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id 46ABF3FD2B for ; Wed, 22 May 2013 20:04:46 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UfFH7-0005QX-PI; Wed, 22 May 2013 20:04:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UfFH4-0002V7-UT; Wed, 22 May 2013 20:04:38 +0000 Received: from mail-ee0-f45.google.com ([74.125.83.45]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UfFH0-0002TZ-Rq for linux-arm-kernel@lists.infradead.org; Wed, 22 May 2013 20:04:36 +0000 Received: by mail-ee0-f45.google.com with SMTP id l10so1350808eei.18 for ; Wed, 22 May 2013 13:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=+6IiBBDekJqgGd2Nq7TMb2tkHB0NzhWzjw4wU3gy6IU=; b=Q1/+oIaj/DoS3ONo87z7vkZniudek519xLxAGsrqrM1DSmuWJQbU0d/iGi6rRIFxVo 0fd1fM84QkHmZ8M24JCrcKqKIWToLmymeQauYwKsMpQm1Vurq+WYqQiFimn1AoiK7cUF frGOcwVYTx2bm2mPonkXcVwtr0PhaQFB5dTkGipTgxt3YJKdqnn734/4fThr6t0gDyEx oyRKBKO/30ES33oamC+MrhM2r8/dvsv+yHXAkKXdi5Px6ncrGq3ve6KXRw37CF+za0Ku w6UADFMwubHR+bW4eq+18g2FCPxggkiQqYL8991D9Qqx1/Xj8+eFzcpLYX/pqmuwyn5S FY7g== X-Received: by 10.15.51.78 with SMTP id m54mr4609126eew.1.1369253052637; Wed, 22 May 2013 13:04:12 -0700 (PDT) Received: from topkick.lan (dslc-082-083-251-181.pools.arcor-ip.net. [82.83.251.181]) by mx.google.com with ESMTPSA id s43sm12211167eem.13.2013.05.22.13.04.10 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 May 2013 13:04:11 -0700 (PDT) Received: from edge.lan (magicgate.lan [192.168.1.1]) by topkick.lan (Postfix) with ESMTPSA id 80B6D60538; Wed, 22 May 2013 22:03:22 +0200 (CEST) From: Sebastian Hesselbarth To: Sebastian Hesselbarth Subject: [PATCH 1/2] ARM: kirkwood: proper retain MAC address workaround on DT ethernet Date: Wed, 22 May 2013 22:04:01 +0200 Message-Id: <1369253042-15082-1-git-send-email-sebastian.hesselbarth@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1369154510-4927-1-git-send-email-sebastian.hesselbarth@gmail.com> References: <1369154510-4927-1-git-send-email-sebastian.hesselbarth@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130522_160435_021778_7B03F576 X-CRM114-Status: GOOD ( 17.23 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.83.45 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (sebastian.hesselbarth[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Andrew Lunn , Jason Cooper , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, David Miller , Lennert Buytenhek X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Kirkwood ethernet controllers suffer from loosing MAC register content on gated clocks. In the past this was prevented by not gating the ethernet controller clocks. With DT support for mv643xx_eth and corresponding nodes available, a different approach is more reasonable. This patch replaces the former clock gating workaround by parsing the ethernet controller nodes for *invalid* MAC addresses and overwrites the local-mac-address property with MAC register contents early. The clock can now properly gated in modular mv643xx_eth and DT agnostic boot loader scenarios because mv643xx_eth will find the stored MAC in the corresponding MAC address property. Signed-off-by: Sebastian Hesselbarth --- Cc: David Miller Cc: Lennert Buytenhek Cc: Jason Cooper Cc: Andrew Lunn Cc: Benjamin Herrenschmidt Cc: netdev@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org --- arch/arm/mach-kirkwood/board-dt.c | 67 +++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/arch/arm/mach-kirkwood/board-dt.c b/arch/arm/mach-kirkwood/board-dt.c index a86b41c..0aad9f7 100644 --- a/arch/arm/mach-kirkwood/board-dt.c +++ b/arch/arm/mach-kirkwood/board-dt.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -31,6 +33,56 @@ static struct of_device_id kirkwood_dt_match_table[] __initdata = { }; /* + * Kirkwood ethernet controllers suffer from loosing the MAC address + * register content on gated clocks. Rather than always ungate the + * clocks, we get the MAC address early and put it into DT for those + * boot loaders that don't provide a valid MAC address property. + */ +#define ETH_MAC_ADDR_L(n) (0x400 + ((n) * 0x400) + 0x14) +#define ETH_MAC_ADDR_H(n) (0x400 + ((n) * 0x400) + 0x18) + +static void __init kirkwood_dt_eth_quirk(void) +{ + struct device_node *np; + + for_each_compatible_node(np, NULL, "marvell,orion-eth") { + struct device_node *pnp; + void __iomem *base; + + if (!of_device_is_available(np)) + continue; + + base = of_iomap(np, 0); + if (!base) + continue; + + for_each_available_child_of_node(np, pnp) { + const void *mac_addr; + struct property *p; + u32 n, reg[2]; + + mac_addr = of_get_mac_address(pnp); + if (mac_addr) + continue; + + p = of_find_property(pnp, "local-mac-address", NULL); + if (!p || p->length != 6) + continue; + + if (of_property_read_u32(pnp, "reg", &n)) + continue; + + reg[0] = cpu_to_be32(readl(base + ETH_MAC_ADDR_H(n))); + reg[1] = cpu_to_be32(readl(base + + ETH_MAC_ADDR_L(n)) << 16); + memcpy((void *)p->value, reg, 6); + } + + iounmap(base); + } +} + +/* * There are still devices that doesn't know about DT yet. Get clock * gates here and add a clock lookup alias, so that old platform * devices still work. @@ -42,7 +94,6 @@ static void __init kirkwood_legacy_clk_init(void) struct device_node *np = of_find_compatible_node( NULL, NULL, "marvell,kirkwood-gating-clock"); struct of_phandle_args clkspec; - struct clk *clk; clkspec.np = np; clkspec.args_count = 1; @@ -58,19 +109,6 @@ static void __init kirkwood_legacy_clk_init(void) clkspec.args[0] = CGC_BIT_SDIO; orion_clkdev_add(NULL, "mvsdio", of_clk_get_from_provider(&clkspec)); - - /* - * The ethernet interfaces forget the MAC address assigned by - * u-boot if the clocks are turned off. Until proper DT support - * is available we always enable them for now. - */ - clkspec.args[0] = CGC_BIT_GE0; - clk = of_clk_get_from_provider(&clkspec); - clk_prepare_enable(clk); - - clkspec.args[0] = CGC_BIT_GE1; - clk = of_clk_get_from_provider(&clkspec); - clk_prepare_enable(clk); } static void __init kirkwood_of_clk_init(void) @@ -97,6 +135,7 @@ static void __init kirkwood_dt_init(void) /* Setup root of clk tree */ kirkwood_of_clk_init(); + kirkwood_dt_eth_quirk(); kirkwood_cpuidle_init();