From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 634FBC44506 for ; Thu, 9 Jul 2026 04:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wK0zgVr1730o4bU02YyCGsEJba3OY0JKYDWYZK+gXCQ=; b=mxi1Z2Kjl4jEdP p92PDqZqtOu0MWIlaN6xv5ZwYqSAOz5HPWtGPHoyoCm3Zh1NtcwI1/BfO/SAn1Kjny1ncsLTCSBE5 RYv6cP4HXlT/7Mu/ohFF5cevOXKO47nAC8/NIHci9lzhmSuTVRwpWFuQDoNYaBd4poyKY3hdeKxl2 U1jybWgzfU42X20T1KpA673JOsfNUwlaVZEI4zRlxkrfAHi8cZhX1cR4U5LO0pF9CLT1/Q/OhhjsO gSX41Eu90iXnVLxzPiz6A6w4OO72rAtq4nmNAupC9n/2ZelGwNdZMhuQTu8XEqjPKb7JSdyHvJwht rj+W1/qwL0wBDh5+jtsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1whfx3-00000000xCt-3mGc; Thu, 09 Jul 2026 04:01:29 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1whfx0-00000000xBQ-3mdv for linux-riscv@lists.infradead.org; Thu, 09 Jul 2026 04:01:29 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2cc61541f8cso7241255ad.0 for ; Wed, 08 Jul 2026 21:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783569686; x=1784174486; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5q+pTBwamVSA/mf9LeULWykUlYzRmW8hf3toSZ8K/5w=; b=ibkplstU5rPbaTRRcHS8ZT3I7v2Gq0A6K5O3aJPCZxlv+ifTrHBUMfS55X8P/5va9x gBBYqDcOibtqNDbxZDYerSivviD+Iw01BJWFI8e0lWc7a/8os7jvdFXnw8odFXzHVR3w r0dyZVRFETl8/+qe/OzgkZJHEeVlzFzLgj6hpeCV7xMQCO4EaQysas7EqKHyTAHPU/MQ REC/W41J3vjzdee/lBOBiOKlKBCfV4bGwdfzw7BkscQbfHM/1RT8ZLTJldKhVzE1vkel PabqpNHGGI3eCj0kva2zt525g1SYiRBEdBkrzYRVvoithiAARNJ/wWpxBlC/3n+CuO/V ApPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783569686; x=1784174486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5q+pTBwamVSA/mf9LeULWykUlYzRmW8hf3toSZ8K/5w=; b=npDoE9LLk0P5tbVpEVJZcFqMBR737ZPh9LIjj7Kuq9v4/k1ZiPcX8MuFVhUs7pFAq7 0TIETcnfFl9TOWwVLUbRtc8/LMtXBcLOJ2Pph5An1B4PdA6i/rcjZhVpv6wPSSRy1pNk vReWLR0h7j+Wn4CCjHok8IAXsdN8z8GCXgtWDtD1gyQ5y6BqQMp5uRcN1Jgq33II/qpg pjl3ecdQz8Y1Ecv1SFdcFeyF4Xqf0kDfSQ1XEIX091LOlyc5LMkECun49FKvKHbiMy6y Qnj8OgMZuCeT5jaEDlfzrjgwkLwvryQoOW+prN5qpvrqC66uShIgl3TR+oY65+/2LMRR cIXQ== X-Forwarded-Encrypted: i=1; AHgh+RpTyo9Op0Fz1hk/jOGpXfbsf/9adenjK5y+iWb8CYIpTBWq4sky8QaDXoehiA7XK3sQJ4FPsAzoApDEgg==@lists.infradead.org X-Gm-Message-State: AOJu0YyQe7ocyuCPfOpjhkrdNWRukMInvrKH+0F0cg4+bcylahpHjKKO qt4orna0hnjeGX3ahTpunhjjUDxcFSh5BzWjC33TrPx+gSevYq2Za+tl X-Gm-Gg: AfdE7ck9pTejWtoAbn1pVZD1wzAEouejYLllRd5uDBNVTtdo5E4VN2j0snfnwH3gDdB SAm5qNFR/+8zdLwLtKH79BuEzAP9sfMVPnDPq0qzhofHBW2eo3aJ3pIM81YSPqpFUXrJILraXmj sPen9PstDTtWtUPQc5lY4Aw/toZBopW8SjC9kysvrHUfR5ZkLpszHOJkJR8+TmyrOtl7hr+WXbv ikhZIs1vq2oSpGxxH1P85pLdT0LsZAhjHDQmkQGjEDVgZRLz/hCsNKKDOdSHUfzg93cfMwEZB2X iVq/T+Swc9tOoBJNBJZtzEO5So36Z7+o25/OZ2TxYncFyvUmEePrz7TJQ8mo2Bup74pTRggz4QU TG9aSEBaPZDglvmr6wNLSXamlwX5/BLThoNIr+Tp5wpvgfwnanKNBErYCfY9IBenUYN8NbIBBvp 4= X-Received: by 2002:a17:90b:524f:b0:36b:769c:c037 with SMTP id 98e67ed59e1d1-38b73c6a1fcmr1044903a91.5.1783569685878; Wed, 08 Jul 2026 21:01:25 -0700 (PDT) Received: from localhost ([2001:da8:7001:11::cb]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38a55557f25sm443538a91.5.2026.07.08.21.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 21:01:25 -0700 (PDT) From: Inochi Amaoto To: Jingoo Han , Manivannan Sadhasivam , Bjorn Helgaas , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Yixun Lan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Christian Bruel , Inochi Amaoto , Frank Li , Nam Cao , Qiang Yu , Krishna Chaitanya Chundru , Xincheng Zhang , Alex Elder , Siddharth Vadapalli , Andy Shevchenko , Vidya Sagar , Neil Armstrong , Gustavo Pimentel Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, Yixun Lan , Longbin Li Subject: [PATCH v4 2/6] PCI: spacemit-k1: Add multiple PHY handles support Date: Thu, 9 Jul 2026 12:00:22 +0800 Message-ID: <20260709040027.958400-3-inochiama@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260709040027.958400-1-inochiama@gmail.com> References: <20260709040027.958400-1-inochiama@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260708_210126_966560_360E0875 X-CRM114-Status: GOOD ( 21.99 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The PCIe controller on Spacemit K3 may use multiple PHYs at the same time. The feature is not support by the current driver. So extend the PHY definition to support multiple PHY handles. Signed-off-by: Inochi Amaoto --- drivers/pci/controller/dwc/pcie-spacemit-k1.c | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-spacemit-k1.c b/drivers/pci/controller/dwc/pcie-spacemit-k1.c index f6ae8ff3589a..e22ecbd09579 100644 --- a/drivers/pci/controller/dwc/pcie-spacemit-k1.c +++ b/drivers/pci/controller/dwc/pcie-spacemit-k1.c @@ -55,12 +55,14 @@ struct k1_pcie_device_data { const struct dw_pcie_host_ops *host_ops; const struct dw_pcie_ops *ops; int (*parse_port)(struct k1_pcie *k1); + unsigned int max_phy_count; }; struct k1_pcie { struct dw_pcie pci; const struct k1_pcie_device_data *data; - struct phy *phy; + struct phy **phy; + unsigned int phy_count; void __iomem *link; struct regmap *pmu; /* Errors ignored; MMIO-backed regmap */ u32 pmu_off; @@ -119,6 +121,54 @@ static void k1_pcie_disable_resources(struct k1_pcie *k1) clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks); } +static int k1_pcie_get_phy_handle(struct k1_pcie *k1, struct device_node *node) +{ + const struct k1_pcie_device_data *data = k1->data; + struct device *dev = k1->pci.dev; + unsigned int i; + + k1->phy = devm_kmalloc_array(dev, data->max_phy_count, + sizeof(*k1->phy), GFP_KERNEL); + if (!k1->phy) + return -ENOMEM; + + for (i = 0; i < data->max_phy_count; i++) { + k1->phy[i] = devm_of_phy_get_by_index(dev, node, i); + if (IS_ERR(k1->phy[i])) { + if (PTR_ERR(k1->phy[i]) == -ENODEV) + break; + + return PTR_ERR(k1->phy[i]); + } + } + + k1->phy_count = i; + if (k1->phy_count == 0) + return -EINVAL; + + return 0; +} + +static int k1_pcie_enable_phy(struct k1_pcie *k1) +{ + unsigned int i; + int ret; + + for (i = 0; i < k1->phy_count; i++) { + ret = phy_init(k1->phy[i]); + if (ret) + goto err_phy; + } + + return 0; + +err_phy: + while (i--) + phy_exit(k1->phy[i]); + + return ret; +} + /* FIXME: Disable ASPM L1 to avoid errors reported on some NVMe drives */ static void k1_pcie_disable_aspm_l1(struct k1_pcie *k1) { @@ -174,7 +224,7 @@ static int k1_pcie_init(struct dw_pcie_rp *pp) */ regmap_set_bits(k1->pmu, reset_ctrl, DEVICE_TYPE_RC | PCIE_AUX_PWR_DET); - ret = phy_init(k1->phy); + ret = k1_pcie_enable_phy(k1); if (ret) { k1_pcie_disable_resources(k1); @@ -194,12 +244,14 @@ static void k1_pcie_deinit(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); struct k1_pcie *k1 = to_k1_pcie(pci); + int i; /* Assert fundamental reset (drive PERST# low) */ regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL, PCIE_RC_PERST); - phy_exit(k1->phy); + for (i = 0; i < k1->phy_count; i++) + phy_exit(k1->phy[i]); k1_pcie_disable_resources(k1); } @@ -266,23 +318,18 @@ static int k1_pcie_parse_port(struct k1_pcie *k1) { struct device *dev = k1->pci.dev; struct device_node *root_port; - struct phy *phy; + int ret; /* We assume only one root port */ root_port = of_get_next_available_child(dev_of_node(dev), NULL); if (!root_port) return -EINVAL; - phy = devm_of_phy_get(dev, root_port, NULL); + ret = k1_pcie_get_phy_handle(k1, root_port); of_node_put(root_port); - if (IS_ERR(phy)) - return PTR_ERR(phy); - - k1->phy = phy; - - return 0; + return ret; } static int k1_pcie_probe(struct platform_device *pdev) @@ -358,6 +405,7 @@ static const struct k1_pcie_device_data k1_pcie_device_data = { .host_ops = &k1_pcie_host_ops, .ops = &k1_pcie_ops, .parse_port = k1_pcie_parse_port, + .max_phy_count = 1, }; static const struct of_device_id k1_pcie_of_match_table[] = { -- 2.55.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv