@ -51,7 +51,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
--- /dev/null
--- /dev/null
+++ b/arch/mips/lantiq/xway/ath_eep.c
+++ b/arch/mips/lantiq/xway/ath_eep.c
@@ -0,0 +1,307 @@
@@ -0,0 +1,281 @@
+/*
+/*
+ * Copyright (C) 2011 Luca Olivetti <luca@ventoso.org>
+ * Copyright (C) 2011 Luca Olivetti <luca@ventoso.org>
+ * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
@ -93,9 +93,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+static int ath9k_eep_load;
+static int ath9k_eep_load;
+int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
+int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
+{
+{
+ struct device_node *np = pdev->dev.of_node, *mtd_np;
+ struct device_node *np = pdev->dev.of_node, *mtd_np = NULL;
+ struct resource *eep_res, *mac_res = NULL;
+ void __iomem *eep, *mac;
+ int mac_offset, led_pin;
+ int mac_offset, led_pin;
+ u32 mac_inc = 0, pci_slot = 0;
+ u32 mac_inc = 0, pci_slot = 0;
+ int i;
+ int i;
@ -106,41 +104,38 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ phandle phandle;
+ phandle phandle;
+ u16 dev_ids[2] = { 0 };
+ u16 dev_ids[2] = { 0 };
+
+
+ if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
+ list = of_get_property(np, "ath,eep-flash", &i);
+ sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
+ if (!list || (i != (2 * sizeof(*list))))
+ (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
+ return -ENODEV;
+ of_get_property(mtd_np, "label", NULL)) || (part =
+
+ mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
+ phandle = be32_to_cpup(list++);
+ != ERR_PTR(-ENODEV)) {
+ if (phandle)
+ i = mtd_read(the_mtd, be32_to_cpup(list),
+ mtd_np = of_find_node_by_phandle(phandle);
+ ATH9K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
+
+ (void *) ath9k_pdata.eeprom_data);
+ if (!mtd_np)
+ if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
+ return -ENODEV;
+ size_t mac_readlen;
+
+ mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
+ part = of_get_property(mtd_np, "label", NULL);
+ (void *) athxk_eeprom_mac);
+ if (!part)
+ }
+ part = mtd_np->name;
+ put_mtd_device(the_mtd);
+
+ if ((sizeof(ath9k_pdata.eeprom_data) != flash_readlen) || i) {
+ the_mtd = get_mtd_device_nm(part);
+ dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
+ if (IS_ERR(the_mtd))
+ return -ENODEV;
+ return -ENODEV;
+ }
+
+ } else {
+ i = mtd_read(the_mtd, be32_to_cpup(list), ATH9K_PLAT_EEP_MAX_WORDS << 1,
+ eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ &flash_readlen, (void *) ath9k_pdata.eeprom_data);
+ mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+
+
+ if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
+ if (!eep_res) {
+ size_t mac_readlen;
+ dev_err(&pdev->dev, "failed to load eeprom address\n");
+ mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
+ return -ENODEV;
+ (void *) athxk_eeprom_mac);
+ }
+ }
+ if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
+ put_mtd_device(the_mtd);
+ dev_err(&pdev->dev, "eeprom has an invalid size\n");
+
+ return -EINVAL;
+ if ((sizeof(ath9k_pdata.eeprom_data) != flash_readlen) || i) {
+ }
+ dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
+
+ return -ENODEV;
+ 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))
+ if (of_find_property(np, "ath,eep-swap", NULL))
@ -153,18 +148,9 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ dev_info(&pdev->dev, "endian check enabled.\n");
+ dev_info(&pdev->dev, "endian check enabled.\n");
+ }
+ }
+
+
+ if (!is_valid_ether_addr(athxk_eeprom_mac)) {
+ if (!is_valid_ether_addr(athxk_eeprom_mac) && ltq_get_eth_mac())
+ if (mac_res) {
+ memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
+ 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)) {
+ if (!is_valid_ether_addr(athxk_eeprom_mac)) {
+ dev_warn(&pdev->dev, "using random mac\n");
+ dev_warn(&pdev->dev, "using random mac\n");
+ random_ether_addr(athxk_eeprom_mac);
+ random_ether_addr(athxk_eeprom_mac);
@ -263,9 +249,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+
+
+int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
+int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
+{
+{
+ struct device_node *np = pdev->dev.of_node, *mtd_np;
+ struct device_node *np = pdev->dev.of_node, *mtd_np = NULL;
+ struct resource *eep_res, *mac_res = NULL;
+ void __iomem *eep, *mac;
+ int mac_offset;
+ int mac_offset;
+ u32 mac_inc = 0;
+ u32 mac_inc = 0;
+ int i;
+ int i;
@ -275,57 +259,47 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ const char *part;
+ const char *part;
+ phandle phandle;
+ phandle phandle;
+
+
+ if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
+ list = of_get_property(np, "ath,eep-flash", &i);
+ sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
+ if (!list || (i != (2 * sizeof(*list))))
+ (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
+ return -ENODEV;
+ of_get_property(mtd_np, "label", NULL)) || (part =
+
+ mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
+ phandle = be32_to_cpup(list++);
+ != ERR_PTR(-ENODEV)) {
+ if (phandle)
+ i = mtd_read(the_mtd, be32_to_cpup(list),
+ mtd_np = of_find_node_by_phandle(phandle);
+ ATH5K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
+
+ (void *) ath5k_pdata.eeprom_data);
+ if (!mtd_np)
+ put_mtd_device(the_mtd);
+ return -ENODEV;
+ if ((sizeof(ATH5K_PLAT_EEP_MAX_WORDS << 1) != flash_readlen)
+
+ || i) {
+ part = of_get_property(mtd_np, "label", NULL);
+ dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
+ if (!part)
+ return -ENODEV;
+ part = mtd_np->name;
+ }
+
+ } else {
+ the_mtd = get_mtd_device_nm(part);
+ eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (IS_ERR(the_mtd))
+ mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ return -ENODEV;
+
+
+ if (!eep_res) {
+ i = mtd_read(the_mtd, be32_to_cpup(list), ATH5K_PLAT_EEP_MAX_WORDS << 1,
+ dev_err(&pdev->dev, "failed to load eeprom address\n");
+ &flash_readlen, (void *) ath5k_pdata.eeprom_data);
+ return -ENODEV;
+
+ }
+ put_mtd_device(the_mtd);
+ if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
+
+ dev_err(&pdev->dev, "eeprom has an invalid size\n");
+ if ((sizeof(ATH5K_PLAT_EEP_MAX_WORDS << 1) != flash_readlen)
+ return -EINVAL;
+ || i) {
+ }
+ dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
+
+ return -ENODEV;
+ 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);
+ }
+ }
+
+
+ if (of_find_property(np, "ath,eep-swap", NULL))
+ if (of_find_property(np, "ath,eep-swap", NULL))
+ for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
+ for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
+ ath5k_pdata.eeprom_data[i] = swab16(ath5k_pdata.eeprom_data[i]);
+ ath5k_pdata.eeprom_data[i] = swab16(ath5k_pdata.eeprom_data[i]);
+
+
+ if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
+ if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset))
+ memcpy_fromio(athxk_eeprom_mac, (void*) ath5k_pdata.eeprom_data + mac_offset, 6);
+ memcpy_fromio(athxk_eeprom_mac, (void*) ath5k_pdata.eeprom_data + mac_offset, 6);
+ } else if (mac_res) {
+
+ if (resource_size(mac_res) != 6) {
+ if (!is_valid_ether_addr(athxk_eeprom_mac) && ltq_get_eth_mac())
+ 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);
+ memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
+ else {
+
+ if (!is_valid_ether_addr(athxk_eeprom_mac)) {
+ dev_warn(&pdev->dev, "using random mac\n");
+ dev_warn(&pdev->dev, "using random mac\n");
+ random_ether_addr(athxk_eeprom_mac);
+ random_ether_addr(athxk_eeprom_mac);
+ }
+ }