blob: bc40070e45c9471ba51d5a851d6d78d7551412b6 [file] [log] [blame]
Gabor Juhose2dbdc42012-03-14 10:29:21 +01001/*
2 * Atheros AR71XX/AR724X specific PCI setup code
3 *
4 * Copyright (C) 2011 René Bolldorf <xsecute@googlemail.com>
Gabor Juhose9b62e82012-03-14 10:36:14 +01005 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 *
8 * Parts of this file are based on Atheros' 2.6.15 BSP
Gabor Juhose2dbdc42012-03-14 10:29:21 +01009 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
Gabor Juhosd22ce252012-03-14 10:36:11 +010015#include <linux/init.h>
Gabor Juhose2dbdc42012-03-14 10:29:21 +010016#include <linux/pci.h>
Gabor Juhos6335aef2012-03-14 10:29:24 +010017#include <asm/mach-ath79/ath79.h>
Gabor Juhos4c07c7d2012-03-14 10:36:07 +010018#include <asm/mach-ath79/irq.h>
Gabor Juhos6335aef2012-03-14 10:29:24 +010019#include <asm/mach-ath79/pci.h>
Gabor Juhos3a6208d2012-03-14 10:29:22 +010020#include "pci.h"
Gabor Juhose2dbdc42012-03-14 10:29:21 +010021
Gabor Juhosa68ad4d2012-03-14 10:36:09 +010022static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev);
Gabor Juhosd22ce252012-03-14 10:36:11 +010023static const struct ath79_pci_irq *ath79_pci_irq_map __initdata;
24static unsigned ath79_pci_nr_irqs __initdata;
Gabor Juhose2dbdc42012-03-14 10:29:21 +010025
Gabor Juhosd22ce252012-03-14 10:36:11 +010026static const struct ath79_pci_irq ar71xx_pci_irq_map[] __initconst = {
27 {
28 .slot = 17,
29 .pin = 1,
30 .irq = ATH79_PCI_IRQ(0),
31 }, {
32 .slot = 18,
33 .pin = 1,
34 .irq = ATH79_PCI_IRQ(1),
35 }, {
36 .slot = 19,
37 .pin = 1,
38 .irq = ATH79_PCI_IRQ(2),
39 }
40};
41
42static const struct ath79_pci_irq ar724x_pci_irq_map[] __initconst = {
43 {
44 .slot = 0,
45 .pin = 1,
46 .irq = ATH79_PCI_IRQ(0),
47 }
48};
49
Gabor Juhose2dbdc42012-03-14 10:29:21 +010050int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
51{
Gabor Juhose2dbdc42012-03-14 10:29:21 +010052 int irq = -1;
Gabor Juhosd22ce252012-03-14 10:36:11 +010053 int i;
Gabor Juhose2dbdc42012-03-14 10:29:21 +010054
Gabor Juhosd22ce252012-03-14 10:36:11 +010055 if (ath79_pci_nr_irqs == 0 ||
56 ath79_pci_irq_map == NULL) {
57 if (soc_is_ar71xx()) {
58 ath79_pci_irq_map = ar71xx_pci_irq_map;
59 ath79_pci_nr_irqs = ARRAY_SIZE(ar71xx_pci_irq_map);
60 } else if (soc_is_ar724x()) {
61 ath79_pci_irq_map = ar724x_pci_irq_map;
62 ath79_pci_nr_irqs = ARRAY_SIZE(ar724x_pci_irq_map);
63 } else {
64 pr_crit("pci %s: invalid irq map\n",
65 pci_name((struct pci_dev *) dev));
66 return irq;
67 }
68 }
Gabor Juhose2dbdc42012-03-14 10:29:21 +010069
Gabor Juhosd22ce252012-03-14 10:36:11 +010070 for (i = 0; i < ath79_pci_nr_irqs; i++) {
71 const struct ath79_pci_irq *entry;
72
73 entry = &ath79_pci_irq_map[i];
74 if (entry->slot == slot && entry->pin == pin) {
75 irq = entry->irq;
76 break;
77 }
78 }
79
80 if (irq < 0)
81 pr_crit("pci %s: no irq found for pin %u\n",
82 pci_name((struct pci_dev *) dev), pin);
83 else
84 pr_info("pci %s: using irq %d for pin %u\n",
85 pci_name((struct pci_dev *) dev), irq, pin);
Gabor Juhose2dbdc42012-03-14 10:29:21 +010086
87 return irq;
88}
89
90int pcibios_plat_dev_init(struct pci_dev *dev)
91{
Gabor Juhosa68ad4d2012-03-14 10:36:09 +010092 if (ath79_pci_plat_dev_init)
93 return ath79_pci_plat_dev_init(dev);
Gabor Juhose2dbdc42012-03-14 10:29:21 +010094
Gabor Juhosa68ad4d2012-03-14 10:36:09 +010095 return 0;
96}
Gabor Juhose2dbdc42012-03-14 10:29:21 +010097
Gabor Juhosd22ce252012-03-14 10:36:11 +010098void __init ath79_pci_set_irq_map(unsigned nr_irqs,
99 const struct ath79_pci_irq *map)
100{
101 ath79_pci_nr_irqs = nr_irqs;
102 ath79_pci_irq_map = map;
103}
104
Gabor Juhosa68ad4d2012-03-14 10:36:09 +0100105void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev))
106{
107 ath79_pci_plat_dev_init = func;
Gabor Juhose2dbdc42012-03-14 10:29:21 +0100108}
Gabor Juhos6335aef2012-03-14 10:29:24 +0100109
110int __init ath79_register_pci(void)
111{
Gabor Juhosd22ce252012-03-14 10:36:11 +0100112 if (soc_is_ar71xx())
113 return ar71xx_pcibios_init();
114
Gabor Juhos6335aef2012-03-14 10:29:24 +0100115 if (soc_is_ar724x())
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100116 return ar724x_pcibios_init(ATH79_CPU_IRQ_IP2);
Gabor Juhos6335aef2012-03-14 10:29:24 +0100117
118 return -ENODEV;
119}