lantiq: add swconfig to the default packages
[oweals/openwrt.git] / target / linux / lantiq / patches-4.4 / 0035-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch
index 07e6a001ebac4847ab3b15c4243ecd86e1fe0186..fffd42d0ecd5172e3deb50d835b1b3ec066b7673 100644 (file)
@@ -5,19 +5,18 @@ Subject: [PATCH 35/36] owrt: lantiq: wifi and ethernet eeprom handling
 
 Signed-off-by: John Crispin <blogic@openwrt.org>
 ---
- arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h  |    6 +
- .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h |    3 +
- arch/mips/lantiq/xway/Makefile                     |    3 +
- arch/mips/lantiq/xway/ath_eep.c                    |  282 ++++++++++++++++++++
- arch/mips/lantiq/xway/eth_mac.c                    |   76 ++++++
- arch/mips/lantiq/xway/pci-ath-fixup.c              |  109 ++++++++
- arch/mips/lantiq/xway/rt_eep.c                     |   60 +++++
- 7 files changed, 539 insertions(+)
+ arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h  |   6 +
+ .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h |   3 +
+ arch/mips/lantiq/xway/Makefile                     |   3 +
+ arch/mips/lantiq/xway/ath_eep.c                    | 299 +++++++++++++++++++++
+ arch/mips/lantiq/xway/eth_mac.c                    |  25 ++
+ arch/mips/lantiq/xway/pci-ath-fixup.c              | 118 ++++++++
+ drivers/net/ethernet/lantiq_etop.c                 |   6 +-
+ 7 files changed, 459 insertions(+), 1 deletion(-)
  create mode 100644 arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h
  create mode 100644 arch/mips/lantiq/xway/ath_eep.c
  create mode 100644 arch/mips/lantiq/xway/eth_mac.c
  create mode 100644 arch/mips/lantiq/xway/pci-ath-fixup.c
- create mode 100644 arch/mips/lantiq/xway/rt_eep.c
 
 --- /dev/null
 +++ b/arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h
@@ -30,7 +29,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +#endif /* _PCI_ATH_FIXUP */
 --- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
 +++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
