ks8851: Use MAC address from companion EEPROM

Allow the KS8851 SPI Ethernet controller to read the MAC
address out of its companion EEPROM (if available) and only
generate a random MAC address if the EEPROM is not present
or if the address stored there does not look valid.

Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c
index f79dce2..a3aa860 100644
--- a/drivers/net/ks8851.c
+++ b/drivers/net/ks8851.c
@@ -372,19 +372,26 @@
  * @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()
- * 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.
+ * 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)
 {
 	struct net_device *dev = ks->netdev;
+	int i;
 
-	random_ether_addr(dev->dev_addr);
-	ks8851_write_mac_addr(dev);
+	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);
+
+	if (!(ks->rc_ccr & CCR_EEPROM) || !is_valid_ether_addr(dev->dev_addr)) {
+		random_ether_addr(dev->dev_addr);
+		ks8851_write_mac_addr(dev);
+	}
 }
 
 /**