From patchwork Mon Jul 4 05:50:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 941542 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p645iIWr026083 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 4 Jul 2011 05:44:44 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qdbx4-0000EA-0P; Mon, 04 Jul 2011 05:44:10 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qdbx3-0008VU-LK; Mon, 04 Jul 2011 05:44:09 +0000 Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12] helo=TX2EHSOBE004.bigfish.com) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qdbwz-0008VB-V4 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2011 05:44:07 +0000 Received: from mail32-tx2-R.bigfish.com (10.9.14.243) by TX2EHSOBE004.bigfish.com (10.9.40.24) with Microsoft SMTP Server id 14.1.225.22; Mon, 4 Jul 2011 05:44:03 +0000 Received: from mail32-tx2 (localhost.localdomain [127.0.0.1]) by mail32-tx2-R.bigfish.com (Postfix) with ESMTP id 6C871258124; Mon, 4 Jul 2011 05:44:03 +0000 (UTC) X-SpamScore: -12 X-BigFish: VS-12(zz146fK1432N98dKzz1202hzz8275ch8275dhz2dh2a8h668h839h944h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail32-tx2 (localhost.localdomain [127.0.0.1]) by mail32-tx2 (MessageSwitch) id 1309758243248153_18825; Mon, 4 Jul 2011 05:44:03 +0000 (UTC) Received: from TX2EHSMHS032.bigfish.com (unknown [10.9.14.254]) by mail32-tx2.bigfish.com (Postfix) with ESMTP id 372954E0050; Mon, 4 Jul 2011 05:44:03 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS032.bigfish.com (10.9.99.132) with Microsoft SMTP Server (TLS) id 14.1.225.22; Mon, 4 Jul 2011 05:44:03 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.289.8; Mon, 4 Jul 2011 00:44:02 -0500 Received: from S2100-06.ap.freescale.net (S2100-06.ap.freescale.net [10.192.242.125]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p645hxD0017064; Mon, 4 Jul 2011 00:43:59 -0500 (CDT) Date: Mon, 4 Jul 2011 13:50:22 +0800 From: Shawn Guo To: Grant Likely Subject: Re: [PATCH] net/fec: add device tree probe support Message-ID: <20110704055021.GC10245@S2100-06.ap.freescale.net> References: <1309680401-22904-1-git-send-email-shawn.guo@linaro.org> <20110703212312.GD13742@ponder.secretlab.ca> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110703212312.GD13742@ponder.secretlab.ca> User-Agent: Mutt/1.5.21 (2010-09-15) X-OriginatorOrg: freescale.com X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110704_014406_185260_25A35FD7 X-CRM114-Status: GOOD ( 32.22 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [65.55.88.12 listed in list.dnswl.org] Cc: patches@linaro.org, netdev@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, Jason Liu , Shawn Guo , "David S. Miller" , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 04 Jul 2011 05:44:44 +0000 (UTC) On Sun, Jul 03, 2011 at 03:23:12PM -0600, Grant Likely wrote: > On Sun, Jul 03, 2011 at 04:06:41PM +0800, Shawn Guo wrote: > > It adds device tree probe support for fec driver. > > > > Signed-off-by: Jason Liu > > Signed-off-by: Shawn Guo > > Cc: David S. Miller > > Cc: Grant Likely > > Minor comments below. After addressing them you can add my: > > Acked-by: Grant Likely > > I don't see any reason not to merge this one in v3.1 > > g. > > > --- > > Documentation/devicetree/bindings/net/fsl-fec.txt | 24 ++++ > > drivers/net/fec.c | 120 ++++++++++++++++++++- > > 2 files changed, 139 insertions(+), 5 deletions(-) > > create mode 100644 Documentation/devicetree/bindings/net/fsl-fec.txt > > > > diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt > > new file mode 100644 > > index 0000000..1dad888 > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/net/fsl-fec.txt > > @@ -0,0 +1,24 @@ > > +* Freescale Fast Ethernet Controller (FEC) > > + > > +Required properties: > > +- compatible : Should be "fsl,-fec" > > +- reg : Address and length of the register set for the device > > +- interrupts : Should contain fec interrupt > > +- phy-mode : String, operation mode of the PHY interface. > > + Supported values are: "mii", "gmii", "sgmii", "tbi", "rmii", > > + "rgmii", "rgmii-id", "rgmii-rxid", "rgmii-txid", "rtbi". > > We don't have a common binding for this yet. Should be > "fsl,phy-mode". > There is nothing really fsl specific. How does the following patch look to you? ---8<--------- ------------ [...] > > @@ -734,8 +748,25 @@ static void __inline__ fec_get_mac(struct net_device *ndev) > > */ > > iap = macaddr; > > > > +#ifdef CONFIG_OF > > + /* > > + * 2) from device tree data > > + */ > > + if (!is_valid_ether_addr(iap)) { > > + struct device_node *np = fep->pdev->dev.of_node; > > + if (np) { > > + const char *mac; > > + int err; > > + err = of_property_read_string(np, > > + "local-mac-address", &mac); > > + if (err) > > + iap = (unsigned char *) mac; > > There is already a function for doing this. of_get_mac_address(). > And mac address is *not* a string, it is a byte array. > Yes, I mistakenly converted of_find_property to of_property_read_string. Anyway, I'm now using of_get_mac_address as you suggested. diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index 86f334a..cc117db 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -8,6 +8,49 @@ #include #include #include +#include + +/** + * It maps 'enum phy_interface_t' found in include/linux/phy.h + * into the device tree binding of 'phy-mode', so that Ethernet + * device driver can get phy interface from device tree. + */ +static const char *phy_modes[] = { + [PHY_INTERFACE_MODE_MII] = "mii", + [PHY_INTERFACE_MODE_GMII] = "gmii", + [PHY_INTERFACE_MODE_SGMII] = "sgmii", + [PHY_INTERFACE_MODE_TBI] = "tbi", + [PHY_INTERFACE_MODE_RMII] = "rmii", + [PHY_INTERFACE_MODE_RGMII] = "rgmii", + [PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id", + [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid", + [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid", + [PHY_INTERFACE_MODE_RTBI] = "rtbi", +}; + +/** + * of_get_phy_mode - Get phy mode for given device_node + * @np: Pointer to the given device_node + * + * The function gets phy interface string from property 'phy-mode', + * and return its index in phy_modes table, or errno in error case. + */ +const int of_get_phy_mode(struct device_node *np) +{ + const char *pm; + int err, i; + + err = of_property_read_string(np, "phy-mode", &pm); + if (err < 0) + return err; + + for (i = 0; i < ARRAY_SIZE(phy_modes); i++) + if (!strcasecmp(pm, phy_modes[i])) + return i; + + return -ENODEV; +} +EXPORT_SYMBOL_GPL(of_get_phy_mode); /** * Search the device tree for the best MAC address to use. 'mac-address' is