pci-rt3883.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * Ralink RT3662/RT3883 SoC PCI support
  3. *
  4. * Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * Parts of this file are based on Ralink's 2.6.21 BSP
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/pci.h>
  14. #include <linux/io.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/of.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of_pci.h>
  21. #include <linux/platform_device.h>
  22. #include <asm/mach-ralink/rt3883.h>
  23. #include <asm/mach-ralink/ralink_regs.h>
  24. #define RT3883_MEMORY_BASE 0x00000000
  25. #define RT3883_MEMORY_SIZE 0x02000000
  26. #define RT3883_PCI_REG_PCICFG 0x00
  27. #define RT3883_PCICFG_P2P_BR_DEVNUM_M 0xf
  28. #define RT3883_PCICFG_P2P_BR_DEVNUM_S 16
  29. #define RT3883_PCICFG_PCIRST BIT(1)
  30. #define RT3883_PCI_REG_PCIRAW 0x04
  31. #define RT3883_PCI_REG_PCIINT 0x08
  32. #define RT3883_PCI_REG_PCIENA 0x0c
  33. #define RT3883_PCI_REG_CFGADDR 0x20
  34. #define RT3883_PCI_REG_CFGDATA 0x24
  35. #define RT3883_PCI_REG_MEMBASE 0x28
  36. #define RT3883_PCI_REG_IOBASE 0x2c
  37. #define RT3883_PCI_REG_ARBCTL 0x80
  38. #define RT3883_PCI_REG_BASE(_x) (0x1000 + (_x) * 0x1000)
  39. #define RT3883_PCI_REG_BAR0SETUP(_x) (RT3883_PCI_REG_BASE((_x)) + 0x10)
  40. #define RT3883_PCI_REG_IMBASEBAR0(_x) (RT3883_PCI_REG_BASE((_x)) + 0x18)
  41. #define RT3883_PCI_REG_ID(_x) (RT3883_PCI_REG_BASE((_x)) + 0x30)
  42. #define RT3883_PCI_REG_CLASS(_x) (RT3883_PCI_REG_BASE((_x)) + 0x34)
  43. #define RT3883_PCI_REG_SUBID(_x) (RT3883_PCI_REG_BASE((_x)) + 0x38)
  44. #define RT3883_PCI_REG_STATUS(_x) (RT3883_PCI_REG_BASE((_x)) + 0x50)
  45. #define RT3883_PCI_MODE_NONE 0
  46. #define RT3883_PCI_MODE_PCI BIT(0)
  47. #define RT3883_PCI_MODE_PCIE BIT(1)
  48. #define RT3883_PCI_MODE_BOTH (RT3883_PCI_MODE_PCI | RT3883_PCI_MODE_PCIE)
  49. #define RT3883_PCI_IRQ_COUNT 32
  50. #define RT3883_P2P_BR_DEVNUM 1
  51. struct rt3883_pci_controller {
  52. void __iomem *base;
  53. struct device_node *intc_of_node;
  54. struct irq_domain *irq_domain;
  55. struct pci_controller pci_controller;
  56. struct resource io_res;
  57. struct resource mem_res;
  58. bool pcie_ready;
  59. };
  60. static inline struct rt3883_pci_controller *
  61. pci_bus_to_rt3883_controller(struct pci_bus *bus)
  62. {
  63. struct pci_controller *hose;
  64. hose = (struct pci_controller *) bus->sysdata;
  65. return container_of(hose, struct rt3883_pci_controller, pci_controller);
  66. }
  67. static inline u32 rt3883_pci_r32(struct rt3883_pci_controller *rpc,
  68. unsigned reg)
  69. {
  70. return ioread32(rpc->base + reg);
  71. }
  72. static inline void rt3883_pci_w32(struct rt3883_pci_controller *rpc,
  73. u32 val, unsigned reg)
  74. {
  75. iowrite32(val, rpc->base + reg);
  76. }
  77. static inline u32 rt3883_pci_get_cfgaddr(unsigned int bus, unsigned int slot,
  78. unsigned int func, unsigned int where)
  79. {
  80. return (bus << 16) | (slot << 11) | (func << 8) | (where & 0xfc) |
  81. 0x80000000;
  82. }
  83. static u32 rt3883_pci_read_cfg32(struct rt3883_pci_controller *rpc,
  84. unsigned bus, unsigned slot,
  85. unsigned func, unsigned reg)
  86. {
  87. unsigned long flags;
  88. u32 address;
  89. u32 ret;
  90. address = rt3883_pci_get_cfgaddr(bus, slot, func, reg);
  91. rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
  92. ret = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
  93. return ret;
  94. }
  95. static void rt3883_pci_write_cfg32(struct rt3883_pci_controller *rpc,
  96. unsigned bus, unsigned slot,
  97. unsigned func, unsigned reg, u32 val)
  98. {
  99. unsigned long flags;
  100. u32 address;
  101. address = rt3883_pci_get_cfgaddr(bus, slot, func, reg);
  102. rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
  103. rt3883_pci_w32(rpc, val, RT3883_PCI_REG_CFGDATA);
  104. }
  105. static void rt3883_pci_irq_handler(struct irq_desc *desc)
  106. {
  107. struct rt3883_pci_controller *rpc;
  108. u32 pending;
  109. rpc = irq_desc_get_handler_data(desc);
  110. pending = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIINT) &
  111. rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
  112. if (!pending) {
  113. spurious_interrupt();
  114. return;
  115. }
  116. while (pending) {
  117. unsigned irq, bit = __ffs(pending);
  118. irq = irq_find_mapping(rpc->irq_domain, bit);
  119. generic_handle_irq(irq);
  120. pending &= ~BIT(bit);
  121. }
  122. }
  123. static void rt3883_pci_irq_unmask(struct irq_data *d)
  124. {
  125. struct rt3883_pci_controller *rpc;
  126. u32 t;
  127. rpc = irq_data_get_irq_chip_data(d);
  128. t = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
  129. rt3883_pci_w32(rpc, t | BIT(d->hwirq), RT3883_PCI_REG_PCIENA);
  130. /* flush write */
  131. rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
  132. }
  133. static void rt3883_pci_irq_mask(struct irq_data *d)
  134. {
  135. struct rt3883_pci_controller *rpc;
  136. u32 t;
  137. rpc = irq_data_get_irq_chip_data(d);
  138. t = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
  139. rt3883_pci_w32(rpc, t & ~BIT(d->hwirq), RT3883_PCI_REG_PCIENA);
  140. /* flush write */
  141. rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
  142. }
  143. static struct irq_chip rt3883_pci_irq_chip = {
  144. .name = "RT3883 PCI",
  145. .irq_mask = rt3883_pci_irq_mask,
  146. .irq_unmask = rt3883_pci_irq_unmask,
  147. .irq_mask_ack = rt3883_pci_irq_mask,
  148. };
  149. static int rt3883_pci_irq_map(struct irq_domain *d, unsigned int irq,
  150. irq_hw_number_t hw)
  151. {
  152. irq_set_chip_and_handler(irq, &rt3883_pci_irq_chip, handle_level_irq);
  153. irq_set_chip_data(irq, d->host_data);
  154. return 0;
  155. }
  156. static const struct irq_domain_ops rt3883_pci_irq_domain_ops = {
  157. .map = rt3883_pci_irq_map,
  158. .xlate = irq_domain_xlate_onecell,
  159. };
  160. static int rt3883_pci_irq_init(struct device *dev,
  161. struct rt3883_pci_controller *rpc)
  162. {
  163. int irq;
  164. irq = irq_of_parse_and_map(rpc->intc_of_node, 0);
  165. if (irq == 0) {
  166. dev_err(dev, "%s has no IRQ",
  167. of_node_full_name(rpc->intc_of_node));
  168. return -EINVAL;
  169. }
  170. /* disable all interrupts */
  171. rt3883_pci_w32(rpc, 0, RT3883_PCI_REG_PCIENA);
  172. rpc->irq_domain =
  173. irq_domain_add_linear(rpc->intc_of_node, RT3883_PCI_IRQ_COUNT,
  174. &rt3883_pci_irq_domain_ops,
  175. rpc);
  176. if (!rpc->irq_domain) {
  177. dev_err(dev, "unable to add IRQ domain\n");
  178. return -ENODEV;
  179. }
  180. irq_set_chained_handler_and_data(irq, rt3883_pci_irq_handler, rpc);
  181. return 0;
  182. }
  183. static int rt3883_pci_config_read(struct pci_bus *bus, unsigned int devfn,
  184. int where, int size, u32 *val)
  185. {
  186. struct rt3883_pci_controller *rpc;
  187. unsigned long flags;
  188. u32 address;
  189. u32 data;
  190. rpc = pci_bus_to_rt3883_controller(bus);
  191. if (!rpc->pcie_ready && bus->number == 1)
  192. return PCIBIOS_DEVICE_NOT_FOUND;
  193. address = rt3883_pci_get_cfgaddr(bus->number, PCI_SLOT(devfn),
  194. PCI_FUNC(devfn), where);
  195. rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
  196. data = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
  197. switch (size) {
  198. case 1:
  199. *val = (data >> ((where & 3) << 3)) & 0xff;
  200. break;
  201. case 2:
  202. *val = (data >> ((where & 3) << 3)) & 0xffff;
  203. break;
  204. case 4:
  205. *val = data;
  206. break;
  207. }
  208. return PCIBIOS_SUCCESSFUL;
  209. }
  210. static int rt3883_pci_config_write(struct pci_bus *bus, unsigned int devfn,
  211. int where, int size, u32 val)
  212. {
  213. struct rt3883_pci_controller *rpc;
  214. unsigned long flags;
  215. u32 address;
  216. u32 data;
  217. rpc = pci_bus_to_rt3883_controller(bus);
  218. if (!rpc->pcie_ready && bus->number == 1)
  219. return PCIBIOS_DEVICE_NOT_FOUND;
  220. address = rt3883_pci_get_cfgaddr(bus->number, PCI_SLOT(devfn),
  221. PCI_FUNC(devfn), where);
  222. rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
  223. data = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
  224. switch (size) {
  225. case 1:
  226. data = (data & ~(0xff << ((where & 3) << 3))) |
  227. (val << ((where & 3) << 3));
  228. break;
  229. case 2:
  230. data = (data & ~(0xffff << ((where & 3) << 3))) |
  231. (val << ((where & 3) << 3));
  232. break;
  233. case 4:
  234. data = val;
  235. break;
  236. }
  237. rt3883_pci_w32(rpc, data, RT3883_PCI_REG_CFGDATA);
  238. return PCIBIOS_SUCCESSFUL;
  239. }
  240. static struct pci_ops rt3883_pci_ops = {
  241. .read = rt3883_pci_config_read,
  242. .write = rt3883_pci_config_write,
  243. };
  244. static void rt3883_pci_preinit(struct rt3883_pci_controller *rpc, unsigned mode)
  245. {
  246. u32 syscfg1;
  247. u32 rstctrl;
  248. u32 clkcfg1;
  249. u32 t;
  250. rstctrl = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
  251. syscfg1 = rt_sysc_r32(RT3883_SYSC_REG_SYSCFG1);
  252. clkcfg1 = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
  253. if (mode & RT3883_PCI_MODE_PCIE) {
  254. rstctrl |= RT3883_RSTCTRL_PCIE;
  255. rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
  256. /* setup PCI PAD drive mode */
  257. syscfg1 &= ~(0x30);
  258. syscfg1 |= (2 << 4);
  259. rt_sysc_w32(syscfg1, RT3883_SYSC_REG_SYSCFG1);
  260. t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
  261. t &= ~BIT(31);
  262. rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
  263. t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN1);
  264. t &= 0x80ffffff;
  265. rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN1);
  266. t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN1);
  267. t |= 0xa << 24;
  268. rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN1);
  269. t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
  270. t |= BIT(31);
  271. rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
  272. msleep(50);
  273. rstctrl &= ~RT3883_RSTCTRL_PCIE;
  274. rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
  275. }
  276. syscfg1 |= (RT3883_SYSCFG1_PCIE_RC_MODE | RT3883_SYSCFG1_PCI_HOST_MODE);
  277. clkcfg1 &= ~(RT3883_CLKCFG1_PCI_CLK_EN | RT3883_CLKCFG1_PCIE_CLK_EN);
  278. if (mode & RT3883_PCI_MODE_PCI) {
  279. clkcfg1 |= RT3883_CLKCFG1_PCI_CLK_EN;
  280. rstctrl &= ~RT3883_RSTCTRL_PCI;
  281. }
  282. if (mode & RT3883_PCI_MODE_PCIE) {
  283. clkcfg1 |= RT3883_CLKCFG1_PCIE_CLK_EN;
  284. rstctrl &= ~RT3883_RSTCTRL_PCIE;
  285. }
  286. rt_sysc_w32(syscfg1, RT3883_SYSC_REG_SYSCFG1);
  287. rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
  288. rt_sysc_w32(clkcfg1, RT3883_SYSC_REG_CLKCFG1);
  289. msleep(500);
  290. /*
  291. * setup the device number of the P2P bridge
  292. * and de-assert the reset line
  293. */
  294. t = (RT3883_P2P_BR_DEVNUM << RT3883_PCICFG_P2P_BR_DEVNUM_S);
  295. rt3883_pci_w32(rpc, t, RT3883_PCI_REG_PCICFG);
  296. /* flush write */
  297. rt3883_pci_r32(rpc, RT3883_PCI_REG_PCICFG);
  298. msleep(500);
  299. if (mode & RT3883_PCI_MODE_PCIE) {
  300. msleep(500);
  301. t = rt3883_pci_r32(rpc, RT3883_PCI_REG_STATUS(1));
  302. rpc->pcie_ready = t & BIT(0);
  303. if (!rpc->pcie_ready) {
  304. /* reset the PCIe block */
  305. t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
  306. t |= RT3883_RSTCTRL_PCIE;
  307. rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
  308. t &= ~RT3883_RSTCTRL_PCIE;
  309. rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
  310. /* turn off PCIe clock */
  311. t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
  312. t &= ~RT3883_CLKCFG1_PCIE_CLK_EN;
  313. rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
  314. t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
  315. t &= ~0xf000c080;
  316. rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
  317. }
  318. }
  319. /* enable PCI arbiter */
  320. rt3883_pci_w32(rpc, 0x79, RT3883_PCI_REG_ARBCTL);
  321. }
  322. static int rt3883_pci_probe(struct platform_device *pdev)
  323. {
  324. struct rt3883_pci_controller *rpc;
  325. struct device *dev = &pdev->dev;
  326. struct device_node *np = dev->of_node;
  327. struct resource *res;
  328. struct device_node *child;
  329. u32 val;
  330. int err;
  331. int mode;
  332. rpc = devm_kzalloc(dev, sizeof(*rpc), GFP_KERNEL);
  333. if (!rpc)
  334. return -ENOMEM;
  335. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  336. rpc->base = devm_ioremap_resource(dev, res);
  337. if (IS_ERR(rpc->base))
  338. return PTR_ERR(rpc->base);
  339. /* find the interrupt controller child node */
  340. for_each_child_of_node(np, child) {
  341. if (of_get_property(child, "interrupt-controller", NULL)) {
  342. rpc->intc_of_node = child;
  343. break;
  344. }
  345. }
  346. if (!rpc->intc_of_node) {
  347. dev_err(dev, "%s has no %s child node",
  348. of_node_full_name(rpc->intc_of_node),
  349. "interrupt controller");
  350. return -EINVAL;
  351. }
  352. /* find the PCI host bridge child node */
  353. for_each_child_of_node(np, child) {
  354. if (child->type &&
  355. of_node_cmp(child->type, "pci") == 0) {
  356. rpc->pci_controller.of_node = child;
  357. break;
  358. }
  359. }
  360. if (!rpc->pci_controller.of_node) {
  361. dev_err(dev, "%s has no %s child node",
  362. of_node_full_name(rpc->intc_of_node),
  363. "PCI host bridge");
  364. err = -EINVAL;
  365. goto err_put_intc_node;
  366. }
  367. mode = RT3883_PCI_MODE_NONE;
  368. for_each_available_child_of_node(rpc->pci_controller.of_node, child) {
  369. int devfn;
  370. if (!child->type ||
  371. of_node_cmp(child->type, "pci") != 0)
  372. continue;
  373. devfn = of_pci_get_devfn(child);
  374. if (devfn < 0)
  375. continue;
  376. switch (PCI_SLOT(devfn)) {
  377. case 1:
  378. mode |= RT3883_PCI_MODE_PCIE;
  379. break;
  380. case 17:
  381. case 18:
  382. mode |= RT3883_PCI_MODE_PCI;
  383. break;
  384. }
  385. }
  386. if (mode == RT3883_PCI_MODE_NONE) {
  387. dev_err(dev, "unable to determine PCI mode\n");
  388. err = -EINVAL;
  389. goto err_put_hb_node;
  390. }
  391. dev_info(dev, "mode:%s%s\n",
  392. (mode & RT3883_PCI_MODE_PCI) ? " PCI" : "",
  393. (mode & RT3883_PCI_MODE_PCIE) ? " PCIe" : "");
  394. rt3883_pci_preinit(rpc, mode);
  395. rpc->pci_controller.pci_ops = &rt3883_pci_ops;
  396. rpc->pci_controller.io_resource = &rpc->io_res;
  397. rpc->pci_controller.mem_resource = &rpc->mem_res;
  398. /* Load PCI I/O and memory resources from DT */
  399. pci_load_of_ranges(&rpc->pci_controller,
  400. rpc->pci_controller.of_node);
  401. rt3883_pci_w32(rpc, rpc->mem_res.start, RT3883_PCI_REG_MEMBASE);
  402. rt3883_pci_w32(rpc, rpc->io_res.start, RT3883_PCI_REG_IOBASE);
  403. ioport_resource.start = rpc->io_res.start;
  404. ioport_resource.end = rpc->io_res.end;
  405. /* PCI */
  406. rt3883_pci_w32(rpc, 0x03ff0000, RT3883_PCI_REG_BAR0SETUP(0));
  407. rt3883_pci_w32(rpc, RT3883_MEMORY_BASE, RT3883_PCI_REG_IMBASEBAR0(0));
  408. rt3883_pci_w32(rpc, 0x08021814, RT3883_PCI_REG_ID(0));
  409. rt3883_pci_w32(rpc, 0x00800001, RT3883_PCI_REG_CLASS(0));
  410. rt3883_pci_w32(rpc, 0x28801814, RT3883_PCI_REG_SUBID(0));
  411. /* PCIe */
  412. rt3883_pci_w32(rpc, 0x03ff0000, RT3883_PCI_REG_BAR0SETUP(1));
  413. rt3883_pci_w32(rpc, RT3883_MEMORY_BASE, RT3883_PCI_REG_IMBASEBAR0(1));
  414. rt3883_pci_w32(rpc, 0x08021814, RT3883_PCI_REG_ID(1));
  415. rt3883_pci_w32(rpc, 0x06040001, RT3883_PCI_REG_CLASS(1));
  416. rt3883_pci_w32(rpc, 0x28801814, RT3883_PCI_REG_SUBID(1));
  417. err = rt3883_pci_irq_init(dev, rpc);
  418. if (err)
  419. goto err_put_hb_node;
  420. /* PCIe */
  421. val = rt3883_pci_read_cfg32(rpc, 0, 0x01, 0, PCI_COMMAND);
  422. val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  423. rt3883_pci_write_cfg32(rpc, 0, 0x01, 0, PCI_COMMAND, val);
  424. /* PCI */
  425. val = rt3883_pci_read_cfg32(rpc, 0, 0x00, 0, PCI_COMMAND);
  426. val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  427. rt3883_pci_write_cfg32(rpc, 0, 0x00, 0, PCI_COMMAND, val);
  428. if (mode == RT3883_PCI_MODE_PCIE) {
  429. rt3883_pci_w32(rpc, 0x03ff0001, RT3883_PCI_REG_BAR0SETUP(0));
  430. rt3883_pci_w32(rpc, 0x03ff0001, RT3883_PCI_REG_BAR0SETUP(1));
  431. rt3883_pci_write_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
  432. PCI_BASE_ADDRESS_0,
  433. RT3883_MEMORY_BASE);
  434. /* flush write */
  435. rt3883_pci_read_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
  436. PCI_BASE_ADDRESS_0);
  437. } else {
  438. rt3883_pci_write_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
  439. PCI_IO_BASE, 0x00000101);
  440. }
  441. register_pci_controller(&rpc->pci_controller);
  442. return 0;
  443. err_put_hb_node:
  444. of_node_put(rpc->pci_controller.of_node);
  445. err_put_intc_node:
  446. of_node_put(rpc->intc_of_node);
  447. return err;
  448. }
  449. int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  450. {
  451. return of_irq_parse_and_map_pci(dev, slot, pin);
  452. }
  453. int pcibios_plat_dev_init(struct pci_dev *dev)
  454. {
  455. return 0;
  456. }
  457. static const struct of_device_id rt3883_pci_ids[] = {
  458. { .compatible = "ralink,rt3883-pci" },
  459. {},
  460. };
  461. static struct platform_driver rt3883_pci_driver = {
  462. .probe = rt3883_pci_probe,
  463. .driver = {
  464. .name = "rt3883-pci",
  465. .of_match_table = of_match_ptr(rt3883_pci_ids),
  466. },
  467. };
  468. static int __init rt3883_pci_init(void)
  469. {
  470. return platform_driver_register(&rt3883_pci_driver);
  471. }
  472. postcore_initcall(rt3883_pci_init);