Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ECD87C04E69 for ; Wed, 2 Aug 2023 19:29:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 39D5B86879; Wed, 2 Aug 2023 21:29:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kwiboo.se header.i=@kwiboo.se header.b="Ebwi1cE6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C5AD28686F; Wed, 2 Aug 2023 21:29:08 +0200 (CEST) Received: from wfbtzhsw.outbound-mail.sendgrid.net (wfbtzhsw.outbound-mail.sendgrid.net [159.183.224.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 88A98868DA for ; Wed, 2 Aug 2023 21:29:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bounces+31435339-7456-u-boot=lists.denx.de@em2124.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type:cc:content-type:from:subject:to; s=s1; bh=YiA8kjy8TlGETXJvK97vidwLAEYW7Yx6EVk3UU6a+Vo=; b=Ebwi1cE6VS8CTl/r4GhKeVhmD6Y5ucOYWLNCP7BlcNtn20J4nZDpYB0FaYczjJUQ/xf3 6JklaGWT8RSP2VLYlPkheM7ehK+M12hlU8mpy6TDBpWyCvmLOJarzjD54M3abZqwJhZr82 guPrxKrKQz4TbXGiLeEZW1sOLr/SF5YbcbMedPjera3ziSsRE4YToMvMVXveSej8e0eamT tTAsIA1kSNMeIHxrEOpn43wnbZcEhYvfs6WT0xFgr085ieNGZXcSYA1hej7YclZK/VEGLd 8jD5wEq9B/g636yZQJZGeeGKnylT8JLOnV96VOsPE5gWZzznerBmR1XDF4Btzt8A== Received: by filterdrecv-66949dbc98-2wdbb with SMTP id filterdrecv-66949dbc98-2wdbb-1-64CAAE61-4 2023-08-02 19:28:33.181801167 +0000 UTC m=+7242520.469049571 Received: from bionic.localdomain (unknown) by geopod-ismtpd-6 (SG) with ESMTP id 4QKdkmU1TgyKTZv-6YctBA for ; Wed, 02 Aug 2023 19:28:33.010 +0000 (UTC) From: Jonas Karlman Subject: [PATCH v2 4/7] phy: rockchip: snps-pcie3: Add bifurcation support for RK3568 Date: Wed, 02 Aug 2023 19:28:33 +0000 (UTC) Message-ID: <20230802190424.2963185-5-jonas@kwiboo.se> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802190424.2963185-1-jonas@kwiboo.se> References: <20230802190424.2963185-1-jonas@kwiboo.se> MIME-Version: 1.0 X-SG-EID: =?us-ascii?Q?TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxA?= =?us-ascii?Q?fZekEeQsTe+RrMu3cja6a0h1MUCZ0w2X56xsqmY?= =?us-ascii?Q?MxZGlTQk73tpNvUycR0vncvGVYPs8BHtAGLQw0S?= =?us-ascii?Q?CI2beEXdZmy8LyBtul2Vra6To22Vgn6ElI060OW?= =?us-ascii?Q?n62rBiRVPLBW4XcpQEm+eWdMkG8=2Fhw7buo5rYIp?= =?us-ascii?Q?eVj16aLNte5nitXRUENQ=2FWzUEcX5T9i1t+JRcy?= To: Kever Yang , Simon Glass , Philipp Tomsich , Shawn Lin Cc: Eugen Hristev , Jon Lin , FUKAUMI Naoki , John Clark , u-boot@lists.denx.de, Jonas Karlman X-Entity-ID: P7KYpSJvGCELWjBME/J5tg== Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Configure aggregation or bifurcation mode on RK3568 based on the value of data-lanes property. Code imported almost 1:1 from mainline linux driver. Fixes: 6ec62b6ca698 ("phy: rockchip: Add Rockchip Synopsys PCIe 3.0 PHY") Signed-off-by: Jonas Karlman --- v2: - Add fixes tag .../phy/rockchip/phy-rockchip-snps-pcie3.c | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c b/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c index b76b5386bef0..642819b1f672 100644 --- a/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c +++ b/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c @@ -16,9 +16,16 @@ #include #include -#define GRF_PCIE30PHY_CON1 0x4 -#define GRF_PCIE30PHY_CON6 0x18 -#define GRF_PCIE30PHY_CON9 0x24 +/* Register for RK3568 */ +#define GRF_PCIE30PHY_CON1 0x4 +#define GRF_PCIE30PHY_CON6 0x18 +#define GRF_PCIE30PHY_CON9 0x24 +#define GRF_PCIE30PHY_DA_OCM (BIT(15) | BIT(31)) +#define GRF_PCIE30PHY_STATUS0 0x80 +#define GRF_PCIE30PHY_WR_EN (0xf << 16) +#define SRAM_INIT_DONE(reg) (reg & BIT(14)) + +#define RK3568_BIFURCATION_LANE_0_1 BIT(0) /** * struct rockchip_p3phy_priv - RK DW PCIe PHY state @@ -27,12 +34,16 @@ * @phy_grf: The regmap for controlling pipe signal * @p30phy: The reset signal for PHY * @clks: The clocks for PHY + * @num_lanes: The number of lane to controller mappings + * @lanes: The lane to controller mapping */ struct rockchip_p3phy_priv { void __iomem *mmio; struct regmap *phy_grf; struct reset_ctl p30phy; struct clk_bulk clks; + int num_lanes; + u32 lanes[4]; }; struct rockchip_p3phy_ops { @@ -42,15 +53,40 @@ struct rockchip_p3phy_ops { static int rockchip_p3phy_rk3568_init(struct phy *phy) { struct rockchip_p3phy_priv *priv = dev_get_priv(phy->dev); + bool bifurcation = false; + int ret; + u32 reg; /* Deassert PCIe PMA output clamp mode */ - regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON9, - (0x1 << 15) | (0x1 << 31)); + regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON9, GRF_PCIE30PHY_DA_OCM); + + for (int i = 0; i < priv->num_lanes; i++) { + if (priv->lanes[i] > 1) + bifurcation = true; + } + + /* Set bifurcation if needed, and it doesn't care RC/EP */ + if (bifurcation) { + regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON6, + GRF_PCIE30PHY_WR_EN | RK3568_BIFURCATION_LANE_0_1); + regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON1, + GRF_PCIE30PHY_DA_OCM); + } else { + regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON6, + GRF_PCIE30PHY_WR_EN & ~RK3568_BIFURCATION_LANE_0_1); + } reset_deassert(&priv->p30phy); udelay(1); - return 0; + ret = regmap_read_poll_timeout(priv->phy_grf, + GRF_PCIE30PHY_STATUS0, + reg, SRAM_INIT_DONE(reg), + 0, 500); + if (ret) + dev_err(phy->dev, "lock failed 0x%x\n", reg); + + return ret; } static const struct rockchip_p3phy_ops rk3568_ops = { @@ -103,6 +139,23 @@ static int rockchip_p3phy_probe(struct udevice *dev) return PTR_ERR(priv->phy_grf); } + ret = dev_read_size(dev, "data-lanes"); + if (ret > 0) { + priv->num_lanes = ret / sizeof(u32); + if (priv->num_lanes < 2 || + priv->num_lanes > ARRAY_SIZE(priv->lanes)) { + dev_err(dev, "unsupported data-lanes property size\n"); + return -EINVAL; + } + + ret = dev_read_u32_array(dev, "data-lanes", priv->lanes, + priv->num_lanes); + if (ret) { + dev_err(dev, "failed to read data-lanes property\n"); + return ret; + } + } + ret = reset_get_by_name(dev, "phy", &priv->p30phy); if (ret) { dev_err(dev, "no phy reset control specified\n"); -- 2.41.0