From nobody Sat Feb 7 21:24:15 2026 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 9A35E34B40C for ; Thu, 18 Dec 2025 15:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070764; cv=none; b=QLGILS+XgvIlJkrILqcKyiiCN9nuSQ+bJcnIM8LZ77PQ2N2YJTFD9VUpAoaEMG1Hme5mJHJ+2ztfTe0nwW6O+29jBvfvKk8WeoxJ7f0neI4X4+n8a3xmOzF4eWuao0mAyoKycLPbjAcjdHKcyiSkVxJjDrk10SNZYaE0BCBFMc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070764; c=relaxed/simple; bh=AxniUDFPOEBa6Hk3PEu2qbO8OY5+iC7H8GeN4m2w6cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m08NGkM2DUtJvK/y3Md3gNLWGj00/Krw3OGWFr30WLY61S2zDJ5qIDYlqzaiqvn57M9qOAOMCwlLcx+cU42mOOJ12NTilccQ62j2hH0YSlIrxtFliSYDMmFYdfkWPj2pe/79nsHZ/yd2IFSfFu1/4Bh6YAkpeYUlKnuoPdfO9Gg= 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=h+pcOVic; arc=none smtp.client-ip=209.85.222.169 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="h+pcOVic" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-8c07bc2ad13so19574085a.2 for ; Thu, 18 Dec 2025 07:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1766070761; x=1766675561; 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=gLTdLkz5qoTZ4VZft5RozafvHivyKGwCA/saZ7bnL/c=; b=h+pcOVichRfbjRAvWEjQOjdzp9sn0ga+6m4ElqcLr3XgI1HPDDQqDVHpN0OuzNU658 44+zxnapCG36rImgJ4uqWQQ/9+G929hGBJlSzMP+ddOFjXwpdDKE2DpP3uxiB6yfrZ3W LgfrxiXDXFEQNY4LLjanyV56cQl+G8tpdxjLEvPDWHyGLBoYrliWEYXSeNkR3+dMM4i1 2an5Y9rp6s8/vlJpyrjFIuTY7L0KPjH55llw5ZGjPcROasW2LveZSsYlJW+oz7bF7Frz SbatZg2r9NxWbStqGe/hwAN8I3wwzQe8G+p8Q3LJEyKiTyEXAG8NpCdzoKVYqoMWyI6q xcpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766070761; x=1766675561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gLTdLkz5qoTZ4VZft5RozafvHivyKGwCA/saZ7bnL/c=; b=dtae7+fQkAMo52jxygM1/diXgJV619/i4cD8ikcSbwXMz7E1l2qYLXuRWbCzwWyB1Y hxKkkK9eNxBe6vdVfbUdAVjctWbBqVRxBoy2jdgiiNwDWRK3ptn9JtE2pVUC6MAXkWLf hYnhzJFlFKq/ypjgxLjd3qylLQs3eZw+quTCQh2LD8qi/Sqf9uxSktkcPbd9g2vtKJJ3 ES8/99/vHV8G/VFiExhTT3u4D7tLMB+SKLQ+AHRLkTJ/udH84nwjOmhSMwkUcfoD3Bqe LyEvUF2iwNVkosErgLEQsmdOdKgpShOk6bseXf5yFwspbSANJsPHQch/gUmQDecA9NBA fDGQ== X-Forwarded-Encrypted: i=1; AJvYcCUvRm1ATVgMMZ2cLVL6CJLnWf7fSFgTgOW9Ft3orsQhfkFBMlmDTUIAvIY1rxte2/vn/H6tECOQOMOxyvw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz14f126qATF8/OakUgVp4RSPbVWHfog8Vpzpm90/+oJcPM21Wb /44zmmjUL7LvY7xH1Ba/n1oKx175X39H0BXfbhX0V924Pnpau00wpgilz8Ew25uA9u0= X-Gm-Gg: AY/fxX4bipQEtQoe25m1PNBgqBstkkEmbJNAYEkxfamnpS/p9sg6pOvi3Vb0BVWsn8/ 1aL8jZCyEg4MdJ0AJara/P03Du0vz7bScDJT9DFAPoNvPDyrr1OWixlz0d55HKJZfmRUpIcfHbg I+7JTfW97XrtcJr7GrYgS8ExmLjSKxHsms5bTznLfUs+YoYAdA0yamMMq8ZgwbWZA2MmdMGg2y1 r0TiTtVTiv9MWVTgUjaoQhw5Qlx1wxC1GbkQoyAl48X8HpyDoZXlPBkKktqPAsa1+bvYCDYdejk D2kxCcf4qbaa2Gd1Wlo2LqXirFuIFWJreXU/1iCDFjQAu6YANQfcHXLV1taSkpkIubmHHu/HPTG UN3Sv8XXv9eBa4yjsB7kDl3+TPpeY67HBMoAo2ZB7UmgO3PV3jHcezujtNTMh2Dm+kKzgNYW19X ueNADI/OuwDxXK8YcVFVRgLNlK0UessEtRgmJdRB6Y8vGfoXfPpSmQHw== X-Google-Smtp-Source: AGHT+IHSKbVF665YqEXD6O7jBmj3jVOl2qS/oc2FAj0GURakfZVq9yDRUofhfwxuBkxQ2pFqUC7fSw== X-Received: by 2002:a05:620a:6919:b0:8b2:e88e:a518 with SMTP id af79cd13be357-8bb3a384dafmr3194221685a.68.1766070761282; Thu, 18 Dec 2025 07:12:41 -0800 (PST) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8beeb5d6952sm186866985a.3.2025.12.18.07.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 07:12:41 -0800 (PST) From: Alex Elder To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, vkoul@kernel.org, kishon@kernel.org Cc: dlan@gentoo.org, guodong@riscstar.com, devicetree@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 1/5] dt-bindings: phy: spacemit: Add SpacemiT PCIe/combo PHY Date: Thu, 18 Dec 2025 09:12:27 -0600 Message-ID: <20251218151235.454997-2-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251218151235.454997-1-elder@riscstar.com> References: <20251218151235.454997-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. Reviewed-by: Rob Herring (Arm) Signed-off-by: Alex Elder Tested-by: Yixun Lan --- .../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..b59476cd78b57 --- /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: PHY reset; remains deasserted after initialization + - 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 + + reset-names: + items: + - const: phy + - const: dbi + - const: mstr + - const: slv + + 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_GLOBAL>, + <&syscon_apmu RESET_PCIE0_DBI>, + <&syscon_apmu RESET_PCIE0_MASTER>, + <&syscon_apmu RESET_PCIE0_SLAVE>; + reset-names =3D "phy", + "dbi", + "mstr", + "slv"; + spacemit,apmu =3D <&syscon_apmu>; + #phy-cells =3D <1>; + }; --=20 2.48.1 From nobody Sat Feb 7 21:24:15 2026 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 E6C2134B413 for ; Thu, 18 Dec 2025 15:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070766; cv=none; b=OiDcDddpX31lbCBZUG6T6+9psudvk3Nqiwqv8A7jZ5s/KX4iiuM/kx7BC1rKbEf44lQJQFYO3Nr5Qwh/ChQnWbrJxbwA4AnVyy8yP3r3v1OmEvXn2iJnqh30KcjuMJNBnpI6WXAQQC7vnH++/5s4dxZ8dIXMVbOHt5wDdS6OvHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070766; c=relaxed/simple; bh=8LppfTqRL5l2SybiAnwAcKY+acsrML8ysTdBgNm1hLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kAjiBh7tmLFabJmdoKdWAa0ztPe7yIckjfcWWyOEmK6D35kN1CsiCtJDZAJLBME/n0rduigRhlh6W/8OWDI892MSaA6aSSFoNrWGPgT/7i7yLxBVKyX8YCS5HyluBx1vDd0ij2o9x1NNw0UIep7VJP2j1aSZYxTJNvIMWNU0SUk= 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=2Ub2vX2C; arc=none smtp.client-ip=209.85.222.175 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="2Ub2vX2C" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8be92e393f8so77366285a.1 for ; Thu, 18 Dec 2025 07:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1766070763; x=1766675563; 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=oxyyAVz+sgzum76hhNZkaYgPP0OtOtVsykA+Y1mmKUg=; b=2Ub2vX2C5hh+zwL9v/hIZ5O/KDK0vFlYZc/EUa0pq/fTXksrjA4v3WO38rXE/fLr0j RmmOgTVBu21Q2m1AhIwVbuHGAG/cewbhqOf910WNcGaT/Y9nQiBfSB2pjWB109Z/CP7K jyYhUv9ibGvWoB6nmqbmU1qcy2YHJbN3tRn6TpLiETFFmBm3IjGqOvU7cqnswERPnDpC ioc1aVo04USvo8gVf56LB4qOrLvm76nwFa74PfVbhqe7xb3VliGQw3PFjq26oKujgtrp xe3Yjy+HImOjFRfDk3dkOvSC3DQ0UzLSu6XgeIhYODgKTsPVnPU60IdDWi7+5Eg0wNED kFSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766070763; x=1766675563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oxyyAVz+sgzum76hhNZkaYgPP0OtOtVsykA+Y1mmKUg=; b=RoRWmixprw8vk8Gbbh6dzUyT8bzLBrtcMiOHR7fCEGCwmYGCYmX339pvlLwgHDcYC3 ou5tqNCh1KMYx/A9ENpt9q3nuiCPl4Z5ZqANqc6ZU6Tt1cRYrPfvz9pvrvHrqF7/W1yR 17+ApY+aGFdtJlQQsHPWAo5nzxdEfKd28UnjcKH/0mpkZahq6WX9Z2UCdPLntMBCzm/b f52DBjpFddk7BZAX2QIr9Yvr5za3wDUAv0VegxRRXloWJohyxyTVwkZxW140QHVxbSYT 9CzuMiOQIqHQXpXTbWWDy0lXTiQpCnyiDIjLFFRtbBG4+UgUF66Pv9h8JJ+l3PSmBB6m Md3w== X-Forwarded-Encrypted: i=1; AJvYcCUInXoXBfAPPUtJTdIr6zebdFuPNthnAA4YgD9gkuZWtliV9w7Vnw7IR57nTzy+/3i2p8KofOXgObvs9b0=@vger.kernel.org X-Gm-Message-State: AOJu0YxZV+09o80TrQM29c2Mc0OinAcXDfTWrKWwRqw2ateFz4GnwqqR NnW2STHncW++8Ji8S8VL+bOLcXej+oXHLOdhXi9ozyWYcPl7HsLfkaZv8s3a66JaSck= X-Gm-Gg: AY/fxX6ylEpU3bbBj+sC3R7nhoPclwAAqFv1zTixOVOPIKZ2yOwfoFfbJwBtGL5oekP gS3oQMlDZpKTgHbM+Pa5sE7UZ807SZJNMtckKcyHu9ZgoW8NVHTKdSJqeLugLcWv0XKeLAJY9gu aIzAmboehOTWTLJYZWojsYSHfV9suq8ycwd3UoswaTX6efIE1swhCw6KldrnbaWDZw4A2Syis0o D2R4rfCi4ZDmpjxEphyEgJ86R/1dqCALVNk1cRtlJhhE/JASO5fyhUo5LqsezJatny8UY9ZOWYH g4/aYcvvCUAP+DFImiCKehHHtg3fPeWP+lgqxObeQ5r/rxvjZh3vnHtWqCD/jXdYBPPF832CqFi XczrWEagynCcUDH71uiex+PIN6gN9RCfLoTLUqCRiW6J6OogGDyHpMAdz6ayoJ2BGexEm6UAHIO ZLf5tpPtHSGfgqtG+Y0W8uM0Qmg0qgf/VqooCupNHcrehLaX+BF8OP/Q== X-Google-Smtp-Source: AGHT+IFt4skkDsPUjK60b1wetqDLMvA4QbKiBZIS/djWkmayCVcOzRtJDIo76oiNu2+mujPOEGHHUw== X-Received: by 2002:a05:620a:1912:b0:8b2:eebc:64bc with SMTP id af79cd13be357-8bee75c3e36mr423410285a.35.1766070762753; Thu, 18 Dec 2025 07:12:42 -0800 (PST) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8beeb5d6952sm186866985a.3.2025.12.18.07.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 07:12:42 -0800 (PST) From: Alex Elder To: vkoul@kernel.org, kishon@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: ziyao@disroot.org, dlan@gentoo.org, guodong@riscstar.com, devicetree@vger.kernel.org, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/5] dt-bindings: phy: spacemit: Introduce PCIe PHY Date: Thu, 18 Dec 2025 09:12:28 -0600 Message-ID: <20251218151235.454997-3-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251218151235.454997-1-elder@riscstar.com> References: <20251218151235.454997-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. Reviewed-by: Rob Herring (Arm) Signed-off-by: Alex Elder Tested-by: Yixun Lan --- .../bindings/phy/spacemit,k1-pcie-phy.yaml | 71 +++++++++++++++++++ 1 file changed, 71 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..019b28349be75 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml @@ -0,0 +1,71 @@ +# 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: > + Two PHYs on the SpacemiT K1 SoC used for only for PCIe. 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 + + resets: + items: + - description: PHY reset; remains deasserted after initialization + + reset-names: + const: phy + + "#phy-cells": + const: 0 + +required: + - compatible + - reg + - clocks + - clock-names + - resets + - reset-names + - "#phy-cells" + +additionalProperties: false + +examples: + - | + #include + phy@c0c10000 { + compatible =3D "spacemit,k1-pcie-phy"; + reg =3D <0xc0c10000 0x1000>; + clocks =3D <&vctcxo_24m>; + clock-names =3D "refclk"; + resets =3D <&syscon_apmu RESET_PCIE1_GLOBAL>; + reset-names =3D "phy"; + #phy-cells =3D <0>; + }; --=20 2.48.1 From nobody Sat Feb 7 21:24:15 2026 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 78E0934B40F for ; Thu, 18 Dec 2025 15:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070768; cv=none; b=WeP6dFlJ4thvrvhIj/DahG3D41718MpFNqiSj8QSj1GOc4Bv7BMkKaI2M0oZwjNgeMPDznMAlMjtuzpSd6YE0lhPQUavHFPneQVJpPVJAqpsn6s6Pj5b8Eo+D3dV1m3aNhppnHOG/31wYFoHokDckShnT/wKPXZMNaAmeRNHIGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070768; c=relaxed/simple; bh=wPVeC9eXx0IbyXvhwCId2YdnCqWBRCPftMpWfA+2J0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TotoGYNaq/hYr4n4fXJ15mJAO1gGgRFpgJaDOzKWTypTFVKBcpsHdfnB1HqUL/UAdfRfdETLtGaWTpxaz5NSja5KxdplwwtVquwrkxQpuTXEjDfB8e+BsXa1UhR44N2M8qxke8x0kgX5friQ/Ysf7fGvFZEKYIRYW7ZjzUiJmDU= 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=b9+IWEBT; arc=none smtp.client-ip=209.85.222.176 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="b9+IWEBT" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-8b2ec756de0so77854085a.3 for ; Thu, 18 Dec 2025 07:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1766070764; x=1766675564; 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=e9b5Ge8azVW/F4qoVE6FFa1ASOiFqqpnk2QkoX/YwMI=; b=b9+IWEBTAc3gyZ0PH88gvp0TaN+DNBWgWZ5xRSOKmKLmbmKwwmvJOB+nzvABZnBIdL fmY7Z0JjaIkdHsyVApKX5T0V96mMw6EZ72oQrJej/55tqS4rzLh96XeXoFRwiZZruCpa /ZOzGPQUSUe9ZsRE4pUn0LGd04Maz7AG1NCC3hkfgQ7Q+k/ockV+ynnCwpDORK1JelCM jfMBpFsY6ARQa4fZyj6JeOMTGwO2vzVKwp5oA5FqoupxD1pxg2aqnX7v+aQ8BSbO6OCe xzmpPnMx8kcGWibuBRzVXIpu8mrPynEMEyIsNHVHO217z5uiJoSKvsZs+g6J5K6raf5p Y3tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766070764; x=1766675564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=e9b5Ge8azVW/F4qoVE6FFa1ASOiFqqpnk2QkoX/YwMI=; b=VkFHQ1WfaJda2Bu1SzTg/hMRH5oyO3Wgq/j123uCNDhxEO3Jd8+lO6B8pvbpjoAFFX bOQMFiZtHS5jHTki88gjZWDunbdCfxSTqAqK3nZD60LWNSYB7zduVsrO6MUNJ65mZC4H c8MJNwbEI5qT+1z4ViUENO9Kip24czZLfYDw/cOBrtxRSZZdeTeoAda5qOdUSGxX8wqQ MDk8/oglG50xk2yOEPMH+2sHYN1EkUyBiO9yKA/dsCKqza94Pw7nDg7q/yVIr3sjQe0i lR7FXmEayTftazYiu2d+omhCiPBl1X5GM27QHzBLtxeO9w8/jnW7M/Mm8xBV+Oq4oIsc EKiA== X-Forwarded-Encrypted: i=1; AJvYcCU8bEELRorI37dHMe3iT0ETKMdkneb7TZRKVdArJgppsAh/6gMoVXBYx8brxxfUl73HwFctKaOyJT1rDMI=@vger.kernel.org X-Gm-Message-State: AOJu0Ywf6WscYQzglACSdRf6oOLN6aA1Z3BmQjrxJbdoaYepyjcBSnI8 AbS9hw4eVGTRWcVP2usoR5vYHgl8l96+VkH7AP8TUvPNdNGkogmwyC2rGQdkrP5cjc8= X-Gm-Gg: AY/fxX6UzmWIOoldahrLLlU6dTjxRiEtwtV/AGqxa4fFySpe6Ih9wyFp6R+azjCSGlh Z5GZ1MJNBqp82WQE7r1nwjGpoBMyqQOi9lp5zCK9rzSok9tTgLonxn29wBeUWdUhBzU+SC1ngPk xHSSboeAhvQUU6oRRL6PdrzjEMnRmQh2wWJdTywLauu3cXiu3yJ69q1tQje/XBdTNz+/eJd3Log XnZvLy9+ydGSRtRL0dbusQBAczG2CH/yRBoKhHhxqHZfFBv9N8C07MOVMzEMPhlGhcKz7L1C25q 5K6gDzNMUW0FeR9IknJqvJDfPxyxr/OCKvqIcP4791c82zJ9FGMl2yYTcs+JAyir+1awwR6WdNW gf8PDNAPke2FnTc2eVWpCLsFp65GIK+yQhRZ6Lld+AkXzxeUoCPmosBYRSqpWpIwRvm4yfmdULP yYoqLH+uX7q9fC03pwgkxegzGSzGh/xOFKuYAe4yVaWtgxvc5y7ZfsCg== X-Google-Smtp-Source: AGHT+IEYT0cZnGev5d6WQOXM3A1Ul1uY0zY5frm4Pys3XFYtgHLGdIFPKHjatEspqlVZMmfXkGvrrw== X-Received: by 2002:a05:620a:22a:b0:8bb:a675:aa6c with SMTP id af79cd13be357-8bba675ae64mr1927324085a.90.1766070764208; Thu, 18 Dec 2025 07:12:44 -0800 (PST) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8beeb5d6952sm186866985a.3.2025.12.18.07.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 07:12:43 -0800 (PST) From: Alex Elder To: vkoul@kernel.org, kishon@kernel.org Cc: p.zabel@pengutronix.de, dlan@gentoo.org, aurelien@aurel32.net, guodong@riscstar.com, linux-phy@lists.infradead.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Junzhong Pan Subject: [PATCH v7 3/5] phy: spacemit: Introduce PCIe/combo PHY Date: Thu, 18 Dec 2025 09:12:29 -0600 Message-ID: <20251218151235.454997-4-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251218151235.454997-1-elder@riscstar.com> References: <20251218151235.454997-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 Tested-by: Yixun Lan --- drivers/phy/Kconfig | 11 + drivers/phy/Makefile | 1 + drivers/phy/phy-spacemit-k1-pcie.c | 670 +++++++++++++++++++++++++++++ 3 files changed, 682 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..75477bea7f700 --- /dev/null +++ b/drivers/phy/phy-spacemit-k1-pcie.c @@ -0,0 +1,670 @@ +// 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 has a reset that it gets and deasserts during initialization. + * Each depends also on other 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; + int ret =3D 0; + int val; + + /* Nothing to do if we already set the receiver termination value */ + if (k1_phy_rterm_valid()) + return 0; + + /* + * 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 < 0) + 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(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 reset_control *phy_reset; + 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"); + + /* De-assert the PHY (global) reset and leave it that way */ + phy_reset =3D devm_reset_control_get_exclusive_deasserted(dev, "phy"); + if (IS_ERR(phy_reset)) + return PTR_ERR(phy_reset); + + 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 Sat Feb 7 21:24:15 2026 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 E18C634BA42 for ; Thu, 18 Dec 2025 15:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070769; cv=none; b=Mdysx0q4SQP8Hv8/SDODFBxXtwLsB00nDC2YH+JLn7WuH7MKSUjaLo1nJXM0Z4q356dkofuJZidGvHTnMPLmleCMMoWvBD0FDJ8ILyyWYXkE+6jWM27oAeZA6rmRl+U4wL0y5eC8szBuSHUZfB1pKOuegGxwbW+JO82+g2EIGS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070769; c=relaxed/simple; bh=rpoPtr0vcuPSzME+OCHzsK/d0X2Myz27uF4+n3Cpbv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PHo2bNyoG2M5B0royMcZJZFf+j3vGAudHlXeWY0bzVwOGQRTcL92FJXbNXyLcZTXh4KdZT26I8bU6YSO2LscktsjF6xyvg2rSq7hc23YFH0XmqpJNz3D5FIlOeye9r0g1tv0ulLZdO6sFWevNmKfkAps37AnJnZ18Omw9ryfVbo= 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=FUtXwpq6; arc=none smtp.client-ip=209.85.219.44 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="FUtXwpq6" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-8804f1bd6a7so7514646d6.2 for ; Thu, 18 Dec 2025 07:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1766070766; x=1766675566; 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=UrbGzwoMT9Ducrx+C40YCeeXZtuMUvm1QSQu39eFix8=; b=FUtXwpq6e26qRGFTx+RCzRrEXgneXeVdBE0ey6vdiXlsyi3NYiEYVtFOQk5adKWj0l w/FgSproFkoXxVUoNB4WJJCf8hWL11Fu5Fr4AsuyI1Z5TXtWlefixnlCLNIKkZ6fbrJz zoInvAprXNXHtQTHm2tYTa8FvVtCBpcHMvHFVpsNinn0kAF4Pnj4MiO5BoVupskYg6ut 4YwdPZyFUYT79mj/RgVhuwCCRhhRThbtJ8SKB3EgRQdPZZIZ+IFhbEnVNfQp1x0V2OTu SL48qK7ICk5oPa7q5+LIK9UeEyVnhhks7r2Z74moHs+eXQh7/h2AgqJu1c4NcLjgeLrp /Lyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766070766; x=1766675566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UrbGzwoMT9Ducrx+C40YCeeXZtuMUvm1QSQu39eFix8=; b=mfzYno1qFHnF7gsYDgTHB8TuQyJntG7pteln5h/PdWWTtH5PXywq/BgPewfAN8Ott4 LKRhMm5rDH22bHtyL0sbhunm+byrAx2JRKnrZTClBwMef9t2YSsL2tCnLo1OC7bql2ml 2Ot7xIGHWfkTBvG5UHfslrttYsPn3PK8V10+qpRlJALnLjbpXOHn/HI02CZvI9psZpuE cof/ccLBmBrvxKGFFRlWlTDqgFJqpz+LkqsHJ1vU/8h1k+03HEisU05z/7zJzfelHwuH VizzRatpKaRP6xK+9zMvFRdZe8ezsjFcsdHY57s3pvjlzMjzeMlp/6DBicKN6YDiu+mq Zg5g== X-Forwarded-Encrypted: i=1; AJvYcCXdFeUXy4djy1ujanCA+s2x2L9u8tvmVVRkDAhgJIEfefNtk8iXJlDd12CpZtKmSc6xAZmxXm38WRvCnvQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyXeXas1/tLP81d120WYp0T5N7oT0KvyZjf+07fdDkyqWNiqh3k 54vDjAm3NXgMtMKmUzfziU6FvrnVzr9hgaGSvvEUGSxnwEXpX0H9aGjEjQ9kQNKgOPM= X-Gm-Gg: AY/fxX69rwA/ktoGr8dR9KVFq+qHEGDzA0zTrDZy7TlNpHkReNKfMNsAu3roF0Nb5+J MzjkVPlDG/016g4lF3tpV7mI5hzMD6SPWaFotCJzyOszIvUcrRkk2lcMAXFZ7UiuNClDzRyrEwL IhH8f8S/ZL6aZSKrO75aukcmqpz0kEcF1dO9PgYb2e1lgzCBZ2gIwKR/ytcxJ7WSxURyY/Mh2mb fsO5n40mHwo+RHZ6zRH2goGM1eKerEte2ND7R/QoSamYFatR72VEc5HY7NCcdRgTgB90779MQ41 W1cpLVl88NkJWTgoAk0jbQlzeRwOMWKkUpLp8iNNsKRwU6MRXke6dq+PFceVzF5xXscNFpBLAWA CFfGcSzmaUD6R+amo0sWjEAqiQjEBEp76DFBfetLt2WHExLXi6Cf/MBQUy4fpR5ujEnLeoT01F7 ClpZH/NaxOcCRYgAhSSOW4AO+p6tUNPnpOy7JMjI3vCG7NkkR9f7OM7KEY7IH8sPOr X-Google-Smtp-Source: AGHT+IERRhvykRpFylfwji2IOQvYUcPVAffeIot0RaCQgPjegE4XUR5NaxLoYPi/HSBk+K0ZcroidQ== X-Received: by 2002:a05:6214:14ae:b0:888:7c7e:fce1 with SMTP id 6a1803df08f44-8887e1e9bd8mr237057126d6.4.1766070765721; Thu, 18 Dec 2025 07:12:45 -0800 (PST) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8beeb5d6952sm186866985a.3.2025.12.18.07.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 07:12:45 -0800 (PST) From: Alex Elder To: dlan@gentoo.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v7 4/5] riscv: dts: spacemit: Add a PCIe regulator Date: Thu, 18 Dec 2025 09:12:30 -0600 Message-ID: <20251218151235.454997-5-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251218151235.454997-1-elder@riscstar.com> References: <20251218151235.454997-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 Reviewed-by: Yixun Lan Tested-by: Yixun Lan --- 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 02f218a16318e..71f48454ba47c 100644 --- a/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +++ b/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts @@ -33,6 +33,14 @@ led1 { }; }; =20 + 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; + }; + reg_dc_in: dc-in-12v { compatible =3D "regulator-fixed"; regulator-name =3D "dc_in_12v"; --=20 2.48.1 From nobody Sat Feb 7 21:24:15 2026 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 7CFA734B691 for ; Thu, 18 Dec 2025 15:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070770; cv=none; b=ZZ8WBLgvaK7p21cICtGoe/tcUvVsi68tIkEWBmb9f+kGZVSy8Gx2aSXOR0hAvquXtTvIB/O49Ji658NvU8bS4Mx4zFvQ4Oydj6Ot14FyG8SKZgjBx7NEPx1MGwkl387zUGEqDug8q1GANqZ9cAft06V0ZXeE13Tc4fzq1fPs20A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070770; c=relaxed/simple; bh=LJ5v3sn1H+YFrsC7suciW3nVsqkQr7o+AMQ0WWlVsNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IO5yAcWRDM4hp9ziwYAYWXtPEePaze36IN0G33xuClTnu+ae+x1m2NxrgYCULDFPqhabzQ+mtGZu+pFLQoI+wx14ofnwCKV6NOuG4obZMKAMHVLUTVwovGWzTjp70LW49Hy+0Kluj11Q2AfM1ZlHkEmFp8kLT73UivWccixNI7Q= 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=bwdqoVff; arc=none smtp.client-ip=209.85.222.182 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="bwdqoVff" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-8b25ed53fcbso111720885a.0 for ; Thu, 18 Dec 2025 07:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1766070767; x=1766675567; 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=deRuCrhbg73yoYSTX7ZbEzVdWXcb3YNjOYMcREzS1gQ=; b=bwdqoVffbL/csQ5e9YFFPSgwfmkI4OYxi9LHDetffdAJKyRUzLD7OnGjZM4vPAaeaA i6yZaYOYlqOiwQaqiJWXMH+NyIQL/7Cl1B5PEdebqu9Cl0ojxRLSQ4TRA+21Fgd66l4B 63k/qgtiAp/10xuD63SK7oFcQJeYK6ryKY/Vwjr+vObzI8MP0c6XTVuuyUsmQxdFoZh6 POLylISip/ffMozGg/PrclwrVCBf6LE1U4h6Vbprm/TP/60eDuK+0HjD1MduLVW1A2Fl rU1AMoVjdib4E73mQ//MM+qz2R2R/dD8NahNBsPhHG0rcrhy88lnRdUUYIXvFTjEa4AK fhWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766070767; x=1766675567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=deRuCrhbg73yoYSTX7ZbEzVdWXcb3YNjOYMcREzS1gQ=; b=uZs16NETJqo1icGmh8kQbu7dcDO2Qf6bWtpKLlpDOxmflWj23jFCAVBYL5bwuAf5Mi 0UjDM+kAVGpyVIjboaQ+Czi0WWCs6lpPmTibzBHCHLCoMUVLsEkCP1WItCtZ6tpcU+zt wiez3YJzGG+1RgxMUzSh4ej+799yDXp371N1GXKv3Y3zvX/iS4BFccNIA92ieZOlqIeU Sksmis3IEDeFS+/jcFRan8huavR1oBYaZXNooS2SUbutbnyWMi6zXDhwYqEDNv8FpTx6 /8Cxc/J6/nmIk/ydeE7Lg3RSfzwi3ftB2T46gc+0idOxOPNJV6ASRwInmnXeHfW43M9D MPnA== X-Forwarded-Encrypted: i=1; AJvYcCVA0F09UMiVJtXm+edNoiWsuFuPhpOQIemNS4w+UI9BrftYM4PPTez+A+2VNtIWO4QLzqTtIxmEt4u8JVs=@vger.kernel.org X-Gm-Message-State: AOJu0YyLMPSm0/DnVVXCsskeWe9JR0jk0ScG4R/AV8Nuyp44hrNxhM0r iewKb/tyD6G8A3Z2b2y7tk7QZADHQGoejEzr6WXWZZbL8aRVua0fI3FeHIZWL5uE1g4= X-Gm-Gg: AY/fxX72ULYee3PNMfXVnpq+XfTDN/wZnj/AVqsOL3gcw1Ex6nrG4mBWqaOd+MnRqjv T63XTwfSBx8AGbb41VBdQTTydz0TOhYAbf8pOmuFbW3Oc2pKxUpfq2zT7EfHRAJk/c5I4ke4sKJ 3yabv0ZPzzR/0GvO4E5RG1yPoIUT3HV3DaU6rTcWO6Ck7RJxLPdX60zCNJcAxBwvnINJ5osjPzj 6N/D/5rV8Xcgc3tuW/cWHSGsAsa8fNX+HmeTsB1bGXo5cFxzc19frh69RimcZhM6mLN/hgT9FmJ PTnwxK7QlVGh7q1gHX2Cot+r4GUpFM6v0PM9q9AKkeEuxo5kfvPmFJlOFSu+j7nGA2d4FYFH/C3 p5kOQn8zmE93SfgtoTcq6pJyBiIioSpTTBxKXPXuPumgujmPGeCxPCH9DCiq00eQgJj3c465nOp rXTIToDE3t4nV1to1xfFMwtNseg2RX4/UhA8l1vYocBg55Jq8pyix3hT93hEIVCYyd X-Google-Smtp-Source: AGHT+IEHCa1eJb4MT97WJ2TBr0bKtCpanSEsyCdC2JZoWgz6PHaUL53lwZhkFeEOHvvP2mt5XmJ0qg== X-Received: by 2002:a05:620a:44d5:b0:8b2:ef2d:f74b with SMTP id af79cd13be357-8bb39ad47fbmr3261657885a.29.1766070767326; Thu, 18 Dec 2025 07:12:47 -0800 (PST) Received: from zippy.localdomain (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8beeb5d6952sm186866985a.3.2025.12.18.07.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 07:12:47 -0800 (PST) From: Alex Elder To: dlan@gentoo.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, guodong@riscstar.com, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v7 5/5] riscv: dts: spacemit: PCIe and PHY-related updates Date: Thu, 18 Dec 2025 09:12:31 -0600 Message-ID: <20251218151235.454997-6-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251218151235.454997-1-elder@riscstar.com> References: <20251218151235.454997-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 Reviewed-by: Yixun Lan Tested-by: Yixun Lan --- .../boot/dts/spacemit/k1-bananapi-f3.dts | 36 ++++ arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi | 33 ++++ arch/riscv/boot/dts/spacemit/k1.dtsi | 176 ++++++++++++++++++ 3 files changed, 245 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 71f48454ba47c..3f10efd925dc8 100644 --- a/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +++ b/arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts @@ -61,6 +61,12 @@ reg_vcc_4v: vcc-4v { }; }; =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; @@ -272,6 +278,36 @@ dldo7 { }; }; =20 +&pcie1_phy { + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie1_3_cfg>; + status =3D "okay"; +}; + +&pcie1_port { + phys =3D <&pcie1_phy>; +}; + +&pcie1 { + vpcie3v3-supply =3D <&pcie_vcc_3v3>; + status =3D "okay"; +}; + +&pcie2_phy { + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie2_4_cfg>; + status =3D "okay"; +}; + +&pcie2_port { + phys =3D <&pcie2_phy>; +}; + +&pcie2 { + 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 e922e05ff856d..b13dcb10f4d66 100644 --- a/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi +++ b/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi @@ -530,6 +530,39 @@ uart9-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 7818ca4979b6a..86d1db14e2ee4 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/; / { @@ -423,6 +424,52 @@ i2c5: i2c@d4013800 { status =3D "disabled"; }; =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_GLOBAL>, + <&syscon_apmu RESET_PCIE0_DBI>, + <&syscon_apmu RESET_PCIE0_MASTER>, + <&syscon_apmu RESET_PCIE0_SLAVE>; + reset-names =3D "phy", + "dbi", + "mstr", + "slv"; + #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"; + resets =3D <&syscon_apmu RESET_PCIE1_GLOBAL>; + reset-names =3D "phy"; + #phy-cells =3D <0>; + status =3D "disabled"; + }; + + pcie2_phy: phy@c0d10000 { + compatible =3D "spacemit,k1-pcie-phy"; + reg =3D <0x0 0xc0d10000 0x0 0x1000>; + clocks =3D <&vctcxo_24m>; + clock-names =3D "refclk"; + resets =3D <&syscon_apmu RESET_PCIE2_GLOBAL>; + reset-names =3D "phy"; + #phy-cells =3D <0>; + status =3D "disabled"; + }; + syscon_apbc: system-controller@d4015000 { compatible =3D "spacemit,k1-syscon-apbc"; reg =3D <0x0 0xd4015000 0x0 0x1000>; @@ -969,6 +1016,135 @@ pcie-bus { #size-cells =3D <2>; dma-ranges =3D <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>, <0x0 0xb8000000 0x1 0x38000000 0x3 0x48000000>; + pcie0: pcie@ca000000 { + device_type =3D "pci"; + 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>; + reset-names =3D "dbi", + "mstr", + "slv"; + spacemit,apmu =3D <&syscon_apmu 0x03cc>; + status =3D "disabled"; + + pcie0_port: pcie@0 { + device_type =3D "pci"; + compatible =3D "pciclass,0604"; + reg =3D <0x0 0x0 0x0 0x0 0x0>; + bus-range =3D <0x01 0xff>; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges; + }; + }; + + pcie1: pcie@ca400000 { + device_type =3D "pci"; + 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>; + reset-names =3D "dbi", + "mstr", + "slv"; + spacemit,apmu =3D <&syscon_apmu 0x3d4>; + status =3D "disabled"; + + pcie1_port: pcie@0 { + device_type =3D "pci"; + compatible =3D "pciclass,0604"; + reg =3D <0x0 0x0 0x0 0x0 0x0>; + bus-range =3D <0x01 0xff>; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges; + }; + }; + + pcie2: pcie@ca800000 { + device_type =3D "pci"; + 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>; + reset-names =3D "dbi", + "mstr", + "slv"; + spacemit,apmu =3D <&syscon_apmu 0x3dc>; + status =3D "disabled"; + + pcie2_port: pcie@0 { + device_type =3D "pci"; + compatible =3D "pciclass,0604"; + reg =3D <0x0 0x0 0x0 0x0 0x0>; + bus-range =3D <0x01 0xff>; + #address-cells =3D <3>; + #size-cells =3D <2>; + ranges; + }; + }; }; =20 storage-bus { --=20 2.48.1