blob: f089c48f02869693abcbc13f9e18727f2a34c33c [file] [log] [blame]
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Broadcom STB PCIe controller driver
4 *
5 * Copyright (C) 2020 Samsung Electronics Co., Ltd.
6 *
7 * Based on upstream Linux kernel driver:
8 * drivers/pci/controller/pcie-brcmstb.c
9 * Copyright (C) 2009 - 2017 Broadcom
10 *
11 * Based driver by Nicolas Saenz Julienne
12 * Copyright (C) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
13 */
14
Simon Glass3ed3a4d2024-10-23 15:20:10 +020015#include <asm/arch/acpi/bcm2711.h>
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +020016#include <errno.h>
17#include <dm.h>
18#include <dm/ofnode.h>
19#include <pci.h>
20#include <asm/io.h>
21#include <linux/bitfield.h>
22#include <linux/log2.h>
23#include <linux/iopoll.h>
24
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +020025/* PCIe parameters */
26#define BRCM_NUM_PCIE_OUT_WINS 4
27
28/* MDIO registers */
29#define MDIO_PORT0 0x0
30#define MDIO_DATA_MASK 0x7fffffff
31#define MDIO_DATA_SHIFT 0
32#define MDIO_PORT_MASK 0xf0000
33#define MDIO_PORT_SHIFT 16
34#define MDIO_REGAD_MASK 0xffff
35#define MDIO_REGAD_SHIFT 0
36#define MDIO_CMD_MASK 0xfff00000
37#define MDIO_CMD_SHIFT 20
38#define MDIO_CMD_READ 0x1
39#define MDIO_CMD_WRITE 0x0
40#define MDIO_DATA_DONE_MASK 0x80000000
41#define SSC_REGS_ADDR 0x1100
42#define SET_ADDR_OFFSET 0x1f
43#define SSC_CNTL_OFFSET 0x2
44#define SSC_CNTL_OVRD_EN_MASK 0x8000
45#define SSC_CNTL_OVRD_VAL_MASK 0x4000
46#define SSC_STATUS_OFFSET 0x1
47#define SSC_STATUS_SSC_MASK 0x400
48#define SSC_STATUS_SSC_SHIFT 10
49#define SSC_STATUS_PLL_LOCK_MASK 0x800
50#define SSC_STATUS_PLL_LOCK_SHIFT 11
51
52/**
53 * struct brcm_pcie - the PCIe controller state
54 * @base: Base address of memory mapped IO registers of the controller
55 * @gen: Non-zero value indicates limitation of the PCIe controller operation
56 * to a specific generation (1, 2 or 3)
57 * @ssc: true indicates active Spread Spectrum Clocking operation
58 */
59struct brcm_pcie {
60 void __iomem *base;
61
62 int gen;
63 bool ssc;
64};
65
66/**
67 * brcm_pcie_encode_ibar_size() - Encode the inbound "BAR" region size
68 * @size: The inbound region size
69 *
70 * This function converts size of the inbound "BAR" region to the non-linear
71 * values of the PCIE_MISC_RC_BAR[123]_CONFIG_LO register SIZE field.
72 *
73 * Return: The encoded inbound region size
74 */
75static int brcm_pcie_encode_ibar_size(u64 size)
76{
77 int log2_in = ilog2(size);
78
79 if (log2_in >= 12 && log2_in <= 15)
80 /* Covers 4KB to 32KB (inclusive) */
81 return (log2_in - 12) + 0x1c;
82 else if (log2_in >= 16 && log2_in <= 37)
83 /* Covers 64KB to 32GB, (inclusive) */
84 return log2_in - 15;
85
86 /* Something is awry so disable */
87 return 0;
88}
89
90/**
91 * brcm_pcie_rc_mode() - Check if PCIe controller is in RC mode
92 * @pcie: Pointer to the PCIe controller state
93 *
94 * The controller is capable of serving in both RC and EP roles.
95 *
96 * Return: true for RC mode, false for EP mode.
97 */
98static bool brcm_pcie_rc_mode(struct brcm_pcie *pcie)
99{
100 u32 val;
101
102 val = readl(pcie->base + PCIE_MISC_PCIE_STATUS);
103
104 return (val & STATUS_PCIE_PORT_MASK) >> STATUS_PCIE_PORT_SHIFT;
105}
106
107/**
108 * brcm_pcie_link_up() - Check whether the PCIe link is up
109 * @pcie: Pointer to the PCIe controller state
110 *
111 * Return: true if the link is up, false otherwise.
112 */
113static bool brcm_pcie_link_up(struct brcm_pcie *pcie)
114{
115 u32 val, dla, plu;
116
117 val = readl(pcie->base + PCIE_MISC_PCIE_STATUS);
118 dla = (val & STATUS_PCIE_DL_ACTIVE_MASK) >> STATUS_PCIE_DL_ACTIVE_SHIFT;
119 plu = (val & STATUS_PCIE_PHYLINKUP_MASK) >> STATUS_PCIE_PHYLINKUP_SHIFT;
120
121 return dla && plu;
122}
123
124static int brcm_pcie_config_address(const struct udevice *dev, pci_dev_t bdf,
125 uint offset, void **paddress)
126{
127 struct brcm_pcie *pcie = dev_get_priv(dev);
128 unsigned int pci_bus = PCI_BUS(bdf);
129 unsigned int pci_dev = PCI_DEV(bdf);
130 unsigned int pci_func = PCI_FUNC(bdf);
131 int idx;
132
133 /*
134 * Busses 0 (host PCIe bridge) and 1 (its immediate child)
135 * are limited to a single device each
136 */
137 if (pci_bus < 2 && pci_dev > 0)
138 return -EINVAL;
139
140 /* Accesses to the RC go right to the RC registers */
141 if (pci_bus == 0) {
142 *paddress = pcie->base + offset;
143 return 0;
144 }
145
Sam Edwards30e58592023-08-14 16:34:13 -0600146 /* An access to our HW w/o link-up will cause a CPU Abort */
147 if (!brcm_pcie_link_up(pcie))
148 return -EINVAL;
149
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200150 /* For devices, write to the config space index register */
Pali Rohár9e98eb72021-11-24 18:00:31 +0100151 idx = PCIE_ECAM_OFFSET(pci_bus, pci_dev, pci_func, 0);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200152
153 writel(idx, pcie->base + PCIE_EXT_CFG_INDEX);
154 *paddress = pcie->base + PCIE_EXT_CFG_DATA + offset;
155
156 return 0;
157}
158
159static int brcm_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
160 uint offset, ulong *valuep,
161 enum pci_size_t size)
162{
163 return pci_generic_mmap_read_config(bus, brcm_pcie_config_address,
164 bdf, offset, valuep, size);
165}
166
167static int brcm_pcie_write_config(struct udevice *bus, pci_dev_t bdf,
168 uint offset, ulong value,
169 enum pci_size_t size)
170{
171 return pci_generic_mmap_write_config(bus, brcm_pcie_config_address,
172 bdf, offset, value, size);
173}
174
175static const char *link_speed_to_str(unsigned int cls)
176{
177 switch (cls) {
178 case PCI_EXP_LNKSTA_CLS_2_5GB: return "2.5";
179 case PCI_EXP_LNKSTA_CLS_5_0GB: return "5.0";
180 case PCI_EXP_LNKSTA_CLS_8_0GB: return "8.0";
181 default:
182 break;
183 }
184
185 return "??";
186}
187
188static u32 brcm_pcie_mdio_form_pkt(unsigned int port, unsigned int regad,
189 unsigned int cmd)
190{
191 u32 pkt;
192
193 pkt = (port << MDIO_PORT_SHIFT) & MDIO_PORT_MASK;
194 pkt |= (regad << MDIO_REGAD_SHIFT) & MDIO_REGAD_MASK;
195 pkt |= (cmd << MDIO_CMD_SHIFT) & MDIO_CMD_MASK;
196
197 return pkt;
198}
199
200/**
201 * brcm_pcie_mdio_read() - Perform a register read on the internal MDIO bus
202 * @base: Pointer to the PCIe controller IO registers
203 * @port: The MDIO port number
204 * @regad: The register address
205 * @val: A pointer at which to store the read value
206 *
207 * Return: 0 on success and register value in @val, negative error value
208 * on failure.
209 */
210static int brcm_pcie_mdio_read(void __iomem *base, unsigned int port,
211 unsigned int regad, u32 *val)
212{
213 u32 data, addr;
214 int ret;
215
216 addr = brcm_pcie_mdio_form_pkt(port, regad, MDIO_CMD_READ);
217 writel(addr, base + PCIE_RC_DL_MDIO_ADDR);
218 readl(base + PCIE_RC_DL_MDIO_ADDR);
219
220 ret = readl_poll_timeout(base + PCIE_RC_DL_MDIO_RD_DATA, data,
221 (data & MDIO_DATA_DONE_MASK), 100);
222
223 *val = data & MDIO_DATA_MASK;
224
225 return ret;
226}
227
228/**
229 * brcm_pcie_mdio_write() - Perform a register write on the internal MDIO bus
230 * @base: Pointer to the PCIe controller IO registers
231 * @port: The MDIO port number
232 * @regad: Address of the register
233 * @wrdata: The value to write
234 *
235 * Return: 0 on success, negative error value on failure.
236 */
237static int brcm_pcie_mdio_write(void __iomem *base, unsigned int port,
238 unsigned int regad, u16 wrdata)
239{
240 u32 data, addr;
241
242 addr = brcm_pcie_mdio_form_pkt(port, regad, MDIO_CMD_WRITE);
243 writel(addr, base + PCIE_RC_DL_MDIO_ADDR);
244 readl(base + PCIE_RC_DL_MDIO_ADDR);
245 writel(MDIO_DATA_DONE_MASK | wrdata, base + PCIE_RC_DL_MDIO_WR_DATA);
246
247 return readl_poll_timeout(base + PCIE_RC_DL_MDIO_WR_DATA, data,
248 !(data & MDIO_DATA_DONE_MASK), 100);
249}
250
251/**
252 * brcm_pcie_set_ssc() - Configure the controller for Spread Spectrum Clocking
253 * @base: pointer to the PCIe controller IO registers
254 *
255 * Return: 0 on success, negative error value on failure.
256 */
257static int brcm_pcie_set_ssc(void __iomem *base)
258{
259 int pll, ssc;
260 int ret;
261 u32 tmp;
262
263 ret = brcm_pcie_mdio_write(base, MDIO_PORT0, SET_ADDR_OFFSET,
264 SSC_REGS_ADDR);
265 if (ret < 0)
266 return ret;
267
268 ret = brcm_pcie_mdio_read(base, MDIO_PORT0, SSC_CNTL_OFFSET, &tmp);
269 if (ret < 0)
270 return ret;
271
272 tmp |= (SSC_CNTL_OVRD_EN_MASK | SSC_CNTL_OVRD_VAL_MASK);
273
274 ret = brcm_pcie_mdio_write(base, MDIO_PORT0, SSC_CNTL_OFFSET, tmp);
275 if (ret < 0)
276 return ret;
277
278 udelay(1000);
279 ret = brcm_pcie_mdio_read(base, MDIO_PORT0, SSC_STATUS_OFFSET, &tmp);
280 if (ret < 0)
281 return ret;
282
283 ssc = (tmp & SSC_STATUS_SSC_MASK) >> SSC_STATUS_SSC_SHIFT;
284 pll = (tmp & SSC_STATUS_PLL_LOCK_MASK) >> SSC_STATUS_PLL_LOCK_SHIFT;
285
286 return ssc && pll ? 0 : -EIO;
287}
288
289/**
290 * brcm_pcie_set_gen() - Limits operation to a specific generation (1, 2 or 3)
291 * @pcie: pointer to the PCIe controller state
292 * @gen: PCIe generation to limit the controller's operation to
293 */
294static void brcm_pcie_set_gen(struct brcm_pcie *pcie, unsigned int gen)
295{
296 void __iomem *cap_base = pcie->base + BRCM_PCIE_CAP_REGS;
297
298 u16 lnkctl2 = readw(cap_base + PCI_EXP_LNKCTL2);
299 u32 lnkcap = readl(cap_base + PCI_EXP_LNKCAP);
300
301 lnkcap = (lnkcap & ~PCI_EXP_LNKCAP_SLS) | gen;
302 writel(lnkcap, cap_base + PCI_EXP_LNKCAP);
303
304 lnkctl2 = (lnkctl2 & ~0xf) | gen;
305 writew(lnkctl2, cap_base + PCI_EXP_LNKCTL2);
306}
307
308static void brcm_pcie_set_outbound_win(struct brcm_pcie *pcie,
309 unsigned int win, u64 phys_addr,
310 u64 pcie_addr, u64 size)
311{
312 void __iomem *base = pcie->base;
313 u32 phys_addr_mb_high, limit_addr_mb_high;
314 phys_addr_t phys_addr_mb, limit_addr_mb;
315 int high_addr_shift;
316 u32 tmp;
317
318 /* Set the base of the pcie_addr window */
319 writel(lower_32_bits(pcie_addr), base + PCIE_MEM_WIN0_LO(win));
320 writel(upper_32_bits(pcie_addr), base + PCIE_MEM_WIN0_HI(win));
321
322 /* Write the addr base & limit lower bits (in MBs) */
323 phys_addr_mb = phys_addr / SZ_1M;
324 limit_addr_mb = (phys_addr + size - 1) / SZ_1M;
325
326 tmp = readl(base + PCIE_MEM_WIN0_BASE_LIMIT(win));
327 u32p_replace_bits(&tmp, phys_addr_mb,
328 MEM_WIN0_BASE_LIMIT_BASE_MASK);
329 u32p_replace_bits(&tmp, limit_addr_mb,
330 MEM_WIN0_BASE_LIMIT_LIMIT_MASK);
331 writel(tmp, base + PCIE_MEM_WIN0_BASE_LIMIT(win));
332
333 /* Write the cpu & limit addr upper bits */
334 high_addr_shift = MEM_WIN0_BASE_LIMIT_BASE_HI_SHIFT;
335 phys_addr_mb_high = phys_addr_mb >> high_addr_shift;
336 tmp = readl(base + PCIE_MEM_WIN0_BASE_HI(win));
337 u32p_replace_bits(&tmp, phys_addr_mb_high,
338 MEM_WIN0_BASE_HI_BASE_MASK);
339 writel(tmp, base + PCIE_MEM_WIN0_BASE_HI(win));
340
341 limit_addr_mb_high = limit_addr_mb >> high_addr_shift;
342 tmp = readl(base + PCIE_MEM_WIN0_LIMIT_HI(win));
343 u32p_replace_bits(&tmp, limit_addr_mb_high,
344 PCIE_MEM_WIN0_LIMIT_HI_LIMIT_MASK);
345 writel(tmp, base + PCIE_MEM_WIN0_LIMIT_HI(win));
346}
347
348static int brcm_pcie_probe(struct udevice *dev)
349{
350 struct udevice *ctlr = pci_get_controller(dev);
351 struct pci_controller *hose = dev_get_uclass_priv(ctlr);
352 struct brcm_pcie *pcie = dev_get_priv(dev);
353 void __iomem *base = pcie->base;
Nicolas Saenz Julienne038876b2021-01-12 13:55:21 +0100354 struct pci_region region;
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200355 bool ssc_good = false;
356 int num_out_wins = 0;
357 u64 rc_bar2_offset, rc_bar2_size;
358 unsigned int scb_size_val;
359 int i, ret;
360 u16 nlw, cls, lnksta;
361 u32 tmp;
362
363 /*
364 * Reset the bridge, assert the fundamental reset. Note for some SoCs,
365 * e.g. BCM7278, the fundamental reset should not be asserted here.
366 * This will need to be changed when support for other SoCs is added.
367 */
368 setbits_le32(base + PCIE_RGR1_SW_INIT_1,
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200369 PCIE_RGR1_SW_INIT_1_INIT_MASK | PCIE_RGR1_SW_INIT_1_PERST_MASK);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200370 /*
371 * The delay is a safety precaution to preclude the reset signal
372 * from looking like a glitch.
373 */
374 udelay(100);
375
376 /* Take the bridge out of reset */
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200377 clrbits_le32(base + PCIE_RGR1_SW_INIT_1, PCIE_RGR1_SW_INIT_1_INIT_MASK);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200378
379 clrbits_le32(base + PCIE_MISC_HARD_PCIE_HARD_DEBUG,
380 PCIE_HARD_DEBUG_SERDES_IDDQ_MASK);
381
382 /* Wait for SerDes to be stable */
383 udelay(100);
384
385 /* Set SCB_MAX_BURST_SIZE, CFG_READ_UR_MODE, SCB_ACCESS_EN */
386 clrsetbits_le32(base + PCIE_MISC_MISC_CTRL,
387 MISC_CTRL_MAX_BURST_SIZE_MASK,
388 MISC_CTRL_SCB_ACCESS_EN_MASK |
389 MISC_CTRL_CFG_READ_UR_MODE_MASK |
390 MISC_CTRL_MAX_BURST_SIZE_128);
Nicolas Saenz Julienne038876b2021-01-12 13:55:21 +0100391
392 pci_get_dma_regions(dev, &region, 0);
393 rc_bar2_offset = region.bus_start - region.phys_start;
394 rc_bar2_size = 1ULL << fls64(region.size - 1);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200395
396 tmp = lower_32_bits(rc_bar2_offset);
397 u32p_replace_bits(&tmp, brcm_pcie_encode_ibar_size(rc_bar2_size),
398 RC_BAR2_CONFIG_LO_SIZE_MASK);
399 writel(tmp, base + PCIE_MISC_RC_BAR2_CONFIG_LO);
400 writel(upper_32_bits(rc_bar2_offset),
401 base + PCIE_MISC_RC_BAR2_CONFIG_HI);
402
403 scb_size_val = rc_bar2_size ?
404 ilog2(rc_bar2_size) - 15 : 0xf; /* 0xf is 1GB */
405
406 tmp = readl(base + PCIE_MISC_MISC_CTRL);
407 u32p_replace_bits(&tmp, scb_size_val,
408 MISC_CTRL_SCB0_SIZE_MASK);
409 writel(tmp, base + PCIE_MISC_MISC_CTRL);
410
411 /* Disable the PCIe->GISB memory window (RC_BAR1) */
412 clrbits_le32(base + PCIE_MISC_RC_BAR1_CONFIG_LO,
413 RC_BAR1_CONFIG_LO_SIZE_MASK);
414
415 /* Disable the PCIe->SCB memory window (RC_BAR3) */
416 clrbits_le32(base + PCIE_MISC_RC_BAR3_CONFIG_LO,
417 RC_BAR3_CONFIG_LO_SIZE_MASK);
418
419 /* Mask all interrupts since we are not handling any yet */
420 writel(0xffffffff, base + PCIE_MSI_INTR2_MASK_SET);
421
422 /* Clear any interrupts we find on boot */
423 writel(0xffffffff, base + PCIE_MSI_INTR2_CLR);
424
425 if (pcie->gen)
426 brcm_pcie_set_gen(pcie, pcie->gen);
427
428 /* Unassert the fundamental reset */
429 clrbits_le32(pcie->base + PCIE_RGR1_SW_INIT_1,
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200430 PCIE_RGR1_SW_INIT_1_PERST_MASK);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200431
Sam Edwards30e58592023-08-14 16:34:13 -0600432 /*
433 * Wait for 100ms after PERST# deassertion; see PCIe CEM specification
434 * sections 2.2, PCIe r5.0, 6.6.1.
435 */
436 mdelay(100);
437
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200438 /* Give the RC/EP time to wake up, before trying to configure RC.
439 * Intermittently check status for link-up, up to a total of 100ms.
440 */
441 for (i = 0; i < 100 && !brcm_pcie_link_up(pcie); i += 5)
442 mdelay(5);
443
444 if (!brcm_pcie_link_up(pcie)) {
445 printf("PCIe BRCM: link down\n");
446 return -EINVAL;
447 }
448
449 if (!brcm_pcie_rc_mode(pcie)) {
450 printf("PCIe misconfigured; is in EP mode\n");
451 return -EINVAL;
452 }
453
454 for (i = 0; i < hose->region_count; i++) {
455 struct pci_region *reg = &hose->regions[i];
456
457 if (reg->flags != PCI_REGION_MEM)
458 continue;
459
460 if (num_out_wins >= BRCM_NUM_PCIE_OUT_WINS)
461 return -EINVAL;
462
463 brcm_pcie_set_outbound_win(pcie, num_out_wins, reg->phys_start,
464 reg->bus_start, reg->size);
465
466 num_out_wins++;
467 }
468
469 /*
470 * For config space accesses on the RC, show the right class for
471 * a PCIe-PCIe bridge (the default setting is to be EP mode).
472 */
473 clrsetbits_le32(base + PCIE_RC_CFG_PRIV1_ID_VAL3,
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200474 PCIE_RC_CFG_PRIV1_ID_VAL3_CLASS_CODE_MASK, 0x060400);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200475
476 if (pcie->ssc) {
477 ret = brcm_pcie_set_ssc(pcie->base);
478 if (!ret)
479 ssc_good = true;
480 else
481 printf("PCIe BRCM: failed attempt to enter SSC mode\n");
482 }
483
484 lnksta = readw(base + BRCM_PCIE_CAP_REGS + PCI_EXP_LNKSTA);
485 cls = lnksta & PCI_EXP_LNKSTA_CLS;
486 nlw = (lnksta & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT;
487
488 printf("PCIe BRCM: link up, %s Gbps x%u %s\n", link_speed_to_str(cls),
489 nlw, ssc_good ? "(SSC)" : "(!SSC)");
490
491 /* PCIe->SCB endian mode for BAR */
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200492 clrsetbits_le32(base + PCIE_RC_CFG_VENDOR_VENDOR_SPECIFIC_REG1,
493 PCIE_RC_CFG_VENDOR_VENDOR_SPECIFIC_REG1_ENDIAN_MODE_BAR2_MASK,
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200494 VENDOR_SPECIFIC_REG1_LITTLE_ENDIAN);
Sam Edwardsfa8c9882023-08-16 15:27:53 -0700495
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200496 /*
Sam Edwardsfa8c9882023-08-16 15:27:53 -0700497 * We used to enable the CLKREQ# input here, but a few PCIe cards don't
498 * attach anything to the CLKREQ# line, so we shouldn't assume that
499 * it's connected and working. The controller does allow detecting
500 * whether the port on the other side of our link is/was driving this
501 * signal, so we could check before we assume. But because this signal
502 * is for power management, which doesn't make sense in a bootloader,
503 * let's instead just unadvertise ASPM support.
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200504 */
Sam Edwardsfa8c9882023-08-16 15:27:53 -0700505 clrbits_le32(base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY,
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200506 LINK_CAPABILITY_ASPM_SUPPORT_MASK);
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200507
508 return 0;
509}
510
Nicolas Saenz Juliennedf10fe82021-01-14 16:49:01 +0100511static int brcm_pcie_remove(struct udevice *dev)
512{
513 struct brcm_pcie *pcie = dev_get_priv(dev);
514 void __iomem *base = pcie->base;
515
516 /* Assert fundamental reset */
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200517 setbits_le32(base + PCIE_RGR1_SW_INIT_1, PCIE_RGR1_SW_INIT_1_PERST_MASK);
Nicolas Saenz Juliennedf10fe82021-01-14 16:49:01 +0100518
519 /* Turn off SerDes */
520 setbits_le32(base + PCIE_MISC_HARD_PCIE_HARD_DEBUG,
521 PCIE_HARD_DEBUG_SERDES_IDDQ_MASK);
522
523 /* Shutdown bridge */
Simon Glass3ed3a4d2024-10-23 15:20:10 +0200524 setbits_le32(base + PCIE_RGR1_SW_INIT_1, PCIE_RGR1_SW_INIT_1_INIT_MASK);
Nicolas Saenz Juliennedf10fe82021-01-14 16:49:01 +0100525
526 return 0;
527}
528
Simon Glassaad29ae2020-12-03 16:55:21 -0700529static int brcm_pcie_of_to_plat(struct udevice *dev)
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200530{
531 struct brcm_pcie *pcie = dev_get_priv(dev);
532 ofnode dn = dev_ofnode(dev);
533 u32 max_link_speed;
534 int ret;
535
536 /* Get the controller base address */
537 pcie->base = dev_read_addr_ptr(dev);
538 if (!pcie->base)
539 return -EINVAL;
540
541 pcie->ssc = ofnode_read_bool(dn, "brcm,enable-ssc");
542
543 ret = ofnode_read_u32(dn, "max-link-speed", &max_link_speed);
544 if (ret < 0 || max_link_speed > 4)
545 pcie->gen = 0;
546 else
547 pcie->gen = max_link_speed;
548
549 return 0;
550}
551
552static const struct dm_pci_ops brcm_pcie_ops = {
553 .read_config = brcm_pcie_read_config,
554 .write_config = brcm_pcie_write_config,
555};
556
557static const struct udevice_id brcm_pcie_ids[] = {
558 { .compatible = "brcm,bcm2711-pcie" },
559 { }
560};
561
562U_BOOT_DRIVER(pcie_brcm_base) = {
563 .name = "pcie_brcm",
564 .id = UCLASS_PCI,
565 .ops = &brcm_pcie_ops,
566 .of_match = brcm_pcie_ids,
567 .probe = brcm_pcie_probe,
Nicolas Saenz Juliennedf10fe82021-01-14 16:49:01 +0100568 .remove = brcm_pcie_remove,
Simon Glassaad29ae2020-12-03 16:55:21 -0700569 .of_to_plat = brcm_pcie_of_to_plat,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700570 .priv_auto = sizeof(struct brcm_pcie),
Nicolas Saenz Juliennedf10fe82021-01-14 16:49:01 +0100571 .flags = DM_FLAG_OS_PREPARE,
Sylwester Nawrocki88f51f72020-05-25 13:39:58 +0200572};