From d1955e1f2a9f0b9ca8c86c58acb3549e625c1266 Mon Sep 17 00:00:00 2001 From: Harvey Hunt Date: Fri, 26 Jun 2015 10:55:41 +0100 Subject: [PATCH] net: ethernet: dm9000: Accept a MAC address as a bootarg for CI20. The MAC address for the CI20's DM9000 is stored in EEPROM on a different part of the board. Previously, the DM9000 would make up a random MAC after failing to read its own EEPROM. This commit makes it possible for U-BOOT to pass the MAC address to the DM9000 driver. Such as: bootargs="dm9000.mac_addr=${ethaddr}" Note: This isn't the "correct" way to do this, but will do for now. The correct method would be to recompile U-BOOT with CONFIG_OF_LIBFDT and CONFIG_FIT enabled. Then the kernel should be compiled as a FIT image and U-BOOT can then add an entry to the DM9000's DT node to set the MAC address (local-mac-address = [xx xx xx xx xx xx];). Signed-off-by: Harvey Hunt --- drivers/net/ethernet/davicom/dm9000.c | 36 +++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c index 0bb36debe4a830..fd6553907ba090 100644 --- a/drivers/net/ethernet/davicom/dm9000.c +++ b/drivers/net/ethernet/davicom/dm9000.c @@ -46,6 +46,11 @@ #include "dm9000.h" +#ifdef CONFIG_JZ4780_CI20 +static char *mac_addr = NULL; +module_param(mac_addr, charp, 0); +#endif + /* Board/System/Debug information/definition ---------------- */ #define DM9000_PHY 0x40 /* PHY address 0x01 */ @@ -1438,6 +1443,10 @@ dm9000_probe(struct platform_device *pdev) int reset_gpios; enum of_gpio_flags flags; struct regulator *power; +#ifdef CONFIG_JZ4780_CI20 + u8 eth_addr[6]; + ssize_t sz = 0; +#endif power = devm_regulator_get(dev, "vcc"); if (IS_ERR(power)) { @@ -1666,20 +1675,34 @@ dm9000_probe(struct platform_device *pdev) db->mii.mdio_read = dm9000_phy_read; db->mii.mdio_write = dm9000_phy_write; - mac_src = "eeprom"; +#ifdef CONFIG_JZ4780_CI20 + mac_src = "bootarg"; + if (mac_addr) + sz = sscanf(mac_addr, "%2x:%2x:%2x:%2x:%2x:%2x", + (unsigned int *)eth_addr, + (unsigned int *)(eth_addr + 1), + (unsigned int *)(eth_addr + 2), + (unsigned int *)(eth_addr + 3), + (unsigned int *)(eth_addr + 4), + (unsigned int *)(eth_addr + 5)); + if (sz == ETH_ALEN) + ether_addr_copy(ndev->dev_addr, eth_addr); +#endif - /* try reading the node address from the attached EEPROM */ - for (i = 0; i < 6; i += 2) - dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i); + if (!is_valid_ether_addr(ndev->dev_addr)) { + /* try reading the node address from the attached EEPROM */ + mac_src = "eeprom"; + for (i = 0; i < 6; i += 2) + dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i); + } if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) { mac_src = "platform data"; - memcpy(ndev->dev_addr, pdata->dev_addr, ETH_ALEN); + ether_addr_copy(ndev->dev_addr, pdata->dev_addr); } if (!is_valid_ether_addr(ndev->dev_addr)) { /* try reading from mac */ - mac_src = "chip"; for (i = 0; i < 6; i++) ndev->dev_addr[i] = ior(db, i+DM9000_PAR); @@ -1693,7 +1716,6 @@ dm9000_probe(struct platform_device *pdev) mac_src = "random"; } - platform_set_drvdata(pdev, ndev); ret = register_netdev(ndev);