blob: ce97816f5d64bf946806fbdff3060b83b63b2873 [file] [log] [blame]
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -06001/*
2 * Designware application register space functions for Keystone PCI controller
3 *
4 * Copyright (C) 2013-2014 Texas Instruments., Ltd.
5 * http://www.ti.com
6 *
7 * Author: Murali Karicheri <m-karicheri2@ti.com>
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/irq.h>
16#include <linux/irqdomain.h>
Murali Karicheri025dd3d2016-04-11 10:50:30 -040017#include <linux/irqreturn.h>
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -060018#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/of_pci.h>
21#include <linux/pci.h>
22#include <linux/platform_device.h>
23
24#include "pcie-designware.h"
25#include "pci-keystone.h"
26
27/* Application register defines */
28#define LTSSM_EN_VAL 1
29#define LTSSM_STATE_MASK 0x1f
30#define LTSSM_STATE_L0 0x11
31#define DBI_CS2_EN_VAL 0x20
32#define OB_XLAT_EN_VAL 2
33
34/* Application registers */
35#define CMD_STATUS 0x004
36#define CFG_SETUP 0x008
37#define OB_SIZE 0x030
38#define CFG_PCIM_WIN_SZ_IDX 3
39#define CFG_PCIM_WIN_CNT 32
40#define SPACE0_REMOTE_CFG_OFFSET 0x1000
41#define OB_OFFSET_INDEX(n) (0x200 + (8 * n))
42#define OB_OFFSET_HI(n) (0x204 + (8 * n))
43
44/* IRQ register defines */
45#define IRQ_EOI 0x050
46#define IRQ_STATUS 0x184
47#define IRQ_ENABLE_SET 0x188
48#define IRQ_ENABLE_CLR 0x18c
49
50#define MSI_IRQ 0x054
51#define MSI0_IRQ_STATUS 0x104
52#define MSI0_IRQ_ENABLE_SET 0x108
53#define MSI0_IRQ_ENABLE_CLR 0x10c
54#define IRQ_STATUS 0x184
55#define MSI_IRQ_OFFSET 4
56
Murali Karicheri025dd3d2016-04-11 10:50:30 -040057/* Error IRQ bits */
58#define ERR_AER BIT(5) /* ECRC error */
59#define ERR_AXI BIT(4) /* AXI tag lookup fatal error */
60#define ERR_CORR BIT(3) /* Correctable error */
61#define ERR_NONFATAL BIT(2) /* Non-fatal error */
62#define ERR_FATAL BIT(1) /* Fatal error */
63#define ERR_SYS BIT(0) /* System (fatal, non-fatal, or correctable) */
64#define ERR_IRQ_ALL (ERR_AER | ERR_AXI | ERR_CORR | \
65 ERR_NONFATAL | ERR_FATAL | ERR_SYS)
66#define ERR_FATAL_IRQ (ERR_FATAL | ERR_AXI)
67#define ERR_IRQ_STATUS_RAW 0x1c0
68#define ERR_IRQ_STATUS 0x1c4
69#define ERR_IRQ_ENABLE_SET 0x1c8
70#define ERR_IRQ_ENABLE_CLR 0x1cc
71
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -060072/* Config space registers */
73#define DEBUG0 0x728
74
75#define to_keystone_pcie(x) container_of(x, struct keystone_pcie, pp)
76
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -060077static inline void update_reg_offset_bit_pos(u32 offset, u32 *reg_offset,
78 u32 *bit_pos)
79{
80 *reg_offset = offset % 8;
81 *bit_pos = offset >> 3;
82}
83
Lucas Stach98a97e62015-09-18 13:58:35 -050084phys_addr_t ks_dw_pcie_get_msi_addr(struct pcie_port *pp)
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -060085{
86 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
87
88 return ks_pcie->app.start + MSI_IRQ;
89}
90
91void ks_dw_pcie_handle_msi_irq(struct keystone_pcie *ks_pcie, int offset)
92{
93 struct pcie_port *pp = &ks_pcie->pp;
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -050094 struct device *dev = pp->dev;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -060095 u32 pending, vector;
96 int src, virq;
97
98 pending = readl(ks_pcie->va_app_base + MSI0_IRQ_STATUS + (offset << 4));
99
100 /*
101 * MSI0 status bit 0-3 shows vectors 0, 8, 16, 24, MSI1 status bit
102 * shows 1, 9, 17, 25 and so forth
103 */
104 for (src = 0; src < 4; src++) {
105 if (BIT(src) & pending) {
106 vector = offset + (src << 3);
107 virq = irq_linear_revmap(pp->irq_domain, vector);
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500108 dev_dbg(dev, "irq: bit %d, vector %d, virq %d\n",
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600109 src, vector, virq);
110 generic_handle_irq(virq);
111 }
112 }
113}
114
115static void ks_dw_pcie_msi_irq_ack(struct irq_data *d)
116{
117 u32 offset, reg_offset, bit_pos;
118 struct keystone_pcie *ks_pcie;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600119 struct msi_desc *msi;
120 struct pcie_port *pp;
121
Jiang Liu40b6d3f2015-06-04 12:13:23 +0800122 msi = irq_data_get_msi_desc(d);
Murali Karicheri79e3f4a2016-02-29 17:18:22 -0600123 pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600124 ks_pcie = to_keystone_pcie(pp);
Jiang Liu40b6d3f2015-06-04 12:13:23 +0800125 offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600126 update_reg_offset_bit_pos(offset, &reg_offset, &bit_pos);
127
128 writel(BIT(bit_pos),
129 ks_pcie->va_app_base + MSI0_IRQ_STATUS + (reg_offset << 4));
130 writel(reg_offset + MSI_IRQ_OFFSET, ks_pcie->va_app_base + IRQ_EOI);
131}
132
133void ks_dw_pcie_msi_set_irq(struct pcie_port *pp, int irq)
134{
135 u32 reg_offset, bit_pos;
136 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
137
138 update_reg_offset_bit_pos(irq, &reg_offset, &bit_pos);
139 writel(BIT(bit_pos),
140 ks_pcie->va_app_base + MSI0_IRQ_ENABLE_SET + (reg_offset << 4));
141}
142
143void ks_dw_pcie_msi_clear_irq(struct pcie_port *pp, int irq)
144{
145 u32 reg_offset, bit_pos;
146 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
147
148 update_reg_offset_bit_pos(irq, &reg_offset, &bit_pos);
149 writel(BIT(bit_pos),
150 ks_pcie->va_app_base + MSI0_IRQ_ENABLE_CLR + (reg_offset << 4));
151}
152
153static void ks_dw_pcie_msi_irq_mask(struct irq_data *d)
154{
155 struct keystone_pcie *ks_pcie;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600156 struct msi_desc *msi;
157 struct pcie_port *pp;
158 u32 offset;
159
Jiang Liu40b6d3f2015-06-04 12:13:23 +0800160 msi = irq_data_get_msi_desc(d);
Murali Karicheri79e3f4a2016-02-29 17:18:22 -0600161 pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600162 ks_pcie = to_keystone_pcie(pp);
Jiang Liu40b6d3f2015-06-04 12:13:23 +0800163 offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600164
165 /* Mask the end point if PVM implemented */
166 if (IS_ENABLED(CONFIG_PCI_MSI)) {
167 if (msi->msi_attrib.maskbit)
Thomas Gleixner280510f2014-11-23 12:23:20 +0100168 pci_msi_mask_irq(d);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600169 }
170
171 ks_dw_pcie_msi_clear_irq(pp, offset);
172}
173
174static void ks_dw_pcie_msi_irq_unmask(struct irq_data *d)
175{
176 struct keystone_pcie *ks_pcie;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600177 struct msi_desc *msi;
178 struct pcie_port *pp;
179 u32 offset;
180
Jiang Liu40b6d3f2015-06-04 12:13:23 +0800181 msi = irq_data_get_msi_desc(d);
Murali Karicheri79e3f4a2016-02-29 17:18:22 -0600182 pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600183 ks_pcie = to_keystone_pcie(pp);
Jiang Liu40b6d3f2015-06-04 12:13:23 +0800184 offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600185
186 /* Mask the end point if PVM implemented */
187 if (IS_ENABLED(CONFIG_PCI_MSI)) {
188 if (msi->msi_attrib.maskbit)
Thomas Gleixner280510f2014-11-23 12:23:20 +0100189 pci_msi_unmask_irq(d);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600190 }
191
192 ks_dw_pcie_msi_set_irq(pp, offset);
193}
194
195static struct irq_chip ks_dw_pcie_msi_irq_chip = {
196 .name = "Keystone-PCIe-MSI-IRQ",
197 .irq_ack = ks_dw_pcie_msi_irq_ack,
198 .irq_mask = ks_dw_pcie_msi_irq_mask,
199 .irq_unmask = ks_dw_pcie_msi_irq_unmask,
200};
201
202static int ks_dw_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
203 irq_hw_number_t hwirq)
204{
205 irq_set_chip_and_handler(irq, &ks_dw_pcie_msi_irq_chip,
206 handle_level_irq);
207 irq_set_chip_data(irq, domain->host_data);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600208
209 return 0;
210}
211
Jingoo Han5ba83682014-10-23 11:10:16 +0900212static const struct irq_domain_ops ks_dw_pcie_msi_domain_ops = {
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600213 .map = ks_dw_pcie_msi_map,
214};
215
Yijing Wangc2791b82014-11-11 17:45:45 -0700216int ks_dw_pcie_msi_host_init(struct pcie_port *pp, struct msi_controller *chip)
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600217{
218 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500219 struct device *dev = pp->dev;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600220 int i;
221
222 pp->irq_domain = irq_domain_add_linear(ks_pcie->msi_intc_np,
223 MAX_MSI_IRQS,
224 &ks_dw_pcie_msi_domain_ops,
225 chip);
226 if (!pp->irq_domain) {
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500227 dev_err(dev, "irq domain init failed\n");
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600228 return -ENXIO;
229 }
230
231 for (i = 0; i < MAX_MSI_IRQS; i++)
232 irq_create_mapping(pp->irq_domain, i);
233
234 return 0;
235}
236
237void ks_dw_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie)
238{
239 int i;
240
241 for (i = 0; i < MAX_LEGACY_IRQS; i++)
242 writel(0x1, ks_pcie->va_app_base + IRQ_ENABLE_SET + (i << 4));
243}
244
245void ks_dw_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie, int offset)
246{
247 struct pcie_port *pp = &ks_pcie->pp;
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500248 struct device *dev = pp->dev;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600249 u32 pending;
250 int virq;
251
252 pending = readl(ks_pcie->va_app_base + IRQ_STATUS + (offset << 4));
253
254 if (BIT(0) & pending) {
255 virq = irq_linear_revmap(ks_pcie->legacy_irq_domain, offset);
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500256 dev_dbg(dev, ": irq: irq_offset %d, virq %d\n", offset, virq);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600257 generic_handle_irq(virq);
258 }
259
260 /* EOI the INTx interrupt */
261 writel(offset, ks_pcie->va_app_base + IRQ_EOI);
262}
263
Murali Karicheri025dd3d2016-04-11 10:50:30 -0400264void ks_dw_pcie_enable_error_irq(void __iomem *reg_base)
265{
266 writel(ERR_IRQ_ALL, reg_base + ERR_IRQ_ENABLE_SET);
267}
268
269irqreturn_t ks_dw_pcie_handle_error_irq(struct device *dev,
270 void __iomem *reg_base)
271{
272 u32 status;
273
274 status = readl(reg_base + ERR_IRQ_STATUS_RAW) & ERR_IRQ_ALL;
275 if (!status)
276 return IRQ_NONE;
277
278 if (status & ERR_FATAL_IRQ)
279 dev_err(dev, "fatal error (status %#010x)\n", status);
280
281 /* Ack the IRQ; status bits are RW1C */
282 writel(status, reg_base + ERR_IRQ_STATUS);
283 return IRQ_HANDLED;
284}
285
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600286static void ks_dw_pcie_ack_legacy_irq(struct irq_data *d)
287{
288}
289
290static void ks_dw_pcie_mask_legacy_irq(struct irq_data *d)
291{
292}
293
294static void ks_dw_pcie_unmask_legacy_irq(struct irq_data *d)
295{
296}
297
298static struct irq_chip ks_dw_pcie_legacy_irq_chip = {
299 .name = "Keystone-PCI-Legacy-IRQ",
300 .irq_ack = ks_dw_pcie_ack_legacy_irq,
301 .irq_mask = ks_dw_pcie_mask_legacy_irq,
302 .irq_unmask = ks_dw_pcie_unmask_legacy_irq,
303};
304
305static int ks_dw_pcie_init_legacy_irq_map(struct irq_domain *d,
306 unsigned int irq, irq_hw_number_t hw_irq)
307{
308 irq_set_chip_and_handler(irq, &ks_dw_pcie_legacy_irq_chip,
309 handle_level_irq);
310 irq_set_chip_data(irq, d->host_data);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600311
312 return 0;
313}
314
315static const struct irq_domain_ops ks_dw_pcie_legacy_irq_domain_ops = {
316 .map = ks_dw_pcie_init_legacy_irq_map,
317 .xlate = irq_domain_xlate_onetwocell,
318};
319
320/**
321 * ks_dw_pcie_set_dbi_mode() - Set DBI mode to access overlaid BAR mask
322 * registers
323 *
324 * Since modification of dbi_cs2 involves different clock domain, read the
325 * status back to ensure the transition is complete.
326 */
327static void ks_dw_pcie_set_dbi_mode(void __iomem *reg_virt)
328{
329 u32 val;
330
331 writel(DBI_CS2_EN_VAL | readl(reg_virt + CMD_STATUS),
332 reg_virt + CMD_STATUS);
333
334 do {
335 val = readl(reg_virt + CMD_STATUS);
336 } while (!(val & DBI_CS2_EN_VAL));
337}
338
339/**
340 * ks_dw_pcie_clear_dbi_mode() - Disable DBI mode
341 *
342 * Since modification of dbi_cs2 involves different clock domain, read the
343 * status back to ensure the transition is complete.
344 */
345static void ks_dw_pcie_clear_dbi_mode(void __iomem *reg_virt)
346{
347 u32 val;
348
349 writel(~DBI_CS2_EN_VAL & readl(reg_virt + CMD_STATUS),
350 reg_virt + CMD_STATUS);
351
352 do {
353 val = readl(reg_virt + CMD_STATUS);
354 } while (val & DBI_CS2_EN_VAL);
355}
356
357void ks_dw_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
358{
359 struct pcie_port *pp = &ks_pcie->pp;
Zhou Wang0021d222015-10-29 19:57:06 -0500360 u32 start = pp->mem->start, end = pp->mem->end;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600361 int i, tr_size;
362
363 /* Disable BARs for inbound access */
364 ks_dw_pcie_set_dbi_mode(ks_pcie->va_app_base);
Bjorn Helgaasf3eca6c2016-10-06 13:36:57 -0500365 dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, 0);
366 dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_1, 0);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600367 ks_dw_pcie_clear_dbi_mode(ks_pcie->va_app_base);
368
369 /* Set outbound translation size per window division */
370 writel(CFG_PCIM_WIN_SZ_IDX & 0x7, ks_pcie->va_app_base + OB_SIZE);
371
372 tr_size = (1 << (CFG_PCIM_WIN_SZ_IDX & 0x7)) * SZ_1M;
373
374 /* Using Direct 1:1 mapping of RC <-> PCI memory space */
375 for (i = 0; (i < CFG_PCIM_WIN_CNT) && (start < end); i++) {
376 writel(start | 1, ks_pcie->va_app_base + OB_OFFSET_INDEX(i));
377 writel(0, ks_pcie->va_app_base + OB_OFFSET_HI(i));
378 start += tr_size;
379 }
380
381 /* Enable OB translation */
382 writel(OB_XLAT_EN_VAL | readl(ks_pcie->va_app_base + CMD_STATUS),
383 ks_pcie->va_app_base + CMD_STATUS);
384}
385
386/**
387 * ks_pcie_cfg_setup() - Set up configuration space address for a device
388 *
389 * @ks_pcie: ptr to keystone_pcie structure
390 * @bus: Bus number the device is residing on
391 * @devfn: device, function number info
392 *
393 * Forms and returns the address of configuration space mapped in PCIESS
394 * address space 0. Also configures CFG_SETUP for remote configuration space
395 * access.
396 *
397 * The address space has two regions to access configuration - local and remote.
398 * We access local region for bus 0 (as RC is attached on bus 0) and remote
399 * region for others with TYPE 1 access when bus > 1. As for device on bus = 1,
400 * we will do TYPE 0 access as it will be on our secondary bus (logical).
401 * CFG_SETUP is needed only for remote configuration access.
402 */
403static void __iomem *ks_pcie_cfg_setup(struct keystone_pcie *ks_pcie, u8 bus,
404 unsigned int devfn)
405{
406 u8 device = PCI_SLOT(devfn), function = PCI_FUNC(devfn);
407 struct pcie_port *pp = &ks_pcie->pp;
408 u32 regval;
409
410 if (bus == 0)
411 return pp->dbi_base;
412
413 regval = (bus << 16) | (device << 8) | function;
414
415 /*
416 * Since Bus#1 will be a virtual bus, we need to have TYPE0
417 * access only.
418 * TYPE 1
419 */
420 if (bus != 1)
421 regval |= BIT(24);
422
423 writel(regval, ks_pcie->va_app_base + CFG_SETUP);
424 return pp->va_cfg0_base;
425}
426
427int ks_dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
428 unsigned int devfn, int where, int size, u32 *val)
429{
430 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
431 u8 bus_num = bus->number;
432 void __iomem *addr;
433
434 addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
435
Gabriele Paoloni4c458522015-10-08 14:27:48 -0500436 return dw_pcie_cfg_read(addr + where, size, val);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600437}
438
439int ks_dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
440 unsigned int devfn, int where, int size, u32 val)
441{
442 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
443 u8 bus_num = bus->number;
444 void __iomem *addr;
445
446 addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
447
Gabriele Paoloni4c458522015-10-08 14:27:48 -0500448 return dw_pcie_cfg_write(addr + where, size, val);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600449}
450
451/**
452 * ks_dw_pcie_v3_65_scan_bus() - keystone scan_bus post initialization
453 *
454 * This sets BAR0 to enable inbound access for MSI_IRQ register
455 */
456void ks_dw_pcie_v3_65_scan_bus(struct pcie_port *pp)
457{
458 struct keystone_pcie *ks_pcie = to_keystone_pcie(pp);
459
460 /* Configure and set up BAR0 */
461 ks_dw_pcie_set_dbi_mode(ks_pcie->va_app_base);
462
463 /* Enable BAR0 */
Bjorn Helgaasf3eca6c2016-10-06 13:36:57 -0500464 dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, 1);
465 dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, SZ_4K - 1);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600466
467 ks_dw_pcie_clear_dbi_mode(ks_pcie->va_app_base);
468
469 /*
470 * For BAR0, just setting bus address for inbound writes (MSI) should
471 * be sufficient. Use physical address to avoid any conflicts.
472 */
Bjorn Helgaasf3eca6c2016-10-06 13:36:57 -0500473 dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, ks_pcie->app.start);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600474}
475
476/**
477 * ks_dw_pcie_link_up() - Check if link up
478 */
479int ks_dw_pcie_link_up(struct pcie_port *pp)
480{
Bjorn Helgaasf3eca6c2016-10-06 13:36:57 -0500481 u32 val;
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600482
Bjorn Helgaasf3eca6c2016-10-06 13:36:57 -0500483 val = dw_pcie_readl_rc(pp, DEBUG0);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600484 return (val & LTSSM_STATE_MASK) == LTSSM_STATE_L0;
485}
486
487void ks_dw_pcie_initiate_link_train(struct keystone_pcie *ks_pcie)
488{
489 u32 val;
490
491 /* Disable Link training */
492 val = readl(ks_pcie->va_app_base + CMD_STATUS);
493 val &= ~LTSSM_EN_VAL;
494 writel(LTSSM_EN_VAL | val, ks_pcie->va_app_base + CMD_STATUS);
495
496 /* Initiate Link Training */
497 val = readl(ks_pcie->va_app_base + CMD_STATUS);
498 writel(LTSSM_EN_VAL | val, ks_pcie->va_app_base + CMD_STATUS);
499}
500
501/**
502 * ks_dw_pcie_host_init() - initialize host for v3_65 dw hardware
503 *
504 * Ioremap the register resources, initialize legacy irq domain
505 * and call dw_pcie_v3_65_host_init() API to initialize the Keystone
506 * PCI host controller.
507 */
508int __init ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie,
509 struct device_node *msi_intc_np)
510{
511 struct pcie_port *pp = &ks_pcie->pp;
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500512 struct device *dev = pp->dev;
513 struct platform_device *pdev = to_platform_device(dev);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600514 struct resource *res;
515
516 /* Index 0 is the config reg. space address */
517 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500518 pp->dbi_base = devm_ioremap_resource(dev, res);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600519 if (IS_ERR(pp->dbi_base))
520 return PTR_ERR(pp->dbi_base);
521
522 /*
523 * We set these same and is used in pcie rd/wr_other_conf
524 * functions
525 */
526 pp->va_cfg0_base = pp->dbi_base + SPACE0_REMOTE_CFG_OFFSET;
527 pp->va_cfg1_base = pp->va_cfg0_base;
528
529 /* Index 1 is the application reg. space address */
530 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500531 ks_pcie->va_app_base = devm_ioremap_resource(dev, res);
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600532 if (IS_ERR(ks_pcie->va_app_base))
533 return PTR_ERR(ks_pcie->va_app_base);
534
Bjorn Helgaasf76ea572015-04-09 14:34:10 -0500535 ks_pcie->app = *res;
536
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600537 /* Create legacy IRQ domain */
538 ks_pcie->legacy_irq_domain =
539 irq_domain_add_linear(ks_pcie->legacy_intc_np,
540 MAX_LEGACY_IRQS,
541 &ks_dw_pcie_legacy_irq_domain_ops,
542 NULL);
543 if (!ks_pcie->legacy_irq_domain) {
Bjorn Helgaas21fa0c52016-10-11 22:48:42 -0500544 dev_err(dev, "Failed to add irq domain for legacy irqs\n");
Murali Karicheri0c4ffcf2014-09-02 17:26:19 -0600545 return -EINVAL;
546 }
547
548 return dw_pcie_host_init(pp);
549}