-@@ -104,5 +104,8 @@
+@@ -104,5 +104,8 @@ int xrx200_gphy_boot(struct device *dev,
  extern void ltq_pmu_enable(unsigned int module);
  extern void ltq_pmu_disable(unsigned int module);
  
@@ -41,17 +40,17 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  #endif /* _LTQ_XWAY_H__ */
 --- a/arch/mips/lantiq/xway/Makefile
 +++ b/arch/mips/lantiq/xway/Makefile
-@@ -2,4 +2,7 @@
+@@ -2,4 +2,7 @@ obj-y := prom.o sysctrl.o clk.o reset.o
  
  obj-y += vmmc.o tffs.o
  
 +obj-y += eth_mac.o
-+obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
++obj-$(CONFIG_PCI) += ath_eep.o pci-ath-fixup.o
 +
  obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
 --- /dev/null
 +++ b/arch/mips/lantiq/xway/ath_eep.c
-@@ -0,0 +1,307 @@
+@@ -0,0 +1,299 @@
 +/*
 + *  Copyright (C) 2011 Luca Olivetti <luca@ventoso.org>
 + *  Copyright (C) 2011 John Crispin <blogic@openwrt.org>
@@ -93,9 +92,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +static int ath9k_eep_load;
 +int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
 +{
-+      struct device_node *np = pdev->dev.of_node, *mtd_np;
-+      struct resource *eep_res, *mac_res = NULL;
-+      void __iomem *eep, *mac;
++      struct device_node *np = pdev->dev.of_node, *mtd_np = NULL;
 +      int mac_offset, led_pin;
 +      u32 mac_inc = 0, pci_slot = 0;
 +      int i;
@@ -106,41 +103,38 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +      phandle phandle;
 +      u16 dev_ids[2] = { 0 };
 +
-+      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);
-+              if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
-+                      size_t mac_readlen;
-+                      mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
-+                              (void *) athxk_eeprom_mac);
-+              }
-+              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);
-+
-+              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);
++      list = of_get_property(np, "ath,eep-flash", &i);
++      if (!list || (i != (2 * sizeof(*list))))
++              return -ENODEV;
++
++      phandle = be32_to_cpup(list++);
++      if (phandle)
++              mtd_np = of_find_node_by_phandle(phandle);
++
++      if (!mtd_np)
++              return -ENODEV;
++
++      part = of_get_property(mtd_np, "label", NULL);
++      if (!part)
++              part = mtd_np->name;
++
++      the_mtd = get_mtd_device_nm(part);
++      if (IS_ERR(the_mtd))
++              return -ENODEV;
++
++      i = mtd_read(the_mtd, be32_to_cpup(list), ATH9K_PLAT_EEP_MAX_WORDS << 1,
++              &flash_readlen, (void *) ath9k_pdata.eeprom_data);
++
++      if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
++              size_t mac_readlen;
++              mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
++                      (void *) athxk_eeprom_mac);
++      }
++      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;
 +      }
 +
 +      if (of_find_property(np, "ath,eep-swap", NULL))
@@ -153,18 +147,9 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +              dev_info(&pdev->dev, "endian check enabled.\n");
 +      }
 +
-+      if (!is_valid_ether_addr(athxk_eeprom_mac)) {
-+              if (mac_res) {
-+                      if (resource_size(mac_res) != 6) {
-+                              dev_err(&pdev->dev, "mac has an invalid size\n");
-+                              return -EINVAL;
-+                      }
-+                      mac = ioremap(mac_res->start, resource_size(mac_res));
-+                      memcpy_fromio(athxk_eeprom_mac, mac, 6);
-+              } else if (ltq_get_eth_mac()) {
-+                      memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
-+              }
-+      }
++      if (!is_valid_ether_addr(athxk_eeprom_mac) && ltq_get_eth_mac())
++              memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
++
 +      if (!is_valid_ether_addr(athxk_eeprom_mac)) {
 +              dev_warn(&pdev->dev, "using random mac\n");
 +              random_ether_addr(athxk_eeprom_mac);
@@ -261,11 +246,10 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +      return 0;
 +}
 +
++static int ath5k_eep_load;
 +int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
 +{
-+      struct device_node *np = pdev->dev.of_node, *mtd_np;
-+      struct resource *eep_res, *mac_res = NULL;
-+      void __iomem *eep, *mac;
++      struct device_node *np = pdev->dev.of_node, *mtd_np = NULL;
 +      int mac_offset;
 +      u32 mac_inc = 0;
 +      int i;
@@ -275,57 +259,50 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +      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);
-+
-+              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));
-+              ath5k_pdata.eeprom_data = kmalloc(ATH5K_PLAT_EEP_MAX_WORDS<<1,
-+                              GFP_KERNEL);
-+              memcpy_fromio(ath5k_pdata.eeprom_data, eep,
-+                              ATH5K_PLAT_EEP_MAX_WORDS << 1);
++      list = of_get_property(np, "ath,eep-flash", &i);
++      if (!list || (i != (2 * sizeof(*list))))
++              return -ENODEV;
++
++      phandle = be32_to_cpup(list++);
++      if (phandle)
++              mtd_np = of_find_node_by_phandle(phandle);
++
++      if (!mtd_np)
++              return -ENODEV;
++
++      part = of_get_property(mtd_np, "label", NULL);
++      if (!part)
++              part = mtd_np->name;
++
++      the_mtd = get_mtd_device_nm(part);
++      if (IS_ERR(the_mtd))
++              return -ENODEV;
++
++      ath5k_pdata.eeprom_data = kmalloc(ATH5K_PLAT_EEP_MAX_WORDS<<1, GFP_KERNEL);
++
++      i = mtd_read(the_mtd, be32_to_cpup(list), ATH5K_PLAT_EEP_MAX_WORDS << 1,
++              &flash_readlen, (void *) ath5k_pdata.eeprom_data);
++
++      if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
++              size_t mac_readlen;
++              mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
++                      (void *) athxk_eeprom_mac);
++      }
++      put_mtd_device(the_mtd);
++
++      if (((ATH5K_PLAT_EEP_MAX_WORDS<<1) != flash_readlen) || i) {
++              dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
++              return -ENODEV;
 +      }
 +
 +      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]);
 +
-+      if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
-+              memcpy_fromio(athxk_eeprom_mac, (void*) ath5k_pdata.eeprom_data + mac_offset, 6);
-+      } else if (mac_res) {
-+              if (resource_size(mac_res) != 6) {
-+                      dev_err(&pdev->dev, "mac has an invalid size\n");
-+                      return -EINVAL;
-+              }
-+              mac = ioremap(mac_res->start, resource_size(mac_res));
-+              memcpy_fromio(athxk_eeprom_mac, mac, 6);
-+      } else if (ltq_get_eth_mac())
-+              memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
-+      else {
++      if (!is_valid_ether_addr(athxk_eeprom_mac) && ltq_get_eth_mac())
++              ether_addr_copy(athxk_eeprom_mac, ltq_get_eth_mac());
++
++      if (!is_valid_ether_addr(athxk_eeprom_mac)) {
 +              dev_warn(&pdev->dev, "using random mac\n");
 +              random_ether_addr(athxk_eeprom_mac);
 +      }
@@ -356,12 +333,26 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +
 +static int __init of_ath5k_eeprom_init(void)
 +{
++      int ret = platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
++
++      if (ret)
++              ath5k_eep_load = 1;
++
++      return ret;
++}
++
++static int __init of_ath5k_eeprom_init_late(void)
++{
++      if (!ath5k_eep_load)
++              return 0;
++
 +      return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
 +}
-+device_initcall(of_ath5k_eeprom_init);
++late_initcall(of_ath5k_eeprom_init_late);
++subsys_initcall(of_ath5k_eeprom_init);
 --- /dev/null
 +++ b/arch/mips/lantiq/xway/eth_mac.c
-@@ -0,0 +1,76 @@
+@@ -0,0 +1,25 @@
 +/*
 + *  Copyright (C) 2012 John Crispin <blogic@openwrt.org>
 + *
@@ -371,8 +362,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 + */
 +
 +#include <linux/init.h>
-+#include <linux/module.h>
-+#include <linux/of_platform.h>
 +#include <linux/if_ether.h>
 +
 +static u8 eth_mac[6];
@@ -389,55 +378,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +      return !eth_mac_set;
 +}
 +early_param("ethaddr", setup_ethaddr);
