[ARM] pxa/colibri: provide MAC address from ATAG_SERIAL
authorDaniel Mack <daniel@caiaq.de>
Thu, 2 Apr 2009 06:33:14 +0000 (08:33 +0200)
committerEric Miao <eric.miao@marvell.com>
Sat, 4 Apr 2009 02:26:34 +0000 (10:26 +0800)
In 67fca028f1535e510689d2e444b0289e264e05c1, the ax88796 ethernet driver
learned a way to let the platform data hand in the MAC address. Use it
here as the original Colibri bootloader passes in a MAC address via
ATAG_SERIAL.

Reported-by: Matthias Meier <matthias.j.meier@gmx.net>
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
arch/arm/mach-pxa/colibri-pxa300.c
arch/arm/mach-pxa/colibri-pxa320.c
arch/arm/mach-pxa/colibri-pxa3xx.c
arch/arm/mach-pxa/include/mach/colibri.h

index 10c2eaf..0964eda 100644 (file)
 
 #if defined(CONFIG_AX88796)
 #define COLIBRI_ETH_IRQ_GPIO   mfp_to_gpio(GPIO26_GPIO)
+
 /*
  * Asix AX88796 Ethernet
  */
 static struct ax_plat_data colibri_asix_platdata = {
-       .flags          = AXFLG_MAC_FROMDEV,
-       .wordlength     = 2
+       .flags          = 0, /* defined later */
+       .wordlength     = 2,
 };
 
 static struct resource colibri_asix_resource[] = {
@@ -70,6 +71,7 @@ static mfp_cfg_t colibri_pxa300_eth_pin_config[] __initdata = {
 
 static void __init colibri_pxa300_init_eth(void)
 {
+       colibri_pxa3xx_init_eth(&colibri_asix_platdata);
        pxa3xx_mfp_config(ARRAY_AND_SIZE(colibri_pxa300_eth_pin_config));
        set_irq_type(gpio_to_irq(COLIBRI_ETH_IRQ_GPIO), IRQ_TYPE_EDGE_FALLING);
        platform_device_register(&asix_device);
index 55b74a7..8a742b7 100644 (file)
@@ -38,8 +38,8 @@
  * Asix AX88796 Ethernet
  */
 static struct ax_plat_data colibri_asix_platdata = {
-       .flags          = AXFLG_MAC_FROMDEV,
-       .wordlength     = 2
+       .flags          = 0, /* defined later */
+       .wordlength     = 2,
 };
 
 static struct resource colibri_asix_resource[] = {
@@ -72,6 +72,7 @@ static mfp_cfg_t colibri_pxa320_eth_pin_config[] __initdata = {
 
 static void __init colibri_pxa320_init_eth(void)
 {
+       colibri_pxa3xx_init_eth(&colibri_asix_platdata);
        pxa3xx_mfp_config(ARRAY_AND_SIZE(colibri_pxa320_eth_pin_config));
        set_irq_type(gpio_to_irq(COLIBRI_ETH_IRQ_GPIO), IRQ_TYPE_EDGE_FALLING);
        platform_device_register(&asix_device);
index 12d0afc..ea34e34 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
+#include <linux/etherdevice.h>
 #include <asm/mach-types.h>
 #include <mach/hardware.h>
 #include <asm/sizes.h>
 #include "generic.h"
 #include "devices.h"
 
+#if defined(CONFIG_AX88796)
+#define ETHER_ADDR_LEN 6
+static u8 ether_mac_addr[ETHER_ADDR_LEN];
+
+void __init colibri_pxa3xx_init_eth(struct ax_plat_data *plat_data)
+{
+       int i;
+       u64 serial = ((u64) system_serial_high << 32) | system_serial_low;
+
+       /*
+        * If the bootloader passed in a serial boot tag, which contains a
+        * valid ethernet MAC, pass it to the interface. Toradex ships the
+        * modules with their own bootloader which provides a valid MAC
+        * this way.
+        */
+
+       for (i = 0; i < ETHER_ADDR_LEN; i++) {
+               ether_mac_addr[i] = serial & 0xff;
+               serial >>= 8;
+       }
+
+       if (is_valid_ether_addr(ether_mac_addr)) {
+               plat_data->flags |= AXFLG_MAC_FROMPLATFORM;
+               plat_data->mac_addr = ether_mac_addr;
+               printk(KERN_INFO "%s(): taking MAC from serial boot tag\n",
+                       __func__);
+       } else {
+               plat_data->flags |= AXFLG_MAC_FROMDEV;
+               printk(KERN_INFO "%s(): no valid serial boot tag found, "
+                       "taking MAC from device\n", __func__);
+       }
+}
+#endif
+
 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
 static int mmc_detect_pin;
 
index 3f2a01d..306ad64 100644 (file)
@@ -16,6 +16,10 @@ extern void colibri_pxa3xx_init_lcd(int bl_pin);
 static inline void colibri_pxa3xx_init_lcd(int) {}
 #endif
 
+#if defined(CONFIG_AX88796)
+extern void colibri_pxa3xx_init_eth(struct ax_plat_data *plat_data);
+#endif
+
 /* physical memory regions */
 #define COLIBRI_SDRAM_BASE     0xa0000000      /* SDRAM region */