]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
pci: ftpci100: add new driver implementation
authorSergei Antonov <saproj@gmail.com>
Sun, 30 Jul 2023 18:17:09 +0000 (21:17 +0300)
committerTom Rini <trini@konsulko.com>
Mon, 14 Aug 2023 21:55:53 +0000 (17:55 -0400)
Add a new DM driver supporting FTPCI100 IP used in SoC designs.
This implementation is not based on the old non-DM ftpci100 code
dropped from U-Boot.

Enable the driver in sandbox_defconfig to test compilability.

Signed-off-by: Sergei Antonov <saproj@gmail.com>
configs/sandbox_defconfig
drivers/pci/Kconfig
drivers/pci/Makefile
drivers/pci/pci_ftpci100.c [new file with mode: 0644]

index f031b50910523cd0cf169f918e7f57d02f463bb4..259f31f26cee35633b60e275dbf30030d30be0bc 100644 (file)
@@ -231,6 +231,7 @@ CONFIG_MUX_MMIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PCI_SANDBOX=y
+CONFIG_PCI_FTPCI100=y
 CONFIG_PHY=y
 CONFIG_PHY_SANDBOX=y
 CONFIG_PINCTRL=y
index 74e514adbe0a812d43a66b536d0bcaf689a21532..463ec47eb92d5cdbda4d84fa9b1edc4663df3520 100644 (file)
@@ -127,6 +127,12 @@ config PCIE_APPLE
          Say Y here if you want to enable PCIe controller support on
          Apple SoCs.
 
+config PCI_FTPCI100
+       bool "Enable Faraday FTPCI100 PCI Bridge Controller driver"
+       help
+         Say Y here if you want to enable Faraday FTPCI100 PCI.
+         FTPCI100 IP is used in SoC chip designs.
+
 config PCI_GT64120
        bool "GT64120 PCI support"
        depends on MIPS
index a712a317a398a079555ed68d700ea5d973bfca10..72ef8b4bc77279b52b5e6cfa8cc2e39db2f78c22 100644 (file)
@@ -14,6 +14,7 @@ obj-$(CONFIG_PCI) += pci_auto_common.o pci_common.o
 obj-$(CONFIG_PCIE_ECAM_GENERIC) += pcie_ecam_generic.o
 obj-$(CONFIG_PCIE_ECAM_SYNQUACER) += pcie_ecam_synquacer.o
 obj-$(CONFIG_PCIE_APPLE) += pcie_apple.o
+obj-$(CONFIG_PCI_FTPCI100) += pci_ftpci100.o
 obj-$(CONFIG_PCI_GT64120) += pci_gt64120.o
 obj-$(CONFIG_PCI_MPC85XX) += pci_mpc85xx.o
 obj-$(CONFIG_PCI_MSC01) += pci_msc01.o
diff --git a/drivers/pci/pci_ftpci100.c b/drivers/pci/pci_ftpci100.c
new file mode 100644 (file)
index 0000000..a177544
--- /dev/null
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <common.h>
+#include <pci.h>
+#include <dm.h>
+#include <asm/io.h>
+
+struct ftpci100_data {
+       void *reg_base;
+};
+
+/* AHB Control Registers */
+struct ftpci100_ahbc {
+       u32 iosize;     /* 0x00 - I/O Space Size Signal */
+       u32 prot;       /* 0x04 - AHB Protection */
+       u32 rsved[8];   /* 0x08-0x24 - Reserved */
+       u32 conf;       /* 0x28 - PCI Configuration */
+       u32 data;       /* 0x2c - PCI Configuration DATA */
+};
+
+static int ftpci100_read_config(const struct udevice *dev, pci_dev_t bdf,
+                               uint offset, ulong *valuep,
+                               enum pci_size_t size)
+{
+       struct ftpci100_data *priv = dev_get_priv(dev);
+       struct ftpci100_ahbc *regs = priv->reg_base;
+       u32 data;
+
+       out_le32(&regs->conf, PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset));
+       data = in_le32(&regs->data);
+       *valuep = pci_conv_32_to_size(data, offset, size);
+
+       return 0;
+}
+
+static int ftpci100_write_config(struct udevice *dev, pci_dev_t bdf,
+                                uint offset, ulong value,
+                                enum pci_size_t size)
+{
+       struct ftpci100_data *priv = dev_get_priv(dev);
+       struct ftpci100_ahbc *regs = priv->reg_base;
+       u32 data;
+
+       out_le32(&regs->conf, PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset));
+
+       if (size == PCI_SIZE_32) {
+               data = value;
+       } else {
+               u32 old = in_le32(&regs->data);
+
+               data = pci_conv_size_to_32(old, value, offset, size);
+       }
+
+       out_le32(&regs->data, data);
+
+       return 0;
+}
+
+static int ftpci100_probe(struct udevice *dev)
+{
+       struct ftpci100_data *priv = dev_get_priv(dev);
+       struct pci_region *io, *mem;
+       int count;
+
+       count = pci_get_regions(dev, &io, &mem, NULL);
+       if (count != 2) {
+               printf("%s: wrong count of regions: %d != 2\n", dev->name, count);
+               return -EINVAL;
+       }
+
+       priv->reg_base = phys_to_virt(io->phys_start);
+       if (!priv->reg_base)
+               return -EINVAL;
+
+       return 0;
+}
+
+static const struct dm_pci_ops ftpci100_ops = {
+       .read_config    = ftpci100_read_config,
+       .write_config   = ftpci100_write_config,
+};
+
+static const struct udevice_id ftpci100_ids[] = {
+       { .compatible = "faraday,ftpci100" },
+       { }
+};
+
+U_BOOT_DRIVER(ftpci100_pci) = {
+       .name           = "ftpci100_pci",
+       .id             = UCLASS_PCI,
+       .of_match       = ftpci100_ids,
+       .ops            = &ftpci100_ops,
+       .probe          = ftpci100_probe,
+       .priv_auto      = sizeof(struct ftpci100_data),
+};