From patchwork Sun Jul 30 16:41:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 9870595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9AD0060353 for ; Sun, 30 Jul 2017 16:44:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 885F027F10 for ; Sun, 30 Jul 2017 16:44:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79DC62859F; Sun, 30 Jul 2017 16:44:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 066CA27F10 for ; Sun, 30 Jul 2017 16:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Kb86zpyBjYmDLBv1aHtuWscfdN2kpJUwIQqBHUvIXnA=; b=iSKTU4nFn041w2+C/rG4jxZHLk p2N+UTV+PWeJcTIe6XIHBTSQNb2KJai/X94xPJ2icxn4RqVKEsdGcGi0XX4DHrigzkQ5As4Q463yc M781NfdZ061syF0BhT5NmMnfigqQXHud8PtKdyGQpfBmWla/7AG0O8Lgeq0l3Y9qwu4r5LkLAsyj/ OYEhGic4CkaUDeaR6fLFY2Hzdx+h3S3wWGEsVeDjJl8RnDj0/XtiVuX8gwf/vnzcivnwED2A9r0Oj +gTF2VqmuWZoLW9eLPkhZHUWfLJ68HEEjFr6VuYddhWxBB1FqZMJkIRBqT4UaKSeF1eAdZKXMRB1s NVstTMEA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dbrJd-0002qA-3N; Sun, 30 Jul 2017 16:43:41 +0000 Received: from mailoutvs1.siol.net ([213.250.19.134] helo=mail.siol.net) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dbrIf-0002CO-6r for linux-arm-kernel@lists.infradead.org; Sun, 30 Jul 2017 16:42:44 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.siol.net (Postfix) with ESMTP id C19E4520A34; Sun, 30 Jul 2017 18:42:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at psrvmta11.zcs-production.pri Received: from mail.siol.net ([127.0.0.1]) by localhost (psrvmta11.zcs-production.pri [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id s3KT_93Bou0D; Sun, 30 Jul 2017 18:42:22 +0200 (CEST) Received: from mail.siol.net (localhost [127.0.0.1]) by mail.siol.net (Postfix) with ESMTPS id 3B20C520A37; Sun, 30 Jul 2017 18:42:22 +0200 (CEST) Received: from localhost.localdomain (cpe-86-58-68-135.ftth.triera.net [86.58.68.135]) (Authenticated sender: 031275009) by mail.siol.net (Postfix) with ESMTPSA id E11A3520A34; Sun, 30 Jul 2017 18:42:19 +0200 (CEST) From: Jernej Skrabec To: maxime.ripard@free-electrons.com Subject: [PATCH 4/4] clk: sunxi-ng: Wait for lock when using fractional mode Date: Sun, 30 Jul 2017 18:41:50 +0200 Message-Id: <20170730164150.26302-5-jernej.skrabec@siol.net> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170730164150.26302-1-jernej.skrabec@siol.net> References: <20170730164150.26302-1-jernej.skrabec@siol.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170730_094241_697304_18E6ACAA X-CRM114-Status: UNSURE ( 9.27 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mturquette@baylibre.com, linux-sunxi@googlegroups.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, wens@csie.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently ccu_frac_helper_set_rate() doesn't wait for a lock bit to be set before returning. Because of that, unstable clock may be used. Add a wait for lock in the helper function. Signed-off-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_frac.c | 4 +++- drivers/clk/sunxi-ng/ccu_frac.h | 2 +- drivers/clk/sunxi-ng/ccu_mult.c | 3 ++- drivers/clk/sunxi-ng/ccu_nm.c | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_frac.c b/drivers/clk/sunxi-ng/ccu_frac.c index ff9e72dc5337..d1d168d4c4f0 100644 --- a/drivers/clk/sunxi-ng/ccu_frac.c +++ b/drivers/clk/sunxi-ng/ccu_frac.c @@ -85,7 +85,7 @@ unsigned long ccu_frac_helper_read_rate(struct ccu_common *common, int ccu_frac_helper_set_rate(struct ccu_common *common, struct ccu_frac_internal *cf, - unsigned long rate) + unsigned long rate, u32 lock) { unsigned long flags; u32 reg, sel; @@ -106,5 +106,7 @@ int ccu_frac_helper_set_rate(struct ccu_common *common, writel(reg | sel, common->base + common->reg); spin_unlock_irqrestore(common->lock, flags); + ccu_helper_wait_for_lock(common, lock); + return 0; } diff --git a/drivers/clk/sunxi-ng/ccu_frac.h b/drivers/clk/sunxi-ng/ccu_frac.h index 7b1ee380156f..efe2dd6bac01 100644 --- a/drivers/clk/sunxi-ng/ccu_frac.h +++ b/drivers/clk/sunxi-ng/ccu_frac.h @@ -48,6 +48,6 @@ unsigned long ccu_frac_helper_read_rate(struct ccu_common *common, int ccu_frac_helper_set_rate(struct ccu_common *common, struct ccu_frac_internal *cf, - unsigned long rate); + unsigned long rate, u32 lock); #endif /* _CCU_FRAC_H_ */ diff --git a/drivers/clk/sunxi-ng/ccu_mult.c b/drivers/clk/sunxi-ng/ccu_mult.c index ee5e96222cb2..12e0783caee6 100644 --- a/drivers/clk/sunxi-ng/ccu_mult.c +++ b/drivers/clk/sunxi-ng/ccu_mult.c @@ -114,7 +114,8 @@ static int ccu_mult_set_rate(struct clk_hw *hw, unsigned long rate, if (ccu_frac_helper_has_rate(&cm->common, &cm->frac, rate)) { ccu_frac_helper_enable(&cm->common, &cm->frac); - return ccu_frac_helper_set_rate(&cm->common, &cm->frac, rate); + return ccu_frac_helper_set_rate(&cm->common, &cm->frac, + rate, cm->lock); } else { ccu_frac_helper_disable(&cm->common, &cm->frac); } diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c index c6ba866b99d3..a32158e8f2e3 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.c +++ b/drivers/clk/sunxi-ng/ccu_nm.c @@ -129,7 +129,8 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned long rate, ccu_frac_helper_enable(&nm->common, &nm->frac); - return ccu_frac_helper_set_rate(&nm->common, &nm->frac, rate); + return ccu_frac_helper_set_rate(&nm->common, &nm->frac, + rate, nm->lock); } else { ccu_frac_helper_disable(&nm->common, &nm->frac); }