0035-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. From f8c5db89e793a4bc6c1e87bd7b3a5cec16b75bc3 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Wed, 10 Sep 2014 22:42:14 +0200
  4. Subject: [PATCH 35/36] owrt: lantiq: wifi and ethernet eeprom handling
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  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 | 282 ++++++++++++++++++++
  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. 7 files changed, 539 insertions(+)
  15. create mode 100644 arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h
  16. create mode 100644 arch/mips/lantiq/xway/ath_eep.c
  17. create mode 100644 arch/mips/lantiq/xway/eth_mac.c
  18. create mode 100644 arch/mips/lantiq/xway/pci-ath-fixup.c
  19. create mode 100644 arch/mips/lantiq/xway/rt_eep.c
  20. --- /dev/null
  21. +++ b/arch/mips/include/asm/mach-lantiq/pci-ath-fixup.h
  22. @@ -0,0 +1,6 @@
  23. +#ifndef _PCI_ATH_FIXUP
  24. +#define _PCI_ATH_FIXUP
  25. +
  26. +void ltq_pci_ath_fixup(unsigned slot, u16 *cal_data) __init;
  27. +
  28. +#endif /* _PCI_ATH_FIXUP */
  29. --- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
  30. +++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
  31. @@ -104,5 +104,8 @@ int xrx200_gphy_boot(struct device *dev,
  32. extern void ltq_pmu_enable(unsigned int module);
  33. extern void ltq_pmu_disable(unsigned int module);
  34. +/* allow the ethernet driver to load a flash mapped mac addr */
  35. +const u8* ltq_get_eth_mac(void);
  36. +
  37. #endif /* CONFIG_SOC_TYPE_XWAY */
  38. #endif /* _LTQ_XWAY_H__ */
  39. --- a/arch/mips/lantiq/xway/Makefile
  40. +++ b/arch/mips/lantiq/xway/Makefile
  41. @@ -2,4 +2,7 @@ obj-y := prom.o sysctrl.o clk.o reset.o
  42. obj-y += vmmc.o tffs.o
  43. +obj-y += eth_mac.o
  44. +obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
  45. +
  46. obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
  47. --- /dev/null
  48. +++ b/arch/mips/lantiq/xway/ath_eep.c
  49. @@ -0,0 +1,307 @@
  50. +/*
  51. + * Copyright (C) 2011 Luca Olivetti <luca@ventoso.org>
  52. + * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
  53. + * Copyright (C) 2011 Andrej Vlašić <andrej.vlasic0@gmail.com>
  54. + * Copyright (C) 2013 Álvaro Fernández Rojas <noltari@gmail.com>
  55. + * Copyright (C) 2013 Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
  56. + * Copyright (C) 2015 Vittorio Gambaletta <openwrt@vittgam.net>
  57. + *
  58. + * This program is free software; you can redistribute it and/or modify it
  59. + * under the terms of the GNU General Public License version 2 as published
  60. + * by the Free Software Foundation.
  61. + */
  62. +
  63. +#include <linux/init.h>
  64. +#include <linux/module.h>
  65. +#include <linux/platform_device.h>
  66. +#include <linux/etherdevice.h>
  67. +#include <linux/ath5k_platform.h>
  68. +#include <linux/ath9k_platform.h>
  69. +#include <linux/pci.h>
  70. +#include <linux/err.h>
  71. +#include <linux/mtd/mtd.h>
  72. +#include <pci-ath-fixup.h>
  73. +#include <lantiq_soc.h>
  74. +
  75. +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
  76. +struct ath5k_platform_data ath5k_pdata;
  77. +struct ath9k_platform_data ath9k_pdata = {
  78. + .led_pin = -1,
  79. +};
  80. +static u8 athxk_eeprom_mac[6];
  81. +
  82. +static int ath9k_pci_plat_dev_init(struct pci_dev *dev)
  83. +{
  84. + dev->dev.platform_data = &ath9k_pdata;
  85. + return 0;
  86. +}
  87. +
  88. +static int ath9k_eep_load;
  89. +int __init of_ath9k_eeprom_probe(struct platform_device *pdev)
  90. +{
  91. + struct device_node *np = pdev->dev.of_node, *mtd_np;
  92. + struct resource *eep_res, *mac_res = NULL;
  93. + void __iomem *eep, *mac;
  94. + int mac_offset, led_pin;
  95. + u32 mac_inc = 0, pci_slot = 0;
  96. + int i;
  97. + struct mtd_info *the_mtd;
  98. + size_t flash_readlen;
  99. + const __be32 *list;
  100. + const char *part;
  101. + phandle phandle;
  102. + u16 dev_ids[2] = { 0 };
  103. +
  104. + if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
  105. + sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
  106. + (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
  107. + of_get_property(mtd_np, "label", NULL)) || (part =
  108. + mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
  109. + != ERR_PTR(-ENODEV)) {
  110. + i = mtd_read(the_mtd, be32_to_cpup(list),
  111. + ATH9K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
  112. + (void *) ath9k_pdata.eeprom_data);
  113. + if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
  114. + size_t mac_readlen;
  115. + mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
  116. + (void *) athxk_eeprom_mac);
  117. + }
  118. + put_mtd_device(the_mtd);
  119. + if ((sizeof(ath9k_pdata.eeprom_data) != flash_readlen) || i) {
  120. + dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
  121. + return -ENODEV;
  122. + }
  123. + } else {
  124. + eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  125. + mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  126. +
  127. + if (!eep_res) {
  128. + dev_err(&pdev->dev, "failed to load eeprom address\n");
  129. + return -ENODEV;
  130. + }
  131. + if (resource_size(eep_res) != ATH9K_PLAT_EEP_MAX_WORDS << 1) {
  132. + dev_err(&pdev->dev, "eeprom has an invalid size\n");
  133. + return -EINVAL;
  134. + }
  135. +
  136. + eep = ioremap(eep_res->start, resource_size(eep_res));
  137. + memcpy_fromio(ath9k_pdata.eeprom_data, eep,
  138. + ATH9K_PLAT_EEP_MAX_WORDS << 1);
  139. + }
  140. +
  141. + if (of_find_property(np, "ath,eep-swap", NULL))
  142. + for (i = 0; i < ATH9K_PLAT_EEP_MAX_WORDS; i++)
  143. + ath9k_pdata.eeprom_data[i] = swab16(ath9k_pdata.eeprom_data[i]);
  144. +
  145. + if (of_find_property(np, "ath,eep-endian", NULL)) {
  146. + ath9k_pdata.endian_check = true;
  147. +
  148. + dev_info(&pdev->dev, "endian check enabled.\n");
  149. + }
  150. +
  151. + if (!is_valid_ether_addr(athxk_eeprom_mac)) {
  152. + if (mac_res) {
  153. + if (resource_size(mac_res) != 6) {
  154. + dev_err(&pdev->dev, "mac has an invalid size\n");
  155. + return -EINVAL;
  156. + }
  157. + mac = ioremap(mac_res->start, resource_size(mac_res));
  158. + memcpy_fromio(athxk_eeprom_mac, mac, 6);
  159. + } else if (ltq_get_eth_mac()) {
  160. + memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
  161. + }
  162. + }
  163. + if (!is_valid_ether_addr(athxk_eeprom_mac)) {
  164. + dev_warn(&pdev->dev, "using random mac\n");
  165. + random_ether_addr(athxk_eeprom_mac);
  166. + }
  167. +
  168. + if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
  169. + athxk_eeprom_mac[5] += mac_inc;
  170. +
  171. + ath9k_pdata.macaddr = athxk_eeprom_mac;
  172. + ltq_pci_plat_dev_init = ath9k_pci_plat_dev_init;
  173. +
  174. + if (!of_property_read_u32(np, "ath,pci-slot", &pci_slot)) {
  175. + ltq_pci_ath_fixup(pci_slot, ath9k_pdata.eeprom_data);
  176. +
  177. + dev_info(&pdev->dev, "pci slot: %u\n", pci_slot);
  178. + if (ath9k_eep_load) {
  179. + struct pci_dev *d = NULL;
  180. + while ((d = pci_get_device(PCI_VENDOR_ID_ATHEROS,
  181. + PCI_ANY_ID, d)) != NULL)
  182. + pci_fixup_device(pci_fixup_early, d);
  183. + }
  184. +
  185. + }
  186. +
  187. + if (!of_property_read_u16_array(np, "ath,device-id", dev_ids, 2)) {
  188. + struct pci_dev *d = NULL;
  189. +
  190. + while ((d = pci_get_device(PCI_VENDOR_ID_ATHEROS,
  191. + dev_ids[0], d)) != NULL)
  192. + d->device = dev_ids[1];
  193. + }
  194. +
  195. + if (!of_property_read_u32(np, "ath,led-pin", &led_pin)) {
  196. + ath9k_pdata.led_pin = led_pin;
  197. + dev_info(&pdev->dev, "using led pin %d.\n", led_pin);
  198. + }
  199. +
  200. + if (of_property_read_bool(np, "ath,led-active-high")) {
  201. + ath9k_pdata.led_active_high = true;
  202. + dev_info(&pdev->dev, "inverted LED polarity\n");
  203. + }
  204. +
  205. + if (of_property_read_bool(np, "ath,disable-2ghz")) {
  206. + ath9k_pdata.disable_2ghz = true;
  207. + dev_info(&pdev->dev, "disabled 2.4 GHz band\n");
  208. + }
  209. +
  210. + if (of_property_read_bool(np, "ath,disable-5ghz")) {
  211. + ath9k_pdata.disable_5ghz = true;
  212. + dev_info(&pdev->dev, "disabled 5 GHz band\n");
  213. + }
  214. +
  215. + dev_info(&pdev->dev, "loaded ath9k eeprom\n");
  216. +
  217. + return 0;
  218. +}
  219. +
  220. +static struct of_device_id ath9k_eeprom_ids[] = {
  221. + { .compatible = "ath9k,eeprom" },
  222. + { }
  223. +};
  224. +
  225. +static struct platform_driver ath9k_eeprom_driver = {
  226. + .driver = {
  227. + .name = "ath9k,eeprom",
  228. + .owner = THIS_MODULE,
  229. + .of_match_table = of_match_ptr(ath9k_eeprom_ids),
  230. + },
  231. +};
  232. +
  233. +static int __init of_ath9k_eeprom_init(void)
  234. +{
  235. + int ret = platform_driver_probe(&ath9k_eeprom_driver, of_ath9k_eeprom_probe);
  236. +
  237. + if (ret)
  238. + ath9k_eep_load = 1;
  239. +
  240. + return ret;
  241. +}
  242. +
  243. +static int __init of_ath9k_eeprom_init_late(void)
  244. +{
  245. + if (!ath9k_eep_load)
  246. + return 0;
  247. + return platform_driver_probe(&ath9k_eeprom_driver, of_ath9k_eeprom_probe);
  248. +}
  249. +late_initcall(of_ath9k_eeprom_init_late);
  250. +subsys_initcall(of_ath9k_eeprom_init);
  251. +
  252. +
  253. +static int ath5k_pci_plat_dev_init(struct pci_dev *dev)
  254. +{
  255. + dev->dev.platform_data = &ath5k_pdata;
  256. + return 0;
  257. +}
  258. +
  259. +int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
  260. +{
  261. + struct device_node *np = pdev->dev.of_node, *mtd_np;
  262. + struct resource *eep_res, *mac_res = NULL;
  263. + void __iomem *eep, *mac;
  264. + int mac_offset;
  265. + u32 mac_inc = 0;
  266. + int i;
  267. + struct mtd_info *the_mtd;
  268. + size_t flash_readlen;
  269. + const __be32 *list;
  270. + const char *part;
  271. + phandle phandle;
  272. +
  273. + if ((list = of_get_property(np, "ath,eep-flash", &i)) && i == 2 *
  274. + sizeof(*list) && (phandle = be32_to_cpup(list++)) &&
  275. + (mtd_np = of_find_node_by_phandle(phandle)) && ((part =
  276. + of_get_property(mtd_np, "label", NULL)) || (part =
  277. + mtd_np->name)) && (the_mtd = get_mtd_device_nm(part))
  278. + != ERR_PTR(-ENODEV)) {
  279. + i = mtd_read(the_mtd, be32_to_cpup(list),
  280. + ATH5K_PLAT_EEP_MAX_WORDS << 1, &flash_readlen,
  281. + (void *) ath5k_pdata.eeprom_data);
  282. + put_mtd_device(the_mtd);
  283. + if ((sizeof(ATH5K_PLAT_EEP_MAX_WORDS << 1) != flash_readlen)
  284. + || i) {
  285. + dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
  286. + return -ENODEV;
  287. + }
  288. + } else {
  289. + eep_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  290. + mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  291. +
  292. + if (!eep_res) {
  293. + dev_err(&pdev->dev, "failed to load eeprom address\n");
  294. + return -ENODEV;
  295. + }
  296. + if (resource_size(eep_res) != ATH5K_PLAT_EEP_MAX_WORDS << 1) {
  297. + dev_err(&pdev->dev, "eeprom has an invalid size\n");
  298. + return -EINVAL;
  299. + }
  300. +
  301. + eep = ioremap(eep_res->start, resource_size(eep_res));
  302. + ath5k_pdata.eeprom_data = kmalloc(ATH5K_PLAT_EEP_MAX_WORDS<<1,
  303. + GFP_KERNEL);
  304. + memcpy_fromio(ath5k_pdata.eeprom_data, eep,
  305. + ATH5K_PLAT_EEP_MAX_WORDS << 1);
  306. + }
  307. +
  308. + if (of_find_property(np, "ath,eep-swap", NULL))
  309. + for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
  310. + ath5k_pdata.eeprom_data[i] = swab16(ath5k_pdata.eeprom_data[i]);
  311. +
  312. + if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
  313. + memcpy_fromio(athxk_eeprom_mac, (void*) ath5k_pdata.eeprom_data + mac_offset, 6);
  314. + } else if (mac_res) {
  315. + if (resource_size(mac_res) != 6) {
  316. + dev_err(&pdev->dev, "mac has an invalid size\n");
  317. + return -EINVAL;
  318. + }
  319. + mac = ioremap(mac_res->start, resource_size(mac_res));
  320. + memcpy_fromio(athxk_eeprom_mac, mac, 6);
  321. + } else if (ltq_get_eth_mac())
  322. + memcpy(athxk_eeprom_mac, ltq_get_eth_mac(), 6);
  323. + else {
  324. + dev_warn(&pdev->dev, "using random mac\n");
  325. + random_ether_addr(athxk_eeprom_mac);
  326. + }
  327. +
  328. + if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
  329. + athxk_eeprom_mac[5] += mac_inc;
  330. +
  331. + ath5k_pdata.macaddr = athxk_eeprom_mac;
  332. + ltq_pci_plat_dev_init = ath5k_pci_plat_dev_init;
  333. +
  334. + dev_info(&pdev->dev, "loaded ath5k eeprom\n");
  335. +
  336. + return 0;
  337. +}
  338. +
  339. +static struct of_device_id ath5k_eeprom_ids[] = {
  340. + { .compatible = "ath5k,eeprom" },
  341. + { }
  342. +};
  343. +
  344. +static struct platform_driver ath5k_eeprom_driver = {
  345. + .driver = {
  346. + .name = "ath5k,eeprom",
  347. + .owner = THIS_MODULE,
  348. + .of_match_table = of_match_ptr(ath5k_eeprom_ids),
  349. + },
  350. +};
  351. +
  352. +static int __init of_ath5k_eeprom_init(void)
  353. +{
  354. + return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
  355. +}
  356. +device_initcall(of_ath5k_eeprom_init);
  357. --- /dev/null
  358. +++ b/arch/mips/lantiq/xway/eth_mac.c
  359. @@ -0,0 +1,76 @@
  360. +/*
  361. + * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
  362. + *
  363. + * This program is free software; you can redistribute it and/or modify it
  364. + * under the terms of the GNU General Public License version 2 as published
  365. + * by the Free Software Foundation.
  366. + */
  367. +
  368. +#include <linux/init.h>
  369. +#include <linux/module.h>
  370. +#include <linux/of_platform.h>
  371. +#include <linux/if_ether.h>
  372. +
  373. +static u8 eth_mac[6];
  374. +static int eth_mac_set;
  375. +
  376. +const u8* ltq_get_eth_mac(void)
  377. +{
  378. + return eth_mac;
  379. +}
  380. +
  381. +static int __init setup_ethaddr(char *str)
  382. +{
  383. + eth_mac_set = mac_pton(str, eth_mac);
  384. + return !eth_mac_set;
  385. +}
  386. +early_param("ethaddr", setup_ethaddr);
  387. +
  388. +int __init of_eth_mac_probe(struct platform_device *pdev)
  389. +{
  390. + struct device_node *np = pdev->dev.of_node;
  391. + struct resource *mac_res;
  392. + void __iomem *mac;
  393. + u32 mac_inc = 0;
  394. +
  395. + if (eth_mac_set) {
  396. + dev_err(&pdev->dev, "mac was already set by bootloader\n");
  397. + return -EINVAL;
  398. + }
  399. + mac_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  400. +
  401. + if (!mac_res) {
  402. + dev_err(&pdev->dev, "failed to load mac\n");
  403. + return -EINVAL;
  404. + }
  405. + if (resource_size(mac_res) != 6) {
  406. + dev_err(&pdev->dev, "mac has an invalid size\n");
  407. + return -EINVAL;
  408. + }
  409. + mac = ioremap(mac_res->start, resource_size(mac_res));
  410. + memcpy_fromio(eth_mac, mac, 6);
  411. +
  412. + if (!of_property_read_u32(np, "mac-increment", &mac_inc))
  413. + eth_mac[5] += mac_inc;
  414. +
  415. + return 0;
  416. +}
  417. +
  418. +static struct of_device_id eth_mac_ids[] = {
  419. + { .compatible = "lantiq,eth-mac" },
  420. + { /* sentinel */ }
  421. +};
  422. +
  423. +static struct platform_driver eth_mac_driver = {
  424. + .driver = {
  425. + .name = "lantiq,eth-mac",
  426. + .owner = THIS_MODULE,
  427. + .of_match_table = of_match_ptr(eth_mac_ids),
  428. + },
  429. +};
  430. +
  431. +static int __init of_eth_mac_init(void)
  432. +{
  433. + return platform_driver_probe(&eth_mac_driver, of_eth_mac_probe);
  434. +}
  435. +device_initcall(of_eth_mac_init);
  436. --- /dev/null
  437. +++ b/arch/mips/lantiq/xway/pci-ath-fixup.c
  438. @@ -0,0 +1,118 @@
  439. +/*
  440. + * Atheros AP94 reference board PCI initialization
  441. + *
  442. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  443. + *
  444. + * This program is free software; you can redistribute it and/or modify it
  445. + * under the terms of the GNU General Public License version 2 as published
  446. + * by the Free Software Foundation.
  447. + */
  448. +
  449. +#include <linux/pci.h>
  450. +#include <linux/init.h>
  451. +#include <linux/delay.h>
  452. +#include <lantiq_soc.h>
  453. +
  454. +struct ath_fixup {
  455. + u16 *cal_data;
  456. + unsigned slot;
  457. +};
  458. +
  459. +static int ath_num_fixups;
  460. +static struct ath_fixup ath_fixups[2];
  461. +
  462. +static void ath_pci_fixup(struct pci_dev *dev)
  463. +{
  464. + void __iomem *mem;
  465. + struct pci_dev *bridge = pci_upstream_bridge(dev);
  466. + u16 *cal_data = NULL;
  467. + u16 cmd;
  468. + u32 bar0;
  469. + u32 val;
  470. + u32 base;
  471. + unsigned i;
  472. +
  473. + for (i = 0; i < ath_num_fixups; i++) {
  474. + if (ath_fixups[i].cal_data == NULL)
  475. + continue;
  476. +
  477. + if (ath_fixups[i].slot != PCI_SLOT(dev->devfn))
  478. + continue;
  479. +
  480. + cal_data = ath_fixups[i].cal_data;
  481. + break;
  482. + }
  483. +
  484. + if (cal_data == NULL)
  485. + return;
  486. +
  487. + if (*cal_data != 0xa55a) {
  488. + pr_err("pci %s: invalid calibration data\n", pci_name(dev));
  489. + return;
  490. + }
  491. +
  492. + pr_info("pci %s: fixup device configuration\n", pci_name(dev));
  493. +
  494. + base = dev->resource[0].start;
  495. + mem = ioremap(base, 0x10000);
  496. + if (!mem) {
  497. + pr_err("pci %s: ioremap error\n", pci_name(dev));
  498. + return;
  499. + }
  500. +
  501. + if (bridge) {
  502. + pci_enable_device(dev);
  503. + }
  504. +
  505. + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
  506. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, base);
  507. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  508. + cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  509. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  510. +
  511. + /* set pointer to first reg address */
  512. + cal_data += 3;
  513. + while (*cal_data != 0xffff) {
  514. + u32 reg;
  515. + reg = *cal_data++;
  516. + val = *cal_data++;
  517. + val |= (*cal_data++) << 16;
  518. +
  519. + ltq_w32(swab32(val), mem + reg);
  520. + udelay(100);
  521. + }
  522. +
  523. + pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
  524. + dev->vendor = val & 0xffff;
  525. + dev->device = (val >> 16) & 0xffff;
  526. +
  527. + pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
  528. + dev->revision = val & 0xff;
  529. + dev->class = val >> 8; /* upper 3 bytes */
  530. +
  531. + pr_info("pci %s: fixup info: [%04x:%04x] revision %02x class %#08x\n",
  532. + pci_name(dev), dev->vendor, dev->device, dev->revision, dev->class);
  533. +
  534. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  535. + cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  536. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  537. +
  538. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
  539. +
  540. + if (bridge) {
  541. + pci_disable_device(dev);
  542. + }
  543. +
  544. + iounmap(mem);
  545. +}
  546. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath_pci_fixup);
  547. +
  548. +void __init ltq_pci_ath_fixup(unsigned slot, u16 *cal_data)
  549. +{
  550. + if (ath_num_fixups >= ARRAY_SIZE(ath_fixups))
  551. + return;
  552. +
  553. + ath_fixups[ath_num_fixups].slot = slot;
  554. + ath_fixups[ath_num_fixups].cal_data = cal_data;
  555. + ath_num_fixups++;
  556. +}
  557. --- /dev/null
  558. +++ b/arch/mips/lantiq/xway/rt_eep.c
  559. @@ -0,0 +1,60 @@
  560. +/*
  561. + * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
  562. + *
  563. + * This program is free software; you can redistribute it and/or modify it
  564. + * under the terms of the GNU General Public License version 2 as published
  565. + * by the Free Software Foundation.
  566. + */
  567. +
  568. +#include <linux/init.h>
  569. +#include <linux/module.h>
  570. +#include <linux/pci.h>
  571. +#include <linux/platform_device.h>
  572. +#include <linux/rt2x00_platform.h>
  573. +
  574. +extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
  575. +static struct rt2x00_platform_data rt2x00_pdata;
  576. +
  577. +static int rt2x00_pci_plat_dev_init(struct pci_dev *dev)
  578. +{
  579. + dev->dev.platform_data = &rt2x00_pdata;
  580. + return 0;
  581. +}
  582. +
  583. +int __init of_ralink_eeprom_probe(struct platform_device *pdev)
  584. +{
  585. + struct device_node *np = pdev->dev.of_node;
  586. + const char *eeprom;
  587. +
  588. + if (of_property_read_string(np, "ralink,eeprom", &eeprom)) {
  589. + dev_err(&pdev->dev, "failed to load eeprom filename\n");
  590. + return 0;
  591. + }
  592. +
  593. + rt2x00_pdata.eeprom_file_name = kstrdup(eeprom, GFP_KERNEL);
  594. +// rt2x00_pdata.mac_address = mac;
  595. + ltq_pci_plat_dev_init = rt2x00_pci_plat_dev_init;
  596. +
  597. + dev_info(&pdev->dev, "using %s as eeprom\n", eeprom);
  598. +
  599. + return 0;
  600. +}
  601. +
  602. +static struct of_device_id ralink_eeprom_ids[] = {
  603. + { .compatible = "ralink,eeprom" },
  604. + { }
  605. +};
  606. +
  607. +static struct platform_driver ralink_eeprom_driver = {
  608. + .driver = {
  609. + .name = "ralink,eeprom",
  610. + .owner = THIS_MODULE,
  611. + .of_match_table = of_match_ptr(ralink_eeprom_ids),
  612. + },
  613. +};
  614. +
  615. +static int __init of_ralink_eeprom_init(void)
  616. +{
  617. + return platform_driver_probe(&ralink_eeprom_driver, of_ralink_eeprom_probe);
  618. +}
  619. +device_initcall(of_ralink_eeprom_init);
  620. --- a/drivers/net/ethernet/lantiq_etop.c
  621. +++ b/drivers/net/ethernet/lantiq_etop.c
  622. @@ -840,7 +840,11 @@ ltq_etop_init(struct net_device *dev)
  623. if (err)
  624. goto err_hw;
  625. - memcpy(&mac, &priv->pldata->mac, sizeof(struct sockaddr));
  626. + memcpy(&mac.sa_data, ltq_get_eth_mac(), ETH_ALEN);
  627. +
  628. + if (priv->mac && !is_valid_ether_addr(mac.sa_data))
  629. + memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
  630. +
  631. if (!is_valid_ether_addr(mac.sa_data)) {
  632. pr_warn("etop: invalid MAC, using random\n");
  633. eth_random_addr(mac.sa_data);