From patchwork Tue Jul 5 15:13:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 2461 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 0B6C124130 for ; Tue, 5 Jul 2011 15:07:43 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id B40E7A186B5 for ; Tue, 5 Jul 2011 15:07:42 +0000 (UTC) Received: by qwb8 with SMTP id 8so4156366qwb.11 for ; Tue, 05 Jul 2011 08:07:42 -0700 (PDT) Received: by 10.229.102.98 with SMTP id f34mr5643863qco.42.1309878462216; Tue, 05 Jul 2011 08:07:42 -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 r7cs53847qcf; Tue, 5 Jul 2011 08:07:42 -0700 (PDT) Received: by 10.52.100.98 with SMTP id ex2mr9489931vdb.194.1309878461712; Tue, 05 Jul 2011 08:07:41 -0700 (PDT) Received: from TX2EHSOBE009.bigfish.com (tx2ehsobe004.messaging.microsoft.com [65.55.88.14]) by mx.google.com with ESMTPS id p7si2582282vcc.81.2011.07.05.08.07.41 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jul 2011 08:07:41 -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 mail115-tx2-R.bigfish.com (10.9.14.251) by TX2EHSOBE009.bigfish.com (10.9.40.29) with Microsoft SMTP Server id 14.1.225.22; Tue, 5 Jul 2011 15:07:40 +0000 Received: from mail115-tx2 (localhost.localdomain [127.0.0.1]) by mail115-tx2-R.bigfish.com (Postfix) with ESMTP id 71B381468239; Tue, 5 Jul 2011 15:07:40 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275dhz2dh87h2a8h668h839h61h) 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 X-FB-DOMAIN-IP-MATCH: fail Received: from mail115-tx2 (localhost.localdomain [127.0.0.1]) by mail115-tx2 (MessageSwitch) id 130987846094227_20356; Tue, 5 Jul 2011 15:07:40 +0000 (UTC) Received: from TX2EHSMHS034.bigfish.com (unknown [10.9.14.239]) by mail115-tx2.bigfish.com (Postfix) with ESMTP id 10ADA1890050; Tue, 5 Jul 2011 15:07:40 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS034.bigfish.com (10.9.99.134) with Microsoft SMTP Server (TLS) id 14.1.225.22; Tue, 5 Jul 2011 15:07:39 +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:38 -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 p65F7Y2q029575; Tue, 5 Jul 2011 10:07:36 -0500 (CDT) From: Shawn Guo To: CC: , , , Shawn Guo , Grant Likely Subject: [PATCH v2 1/3] dt/net: add helper function of_get_phy_mode Date: Tue, 5 Jul 2011 23:13:57 +0800 Message-ID: <1309878839-25743-2-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 It adds the helper function of_get_phy_mode getting phy interface from device tree. Signed-off-by: Shawn Guo Cc: Grant Likely Acked-by: Grant Likely --- drivers/of/of_net.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/of_net.h | 1 + 2 files changed, 44 insertions(+), 0 deletions(-) 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 diff --git a/include/linux/of_net.h b/include/linux/of_net.h index e913081..f474641 100644 --- a/include/linux/of_net.h +++ b/include/linux/of_net.h @@ -9,6 +9,7 @@ #ifdef CONFIG_OF_NET #include +extern const int of_get_phy_mode(struct device_node *np); extern const void *of_get_mac_address(struct device_node *np); #endif