From patchwork Wed Oct 16 07:40:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 3050931 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 641E7BF924 for ; Wed, 16 Oct 2013 07:41:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AB16201FD for ; Wed, 16 Oct 2013 07:41:54 +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 EA5A720149 for ; Wed, 16 Oct 2013 07:41:52 +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 1VWLjI-0005Vp-Ua; Wed, 16 Oct 2013 07:41: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 1VWLj8-0000aX-3C; Wed, 16 Oct 2013 07:41:06 +0000 Received: from smtp.codeaurora.org ([198.145.11.231]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VWLii-0000Tk-6v for linux-arm-kernel@lists.infradead.org; Wed, 16 Oct 2013 07:40:46 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 0BF0813EF05; Wed, 16 Oct 2013 07:40:19 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id EE82313F2A3; Wed, 16 Oct 2013 07:40:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from sboyd-linux.qualcomm.com (i-global252.qualcomm.com [199.106.103.252]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5C8B313EF05; Wed, 16 Oct 2013 07:40:18 +0000 (UTC) From: Stephen Boyd To: Mike Turquette Subject: [PATCH v3 04/12] clk: Add regmap core helpers for enable/disable/is_enabled Date: Wed, 16 Oct 2013 00:40:06 -0700 Message-Id: <1381909214-12693-5-git-send-email-sboyd@codeaurora.org> X-Mailer: git-send-email 1.8.4.1.503.g2b7ca91 In-Reply-To: <1381909214-12693-1-git-send-email-sboyd@codeaurora.org> References: <1381909214-12693-1-git-send-email-sboyd@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131016_034040_751479_4CB00F19 X-CRM114-Status: GOOD ( 19.32 ) X-Spam-Score: -2.4 (--) Cc: linux-arm-msm@vger.kernel.org, Saravana Kannan , linux-kernel@vger.kernel.org, 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-Virus-Scanned: ClamAV using ClamSMTP The clock framework already has support for simple gate clocks but if drivers want to use the gate clock functionality they need to wrap the gate clock in another struct and chain the ops by calling the gate ops from their own custom ops. Plus the gate clock implementation only supports MMIO accessors so other bus type clocks don't benefit from the potential code reuse. Add some simple regmap helpers for enable/disable/is_enabled that drivers can use as drop in replacements for their clock ops or as simple functions they call from their own custom ops. Signed-off-by: Stephen Boyd --- drivers/clk/clk.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 13 ++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8042c00..7cc8cb0 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -742,6 +742,76 @@ out: return best; } +/** + * clk_is_enabled_regmap - standard is_enabled() for regmap users + * + * @hw: clk to operate on + * + * Clocks that use regmap for their register I/O can set the + * enable_reg and enable_mask fields in their struct clk_hw and then use + * this as their is_enabled operation, saving some code. + */ +int clk_is_enabled_regmap(struct clk_hw *hw) +{ + unsigned int val; + int ret; + + ret = regmap_read(hw->regmap, hw->enable_reg, &val); + if (ret != 0) + return ret; + + if (hw->enable_is_inverted) + return (val & hw->enable_mask) == 0; + else + return (val & hw->enable_mask) != 0; +} +EXPORT_SYMBOL_GPL(clk_is_enabled_regmap); + +/** + * clk_enable_regmap - standard enable() for regmap users + * + * @hw: clk to operate on + * + * Clocks that use regmap for their register I/O can set the + * enable_reg and enable_mask fields in their struct clk_hw and then use + * this as their enable() operation, saving some code. + */ +int clk_enable_regmap(struct clk_hw *hw) +{ + unsigned int val; + + if (hw->enable_is_inverted) + val = 0; + else + val = hw->enable_mask; + + return regmap_update_bits(hw->regmap, hw->enable_reg, + hw->enable_mask, val); +} +EXPORT_SYMBOL_GPL(clk_enable_regmap); + +/** + * clk_disable_regmap - standard disable() for regmap users + * + * @hw: clk to operate on + * + * Clocks that use regmap for their register I/O can set the + * enable_reg and enable_mask fields in their struct clk_hw and then use + * this as their disable() operation, saving some code. + */ +void clk_disable_regmap(struct clk_hw *hw) +{ + unsigned int val; + + if (hw->enable_is_inverted) + val = hw->enable_mask; + else + val = 0; + + regmap_update_bits(hw->regmap, hw->enable_reg, hw->enable_mask, val); +} +EXPORT_SYMBOL_GPL(clk_disable_regmap); + /*** clk api ***/ void __clk_unprepare(struct clk *clk) diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 6ed62f1..4087a9b 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -177,11 +177,21 @@ struct clk_init_data { * with the common clock framework. * * @regmap: regmap to use for regmap helpers and/or by providers + * + * @enable_reg: register when using regmap enable/disable ops + * + * @enable_mask: mask when using regmap enable/disable ops + * + * @enable_is_inverted: flag to indicate set enable_mask bits to disable + * when using clock_enable_regmap and friends APIs. */ struct clk_hw { struct clk *clk; const struct clk_init_data *init; struct regmap *regmap; + unsigned int enable_reg; + unsigned int enable_mask; + bool enable_is_inverted; }; /* @@ -447,6 +457,9 @@ struct clk *__clk_lookup(const char *name); long __clk_mux_determine_rate(struct clk_hw *hw, unsigned long rate, unsigned long *best_parent_rate, struct clk **best_parent_p); +int clk_is_enabled_regmap(struct clk_hw *hw); +int clk_enable_regmap(struct clk_hw *hw); +void clk_disable_regmap(struct clk_hw *hw); /* * FIXME clock api without lock protection