--- zzzz-none-000/linux-3.10.107/drivers/of/of_net.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/of/of_net.c 2021-02-04 17:41:59.000000000 +0000 @@ -10,51 +10,44 @@ #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_NA] = "", - [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", - [PHY_INTERFACE_MODE_SMII] = "smii", -}; +#include /** * 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. + * The function gets phy interface string from property 'phy-mode' or + * 'phy-connection-type', and return its index in phy_modes table, or errno in + * error case. */ -const int of_get_phy_mode(struct device_node *np) +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) + err = of_property_read_string(np, "phy-connection-type", &pm); + if (err < 0) return err; - for (i = 0; i < ARRAY_SIZE(phy_modes); i++) - if (!strcasecmp(pm, phy_modes[i])) + for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) + if (!strcasecmp(pm, phy_modes(i))) return i; return -ENODEV; } EXPORT_SYMBOL_GPL(of_get_phy_mode); +static const void *of_get_mac_addr(struct device_node *np, const char *name) +{ + struct property *pp = of_find_property(np, name, NULL); + + if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value)) + return pp->value; + return NULL; +} + /** * Search the device tree for the best MAC address to use. 'mac-address' is * checked first, because that is supposed to contain to "most recent" MAC @@ -75,20 +68,58 @@ */ const void *of_get_mac_address(struct device_node *np) { - struct property *pp; + const void *addr; - pp = of_find_property(np, "mac-address", NULL); - if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) - return pp->value; + addr = of_get_mac_addr(np, "mac-address"); + if (addr) + return addr; - pp = of_find_property(np, "local-mac-address", NULL); - if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) - return pp->value; - - pp = of_find_property(np, "address", NULL); - if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) - return pp->value; + addr = of_get_mac_addr(np, "local-mac-address"); + if (addr) + return addr; - return NULL; + return of_get_mac_addr(np, "address"); } EXPORT_SYMBOL(of_get_mac_address); + +#ifdef CONFIG_MTD +int of_get_mac_address_mtd(struct device_node *np, unsigned char *mac) +{ + struct device_node *mtd_np = NULL; + size_t retlen; + int size, ret; + struct mtd_info *mtd; + const char *part; + const __be32 *list; + phandle phandle; + u32 mac_inc = 0; + + list = of_get_property(np, "mtd-mac-address", &size); + if (!list || (size != (2 * sizeof(*list)))) + return -ENOENT; + + phandle = be32_to_cpup(list++); + if (phandle) + mtd_np = of_find_node_by_phandle(phandle); + + if (!mtd_np) + return -ENOENT; + + part = of_get_property(mtd_np, "label", NULL); + if (!part) + part = mtd_np->name; + + mtd = get_mtd_device_nm(part); + if (IS_ERR(mtd)) + return PTR_ERR(mtd); + + ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac); + put_mtd_device(mtd); + + if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc)) + mac[5] += mac_inc; + + return ret; +} +EXPORT_SYMBOL_GPL(of_get_mac_address_mtd); +#endif