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: 123553 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1058256qgn; Fri, 5 Jan 2018 09:10:29 -0800 (PST) X-Google-Smtp-Source: ACJfBosBWWALUC0HuCxg1GWwLNAQNqFeu+JJRzrj9ktNao3SbXIS5BE6m6eoCYfn0w3HHrm5kqmc X-Received: by 10.159.214.136 with SMTP id n8mr3707144plp.177.1515172229325; Fri, 05 Jan 2018 09:10:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515172229; cv=none; d=google.com; s=arc-20160816; b=N4rnHqlPB55/0UlJ8tM7puNhNUKJojFuugx04od8HSb+/poOtpXtQE1jgiWYaEzdD+ Njbj8HZFWGir+jBi1Lq5IpJjNlliEuQWt8E+QSFzcq+ZT9F3NoUVCf5cXhW/zPRiZ56B 5XLDnV+cFfbDbAQPmvPYsx8txqgh1IsHW74F0Xx81qEf1AfeBSpz/v/RviIs9MkVQ5hs lE/siw2H5kmklT8PGv/l6tELaNSnpOn5y4IGI9bUng+LLTJELw8X2Qe5VvUfvHFnP9u1 JV/Z4STE+0eoLHJgyn8evzT2BvomHtigvx4RuuJEUn0SoBGO4YGE/nZUyFymmmE5lE6n FZeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=oT5XnXkU5wpCx94LEAc83EIDdFz32DQyoKBYgJ+3Lq8=; b=qfb//4DmDiah6ehp5XCQnId17UEMQ/B2sEth0IzVOfF+nAlhMYIFt1aW9seHN1z05D WO/Ct84pW7+fApGJ7WLBXjiojK4qd8TZ+RKi6j9qU2ql1uEAIZkaZiaR71HZo9JHPbun wHb8o5qLTOE0vUw31LX5J4wRxH3fmI6a8VJ71sdNx/DfRTnYEBy9oHlwy3ohZBs/zhzS CY913xUlgNi1mADhKuDDw7z8WZgsQkfcVgkJ63vINdG+A9pkX8APRObUXTelD0w0tLQm rsdWOakNpIXRbU5N+Rscei6n0TTbvuHlUJ/MvzdEU48UCxXHM0QGJZWhSQqL9Rr+joXx bmhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=xAqrcGoQ; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si4213934plh.477.2018.01.05.09.10.29; Fri, 05 Jan 2018 09:10:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=xAqrcGoQ; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752479AbeAERK2 (ORCPT + 10 others); 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-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 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(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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 */