From nobody Mon Oct 6 01:23:47 2025 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (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 4C8C124676A; Mon, 28 Jul 2025 10:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.21.23.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753698711; cv=none; b=S229IQFdl7LSENV1sa6boFK2V7x5V5WzQ43Y9S2dBH7UpTBxnsSQMrERmtN8u5vdZqjN9k3ByWcsJc24UUueP4AZsNqVxhKvw7h2veKCB484OCAr0W5LdVqYcF/cPQ4NKOGPlwNX70ws7puXuQjeCOzbktRJIK+7Kh2mctd2EZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753698711; c=relaxed/simple; bh=IBUegwoSVCEGUi2guCueCTNaXBxw8yQDmiCjNYZTQWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=COhC0Ts6juLYvSdPJ/iSub12fbsGNbfIUPasj/rywct5Bw1vvvVI4pU+UarLxkYRViCMpO9vEepqi+qB34chMY+oVx4G63chc7ssAtH1wAG4LjK28n4mw8Ms9vAQUHD3SYpqxppHMBiMVzwqF2zSmi250WQmh0HLVzw+jZrYpBU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b=l3t8VRwP; arc=none smtp.client-ip=178.21.23.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b="l3t8VRwP" Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id B18DD22B44; Mon, 28 Jul 2025 12:31:47 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id xoEDLdzWHo2z; Mon, 28 Jul 2025 12:31:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1753698705; bh=IBUegwoSVCEGUi2guCueCTNaXBxw8yQDmiCjNYZTQWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=l3t8VRwP249bW2pC63+lBTZGAuNj5FkZGl6ntP5AjpwBv68m0C4Z0cy1OBRYNFN0l TsUjgsx5BYEq1pDyX84ISJwZxKjdjHvihknfzZAtoPPWaqVZ/slz/PEZ4mdHSTq1p/ N9bJP5cGc1sSP0faQ8x0R33Elcr1WOrhmwMQOL1wPdEXMkIz/c6WeD7v2ZPkhS9WeR bWtABWJKdYWg0CgnYT9ndRhOZ/Jg0PFmQ+V2RsGU5a20+ZgMgs4a3QpbY8kGQRybkB Hpc6fgSKKW6yNAekZ0r4pPryoZD26w+uPn1H1dd3pmkTrPe0biq+IlmkSWoSgZNAe2 FdrKFe+vZTBxw== From: Yao Zi To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Yao Zi , Frank Wang , Andy Yan , Cristian Ciocaltea , Detlev Casanova , Shresth Prasad , Chukun Pan , Jonas Karlman Cc: linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Neil Armstrong Subject: [PATCH v5 5/6] phy: rockchip: naneng-combphy: Add RK3528 support Date: Mon, 28 Jul 2025 10:29:47 +0000 Message-ID: <20250728102947.38984-7-ziyao@disroot.org> In-Reply-To: <20250728102947.38984-2-ziyao@disroot.org> References: <20250728102947.38984-2-ziyao@disroot.org> 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" Rockchip RK3528 integrates one naneng-combphy that is able to operate in PCIe and USB3 mode. The control logic is similar to previous variants of naneng-combphy but the register layout is apperantly different from the RK3568 one. Signed-off-by: Yao Zi Reviewed-by: Heiko Stuebner Reviewed-by: Neil Armstrong --- .../rockchip/phy-rockchip-naneng-combphy.c | 189 +++++++++++++++++- 1 file changed, 188 insertions(+), 1 deletion(-) diff --git a/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c b/drivers/p= hy/rockchip/phy-rockchip-naneng-combphy.c index ce84166cd772..0d25872e6712 100644 --- a/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +++ b/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c @@ -20,7 +20,46 @@ #define REF_CLOCK_25MHz (25 * HZ_PER_MHZ) #define REF_CLOCK_100MHz (100 * HZ_PER_MHZ) =20 -/* COMBO PHY REG */ +/* RK3528 COMBO PHY REG */ +#define RK3528_PHYREG6 0x18 +#define RK3528_PHYREG6_PLL_KVCO GENMASK(12, 10) +#define RK3528_PHYREG6_PLL_KVCO_VALUE 0x2 +#define RK3528_PHYREG6_SSC_DIR GENMASK(5, 4) +#define RK3528_PHYREG6_SSC_UPWARD 0 +#define RK3528_PHYREG6_SSC_DOWNWARD 1 + +#define RK3528_PHYREG40 0x100 +#define RK3528_PHYREG40_SSC_EN BIT(20) +#define RK3528_PHYREG40_SSC_CNT GENMASK(10, 0) +#define RK3528_PHYREG40_SSC_CNT_VALUE 0x17d + +#define RK3528_PHYREG42 0x108 +#define RK3528_PHYREG42_CKDRV_CLK_SEL BIT(29) +#define RK3528_PHYREG42_CKDRV_CLK_PLL 0 +#define RK3528_PHYREG42_CKDRV_CLK_CKRCV 1 +#define RK3528_PHYREG42_PLL_LPF_R1_ADJ GENMASK(10, 7) +#define RK3528_PHYREG42_PLL_LPF_R1_ADJ_VALUE 0x9 +#define RK3528_PHYREG42_PLL_CHGPUMP_CUR_ADJ GENMASK(6, 4) +#define RK3528_PHYREG42_PLL_CHGPUMP_CUR_ADJ_VALUE 0x7 +#define RK3528_PHYREG42_PLL_KVCO_ADJ GENMASK(2, 0) +#define RK3528_PHYREG42_PLL_KVCO_ADJ_VALUE 0x0 + +#define RK3528_PHYREG80 0x200 +#define RK3528_PHYREG80_CTLE_EN BIT(17) + +#define RK3528_PHYREG81 0x204 +#define RK3528_PHYREG81_CDR_PHASE_PATH_GAIN_2X BIT(5) +#define RK3528_PHYREG81_SLEW_RATE_CTRL GENMASK(2, 0) +#define RK3528_PHYREG81_SLEW_RATE_CTRL_SLOW 0x7 + +#define RK3528_PHYREG83 0x20c +#define RK3528_PHYREG83_RX_SQUELCH GENMASK(2, 0) +#define RK3528_PHYREG83_RX_SQUELCH_VALUE 0x6 + +#define RK3528_PHYREG86 0x218 +#define RK3528_PHYREG86_RTERM_DET_CLK_EN BIT(14) + +/* RK3568 COMBO PHY REG */ #define RK3568_PHYREG6 0x14 #define RK3568_PHYREG6_PLL_DIV_MASK GENMASK(7, 6) #define RK3568_PHYREG6_PLL_DIV_SHIFT 6 @@ -400,6 +439,150 @@ static int rockchip_combphy_probe(struct platform_dev= ice *pdev) return PTR_ERR_OR_ZERO(phy_provider); } =20 +static int rk3528_combphy_cfg(struct rockchip_combphy_priv *priv) +{ + const struct rockchip_combphy_grfcfg *cfg =3D priv->cfg->grfcfg; + unsigned long rate; + u32 val; + + /* Set SSC downward spread spectrum */ + val =3D FIELD_PREP(RK3528_PHYREG6_SSC_DIR, RK3528_PHYREG6_SSC_DOWNWARD); + rockchip_combphy_updatel(priv, RK3528_PHYREG6_SSC_DIR, val, RK3528_PHYREG= 6); + + switch (priv->type) { + case PHY_TYPE_PCIE: + rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_pcie, true); + rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_pcie, true); + rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_pcie, true); + rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_pcie, true); + break; + case PHY_TYPE_USB3: + /* Enable adaptive CTLE for USB3.0 Rx */ + rockchip_combphy_updatel(priv, RK3528_PHYREG80_CTLE_EN, RK3528_PHYREG80_= CTLE_EN, + RK3528_PHYREG80); + + /* Set slow slew rate control for PI */ + val =3D FIELD_PREP(RK3528_PHYREG81_SLEW_RATE_CTRL, + RK3528_PHYREG81_SLEW_RATE_CTRL_SLOW); + rockchip_combphy_updatel(priv, RK3528_PHYREG81_SLEW_RATE_CTRL, val, + RK3528_PHYREG81); + + /* Set CDR phase path with 2x gain */ + rockchip_combphy_updatel(priv, RK3528_PHYREG81_CDR_PHASE_PATH_GAIN_2X, + RK3528_PHYREG81_CDR_PHASE_PATH_GAIN_2X, RK3528_PHYREG81); + + /* Set Rx squelch input filler bandwidth */ + val =3D FIELD_PREP(RK3528_PHYREG83_RX_SQUELCH, RK3528_PHYREG83_RX_SQUELC= H_VALUE); + rockchip_combphy_updatel(priv, RK3528_PHYREG83_RX_SQUELCH, val, RK3528_P= HYREG83); + + rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false= ); + rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false= ); + rockchip_combphy_param_write(priv->phy_grf, &cfg->usb_mode_set, true); + rockchip_combphy_param_write(priv->pipe_grf, &cfg->u3otg0_port_en, true); + break; + default: + dev_err(priv->dev, "incompatible PHY type\n"); + return -EINVAL; + } + + rate =3D clk_get_rate(priv->refclk); + + switch (rate) { + case REF_CLOCK_24MHz: + rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_24m, true); + if (priv->type =3D=3D PHY_TYPE_USB3) { + /* Set ssc_cnt[10:0]=3D00101111101 & 31.5KHz */ + val =3D FIELD_PREP(RK3528_PHYREG40_SSC_CNT, RK3528_PHYREG40_SSC_CNT_VAL= UE); + rockchip_combphy_updatel(priv, RK3528_PHYREG40_SSC_CNT, val, + RK3528_PHYREG40); + } else if (priv->type =3D=3D PHY_TYPE_PCIE) { + /* tx_trim[14]=3D1, Enable the counting clock of the rterm detect */ + rockchip_combphy_updatel(priv, RK3528_PHYREG86_RTERM_DET_CLK_EN, + RK3528_PHYREG86_RTERM_DET_CLK_EN, RK3528_PHYREG86); + } + break; + case REF_CLOCK_100MHz: + rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_100m, true); + if (priv->type =3D=3D PHY_TYPE_PCIE) { + /* PLL KVCO tuning fine */ + val =3D FIELD_PREP(RK3528_PHYREG6_PLL_KVCO, RK3528_PHYREG6_PLL_KVCO_VAL= UE); + rockchip_combphy_updatel(priv, RK3528_PHYREG6_PLL_KVCO, val, + RK3528_PHYREG6); + + /* su_trim[6:4]=3D111, [10:7]=3D1001, [2:0]=3D000, swing 650mv */ + writel(0x570804f0, priv->mmio + RK3528_PHYREG42); + } + break; + default: + dev_err(priv->dev, "Unsupported rate: %lu\n", rate); + return -EINVAL; + } + + if (device_property_read_bool(priv->dev, "rockchip,ext-refclk")) { + rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_ext, true); + + if (priv->type =3D=3D PHY_TYPE_PCIE && rate =3D=3D REF_CLOCK_100MHz) { + val =3D FIELD_PREP(RK3528_PHYREG42_CKDRV_CLK_SEL, + RK3528_PHYREG42_CKDRV_CLK_CKRCV); + val |=3D FIELD_PREP(RK3528_PHYREG42_PLL_LPF_R1_ADJ, + RK3528_PHYREG42_PLL_LPF_R1_ADJ_VALUE); + val |=3D FIELD_PREP(RK3528_PHYREG42_PLL_CHGPUMP_CUR_ADJ, + RK3528_PHYREG42_PLL_CHGPUMP_CUR_ADJ_VALUE); + val |=3D FIELD_PREP(RK3528_PHYREG42_PLL_KVCO_ADJ, + RK3528_PHYREG42_PLL_KVCO_ADJ_VALUE); + rockchip_combphy_updatel(priv, + RK3528_PHYREG42_CKDRV_CLK_SEL | + RK3528_PHYREG42_PLL_LPF_R1_ADJ | + RK3528_PHYREG42_PLL_CHGPUMP_CUR_ADJ | + RK3528_PHYREG42_PLL_KVCO_ADJ, + val, RK3528_PHYREG42); + + val =3D FIELD_PREP(RK3528_PHYREG6_PLL_KVCO, RK3528_PHYREG6_PLL_KVCO_VAL= UE); + rockchip_combphy_updatel(priv, RK3528_PHYREG6_PLL_KVCO, val, + RK3528_PHYREG6); + } + } + + if (priv->type =3D=3D PHY_TYPE_PCIE) { + if (device_property_read_bool(priv->dev, "rockchip,enable-ssc")) + rockchip_combphy_updatel(priv, RK3528_PHYREG40_SSC_EN, + RK3528_PHYREG40_SSC_EN, RK3528_PHYREG40); + } + + return 0; +} + +static const struct rockchip_combphy_grfcfg rk3528_combphy_grfcfgs =3D { + /* pipe-phy-grf */ + .pcie_mode_set =3D { 0x0000, 5, 0, 0x00, 0x11 }, + .usb_mode_set =3D { 0x0000, 5, 0, 0x00, 0x04 }, + .pipe_rxterm_set =3D { 0x0000, 12, 12, 0x00, 0x01 }, + .pipe_txelec_set =3D { 0x0004, 1, 1, 0x00, 0x01 }, + .pipe_txcomp_set =3D { 0x0004, 4, 4, 0x00, 0x01 }, + .pipe_clk_24m =3D { 0x0004, 14, 13, 0x00, 0x00 }, + .pipe_clk_100m =3D { 0x0004, 14, 13, 0x00, 0x02 }, + .pipe_rxterm_sel =3D { 0x0008, 8, 8, 0x00, 0x01 }, + .pipe_txelec_sel =3D { 0x0008, 12, 12, 0x00, 0x01 }, + .pipe_txcomp_sel =3D { 0x0008, 15, 15, 0x00, 0x01 }, + .pipe_clk_ext =3D { 0x000c, 9, 8, 0x02, 0x01 }, + .pipe_phy_status =3D { 0x0034, 6, 6, 0x01, 0x00 }, + .con0_for_pcie =3D { 0x0000, 15, 0, 0x00, 0x110 }, + .con1_for_pcie =3D { 0x0004, 15, 0, 0x00, 0x00 }, + .con2_for_pcie =3D { 0x0008, 15, 0, 0x00, 0x101 }, + .con3_for_pcie =3D { 0x000c, 15, 0, 0x00, 0x0200 }, + /* pipe-grf */ + .u3otg0_port_en =3D { 0x0044, 15, 0, 0x0181, 0x1100 }, +}; + +static const struct rockchip_combphy_cfg rk3528_combphy_cfgs =3D { + .num_phys =3D 1, + .phy_ids =3D { + 0xffdc0000, + }, + .grfcfg =3D &rk3528_combphy_grfcfgs, + .combphy_cfg =3D rk3528_combphy_cfg, +}; + static int rk3562_combphy_cfg(struct rockchip_combphy_priv *priv) { const struct rockchip_combphy_grfcfg *cfg =3D priv->cfg->grfcfg; @@ -1225,6 +1408,10 @@ static const struct rockchip_combphy_cfg rk3588_comb= phy_cfgs =3D { }; =20 static const struct of_device_id rockchip_combphy_of_match[] =3D { + { + .compatible =3D "rockchip,rk3528-naneng-combphy", + .data =3D &rk3528_combphy_cfgs, + }, { .compatible =3D "rockchip,rk3562-naneng-combphy", .data =3D &rk3562_combphy_cfgs, --=20 2.50.1