From nobody Fri Dec 19 15:34:16 2025 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9274130FC35 for ; Mon, 13 Oct 2025 15:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369735; cv=none; b=OhuiaAh2Fmyq99GLOYts19vei79tpwORcGykBjUvfS2ChFaxiPc/kt195ZYbGiloiUGWIVZhCIOsokn4Mg0w/wb83fjMQcqzejZ48ofqVJONLf5NdO2uUqY9BwOHjkOII3LQNrcM5SCU8aJUuKL5Tsmm9rFHbRH/0pBnqFZeCyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369735; c=relaxed/simple; bh=BpOZ7MH28/mxqVI8xL2FBxK2+2yB/1BVmp49i4x2sTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TOBxMAoGwWCgk/tp8AaGOfcArod0x/CcOoCQ7nIslGYO6HEdISZ3Ne9M1wITTotVgcUBuFUqA9Z0WEvh4SNUP9jAixxF4TQXrFu3XnwGYhJfHF0q5jBLuk/40yHaxhmjnLcxIaqqXvFJalB7zLW47sMDMRGnvNjuo+E0oig3em0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=AiNHPnyM; arc=none smtp.client-ip=209.85.166.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="AiNHPnyM" Received: by mail-io1-f68.google.com with SMTP id ca18e2360f4ac-912d4135379so174756039f.1 for ; Mon, 13 Oct 2025 08:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369733; x=1760974533; darn=vger.kernel.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; bh=RoI6kMthZduzT8ZYZ3qN3cAQpgGG6MRRgU4QbQyijoo=; b=AiNHPnyMeR9AgSoj4A4nm0c/kJxdiAsH5EuejfXiTm596EnHvm9+tcdxMASb0VS07a WXks2/yY+ks1NkQ9spaDerqfJTgm7J89GTNdikXVWd7w2ap0X9aE4YWIVOw11esluXyX MH3GKhKDv1w9dWBRTN6KGN4MxLfzYA0mqRg0IlTIvZQjrKZKrlrtM9Lgn0sNQenNI+si gkzgxT+/vKaVp7KI9lQ6UxaIXvWrxoJG4/lLHiq/GHiTRztV2SLQxLRP5WI7yrOJfbNq Yz6ejToMa/PSwe38ToE06tbGXkdKO2vGFK35K8aYnoNiqWq0ayHvpChOpQ4GWI+2FLEP H7CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369733; x=1760974533; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RoI6kMthZduzT8ZYZ3qN3cAQpgGG6MRRgU4QbQyijoo=; b=hFe5QtBPPTRXs48RzLsE3ywO36wSV/Uk4PR/KspXLcjEutZAbrdQ9HH1TeFUwzxM36 jj3b59XpxRDd7VK07jWwiiMkqCtzWk0acQjNAdIt2rjAXwCbCGc+q5nQAG7jLYUaeVHm wPWB3/TaJRgOjQBMbD3/g7eBPZXR0IDBWLbYsZLiV13q0xHDnc6fkNXhNEcCyl7pPLp0 su4RguLtOG/mcH0OGjPJP3YXWuDYYa7LNzI1xwEVowxufdj8OraPyz9yIOsQ7reCbzsK MpdKiME9KPkJfaczeLbSOqTucOCGoWn5PCLzMkLsfnqv34C+Ngdk9DASRr1W1soz3br3 UToQ== X-Forwarded-Encrypted: i=1; AJvYcCXaiWLJulhPwOPY32H9nJR6+a/I4P559sigiaB8tn8X1nuhldNJvSAUyVHIqyEsdknQacgt3uFBTrx3Orc=@vger.kernel.org X-Gm-Message-State: AOJu0YyH8OKVK4JBjUkxy5Qti5OU5nj/9Bux/no8rC6Qt+NUQBgFFq7J snyv+dmgiEOaA75KkR1h1KvuIx+AgBjD3PnvraUrcHOIBxd7OKvjDEX9tHEHndeEKdc= X-Gm-Gg: ASbGnctVM4cK2GmgcciBAZklZFxb58oRInS4vwEIT29mrsHY7wa4FjDs9BZM+OsYKJ/ fGOyzquuJQ4jJi+gZuRupasEKUkndvK+MD6NWaTOXMYfhojT+Byf3XT0pKdqdNuwhTvIpnjk7cl Fn9MKCjyrUnjFoXNaocoMuAS3qTQ72G9UD9ze8jZDdjPfUPcVt5a+NmvmKqnxSFvO7L2dMWa0k0 no4UdWC8lxzYV5WR5BV4Im3Z4UoJa4Pr64rlFPS5WcGT+/yNuvR0QDwQuT/5nPmU12y/+Xi1uIH Zc7uH2fg6MU67UbfuDRg9RUsQ6IaAaa6Fa0AYTt9/eYwwYyjDroj/5QGOfz/VS7xBHt+SagjYSv gSoUCG4BOiuSxgmMSkrFNg2Ye0ZHW6eOjJ9tjrniJoTJHuLk93xDpSZImsJkw9NUXOi7cQ8sGHp vK8rkzrxb4 X-Google-Smtp-Source: AGHT+IHNZy44agm51sCB0W97tyTX1zzziU2yBhjgQ7PRISv17V55+lCQRt+SG1OTrzoY5/d0w7/HeA== X-Received: by 2002:a05:6602:492:b0:900:1fa2:5919 with SMTP id ca18e2360f4ac-93bd19882e8mr2625044139f.9.1760369732669; Mon, 13 Oct 2025 08:35:32 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:32 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] dt-bindings: phy: spacemit: add SpacemiT PCIe/combo PHY Date: Mon, 13 Oct 2025 10:35:18 -0500 Message-ID: <20251013153526.2276556-2-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the Device Tree binding for the PCIe/USB 3.0 combo PHY found in the SpacemiT K1 SoC. This is one of three PCIe PHYs, and is unusual in that only the combo PHY can perform a calibration step needed to determine settings used by the other two PCIe PHYs. Calibration must be done with the combo PHY in PCIe mode, and to allow this to occur independent of the eventual use for the PHY (PCIe or USB) some PCIe-related properties must be supplied: clocks; resets; and a syscon phandle. Signed-off-by: Alex Elder Reviewed-by: Rob Herring (Arm) --- v2: - Added '>' to the description, and reworded it a bit - Added an external oscillator clock, "refclk" - Renamed the "global" reset to be "phy" - Renamed a phandle property to be "spacemit,apmu" - Dropped the label and status property from the example .../bindings/phy/spacemit,k1-combo-phy.yaml | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-combo= -phy.yaml diff --git a/Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.ya= ml b/Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml new file mode 100644 index 0000000000000..6e2f401b0ac27 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml @@ -0,0 +1,114 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/spacemit,k1-combo-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K1 PCIe/USB3 Combo PHY + +maintainers: + - Alex Elder + +description: > + Of the three PHYs on the SpacemiT K1 SoC capable of being used for + PCIe, one is a combo PHY that can also be configured for use by a + USB 3 controller. Using PCIe or USB 3 is a board design decision. + + The combo PHY is also the only PCIe PHY that is able to determine + PCIe calibration values to use, and this must be determined before + the other two PCIe PHYs can be used. This calibration must be + performed with the combo PHY in PCIe mode, and is this is done + when the combo PHY is probed. + + The combo PHY uses an external oscillator as a reference clock. + During normal operation, the PCIe or USB port driver is responsible + for ensuring all other clocks needed by a PHY are enabled, and all + resets affecting the PHY are deasserted. However, for the combo + PHY to perform calibration independent of whether it's later used + for PCIe or USB, all PCIe mode clocks and resets must be defined. + +properties: + compatible: + const: spacemit,k1-combo-phy + + reg: + items: + - description: PHY control registers + + clocks: + items: + - description: External oscillator used by the PHY PLL + - description: DWC PCIe Data Bus Interface (DBI) clock + - description: DWC PCIe application AXI-bus Master interface clock + - description: DWC PCIe application AXI-bus slave interface clock + + clock-names: + items: + - const: refclk + - const: dbi + - const: mstr + - const: slv + + resets: + items: + - description: DWC PCIe Data Bus Interface (DBI) reset + - description: DWC PCIe application AXI-bus Master interface reset + - description: DWC PCIe application AXI-bus slave interface reset + - description: PHY reset; must be deasserted for PHY to function + + reset-names: + items: + - const: dbi + - const: mstr + - const: slv + - const: phy + + spacemit,apmu: + description: + A phandle that refers to the APMU system controller, whose + regmap is used in setting the mode + $ref: /schemas/types.yaml#/definitions/phandle + + "#phy-cells": + const: 1 + description: + The argument value (PHY_TYPE_PCIE or PHY_TYPE_USB3) determines + whether the PHY operates in PCIe or USB3 mode. + +required: + - compatible + - reg + - clocks + - clock-names + - resets + - reset-names + - spacemit,apmu + - "#phy-cells" + +additionalProperties: false + +examples: + - | + #include + phy@c0b10000 { + compatible =3D "spacemit,k1-combo-phy"; + reg =3D <0xc0b10000 0x1000>; + clocks =3D <&vctcxo_24m>, + <&syscon_apmu CLK_PCIE0_DBI>, + <&syscon_apmu CLK_PCIE0_MASTER>, + <&syscon_apmu CLK_PCIE0_SLAVE>; + clock-names =3D "refclk", + "dbi", + "mstr", + "slv"; + resets =3D <&syscon_apmu RESET_PCIE0_DBI>, + <&syscon_apmu RESET_PCIE0_MASTER>, + <&syscon_apmu RESET_PCIE0_SLAVE>, + <&syscon_apmu RESET_PCIE0_GLOBAL>; + reset-names =3D "dbi", + "mstr", + "slv", + "phy"; + spacemit,apmu =3D <&syscon_apmu>; + #phy-cells =3D <1>; + }; --=20 2.48.1 From nobody Fri Dec 19 15:34:16 2025 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B99253128C9 for ; Mon, 13 Oct 2025 15:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369737; cv=none; b=pGWgqyk1EE6rxkM9cTYtxRmxck/HHddmCGNpGoUBStqE94lE+OqjesOVufT8kBL7CNn5oRV22mPPK6JhQkV1JH7ocD6y+bwNgdmFnsdouWCehdUYmtFHFiC8et26jKYlQc7UpeuGPc3Lhn1AM08wD8Kh5SP3rwjKfsn9QpYBQ3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369737; c=relaxed/simple; bh=hkeK1J/xegPc5qIcOqDK54lS/unN+bKpCdPA2OuYM+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VhVaT8Dghmd7vPZi/L3etazuXmVoeO2uMuyGKFdvscOlvP+/z+2jo6o8g1S99oz6gNRXi7jeXbItEJff0Q7ULhvC0386bpa/rhdUHfQZF80vFVzV8kdYsL6Pf4BilNG7s8KRtfbq+5Neu0O0TO0+MxAwng4fne+RQRKJfLwO6NE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=DDrxncu7; arc=none smtp.client-ip=209.85.166.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="DDrxncu7" Received: by mail-io1-f65.google.com with SMTP id ca18e2360f4ac-93e2d26fc82so242974039f.0 for ; Mon, 13 Oct 2025 08:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369734; x=1760974534; darn=vger.kernel.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; bh=ItZ4QqP7CdgD+87y0OCgM795Wvqv9yPDWR/uT7250ws=; b=DDrxncu7OIS7Sber7v9EsFaCJa+SDfC9HCiEDpn8eFRSI0PHkoa1UJI+JmMLlaYmqR V92aNMjQPUBLqu6LGbkyL/EysPJBL9Ce+nhQAxaC+u5U63FVTGBvxa4v0mMhDbzOaf0S oxzCtTjvxx6MwvYzVqXgvT3Uf6sS0M4ktEpYqgyqtCWgAj/uZjiNb5OsvLrybQLGbfDW 1gil3egM9UuBoxhECvHMTyUoOTc8qxYXagXK5CUG6a852mnEYblgYYrarE0vwq6xG0lD EwH+2VuqhJTtYPR7n2sdLBEwMiY+RgyljHADH+Emo7Z4ClWyacsypSy3ZSUzfjjb83Dp H0pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369734; x=1760974534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ItZ4QqP7CdgD+87y0OCgM795Wvqv9yPDWR/uT7250ws=; b=rGXivkqX6GAL3ePd9GywqKfL8kd6GQjbglW7HuyqJwecaDDFh1eJOx7Ql5KzlHXO/X qn0grW8oFbGFHU9eRoklM4XLl9V0A4lJRWDr7NBV/QFWob9oquJlSRCvrvBR/Vk1TZRa 46vIIGNAgQ7aeLdRl98Uk/ohpBDJPDlHvqZaDfbzGjt3rgNGPxZcxH3tyJduOGGcT5Ov 10jiC/0kbHmZyGY27lH4jK08NI2UEPX7wJWoFuncENmLUMNYiwou2rljMELslLZxYn+i VmGnrHi++JeTxb+iXIAQ3+ReBGfkoWpxbt0ppyYLxmJfxdwrtnEs1lq3vn6JyRvXY61j g9Fw== X-Forwarded-Encrypted: i=1; AJvYcCW3cPhudRJnWmAR40cqVfVAggNpgS9lka9L8kagPahzQ7iYft+qsR1Iy4encVX8ZqRgzZysaR7M/omWYI4=@vger.kernel.org X-Gm-Message-State: AOJu0YzXOcKaWant5nnn9BcXLPTJHOyxKD28MkDxqXSjW7qbeNwL4BzF +ycu7Csoh+J5tSm1jvP96Si/ftMMPZ1tbHfPi2bIcIbQpjiqxhCu//d90LNRK9+aUv0= X-Gm-Gg: ASbGnctAyMXh+vE+fmbA0f/OJXSgaa4OV8BEYkD/h/PSedq91nM6h0IUa9J/XpOKEAZ 0HVqHVgr7ME6Ztm5qwQOsG1WoLqA1DjgaFd3hgstEMjxQz+6c3W5oip+DkpBkxAzlnP8YdTibpz UEVy+e2NnlgUMBaiGbQV3AMqmPz7gSl8ttxW8eGGv4qyaweynazowPZBRfQ6WODMwuHTnoOaieO Ep7MXzDmwDN/LeJaR3ex099mkE63j4frgm4x668pV4W2ficP57Gq0/wzH/48UbdztyTSVbQC5rq E7QZsCVqlUPiYdZ5sVKe4Tx8PQDASlQQBVPpp9Aiu22R7T1ncyHaby9gP7urnfbodhsD0m6E/K1 85wpxFWEtGrxvCnG/PgGenlM5AZGWQb/enRm/TrGSQH/0+NWRolHxp4Pw+yucCoGi/gU48uzHSm JxepwBCriSa7h11clO8Zk= X-Google-Smtp-Source: AGHT+IFmberiHinW0psgBSVXvfzyFWo7xiMin2ObR4QgSx+XvFz7VLt0jdPRSfZZaq11AbbGpmoe2w== X-Received: by 2002:a05:6e02:1808:b0:42f:a6cf:8afa with SMTP id e9e14a558f8ab-42fa6cf8cc8mr116550035ab.19.1760369734595; Mon, 13 Oct 2025 08:35:34 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:34 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] dt-bindings: phy: spacemit: introduce PCIe PHY Date: Mon, 13 Oct 2025 10:35:19 -0500 Message-ID: <20251013153526.2276556-3-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the Device Tree binding for two PCIe PHYs present on the SpacemiT K1 SoC. These PHYs are dependent on a separate combo PHY, which determines at probe time the calibration values used by the PCIe-only PHYs. Signed-off-by: Alex Elder Reviewed-by: Rob Herring (Arm) --- v2: - Added '>' to the description, and reworded it a bit - Added clocks and clock-names properties - Dropped the label and status property from the example .../bindings/phy/spacemit,k1-pcie-phy.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-pcie-= phy.yaml diff --git a/Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yam= l b/Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml new file mode 100644 index 0000000000000..c821f6cafcdae --- /dev/null +++ b/Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/spacemit,k1-pcie-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K1 PCIe PHY + +maintainers: + - Alex Elder + +description: > + There are two PHYs on the SpacemiT K1 SoC used for PCIe (only). + These PHYs must be configured using calibration values that are + determined by a third "combo PHY". The combo PHY determines + these calibration values during probe so they can be used for + the two PCIe-only PHYs. + + The PHY uses an external oscillator as a reference clock. During + normal operation, the PCIe host driver is responsible for ensuring + all other clocks needed by a PHY are enabled, and all resets + affecting the PHY are deasserted. + +properties: + compatible: + const: spacemit,k1-pcie-phy + + reg: + items: + - description: PHY control registers + + clocks: + items: + - description: External oscillator used by the PHY PLL + + clock-names: + const: refclk + + "#phy-cells": + const: 0 + +required: + - compatible + - reg + - clocks + - clock-names + - "#phy-cells" + +additionalProperties: false + +examples: + - | + phy@c0c10000 { + compatible =3D "spacemit,k1-pcie-phy"; + reg =3D <0xc0c10000 0x1000>; + clocks =3D <&vctcxo_24m>; + clock-names =3D "refclk"; + #phy-cells =3D <0>; + }; --=20 2.48.1 From nobody Fri Dec 19 15:34:16 2025 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5549B3128DD for ; Mon, 13 Oct 2025 15:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369739; cv=none; b=lE9+xYtUBud5JRmjAaGgqfv56wpsuCfFBD7zqnvwgTTevkTt02jnV4dqN25dwj5E1MfxU32TfmIHkixArA8KIXhin5p306V/qRm/EgE0Qj0AohMQKhGrxA7HKTpWCq51Q+/0rk19dRPimlVhCB21JuZQn2bvv8IHzkVp8V3PogM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369739; c=relaxed/simple; bh=g3onUkgevlk1RjMxAzZNUt+BDhEsfUgytM/vs6wob2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GJfecR9Cz5+Tv4lBhtnBCfQmnIln5WyZvDIl/PeB4ApeJCEnKRwNMV9+EWneq18L8fMxJjJBq7kfIZDCc5KnCFkdzCajtLckE59nRYmikj3a4Eq7nBSpBES8G2KMCJ0scL1823ENmDh8vnGMDjlIy4y7/eWfztqzIY0QdPwHwig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=1pxTxKAE; arc=none smtp.client-ip=209.85.166.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="1pxTxKAE" Received: by mail-il1-f195.google.com with SMTP id e9e14a558f8ab-425911e5661so17814555ab.1 for ; Mon, 13 Oct 2025 08:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369736; x=1760974536; darn=vger.kernel.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; bh=clcUhTCzkpc78EGP0YwMtfP0eONI0FKHMHfxFBjJETM=; b=1pxTxKAEKDjWDENqK9uLdjrSl0iCodsgCx5ckEZNC6hu199q2Dl2dIS/fcKEHqz7Y7 p/CmPx9W8kNHm3Yk/EgwxUkEqKAgnloEO9jcLRJ6RkvCsxM9ChDLqEv4co1bgD9EXIUO OSbn51X5gPWcAx4Xmnuv3g7FxrkxUlO5BDtXGKs1VacnimO0h2g/4XvuQYNAHspaKPxI SlUAn4kqRAn4RQ24c5sbS0oSb+A3/HP+n42QPomD3EEKqeQshyI+kA2fHdPz4usFGl54 PuLUFSxEb6vrecO3SqG75yf4XM83p/w1zXC+o6goBtGA0OuNQWMk5jmmGE3aFLWqUC3w bQlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369736; x=1760974536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=clcUhTCzkpc78EGP0YwMtfP0eONI0FKHMHfxFBjJETM=; b=ESyj9T2pJU0n8RNSHNj7OR7Z6S+HqrDyEF7FTRkk+0dJBVjHkNVSDW9Qucej2yzoyt Mrg/+LWS04nLOWI7UacNErNhNZrTV48zRkfaLk7XPJo8YbRzuGvCKZCJSDeYy2XLPMJh zOp52Cr6gJkUS2nu01wg1uuUwEQLUEWa/LKJPU55I9hA+kD+jjwFpWHAt3HA8AXAjuNz Sf5bKRzV8U6UKW+VGxhRHutHTL2N7y2EsVlInFbKYzMVevf+YhSa455BhiIT+lWoNIZv Tfa1HU6cHLewJk7QovFk9UtWhu6SW4F+2EcUqOPIOpD1ohxi7NvuWGbE+kG5VK6Ihj2j 3r6Q== X-Forwarded-Encrypted: i=1; AJvYcCXQTL7kHnhSA8K9Ovss3U1SP/06eoc/iFRzTQ+mpCMSg0E3QRsePjUyAAoxS9GxklqZWSCyLzjYkLDQ/G0=@vger.kernel.org X-Gm-Message-State: AOJu0YyKh1kc6SGaRA0woJuOYZuVJsaNkMR+ToSNi723oNcaUdZHNS+3 hpmorJRiHmHOUq28PpD3OdLj31XF2wz0cskaEAO2t2J2St9UC+NIlMJ5y9NoNWIkftE= X-Gm-Gg: ASbGncuaqL9gU1pXtQdcY2B8EQ9ZpV7hzk7KYYupDqs4Z/oNInp4bYEGd1VfRiu2Is8 yN9qoGMo9dW0RaXTlPWvWN6ReVMjHzqS/eLh8Ib5uvWHvRC4h5PXq3MfJ1bgqdIPn80g6hwfHRK xp/IpZ9PaICc/oBNlbUBx2iSpTlU9HUe9mi4sCq/8RyXIxyGEpSDBzKjfdeDqOLb49mMMD5jV0g ghE+nL0HGWeg9WCG5fJjZ/zQ9HXyfiAFgdphMi7NhFJmIrspJzkDXV8cUnn3tUFp6wchG3xhisj q+OdULbhvTKwdP8Sgpt6tcdQwSxsMFBgcEpWhUd0rKltKLZIWmvXnEaCjQdtfM52yKRdSPcuIC9 89RrLN5jiOM75vqxdv+AcG+0XZuYg1nxGwgYkBoStsk5k1y1Gnsc/tKg6SVSiKl0cECse3xdwmS k7kH7OjuNSyRy2WDcMvkQ= X-Google-Smtp-Source: AGHT+IEq1wU/8vuzVnjoUBATSgPDNzjkdQ/9lH3LryiLTNpDHF/z7PYkRPiy89nhGm+aAHjbFqAt/A== X-Received: by 2002:a05:6e02:214a:b0:42d:8bf0:29f7 with SMTP id e9e14a558f8ab-42f8736a9c8mr198413275ab.9.1760369736542; Mon, 13 Oct 2025 08:35:36 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:36 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller Date: Mon, 13 Oct 2025 10:35:20 -0500 Message-ID: <20251013153526.2276556-4-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port. Signed-off-by: Alex Elder --- v2: - Renamed the binding, using "host controller" - Added '>' to the description, and reworded it a bit - Added reference to /schemas/pci/snps,dw-pcie.yaml - Fixed and renamed the compatible string - Renamed the PMU property, and fixed its description - Consistently omit the period at the end of descriptions - Renamed the "global" clock to be "phy" - Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose - Added a vpcie3v3-supply property - Dropped the max-link-speed property - Changed additionalProperties to unevaluatedProperties - Dropped the label and status property from the example .../bindings/pci/spacemit,k1-pcie-host.yaml | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-= host.yaml diff --git a/Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.ya= ml b/Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file mode 100644 index 0000000000000..87745d49c53a1 --- /dev/null +++ b/Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml @@ -0,0 +1,156 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K1 PCI Express Host Controller + +maintainers: + - Alex Elder + +description: > + The SpacemiT K1 SoC PCIe host controller is based on the Synopsys + DesignWare PCIe IP. The controller uses the DesignWare built-in + MSI interrupt controller, and supports 256 MSIs. + +allOf: + - $ref: /schemas/pci/snps,dw-pcie.yaml# + +properties: + compatible: + const: spacemit,k1-pcie + + reg: + items: + - description: DesignWare PCIe registers + - description: ATU address space + - description: PCIe configuration space + - description: Link control registers + + reg-names: + items: + - const: dbi + - const: atu + - const: config + - const: link + + spacemit,apmu: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + A phandle that refers to the APMU system controller, whose + regmap is used in managing resets and link state, along with + and offset of its reset control register. + items: + - items: + - description: phandle to APMU system controller + - description: register offset + + clocks: + items: + - description: DWC PCIe Data Bus Interface (DBI) clock + - description: DWC PCIe application AXI-bus master interface clock + - description: DWC PCIe application AXI-bus slave interface clock + + clock-names: + items: + - const: dbi + - const: mstr + - const: slv + + resets: + items: + - description: DWC PCIe Data Bus Interface (DBI) reset + - description: DWC PCIe application AXI-bus master interface reset + - description: DWC PCIe application AXI-bus slave interface reset + - description: Global reset; must be deasserted for PHY to function + + reset-names: + items: + - const: dbi + - const: mstr + - const: slv + - const: phy + + interrupts: + items: + - description: Interrupt used for MSIs + + interrupt-names: + const: msi + + phys: + maxItems: 1 + + vpcie3v3-supply: + description: + A phandle for 3.3v regulator to use for PCIe + + device_type: + const: pci + + num-viewport: + const: 8 + +required: + - compatible + - reg + - reg-names + - spacemit,apmu + - "#address-cells" + - "#size-cells" + - ranges + - clocks + - clock-names + - resets + - reset-names + - interrupts + - interrupt-names + - phys + - vpcie3v3-supply + - device_type + - num-viewport + +unevaluatedProperties: false + +examples: + - | + #include + pcie@ca400000 { + compatible =3D "spacemit,k1-pcie"; + reg =3D <0xca400000 0x00001000>, + <0xca700000 0x0001ff24>, + <0x9f000000 0x00002000>, + <0xc0c20000 0x00001000>; + reg-names =3D "dbi", + "atu", + "config", + "link"; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges =3D <0x01000000 0x0 0x00000000 0x9f002000 0x0 0x00100000>, + <0x02000000 0x0 0x90000000 0x90000000 0x0 0x0f000000>; + interrupts =3D <142>; + interrupt-names =3D "msi"; + clocks =3D <&syscon_apmu CLK_PCIE1_DBI>, + <&syscon_apmu CLK_PCIE1_MASTER>, + <&syscon_apmu CLK_PCIE1_SLAVE>; + clock-names =3D "dbi", + "mstr", + "slv"; + resets =3D <&syscon_apmu RESET_PCIE1_DBI>, + <&syscon_apmu RESET_PCIE1_MASTER>, + <&syscon_apmu RESET_PCIE1_SLAVE>, + <&syscon_apmu RESET_PCIE1_GLOBAL>; + reset-names =3D "dbi", + "mstr", + "slv", + "phy"; + phys =3D <&pcie1_phy>; + vpcie3v3-supply =3D <&pcie_vcc_3v3>; + device_type =3D "pci"; + num-viewport =3D <8>; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie1_3_cfg>; + spacemit,apmu =3D <&syscon_apmu 0x3d4>; + }; --=20 2.48.1 From nobody Fri Dec 19 15:34:16 2025 Received: from mail-il1-f196.google.com (mail-il1-f196.google.com [209.85.166.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF1B5313295 for ; Mon, 13 Oct 2025 15:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369742; cv=none; b=jweKj0l3kizciOJX2WchkcfgGzOpdFmVURY8NqhUcOlwixdMbaUv0abM4YM8SRlGyjNDOONfECQJiG6brzh/0rN1C4fmdiHpWSiQZvn6bIqzh4Z4XwfpHsOkOTDuzxy3WfnjXmE4PwaDcbzf2OdEWnSzwvSvIJcn0AQ10ne/u8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369742; c=relaxed/simple; bh=BZzLT2zTqqohce5XiFaeA7Y4ZBvLdr8R11zUfUnjosA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YkGyQ054BlOoor7AgPQOFhqufPtt71kSflMXziw0fPDnDRAcX3KIwxkDtyNtObYWLDG0djzEzdF32DS7Div7zoBhjHZ+2Uh5vpVIxVVsBjBOVtTggUriorYsl2ZybobZADGUCxE3L4L5XiFhL+1NkrI2L8Xz5nju84VvxoXmLn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=R/EqLILR; arc=none smtp.client-ip=209.85.166.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="R/EqLILR" Received: by mail-il1-f196.google.com with SMTP id e9e14a558f8ab-42d857dcf92so16515655ab.1 for ; Mon, 13 Oct 2025 08:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369739; x=1760974539; darn=vger.kernel.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; bh=aBCCSnYnVlbpKUHll5nMGocmcp9VAJDVhRzqTmH+szM=; b=R/EqLILRHbcVt/BBTOy6/4asGSiQg2HJXjGP+ic2lB6iZrDc/kqdaAuTE+LShBCc3z Tzjd6DqTmHY677vScXwwnMNMfY7igvJiOYNdRhRLBagf5YkSvf0eWxq6R/D0lUjJN+BC RHflg8KJLjTz2I4grFEDvg6PxKyC5wk/CwvhML62UMI+Gm9BofSF+uKKkCe6LuO7qjOB FvIyKlsGQeCVGMohZ/+0bDlvybSXbU2HlfdjTWyf6g3q6QSVdGoqvkKyM2ar2B5Eeod9 XwX7CCrx90XND/m+pdsHUF6gi8iClvLk10Dfg1xmMUYlNa+1kvMdjtwK0G7KjKZiFfRW 2c3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369739; x=1760974539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aBCCSnYnVlbpKUHll5nMGocmcp9VAJDVhRzqTmH+szM=; b=C3l7EMPvcbVgR5BonhvaEwaemfQ5yqP6TxGXuPuq5ScH9EjdIodFpHeVw3A/D5O5sp /LungMM8SSsMRBRmB1MI0MjFWmgO3ezQOTuwyPSecNzgruxYw0qshG2GK3tU40+OJyC2 B6WMTtUrUHmJG7js1IAo+Pjf/69Bk6VlBdRiDv8AuAj3Qi1etk8HS52C6fV49frevziN vpcEpHt4303nO6sKY6kYVoTwy6Hi3OKo+n2FWo5nXI/HGaxVNxFQlvh75bl30pDvnJEB kQAYiCV+AT0cxZ0Em+B9v4T8X3Tj97HvVcYrUwKpNHh8EKODg0CPEv6llFsw+e14o3mN rXWQ== X-Forwarded-Encrypted: i=1; AJvYcCVhyTpzgoqKvHYzvo7+YFK6cJUIg2idIqrSXab3HyiBMzIwYbj6gfn9qfJEwbVTphZZeca2gBLcQBGZRPo=@vger.kernel.org X-Gm-Message-State: AOJu0YwL3SLsLJAWO3lR67hbmxtF+rJpKFErhbZQpJs0d6JQYPrxMDZX EPoAX/SeROaaEjNFu7KWXkaNTRGuEilRh4pXZqN5DCk9HCb+Fuq8yLaA50eFQSHprDk= X-Gm-Gg: ASbGncuIq6+oAgRedI7H+mSZ/o+HTJ2Aa/Yxf0aREzdQ8s1l2F3ybb22z0ePEGJ/mY0 pn6EkpfJ4BRDYH7DB2WLqwuYhQP8iNTROG9G2mpU7BzE9IdEtH+OTBfHvdJX0AG8fq4GCpLtOvL d9sTWChwqpLENSEp9DazsBndMl3k/qbf9sOw25BksySAaCOIE7GITuigWXzHATSCzWRKAedXnTN or6Hag7QbzHmQF23YukB2wjhgvge9tUI9GG6NXfr2BzIjtv/FzAGOlSdsWm6OhVcrDlQLrkVgNx 7sCrNHPznmduFRBMUzoWquZW0PE20GzwpRg4o/Q/zwddnLNFL/gb8B/+Yp5CXm0uPlp/ersWcx6 rXw/2SjKi93ClBDBy6P+AqMjDA1H2RtoBSxnawJb+JahB7V+aXhvSdhvleSTuiRZYuu2Ml+Kl/1 U7Xsv1ipt2 X-Google-Smtp-Source: AGHT+IEUKLWHfv4WOxCqt3I62OMkhCpDR1jT8M+ohLnH8jpHa2C5L+kA+je4O8RkLJDRWoFTpDkvCw== X-Received: by 2002:a05:6e02:144e:b0:42f:9ba7:e471 with SMTP id e9e14a558f8ab-42f9ba7e713mr122216845ab.20.1760369738846; Mon, 13 Oct 2025 08:35:38 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:38 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Junzhong Pan Subject: [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY Date: Mon, 13 Oct 2025 10:35:21 -0500 Message-ID: <20251013153526.2276556-5-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a driver that supports three PHYs found on the SpacemiT K1 SoC. The first PHY is a combo PHY that can be configured for use for either USB 3 or PCIe. The other two PHYs support PCIe only. All three PHYs must be programmed with an 8 bit receiver termination value, which must be determined dynamically. Only the combo PHY is able to determine this value. The combo PHY performs a special calibration step at probe time to discover this, and that value is used to program each PHY that operates in PCIe mode. The combo PHY must therefore be probed before either of the PCIe-only PHYs will be used. Each PHY has an internal PLL driven from an external oscillator. This PLL started when the PHY is first initialized, and stays on thereafter. During normal operation, the USB or PCIe driver using the PHY must ensure (other) clocks and resets are set up properly. However PCIe mode clocks are enabled and resets are de-asserted temporarily by this driver to perform the calibration step on the combo PHY. Tested-by: Junzhong Pan Signed-off-by: Alex Elder --- v2: - Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1 - Reimplemented the PHY PLL as a clock registered with the common clock framework, driven by an external oscillator - Memory-mapped regmap operations no longer check for errors - Bulk clocks are now named, allowing the PLL clock to be managed separate from the rest - No longer use a "virt" local variable for read/modify/write - Deleted a few unused symbol definitions - Added and reworded some comments drivers/phy/Kconfig | 11 + drivers/phy/Makefile | 1 + drivers/phy/phy-spacemit-k1-pcie.c | 672 +++++++++++++++++++++++++++++ 3 files changed, 684 insertions(+) create mode 100644 drivers/phy/phy-spacemit-k1-pcie.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 678dd0452f0aa..1984c2e56122e 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -101,6 +101,17 @@ config PHY_NXP_PTN3222 schemes. It supports all three USB 2.0 data rates: Low Speed, Full Speed and High Speed. =20 +config PHY_SPACEMIT_K1_PCIE + tristate "PCIe and combo PHY driver for the SpacemiT K1 SoC" + depends on ARCH_SPACEMIT || COMPILE_TEST + depends on HAS_IOMEM + depends on OF + select GENERIC_PHY + default ARCH_SPACEMIT + help + Enable support for the PCIe and USB 3 combo PHY and two + PCIe-only PHYs used in the SpacemiT K1 SoC. + source "drivers/phy/allwinner/Kconfig" source "drivers/phy/amlogic/Kconfig" source "drivers/phy/broadcom/Kconfig" diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index bfb27fb5a4942..a206133a35151 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_PHY_SNPS_EUSB2) +=3D phy-snps-eusb2.o obj-$(CONFIG_USB_LGM_PHY) +=3D phy-lgm-usb.o obj-$(CONFIG_PHY_AIROHA_PCIE) +=3D phy-airoha-pcie.o obj-$(CONFIG_PHY_NXP_PTN3222) +=3D phy-nxp-ptn3222.o +obj-$(CONFIG_PHY_SPACEMIT_K1_PCIE) +=3D phy-spacemit-k1-pcie.o obj-y +=3D allwinner/ \ amlogic/ \ broadcom/ \ diff --git a/drivers/phy/phy-spacemit-k1-pcie.c b/drivers/phy/phy-spacemit-= k1-pcie.c new file mode 100644 index 0000000000000..81bc05823d080 --- /dev/null +++ b/drivers/phy/phy-spacemit-k1-pcie.c @@ -0,0 +1,672 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * SpacemiT K1 PCIe and PCIe/USB 3 combo PHY driver + * + * Copyright (C) 2025 by RISCstar Solutions Corporation. All rights reser= ved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Three PCIe ports are supported in the SpacemiT K1 SoC, and this driver + * supports their PHYs. + * + * The PHY for PCIe port A is different from the PHYs for ports B and C: + * - It has one lane, while ports B and C have two + * - It is a combo PHY can be used for PCIe or USB 3 + * - It can automatically calibrate PCIe TX and RX termination settings + * + * The PHY functionality for PCIe ports B and C is identical: + * - They have two PCIe lanes (but can be restricted to 1 via Device Tree) + * - They are used for PCIe only + * - They are configured using TX and RX values computed for port A + * + * A given board is designed to use the combo PHY for either PCIe or USB 3. + * Whether the combo PHY is configured for PCIe or USB 3 is specified in + * Device Tree using a phandle plus an argument. The argument indicates + * the type (either PHY_TYPE_PCIE or PHY_TYPE_USB3). + * + * Each PHY depends on clocks and resets provided by the controller + * hardware (PCIe or USB) it is associated with. The controller drivers + * are required to enable any clocks and de-assert any resets that affect + * PHY operation. In addition each PHY implements an internal PLL, driven + * by an external (24 MHz) oscillator. + * + * PCIe PHYs must be programmed with RX and TX calibration values. The + * combo PHY is the only one that can determine these values. They are + * determined by temporarily enabling the combo PHY in PCIe mode at probe + * time (if necessary). This calibration only needs to be done once, and + * when it has completed the TX and RX values are saved. + * + * To allow the combo PHY to be enabled for calibration, the resets and + * clocks it uses in PCIe mode must be supplied. + */ + +struct k1_pcie_phy { + struct device *dev; /* PHY provider device */ + struct phy *phy; + void __iomem *regs; + u32 pcie_lanes; /* Max (1 or 2) unless limited by DT */ + struct clk *pll; + struct clk_hw pll_hw; /* Private PLL clock */ + + /* The remaining fields are only used for the combo PHY */ + u32 type; /* PHY_TYPE_PCIE or PHY_TYPE_USB3 */ + struct regmap *pmu; /* MMIO regmap (no errors) */ +}; + +#define CALIBRATION_TIMEOUT 500000 /* For combo PHY (usec) */ +#define PLL_TIMEOUT 500000 /* For PHY PLL lock (usec) */ +#define POLL_DELAY 500 /* Time between polls (usec) */ + +/* Selecting the combo PHY operating mode requires APMU regmap access */ +#define SYSCON_APMU "spacemit,apmu" + +/* PMU space, for selecting between PCIe and USB 3 mode (combo PHY only) */ + +#define PMUA_USB_PHY_CTRL0 0x0110 +#define COMBO_PHY_SEL BIT(3) /* 0: PCIe; 1: USB 3 */ + +#define PCIE_CLK_RES_CTRL 0x03cc +#define PCIE_APP_HOLD_PHY_RST BIT(30) + +/* PHY register space */ + +/* Offset between lane 0 and lane 1 registers when there are two */ +#define PHY_LANE_OFFSET 0x0400 + +/* PHY PLL configuration */ +#define PCIE_PU_ADDR_CLK_CFG 0x0008 +#define PLL_READY BIT(0) /* read-only */ +#define CFG_INTERNAL_TIMER_ADJ GENMASK(10, 7) +#define TIMER_ADJ_USB 0x2 +#define TIMER_ADJ_PCIE 0x6 +#define CFG_SW_PHY_INIT_DONE BIT(11) /* We set after PLL config */ + +#define PCIE_RC_DONE_STATUS 0x0018 +#define CFG_FORCE_RCV_RETRY BIT(10) /* Used for PCIe */ + +/* PCIe PHY lane calibration; assumes 24MHz input clock */ +#define PCIE_RC_CAL_REG2 0x0020 +#define RC_CAL_TOGGLE BIT(22) +#define CLKSEL GENMASK(31, 29) +#define CLKSEL_24M 0x3 + +/* Additional PHY PLL configuration (USB 3 and PCIe) */ +#define PCIE_PU_PLL_1 0x0048 +#define REF_100_WSSC BIT(12) /* 1: input is 100MHz, SSC */ +#define FREF_SEL GENMASK(15, 13) +#define FREF_24M 0x1 +#define SSC_DEP_SEL GENMASK(19, 16) +#define SSC_DEP_NONE 0x0 +#define SSC_DEP_5000PPM 0xa + +/* PCIe PHY configuration */ +#define PCIE_PU_PLL_2 0x004c +#define GEN_REF100 BIT(4) /* 1: generate 100MHz clk */ + +#define PCIE_RX_REG1 0x0050 +#define EN_RTERM BIT(3) +#define AFE_RTERM_REG GENMASK(11, 8) + +#define PCIE_RX_REG2 0x0054 +#define RX_RTERM_SEL BIT(5) /* 0: use AFE_RTERM_REG value */ + +#define PCIE_LTSSM_DIS_ENTRY 0x005c +#define CFG_REFCLK_MODE GENMASK(9, 8) +#define RFCLK_MODE_DRIVER 0x1 +#define OVRD_REFCLK_MODE BIT(10) /* 1: use CFG_RFCLK_MODE */ + +#define PCIE_TX_REG1 0x0064 +#define TX_RTERM_REG GENMASK(15, 12) +#define TX_RTERM_SEL BIT(25) /* 1: use TX_RTERM_REG */ + +/* Zeroed for the combo PHY operating in USB mode */ +#define USB3_TEST_CTRL 0x0068 + +/* PHY calibration values, determined by the combo PHY at probe time */ +#define PCIE_RCAL_RESULT 0x0084 /* Port A PHY only */ +#define RTERM_VALUE_RX GENMASK(3, 0) +#define RTERM_VALUE_TX GENMASK(7, 4) +#define R_TUNE_DONE BIT(10) + +static u32 k1_phy_rterm =3D ~0; /* Invalid initial value */ + +/* Save the RX and TX receiver termination values */ +static void k1_phy_rterm_set(u32 val) +{ + k1_phy_rterm =3D val & (RTERM_VALUE_RX | RTERM_VALUE_TX); +} + +static bool k1_phy_rterm_valid(void) +{ + /* Valid if no bits outside those we care about are set */ + return !(k1_phy_rterm & ~(RTERM_VALUE_RX | RTERM_VALUE_TX)); +} + +static u32 k1_phy_rterm_rx(void) +{ + return FIELD_GET(RTERM_VALUE_RX, k1_phy_rterm); +} + +static u32 k1_phy_rterm_tx(void) +{ + return FIELD_GET(RTERM_VALUE_TX, k1_phy_rterm); +} + +/* Only the combo PHY has a PMU pointer defined */ +static bool k1_phy_port_a(struct k1_pcie_phy *k1_phy) +{ + return !!k1_phy->pmu; +} + +/* The PLL clocks are driven by the external oscillator */ +static const struct clk_parent_data k1_pcie_phy_data[] =3D { + { .fw_name =3D "refclk", }, +}; + +static struct k1_pcie_phy *clk_hw_to_k1_phy(struct clk_hw *clk_hw) +{ + return container_of(clk_hw, struct k1_pcie_phy, pll_hw); +} + +/* USB mode only works on the combo PHY, which has only one lane */ +static void k1_pcie_phy_pll_prepare_usb(struct k1_pcie_phy *k1_phy) +{ + void __iomem *regs =3D k1_phy->regs; + u32 val; + + val =3D readl(regs + PCIE_PU_ADDR_CLK_CFG); + val &=3D ~CFG_INTERNAL_TIMER_ADJ; + val |=3D FIELD_PREP(CFG_INTERNAL_TIMER_ADJ, TIMER_ADJ_USB); + writel(val, regs + PCIE_PU_ADDR_CLK_CFG); + + val =3D readl(regs + PCIE_PU_PLL_1); + val &=3D ~SSC_DEP_SEL; + val |=3D FIELD_PREP(SSC_DEP_SEL, SSC_DEP_5000PPM); + writel(val, regs + PCIE_PU_PLL_1); +} + +/* Perform PCIe-specific register updates before starting the PLL clock */ +static void k1_pcie_phy_pll_prepare_pcie(struct k1_pcie_phy *k1_phy) +{ + void __iomem *regs =3D k1_phy->regs; + u32 val; + u32 i; + + for (i =3D 0; i < k1_phy->pcie_lanes; i++) { + val =3D readl(regs + PCIE_PU_ADDR_CLK_CFG); + val &=3D ~CFG_INTERNAL_TIMER_ADJ; + val |=3D FIELD_PREP(CFG_INTERNAL_TIMER_ADJ, TIMER_ADJ_PCIE); + writel(val, regs + PCIE_PU_ADDR_CLK_CFG); + + regs +=3D PHY_LANE_OFFSET; /* Next lane */ + } + + regs =3D k1_phy->regs; + val =3D readl(regs + PCIE_RC_DONE_STATUS); + val |=3D CFG_FORCE_RCV_RETRY; + writel(val, regs + PCIE_RC_DONE_STATUS); + + val =3D readl(regs + PCIE_PU_PLL_1); + val &=3D ~SSC_DEP_SEL; + val |=3D FIELD_PREP(SSC_DEP_SEL, SSC_DEP_NONE); + writel(val, regs + PCIE_PU_PLL_1); + + val =3D readl(regs + PCIE_PU_PLL_2); + val |=3D GEN_REF100; /* Enable 100 MHz PLL output clock */ + writel(val, regs + PCIE_PU_PLL_2); +} + +static int k1_pcie_phy_pll_prepare(struct clk_hw *clk_hw) +{ + struct k1_pcie_phy *k1_phy =3D clk_hw_to_k1_phy(clk_hw); + void __iomem *regs =3D k1_phy->regs; + u32 val; + u32 i; + + if (k1_phy_port_a(k1_phy) && k1_phy->type =3D=3D PHY_TYPE_USB3) + k1_pcie_phy_pll_prepare_usb(k1_phy); + else + k1_pcie_phy_pll_prepare_pcie(k1_phy); + + /* + * Disable 100 MHz input reference with spread-spectrum + * clocking and select the 24 MHz clock input frequency + */ + val =3D readl(regs + PCIE_PU_PLL_1); + val &=3D ~REF_100_WSSC; + val &=3D ~FREF_SEL; + val |=3D FIELD_PREP(FREF_SEL, FREF_24M); + writel(val, regs + PCIE_PU_PLL_1); + + /* Mark PLL configuration done on all lanes */ + for (i =3D 0; i < k1_phy->pcie_lanes; i++) { + val =3D readl(regs + PCIE_PU_ADDR_CLK_CFG); + val |=3D CFG_SW_PHY_INIT_DONE; + writel(val, regs + PCIE_PU_ADDR_CLK_CFG); + + regs +=3D PHY_LANE_OFFSET; /* Next lane */ + } + + /* + * Wait for indication the PHY PLL is locked. Lanes for ports + * B and C share a PLL, so it's enough to sample just lane 0. + */ + return readl_poll_timeout(k1_phy->regs + PCIE_PU_ADDR_CLK_CFG, + val, val & PLL_READY, + POLL_DELAY, PLL_TIMEOUT); +} + +/* Prepare implies enable, and once enabled, it's always on */ +static const struct clk_ops k1_pcie_phy_pll_ops =3D { + .prepare =3D k1_pcie_phy_pll_prepare, +}; + +/* We represent the PHY PLL as a private clock */ +static int k1_pcie_phy_pll_setup(struct k1_pcie_phy *k1_phy) +{ + struct clk_hw *hw =3D &k1_phy->pll_hw; + struct device *dev =3D k1_phy->dev; + struct clk_init_data init =3D { }; + char *name; + int ret; + + name =3D kasprintf(GFP_KERNEL, "pcie%u_phy_pll", k1_phy->phy->id); + if (!name) + return -ENOMEM; + + init.name =3D name; + init.ops =3D &k1_pcie_phy_pll_ops; + init.parent_data =3D k1_pcie_phy_data; + init.num_parents =3D ARRAY_SIZE(k1_pcie_phy_data); + + hw->init =3D &init; + + ret =3D devm_clk_hw_register(dev, hw); + + kfree(name); /* __clk_register() duplicates the name we provide */ + + if (ret) + return ret; + + k1_phy->pll =3D devm_clk_hw_get_clk(dev, hw, "pll"); + if (IS_ERR(k1_phy->pll)) + return PTR_ERR(k1_phy->pll); + + return 0; +} + +/* Select PCIe or USB 3 mode for the combo PHY. */ +static void k1_combo_phy_sel(struct k1_pcie_phy *k1_phy, bool usb) +{ + struct regmap *pmu =3D k1_phy->pmu; + + /* Only change it if it's not already in the desired state */ + if (!regmap_test_bits(pmu, PMUA_USB_PHY_CTRL0, COMBO_PHY_SEL) =3D=3D usb) + regmap_assign_bits(pmu, PMUA_USB_PHY_CTRL0, COMBO_PHY_SEL, usb); +} + +static void k1_pcie_phy_init_pcie(struct k1_pcie_phy *k1_phy) +{ + u32 rx_rterm =3D k1_phy_rterm_rx(); + u32 tx_rterm =3D k1_phy_rterm_tx(); + void __iomem *regs; + u32 val; + int i; + + /* For the combo PHY, set PHY to PCIe mode */ + if (k1_phy_port_a(k1_phy)) + k1_combo_phy_sel(k1_phy, false); + + regs =3D k1_phy->regs; + for (i =3D 0; i < k1_phy->pcie_lanes; i++) { + val =3D readl(regs + PCIE_RX_REG1); + + /* Set RX analog front-end receiver termination value */ + val &=3D ~AFE_RTERM_REG; + val |=3D FIELD_PREP(AFE_RTERM_REG, rx_rterm); + + /* And enable refclock receiver termination */ + val |=3D EN_RTERM; + writel(val, regs + PCIE_RX_REG1); + + val =3D readl(regs + PCIE_RX_REG2); + /* Use PCIE_RX_REG1 AFE_RTERM_REG value */ + val &=3D ~RX_RTERM_SEL; + writel(val, regs + PCIE_RX_REG2); + + val =3D readl(regs + PCIE_TX_REG1); + + /* Set TX driver termination value */ + val &=3D ~TX_RTERM_REG; + val |=3D FIELD_PREP(TX_RTERM_REG, tx_rterm); + + /* Use PCIE_TX_REG1 TX_RTERM_REG value */ + val |=3D TX_RTERM_SEL; + writel(val, regs + PCIE_TX_REG1); + + /* Set the input clock to 24 MHz, and clear RC_CAL_TOGGLE */ + val =3D readl(regs + PCIE_RC_CAL_REG2); + val &=3D CLKSEL; + val |=3D FIELD_PREP(CLKSEL, CLKSEL_24M); + val &=3D ~RC_CAL_TOGGLE; + writel(val, regs + PCIE_RC_CAL_REG2); + + /* Now trigger recalibration by setting RC_CAL_TOGGLE again */ + val |=3D RC_CAL_TOGGLE; + writel(val, regs + PCIE_RC_CAL_REG2); + + val =3D readl(regs + PCIE_LTSSM_DIS_ENTRY); + /* Override the reference clock; set to refclk driver mode */ + val |=3D OVRD_REFCLK_MODE; + val &=3D ~CFG_REFCLK_MODE; + val |=3D FIELD_PREP(CFG_REFCLK_MODE, RFCLK_MODE_DRIVER); + writel(val, regs + PCIE_LTSSM_DIS_ENTRY); + + regs +=3D PHY_LANE_OFFSET; /* Next lane */ + } +} + +/* Only called for combo PHY */ +static void k1_pcie_phy_init_usb(struct k1_pcie_phy *k1_phy) +{ + k1_combo_phy_sel(k1_phy, true); + + /* We're not doing any testing */ + writel(0, k1_phy->regs + USB3_TEST_CTRL); +} + +static int k1_pcie_phy_init(struct phy *phy) +{ + struct k1_pcie_phy *k1_phy =3D phy_get_drvdata(phy); + + /* Note: port type is only valid for port A (both checks needed) */ + if (k1_phy_port_a(k1_phy) && k1_phy->type =3D=3D PHY_TYPE_USB3) + k1_pcie_phy_init_usb(k1_phy); + else + k1_pcie_phy_init_pcie(k1_phy); + + + return clk_prepare_enable(k1_phy->pll); +} + +static int k1_pcie_phy_exit(struct phy *phy) +{ + struct k1_pcie_phy *k1_phy =3D phy_get_drvdata(phy); + + clk_disable_unprepare(k1_phy->pll); + + return 0; +} + +static const struct phy_ops k1_pcie_phy_ops =3D { + .init =3D k1_pcie_phy_init, + .exit =3D k1_pcie_phy_exit, + .owner =3D THIS_MODULE, +}; + +/* + * Get values needed for calibrating PHYs operating in PCIe mode. Only + * the combo PHY is able to do this, and its calibration values are used + * for configuring all PCIe PHYs. + * + * We always need to de-assert the "global" reset on the combo PHY, + * because the USB driver depends on it. If used for PCIe, that driver + * will (also) de-assert this, but by leaving it de-asserted for the + * combo PHY, the USB driver doesn't have to do this. Note: although + * SpacemiT refers to this as the global reset, we name the "phy" reset. + * + * In addition, we guarantee the APP_HOLD_PHY_RESET bit is clear for the + * combo PHY, so the USB driver doesn't have to manage that either. The + * PCIe driver is free to change this bit for normal operation. + * + * Calibration only needs to be done once. It's possible calibration has + * already completed (e.g., it might have happened in the boot loader, or + * -EPROBE_DEFER might result in this function being called again). So we + * check that early too, to avoid doing it more than once. + * + * Otherwise we temporarily power up the PHY using the PCIe app clocks + * and resets, wait for the hardware to indicate calibration is done, + * grab the value, then shut the PHY down again. + */ +static int k1_pcie_combo_phy_calibrate(struct k1_pcie_phy *k1_phy) +{ + struct reset_control_bulk_data resets[] =3D { + { .id =3D "dbi", }, + { .id =3D "mstr", }, + { .id =3D "slv", }, + }; + struct clk_bulk_data clocks[] =3D { + { .id =3D "dbi", }, + { .id =3D "mstr", }, + { .id =3D "slv", }, + }; + struct device *dev =3D k1_phy->dev; + struct reset_control *phy_reset; + int ret =3D 0; + int val; + + /* Nothing to do if we already set the receiver termination value */ + if (k1_phy_rterm_valid()) + return 0; + + /* De-assert the PHY (global) reset and leave it that way for USB */ + phy_reset =3D devm_reset_control_get_exclusive_deasserted(dev, "phy"); + if (IS_ERR(phy_reset)) + return PTR_ERR(phy_reset); + + /* + * We also guarantee the APP_HOLD_PHY_RESET bit is clear. We can + * leave this bit clear even if an error happens below. + */ + regmap_assign_bits(k1_phy->pmu, PCIE_CLK_RES_CTRL, + PCIE_APP_HOLD_PHY_RST, false); + + /* If the calibration already completed (e.g. by U-Boot), we're done */ + val =3D readl(k1_phy->regs + PCIE_RCAL_RESULT); + if (val & R_TUNE_DONE) + goto out_tune_done; + + /* Put the PHY into PCIe mode */ + k1_combo_phy_sel(k1_phy, false); + + /* Get and enable the PCIe app clocks */ + ret =3D clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks); + if (ret <=3D 0) { + if (!ret) + ret =3D -ENOENT; + goto out_tune_done; + } + ret =3D clk_bulk_prepare_enable(ARRAY_SIZE(clocks), clocks); + if (ret) + goto out_put_clocks; + + /* Get the PCIe application resets (not the PHY reset) */ + ret =3D reset_control_bulk_get_shared(dev, ARRAY_SIZE(resets), resets); + if (ret) + goto out_disable_clocks; + + /* De-assert the PCIe application resets */ + ret =3D reset_control_bulk_deassert(ARRAY_SIZE(resets), resets); + if (ret) + goto out_put_resets; + + /* + * This is the core activity here. Wait for the hardware to + * signal that it has completed calibration/tuning. Once it + * has, the register value will contain the values we'll + * use to configure PCIe PHYs. + */ + ret =3D readl_poll_timeout(k1_phy->regs + PCIE_RCAL_RESULT, + val, val & R_TUNE_DONE, + POLL_DELAY, CALIBRATION_TIMEOUT); + + /* Clean up. We're done with the resets and clocks */ + reset_control_bulk_assert(ARRAY_SIZE(resets), resets); +out_put_resets: + reset_control_bulk_put(ARRAY_SIZE(resets), resets); +out_disable_clocks: + clk_bulk_disable_unprepare(ARRAY_SIZE(clocks), clocks); +out_put_clocks: + clk_bulk_put_all(ARRAY_SIZE(clocks), clocks); +out_tune_done: + /* If we got the value without timing out, set k1_phy_rterm */ + if (!ret) + k1_phy_rterm_set(val); + + return ret; +} + +static struct phy * +k1_pcie_combo_phy_xlate(struct device *dev, const struct of_phandle_args *= args) +{ + struct k1_pcie_phy *k1_phy =3D dev_get_drvdata(dev); + u32 type; + + /* The argument specifying the PHY mode is required */ + if (args->args_count !=3D 1) + return ERR_PTR(-EINVAL); + + /* We only support PCIe and USB 3 mode */ + type =3D args->args[0]; + if (type !=3D PHY_TYPE_PCIE && type !=3D PHY_TYPE_USB3) + return ERR_PTR(-EINVAL); + + /* This PHY can only be used once */ + if (k1_phy->type !=3D PHY_NONE) + return ERR_PTR(-EBUSY); + + k1_phy->type =3D type; + + return k1_phy->phy; +} + +/* Use the maximum number of PCIe lanes unless limited by Device Tree */ +static u32 k1_pcie_num_lanes(struct k1_pcie_phy *k1_phy, bool port_a) +{ + struct device *dev =3D k1_phy->dev; + u32 count =3D 0; + u32 max; + int ret; + + ret =3D of_property_read_u32(dev_of_node(dev), "num-lanes", &count); + if (count =3D=3D 1) + return 1; + + if (count =3D=3D 2 && !port_a) + return 2; + + max =3D port_a ? 1 : 2; + if (ret !=3D -EINVAL) + dev_warn(dev, "bad lane count %u for port; using %u\n", + count, max); + + return max; +} + +static int k1_pcie_combo_phy_probe(struct k1_pcie_phy *k1_phy) +{ + struct device *dev =3D k1_phy->dev; + struct regmap *regmap; + int ret; + + /* Setting the PHY mode requires access to the PMU regmap */ + regmap =3D syscon_regmap_lookup_by_phandle(dev_of_node(dev), SYSCON_APMU); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), "failed to get PMU\n"); + k1_phy->pmu =3D regmap; + + ret =3D k1_pcie_combo_phy_calibrate(k1_phy); + if (ret) + return dev_err_probe(dev, ret, "calibration failed\n"); + + /* Needed by k1_pcie_combo_phy_xlate(), which also sets k1_phy->type */ + dev_set_drvdata(dev, k1_phy); + + return 0; +} + +static int k1_pcie_phy_probe(struct platform_device *pdev) +{ + struct phy *(*xlate)(struct device *dev, + const struct of_phandle_args *args); + struct device *dev =3D &pdev->dev; + struct phy_provider *provider; + struct k1_pcie_phy *k1_phy; + bool probing_port_a; + int ret; + + xlate =3D of_device_get_match_data(dev); + probing_port_a =3D xlate =3D=3D k1_pcie_combo_phy_xlate; + + /* Only the combo PHY can calibrate, so it must probe first */ + if (!k1_phy_rterm_valid() && !probing_port_a) + return -EPROBE_DEFER; + + k1_phy =3D devm_kzalloc(dev, sizeof(*k1_phy), GFP_KERNEL); + if (!k1_phy) + return -ENOMEM; + k1_phy->dev =3D dev; + + k1_phy->regs =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(k1_phy->regs)) + return dev_err_probe(dev, PTR_ERR(k1_phy->regs), + "error mapping registers\n"); + + if (probing_port_a) { + ret =3D k1_pcie_combo_phy_probe(k1_phy); + if (ret) + return dev_err_probe(dev, ret, + "error probing combo phy\n"); + } + + k1_phy->pcie_lanes =3D k1_pcie_num_lanes(k1_phy, probing_port_a); + + k1_phy->phy =3D devm_phy_create(dev, NULL, &k1_pcie_phy_ops); + if (IS_ERR(k1_phy->phy)) + return dev_err_probe(dev, PTR_ERR(k1_phy->phy), + "error creating phy\n"); + phy_set_drvdata(k1_phy->phy, k1_phy); + + ret =3D k1_pcie_phy_pll_setup(k1_phy); + if (ret) + return dev_err_probe(dev, ret, "error initializing clock\n"); + + provider =3D devm_of_phy_provider_register(dev, xlate); + if (IS_ERR(provider)) + return dev_err_probe(dev, PTR_ERR(provider), + "error registering provider\n"); + return 0; +} + +static const struct of_device_id k1_pcie_phy_of_match[] =3D { + { .compatible =3D "spacemit,k1-combo-phy", k1_pcie_combo_phy_xlate, }, + { .compatible =3D "spacemit,k1-pcie-phy", of_phy_simple_xlate, }, + { }, +}; +MODULE_DEVICE_TABLE(of, k1_pcie_phy_of_match); + +static struct platform_driver k1_pcie_phy_driver =3D { + .probe =3D k1_pcie_phy_probe, + .driver =3D { + .of_match_table =3D k1_pcie_phy_of_match, + .name =3D "spacemit-k1-pcie-phy", + } +}; +module_platform_driver(k1_pcie_phy_driver); + +MODULE_DESCRIPTION("SpacemiT K1 PCIe and USB 3 PHY driver"); +MODULE_LICENSE("GPL"); --=20 2.48.1 From nobody Fri Dec 19 15:34:16 2025 Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F33C0313527 for ; Mon, 13 Oct 2025 15:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369744; cv=none; b=d7EbxKDRjhORe0JXJ4oVniQ2EG7slWaxI9w5M48yYIKkLRjbnEYOCMjxVHP3PlmqEPNvDyaLDvcW1y3v4oSpcodgi+VlkRsvZ5LmiKdodE8shE9K8U+nJSyOG48LZIzwKuP2NCZc6Y2+TGceu8ezI0LAJUoZC/y24EdSS3ISrhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369744; c=relaxed/simple; bh=zirRCFwQsJHqD/RygoAWOk3ABdfBcwFKfvubHudoZmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QWsIwJ6M+5z4/SaOgWBh4rTf/3vLlLGWJ4l95H4eJYuq7ID3er254L98QJzI8PPVqyt9n6yD7gqsqgnhi+XaV6HzwGlpZcYQmFbArmE9hfhoIWUh2rZR3r67y/dYrHw5+NSWjTFmv0BuUP2Q3PRq6K2SUuuLPakCmdrY2vhtbpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=v4zETj7F; arc=none smtp.client-ip=209.85.166.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="v4zETj7F" Received: by mail-io1-f66.google.com with SMTP id ca18e2360f4ac-92790f12293so205019839f.2 for ; Mon, 13 Oct 2025 08:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369741; x=1760974541; darn=vger.kernel.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; bh=5w3UvnnZmvULW91Nw3sqHq6gHytRfs1UsmObXdK/1xk=; b=v4zETj7FtW/5riTMf/B8yHXJEKvsjPgNUrTDI1KOOW+l7hnjnY7YdGqBdo1XyhoCN8 A7ghvau7X+z9aLoFXOP7qDxZuCOW8Bqlt29nRtIIje5oSBM77vy6UHgx2z3K4nErIl46 JYiJMQFt3thaF/pxrVcIoKRnOHbe2BTNNFnM4ZTsYoP5oBDIT44UMaABqY0FkA3IzNqw SIfSwGxOACRmgi9SQU7v2PHN0dYl1+9y0d8WhRcoLTBtj+D1mafQLGRcaVzcodbiwFtE MxKz1oSMw0j9IAx4tcZsUFJVVA11GyMvqRyF7iusCCxF646gHNjdr5OwO6HI3S9ynvi9 DroA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369741; x=1760974541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5w3UvnnZmvULW91Nw3sqHq6gHytRfs1UsmObXdK/1xk=; b=T4X0dHaLXICQn3ZltlwPV6R9c6MMPmTLN0+ygWnrIY2tdqA2Et2CDi6eFF8L52zMSj Ye1FsctUmbG+laoCv7g+R16JL20HUVO8xEqUeeTZs4tBIl+9jH29yQ0PhAAOCxq0RqZs 7/UJuFhjSOMQqRMNhqb/BQsEL7AuRx52Og/qIEKKnRu0C/pJTeKAYQnTtTb//upCraE+ gEokNJ/vo+utMAcclHvdpKOu9mldLTOcsZRvfwflBdJXQlNesS528b7hamuJVnqWQGx0 DKP2o7i4ZxcbaH0y8AY0NU+o7Y14+CmjC8v5ZE/U0VJkFS6DoB5ZSEGqibdfooqbQe5A rYDQ== X-Forwarded-Encrypted: i=1; AJvYcCVVj+ZgYoBB0VdjLFayi780VDwo+iMN8kWwMBumHY3r/ZeK+02nwg/2VHURzkcpkQXmRBNj2bKbtaKmxIY=@vger.kernel.org X-Gm-Message-State: AOJu0YyasS80h/5aH1cQEGI+4HD5gWtMz8iVSPPVCHrW1JWKTXTWKx7c OJ7tNQqDZo28/458B1a2NhLrJujaTtj0CuFZHMnu71EdsRB2rie43oKwQzMlphxRLgo= X-Gm-Gg: ASbGncsHxyth5zG+hSbqUXw8m/ZxSJ7BHvyB5fUa/PzNM4I2gtAwe1hFT7ZC860iBJH 8tYNkL5hr5hHgXfMzslu8UspoY2KDHNANQE7Lvmvu+1BMNi89IfmoBk706LU7sPpxvV9HtmzW+W heNZDhX9I7G4LSxlFveT/P8RN5n5cY86yPoAxmq2CH19TYQumUPdin0IQdjjaz1xX5a+6YY0USN z5LHRDXUQHc9bZyissYDDZEoCVxf9kNeDIWpyeRXzVD4bq9rdTPqYF2Jk+vnskqth2/zBxZISGm LDzDhKDykbg/55I6x7foRV6Sk2U5q1y2DZqY7VK2WJmosoLUQPrRVTpUCPERnkaqfG2SGLewB4V I/J9sj1A84JGjO/1HQ9EouYDeGO1KXEU+NjVw4mcG6KPczbwPVfMgsa+C5/f2hnhCi89ySRXz5R 1I6q0dskQ3Yjxpa1K0INQ= X-Google-Smtp-Source: AGHT+IES+fB7FUMZ1lbNwr3SH2nYvzCas9CYlWeRrdVjRa/jHhDD4zHUYKmDNK63qqxQfLzG9WgNYg== X-Received: by 2002:a05:6e02:1946:b0:42f:96ec:50a5 with SMTP id e9e14a558f8ab-42f96ec51a2mr136311375ab.20.1760369740902; Mon, 13 Oct 2025 08:35:40 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:40 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver Date: Mon, 13 Oct 2025 10:35:22 -0500 Message-ID: <20251013153526.2276556-6-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead. Signed-off-by: Alex Elder --- v2: - Renamed the PCIe driver source file "pcie-spacemit-k1.c" - Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1; it is now tristate rather than Boolean - The PCIe host compatible string is now "spacemit,k1-pcie" - Renamed the PMU syscon property to be "spacemit,apmu" - Renamed the symbols representing the PCI vendor and device IDs to align with - Use PCIE_T_PVPERL_MS rather than 100 to represent a standard delay period. - Use platform (not dev) driver-data access functions; assignment is done only after the private structure is initialized - Deleted some unneeded includes in the PCIe driver. - Dropped error checking when operating on MMIO-backed regmaps - Added a regmap_read() call in two places, to ensure a specified delay occurs *after* the a MMIO write has reached its target. - Used ARRAY_SIZE() (not a local variable value) in a few spots - Now use readl_relaxed()/writel_relaxed() when operating on the "link" I/O memory space in the PCIe driver - Updated a few error messages for consistency - No longer specify suppress_bind_attrs in the PCIe driver - Now specify PCIe driver probe type as PROBE_PREFER_ASYNCHRONOUS - No longer use (void) cast to indicate ignored return values drivers/pci/controller/dwc/Kconfig | 10 + drivers/pci/controller/dwc/Makefile | 1 + drivers/pci/controller/dwc/pcie-spacemit-k1.c | 319 ++++++++++++++++++ 3 files changed, 330 insertions(+) create mode 100644 drivers/pci/controller/dwc/pcie-spacemit-k1.c diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dw= c/Kconfig index 349d4657393c9..ede59b34c99ba 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -509,6 +509,16 @@ config PCI_KEYSTONE_EP on DesignWare hardware and therefore the driver re-uses the DesignWare core functions to implement the driver. =20 +config PCIE_SPACEMIT_K1 + tristate "SpacemiT K1 PCIe controller (host mode)" + depends on ARCH_SPACEMIT || COMPILE_TEST + depends on PCI && OF && HAS_IOMEM + select PCIE_DW_HOST + default ARCH_SPACEMIT + help + Enables support for the PCIe controller in the K1 SoC operating + in host mode. + config PCIE_VISCONTI_HOST bool "Toshiba Visconti PCIe controller" depends on ARCH_VISCONTI || COMPILE_TEST diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/d= wc/Makefile index 7ae28f3b0fb39..662b0a219ddc4 100644 --- a/drivers/pci/controller/dwc/Makefile +++ b/drivers/pci/controller/dwc/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_PCIE_UNIPHIER) +=3D pcie-uniphier.o obj-$(CONFIG_PCIE_UNIPHIER_EP) +=3D pcie-uniphier-ep.o obj-$(CONFIG_PCIE_VISCONTI_HOST) +=3D pcie-visconti.o obj-$(CONFIG_PCIE_RCAR_GEN4) +=3D pcie-rcar-gen4.o +obj-$(CONFIG_PCIE_SPACEMIT_K1) +=3D pcie-spacemit-k1.o obj-$(CONFIG_PCIE_STM32_HOST) +=3D pcie-stm32.o obj-$(CONFIG_PCIE_STM32_EP) +=3D pcie-stm32-ep.o =20 diff --git a/drivers/pci/controller/dwc/pcie-spacemit-k1.c b/drivers/pci/co= ntroller/dwc/pcie-spacemit-k1.c new file mode 100644 index 0000000000000..d58232cbb8a02 --- /dev/null +++ b/drivers/pci/controller/dwc/pcie-spacemit-k1.c @@ -0,0 +1,319 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * SpacemiT K1 PCIe host driver + * + * Copyright (C) 2025 by RISCstar Solutions Corporation. All rights reser= ved. + * Copyright (c) 2023, spacemit Corporation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie-designware.h" + +#define PCI_VENDOR_ID_SPACEMIT 0x201f +#define PCI_DEVICE_ID_SPACEMIT_K1 0x0001 + +/* Offsets and field definitions for link management registers */ + +#define K1_PHY_AHB_IRQ_EN 0x0000 +#define PCIE_INTERRUPT_EN BIT(0) + +#define K1_PHY_AHB_LINK_STS 0x0004 +#define SMLH_LINK_UP BIT(1) +#define RDLH_LINK_UP BIT(12) + +#define INTR_ENABLE 0x0014 +#define MSI_CTRL_INT BIT(11) + +/* Some controls require APMU regmap access */ +#define SYSCON_APMU "spacemit,apmu" + +/* Offsets and field definitions for APMU registers */ + +#define PCIE_CLK_RESET_CONTROL 0x0000 +#define LTSSM_EN BIT(6) +#define PCIE_AUX_PWR_DET BIT(9) +#define PCIE_RC_PERST BIT(12) /* 1: assert PERST# */ +#define APP_HOLD_PHY_RST BIT(30) +#define DEVICE_TYPE_RC BIT(31) /* 0: endpoint; 1: RC */ + +#define PCIE_CONTROL_LOGIC 0x0004 +#define PCIE_SOFT_RESET BIT(0) + +struct k1_pcie { + struct dw_pcie pci; + struct phy *phy; + void __iomem *link; + struct regmap *pmu; /* Errors ignored; MMIO-backed regmap */ + u32 pmu_off; +}; + +#define to_k1_pcie(dw_pcie) \ + platform_get_drvdata(to_platform_device((dw_pcie)->dev)) + +static void k1_pcie_toggle_soft_reset(struct k1_pcie *k1) +{ + u32 offset; + u32 val; + + /* + * Write, then read back to guarantee it has reached the device + * before we start the delay. + */ + offset =3D k1->pmu_off + PCIE_CONTROL_LOGIC; + regmap_set_bits(k1->pmu, offset, PCIE_SOFT_RESET); + regmap_read(k1->pmu, offset, &val); + + mdelay(2); + + regmap_clear_bits(k1->pmu, offset, PCIE_SOFT_RESET); +} + +/* Enable app clocks, deassert resets */ +static int k1_pcie_activate(struct k1_pcie *k1) +{ + struct dw_pcie *pci =3D &k1->pci; + int ret; + + ret =3D clk_bulk_prepare_enable(ARRAY_SIZE(pci->app_clks), pci->app_clks); + if (ret) + return ret; + + ret =3D reset_control_bulk_deassert(ARRAY_SIZE(pci->app_rsts), + pci->app_rsts); + if (ret) + goto err_disable_clks; + + ret =3D reset_control_bulk_deassert(ARRAY_SIZE(pci->core_rsts), + pci->core_rsts); + if (ret) + goto err_assert_resets; + + return 0; + +err_assert_resets: + reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts); +err_disable_clks: + clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks); + + return ret; +} + +/* Assert resets, disable app clocks */ +static void k1_pcie_deactivate(struct k1_pcie *k1) +{ + struct dw_pcie *pci =3D &k1->pci; + + reset_control_bulk_assert(ARRAY_SIZE(pci->core_rsts), pci->core_rsts); + reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts); + clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks); +} + +static int k1_pcie_init(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci =3D to_dw_pcie_from_pp(pp); + struct k1_pcie *k1 =3D to_k1_pcie(pci); + u32 offset; + u32 mask; + u32 val; + int ret; + + k1_pcie_toggle_soft_reset(k1); + + ret =3D k1_pcie_activate(k1); + if (ret) + return ret; + + ret =3D phy_init(k1->phy); + if (ret) { + k1_pcie_deactivate(k1); + + return ret; + } + + /* Set the PCI vendor and device ID */ + dw_pcie_dbi_ro_wr_en(pci); + dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, PCI_VENDOR_ID_SPACEMIT); + dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, PCI_DEVICE_ID_SPACEMIT_K1); + dw_pcie_dbi_ro_wr_dis(pci); + + /* + * Assert fundamental reset (drive PERST# low). Put the port in + * root complex mode, and indicate that Vaux (3.3v) is present. + */ + mask =3D PCIE_RC_PERST; + mask |=3D DEVICE_TYPE_RC | PCIE_AUX_PWR_DET; + + /* + * Write, then read back to guarantee it has reached the device + * before we start the delay. + */ + offset =3D k1->pmu_off + PCIE_CLK_RESET_CONTROL; + regmap_set_bits(k1->pmu, offset, mask); + regmap_read(k1->pmu, offset, &val); + + mdelay(PCIE_T_PVPERL_MS); + + /* Deassert fundamental reset (drive PERST# high) */ + regmap_clear_bits(k1->pmu, offset, PCIE_RC_PERST); + + return 0; +} + +static void k1_pcie_deinit(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci =3D to_dw_pcie_from_pp(pp); + struct k1_pcie *k1 =3D to_k1_pcie(pci); + + /* 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); + + k1_pcie_deactivate(k1); +} + +static const struct dw_pcie_host_ops k1_pcie_host_ops =3D { + .init =3D k1_pcie_init, + .deinit =3D k1_pcie_deinit, +}; + +static bool k1_pcie_link_up(struct dw_pcie *pci) +{ + struct k1_pcie *k1 =3D to_k1_pcie(pci); + u32 val; + + val =3D readl_relaxed(k1->link + K1_PHY_AHB_LINK_STS); + + return (val & RDLH_LINK_UP) && (val & SMLH_LINK_UP); +} + +static int k1_pcie_start_link(struct dw_pcie *pci) +{ + struct k1_pcie *k1 =3D to_k1_pcie(pci); + u32 val; + + /* Stop holding the PHY in reset, and enable link training */ + regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL, + APP_HOLD_PHY_RST | LTSSM_EN, LTSSM_EN); + + /* Enable the MSI interrupt */ + writel_relaxed(MSI_CTRL_INT, k1->link + INTR_ENABLE); + + /* Top-level interrupt enable */ + val =3D readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN); + val |=3D PCIE_INTERRUPT_EN; + writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN); + + return 0; +} + +static void k1_pcie_stop_link(struct dw_pcie *pci) +{ + struct k1_pcie *k1 =3D to_k1_pcie(pci); + u32 val; + + /* Disable interrupts */ + val =3D readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN); + val &=3D ~PCIE_INTERRUPT_EN; + writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN); + + writel_relaxed(0, k1->link + INTR_ENABLE); + + /* Disable the link and hold the PHY in reset */ + regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL, + APP_HOLD_PHY_RST | LTSSM_EN, APP_HOLD_PHY_RST); +} + +static const struct dw_pcie_ops k1_pcie_ops =3D { + .link_up =3D k1_pcie_link_up, + .start_link =3D k1_pcie_start_link, + .stop_link =3D k1_pcie_stop_link, +}; + +static int k1_pcie_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct k1_pcie *k1; + int ret; + + k1 =3D devm_kzalloc(dev, sizeof(*k1), GFP_KERNEL); + if (!k1) + return -ENOMEM; + + k1->pmu =3D syscon_regmap_lookup_by_phandle_args(dev_of_node(dev), + SYSCON_APMU, 1, + &k1->pmu_off); + if (IS_ERR(k1->pmu)) + return dev_err_probe(dev, PTR_ERR(k1->pmu), + "failed to lookup PMU registers\n"); + + k1->link =3D devm_platform_ioremap_resource_byname(pdev, "link"); + if (!k1->link) + return dev_err_probe(dev, -ENOMEM, + "failed to map \"link\" registers\n"); + + ret =3D devm_regulator_get_enable(dev, "vpcie3v3-supply"); + if (ret) + return dev_err_probe(dev, ret, + "failed to get \"vpcie3v3\" supply\n"); + + /* Hold the PHY in reset until we start the link */ + regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL, + APP_HOLD_PHY_RST); + + k1->phy =3D devm_phy_get(dev, NULL); + if (IS_ERR(k1->phy)) + return dev_err_probe(dev, PTR_ERR(k1->phy), + "failed to get PHY\n"); + + k1->pci.dev =3D dev; + k1->pci.ops =3D &k1_pcie_ops; + dw_pcie_cap_set(&k1->pci, REQ_RES); + + k1->pci.pp.ops =3D &k1_pcie_host_ops; + k1->pci.pp.num_vectors =3D MAX_MSI_IRQS; + + platform_set_drvdata(pdev, k1); + + ret =3D dw_pcie_host_init(&k1->pci.pp); + if (ret) + return dev_err_probe(dev, ret, "failed to initialize host\n"); + + return 0; +} + +static void k1_pcie_remove(struct platform_device *pdev) +{ + struct k1_pcie *k1 =3D platform_get_drvdata(pdev); + + dw_pcie_host_deinit(&k1->pci.pp); +} + +static const struct of_device_id k1_pcie_of_match_table[] =3D { + { .compatible =3D "spacemit,k1-pcie", }, + { }, +}; + +static struct platform_driver k1_pcie_driver =3D { + .probe =3D k1_pcie_probe, + .remove =3D k1_pcie_remove, + .driver =3D { + .name =3D "spacemit-k1-pcie", + .of_match_table =3D k1_pcie_of_match_table, + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, +}; +module_platform_driver(k1_pcie_driver); --=20 2.48.1 From nobody Fri Dec 19 15:34:16 2025 Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E40931353A for ; Mon, 13 Oct 2025 15:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369747; cv=none; b=a86NDvNTAoKHUfXVhN2aZYu2OBGx60+wczmTXx5Ty8GvmRc61WQrE84jtdcKPnKMwVMAFoGI+gHyINoNp6XmTvpl1RGhZ6nkJ9V1dGfIXFgqGHVOnNIZza++jnCJfMMs/OMPu/c5bniIrXvb5WxooPcx64DZtn7vVyZbn1Htr4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369747; c=relaxed/simple; bh=WJWs+NFUcGbJALoN3wXML39lAbVPkKGzBxDYg5OA8Pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N9ck1xp2l72RQUNQSRfurqdigFtHuXFHv0KPkTe0RP1SeiXJtr99EId4Z3X0VPs+DnATe6xLMpNRrLtaizVFXBGAxydL7hwys8hXjSoE8HL4g/8O14/zigh4xKA1SfmdJ5cXarvzyhzt5VnBMduk1ygP7ckrC4k5fsiTkoaGxZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=WUoKgkRq; arc=none smtp.client-ip=209.85.166.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="WUoKgkRq" Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-42f9c2d4a93so11807275ab.0 for ; Mon, 13 Oct 2025 08:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369743; x=1760974543; darn=vger.kernel.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; bh=xbPxvqkXmDdFxjU8mZBTBK/T+YiYjBFrlI/xnqdkqi8=; b=WUoKgkRqAJkfF1tMhRYKer0fra8bVJZ9xJqk9hGZ9WmsqgNg4iaaWd3nKWvbQJpBGz ASggX2PyiyVoKaUZFbuSwooJ3AIFyo0DNAWqKcsTxhfx8pEUBLR2iEsGyyk9QD3p0SFU cjZ+tHmoiYYLEYkscN3YGOuDI7gaw2Rc6H8ARkuUadXxus3UShc/TzN+KrkXfs3eYLD8 mF6HlkyHvQVwo1wIwxXDZ2jEjaw8Rnm5HKmIYQF6Unq73NOxZsKg286AsHseVCqfGQLw Hq60x0xfIi569ooypm27zNiLmLGs6eT5e2vP7fCdck4CWuRxe44s+Huqr5BBkZbh/yRA cTqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369743; x=1760974543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xbPxvqkXmDdFxjU8mZBTBK/T+YiYjBFrlI/xnqdkqi8=; b=t99aF8ddlXPV0J+K40A0B93QVbpBzkG5sIFW+o6ylCY4sj43xeWBtV6yaEInLtOqGN r1fyHTZJ1xKuS8SdRCYzV8PLPFlwgtaLV4JjnNKMKLeqse/MLkoBgxN0SbT8t/UEp6re g6095walXZjvGzOa1QwgaRKGjY11tQwGvUlKm1ZnbXQDxohfuS8UdgjViTkIE+vpZdv0 dDIbX4tCVL3SF+jGQpC6gf139ngDIOUVQD+l2PzvfcR0ia4T6ug5vIsGU08hn90hI4ai uR9pErJP1T70RHAou6fD0upMV6g5CouyeoEfEb2OqG+xO0nvsB92yfctbaZO/lnVn6k/ 8dGA== X-Forwarded-Encrypted: i=1; AJvYcCUbFNixUqFPcquutUfCibanFgjGQTTjzI2mldUSZL5/deks08tiirO52i/YjzNP9we8WBTRwZRIFqF31ec=@vger.kernel.org X-Gm-Message-State: AOJu0YxOWpG89vkVyIFG++0yTa+pNru/FxEL/XF3S05XhT0Fal9j/Maj M9NCYRxVMkEj9IKNomL9tCMYugFD40YtXxjqVTLt9G4q1FS/3lduwZF95FpxnGnW0HQ= X-Gm-Gg: ASbGncvG8YfBov2wJiuDymbXmCCpgcMmhehSNj1XceUAFCc6wv/i1CKdQmkblzIvKk7 /cCJyOEpQZu7AhGekqRmaI8oO4Pug1WAOV/nD6GA3hM3OlVk/UzzWiqzuPzUxDzMYMWf63OZraB ZUPjKAy53qp0rLyvxFTZt9qls5+RjDbjLH6PwD6ztVdd19IDheu3QsF3vZUdu5lrQRS3xsb2MjG hUQj5HQjQ9pw2GBvTH65GUcWa9ThUaNkOCQnaePAyGiJWkAeUBePNW1ojPuqmaiOzU9go0ni2DK Ou+rO9PDgZwXpnwKxhq4ll4KBrshP4q7nxW04VOPYtgS391hXugEtWXCQcjR5S3Bor4wVd99U1Y lZtTx8ErzKmGzgW7gtAn4OYEjMSAP9B/zYYPJjtt1I32ePRYb97dbM1/LEsnHmIKBpaasC4/YJp aBd2g585nd X-Google-Smtp-Source: AGHT+IE+RgkOmKUAmZ+h2lR6Ri91hcZZDy7nYDDMDTZK5PVvcsi3GRbcTYzKlh5jsPOXdbbG42NjVw== X-Received: by 2002:a05:6e02:4918:b0:430:9bc3:e1d3 with SMTP id e9e14a558f8ab-4309bc3e4b3mr13658895ab.12.1760369743033; Mon, 13 Oct 2025 08:35:43 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:42 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] riscv: dts: spacemit: add a PCIe regulator Date: Mon, 13 Oct 2025 10:35:23 -0500 Message-ID: <20251013153526.2276556-7-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define a 3.3v fixed voltage regulator to be used by PCIe on the Banana Pi BPI-F3. On this platform, this regulator is always on. Signed-off-by: Alex Elder --- v2: - New patch, for a newly-added regulator arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts b/arch/riscv/b= oot/dts/spacemit/k1-bananapi-f3.dts index 2aaaff77831e1..046ad441b7b4e 100644 --- a/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +++ b/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts @@ -30,6 +30,14 @@ led1 { default-state =3D "on"; }; }; + + pcie_vcc_3v3: pcie-vcc3v3 { + compatible =3D "regulator-fixed"; + regulator-name =3D "PCIE_VCC3V3"; + regulator-min-microvolt =3D <3300000>; + regulator-max-microvolt =3D <3300000>; + regulator-always-on; + }; }; =20 &emmc { --=20 2.48.1 From nobody Fri Dec 19 15:34:16 2025 Received: from mail-il1-f181.google.com (mail-il1-f181.google.com [209.85.166.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AD77313548 for ; Mon, 13 Oct 2025 15:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369748; cv=none; b=P5gETOP5p8Qt+SV+NR2dD6RwTVCSWNALoUr4tN/9QMWkWKbZq4T3jagrMejOCjwmmFB+pqwvjNA25/T1uSbenPt9vUH6SMNKuxX2XsvARsHw/emT5BJc5x12aazFyi/XyIXyMH7y4IJQ+0pSlu7wp61ikhII6hwPwTRkenroer0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369748; c=relaxed/simple; bh=4aZka/RAU4QYbrbCdQ/ULFAxcWVzlo5Q0/JoKZooWf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dTHFqP+VkOArmzWmH0sbWZPIKID07AUuYembJvnzVs+6qCs2UcpMbCQfEh8mj4JEKrY5Tg8a4CehepnLQYw8F/67jSbGp1O6G6HHd/y8jxN9JCDmGjUqpAUsmegHb6rg/BsSG3gxQUw3Oz0zaox5Z6EnVCYXyGY0WbTjhsSrKws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=XB1W3/4Y; arc=none smtp.client-ip=209.85.166.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="XB1W3/4Y" Received: by mail-il1-f181.google.com with SMTP id e9e14a558f8ab-42f91d225c9so17699855ab.0 for ; Mon, 13 Oct 2025 08:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1760369745; x=1760974545; darn=vger.kernel.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; bh=IC7TMG3lk59s+A7a4ImbP9PPZe+ugMZHmrnVEzsSLBc=; b=XB1W3/4YXfKWBN7N8PXR5JDV8WMyWgKcUjwcsdPrgY3tRzgQHMu/rJwOs1ltkB6F6N N5tLw1oQY6kfu7NZlggWYegFYU79szF1kEjW1pBwJ3UoJL9zCywV3YITk9VQlXasp/Nl JhM13S33p6Lj/MudxFuZYEuSYvHdqx6lQAatnIKdKIDpezy1eckO8q/rvEv4ehxXGDOy +kbXv/Wmq43FjKU6rXe6mtEaKBzXpw2yBVJE0CHsX7FPD+uxy4AF6MFBBm6DQU8ZHrww JeKcse3k1zLEbanEEv8upLaRzAh6gla2rYRznl25m6yg0Eo5A6JwftjS59oRUhEbdO7H pitg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760369745; x=1760974545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IC7TMG3lk59s+A7a4ImbP9PPZe+ugMZHmrnVEzsSLBc=; b=JzP02xbevLm+MuJ1VflyrNqF7qihpCr+kRrHu8JIdeyUbb+/N6UTUU4zFr9rPH3xZU VEnwE0N+szlpDtEcFP89dPqFNSQAMQo0BIEQPfhPjmn3wTv7OVvNdJ/w2yz0rsM/otnx eVV5eg6cnNppIbb4lH0M3TGSO7Ub0g+YIHA9R1uvqjVaVPeemxwt4DKhOOLpFYmj1EUT l4/1bJXQJ/38CLh3xaOMwGCBqDZFV4VeCENgTqYRJza/m3HktEVigC3+CHSMGuuri+Ca TdWdG1nYphTZ59vOf2eK1gnMe16wrn2vLihpqb2GJ5xVQrVcAPXfVyEVOLa08ISjE1aR 6C9Q== X-Forwarded-Encrypted: i=1; AJvYcCWVUKuFhTWKlo4ie/MSI2binBXApB39ecLVjbs1eSa+HEG0KjwORTssmJIyc7sEGqQo1IPcv06Oc7Og0rU=@vger.kernel.org X-Gm-Message-State: AOJu0YwelUNaE6HuurADABPKIi+t3x99fPFDXfznaoXKsqAD5Cz4hYGy dOKMXshLq6pQj1/QEI43MOvfFBj36W2wHOdnCS6BjWYpub4cYUjSZlskbwSNmghakhY= X-Gm-Gg: ASbGncsytnT0SQBs8ErOmcqBkz2Q+LRsa532au0oVKIyER+Du2X1EZRs+Yb82dT3f6O ASXgJVJHPP7VT+t+at6Bv3BASbHcXy3b8ZvzE/sIyK+SsP9r1BsAx41+potJu89ZiL9wE0Zj7Ui q7kP3x3hOW1+INFmdmTmdhDLWXfJAe4x24hL9QExBejTXoSzoFwk906o8nzaoAF0N5hPePf2uls 8F3L1w+6bRQs4xy0bN+bDGlZwVkOL+3Jl5EeWnBY9B86LAAAQXKUy8ahNI1oQM0Q8Iyn005gXTw eIWv0EYArITBBlGfgPQ1GuMnCQzlhhGzpBS4EcsL3TPDwD6QM/n5pzj473cNwEaIjvPXJSS/Pyy ILP5y5uJBAQB2OkNjppldewaTaLfELVnxsQxoVtFs4PNutgVV0qvh69WWKgvO5cLvJLDjCdZ+K4 ftenTLtr0RKrKOmWlSfmI= X-Google-Smtp-Source: AGHT+IHjDpApPK7L1lugdyMLdu/ALrQ3dDMp82iS7o9Xm0eHdrN9XhJaFVaUZhe9AQe+NVGfsh4gKw== X-Received: by 2002:a05:6e02:1545:b0:42f:8d6c:f502 with SMTP id e9e14a558f8ab-42f8d6cf905mr216933655ab.0.1760369745223; Mon, 13 Oct 2025 08:35:45 -0700 (PDT) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-58f6c49b522sm3910266173.1.2025.10.13.08.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 08:35:44 -0700 (PDT) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, p.zabel@pengutronix.de, christian.bruel@foss.st.com, shradha.t@samsung.com, krishna.chundru@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, namcao@linutronix.de, thippeswamy.havalige@amd.com, inochiama@gmail.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] riscv: dts: spacemit: PCIe and PHY-related updates Date: Mon, 13 Oct 2025 10:35:24 -0500 Message-ID: <20251013153526.2276556-8-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013153526.2276556-1-elder@riscstar.com> References: <20251013153526.2276556-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define PCIe and PHY-related Device Tree nodes for the SpacemiT K1 SoC. Enable the combo PHY and the two PCIe-only PHYs on the Banana Pi BPI-F3 board. The combo PHY is used for USB on this board, and that will be enabled when USB 3 support is accepted. The combo PHY must perform a calibration step to determine configuration values used by the PCIe-only PHYs. As a result, it must be enabled if either of the other two PHYs is enabled. Signed-off-by: Alex Elder --- v2: - Added vpcie3v3-supply nodes to PCIe ports - Combo PHY node is now defined earlier in the file (alphabetized) .../boot/dts/spacemit/k1-bananapi-f3.dts | 30 ++++ arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi | 33 ++++ arch/riscv/boot/dts/spacemit/k1.dtsi | 151 ++++++++++++++++++ 3 files changed, 214 insertions(+) diff --git a/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts b/arch/riscv/b= oot/dts/spacemit/k1-bananapi-f3.dts index 046ad441b7b4e..6d566780aed9d 100644 --- a/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +++ b/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts @@ -40,6 +40,12 @@ pcie_vcc_3v3: pcie-vcc3v3 { }; }; =20 +&combo_phy { + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie0_3_cfg>; + status =3D "okay"; +}; + &emmc { bus-width =3D <8>; mmc-hs400-1_8v; @@ -100,6 +106,30 @@ &pdma { status =3D "okay"; }; =20 +&pcie1_phy { + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie1_3_cfg>; + status =3D "okay"; +}; + +&pcie2_phy { + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie2_4_cfg>; + status =3D "okay"; +}; + +&pcie1 { + phys =3D <&pcie1_phy>; + vpcie3v3-supply =3D <&pcie_vcc_3v3>; + status =3D "okay"; +}; + +&pcie2 { + phys =3D <&pcie2_phy>; + vpcie3v3-supply =3D <&pcie_vcc_3v3>; + status =3D "okay"; +}; + &uart0 { pinctrl-names =3D "default"; pinctrl-0 =3D <&uart0_2_cfg>; diff --git a/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi b/arch/riscv/boot= /dts/spacemit/k1-pinctrl.dtsi index aff19c86d5ff3..5bacb6aff23f8 100644 --- a/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi +++ b/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi @@ -69,6 +69,39 @@ uart0-2-pins { }; }; =20 + pcie0_3_cfg: pcie0-3-cfg { + pcie0-3-pins { + pinmux =3D , /* PERST# */ + , /* WAKE# */ + ; /* CLKREQ# */ + + bias-pull-up =3D <0>; + drive-strength =3D <21>; + }; + }; + + pcie1_3_cfg: pcie1-3-cfg { + pcie1-3-pins { + pinmux =3D , /* PERST# */ + , /* WAKE# */ + ; /* CLKREQ# */ + + bias-pull-up =3D <0>; + drive-strength =3D <21>; + }; + }; + + pcie2_4_cfg: pcie2-4-cfg { + pcie2-4-pins { + pinmux =3D , /* PERST# */ + , /* WAKE# */ + ; /* CLKREQ# */ + + bias-pull-up =3D <0>; + drive-strength =3D <21>; + }; + }; + pwm14_1_cfg: pwm14-1-cfg { pwm14-1-pins { pinmux =3D ; diff --git a/arch/riscv/boot/dts/spacemit/k1.dtsi b/arch/riscv/boot/dts/spa= cemit/k1.dtsi index 6cdcd80a7c83b..a38c578f24004 100644 --- a/arch/riscv/boot/dts/spacemit/k1.dtsi +++ b/arch/riscv/boot/dts/spacemit/k1.dtsi @@ -4,6 +4,7 @@ */ =20 #include +#include =20 /dts-v1/; / { @@ -358,6 +359,48 @@ syscon_rcpu2: system-controller@c0888000 { #reset-cells =3D <1>; }; =20 + combo_phy: phy@c0b10000 { + compatible =3D "spacemit,k1-combo-phy"; + reg =3D <0x0 0xc0b10000 0x0 0x1000>; + clocks =3D <&vctcxo_24m>, + <&syscon_apmu CLK_PCIE0_DBI>, + <&syscon_apmu CLK_PCIE0_MASTER>, + <&syscon_apmu CLK_PCIE0_SLAVE>; + clock-names =3D "refclk", + "dbi", + "mstr", + "slv"; + resets =3D <&syscon_apmu RESET_PCIE0_DBI>, + <&syscon_apmu RESET_PCIE0_MASTER>, + <&syscon_apmu RESET_PCIE0_SLAVE>, + <&syscon_apmu RESET_PCIE0_GLOBAL>; + reset-names =3D "dbi", + "mstr", + "slv", + "phy"; + #phy-cells =3D <1>; + spacemit,apmu =3D <&syscon_apmu>; + status =3D "disabled"; + }; + + pcie1_phy: phy@c0c10000 { + compatible =3D "spacemit,k1-pcie-phy"; + reg =3D <0x0 0xc0c10000 0x0 0x1000>; + clocks =3D <&vctcxo_24m>; + clock-names =3D "refclk"; + #phy-cells =3D <0>; + status =3D "disabled"; + }; + + pcie2_phy: phy@c0d10000 { + compatible =3D "spacemit,k1-pcie-phy"; + clocks =3D <&vctcxo_24m>; + clock-names =3D "refclk"; + reg =3D <0x0 0xc0d10000 0x0 0x1000>; + #phy-cells =3D <0>; + status =3D "disabled"; + }; + syscon_apbc: system-controller@d4015000 { compatible =3D "spacemit,k1-syscon-apbc"; reg =3D <0x0 0xd4015000 0x0 0x1000>; @@ -847,6 +890,114 @@ pcie-bus { #size-cells =3D <2>; dma-ranges =3D <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>, <0x0 0xb8000000 0x1 0x38000000 0x3 0x48000000>; + pcie0: pcie@ca000000 { + compatible =3D "spacemit,k1-pcie"; + reg =3D <0x0 0xca000000 0x0 0x00001000>, + <0x0 0xca300000 0x0 0x0001ff24>, + <0x0 0x8f000000 0x0 0x00002000>, + <0x0 0xc0b20000 0x0 0x00001000>; + reg-names =3D "dbi", + "atu", + "config", + "link"; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges =3D <0x01000000 0x0 0x00000000 0x0 0x8f002000 0x0 0x00100000>, + <0x02000000 0x0 0x80000000 0x0 0x80000000 0x0 0x0f000000>; + interrupts =3D <141>; + interrupt-names =3D "msi"; + clocks =3D <&syscon_apmu CLK_PCIE0_DBI>, + <&syscon_apmu CLK_PCIE0_MASTER>, + <&syscon_apmu CLK_PCIE0_SLAVE>; + clock-names =3D "dbi", + "mstr", + "slv"; + resets =3D <&syscon_apmu RESET_PCIE0_DBI>, + <&syscon_apmu RESET_PCIE0_MASTER>, + <&syscon_apmu RESET_PCIE0_SLAVE>, + <&syscon_apmu RESET_PCIE0_GLOBAL>; + reset-names =3D "dbi", + "mstr", + "slv", + "phy"; + device_type =3D "pci"; + num-viewport =3D <8>; + spacemit,apmu =3D <&syscon_apmu 0x03cc>; + status =3D "disabled"; + }; + + pcie1: pcie@ca400000 { + compatible =3D "spacemit,k1-pcie"; + reg =3D <0x0 0xca400000 0x0 0x00001000>, + <0x0 0xca700000 0x0 0x0001ff24>, + <0x0 0x9f000000 0x0 0x00002000>, + <0x0 0xc0c20000 0x0 0x00001000>; + reg-names =3D "dbi", + "atu", + "config", + "link"; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges =3D <0x01000000 0x0 0x00000000 0x0 0x9f002000 0x0 0x00100000>, + <0x02000000 0x0 0x90000000 0x0 0x90000000 0x0 0x0f000000>; + interrupts =3D <142>; + interrupt-names =3D "msi"; + clocks =3D <&syscon_apmu CLK_PCIE1_DBI>, + <&syscon_apmu CLK_PCIE1_MASTER>, + <&syscon_apmu CLK_PCIE1_SLAVE>; + clock-names =3D "dbi", + "mstr", + "slv"; + resets =3D <&syscon_apmu RESET_PCIE1_DBI>, + <&syscon_apmu RESET_PCIE1_MASTER>, + <&syscon_apmu RESET_PCIE1_SLAVE>, + <&syscon_apmu RESET_PCIE1_GLOBAL>; + reset-names =3D "dbi", + "mstr", + "slv", + "phy"; + device_type =3D "pci"; + num-viewport =3D <8>; + spacemit,apmu =3D <&syscon_apmu 0x3d4>; + status =3D "disabled"; + }; + + pcie2: pcie@ca800000 { + compatible =3D "spacemit,k1-pcie"; + reg =3D <0x0 0xca800000 0x0 0x00001000>, + <0x0 0xcab00000 0x0 0x0001ff24>, + <0x0 0xb7000000 0x0 0x00002000>, + <0x0 0xc0d20000 0x0 0x00001000>; + reg-names =3D "dbi", + "atu", + "config", + "link"; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges =3D <0x01000000 0x0 0x00000000 0x0 0xb7002000 0x0 0x00100000>, + <0x42000000 0x0 0xa0000000 0x0 0xa0000000 0x0 0x10000000>, + <0x02000000 0x0 0xb0000000 0x0 0xb0000000 0x0 0x07000000>; + interrupts =3D <143>; + interrupt-names =3D "msi"; + clocks =3D <&syscon_apmu CLK_PCIE2_DBI>, + <&syscon_apmu CLK_PCIE2_MASTER>, + <&syscon_apmu CLK_PCIE2_SLAVE>; + clock-names =3D "dbi", + "mstr", + "slv"; + resets =3D <&syscon_apmu RESET_PCIE2_DBI>, + <&syscon_apmu RESET_PCIE2_MASTER>, + <&syscon_apmu RESET_PCIE2_SLAVE>, + <&syscon_apmu RESET_PCIE2_GLOBAL>; + reset-names =3D "dbi", + "mstr", + "slv", + "phy"; + device_type =3D "pci"; + num-viewport =3D <8>; + spacemit,apmu =3D <&syscon_apmu 0x3dc>; + status =3D "disabled"; + }; }; =20 storage-bus { --=20 2.48.1