-+
-+int __init of_eth_mac_probe(struct platform_device *pdev)
-+{
-+      struct device_node *np = pdev->dev.of_node;
-+      struct resource *mac_res;
-+      void __iomem *mac;
-+      u32 mac_inc = 0;
-+
-+      if (eth_mac_set) {
-+              dev_err(&pdev->dev, "mac was already set by bootloader\n");
-+              return -EINVAL;
-+      }
-+      mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-+
-+      if (!mac_res) {
-+              dev_err(&pdev->dev, "failed to load mac\n");
-+              return -EINVAL;
-+      }
-+      if (resource_size(mac_res) != 6) {
-+              dev_err(&pdev->dev, "mac has an invalid size\n");
-+              return -EINVAL;
-+      }
-+      mac = ioremap(mac_res->start, resource_size(mac_res));
-+      memcpy_fromio(eth_mac, mac, 6);
-+
-+      if (!of_property_read_u32(np, "mac-increment", &mac_inc))
-+              eth_mac[5] += mac_inc;
-+
-+      return 0;
-+}
-+
-+static struct of_device_id eth_mac_ids[] = {
-+      { .compatible = "lantiq,eth-mac" },
-+      { /* sentinel */ }
-+};
-+
-+static struct platform_driver eth_mac_driver = {
-+      .driver         = {
-+              .name           = "lantiq,eth-mac",
-+              .owner  = THIS_MODULE,
-+              .of_match_table = of_match_ptr(eth_mac_ids),
-+      },
-+};
-+
-+static int __init of_eth_mac_init(void)
-+{
-+      return platform_driver_probe(&eth_mac_driver, of_eth_mac_probe);
-+}
-+device_initcall(of_eth_mac_init);
 --- /dev/null
 +++ b/arch/mips/lantiq/xway/pci-ath-fixup.c
 @@ -0,0 +1,118 @@
@@ -559,72 +499,9 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 +      ath_fixups[ath_num_fixups].cal_data = cal_data;
 +      ath_num_fixups++;
 +}
---- /dev/null
-+++ b/arch/mips/lantiq/xway/rt_eep.c
-@@ -0,0 +1,60 @@
-+/*
-+ *  Copyright (C) 2011 John Crispin <blogic@openwrt.org>
-+ *
-+ *  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.
-+ */
-+
-+#include <linux/init.h>
-+#include <linux/module.h>
-+#include <linux/pci.h>
-+#include <linux/platform_device.h>
-+#include <linux/rt2x00_platform.h>
-+
-+extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
-+static struct rt2x00_platform_data rt2x00_pdata;
-+
-+static int rt2x00_pci_plat_dev_init(struct pci_dev *dev)
-+{
-+      dev->dev.platform_data = &rt2x00_pdata;
-+      return 0;
-+}
-+
-+int __init of_ralink_eeprom_probe(struct platform_device *pdev)
-+{
-+      struct device_node *np = pdev->dev.of_node;
-+      const char *eeprom;
-+
-+      if (of_property_read_string(np, "ralink,eeprom", &eeprom)) {
-+              dev_err(&pdev->dev, "failed to load eeprom filename\n");
-+              return 0;
-+      }
-+
-+      rt2x00_pdata.eeprom_file_name = kstrdup(eeprom, GFP_KERNEL);
-+//    rt2x00_pdata.mac_address = mac;
-+      ltq_pci_plat_dev_init = rt2x00_pci_plat_dev_init;
-+
-+      dev_info(&pdev->dev, "using %s as eeprom\n", eeprom);
-+
-+      return 0;
-+}
-+
-+static struct of_device_id ralink_eeprom_ids[] = {
-+      { .compatible = "ralink,eeprom" },
-+      { }
-+};
-+
-+static struct platform_driver ralink_eeprom_driver = {
-+      .driver         = {
-+              .name           = "ralink,eeprom",
-+              .owner  = THIS_MODULE,
-+              .of_match_table = of_match_ptr(ralink_eeprom_ids),
-+      },
-+};
-+
-+static int __init of_ralink_eeprom_init(void)
-+{
-+      return platform_driver_probe(&ralink_eeprom_driver, of_ralink_eeprom_probe);
-+}
-+device_initcall(of_ralink_eeprom_init);
 --- a/drivers/net/ethernet/lantiq_etop.c
 +++ b/drivers/net/ethernet/lantiq_etop.c
-@@ -840,7 +840,11 @@
+@@ -840,7 +840,11 @@ ltq_etop_init(struct net_device *dev)
        if (err)
                goto err_hw;