blob: 6ecdd6af408c8ff13cd5206a2f343a2e67b0e490 [file] [log] [blame]
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +00001// SPDX-License-Identifier: GPL-2.0+ OR X11
2/*
Hou Zhiqiangbe384162021-11-09 16:56:24 +05303 * Copyright 2018-2021 NXP
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +00004 *
5 * PCIe Gen4 driver for NXP Layerscape SoCs
6 * Author: Hou Zhiqiang <Minder.Hou@gmail.com>
7 */
8
9#include <common.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +000011#include <asm/arch/fsl_serdes.h>
12#include <pci.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +000014#include <asm/io.h>
15#include <errno.h>
16#include <malloc.h>
17#include <dm.h>
18#include <linux/sizes.h>
19
20#include "pcie_layerscape_gen4.h"
21
22DECLARE_GLOBAL_DATA_PTR;
23
24LIST_HEAD(ls_pcie_g4_list);
25
26static u64 bar_size[4] = {
27 PCIE_BAR0_SIZE,
28 PCIE_BAR1_SIZE,
29 PCIE_BAR2_SIZE,
30 PCIE_BAR4_SIZE
31};
32
33static int ls_pcie_g4_ltssm(struct ls_pcie_g4 *pcie)
34{
35 u32 state;
36
37 state = pf_ctrl_readl(pcie, PCIE_LTSSM_STA) & LTSSM_STATE_MASK;
38
39 return state;
40}
41
42static int ls_pcie_g4_link_up(struct ls_pcie_g4 *pcie)
43{
44 int ltssm;
45
46 ltssm = ls_pcie_g4_ltssm(pcie);
47 if (ltssm != LTSSM_PCIE_L0)
48 return 0;
49
50 return 1;
51}
52
53static void ls_pcie_g4_ep_enable_cfg(struct ls_pcie_g4 *pcie)
54{
55 ccsr_writel(pcie, GPEX_CFG_READY, PCIE_CONFIG_READY);
56}
57
58static void ls_pcie_g4_cfg_set_target(struct ls_pcie_g4 *pcie, u32 target)
59{
60 ccsr_writel(pcie, PAB_AXI_AMAP_PEX_WIN_L(0), target);
61 ccsr_writel(pcie, PAB_AXI_AMAP_PEX_WIN_H(0), 0);
62}
63
64static int ls_pcie_g4_outbound_win_set(struct ls_pcie_g4 *pcie, int idx,
65 int type, u64 phys, u64 bus_addr,
66 pci_size_t size)
67{
68 u32 val;
69 u32 size_h, size_l;
70
71 if (idx >= PAB_WINS_NUM)
72 return -EINVAL;
73
74 size_h = upper_32_bits(~(size - 1));
75 size_l = lower_32_bits(~(size - 1));
76
77 val = ccsr_readl(pcie, PAB_AXI_AMAP_CTRL(idx));
78 val &= ~((AXI_AMAP_CTRL_TYPE_MASK << AXI_AMAP_CTRL_TYPE_SHIFT) |
79 (AXI_AMAP_CTRL_SIZE_MASK << AXI_AMAP_CTRL_SIZE_SHIFT) |
80 AXI_AMAP_CTRL_EN);
81 val |= ((type & AXI_AMAP_CTRL_TYPE_MASK) << AXI_AMAP_CTRL_TYPE_SHIFT) |
82 ((size_l >> AXI_AMAP_CTRL_SIZE_SHIFT) <<
83 AXI_AMAP_CTRL_SIZE_SHIFT) | AXI_AMAP_CTRL_EN;
84
85 ccsr_writel(pcie, PAB_AXI_AMAP_CTRL(idx), val);
86
87 ccsr_writel(pcie, PAB_AXI_AMAP_AXI_WIN(idx), lower_32_bits(phys));
88 ccsr_writel(pcie, PAB_EXT_AXI_AMAP_AXI_WIN(idx), upper_32_bits(phys));
89 ccsr_writel(pcie, PAB_AXI_AMAP_PEX_WIN_L(idx), lower_32_bits(bus_addr));
90 ccsr_writel(pcie, PAB_AXI_AMAP_PEX_WIN_H(idx), upper_32_bits(bus_addr));
91 ccsr_writel(pcie, PAB_EXT_AXI_AMAP_SIZE(idx), size_h);
92
93 return 0;
94}
95
96static int ls_pcie_g4_rc_inbound_win_set(struct ls_pcie_g4 *pcie, int idx,
97 int type, u64 phys, u64 bus_addr,
98 pci_size_t size)
99{
100 u32 val;
101 pci_size_t win_size = ~(size - 1);
102
103 val = ccsr_readl(pcie, PAB_PEX_AMAP_CTRL(idx));
104
105 val &= ~(PEX_AMAP_CTRL_TYPE_MASK << PEX_AMAP_CTRL_TYPE_SHIFT);
106 val &= ~(PEX_AMAP_CTRL_EN_MASK << PEX_AMAP_CTRL_EN_SHIFT);
107 val = (val | (type << PEX_AMAP_CTRL_TYPE_SHIFT));
108 val = (val | (1 << PEX_AMAP_CTRL_EN_SHIFT));
109
110 ccsr_writel(pcie, PAB_PEX_AMAP_CTRL(idx),
111 val | lower_32_bits(win_size));
112
113 ccsr_writel(pcie, PAB_EXT_PEX_AMAP_SIZE(idx), upper_32_bits(win_size));
114 ccsr_writel(pcie, PAB_PEX_AMAP_AXI_WIN(idx), lower_32_bits(phys));
115 ccsr_writel(pcie, PAB_EXT_PEX_AMAP_AXI_WIN(idx), upper_32_bits(phys));
116 ccsr_writel(pcie, PAB_PEX_AMAP_PEX_WIN_L(idx), lower_32_bits(bus_addr));
117 ccsr_writel(pcie, PAB_PEX_AMAP_PEX_WIN_H(idx), upper_32_bits(bus_addr));
118
119 return 0;
120}
121
122static void ls_pcie_g4_dump_wins(struct ls_pcie_g4 *pcie, int wins)
123{
124 int i;
125
126 for (i = 0; i < wins; i++) {
127 debug("APIO Win%d:\n", i);
128 debug("\tLOWER PHYS: 0x%08x\n",
129 ccsr_readl(pcie, PAB_AXI_AMAP_AXI_WIN(i)));
130 debug("\tUPPER PHYS: 0x%08x\n",
131 ccsr_readl(pcie, PAB_EXT_AXI_AMAP_AXI_WIN(i)));
132 debug("\tLOWER BUS: 0x%08x\n",
133 ccsr_readl(pcie, PAB_AXI_AMAP_PEX_WIN_L(i)));
134 debug("\tUPPER BUS: 0x%08x\n",
135 ccsr_readl(pcie, PAB_AXI_AMAP_PEX_WIN_H(i)));
136 debug("\tSIZE: 0x%08x\n",
137 ccsr_readl(pcie, PAB_AXI_AMAP_CTRL(i)) &
138 (AXI_AMAP_CTRL_SIZE_MASK << AXI_AMAP_CTRL_SIZE_SHIFT));
139 debug("\tEXT_SIZE: 0x%08x\n",
140 ccsr_readl(pcie, PAB_EXT_AXI_AMAP_SIZE(i)));
141 debug("\tPARAM: 0x%08x\n",
142 ccsr_readl(pcie, PAB_AXI_AMAP_PCI_HDR_PARAM(i)));
143 debug("\tCTRL: 0x%08x\n",
144 ccsr_readl(pcie, PAB_AXI_AMAP_CTRL(i)));
145 }
146}
147
148static void ls_pcie_g4_setup_wins(struct ls_pcie_g4 *pcie)
149{
150 struct pci_region *io, *mem, *pref;
151 int idx = 1;
152
153 /* INBOUND WIN */
154 ls_pcie_g4_rc_inbound_win_set(pcie, 0, IB_TYPE_MEM_F, 0, 0, SIZE_1T);
155
156 /* OUTBOUND WIN 0: CFG */
157 ls_pcie_g4_outbound_win_set(pcie, 0, PAB_AXI_TYPE_CFG,
158 pcie->cfg_res.start, 0,
159 fdt_resource_size(&pcie->cfg_res));
160
161 pci_get_regions(pcie->bus, &io, &mem, &pref);
162
163 if (io)
164 /* OUTBOUND WIN: IO */
165 ls_pcie_g4_outbound_win_set(pcie, idx++, PAB_AXI_TYPE_IO,
166 io->phys_start, io->bus_start,
167 io->size);
168
169 if (mem)
170 /* OUTBOUND WIN: MEM */
171 ls_pcie_g4_outbound_win_set(pcie, idx++, PAB_AXI_TYPE_MEM,
172 mem->phys_start, mem->bus_start,
173 mem->size);
174
175 if (pref)
176 /* OUTBOUND WIN: perf MEM */
177 ls_pcie_g4_outbound_win_set(pcie, idx++, PAB_AXI_TYPE_MEM,
178 pref->phys_start, pref->bus_start,
179 pref->size);
180
181 ls_pcie_g4_dump_wins(pcie, idx);
182}
183
184/* Return 0 if the address is valid, -errno if not valid */
185static int ls_pcie_g4_addr_valid(struct ls_pcie_g4 *pcie, pci_dev_t bdf)
186{
187 struct udevice *bus = pcie->bus;
188
189 if (pcie->mode == PCI_HEADER_TYPE_NORMAL)
190 return -ENODEV;
191
192 if (!pcie->enabled)
193 return -ENXIO;
194
Simon Glass8b85dfc2020-12-16 21:20:07 -0700195 if (PCI_BUS(bdf) < dev_seq(bus))
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000196 return -EINVAL;
197
Simon Glass8b85dfc2020-12-16 21:20:07 -0700198 if ((PCI_BUS(bdf) > dev_seq(bus)) && (!ls_pcie_g4_link_up(pcie)))
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000199 return -EINVAL;
200
Simon Glass8b85dfc2020-12-16 21:20:07 -0700201 if (PCI_BUS(bdf) <= (dev_seq(bus) + 1) && (PCI_DEV(bdf) > 0))
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000202 return -EINVAL;
203
204 return 0;
205}
206
207void *ls_pcie_g4_conf_address(struct ls_pcie_g4 *pcie, pci_dev_t bdf,
208 int offset)
209{
210 struct udevice *bus = pcie->bus;
211 u32 target;
212
Simon Glass8b85dfc2020-12-16 21:20:07 -0700213 if (PCI_BUS(bdf) == dev_seq(bus)) {
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000214 if (offset < INDIRECT_ADDR_BNDRY) {
215 ccsr_set_page(pcie, 0);
216 return pcie->ccsr + offset;
217 }
218
219 ccsr_set_page(pcie, OFFSET_TO_PAGE_IDX(offset));
220 return pcie->ccsr + OFFSET_TO_PAGE_ADDR(offset);
221 }
222
Simon Glass8b85dfc2020-12-16 21:20:07 -0700223 target = PAB_TARGET_BUS(PCI_BUS(bdf) - dev_seq(bus)) |
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000224 PAB_TARGET_DEV(PCI_DEV(bdf)) |
225 PAB_TARGET_FUNC(PCI_FUNC(bdf));
226
227 ls_pcie_g4_cfg_set_target(pcie, target);
228
229 return pcie->cfg + offset;
230}
231
Simon Glassc4e72c42020-01-27 08:49:37 -0700232static int ls_pcie_g4_read_config(const struct udevice *bus, pci_dev_t bdf,
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000233 uint offset, ulong *valuep,
234 enum pci_size_t size)
235{
236 struct ls_pcie_g4 *pcie = dev_get_priv(bus);
237 void *address;
238 int ret = 0;
239
240 if (ls_pcie_g4_addr_valid(pcie, bdf)) {
241 *valuep = pci_get_ff(size);
242 return 0;
243 }
244
245 address = ls_pcie_g4_conf_address(pcie, bdf, offset);
246
247 switch (size) {
248 case PCI_SIZE_8:
249 *valuep = readb(address);
250 break;
251 case PCI_SIZE_16:
252 *valuep = readw(address);
253 break;
254 case PCI_SIZE_32:
255 *valuep = readl(address);
256 break;
257 default:
258 ret = -EINVAL;
259 break;
260 }
261
262 return ret;
263}
264
265static int ls_pcie_g4_write_config(struct udevice *bus, pci_dev_t bdf,
266 uint offset, ulong value,
267 enum pci_size_t size)
268{
269 struct ls_pcie_g4 *pcie = dev_get_priv(bus);
270 void *address;
271
272 if (ls_pcie_g4_addr_valid(pcie, bdf))
273 return 0;
274
275 address = ls_pcie_g4_conf_address(pcie, bdf, offset);
276
277 switch (size) {
278 case PCI_SIZE_8:
279 writeb(value, address);
280 return 0;
281 case PCI_SIZE_16:
282 writew(value, address);
283 return 0;
284 case PCI_SIZE_32:
285 writel(value, address);
286 return 0;
287 default:
288 return -EINVAL;
289 }
290}
291
292static void ls_pcie_g4_setup_ctrl(struct ls_pcie_g4 *pcie)
293{
294 u32 val;
295
296 /* Fix class code */
297 val = ccsr_readl(pcie, GPEX_CLASSCODE);
298 val &= ~(GPEX_CLASSCODE_MASK << GPEX_CLASSCODE_SHIFT);
299 val |= PCI_CLASS_BRIDGE_PCI << GPEX_CLASSCODE_SHIFT;
300 ccsr_writel(pcie, GPEX_CLASSCODE, val);
301
302 /* Enable APIO and Memory/IO/CFG Wins */
303 val = ccsr_readl(pcie, PAB_AXI_PIO_CTRL(0));
304 val |= APIO_EN | MEM_WIN_EN | IO_WIN_EN | CFG_WIN_EN;
305 ccsr_writel(pcie, PAB_AXI_PIO_CTRL(0), val);
306
307 ls_pcie_g4_setup_wins(pcie);
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000308}
309
310static void ls_pcie_g4_ep_inbound_win_set(struct ls_pcie_g4 *pcie, int pf,
311 int bar, u64 phys)
312{
313 u32 val;
314
315 /* PF BAR1 is for MSI-X and only need to enable */
316 if (bar == 1) {
317 ccsr_writel(pcie, PAB_PEX_BAR_AMAP(pf, bar), BAR_AMAP_EN);
318 return;
319 }
320
321 val = upper_32_bits(phys);
322 ccsr_writel(pcie, PAB_EXT_PEX_BAR_AMAP(pf, bar), val);
323 val = lower_32_bits(phys) | BAR_AMAP_EN;
324 ccsr_writel(pcie, PAB_PEX_BAR_AMAP(pf, bar), val);
325}
326
327static void ls_pcie_g4_ep_setup_wins(struct ls_pcie_g4 *pcie, int pf)
328{
329 u64 phys;
330 int bar;
331 u32 val;
332
333 if ((!pcie->sriov_support && pf > LS_G4_PF0) || pf > LS_G4_PF1)
334 return;
335
336 phys = CONFIG_SYS_PCI_EP_MEMORY_BASE + PCIE_BAR_SIZE * 4 * pf;
337 for (bar = 0; bar < PF_BAR_NUM; bar++) {
338 ls_pcie_g4_ep_inbound_win_set(pcie, pf, bar, phys);
339 phys += PCIE_BAR_SIZE;
340 }
341
342 /* OUTBOUND: map MEM */
343 ls_pcie_g4_outbound_win_set(pcie, pf, PAB_AXI_TYPE_MEM,
344 pcie->cfg_res.start +
345 CONFIG_SYS_PCI_MEMORY_SIZE * pf, 0x0,
346 CONFIG_SYS_PCI_MEMORY_SIZE);
347
348 val = ccsr_readl(pcie, PAB_AXI_AMAP_PCI_HDR_PARAM(pf));
349 val &= ~FUNC_NUM_PCIE_MASK;
350 val |= pf;
351 ccsr_writel(pcie, PAB_AXI_AMAP_PCI_HDR_PARAM(pf), val);
352}
353
354static void ls_pcie_g4_ep_enable_bar(struct ls_pcie_g4 *pcie, int pf,
355 int bar, bool vf_bar, bool enable)
356{
357 u32 val;
358 u32 bar_pos = BAR_POS(bar, pf, vf_bar);
359
360 val = ccsr_readl(pcie, GPEX_BAR_ENABLE);
361 if (enable)
362 val |= 1 << bar_pos;
363 else
364 val &= ~(1 << bar_pos);
365 ccsr_writel(pcie, GPEX_BAR_ENABLE, val);
366}
367
368static void ls_pcie_g4_ep_set_bar_size(struct ls_pcie_g4 *pcie, int pf,
369 int bar, bool vf_bar, u64 size)
370{
371 u32 bar_pos = BAR_POS(bar, pf, vf_bar);
372 u32 mask_l = lower_32_bits(~(size - 1));
373 u32 mask_h = upper_32_bits(~(size - 1));
374
375 ccsr_writel(pcie, GPEX_BAR_SELECT, bar_pos);
376 ccsr_writel(pcie, GPEX_BAR_SIZE_LDW, mask_l);
377 ccsr_writel(pcie, GPEX_BAR_SIZE_UDW, mask_h);
378}
379
380static void ls_pcie_g4_ep_setup_bar(struct ls_pcie_g4 *pcie, int pf,
381 int bar, bool vf_bar, u64 size)
382{
383 bool en = size ? true : false;
384
385 ls_pcie_g4_ep_enable_bar(pcie, pf, bar, vf_bar, en);
386 ls_pcie_g4_ep_set_bar_size(pcie, pf, bar, vf_bar, size);
387}
388
389static void ls_pcie_g4_ep_setup_bars(struct ls_pcie_g4 *pcie, int pf)
390{
391 int bar;
392
393 /* Setup PF BARs */
394 for (bar = 0; bar < PF_BAR_NUM; bar++)
395 ls_pcie_g4_ep_setup_bar(pcie, pf, bar, false, bar_size[bar]);
396
397 if (!pcie->sriov_support)
398 return;
399
400 /* Setup VF BARs */
401 for (bar = 0; bar < VF_BAR_NUM; bar++)
402 ls_pcie_g4_ep_setup_bar(pcie, pf, bar, true, bar_size[bar]);
403}
404
405static void ls_pcie_g4_set_sriov(struct ls_pcie_g4 *pcie, int pf)
406{
407 unsigned int val;
408
409 val = ccsr_readl(pcie, GPEX_SRIOV_INIT_VFS_TOTAL_VF(pf));
410 val &= ~(TTL_VF_MASK << TTL_VF_SHIFT);
411 val |= PCIE_VF_NUM << TTL_VF_SHIFT;
412 val &= ~(INI_VF_MASK << INI_VF_SHIFT);
413 val |= PCIE_VF_NUM << INI_VF_SHIFT;
414 ccsr_writel(pcie, GPEX_SRIOV_INIT_VFS_TOTAL_VF(pf), val);
415
416 val = ccsr_readl(pcie, PCIE_SRIOV_VF_OFFSET_STRIDE);
417 val += PCIE_VF_NUM * pf - pf;
418 ccsr_writel(pcie, GPEX_SRIOV_VF_OFFSET_STRIDE(pf), val);
419}
420
421static void ls_pcie_g4_setup_ep(struct ls_pcie_g4 *pcie)
422{
423 u32 pf, sriov;
424 u32 val;
425 int i;
426
427 /* Enable APIO and Memory Win */
428 val = ccsr_readl(pcie, PAB_AXI_PIO_CTRL(0));
429 val |= APIO_EN | MEM_WIN_EN;
430 ccsr_writel(pcie, PAB_AXI_PIO_CTRL(0), val);
431
432 sriov = ccsr_readl(pcie, PCIE_SRIOV_CAPABILITY);
433 if (PCI_EXT_CAP_ID(sriov) == PCI_EXT_CAP_ID_SRIOV)
434 pcie->sriov_support = 1;
435
436 pf = pcie->sriov_support ? PCIE_PF_NUM : 1;
437
438 for (i = 0; i < pf; i++) {
439 ls_pcie_g4_ep_setup_bars(pcie, i);
440 ls_pcie_g4_ep_setup_wins(pcie, i);
441 if (pcie->sriov_support)
442 ls_pcie_g4_set_sriov(pcie, i);
443 }
444
445 ls_pcie_g4_ep_enable_cfg(pcie);
446 ls_pcie_g4_dump_wins(pcie, pf);
447}
448
449static int ls_pcie_g4_probe(struct udevice *dev)
450{
451 struct ls_pcie_g4 *pcie = dev_get_priv(dev);
452 const void *fdt = gd->fdt_blob;
453 int node = dev_of_offset(dev);
454 u32 link_ctrl_sta;
455 u32 val;
456 int ret;
Wasim Khan1255f8b2020-09-28 16:26:14 +0530457 fdt_size_t cfg_size;
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000458
459 pcie->bus = dev;
460
461 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
462 "ccsr", &pcie->ccsr_res);
463 if (ret) {
464 printf("ls-pcie-g4: resource \"ccsr\" not found\n");
465 return ret;
466 }
467
468 pcie->idx = (pcie->ccsr_res.start - PCIE_SYS_BASE_ADDR) /
469 PCIE_CCSR_SIZE;
470
471 list_add(&pcie->list, &ls_pcie_g4_list);
472
473 pcie->enabled = is_serdes_configured(PCIE_SRDS_PRTCL(pcie->idx));
474 if (!pcie->enabled) {
Wasim Khaneac36442020-09-28 16:26:05 +0530475 printf("PCIe%d: %s disabled\n", PCIE_SRDS_PRTCL(pcie->idx),
476 dev->name);
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000477 return 0;
478 }
479
480 pcie->ccsr = map_physmem(pcie->ccsr_res.start,
481 fdt_resource_size(&pcie->ccsr_res),
482 MAP_NOCACHE);
483
484 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
485 "config", &pcie->cfg_res);
486 if (ret) {
487 printf("%s: resource \"config\" not found\n", dev->name);
488 return ret;
489 }
490
Wasim Khan1255f8b2020-09-28 16:26:14 +0530491 cfg_size = fdt_resource_size(&pcie->cfg_res);
492 if (cfg_size < SZ_4K) {
493 printf("PCIe%d: %s Invalid size(0x%llx) for resource \"config\",expected minimum 0x%x\n",
494 PCIE_SRDS_PRTCL(pcie->idx), dev->name, cfg_size, SZ_4K);
495 return 0;
496 }
497
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000498 pcie->cfg = map_physmem(pcie->cfg_res.start,
499 fdt_resource_size(&pcie->cfg_res),
500 MAP_NOCACHE);
501
502 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
503 "lut", &pcie->lut_res);
504 if (ret) {
505 printf("ls-pcie-g4: resource \"lut\" not found\n");
506 return ret;
507 }
508
509 pcie->lut = map_physmem(pcie->lut_res.start,
510 fdt_resource_size(&pcie->lut_res),
511 MAP_NOCACHE);
512
513 ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
514 "pf_ctrl", &pcie->pf_ctrl_res);
515 if (ret) {
516 printf("ls-pcie-g4: resource \"pf_ctrl\" not found\n");
517 return ret;
518 }
519
520 pcie->pf_ctrl = map_physmem(pcie->pf_ctrl_res.start,
521 fdt_resource_size(&pcie->pf_ctrl_res),
522 MAP_NOCACHE);
523
524 pcie->big_endian = fdtdec_get_bool(fdt, node, "big-endian");
525
526 debug("%s ccsr:%lx, cfg:0x%lx, big-endian:%d\n",
527 dev->name, (unsigned long)pcie->ccsr, (unsigned long)pcie->cfg,
528 pcie->big_endian);
529
530 pcie->mode = readb(pcie->ccsr + PCI_HEADER_TYPE) & 0x7f;
531
532 if (pcie->mode == PCI_HEADER_TYPE_NORMAL) {
Wasim Khaneac36442020-09-28 16:26:05 +0530533 printf("PCIe%u: %s %s", PCIE_SRDS_PRTCL(pcie->idx), dev->name,
534 "Endpoint");
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000535 ls_pcie_g4_setup_ep(pcie);
536 } else {
Wasim Khaneac36442020-09-28 16:26:05 +0530537 printf("PCIe%u: %s %s", PCIE_SRDS_PRTCL(pcie->idx), dev->name,
538 "Root Complex");
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000539 ls_pcie_g4_setup_ctrl(pcie);
540 }
541
542 /* Enable Amba & PEX PIO */
543 val = ccsr_readl(pcie, PAB_CTRL);
544 val |= PAB_CTRL_APIO_EN | PAB_CTRL_PPIO_EN;
545 ccsr_writel(pcie, PAB_CTRL, val);
546
547 val = ccsr_readl(pcie, PAB_PEX_PIO_CTRL(0));
548 val |= PPIO_EN;
549 ccsr_writel(pcie, PAB_PEX_PIO_CTRL(0), val);
550
551 if (!ls_pcie_g4_link_up(pcie)) {
552 /* Let the user know there's no PCIe link */
553 printf(": no link\n");
554 return 0;
555 }
556
557 /* Print the negotiated PCIe link width */
558 link_ctrl_sta = ccsr_readl(pcie, PCIE_LINK_CTRL_STA);
559 printf(": x%d gen%d\n",
560 (link_ctrl_sta >> PCIE_LINK_WIDTH_SHIFT & PCIE_LINK_WIDTH_MASK),
561 (link_ctrl_sta >> PCIE_LINK_SPEED_SHIFT) & PCIE_LINK_SPEED_MASK);
562
563 return 0;
564}
565
566static const struct dm_pci_ops ls_pcie_g4_ops = {
567 .read_config = ls_pcie_g4_read_config,
568 .write_config = ls_pcie_g4_write_config,
569};
570
571static const struct udevice_id ls_pcie_g4_ids[] = {
572 { .compatible = "fsl,lx2160a-pcie" },
573 { }
574};
575
576U_BOOT_DRIVER(pcie_layerscape_gen4) = {
577 .name = "pcie_layerscape_gen4",
578 .id = UCLASS_PCI,
579 .of_match = ls_pcie_g4_ids,
580 .ops = &ls_pcie_g4_ops,
581 .probe = ls_pcie_g4_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700582 .priv_auto = sizeof(struct ls_pcie_g4),
Hou Zhiqiang07ce19f2019-04-08 10:15:46 +0000583};