From patchwork Sat Jan 6 18:19:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 10147983 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 21D2D601BE for ; Sat, 6 Jan 2018 18:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0888026E97 for ; Sat, 6 Jan 2018 18:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0EAB28952; Sat, 6 Jan 2018 18:20:26 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D59E26E97 for ; Sat, 6 Jan 2018 18:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751136AbeAFSUW (ORCPT ); Sat, 6 Jan 2018 13:20:22 -0500 Received: from vern.gendns.com ([206.190.152.46]:60678 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750849AbeAFSUW (ORCPT ); Sat, 6 Jan 2018 13:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=VzpRg2iSbswX+XrDFd8//tWsx+d/q/8DO2jTuEv7LFA=; b=CSdNkskpNcrWYL7IHrGd7iW/j0 l4afA4Tn8Jd62PBoLHrMHqMnMxiiMoZDgsYAZjvO3D+jnzzz/4ZZUTnp8XtNaVa2wJT43nbyziV0H sKTpNbDSXnDNeqd7nTt+pnWGCiUrKtE6ujdFszJv9CrIj/2bpbCLFh3HVhjbuFIsEl34+yVPELxa3 KWL4p2jBL0xo+qGhXkvLwE59xSQ2zrA7Hf04Bf+K8TwFSztljZrxT7kXxIjG2+vgCqNavscja4eFM uwRHwhUOmZbhd+1xOCeBKpZyt9BRJ/9HTon421mkT3k6+SHbWkKzrkkJUu0MUpov3fw/sT+E4KxSp iGBOlwAg==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:52460 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89) (envelope-from ) id 1eXt4o-003MnC-Fa; Sat, 06 Jan 2018 13:20:14 -0500 From: David Lechner To: linux-clk@vger.kernel.org Cc: David Lechner , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH] clk: divider: fix clk_round_rate() when CLK_DIVIDER_READ_ONLY && CLK_RATE_SET_PARENT Date: Sat, 6 Jan 2018 12:19:29 -0600 Message-Id: <1515262769-22665-1-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP clk_round_rate() 'answers the question "if I were to pass @rate to clk_set_rate(), what clock rate would I end up with?" without changing the hardware'. Currently, clk_divider_round_rate() returns the "current value" when divider->flags & CLK_DIVIDER_READ_ONLY. But, if CLK_SET_RATE_PARENT is set, then clk_set_rate() is supposed to propagate the rate change to the parent clock. So, we need to do check for CLK_SET_RATE_PARENT and if it is set, ask the parent clock what rate it can provide given the current divider value. Signed-off-by: David Lechner --- drivers/clk/clk-divider.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 4ed516c..cffe9ef 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -357,6 +357,13 @@ static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, bestdiv &= div_mask(divider->width); bestdiv = _get_div(divider->table, bestdiv, divider->flags, divider->width); + + if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { + struct clk_hw *parent = clk_hw_get_parent(hw); + + *prate = clk_hw_round_rate(parent, rate * bestdiv); + } + return DIV_ROUND_UP_ULL((u64)*prate, bestdiv); }