Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 1 | /* |
Gabor Juhos | e9b62e8 | 2012-03-14 10:36:14 +0100 | [diff] [blame] | 2 | * Atheros AR724X PCI host controller driver |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 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) 2009-2011 Gabor Juhos <juhosg@openwrt.org> |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published |
| 9 | * by the Free Software Foundation. |
| 10 | */ |
| 11 | |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 12 | #include <linux/irq.h> |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 13 | #include <linux/pci.h> |
Gabor Juhos | 58d2e9b | 2013-02-02 11:40:42 +0000 | [diff] [blame^] | 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
Gabor Juhos | 6015a85 | 2012-03-14 10:36:05 +0100 | [diff] [blame] | 16 | #include <asm/mach-ath79/ath79.h> |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 17 | #include <asm/mach-ath79/ar71xx_regs.h> |
Gabor Juhos | 659243c | 2012-03-14 10:29:23 +0100 | [diff] [blame] | 18 | #include <asm/mach-ath79/pci.h> |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 19 | |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 20 | #define AR724X_PCI_CFG_BASE 0x14000000 |
| 21 | #define AR724X_PCI_CFG_SIZE 0x1000 |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 22 | #define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000f0000) |
| 23 | #define AR724X_PCI_CTRL_SIZE 0x100 |
| 24 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 25 | #define AR724X_PCI_MEM_BASE 0x10000000 |
Gabor Juhos | 4c96091 | 2013-01-29 08:27:03 +0000 | [diff] [blame] | 26 | #define AR724X_PCI_MEM_SIZE 0x04000000 |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 27 | |
Gabor Juhos | a1dca31 | 2012-08-23 15:35:26 +0200 | [diff] [blame] | 28 | #define AR724X_PCI_REG_RESET 0x18 |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 29 | #define AR724X_PCI_REG_INT_STATUS 0x4c |
| 30 | #define AR724X_PCI_REG_INT_MASK 0x50 |
| 31 | |
Gabor Juhos | a1dca31 | 2012-08-23 15:35:26 +0200 | [diff] [blame] | 32 | #define AR724X_PCI_RESET_LINK_UP BIT(0) |
| 33 | |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 34 | #define AR724X_PCI_INT_DEV0 BIT(14) |
| 35 | |
| 36 | #define AR724X_PCI_IRQ_COUNT 1 |
| 37 | |
Gabor Juhos | 6015a85 | 2012-03-14 10:36:05 +0100 | [diff] [blame] | 38 | #define AR7240_BAR0_WAR_VALUE 0xffff |
| 39 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 40 | static DEFINE_SPINLOCK(ar724x_pci_lock); |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 41 | static void __iomem *ar724x_pci_devcfg_base; |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 42 | static void __iomem *ar724x_pci_ctrl_base; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 43 | |
Gabor Juhos | 6015a85 | 2012-03-14 10:36:05 +0100 | [diff] [blame] | 44 | static u32 ar724x_pci_bar0_value; |
| 45 | static bool ar724x_pci_bar0_is_cached; |
Gabor Juhos | a1dca31 | 2012-08-23 15:35:26 +0200 | [diff] [blame] | 46 | static bool ar724x_pci_link_up; |
| 47 | |
| 48 | static inline bool ar724x_pci_check_link(void) |
| 49 | { |
| 50 | u32 reset; |
| 51 | |
| 52 | reset = __raw_readl(ar724x_pci_ctrl_base + AR724X_PCI_REG_RESET); |
| 53 | return reset & AR724X_PCI_RESET_LINK_UP; |
| 54 | } |
Gabor Juhos | 6015a85 | 2012-03-14 10:36:05 +0100 | [diff] [blame] | 55 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 56 | static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where, |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 57 | int size, uint32_t *value) |
| 58 | { |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 59 | unsigned long flags; |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 60 | void __iomem *base; |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 61 | u32 data; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 62 | |
Gabor Juhos | a1dca31 | 2012-08-23 15:35:26 +0200 | [diff] [blame] | 63 | if (!ar724x_pci_link_up) |
| 64 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 65 | |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 66 | if (devfn) |
| 67 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 68 | |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 69 | base = ar724x_pci_devcfg_base; |
| 70 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 71 | spin_lock_irqsave(&ar724x_pci_lock, flags); |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 72 | data = __raw_readl(base + (where & ~3)); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 73 | |
| 74 | switch (size) { |
| 75 | case 1: |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 76 | if (where & 1) |
| 77 | data >>= 8; |
| 78 | if (where & 2) |
| 79 | data >>= 16; |
| 80 | data &= 0xff; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 81 | break; |
| 82 | case 2: |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 83 | if (where & 2) |
| 84 | data >>= 16; |
| 85 | data &= 0xffff; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 86 | break; |
| 87 | case 4: |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 88 | break; |
| 89 | default: |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 90 | spin_unlock_irqrestore(&ar724x_pci_lock, flags); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 91 | |
| 92 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 93 | } |
| 94 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 95 | spin_unlock_irqrestore(&ar724x_pci_lock, flags); |
Gabor Juhos | 6015a85 | 2012-03-14 10:36:05 +0100 | [diff] [blame] | 96 | |
| 97 | if (where == PCI_BASE_ADDRESS_0 && size == 4 && |
| 98 | ar724x_pci_bar0_is_cached) { |
| 99 | /* use the cached value */ |
| 100 | *value = ar724x_pci_bar0_value; |
| 101 | } else { |
| 102 | *value = data; |
| 103 | } |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 104 | |
| 105 | return PCIBIOS_SUCCESSFUL; |
| 106 | } |
| 107 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 108 | static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where, |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 109 | int size, uint32_t value) |
| 110 | { |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 111 | unsigned long flags; |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 112 | void __iomem *base; |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 113 | u32 data; |
| 114 | int s; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 115 | |
Gabor Juhos | a1dca31 | 2012-08-23 15:35:26 +0200 | [diff] [blame] | 116 | if (!ar724x_pci_link_up) |
| 117 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 118 | |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 119 | if (devfn) |
| 120 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 121 | |
Gabor Juhos | 6015a85 | 2012-03-14 10:36:05 +0100 | [diff] [blame] | 122 | if (soc_is_ar7240() && where == PCI_BASE_ADDRESS_0 && size == 4) { |
| 123 | if (value != 0xffffffff) { |
| 124 | /* |
| 125 | * WAR for a hw issue. If the BAR0 register of the |
| 126 | * device is set to the proper base address, the |
| 127 | * memory space of the device is not accessible. |
| 128 | * |
| 129 | * Cache the intended value so it can be read back, |
| 130 | * and write a SoC specific constant value to the |
| 131 | * BAR0 register in order to make the device memory |
| 132 | * accessible. |
| 133 | */ |
| 134 | ar724x_pci_bar0_is_cached = true; |
| 135 | ar724x_pci_bar0_value = value; |
| 136 | |
| 137 | value = AR7240_BAR0_WAR_VALUE; |
| 138 | } else { |
| 139 | ar724x_pci_bar0_is_cached = false; |
| 140 | } |
| 141 | } |
| 142 | |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 143 | base = ar724x_pci_devcfg_base; |
| 144 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 145 | spin_lock_irqsave(&ar724x_pci_lock, flags); |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 146 | data = __raw_readl(base + (where & ~3)); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 147 | |
| 148 | switch (size) { |
| 149 | case 1: |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 150 | s = ((where & 3) * 8); |
| 151 | data &= ~(0xff << s); |
| 152 | data |= ((value & 0xff) << s); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 153 | break; |
| 154 | case 2: |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 155 | s = ((where & 2) * 8); |
| 156 | data &= ~(0xffff << s); |
| 157 | data |= ((value & 0xffff) << s); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 158 | break; |
| 159 | case 4: |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 160 | data = value; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 161 | break; |
| 162 | default: |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 163 | spin_unlock_irqrestore(&ar724x_pci_lock, flags); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 164 | |
| 165 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 166 | } |
| 167 | |
Gabor Juhos | 64adb6b | 2012-03-14 10:36:04 +0100 | [diff] [blame] | 168 | __raw_writel(data, base + (where & ~3)); |
| 169 | /* flush write */ |
| 170 | __raw_readl(base + (where & ~3)); |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 171 | spin_unlock_irqrestore(&ar724x_pci_lock, flags); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 172 | |
| 173 | return PCIBIOS_SUCCESSFUL; |
| 174 | } |
| 175 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 176 | static struct pci_ops ar724x_pci_ops = { |
| 177 | .read = ar724x_pci_read, |
| 178 | .write = ar724x_pci_write, |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 181 | static struct resource ar724x_io_resource = { |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 182 | .name = "PCI IO space", |
| 183 | .start = 0, |
| 184 | .end = 0, |
| 185 | .flags = IORESOURCE_IO, |
| 186 | }; |
| 187 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 188 | static struct resource ar724x_mem_resource = { |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 189 | .name = "PCI memory space", |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 190 | .start = AR724X_PCI_MEM_BASE, |
| 191 | .end = AR724X_PCI_MEM_BASE + AR724X_PCI_MEM_SIZE - 1, |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 192 | .flags = IORESOURCE_MEM, |
| 193 | }; |
| 194 | |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 195 | static struct pci_controller ar724x_pci_controller = { |
| 196 | .pci_ops = &ar724x_pci_ops, |
| 197 | .io_resource = &ar724x_io_resource, |
| 198 | .mem_resource = &ar724x_mem_resource, |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 201 | static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc) |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 202 | { |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 203 | void __iomem *base; |
| 204 | u32 pending; |
| 205 | |
| 206 | base = ar724x_pci_ctrl_base; |
| 207 | |
| 208 | pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) & |
| 209 | __raw_readl(base + AR724X_PCI_REG_INT_MASK); |
| 210 | |
| 211 | if (pending & AR724X_PCI_INT_DEV0) |
| 212 | generic_handle_irq(ATH79_PCI_IRQ(0)); |
| 213 | |
| 214 | else |
| 215 | spurious_interrupt(); |
| 216 | } |
| 217 | |
| 218 | static void ar724x_pci_irq_unmask(struct irq_data *d) |
| 219 | { |
| 220 | void __iomem *base; |
| 221 | u32 t; |
| 222 | |
| 223 | base = ar724x_pci_ctrl_base; |
| 224 | |
| 225 | switch (d->irq) { |
| 226 | case ATH79_PCI_IRQ(0): |
| 227 | t = __raw_readl(base + AR724X_PCI_REG_INT_MASK); |
| 228 | __raw_writel(t | AR724X_PCI_INT_DEV0, |
| 229 | base + AR724X_PCI_REG_INT_MASK); |
| 230 | /* flush write */ |
| 231 | __raw_readl(base + AR724X_PCI_REG_INT_MASK); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | static void ar724x_pci_irq_mask(struct irq_data *d) |
| 236 | { |
| 237 | void __iomem *base; |
| 238 | u32 t; |
| 239 | |
| 240 | base = ar724x_pci_ctrl_base; |
| 241 | |
| 242 | switch (d->irq) { |
| 243 | case ATH79_PCI_IRQ(0): |
| 244 | t = __raw_readl(base + AR724X_PCI_REG_INT_MASK); |
| 245 | __raw_writel(t & ~AR724X_PCI_INT_DEV0, |
| 246 | base + AR724X_PCI_REG_INT_MASK); |
| 247 | |
| 248 | /* flush write */ |
| 249 | __raw_readl(base + AR724X_PCI_REG_INT_MASK); |
| 250 | |
| 251 | t = __raw_readl(base + AR724X_PCI_REG_INT_STATUS); |
| 252 | __raw_writel(t | AR724X_PCI_INT_DEV0, |
| 253 | base + AR724X_PCI_REG_INT_STATUS); |
| 254 | |
| 255 | /* flush write */ |
| 256 | __raw_readl(base + AR724X_PCI_REG_INT_STATUS); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | static struct irq_chip ar724x_pci_irq_chip = { |
| 261 | .name = "AR724X PCI ", |
| 262 | .irq_mask = ar724x_pci_irq_mask, |
| 263 | .irq_unmask = ar724x_pci_irq_unmask, |
| 264 | .irq_mask_ack = ar724x_pci_irq_mask, |
| 265 | }; |
| 266 | |
Gabor Juhos | 58d2e9b | 2013-02-02 11:40:42 +0000 | [diff] [blame^] | 267 | static void ar724x_pci_irq_init(int irq) |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 268 | { |
| 269 | void __iomem *base; |
| 270 | int i; |
| 271 | |
| 272 | base = ar724x_pci_ctrl_base; |
| 273 | |
| 274 | __raw_writel(0, base + AR724X_PCI_REG_INT_MASK); |
| 275 | __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS); |
| 276 | |
| 277 | BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR724X_PCI_IRQ_COUNT); |
| 278 | |
| 279 | for (i = ATH79_PCI_IRQ_BASE; |
| 280 | i < ATH79_PCI_IRQ_BASE + AR724X_PCI_IRQ_COUNT; i++) |
| 281 | irq_set_chip_and_handler(i, &ar724x_pci_irq_chip, |
| 282 | handle_level_irq); |
| 283 | |
| 284 | irq_set_chained_handler(irq, ar724x_pci_irq_handler); |
| 285 | } |
| 286 | |
Gabor Juhos | 58d2e9b | 2013-02-02 11:40:42 +0000 | [diff] [blame^] | 287 | int ar724x_pcibios_init(int irq) |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 288 | { |
| 289 | int ret; |
| 290 | |
| 291 | ret = -ENOMEM; |
| 292 | |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 293 | ar724x_pci_devcfg_base = ioremap(AR724X_PCI_CFG_BASE, |
| 294 | AR724X_PCI_CFG_SIZE); |
| 295 | if (ar724x_pci_devcfg_base == NULL) |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 296 | goto err; |
Gabor Juhos | c198441 | 2012-03-14 10:29:27 +0100 | [diff] [blame] | 297 | |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 298 | ar724x_pci_ctrl_base = ioremap(AR724X_PCI_CTRL_BASE, |
| 299 | AR724X_PCI_CTRL_SIZE); |
| 300 | if (ar724x_pci_ctrl_base == NULL) |
| 301 | goto err_unmap_devcfg; |
| 302 | |
Gabor Juhos | a1dca31 | 2012-08-23 15:35:26 +0200 | [diff] [blame] | 303 | ar724x_pci_link_up = ar724x_pci_check_link(); |
| 304 | if (!ar724x_pci_link_up) |
| 305 | pr_warn("ar724x: PCIe link is down\n"); |
| 306 | |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 307 | ar724x_pci_irq_init(irq); |
Gabor Juhos | d624bd3 | 2012-03-14 10:29:26 +0100 | [diff] [blame] | 308 | register_pci_controller(&ar724x_pci_controller); |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 309 | |
| 310 | return PCIBIOS_SUCCESSFUL; |
Gabor Juhos | 4c07c7d | 2012-03-14 10:36:07 +0100 | [diff] [blame] | 311 | |
| 312 | err_unmap_devcfg: |
| 313 | iounmap(ar724x_pci_devcfg_base); |
| 314 | err: |
| 315 | return ret; |
Rene Bolldorf | 4ff40d5 | 2011-11-17 14:25:09 +0000 | [diff] [blame] | 316 | } |
Gabor Juhos | 58d2e9b | 2013-02-02 11:40:42 +0000 | [diff] [blame^] | 317 | |
| 318 | static int ar724x_pci_probe(struct platform_device *pdev) |
| 319 | { |
| 320 | struct resource *res; |
| 321 | int irq; |
| 322 | |
| 323 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl_base"); |
| 324 | if (!res) |
| 325 | return -EINVAL; |
| 326 | |
| 327 | ar724x_pci_ctrl_base = devm_request_and_ioremap(&pdev->dev, res); |
| 328 | if (ar724x_pci_ctrl_base == NULL) |
| 329 | return -EBUSY; |
| 330 | |
| 331 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg_base"); |
| 332 | if (!res) |
| 333 | return -EINVAL; |
| 334 | |
| 335 | ar724x_pci_devcfg_base = devm_request_and_ioremap(&pdev->dev, res); |
| 336 | if (!ar724x_pci_devcfg_base) |
| 337 | return -EBUSY; |
| 338 | |
| 339 | irq = platform_get_irq(pdev, 0); |
| 340 | if (irq < 0) |
| 341 | return -EINVAL; |
| 342 | |
| 343 | ar724x_pci_link_up = ar724x_pci_check_link(); |
| 344 | if (!ar724x_pci_link_up) |
| 345 | dev_warn(&pdev->dev, "PCIe link is down\n"); |
| 346 | |
| 347 | ar724x_pci_irq_init(irq); |
| 348 | |
| 349 | register_pci_controller(&ar724x_pci_controller); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static struct platform_driver ar724x_pci_driver = { |
| 355 | .probe = ar724x_pci_probe, |
| 356 | .driver = { |
| 357 | .name = "ar724x-pci", |
| 358 | .owner = THIS_MODULE, |
| 359 | }, |
| 360 | }; |
| 361 | |
| 362 | static int __init ar724x_pci_init(void) |
| 363 | { |
| 364 | return platform_driver_register(&ar724x_pci_driver); |
| 365 | } |
| 366 | |
| 367 | postcore_initcall(ar724x_pci_init); |