From patchwork Fri Jun 21 06:14:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 2760321 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 56EA3C0AB1 for ; Fri, 21 Jun 2013 06:15:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 489A320193 for ; Fri, 21 Jun 2013 06:15:49 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F21AB2018A for ; Fri, 21 Jun 2013 06:15:47 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Upucu-0003pz-J4; Fri, 21 Jun 2013 06:15:17 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Upucm-0000jp-Rg; Fri, 21 Jun 2013 06:15:08 +0000 Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpucV-0000gg-Uu for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2013 06:14:54 +0000 Received: by mail-pb0-f49.google.com with SMTP id jt11so7305454pbb.36 for ; Thu, 20 Jun 2013 23:14:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=NrKOVWYcKarEMFCB3L2kq+osdFvsLbz1W4PlHic5+40=; b=W7njcAGoSHljlNYwET6AJS6O3J1pN2imuh+MKNDZinKxYZADu4elCZIKvKPe0T8DEb wdK51lUFrA/vWMcGUASXctAiBTFDNoM1WxIY7yb3wmzR4XACxvMTIiapYWPEvGPjqMQv gpNgLPkOUeE4klT7p4Lju3NkhBOQULSMQvrzMCCk/Ebz0kmSm/bSB9eAhId72je+8rWw +fVX1BUYjx6MVpUor0zb+xpyRLvkzve0wu3bOZEs5t1FUscjzOpl49irNM+gW92Kk9gO gl8NZitI1S6pIB6jQmzoohlaen7U/b+jicUGpJXzL1o7aIlKzrlxIOyf7ScjmRGFa60A PEag== X-Received: by 10.68.197.165 with SMTP id iv5mr10744655pbc.47.1371795270432; Thu, 20 Jun 2013 23:14:30 -0700 (PDT) Received: from localhost.localdomain (c-50-152-203-145.hsd1.ca.comcast.net. [50.152.203.145]) by mx.google.com with ESMTPSA id tq3sm4250612pab.7.2013.06.20.23.14.28 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Jun 2013 23:14:29 -0700 (PDT) From: Mike Turquette To: linux-kernel@vger.kernel.org Subject: [PATCH v3 1/5] clk: divider: replace bitfield width with mask Date: Thu, 20 Jun 2013 23:14:12 -0700 Message-Id: <1371795256-16703-2-git-send-email-mturquette@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1371795256-16703-1-git-send-email-mturquette@linaro.org> References: <1371795256-16703-1-git-send-email-mturquette@linaro.org> X-Gm-Message-State: ALoCoQnmrYtnjBwMBBb+PbVjJdo23FGCiUEN/LUf0+qNE8spnLud/pQ413+VTVIeSJUJgFTKllTl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130621_021452_236818_A6BAF5BD X-CRM114-Status: GOOD ( 18.37 ) X-Spam-Score: -1.9 (-) Cc: Mike Turquette , =?UTF-8?q?Heiko=20St=C3=BCbner?= , devicetree-discuss@lists.ozlabs.org, Stephen Boyd , Tero Kristo , Haojian Zhuang , Matt Sealey , Sascha Hauer , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The forthcoming Device Tree binding for the divider clock type will use a bitfield mask instead of bitfield width, which is what the current basic divider implementation uses. This patch replaces the u8 width in struct clk_divider with a u32 mask. The divider code is updated to use the bit mask internally but the two registration functions still accept the width to maintain compatibility with existing users. Also updated in this patch is the clk-private.h divider macro and two Freescale clock divider implementations that are based on struct clk_divider. Cc: Sascha Hauer Tested-by: Shawn Guo Signed-off-by: Mike Turquette --- No change since v2 arch/arm/mach-imx/clk-busy.c | 2 +- drivers/clk/clk-divider.c | 31 +++++++++++++++---------------- drivers/clk/mxs/clk-div.c | 2 +- include/linux/clk-private.h | 2 +- include/linux/clk-provider.h | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/arch/arm/mach-imx/clk-busy.c b/arch/arm/mach-imx/clk-busy.c index 4bb1bc4..bc88e38 100644 --- a/arch/arm/mach-imx/clk-busy.c +++ b/arch/arm/mach-imx/clk-busy.c @@ -95,7 +95,7 @@ struct clk *imx_clk_busy_divider(const char *name, const char *parent_name, busy->div.reg = reg; busy->div.shift = shift; - busy->div.width = width; + busy->div.mask = BIT(width) - 1; busy->div.lock = &imx_ccm_lock; busy->div_ops = &clk_divider_ops; diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 6d55eb2..ac9cb7f 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -30,8 +30,6 @@ #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw) -#define div_mask(d) ((1 << ((d)->width)) - 1) - static unsigned int _get_table_maxdiv(const struct clk_div_table *table) { unsigned int maxdiv = 0; @@ -46,12 +44,12 @@ static unsigned int _get_table_maxdiv(const struct clk_div_table *table) static unsigned int _get_maxdiv(struct clk_divider *divider) { if (divider->flags & CLK_DIVIDER_ONE_BASED) - return div_mask(divider); + return divider->mask; if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) - return 1 << div_mask(divider); + return 1 << divider->mask; if (divider->table) return _get_table_maxdiv(divider->table); - return div_mask(divider) + 1; + return divider->mask + 1; } static unsigned int _get_table_div(const struct clk_div_table *table, @@ -105,7 +103,7 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, unsigned int div, val; val = readl(divider->reg) >> divider->shift; - val &= div_mask(divider); + val &= divider->mask; div = _get_div(divider, val); if (!div) { @@ -221,17 +219,17 @@ static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate, div = parent_rate / rate; value = _get_val(divider, div); - if (value > div_mask(divider)) - value = div_mask(divider); + if (value > divider->mask) + value = divider->mask; if (divider->lock) spin_lock_irqsave(divider->lock, flags); if (divider->flags & CLK_DIVIDER_HIWORD_MASK) { - val = div_mask(divider) << (divider->shift + 16); + val = divider->mask << (divider->shift + 16); } else { val = readl(divider->reg); - val &= ~(div_mask(divider) << divider->shift); + val &= ~(divider->mask << divider->shift); } val |= value << divider->shift; writel(val, divider->reg); @@ -251,7 +249,7 @@ EXPORT_SYMBOL_GPL(clk_divider_ops); static struct clk *_register_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, - void __iomem *reg, u8 shift, u8 width, + void __iomem *reg, u8 shift, u32 mask, u8 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { @@ -260,8 +258,9 @@ static struct clk *_register_divider(struct device *dev, const char *name, struct clk_init_data init; if (clk_divider_flags & CLK_DIVIDER_HIWORD_MASK) { - if (width + shift > 16) { - pr_warn("divider value exceeds LOWORD field\n"); + if ((mask << shift) & 0xffff0000) { + pr_warn("%s: divider value exceeds LOWORD field\n", + __func__); return ERR_PTR(-EINVAL); } } @@ -282,7 +281,7 @@ static struct clk *_register_divider(struct device *dev, const char *name, /* struct clk_divider assignments */ div->reg = reg; div->shift = shift; - div->width = width; + div->mask = mask; div->flags = clk_divider_flags; div->lock = lock; div->hw.init = &init; @@ -315,7 +314,7 @@ struct clk *clk_register_divider(struct device *dev, const char *name, u8 clk_divider_flags, spinlock_t *lock) { return _register_divider(dev, name, parent_name, flags, reg, shift, - width, clk_divider_flags, NULL, lock); + ((1 << width) - 1), clk_divider_flags, NULL, lock); } /** @@ -339,5 +338,5 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name, spinlock_t *lock) { return _register_divider(dev, name, parent_name, flags, reg, shift, - width, clk_divider_flags, table, lock); + ((1 << width) - 1), clk_divider_flags, table, lock); } diff --git a/drivers/clk/mxs/clk-div.c b/drivers/clk/mxs/clk-div.c index 90e1da9..af2428e 100644 --- a/drivers/clk/mxs/clk-div.c +++ b/drivers/clk/mxs/clk-div.c @@ -96,7 +96,7 @@ struct clk *mxs_clk_div(const char *name, const char *parent_name, div->divider.reg = reg; div->divider.shift = shift; - div->divider.width = width; + div->divider.mask = BIT(width) - 1; div->divider.flags = CLK_DIVIDER_ONE_BASED; div->divider.lock = &mxs_lock; div->divider.hw.init = &init; diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index dd7adff..67a3069 100644 --- a/include/linux/clk-private.h +++ b/include/linux/clk-private.h @@ -119,7 +119,7 @@ struct clk { }, \ .reg = _reg, \ .shift = _shift, \ - .width = _width, \ + .mask = ((1 << _width) - 1), \ .flags = _divider_flags, \ .table = _table, \ .lock = _lock, \ diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 1ec14a7..4920fd1 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -271,7 +271,7 @@ struct clk_divider { struct clk_hw hw; void __iomem *reg; u8 shift; - u8 width; + u32 mask; u8 flags; const struct clk_div_table *table; spinlock_t *lock;