From patchwork Wed Feb 14 13:43:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10218941 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 E11F4601D7 for ; Wed, 14 Feb 2018 13:48:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFA5928517 for ; Wed, 14 Feb 2018 13:48:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C44492896D; Wed, 14 Feb 2018 13:48: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 8A55F2869D for ; Wed, 14 Feb 2018 13:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030301AbeBNNsW (ORCPT ); Wed, 14 Feb 2018 08:48:22 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33664 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030251AbeBNNnq (ORCPT ); Wed, 14 Feb 2018 08:43:46 -0500 Received: by mail-wm0-f68.google.com with SMTP id x4so17838725wmc.0 for ; Wed, 14 Feb 2018 05:43:46 -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=blC1VwQdaVr/4deMW4rI29x2chj1BXiX6xYvvmEtHUE=; b=ccuTV43N1uHwEljJrKQsIhAHLSmNps7qtCBGDavW3F9eQOw93v09G3qwj7BJnZMaAZ IDvYaK+BfT1TNCtPEW437OZdjS17TrixfYH+0ZKV0PDyLqwyhP25TkAQfkkrDWtSddOJ KjEXpMM8tbN58wzMJZZeKUOBWpM6TOjG0x14fONEGPHSX9bnfPj9qbwooxQN27y1LTsr 4UwRpmQY1JfZD+L7HK17rXzoGye7Yi7aHUtXD0EyOx8u6JDhWXV/VTQGI/bXvT+pERsq KpXHOrueOp+y2/X1aBsIRzUuId0G+tt1Z59rmMBFMFXuzY9gEeGinAOY90gYxfQ9+EmC F6Hg== 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=blC1VwQdaVr/4deMW4rI29x2chj1BXiX6xYvvmEtHUE=; b=iwA86CYq9xwFvbCZO+J9hyF8cSzUVZynvPlpArVHDxUkUEv6BwEYuF9gwb5yMOzRvK /6Oup8LzZxA1y5FLyLYiJvY1beAVd1QSYXaNau3u0ySEGEfaw0g6KlRTAWmrjQ3wV5LR 32CceoqpQAqroKkGeyA4yNY1o1vrIFtV/q6HLBLfixhM392zI2Z0RHYabBfd5T1dBoHq pcRiRfGBr7xsjcaJRyEEUfAod9eRrOtkAVDKSTGdKhBaGcNn8/BrwT4SJm8s7sHXgN/N 72PqA7GQSJlh8eDFWfMrlZM9Y5xzGQVUsdxOo0QjoFnWZMqC7OkXqC+pxABB4fP3t4Sl iQjg== X-Gm-Message-State: APf1xPC/z13tJ5tjHvLlh+AJCljqyDwPLrf8lws2fmJiYORqCOtOpNNY x3J2jTToyPWvaejZK/6amI87vA== X-Google-Smtp-Source: AH8x227mci4Te4EHW1Lv/t9m6X1yAfNkrB//h+BNDC+h96/+dNOfuKCQece2PNSv1o0jiAan0Njdxg== X-Received: by 10.28.138.85 with SMTP id m82mr4425733wmd.56.1518615825472; Wed, 14 Feb 2018 05:43:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2018 05:43:44 -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 1/8] clk: divider: export clk_div_mask() helper Date: Wed, 14 Feb 2018 14:43:33 +0100 Message-Id: <20180214134340.17242-2-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 Export clk_div_mask() in clk-provider header so every clock providers derived from the generic clock divider may share the definition instead of redefining it. Signed-off-by: Jerome Brunet --- I have 's/div_mask/clk_div_mask' to avoid the conflict with tegra's divider, which also defines the macro div_mask() but does not actually derives from the generic divider. drivers/clk/clk-divider.c | 24 +++++++++++------------- include/linux/clk-provider.h | 1 + 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index b49942b9fe50..3c98d2650fa3 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -28,12 +28,10 @@ * parent - fixed parent. No clk_set_parent support */ -#define div_mask(width) ((1 << (width)) - 1) - static unsigned int _get_table_maxdiv(const struct clk_div_table *table, u8 width) { - unsigned int maxdiv = 0, mask = div_mask(width); + unsigned int maxdiv = 0, mask = clk_div_mask(width); const struct clk_div_table *clkt; for (clkt = table; clkt->div; clkt++) @@ -57,12 +55,12 @@ static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width, unsigned long flags) { if (flags & CLK_DIVIDER_ONE_BASED) - return div_mask(width); + return clk_div_mask(width); if (flags & CLK_DIVIDER_POWER_OF_TWO) - return 1 << div_mask(width); + return 1 << clk_div_mask(width); if (table) return _get_table_maxdiv(table, width); - return div_mask(width) + 1; + return clk_div_mask(width) + 1; } static unsigned int _get_table_div(const struct clk_div_table *table, @@ -84,7 +82,7 @@ static unsigned int _get_div(const struct clk_div_table *table, if (flags & CLK_DIVIDER_POWER_OF_TWO) return 1 << val; if (flags & CLK_DIVIDER_MAX_AT_ZERO) - return val ? val : div_mask(width) + 1; + return val ? val : clk_div_mask(width) + 1; if (table) return _get_table_div(table, val); return val + 1; @@ -109,7 +107,7 @@ static unsigned int _get_val(const struct clk_div_table *table, if (flags & CLK_DIVIDER_POWER_OF_TWO) return __ffs(div); if (flags & CLK_DIVIDER_MAX_AT_ZERO) - return (div == div_mask(width) + 1) ? 0 : div; + return (div == clk_div_mask(width) + 1) ? 0 : div; if (table) return _get_table_val(table, div); return div - 1; @@ -141,7 +139,7 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, unsigned int val; val = clk_readl(divider->reg) >> divider->shift; - val &= div_mask(divider->width); + val &= clk_div_mask(divider->width); return divider_recalc_rate(hw, parent_rate, val, divider->table, divider->flags, divider->width); @@ -353,7 +351,7 @@ static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, /* 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 &= clk_div_mask(divider->width); bestdiv = _get_div(divider->table, bestdiv, divider->flags, divider->width); return DIV_ROUND_UP_ULL((u64)*prate, bestdiv); @@ -376,7 +374,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate, value = _get_val(table, div, flags, width); - return min_t(unsigned int, value, div_mask(width)); + return min_t(unsigned int, value, clk_div_mask(width)); } EXPORT_SYMBOL_GPL(divider_get_val); @@ -399,10 +397,10 @@ static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate, __acquire(divider->lock); if (divider->flags & CLK_DIVIDER_HIWORD_MASK) { - val = div_mask(divider->width) << (divider->shift + 16); + val = clk_div_mask(divider->width) << (divider->shift + 16); } else { val = clk_readl(divider->reg); - val &= ~(div_mask(divider->width) << divider->shift); + val &= ~(clk_div_mask(divider->width) << divider->shift); } val |= (u32)value << divider->shift; clk_writel(val, divider->reg); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index f711be6e8c44..d8ba26d03332 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -399,6 +399,7 @@ struct clk_divider { spinlock_t *lock; }; +#define clk_div_mask(width) ((1 << (width)) - 1) #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw) #define CLK_DIVIDER_ONE_BASED BIT(0)