Skip to content

Commit

Permalink
Merge pull request #37 from HarveyHunt/ci20-v3.18-mac-address
Browse files Browse the repository at this point in the history
net: ethernet: dm9000: Accept a MAC address as a bootarg for CI20.
  • Loading branch information
ZubairLK committed Jun 29, 2015
2 parents a1655e7 + d1955e1 commit e3d0871
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions drivers/net/ethernet/davicom/dm9000.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand All @@ -1693,7 +1716,6 @@ dm9000_probe(struct platform_device *pdev)
mac_src = "random";
}


platform_set_drvdata(pdev, ndev);
ret = register_netdev(ndev);

Expand Down

0 comments on commit e3d0871

Please sign in to comment.