lantiq: drop orphaned eeprom-handling code branches

All device tree nodes are using the named properties now and the code
path handling the reg property isn't required any more.

The code related to the ath,eep-flash property has been reformatted to
be better readable.

Signed-off-by: Mathias Kresin <dev@kresin.me>
This commit is contained in:
Mathias Kresin 2016-08-02 22:25:59 +02:00 committed by John Crispin
parent 12fe4b5798
commit a7cce111db

View File

@ -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))
+ != 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) { + phandle = be32_to_cpup(list++);
+ dev_err(&pdev->dev, "failed to load eeprom address\n"); + if (phandle)
+ return -ENODEV; + mtd_np = of_find_node_by_phandle(phandle);
+ }
+ 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)); + if (!mtd_np)
+ memcpy_fromio(ath9k_pdata.eeprom_data, eep, + return -ENODEV;
+ ATH9K_PLAT_EEP_MAX_WORDS << 1); +
+ 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)) + 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))
+ != 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) { + phandle = be32_to_cpup(list++);
+ dev_err(&pdev->dev, "failed to load eeprom address\n"); + if (phandle)
+ return -ENODEV; + mtd_np = of_find_node_by_phandle(phandle);
+ }
+ 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)); + if (!mtd_np)
+ ath5k_pdata.eeprom_data = kmalloc(ATH5K_PLAT_EEP_MAX_WORDS<<1, + return -ENODEV;
+ GFP_KERNEL); +
+ memcpy_fromio(ath5k_pdata.eeprom_data, eep, + part = of_get_property(mtd_np, "label", NULL);
+ ATH5K_PLAT_EEP_MAX_WORDS << 1); + 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), 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;
+ } + }
+ +
+ 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);
+ } + }