Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Atheros AR71XX/AR724X specific PCI setup code |
| 3 | * |
| 4 | * Copyright (C) 2011 René Bolldorf <xsecute@googlemail.com> |
Gabor Juhos | e9b62e8 | 2012-03-14 10:36:14 +0100 | [diff] [blame^] | 5 | * 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 Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 9 | * |
| 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 Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 15 | #include <linux/init.h> |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 16 | #include <linux/pci.h> |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 17 | #include <asm/mach-ath79/ath79.h> |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 18 | #include <asm/mach-ath79/irq.h> |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 19 | #include <asm/mach-ath79/pci.h> |
Gabor Juhos | 3a6208d | 2012-03-14 10:29:22 +0100 | [diff] [blame] | 20 | #include "pci.h" |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 21 | |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 22 | static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev); |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 23 | static const struct ath79_pci_irq *ath79_pci_irq_map __initdata; |
| 24 | static unsigned ath79_pci_nr_irqs __initdata; |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 25 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 26 | static 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 | |
| 42 | static 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 Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 50 | int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin) |
| 51 | { |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 52 | int irq = -1; |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 53 | int i; |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 54 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 55 | 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 Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 69 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 70 | 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 Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 86 | |
| 87 | return irq; |
| 88 | } |
| 89 | |
| 90 | int pcibios_plat_dev_init(struct pci_dev *dev) |
| 91 | { |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 92 | if (ath79_pci_plat_dev_init) |
| 93 | return ath79_pci_plat_dev_init(dev); |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 94 | |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 95 | return 0; |
| 96 | } |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 97 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 98 | void __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 Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 105 | void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev)) |
| 106 | { |
| 107 | ath79_pci_plat_dev_init = func; |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 108 | } |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 109 | |
| 110 | int __init ath79_register_pci(void) |
| 111 | { |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame] | 112 | if (soc_is_ar71xx()) |
| 113 | return ar71xx_pcibios_init(); |
| 114 | |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 115 | if (soc_is_ar724x()) |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 116 | return ar724x_pcibios_init(ATH79_CPU_IRQ_IP2); |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 117 | |
| 118 | return -ENODEV; |
| 119 | } |