From patchwork Tue Mar 12 12:37:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Huang X-Patchwork-Id: 15283 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5CBC323E14 for ; Tue, 12 Mar 2013 12:16:46 +0000 (UTC) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by fiordland.canonical.com (Postfix) with ESMTP id EB1C4A18E22 for ; Tue, 12 Mar 2013 12:16:45 +0000 (UTC) Received: by mail-ve0-f178.google.com with SMTP id db10so3413783veb.37 for ; Tue, 12 Mar 2013 05:16:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-pgp-universal:from:to:cc:subject:date:message-id :x-mailer:x-nvconfidentiality:mime-version:content-type :x-gm-message-state; bh=p/qNaDlS1Rvj+bYZhL+WjaW+fRsIBK8FVcS9mCpk0qY=; b=iWfqr2dl9NNY1IvNCqt4xlcXAuYd4KckdRFMgbBePDr7xctawlp3do43jVK1QVE0ct aqU6nnqdS7FaInar2PpxpChSuQBWVSdyfh1a/FBiudiyINhhrb8B0Pv4V26Yz6oW2VgD wywMzGfaiCKzS6Cj1ZO/Alwn0lAhvd9eQwoP/B/wukEFsE3rMeqUQuXpUMWNfE/JX5gI b08OiTPMnuE5DpIYCkrD1Mc6ZqpU1NxKvkI0wHigMpixEbfWBrpl7+Hmm/wdNyfJ5KUu 4kMDIHJU1DJApH+Ds33ygovYr6ShEliKhGTch36MXuJ+bOKkgmdR4QWeXB1kJzCBDXdk 4Clw== X-Received: by 10.52.88.237 with SMTP id bj13mr5573923vdb.75.1363090605383; Tue, 12 Mar 2013 05:16:45 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp124777veb; Tue, 12 Mar 2013 05:16:44 -0700 (PDT) X-Received: by 10.68.130.1 with SMTP id oa1mr37349360pbb.134.1363090602245; Tue, 12 Mar 2013 05:16:42 -0700 (PDT) Received: from hqemgate03.nvidia.com (hqemgate03.nvidia.com. [216.228.121.140]) by mx.google.com with ESMTPS id xm3si29095574pbc.136.2013.03.12.05.16.40 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 12 Mar 2013 05:16:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bilhuang@nvidia.com designates 216.228.121.140 as permitted sender) client-ip=216.228.121.140; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bilhuang@nvidia.com designates 216.228.121.140 as permitted sender) smtp.mail=bilhuang@nvidia.com Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Tue, 12 Mar 2013 05:21:52 -0700 Received: from hqemhub03.nvidia.com ([172.17.108.22]) by hqnvupgp08.nvidia.com (PGP Universal service); Tue, 12 Mar 2013 05:10:08 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Tue, 12 Mar 2013 05:10:08 -0700 Received: from localhost.localdomain (172.20.144.16) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.298.1; Tue, 12 Mar 2013 05:16:39 -0700 From: Bill Huang To: , CC: , , , Bill Huang Subject: [RFC 1/1] clk: Add notifier support in clk_prepare_enable/clk_disable_unprepare Date: Tue, 12 Mar 2013 05:37:41 -0700 Message-ID: <1363091861-21534-1-git-send-email-bilhuang@nvidia.com> X-Mailer: git-send-email 1.7.9.5 X-NVConfidentiality: public MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlWnR6IFQsCcLPEcBm63vAT1VWnoY3n8uN/jAGvwx6o9+DEJ8xxGgeAWkABwnI62FQUAdIf Add the below four notifier events so drivers which are interested in knowing the clock status can act accordingly. This is extremely useful in some of the DVFS (Dynamic Voltage Frequency Scaling) design. PRE_CLK_ENABLE POST_CLK_ENABLE PRE_CLK_DISABLE POST_CLK_DISABLE Signed-off-by: Bill Huang --- drivers/clk/clk.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 40 ++++++++++++++++++++--------------- 2 files changed, 81 insertions(+), 17 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ed87b24..720a16a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1104,6 +1104,64 @@ struct clk *clk_get_parent(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_get_parent); +/** + * clk_prepare_enable - call clk_enable in non-atomic context. + * @clk: the clk to enable + * + * Send PRE_CLK_ENABLE/POST_CLK_ENABLE before/after calling + * clk_enalbe respectively + * + * Return success (0) or errno. + */ +int clk_prepare_enable(struct clk *clk) +{ + int ret; + + mutex_lock(&prepare_lock); + ret = __clk_prepare(clk); + if (ret) + return ret; + + if (clk->notifier_count) + __clk_notify(clk, PRE_CLK_ENABLE, clk->rate, clk->rate); + + ret = clk_enable(clk); + if (ret) + __clk_unprepare(clk); + + if (clk->notifier_count) + __clk_notify(clk, POST_CLK_ENABLE, clk->rate, clk->rate); + + mutex_unlock(&prepare_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(clk_prepare_enable); + +/** + * clk_disable_unprepare - call clk_disable in non-atomic context. + * @clk: the clk to enable + * + * Send PRE_CLK_DISABLE/POST_CLK_DISABLE before/after calling + * clk_disalbe respectively + */ +void clk_disable_unprepare(struct clk *clk) +{ + mutex_lock(&prepare_lock); + + if (clk->notifier_count) + __clk_notify(clk, PRE_CLK_DISABLE, clk->rate, clk->rate); + + clk_disable(clk); + __clk_unprepare(clk); + + if (clk->notifier_count) + __clk_notify(clk, POST_CLK_DISABLE, clk->rate, clk->rate); + + mutex_unlock(&prepare_lock); +} +EXPORT_SYMBOL_GPL(clk_disable_unprepare); + /* * .get_parent is mandatory for clocks with multiple possible parents. It is * optional for single-parent clocks. Always call .get_parent if it is diff --git a/include/linux/clk.h b/include/linux/clk.h index b3ac22d..4bbe1903 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -43,6 +43,10 @@ struct clk; #define PRE_RATE_CHANGE BIT(0) #define POST_RATE_CHANGE BIT(1) #define ABORT_RATE_CHANGE BIT(2) +#define PRE_CLK_ENABLE BIT(3) +#define POST_CLK_ENABLE BIT(4) +#define PRE_CLK_DISABLE BIT(5) +#define POST_CLK_DISABLE BIT(6) /** * struct clk_notifier - associate a clk with a notifier @@ -276,6 +280,20 @@ struct clk *clk_get_parent(struct clk *clk); */ struct clk *clk_get_sys(const char *dev_id, const char *con_id); +/** + * clk_prepare_enable - helps cases using clk_enable in non-atomic context. + * @clk: clock source + * + * Return success (0) or nagative errno. + */ +int clk_prepare_enable(struct clk *clk); + +/** + * clk_disable_unprepare - helps cases using clk_disable in non-atomic context. + * @clk: clock source + */ +void clk_disable_unprepare(struct clk *clk); + #else /* !CONFIG_HAVE_CLK */ static inline struct clk *clk_get(struct device *dev, const char *id) @@ -324,30 +342,18 @@ static inline struct clk *clk_get_parent(struct clk *clk) return NULL; } -#endif - -/* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ static inline int clk_prepare_enable(struct clk *clk) { - int ret; - - ret = clk_prepare(clk); - if (ret) - return ret; - ret = clk_enable(clk); - if (ret) - clk_unprepare(clk); - - return ret; + return 0; } -/* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ -static inline void clk_disable_unprepare(struct clk *clk) +static inline int clk_disable_unprepare(struct clk *clk) { - clk_disable(clk); - clk_unprepare(clk); + return 0; } +#endif + /** * clk_add_alias - add a new clock alias * @alias: name for clock alias