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

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