Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13637286pxu; Sun, 3 Jan 2021 23:31:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQ1QE/yPxrbb4UVeyvFnMixqklbgvUD5nK4t+NjPKytFRyl8UGT9RRjwJ8vqzRtUZjN7ue X-Received: by 2002:a17:907:20cc:: with SMTP id qq12mr68699636ejb.316.1609745508508; Sun, 03 Jan 2021 23:31:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609745508; cv=none; d=google.com; s=arc-20160816; b=Hjcpa6Yh7mIJC1rKMzcVt+JtLhmQ28NzoIY3dOH7GQX4a+XSYBKqjHVV+jxiHZ32Nr gSLxDKerNCgDnm6OWGC7cpsAwAjLsPSD4ZEidee9evHz3TZrqmCgbBXf5gelspxCBLtr uHir2x+VW8I8NiI2epO6bc6m5zCzOjj54lF8/6TsemIKMPrsPO2NBEKrqVJDi/gfBA+a BSfYzzD4fceTlQhcG6qGlN+UvKgubNGbciWDhC+xOkH5aGxnsZcZBkScA1JDEXo7PK4o 6zuzQYTJbYB7hMg7PYwMpCxtZf9PfMaO7AgHHSkvJAwBdGObgNYDY+6IJsM0OD9nBv6Q UnFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ytuhBxBxzI0LnodRnLzLjlBGY2QmkWap0NLzWIO3xGw=; b=zcXw874+93fRk9J+Tsi/6BvjvvxE1i2RJg/7mCN2WCtiBuuhFnt07c0a4Jb6EmerkK tDOB3ozyMhLTLAQ2P5zbjzOcBRwg0KsEKJYUpXdcNmS/hWeC0qTy9V76JTH9uDTcnHGw 4iVe0iEbn+6JIRao6/PTG7HjwL54WhW3stxIxKCXC+DPEcDMDwMqqcnn7wcYuIUoXrsv TZjJ3fVSwTpHoKAu2qOk4GCE2UPvqRT6nMQ497ELAgmA0ADFfcV9kDzay35uKQxcT46b gTC33uCEIscFRLHglaWb1KRG+pd1SLGW+vudW6dXSlF5wv0KjsvXmp24iuum4K468LMB EnOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e21si30401729edv.260.2021.01.03.23.31.24; Sun, 03 Jan 2021 23:31:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbhADHMv (ORCPT + 99 others); Mon, 4 Jan 2021 02:12:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725616AbhADHMu (ORCPT ); Mon, 4 Jan 2021 02:12:50 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BFC5C061574 for ; Sun, 3 Jan 2021 23:12:10 -0800 (PST) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwK1x-00044f-Iy; Mon, 04 Jan 2021 08:11:53 +0100 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1kwK1w-0000k2-1v; Mon, 04 Jan 2021 08:11:52 +0100 Date: Mon, 4 Jan 2021 08:11:52 +0100 From: Sascha Hauer To: Adam Ford Cc: linux-arm-kernel@lists.infradead.org, Fugang Duan , Michael Turquette , Stephen Boyd , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Linus Walleij , Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] clk: imx: enable the earlycon uart clocks by parsing from dt Message-ID: <20210104071152.GA19063@pengutronix.de> References: <20201229145130.2680442-1-aford173@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201229145130.2680442-1-aford173@gmail.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 07:55:54 up 32 days, 19:22, 49 users, load average: 0.13, 0.08, 0.10 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Adam, On Tue, Dec 29, 2020 at 08:51:28AM -0600, Adam Ford wrote: > Remove the earlycon uart clocks that are hard cord in platforms > clock driver, instead of parsing the earlycon uart port from dt "instead parse the earlycon uart..." Otherwise it's confusing what you mean here. > and enable these clocks from clock property in dt node. > > Fixes: 9461f7b33d11c ("clk: fix CLK_SET_RATE_GATE with clock rate protection") > Signed-off-by: Fugang Duan > Signed-off-by: Adam Ford > --- > Based on NXP's code base and adapted for 5.11-rc1. > https://source.codeaurora.org/external/imx/linux-imx/commit/drivers/clk/imx/clk.c?h=imx_5.4.47_2.2.0&id=754ae82cc55b7445545fc2f092a70e0f490e9c1b > > The original signed-off was retained. > Added the fixes tag. > --- > drivers/clk/imx/clk.c | 43 +++++++++++++++++++++++++++++-------------- > 1 file changed, 29 insertions(+), 14 deletions(-) > > diff --git a/drivers/clk/imx/clk.c b/drivers/clk/imx/clk.c > index 47882c51cb85..c32b46890945 100644 > --- a/drivers/clk/imx/clk.c > +++ b/drivers/clk/imx/clk.c > @@ -148,7 +148,7 @@ void imx_cscmr1_fixup(u32 *val) > > #ifndef MODULE > static int imx_keep_uart_clocks; > -static struct clk ** const *imx_uart_clocks; > +static bool imx_uart_clks_on; > > static int __init imx_keep_uart_clocks_param(char *str) > { > @@ -161,25 +161,40 @@ __setup_param("earlycon", imx_keep_uart_earlycon, > __setup_param("earlyprintk", imx_keep_uart_earlyprintk, > imx_keep_uart_clocks_param, 0); > > -void imx_register_uart_clocks(struct clk ** const clks[]) > +static void imx_earlycon_uart_clks_onoff(bool is_on) "is_on" sounds like it's the current state of the clock, but actually the variable is used for the desired state, so I suggest using plain "on" as name. > { > - if (imx_keep_uart_clocks) { > - int i; > + struct clk *uart_clk; > + int i = 0; > > - imx_uart_clocks = clks; > - for (i = 0; imx_uart_clocks[i]; i++) > - clk_prepare_enable(*imx_uart_clocks[i]); > - } > + if (!imx_keep_uart_clocks || (!is_on && !imx_uart_clks_on)) > + return; > + > + /* only support dt */ > + if (!of_stdout) > + return; > + > + do { > + uart_clk = of_clk_get(of_stdout, i++); of_clk_get() allocates memory and gets you a reference to the clock. You have to release the clock with clk_put(). I think what you have to do here is to fill an array with clks when called from imx_register_uart_clocks() and when called from imx_clk_disable_uart() use that array to clk_disable_unprepare()/clk_put() the clocks. Sascha > + if (IS_ERR(uart_clk)) > + break; > + > + if (is_on) > + clk_prepare_enable(uart_clk); > + else > + clk_disable_unprepare(uart_clk); > + } while (true); > + > + if (is_on) > + imx_uart_clks_on = true; > +} > +void imx_register_uart_clocks(struct clk ** const clks[]) > +{ > + imx_earlycon_uart_clks_onoff(true); > } > > static int __init imx_clk_disable_uart(void) > { > - if (imx_keep_uart_clocks && imx_uart_clocks) { > - int i; > - > - for (i = 0; imx_uart_clocks[i]; i++) > - clk_disable_unprepare(*imx_uart_clocks[i]); > - } > + imx_earlycon_uart_clks_onoff(false); > > return 0; > } > -- > 2.25.1 > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |