lantiq: add devicetree for TP-Link TDW8970
[openwrt.git] / target / linux / lantiq / patches-3.8 / 0037-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch
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
5
6 ---
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
21
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
26 @@ -0,0 +1,6 @@
27 +#ifndef _PCI_ATH_FIXUP
28 +#define _PCI_ATH_FIXUP
29 +
30 +void ltq_pci_ath_fixup(unsigned slot, u16 *cal_data) __init;
31 +
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
37 @@ -90,5 +90,8 @@
38  extern void ltq_pmu_enable(unsigned int module);
39  extern void ltq_pmu_disable(unsigned int module);
40  
41 +/* allow the ethernet driver to load a flash mapped mac addr */
42 +const u8* ltq_get_eth_mac(void);
43 +
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
50 @@ -1,3 +1,6 @@
51  obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o dcdc.o
52  
53 +obj-y += eth_mac.o
54 +obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
55 +
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
61 @@ -0,0 +1,248 @@
62 +/*
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>
68 + *
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.
72 + */
73 +
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>
85 +
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 = {
89 +       .led_pin = -1,
90 +};
91 +static u8 athxk_eeprom_mac[6];
92 +
93 +static int ath9k_pci_plat_dev_init(struct pci_dev *dev)
94 +{
95 +       dev->dev.platform_data = &ath9k_pdata;
96 +       return 0;
97 +}
98 +
99 +int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
100 +{
101 +       struct device_node *np = pdev->dev.of_node, *mtd_np;
102 +       struct resource *eep_res, *mac_res = NULL;
103 +       void __iomem *eep, *mac;
104 +       int mac_offset;
105 +       u32 mac_inc = 0, pci_slot = 0;
106 +       int i;
107 +       struct mtd_info *the_mtd;
108 +       size_t flash_readlen;
109 +       const __be32 *list;
110 +       const char *part;
111 +       phandle phandle;
112 +
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");
125 +                       return -ENODEV;
126 +               }
127 +       } else {
128 +               eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129 +               mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
130 +
131 +               if (!eep_res) {
132 +                       dev_err(&pdev->dev, "failed to load eeprom address\n");
133 +                       return -ENODEV;
134 +               }
135 +               if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
136 +                       dev_err(&pdev->dev, "eeprom has an invalid size\n");
137 +                       return -EINVAL;
138 +               }
139 +
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);
143 +       }
144 +
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]);
148 +
149 +       if (of_find_property(np, "ath,eep-endian", NULL)) {
150 +               ath9k_pdata.endian_check = true;
151 +
152 +               dev_info(&pdev->dev, "endian check enabled.\n");
153 +       }
154 +
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");
160 +                       return -EINVAL;
161 +               }
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);
166 +       else {
167 +               dev_warn(&pdev->dev, "using random mac\n");
168 +               random_ether_addr(athxk_eeprom_mac);
169 +       }
170 +
171 +       if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
172 +               athxk_eeprom_mac[5] += mac_inc;
173 +
174 +       ath9k_pdata.macaddr = athxk_eeprom_mac;
175 +       ltq_pci_plat_dev_init = ath9k_pci_plat_dev_init;
176 +
177 +       if (!of_property_read_u32(np, "ath,pci-slot", &pci_slot)) {
178 +               ltq_pci_ath_fixup(pci_slot, ath9k_pdata.eeprom_data);
179 +
180 +               dev_info(&pdev->dev, "pci slot: %u\n", pci_slot);
181 +       }
182 +
183 +       dev_info(&pdev->dev, "loaded ath9k eeprom\n");
184 +
185 +       return 0;
186 +}
187 +
188 +static struct of_device_id ath9k_eeprom_ids[] = {
189 +       { .compatible = "ath9k,eeprom" },
190 +       { }
191 +};
192 +
193 +static struct platform_driver ath9k_eeprom_driver = {
194 +       .driver         = {
195 +               .name           = "ath9k,eeprom",
196 +               .owner  = THIS_MODULE,
197 +               .of_match_table = of_match_ptr(ath9k_eeprom_ids),
198 +       },
199 +};
200 +
201 +static int __init of_ath9k_eeprom_init(void)
202 +{
203 +       return platform_driver_probe(&ath9k_eeprom_driver, of_ath9k_eeprom_probe);
204 +}
205 +late_initcall(of_ath9k_eeprom_init);
206 +
207 +
208 +static int ath5k_pci_plat_dev_init(struct pci_dev *dev)
209 +{
210 +       dev->dev.platform_data = &ath5k_pdata;
211 +       return 0;
212 +}
213 +
214 +int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
215 +{
216 +       struct device_node *np = pdev->dev.of_node, *mtd_np;
217 +       struct resource *eep_res, *mac_res = NULL;
218 +       void __iomem *eep, *mac;
219 +       int mac_offset;
220 +       u32 mac_inc = 0;
221 +       int i;
222 +       struct mtd_info *the_mtd;
223 +       size_t flash_readlen;
224 +       const __be32 *list;
225 +       const char *part;
226 +       phandle phandle;
227 +
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)
239 +                               || i) {
240 +                       dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
241 +                       return -ENODEV;
242 +               }
243 +       } else {
244 +               eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
245 +               mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
246 +
247 +               if (!eep_res) {
248 +                       dev_err(&pdev->dev, "failed to load eeprom address\n");
249 +                       return -ENODEV;
250 +               }
251 +               if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
252 +                       dev_err(&pdev->dev, "eeprom has an invalid size\n");
253 +                       return -EINVAL;
254 +               }
255 +
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);
259 +       }
260 +
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]);
264 +
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");
270 +                       return -EINVAL;
271 +               }
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);
276 +       else {
277 +               dev_warn(&pdev->dev, "using random mac\n");
278 +               random_ether_addr(athxk_eeprom_mac);
279 +       }
280 +
281 +       if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
282 +               athxk_eeprom_mac[5] += mac_inc;
283 +
284 +       ath5k_pdata.macaddr = athxk_eeprom_mac;
285 +       ltq_pci_plat_dev_init = ath5k_pci_plat_dev_init;
286 +
287 +       dev_info(&pdev->dev, "loaded ath5k eeprom\n");
288 +
289 +       return 0;
290 +}
291 +
292 +static struct of_device_id ath5k_eeprom_ids[] = {
293 +       { .compatible = "ath5k,eeprom" },
294 +       { }
295 +};
296 +
297 +static struct platform_driver ath5k_eeprom_driver = {
298 +       .driver         = {
299 +               .name           = "ath5k,eeprom",
300 +               .owner  = THIS_MODULE,
301 +               .of_match_table = of_match_ptr(ath5k_eeprom_ids),
302 +       },
303 +};
304 +
305 +static int __init of_ath5k_eeprom_init(void)
306 +{
307 +       return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
308 +}
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
314 @@ -0,0 +1,98 @@
315 +/*
316 + *  Copyright (C) 2012 John Crispin <blogic@openwrt.org>
317 + *
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.
321 + */
322 +
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>
328 +
329 +static u8 eth_mac[6];
330 +static int eth_mac_set;
331 +
332 +const u8* ltq_get_eth_mac(void)
333 +{
334 +       return eth_mac;
335 +}
336 +
337 +static int __init setup_ethaddr(char *str)
338 +{
339 +       eth_mac_set = mac_pton(str, eth_mac);
340 +       return !eth_mac_set;
341 +}
342 +__setup("ethaddr=", setup_ethaddr);
343 +
344 +int __init of_eth_mac_probe(struct platform_device *pdev)
345 +{
346 +       struct device_node *np = pdev->dev.of_node, *mtd_np;
347 +       struct resource *mac_res;
348 +       void __iomem *mac;
349 +       u32 mac_inc = 0;
350 +       phandle phandle;
351 +       size_t flash_readlen;
352 +       const __be32 *list;
353 +       const char *part;
354 +       struct mtd_info *the_mtd;
355 +       int i;
356 +
357 +       if (eth_mac_set) {
358 +               dev_err(&pdev->dev, "mac was already set by bootloader\n");
359 +               return -EINVAL;
360 +       }
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,
368 +                                       (void *) eth_mac);
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");
372 +                       return -ENODEV;
373 +               }
374 +       } else {
375 +               mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
376 +
377 +               if (!mac_res) {
378 +                       dev_err(&pdev->dev, "failed to load mac\n");
379 +                       return -EINVAL;
380 +               }
381 +               if (resource_size(mac_res) != 6) {
382 +                       dev_err(&pdev->dev, "mac has an invalid size\n");
383 +                       return -EINVAL;
384 +               }
385 +               mac = ioremap(mac_res->start, resource_size(mac_res));
386 +               memcpy_fromio(eth_mac, mac, 6);
387 +
388 +       }
389 +       if (!of_property_read_u32(np, "mac-increment", &mac_inc))
390 +               eth_mac[5] += mac_inc;
391 +
392 +       return 0;
393 +}
394 +
395 +static struct of_device_id eth_mac_ids[] = {
396 +       { .compatible = "lantiq,eth-mac" },
397 +       { /* sentinel */ }
398 +};
399 +
400 +static struct platform_driver eth_mac_driver = {
401 +       .driver         = {
402 +               .name           = "lantiq,eth-mac",
403 +               .owner  = THIS_MODULE,
404 +               .of_match_table = of_match_ptr(eth_mac_ids),
405 +       },
406 +};
407 +
408 +static int __init of_eth_mac_init(void)
409 +{
410 +       return platform_driver_probe(&eth_mac_driver, of_eth_mac_probe);
411 +}
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
417 @@ -0,0 +1,109 @@
418 +/*
419 + *  Atheros AP94 reference board PCI initialization
420 + *
421 + *  Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
422 + *
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.
426 + */
427 +
428 +#include <linux/pci.h>
429 +#include <linux/init.h>
430 +#include <linux/delay.h>
431 +#include <lantiq_soc.h>
432 +
433 +#define LTQ_PCI_MEM_BASE               0x18000000
434 +
435 +struct ath_fixup {
436 +       u16             *cal_data;
437 +       unsigned        slot;
438 +};
439 +
440 +static int ath_num_fixups;
441 +static struct ath_fixup ath_fixups[2];
442 +
443 +static void ath_pci_fixup(struct pci_dev *dev)
444 +{
445 +       void __iomem *mem;
446 +       u16 *cal_data = NULL;
447 +       u16 cmd;
448 +       u32 bar0;
449 +       u32 val;
450 +       unsigned i;
451 +
452 +       for (i = 0; i < ath_num_fixups; i++) {
453 +               if (ath_fixups[i].cal_data == NULL)
454 +                       continue;
455 +
456 +               if (ath_fixups[i].slot != PCI_SLOT(dev->devfn))
457 +                       continue;
458 +
459 +               cal_data = ath_fixups[i].cal_data;
460 +               break;
461 +       }
462 +
463 +       if (cal_data == NULL)
464 +               return;
465 +
466 +       if (*cal_data != 0xa55a) {
467 +               pr_err("pci %s: invalid calibration data\n", pci_name(dev));
468 +               return;
469 +       }
470 +
471 +       pr_info("pci %s: fixup device configuration\n", pci_name(dev));
472 +
473 +       mem = ioremap(LTQ_PCI_MEM_BASE, 0x10000);
474 +       if (!mem) {
475 +               pr_err("pci %s: ioremap error\n", pci_name(dev));
476 +               return;
477 +       }
478 +
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);
484 +
485 +       /* set pointer to first reg address */
486 +       cal_data += 3;
487 +       while (*cal_data != 0xffff) {
488 +               u32 reg;
489 +               reg = *cal_data++;
490 +               val = *cal_data++;
491 +               val |= (*cal_data++) << 16;
492 +
493 +               ltq_w32(swab32(val), mem + reg);
494 +               udelay(100);
495 +       }
496 +
497 +       pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
498 +       dev->vendor = val & 0xffff;
499 +       dev->device = (val >> 16) & 0xffff;
500 +
501 +       pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
502 +       dev->revision = val & 0xff;
503 +       dev->class = val >> 8; /* upper 3 bytes */
504 +
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);
507 +
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);
511 +
512 +       pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
513 +
514 +       iounmap(mem);
515 +}
516 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath_pci_fixup);
517 +
518 +void __init ltq_pci_ath_fixup(unsigned slot, u16 *cal_data)
519 +{
520 +       if (ath_num_fixups >= ARRAY_SIZE(ath_fixups))
521 +               return;
522 +
523 +       ath_fixups[ath_num_fixups].slot = slot;
524 +       ath_fixups[ath_num_fixups].cal_data = cal_data;
525 +       ath_num_fixups++;
526 +}
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
531 @@ -0,0 +1,60 @@
532 +/*
533 + *  Copyright (C) 2011 John Crispin <blogic@openwrt.org>
534 + *
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.
538 + */
539 +
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>
545 +
546 +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
547 +static struct rt2x00_platform_data rt2x00_pdata;
548 +
549 +static int rt2x00_pci_plat_dev_init(struct pci_dev *dev)
550 +{
551 +       dev->dev.platform_data = &rt2x00_pdata;
552 +       return 0;
553 +}
554 +
555 +int __init of_ralink_eeprom_probe(struct platform_device *pdev)
556 +{
557 +       struct device_node *np = pdev->dev.of_node;
558 +       const char *eeprom;
559 +
560 +       if (of_property_read_string(np, "ralink,eeprom", &eeprom)) {
561 +               dev_err(&pdev->dev, "failed to load eeprom filename\n");
562 +               return 0;
563 +       }
564 +
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;
568 +
569 +       dev_info(&pdev->dev, "using %s as eeprom\n", eeprom);
570 +
571 +       return 0;
572 +}
573 +
574 +static struct of_device_id ralink_eeprom_ids[] = {
575 +       { .compatible = "ralink,eeprom" },
576 +       { }
577 +};
578 +
579 +static struct platform_driver ralink_eeprom_driver = {
580 +       .driver         = {
581 +               .name           = "ralink,eeprom",
582 +               .owner  = THIS_MODULE,
583 +               .of_match_table = of_match_ptr(ralink_eeprom_ids),
584 +       },
585 +};
586 +
587 +static int __init of_ralink_eeprom_init(void)
588 +{
589 +       return platform_driver_probe(&ralink_eeprom_driver, of_ralink_eeprom_probe);
590 +}
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
596 @@ -829,7 +829,8 @@
597  
598         ltq_etop_change_mtu(dev, 1500);
599  
600 -       memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
601 +       if (priv->mac)
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);
606 @@ -888,8 +889,7 @@
607         .ndo_tx_timeout = ltq_etop_tx_timeout,
608  };
609  
610 -static int __devinit
611 -ltq_etop_probe(struct platform_device *pdev)
612 +static int ltq_etop_probe(struct platform_device *pdev)
613  {
614         struct net_device *dev;
615         struct ltq_etop_priv *priv;
616 @@ -953,7 +953,9 @@
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();
622 +       if (!priv->mac)
623 +               priv->mac = of_get_mac_address(pdev->dev.of_node);
624  
625         priv->clk_ppe = clk_get(&pdev->dev, NULL);
626         if (IS_ERR(priv->clk_ppe))