1 From patchwork Fri Aug 9 16:03:32 2013
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
5 Subject: MIPS: add driver for the built-in PCI controller of the RT3883 SoC
6 From: Gabor Juhos <juhosg@openwrt.org>
8 Message-Id: <1376064212-28415-1-git-send-email-juhosg@openwrt.org>
9 To: Ralf Baechle <ralf@linux-mips.org>
10 Cc: linux-mips@linux-mips.org, John Crispin <blogic@openwrt.org>,
11 Gabor Juhos <juhosg@openwrt.org>, devicetree@vger.kernel.org
12 Date: Fri, 9 Aug 2013 18:03:32 +0200
14 The Ralink RT3883 SoCs have a built-in PCI Host Controller
15 device. The patch adds a platform driver and device tree
16 binding documentation for that.
18 The patch also enables the HW_HAS_PCI config option. This
19 is required in order to be able to enable the PCI support.
21 Cc: devicetree@vger.kernel.org
22 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
23 Acked-by: John Crispin <blogic@openwrt.org>
26 .../devicetree/bindings/pci/ralink,rt3883-pci.txt | 169 ++++++
27 arch/mips/pci/Makefile | 1 +
28 arch/mips/pci/pci-rt3883.c | 636 ++++++++++++++++++++
29 arch/mips/ralink/Kconfig | 1 +
30 4 files changed, 807 insertions(+)
31 create mode 100644 Documentation/devicetree/bindings/pci/ralink,rt3883-pci.txt
32 create mode 100644 arch/mips/pci/pci-rt3883.c
35 +++ b/Documentation/devicetree/bindings/pci/ralink,rt3883-pci.txt
37 +* Mediatek/Ralink RT3883 PCI controller
41 + Required properties:
43 + - compatible: must be "ralink,rt3883-pci"
45 + - reg: specifies the physical base address of the controller and
46 + the length of the memory mapped region.
48 + - #address-cells: specifies the number of cells needed to encode an
49 + address. The value must be 1.
51 + - #size-cells: specifies the number of cells used to represent the size
52 + of an address. The value must be 1.
54 + - ranges: specifies the translation between child address space and parent
57 + - status: either "disabled" or "okay"
61 + The main node must have two child nodes which describes the built-in
62 + interrupt controller and the PCI host bridge.
64 + a) Interrupt controller:
66 + Required properties:
68 + - interrupt-controller: identifies the node as an interrupt controller
70 + - #address-cells: specifies the number of cells needed to encode an
71 + address. The value must be 0. As such, 'interrupt-map' nodes do not
72 + have to specify a parent unit address.
74 + - #interrupt-cells: specifies the number of cells needed to encode an
75 + interrupt source. The value must be 1.
77 + - interrupt-parent: the phandle for the interrupt controller that
78 + services interrupts for this device.
80 + - interrupts: specifies the interrupt source of the parent interrupt
81 + controller. The format of the interrupt specifier depends on the
82 + parent interrupt controller.
86 + Required properties:
88 + - #address-cells: specifies the number of cells needed to encode an
89 + address. The value must be 0.
91 + - #size-cells: specifies the number of cells used to represent the size
92 + of an address. The value must be 2.
94 + - #interrupt-cells: specifies the number of cells needed to encode an
95 + interrupt source. The value must be 1.
97 + - device_type: must be "pci"
99 + - bus-range: PCI bus numbers covered
101 + - ranges: specifies the ranges for the PCI memory and I/O regions
103 + - interrupt-map-mask,
104 + - interrupt-map: standard PCI properties to define the mapping of the
105 + PCI interface to interrupt numbers.
107 + The PCI host bridge node migh have additional sub-nodes representing
108 + the onboard PCI devices/PCI slots. Each such sub-node must have the
109 + following mandatory properties:
111 + - reg: used only for interrupt mapping, so only the first four bytes
112 + are used to refer to the correct bus number and device number.
114 + - device_type: must be "pci"
116 + - status: either "disabled" or "okay"
118 + If a given sub-node represents a PCI bridge it must have following
119 + mandatory properties as well:
121 + - #address-cells: must be set to <3>
123 + - #size-cells: must set to <2>
125 + - #interrupt-cells: must be set to <1>
127 + - interrupt-map-mask,
128 + - interrupt-map: standard PCI properties to define the mapping of the
129 + PCI interface to interrupt numbers.
134 + compatible = "ralink,rt3883-pci";
135 + reg = <0x10140000 0x20000>;
136 + #address-cells = <1>;
138 + ranges; /* direct mapping */
140 + status = "disabled";
142 + pciintc: interrupt-controller {
143 + interrupt-controller;
144 + #address-cells = <0>;
145 + #interrupt-cells = <1>;
147 + interrupt-parent = <&cpuintc>;
152 + #address-cells = <3>;
154 + #interrupt-cells = <1>;
156 + device_type = "pci";
158 + bus-range = <0 255>;
160 + 0x02000000 0 0x00000000 0x20000000 0 0x10000000 /* pci memory */
161 + 0x01000000 0 0x00000000 0x10160000 0 0x00010000 /* io space */
164 + interrupt-map-mask = <0xf800 0 0 7>;
167 + 0x8800 0 0 1 &pciintc 18
168 + 0x8800 0 0 2 &pciintc 18
169 + 0x8800 0 0 3 &pciintc 18
170 + 0x8800 0 0 4 &pciintc 18
172 + 0x9000 0 0 1 &pciintc 19
173 + 0x9000 0 0 2 &pciintc 19
174 + 0x9000 0 0 3 &pciintc 19
175 + 0x9000 0 0 4 &pciintc 19
179 + reg = <0x0800 0 0 0 0>;
180 + device_type = "pci";
181 + #interrupt-cells = <1>;
182 + #address-cells = <3>;
185 + interrupt-map-mask = <0x0 0 0 0>;
186 + interrupt-map = <0x0 0 0 0 &pciintc 20>;
188 + status = "disabled";
192 + reg = <0x8800 0 0 0 0>;
193 + device_type = "pci";
195 + status = "disabled";
199 + reg = <0x9000 0 0 0 0>;
200 + device_type = "pci";
202 + status = "disabled";
206 --- a/arch/mips/pci/Makefile
207 +++ b/arch/mips/pci/Makefile
208 @@ -41,6 +41,7 @@ obj-$(CONFIG_SIBYTE_BCM1x80) += pci-bcm1
209 obj-$(CONFIG_SNI_RM) += fixup-sni.o ops-sni.o
210 obj-$(CONFIG_LANTIQ) += fixup-lantiq.o
211 obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o ops-lantiq.o
212 +obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
213 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
214 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
215 obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
217 +++ b/arch/mips/pci/pci-rt3883.c
220 + * Ralink RT3662/RT3883 SoC PCI support
222 + * Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org>
224 + * Parts of this file are based on Ralink's 2.6.21 BSP
226 + * This program is free software; you can redistribute it and/or modify it
227 + * under the terms of the GNU General Public License version 2 as published
228 + * by the Free Software Foundation.
231 +#include <linux/types.h>
232 +#include <linux/pci.h>
233 +#include <linux/io.h>
234 +#include <linux/init.h>
235 +#include <linux/delay.h>
236 +#include <linux/interrupt.h>
237 +#include <linux/module.h>
238 +#include <linux/of.h>
239 +#include <linux/of_irq.h>
240 +#include <linux/of_pci.h>
241 +#include <linux/platform_device.h>
243 +#include <asm/mach-ralink/rt3883.h>
244 +#include <asm/mach-ralink/ralink_regs.h>
246 +#define RT3883_MEMORY_BASE 0x00000000
247 +#define RT3883_MEMORY_SIZE 0x02000000
249 +#define RT3883_PCI_REG_PCICFG 0x00
250 +#define RT3883_PCICFG_P2P_BR_DEVNUM_M 0xf
251 +#define RT3883_PCICFG_P2P_BR_DEVNUM_S 16
252 +#define RT3883_PCICFG_PCIRST BIT(1)
253 +#define RT3883_PCI_REG_PCIRAW 0x04
254 +#define RT3883_PCI_REG_PCIINT 0x08
255 +#define RT3883_PCI_REG_PCIENA 0x0c
257 +#define RT3883_PCI_REG_CFGADDR 0x20
258 +#define RT3883_PCI_REG_CFGDATA 0x24
259 +#define RT3883_PCI_REG_MEMBASE 0x28
260 +#define RT3883_PCI_REG_IOBASE 0x2c
261 +#define RT3883_PCI_REG_ARBCTL 0x80
263 +#define RT3883_PCI_REG_BASE(_x) (0x1000 + (_x) * 0x1000)
264 +#define RT3883_PCI_REG_BAR0SETUP(_x) (RT3883_PCI_REG_BASE((_x)) + 0x10)
265 +#define RT3883_PCI_REG_IMBASEBAR0(_x) (RT3883_PCI_REG_BASE((_x)) + 0x18)
266 +#define RT3883_PCI_REG_ID(_x) (RT3883_PCI_REG_BASE((_x)) + 0x30)
267 +#define RT3883_PCI_REG_CLASS(_x) (RT3883_PCI_REG_BASE((_x)) + 0x34)
268 +#define RT3883_PCI_REG_SUBID(_x) (RT3883_PCI_REG_BASE((_x)) + 0x38)
269 +#define RT3883_PCI_REG_STATUS(_x) (RT3883_PCI_REG_BASE((_x)) + 0x50)
271 +#define RT3883_PCI_MODE_NONE 0
272 +#define RT3883_PCI_MODE_PCI BIT(0)
273 +#define RT3883_PCI_MODE_PCIE BIT(1)
274 +#define RT3883_PCI_MODE_BOTH (RT3883_PCI_MODE_PCI | RT3883_PCI_MODE_PCIE)
276 +#define RT3883_PCI_IRQ_COUNT 32
278 +#define RT3883_P2P_BR_DEVNUM 1
280 +struct rt3883_pci_controller {
281 + void __iomem *base;
284 + struct device_node *intc_of_node;
285 + struct irq_domain *irq_domain;
287 + struct pci_controller pci_controller;
288 + struct resource io_res;
289 + struct resource mem_res;
294 +static inline struct rt3883_pci_controller *
295 +pci_bus_to_rt3883_controller(struct pci_bus *bus)
297 + struct pci_controller *hose;
299 + hose = (struct pci_controller *) bus->sysdata;
300 + return container_of(hose, struct rt3883_pci_controller, pci_controller);
303 +static inline u32 rt3883_pci_r32(struct rt3883_pci_controller *rpc,
306 + return ioread32(rpc->base + reg);
309 +static inline void rt3883_pci_w32(struct rt3883_pci_controller *rpc,
310 + u32 val, unsigned reg)
312 + iowrite32(val, rpc->base + reg);
315 +static inline u32 rt3883_pci_get_cfgaddr(unsigned int bus, unsigned int slot,
316 + unsigned int func, unsigned int where)
318 + return (bus << 16) | (slot << 11) | (func << 8) | (where & 0xfc) |
322 +static u32 rt3883_pci_read_cfg32(struct rt3883_pci_controller *rpc,
323 + unsigned bus, unsigned slot,
324 + unsigned func, unsigned reg)
326 + unsigned long flags;
330 + address = rt3883_pci_get_cfgaddr(bus, slot, func, reg);
332 + spin_lock_irqsave(&rpc->lock, flags);
333 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
334 + ret = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
335 + spin_unlock_irqrestore(&rpc->lock, flags);
340 +static void rt3883_pci_write_cfg32(struct rt3883_pci_controller *rpc,
341 + unsigned bus, unsigned slot,
342 + unsigned func, unsigned reg, u32 val)
344 + unsigned long flags;
347 + address = rt3883_pci_get_cfgaddr(bus, slot, func, reg);
349 + spin_lock_irqsave(&rpc->lock, flags);
350 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
351 + rt3883_pci_w32(rpc, val, RT3883_PCI_REG_CFGDATA);
352 + spin_unlock_irqrestore(&rpc->lock, flags);
355 +static void rt3883_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
357 + struct rt3883_pci_controller *rpc;
360 + rpc = irq_get_handler_data(irq);
362 + pending = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIINT) &
363 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
366 + spurious_interrupt();
371 + unsigned bit = __ffs(pending);
373 + irq = irq_find_mapping(rpc->irq_domain, bit);
374 + generic_handle_irq(irq);
376 + pending &= ~BIT(bit);
380 +static void rt3883_pci_irq_unmask(struct irq_data *d)
382 + struct rt3883_pci_controller *rpc;
385 + rpc = irq_data_get_irq_chip_data(d);
387 + t = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
388 + rt3883_pci_w32(rpc, t | BIT(d->hwirq), RT3883_PCI_REG_PCIENA);
390 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
393 +static void rt3883_pci_irq_mask(struct irq_data *d)
395 + struct rt3883_pci_controller *rpc;
398 + rpc = irq_data_get_irq_chip_data(d);
400 + t = rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
401 + rt3883_pci_w32(rpc, t & ~BIT(d->hwirq), RT3883_PCI_REG_PCIENA);
403 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCIENA);
406 +static struct irq_chip rt3883_pci_irq_chip = {
407 + .name = "RT3883 PCI",
408 + .irq_mask = rt3883_pci_irq_mask,
409 + .irq_unmask = rt3883_pci_irq_unmask,
410 + .irq_mask_ack = rt3883_pci_irq_mask,
413 +static int rt3883_pci_irq_map(struct irq_domain *d, unsigned int irq,
414 + irq_hw_number_t hw)
416 + irq_set_chip_and_handler(irq, &rt3883_pci_irq_chip, handle_level_irq);
417 + irq_set_chip_data(irq, d->host_data);
422 +static const struct irq_domain_ops rt3883_pci_irq_domain_ops = {
423 + .map = rt3883_pci_irq_map,
424 + .xlate = irq_domain_xlate_onecell,
427 +static int rt3883_pci_irq_init(struct device *dev,
428 + struct rt3883_pci_controller *rpc)
432 + irq = irq_of_parse_and_map(rpc->intc_of_node, 0);
434 + dev_err(dev, "%s has no IRQ",
435 + of_node_full_name(rpc->intc_of_node));
439 + /* disable all interrupts */
440 + rt3883_pci_w32(rpc, 0, RT3883_PCI_REG_PCIENA);
443 + irq_domain_add_linear(rpc->intc_of_node, RT3883_PCI_IRQ_COUNT,
444 + &rt3883_pci_irq_domain_ops,
446 + if (!rpc->irq_domain) {
447 + dev_err(dev, "unable to add IRQ domain\n");
451 + irq_set_handler_data(irq, rpc);
452 + irq_set_chained_handler(irq, rt3883_pci_irq_handler);
457 +static int rt3883_pci_config_read(struct pci_bus *bus, unsigned int devfn,
458 + int where, int size, u32 *val)
460 + struct rt3883_pci_controller *rpc;
461 + unsigned long flags;
465 + rpc = pci_bus_to_rt3883_controller(bus);
467 + if (!rpc->pcie_ready && bus->number == 1)
468 + return PCIBIOS_DEVICE_NOT_FOUND;
470 + address = rt3883_pci_get_cfgaddr(bus->number, PCI_SLOT(devfn),
471 + PCI_FUNC(devfn), where);
473 + spin_lock_irqsave(&rpc->lock, flags);
474 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
475 + data = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
476 + spin_unlock_irqrestore(&rpc->lock, flags);
480 + *val = (data >> ((where & 3) << 3)) & 0xff;
483 + *val = (data >> ((where & 3) << 3)) & 0xffff;
490 + return PCIBIOS_SUCCESSFUL;
493 +static int rt3883_pci_config_write(struct pci_bus *bus, unsigned int devfn,
494 + int where, int size, u32 val)
496 + struct rt3883_pci_controller *rpc;
497 + unsigned long flags;
501 + rpc = pci_bus_to_rt3883_controller(bus);
503 + if (!rpc->pcie_ready && bus->number == 1)
504 + return PCIBIOS_DEVICE_NOT_FOUND;
506 + address = rt3883_pci_get_cfgaddr(bus->number, PCI_SLOT(devfn),
507 + PCI_FUNC(devfn), where);
509 + spin_lock_irqsave(&rpc->lock, flags);
510 + rt3883_pci_w32(rpc, address, RT3883_PCI_REG_CFGADDR);
511 + data = rt3883_pci_r32(rpc, RT3883_PCI_REG_CFGDATA);
515 + data = (data & ~(0xff << ((where & 3) << 3))) |
516 + (val << ((where & 3) << 3));
519 + data = (data & ~(0xffff << ((where & 3) << 3))) |
520 + (val << ((where & 3) << 3));
527 + rt3883_pci_w32(rpc, data, RT3883_PCI_REG_CFGDATA);
528 + spin_unlock_irqrestore(&rpc->lock, flags);
530 + return PCIBIOS_SUCCESSFUL;
533 +static struct pci_ops rt3883_pci_ops = {
534 + .read = rt3883_pci_config_read,
535 + .write = rt3883_pci_config_write,
538 +static void rt3883_pci_preinit(struct rt3883_pci_controller *rpc, unsigned mode)
545 + rstctrl = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
546 + syscfg1 = rt_sysc_r32(RT3883_SYSC_REG_SYSCFG1);
547 + clkcfg1 = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
549 + if (mode & RT3883_PCI_MODE_PCIE) {
550 + rstctrl |= RT3883_RSTCTRL_PCIE;
551 + rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
553 + /* setup PCI PAD drive mode */
554 + syscfg1 &= ~(0x30);
555 + syscfg1 |= (2 << 4);
556 + rt_sysc_w32(syscfg1, RT3883_SYSC_REG_SYSCFG1);
558 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
560 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
562 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN1);
564 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN1);
566 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN1);
568 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN1);
570 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
572 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
576 + rstctrl &= ~RT3883_RSTCTRL_PCIE;
577 + rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
580 + syscfg1 |= (RT3883_SYSCFG1_PCIE_RC_MODE | RT3883_SYSCFG1_PCI_HOST_MODE);
582 + clkcfg1 &= ~(RT3883_CLKCFG1_PCI_CLK_EN | RT3883_CLKCFG1_PCIE_CLK_EN);
584 + if (mode & RT3883_PCI_MODE_PCI) {
585 + clkcfg1 |= RT3883_CLKCFG1_PCI_CLK_EN;
586 + rstctrl &= ~RT3883_RSTCTRL_PCI;
589 + if (mode & RT3883_PCI_MODE_PCIE) {
590 + clkcfg1 |= RT3883_CLKCFG1_PCIE_CLK_EN;
591 + rstctrl &= ~RT3883_RSTCTRL_PCIE;
594 + rt_sysc_w32(syscfg1, RT3883_SYSC_REG_SYSCFG1);
595 + rt_sysc_w32(rstctrl, RT3883_SYSC_REG_RSTCTRL);
596 + rt_sysc_w32(clkcfg1, RT3883_SYSC_REG_CLKCFG1);
601 + * setup the device number of the P2P bridge
602 + * and de-assert the reset line
604 + t = (RT3883_P2P_BR_DEVNUM << RT3883_PCICFG_P2P_BR_DEVNUM_S);
605 + rt3883_pci_w32(rpc, t, RT3883_PCI_REG_PCICFG);
608 + rt3883_pci_r32(rpc, RT3883_PCI_REG_PCICFG);
611 + if (mode & RT3883_PCI_MODE_PCIE) {
614 + t = rt3883_pci_r32(rpc, RT3883_PCI_REG_STATUS(1));
616 + rpc->pcie_ready = t & BIT(0);
618 + if (!rpc->pcie_ready) {
619 + /* reset the PCIe block */
620 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
621 + t |= RT3883_RSTCTRL_PCIE;
622 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
623 + t &= ~RT3883_RSTCTRL_PCIE;
624 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
626 + /* turn off PCIe clock */
627 + t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
628 + t &= ~RT3883_CLKCFG1_PCIE_CLK_EN;
629 + rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
631 + t = rt_sysc_r32(RT3883_SYSC_REG_PCIE_CLK_GEN0);
633 + rt_sysc_w32(t, RT3883_SYSC_REG_PCIE_CLK_GEN0);
637 + /* enable PCI arbiter */
638 + rt3883_pci_w32(rpc, 0x79, RT3883_PCI_REG_ARBCTL);
641 +static int rt3883_pci_probe(struct platform_device *pdev)
643 + struct rt3883_pci_controller *rpc;
644 + struct device *dev = &pdev->dev;
645 + struct device_node *np = dev->of_node;
646 + struct resource *res;
647 + struct device_node *child;
652 + rpc = devm_kzalloc(dev, sizeof(*rpc), GFP_KERNEL);
656 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
660 + rpc->base = devm_ioremap_resource(dev, res);
661 + if (IS_ERR(rpc->base))
662 + return PTR_ERR(rpc->base);
664 + /* find the interrupt controller child node */
665 + for_each_child_of_node(np, child) {
666 + if (of_get_property(child, "interrupt-controller", NULL) &&
667 + of_node_get(child)) {
668 + rpc->intc_of_node = child;
673 + if (!rpc->intc_of_node) {
674 + dev_err(dev, "% has no %s child node",
675 + of_node_full_name(rpc->intc_of_node),
676 + "interrupt controller");
680 + /* find the PCI host bridge child node */
681 + for_each_child_of_node(np, child) {
683 + of_node_cmp(child->type, "pci") == 0 &&
684 + of_node_get(child)) {
685 + rpc->pci_controller.of_node = child;
690 + if (!rpc->pci_controller.of_node) {
691 + dev_err(dev, "%s has no %s child node",
692 + of_node_full_name(rpc->intc_of_node),
693 + "PCI host bridge");
695 + goto err_put_intc_node;
698 + mode = RT3883_PCI_MODE_NONE;
699 + for_each_available_child_of_node(rpc->pci_controller.of_node, child) {
702 + if (!child->type ||
703 + of_node_cmp(child->type, "pci") != 0)
706 + devfn = of_pci_get_devfn(child);
710 + switch (PCI_SLOT(devfn)) {
712 + mode |= RT3883_PCI_MODE_PCIE;
717 + mode |= RT3883_PCI_MODE_PCI;
722 + if (mode == RT3883_PCI_MODE_NONE) {
723 + dev_err(dev, "unable to determine PCI mode\n");
725 + goto err_put_hb_node;
728 + dev_info(dev, "mode:%s%s\n",
729 + (mode & RT3883_PCI_MODE_PCI) ? " PCI" : "",
730 + (mode & RT3883_PCI_MODE_PCIE) ? " PCIe" : "");
732 + rt3883_pci_preinit(rpc, mode);
734 + rpc->pci_controller.pci_ops = &rt3883_pci_ops;
735 + rpc->pci_controller.io_resource = &rpc->io_res;
736 + rpc->pci_controller.mem_resource = &rpc->mem_res;
738 + /* Load PCI I/O and memory resources from DT */
739 + pci_load_of_ranges(&rpc->pci_controller,
740 + rpc->pci_controller.of_node);
742 + rt3883_pci_w32(rpc, rpc->mem_res.start, RT3883_PCI_REG_MEMBASE);
743 + rt3883_pci_w32(rpc, rpc->io_res.start, RT3883_PCI_REG_IOBASE);
745 + ioport_resource.start = rpc->io_res.start;
746 + ioport_resource.end = rpc->io_res.end;
749 + rt3883_pci_w32(rpc, 0x03ff0000, RT3883_PCI_REG_BAR0SETUP(0));
750 + rt3883_pci_w32(rpc, RT3883_MEMORY_BASE, RT3883_PCI_REG_IMBASEBAR0(0));
751 + rt3883_pci_w32(rpc, 0x08021814, RT3883_PCI_REG_ID(0));
752 + rt3883_pci_w32(rpc, 0x00800001, RT3883_PCI_REG_CLASS(0));
753 + rt3883_pci_w32(rpc, 0x28801814, RT3883_PCI_REG_SUBID(0));
756 + rt3883_pci_w32(rpc, 0x03ff0000, RT3883_PCI_REG_BAR0SETUP(1));
757 + rt3883_pci_w32(rpc, RT3883_MEMORY_BASE, RT3883_PCI_REG_IMBASEBAR0(1));
758 + rt3883_pci_w32(rpc, 0x08021814, RT3883_PCI_REG_ID(1));
759 + rt3883_pci_w32(rpc, 0x06040001, RT3883_PCI_REG_CLASS(1));
760 + rt3883_pci_w32(rpc, 0x28801814, RT3883_PCI_REG_SUBID(1));
762 + err = rt3883_pci_irq_init(dev, rpc);
764 + goto err_put_hb_node;
767 + val = rt3883_pci_read_cfg32(rpc, 0, 0x01, 0, PCI_COMMAND);
768 + val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
769 + rt3883_pci_write_cfg32(rpc, 0, 0x01, 0, PCI_COMMAND, val);
772 + val = rt3883_pci_read_cfg32(rpc, 0, 0x00, 0, PCI_COMMAND);
773 + val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
774 + rt3883_pci_write_cfg32(rpc, 0, 0x00, 0, PCI_COMMAND, val);
776 + if (mode == RT3883_PCI_MODE_PCIE) {
777 + rt3883_pci_w32(rpc, 0x03ff0001, RT3883_PCI_REG_BAR0SETUP(0));
778 + rt3883_pci_w32(rpc, 0x03ff0001, RT3883_PCI_REG_BAR0SETUP(1));
780 + rt3883_pci_write_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
781 + PCI_BASE_ADDRESS_0,
782 + RT3883_MEMORY_BASE);
784 + rt3883_pci_read_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
785 + PCI_BASE_ADDRESS_0);
787 + rt3883_pci_write_cfg32(rpc, 0, RT3883_P2P_BR_DEVNUM, 0,
788 + PCI_IO_BASE, 0x00000101);
791 + register_pci_controller(&rpc->pci_controller);
796 + of_node_put(rpc->pci_controller.of_node);
798 + of_node_put(rpc->intc_of_node);
802 +int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
804 + struct of_irq dev_irq;
808 + err = of_irq_map_pci(dev, &dev_irq);
810 + pr_err("pci %s: unable to get irq map, err=%d\n",
811 + pci_name((struct pci_dev *) dev), err);
815 + irq = irq_create_of_mapping(dev_irq.controller,
820 + pr_crit("pci %s: no irq found for pin %u\n",
821 + pci_name((struct pci_dev *) dev), pin);
823 + pr_info("pci %s: using irq %d for pin %u\n",
824 + pci_name((struct pci_dev *) dev), irq, pin);
829 +int pcibios_plat_dev_init(struct pci_dev *dev)
834 +static const struct of_device_id rt3883_pci_ids[] = {
835 + { .compatible = "ralink,rt3883-pci" },
838 +MODULE_DEVICE_TABLE(of, rt3883_pci_ids);
840 +static struct platform_driver rt3883_pci_driver = {
841 + .probe = rt3883_pci_probe,
843 + .name = "rt3883-pci",
844 + .owner = THIS_MODULE,
845 + .of_match_table = of_match_ptr(rt3883_pci_ids),
849 +static int __init rt3883_pci_init(void)
851 + return platform_driver_register(&rt3883_pci_driver);
854 +postcore_initcall(rt3883_pci_init);
855 --- a/arch/mips/ralink/Kconfig
856 +++ b/arch/mips/ralink/Kconfig
857 @@ -26,6 +26,7 @@ choice
859 select USB_ARCH_HAS_OHCI
860 select USB_ARCH_HAS_EHCI