blob: 47394bdba71ab90df12ceb191f45dfbfc4aa7100 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Minghuan Liana4d6b612014-10-31 13:43:44 +08002/*
Wasim Khan4a0e9be2019-11-15 09:23:34 +00003 * Copyright 2017-2019 NXP
Minghuan Lianfdab5452015-01-21 17:29:20 +08004 * Copyright 2014-2015 Freescale Semiconductor, Inc.
Minghuan Liana4d6b612014-10-31 13:43:44 +08005 * Layerscape PCIe driver
Minghuan Liana4d6b612014-10-31 13:43:44 +08006 */
7
8#include <common.h>
9#include <asm/arch/fsl_serdes.h>
10#include <pci.h>
11#include <asm/io.h>
Minghuan Lianfdab5452015-01-21 17:29:20 +080012#include <errno.h>
13#include <malloc.h>
Minghuan Lianc1067842016-12-13 14:54:17 +080014#include <dm.h>
Simon Glass243182c2017-05-17 08:23:06 -060015#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
16 defined(CONFIG_ARM)
17#include <asm/arch/clock.h>
18#endif
Hou Zhiqiang09716a7b2016-12-13 14:54:16 +080019#include "pcie_layerscape.h"
Minghuan Lianfdab5452015-01-21 17:29:20 +080020
Minghuan Lianc1067842016-12-13 14:54:17 +080021DECLARE_GLOBAL_DATA_PTR;
22
Minghuan Lianc1067842016-12-13 14:54:17 +080023LIST_HEAD(ls_pcie_list);
24
25static unsigned int dbi_readl(struct ls_pcie *pcie, unsigned int offset)
26{
27 return in_le32(pcie->dbi + offset);
28}
29
30static void dbi_writel(struct ls_pcie *pcie, unsigned int value,
31 unsigned int offset)
32{
33 out_le32(pcie->dbi + offset, value);
34}
35
36static unsigned int ctrl_readl(struct ls_pcie *pcie, unsigned int offset)
37{
38 if (pcie->big_endian)
39 return in_be32(pcie->ctrl + offset);
40 else
41 return in_le32(pcie->ctrl + offset);
42}
43
44static void ctrl_writel(struct ls_pcie *pcie, unsigned int value,
45 unsigned int offset)
46{
47 if (pcie->big_endian)
48 out_be32(pcie->ctrl + offset, value);
49 else
50 out_le32(pcie->ctrl + offset, value);
51}
52
53static int ls_pcie_ltssm(struct ls_pcie *pcie)
54{
55 u32 state;
56 uint svr;
57
58 svr = get_svr();
59 if (((svr >> SVR_VAR_PER_SHIFT) & SVR_LS102XA_MASK) == SVR_LS102XA) {
60 state = ctrl_readl(pcie, LS1021_PEXMSCPORTSR(pcie->idx));
61 state = (state >> LS1021_LTSSM_STATE_SHIFT) & LTSSM_STATE_MASK;
62 } else {
63 state = ctrl_readl(pcie, PCIE_PF_DBG) & LTSSM_STATE_MASK;
64 }
65
66 return state;
67}
68
69static int ls_pcie_link_up(struct ls_pcie *pcie)
70{
71 int ltssm;
72
73 ltssm = ls_pcie_ltssm(pcie);
74 if (ltssm < LTSSM_PCIE_L0)
75 return 0;
76
77 return 1;
78}
79
80static void ls_pcie_cfg0_set_busdev(struct ls_pcie *pcie, u32 busdev)
81{
82 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
83 PCIE_ATU_VIEWPORT);
84 dbi_writel(pcie, busdev, PCIE_ATU_LOWER_TARGET);
85}
86
87static void ls_pcie_cfg1_set_busdev(struct ls_pcie *pcie, u32 busdev)
88{
89 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
90 PCIE_ATU_VIEWPORT);
91 dbi_writel(pcie, busdev, PCIE_ATU_LOWER_TARGET);
92}
93
94static void ls_pcie_atu_outbound_set(struct ls_pcie *pcie, int idx, int type,
95 u64 phys, u64 bus_addr, pci_size_t size)
96{
97 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | idx, PCIE_ATU_VIEWPORT);
98 dbi_writel(pcie, (u32)phys, PCIE_ATU_LOWER_BASE);
99 dbi_writel(pcie, phys >> 32, PCIE_ATU_UPPER_BASE);
100 dbi_writel(pcie, (u32)phys + size - 1, PCIE_ATU_LIMIT);
101 dbi_writel(pcie, (u32)bus_addr, PCIE_ATU_LOWER_TARGET);
102 dbi_writel(pcie, bus_addr >> 32, PCIE_ATU_UPPER_TARGET);
103 dbi_writel(pcie, type, PCIE_ATU_CR1);
104 dbi_writel(pcie, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
105}
106
107/* Use bar match mode and MEM type as default */
108static void ls_pcie_atu_inbound_set(struct ls_pcie *pcie, int idx,
109 int bar, u64 phys)
110{
111 dbi_writel(pcie, PCIE_ATU_REGION_INBOUND | idx, PCIE_ATU_VIEWPORT);
112 dbi_writel(pcie, (u32)phys, PCIE_ATU_LOWER_TARGET);
113 dbi_writel(pcie, phys >> 32, PCIE_ATU_UPPER_TARGET);
114 dbi_writel(pcie, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1);
115 dbi_writel(pcie, PCIE_ATU_ENABLE | PCIE_ATU_BAR_MODE_ENABLE |
116 PCIE_ATU_BAR_NUM(bar), PCIE_ATU_CR2);
117}
118
119static void ls_pcie_dump_atu(struct ls_pcie *pcie)
120{
121 int i;
122
123 for (i = 0; i < PCIE_ATU_REGION_NUM; i++) {
124 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | i,
125 PCIE_ATU_VIEWPORT);
126 debug("iATU%d:\n", i);
127 debug("\tLOWER PHYS 0x%08x\n",
128 dbi_readl(pcie, PCIE_ATU_LOWER_BASE));
129 debug("\tUPPER PHYS 0x%08x\n",
130 dbi_readl(pcie, PCIE_ATU_UPPER_BASE));
131 debug("\tLOWER BUS 0x%08x\n",
132 dbi_readl(pcie, PCIE_ATU_LOWER_TARGET));
133 debug("\tUPPER BUS 0x%08x\n",
134 dbi_readl(pcie, PCIE_ATU_UPPER_TARGET));
135 debug("\tLIMIT 0x%08x\n",
136 readl(pcie->dbi + PCIE_ATU_LIMIT));
137 debug("\tCR1 0x%08x\n",
138 dbi_readl(pcie, PCIE_ATU_CR1));
139 debug("\tCR2 0x%08x\n",
140 dbi_readl(pcie, PCIE_ATU_CR2));
141 }
142}
143
144static void ls_pcie_setup_atu(struct ls_pcie *pcie)
145{
146 struct pci_region *io, *mem, *pref;
147 unsigned long long offset = 0;
148 int idx = 0;
149 uint svr;
150
151 svr = get_svr();
152 if (((svr >> SVR_VAR_PER_SHIFT) & SVR_LS102XA_MASK) == SVR_LS102XA) {
153 offset = LS1021_PCIE_SPACE_OFFSET +
154 LS1021_PCIE_SPACE_SIZE * pcie->idx;
155 }
156
157 /* ATU 0 : OUTBOUND : CFG0 */
158 ls_pcie_atu_outbound_set(pcie, PCIE_ATU_REGION_INDEX0,
159 PCIE_ATU_TYPE_CFG0,
160 pcie->cfg_res.start + offset,
161 0,
162 fdt_resource_size(&pcie->cfg_res) / 2);
163 /* ATU 1 : OUTBOUND : CFG1 */
164 ls_pcie_atu_outbound_set(pcie, PCIE_ATU_REGION_INDEX1,
165 PCIE_ATU_TYPE_CFG1,
166 pcie->cfg_res.start + offset +
167 fdt_resource_size(&pcie->cfg_res) / 2,
168 0,
169 fdt_resource_size(&pcie->cfg_res) / 2);
170
171 pci_get_regions(pcie->bus, &io, &mem, &pref);
172 idx = PCIE_ATU_REGION_INDEX1 + 1;
173
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800174 /* Fix the pcie memory map for LS2088A series SoCs */
175 svr = (svr >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
176 if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
Priyanka Jain2b361782017-04-27 15:08:06 +0530177 svr == SVR_LS2048A || svr == SVR_LS2044A ||
178 svr == SVR_LS2081A || svr == SVR_LS2041A) {
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800179 if (io)
180 io->phys_start = (io->phys_start &
181 (PCIE_PHYS_SIZE - 1)) +
182 LS2088A_PCIE1_PHYS_ADDR +
183 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
184 if (mem)
185 mem->phys_start = (mem->phys_start &
186 (PCIE_PHYS_SIZE - 1)) +
187 LS2088A_PCIE1_PHYS_ADDR +
188 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
189 if (pref)
190 pref->phys_start = (pref->phys_start &
191 (PCIE_PHYS_SIZE - 1)) +
192 LS2088A_PCIE1_PHYS_ADDR +
193 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
194 }
195
Minghuan Lianc1067842016-12-13 14:54:17 +0800196 if (io)
197 /* ATU : OUTBOUND : IO */
198 ls_pcie_atu_outbound_set(pcie, idx++,
199 PCIE_ATU_TYPE_IO,
200 io->phys_start + offset,
201 io->bus_start,
202 io->size);
203
204 if (mem)
205 /* ATU : OUTBOUND : MEM */
206 ls_pcie_atu_outbound_set(pcie, idx++,
207 PCIE_ATU_TYPE_MEM,
208 mem->phys_start + offset,
209 mem->bus_start,
210 mem->size);
211
212 if (pref)
213 /* ATU : OUTBOUND : pref */
214 ls_pcie_atu_outbound_set(pcie, idx++,
215 PCIE_ATU_TYPE_MEM,
216 pref->phys_start + offset,
217 pref->bus_start,
218 pref->size);
219
220 ls_pcie_dump_atu(pcie);
221}
222
223/* Return 0 if the address is valid, -errno if not valid */
224static int ls_pcie_addr_valid(struct ls_pcie *pcie, pci_dev_t bdf)
225{
226 struct udevice *bus = pcie->bus;
227
Xiaowei Bao4da0ae22018-10-26 09:56:25 +0800228 if (pcie->mode == PCI_HEADER_TYPE_NORMAL)
229 return -ENODEV;
230
Minghuan Lianc1067842016-12-13 14:54:17 +0800231 if (!pcie->enabled)
232 return -ENXIO;
233
234 if (PCI_BUS(bdf) < bus->seq)
235 return -EINVAL;
236
237 if ((PCI_BUS(bdf) > bus->seq) && (!ls_pcie_link_up(pcie)))
238 return -EINVAL;
239
240 if (PCI_BUS(bdf) <= (bus->seq + 1) && (PCI_DEV(bdf) > 0))
241 return -EINVAL;
242
243 return 0;
244}
245
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300246int ls_pcie_conf_address(struct udevice *bus, pci_dev_t bdf,
247 uint offset, void **paddress)
Minghuan Lianc1067842016-12-13 14:54:17 +0800248{
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300249 struct ls_pcie *pcie = dev_get_priv(bus);
Minghuan Lianc1067842016-12-13 14:54:17 +0800250 u32 busdev;
251
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300252 if (ls_pcie_addr_valid(pcie, bdf))
253 return -EINVAL;
254
255 if (PCI_BUS(bdf) == bus->seq) {
256 *paddress = pcie->dbi + offset;
257 return 0;
258 }
Minghuan Lianc1067842016-12-13 14:54:17 +0800259
Minghuan Liana1c94382017-10-20 10:45:50 +0800260 busdev = PCIE_ATU_BUS(PCI_BUS(bdf) - bus->seq) |
Minghuan Lianc1067842016-12-13 14:54:17 +0800261 PCIE_ATU_DEV(PCI_DEV(bdf)) |
262 PCIE_ATU_FUNC(PCI_FUNC(bdf));
263
264 if (PCI_BUS(bdf) == bus->seq + 1) {
265 ls_pcie_cfg0_set_busdev(pcie, busdev);
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300266 *paddress = pcie->cfg0 + offset;
Minghuan Lianc1067842016-12-13 14:54:17 +0800267 } else {
268 ls_pcie_cfg1_set_busdev(pcie, busdev);
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300269 *paddress = pcie->cfg1 + offset;
Minghuan Lianc1067842016-12-13 14:54:17 +0800270 }
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300271 return 0;
Minghuan Lianc1067842016-12-13 14:54:17 +0800272}
273
274static int ls_pcie_read_config(struct udevice *bus, pci_dev_t bdf,
275 uint offset, ulong *valuep,
276 enum pci_size_t size)
277{
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300278 return pci_generic_mmap_read_config(bus, ls_pcie_conf_address,
279 bdf, offset, valuep, size);
Minghuan Lianc1067842016-12-13 14:54:17 +0800280}
281
282static int ls_pcie_write_config(struct udevice *bus, pci_dev_t bdf,
283 uint offset, ulong value,
284 enum pci_size_t size)
285{
Tuomas Tynkkynen544a2e72017-09-19 23:18:05 +0300286 return pci_generic_mmap_write_config(bus, ls_pcie_conf_address,
287 bdf, offset, value, size);
Minghuan Lianc1067842016-12-13 14:54:17 +0800288}
289
290/* Clear multi-function bit */
291static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
292{
293 writeb(PCI_HEADER_TYPE_BRIDGE, pcie->dbi + PCI_HEADER_TYPE);
294}
295
296/* Fix class value */
297static void ls_pcie_fix_class(struct ls_pcie *pcie)
298{
299 writew(PCI_CLASS_BRIDGE_PCI, pcie->dbi + PCI_CLASS_DEVICE);
300}
301
302/* Drop MSG TLP except for Vendor MSG */
303static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
304{
305 u32 val;
306
307 val = dbi_readl(pcie, PCIE_STRFMR1);
308 val &= 0xDFFFFFFF;
309 dbi_writel(pcie, val, PCIE_STRFMR1);
310}
311
312/* Disable all bars in RC mode */
313static void ls_pcie_disable_bars(struct ls_pcie *pcie)
314{
315 u32 sriov;
316
317 sriov = in_le32(pcie->dbi + PCIE_SRIOV);
318
319 /*
320 * TODO: For PCIe controller with SRIOV, the method to disable bars
321 * is different and more complex, so will add later.
322 */
323 if (PCI_EXT_CAP_ID(sriov) == PCI_EXT_CAP_ID_SRIOV)
324 return;
325
326 dbi_writel(pcie, 0, PCIE_CS2_OFFSET + PCI_BASE_ADDRESS_0);
327 dbi_writel(pcie, 0, PCIE_CS2_OFFSET + PCI_BASE_ADDRESS_1);
328 dbi_writel(pcie, 0, PCIE_CS2_OFFSET + PCI_ROM_ADDRESS1);
329}
330
331static void ls_pcie_setup_ctrl(struct ls_pcie *pcie)
332{
333 ls_pcie_setup_atu(pcie);
334
335 dbi_writel(pcie, 1, PCIE_DBI_RO_WR_EN);
336 ls_pcie_fix_class(pcie);
337 ls_pcie_clear_multifunction(pcie);
338 ls_pcie_drop_msg_tlp(pcie);
339 dbi_writel(pcie, 0, PCIE_DBI_RO_WR_EN);
340
341 ls_pcie_disable_bars(pcie);
Wasim Khan4a0e9be2019-11-15 09:23:34 +0000342 pcie->stream_id_cur = 0;
Minghuan Lianc1067842016-12-13 14:54:17 +0800343}
344
345static void ls_pcie_ep_setup_atu(struct ls_pcie *pcie)
346{
347 u64 phys = CONFIG_SYS_PCI_EP_MEMORY_BASE;
348
349 /* ATU 0 : INBOUND : map BAR0 */
350 ls_pcie_atu_inbound_set(pcie, 0, 0, phys);
351 /* ATU 1 : INBOUND : map BAR1 */
352 phys += PCIE_BAR1_SIZE;
353 ls_pcie_atu_inbound_set(pcie, 1, 1, phys);
354 /* ATU 2 : INBOUND : map BAR2 */
355 phys += PCIE_BAR2_SIZE;
356 ls_pcie_atu_inbound_set(pcie, 2, 2, phys);
357 /* ATU 3 : INBOUND : map BAR4 */
358 phys = CONFIG_SYS_PCI_EP_MEMORY_BASE + PCIE_BAR4_SIZE;
359 ls_pcie_atu_inbound_set(pcie, 3, 4, phys);
360
361 /* ATU 0 : OUTBOUND : map MEM */
362 ls_pcie_atu_outbound_set(pcie, 0,
363 PCIE_ATU_TYPE_MEM,
364 pcie->cfg_res.start,
365 0,
366 CONFIG_SYS_PCI_MEMORY_SIZE);
367}
368
369/* BAR0 and BAR1 are 32bit BAR2 and BAR4 are 64bit */
370static void ls_pcie_ep_setup_bar(void *bar_base, int bar, u32 size)
371{
372 /* The least inbound window is 4KiB */
373 if (size < 4 * 1024)
374 return;
375
376 switch (bar) {
377 case 0:
378 writel(size - 1, bar_base + PCI_BASE_ADDRESS_0);
379 break;
380 case 1:
381 writel(size - 1, bar_base + PCI_BASE_ADDRESS_1);
382 break;
383 case 2:
384 writel(size - 1, bar_base + PCI_BASE_ADDRESS_2);
385 writel(0, bar_base + PCI_BASE_ADDRESS_3);
386 break;
387 case 4:
388 writel(size - 1, bar_base + PCI_BASE_ADDRESS_4);
389 writel(0, bar_base + PCI_BASE_ADDRESS_5);
390 break;
391 default:
392 break;
393 }
394}
395
396static void ls_pcie_ep_setup_bars(void *bar_base)
397{
398 /* BAR0 - 32bit - 4K configuration */
399 ls_pcie_ep_setup_bar(bar_base, 0, PCIE_BAR0_SIZE);
400 /* BAR1 - 32bit - 8K MSIX*/
401 ls_pcie_ep_setup_bar(bar_base, 1, PCIE_BAR1_SIZE);
402 /* BAR2 - 64bit - 4K MEM desciptor */
403 ls_pcie_ep_setup_bar(bar_base, 2, PCIE_BAR2_SIZE);
404 /* BAR4 - 64bit - 1M MEM*/
405 ls_pcie_ep_setup_bar(bar_base, 4, PCIE_BAR4_SIZE);
406}
407
Hou Zhiqiang5faf5612017-02-10 15:42:11 +0800408static void ls_pcie_ep_enable_cfg(struct ls_pcie *pcie)
409{
Pankaj Bansalc63fac82019-10-14 11:43:19 +0000410 u32 config;
411
412 config = ctrl_readl(pcie, PCIE_PF_CONFIG);
413 config |= PCIE_CONFIG_READY;
414 ctrl_writel(pcie, config, PCIE_PF_CONFIG);
Hou Zhiqiang5faf5612017-02-10 15:42:11 +0800415}
416
Minghuan Lianc1067842016-12-13 14:54:17 +0800417static void ls_pcie_setup_ep(struct ls_pcie *pcie)
418{
419 u32 sriov;
420
421 sriov = readl(pcie->dbi + PCIE_SRIOV);
422 if (PCI_EXT_CAP_ID(sriov) == PCI_EXT_CAP_ID_SRIOV) {
423 int pf, vf;
424
425 for (pf = 0; pf < PCIE_PF_NUM; pf++) {
426 for (vf = 0; vf <= PCIE_VF_NUM; vf++) {
427 ctrl_writel(pcie, PCIE_LCTRL0_VAL(pf, vf),
428 PCIE_PF_VF_CTRL);
429
430 ls_pcie_ep_setup_bars(pcie->dbi);
431 ls_pcie_ep_setup_atu(pcie);
432 }
433 }
434 /* Disable CFG2 */
435 ctrl_writel(pcie, 0, PCIE_PF_VF_CTRL);
436 } else {
437 ls_pcie_ep_setup_bars(pcie->dbi + PCIE_NO_SRIOV_BAR_BASE);
438 ls_pcie_ep_setup_atu(pcie);
439 }
Hou Zhiqiang5faf5612017-02-10 15:42:11 +0800440
441 ls_pcie_ep_enable_cfg(pcie);
Minghuan Lianc1067842016-12-13 14:54:17 +0800442}
443
444static int ls_pcie_probe(struct udevice *dev)
445{
446 struct ls_pcie *pcie = dev_get_priv(dev);
447 const void *fdt = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700448 int node = dev_of_offset(dev);
Minghuan Lianc1067842016-12-13 14:54:17 +0800449 u16 link_sta;
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800450 uint svr;
Minghuan Lianc1067842016-12-13 14:54:17 +0800451 int ret;
Hou Zhiqiangb9dd2e62017-07-18 11:29:12 +0800452 fdt_size_t cfg_size;
Minghuan Lianc1067842016-12-13 14:54:17 +0800453
454 pcie->bus = dev;
455
456 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
457 "dbi", &pcie->dbi_res);
458 if (ret) {
459 printf("ls-pcie: resource \"dbi\" not found\n");
460 return ret;
461 }
462
463 pcie->idx = (pcie->dbi_res.start - PCIE_SYS_BASE_ADDR) / PCIE_CCSR_SIZE;
464
465 list_add(&pcie->list, &ls_pcie_list);
466
467 pcie->enabled = is_serdes_configured(PCIE_SRDS_PRTCL(pcie->idx));
468 if (!pcie->enabled) {
469 printf("PCIe%d: %s disabled\n", pcie->idx, dev->name);
470 return 0;
471 }
472
473 pcie->dbi = map_physmem(pcie->dbi_res.start,
474 fdt_resource_size(&pcie->dbi_res),
475 MAP_NOCACHE);
476
477 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
478 "lut", &pcie->lut_res);
479 if (!ret)
480 pcie->lut = map_physmem(pcie->lut_res.start,
481 fdt_resource_size(&pcie->lut_res),
482 MAP_NOCACHE);
483
484 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
485 "ctrl", &pcie->ctrl_res);
486 if (!ret)
487 pcie->ctrl = map_physmem(pcie->ctrl_res.start,
488 fdt_resource_size(&pcie->ctrl_res),
489 MAP_NOCACHE);
490 if (!pcie->ctrl)
491 pcie->ctrl = pcie->lut;
492
493 if (!pcie->ctrl) {
494 printf("%s: NOT find CTRL\n", dev->name);
495 return -1;
496 }
497
498 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
499 "config", &pcie->cfg_res);
500 if (ret) {
501 printf("%s: resource \"config\" not found\n", dev->name);
502 return ret;
503 }
504
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800505 /*
506 * Fix the pcie memory map address and PF control registers address
507 * for LS2088A series SoCs
508 */
509 svr = get_svr();
510 svr = (svr >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
511 if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
Priyanka Jain2b361782017-04-27 15:08:06 +0530512 svr == SVR_LS2048A || svr == SVR_LS2044A ||
513 svr == SVR_LS2081A || svr == SVR_LS2041A) {
Hou Zhiqiangb9dd2e62017-07-18 11:29:12 +0800514 cfg_size = fdt_resource_size(&pcie->cfg_res);
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800515 pcie->cfg_res.start = LS2088A_PCIE1_PHYS_ADDR +
516 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
Hou Zhiqiangb9dd2e62017-07-18 11:29:12 +0800517 pcie->cfg_res.end = pcie->cfg_res.start + cfg_size;
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800518 pcie->ctrl = pcie->lut + 0x40000;
519 }
520
Minghuan Lianc1067842016-12-13 14:54:17 +0800521 pcie->cfg0 = map_physmem(pcie->cfg_res.start,
522 fdt_resource_size(&pcie->cfg_res),
523 MAP_NOCACHE);
524 pcie->cfg1 = pcie->cfg0 + fdt_resource_size(&pcie->cfg_res) / 2;
525
526 pcie->big_endian = fdtdec_get_bool(fdt, node, "big-endian");
527
528 debug("%s dbi:%lx lut:%lx ctrl:0x%lx cfg0:0x%lx, big-endian:%d\n",
529 dev->name, (unsigned long)pcie->dbi, (unsigned long)pcie->lut,
530 (unsigned long)pcie->ctrl, (unsigned long)pcie->cfg0,
531 pcie->big_endian);
532
Xiaowei Bao77d56f92018-10-26 09:56:24 +0800533 pcie->mode = readb(pcie->dbi + PCI_HEADER_TYPE) & 0x7f;
Minghuan Lianc1067842016-12-13 14:54:17 +0800534
Xiaowei Bao77d56f92018-10-26 09:56:24 +0800535 if (pcie->mode == PCI_HEADER_TYPE_NORMAL) {
536 printf("PCIe%u: %s %s", pcie->idx, dev->name, "Endpoint");
537 ls_pcie_setup_ep(pcie);
538 } else {
539 printf("PCIe%u: %s %s", pcie->idx, dev->name, "Root Complex");
540 ls_pcie_setup_ctrl(pcie);
541 }
Minghuan Lianc1067842016-12-13 14:54:17 +0800542
543 if (!ls_pcie_link_up(pcie)) {
544 /* Let the user know there's no PCIe link */
545 printf(": no link\n");
546 return 0;
547 }
548
549 /* Print the negotiated PCIe link width */
550 link_sta = readw(pcie->dbi + PCIE_LINK_STA);
551 printf(": x%d gen%d\n", (link_sta & PCIE_LINK_WIDTH_MASK) >> 4,
552 link_sta & PCIE_LINK_SPEED_MASK);
553
554 return 0;
555}
556
557static const struct dm_pci_ops ls_pcie_ops = {
558 .read_config = ls_pcie_read_config,
559 .write_config = ls_pcie_write_config,
560};
561
562static const struct udevice_id ls_pcie_ids[] = {
563 { .compatible = "fsl,ls-pcie" },
564 { }
565};
566
567U_BOOT_DRIVER(pci_layerscape) = {
568 .name = "pci_layerscape",
569 .id = UCLASS_PCI,
570 .of_match = ls_pcie_ids,
571 .ops = &ls_pcie_ops,
572 .probe = ls_pcie_probe,
573 .priv_auto_alloc_size = sizeof(struct ls_pcie),
574};