From patchwork Wed Feb 14 13:43:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10218927 X-Patchwork-Delegate: mturquette@baylibre.com 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 94EA0601D7 for ; Wed, 14 Feb 2018 13:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8233028517 for ; Wed, 14 Feb 2018 13:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76DDE28787; Wed, 14 Feb 2018 13:47:36 +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=unavailable 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 EBAF228517 for ; Wed, 14 Feb 2018 13:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030429AbeBNNoW (ORCPT ); Wed, 14 Feb 2018 08:44:22 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43686 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030397AbeBNNnx (ORCPT ); Wed, 14 Feb 2018 08:43:53 -0500 Received: by mail-wr0-f193.google.com with SMTP id b52so22171401wrd.10 for ; Wed, 14 Feb 2018 05:43:53 -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=xpoPJpSjmefP/eaP3ikiVrqO/x/qS2dsetdWYBOL7/A=; b=Woyjf2hyrBLeryTnWdKQH1XPJNksSZtGntWrSwKEbI4oplGxntR9R/6iSAz1z6rcEH eQPtpWRE05libxYLfRqrqE5oSyOF44dQasmD9agj9JSux/cONYnbuBZIr9kv+z+Gnn71 UYt25cOENH6xn8on3ZCUHOEdmBasrKunZ93z0MeqW1yknZiuhjRiFtSPOshHcSTSziHv bz2bs/qtMv+leTrgBaM454iJD46qPkuLJXvtghXhqJfRra2dUGsIk1ObydLfTnRXSs21 qbQgPOlRAtr/HQubh8Fmw30sSRPOMABXNtf/mC6WseqJlzjR3pgeJd6BB9TolV7I35mO 49KA== 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=xpoPJpSjmefP/eaP3ikiVrqO/x/qS2dsetdWYBOL7/A=; b=fGeOiRXZb6BTeQfG1XqKNAku/a/EzhvtoRUIH8mWSb8LdqtZoNk+v6fHTzOkGQ+DGu Zu6kDPi9DSAc1O3UJNFZ1glZ1foPM29e7Ij01oEDvFXiHwPz4A5GyGOshcX6rdF3CpMx o3GurTaJUHGuBG2nZAQneBO9b7XZPRatzS9X+4hV1MXdJ25kZGOantBBUrnX2kP9Q+ZO +uRNT1Go9M8UOLjUwzQiROFou8O45/CaI8AZRhcHhk4OexKKPXH+kIMSLDi9ry3E9YaR QyU49SC0ara1QDIFIL62OE50KvZIlwap+Ec7RUoFlprc/9p8P3x8D7pGiV44YUieB0pT zL6g== X-Gm-Message-State: APf1xPDHQQsr8J5rFnbq+zbEPq7n7GQE5ZFOISBrgn5iogeYrM++7fIn i77nu3bE8g/70ErVfqfNqsDMUw== X-Google-Smtp-Source: AH8x226Dtf302JI6m3Mf9BwXZ1Nz/M8BuackjqNllgGeQxCC3xBv5fjLAqFKl6UxYUPkcyKtSFdHxw== X-Received: by 10.223.159.77 with SMTP id f13mr4521216wrg.196.1518615832402; Wed, 14 Feb 2018 05:43:52 -0800 (PST) Received: from boomer.lan (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id k5sm6337694wmg.47.2018.02.14.05.43.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2018 05:43:51 -0800 (PST) From: Jerome Brunet To: Michael Turquette , Stephen Boyd Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/8] clk: divider: read-only divider can propagate rate change Date: Wed, 14 Feb 2018 14:43:39 +0100 Message-Id: <20180214134340.17242-8-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180214134340.17242-1-jbrunet@baylibre.com> References: <20180214134340.17242-1-jbrunet@baylibre.com> 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 When a divider clock has CLK_DIVIDER_READ_ONLY set, it means that the register shall be left un-touched, but it does not mean the clock should stop rate propagation if CLK_SET_RATE_PARENT is set This is properly handled in qcom clk-regmap-divider but it was not in the generic divider To fix this situation, introduce a new helper function divider_ro_round_rate, on the same model as divider_round_rate. Fixes: e6d5e7d90be9 ("clk-divider: Fix READ_ONLY when divider > 1") Signed-off-by: Jerome Brunet Tested-By: David Lechner --- drivers/clk/clk-divider.c | 36 ++++++++++++++++++++++++++++++------ include/linux/clk-provider.h | 15 +++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 3c98d2650fa3..b6234a5da12d 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -342,19 +342,43 @@ 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); - int bestdiv; /* if read only, just return current value */ if (divider->flags & CLK_DIVIDER_READ_ONLY) { - bestdiv = clk_readl(divider->reg) >> divider->shift; - bestdiv &= clk_div_mask(divider->width); - bestdiv = _get_div(divider->table, bestdiv, divider->flags, - divider->width); - return DIV_ROUND_UP_ULL((u64)*prate, bestdiv); + u32 val; + + val = clk_readl(divider->reg) >> divider->shift; + val &= clk_div_mask(divider->width); + + 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 cb18526d69cb..210a890008f9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -420,6 +420,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); @@ -780,6 +784,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 */