ar71xx: fix WLAN led for RB751U-2HnD and RB751G-2HnD
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-rb750.c
index 3e4a5527f80eb5be99284c81fb437ebc17690075..0115cb3a1ef3ff71ac66c4f8df06f2bf37d2d55a 100644 (file)
 #include <asm/mach-ath79/mach-rb750.h>
 
 #include "common.h"
+#include "dev-ap9x-pci.h"
 #include "dev-usb.h"
 #include "dev-eth.h"
 #include "machtypes.h"
-#include "pci-ath9k-fixup.h"
-#include "pci.h"
 
 static struct rb750_led_data rb750_leds[] = {
        {
@@ -278,45 +277,33 @@ static void __init rb750gr3_setup(void)
 MIPS_MACHINE(ATH79_MACH_RB_750G_R3, "750Gr3", "MikroTik RouterBOARD 750GL",
             rb750gr3_setup);
 
-static struct ath9k_platform_data rb751_wmac_data = {
-       .led_pin = -1,
-};
-
-static u8 rb751_wmac_mac[6];
-
-static int rb751_pci_plat_dev_init(struct pci_dev *dev)
-{
-       switch (PCI_SLOT(dev->devfn)) {
-       case 0:
-               dev->dev.platform_data = &rb751_wmac_data;
-               break;
-       }
-
-       return 0;
-}
-
 static int decode_rle(char *output, int len, char *in)
 {
        char *ptr = output;
        char *end = output + len;
+
+       if (!output || !in)
+               return -EINVAL;
+
        while (*in) {
                if (*in < 0) {
                        int i = -*in++;
                        while (i-- > 0) {
                                if (ptr >= end)
-                                       return -1;
+                                       return -EINVAL;
                                *ptr++ = *in++;
                        }
                } else if (*in > 0) {
                        int i = *in++;
                        while (i-- > 0) {
                                if (ptr >= end)
-                                       return -1;
+                                       return -EINVAL;
                                *ptr++ = *in;
                        }
                        in++;
                }
        }
+
        return ptr - output;
 }
 
@@ -324,31 +311,36 @@ static int decode_rle(char *output, int len, char *in)
 #define RB751_MAC_ADDRESS_OFFSET 0xE80
 #define RB751_CALDATA_OFFSET 0x27C
 
-static void __init rb751_wlan_and_usb_setup(void)
+static void __init rb751_wlan_setup(void)
 {
        u8 *hardconfig = (u8 *) KSEG1ADDR(RB751_HARDCONFIG);
+       struct ath9k_platform_data *wmac_data;
+       int dec_size;
 
-       ath79_register_usb();
-
-       ath79_pci_set_plat_dev_init(rb751_pci_plat_dev_init);
-       ath79_register_pci();
+       wmac_data = ap9x_pci_get_wmac_data(0);
+       if (!wmac_data) {
+               pr_err("rb75x: unable to get address of wlan data\n");
+               return;
+       }
 
-       rb751_wmac_data.macaddr = memcpy(rb751_wmac_mac,
-                       hardconfig + RB751_MAC_ADDRESS_OFFSET, 6);
+       ap9x_pci_setup_wmac_led_pin(0, 9);
 
-       if (decode_rle((char *)rb751_wmac_data.eeprom_data,
-                       sizeof(rb751_wmac_data.eeprom_data),
-                       hardconfig + RB751_CALDATA_OFFSET) ==
-                       sizeof(rb751_wmac_data.eeprom_data)) {
-               pr_info("rb7xx: calibration data found\n");
-               pci_enable_ath9k_fixup(0, rb751_wmac_data.eeprom_data);
+       dec_size = decode_rle((char *) wmac_data->eeprom_data,
+                             sizeof(wmac_data->eeprom_data),
+                             hardconfig + RB751_CALDATA_OFFSET);
+       if (dec_size != sizeof(wmac_data->eeprom_data)) {
+               pr_err("rb75x: unable to decode wlan eeprom data\n");
+               return;
        }
+
+       ap91_pci_init(NULL, hardconfig + RB751_MAC_ADDRESS_OFFSET);
 }
 
 static void __init rb751_setup(void)
 {
        rb750_setup();
-       rb751_wlan_and_usb_setup();
+       ath79_register_usb();
+       rb751_wlan_setup();
 }
 
 MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
@@ -357,7 +349,8 @@ MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
 static void __init rb751g_setup(void)
 {
        rb750gr3_setup();
-       rb751_wlan_and_usb_setup();
+       ath79_register_usb();
+       rb751_wlan_setup();
 }
 
 MIPS_MACHINE(ATH79_MACH_RB_751G, "751g", "MikroTik RouterBOARD 751G",