Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5903DC001DF for ; Sun, 30 Jul 2023 18:17:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0E5638688B; Sun, 30 Jul 2023 20:17:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Xb8hbtd0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F0B77868D1; Sun, 30 Jul 2023 20:17:17 +0200 (CEST) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 898D9866DA for ; Sun, 30 Jul 2023 20:17:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=saproj@gmail.com Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5222b917e0cso5658096a12.0 for ; Sun, 30 Jul 2023 11:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690741035; x=1691345835; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fiX04wWoBiCje2SwSLJeXncNAihU5mKHeNy4nDgkye0=; b=Xb8hbtd0pOD0jaUqpM/oX4NjWhXRVBV1KzCqaNdfduqw08uF07SSS5mBvVbh7bB08x AWzQscLUqoxVEMG7INyXMQ8MW3ggfaL0u0rdL/PVLCo2/WDnSDTAGokT633R9nF0fh23 hEfIxlWTddL94b4aQoOI7vhK94g6TMX6bjC7YYSYOAWzawwxg6JhN44YX23QcK9qwMQ2 b+EkHWF0sXQWJ2Of2R0y1V/X/spSUfRVFkmpi9FBP1if5DqEU3XmOjBXB6Z5Dy+ReSYB 7kGCDJ0pTAtEuZDhyxJi2Qy8zcXy6t+m39hLtinkgYt2yS/KTSR7MbDhyWlmdQh+vShr E/mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690741035; x=1691345835; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fiX04wWoBiCje2SwSLJeXncNAihU5mKHeNy4nDgkye0=; b=JQHA/Ax0xYJuKXL+lfOqvNewk/4Y/WJv7dajAaqYCMR6dXpeWb7ytrFheNiv2sek2E cjrtHCCPg6XKAX2uwW8zJAjqaU59ll7gAwf9BC1wCH4f2c667y8GdVHv1ASTKUpy2i6I lRDST/7e3stsuy4SbAqw/vuR2fwtNFJGbK6U28HODLEFW4NUZLbSqbjFsqYyblI+ZfwW GJYr6TL+vwkM63GoK7W3wGVfTXFpdBdnqgKUT+i2hxzoZtIgZdpW1iQPFHk3+t7Mv5hg xumPRv8TNpeubHfW8B9SPIyWNIpAFD2tqMi6ZJAt8FcSxR7mb+2KfKasSWsy7hZbhYhk a/PA== X-Gm-Message-State: ABy/qLa9q8eYW2vKPg57550v7YKkQgEc0/bnrep+m62XvNFDZXhATdJ7 v1YLczLXlYosjzv7s9t3/I599cuN82M= X-Google-Smtp-Source: APBJJlHWuwsIjRcpdllNmLvfBXgzx82evQX2QnEVkiemL8bqxg7i60/4t4iSA4jytvWRDlLi7XzhCQ== X-Received: by 2002:a17:907:75da:b0:969:93f2:259a with SMTP id jl26-20020a17090775da00b0096993f2259amr5414647ejc.73.1690741034878; Sun, 30 Jul 2023 11:17:14 -0700 (PDT) Received: from saproj-Latitude-5501.yandex.net ([2a02:6b8:0:51e:788:6f8f:4433:f435]) by smtp.gmail.com with ESMTPSA id y9-20020a170906470900b0099bc8db97bcsm4935203ejq.131.2023.07.30.11.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 11:17:14 -0700 (PDT) From: Sergei Antonov To: u-boot@lists.denx.de, sjg@chromium.org Cc: Sergei Antonov Subject: [PATCH] pci: ftpci100: add new driver implementation Date: Sun, 30 Jul 2023 21:17:09 +0300 Message-Id: <20230730181709.1608133-1-saproj@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 --- configs/sandbox_defconfig | 1 + drivers/pci/Kconfig | 6 +++ drivers/pci/Makefile | 1 + drivers/pci/pci_ftpci100.c | 95 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 drivers/pci/pci_ftpci100.c diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index b6c4f735f2bd..c8538d4a193c 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -233,6 +233,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 diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index aca439d92139..f0678921e99d 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -125,6 +125,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 diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 11f60c6991d9..033dce98a4e1 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -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 index 000000000000..a1775445005a --- /dev/null +++ b/drivers/pci/pci_ftpci100.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include + +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(®s->conf, PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset)); + data = in_le32(®s->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(®s->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(®s->data); + + data = pci_conv_size_to_32(old, value, offset, size); + } + + out_le32(®s->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), +}; -- 2.37.2