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> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation. |
| 9 | */ |
| 10 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 11 | #include <linux/init.h> |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 12 | #include <linux/pci.h> |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 13 | #include <asm/mach-ath79/ath79.h> |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 14 | #include <asm/mach-ath79/irq.h> |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 15 | #include <asm/mach-ath79/pci.h> |
Gabor Juhos | 3a6208d | 2012-03-14 10:29:22 +0100 | [diff] [blame] | 16 | #include "pci.h" |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 17 | |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 18 | static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev); |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 19 | static const struct ath79_pci_irq *ath79_pci_irq_map __initdata; |
| 20 | static unsigned ath79_pci_nr_irqs __initdata; |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 21 | static struct ar724x_pci_data *pci_data; |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 22 | static int pci_data_size; |
| 23 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 24 | static const struct ath79_pci_irq ar71xx_pci_irq_map[] __initconst = { |
| 25 | { |
| 26 | .slot = 17, |
| 27 | .pin = 1, |
| 28 | .irq = ATH79_PCI_IRQ(0), |
| 29 | }, { |
| 30 | .slot = 18, |
| 31 | .pin = 1, |
| 32 | .irq = ATH79_PCI_IRQ(1), |
| 33 | }, { |
| 34 | .slot = 19, |
| 35 | .pin = 1, |
| 36 | .irq = ATH79_PCI_IRQ(2), |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | static const struct ath79_pci_irq ar724x_pci_irq_map[] __initconst = { |
| 41 | { |
| 42 | .slot = 0, |
| 43 | .pin = 1, |
| 44 | .irq = ATH79_PCI_IRQ(0), |
| 45 | } |
| 46 | }; |
| 47 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 48 | void ar724x_pci_add_data(struct ar724x_pci_data *data, int size) |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 49 | { |
| 50 | pci_data = data; |
| 51 | pci_data_size = size; |
| 52 | } |
| 53 | |
| 54 | int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin) |
| 55 | { |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 56 | int irq = -1; |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 57 | int i; |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 58 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 59 | if (ath79_pci_nr_irqs == 0 || |
| 60 | ath79_pci_irq_map == NULL) { |
| 61 | if (soc_is_ar71xx()) { |
| 62 | ath79_pci_irq_map = ar71xx_pci_irq_map; |
| 63 | ath79_pci_nr_irqs = ARRAY_SIZE(ar71xx_pci_irq_map); |
| 64 | } else if (soc_is_ar724x()) { |
| 65 | ath79_pci_irq_map = ar724x_pci_irq_map; |
| 66 | ath79_pci_nr_irqs = ARRAY_SIZE(ar724x_pci_irq_map); |
| 67 | } else { |
| 68 | pr_crit("pci %s: invalid irq map\n", |
| 69 | pci_name((struct pci_dev *) dev)); |
| 70 | return irq; |
| 71 | } |
| 72 | } |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 73 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 74 | for (i = 0; i < ath79_pci_nr_irqs; i++) { |
| 75 | const struct ath79_pci_irq *entry; |
| 76 | |
| 77 | entry = &ath79_pci_irq_map[i]; |
| 78 | if (entry->slot == slot && entry->pin == pin) { |
| 79 | irq = entry->irq; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (irq < 0) |
| 85 | pr_crit("pci %s: no irq found for pin %u\n", |
| 86 | pci_name((struct pci_dev *) dev), pin); |
| 87 | else |
| 88 | pr_info("pci %s: using irq %d for pin %u\n", |
| 89 | pci_name((struct pci_dev *) dev), irq, pin); |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 90 | |
| 91 | return irq; |
| 92 | } |
| 93 | |
| 94 | int pcibios_plat_dev_init(struct pci_dev *dev) |
| 95 | { |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 96 | if (ath79_pci_plat_dev_init) |
| 97 | return ath79_pci_plat_dev_init(dev); |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 98 | |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 99 | return 0; |
| 100 | } |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 101 | |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 102 | void __init ath79_pci_set_irq_map(unsigned nr_irqs, |
| 103 | const struct ath79_pci_irq *map) |
| 104 | { |
| 105 | ath79_pci_nr_irqs = nr_irqs; |
| 106 | ath79_pci_irq_map = map; |
| 107 | } |
| 108 | |
Gabor Juhos | a68ad4d | 2012-03-14 10:36:09 +0100 | [diff] [blame] | 109 | void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev)) |
| 110 | { |
| 111 | ath79_pci_plat_dev_init = func; |
Gabor Juhos | e2dbdc4 | 2012-03-14 10:29:21 +0100 | [diff] [blame] | 112 | } |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 113 | |
| 114 | int __init ath79_register_pci(void) |
| 115 | { |
Gabor Juhos | d22ce25 | 2012-03-14 10:36:11 +0100 | [diff] [blame^] | 116 | if (soc_is_ar71xx()) |
| 117 | return ar71xx_pcibios_init(); |
| 118 | |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 119 | if (soc_is_ar724x()) |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 120 | return ar724x_pcibios_init(ATH79_CPU_IRQ_IP2); |
Gabor Juhos | 6335aef | 2012-03-14 10:29:24 +0100 | [diff] [blame] | 121 | |
| 122 | return -ENODEV; |
| 123 | } |