1 From 0c9b05716ac0e597ae0f81a96ff68e54716decc9 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 13 Mar 2013 10:02:58 +0100
4 Subject: [PATCH 37/40] owrt: lantiq: wifi and ethernet eeprom handling
7 arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h | 6 +
8 .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h | 3 +
9 arch/mips/lantiq/xway/Makefile | 3 +
10 arch/mips/lantiq/xway/ath_eep.c | 206 ++++++++++++++++++++
11 arch/mips/lantiq/xway/eth_mac.c | 76 ++++++++
12 arch/mips/lantiq/xway/pci-ath-fixup.c | 109 +++++++++++
13 arch/mips/lantiq/xway/rt_eep.c | 60 ++++++
14 drivers/net/ethernet/lantiq_etop.c | 10 +-
15 8 files changed, 469 insertions(+), 4 deletions(-)
16 create mode 100644 arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h
17 create mode 100644 arch/mips/lantiq/xway/ath_eep.c
18 create mode 100644 arch/mips/lantiq/xway/eth_mac.c
19 create mode 100644 arch/mips/lantiq/xway/pci-ath-fixup.c
20 create mode 100644 arch/mips/lantiq/xway/rt_eep.c
22 Index: linux-3.8.13/arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h
23 ===================================================================
24 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
25 +++ linux-3.8.13/arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h 2013-07-25 20:47:01.531327796 +0200
27 +#ifndef _PCI_ATH_FIXUP
28 +#define _PCI_ATH_FIXUP
30 +void ltq_pci_ath_fixup(unsigned slot, u16 *cal_data) __init;
32 +#endif /* _PCI_ATH_FIXUP */
33 Index: linux-3.8.13/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
34 ===================================================================
35 --- linux-3.8.13.orig/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h 2013-07-25 20:46:52.599327583 +0200
36 +++ linux-3.8.13/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h 2013-07-25 20:47:01.531327796 +0200
38 extern void ltq_pmu_enable(unsigned int module);
39 extern void ltq_pmu_disable(unsigned int module);
41 +/* allow the ethernet driver to load a flash mapped mac addr */
42 +const u8* ltq_get_eth_mac(void);
44 #endif /* CONFIG_SOC_TYPE_XWAY */
45 #endif /* _LTQ_XWAY_H__ */
46 Index: linux-3.8.13/arch/mips/lantiq/xway/Makefile
47 ===================================================================
48 --- linux-3.8.13.orig/arch/mips/lantiq/xway/Makefile 2013-07-25 20:47:01.371327792 +0200
49 +++ linux-3.8.13/arch/mips/lantiq/xway/Makefile 2013-07-25 21:31:31.287391412 +0200
51 obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o dcdc.o
54 +obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
56 obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
57 Index: linux-3.8.13/arch/mips/lantiq/xway/ath_eep.c
58 ===================================================================
59 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
60 +++ linux-3.8.13/arch/mips/lantiq/xway/ath_eep.c 2013-07-25 20:47:01.535327796 +0200
63 + * Copyright (C) 2011 Luca Olivetti <luca@ventoso.org>
64 + * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
65 + * Copyright (C) 2011 Andrej Vlašić <andrej.vlasic0@gmail.com>
66 + * Copyright (C) 2013 Álvaro Fernández Rojas <noltari@gmail.com>
67 + * Copyright (C) 2013 Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
69 + * This program is free software; you can redistribute it and/or modify it
70 + * under the terms of the GNU General Public License version 2 as published
71 + * by the Free Software Foundation.
74 +#include <linux/init.h>
75 +#include <linux/module.h>
76 +#include <linux/platform_device.h>
77 +#include <linux/etherdevice.h>
78 +#include <linux/ath5k_platform.h>
79 +#include <linux/ath9k_platform.h>
80 +#include <linux/pci.h>
81 +#include <linux/err.h>
82 +#include <linux/mtd/mtd.h>
83 +#include <pci-ath-fixup.h>
84 +#include <lantiq_soc.h>
86 +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
87 +struct ath5k_platform_data ath5k_pdata;
88 +struct ath9k_platform_data ath9k_pdata = {
91 +static u8 athxk_eeprom_mac[6];
93 +static int ath9k_pci_plat_dev_init(struct pci_dev *dev)
95 + dev->dev.platform_data = &ath9k_pdata;
99 +int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
101 + struct device_node *np = pdev->dev.of_node, *mtd_np;
102 + struct resource *eep_res, *mac_res = NULL;
103 + void __iomem *eep, *mac;
105 + u32 mac_inc = 0, pci_slot = 0;
107 + struct mtd_info *the_mtd;
108 + size_t flash_readlen;
109 + const __be32 *list;
113 + if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
114 + sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
115 + (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
116 + of_get_property(mtd_np, "label", NULL)) || (part =
117 + mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
118 + != ERR_PTR(-ENODEV)) {
119 + i = mtd_read(the_mtd, be32_to_cpup(list),
120 + ATH9K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
121 + (void *) ath9k_pdata.eeprom_data);
122 + put_mtd_device(the_mtd);
123 + if ((sizeof(ath9k_pdata.eeprom_data) != flash_readlen) || i) {
124 + dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
128 + eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129 + mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
132 + dev_err(&pdev->dev, "failed to load eeprom address\n");
135 + if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
136 + dev_err(&pdev->dev, "eeprom has an invalid size\n");
140 + eep = ioremap(eep_res->start, resource_size(eep_res));
141 + memcpy_fromio(ath9k_pdata.eeprom_data, eep,
142 + ATH9K_PLAT_EEP_MAX_WORDS << 1);
145 + if (of_find_property(np, "ath,eep-swap", NULL))
146 + for (i = 0; i < ATH9K_PLAT_EEP_MAX_WORDS; i++)
147 + ath9k_pdata.eeprom_data[i] = swab16(ath9k_pdata.eeprom_data[i]);
149 + if (of_find_property(np, "ath,eep-endian", NULL)) {
150 + ath9k_pdata.endian_check = true;
152 + dev_info(&pdev->dev, "endian check enabled.\n");
155 + if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
156 + memcpy_fromio(athxk_eeprom_mac, (void*) ath9k_pdata.eeprom_data + mac_offset, 6);
157 + } else if (mac_res) {
158 + if (resource_size(mac_res) != 6) {
159 + dev_err(&pdev->dev, "mac has an invalid size\n");
162 + mac = ioremap(mac_res->start, resource_size(mac_res));
163 + memcpy_fromio(athxk_eeprom_mac, mac, 6);
164 + } else if (ltq_get_eth_mac())
165 + memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
167 + dev_warn(&pdev->dev, "using random mac\n");
168 + random_ether_addr(athxk_eeprom_mac);
171 + if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
172 + athxk_eeprom_mac[5] += mac_inc;
174 + ath9k_pdata.macaddr = athxk_eeprom_mac;
175 + ltq_pci_plat_dev_init = ath9k_pci_plat_dev_init;
177 + if (!of_property_read_u32(np, "ath,pci-slot", &pci_slot)) {
178 + ltq_pci_ath_fixup(pci_slot, ath9k_pdata.eeprom_data);
180 + dev_info(&pdev->dev, "pci slot: %u\n", pci_slot);
183 + dev_info(&pdev->dev, "loaded ath9k eeprom\n");
188 +static struct of_device_id ath9k_eeprom_ids[] = {
189 + { .compatible = "ath9k,eeprom" },
193 +static struct platform_driver ath9k_eeprom_driver = {
195 + .name = "ath9k,eeprom",
196 + .owner = THIS_MODULE,
197 + .of_match_table = of_match_ptr(ath9k_eeprom_ids),
201 +static int __init of_ath9k_eeprom_init(void)
203 + return platform_driver_probe(&ath9k_eeprom_driver, of_ath9k_eeprom_probe);
205 +late_initcall(of_ath9k_eeprom_init);
208 +static int ath5k_pci_plat_dev_init(struct pci_dev *dev)
210 + dev->dev.platform_data = &ath5k_pdata;
214 +int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
216 + struct device_node *np = pdev->dev.of_node, *mtd_np;
217 + struct resource *eep_res, *mac_res = NULL;
218 + void __iomem *eep, *mac;
222 + struct mtd_info *the_mtd;
223 + size_t flash_readlen;
224 + const __be32 *list;
228 + if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
229 + sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
230 + (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
231 + of_get_property(mtd_np, "label", NULL)) || (part =
232 + mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
233 + != ERR_PTR(-ENODEV)) {
234 + i = mtd_read(the_mtd, be32_to_cpup(list),
235 + ATH5K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
236 + (void *) ath5k_pdata.eeprom_data);
237 + put_mtd_device(the_mtd);
238 + if ((sizeof(ATH5K_PLAT_EEP_MAX_WORDS << 1) != flash_readlen)
240 + dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
244 + eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
245 + mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
248 + dev_err(&pdev->dev, "failed to load eeprom address\n");
251 + if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
252 + dev_err(&pdev->dev, "eeprom has an invalid size\n");
256 + eep = ioremap(eep_res->start, resource_size(eep_res));
257 + memcpy_fromio(ath5k_pdata.eeprom_data, eep,
258 + ATH5K_PLAT_EEP_MAX_WORDS << 1);
261 + if (of_find_property(np, "ath,eep-swap", NULL))
262 + for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
263 + ath5k_pdata.eeprom_data[i] = swab16(ath5k_pdata.eeprom_data[i]);
265 + if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
266 + memcpy_fromio(athxk_eeprom_mac, (void*) ath5k_pdata.eeprom_data + mac_offset, 6);
267 + } else if (mac_res) {
268 + if (resource_size(mac_res) != 6) {
269 + dev_err(&pdev->dev, "mac has an invalid size\n");
272 + mac = ioremap(mac_res->start, resource_size(mac_res));
273 + memcpy_fromio(athxk_eeprom_mac, mac, 6);
274 + } else if (ltq_get_eth_mac())
275 + memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
277 + dev_warn(&pdev->dev, "using random mac\n");
278 + random_ether_addr(athxk_eeprom_mac);
281 + if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
282 + athxk_eeprom_mac[5] += mac_inc;
284 + ath5k_pdata.macaddr = athxk_eeprom_mac;
285 + ltq_pci_plat_dev_init = ath5k_pci_plat_dev_init;
287 + dev_info(&pdev->dev, "loaded ath5k eeprom\n");
292 +static struct of_device_id ath5k_eeprom_ids[] = {
293 + { .compatible = "ath5k,eeprom" },
297 +static struct platform_driver ath5k_eeprom_driver = {
299 + .name = "ath5k,eeprom",
300 + .owner = THIS_MODULE,
301 + .of_match_table = of_match_ptr(ath5k_eeprom_ids),
305 +static int __init of_ath5k_eeprom_init(void)
307 + return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
309 +device_initcall(of_ath5k_eeprom_init);
310 Index: linux-3.8.13/arch/mips/lantiq/xway/eth_mac.c
311 ===================================================================
312 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
313 +++ linux-3.8.13/arch/mips/lantiq/xway/eth_mac.c 2013-07-25 21:28:37.743387278 +0200
316 + * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
318 + * This program is free software; you can redistribute it and/or modify it
319 + * under the terms of the GNU General Public License version 2 as published
320 + * by the Free Software Foundation.
323 +#include <linux/init.h>
324 +#include <linux/module.h>
325 +#include <linux/of_platform.h>
326 +#include <linux/if_ether.h>
327 +#include <linux/mtd/mtd.h>
329 +static u8 eth_mac[6];
330 +static int eth_mac_set;
332 +const u8* ltq_get_eth_mac(void)
337 +static int __init setup_ethaddr(char *str)
339 + eth_mac_set = mac_pton(str, eth_mac);
340 + return !eth_mac_set;
342 +__setup("ethaddr=", setup_ethaddr);
344 +int __init of_eth_mac_probe(struct platform_device *pdev)
346 + struct device_node *np = pdev->dev.of_node, *mtd_np;
347 + struct resource *mac_res;
351 + size_t flash_readlen;
352 + const __be32 *list;
354 + struct mtd_info *the_mtd;
358 + dev_err(&pdev->dev, "mac was already set by bootloader\n");
361 + if ((list = of_get_property(np, "ath,eep-mac", &i)) && i == 2 *
362 + sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
363 + (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
364 + of_get_property(mtd_np, "label", NULL)) || (part =
365 + mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
366 + != ERR_PTR(-ENODEV)) {
367 + i = mtd_read(the_mtd, be32_to_cpup(list), 6, &flash_readlen,
369 + put_mtd_device(the_mtd);
370 + if ((sizeof(eth_mac) != flash_readlen) || i) {
371 + dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
375 + mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
378 + dev_err(&pdev->dev, "failed to load mac\n");
381 + if (resource_size(mac_res) != 6) {
382 + dev_err(&pdev->dev, "mac has an invalid size\n");
385 + mac = ioremap(mac_res->start, resource_size(mac_res));
386 + memcpy_fromio(eth_mac, mac, 6);
389 + if (!of_property_read_u32(np, "mac-increment", &mac_inc))
390 + eth_mac[5] += mac_inc;
395 +static struct of_device_id eth_mac_ids[] = {
396 + { .compatible = "lantiq,eth-mac" },
400 +static struct platform_driver eth_mac_driver = {
402 + .name = "lantiq,eth-mac",
403 + .owner = THIS_MODULE,
404 + .of_match_table = of_match_ptr(eth_mac_ids),
408 +static int __init of_eth_mac_init(void)
410 + return platform_driver_probe(ð_mac_driver, of_eth_mac_probe);
412 +device_initcall(of_eth_mac_init);
413 Index: linux-3.8.13/arch/mips/lantiq/xway/pci-ath-fixup.c
414 ===================================================================
415 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
416 +++ linux-3.8.13/arch/mips/lantiq/xway/pci-ath-fixup.c 2013-07-25 20:47:01.535327796 +0200
419 + * Atheros AP94 reference board PCI initialization
421 + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
423 + * This program is free software; you can redistribute it and/or modify it
424 + * under the terms of the GNU General Public License version 2 as published
425 + * by the Free Software Foundation.
428 +#include <linux/pci.h>
429 +#include <linux/init.h>
430 +#include <linux/delay.h>
431 +#include <lantiq_soc.h>
433 +#define LTQ_PCI_MEM_BASE 0x18000000
440 +static int ath_num_fixups;
441 +static struct ath_fixup ath_fixups[2];
443 +static void ath_pci_fixup(struct pci_dev *dev)
446 + u16 *cal_data = NULL;
452 + for (i = 0; i < ath_num_fixups; i++) {
453 + if (ath_fixups[i].cal_data == NULL)
456 + if (ath_fixups[i].slot != PCI_SLOT(dev->devfn))
459 + cal_data = ath_fixups[i].cal_data;
463 + if (cal_data == NULL)
466 + if (*cal_data != 0xa55a) {
467 + pr_err("pci %s: invalid calibration data\n", pci_name(dev));
471 + pr_info("pci %s: fixup device configuration\n", pci_name(dev));
473 + mem = ioremap(LTQ_PCI_MEM_BASE, 0x10000);
475 + pr_err("pci %s: ioremap error\n", pci_name(dev));
479 + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
480 + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, LTQ_PCI_MEM_BASE);
481 + pci_read_config_word(dev, PCI_COMMAND, &cmd);
482 + cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
483 + pci_write_config_word(dev, PCI_COMMAND, cmd);
485 + /* set pointer to first reg address */
487 + while (*cal_data != 0xffff) {
491 + val |= (*cal_data++) << 16;
493 + ltq_w32(swab32(val), mem + reg);
497 + pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
498 + dev->vendor = val & 0xffff;
499 + dev->device = (val >> 16) & 0xffff;
501 + pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
502 + dev->revision = val & 0xff;
503 + dev->class = val >> 8; /* upper 3 bytes */
505 + pr_info("pci %s: fixup info: [%04x:%04x] revision %02x class %#08x\n",
506 + pci_name(dev), dev->vendor, dev->device, dev->revision, dev->class);
508 + pci_read_config_word(dev, PCI_COMMAND, &cmd);
509 + cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
510 + pci_write_config_word(dev, PCI_COMMAND, cmd);
512 + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
516 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath_pci_fixup);
518 +void __init ltq_pci_ath_fixup(unsigned slot, u16 *cal_data)
520 + if (ath_num_fixups >= ARRAY_SIZE(ath_fixups))
523 + ath_fixups[ath_num_fixups].slot = slot;
524 + ath_fixups[ath_num_fixups].cal_data = cal_data;
527 Index: linux-3.8.13/arch/mips/lantiq/xway/rt_eep.c
528 ===================================================================
529 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
530 +++ linux-3.8.13/arch/mips/lantiq/xway/rt_eep.c 2013-07-25 20:47:01.535327796 +0200
533 + * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
535 + * This program is free software; you can redistribute it and/or modify it
536 + * under the terms of the GNU General Public License version 2 as published
537 + * by the Free Software Foundation.
540 +#include <linux/init.h>
541 +#include <linux/module.h>
542 +#include <linux/pci.h>
543 +#include <linux/platform_device.h>
544 +#include <linux/rt2x00_platform.h>
546 +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
547 +static struct rt2x00_platform_data rt2x00_pdata;
549 +static int rt2x00_pci_plat_dev_init(struct pci_dev *dev)
551 + dev->dev.platform_data = &rt2x00_pdata;
555 +int __init of_ralink_eeprom_probe(struct platform_device *pdev)
557 + struct device_node *np = pdev->dev.of_node;
558 + const char *eeprom;
560 + if (of_property_read_string(np, "ralink,eeprom", &eeprom)) {
561 + dev_err(&pdev->dev, "failed to load eeprom filename\n");
565 + rt2x00_pdata.eeprom_file_name = kstrdup(eeprom, GFP_KERNEL);
566 +// rt2x00_pdata.mac_address = mac;
567 + ltq_pci_plat_dev_init = rt2x00_pci_plat_dev_init;
569 + dev_info(&pdev->dev, "using %s as eeprom\n", eeprom);
574 +static struct of_device_id ralink_eeprom_ids[] = {
575 + { .compatible = "ralink,eeprom" },
579 +static struct platform_driver ralink_eeprom_driver = {
581 + .name = "ralink,eeprom",
582 + .owner = THIS_MODULE,
583 + .of_match_table = of_match_ptr(ralink_eeprom_ids),
587 +static int __init of_ralink_eeprom_init(void)
589 + return platform_driver_probe(&ralink_eeprom_driver, of_ralink_eeprom_probe);
591 +device_initcall(of_ralink_eeprom_init);
592 Index: linux-3.8.13/drivers/net/ethernet/lantiq_etop.c
593 ===================================================================
594 --- linux-3.8.13.orig/drivers/net/ethernet/lantiq_etop.c 2013-07-25 20:46:52.599327583 +0200
595 +++ linux-3.8.13/drivers/net/ethernet/lantiq_etop.c 2013-07-25 20:47:01.535327796 +0200
598 ltq_etop_change_mtu(dev, 1500);
600 - memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
602 + memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
603 if (!is_valid_ether_addr(mac.sa_data)) {
604 pr_warn("etop: invalid MAC, using random\n");
605 random_ether_addr(mac.sa_data);
607 .ndo_tx_timeout = ltq_etop_tx_timeout,
610 -static int __devinit
611 -ltq_etop_probe(struct platform_device *pdev)
612 +static int ltq_etop_probe(struct platform_device *pdev)
614 struct net_device *dev;
615 struct ltq_etop_priv *priv;
617 priv->tx_irq = irqres[0].start;
618 priv->rx_irq = irqres[1].start;
619 priv->mii_mode = of_get_phy_mode(pdev->dev.of_node);
620 - priv->mac = of_get_mac_address(pdev->dev.of_node);
621 + priv->mac = ltq_get_eth_mac();
623 + priv->mac = of_get_mac_address(pdev->dev.of_node);
625 priv->clk_ppe = clk_get(&pdev->dev, NULL);
626 if (IS_ERR(priv->clk_ppe))