0018-owrt-lantiq-wifi-and-ethernet-eeprom-handling.patch 16 KB

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