From patchwork Tue Jul 5 15:13:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 2462 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AE29224130 for ; Tue, 5 Jul 2011 15:07:46 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id 68750A186B5 for ; Tue, 5 Jul 2011 15:07:46 +0000 (UTC) Received: by mail-qy0-f173.google.com with SMTP id 10so1824280qyk.11 for ; Tue, 05 Jul 2011 08:07:46 -0700 (PDT) Received: by 10.229.54.12 with SMTP id o12mr1944054qcg.80.1309878466137; Tue, 05 Jul 2011 08:07:46 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.48.135 with SMTP id r7cs53850qcf; Tue, 5 Jul 2011 08:07:45 -0700 (PDT) Received: by 10.52.27.199 with SMTP id v7mr6666200vdg.206.1309878465686; Tue, 05 Jul 2011 08:07:45 -0700 (PDT) Received: from TX2EHSOBE009.bigfish.com (tx2ehsobe004.messaging.microsoft.com [65.55.88.14]) by mx.google.com with ESMTPS id t3si3422427vbx.100.2011.07.05.08.07.45 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jul 2011 08:07:45 -0700 (PDT) Received-SPF: neutral (google.com: 65.55.88.14 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) client-ip=65.55.88.14; Authentication-Results: mx.google.com; spf=neutral (google.com: 65.55.88.14 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) smtp.mail=shawn.guo@linaro.org Received: from mail158-tx2-R.bigfish.com (10.9.14.250) by TX2EHSOBE009.bigfish.com (10.9.40.29) with Microsoft SMTP Server id 14.1.225.22; Tue, 5 Jul 2011 15:07:45 +0000 Received: from mail158-tx2 (localhost.localdomain [127.0.0.1]) by mail158-tx2-R.bigfish.com (Postfix) with ESMTP id CEBC2CA01BC; Tue, 5 Jul 2011 15:07:44 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275ch8275dhz2dh87h2a8h668h839h) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-FB-DOMAIN-IP-MATCH: fail Received: from mail158-tx2 (localhost.localdomain [127.0.0.1]) by mail158-tx2 (MessageSwitch) id 1309878462554253_4460; Tue, 5 Jul 2011 15:07:42 +0000 (UTC) Received: from TX2EHSMHS025.bigfish.com (unknown [10.9.14.250]) by mail158-tx2.bigfish.com (Postfix) with ESMTP id 73C8B198004B; Tue, 5 Jul 2011 15:07:42 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS025.bigfish.com (10.9.99.125) with Microsoft SMTP Server (TLS) id 14.1.225.22; Tue, 5 Jul 2011 15:07:42 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.289.8; Tue, 5 Jul 2011 10:07:41 -0500 Received: from S2100-06.ap.freescale.net (S2100-06.ap.freescale.net [10.192.242.125]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id p65F7Y2r029575; Tue, 5 Jul 2011 10:07:38 -0500 (CDT) From: Shawn Guo To: CC: , , , Shawn Guo , "David S. Miller" , Grant Likely Subject: [PATCH v2 2/3] net: ibm_newemac: convert it to use of_get_phy_mode Date: Tue, 5 Jul 2011 23:13:58 +0800 Message-ID: <1309878839-25743-3-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1309878839-25743-1-git-send-email-shawn.guo@linaro.org> References: <1309878839-25743-1-git-send-email-shawn.guo@linaro.org> MIME-Version: 1.0 X-OriginatorOrg: sigmatel.com The patch extends 'enum phy_interface_t' and of_get_phy_mode a little bit with PHY_INTERFACE_MODE_NA and PHY_INTERFACE_MODE_SMII added, and then converts ibm_newemac net driver to use of_get_phy_mode getting phy mode from device tree. It also resolves the namespace conflict on phy_read/write between common mdiobus interface and ibm_newemac private one. Signed-off-by: Shawn Guo Cc: David S. Miller Cc: Grant Likely Acked-by: Grant Likely --- drivers/net/ibm_newemac/core.c | 33 ++++----------------------------- drivers/net/ibm_newemac/emac.h | 19 ++++++++++--------- drivers/net/ibm_newemac/phy.c | 7 +++++-- drivers/of/of_net.c | 2 ++ include/linux/phy.h | 4 +++- 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c index 725399e..70cb7d8 100644 --- a/drivers/net/ibm_newemac/core.c +++ b/drivers/net/ibm_newemac/core.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -2506,18 +2507,6 @@ static int __devinit emac_init_config(struct emac_instance *dev) { struct device_node *np = dev->ofdev->dev.of_node; const void *p; - unsigned int plen; - const char *pm, *phy_modes[] = { - [PHY_MODE_NA] = "", - [PHY_MODE_MII] = "mii", - [PHY_MODE_RMII] = "rmii", - [PHY_MODE_SMII] = "smii", - [PHY_MODE_RGMII] = "rgmii", - [PHY_MODE_TBI] = "tbi", - [PHY_MODE_GMII] = "gmii", - [PHY_MODE_RTBI] = "rtbi", - [PHY_MODE_SGMII] = "sgmii", - }; /* Read config from device-tree */ if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) @@ -2566,23 +2555,9 @@ static int __devinit emac_init_config(struct emac_instance *dev) dev->mal_burst_size = 256; /* PHY mode needs some decoding */ - dev->phy_mode = PHY_MODE_NA; - pm = of_get_property(np, "phy-mode", &plen); - if (pm != NULL) { - int i; - for (i = 0; i < ARRAY_SIZE(phy_modes); i++) - if (!strcasecmp(pm, phy_modes[i])) { - dev->phy_mode = i; - break; - } - } - - /* Backward compat with non-final DT */ - if (dev->phy_mode == PHY_MODE_NA && pm != NULL && plen == 4) { - u32 nmode = *(const u32 *)pm; - if (nmode > PHY_MODE_NA && nmode <= PHY_MODE_SGMII) - dev->phy_mode = nmode; - } + dev->phy_mode = of_get_phy_mode(np); + if (dev->phy_mode < 0) + dev->phy_mode = PHY_MODE_NA; /* Check EMAC version */ if (of_device_is_compatible(np, "ibm,emac4sync")) { diff --git a/drivers/net/ibm_newemac/emac.h b/drivers/net/ibm_newemac/emac.h index 8a61b597..1568278 100644 --- a/drivers/net/ibm_newemac/emac.h +++ b/drivers/net/ibm_newemac/emac.h @@ -26,6 +26,7 @@ #define __IBM_NEWEMAC_H #include +#include /* EMAC registers Write Access rules */ struct emac_regs { @@ -106,15 +107,15 @@ struct emac_regs { /* * PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY) */ -#define PHY_MODE_NA 0 -#define PHY_MODE_MII 1 -#define PHY_MODE_RMII 2 -#define PHY_MODE_SMII 3 -#define PHY_MODE_RGMII 4 -#define PHY_MODE_TBI 5 -#define PHY_MODE_GMII 6 -#define PHY_MODE_RTBI 7 -#define PHY_MODE_SGMII 8 +#define PHY_MODE_NA PHY_INTERFACE_MODE_NA +#define PHY_MODE_MII PHY_INTERFACE_MODE_MII +#define PHY_MODE_RMII PHY_INTERFACE_MODE_RMII +#define PHY_MODE_SMII PHY_INTERFACE_MODE_SMII +#define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII +#define PHY_MODE_TBI PHY_INTERFACE_MODE_TBI +#define PHY_MODE_GMII PHY_INTERFACE_MODE_GMII +#define PHY_MODE_RTBI PHY_INTERFACE_MODE_RTBI +#define PHY_MODE_SGMII PHY_INTERFACE_MODE_SGMII /* EMACx_MR0 */ #define EMAC_MR0_RXI 0x80000000 diff --git a/drivers/net/ibm_newemac/phy.c b/drivers/net/ibm_newemac/phy.c index ac9d964..ab4e596 100644 --- a/drivers/net/ibm_newemac/phy.c +++ b/drivers/net/ibm_newemac/phy.c @@ -28,12 +28,15 @@ #include "emac.h" #include "phy.h" -static inline int phy_read(struct mii_phy *phy, int reg) +#define phy_read _phy_read +#define phy_write _phy_write + +static inline int _phy_read(struct mii_phy *phy, int reg) { return phy->mdio_read(phy->dev, phy->address, reg); } -static inline void phy_write(struct mii_phy *phy, int reg, int val) +static inline void _phy_write(struct mii_phy *phy, int reg, int val) { phy->mdio_write(phy->dev, phy->address, reg, val); } diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index cc117db..bb18471 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -16,6 +16,7 @@ * device driver can get phy interface from device tree. */ static const char *phy_modes[] = { + [PHY_INTERFACE_MODE_NA] = "", [PHY_INTERFACE_MODE_MII] = "mii", [PHY_INTERFACE_MODE_GMII] = "gmii", [PHY_INTERFACE_MODE_SGMII] = "sgmii", @@ -26,6 +27,7 @@ static const char *phy_modes[] = { [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid", [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid", [PHY_INTERFACE_MODE_RTBI] = "rtbi", + [PHY_INTERFACE_MODE_SMII] = "smii", }; /** diff --git a/include/linux/phy.h b/include/linux/phy.h index 7da5fa8..1622081 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -53,6 +53,7 @@ /* Interface Mode definitions */ typedef enum { + PHY_INTERFACE_MODE_NA, PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_SGMII, @@ -62,7 +63,8 @@ typedef enum { PHY_INTERFACE_MODE_RGMII_ID, PHY_INTERFACE_MODE_RGMII_RXID, PHY_INTERFACE_MODE_RGMII_TXID, - PHY_INTERFACE_MODE_RTBI + PHY_INTERFACE_MODE_RTBI, + PHY_INTERFACE_MODE_SMII, } phy_interface_t;