823488aaa9b90e2380bc9b7410c65c91cac6877c
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / patches-3.8 / 018-MIPS-pci-ar724x-remove-static-PCI-IO-MEM-resources.patch
1 From d80b05d19c2772ded40403d578d8e90d38c85257 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sun, 3 Feb 2013 09:59:45 +0000
4 Subject: [PATCH] MIPS: pci-ar724x: remove static PCI IO/MEM resources
5
6 commit 34b134aebda89888b6985b7a3139e9cbdf209236 upstream.
7
8 Static resources become impractical when multiple
9 PCI controllers are present. Move the resources
10 into the platform device registration code and
11 change the probe routine to get those from there
12 platform device's resources.
13
14 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
15 Patchwork: http://patchwork.linux-mips.org/patch/4914/
16 Signed-off-by: John Crispin <blogic@openwrt.org>
17 ---
18 arch/mips/ath79/pci.c | 21 ++++++++++++++++++++-
19 arch/mips/pci/pci-ar724x.c | 40 ++++++++++++++++++++++++----------------
20 2 files changed, 44 insertions(+), 17 deletions(-)
21
22 --- a/arch/mips/ath79/pci.c
23 +++ b/arch/mips/ath79/pci.c
24 @@ -139,10 +139,13 @@ static struct platform_device *
25 ath79_register_pci_ar724x(int id,
26 unsigned long cfg_base,
27 unsigned long ctrl_base,
28 + unsigned long mem_base,
29 + unsigned long mem_size,
30 + unsigned long io_base,
31 int irq)
32 {
33 struct platform_device *pdev;
34 - struct resource res[3];
35 + struct resource res[5];
36
37 memset(res, 0, sizeof(res));
38
39 @@ -160,6 +163,16 @@ ath79_register_pci_ar724x(int id,
40 res[2].start = irq;
41 res[2].end = irq;
42
43 + res[3].name = "mem_base";
44 + res[3].flags = IORESOURCE_MEM;
45 + res[3].start = mem_base;
46 + res[3].end = mem_base + mem_size - 1;
47 +
48 + res[4].name = "io_base";
49 + res[4].flags = IORESOURCE_IO;
50 + res[4].start = io_base;
51 + res[4].end = io_base;
52 +
53 pdev = platform_device_register_simple("ar724x-pci", id,
54 res, ARRAY_SIZE(res));
55 return pdev;
56 @@ -175,6 +188,9 @@ int __init ath79_register_pci(void)
57 pdev = ath79_register_pci_ar724x(-1,
58 AR724X_PCI_CFG_BASE,
59 AR724X_PCI_CTRL_BASE,
60 + AR724X_PCI_MEM_BASE,
61 + AR724X_PCI_MEM_SIZE,
62 + 0,
63 ATH79_CPU_IRQ_IP2);
64 } else if (soc_is_ar9342() ||
65 soc_is_ar9344()) {
66 @@ -187,6 +203,9 @@ int __init ath79_register_pci(void)
67 pdev = ath79_register_pci_ar724x(-1,
68 AR724X_PCI_CFG_BASE,
69 AR724X_PCI_CTRL_BASE,
70 + AR724X_PCI_MEM_BASE,
71 + AR724X_PCI_MEM_SIZE,
72 + 0,
73 ATH79_IP2_IRQ(0));
74 } else {
75 /* No PCI support */
76 --- a/arch/mips/pci/pci-ar724x.c
77 +++ b/arch/mips/pci/pci-ar724x.c
78 @@ -42,6 +42,8 @@ struct ar724x_pci_controller {
79 spinlock_t lock;
80
81 struct pci_controller pci_controller;
82 + struct resource io_res;
83 + struct resource mem_res;
84 };
85
86 static inline bool ar724x_pci_check_link(struct ar724x_pci_controller *apc)
87 @@ -190,20 +192,6 @@ static struct pci_ops ar724x_pci_ops = {
88 .write = ar724x_pci_write,
89 };
90
91 -static struct resource ar724x_io_resource = {
92 - .name = "PCI IO space",
93 - .start = 0,
94 - .end = 0,
95 - .flags = IORESOURCE_IO,
96 -};
97 -
98 -static struct resource ar724x_mem_resource = {
99 - .name = "PCI memory space",
100 - .start = AR724X_PCI_MEM_BASE,
101 - .end = AR724X_PCI_MEM_BASE + AR724X_PCI_MEM_SIZE - 1,
102 - .flags = IORESOURCE_MEM,
103 -};
104 -
105 static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
106 {
107 struct ar724x_pci_controller *apc;
108 @@ -331,9 +319,29 @@ static int ar724x_pci_probe(struct platf
109
110 spin_lock_init(&apc->lock);
111
112 + res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
113 + if (!res)
114 + return -EINVAL;
115 +
116 + apc->io_res.parent = res;
117 + apc->io_res.name = "PCI IO space";
118 + apc->io_res.start = res->start;
119 + apc->io_res.end = res->end;
120 + apc->io_res.flags = IORESOURCE_IO;
121 +
122 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
123 + if (!res)
124 + return -EINVAL;
125 +
126 + apc->mem_res.parent = res;
127 + apc->mem_res.name = "PCI memory space";
128 + apc->mem_res.start = res->start;
129 + apc->mem_res.end = res->end;
130 + apc->mem_res.flags = IORESOURCE_MEM;
131 +
132 apc->pci_controller.pci_ops = &ar724x_pci_ops;
133 - apc->pci_controller.io_resource = &ar724x_io_resource;
134 - apc->pci_controller.mem_resource = &ar724x_mem_resource;
135 + apc->pci_controller.io_resource = &apc->io_res;
136 + apc->pci_controller.mem_resource = &apc->mem_res;
137
138 apc->link_up = ar724x_pci_check_link(apc);
139 if (!apc->link_up)