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.

Change-Id: Id23e88fbbb970daeb28ec0dceba4752eddd2d827
Signed-off-by: Ben Dooks <ben@simtec.co.uk>
[sboyd@codeaurora.org: Remove our implementation]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c
index e338aed..183fa37 100644
--- a/drivers/net/ks8851.c
+++ b/drivers/net/ks8851.c
@@ -370,17 +370,14 @@
 }
 
 /**
- * ks8851_init_mac - initialise the mac address
- * @ks: The device structure
+ * ks8851_read_mac_addr - read mac address from device registers
+ * @dev: The network device
  *
- * Get or create the initial mac address for the device and then set that
- * into the station address register. The device will try to read a MAC address
- * from the EEPROM and program it into the MARs. We use random_ether_addr()
- * if the EEPROM is not present or if the address in the MARs appears invalid.
- */
-static void ks8851_init_mac(struct ks8851_net *ks)
+ * Update our copy of the KS8851 MAC address from the registers of @dev.
+*/
+static void ks8851_read_mac_addr(struct net_device *dev)
 {
-	struct net_device *dev = ks->netdev;
+	struct ks8851_net *ks = netdev_priv(dev);
 	int i;
 
 	mutex_lock(&ks->lock);
@@ -389,11 +386,33 @@
 		dev->dev_addr[i] = ks8851_rdreg8(ks, KS_MAR(i));
 
 	mutex_unlock(&ks->lock);
+}
 
-	if (!(ks->rc_ccr & CCR_EEPROM) || !is_valid_ether_addr(dev->dev_addr)) {
-		random_ether_addr(dev->dev_addr);
-		ks8851_write_mac_addr(dev);
+/**
+ * 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. 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.
+ */
+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);
 }
 
 /**
@@ -1711,9 +1730,10 @@
 		goto err_netdev;
 	}
 
-	netdev_info(ndev, "revision %d, MAC %pM, IRQ %d\n",
+	netdev_info(ndev, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n",
 		    CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)),
-		    ndev->dev_addr, ndev->irq);
+		    ndev->dev_addr, ndev->irq,
+		    ks->rc_ccr & CCR_EEPROM ? "has" : "no");
 
 	return 0;