blob: 8bc04c978d0446ac9df1404bf5ed8b65679b660b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Anton Schubert9c28d612015-08-11 11:54:01 +02002/*
3 * PCIe driver for Marvell MVEBU SoCs
4 *
5 * Based on Barebox drivers/pci/pci-mvebu.c
6 *
7 * Ported to U-Boot by:
8 * Anton Schubert <anton.schubert@gmx.de>
9 * Stefan Roese <sr@denx.de>
Anton Schubert9c28d612015-08-11 11:54:01 +020010 */
11
12#include <common.h>
Stefan Roese94f453e2019-01-25 11:52:43 +010013#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070015#include <malloc.h>
Stefan Roese94f453e2019-01-25 11:52:43 +010016#include <dm/device-internal.h>
17#include <dm/lists.h>
18#include <dm/of_access.h>
Anton Schubert9c28d612015-08-11 11:54:01 +020019#include <pci.h>
Anton Schubert9c28d612015-08-11 11:54:01 +020020#include <asm/io.h>
21#include <asm/arch/cpu.h>
22#include <asm/arch/soc.h>
Stefan Roese94f453e2019-01-25 11:52:43 +010023#include <linux/errno.h>
24#include <linux/ioport.h>
Anton Schubert9c28d612015-08-11 11:54:01 +020025#include <linux/mbus.h>
26
27DECLARE_GLOBAL_DATA_PTR;
28
29/* PCIe unit register offsets */
30#define SELECT(x, n) ((x >> n) & 1UL)
31
32#define PCIE_DEV_ID_OFF 0x0000
33#define PCIE_CMD_OFF 0x0004
34#define PCIE_DEV_REV_OFF 0x0008
35#define PCIE_BAR_LO_OFF(n) (0x0010 + ((n) << 3))
36#define PCIE_BAR_HI_OFF(n) (0x0014 + ((n) << 3))
37#define PCIE_CAPAB_OFF 0x0060
38#define PCIE_CTRL_STAT_OFF 0x0068
39#define PCIE_HEADER_LOG_4_OFF 0x0128
40#define PCIE_BAR_CTRL_OFF(n) (0x1804 + (((n) - 1) * 4))
41#define PCIE_WIN04_CTRL_OFF(n) (0x1820 + ((n) << 4))
42#define PCIE_WIN04_BASE_OFF(n) (0x1824 + ((n) << 4))
43#define PCIE_WIN04_REMAP_OFF(n) (0x182c + ((n) << 4))
44#define PCIE_WIN5_CTRL_OFF 0x1880
45#define PCIE_WIN5_BASE_OFF 0x1884
46#define PCIE_WIN5_REMAP_OFF 0x188c
47#define PCIE_CONF_ADDR_OFF 0x18f8
48#define PCIE_CONF_ADDR_EN BIT(31)
49#define PCIE_CONF_REG(r) ((((r) & 0xf00) << 16) | ((r) & 0xfc))
50#define PCIE_CONF_BUS(b) (((b) & 0xff) << 16)
51#define PCIE_CONF_DEV(d) (((d) & 0x1f) << 11)
52#define PCIE_CONF_FUNC(f) (((f) & 0x7) << 8)
53#define PCIE_CONF_ADDR(dev, reg) \
54 (PCIE_CONF_BUS(PCI_BUS(dev)) | PCIE_CONF_DEV(PCI_DEV(dev)) | \
55 PCIE_CONF_FUNC(PCI_FUNC(dev)) | PCIE_CONF_REG(reg) | \
56 PCIE_CONF_ADDR_EN)
57#define PCIE_CONF_DATA_OFF 0x18fc
58#define PCIE_MASK_OFF 0x1910
59#define PCIE_MASK_ENABLE_INTS (0xf << 24)
60#define PCIE_CTRL_OFF 0x1a00
61#define PCIE_CTRL_X1_MODE BIT(0)
62#define PCIE_STAT_OFF 0x1a04
63#define PCIE_STAT_BUS (0xff << 8)
64#define PCIE_STAT_DEV (0x1f << 16)
65#define PCIE_STAT_LINK_DOWN BIT(0)
66#define PCIE_DEBUG_CTRL 0x1a60
67#define PCIE_DEBUG_SOFT_RESET BIT(20)
68
Anton Schubert9c28d612015-08-11 11:54:01 +020069struct mvebu_pcie {
70 struct pci_controller hose;
Anton Schubert9c28d612015-08-11 11:54:01 +020071 void __iomem *base;
72 void __iomem *membase;
73 struct resource mem;
74 void __iomem *iobase;
75 u32 port;
76 u32 lane;
Stefan Roese94f453e2019-01-25 11:52:43 +010077 int devfn;
Anton Schubert9c28d612015-08-11 11:54:01 +020078 u32 lane_mask;
79 pci_dev_t dev;
Stefan Roese94f453e2019-01-25 11:52:43 +010080 char name[16];
81 unsigned int mem_target;
82 unsigned int mem_attr;
Anton Schubert9c28d612015-08-11 11:54:01 +020083};
84
Anton Schubert9c28d612015-08-11 11:54:01 +020085/*
86 * MVEBU PCIe controller needs MEMORY and I/O BARs to be mapped
VlaoMao49b23e02017-09-22 18:49:02 +030087 * into SoCs address space. Each controller will map 128M of MEM
Anton Schubert9c28d612015-08-11 11:54:01 +020088 * and 64K of I/O space when registered.
89 */
90static void __iomem *mvebu_pcie_membase = (void __iomem *)MBUS_PCI_MEM_BASE;
VlaoMao49b23e02017-09-22 18:49:02 +030091#define PCIE_MEM_SIZE (128 << 20)
Anton Schubert9c28d612015-08-11 11:54:01 +020092
Anton Schubert9c28d612015-08-11 11:54:01 +020093static inline bool mvebu_pcie_link_up(struct mvebu_pcie *pcie)
94{
95 u32 val;
96 val = readl(pcie->base + PCIE_STAT_OFF);
97 return !(val & PCIE_STAT_LINK_DOWN);
98}
99
100static void mvebu_pcie_set_local_bus_nr(struct mvebu_pcie *pcie, int busno)
101{
102 u32 stat;
103
104 stat = readl(pcie->base + PCIE_STAT_OFF);
105 stat &= ~PCIE_STAT_BUS;
106 stat |= busno << 8;
107 writel(stat, pcie->base + PCIE_STAT_OFF);
108}
109
110static void mvebu_pcie_set_local_dev_nr(struct mvebu_pcie *pcie, int devno)
111{
112 u32 stat;
113
114 stat = readl(pcie->base + PCIE_STAT_OFF);
115 stat &= ~PCIE_STAT_DEV;
116 stat |= devno << 16;
117 writel(stat, pcie->base + PCIE_STAT_OFF);
118}
119
120static int mvebu_pcie_get_local_bus_nr(struct mvebu_pcie *pcie)
121{
122 u32 stat;
123
124 stat = readl(pcie->base + PCIE_STAT_OFF);
125 return (stat & PCIE_STAT_BUS) >> 8;
126}
127
128static int mvebu_pcie_get_local_dev_nr(struct mvebu_pcie *pcie)
129{
130 u32 stat;
131
132 stat = readl(pcie->base + PCIE_STAT_OFF);
133 return (stat & PCIE_STAT_DEV) >> 16;
134}
135
136static inline struct mvebu_pcie *hose_to_pcie(struct pci_controller *hose)
137{
138 return container_of(hose, struct mvebu_pcie, hose);
139}
140
Simon Glassc4e72c42020-01-27 08:49:37 -0700141static int mvebu_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
Stefan Roese94f453e2019-01-25 11:52:43 +0100142 uint offset, ulong *valuep,
143 enum pci_size_t size)
Anton Schubert9c28d612015-08-11 11:54:01 +0200144{
Stefan Roese94f453e2019-01-25 11:52:43 +0100145 struct mvebu_pcie *pcie = dev_get_platdata(bus);
Anton Schubert9c28d612015-08-11 11:54:01 +0200146 int local_bus = PCI_BUS(pcie->dev);
147 int local_dev = PCI_DEV(pcie->dev);
148 u32 reg;
Stefan Roese94f453e2019-01-25 11:52:43 +0100149 u32 data;
150
151 debug("PCIE CFG read: (b,d,f)=(%2d,%2d,%2d) ",
152 PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
Anton Schubert9c28d612015-08-11 11:54:01 +0200153
154 /* Only allow one other device besides the local one on the local bus */
Stefan Roese94f453e2019-01-25 11:52:43 +0100155 if (PCI_BUS(bdf) == local_bus && PCI_DEV(bdf) != local_dev) {
156 if (local_dev == 0 && PCI_DEV(bdf) != 1) {
157 debug("- out of range\n");
Anton Schubert9c28d612015-08-11 11:54:01 +0200158 /*
159 * If local dev is 0, the first other dev can
160 * only be 1
161 */
Stefan Roese94f453e2019-01-25 11:52:43 +0100162 *valuep = pci_get_ff(size);
163 return 0;
164 } else if (local_dev != 0 && PCI_DEV(bdf) != 0) {
165 debug("- out of range\n");
Anton Schubert9c28d612015-08-11 11:54:01 +0200166 /*
167 * If local dev is not 0, the first other dev can
168 * only be 0
169 */
Stefan Roese94f453e2019-01-25 11:52:43 +0100170 *valuep = pci_get_ff(size);
171 return 0;
Anton Schubert9c28d612015-08-11 11:54:01 +0200172 }
173 }
174
175 /* write address */
Stefan Roese94f453e2019-01-25 11:52:43 +0100176 reg = PCIE_CONF_ADDR(bdf, offset);
Anton Schubert9c28d612015-08-11 11:54:01 +0200177 writel(reg, pcie->base + PCIE_CONF_ADDR_OFF);
Stefan Roese94f453e2019-01-25 11:52:43 +0100178 data = readl(pcie->base + PCIE_CONF_DATA_OFF);
179 debug("(addr,val)=(0x%04x, 0x%08x)\n", offset, data);
180 *valuep = pci_conv_32_to_size(data, offset, size);
Anton Schubert9c28d612015-08-11 11:54:01 +0200181
182 return 0;
183}
184
Stefan Roese94f453e2019-01-25 11:52:43 +0100185static int mvebu_pcie_write_config(struct udevice *bus, pci_dev_t bdf,
186 uint offset, ulong value,
187 enum pci_size_t size)
Anton Schubert9c28d612015-08-11 11:54:01 +0200188{
Stefan Roese94f453e2019-01-25 11:52:43 +0100189 struct mvebu_pcie *pcie = dev_get_platdata(bus);
Anton Schubert9c28d612015-08-11 11:54:01 +0200190 int local_bus = PCI_BUS(pcie->dev);
191 int local_dev = PCI_DEV(pcie->dev);
Stefan Roese94f453e2019-01-25 11:52:43 +0100192 u32 data;
193
194 debug("PCIE CFG write: (b,d,f)=(%2d,%2d,%2d) ",
195 PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
196 debug("(addr,val)=(0x%04x, 0x%08lx)\n", offset, value);
Anton Schubert9c28d612015-08-11 11:54:01 +0200197
198 /* Only allow one other device besides the local one on the local bus */
Stefan Roese94f453e2019-01-25 11:52:43 +0100199 if (PCI_BUS(bdf) == local_bus && PCI_DEV(bdf) != local_dev) {
200 if (local_dev == 0 && PCI_DEV(bdf) != 1) {
Anton Schubert9c28d612015-08-11 11:54:01 +0200201 /*
202 * If local dev is 0, the first other dev can
203 * only be 1
204 */
Stefan Roese94f453e2019-01-25 11:52:43 +0100205 return 0;
206 } else if (local_dev != 0 && PCI_DEV(bdf) != 0) {
Anton Schubert9c28d612015-08-11 11:54:01 +0200207 /*
208 * If local dev is not 0, the first other dev can
209 * only be 0
210 */
Stefan Roese94f453e2019-01-25 11:52:43 +0100211 return 0;
Anton Schubert9c28d612015-08-11 11:54:01 +0200212 }
213 }
214
Stefan Roese94f453e2019-01-25 11:52:43 +0100215 writel(PCIE_CONF_ADDR(bdf, offset), pcie->base + PCIE_CONF_ADDR_OFF);
216 data = pci_conv_size_to_32(0, value, offset, size);
217 writel(data, pcie->base + PCIE_CONF_DATA_OFF);
Anton Schubert9c28d612015-08-11 11:54:01 +0200218
219 return 0;
220}
221
222/*
223 * Setup PCIE BARs and Address Decode Wins:
224 * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks
225 * WIN[0-3] -> DRAM bank[0-3]
226 */
227static void mvebu_pcie_setup_wins(struct mvebu_pcie *pcie)
228{
229 const struct mbus_dram_target_info *dram = mvebu_mbus_dram_info();
230 u32 size;
231 int i;
232
233 /* First, disable and clear BARs and windows. */
234 for (i = 1; i < 3; i++) {
235 writel(0, pcie->base + PCIE_BAR_CTRL_OFF(i));
236 writel(0, pcie->base + PCIE_BAR_LO_OFF(i));
237 writel(0, pcie->base + PCIE_BAR_HI_OFF(i));
238 }
239
240 for (i = 0; i < 5; i++) {
241 writel(0, pcie->base + PCIE_WIN04_CTRL_OFF(i));
242 writel(0, pcie->base + PCIE_WIN04_BASE_OFF(i));
243 writel(0, pcie->base + PCIE_WIN04_REMAP_OFF(i));
244 }
245
246 writel(0, pcie->base + PCIE_WIN5_CTRL_OFF);
247 writel(0, pcie->base + PCIE_WIN5_BASE_OFF);
248 writel(0, pcie->base + PCIE_WIN5_REMAP_OFF);
249
250 /* Setup windows for DDR banks. Count total DDR size on the fly. */
251 size = 0;
252 for (i = 0; i < dram->num_cs; i++) {
253 const struct mbus_dram_window *cs = dram->cs + i;
254
255 writel(cs->base & 0xffff0000,
256 pcie->base + PCIE_WIN04_BASE_OFF(i));
257 writel(0, pcie->base + PCIE_WIN04_REMAP_OFF(i));
258 writel(((cs->size - 1) & 0xffff0000) |
259 (cs->mbus_attr << 8) |
260 (dram->mbus_dram_target_id << 4) | 1,
261 pcie->base + PCIE_WIN04_CTRL_OFF(i));
262
263 size += cs->size;
264 }
265
266 /* Round up 'size' to the nearest power of two. */
267 if ((size & (size - 1)) != 0)
268 size = 1 << fls(size);
269
270 /* Setup BAR[1] to all DRAM banks. */
271 writel(dram->cs[0].base | 0xc, pcie->base + PCIE_BAR_LO_OFF(1));
272 writel(0, pcie->base + PCIE_BAR_HI_OFF(1));
273 writel(((size - 1) & 0xffff0000) | 0x1,
274 pcie->base + PCIE_BAR_CTRL_OFF(1));
275}
276
Stefan Roese94f453e2019-01-25 11:52:43 +0100277static int mvebu_pcie_probe(struct udevice *dev)
Anton Schubert9c28d612015-08-11 11:54:01 +0200278{
Stefan Roese94f453e2019-01-25 11:52:43 +0100279 struct mvebu_pcie *pcie = dev_get_platdata(dev);
280 struct udevice *ctlr = pci_get_controller(dev);
281 struct pci_controller *hose = dev_get_uclass_priv(ctlr);
282 static int bus;
Anton Schubert9c28d612015-08-11 11:54:01 +0200283 u32 reg;
Anton Schubert9c28d612015-08-11 11:54:01 +0200284
Stefan Roese94f453e2019-01-25 11:52:43 +0100285 debug("%s: PCIe %d.%d - up, base %08x\n", __func__,
286 pcie->port, pcie->lane, (u32)pcie->base);
Anton Schubert9c28d612015-08-11 11:54:01 +0200287
Stefan Roese94f453e2019-01-25 11:52:43 +0100288 /* Read Id info and local bus/dev */
289 debug("direct conf read %08x, local bus %d, local dev %d\n",
290 readl(pcie->base), mvebu_pcie_get_local_bus_nr(pcie),
291 mvebu_pcie_get_local_dev_nr(pcie));
Anton Schubert9c28d612015-08-11 11:54:01 +0200292
Stefan Roese94f453e2019-01-25 11:52:43 +0100293 mvebu_pcie_set_local_bus_nr(pcie, bus);
294 mvebu_pcie_set_local_dev_nr(pcie, 0);
295 pcie->dev = PCI_BDF(bus, 0, 0);
Anton Schubert9c28d612015-08-11 11:54:01 +0200296
Stefan Roese94f453e2019-01-25 11:52:43 +0100297 pcie->mem.start = (u32)mvebu_pcie_membase;
298 pcie->mem.end = pcie->mem.start + PCIE_MEM_SIZE - 1;
299 mvebu_pcie_membase += PCIE_MEM_SIZE;
300
301 if (mvebu_mbus_add_window_by_id(pcie->mem_target, pcie->mem_attr,
302 (phys_addr_t)pcie->mem.start,
303 PCIE_MEM_SIZE)) {
304 printf("PCIe unable to add mbus window for mem at %08x+%08x\n",
305 (u32)pcie->mem.start, PCIE_MEM_SIZE);
306 }
307
308 /* Setup windows and configure host bridge */
309 mvebu_pcie_setup_wins(pcie);
310
311 /* Master + slave enable. */
312 reg = readl(pcie->base + PCIE_CMD_OFF);
313 reg |= PCI_COMMAND_MEMORY;
314 reg |= PCI_COMMAND_MASTER;
315 reg |= BIT(10); /* disable interrupts */
316 writel(reg, pcie->base + PCIE_CMD_OFF);
317
Stefan Roese94f453e2019-01-25 11:52:43 +0100318 /* PCI memory space */
319 pci_set_region(hose->regions + 0, pcie->mem.start,
320 pcie->mem.start, PCIE_MEM_SIZE, PCI_REGION_MEM);
321 pci_set_region(hose->regions + 1,
322 0, 0,
323 gd->ram_size,
324 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
325 hose->region_count = 2;
326
Marek Behún193a1e92019-08-07 15:01:56 +0200327 /* Set BAR0 to internal registers */
328 writel(SOC_REGS_PHY_BASE, pcie->base + PCIE_BAR_LO_OFF(0));
329 writel(0, pcie->base + PCIE_BAR_HI_OFF(0));
330
Stefan Roese94f453e2019-01-25 11:52:43 +0100331 bus++;
332
333 return 0;
334}
335
336static int mvebu_pcie_port_parse_dt(ofnode node, struct mvebu_pcie *pcie)
337{
338 const u32 *addr;
339 int len;
340
341 addr = ofnode_get_property(node, "assigned-addresses", &len);
342 if (!addr) {
343 pr_err("property \"assigned-addresses\" not found");
344 return -FDT_ERR_NOTFOUND;
345 }
346
347 pcie->base = (void *)(fdt32_to_cpu(addr[2]) + SOC_REGS_PHY_BASE);
348
349 return 0;
350}
351
352#define DT_FLAGS_TO_TYPE(flags) (((flags) >> 24) & 0x03)
353#define DT_TYPE_IO 0x1
354#define DT_TYPE_MEM32 0x2
355#define DT_CPUADDR_TO_TARGET(cpuaddr) (((cpuaddr) >> 56) & 0xFF)
356#define DT_CPUADDR_TO_ATTR(cpuaddr) (((cpuaddr) >> 48) & 0xFF)
357
358static int mvebu_get_tgt_attr(ofnode node, int devfn,
359 unsigned long type,
360 unsigned int *tgt,
361 unsigned int *attr)
362{
363 const int na = 3, ns = 2;
364 const __be32 *range;
365 int rlen, nranges, rangesz, pna, i;
366
367 *tgt = -1;
368 *attr = -1;
369
370 range = ofnode_get_property(node, "ranges", &rlen);
371 if (!range)
372 return -EINVAL;
373
Stefan Roese0df62e82019-02-11 07:53:34 +0100374 /*
375 * Linux uses of_n_addr_cells() to get the number of address cells
376 * here. Currently this function is only available in U-Boot when
377 * CONFIG_OF_LIVE is enabled. Until this is enabled for MVEBU in
378 * general, lets't hardcode the "pna" value in the U-Boot code.
379 */
Stefan Roese94f453e2019-01-25 11:52:43 +0100380 pna = 2; /* hardcoded for now because of lack of of_n_addr_cells() */
381 rangesz = pna + na + ns;
382 nranges = rlen / sizeof(__be32) / rangesz;
383
384 for (i = 0; i < nranges; i++, range += rangesz) {
385 u32 flags = of_read_number(range, 1);
386 u32 slot = of_read_number(range + 1, 1);
387 u64 cpuaddr = of_read_number(range + na, pna);
388 unsigned long rtype;
389
390 if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_IO)
391 rtype = IORESOURCE_IO;
392 else if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_MEM32)
393 rtype = IORESOURCE_MEM;
394 else
Anton Schubert9c28d612015-08-11 11:54:01 +0200395 continue;
Anton Schubert9c28d612015-08-11 11:54:01 +0200396
Stefan Roese94f453e2019-01-25 11:52:43 +0100397 /*
398 * The Linux code used PCI_SLOT() here, which expects devfn
399 * in bits 7..0. PCI_DEV() in U-Boot is similar to PCI_SLOT(),
400 * only expects devfn in 15..8, where its saved in this driver.
401 */
402 if (slot == PCI_DEV(devfn) && type == rtype) {
403 *tgt = DT_CPUADDR_TO_TARGET(cpuaddr);
404 *attr = DT_CPUADDR_TO_ATTR(cpuaddr);
405 return 0;
Phil Sutter9a045272015-12-25 14:41:20 +0100406 }
Anton Schubert9c28d612015-08-11 11:54:01 +0200407 }
Stefan Roese94f453e2019-01-25 11:52:43 +0100408
409 return -ENOENT;
Anton Schubert9c28d612015-08-11 11:54:01 +0200410}
Stefan Roese94f453e2019-01-25 11:52:43 +0100411
412static int mvebu_pcie_ofdata_to_platdata(struct udevice *dev)
413{
414 struct mvebu_pcie *pcie = dev_get_platdata(dev);
415 int ret = 0;
416
417 /* Get port number, lane number and memory target / attr */
418 if (ofnode_read_u32(dev_ofnode(dev), "marvell,pcie-port",
419 &pcie->port)) {
420 ret = -ENODEV;
421 goto err;
422 }
423
424 if (ofnode_read_u32(dev_ofnode(dev), "marvell,pcie-lane", &pcie->lane))
425 pcie->lane = 0;
426
427 sprintf(pcie->name, "pcie%d.%d", pcie->port, pcie->lane);
428
429 /* pci_get_devfn() returns devfn in bits 15..8, see PCI_DEV usage */
430 pcie->devfn = pci_get_devfn(dev);
431 if (pcie->devfn < 0) {
432 ret = -ENODEV;
433 goto err;
434 }
435
436 ret = mvebu_get_tgt_attr(dev_ofnode(dev->parent), pcie->devfn,
437 IORESOURCE_MEM,
438 &pcie->mem_target, &pcie->mem_attr);
439 if (ret < 0) {
440 printf("%s: cannot get tgt/attr for mem window\n", pcie->name);
441 goto err;
442 }
443
444 /* Parse PCIe controller register base from DT */
445 ret = mvebu_pcie_port_parse_dt(dev_ofnode(dev), pcie);
446 if (ret < 0)
447 goto err;
448
449 /* Check link and skip ports that have no link */
450 if (!mvebu_pcie_link_up(pcie)) {
451 debug("%s: %s - down\n", __func__, pcie->name);
452 ret = -ENODEV;
453 goto err;
454 }
455
456 return 0;
457
458err:
459 return ret;
460}
461
462static const struct dm_pci_ops mvebu_pcie_ops = {
463 .read_config = mvebu_pcie_read_config,
464 .write_config = mvebu_pcie_write_config,
465};
466
467static struct driver pcie_mvebu_drv = {
468 .name = "pcie_mvebu",
469 .id = UCLASS_PCI,
470 .ops = &mvebu_pcie_ops,
471 .probe = mvebu_pcie_probe,
472 .ofdata_to_platdata = mvebu_pcie_ofdata_to_platdata,
473 .platdata_auto_alloc_size = sizeof(struct mvebu_pcie),
474};
475
476/*
477 * Use a MISC device to bind the n instances (child nodes) of the
478 * PCIe base controller in UCLASS_PCI.
479 */
480static int mvebu_pcie_bind(struct udevice *parent)
481{
482 struct mvebu_pcie *pcie;
483 struct uclass_driver *drv;
484 struct udevice *dev;
485 ofnode subnode;
486
487 /* Lookup eth driver */
488 drv = lists_uclass_lookup(UCLASS_PCI);
489 if (!drv) {
490 puts("Cannot find PCI driver\n");
491 return -ENOENT;
492 }
493
494 ofnode_for_each_subnode(subnode, dev_ofnode(parent)) {
495 if (!ofnode_is_available(subnode))
496 continue;
497
498 pcie = calloc(1, sizeof(*pcie));
499 if (!pcie)
500 return -ENOMEM;
501
502 /* Create child device UCLASS_PCI and bind it */
503 device_bind_ofnode(parent, &pcie_mvebu_drv, pcie->name, pcie,
504 subnode, &dev);
505 }
506
507 return 0;
508}
509
510static const struct udevice_id mvebu_pcie_ids[] = {
511 { .compatible = "marvell,armada-xp-pcie" },
512 { .compatible = "marvell,armada-370-pcie" },
513 { }
514};
515
516U_BOOT_DRIVER(pcie_mvebu_base) = {
517 .name = "pcie_mvebu_base",
518 .id = UCLASS_MISC,
519 .of_match = mvebu_pcie_ids,
520 .bind = mvebu_pcie_bind,
521};