blob: 869d5c9a2f8d7e5ed82bc31a4066669aa543860a [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Rene Bolldorf4ff40d52011-11-17 14:25:09 +00002/*
Gabor Juhose9b62e82012-03-14 10:36:14 +01003 * Atheros AR724X PCI host controller driver
Rene Bolldorf4ff40d52011-11-17 14:25:09 +00004 *
5 * Copyright (C) 2011 René Bolldorf <xsecute@googlemail.com>
Gabor Juhose9b62e82012-03-14 10:36:14 +01006 * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
Rene Bolldorf4ff40d52011-11-17 14:25:09 +00007 */
8
Gabor Juhos4c07c7d2012-03-14 10:36:07 +01009#include <linux/irq.h>
Rene Bolldorf4ff40d52011-11-17 14:25:09 +000010#include <linux/pci.h>
Paul Gortmaker27220902016-08-21 15:58:16 -040011#include <linux/init.h>
Mathias Kresin0316b052018-07-20 13:58:25 +020012#include <linux/delay.h>
Gabor Juhos58d2e9b2013-02-02 11:40:42 +000013#include <linux/platform_device.h>
Gabor Juhos6015a852012-03-14 10:36:05 +010014#include <asm/mach-ath79/ath79.h>
Gabor Juhos4c07c7d2012-03-14 10:36:07 +010015#include <asm/mach-ath79/ar71xx_regs.h>
Rene Bolldorf4ff40d52011-11-17 14:25:09 +000016
Mathias Kresin0316b052018-07-20 13:58:25 +020017#define AR724X_PCI_REG_APP 0x00
Gabor Juhosa1dca312012-08-23 15:35:26 +020018#define AR724X_PCI_REG_RESET 0x18
Gabor Juhos4c07c7d2012-03-14 10:36:07 +010019#define AR724X_PCI_REG_INT_STATUS 0x4c
20#define AR724X_PCI_REG_INT_MASK 0x50
21
Mathias Kresin0316b052018-07-20 13:58:25 +020022#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
23
Gabor Juhosa1dca312012-08-23 15:35:26 +020024#define AR724X_PCI_RESET_LINK_UP BIT(0)
25
Gabor Juhos4c07c7d2012-03-14 10:36:07 +010026#define AR724X_PCI_INT_DEV0 BIT(14)
27
28#define AR724X_PCI_IRQ_COUNT 1
29
Gabor Juhos6015a852012-03-14 10:36:05 +010030#define AR7240_BAR0_WAR_VALUE 0xffff
31
Gabor Juhos12401fc2013-02-03 14:52:47 +000032#define AR724X_PCI_CMD_INIT (PCI_COMMAND_MEMORY | \
33 PCI_COMMAND_MASTER | \
34 PCI_COMMAND_INVALIDATE | \
35 PCI_COMMAND_PARITY | \
36 PCI_COMMAND_SERR | \
37 PCI_COMMAND_FAST_BACK)
38
Gabor Juhos908339e2013-02-03 09:58:38 +000039struct ar724x_pci_controller {
40 void __iomem *devcfg_base;
41 void __iomem *ctrl_base;
Gabor Juhos12401fc2013-02-03 14:52:47 +000042 void __iomem *crp_base;
Rene Bolldorf4ff40d52011-11-17 14:25:09 +000043
Gabor Juhos908339e2013-02-03 09:58:38 +000044 int irq;
Gabor Juhos8b66d462013-02-03 10:00:16 +000045 int irq_base;
Gabor Juhosa1dca312012-08-23 15:35:26 +020046
Gabor Juhos908339e2013-02-03 09:58:38 +000047 bool link_up;
48 bool bar0_is_cached;
49 u32 bar0_value;
50
Gabor Juhos908339e2013-02-03 09:58:38 +000051 struct pci_controller pci_controller;
Gabor Juhos34b134a2013-02-03 09:59:45 +000052 struct resource io_res;
53 struct resource mem_res;
Gabor Juhos908339e2013-02-03 09:58:38 +000054};
55
56static inline bool ar724x_pci_check_link(struct ar724x_pci_controller *apc)
Gabor Juhosa1dca312012-08-23 15:35:26 +020057{
58 u32 reset;
59
Gabor Juhos908339e2013-02-03 09:58:38 +000060 reset = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_RESET);
Gabor Juhosa1dca312012-08-23 15:35:26 +020061 return reset & AR724X_PCI_RESET_LINK_UP;
62}
Gabor Juhos6015a852012-03-14 10:36:05 +010063
Gabor Juhos908339e2013-02-03 09:58:38 +000064static inline struct ar724x_pci_controller *
65pci_bus_to_ar724x_controller(struct pci_bus *bus)
66{
67 struct pci_controller *hose;
68
69 hose = (struct pci_controller *) bus->sysdata;
70 return container_of(hose, struct ar724x_pci_controller, pci_controller);
71}
72
Gabor Juhos12401fc2013-02-03 14:52:47 +000073static int ar724x_pci_local_write(struct ar724x_pci_controller *apc,
74 int where, int size, u32 value)
75{
Gabor Juhos12401fc2013-02-03 14:52:47 +000076 void __iomem *base;
77 u32 data;
78 int s;
79
80 WARN_ON(where & (size - 1));
81
82 if (!apc->link_up)
83 return PCIBIOS_DEVICE_NOT_FOUND;
84
85 base = apc->crp_base;
Gabor Juhos12401fc2013-02-03 14:52:47 +000086 data = __raw_readl(base + (where & ~3));
87
88 switch (size) {
89 case 1:
90 s = ((where & 3) * 8);
91 data &= ~(0xff << s);
92 data |= ((value & 0xff) << s);
93 break;
94 case 2:
95 s = ((where & 2) * 8);
96 data &= ~(0xffff << s);
97 data |= ((value & 0xffff) << s);
98 break;
99 case 4:
100 data = value;
101 break;
102 default:
Gabor Juhos12401fc2013-02-03 14:52:47 +0000103 return PCIBIOS_BAD_REGISTER_NUMBER;
104 }
105
106 __raw_writel(data, base + (where & ~3));
107 /* flush write */
108 __raw_readl(base + (where & ~3));
Gabor Juhos12401fc2013-02-03 14:52:47 +0000109
110 return PCIBIOS_SUCCESSFUL;
111}
112
Gabor Juhosd624bd32012-03-14 10:29:26 +0100113static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000114 int size, uint32_t *value)
115{
Gabor Juhos908339e2013-02-03 09:58:38 +0000116 struct ar724x_pci_controller *apc;
Gabor Juhosc1984412012-03-14 10:29:27 +0100117 void __iomem *base;
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100118 u32 data;
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000119
Gabor Juhos908339e2013-02-03 09:58:38 +0000120 apc = pci_bus_to_ar724x_controller(bus);
121 if (!apc->link_up)
Gabor Juhosa1dca312012-08-23 15:35:26 +0200122 return PCIBIOS_DEVICE_NOT_FOUND;
123
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000124 if (devfn)
125 return PCIBIOS_DEVICE_NOT_FOUND;
126
Gabor Juhos908339e2013-02-03 09:58:38 +0000127 base = apc->devcfg_base;
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100128 data = __raw_readl(base + (where & ~3));
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000129
130 switch (size) {
131 case 1:
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100132 if (where & 1)
133 data >>= 8;
134 if (where & 2)
135 data >>= 16;
136 data &= 0xff;
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000137 break;
138 case 2:
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100139 if (where & 2)
140 data >>= 16;
141 data &= 0xffff;
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000142 break;
143 case 4:
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000144 break;
145 default:
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000146 return PCIBIOS_BAD_REGISTER_NUMBER;
147 }
148
Gabor Juhos6015a852012-03-14 10:36:05 +0100149 if (where == PCI_BASE_ADDRESS_0 && size == 4 &&
Gabor Juhos908339e2013-02-03 09:58:38 +0000150 apc->bar0_is_cached) {
Gabor Juhos6015a852012-03-14 10:36:05 +0100151 /* use the cached value */
Gabor Juhos908339e2013-02-03 09:58:38 +0000152 *value = apc->bar0_value;
Gabor Juhos6015a852012-03-14 10:36:05 +0100153 } else {
154 *value = data;
155 }
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000156
157 return PCIBIOS_SUCCESSFUL;
158}
159
Gabor Juhosd624bd32012-03-14 10:29:26 +0100160static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000161 int size, uint32_t value)
162{
Gabor Juhos908339e2013-02-03 09:58:38 +0000163 struct ar724x_pci_controller *apc;
Gabor Juhosc1984412012-03-14 10:29:27 +0100164 void __iomem *base;
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100165 u32 data;
166 int s;
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000167
Gabor Juhos908339e2013-02-03 09:58:38 +0000168 apc = pci_bus_to_ar724x_controller(bus);
169 if (!apc->link_up)
Gabor Juhosa1dca312012-08-23 15:35:26 +0200170 return PCIBIOS_DEVICE_NOT_FOUND;
171
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000172 if (devfn)
173 return PCIBIOS_DEVICE_NOT_FOUND;
174
Gabor Juhos6015a852012-03-14 10:36:05 +0100175 if (soc_is_ar7240() && where == PCI_BASE_ADDRESS_0 && size == 4) {
176 if (value != 0xffffffff) {
177 /*
178 * WAR for a hw issue. If the BAR0 register of the
179 * device is set to the proper base address, the
180 * memory space of the device is not accessible.
181 *
182 * Cache the intended value so it can be read back,
183 * and write a SoC specific constant value to the
184 * BAR0 register in order to make the device memory
185 * accessible.
186 */
Gabor Juhos908339e2013-02-03 09:58:38 +0000187 apc->bar0_is_cached = true;
188 apc->bar0_value = value;
Gabor Juhos6015a852012-03-14 10:36:05 +0100189
190 value = AR7240_BAR0_WAR_VALUE;
191 } else {
Gabor Juhos908339e2013-02-03 09:58:38 +0000192 apc->bar0_is_cached = false;
Gabor Juhos6015a852012-03-14 10:36:05 +0100193 }
194 }
195
Gabor Juhos908339e2013-02-03 09:58:38 +0000196 base = apc->devcfg_base;
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100197 data = __raw_readl(base + (where & ~3));
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000198
199 switch (size) {
200 case 1:
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100201 s = ((where & 3) * 8);
202 data &= ~(0xff << s);
203 data |= ((value & 0xff) << s);
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000204 break;
205 case 2:
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100206 s = ((where & 2) * 8);
207 data &= ~(0xffff << s);
208 data |= ((value & 0xffff) << s);
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000209 break;
210 case 4:
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100211 data = value;
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000212 break;
213 default:
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000214 return PCIBIOS_BAD_REGISTER_NUMBER;
215 }
216
Gabor Juhos64adb6b2012-03-14 10:36:04 +0100217 __raw_writel(data, base + (where & ~3));
218 /* flush write */
219 __raw_readl(base + (where & ~3));
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000220
221 return PCIBIOS_SUCCESSFUL;
222}
223
Gabor Juhosd624bd32012-03-14 10:29:26 +0100224static struct pci_ops ar724x_pci_ops = {
225 .read = ar724x_pci_read,
226 .write = ar724x_pci_write,
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000227};
228
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200229static void ar724x_pci_irq_handler(struct irq_desc *desc)
Rene Bolldorf4ff40d52011-11-17 14:25:09 +0000230{
Gabor Juhos908339e2013-02-03 09:58:38 +0000231 struct ar724x_pci_controller *apc;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100232 void __iomem *base;
233 u32 pending;
234
Jiang Liu25aae562015-05-20 17:59:51 +0800235 apc = irq_desc_get_handler_data(desc);
Gabor Juhos908339e2013-02-03 09:58:38 +0000236 base = apc->ctrl_base;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100237
238 pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
239 __raw_readl(base + AR724X_PCI_REG_INT_MASK);
240
241 if (pending & AR724X_PCI_INT_DEV0)
Gabor Juhos8b66d462013-02-03 10:00:16 +0000242 generic_handle_irq(apc->irq_base + 0);
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100243
244 else
245 spurious_interrupt();
246}
247
248static void ar724x_pci_irq_unmask(struct irq_data *d)
249{
Gabor Juhos908339e2013-02-03 09:58:38 +0000250 struct ar724x_pci_controller *apc;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100251 void __iomem *base;
Gabor Juhos8b66d462013-02-03 10:00:16 +0000252 int offset;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100253 u32 t;
254
Gabor Juhos908339e2013-02-03 09:58:38 +0000255 apc = irq_data_get_irq_chip_data(d);
256 base = apc->ctrl_base;
Gabor Juhos8b66d462013-02-03 10:00:16 +0000257 offset = apc->irq_base - d->irq;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100258
Gabor Juhos8b66d462013-02-03 10:00:16 +0000259 switch (offset) {
260 case 0:
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100261 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
262 __raw_writel(t | AR724X_PCI_INT_DEV0,
263 base + AR724X_PCI_REG_INT_MASK);
264 /* flush write */
265 __raw_readl(base + AR724X_PCI_REG_INT_MASK);
266 }
267}
268
269static void ar724x_pci_irq_mask(struct irq_data *d)
270{
Gabor Juhos908339e2013-02-03 09:58:38 +0000271 struct ar724x_pci_controller *apc;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100272 void __iomem *base;
Gabor Juhos8b66d462013-02-03 10:00:16 +0000273 int offset;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100274 u32 t;
275
Gabor Juhos908339e2013-02-03 09:58:38 +0000276 apc = irq_data_get_irq_chip_data(d);
277 base = apc->ctrl_base;
Gabor Juhos8b66d462013-02-03 10:00:16 +0000278 offset = apc->irq_base - d->irq;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100279
Gabor Juhos8b66d462013-02-03 10:00:16 +0000280 switch (offset) {
281 case 0:
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100282 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
283 __raw_writel(t & ~AR724X_PCI_INT_DEV0,
284 base + AR724X_PCI_REG_INT_MASK);
285
286 /* flush write */
287 __raw_readl(base + AR724X_PCI_REG_INT_MASK);
288
289 t = __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
290 __raw_writel(t | AR724X_PCI_INT_DEV0,
291 base + AR724X_PCI_REG_INT_STATUS);
292
293 /* flush write */
294 __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
295 }
296}
297
298static struct irq_chip ar724x_pci_irq_chip = {
299 .name = "AR724X PCI ",
300 .irq_mask = ar724x_pci_irq_mask,
301 .irq_unmask = ar724x_pci_irq_unmask,
302 .irq_mask_ack = ar724x_pci_irq_mask,
303};
304
Gabor Juhos8b66d462013-02-03 10:00:16 +0000305static void ar724x_pci_irq_init(struct ar724x_pci_controller *apc,
306 int id)
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100307{
308 void __iomem *base;
309 int i;
310
Gabor Juhos908339e2013-02-03 09:58:38 +0000311 base = apc->ctrl_base;
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100312
313 __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
314 __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
315
Gabor Juhos8b66d462013-02-03 10:00:16 +0000316 apc->irq_base = ATH79_PCI_IRQ_BASE + (id * AR724X_PCI_IRQ_COUNT);
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100317
Gabor Juhos8b66d462013-02-03 10:00:16 +0000318 for (i = apc->irq_base;
319 i < apc->irq_base + AR724X_PCI_IRQ_COUNT; i++) {
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100320 irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
321 handle_level_irq);
Gabor Juhos908339e2013-02-03 09:58:38 +0000322 irq_set_chip_data(i, apc);
323 }
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100324
Thomas Gleixner4d3f77d2015-07-13 20:45:56 +0000325 irq_set_chained_handler_and_data(apc->irq, ar724x_pci_irq_handler,
326 apc);
Gabor Juhos4c07c7d2012-03-14 10:36:07 +0100327}
328
Mathias Kresin0316b052018-07-20 13:58:25 +0200329static void ar724x_pci_hw_init(struct ar724x_pci_controller *apc)
330{
331 u32 ppl, app;
332 int wait = 0;
333
334 /* deassert PCIe host controller and PCIe PHY reset */
335 ath79_device_reset_clear(AR724X_RESET_PCIE);
336 ath79_device_reset_clear(AR724X_RESET_PCIE_PHY);
337
338 /* remove the reset of the PCIE PLL */
339 ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
340 ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_RESET;
341 ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
342
343 /* deassert bypass for the PCIE PLL */
344 ppl = ath79_pll_rr(AR724X_PLL_REG_PCIE_CONFIG);
345 ppl &= ~AR724X_PLL_REG_PCIE_CONFIG_PPL_BYPASS;
346 ath79_pll_wr(AR724X_PLL_REG_PCIE_CONFIG, ppl);
347
348 /* set PCIE Application Control to ready */
349 app = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_APP);
350 app |= AR724X_PCI_APP_LTSSM_ENABLE;
351 __raw_writel(app, apc->ctrl_base + AR724X_PCI_REG_APP);
352
353 /* wait up to 100ms for PHY link up */
354 do {
355 mdelay(10);
356 wait++;
357 } while (wait < 10 && !ar724x_pci_check_link(apc));
358}
359
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000360static int ar724x_pci_probe(struct platform_device *pdev)
361{
Gabor Juhos908339e2013-02-03 09:58:38 +0000362 struct ar724x_pci_controller *apc;
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000363 struct resource *res;
Gabor Juhos8b66d462013-02-03 10:00:16 +0000364 int id;
365
366 id = pdev->id;
367 if (id == -1)
368 id = 0;
Gabor Juhos908339e2013-02-03 09:58:38 +0000369
370 apc = devm_kzalloc(&pdev->dev, sizeof(struct ar724x_pci_controller),
371 GFP_KERNEL);
372 if (!apc)
373 return -ENOMEM;
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000374
375 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl_base");
Silviu-Mihai Popescuf560fab2013-03-12 10:30:05 +0000376 apc->ctrl_base = devm_ioremap_resource(&pdev->dev, res);
377 if (IS_ERR(apc->ctrl_base))
378 return PTR_ERR(apc->ctrl_base);
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000379
380 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg_base");
Silviu-Mihai Popescuf560fab2013-03-12 10:30:05 +0000381 apc->devcfg_base = devm_ioremap_resource(&pdev->dev, res);
382 if (IS_ERR(apc->devcfg_base))
383 return PTR_ERR(apc->devcfg_base);
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000384
Gabor Juhos12401fc2013-02-03 14:52:47 +0000385 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "crp_base");
Silviu-Mihai Popescuf560fab2013-03-12 10:30:05 +0000386 apc->crp_base = devm_ioremap_resource(&pdev->dev, res);
387 if (IS_ERR(apc->crp_base))
388 return PTR_ERR(apc->crp_base);
Gabor Juhos12401fc2013-02-03 14:52:47 +0000389
Gabor Juhos908339e2013-02-03 09:58:38 +0000390 apc->irq = platform_get_irq(pdev, 0);
391 if (apc->irq < 0)
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000392 return -EINVAL;
393
Gabor Juhos34b134a2013-02-03 09:59:45 +0000394 res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
395 if (!res)
396 return -EINVAL;
397
398 apc->io_res.parent = res;
399 apc->io_res.name = "PCI IO space";
400 apc->io_res.start = res->start;
401 apc->io_res.end = res->end;
402 apc->io_res.flags = IORESOURCE_IO;
403
404 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
405 if (!res)
406 return -EINVAL;
407
408 apc->mem_res.parent = res;
409 apc->mem_res.name = "PCI memory space";
410 apc->mem_res.start = res->start;
411 apc->mem_res.end = res->end;
412 apc->mem_res.flags = IORESOURCE_MEM;
413
Gabor Juhos908339e2013-02-03 09:58:38 +0000414 apc->pci_controller.pci_ops = &ar724x_pci_ops;
Gabor Juhos34b134a2013-02-03 09:59:45 +0000415 apc->pci_controller.io_resource = &apc->io_res;
416 apc->pci_controller.mem_resource = &apc->mem_res;
Gabor Juhos908339e2013-02-03 09:58:38 +0000417
Mathias Kresin0316b052018-07-20 13:58:25 +0200418 /*
419 * Do the full PCIE Root Complex Initialization Sequence if the PCIe
420 * host controller is in reset.
421 */
422 if (ath79_reset_rr(AR724X_RESET_REG_RESET_MODULE) & AR724X_RESET_PCIE)
423 ar724x_pci_hw_init(apc);
424
Gabor Juhos908339e2013-02-03 09:58:38 +0000425 apc->link_up = ar724x_pci_check_link(apc);
426 if (!apc->link_up)
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000427 dev_warn(&pdev->dev, "PCIe link is down\n");
428
Gabor Juhos8b66d462013-02-03 10:00:16 +0000429 ar724x_pci_irq_init(apc, id);
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000430
Gabor Juhos12401fc2013-02-03 14:52:47 +0000431 ar724x_pci_local_write(apc, PCI_COMMAND, 4, AR724X_PCI_CMD_INIT);
432
Gabor Juhos908339e2013-02-03 09:58:38 +0000433 register_pci_controller(&apc->pci_controller);
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000434
435 return 0;
436}
437
438static struct platform_driver ar724x_pci_driver = {
439 .probe = ar724x_pci_probe,
440 .driver = {
441 .name = "ar724x-pci",
Gabor Juhos58d2e9b2013-02-02 11:40:42 +0000442 },
443};
444
445static int __init ar724x_pci_init(void)
446{
447 return platform_driver_register(&ar724x_pci_driver);
448}
449
450postcore_initcall(ar724x_pci_init);