From nobody Fri Dec 19 15:33:14 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 ED83C2D8783 for ; Thu, 13 Nov 2025 21:45:47 +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=1763070350; cv=none; b=n+LGWg49r0v6AXPu0PuMK/ihGAqBEQOmVvSmko9DsSjbI0MBJdI/NuZAmb/4lIwOyD7rVyyImrwNUxwA5I74Sizprsk2hAi1yh5xNvRP8kQybP8UJc3s0eXqaT3Z1gCpFSEwsehpgzEA/pRi5GFlEigc82jIUiDqosWaPucUKdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070350; c=relaxed/simple; bh=AxniUDFPOEBa6Hk3PEu2qbO8OY5+iC7H8GeN4m2w6cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sAmuhl5gahje13o8BBjCibIQC/idMVwtw+qwMfQYzT5YBhbDkTGG1vIaiFiyXjAOMkzszy2E2sR7/zH+RfwHSchd+pNpIjuPyN2tXDk5zFftEk0763kETvWuHt+nhlG7qo707C1mLw+F4w+vVCw7pBcH04apW3YVzBu9acpjJiE= 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=tK7rt++X; 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="tK7rt++X" Received: by mail-io1-f65.google.com with SMTP id ca18e2360f4ac-94880628ffaso55449839f.0 for ; Thu, 13 Nov 2025 13:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070347; x=1763675147; 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=tK7rt++XzN7M9/Xn0MTrNHVyKZH18Oirc7/q+qe77XZZCrbIsG7X6HExKzXpdgQ6ge GyfARBP4qpmGVnMXDEC0pSPTbjjpzjNAOKhTJdZm6YGbI+kPnAhFOojWS1JhM2JIj7FL Z0WQcwkxdSgnDHGWpTAOz2aJdqOjGpB5mkHzfwNgndt2qmh/4FDdWjVFdRcTAu53LZSl GVPgle2w7kBgp0CCLP9Sk+qzdEyckZRBG1+YG9mDmqy2zHaw/r1S9geiFXLJ+GCfL8QG htqPXftFsaIvCJw1Tuu3Ri7RzB4Fgyw6HYm/ed0UxRZVlKN4+bSL8PUT+YzH4u1uIe/n 4Hxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070347; x=1763675147; 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=UC+//ablIrdMi3z8IteX/j5szKISJcoH7UkQyULpRgfCH8ZPYtn+lNws+Xg7abRcV3 eGyHyWpkmmLvanOW4XAkKVw7O8Aijt7kV9spScCzJHCEmdnm1UrNCGCOCKuWxMyAy2ck SSCMGSfB2OWHzlrmXxZpoygrT9+VOHKWHZYc2dElsYZ6iafEWPtuj3DaDDjU8qy50d5f aeYlH2BCmfRJ+IWSxFzQLFkRMvd4f9+McfVx/AAeMCYVJ1SND5ax7NhJgUckrLreQ3Me i+5IhZ/NUb23Co8EcimeCNhcGP6AWoQCptBJxNuVzGhYbBesOeE/EJZEViq1WIragIv6 W7NQ== X-Forwarded-Encrypted: i=1; AJvYcCViS5+dcaCpf8Yc97pUJgSXFkw+eik2gMZ1tFYs+TFRG+IeOWafCCKqc3gemR+dhYMQ04BDyd2xzX8l18I=@vger.kernel.org X-Gm-Message-State: AOJu0YxGi2Howu5kgZtQGBehR9kTD9zjDOACR//f4lc/j6ycKrMyEUtv OSE1nC823fyT4wc/ZQ0/x4j/2O2SNhtAFkFXVfW63cRN9qwZEXuIj4qSzvr82OUNIBg= X-Gm-Gg: ASbGncsf5cW4FdfABTDx5Ihy6141MqnQE2gwsiwM+4Z98OSnKkD+j6fcBS/BwSpY3e3 clxpKDF25P008L2wVPkmqWnzZ8aXAPIXYuIG+pFjgfUYgsJr53Yv5AEG1e+H93mpaPLVU0zAZVo A0IKjJYa/FiWVKXBeQpE95rrY00hUfSnoj719QLkzeZSF/vCoVPfbGlPfPMwESFR78JkSNX6849 mFyQxQGiMuYq6Jq/tU7R4iYXy01C4B1OHBS7hxjtf56vLF96hsojHGtjE5yoNpLneYprueQc2oD kYK3P8na4RgNnTyWqByZ+J4GLXOG1jMpQwaXnuLYMFTFJh4O4O3+B+m41dpa0lcg0XPf7NMhnzE nig4BCjIIEksIbIRSmPSsjEwuZImgjgfbtv0P+uLOv5Cf5ytjgYmF3xgMFpxbQUNRfvK0B/Zvvn 9KZWI779YvjZPN5DkMPU7MM4vBdesvJ/lIsuU4bZ8u1QpgeggaI89OxShkwzD87L0j X-Google-Smtp-Source: AGHT+IH0iaOFvKkFoSvyh+E7QrJE8ooJ0JLk+JkYQy9a2bR8btw1mCKtxexcV6NZgeMvAElxAUOLHA== X-Received: by 2002:a05:6e02:c8d:b0:433:786a:5203 with SMTP id e9e14a558f8ab-4347c4c87d1mr64708185ab.10.1763070346997; Thu, 13 Nov 2025 13:45:46 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:46 -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 v6 1/7] dt-bindings: phy: spacemit: Add SpacemiT PCIe/combo PHY Date: Thu, 13 Nov 2025 15:45:33 -0600 Message-ID: <20251113214540.2623070-2-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- .../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 Fri Dec 19 15:33:14 2025 Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) (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 756CA3128D9 for ; Thu, 13 Nov 2025 21:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070352; cv=none; b=Lu/piVEA6HRj1Vl2kGfWVYfj5xHzBb3Job1ljQvyp6G+CZLSu+gG244e8mRAsageI/l2BTZe/QazbJTzS8HJHCbMZv/nQ793ZEsneiyGFGp2KPqWIHlMr3qycZq0FirDMZZzhv1+XnBLmXAUeKc/J6ELI2XS5xRl40FSrpADcwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070352; c=relaxed/simple; bh=8LppfTqRL5l2SybiAnwAcKY+acsrML8ysTdBgNm1hLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ar+9+RL5d6v0KVnkLMPeJNj6IDgWW3W8BicHNC1cAAj6R7T/5ohEzkOr88ET1Hx3x7lvVeMF6URj+1UyOmLVzWiqkB2ZXh7uJGC6GNeYDCrlMaKKSy4uEA8g0DYbjWqAV6/C9YzI7XqZPe/nn0+AvQJeZoyOt1eYhY4UniiMXEg= 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=T20y3C1K; arc=none smtp.client-ip=209.85.166.67 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="T20y3C1K" Received: by mail-io1-f67.google.com with SMTP id ca18e2360f4ac-948a7964a41so45227439f.2 for ; Thu, 13 Nov 2025 13:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070348; x=1763675148; 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=T20y3C1KbWBHS0uSeL6FfB99PQGiqOJrJneymWV6QFr2y/wOKe3mUAWGq96bjhEK5c 1XpgkAg6OYh0cDlN1jqQ7imdZ7VY0HEsaHTX7sQIdkqOvWw0nPNVuDucuz9N/d2X7ALT nFmmvpNovQLIOnRbr08ulJJBFAS8+Fl3hBtwrG4owXDSUrUrRZ+p1sLoHW7hCDga18er 9s03gKdqqMJSgsf5/zB+ZnK51UK/DoH4D4RbPhLCmFKW2vk+9tF+e1MU5FxE4RMoFHs8 gFh8xBAqqvIywAGhGox+MaN4BLkkEbOvjGwv3Ei2WEiRIjGrR/V/2ol4VHo6dDoQVcJm FwkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070348; x=1763675148; 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=Iybx8lZtYCWi2P6xJ5BU483Ugu+6uP13FaUV47uN/5yrZbMllW2BJG6l6c7jGq0vpR 19HY1CiKR6v25BwOpD0P9J/nawAOhiIGSNjadHIqT/lNWvkSiekZ7KkhuyrJaRUW76/d pGmnPXbhlm0KirOpfb9Jse6+CyP6poYe+tCzT2sHLJtt/8zFU+MVKzZ8WyAvfbiF6h4a r0VE3ph55cA0yHBT7ehohTkbDVs+SG2v0pKtn6B1gCGBlwHWMltEC0NHhjSml9teTUdS gmos6arYWZr+eajznCNbcDGBzmKDj00vvD4gThs8mgMLlGZEaudPXkjraZm1zLiJlavi 8llw== X-Forwarded-Encrypted: i=1; AJvYcCX2B65b3/nUG1cnd8+8G6tunx/NSaKH08rzJMG5uu2BeQm/eMA6dguL/SKMorkxbZ2jwTc35A6U5sciBjw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy92oTcMZtvPS4moqkDfby1XtAFnkKqUBWPOCDuIrKX81SiC0qK Blz7Lwm1IFb14MDX4DxepXkbdCoVidBgonXx34mvFV2LacXq588dZXXycOiaxhHhpCQ= X-Gm-Gg: ASbGnctae+kUgK9Z0/NkrCWO/0lxpxz7WfUsvJS26lICBUk/Zldq0REKDF3sQV/TyUL TPX4VjichKI7zu3S3Yd0Yd3ttN4S2wEoV+dKSp5MoUNnRHxwiDq9NAwM26XXwAgSn8UQGZN7YtS YD8hbjwj9EhrvgkkPPux2dQOrjp1iiR9Hw0mI1wDIncwRnPYj9hOSFvC2HLszf2kMl5UN3fER6b M9ibgDmosPVRaEdtx+1hedmrXVHnu7EWUTjhFyxE9AXk2OUCg1OCjPRl/7U/2O3lPrw/xcw9Gh1 LJzdEl12h+/kQZYx7AzpMQOIrV+2ort3QGQ7PNr4uvxlKB4Fsg98VzVF6UHK9nq8lk1I04TcQ49 qHwK2eTljOUda1nwO7e5VgUGgAj5sDDETlBoqzE+Sq6d3qigkU0v4X5LOWuFZSDVDM6k12sUkkg //IyN9pjq3r0uQHLyKYpqRU2Hz4NXUXu1nsaUGW25LKmvFd0Wi1btpQQ== X-Google-Smtp-Source: AGHT+IGBzq32Gwd/w1dsCQxRVXMGXyEzSrmOWSlAFvmiA2MTt5gy/g9voUkgRjr4rNHNd8IF81q02A== X-Received: by 2002:a05:6e02:214e:b0:433:589e:294f with SMTP id e9e14a558f8ab-4348c93ed24mr16120625ab.27.1763070348557; Thu, 13 Nov 2025 13:45:48 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:48 -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 v6 2/7] dt-bindings: phy: spacemit: Introduce PCIe PHY Date: Thu, 13 Nov 2025 15:45:34 -0600 Message-ID: <20251113214540.2623070-3-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- .../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 Fri Dec 19 15:33:14 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 48C24325705 for ; Thu, 13 Nov 2025 21:45:51 +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=1763070353; cv=none; b=nk6DSxZfrws0YaQw3NqGSbHeDX3KZGpbvLEvwM8zvdWEPmTi5BKOo5lE/V5k6BFMZ7nPuYiTXFnb8Cj0dI7x57BcHyI1DUZZH+MGgu+hphPqC7XoslrLYZRP+T6kikCWnWo+PmRtwwkNpmDbvAndb9rvZ1KmaJWd5BMWYxnxCcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070353; c=relaxed/simple; bh=pUZ/2iJtftGs7oXna+UtCd7yHJv39wuU0cwbMoeHLk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cEciy6iEuxFjVry7PdBwnjrGeSkU0+D4fKRx2mCt/rkXX7ALR7t+TbmsnlztYo0IESQHtC/vd9GP3K+lb2yh3Sj+8k2z1qxrZHq982FSPZh7aPFO8s8qhbPEEZck/xFDtOOyUMPcgdP/MDe+d7qz01RfSjPGALYyf15vDG9rLt0= 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=J049lLwe; 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="J049lLwe" Received: by mail-il1-f196.google.com with SMTP id e9e14a558f8ab-4330e912c51so6810025ab.3 for ; Thu, 13 Nov 2025 13:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070350; x=1763675150; 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=mH/xVMS32HLxpkBHVxi/V+Wnd3NwVi+5SDMCFTBBK7U=; b=J049lLweJUg1+X2mCoN/7sW8Yq6/zoe81i4bWw0I0+xEFryrJtfTRVI6cPNuuzL8If L5lwgtssy1n6GMQCUAo4Fxo4g/sYpqKrmVMKZgHCMU1DfmsATgtLuz80NrXtyCfDUXGH VfHs29wg309dP/AXZcwXMJ+JuGK66jiQou7vQJsOsnlQmBD71m4L9Y+ZAVGzznNb3rfP sZKIRxWUJKnjeC49OgAfD1UJ40SjQIQTKmyxzdtuA2aErh3EySL83DchY/XSAijZ1TFN 0dGC+94FGJxBwELCnzEUO6BB4MkiJOgqm5ip431hkuGMTcR6VJ7XZxU9oOznCyirHKKU RJxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070350; x=1763675150; 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=mH/xVMS32HLxpkBHVxi/V+Wnd3NwVi+5SDMCFTBBK7U=; b=mtDYIeEatrZUeMi3KyE/1jW79Hc1dTCUFp6kYHhPmK62vfzn7zrT7ADeaWKczW0ckd WfrGISC9RW8K1HTc3I/LxX7tHzx9WO7tHfWLoZO+PDoro0ryd8LQPisR8yWCAcAhdtd1 0CK4VZwPLU6gBIZp+4/Z3hlVfaAKC7iNCAyeAOm9O8Y5Q63QwjLbaOcRv4bzo0FUUj4k 66LtUfmnZWz87TwvaCO/q1fxYYbMd46hb25RhFMEXe6ov8XRkJES0ctK3gXzBQj80z03 2RjJVgol/g19B5YyLpwKuZUnpMCeBvxJMZSAn8Bq2xp7aRjgPvmUq1gXFOWwMMzQBK9L PuFQ== X-Forwarded-Encrypted: i=1; AJvYcCVZB7nBKK+gqX6PluWLBqcWjFbEONBer2U/J6Umgetu5/VmDLBr9UhAWRbpRCRi/39026+Umee9u+99IrE=@vger.kernel.org X-Gm-Message-State: AOJu0YwNsf8VvQ7Xj35c+uHOKWC9WQUbQNMWFUeSEyun5w83LhPdb/Py SJ048jDBeBW9T0q1iWUYAG92QCBZoBRMVwFPCWtrtB+/r1hyh8savnJ7Y0GbMUDQybE= X-Gm-Gg: ASbGncsmSeLco+9t4+bYpKJ0JqxslzLJFZM8fksE4FeGsBTr0F3gBBEv8FlZNv/gtWl Cf/nya7JkvuEXGEDvk29frLAyKu/K1G9U6C0yl+QDi3ul1igZ7+19W0R8Bb7Uarc1inQP+oTyQP UiFriY2ns2/HLgVbjoMqaS10G1zGKW9WiTOuOhdYyKYMvNUFw5Zs3qb4pYqnrOGMhjbQusCJGZT veYeDO/7e+nH2fcHIgwqViHds7AimXM6jr+VzvwdY1XM7CeaQad50IHLHkniEugXoGaVSiqMJyf DUIQN2djjhm1KG2Samq6zcPG7O6qQBdcD0IcdZAiMp5oofdNe2KxUxxwpz0KB1PNqNVBZWkAOr1 DZ7zP2o/jJfIClJIC7KYlpSCzGIWu8Gx8hHEKQ70H8JEQ+Bkle1gIF0LEAZ5VChN7195RzvY4zd SPgRhVIPKm2nV7IeFtrhirKp+IMh/VLSEv2LHzXJOmTh2xrFKQzzo99Q== X-Google-Smtp-Source: AGHT+IHT5rjiNvmqOH2t901xQsIP//7SsNWDMamOM11kpXdtNiVAX9RsLeYKi9slTC6iSHqCfSYAzg== X-Received: by 2002:a92:c26c:0:b0:433:7896:3e51 with SMTP id e9e14a558f8ab-4348c878e29mr17562905ab.2.1763070350356; Thu, 13 Nov 2025 13:45:50 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:49 -0800 (PST) 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 Cc: dlan@gentoo.org, guodong@riscstar.com, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/7] dt-bindings: pci: spacemit: Introduce PCIe host controller Date: Thu, 13 Nov 2025 15:45:35 -0600 Message-ID: <20251113214540.2623070-4-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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. Reviewed-by: Rob Herring (Arm) Signed-off-by: Alex Elder Tested-by: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- .../bindings/pci/spacemit,k1-pcie-host.yaml | 157 ++++++++++++++++++ 1 file changed, 157 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..c4c00b5fcdc0c --- /dev/null +++ b/Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml @@ -0,0 +1,157 @@ +# 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 Design= Ware + 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 + + 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 + + reset-names: + items: + - const: dbi + - const: mstr + - const: slv + + interrupts: + items: + - description: Interrupt used for MSIs + + interrupt-names: + const: msi + + 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 + +patternProperties: + '^pcie@': + type: object + $ref: /schemas/pci/pci-pci-bridge.yaml# + + properties: + phys: + maxItems: 1 + + vpcie3v3-supply: + description: + A phandle for 3.3v regulator to use for PCIe + + required: + - phys + - vpcie3v3-supply + + unevaluatedProperties: false + +required: + - clocks + - clock-names + - resets + - reset-names + - interrupts + - interrupt-names + - spacemit,apmu + +unevaluatedProperties: false + +examples: + - | + #include + pcie@ca400000 { + device_type =3D "pci"; + 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>; + reset-names =3D "dbi", + "mstr", + "slv"; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&pcie1_3_cfg>; + spacemit,apmu =3D <&syscon_apmu 0x3d4>; + + 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; + phys =3D <&pcie1_phy>; + vpcie3v3-supply =3D <&pcie_vcc_3v3>; + }; + }; --=20 2.48.1 From nobody Fri Dec 19 15:33:14 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 27977313E29 for ; Thu, 13 Nov 2025 21:45:53 +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=1763070356; cv=none; b=Cby9xwxW4tSCKPOm7HBkEO91ZngURljTJOUp330CCwrGmFq7WjT2UgogQb49OhTGyQp+/3CJiP7tlAdE/2NLdBl4cv0eNHsxfYmJ8GoLm4+L0MJKFJDGLkllFJZ7DB+u2AgSHZ7wjBmwKTCtlJIlnp5hMAdCEDrp9nMAi5XDyFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070356; c=relaxed/simple; bh=wPVeC9eXx0IbyXvhwCId2YdnCqWBRCPftMpWfA+2J0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rlB/VqHp+/B+hnke+NnpnZdSqBNz5w03pl1zH62b0FAoX3myjOPSRziswMEfIPB1Jm57fQ4OXxVIXX1y3VBBKLhFLDowPxihm58mienChfaqtcF9pI+AXVlKBM3Gt6BYKnu5N+TCwKO4fcDpRAPB5KSR0d1WjuhFkA6hcCGDTvE= 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=y2J7LITd; 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="y2J7LITd" Received: by mail-io1-f66.google.com with SMTP id ca18e2360f4ac-948e03b096dso31339339f.0 for ; Thu, 13 Nov 2025 13:45:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070352; x=1763675152; 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=y2J7LITdXuNDJQCWGZ9ZjfExG4awlhd6H4mvVw6DLmqB4bcIShvLyg/gDLGvZmUeKU s6gaHODlBCxgtxIc/SZHr5dP0//NteEGX8p2it1ofReNdvM7fgJGclF/udVUW+CdvbxC evBVUerjbIi6tjy3fVVeisGagUDQLOBbTNjzVOOvLIyutlXb4vnfjiPSCvO21FfxLF+m HTrSN0QO/6mz+5cVmD77qFczVkxOL2TvwrfPHgeQH2Upg0ORjUYYlZXuuBX6m8oeWx6f iP0b6sn2VYbLYoTyS5qLOt7eJl98H0qCBg6fT2SUvpbgsRXkT9Qm6bPe0ZMpb7eDJwvk v6/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070352; x=1763675152; 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=cEBS0XqU+iE3IX8iJx1jIwsPV4golsvXktSbHVaT3dvItwYMUKTh3z7YJ5UsocXgEn G6Hh69nVDPU8mnDfSqOdo0JZQRxrMltJAGj+edQIgy62gx+/UaXnZISth3YR2fmVZIeW zlQWIfx+CuCh9cEY96TruZ20xYqBJ9FHh3w47kjr2Tj/CW97RRB+cKJ4WrkUfIQCPfE3 166RrtCr8I9MEd2X0kwfU479PaMSAt4BF+QeTaV5ulph6ZjJWdUF0aoN4/k3F3vz5NG9 73L3N2cR+8oNpSliagwWeeEk8PUlWjfXQIVsXPyFpnaheiHimFbO0lFDCfzXc5ZUK0/F Re6w== X-Forwarded-Encrypted: i=1; AJvYcCXgtTissyRauBKT0XxadwDmcuC3jlgETSD5yyCaaIII/QEvfM5uYDi7HqfmD0EB3X+C2gImBbok4ELEX7o=@vger.kernel.org X-Gm-Message-State: AOJu0Yxt4oXh7RRowy4Rx3RPjNnVs6DZDnOw8G6WqRgqmdkgZswTd+Vs bniO+JYbdssJpbHcIOui0FgIkacLQ5uTaYOt+sf6C2xdHyRiH89h0lfdfAR2kdbbL+s= X-Gm-Gg: ASbGncvDPJj2Uu+vFOPAHJNfm3dX24Y5wzNXsnJ94o+a0KTIoo3fsI1KJ8vwXGDZ9MF MnsTV+uMS1wwz4smDIIZOFRLUn0vJG0pZhmAPPveG9VJxIgSP5IbBtuYAIJYFf2OkI/Jp5H6ahl yTqUA2uq/0K+nF+O9PG/jHbUY/AnReUQZazHyRPOt6zcLGaxQ6/3+s7g3eoIiOLB7N9mqs7m1qv IMZy4+PgNko2ves1KJqDhuxTqpEYS0/NGeaUay4cTDfbGCeGTmxInLbaQxlXv2wvOosCgwmWBuo d6wXGXNELoZmJ/ter4Q3zk4PtMQn4x9xHXfTl647OnRo1VvvJEST3kTzN3Cc7Hs6rfETVX1Uaew ZQED5XLqCWZSVt6SYkVCSEoQajoCnDMiJl+fZSPAoEP+VMURNpItSvv7pxta7ZVG7wjsD+2hRnm IYuVAAEml4Qcok+UXg5LtMPfYH+CSx7+zgxSyiPzVU70rfAN/4zeR5gw== X-Google-Smtp-Source: AGHT+IGSpPuXfEGslAwvRhtbaO3W2zl9E0/+K2sEyFW+QHvqD0+5CGi8aNojiTqdFQOs0OrbVStrCA== X-Received: by 2002:a05:6e02:184b:b0:433:7310:f5bf with SMTP id e9e14a558f8ab-4348c9491bdmr16687955ab.22.1763070352161; Thu, 13 Nov 2025 13:45:52 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:51 -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 v6 4/7] phy: spacemit: Introduce PCIe/combo PHY Date: Thu, 13 Nov 2025 15:45:36 -0600 Message-ID: <20251113214540.2623070-5-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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 Reviewed-by: Neil Armstrong Tested-by: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- 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 Fri Dec 19 15:33:14 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 7A54732693A for ; Thu, 13 Nov 2025 21:45:55 +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=1763070359; cv=none; b=U81XZqjFfxWQ5E6wuCKcReONM/X/Bu1gVcvkI+r7qIUakunHLu2MhxmDJHC60s6sC1lWQwdKidD4n2+ofrPxe4IWt749SQ1/6AFWn5ZrXXwKpAcwxxl7f8b/Qw90tOWsR+FzaOtGqg+FdjRD09C6YddavgAF5tRdO/QOwmpNtlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070359; c=relaxed/simple; bh=dmttAo+Jemguo+z64TFi9xk7TLfeTE44rROL+Uf68BU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DufCK01k4fiRJbV27yEQXBxGlcpIeSU2qPzJgewwC+jxC77Q+QMEYiYXXU+WP9E3ud0H2dOqgeG9CnWimRyF2qtHYoYXlGJXaLnPmTnOtwNqP1Yyzm6IBJPRKx3OSAgd9BoEBy6ivepVO8ygdh7f3Z629qX+IIVpBBAx7f51Imo= 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=kONDiLhT; 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="kONDiLhT" Received: by mail-io1-f66.google.com with SMTP id ca18e2360f4ac-94895f6b144so61433539f.0 for ; Thu, 13 Nov 2025 13:45:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070354; x=1763675154; 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=KHK8zPr6d0GmFSaiLzIgkmN/zTwMi8I5yquyjriCdgc=; b=kONDiLhTluJOV4V5R/Ep71qCBtmLA9mMWZnXCEuWVuGDjknw7q0bLLm1EK0Qs1rIXH QSpLGPCblAt7fAyGU+JXBJifIFGawh1Swd6/SR1mxMfYIBiu8SJAhbFwHNaVIEuhz+s5 bBMtaa6fuAEdubBmVAsjBolATg6sczgwtZZlX03dnRsDtj2ONOAqQr9rvJUBgWXr6NqX FDz4bjOZIIXtmyv4GZvJVnkxI1WZ8ypdpJYAh5iaqM4hnUc+eaf6IgjmaPa+bXvkXSzj h27fzVmcE1RLfCTceqX8n72kivHHNETCIlaGAXNdWpNUBxI5DwstI2EV/0Sc8po0IGvu D8Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070354; x=1763675154; 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=KHK8zPr6d0GmFSaiLzIgkmN/zTwMi8I5yquyjriCdgc=; b=JyMEwhhnmOCpRnLUn3hJgu2PqxVhRJTA6QOyGKfCa03rDOdbQKITHCRG05fHSnH5on eln/K9nWDlt8jbwAFD7iKAnnL2RswDX9K6UPy05As4fAzYBWcDwhd34Lx6X+FV6PAe6L SsLhWN6ycvabEF9WI7ob3/dsJ3VnPgZt2JdopgW0tAEH/VxhslF0UCAuoR6ziLX7iUND zkP3dzFMuqvxf8Wed3GxNnc/fyLzEhnQzBv/BwdLV5H2SYiPZTqQLvj4OSPqDdJItQYs oZZAkZ6mnKNOjxj11RIXtt9Mzac4dnsh/6C4eHSQgysIoLySZ5O7632iRhDka1u1ZYjJ Cvcg== X-Forwarded-Encrypted: i=1; AJvYcCUW7SVFrpiXArjvuQ460j5Lm3QkEB7JSv+KvvMSHOaTnPaZ5KiRKlE/BeRC+8AynegVfX8Etr4sQzo2uTw=@vger.kernel.org X-Gm-Message-State: AOJu0YximiC4FStGlfpc4e1BRgmuk1hdvtewDhyyx5Ip+PrAL0VfBuVQ c8y4OB3bw0V96Zi+BgNSg2nAe0s+hENPnVei01rCwgwayoFOc2HcN8ou/kqqYAJVJrQ= X-Gm-Gg: ASbGncvtECzRaoYoHoSRkEK21OuIWEV+zplJxu8MMK2wd/aji9ezODUlyGglOzTVW26 ad//fgZZGFjP6NjWrYqEKQmNMn3oc+hCbcSHx2rf8tKV8fnKa4msnh5hotI8wiEPuV2MW+zdwb0 mpqY3YmBi2KJ6pDrshOWLB53+c3DxKM0E04oe9dCmm5pxlmEU24Bn4XFgrKwu37UJGtHqHsy17b Am3iD4Df/JgyqEN/bWBY+pJ2gD3yczckFqyxUB6Tg64gDDJ0aBCzbKJnunfde/iK/zXSy14aMvP tBNSonqRIlwdegvSpB4VsQQcUqqIC+w79PqiD55TwZZ4DvXVB23AkXg+n+tl4mlNg1YM/H8p75+ GAg1AwjYHx7wOzqfAmZr8oJAzdEicH32PvNlmdeJnF5ct9wd5z+R9bQRpwBqZPXC0z2uRXzsK/j LciBuKNG6fR5Q52yRYdnVbBLUhExdrNiwWppPenR8fGbhmCJEFJGNJhA== X-Google-Smtp-Source: AGHT+IFl4CpymPkt5vmQxCdNn8nKwjZaGBs4cxdbPCn8PzMUOAsPh052vrqTvmxUyL9S/rllocpFOg== X-Received: by 2002:a05:6e02:3c86:b0:433:7b22:c2bd with SMTP id e9e14a558f8ab-4348c864268mr17350665ab.2.1763070354464; Thu, 13 Nov 2025 13:45:54 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:53 -0800 (PST) From: Alex Elder To: lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com Cc: dlan@gentoo.org, aurelien@aurel32.net, johannes@erdfelt.com, p.zabel@pengutronix.de, christian.bruel@foss.st.com, thippeswamy.havalige@amd.com, krishna.chundru@oss.qualcomm.com, mayank.rana@oss.qualcomm.com, qiang.yu@oss.qualcomm.com, shradha.t@samsung.com, inochiama@gmail.com, guodong@riscstar.com, linux-pci@vger.kernel.org, spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 5/7] PCI: spacemit: Add SpacemiT PCIe host driver Date: Thu, 13 Nov 2025 15:45:37 -0600 Message-ID: <20251113214540.2623070-6-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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 Tested-by: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- v6: - Disabling ASPM L1 is now done earlier, at the end of the dw_pcie_host_ops->init callback rather than ->post_init - The function that disables ASPM L1 has been moved an renamed to be k1_pcie_disable_aspm_l1() - The return value from devm_platform_ioremap_resource_byname() is now checked with IS_ERR() - The number of MSI vectors implemented 256, rather than the default - The sentinel entry in the OF match table no longer includes a trailing comma - MODULE_LICENSE() and MODULE_DESCRIPTION() macros are now included drivers/pci/controller/dwc/Kconfig | 13 + drivers/pci/controller/dwc/Makefile | 1 + drivers/pci/controller/dwc/pcie-spacemit-k1.c | 358 ++++++++++++++++++ 3 files changed, 372 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..718bb54e943f6 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -416,6 +416,19 @@ config PCIE_SOPHGO_DW Say Y here if you want PCIe host controller support on Sophgo SoCs. =20 +config PCIE_SPACEMIT_K1 + tristate "SpacemiT K1 PCIe controller (host mode)" + depends on ARCH_SPACEMIT || COMPILE_TEST + depends on HAS_IOMEM + select PCIE_DW_HOST + select PCI_PWRCTRL_SLOT + default ARCH_SPACEMIT + help + Enables support for the DesignWare based PCIe controller in + the SpacemiT K1 SoC operating in host mode. Three controllers + are available on the K1 SoC; the first of these shares a PHY + with a USB 3.0 host controller (one or the other can be used). + config PCIE_SPEAR13XX bool "STMicroelectronics SPEAr PCIe controller" depends on ARCH_SPEAR13XX || 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..451febfa326b7 --- /dev/null +++ b/drivers/pci/controller/dwc/pcie-spacemit-k1.c @@ -0,0 +1,358 @@ +// 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_enable_resources(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; + + return 0; + +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_disable_resources(struct k1_pcie *k1) +{ + struct dw_pcie *pci =3D &k1->pci; + + reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts); + clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks); +} + +/* Disable ASPM L1 to avoid errors reported on some NVMe drives */ +static void k1_pcie_disable_aspm_l1(struct k1_pcie *k1) +{ + struct dw_pcie *pci =3D &k1->pci; + u8 offset; + u32 val; + + offset =3D dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + offset +=3D PCI_EXP_LNKCAP; + + /* Turn off ASPM L1 for the link */ + dw_pcie_dbi_ro_wr_en(pci); + val =3D dw_pcie_readl_dbi(pci, offset); + val &=3D ~PCI_EXP_LNKCAP_ASPM_L1; + dw_pcie_writel_dbi(pci, offset, val); + dw_pcie_dbi_ro_wr_dis(pci); +} + +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 reset_ctrl; + u32 val; + int ret; + + k1_pcie_toggle_soft_reset(k1); + + ret =3D k1_pcie_enable_resources(k1); + if (ret) + 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); + + /* + * Start by asserting fundamental reset (drive PERST# low). The + * PCI CEM spec says that PERST# should be deasserted at least + * 100ms after the power becomes stable, so we'll insert that + * delay first. Write, then read it back to guarantee the write + * reaches the device before we start the delay. + */ + reset_ctrl =3D k1->pmu_off + PCIE_CLK_RESET_CONTROL; + regmap_set_bits(k1->pmu, reset_ctrl, PCIE_RC_PERST); + regmap_read(k1->pmu, reset_ctrl, &val); + mdelay(PCIE_T_PVPERL_MS); + + /* + * Put the controller in root complex mode, and indicate that + * Vaux (3.3v) is present. + */ + regmap_set_bits(k1->pmu, reset_ctrl, DEVICE_TYPE_RC | PCIE_AUX_PWR_DET); + + ret =3D phy_init(k1->phy); + if (ret) { + k1_pcie_disable_resources(k1); + + return ret; + } + + /* Deassert fundamental reset (drive PERST# high) */ + regmap_clear_bits(k1->pmu, reset_ctrl, PCIE_RC_PERST); + + /* Finally, as a workaround, disable ASPM L1 */ + k1_pcie_disable_aspm_l1(k1); + + 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_disable_resources(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_parse_port(struct k1_pcie *k1) +{ + struct device *dev =3D k1->pci.dev; + struct device_node *root_port; + struct phy *phy; + + /* We assume only one root port */ + root_port =3D of_get_next_available_child(dev_of_node(dev), NULL); + if (!root_port) + return -EINVAL; + + phy =3D devm_of_phy_get(dev, root_port, NULL); + + of_node_put(root_port); + + if (IS_ERR(phy)) + return PTR_ERR(phy); + + k1->phy =3D phy; + + return 0; +} + +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 (IS_ERR(k1->link)) + return dev_err_probe(dev, PTR_ERR(k1->link), + "failed to map \"link\" registers\n"); + + k1->pci.dev =3D dev; + k1->pci.ops =3D &k1_pcie_ops; + k1->pci.pp.num_vectors =3D MAX_MSI_IRQS; + dw_pcie_cap_set(&k1->pci, REQ_RES); + + k1->pci.pp.ops =3D &k1_pcie_host_ops; + + /* 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); + + ret =3D devm_regulator_get_enable(dev, "vpcie3v3"); + if (ret) + return dev_err_probe(dev, ret, + "failed to get \"vpcie3v3\" supply\n"); + + pm_runtime_set_active(dev); + pm_runtime_no_callbacks(dev); + devm_pm_runtime_enable(dev); + + platform_set_drvdata(pdev, k1); + + ret =3D k1_pcie_parse_port(k1); + if (ret) + return dev_err_probe(dev, ret, "failed to parse root port\n"); + + 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); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SpacemiT K1 PCIe host driver"); --=20 2.48.1 From nobody Fri Dec 19 15:33:14 2025 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) (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 C41C0326944 for ; Thu, 13 Nov 2025 21:45:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070358; cv=none; b=AajqBg0elha1TzlKinWSvfw4T/PrCBcc95OOYyk8nDWYajVB84vVS8ueVwz/+P+duav/PJUMryPVRQqVB9YNCE2W1FLYAaKTIpP7dnynSz61W+GaQ5+bwBXHU7Sjg6fy3ThxpbxQrFy6fa2CnApvZhn6S0hOz/m+5nGkbnSTpxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070358; c=relaxed/simple; bh=rpoPtr0vcuPSzME+OCHzsK/d0X2Myz27uF4+n3Cpbv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YmdN3iAtpumPuaQhHLeGSeqzNsHdhfaD0uG51CgEtzogjWOuTnfzPFr1xfQIav6YStEC68WIyGX1SrPvaAc2ND9Popsd6LOGHmtPTiHbM0rLGLHf+tz/cu3sO2UVW9ZHBfJtHVEm8rok4rDEjsEIVp0sppCQCIMXx9im1qxB3kM= 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+gsh3o0; arc=none smtp.client-ip=209.85.166.177 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+gsh3o0" Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-43320988dcfso5950595ab.3 for ; Thu, 13 Nov 2025 13:45:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070356; x=1763675156; 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=h+gsh3o0gaYX+bns0SrdMvFrGAYTyFE5fxMme+KQDTMsbW0msYj8ryo+yZk/JQdOOx 75lN9ifMBCMgYkPAS0Dc/rHOSeo1+ABAnBIZMDVTfCuLNuydC9maGC887JI33h7Mq9vL KP+rLA0nYddAlra2zGoN3xf5H0VBr4K8gZ1qpiwBvgjUATlEtR0cIcuX+zCVjKbICyRA ZmUNOuZ7XtDw81gOTqX0Fnq0HSD4ro5ij4cAB+8UyB0UuhOjJBsFT5NIzIlyQ2HwNiZ1 y6wwIzvuwK7zUL64OLhEjPr79SwdPd/obLrI/6zvfwMMF+Uf34Jd4hUv+jmzcYcwGPr/ NNxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070356; x=1763675156; 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=tC0MGUQuuK8NV5AVedjg3IzBfJaxe0ZVllc57cFgUrZq8O5xvRffA3NtKrWPsR51nw iWMTBcIrbCqR/Ck1mIQU03O8BUJ1mL1QMi6X+U/zVISaKLU4Lb6INi6b4nuWR5oRxifs 1y5yBRLR66gsrz/a97tQWUQjPaajMh1HFSEhimEdCQiM4mwHsaLLS9eCe/hE2cmR+9/a Dhtq4cbe89/u1ch4WxGFmEYA6pvBNKmnbs+xcs3BTu9XpEyN2Z4vEQqRXY/Hq6EEo5nB YInUpuspJuYJQHeatldFCdJWzoQMSO+CY27n9CgBRu7B9ZGbdBhjSxEqZIRDzXq1TdTS /Njw== X-Forwarded-Encrypted: i=1; AJvYcCXFxLIbroav5NwXHNuauzykaLXOKxgByhimkm3/b9/WZbRuhIQPFNKPkDg4qe0FzRya4+1NNFRB/B53/cU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/Px9c/aXTkd5MWXCwsPJB+WV6oG7R+l0BZvdcyEbkKCJKqW6W adsEIxljTZK2mtjNa4tEDXmYcE0G3L8vASmAqf9izwTiuYk997s9EmMLMs3Jnl9IJe8= X-Gm-Gg: ASbGncsWA0EnCjhuGn3Q2eeTYKZPRD8Fcy4ZZrh/5CQQ6ouwBjlNhzrHxIla1e3EHQE WSYq74fJOsvv78HIzzaVMpPCqoYN/aY98ngQV89Aq7RbCqQaWqjyZ4NxdyrkYy932FeAzc7CMsz 2sgKsHpwrYHctyturVY3AGRPsjBhxwp2ED8dRNVpeifbetef7mvoHZs3xW/prg4LI5pxQYTvIeA HhHV02Slk8H9NdpPUtxxLqb9nGiUE150OooOJXOm2KzUL7Ce02nQ/3vKH1fM6kdQ0kGuSa0N/ho FvkKt44bqzo9JC3nA53TYO66l2RgBao6tdLVI+vbb3/Q+AA0b947cBBcmZ80+YLVcalT3BSJSrO h90Hb8vT5uFYBM19ogni462sillDKR+6ZtxRwhfEXqpkCd506DqjrJqJv6sT+Ig5cSkiC/hF7HL pIjv+JmWfhRu0s+8M0FtbRdW8/nKo8lG3vLZ3K1zSRGmzPuWoQ4jtOHw== X-Google-Smtp-Source: AGHT+IFomP3OhkAPUlXBqH3nkrCRAP2vPJKy7pF18zv2dwYytVZuZbONaXMoLuyWSdunyx1jnM/2/w== X-Received: by 2002:a05:6e02:1d99:b0:433:7e25:b93d with SMTP id e9e14a558f8ab-4348c949c9amr17614215ab.28.1763070355985; Thu, 13 Nov 2025 13:45:55 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:55 -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 v6 6/7] riscv: dts: spacemit: Add a PCIe regulator Date: Thu, 13 Nov 2025 15:45:38 -0600 Message-ID: <20251113214540.2623070-7-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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 Tested-by: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- 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 Fri Dec 19 15:33:14 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 C6CE9326939 for ; Thu, 13 Nov 2025 21:45:58 +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=1763070360; cv=none; b=K1CqdN4gJJ/EacNI1EAd1SexW1ngWva9Vm3XFuflkGAe4JFVvCg2oQm7Jb6V7JWwTkCfYFkcR8yh5a83+haLFFJYdAQTHbayg+8YTzO5+8viWbGKAVl0cvCHK6olT3tiqCccYFYeHmdnQMPL9NycBsR3b0s7ykxt212UxhrwZbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763070360; c=relaxed/simple; bh=LJ5v3sn1H+YFrsC7suciW3nVsqkQr7o+AMQ0WWlVsNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HjKQGbAsZQkCLObdtYcXxEPNaqW0dPxrD4+a4lA+xspDgNim1dMYnTLjlWf+YdpHWH1Zl/fJk0bEVVXcmSZcjMgYwE08NCUdHHQAPEUNE7TLIGEk1GkvLuCvcjq3w+Tg066F1NQ/kyU40rFTlTeUtni1acNFs08HYgLdfGnuRc8= 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=DoYl6cvw; 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="DoYl6cvw" Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-4331b4d5c6eso5322875ab.2 for ; Thu, 13 Nov 2025 13:45:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1763070358; x=1763675158; 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=DoYl6cvw2C2jvaopH+augCbtZcSQtHW6Ne9EVVyniy8tVhGiBNZVlNI4tttoM7chgS NDxoXuLlUNSjuKVwBuXoOVb+DXmuV6Z15ymL47mU1CC/ZCcyiXkVm7Y5XQ7Vy1ogj+AL Rr5qFYIGXmDw+T6+wmvc8jMGnRlTZt08eEwDOtEyWzAbxG5fjl6TcBIM4PWsIweMqs90 P3IZKEYPWAu851U3ldg222q9Sk5nbdyO9MJbzcUSwuenpgf0bae5o4v4vRR37T4hVLzZ XxcdBXu23GFRi2WOpO/YI7X3fykZedBtA3iyPXGWyXfXK+ra7Nu+FY4Smge/QF1wov21 +mrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763070358; x=1763675158; 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=R9z8aanLYTR7HTP/dwOggqGWBVWLtQX/jiaj4tXG5PdgolcHYfYr9CGP9z6uFjUaRv 4RtIpapkkUW63y2Vec5VzLUsSzz1LmRWavLB+ROsI8LnI9gSCqHihGNZVZ7jeHdk+uKW Fkx+NByKZaveSb4drHsf3K2yINEqWiyh7TMjT24BOHS5UEiAlXrb6ev815Zn86Gxn/LF oJdwJkqNQLXZyOoTlUW28QlVrQa6ScXAv1kJ6MiVIy0zgI3emYpW+M3NDKPMuAFPTrxp ib9WFvEwRt6YZoCDmAu5AeArhUUL86/TXpkFk/MXpBuNk3U41F8N8DwBxPv+1DhmeKNr 6Bqw== X-Forwarded-Encrypted: i=1; AJvYcCV/0zqvKSoqH8VXAdISoAml3mk5MvrRsNUrmC9wyCZCbJT+m2yctPLKwZ0INyNjaM5jLXKc80XKC/21bbA=@vger.kernel.org X-Gm-Message-State: AOJu0YxM/Q3Bwi+loplypTWzvEE//Qhwt13mEl1oi7B4dkeumCV/XPq7 6YEXPfrWlcFRjSNGSD66fks9m+n5AHP6sYU608ZgcnU6ZSaX3NLm9aATZQnC5uPm034= X-Gm-Gg: ASbGncuHZ3wA+ZQKr6hzb1Hu0FQDv06CTSAQkx76+nX0jJ6eICcnepSOTa7jsuQG2g8 ADBY/tc6Vd0GTSXVHylRSr51Nsr2w/k9SlvI2o0UblvG7gY5BbxtUKikevqbD4O1DzJnXrhjbUb VkBquIBOgm1KZS264tSsV2yErzxutpCYJTHONr4h6T/soiZNuH5tdd0qSz4bZLXMsNycG337HAO LaOvyM85qjU/1zmZLLeghmEdfqkBD2ns0I+4RbI/PWxSYtGFJuVVZ0ugPXgt/HSYZ3pWOxh3h9l he44psqogUMb7H/jK7kBNmPyBHc6JvvSHQq7i+F7Dc+RfP6rATNsP7iZN5WB+w04grM/kbCnz/d U+am3GDfSt8zlKY+NCOQwuUwRPGkZ4vNSWF0DP9Zow9BF6Bd+pw5/rEvVwPzIxt17ZYmemUErXg BqTxklbItRNkzWDucg0BISu8Fj3EQT0J+PB4tLCF789BBXzDoShhRvsq/ukRgSgd/p X-Google-Smtp-Source: AGHT+IEvguf6tBlTrnNH3WYTCFykO/NToGvTaWWLy0FsWmSPv03pSe9jJlt9kRkNhm10ZfiEVXgJMw== X-Received: by 2002:a92:cda5:0:b0:434:767d:8a3f with SMTP id e9e14a558f8ab-4348c942b89mr16005835ab.21.1763070357875; Thu, 13 Nov 2025 13:45:57 -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 e9e14a558f8ab-434839a4ac7sm10877115ab.25.2025.11.13.13.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 13:45:57 -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 v6 7/7] riscv: dts: spacemit: PCIe and PHY-related updates Date: Thu, 13 Nov 2025 15:45:39 -0600 Message-ID: <20251113214540.2623070-8-elder@riscstar.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113214540.2623070-1-elder@riscstar.com> References: <20251113214540.2623070-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 Tested-by: Aurelien Jarno Tested-by: Jason Montleon Tested-by: Johannes Erdfelt --- .../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