From patchwork Fri Jan 5 17:09:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10146825 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 56E10601A1 for ; Fri, 5 Jan 2018 17:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392FE28537 for ; Fri, 5 Jan 2018 17:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DB4228779; Fri, 5 Jan 2018 17:11:41 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable 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 B12C228537 for ; Fri, 5 Jan 2018 17:11:40 +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=cmQ0m+NjbbMQAQbRxbYNa5bXGhJi3nSrOdWuU881A9w=; b=OQok9yea5OS/uCofqSVbllElFO bFZs3ZTShfoBLPoBCRvr05An1CY/bvFJPRXrU2ng8NPNR0KYxFAdIUdVsG8YRv/jIckyl5s4dolPu 2ZDz+s8qngGbxyAjeepK5Csrs3oaST94qOcdgIKaUSUUiiJPhdfbqg1hJE+FJmWYB2q44jSMhsE27 o8H4OQNk7xKb9p/vDvCJzazZm2zAlL7HmEFAPJKTMFRMhjTGTu1HgpefyY5Gw5hl+9XT2K+IUoNtI To2Xm+vUuTVWnzyfGCopJGIq7AllPAab9XxIoklQ/CMMe82jk18uzSE6//k7ThJjobp1br0R7/Oy3 26uDn1jg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eXVWo-0003nA-6v; Fri, 05 Jan 2018 17:11:34 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eXVVa-00020v-Kd for linux-arm-kernel@lists.infradead.org; Fri, 05 Jan 2018 17:10:22 +0000 Received: by mail-wr0-x242.google.com with SMTP id g17so4873059wrd.13 for ; Fri, 05 Jan 2018 09:10:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/cTPFCF2pDMJdLTGLBf43E+wpipcGpQZCgaWQCdcZg0=; b=xAqrcGoQ2QRv30DHA2zQY93h/BbZbV2ysBonedVw7qajTnRtZuutQnfVAKAeVEVDRp 10jKgX3W4EDcFTFD+DfXnVVgI+6FPsxV6KE02egft3/CRXMQ2CExoFOzwG3otoiC4FoG k6KT0CITXa8MkrFZZnYT+B041+cjb8DnT6RnDsnjPUE2bpwJSUGseJ8GhtiAk8j97tqC 7qfOfakhqWsHKFwNXzktA68+IfXjt2MmgwVRfCNCK1Chv5Ul6Ao4sWNT7yzYgAawQkG4 49v+XxCNMSbeG+E9oQkpVFvRt50pMpokaH2kPcDvwHQGoED1xOp9lgxyd7RJz0FjjRAr VBgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/cTPFCF2pDMJdLTGLBf43E+wpipcGpQZCgaWQCdcZg0=; b=XQMtD+Wx8iER0vELRtc/sb9uEVtexhwKYcYApoo6p2DaqE6nxmXk8WucUhKjs6a2Gx DSN/WSlG4tajOIXMVSVqAKZndYiyrv3Mzspq9ztysy4o5eDlLal0jTVrIXYAmk7gR/0J HKZON/Jeg2ujw+fK52wp77a3/2Pmm8oYBJIOIIbIo+RlmnvzS1uNQHpZf+P46T6JLf3J 6yalnCtOHLp8iP5MHS0Iv3UI0yTuorUFM+5Nml7P/YDUQZZkoyGtyjkWaQ6S1IKsm9O3 sWDblqJBGkVjxh2GXbDIbh4cKHg3Nh8Om0AIu2E0Gf6rQ17g7pLsF6XIX2sNjMYd6F/d vZrg== X-Gm-Message-State: AKGB3mIL66BMP0Cp71PjCB+k6fqVB58anhq2iITuyFdfOYPJeGL2eMZ4 bMpozOz3zfaOQPhCHjJJBqDZUw== X-Google-Smtp-Source: ACJfBouDM9H1lPTwdL2C9DtFrZcytp21AaAupe4U3Gd1ctEDq9anpoKfR/ywbqpYYUDrvIEsN+OoXQ== X-Received: by 10.223.166.242 with SMTP id t105mr3370771wrc.106.1515172206688; Fri, 05 Jan 2018 09:10:06 -0800 (PST) Received: from boomer.baylibre.local ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id g17sm3263661wra.6.2018.01.05.09.10.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jan 2018 09:10:06 -0800 (PST) From: Jerome Brunet To: Stephen Boyd , Michael Turquette , linux-clk@vger.kernel.org Subject: [PATCH 3/5] clk: divider: add divider_ro_round_rate helper Date: Fri, 5 Jan 2018 18:09:57 +0100 Message-Id: <20180105170959.17266-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180105170959.17266-1-jbrunet@baylibre.com> References: <20180105170959.17266-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180105_091018_859016_F9ABE9AB X-CRM114-Status: GOOD ( 11.77 ) 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: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Zapolskiy , David Brown , Sylvain Lemieux , Andy Gross , linux-arm-kernel@lists.infradead.org, Jerome Brunet 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 Like divider_round_rate, a couple a of driver are doing more or less the same operation to round the rate of the divider when it is read-only. We can factor this code so let's provide an helper function for this Signed-off-by: Jerome Brunet --- drivers/clk/clk-divider.c | 43 ++++++++++++++++++++++++++++--------------- include/linux/clk-provider.h | 15 +++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index a851d3e04c7f..3eb2b27f3513 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -344,29 +344,42 @@ long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, } EXPORT_SYMBOL_GPL(divider_round_rate_parent); +long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, + unsigned long rate, unsigned long *prate, + const struct clk_div_table *table, u8 width, + unsigned long flags, unsigned int val) +{ + int div; + + div = _get_div(table, val, flags, width); + + /* Even a read-only clock can propagate a rate change */ + if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { + if (!parent) + return -EINVAL; + + *prate = clk_hw_round_rate(parent, rate * div); + } + + return DIV_ROUND_UP_ULL((u64)*prate, div); +} +EXPORT_SYMBOL_GPL(divider_ro_round_rate_parent); + + static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct clk_divider *divider = to_clk_divider(hw); - struct clk_hw *hw_parent = clk_hw_get_parent(hw); - int bestdiv; + u32 val; /* if read only, just return current value */ if (divider->flags & CLK_DIVIDER_READ_ONLY) { - bestdiv = clk_readl(divider->reg) >> divider->shift; - bestdiv &= div_mask(divider->width); - bestdiv = _get_div(divider->table, bestdiv, divider->flags, - divider->width); - - /* Even a read-only clock can propagate a rate change */ - if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { - if (!hw_parent) - return -EINVAL; - - *prate = clk_hw_round_rate(hw_parent, rate * bestdiv); - } + val = clk_readl(divider->reg) >> divider->shift; + val &= div_mask(divider->width); - return DIV_ROUND_UP_ULL((u64)*prate, bestdiv); + return divider_ro_round_rate(hw, rate, prate, divider->table, + divider->width, divider->flags, + val); } return divider_round_rate(hw, rate, prate, divider->table, diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 175a62a15619..eb2c3a035e98 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -417,6 +417,10 @@ long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, unsigned long rate, unsigned long *prate, const struct clk_div_table *table, u8 width, unsigned long flags); +long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, + unsigned long rate, unsigned long *prate, + const struct clk_div_table *table, u8 width, + unsigned long flags, unsigned int val); int divider_get_val(unsigned long rate, unsigned long parent_rate, const struct clk_div_table *table, u8 width, unsigned long flags); @@ -772,6 +776,17 @@ static inline long divider_round_rate(struct clk_hw *hw, unsigned long rate, rate, prate, table, width, flags); } +static inline long divider_ro_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate, + const struct clk_div_table *table, + u8 width, unsigned long flags, + unsigned int val) +{ + return divider_ro_round_rate_parent(hw, clk_hw_get_parent(hw), + rate, prate, table, width, flags, + val); +} + /* * FIXME clock api without lock protection */