Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dt/net: add helper function of_get_phy_mode

It adds the helper function of_get_phy_mode getting phy interface
from device tree.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: David Miller <davem@davemloft.net>

Shawn Guo 6ca1a113 0ca1e290

+44
+43
drivers/of/of_net.c
··· 8 8 #include <linux/etherdevice.h> 9 9 #include <linux/kernel.h> 10 10 #include <linux/of_net.h> 11 + #include <linux/phy.h> 12 + 13 + /** 14 + * It maps 'enum phy_interface_t' found in include/linux/phy.h 15 + * into the device tree binding of 'phy-mode', so that Ethernet 16 + * device driver can get phy interface from device tree. 17 + */ 18 + static const char *phy_modes[] = { 19 + [PHY_INTERFACE_MODE_MII] = "mii", 20 + [PHY_INTERFACE_MODE_GMII] = "gmii", 21 + [PHY_INTERFACE_MODE_SGMII] = "sgmii", 22 + [PHY_INTERFACE_MODE_TBI] = "tbi", 23 + [PHY_INTERFACE_MODE_RMII] = "rmii", 24 + [PHY_INTERFACE_MODE_RGMII] = "rgmii", 25 + [PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id", 26 + [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid", 27 + [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid", 28 + [PHY_INTERFACE_MODE_RTBI] = "rtbi", 29 + }; 30 + 31 + /** 32 + * of_get_phy_mode - Get phy mode for given device_node 33 + * @np: Pointer to the given device_node 34 + * 35 + * The function gets phy interface string from property 'phy-mode', 36 + * and return its index in phy_modes table, or errno in error case. 37 + */ 38 + const int of_get_phy_mode(struct device_node *np) 39 + { 40 + const char *pm; 41 + int err, i; 42 + 43 + err = of_property_read_string(np, "phy-mode", &pm); 44 + if (err < 0) 45 + return err; 46 + 47 + for (i = 0; i < ARRAY_SIZE(phy_modes); i++) 48 + if (!strcasecmp(pm, phy_modes[i])) 49 + return i; 50 + 51 + return -ENODEV; 52 + } 53 + EXPORT_SYMBOL_GPL(of_get_phy_mode); 11 54 12 55 /** 13 56 * Search the device tree for the best MAC address to use. 'mac-address' is
+1
include/linux/of_net.h
··· 9 9 10 10 #ifdef CONFIG_OF_NET 11 11 #include <linux/of.h> 12 + extern const int of_get_phy_mode(struct device_node *np); 12 13 extern const void *of_get_mac_address(struct device_node *np); 13 14 #endif 14 15