atheros: v3.18: remap flash for boardconfig parsing
[librecmc/librecmc.git] / target / linux / atheros / patches-3.18 / 105-ar2315_pci.patch
1 --- a/arch/mips/pci/Makefile
2 +++ b/arch/mips/pci/Makefile
3 @@ -19,6 +19,7 @@ obj-$(CONFIG_BCM47XX)         += pci-bcm47xx.o
4  obj-$(CONFIG_BCM63XX)          += pci-bcm63xx.o fixup-bcm63xx.o \
5                                         ops-bcm63xx.o
6  obj-$(CONFIG_MIPS_ALCHEMY)     += pci-alchemy.o
7 +obj-$(CONFIG_PCI_AR2315)       += pci-ar2315.o
8  obj-$(CONFIG_SOC_AR71XX)       += pci-ar71xx.o
9  obj-$(CONFIG_PCI_AR724X)       += pci-ar724x.o
10  obj-$(CONFIG_MIPS_PCI_VIRTIO)  += pci-virtio-guest.o
11 --- /dev/null
12 +++ b/arch/mips/pci/pci-ar2315.c
13 @@ -0,0 +1,494 @@
14 +/*
15 + * This program is free software; you can redistribute it and/or
16 + * modify it under the terms of the GNU General Public License
17 + * as published by the Free Software Foundation; either version 2
18 + * of the License, or (at your option) any later version.
19 + *
20 + * This program is distributed in the hope that it will be useful,
21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 + * GNU General Public License for more details.
24 + *
25 + * You should have received a copy of the GNU General Public License
26 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 + */
28 +
29 +/**
30 + * Both AR2315 and AR2316 chips have PCI interface unit, which supports DMA
31 + * and interrupt. PCI interface supports MMIO access method, but does not
32 + * seem to support I/O ports.
33 + *
34 + * Read/write operation in the region 0x80000000-0xBFFFFFFF causes
35 + * a memory read/write command on the PCI bus. 30 LSBs of address on
36 + * the bus are taken from memory read/write request and 2 MSBs are
37 + * determined by PCI unit configuration.
38 + *
39 + * To work with the configuration space instead of memory is necessary set
40 + * the CFG_SEL bit in the PCI_MISC_CONFIG register.
41 + *
42 + * Devices on the bus can perform DMA requests via chip BAR1. PCI host
43 + * controller BARs are programmend as if an external device is programmed.
44 + * Which means that during configuration, IDSEL pin of the chip should be
45 + * asserted.
46 + *
47 + * We know (and support) only one board that uses the PCI interface -
48 + * Fonera 2.0g (FON2202). It has a USB EHCI controller connected to the
49 + * AR2315 PCI bus. IDSEL pin of USB controller is connected to AD[13] line
50 + * and IDSEL pin of AR125 is connected to AD[16] line.
51 + */
52 +
53 +#include <linux/types.h>
54 +#include <linux/pci.h>
55 +#include <linux/platform_device.h>
56 +#include <linux/kernel.h>
57 +#include <linux/init.h>
58 +#include <linux/mm.h>
59 +#include <linux/delay.h>
60 +#include <linux/irq.h>
61 +#include <linux/io.h>
62 +#include <asm/paccess.h>
63 +
64 +/*
65 + * PCI Bus Interface Registers
66 + */
67 +#define AR2315_PCI_1MS_REG             0x0008
68 +
69 +#define AR2315_PCI_1MS_MASK            0x3FFFF /* # of AHB clk cycles in 1ms */
70 +
71 +#define AR2315_PCI_MISC_CONFIG         0x000c
72 +
73 +#define AR2315_PCIMISC_TXD_EN  0x00000001      /* Enable TXD for fragments */
74 +#define AR2315_PCIMISC_CFG_SEL 0x00000002      /* Mem or Config cycles */
75 +#define AR2315_PCIMISC_GIG_MASK        0x0000000C      /* bits 31-30 for pci req */
76 +#define AR2315_PCIMISC_RST_MODE        0x00000030
77 +#define AR2315_PCIRST_INPUT    0x00000000      /* 4:5=0 rst is input */
78 +#define AR2315_PCIRST_LOW      0x00000010      /* 4:5=1 rst to GND */
79 +#define AR2315_PCIRST_HIGH     0x00000020      /* 4:5=2 rst to VDD */
80 +#define AR2315_PCIGRANT_EN     0x00000000      /* 6:7=0 early grant en */
81 +#define AR2315_PCIGRANT_FRAME  0x00000040      /* 6:7=1 grant waits 4 frame */
82 +#define AR2315_PCIGRANT_IDLE   0x00000080      /* 6:7=2 grant waits 4 idle */
83 +#define AR2315_PCIGRANT_GAP    0x00000000      /* 6:7=2 grant waits 4 idle */
84 +#define AR2315_PCICACHE_DIS    0x00001000      /* PCI external access cache
85 +                                                * disable */
86 +
87 +#define AR2315_PCI_OUT_TSTAMP          0x0010
88 +
89 +#define AR2315_PCI_UNCACHE_CFG         0x0014
90 +
91 +#define AR2315_PCI_IN_EN               0x0100
92 +
93 +#define AR2315_PCI_IN_EN0      0x01    /* Enable chain 0 */
94 +#define AR2315_PCI_IN_EN1      0x02    /* Enable chain 1 */
95 +#define AR2315_PCI_IN_EN2      0x04    /* Enable chain 2 */
96 +#define AR2315_PCI_IN_EN3      0x08    /* Enable chain 3 */
97 +
98 +#define AR2315_PCI_IN_DIS              0x0104
99 +
100 +#define AR2315_PCI_IN_DIS0     0x01    /* Disable chain 0 */
101 +#define AR2315_PCI_IN_DIS1     0x02    /* Disable chain 1 */
102 +#define AR2315_PCI_IN_DIS2     0x04    /* Disable chain 2 */
103 +#define AR2315_PCI_IN_DIS3     0x08    /* Disable chain 3 */
104 +
105 +#define AR2315_PCI_IN_PTR              0x0200
106 +
107 +#define AR2315_PCI_OUT_EN              0x0400
108 +
109 +#define AR2315_PCI_OUT_EN0     0x01    /* Enable chain 0 */
110 +
111 +#define AR2315_PCI_OUT_DIS             0x0404
112 +
113 +#define AR2315_PCI_OUT_DIS0    0x01    /* Disable chain 0 */
114 +
115 +#define AR2315_PCI_OUT_PTR             0x0408
116 +
117 +/* PCI interrupt status (write one to clear) */
118 +#define AR2315_PCI_ISR                 0x0500
119 +
120 +#define AR2315_PCI_INT_TX      0x00000001      /* Desc In Completed */
121 +#define AR2315_PCI_INT_TXOK    0x00000002      /* Desc In OK */
122 +#define AR2315_PCI_INT_TXERR   0x00000004      /* Desc In ERR */
123 +#define AR2315_PCI_INT_TXEOL   0x00000008      /* Desc In End-of-List */
124 +#define AR2315_PCI_INT_RX      0x00000010      /* Desc Out Completed */
125 +#define AR2315_PCI_INT_RXOK    0x00000020      /* Desc Out OK */
126 +#define AR2315_PCI_INT_RXERR   0x00000040      /* Desc Out ERR */
127 +#define AR2315_PCI_INT_RXEOL   0x00000080      /* Desc Out EOL */
128 +#define AR2315_PCI_INT_TXOOD   0x00000200      /* Desc In Out-of-Desc */
129 +#define AR2315_PCI_INT_DESCMASK        0x0000FFFF      /* Desc Mask */
130 +#define AR2315_PCI_INT_EXT     0x02000000      /* Extern PCI INTA */
131 +#define AR2315_PCI_INT_ABORT   0x04000000      /* PCI bus abort event */
132 +
133 +/* PCI interrupt mask */
134 +#define AR2315_PCI_IMR                 0x0504
135 +
136 +/* Global PCI interrupt enable */
137 +#define AR2315_PCI_IER                 0x0508
138 +
139 +#define AR2315_PCI_IER_DISABLE         0x00    /* disable pci interrupts */
140 +#define AR2315_PCI_IER_ENABLE          0x01    /* enable pci interrupts */
141 +
142 +#define AR2315_PCI_HOST_IN_EN          0x0800
143 +#define AR2315_PCI_HOST_IN_DIS         0x0804
144 +#define AR2315_PCI_HOST_IN_PTR         0x0810
145 +#define AR2315_PCI_HOST_OUT_EN         0x0900
146 +#define AR2315_PCI_HOST_OUT_DIS                0x0904
147 +#define AR2315_PCI_HOST_OUT_PTR                0x0908
148 +
149 +/*
150 + * PCI interrupts, which share IP5
151 + * Keep ordered according to AR2315_PCI_INT_XXX bits
152 + */
153 +#define AR2315_PCI_IRQ_BASE            0x50
154 +#define AR2315_PCI_IRQ_EXT             (AR2315_PCI_IRQ_BASE+0)
155 +#define AR2315_PCI_IRQ_ABORT           (AR2315_PCI_IRQ_BASE+1)
156 +#define AR2315_PCI_IRQ_COUNT           2
157 +#define AR2315_PCI_IRQ_SHIFT           25      /* in AR2315_PCI_INT_STATUS */
158 +
159 +/* Arbitrary size of memory region to access the configuration space */
160 +#define AR2315_PCI_CFG_SIZE    0x00100000
161 +
162 +#define AR2315_PCI_HOST_SLOT   3
163 +#define AR2315_PCI_HOST_DEVID  ((0xff18 << 16) | PCI_VENDOR_ID_ATHEROS)
164 +
165 +/* ??? access BAR */
166 +#define AR2315_PCI_HOST_MBAR0          0x10000000
167 +/* RAM access BAR */
168 +#define AR2315_PCI_HOST_MBAR1          AR2315_PCI_HOST_SDRAM_BASEADDR
169 +/* ??? access BAR */
170 +#define AR2315_PCI_HOST_MBAR2          0x30000000
171 +
172 +struct ar2315_pci_ctrl {
173 +       void __iomem *cfg_mem;
174 +       void __iomem *mmr_mem;
175 +       unsigned irq;
176 +       struct pci_controller pci_ctrl;
177 +       struct resource mem_res;
178 +       struct resource io_res;
179 +};
180 +
181 +static inline struct ar2315_pci_ctrl *ar2315_pci_bus_to_apc(struct pci_bus *bus)
182 +{
183 +       struct pci_controller *hose = bus->sysdata;
184 +
185 +       return container_of(hose, struct ar2315_pci_ctrl, pci_ctrl);
186 +}
187 +
188 +static inline u32 ar2315_pci_reg_read(struct ar2315_pci_ctrl *apc, u32 reg)
189 +{
190 +       return __raw_readl(apc->mmr_mem + reg);
191 +}
192 +
193 +static inline void ar2315_pci_reg_write(struct ar2315_pci_ctrl *apc, u32 reg,
194 +                                       u32 val)
195 +{
196 +       __raw_writel(val, apc->mmr_mem + reg);
197 +}
198 +
199 +static inline void ar2315_pci_reg_mask(struct ar2315_pci_ctrl *apc, u32 reg,
200 +                                      u32 mask, u32 val)
201 +{
202 +       u32 ret = ar2315_pci_reg_read(apc, reg);
203 +
204 +       ret &= ~mask;
205 +       ret |= val;
206 +       ar2315_pci_reg_write(apc, reg, ret);
207 +}
208 +
209 +static int ar2315_pci_cfg_access(struct ar2315_pci_ctrl *apc, unsigned devfn,
210 +                                int where, int size, u32 *ptr, bool write)
211 +{
212 +       int func = PCI_FUNC(devfn);
213 +       int dev = PCI_SLOT(devfn);
214 +       u32 addr = (1 << (13 + dev)) | (func << 8) | (where & ~3);
215 +       u32 mask = 0xffffffff >> 8 * (4 - size);
216 +       u32 sh = (where & 3) * 8;
217 +       u32 value, isr;
218 +
219 +       /* Prevent access past the remapped area */
220 +       if (addr >= AR2315_PCI_CFG_SIZE || dev > 18)
221 +               return PCIBIOS_DEVICE_NOT_FOUND;
222 +
223 +       /* Clear pending errors */
224 +       ar2315_pci_reg_write(apc, AR2315_PCI_ISR, AR2315_PCI_INT_ABORT);
225 +       /* Select Configuration access */
226 +       ar2315_pci_reg_mask(apc, AR2315_PCI_MISC_CONFIG, 0,
227 +                           AR2315_PCIMISC_CFG_SEL);
228 +
229 +       mb();   /* PCI must see space change before we begin */
230 +
231 +       value = __raw_readl(apc->cfg_mem + addr);
232 +
233 +       isr = ar2315_pci_reg_read(apc, AR2315_PCI_ISR);
234 +
235 +       if (isr & AR2315_PCI_INT_ABORT)
236 +               goto exit_err;
237 +
238 +       if (write) {
239 +               value = (value & ~(mask << sh)) | *ptr << sh;
240 +               __raw_writel(value, apc->cfg_mem + addr);
241 +               isr = ar2315_pci_reg_read(apc, AR2315_PCI_ISR);
242 +               if (isr & AR2315_PCI_INT_ABORT)
243 +                       goto exit_err;
244 +       } else {
245 +               *ptr = (value >> sh) & mask;
246 +       }
247 +
248 +       goto exit;
249 +
250 +exit_err:
251 +       ar2315_pci_reg_write(apc, AR2315_PCI_ISR, AR2315_PCI_INT_ABORT);
252 +       if (!write)
253 +               *ptr = 0xffffffff;
254 +
255 +exit:
256 +       /* Select Memory access */
257 +       ar2315_pci_reg_mask(apc, AR2315_PCI_MISC_CONFIG, AR2315_PCIMISC_CFG_SEL,
258 +                           0);
259 +
260 +       return isr & AR2315_PCI_INT_ABORT ? PCIBIOS_DEVICE_NOT_FOUND :
261 +                                           PCIBIOS_SUCCESSFUL;
262 +}
263 +
264 +static inline int ar2315_pci_local_cfg_rd(struct ar2315_pci_ctrl *apc,
265 +                                         unsigned devfn, int where, u32 *val)
266 +{
267 +       return ar2315_pci_cfg_access(apc, devfn, where, sizeof(u32), val,
268 +                                    false);
269 +}
270 +
271 +static inline int ar2315_pci_local_cfg_wr(struct ar2315_pci_ctrl *apc,
272 +                                         unsigned devfn, int where, u32 val)
273 +{
274 +       return ar2315_pci_cfg_access(apc, devfn, where, sizeof(u32), &val,
275 +                                    true);
276 +}
277 +
278 +static int ar2315_pci_cfg_read(struct pci_bus *bus, unsigned devfn, int where,
279 +                              int size, u32 *value)
280 +{
281 +       struct ar2315_pci_ctrl *apc = ar2315_pci_bus_to_apc(bus);
282 +
283 +       if (PCI_SLOT(devfn) == AR2315_PCI_HOST_SLOT)
284 +               return PCIBIOS_DEVICE_NOT_FOUND;
285 +
286 +       return ar2315_pci_cfg_access(apc, devfn, where, size, value, false);
287 +}
288 +
289 +static int ar2315_pci_cfg_write(struct pci_bus *bus, unsigned devfn, int where,
290 +                               int size, u32 value)
291 +{
292 +       struct ar2315_pci_ctrl *apc = ar2315_pci_bus_to_apc(bus);
293 +
294 +       if (PCI_SLOT(devfn) == AR2315_PCI_HOST_SLOT)
295 +               return PCIBIOS_DEVICE_NOT_FOUND;
296 +
297 +       return ar2315_pci_cfg_access(apc, devfn, where, size, &value, true);
298 +}
299 +
300 +static struct pci_ops ar2315_pci_ops = {
301 +       .read   = ar2315_pci_cfg_read,
302 +       .write  = ar2315_pci_cfg_write,
303 +};
304 +
305 +static int ar2315_pci_host_setup(struct ar2315_pci_ctrl *apc)
306 +{
307 +       unsigned devfn = PCI_DEVFN(AR2315_PCI_HOST_SLOT, 0);
308 +       int res;
309 +       u32 id;
310 +
311 +       res = ar2315_pci_local_cfg_rd(apc, devfn, PCI_VENDOR_ID, &id);
312 +       if (res != PCIBIOS_SUCCESSFUL || id != AR2315_PCI_HOST_DEVID)
313 +               return -ENODEV;
314 +
315 +       /* Program MBARs */
316 +       ar2315_pci_local_cfg_wr(apc, devfn, PCI_BASE_ADDRESS_0,
317 +                               AR2315_PCI_HOST_MBAR0);
318 +       ar2315_pci_local_cfg_wr(apc, devfn, PCI_BASE_ADDRESS_1,
319 +                               AR2315_PCI_HOST_MBAR1);
320 +       ar2315_pci_local_cfg_wr(apc, devfn, PCI_BASE_ADDRESS_2,
321 +                               AR2315_PCI_HOST_MBAR2);
322 +
323 +       /* Run */
324 +       ar2315_pci_local_cfg_wr(apc, devfn, PCI_COMMAND, PCI_COMMAND_MEMORY |
325 +                               PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL |
326 +                               PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY |
327 +                               PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK);
328 +
329 +       return 0;
330 +}
331 +
332 +static void ar2315_pci_irq_handler(unsigned irq, struct irq_desc *desc)
333 +{
334 +       struct ar2315_pci_ctrl *apc = irq_get_handler_data(irq);
335 +       u32 pending = ar2315_pci_reg_read(apc, AR2315_PCI_ISR) &
336 +                     ar2315_pci_reg_read(apc, AR2315_PCI_IMR);
337 +
338 +       if (pending & AR2315_PCI_INT_EXT)
339 +               generic_handle_irq(AR2315_PCI_IRQ_EXT);
340 +       else if (pending & AR2315_PCI_INT_ABORT)
341 +               generic_handle_irq(AR2315_PCI_IRQ_ABORT);
342 +       else
343 +               spurious_interrupt();
344 +}
345 +
346 +static void ar2315_pci_irq_mask(struct irq_data *d)
347 +{
348 +       struct ar2315_pci_ctrl *apc = irq_data_get_irq_chip_data(d);
349 +       u32 m = 1 << (d->irq - AR2315_PCI_IRQ_BASE + AR2315_PCI_IRQ_SHIFT);
350 +
351 +       ar2315_pci_reg_mask(apc, AR2315_PCI_IMR, m, 0);
352 +}
353 +
354 +static void ar2315_pci_irq_mask_ack(struct irq_data *d)
355 +{
356 +       struct ar2315_pci_ctrl *apc = irq_data_get_irq_chip_data(d);
357 +       u32 m = 1 << (d->irq - AR2315_PCI_IRQ_BASE + AR2315_PCI_IRQ_SHIFT);
358 +
359 +       ar2315_pci_reg_mask(apc, AR2315_PCI_IMR, m, 0);
360 +       ar2315_pci_reg_write(apc, AR2315_PCI_ISR, m);
361 +}
362 +
363 +static void ar2315_pci_irq_unmask(struct irq_data *d)
364 +{
365 +       struct ar2315_pci_ctrl *apc = irq_data_get_irq_chip_data(d);
366 +       u32 m = 1 << (d->irq - AR2315_PCI_IRQ_BASE + AR2315_PCI_IRQ_SHIFT);
367 +
368 +       ar2315_pci_reg_mask(apc, AR2315_PCI_IMR, 0, m);
369 +}
370 +
371 +static struct irq_chip ar2315_pci_irq_chip = {
372 +       .name = "AR2315-PCI",
373 +       .irq_mask = ar2315_pci_irq_mask,
374 +       .irq_mask_ack = ar2315_pci_irq_mask_ack,
375 +       .irq_unmask = ar2315_pci_irq_unmask,
376 +};
377 +
378 +static void ar2315_pci_irq_init(struct ar2315_pci_ctrl *apc)
379 +{
380 +       int i;
381 +
382 +       ar2315_pci_reg_mask(apc, AR2315_PCI_IER, AR2315_PCI_IER_ENABLE, 0);
383 +       ar2315_pci_reg_mask(apc, AR2315_PCI_IMR, (AR2315_PCI_INT_ABORT |
384 +                           AR2315_PCI_INT_EXT), 0);
385 +
386 +       for (i = 0; i < AR2315_PCI_IRQ_COUNT; ++i) {
387 +               int irq = AR2315_PCI_IRQ_BASE + i;
388 +
389 +               irq_set_chip_and_handler(irq, &ar2315_pci_irq_chip,
390 +                                        handle_level_irq);
391 +               irq_set_chip_data(irq, apc);
392 +       }
393 +
394 +       irq_set_chained_handler(apc->irq, ar2315_pci_irq_handler);
395 +       irq_set_handler_data(apc->irq, apc);
396 +
397 +       /* Clear any pending Abort or external Interrupts
398 +        * and enable interrupt processing */
399 +       ar2315_pci_reg_write(apc, AR2315_PCI_ISR, AR2315_PCI_INT_ABORT |
400 +                                                 AR2315_PCI_INT_EXT);
401 +       ar2315_pci_reg_mask(apc, AR2315_PCI_IER, 0, AR2315_PCI_IER_ENABLE);
402 +}
403 +
404 +static int ar2315_pci_probe(struct platform_device *pdev)
405 +{
406 +       struct ar2315_pci_ctrl *apc;
407 +       struct device *dev = &pdev->dev;
408 +       struct resource *res;
409 +       int irq, err;
410 +
411 +       apc = devm_kzalloc(dev, sizeof(*apc), GFP_KERNEL);
412 +       if (!apc)
413 +               return -ENOMEM;
414 +
415 +       irq = platform_get_irq(pdev, 0);
416 +       if (irq < 0)
417 +               return -EINVAL;
418 +       apc->irq = irq;
419 +
420 +       res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
421 +                                          "ar2315-pci-ctrl");
422 +       apc->mmr_mem = devm_ioremap_resource(dev, res);
423 +       if (IS_ERR(apc->mmr_mem))
424 +               return PTR_ERR(apc->mmr_mem);
425 +
426 +       res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
427 +                                          "ar2315-pci-ext");
428 +       if (!res)
429 +               return -EINVAL;
430 +
431 +       apc->mem_res.name = "AR2315 PCI mem space";
432 +       apc->mem_res.parent = res;
433 +       apc->mem_res.start = res->start;
434 +       apc->mem_res.end = res->end;
435 +       apc->mem_res.flags = IORESOURCE_MEM;
436 +
437 +       /* Remap PCI config space */
438 +       apc->cfg_mem = devm_ioremap_nocache(dev, res->start,
439 +                                           AR2315_PCI_CFG_SIZE);
440 +       if (!apc->cfg_mem) {
441 +               dev_err(dev, "failed to remap PCI config space\n");
442 +               return -ENOMEM;
443 +       }
444 +
445 +       /* Reset the PCI bus by setting bits 5-4 in PCI_MCFG */
446 +       ar2315_pci_reg_mask(apc, AR2315_PCI_MISC_CONFIG,
447 +                           AR2315_PCIMISC_RST_MODE,
448 +                           AR2315_PCIRST_LOW);
449 +       msleep(100);
450 +
451 +       /* Bring the PCI out of reset */
452 +       ar2315_pci_reg_mask(apc, AR2315_PCI_MISC_CONFIG,
453 +                           AR2315_PCIMISC_RST_MODE,
454 +                           AR2315_PCIRST_HIGH | AR2315_PCICACHE_DIS | 0x8);
455 +
456 +       ar2315_pci_reg_write(apc, AR2315_PCI_UNCACHE_CFG,
457 +                            0x1E | /* 1GB uncached */
458 +                            (1 << 5) | /* Enable uncached */
459 +                            (0x2 << 30) /* Base: 0x80000000 */);
460 +       ar2315_pci_reg_read(apc, AR2315_PCI_UNCACHE_CFG);
461 +
462 +       msleep(500);
463 +
464 +       err = ar2315_pci_host_setup(apc);
465 +       if (err)
466 +               return err;
467 +
468 +       ar2315_pci_irq_init(apc);
469 +
470 +       /* PCI controller does not support I/O ports */
471 +       apc->io_res.name = "AR2315 IO space";
472 +       apc->io_res.start = 0;
473 +       apc->io_res.end = 0;
474 +       apc->io_res.flags = IORESOURCE_IO,
475 +
476 +       apc->pci_ctrl.pci_ops = &ar2315_pci_ops;
477 +       apc->pci_ctrl.mem_resource = &apc->mem_res,
478 +       apc->pci_ctrl.io_resource = &apc->io_res,
479 +
480 +       register_pci_controller(&apc->pci_ctrl);
481 +
482 +       return 0;
483 +}
484 +
485 +static struct platform_driver ar2315_pci_driver = {
486 +       .probe = ar2315_pci_probe,
487 +       .driver = {
488 +               .name = "ar2315-pci",
489 +               .owner = THIS_MODULE,
490 +       },
491 +};
492 +
493 +static int __init ar2315_pci_init(void)
494 +{
495 +       return platform_driver_register(&ar2315_pci_driver);
496 +}
497 +arch_initcall(ar2315_pci_init);
498 +
499 +int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
500 +{
501 +       return AR2315_PCI_IRQ_EXT;
502 +}
503 +
504 +int pcibios_plat_dev_init(struct pci_dev *dev)
505 +{
506 +       return 0;
507 +}
508 --- a/arch/mips/ath25/Kconfig
509 +++ b/arch/mips/ath25/Kconfig
510 @@ -9,3 +9,10 @@ config SOC_AR2315
511         depends on ATH25
512         select GPIO_AR2315
513         default y
514 +
515 +config PCI_AR2315
516 +       bool "AR2315 PCI controller support"
517 +       depends on SOC_AR2315
518 +       select HW_HAS_PCI
519 +       select PCI
520 +       default y
521 --- a/arch/mips/ath25/ar2315.c
522 +++ b/arch/mips/ath25/ar2315.c
523 @@ -137,6 +137,10 @@ static void ar2315_irq_dispatch(void)
524                 do_IRQ(AR2315_IRQ_WLAN0_INTRS);
525         else if (pending & CAUSEF_IP4)
526                 do_IRQ(AR2315_IRQ_ENET0_INTRS);
527 +#ifdef CONFIG_PCI_AR2315
528 +       else if (pending & CAUSEF_IP5)
529 +               do_IRQ(AR2315_IRQ_LCBUS_PCI);
530 +#endif
531         else if (pending & CAUSEF_IP2)
532                 do_IRQ(AR2315_IRQ_MISC_INTRS);
533         else if (pending & CAUSEF_IP7)
534 @@ -440,8 +444,60 @@ void __init ar2315_plat_mem_setup(void)
535         _machine_restart = ar2315_restart;
536  }
537  
538 +#ifdef CONFIG_PCI_AR2315
539 +static struct resource ar2315_pci_res[] = {
540 +       {
541 +               .name = "ar2315-pci-ctrl",
542 +               .flags = IORESOURCE_MEM,
543 +               .start = AR2315_PCI,
544 +               .end = AR2315_PCI + AR2315_PCI_SIZE - 1,
545 +       },
546 +       {
547 +               .name = "ar2315-pci-ext",
548 +               .flags = IORESOURCE_MEM,
549 +               .start = AR2315_PCIEXT,
550 +               .end = AR2315_PCIEXT + AR2315_PCIEXT_SZ - 1,
551 +       },
552 +       {
553 +               .name = "ar2315-pci",
554 +               .flags = IORESOURCE_IRQ,
555 +               .start = AR2315_IRQ_LCBUS_PCI,
556 +               .end = AR2315_IRQ_LCBUS_PCI,
557 +       },
558 +};
559 +#endif
560 +
561  void __init ar2315_arch_init(void)
562  {
563         ath25_serial_setup(AR2315_UART0, AR2315_MISC_IRQ_UART0,
564                            ar2315_apb_frequency());
565 +
566 +#ifdef CONFIG_PCI_AR2315
567 +       if (ath25_soc == ATH25_SOC_AR2315) {
568 +               /* Reset PCI DMA logic */
569 +               ar2315_rst_reg_mask(AR2315_RESET, 0, AR2315_RESET_PCIDMA);
570 +               msleep(20);
571 +               ar2315_rst_reg_mask(AR2315_RESET, AR2315_RESET_PCIDMA, 0);
572 +               msleep(20);
573 +
574 +               /* Configure endians */
575 +               ar2315_rst_reg_mask(AR2315_ENDIAN_CTL, 0, AR2315_CONFIG_PCIAHB |
576 +                                   AR2315_CONFIG_PCIAHB_BRIDGE);
577 +
578 +               /* Configure as PCI host with DMA */
579 +               ar2315_rst_reg_write(AR2315_PCICLK, AR2315_PCICLK_PLLC_CLKM |
580 +                                 (AR2315_PCICLK_IN_FREQ_DIV_6 <<
581 +                                  AR2315_PCICLK_DIV_S));
582 +               ar2315_rst_reg_mask(AR2315_AHB_ARB_CTL, 0, AR2315_ARB_PCI);
583 +               ar2315_rst_reg_mask(AR2315_IF_CTL, AR2315_IF_PCI_CLK_MASK |
584 +                                   AR2315_IF_MASK, AR2315_IF_PCI |
585 +                                   AR2315_IF_PCI_HOST | AR2315_IF_PCI_INTR |
586 +                                   (AR2315_IF_PCI_CLK_OUTPUT_CLK <<
587 +                                    AR2315_IF_PCI_CLK_SHIFT));
588 +
589 +               platform_device_register_simple("ar2315-pci", -1,
590 +                                               ar2315_pci_res,
591 +                                               ARRAY_SIZE(ar2315_pci_res));
592 +       }
593 +#endif
594  }