summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Dooks <ben-linux@fluff.org>2011-10-25 10:51:47 +0800
committerAndy Green <andy.green@linaro.org>2011-10-25 10:51:47 +0800
commit4083af199f41e4897507d0c3b052a438ce561b82 (patch)
tree0946e90af6678222d2630c1b075020bb4b35367f
parent172682c760ae746c00e3e5ebcca7e7bd0b2c2ff5 (diff)
KS8851: 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: Abraham Arce <x0066660@ti.com>
-rw-r--r--drivers/net/ks8851.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c
index f56743a28fc..2fdb8017007 100644
--- a/drivers/net/ks8851.c
+++ b/drivers/net/ks8851.c
@@ -367,21 +367,47 @@ static int ks8851_write_mac_addr(struct net_device *dev)
}
/**
+ * ks8851_read_mac_addr - read mac address from device registers
+ * @dev: The network device
+ *
+ * Update our copy of the KS8851 MAC address from the registers of @dev.
+ */
+static void ks8851_read_mac_addr(struct net_device *dev)
+{
+ struct ks8851_net *ks = netdev_priv(dev);
+ int i;
+
+ mutex_lock(&ks->lock);
+
+ for (i = 0; i < ETH_ALEN; i++)
+ dev->dev_addr[i] = ks8851_rdreg8(ks, KS_MAR(i));
+
+ mutex_unlock(&ks->lock);
+}
+
+/**
* ks8851_init_mac - initialise the mac address
* @ks: The device structure
*
* Get or create the initial mac address for the device and then set that
- * into the station address register. Currently we assume that the device
- * does not have a valid mac address in it, and so we use random_ether_addr()
+ * into the station address register. If there is an EEPROM present, then
+ * we try that. If no valid mac address is found we use random_ether_addr()
* to create a new one.
- *
- * In future, the driver should check to see if the device has an EEPROM
- * attached and whether that has a valid ethernet address in it.
*/
static void ks8851_init_mac(struct ks8851_net *ks)
{
struct net_device *dev = ks->netdev;
+ /* first, try reading what we've got already */
+ if (ks->rc_ccr & CCR_EEPROM) {
+ ks8851_read_mac_addr(dev);
+ if (is_valid_ether_addr(dev->dev_addr))
+ return;
+
+ netdev_err(ks->netdev, "invalid mac address read %pM\n",
+ dev->dev_addr);
+ }
+
random_ether_addr(dev->dev_addr);
ks8851_write_mac_addr(dev);
}
@@ -1658,6 +1684,9 @@ static int __devinit ks8851_probe(struct spi_device *spi)
else
ks->eeprom_size = 0;
+ /* cache the contents of the CCR register for EEPROM, etc. */
+ ks->rc_ccr = ks8851_rdreg16(ks, KS_CCR);
+
ks8851_read_selftest(ks);
ks8851_init_mac(ks);
@@ -1674,9 +1703,10 @@ static int __devinit ks8851_probe(struct spi_device *spi)
goto err_netdev;
}
- netdev_info(ndev, "revision %d, MAC %pM, IRQ %d\n",
- CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)),
- ndev->dev_addr, ndev->irq);
+ netdev_info(ks->netdev, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n",
+ CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)),
+ ndev->dev_addr, ndev->irq,
+ ks->rc_ccr & CCR_EEPROM ? "has" : "no");
return 0;