From patchwork Fri Jun 24 18:04:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 917032 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5OHtvV9028994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 24 Jun 2011 17:56:18 GMT Received: from canuck.infradead.org ([134.117.69.58]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QaAbZ-0000wz-MV; Fri, 24 Jun 2011 17:55:46 +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 1QaAbY-0000Iz-VZ; Fri, 24 Jun 2011 17:55:44 +0000 Received: from mail-iw0-f177.google.com ([209.85.214.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QaAb1-00007a-H2 for linux-arm-kernel@lists.infradead.org; Fri, 24 Jun 2011 17:55:13 +0000 Received: by mail-iw0-f177.google.com with SMTP id 35so3145658iwn.36 for ; Fri, 24 Jun 2011 10:55:11 -0700 (PDT) Received: by 10.42.155.4 with SMTP id s4mr3563714icw.32.1308938110942; Fri, 24 Jun 2011 10:55:10 -0700 (PDT) Received: from localhost.localdomain ([117.82.20.237]) by mx.google.com with ESMTPS id a9sm2789268icy.18.2011.06.24.10.55.01 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Jun 2011 10:55:10 -0700 (PDT) From: Shawn Guo To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 4/5] net/fec: add device tree support Date: Sat, 25 Jun 2011 02:04:35 +0800 Message-Id: <1308938676-31121-5-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1308938676-31121-1-git-send-email-shawn.guo@linaro.org> References: <1308938676-31121-1-git-send-email-shawn.guo@linaro.org> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110624_135511_786798_3DBE822C X-CRM114-Status: GOOD ( 21.32 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.177 listed in list.dnswl.org] Cc: patches@linaro.org, netdev@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, Jason Liu , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Shawn Guo , "David S. Miller" 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: , MIME-Version: 1.0 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 (demeter1.kernel.org [140.211.167.41]); Fri, 24 Jun 2011 17:56:18 +0000 (UTC) It adds device tree data parsing support for fec driver. Signed-off-by: Jason Liu Signed-off-by: Shawn Guo Cc: David S. Miller --- Documentation/devicetree/bindings/net/fsl-fec.txt | 22 ++++++ drivers/net/fec.c | 81 +++++++++++++++++++-- 2 files changed, 98 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..345ecb6 --- /dev/null +++ b/Documentation/devicetree/bindings/net/fsl-fec.txt @@ -0,0 +1,22 @@ +* 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". + +Optional properties: +- local-mac-address : 6 bytes, mac address + +Example: + +fec@83fec000 { + compatible = "fsl,imx51-fec", "fsl,imx27-fec"; + reg = <0x83fec000 0x4000>; + interrupts = <87>; + phy-mode = "mii"; + local-mac-address = [00 04 9F 01 1B B9]; +}; diff --git a/drivers/net/fec.c b/drivers/net/fec.c index 885d8ba..16ac1dd 100644 --- a/drivers/net/fec.c +++ b/drivers/net/fec.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include @@ -78,6 +80,12 @@ static struct platform_device_id fec_devtype[] = { { } }; +static const struct of_device_id fec_dt_ids[] = { + { .compatible = "fsl,imx27-fec", .data = &fec_devtype[0], }, + { .compatible = "fsl,imx28-fec", .data = &fec_devtype[1], }, + {}, +}; + static unsigned char macaddr[ETH_ALEN]; module_param_array(macaddr, byte, NULL, 0); MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); @@ -731,8 +739,23 @@ 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 void *p = of_get_property(np, + "local-mac-address", NULL); + if (p) + iap = (unsigned char *) p; + } + } +#endif + /* - * 2) from flash or fuse (via platform data) + * 3) from flash or fuse (via platform data) */ if (!is_valid_ether_addr(iap)) { #ifdef CONFIG_M5272 @@ -745,7 +768,7 @@ static void __inline__ fec_get_mac(struct net_device *ndev) } /* - * 3) FEC mac registers set by bootloader + * 4) FEC mac registers set by bootloader */ if (!is_valid_ether_addr(iap)) { *((unsigned long *) &tmpaddr[0]) = @@ -1355,6 +1378,43 @@ static int fec_enet_init(struct net_device *ndev) return 0; } +#ifdef CONFIG_OF +static int __devinit fec_get_phy_mode_dt(struct net_device *ndev) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct device_node *np = fep->pdev->dev.of_node; + const char *pm, *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", + }; + + if (np) { + pm = of_get_property(np, "phy-mode", NULL); + if (pm) { + int i; + for (i = 0; i < ARRAY_SIZE(phy_modes); i++) + if (!strcasecmp(pm, phy_modes[i])) + return i; + } + } + + return -ENODEV; +} +#else +static int __devinit fec_get_phy_mode_dt(struct net_device *ndev) +{ + return -ENODEV; +} +#endif + static int __devinit fec_probe(struct platform_device *pdev) { @@ -1363,6 +1423,11 @@ fec_probe(struct platform_device *pdev) struct net_device *ndev; int i, irq, ret = 0; struct resource *r; + const struct of_device_id *of_id; + + of_id = of_match_device(fec_dt_ids, &pdev->dev); + if (of_id) + pdev->id_entry = (struct platform_device_id *) of_id->data; r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) @@ -1394,9 +1459,14 @@ fec_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ndev); - pdata = pdev->dev.platform_data; - if (pdata) - fep->phy_interface = pdata->phy; + fep->phy_interface = fec_get_phy_mode_dt(ndev); + if (fep->phy_interface == -ENODEV) { + pdata = pdev->dev.platform_data; + if (pdata) + fep->phy_interface = pdata->phy; + else + fep->phy_interface = PHY_INTERFACE_MODE_MII; + } /* This device has up to three irqs on some platforms */ for (i = 0; i < 3; i++) { @@ -1531,6 +1601,7 @@ static struct platform_driver fec_driver = { #ifdef CONFIG_PM .pm = &fec_pm_ops, #endif + .of_match_table = fec_dt_ids, }, .id_table = fec_devtype, .probe = fec_probe,