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 E4798C4332F for ; Wed, 14 Dec 2022 04:57:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 071BF84F27; Wed, 14 Dec 2022 05:57:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="sEp9NJ7t"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="U1z5Xo23"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A6C5D80EB7; Wed, 14 Dec 2022 05:57:14 +0100 (CET) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9455184F27 for ; Wed, 14 Dec 2022 05:57:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 9DC2D5C01A2; Tue, 13 Dec 2022 23:57:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 13 Dec 2022 23:57:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1670993826; x= 1671080226; bh=kTanejfbpH8psPbkxt4gLelCoHegq/CV8kZISsjuAMM=; b=s Ep9NJ7tj1q1HgoulRMZARwJb3mx+/IjZf5hmGZun4WhmjqiWaj5wyjGogfvh3Pq1 Awvdv94r0LGpxqWvkuEL+UACpindLWQmomzn0favnoXVvo9T89w4SadgHhDuit+P h3Ki6ZjYUqrIKmq9TJWlxSXQQamLLU/ounpYaUVOvEaLbEkhm76c6xZg7M/8gDce wYicnQhbh2+OSOsedzKN6GtwiO7kP5Tb6yeHu7K7vxlUDledFTebvHJpcUamUJ9c kn4sgjB/PYjfq1jQnxZgJ37u+8kCcf6a1g1EvVZ/labsp2Oj2HlvwNEEAbXZr1Sr cSYUMyi7gXgTbAtt55QaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1670993826; x= 1671080226; bh=kTanejfbpH8psPbkxt4gLelCoHegq/CV8kZISsjuAMM=; b=U 1z5Xo239fYFFkhZ9S90CzG1LxZ7SmMOOVy//e1MikT0Gr+VXVgxl43NqIimT/Q8p zSV3c2ItCw+fPjt+Ot7HAcCca2vEiDGWzbKbLkqzG7aHH6hIsmAfJ9gCV5m6ucOd LrsIC/9jDnuh4vkGIugLf82fKJKquPEQIVpfSZ8NUwp47xdNKJvksYvhqM9zH/yy 5svcPfgYOgzBJG+RBCIadlYAf1Ti9RX3p9xAWCWVXI1lWjgzuMU6i40vBaVycQE2 cZ83iyRh8T23tx0ymgMYJJFYjj2zdMA6WMQ4wxAjIg7LSH8lp3oyJkIhh7bdSuRV 7lBGBsnDS1ZxN5/j1lHEw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedvgdejhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfvvehfhffujggtgfesthejredttdefjeenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepheettdefgeeuudelvdffleejheejueeludduiedvkeffgeetueev vdelvdetfeejnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghmuhgvlhesshhhohhllhgr nhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Dec 2022 23:57:05 -0500 (EST) Message-ID: <7985e774-e207-83a2-d8d2-b30df682ac75@sholland.org> Date: Tue, 13 Dec 2022 22:57:05 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux ppc64le; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: Johan Jonker Cc: Simon Glass , u-boot@lists.denx.de, Tom Rini , =?UTF-8?Q?Pali_Roh=c3=a1r?= , Stefan Roese References: <20221213015009.9229-1-samuel@sholland.org> From: Samuel Holland Subject: Re: [PATCH v2] serial: ns16550: Enable clocks during probe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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.6 at phobos.denx.de X-Virus-Status: Clean Hi Johan, On 12/13/22 03:06, Johan Jonker wrote: > Hi Samuel, > > Could you provide an example and or details for which SoC type this is in mind? This is needed for Allwinner sunxi SoCs, which come out of the boot ROM with all clock gates disabled. Currently, the sunxi SPL board code enables a clock gate in clock_init_uart() based on the legacy console UART selection (CONFIG_CONS_INDEX). For new SoCs (e.g. D1), I am using SPL_DM, so now we rely on the DM serial driver to enable the clock gate. > For current Rockchip we don't need this. > Everything works out of the box and is not touched in the clock driver. > The setting is done with serial_rockchip.c > > Your clk_enable() function makes it a requirement for a enable ops function on all SoCs with > compatible "snps,dw-apb-uart" nodes. The patch enables clocks on a best-effort basis, and allows the serial device to continue probing even if an error occurs while getting or enabling a clock. So this patch may not be necessary on Rockchip platforms, but it should not hurt anything either. > The S clock is on position 0 and is set with "clock-frequency" property. > The P clock is on position 1 and is not touched. >> + ret = clk_get_by_index(dev, 0, &clk); > > This tries to enable the S clock instead of the P clock. With the phycore-rk3288 fix[1] applied, I plan to go back to v1 of the patch, which tries to enable all clocks. Presumably both clocks need to be running for the UART to work. So "enabling" them should be conceptually correct, even if no action is needed from U-Boot to accomplish that on Rockchip platforms. Regards, Samuel [1]: https://lore.kernel.org/u-boot/20221213103809.1407187-1-w.egorov@phytec.de/ > So NAK for now. > > Johan > > === > > From Linux clk-rk3188.c: > GATE(PCLK_UART2, "pclk_uart2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 2, GFLAGS), > > static struct rockchip_clk_branch common_uart2_fracmux __initdata = > MUX(SCLK_UART2, "sclk_uart2", mux_sclk_uart2_p, CLK_SET_RATE_PARENT, > RK2928_CLKSEL_CON(15), 8, 2, MFLAGS); > === > > From serial_rockchip.c: > > static int rockchip_serial_probe(struct udevice *dev) > { > #if CONFIG_IS_ENABLED(OF_PLATDATA) > struct rockchip_uart_plat *plat = dev_get_plat(dev); > > /* Create some new platform data for the standard driver */ > plat->plat.base = plat->dtplat.reg[0]; > plat->plat.reg_shift = plat->dtplat.reg_shift; > > //// > plat->plat.clock = plat->dtplat.clock_frequency; > //// > > plat->plat.fcr = UART_FCR_DEFVAL; > dev_set_plat(dev, &plat->plat); > > return ns16550_serial_probe(dev); > #else > return -ENODEV; > #endif > } > > === > > From clk_rk3066.c: > > static int rk3066_clk_enable(struct clk *clk) > { > struct rk3066_clk_priv *priv = dev_get_priv(clk->dev); > > switch (clk->id) { > case HCLK_NANDC0: > rk_clrreg(&priv->cru->cru_clkgate_con[5], BIT(9)); > break; > case HCLK_SDMMC: > rk_clrreg(&priv->cru->cru_clkgate_con[5], BIT(10)); > break; > case HCLK_SDIO: > rk_clrreg(&priv->cru->cru_clkgate_con[5], BIT(11)); > break; > } > > return 0; > } > static struct clk_ops rk3066_clk_ops = { > .disable = rk3066_clk_disable, > .enable = rk3066_clk_enable, > .get_rate = rk3066_clk_get_rate, > .set_rate = rk3066_clk_set_rate, > }; > > === > > For rk3xxx.dtsi: > > uart2: serial@20064000 { > compatible = "snps,dw-apb-uart"; > reg = <0x20064000 0x400>; > interrupts = ; > reg-shift = <2>; > reg-io-width = <1>; > clock-names = "baudclk", "apb_pclk"; > clocks = <&cru SCLK_UART2>, <&cru PCLK_UART2>; > status = "disabled"; > }; > > On 12/13/22 02:50, Samuel Holland wrote: >> If the UART bus clock has a gate, it must be enabled before the UART >> can be used. >> >> Signed-off-by: Samuel Holland >> --- >> >> Changes in v2: >> - Only enable the first clock, as using the clk_get_bulk() API pushes >> a board (phycore-rk3288) over its SPL size limit. >> >> drivers/serial/ns16550.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c >> index 7592979cab5..072419343a3 100644 >> --- a/drivers/serial/ns16550.c >> +++ b/drivers/serial/ns16550.c >> @@ -507,6 +507,7 @@ int ns16550_serial_probe(struct udevice *dev) >> struct ns16550 *const com_port = dev_get_priv(dev); >> struct reset_ctl_bulk reset_bulk; >> fdt_addr_t addr; >> + struct clk clk; >> int ret; >> >> /* >> @@ -524,6 +525,10 @@ int ns16550_serial_probe(struct udevice *dev) >> if (!ret) >> reset_deassert_bulk(&reset_bulk); >> >> + ret = clk_get_by_index(dev, 0, &clk); >> + if (!ret) >> + clk_enable(&clk); >> + >> com_port->plat = dev_get_plat(dev); >> ns16550_init(com_port, -1); >>