Skip to content

Commit d1955e1

Browse files
committed
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 <harvey.hunt@imgtec.com>
1 parent 58aab73 commit d1955e1

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

drivers/net/ethernet/davicom/dm9000.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646

4747
#include "dm9000.h"
4848

49+
#ifdef CONFIG_JZ4780_CI20
50+
static char *mac_addr = NULL;
51+
module_param(mac_addr, charp, 0);
52+
#endif
53+
4954
/* Board/System/Debug information/definition ---------------- */
5055

5156
#define DM9000_PHY 0x40 /* PHY address 0x01 */
@@ -1438,6 +1443,10 @@ dm9000_probe(struct platform_device *pdev)
14381443
int reset_gpios;
14391444
enum of_gpio_flags flags;
14401445
struct regulator *power;
1446+
#ifdef CONFIG_JZ4780_CI20
1447+
u8 eth_addr[6];
1448+
ssize_t sz = 0;
1449+
#endif
14411450

14421451
power = devm_regulator_get(dev, "vcc");
14431452
if (IS_ERR(power)) {
@@ -1666,20 +1675,34 @@ dm9000_probe(struct platform_device *pdev)
16661675
db->mii.mdio_read = dm9000_phy_read;
16671676
db->mii.mdio_write = dm9000_phy_write;
16681677

1669-
mac_src = "eeprom";
1678+
#ifdef CONFIG_JZ4780_CI20
1679+
mac_src = "bootarg";
1680+
if (mac_addr)
1681+
sz = sscanf(mac_addr, "%2x:%2x:%2x:%2x:%2x:%2x",
1682+
(unsigned int *)eth_addr,
1683+
(unsigned int *)(eth_addr + 1),
1684+
(unsigned int *)(eth_addr + 2),
1685+
(unsigned int *)(eth_addr + 3),
1686+
(unsigned int *)(eth_addr + 4),
1687+
(unsigned int *)(eth_addr + 5));
1688+
if (sz == ETH_ALEN)
1689+
ether_addr_copy(ndev->dev_addr, eth_addr);
1690+
#endif
16701691

1671-
/* try reading the node address from the attached EEPROM */
1672-
for (i = 0; i < 6; i += 2)
1673-
dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
1692+
if (!is_valid_ether_addr(ndev->dev_addr)) {
1693+
/* try reading the node address from the attached EEPROM */
1694+
mac_src = "eeprom";
1695+
for (i = 0; i < 6; i += 2)
1696+
dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
1697+
}
16741698

16751699
if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
16761700
mac_src = "platform data";
1677-
memcpy(ndev->dev_addr, pdata->dev_addr, ETH_ALEN);
1701+
ether_addr_copy(ndev->dev_addr, pdata->dev_addr);
16781702
}
16791703

16801704
if (!is_valid_ether_addr(ndev->dev_addr)) {
16811705
/* try reading from mac */
1682-
16831706
mac_src = "chip";
16841707
for (i = 0; i < 6; i++)
16851708
ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
@@ -1693,7 +1716,6 @@ dm9000_probe(struct platform_device *pdev)
16931716
mac_src = "random";
16941717
}
16951718

1696-
16971719
platform_set_drvdata(pdev, ndev);
16981720
ret = register_netdev(ndev);
16991721

0 commit comments

Comments
 (0)