From 65945c8e47e9b34e3b03be603dea714e57607952 Mon Sep 17 00:00:00 2001 From: Shawn Guo Date: Mon, 4 Jul 2011 14:03:17 +0800 Subject: [PATCH] --- yaml --- r: 261126 b: refs/heads/master c: 6ca1a113791eb09dac8c48b2b264c4d72aab410f h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/drivers/of/of_net.c | 43 ++++++++++++++++++++++++++++++++++++ trunk/include/linux/of_net.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index e6317f7ce75e..c982e89b725b 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 0ca1e290b7c517300bf6cc4f14ebcedb5dfea5cc +refs/heads/master: 6ca1a113791eb09dac8c48b2b264c4d72aab410f diff --git a/trunk/drivers/of/of_net.c b/trunk/drivers/of/of_net.c index 86f334a2769c..cc117db05891 100644 --- a/trunk/drivers/of/of_net.c +++ b/trunk/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/trunk/include/linux/of_net.h b/trunk/include/linux/of_net.h index e913081fb52a..f47464188710 100644 --- a/trunk/include/linux/of_net.h +++ b/trunk/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