From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.141 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796057018; b=sC5vILJqu1Xc85RfKWo+wB1Pt2zNaY0CG+RXLjruCjeGMfN3N2fjcM0UZUe8NAP3k7t1 6IgNsgMSWmYoWVq5DU91nOMhxZ4UOkxc2qmIElVvkR81Q191hb/RMpouaHu56R2YFOm+7 26TCxfqqNgZYvYoW3WMAHisWjr0Ac1J/Dtt4g57dTa6Ss+f4C+6+K3G1l3asCNUXpt3op p5UWHN3jp0OZHT7rIXPkNQcXbfOeMhr+pS+w8Sen269JHzimSSGW5cq0CuV3ZmxyEFhoi lPQE10bptoAc85V5ZyH/jdkkW2qZYAH/vy9eGf4RUPZRTjZKRaYU1933dU54wAvrMxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796057018; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:X-ThreadId:Date:From:To:Cc:Message-Id:In-Reply-To: References:Subject:Content-Type:Content-Transfer-Encoding; bh=UdfhZZ1iK+FJnk/FIjb2gKqdnT6ENwH2de4Kr74R0SY=; b=M3Gk/QklWPNA1loOIAN0lysQA8XpIp0TXmqH2Q91zMhNrviCvX9yoegyR3KcSLHHkY0b 72C5TP7i7AUapRNZn5RY/qQlZhxkHwsRKBOt0FTzIvvhkGHpdvBSoQeQey3GGoxLjBO26 VjHzGoByrlmnUdog6oitAJwyj4BXsPKEIdGwcdmL+a6tgRMCspiDrw7XSHjmFMgYrNA6u Noi+XRyDcIs0CHwc5/YneodmAVj9Q+GYV0FSY8Au766BqpIVmgGxECj4UKA28J7wFDiId jr7dC3Yn41T2O1PpM1xw4GlQ9k4SB5wxx3WXp/jKKhtj0fAAczQbxWZKsjlGY463hEA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=glider.be; spf=pass smtp.mailfrom=glider.be; dkim=pass header.d=glider.be header.i=@glider.be header.a=rsa-sha256 header.s=fm1 header.b=XfPP3IZi; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ZRUkqneI; arc=none smtp.remote-ip=103.168.172.141 Received: from flow-a6-smtp.messagingengine.com (flow-a6-smtp.messagingengine.com [103.168.172.141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88E79606A33D for ; Mon, 30 Nov 2026 16:43:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88E79606A33D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=glider.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=glider.be Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=glider.be header.i=@glider.be header.a=rsa-sha256 header.s=fm1 header.b=XfPP3IZi; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ZRUkqneI Received: from ams-compute-02.internal (ams-compute-02.internal [10.64.2.62]) by mailflow.phl.internal (Postfix) with ESMTP id 38621138058C for ; Mon, 30 Nov 2026 11:43:36 -0500 (EST) Received: from ams-imap-13 ([10.64.2.33]) by ams-compute-02.internal (MEProxy); Mon, 30 Nov 2026 11:43:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=glider.be; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1796057006; x=1796060606; bh=UdfhZZ1iK+FJnk/FIjb2gKqdnT6ENwH2de4Kr74R0SY=; b= XfPP3IZiRydCRZm95pVtzAZ7tHlIe29zzMQc6S35Kbadn4aaTinl53v5TA66IMIB 6dFchBEOKKgsE09Jku+xYT+1Xmj0yY8Zn7ZPzvqMmeIqex0xWU55rlfWXsb+TABT CLE9SewqWHfpfRkkPwXijEVvtVrdPoO2vh0FYBlT2GvqThkiNeYZWzdpXorkoesN sXw338aawy/CdnmxZvzUbvpNOpUXm4AvfpA6zTItNkbwkMyv6CjXcQ5NCSHAkoH7 RZ/6oUWhd33ibIddXGzfXK/hLyMaJ8dJ9eWTyTm681hhD9dknuuUC7hwds8q0898 OhFt/tDLpKPrfcOcOiL+tQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1796057006; x= 1796060606; bh=UdfhZZ1iK+FJnk/FIjb2gKqdnT6ENwH2de4Kr74R0SY=; b=Z RUkqneISPIXZgMswaYtfjA7l26ARxGsbM9ghawuXN0MUuRktU5/F6IaXMgRVeoXg OeLXMXdY7WYX98WEz/ZS1wh3JqYsdoG4IcDfyNDViFWu4h+of9JHS2aBTf8o6G6y P5IjvnfTlQ/h02e0EAXMwwFVtU87ncsoJWwqFIXwTQd6AvEqIOkWbj3u9NMxWQOJ oJdjo9slHqonLp2kUrDD6t7qkm4Pvq5zjdVoGPdw9gj62iboqe69YS7iwyLA/LAe KdL5gcyCcbw+E6PLy69SCxxGv9DTmDplvjM9x0AwcSjK6jZ52K6IjQESAE7Nw6gc BqvQmt+DV5EnUR5rk+4iA== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=glider.be a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796057006; d=glider.be; mf=PGdlZXJ0K3JlbmVzYXNAZ2xpZGVyLmJlPg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm1:rsa-sha256:eYMkfRjb8kH8kGkK4VPmSeAhwQ8nbaBAbpWcGs7taGCdpqO eltuBc22l4gw/xtw+9zkHLvPSSQ59AdIfvtyERC03uHxsZfv5i5vjd+mj8xOeMJ/ gTfpWbSfOCtmqiWQvW2SY83qqPkA+i/klr/7d3pXU4WVzpo8G3CqVf5AXA+70dHn 6JNjac7UFJ2vKvJMGLEvVRDy9vh0X2G+df07YgqVemjaqh+55ykWQ1SBx3/adNOW o8FL/reymEOGMlLFx+q0tcMuFVRsIGUUu6aa2UWg+dLJf+EAcGRRNK5vIU8DoAx9 q4mvpii2eFUDlxI8M9rB2Hsnajt7SQGOfjj7IFw==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-transfer-encoding,content-type,date,feedback-id, from,in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:vt0Hb7Mdo5bPEMBVP0ghAuzUW+qIEISG8cXdXFq1pdY=:j0sp/NF/5XdZ6jjdhzDa9MKOHjo6wQWMQtIKFfWxb3w=; X-ME-Sender: X-ME-Proxy-Cause: dmFkZTFXGs4yny/7HRfEVYQhijvOD5xSljnf1W+o68s+lQ917D+xdPzfw69gzN6WZTcg+l unUiR234xeQv8tDu5xFr3isCbJ7gUmPec3RtcdqFU+S6LFCqQTRTVLn6Rxis9Z2Y4to/MX Bnu5mo1ethlv1ThxRbZNQtQtjBn6QsCBMXPUPGPf0g6VmmQCbNyen74lygkGR5IKVeuGUJ wwywXsiDOTTxbl0DfeEf4JU6PFaOZwqTXNvYHn4eZKm6ns1BbgjcjmQbp3tZKeDzA3s2S5 g14cEWxUqejAGI1gSfsYFkTOqXteHCUa+quvQgC8z9cUGbJwClOQA+YO3VVDm4MNvxcaIm WoNI4BE9fXgg9SPXYRjQEiVyCxIfhEAhsnwkZU6JnMhqLl9I7HHY21swLerHy0G8hGOZ/C pnodF5AInac7lw0JeUrKOS9+L8IQPdsQYb4cuypXt3WxmwBIwZUFKYTt+UPtkRHEXg7081 5HdwI2wbZYz7IyzQ/8MM8UfuGPccMxhorFH68ywgM6FDKi+glylDktHueXR/6b4rBQCI4o GPdz8KoGBvJTFWnbQViaP2rgTTRop/H1XLrpwnBwNfRLS+kdWyuz/vtMuCbz2JhjPxXxiZ LcYAMbjdzzj0HdY8Gkyu1/6Pwx2qbaStekAqkckyQJCz0z95DiVPDQRiugbw X-ME-Proxy: Feedback-ID: ia0f84a9e:Fastmail Received: by mailuser.ams.internal (Postfix, from userid 501) id 34206F8009C; Mon, 30 Nov 2026 11:43:20 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-ThreadId: Ag0XD5FkW7ns Date: Mon, 30 Nov 2026 17:42:59 +0100 From: "Geert Uytterhoeven" To: "Marek Vasut" Cc: "Thanh Quan" , "Phong Hoang" , "Hai Pham" , "Yoshihiro Shimoda" , "Arnd Bergmann" , "Biju Das" , "Conor Dooley" , "Krzysztof Kozlowski" , "Magnus Damm" , "Manivannan Sadhasivam" , "Neil Armstrong" , "Rob Herring" , "Tam Nguyen" , "Tommaso Merciai" , "Vinh Nguyen" , "Vinod Koul" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org Message-Id: <8e77b7aa-b5cb-4e60-9a01-a37bd6791b22@app.fastmail.com> In-Reply-To: <20261129173739.282027-2-marek.vasut+renesas@mailbox.org> References: <20261129173739.282027-1-marek.vasut+renesas@mailbox.org> <20261129173739.282027-2-marek.vasut+renesas@mailbox.org> Subject: Re: [PATCH v2 2/3] phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi Marek, On Sun, Nov 29, 2026, at 18:37, Marek Vasut wrote: > From: Thanh Quan > > Add Renesas Multi-Protocol PHY driver for R-Car X5H (R8A78000) SoC. > > This is a multiplexing PHY block with inputs from five IPs, and outputs > to four separate IO blocks. The five inputs are two PCIe4, two USB 3.2, > and ethernet PCS, each connected into the PHY with up to 4 times 2 lanes. > The inputs can be multiplexed to the four IO blocks as needed. > > The datasheet describes initialization procedure without many information > about registers' name/bits. So, this driver does contain a bit of magic > to initialize the hardware. > > Signed-off-by: Thanh Quan > Co-developed-by: Phong Hoang > Signed-off-by: Phong Hoang > Co-developed-by: Hai Pham > Signed-off-by: Hai Pham > Co-developed-by: Yoshihiro Shimoda > Signed-off-by: Yoshihiro Shimoda > Co-developed-by: Marek Vasut > Signed-off-by: Marek Vasut Thanks for your patch! > --- /dev/null > +++ b/drivers/phy/renesas/phy-rcar-gen5-mpphy.c > @@ -0,0 +1,933 @@ > struct mp_phy_priv { > void __iomem *base; > struct device *dev; > struct dev_pm_domain_list *pd_list; > struct reset_control *reset_core; > struct reset_control_bulk_data reset_phy[MPPHY_NUM_CHANNELS]; > struct clk *clk_core; > struct clk_bulk_data *clk_phy; > int num_clks; > const struct firmware *fw; > struct regmap *map; > struct mp_phy_chan_priv chan[MPPHY_NUM_CHANNELS]; > u32 num_lanes[MPPHY_NUM_PCIE]; > u32 write_cntxt1; unsigned int? Although 4 bits is sufficient, u8? > u32 pcs0reg5_mask; > u32 cmncnt[2]; > u8 sramcnt[MPPHY_NUM_CHANNELS]; }; > +static void mp_phy_update_firmware(struct phy *phy) > +{ > + struct mp_phy_priv *priv = phy_get_drvdata(phy); > + int i; > + > + for (i = 0; i < priv->fw->size; i += 2) { unsigned int i = ... > + writew(priv->fw->data[i] | (priv->fw->data[i + 1] << 8), get_unaligned_le16()? > + priv->base + MPPHY_FW_BASE + (MPPHY_FW_CH_OFFSET * phy->id) + > i); > + } > +} > +static void mp_phy_init_pcie4_ch_req(struct mp_phy_priv *priv, const int chs, const int chd, unsigned int first, unsigned int last > + const u32 cntxt2, const u32 txreq) No need for all the consts > +{ > + int ch; > + > + for (ch = chs; ch <= chd; ch++) { unsigned int ch = ... Or perhaps drop ch and just increase first? > + regmap_set_bits(priv->map, MPPHY_PXCNTXT1(ch), 0x2010002); > + regmap_set_bits(priv->map, MPPHY_PXCNTXT2(ch), cntxt2); > + regmap_set_bits(priv->map, MPPHY_PXTXREQ(ch), txreq); > + } > +} > + > +static void mp_phy_init_pcie4_ch_clk(struct mp_phy_priv *priv, const int chs, const int chd) > +{ > + int ch; > + > + for (ch = chs; ch <= chd; ch++) { > + regmap_set_bits(priv->map, MPPHY_PXREFCLK(ch), 0x30); > + regmap_set_bits(priv->map, MPPHY_PXREFCLK(ch), 0x4); > + regmap_set_bits(priv->map, MPPHY_PXREFCLK(ch), 0x1); > + } Likewise > +} > + > +static void mp_phy_init_pcie4_ch_rst(struct mp_phy_priv *priv, const int chs, const int chd) > +{ > + int ch; > + > + for (ch = chs; ch <= chd; ch++) > + regmap_set_bits(priv->map, MPPHY_PXRXCNT(ch), MPPHY_PXRXCNT_RESET_VAL); > + > + for (ch = chs; ch <= chd; ch++) > + regmap_clear_bits(priv->map, MPPHY_PXRXCNT(ch), MPPHY_PXRXCNT_RESET_VAL); > +} Likewise (more or less) > + > +static int mp_phy_init_pcie4(struct phy *phy) > +{ > + struct mp_phy_priv *priv = phy_get_drvdata(phy); > + > + if (priv->num_lanes[phy->id] == 2) { switch ()? However, I am wondering if the below can be refactored / simplified. The loops seem to run from 0 to num_lanes / 2 - 1, with a.o. some special handling for the first iteration? > + if (phy->id == 0) { > + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x80004); > + mp_phy_init_pcie4_ch_clk(priv, 0, 0); > + mp_phy_init_pcie4_ch_rst(priv, 0, 0); > + } else if (phy->id == 1) { > + mp_phy_init_pcie4_ch_req(priv, 2, 2, 0x2020202, 0x8); > + mp_phy_init_pcie4_ch_clk(priv, 2, 2); > + mp_phy_init_pcie4_ch_rst(priv, 2, 2); > + } > + } else if (priv->num_lanes[phy->id] == 4) { > + if (phy->id == 0) { > + mp_phy_init_pcie4_ch_req(priv, 0, 1, 0x2020201, 0x80008); > + mp_phy_init_pcie4_ch_clk(priv, 0, 1); > + /* No reset pulse here. */ > + } else if (phy->id == 1) { > + mp_phy_init_pcie4_ch_req(priv, 2, 3, 0x2020202, 0x8); > + mp_phy_init_pcie4_ch_clk(priv, 2, 3); > + mp_phy_init_pcie4_ch_rst(priv, 2, 3); > + } > + } else if (priv->num_lanes[phy->id] == 8) { > + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x8); > + mp_phy_init_pcie4_ch_req(priv, 1, 3, 0x2020202, 0x8); > + /* No clk settings here. */ > + mp_phy_init_pcie4_ch_rst(priv, 0, 3); > + } > + > + return 0; > +} > +static int mp_phy_init(struct phy *phy) > +{ > + struct mp_phy_priv *priv = phy_get_drvdata(phy); > + struct mp_phy_chan_priv *chan = &priv->chan[phy->id]; > + int ret; > + > + if (chan->initialized) > + return 0; > + > + /* > + * Note: Current source code support for Ethernet, PCIe initialization > + * is based on the bare metal code shared by the board team. > + */ > + ret = pm_runtime_get_sync(priv->pd_list->pd_devs[phy->id]); > + if (ret < 0) { > + dev_err(priv->dev, > + "Failed to power on domain for channel %d: %d\n", > + phy->id, ret); %pe and ERR_PTR(ret)? > + return ret; > + } > + > + if (chan->protocol_id == PHY_MODE_PCIE) switch ()? > + ret = mp_phy_init_pcie4(phy); > + else if (chan->protocol_id == PHY_MODE_ETHERNET) > + ret = mp_phy_init_ethernet(phy); > + else > + ret = mp_phy_init_usb(phy); > + if (ret) > + goto err_init; > + > + chan->initialized = true; > + dev_dbg(priv->dev, > + "Channel %d successfully initialized for protocol %d\n", > + phy->id, chan->protocol_id); > + > + return 0; > + > +err_init: > + pm_runtime_put_sync(priv->pd_list->pd_devs[phy->id]); > + return ret; > +} > + > +static int mp_phy_read_poll_pcie4(struct phy *phy) > +{ > + struct mp_phy_priv *priv = phy_get_drvdata(phy); > + u32 rx_ack, tx_ack; > + > + if (priv->num_lanes[phy->id] == 2) { > + tx_ack = readl(priv->base + MPPHY_PXTXREQ(2 * phy->id)); > + rx_ack = readl(priv->base + MPPHY_PXRXREQ1(2 * phy->id)); > + } else if (priv->num_lanes[phy->id] == 4) { > + tx_ack = readl(priv->base + MPPHY_PXTXREQ(2 * phy->id)) & > + readl(priv->base + MPPHY_PXTXREQ((2 * phy->id) + 1)); > + rx_ack = readl(priv->base + MPPHY_PXRXREQ1(2 * phy->id)) & > + readl(priv->base + MPPHY_PXRXREQ1((2 * phy->id) + 1)); > + } else if (priv->num_lanes[phy->id] == 8) { > + tx_ack = readl(priv->base + MPPHY_PXTXREQ(0)) & > + readl(priv->base + MPPHY_PXTXREQ(1)) & > + readl(priv->base + MPPHY_PXTXREQ(2)) & > + readl(priv->base + MPPHY_PXTXREQ(3)); > + rx_ack = readl(priv->base + MPPHY_PXRXREQ1(0)) & > + readl(priv->base + MPPHY_PXRXREQ1(1)) & > + readl(priv->base + MPPHY_PXRXREQ1(2)) & > + readl(priv->base + MPPHY_PXRXREQ1(3)); > + } Again, some looping from 0 to num_lanes / 2 - 1? > + > + return !(tx_ack & BIT(9)) && !(rx_ack & BIT(1)); > +} > + > +static int mp_phy_power_on_pcie4(struct phy *phy) > +{ > + struct mp_phy_priv *priv = phy_get_drvdata(phy); > + int i, id, ret; > + u32 status; > + > + if (priv->num_lanes[phy->id] == 2 || priv->num_lanes[phy->id] == 4) { > + for (i = 0; i < priv->num_lanes[phy->id] / 2; i++) { unsigned int i = ... > + id = (2 * phy->id) + i; > + ret = mp_phy_update_firmware_sram(priv->chan[id].phy); > + if (ret) > + return ret; > + } > + > + for (i = 0; i < priv->num_lanes[phy->id] / 2; i++) { > + id = (2 * phy->id) + i; > + ret = mp_phy_reg_wait(priv, MPPHY_PXSRAMCNT(id), > + SRAM_INIT_DONE, SRAM_INIT_DONE); > + if (ret) > + return ret; > + } > + > + for (i = 0; i < priv->num_lanes[phy->id] / 2; i++) { > + id = (2 * phy->id) + i; > + ret = mp_phy_reg_wait(priv, MPPHY_PXRXREQ1(id), 0x2, 0); > + if (ret) > + return ret; > + } > + } else if (priv->num_lanes[phy->id] == 8) { > + for (i = 0; i < 4; i++) { > + ret = mp_phy_update_firmware_sram(priv->chan[phy->id].phy); > + if (ret) > + return ret; > + } > + > + for (i = 0; i < 4; i++) { > + ret = mp_phy_reg_wait(priv, MPPHY_PXSRAMCNT(i), > + SRAM_INIT_DONE, SRAM_INIT_DONE); > + if (ret) > + return ret; > + } > + > + for (i = 0; i < 4; i++) { > + ret = mp_phy_reg_wait(priv, MPPHY_PXRXREQ1(i), 0x2, 0); > + if (ret) > + return ret; > + } > + } isn't the code in the two branches doing the exact same thing? > + > + ret = read_poll_timeout(mp_phy_read_poll_pcie4, status, status, > + 20, 2000000, false, phy); > + if (ret) > + dev_err(priv->dev, "TX/RX ack timeout\n"); > + > + return ret; > +} > + > +static int mp_phy_power_on(struct phy *phy) > +{ > + struct mp_phy_priv *priv = phy_get_drvdata(phy); > + struct mp_phy_chan_priv *chan = &priv->chan[phy->id]; > + int ret; > + > + if (!chan->initialized) { > + dev_err(priv->dev, "Channel %d not initialized\n", phy->id); > + return -EINVAL; > + } > + > + /* > + * The datasheet describes initialization procedure without full > + * information about the registers. Therefore, the source code is > + * based on the bare metal code shared by the board team. > + */ > + if (chan->protocol_id == PHY_MODE_PCIE) { switch () > + ret = mp_phy_power_on_pcie4(phy); > + if (ret) > + return ret; > + } else if (chan->protocol_id == PHY_MODE_ETHERNET) { > + regmap_set_bits(priv->map, MPPHY_PXSRAMCNT(phy->id), SRAM_EXT_LD_DONE); > + ret = mp_phy_reg_wait(priv, MPPHY_PXRXREQ1(phy->id), 0x2, 0); > + if (ret) > + return ret; > + } else { /* USB */ > + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_PSTATE_1, 0x3, 0x3); > + if (ret) > + return ret; > + > + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_EN, 0x3); > + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_TCPC, TCA_TCPC_VALID); > + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1, 0x1); > + if (ret) > + return ret; > + > + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1503); > + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_TCPC, > + TCA_TCPC_VALID | > + FIELD_PREP(TCA_TCPC_MUX_CONTRL_USB_CONN, > + TCA_TCPC_MUX_CONTRL_USB_CONN)); > + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1, 0x1); > + if (ret) > + return ret; > + > + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1503); > + } > + > + return 0; > +} > +static int mp_phy_suspend(struct device *dev) > +{ > + struct mp_phy_priv *priv = dev_get_drvdata(dev); > + int i, ret; > + > + for (i = 0; i < MPPHY_NUM_CHANNELS; i++) unsigned int i = ... > + priv->chan[i].initialized = false; > + > + ret = reset_control_bulk_assert(ARRAY_SIZE(priv->reset_phy), > priv->reset_phy); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to assert PHY resets\n"); dev_err(), as dev_err_probe() changes the probe error state in sysfs (everywhere). > + > + clk_bulk_disable_unprepare(priv->num_clks, priv->clk_phy); > + > + return 0; > +} > +static int mp_phy_resume(struct device *dev) > +{ > + struct mp_phy_priv *priv = dev_get_drvdata(dev); > + int i, ret; > + > + ret = clk_bulk_prepare_enable(priv->num_clks, priv->clk_phy); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to enable PHY clocks\n"); > + > + ret = reset_control_bulk_reset(ARRAY_SIZE(priv->reset_phy), priv->reset_phy); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to deassert PHY resets\n"); > + > + /* Reload configuration */ > + regmap_set_bits(priv->map, MPPHY_CMNCNT1, priv->cmncnt[0]); > + regmap_write(priv->map, MPPHY_CMNCNT2, priv->cmncnt[1]); > + > + for (i = 0; i < MPPHY_NUM_CHANNELS; i++) { unsigned int i = ... > + regmap_set_bits(priv->map, MPPHY_PXTEST(i), MPPHY_PXTEST_BIT); > + regmap_write(priv->map, MPPHY_PXSRAMCNT(i), priv->sramcnt[i]); > + > + if (priv->write_cntxt1 & BIT(i)) { > + regmap_write(priv->map, MPPHY_CHAN_BASE(i) + 0x10c, 0xff0ff); > + regmap_write(priv->map, MPPHY_PXCNTXT1(i), 0x180023); > + } > + > + regmap_clear_bits(priv->map, MPPHY_PXTEST(i), MPPHY_PXTEST_BIT); > + } > + > + regmap_clear_bits(priv->map, MPPHY_PCS0REG1, MPPHY_PCS0REG1_VAL); > + /* > + * Release only the PCIe PHYs here. Ethernet PCS released while its > + * PHY is still not initialized blocks the PCIe40 rate change (link > + * stuck at Gen1). > + */ > + regmap_clear_bits(priv->map, MPPHY_PCS0REG5, priv->pcs0reg5_mask); > + > + return 0; > +} > + > +static struct phy *mp_phy_xlate(struct device *dev, > + const struct of_phandle_args *args) > +{ > + struct mp_phy_priv *priv = dev_get_drvdata(dev); > + int id; u32 > + > + if (args->args_count != 2) { > + dev_err(dev, "Invalid args_count: %d\n", args->args_count); > + return ERR_PTR(-EINVAL); > + } > + > + id = args->args[0]; > + > + if (id > MPPHY_NUM_CHANNELS) { > + dev_err(dev, "Invalid channel ID: %d\n", id); %u > + return ERR_PTR(-EINVAL); > + } > + > + return priv->chan[id].phy; > +} > + > +static int mp_phy_parse_dt(struct platform_device *pdev, struct mp_phy_priv *priv) > +{ > + u32 phy_type[2 * MPPHY_NUM_CHANNELS]; > + u32 ext_ref_clk[MPPHY_NUM_CHANNELS]; > + u32 out_ref_clk[MPPHY_NUM_CHANNELS]; > + struct device *dev = &pdev->dev; > + int i, ret; unsigned int i > + > + ret = device_property_read_u32_array(dev, "renesas,phy-type", phy_type, 8); > + if (ret < 0) > + return dev_err_probe(dev, -EINVAL, "Failed to read PHY configuration\n"); > + > + ret = device_property_read_u32_array(dev, "renesas,external-ref-clock", > + ext_ref_clk, 4); > + if (ret < 0) > + return dev_err_probe(dev, -EINVAL, "Failed to read PHY clock configuration\n"); > + > + ret = device_property_read_u32_array(dev, "renesas,output-repeat-ref-clock", > + out_ref_clk, 4); > + if (ret < 0) > + return dev_err_probe(dev, -EINVAL, "Failed to read PHY clock out configuration\n"); > + > + /* Test whether the supplied configuration is valid. */ > + for (i = 0; i < ARRAY_SIZE(mp_phy_valid_configs); i++) { > + if (phy_type[0] == mp_phy_valid_configs[i].phy_type[0] && > + phy_type[1] == mp_phy_valid_configs[i].phy_type[1] && > + phy_type[2] == mp_phy_valid_configs[i].phy_type[2] && > + phy_type[3] == mp_phy_valid_configs[i].phy_type[3] && > + phy_type[4] == mp_phy_valid_configs[i].phy_type[4] && > + phy_type[5] == mp_phy_valid_configs[i].phy_type[5] && > + phy_type[6] == mp_phy_valid_configs[i].phy_type[6] && > + phy_type[7] == mp_phy_valid_configs[i].phy_type[7]) memcmp() > + break; > + } > + > + if (i == ARRAY_SIZE(mp_phy_valid_configs)) > + return dev_err_probe(dev, -EINVAL, "Incorrect PHY configuration\n"); > + > + /* Infer PCIe lane count from renesas,phy-type DT property. */ > + priv->num_lanes[0] = mp_phy_valid_configs[i].num_lanes[0]; > + priv->num_lanes[1] = mp_phy_valid_configs[i].num_lanes[1]; > + > + priv->cmncnt[0] = 0; > + priv->cmncnt[1] = 0x33330000; /* All res_{ack,req}_in_sel are 1 */ > + > + for (i = 0; i < MPPHY_NUM_CHANNELS; i++) { > + priv->chan[i].initialized = false; > + priv->chan[i].protocol_id = PHY_MODE_INVALID; > + > + if (phy_type[2 * i] == PHY_TYPE_PCIE) { switch () > + priv->chan[i].protocol_id = PHY_MODE_PCIE; > + priv->sramcnt[i] = 0x3; > + priv->pcs0reg5_mask |= MPPHY_PCS0REG5_CH(i); > + if (phy_type[(2 * i) + 1] == 0) /* Channel 0 */ > + priv->cmncnt[0] |= 0x0 << (i * 8); > + else /* Channel 1 */ > + priv->cmncnt[0] |= 0x2 << (i * 8); > + } else if (phy_type[2 * i] == PHY_TYPE_XPCS) { > + priv->chan[i].protocol_id = PHY_MODE_ETHERNET; > + priv->sramcnt[i] = 0x0; > + priv->write_cntxt1 |= BIT(i); > + priv->cmncnt[0] |= 0x1 << (i * 8); > + } else if (phy_type[2 * i] == PHY_TYPE_USB3) { > + priv->chan[i].protocol_id = PHY_MODE_USB_OTG; > + priv->sramcnt[i] = 0x9; > + priv->cmncnt[0] |= 0x3 << (i * 8); > + } else { > + /* Cannot be reached. */ > + return -EINVAL; > + } > + > + if (ext_ref_clk[i]) > + priv->cmncnt[1] |= BIT(i * 4); > + > + if (out_ref_clk[i]) > + priv->cmncnt[1] |= BIT((i * 4) + 1); > + } > + > + return 0; > +} > +static int mp_phy_probe(struct platform_device *pdev) > +{ > + for (i = 0; i < MPPHY_NUM_CHANNELS; i++) { unsigned int i = ... > + priv->chan[i].phy = devm_phy_create(dev, NULL, &mp_phy_ops); > + if (IS_ERR(priv->chan[i].phy)) { > + return dev_err_probe(dev, PTR_ERR(priv->chan[i].phy), > + "Failed to create PHY %d\n", i); > + } > + > + priv->chan[i].phy->id = i; > + phy_set_drvdata(priv->chan[i].phy, priv); > + } > + > + ret = mp_phy_resume_early(dev); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to resume PHY\n"); > + > + ret = pm_runtime_get_sync(dev); > + if (ret) { > + dev_err_probe(dev, ret, "Failed to get runtime PM\n"); > + goto err_resume; > + } > + > + return 0; > + > +err_resume: > + mp_phy_suspend_late(dev); > + return ret; > +} > + > +static const struct dev_pm_ops mp_phy_pm_ops = { > + SET_RUNTIME_PM_OPS(mp_phy_suspend, mp_phy_resume, NULL) RUNTIME_PM_OPS() (which includes pm_sleep_ptr()) > + SET_LATE_SYSTEM_SLEEP_PM_OPS(mp_phy_suspend_late, mp_phy_resume_early) LATE_SYSTEM_SLEEP_PM_OPS() > +}; > + > +static const struct of_device_id mp_phy_of_match[] = { > + { .compatible = "renesas,rcar-gen5-mpphy" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(of, mp_phy_of_match); > + > +static struct platform_driver mp_phy_driver = { > + .probe = mp_phy_probe, > + .driver = { > + .name = "renesas-mpphy", > + .of_match_table = mp_phy_of_match, > + .pm = &mp_phy_pm_ops, pm_sleep_ptr() > + .probe_type = PROBE_PREFER_ASYNCHRONOUS, > + }, > +}; > + > +module_platform_driver(mp_phy_driver); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds