ar71xx: use backported PCI patches
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / patches-3.8 / 011-MIPS-pci-ar71xx-convert-into-a-platform-driver.patch
1 From 060c9a226a25e044167e877d9830ec53f836da9e Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sat, 2 Feb 2013 11:40:43 +0000
4 Subject: [PATCH] MIPS: pci-ar71xx: convert into a platform driver
5
6 commit fb167e891d5cc6386840dd092af2d461b38eb802 upstream.
7
8 The patch converts the pci-ar71xx driver into a
9 platform driver. This makes it possible to register
10 the PCI controller as a plain platform device.
11
12 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
13 Patchwork: http://patchwork.linux-mips.org/patch/4906/
14 Signed-off-by: John Crispin <blogic@openwrt.org>
15 ---
16 arch/mips/pci/pci-ar71xx.c | 60 +++++++++++++++++++++++++++++++++++++++++---
17 1 file changed, 56 insertions(+), 4 deletions(-)
18
19 --- a/arch/mips/pci/pci-ar71xx.c
20 +++ b/arch/mips/pci/pci-ar71xx.c
21 @@ -18,6 +18,8 @@
22 #include <linux/pci.h>
23 #include <linux/pci_regs.h>
24 #include <linux/interrupt.h>
25 +#include <linux/module.h>
26 +#include <linux/platform_device.h>
27
28 #include <asm/mach-ath79/ar71xx_regs.h>
29 #include <asm/mach-ath79/ath79.h>
30 @@ -309,7 +311,7 @@ static struct irq_chip ar71xx_pci_irq_ch
31 .irq_mask_ack = ar71xx_pci_irq_mask,
32 };
33
34 -static __init void ar71xx_pci_irq_init(void)
35 +static void ar71xx_pci_irq_init(int irq)
36 {
37 void __iomem *base = ath79_reset_base;
38 int i;
39 @@ -324,10 +326,10 @@ static __init void ar71xx_pci_irq_init(v
40 irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip,
41 handle_level_irq);
42
43 - irq_set_chained_handler(ATH79_CPU_IRQ_IP2, ar71xx_pci_irq_handler);
44 + irq_set_chained_handler(irq, ar71xx_pci_irq_handler);
45 }
46
47 -static __init void ar71xx_pci_reset(void)
48 +static void ar71xx_pci_reset(void)
49 {
50 void __iomem *ddr_base = ath79_ddr_base;
51
52 @@ -367,9 +369,59 @@ __init int ar71xx_pcibios_init(void)
53 /* clear bus errors */
54 ar71xx_pci_check_error(1);
55
56 - ar71xx_pci_irq_init();
57 + ar71xx_pci_irq_init(ATH79_CPU_IRQ_IP2);
58
59 register_pci_controller(&ar71xx_pci_controller);
60
61 return 0;
62 }
63 +
64 +static int ar71xx_pci_probe(struct platform_device *pdev)
65 +{
66 + struct resource *res;
67 + int irq;
68 + u32 t;
69 +
70 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg_base");
71 + if (!res)
72 + return -EINVAL;
73 +
74 + ar71xx_pcicfg_base = devm_request_and_ioremap(&pdev->dev, res);
75 + if (!ar71xx_pcicfg_base)
76 + return -ENOMEM;
77 +
78 + irq = platform_get_irq(pdev, 0);
79 + if (irq < 0)
80 + return -EINVAL;
81 +
82 + ar71xx_pci_reset();
83 +
84 + /* setup COMMAND register */
85 + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
86 + | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
87 + ar71xx_pci_local_write(PCI_COMMAND, 4, t);
88 +
89 + /* clear bus errors */
90 + ar71xx_pci_check_error(1);
91 +
92 + ar71xx_pci_irq_init(irq);
93 +
94 + register_pci_controller(&ar71xx_pci_controller);
95 +
96 + return 0;
97 +}
98 +
99 +static struct platform_driver ar71xx_pci_driver = {
100 + .probe = ar71xx_pci_probe,
101 + .driver = {
102 + .name = "ar71xx-pci",
103 + .owner = THIS_MODULE,
104 + },
105 +};
106 +
107 +static int __init ar71xx_pci_init(void)
108 +{
109 + return platform_driver_register(&ar71xx_pci_driver);
110 +}
111 +
112 +postcore_initcall(ar71xx_pci_init);