Fixes the MAC address handling on avila NPE on startup
[openwrt.git] / target / linux / ixp4xx / patches-2.6.23 / 300-avila_fetch_mac.patch
1 diff -r -u linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c ../../../../trunk/build_dir/linux-ixp4xx_generic/linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c
2 --- linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c  2008-01-04 01:28:24.134925761 +0100
3 +++ ../../../../trunk/build_dir/linux-ixp4xx_generic/linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c 2008-01-04 01:23:27.874042817 +0100
4 @@ -14,10 +14,18 @@
5  #include <linux/kernel.h>
6  #include <linux/init.h>
7  #include <linux/device.h>
8 +#include <linux/if_ether.h>
9 +#include <linux/socket.h>
10 +#include <linux/netdevice.h>
11  #include <linux/serial.h>
12  #include <linux/tty.h>
13  #include <linux/serial_8250.h>
14  #include <linux/slab.h>
15 +#ifdef CONFIG_SENSORS_EEPROM
16 +# include <linux/i2c.h>
17 +# include <linux/eeprom.h>
18 +#endif
19 +
20  #include <linux/i2c-gpio.h>
21  
22  #include <asm/types.h>
23 @@ -194,9 +202,48 @@
24      t->hdr.size = 0;
25  }
26  
27 +#ifdef CONFIG_SENSORS_EEPROM
28 +static int loft_eeprom_do(struct notifier_block *self, unsigned long event, void *t)
29 +{
30 +       struct eeprom_data *data = t;
31 +       struct sockaddr address;
32 +       struct net_device * netdev ;
33 +
34 +       char macs[12];
35 +
36 +       /* The MACs are the first 12 bytes in the eeprom at address 0x51 */
37 +       if (event == EEPROM_REGISTER && data->client.addr == 0x51) {
38 +               data->attr->read(&data->client.dev.kobj, data->attr, macs, 0, 12);
39 +               /*eth0*/
40 +               /* using dev_get_by_name here is really ugly and can cause
41 +               * confusion if other ethernet devices are present. FIXME */
42 +               
43 +               memcpy(address.sa_data, macs, ETH_ALEN);
44 +                       memcpy(&avila_plat_eth[0].hwaddr, macs, ETH_ALEN);
45 +               if ( (netdev = dev_get_by_name("eth0")) )
46 +                       netdev->set_mac_address(netdev, &address);
47 +
48 +                /*same for eth1*/
49 +               memcpy(address.sa_data, macs + ETH_ALEN, ETH_ALEN);
50 +              memcpy(&avila_plat_eth[1].hwaddr, macs + ETH_ALEN, ETH_ALEN);
51 +               if ( (netdev = dev_get_by_name("eth1")) )
52 +                       netdev->set_mac_address(netdev, &address);
53 +       }
54 +
55 +       return NOTIFY_DONE;
56 +}
57 +
58 +static struct notifier_block loft_eeprom_notifier = {
59 +       .notifier_call = loft_eeprom_do
60 +};
61 +#endif
62 +
63  static void __init avila_init(void)
64  {
65         ixp4xx_sys_init();
66 +#ifdef CONFIG_SENSORS_EEPROM
67 +       register_eeprom_notifier(&loft_eeprom_notifier);
68 +#endif
69  
70         avila_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
71         avila_flash_resource.end =
72