From: Nick Date: Mon, 3 Jun 2019 09:54:49 +0000 (+0800) Subject: MAC: get ethernet mac address from command line or DTB X-Git-Tag: khadas-vims-v0.9.6-release~617 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1343e5172031efe6b8e620ccbae40df71f1cc994;p=platform%2Fkernel%2Flinux-amlogic.git MAC: get ethernet mac address from command line or DTB Signed-off-by: Nick --- diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 68854f8..2451c68 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -33,6 +33,38 @@ #include "stmmac.h" #include "stmmac_platform.h" +#ifdef CONFIG_DWMAC_MESON +static u8 DEFMAC[] = {0, 0, 0, 0, 0, 0}; +static unsigned int g_mac_addr_setup; +static unsigned char chartonum(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'A' && c <= 'F') + return (c - 'A') + 10; + if (c >= 'a' && c <= 'f') + return (c - 'a') + 10; + + return 0; +} + +static int __init mac_addr_set(char *line) +{ + unsigned char mac[6]; + int i = 0; + for (i = 0; i < 6 && line[0] != '\0' && line[1] != '\0'; i++) { + mac[i] = chartonum(line[0]) << 4 | chartonum(line[1]); + line += 3; + } + memcpy(DEFMAC, mac, 6); + pr_debug("uboot setup mac-addr: %x:%x:%x:%x:%x:%x\n", + DEFMAC[0], DEFMAC[1], DEFMAC[2], DEFMAC[3], DEFMAC[4], DEFMAC[5]); + g_mac_addr_setup++; + return 0; +} +__setup("mac=", mac_addr_set); +#endif + #ifdef CONFIG_OF /** @@ -198,6 +230,20 @@ static int stmmac_dt_phy(struct plat_stmmacenet_data *plat, return 0; } +static int setup_mac_addr(struct platform_device *pdev, const char **mac) +{ + struct device_node *np = pdev->dev.of_node; +#ifdef CONFIG_DWMAC_MESON + if (g_mac_addr_setup) /*so uboot mac= is first priority.*/ + *mac = DEFMAC; + else + *mac = of_get_mac_address(np); +#else + *mac = of_get_mac_address(np); +#endif + return 0; +} + /** * stmmac_probe_config_dt - parse device-tree driver parameters * @pdev: platform_device structure @@ -217,7 +263,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) if (!plat) return ERR_PTR(-ENOMEM); - *mac = of_get_mac_address(np); + setup_mac_addr(pdev, mac); plat->interface = of_get_phy_mode(np); /* Get max speed of operation from device tree */