19199f15d09e60da87c9db59d533513841696416
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / pci.c
1 /*
2  *  Atheros AR71xx PCI setup code
3  *
4  *  Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  Parts of this file are based on Atheros' 2.6.15 BSP
8  *
9  *  This program is free software; you can redistribute it and/or modify it
10  *  under the terms of the GNU General Public License version 2 as published
11  *  by the Free Software Foundation.
12  */
13
14 #include <asm/mach-ar71xx/ar71xx.h>
15 #include <asm/mach-ar71xx/pci.h>
16
17 unsigned ar71xx_pci_nr_irqs __initdata;
18 struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
19
20 int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
21
22 static int ar71xx_be_handler(struct pt_regs *regs, int is_fixup)
23 {
24         int err = 0;
25
26         err = ar71xx_pci_be_handler(is_fixup);
27
28         return (is_fixup && !err) ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
29 }
30
31 int pcibios_plat_dev_init(struct pci_dev *dev)
32 {
33         if (ar71xx_pci_plat_dev_init)
34                 return ar71xx_pci_plat_dev_init(dev);
35
36         return 0;
37 }
38
39 int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
40 {
41         int ret = 0;
42
43         switch (ar71xx_soc) {
44         case AR71XX_SOC_AR7130:
45         case AR71XX_SOC_AR7141:
46         case AR71XX_SOC_AR7161:
47                 ret = ar71xx_pcibios_map_irq(dev, slot, pin);
48                 break;
49
50         case AR71XX_SOC_AR7240:
51                 ret = ar724x_pcibios_map_irq(dev, slot, pin);
52                 break;
53
54         default:
55                 break;
56         }
57
58         return ret;
59 }
60
61 int __init ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map)
62 {
63         int ret = 0;
64
65         switch (ar71xx_soc) {
66         case AR71XX_SOC_AR7130:
67         case AR71XX_SOC_AR7141:
68         case AR71XX_SOC_AR7161:
69                 board_be_handler = ar71xx_be_handler;
70                 ret = ar71xx_pcibios_init();
71                 break;
72
73         case AR71XX_SOC_AR7240:
74                 ret = ar724x_pcibios_init();
75                 break;
76
77         default:
78                 return 0;
79         }
80
81         ar71xx_pci_nr_irqs = nr_irqs;
82         ar71xx_pci_irq_map = map;
83
84         return ret;
85 }