diff options
author | Ben Dooks <ben@simtec.co.uk> | 2011-11-21 03:57:58 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-11-26 14:59:39 -0500 |
commit | a9a8de214c91eecf596b3e79c7986b74ef17f4ec (patch) | |
tree | 2f98e662775ec21c23563c098eedaba04d169a1b /drivers/net/ethernet/micrel/ks8851.c | |
parent | 072bc80156729f853e8bcafe1b17c48c74462887 (diff) |
KSZ8851-SNL: Add support for EEPROM MAC address
Add support for reading the MAC address from the system registers if there
is an EEPROM present. This involves caching the KS_CCR register for later
use (will also be useful for ETHTOOL support) and adding a print to say
that there is an EEPROM present.
Signed-off-by: Ben Dooks <ben@simtec.co.uk>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/micrel/ks8851.c')
-rw-r--r-- | drivers/net/ethernet/micrel/ks8851.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c index f56743a28fc0..d1669bcd4b4d 100644 --- a/drivers/net/ethernet/micrel/ks8851.c +++ b/drivers/net/ethernet/micrel/ks8851.c | |||
@@ -367,21 +367,47 @@ static int ks8851_write_mac_addr(struct net_device *dev) | |||
367 | } | 367 | } |
368 | 368 | ||
369 | /** | 369 | /** |
370 | * ks8851_read_mac_addr - read mac address from device registers | ||
371 | * @dev: The network device | ||
372 | * | ||
373 | * Update our copy of the KS8851 MAC address from the registers of @dev. | ||
374 | */ | ||
375 | static void ks8851_read_mac_addr(struct net_device *dev) | ||
376 | { | ||
377 | struct ks8851_net *ks = netdev_priv(dev); | ||
378 | int i; | ||
379 | |||
380 | mutex_lock(&ks->lock); | ||
381 | |||
382 | for (i = 0; i < ETH_ALEN; i++) | ||
383 | dev->dev_addr[i] = ks8851_rdreg8(ks, KS_MAR(i)); | ||
384 | |||
385 | mutex_unlock(&ks->lock); | ||
386 | } | ||
387 | |||
388 | /** | ||
370 | * ks8851_init_mac - initialise the mac address | 389 | * ks8851_init_mac - initialise the mac address |
371 | * @ks: The device structure | 390 | * @ks: The device structure |
372 | * | 391 | * |
373 | * Get or create the initial mac address for the device and then set that | 392 | * Get or create the initial mac address for the device and then set that |
374 | * into the station address register. Currently we assume that the device | 393 | * into the station address register. If there is an EEPROM present, then |
375 | * does not have a valid mac address in it, and so we use random_ether_addr() | 394 | * we try that. If no valid mac address is found we use random_ether_addr() |
376 | * to create a new one. | 395 | * to create a new one. |
377 | * | ||
378 | * In future, the driver should check to see if the device has an EEPROM | ||
379 | * attached and whether that has a valid ethernet address in it. | ||
380 | */ | 396 | */ |
381 | static void ks8851_init_mac(struct ks8851_net *ks) | 397 | static void ks8851_init_mac(struct ks8851_net *ks) |
382 | { | 398 | { |
383 | struct net_device *dev = ks->netdev; | 399 | struct net_device *dev = ks->netdev; |
384 | 400 | ||
401 | /* first, try reading what we've got already */ | ||
402 | if (ks->rc_ccr & CCR_EEPROM) { | ||
403 | ks8851_read_mac_addr(dev); | ||
404 | if (is_valid_ether_addr(dev->dev_addr)) | ||
405 | return; | ||
406 | |||
407 | netdev_err(ks->netdev, "invalid mac address read %pM\n", | ||
408 | dev->dev_addr); | ||
409 | } | ||
410 | |||
385 | random_ether_addr(dev->dev_addr); | 411 | random_ether_addr(dev->dev_addr); |
386 | ks8851_write_mac_addr(dev); | 412 | ks8851_write_mac_addr(dev); |
387 | } | 413 | } |
@@ -1674,9 +1700,10 @@ static int __devinit ks8851_probe(struct spi_device *spi) | |||
1674 | goto err_netdev; | 1700 | goto err_netdev; |
1675 | } | 1701 | } |
1676 | 1702 | ||
1677 | netdev_info(ndev, "revision %d, MAC %pM, IRQ %d\n", | 1703 | netdev_info(ndev, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n", |
1678 | CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)), | 1704 | CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)), |
1679 | ndev->dev_addr, ndev->irq); | 1705 | ndev->dev_addr, ndev->irq, |
1706 | ks->rc_ccr & CCR_EEPROM ? "has" : "no"); | ||
1680 | 1707 | ||
1681 | return 0; | 1708 | return 0; |
1682 | 1709 | ||