This patch enables retrieving the wifi calibration data from an MTD partition.
Try to copy mac address from ethernet before generating a random one.
This fixes DGN3500 ath9k support.

Signed-off-by: Daniel Gimpelevich <dan...@gimpelevich.san-francisco.ca.us>
Signed-off-by: Álvaro Fernández Rojas <nolt...@gmail.com>
---
diff --git a/target/linux/lantiq/patches-3.7/0302-wifi-eep.patch 
b/target/linux/lantiq/patches-3.7/0302-wifi-eep.patch
index 8932dfb..e3be82d 100644
--- a/target/linux/lantiq/patches-3.7/0302-wifi-eep.patch
+++ b/target/linux/lantiq/patches-3.7/0302-wifi-eep.patch
@@ -9,12 +9,13 @@
  obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
 --- /dev/null
 +++ b/arch/mips/lantiq/xway/ath_eep.c
-@@ -0,0 +1,195 @@
+@@ -0,0 +1,248 @@
 +/*
 + *  Copyright (C) 2011 Luca Olivetti <l...@ventoso.org>
 + *  Copyright (C) 2011 John Crispin <blo...@openwrt.org>
 + *  Copyright (C) 2011 Andrej Vlašić <andrej.vlas...@gmail.com>
 + *  Copyright (C) 2013 Álvaro Fernández Rojas <nolt...@gmail.com>
++ *  Copyright (C) 2013 Daniel Gimpelevich 
<dan...@gimpelevich.san-francisco.ca.us>
 + *
 + *  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
@@ -28,7 +29,10 @@
 +#include <linux/ath5k_platform.h>
 +#include <linux/ath9k_platform.h>
 +#include <linux/pci.h>
++#include <linux/err.h>
++#include <linux/mtd/mtd.h>
 +#include <pci-ath-fixup.h>
++#include <lantiq_soc.h>
 +
 +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
 +struct ath5k_platform_data ath5k_pdata;
@@ -45,28 +49,50 @@
 +
 +int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
 +{
-+      struct device_node *np = pdev->dev.of_node;
-+      struct resource *eep_res, *mac_res;
++      struct device_node *np = pdev->dev.of_node, *mtd_np;
++      struct resource *eep_res, *mac_res = NULL;
 +      void __iomem *eep, *mac;
 +      int mac_offset;
 +      u32 mac_inc = 0, pci_slot = 0;
 +      int i;
++      struct mtd_info *the_mtd;
++      size_t flash_readlen;
++      const __be32 *list;
++      const char *part;
++      phandle phandle;
++
++      if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
++                      sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
++                      (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
++                      of_get_property(mtd_np, "label", NULL)) || (part =
++                      mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
++                      != ERR_PTR(-ENODEV)) {
++              i = mtd_read(the_mtd, be32_to_cpup(list),
++                              ATH9K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
++                              (void *) ath9k_pdata.eeprom_data);
++              put_mtd_device(the_mtd);
++              if ((sizeof(ath9k_pdata.eeprom_data) != flash_readlen) || i) {
++                      dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
++                      return -ENODEV;
++              }
++      } else {
++              eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
++              mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 +
-+      eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-+      mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
++              if (!eep_res) {
++                      dev_err(&pdev->dev, "failed to load eeprom address\n");
++                      return -ENODEV;
++              }
++              if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
++                      dev_err(&pdev->dev, "eeprom has an invalid size\n");
++                      return -EINVAL;
++              }
 +
-+      if (!eep_res) {
-+              dev_err(&pdev->dev, "failed to load eeprom address\n");
-+              return -ENODEV;
-+      }
-+      if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
-+              dev_err(&pdev->dev, "eeprom has an invalid size\n");
-+              return -EINVAL;
++              eep = ioremap(eep_res->start, resource_size(eep_res));
++              memcpy_fromio(ath9k_pdata.eeprom_data, eep,
++                              ATH9K_PLAT_EEP_MAX_WORDS << 1);
 +      }
 +
-+      eep = ioremap(eep_res->start, resource_size(eep_res));
-+      memcpy_fromio(ath9k_pdata.eeprom_data, eep, ATH9K_PLAT_EEP_MAX_WORDS << 
1);
-+
 +      if (of_find_property(np, "ath,eep-swap", NULL))
 +              for (i = 0; i < ATH9K_PLAT_EEP_MAX_WORDS; i++)
 +                      ath9k_pdata.eeprom_data[i] = 
swab16(ath9k_pdata.eeprom_data[i]);
@@ -86,7 +112,9 @@
 +              }
 +              mac = ioremap(mac_res->start, resource_size(mac_res));
 +              memcpy_fromio(athxk_eeprom_mac, mac, 6);
-+      } else {
++      } else if (ltq_get_eth_mac())
++              memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
++      else {
 +              dev_warn(&pdev->dev, "using random mac\n");
 +              random_ether_addr(athxk_eeprom_mac);
 +      }
@@ -136,28 +164,51 @@
 +
 +int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
 +{
-+      struct device_node *np = pdev->dev.of_node;
-+      struct resource *eep_res, *mac_res;
++      struct device_node *np = pdev->dev.of_node, *mtd_np;
++      struct resource *eep_res, *mac_res = NULL;
 +      void __iomem *eep, *mac;
 +      int mac_offset;
 +      u32 mac_inc = 0;
 +      int i;
++      struct mtd_info *the_mtd;
++      size_t flash_readlen;
++      const __be32 *list;
++      const char *part;
++      phandle phandle;
++
++      if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
++                      sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
++                      (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
++                      of_get_property(mtd_np, "label", NULL)) || (part =
++                      mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
++                      != ERR_PTR(-ENODEV)) {
++              i = mtd_read(the_mtd, be32_to_cpup(list),
++                              ATH5K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
++                              (void *) ath5k_pdata.eeprom_data);
++              put_mtd_device(the_mtd);
++              if ((sizeof(ATH5K_PLAT_EEP_MAX_WORDS << 1) != flash_readlen)
++                              || i) {
++                      dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
++                      return -ENODEV;
++              }
++      } else {
++              eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
++              mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 +
-+      eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-+      mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
++              if (!eep_res) {
++                      dev_err(&pdev->dev, "failed to load eeprom address\n");
++                      return -ENODEV;
++              }
++              if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
++                      dev_err(&pdev->dev, "eeprom has an invalid size\n");
++                      return -EINVAL;
++              }
 +
-+      if (!eep_res) {
-+              dev_err(&pdev->dev, "failed to load eeprom address\n");
-+              return -ENODEV;
-+      }
-+      if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
-+              dev_err(&pdev->dev, "eeprom has an invalid size\n");
-+              return -EINVAL;
++              eep = ioremap(eep_res->start, resource_size(eep_res));
++              memcpy_fromio(ath5k_pdata.eeprom_data, eep,
++                              ATH5K_PLAT_EEP_MAX_WORDS << 1);
 +      }
 +
-+      eep = ioremap(eep_res->start, resource_size(eep_res));
-+      memcpy_fromio(ath5k_pdata.eeprom_data, eep, ATH5K_PLAT_EEP_MAX_WORDS << 
1);
-+
 +      if (of_find_property(np, "ath,eep-swap", NULL))
 +              for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
 +                      ath5k_pdata.eeprom_data[i] = 
swab16(ath5k_pdata.eeprom_data[i]);
@@ -171,7 +222,9 @@
 +              }
 +              mac = ioremap(mac_res->start, resource_size(mac_res));
 +              memcpy_fromio(athxk_eeprom_mac, mac, 6);
-+      } else {
++      } else if (ltq_get_eth_mac())
++              memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
++      else {
 +              dev_warn(&pdev->dev, "using random mac\n");
 +              random_ether_addr(athxk_eeprom_mac);
 +      }
diff --git 
a/target/linux/lantiq/patches-3.8/0037-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch
 
b/target/linux/lantiq/patches-3.8/0037-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch
index 3d64c78..e98a4c0 100644
--- 
a/target/linux/lantiq/patches-3.8/0037-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch
+++ 
b/target/linux/lantiq/patches-3.8/0037-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch
@@ -50,12 +50,13 @@ Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet 
eeprom handling
  obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
 --- /dev/null
 +++ b/arch/mips/lantiq/xway/ath_eep.c
-@@ -0,0 +1,195 @@
+@@ -0,0 +1,248 @@
 +/*
 + *  Copyright (C) 2011 Luca Olivetti <l...@ventoso.org>
 + *  Copyright (C) 2011 John Crispin <blo...@openwrt.org>
 + *  Copyright (C) 2011 Andrej Vlašić <andrej.vlas...@gmail.com>
 + *  Copyright (C) 2013 Álvaro Fernández Rojas <nolt...@gmail.com>
++ *  Copyright (C) 2013 Daniel Gimpelevich 
<dan...@gimpelevich.san-francisco.ca.us>
 + *
 + *  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
@@ -69,7 +70,10 @@ Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet 
eeprom handling
 +#include <linux/ath5k_platform.h>
 +#include <linux/ath9k_platform.h>
 +#include <linux/pci.h>
++#include <linux/err.h>
++#include <linux/mtd/mtd.h>
 +#include <pci-ath-fixup.h>
++#include <lantiq_soc.h>
 +
 +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
 +struct ath5k_platform_data ath5k_pdata;
@@ -86,28 +90,50 @@ Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet 
eeprom handling
 +
 +int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
 +{
-+      struct device_node *np = pdev->dev.of_node;
-+      struct resource *eep_res, *mac_res;
++      struct device_node *np = pdev->dev.of_node, *mtd_np;
++      struct resource *eep_res, *mac_res = NULL;
 +      void __iomem *eep, *mac;
 +      int mac_offset;
 +      u32 mac_inc = 0, pci_slot = 0;
 +      int i;
++      struct mtd_info *the_mtd;
++      size_t flash_readlen;
++      const __be32 *list;
++      const char *part;
++      phandle phandle;
++
++      if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
++                      sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
++                      (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
++                      of_get_property(mtd_np, "label", NULL)) || (part =
++                      mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
++                      != ERR_PTR(-ENODEV)) {
++              i = mtd_read(the_mtd, be32_to_cpup(list),
++                              ATH9K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
++                              (void *) ath9k_pdata.eeprom_data);
++              put_mtd_device(the_mtd);
++              if ((sizeof(ath9k_pdata.eeprom_data) != flash_readlen) || i) {
++                      dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
++                      return -ENODEV;
++              }
++      } else {
++              eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
++              mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 +
-+      eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-+      mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
++              if (!eep_res) {
++                      dev_err(&pdev->dev, "failed to load eeprom address\n");
++                      return -ENODEV;
++              }
++              if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
++                      dev_err(&pdev->dev, "eeprom has an invalid size\n");
++                      return -EINVAL;
++              }
 +
-+      if (!eep_res) {
-+              dev_err(&pdev->dev, "failed to load eeprom address\n");
-+              return -ENODEV;
-+      }
-+      if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
-+              dev_err(&pdev->dev, "eeprom has an invalid size\n");
-+              return -EINVAL;
++              eep = ioremap(eep_res->start, resource_size(eep_res));
++              memcpy_fromio(ath9k_pdata.eeprom_data, eep,
++                              ATH9K_PLAT_EEP_MAX_WORDS << 1);
 +      }
 +
-+      eep = ioremap(eep_res->start, resource_size(eep_res));
-+      memcpy_fromio(ath9k_pdata.eeprom_data, eep, ATH9K_PLAT_EEP_MAX_WORDS << 
1);
-+
 +      if (of_find_property(np, "ath,eep-swap", NULL))
 +              for (i = 0; i < ATH9K_PLAT_EEP_MAX_WORDS; i++)
 +                      ath9k_pdata.eeprom_data[i] = 
swab16(ath9k_pdata.eeprom_data[i]);
@@ -127,7 +153,9 @@ Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet 
eeprom handling
 +              }
 +              mac = ioremap(mac_res->start, resource_size(mac_res));
 +              memcpy_fromio(athxk_eeprom_mac, mac, 6);
-+      } else {
++      } else if (ltq_get_eth_mac())
++              memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
++      else {
 +              dev_warn(&pdev->dev, "using random mac\n");
 +              random_ether_addr(athxk_eeprom_mac);
 +      }
@@ -177,28 +205,51 @@ Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet 
eeprom handling
 +
 +int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
 +{
-+      struct device_node *np = pdev->dev.of_node;
-+      struct resource *eep_res, *mac_res;
++      struct device_node *np = pdev->dev.of_node, *mtd_np;
++      struct resource *eep_res, *mac_res = NULL;
 +      void __iomem *eep, *mac;
 +      int mac_offset;
 +      u32 mac_inc = 0;
 +      int i;
++      struct mtd_info *the_mtd;
++      size_t flash_readlen;
++      const __be32 *list;
++      const char *part;
++      phandle phandle;
++
++      if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
++                      sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
++                      (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
++                      of_get_property(mtd_np, "label", NULL)) || (part =
++                      mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
++                      != ERR_PTR(-ENODEV)) {
++              i = mtd_read(the_mtd, be32_to_cpup(list),
++                              ATH5K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
++                              (void *) ath5k_pdata.eeprom_data);
++              put_mtd_device(the_mtd);
++              if ((sizeof(ATH5K_PLAT_EEP_MAX_WORDS << 1) != flash_readlen)
++                              || i) {
++                      dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
++                      return -ENODEV;
++              }
++      } else {
++              eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
++              mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 +
-+      eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-+      mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
++              if (!eep_res) {
++                      dev_err(&pdev->dev, "failed to load eeprom address\n");
++                      return -ENODEV;
++              }
++              if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
++                      dev_err(&pdev->dev, "eeprom has an invalid size\n");
++                      return -EINVAL;
++              }
 +
-+      if (!eep_res) {
-+              dev_err(&pdev->dev, "failed to load eeprom address\n");
-+              return -ENODEV;
-+      }
-+      if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
-+              dev_err(&pdev->dev, "eeprom has an invalid size\n");
-+              return -EINVAL;
++              eep = ioremap(eep_res->start, resource_size(eep_res));
++              memcpy_fromio(ath5k_pdata.eeprom_data, eep,
++                              ATH5K_PLAT_EEP_MAX_WORDS << 1);
 +      }
 +
-+      eep = ioremap(eep_res->start, resource_size(eep_res));
-+      memcpy_fromio(ath5k_pdata.eeprom_data, eep, ATH5K_PLAT_EEP_MAX_WORDS << 
1);
-+
 +      if (of_find_property(np, "ath,eep-swap", NULL))
 +              for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
 +                      ath5k_pdata.eeprom_data[i] = 
swab16(ath5k_pdata.eeprom_data[i]);
@@ -212,7 +263,9 @@ Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet 
eeprom handling
 +              }
 +              mac = ioremap(mac_res->start, resource_size(mac_res));
 +              memcpy_fromio(athxk_eeprom_mac, mac, 6);
-+      } else {
++      } else if (ltq_get_eth_mac())
++              memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
++      else {
 +              dev_warn(&pdev->dev, "using random mac\n");
 +              random_ether_addr(athxk_eeprom_mac);
 +      }
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to