From patchwork Mon Dec 17 14:26:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Turczak X-Patchwork-Id: 206884 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 676622C008E for ; Tue, 18 Dec 2012 01:37:38 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TkblP-0003FT-Am; Mon, 17 Dec 2012 14:33:51 +0000 Received: from netconsequence.de ([85.214.40.104] helo=mx.netconsequence.de) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TkblG-0003EO-Ta for linux-arm-kernel@lists.infradead.org; Mon, 17 Dec 2012 14:33:47 +0000 Received: from [192.168.0.210] (p5DC68340.dip.t-dialin.net [93.198.131.64]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mx.netconsequence.de (Postfix) with ESMTPSA id 569C411E802E; Mon, 17 Dec 2012 15:26:01 +0100 (CET) From: Peter Turczak Subject: [PATCH/RFC] mxs: mach-mxs: Setup mac address prefix from dt Date: Mon, 17 Dec 2012 15:26:02 +0100 Message-Id: To: linux-arm-kernel@lists.infradead.org Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) X-Mailer: Apple Mail (2.1499) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121217_093343_241980_D7EDF8B5 X-CRM114-Status: GOOD ( 14.45 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Shawn Guo X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org This patch enables setting the the fec ethernet mac address either completely from dt, take only the prefix from dt and use the remaining device unique bytes from the OTP or use OTP uniq bytes and the hardcoded values as before when no mac address is specified in the dt. So compatibility should be maintained to devices already shipped. Currently only Denx or Freescale manufacturer prefixes are guessed from the selected hardware platform. The suggested patch provides a more elegant solution because other vendors to just need to adapt their device tree description file. Example: mac0: ethernet@800f0000 { phy-mode = "rmii"; pinctrl-names = "default"; pinctrl-0 = <&mac0_pins_a>; phy-supply = <®_fec_3v3>; phy-reset-gpios = <&gpio2 5 3>; phy-reset-duration = <100>; local-mac-address = [00 04 1E 5E 1B B9]; status = "okay"; }; or mac0: ethernet@800f0000 { phy-mode = "rmii"; pinctrl-names = "default"; pinctrl-0 = <&mac0_pins_a>; phy-supply = <®_fec_3v3>; phy-reset-gpios = <&gpio2 5 3>; phy-reset-duration = <100>; local-mac-address = [00 04 1E]; status = "okay"; }; Signed-off-by: Peter Turczak Cc: Shawn Guo --- arch/arm/mach-mxs/mach-mxs.c | 83 +++++++++++++++++++++++++----------------- 1 files changed, 49 insertions(+), 34 deletions(-) diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c index 4748ec5..d7b349a 100644 --- a/arch/arm/mach-mxs/mach-mxs.c +++ b/arch/arm/mach-mxs/mach-mxs.c @@ -164,54 +164,69 @@ enum mac_oui { static void __init update_fec_mac_prop(enum mac_oui oui) { - struct device_node *np, *from = NULL; - struct property *newmac; + struct device_node *from = NULL; const u32 *ocotp = mxs_get_ocotp(); u8 *macaddr; + const u8 *maddr = NULL; + int len = 0; u32 val; - int i; - - for (i = 0; i < 2; i++) { - np = of_find_compatible_node(from, NULL, "fsl,imx28-fec"); - if (!np) - return; - from = np; - - newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL); - if (!newmac) - return; - newmac->value = newmac + 1; - newmac->length = 6; - - newmac->name = kstrdup("local-mac-address", GFP_KERNEL); - if (!newmac->name) { - kfree(newmac); + int i = 0; + int tt = 0; + + for_each_compatible_node(from, NULL, "fsl,imx28-fec") { + macaddr = kzalloc(6, GFP_KERNEL); + if (!macaddr) { + pr_err("%s: failed to allocate mem for macaddr\n", + __func__); return; } + /*retrieve MAC from DT*/ + maddr = of_get_property(from, "local-mac-address", &len); + val = ocotp[i]; + i++; + + if (maddr && (len == 6)) { + /*6 bytes MAC defined*/ + for (tt = 0; tt < 6; tt++) + macaddr[tt] = maddr[tt]; + + /*overwrite with DT MAC*/ + val = (macaddr[3] << 16) | (macaddr[4] << 8) | + (macaddr[5] << 0); + + pr_debug("MACH-MXS: %i MAC taken from DT\n", i); + } else if (maddr && (len == 3)) { + /*only vendor OUI defined in DT*/ + macaddr[0] = maddr[0]; + macaddr[1] = maddr[1]; + macaddr[2] = maddr[2]; + + pr_debug("MACH-MXS: %i MAC OUI taken from DT\n", i); + } else { /* * OCOTP only stores the last 4 octets for each mac address, * so hard-code OUI here. */ - macaddr = newmac->value; - switch (oui) { - case OUI_FSL: - macaddr[0] = 0x00; - macaddr[1] = 0x04; - macaddr[2] = 0x9f; - break; - case OUI_DENX: - macaddr[0] = 0xc0; - macaddr[1] = 0xe5; - macaddr[2] = 0x4e; - break; + switch (oui) { + case OUI_FSL: + macaddr[0] = 0x00; + macaddr[1] = 0x04; + macaddr[2] = 0x9f; + break; + case OUI_DENX: + macaddr[0] = 0xc0; + macaddr[1] = 0xe5; + macaddr[2] = 0x4e; + break; + } + + pr_debug("MACH-MXS: %i hard-coded MAC taken\n", i); } - val = ocotp[i]; + macaddr[3] = (val >> 16) & 0xff; macaddr[4] = (val >> 8) & 0xff; macaddr[5] = (val >> 0) & 0xff; - - prom_update_property(np, newmac); } }