1 // SPDX-License-Identifier: GPL-2.0+
11 #include <linux/delay.h>
13 #include <mach/octeon-model.h>
14 #include <mach/octeon_pci.h>
15 #include <mach/cvmx-regs.h>
16 #include <mach/cvmx-pcie.h>
17 #include <mach/cvmx-pemx-defs.h>
27 static bool octeon_bdf_invalid(pci_dev_t bdf, int first_busno)
30 * In PCIe only a single device (0) can exist on the local bus.
31 * Beyound the local bus, there might be a switch and everything
34 if ((PCI_BUS(bdf) == first_busno) && (PCI_DEV(bdf) > 0))
40 static int pcie_octeon_write_config(struct udevice *bus, pci_dev_t bdf,
41 uint offset, ulong value,
44 struct octeon_pcie *pcie = dev_get_priv(bus);
45 struct pci_controller *hose = dev_get_uclass_priv(bus);
49 debug("PCIE CFG write: (b,d,f)=(%2d,%2d,%2d) ",
50 PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
51 debug("(addr,size,val)=(0x%04x, %d, 0x%08lx)\n", offset, size, value);
53 port = pcie->pcie_port;
54 busno = PCI_BUS(bdf) - hose->first_busno + 1;
58 cvmx_pcie_config_write8(port, busno, PCI_DEV(bdf),
59 PCI_FUNC(bdf), offset, value);
62 cvmx_pcie_config_write16(port, busno, PCI_DEV(bdf),
63 PCI_FUNC(bdf), offset, value);
66 cvmx_pcie_config_write32(port, busno, PCI_DEV(bdf),
67 PCI_FUNC(bdf), offset, value);
70 printf("Invalid size\n");
76 static int pcie_octeon_read_config(const struct udevice *bus, pci_dev_t bdf,
77 uint offset, ulong *valuep,
80 struct octeon_pcie *pcie = dev_get_priv(bus);
81 struct pci_controller *hose = dev_get_uclass_priv(bus);
85 port = pcie->pcie_port;
86 busno = PCI_BUS(bdf) - hose->first_busno + 1;
87 if (octeon_bdf_invalid(bdf, pcie->first_busno)) {
88 *valuep = pci_get_ff(size);
94 *valuep = cvmx_pcie_config_read8(port, busno, PCI_DEV(bdf),
95 PCI_FUNC(bdf), offset);
98 *valuep = cvmx_pcie_config_read16(port, busno, PCI_DEV(bdf),
99 PCI_FUNC(bdf), offset);
102 *valuep = cvmx_pcie_config_read32(port, busno, PCI_DEV(bdf),
103 PCI_FUNC(bdf), offset);
106 printf("Invalid size\n");
109 debug("%02x.%02x.%02x: u%d %x -> %lx\n",
110 PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), size, offset, *valuep);
115 static int pcie_octeon_probe(struct udevice *dev)
117 struct octeon_pcie *pcie = dev_get_priv(dev);
118 int node = cvmx_get_node_num();
122 /* Get port number, lane number and memory target / attr */
123 if (ofnode_read_u32(dev_ofnode(dev), "marvell,pcie-port",
129 pcie->first_busno = dev_seq(dev);
130 pcie_port = ((node << 4) | pcie->port);
131 ret = cvmx_pcie_rc_initialize(pcie_port);
141 static const struct dm_pci_ops pcie_octeon_ops = {
142 .read_config = pcie_octeon_read_config,
143 .write_config = pcie_octeon_write_config,
146 static const struct udevice_id pcie_octeon_ids[] = {
147 { .compatible = "marvell,pcie-host-octeon" },
151 U_BOOT_DRIVER(pcie_octeon) = {
152 .name = "pcie_octeon",
154 .of_match = pcie_octeon_ids,
155 .ops = &pcie_octeon_ops,
156 .probe = pcie_octeon_probe,
157 .priv_auto = sizeof(struct octeon_pcie),
158 .flags = DM_FLAG_PRE_RELOC,