net/ethernet: ks8851_mll mac address configuration support added
authorRaffaele Recalcati <raffaele.recalcati@bticino.it>
Sun, 3 Jun 2012 10:43:43 +0000 (10:43 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 4 Jun 2012 15:43:00 +0000 (11:43 -0400)
Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/micrel/ks8851_mll.c
include/linux/ks8851_mll.h [new file with mode: 0644]

index 5ffde23ac8fb729526a9dc9c7cfebd95fb2e9b09..70bd329882c6231f3d93d61d428875fcfb378aee 100644 (file)
@@ -35,7 +35,7 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <asm/io.h>
+#include <linux/ks8851_mll.h>
 
 #define        DRV_NAME        "ks8851_mll"
 
@@ -1515,6 +1515,7 @@ static int __devinit ks8851_probe(struct platform_device *pdev)
        struct net_device *netdev;
        struct ks_net *ks;
        u16 id, data;
+       struct ks8851_mll_platform_data *pdata;
 
        io_d = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        io_c = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -1596,17 +1597,27 @@ static int __devinit ks8851_probe(struct platform_device *pdev)
        ks_disable_qmu(ks);
        ks_setup(ks);
        ks_setup_int(ks);
-       memcpy(netdev->dev_addr, ks->mac_addr, 6);
 
        data = ks_rdreg16(ks, KS_OBCR);
        ks_wrreg16(ks, KS_OBCR, data | OBCR_ODS_16MA);
 
-       /**
-        * If you want to use the default MAC addr,
-        * comment out the 2 functions below.
-        */
+       /* overwriting the default MAC address */
+       pdata = pdev->dev.platform_data;
+       if (!pdata) {
+               netdev_err(netdev, "No platform data\n");
+               err = -ENODEV;
+               goto err_register;
+       }
+       memcpy(ks->mac_addr, pdata->mac_addr, 6);
+       if (!is_valid_ether_addr(ks->mac_addr)) {
+               /* Use random MAC address if none passed */
+               random_ether_addr(ks->mac_addr);
+               netdev_info(netdev, "Using random mac address\n");
+       }
+       netdev_info(netdev, "Mac address is: %pM\n", ks->mac_addr);
+
+       memcpy(netdev->dev_addr, ks->mac_addr, 6);
 
-       random_ether_addr(netdev->dev_addr);
        ks_set_mac(ks, netdev->dev_addr);
 
        id = ks_rdreg16(ks, KS_CIDER);
diff --git a/include/linux/ks8851_mll.h b/include/linux/ks8851_mll.h
new file mode 100644 (file)
index 0000000..e9ccfb5
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * ks8861_mll platform data struct definition
+ * Copyright (c) 2012 BTicino S.p.A.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _LINUX_KS8851_MLL_H
+#define _LINUX_KS8851_MLL_H
+
+#include <linux/if_ether.h>
+
+/**
+ * struct ks8851_mll_platform_data - Platform data of the KS8851_MLL network driver
+ * @macaddr:   The MAC address of the device, set to all 0:s to use the on in
+ *             the chip.
+ */
+struct ks8851_mll_platform_data {
+       u8 mac_addr[ETH_ALEN];
+};
+
+#endif