pci-rt3883.c 15 KB

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