1 From patchwork Fri Aug 23 12:03:20 2013
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
5 Subject: [v3] MIPS: add driver for the built-in PCI controller of the RT3883
7 From: Gabor Juhos <juhosg@openwrt.org>
9 Message-Id: <1377259400-21211-1-git-send-email-juhosg@openwrt.org>
10 To: Ralf Baechle <ralf@linux-mips.org>
11 Cc: linux-mips@linux-mips.org, Gabor Juhos <juhosg@openwrt.org>,
12 devicetree@vger.kernel.org
13 Date: Fri, 23 Aug 2013 14:03:20 +0200
15 The Ralink RT3883 SoCs have a built-in PCI Host Controller
16 device. The patch adds a platform driver and device tree
17 binding documentation for that.
19 The patch also enables the HW_HAS_PCI config option. This
20 is required in order to be able to enable the PCI support.
22 Cc: devicetree@vger.kernel.org
23 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
24 Acked-by: John Crispin <blogic@openwrt.org>
28 - fix compiler warning:
30 CC arch/mips/pci/pci-rt3883.o
31 arch/mips/pci/pci-rt3883.c: In function 'rt3883_pci_probe':
32 arch/mips/pci/pci-rt3883.c:458:4: warning: use of 'h' length modifier with 'a' type character [-Wformat]
35 - change the 'status' property to optional in the binding doc
36 - add board specific example to the binding doc
38 rt3883-pci: fix-build-warning
40 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
42 .../devicetree/bindings/pci/ralink,rt3883-pci.txt | 190 ++++++
43 arch/mips/pci/Makefile | 1 +
44 arch/mips/pci/pci-rt3883.c | 636 ++++++++++++++++++++
45 arch/mips/ralink/Kconfig | 1 +
46 4 files changed, 828 insertions(+)
47 create mode 100644 Documentation/devicetree/bindings/pci/ralink,rt3883-pci.txt
48 create mode 100644 arch/mips/pci/pci-rt3883.c
51 +++ b/Documentation/devicetree/bindings/pci/ralink,rt3883-pci.txt
53 +* Mediatek/Ralink RT3883 PCI controller
57 + Required properties:
59 + - compatible: must be "ralink,rt3883-pci"
61 + - reg: specifies the physical base address of the controller and
62 + the length of the memory mapped region.
64 + - #address-cells: specifies the number of cells needed to encode an
65 + address. The value must be 1.
67 + - #size-cells: specifies the number of cells used to represent the size
68 + of an address. The value must be 1.
70 + - ranges: specifies the translation between child address space and parent
73 + Optional properties:
75 + - status: indicates the operational status of the device.
76 + Value must be either "disabled" or "okay".
80 + The main node must have two child nodes which describes the built-in
81 + interrupt controller and the PCI host bridge.
83 + a) Interrupt controller:
85 + Required properties:
87 + - interrupt-controller: identifies the node as an interrupt controller
89 + - #address-cells: specifies the number of cells needed to encode an
90 + address. The value must be 0. As such, 'interrupt-map' nodes do not
91 + have to specify a parent unit address.
93 + - #interrupt-cells: specifies the number of cells needed to encode an
94 + interrupt source. The value must be 1.
96 + - interrupt-parent: the phandle for the interrupt controller that
97 + services interrupts for this device.
99 + - interrupts: specifies the interrupt source of the parent interrupt
100 + controller. The format of the interrupt specifier depends on the
101 + parent interrupt controller.
103 + b) PCI host bridge:
105 + Required properties:
107 + - #address-cells: specifies the number of cells needed to encode an
108 + address. The value must be 0.
110 + - #size-cells: specifies the number of cells used to represent the size
111 + of an address. The value must be 2.
113 + - #interrupt-cells: specifies the number of cells needed to encode an
114 + interrupt source. The value must be 1.
116 + - device_type: must be "pci"
118 + - bus-range: PCI bus numbers covered
120 + - ranges: specifies the ranges for the PCI memory and I/O regions
122 + - interrupt-map-mask,
123 + - interrupt-map: standard PCI properties to define the mapping of the
124 + PCI interface to interrupt numbers.
126 + The PCI host bridge node migh have additional sub-nodes representing
127 + the onboard PCI devices/PCI slots. Each such sub-node must have the
128 + following mandatory properties:
130 + - reg: used only for interrupt mapping, so only the first four bytes
131 + are used to refer to the correct bus number and device number.
133 + - device_type: must be "pci"
135 + If a given sub-node represents a PCI bridge it must have following
136 + mandatory properties as well:
138 + - #address-cells: must be set to <3>
140 + - #size-cells: must set to <2>
142 + - #interrupt-cells: must be set to <1>
144 + - interrupt-map-mask,
145 + - interrupt-map: standard PCI properties to define the mapping of the
146 + PCI interface to interrupt numbers.
148 + Besides the required properties the sub-nodes may have these optional
151 + - status: indicates the operational status of the sub-node.
152 + Value must be either "disabled" or "okay".
156 + a) SoC specific dtsi file:
159 + compatible = "ralink,rt3883-pci";
160 + reg = <0x10140000 0x20000>;
161 + #address-cells = <1>;
163 + ranges; /* direct mapping */
165 + status = "disabled";
167 + pciintc: interrupt-controller {
168 + interrupt-controller;
169 + #address-cells = <0>;
170 + #interrupt-cells = <1>;
172 + interrupt-parent = <&cpuintc>;
177 + #address-cells = <3>;
179 + #interrupt-cells = <1>;
181 + device_type = "pci";
183 + bus-range = <0 255>;
185 + 0x02000000 0 0x00000000 0x20000000 0 0x10000000 /* pci memory */
186 + 0x01000000 0 0x00000000 0x10160000 0 0x00010000 /* io space */
189 + interrupt-map-mask = <0xf800 0 0 7>;
192 + 0x8800 0 0 1 &pciintc 18
193 + 0x8800 0 0 2 &pciintc 18
194 + 0x8800 0 0 3 &pciintc 18
195 + 0x8800 0 0 4 &pciintc 18
197 + 0x9000 0 0 1 &pciintc 19
198 + 0x9000 0 0 2 &pciintc 19
199 + 0x9000 0 0 3 &pciintc 19
200 + 0x9000 0 0 4 &pciintc 19
204 + reg = <0x0800 0 0 0 0>;
205 + device_type = "pci";
206 + #interrupt-cells = <1>;
207 + #address-cells = <3>;
210 + interrupt-map-mask = <0x0 0 0 0>;
211 + interrupt-map = <0x0 0 0 0 &pciintc 20>;
213 + status = "disabled";
217 + reg = <0x8800 0 0 0 0>;
218 + device_type = "pci";
220 + status = "disabled";
224 + reg = <0x9000 0 0 0 0>;
225 + device_type = "pci";
227 + status = "disabled";
232 + b) Board specific dts file:
243 --- a/arch/mips/pci/Makefile
244 +++ b/arch/mips/pci/Makefile
245 @@ -41,6 +41,7 @@ obj-$(CONFIG_SIBYTE_BCM1x80) += pci-bcm1
246 obj-$(CONFIG_SNI_RM) += fixup-sni.o ops-sni.o
247 obj-$(CONFIG_LANTIQ) += fixup-lantiq.o
248 obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o ops-lantiq.o
249 +obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
250 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
251 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
252 obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
254 +++ b/arch/mips/pci/pci-rt3883.c
257 + * Ralink RT3662/RT3883 SoC PCI support
259 + * Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org>
261 + * Parts of this file are based on Ralink's 2.6.21 BSP
263 + * This program is free software; you can redistribute it and/or modify it
264 + * under the terms of the GNU General Public License version 2 as published
265 + * by the Free Software Foundation.
268 +#include <linux/types.h>
269 +#include <linux/pci.h>
270 +#include <linux/io.h>
271 +#include <linux/init.h>
272 +#include <linux/delay.h>
273 +#include <linux/interrupt.h>
274 +#include <linux/module.h>
275 +#include <linux/of.h>
276 +#include <linux/of_irq.h>
277 +#include <linux/of_pci.h>
278 +#include <linux/platform_device.h>
280 +#include <asm/mach-ralink/rt3883.h>
281 +#include <asm/mach-ralink/ralink_regs.h>
283 +#define RT3883_MEMORY_BASE 0x00000000
284 +#define RT3883_MEMORY_SIZE 0x02000000
286 +#define RT3883_PCI_REG_PCICFG 0x00
287 +#define RT3883_PCICFG_P2P_BR_DEVNUM_M 0xf
288 +#define RT3883_PCICFG_P2P_BR_DEVNUM_S 16
289 +#define RT3883_PCICFG_PCIRST BIT(1)
290 +#define RT3883_PCI_REG_PCIRAW 0x04
291 +#define RT3883_PCI_REG_PCIINT 0x08
292 +#define RT3883_PCI_REG_PCIENA 0x0c
294 +#define RT3883_PCI_REG_CFGADDR 0x20
295 +#define RT3883_PCI_REG_CFGDATA 0x24
296 +#define RT3883_PCI_REG_MEMBASE 0x28
297 +#define RT3883_PCI_REG_IOBASE 0x2c
298 +#define RT3883_PCI_REG_ARBCTL 0x80
300 +#define RT3883_PCI_REG_BASE(_x) (0x1000 + (_x) * 0x1000)
301 +#define RT3883_PCI_REG_BAR0SETUP(_x) (RT3883_PCI_REG_BASE((_x)) + 0x10)
302 +#define RT3883_PCI_REG_IMBASEBAR0(_x) (RT3883_PCI_REG_BASE((_x)) + 0x18)
303 +#define RT3883_PCI_REG_ID(_x) (RT3883_PCI_REG_BASE((_x)) + 0x30)
304 +#define RT3883_PCI_REG_CLASS(_x) (RT3883_PCI_REG_BASE((_x)) + 0x34)
305 +#define RT3883_PCI_REG_SUBID(_x) (RT3883_PCI_REG_BASE((_x)) + 0x38)
306 +#define RT3883_PCI_REG_STATUS(_x) (RT3883_PCI_REG_BASE((_x)) + 0x50)
308 +#define RT3883_PCI_MODE_NONE 0
309 +#define RT3883_PCI_MODE_PCI BIT(0)
310 +#define RT3883_PCI_MODE_PCIE BIT(1)
311 +#define RT3883_PCI_MODE_BOTH (RT3883_PCI_MODE_PCI | RT3883_PCI_MODE_PCIE)
313 +#define RT3883_PCI_IRQ_COUNT 32
315 +#define RT3883_P2P_BR_DEVNUM 1
317 +struct rt3883_pci_controller {
318 + void __iomem *base;
321 + struct device_node *intc_of_node;
322 + struct irq_domain *irq_domain;
324 + struct pci_controller pci_controller;
325 + struct resource io_res;
326 + struct resource mem_res;
331 +static inline struct rt3883_pci_controller *
332 +pci_bus_to_rt3883_controller(struct pci_bus *bus)
334 + struct pci_controller *hose;
336 + hose = (struct pci_controller *) bus->sysdata;
337 + return container_of(hose, struct rt3883_pci_controller, pci_controller);
340 +static inline u32 rt3883_pci_r32(struct rt3883_pci_controller *rpc,
343 + return ioread32(rpc->base + reg);
346 +static inline void rt3883_pci_w32(struct rt3883_pci_controller *rpc,
347 + u32 val, unsigned reg)
349 + iowrite32(val, rpc->base + reg);
352 +static inline u32 rt3883_pci_get_cfgaddr(unsigned int bus, unsigned int slot,
353 + unsigned int func, unsigned int where)
355 + return (bus << 16) | (slot << 11) | (func << 8) | (where & 0xfc) |
359 +static u32 rt3883_pci_read_cfg32(struct rt3883_pci_controller *rpc,
360 + unsigned bus, unsigned slot,
361 + unsigned func, unsigned reg)
363 + unsigned long flags;
367 + address = rt3883_pci_get_cfgaddr(bus, slot, func, reg);
369 + spin_lock_irqsave(&rpc->lock, flags);
370 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
371 + ret = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
372 + spin_unlock_irqrestore(&rpc->lock, flags);
377 +static void rt3883_pci_write_cfg32(struct rt3883_pci_controller *rpc,
378 + unsigned bus, unsigned slot,
379 + unsigned func, unsigned reg, u32 val)
381 + unsigned long flags;
384 + address = rt3883_pci_get_cfgaddr(bus, slot, func, reg);
386 + spin_lock_irqsave(&rpc->lock, flags);
387 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
388 + rt3883_pci_w32(rpc, val, RT3883_PCI_REG_CFGDATA);
389 + spin_unlock_irqrestore(&rpc->lock, flags);
392 +static void rt3883_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
394 + struct rt3883_pci_controller *rpc;
397 + rpc = irq_get_handler_data(irq);
399 + pending = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIINT) &
400 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
403 + spurious_interrupt();
408 + unsigned bit = __ffs(pending);
410 + irq = irq_find_mapping(rpc->irq_domain, bit);
411 + generic_handle_irq(irq);
413 + pending &= ~BIT(bit);
417 +static void rt3883_pci_irq_unmask(struct irq_data *d)
419 + struct rt3883_pci_controller *rpc;
422 + rpc = irq_data_get_irq_chip_data(d);
424 + t = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
425 + rt3883_pci_w32(rpc, t | BIT(d->hwirq), RT3883_PCI_REG_PCIENA);
427 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
430 +static void rt3883_pci_irq_mask(struct irq_data *d)
432 + struct rt3883_pci_controller *rpc;
435 + rpc = irq_data_get_irq_chip_data(d);
437 + t = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
438 + rt3883_pci_w32(rpc, t & ~BIT(d->hwirq), RT3883_PCI_REG_PCIENA);
440 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
443 +static struct irq_chip rt3883_pci_irq_chip = {
444 + .name = "RT3883 PCI",
445 + .irq_mask = rt3883_pci_irq_mask,
446 + .irq_unmask = rt3883_pci_irq_unmask,
447 + .irq_mask_ack = rt3883_pci_irq_mask,
450 +static int rt3883_pci_irq_map(struct irq_domain *d, unsigned int irq,
451 + irq_hw_number_t hw)
453 + irq_set_chip_and_handler(irq, &rt3883_pci_irq_chip, handle_level_irq);
454 + irq_set_chip_data(irq, d->host_data);
459 +static const struct irq_domain_ops rt3883_pci_irq_domain_ops = {
460 + .map = rt3883_pci_irq_map,
461 + .xlate = irq_domain_xlate_onecell,
464 +static int rt3883_pci_irq_init(struct device *dev,
465 + struct rt3883_pci_controller *rpc)
469 + irq = irq_of_parse_and_map(rpc->intc_of_node, 0);
471 + dev_err(dev, "%s has no IRQ",
472 + of_node_full_name(rpc->intc_of_node));
476 + /* disable all interrupts */
477 + rt3883_pci_w32(rpc, 0, RT3883_PCI_REG_PCIENA);
480 + irq_domain_add_linear(rpc->intc_of_node, RT3883_PCI_IRQ_COUNT,
481 + &rt3883_pci_irq_domain_ops,
483 + if (!rpc->irq_domain) {
484 + dev_err(dev, "unable to add IRQ domain\n");
488 + irq_set_handler_data(irq, rpc);
489 + irq_set_chained_handler(irq, rt3883_pci_irq_handler);
494 +static int rt3883_pci_config_read(struct pci_bus *bus, unsigned int devfn,
495 + int where, int size, u32 *val)
497 + struct rt3883_pci_controller *rpc;
498 + unsigned long flags;
502 + rpc = pci_bus_to_rt3883_controller(bus);
504 + if (!rpc->pcie_ready && bus->number == 1)
505 + return PCIBIOS_DEVICE_NOT_FOUND;
507 + address = rt3883_pci_get_cfgaddr(bus->number, PCI_SLOT(devfn),
508 + PCI_FUNC(devfn), where);
510 + spin_lock_irqsave(&rpc->lock, flags);
511 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
512 + data = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
513 + spin_unlock_irqrestore(&rpc->lock, flags);
517 + *val = (data >> ((where & 3) << 3)) & 0xff;
520 + *val = (data >> ((where & 3) << 3)) & 0xffff;
527 + return PCIBIOS_SUCCESSFUL;
530 +static int rt3883_pci_config_write(struct pci_bus *bus, unsigned int devfn,
531 + int where, int size, u32 val)
533 + struct rt3883_pci_controller *rpc;
534 + unsigned long flags;
538 + rpc = pci_bus_to_rt3883_controller(bus);
540 + if (!rpc->pcie_ready && bus->number == 1)
541 + return PCIBIOS_DEVICE_NOT_FOUND;
543 + address = rt3883_pci_get_cfgaddr(bus->number, PCI_SLOT(devfn),
544 + PCI_FUNC(devfn), where);
546 + spin_lock_irqsave(&rpc->lock, flags);
547 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
548 + data = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
552 + data = (data & ~(0xff << ((where & 3) << 3))) |
553 + (val << ((where & 3) << 3));
556 + data = (data & ~(0xffff << ((where & 3) << 3))) |
557 + (val << ((where & 3) << 3));
564 + rt3883_pci_w32(rpc, data, RT3883_PCI_REG_CFGDATA);
565 + spin_unlock_irqrestore(&rpc->lock, flags);
567 + return PCIBIOS_SUCCESSFUL;
570 +static struct pci_ops rt3883_pci_ops = {
571 + .read = rt3883_pci_config_read,
572 + .write = rt3883_pci_config_write,
575 +static void rt3883_pci_preinit(struct rt3883_pci_controller *rpc, unsigned mode)
582 + rstctrl = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
583 + syscfg1 = rt_sysc_r32(RT3883_SYSC_REG_SYSCFG1);
584 + clkcfg1 = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
586 + if (mode & RT3883_PCI_MODE_PCIE) {
587 + rstctrl |= RT3883_RSTCTRL_PCIE;
588 + rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
590 + /* setup PCI PAD drive mode */
591 + syscfg1 &= ~(0x30);
592 + syscfg1 |= (2 << 4);
593 + rt_sysc_w32(syscfg1, RT3883_SYSC_REG_SYSCFG1);
595 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
597 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
599 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN1);
601 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN1);
603 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN1);
605 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN1);
607 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
609 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
613 + rstctrl &= ~RT3883_RSTCTRL_PCIE;
614 + rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
617 + syscfg1 |= (RT3883_SYSCFG1_PCIE_RC_MODE | RT3883_SYSCFG1_PCI_HOST_MODE);
619 + clkcfg1 &= ~(RT3883_CLKCFG1_PCI_CLK_EN | RT3883_CLKCFG1_PCIE_CLK_EN);
621 + if (mode & RT3883_PCI_MODE_PCI) {
622 + clkcfg1 |= RT3883_CLKCFG1_PCI_CLK_EN;
623 + rstctrl &= ~RT3883_RSTCTRL_PCI;
626 + if (mode & RT3883_PCI_MODE_PCIE) {
627 + clkcfg1 |= RT3883_CLKCFG1_PCIE_CLK_EN;
628 + rstctrl &= ~RT3883_RSTCTRL_PCIE;
631 + rt_sysc_w32(syscfg1, RT3883_SYSC_REG_SYSCFG1);
632 + rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
633 + rt_sysc_w32(clkcfg1, RT3883_SYSC_REG_CLKCFG1);
638 + * setup the device number of the P2P bridge
639 + * and de-assert the reset line
641 + t = (RT3883_P2P_BR_DEVNUM << RT3883_PCICFG_P2P_BR_DEVNUM_S);
642 + rt3883_pci_w32(rpc, t, RT3883_PCI_REG_PCICFG);
645 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCICFG);
648 + if (mode & RT3883_PCI_MODE_PCIE) {
651 + t = rt3883_pci_r32(rpc, RT3883_PCI_REG_STATUS(1));
653 + rpc->pcie_ready = t & BIT(0);
655 + if (!rpc->pcie_ready) {
656 + /* reset the PCIe block */
657 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
658 + t |= RT3883_RSTCTRL_PCIE;
659 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
660 + t &= ~RT3883_RSTCTRL_PCIE;
661 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
663 + /* turn off PCIe clock */
664 + t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
665 + t &= ~RT3883_CLKCFG1_PCIE_CLK_EN;
666 + rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
668 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
670 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
674 + /* enable PCI arbiter */
675 + rt3883_pci_w32(rpc, 0x79, RT3883_PCI_REG_ARBCTL);
678 +static int rt3883_pci_probe(struct platform_device *pdev)
680 + struct rt3883_pci_controller *rpc;
681 + struct device *dev = &pdev->dev;
682 + struct device_node *np = dev->of_node;
683 + struct resource *res;
684 + struct device_node *child;
689 + rpc = devm_kzalloc(dev, sizeof(*rpc), GFP_KERNEL);
693 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
697 + rpc->base = devm_ioremap_resource(dev, res);
698 + if (IS_ERR(rpc->base))
699 + return PTR_ERR(rpc->base);
701 + /* find the interrupt controller child node */
702 + for_each_child_of_node(np, child) {
703 + if (of_get_property(child, "interrupt-controller", NULL) &&
704 + of_node_get(child)) {
705 + rpc->intc_of_node = child;
710 + if (!rpc->intc_of_node) {
711 + dev_err(dev, "%s has no %s child node",
712 + of_node_full_name(rpc->intc_of_node),
713 + "interrupt controller");
717 + /* find the PCI host bridge child node */
718 + for_each_child_of_node(np, child) {
720 + of_node_cmp(child->type, "pci") == 0 &&
721 + of_node_get(child)) {
722 + rpc->pci_controller.of_node = child;
727 + if (!rpc->pci_controller.of_node) {
728 + dev_err(dev, "%s has no %s child node",
729 + of_node_full_name(rpc->intc_of_node),
730 + "PCI host bridge");
732 + goto err_put_intc_node;
735 + mode = RT3883_PCI_MODE_NONE;
736 + for_each_available_child_of_node(rpc->pci_controller.of_node, child) {
739 + if (!child->type ||
740 + of_node_cmp(child->type, "pci") != 0)
743 + devfn = of_pci_get_devfn(child);
747 + switch (PCI_SLOT(devfn)) {
749 + mode |= RT3883_PCI_MODE_PCIE;
754 + mode |= RT3883_PCI_MODE_PCI;
759 + if (mode == RT3883_PCI_MODE_NONE) {
760 + dev_err(dev, "unable to determine PCI mode\n");
762 + goto err_put_hb_node;
765 + dev_info(dev, "mode:%s%s\n",
766 + (mode & RT3883_PCI_MODE_PCI) ? " PCI" : "",
767 + (mode & RT3883_PCI_MODE_PCIE) ? " PCIe" : "");
769 + rt3883_pci_preinit(rpc, mode);
771 + rpc->pci_controller.pci_ops = &rt3883_pci_ops;
772 + rpc->pci_controller.io_resource = &rpc->io_res;
773 + rpc->pci_controller.mem_resource = &rpc->mem_res;
775 + /* Load PCI I/O and memory resources from DT */
776 + pci_load_of_ranges(&rpc->pci_controller,
777 + rpc->pci_controller.of_node);
779 + rt3883_pci_w32(rpc, rpc->mem_res.start, RT3883_PCI_REG_MEMBASE);
780 + rt3883_pci_w32(rpc, rpc->io_res.start, RT3883_PCI_REG_IOBASE);
782 + ioport_resource.start = rpc->io_res.start;
783 + ioport_resource.end = rpc->io_res.end;
786 + rt3883_pci_w32(rpc, 0x03ff0000, RT3883_PCI_REG_BAR0SETUP(0));
787 + rt3883_pci_w32(rpc, RT3883_MEMORY_BASE, RT3883_PCI_REG_IMBASEBAR0(0));
788 + rt3883_pci_w32(rpc, 0x08021814, RT3883_PCI_REG_ID(0));
789 + rt3883_pci_w32(rpc, 0x00800001, RT3883_PCI_REG_CLASS(0));
790 + rt3883_pci_w32(rpc, 0x28801814, RT3883_PCI_REG_SUBID(0));
793 + rt3883_pci_w32(rpc, 0x03ff0000, RT3883_PCI_REG_BAR0SETUP(1));
794 + rt3883_pci_w32(rpc, RT3883_MEMORY_BASE, RT3883_PCI_REG_IMBASEBAR0(1));
795 + rt3883_pci_w32(rpc, 0x08021814, RT3883_PCI_REG_ID(1));
796 + rt3883_pci_w32(rpc, 0x06040001, RT3883_PCI_REG_CLASS(1));
797 + rt3883_pci_w32(rpc, 0x28801814, RT3883_PCI_REG_SUBID(1));
799 + err = rt3883_pci_irq_init(dev, rpc);
801 + goto err_put_hb_node;
804 + val = rt3883_pci_read_cfg32(rpc, 0, 0x01, 0, PCI_COMMAND);
805 + val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
806 + rt3883_pci_write_cfg32(rpc, 0, 0x01, 0, PCI_COMMAND, val);
809 + val = rt3883_pci_read_cfg32(rpc, 0, 0x00, 0, PCI_COMMAND);
810 + val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
811 + rt3883_pci_write_cfg32(rpc, 0, 0x00, 0, PCI_COMMAND, val);
813 + if (mode == RT3883_PCI_MODE_PCIE) {
814 + rt3883_pci_w32(rpc, 0x03ff0001, RT3883_PCI_REG_BAR0SETUP(0));
815 + rt3883_pci_w32(rpc, 0x03ff0001, RT3883_PCI_REG_BAR0SETUP(1));
817 + rt3883_pci_write_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
818 + PCI_BASE_ADDRESS_0,
819 + RT3883_MEMORY_BASE);
821 + rt3883_pci_read_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
822 + PCI_BASE_ADDRESS_0);
824 + rt3883_pci_write_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
825 + PCI_IO_BASE, 0x00000101);
828 + register_pci_controller(&rpc->pci_controller);
833 + of_node_put(rpc->pci_controller.of_node);
835 + of_node_put(rpc->intc_of_node);
839 +int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
841 + struct of_irq dev_irq;
845 + err = of_irq_map_pci(dev, &dev_irq);
847 + pr_err("pci %s: unable to get irq map, err=%d\n",
848 + pci_name((struct pci_dev *) dev), err);
852 + irq = irq_create_of_mapping(dev_irq.controller,
857 + pr_crit("pci %s: no irq found for pin %u\n",
858 + pci_name((struct pci_dev *) dev), pin);
860 + pr_info("pci %s: using irq %d for pin %u\n",
861 + pci_name((struct pci_dev *) dev), irq, pin);
866 +int pcibios_plat_dev_init(struct pci_dev *dev)
871 +static const struct of_device_id rt3883_pci_ids[] = {
872 + { .compatible = "ralink,rt3883-pci" },
875 +MODULE_DEVICE_TABLE(of, rt3883_pci_ids);
877 +static struct platform_driver rt3883_pci_driver = {
878 + .probe = rt3883_pci_probe,
880 + .name = "rt3883-pci",
881 + .owner = THIS_MODULE,
882 + .of_match_table = of_match_ptr(rt3883_pci_ids),
886 +static int __init rt3883_pci_init(void)
888 + return platform_driver_register(&rt3883_pci_driver);
891 +postcore_initcall(rt3883_pci_init);
892 --- a/arch/mips/ralink/Kconfig
893 +++ b/arch/mips/ralink/Kconfig
894 @@ -26,6 +26,7 @@ choice
896 select USB_ARCH_HAS_OHCI
897 select USB_ARCH_HAS_EHCI