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: 10146807 X-Patchwork-Delegate: agross@codeaurora.org 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 AA501601A1 for ; Fri, 5 Jan 2018 17:10:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EC672846F for ; Fri, 5 Jan 2018 17:10:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8348F286FF; Fri, 5 Jan 2018 17:10:29 +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 17F292846F for ; Fri, 5 Jan 2018 17:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752479AbeAERK2 (ORCPT ); Fri, 5 Jan 2018 12:10:28 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43839 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752393AbeAERKI (ORCPT ); Fri, 5 Jan 2018 12:10:08 -0500 Received: by mail-wr0-f193.google.com with SMTP id s13so2473375wra.10 for ; Fri, 05 Jan 2018 09:10:07 -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=Cz97887WCQ5Zl4vh3jbuzve3seG9ZFIvHft7GDilPi4nM/SQST8NF4cAGaWdAJQ9mx nMtT4LrNv4O2/05GyzWajxkM3Qt1Fg/PujNsGEhc5DvvH9mfzvyLpE5+Sav7YbAWHf37 GP9kti9xZwWNLC++kX1ZAw7WhXw/CjIj8ncAXsqh4g0mrJmsPoyKGG12AGuAbcjFZwQy ydKsq61uRB0EpL0Re4GhFBIe5CX5s0+BO/P5RYU0TOCfiMMc2IyG7w1V5GID5Ut4mGTs 4nYZ7AmXLbdZ1Dexah9oZHCPDT4wF0RCBYc2QyncpO+lGYI6hlctniMA2H4PRS4QFEsi A6Mg== X-Gm-Message-State: AKGB3mKdCMtU6Dxsehzkxk1zi907jg6MCRtU/bd9sCh+o0DINAxvdIId ReidzyqJDkMNe8hSuw/xFOgKEQ== 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 Cc: Jerome Brunet , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Vladimir Zapolskiy , Sylvain Lemieux , Andy Gross , David Brown 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> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 */