From patchwork Thu Mar 14 09:51:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Huang X-Patchwork-Id: 15346 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 D204723E48 for ; Thu, 14 Mar 2013 09:47:38 +0000 (UTC) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by fiordland.canonical.com (Postfix) with ESMTP id 65B29A18936 for ; Thu, 14 Mar 2013 09:47:38 +0000 (UTC) Received: by mail-ve0-f176.google.com with SMTP id cz10so1514449veb.35 for ; Thu, 14 Mar 2013 02:47:38 -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=oKiadoFosC5chSqy5aLTLFDz+TkhT5eRbY47w2c8U8Q=; b=BaUW/UJBa08SspBq1dY+pGEZYAwCZQbVw7fjC9pl/hJairLfItC01s0/3R46tZRW6E SP5GONZWri6h5w5sLqxck8hRyqAffP6tvsXWxNZH8nzxUO/2gkOHuDOTT02gfBWDea45 iZs7reASWpoP5TmZcsmVWKOyY6jGmXQSdA8T+32pojIuO3u/Uj2VkeWj1iYiRqqb+MS1 Xca8O0zfYaQUDCjvqCY9x9COXPK4eTki4zByDKB1Q+u7TcCRLBBfYf3fUrdbQd7V7uhh ps+LOiTIwvc6LOk1rb7Wf7AyXP/4pnvG5R/+ydHN6/yOXdrKXdz+WkN5BRJRB87SldWz j0nQ== X-Received: by 10.221.11.135 with SMTP id pe7mr766482vcb.41.1363254457845; Thu, 14 Mar 2013 02:47:37 -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 nf2csp62155veb; Thu, 14 Mar 2013 02:47:37 -0700 (PDT) X-Received: by 10.68.254.35 with SMTP id af3mr3942380pbd.176.1363254456833; Thu, 14 Mar 2013 02:47:36 -0700 (PDT) Received: from hqemgate04.nvidia.com (hqemgate04.nvidia.com. [216.228.121.35]) by mx.google.com with ESMTPS id tv4si3371494pbc.335.2013.03.14.02.47.35 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 14 Mar 2013 02:47:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bilhuang@nvidia.com designates 216.228.121.35 as permitted sender) client-ip=216.228.121.35; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bilhuang@nvidia.com designates 216.228.121.35 as permitted sender) smtp.mail=bilhuang@nvidia.com Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Thu, 14 Mar 2013 02:47:28 -0700 Received: from hqemhub01.nvidia.com ([172.17.108.22]) by hqnvupgp08.nvidia.com (PGP Universal service); Thu, 14 Mar 2013 02:40:49 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Thu, 14 Mar 2013 02:40:49 -0700 Received: from localhost.localdomain (172.20.144.16) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.298.1; Thu, 14 Mar 2013 02:47:30 -0700 From: Bill Huang To: , , , , CC: Bill Huang Subject: [RFC v3 1/1] clk: Add notifier support in clk_prepare/clk_unprepare Date: Thu, 14 Mar 2013 02:51:49 -0700 Message-ID: <1363254709-9209-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: ALoCoQmYpc9stxJWDXjAErpygPazaX90WFSi4Q5ek1N6K1QZyx18mj6LBt2j6PJiXwyktQ0mwJ3G Add the below two 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. CLK_PREPARED CLK_UNPREPARED Signed-off-by: Bill Huang --- drivers/clk/clk.c | 75 ++++++++++++++++++++++++++------------------------- include/linux/clk.h | 2 ++ 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ed87b24..d78ed16 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -516,6 +516,42 @@ struct clk *__clk_lookup(const char *name) /*** clk api ***/ +/** + * __clk_notify - call clk notifier chain + * @clk: struct clk * that is changing rate + * @msg: clk notifier type (see include/linux/clk.h) + * @old_rate: old clk rate + * @new_rate: new clk rate + * + * Triggers a notifier call chain on the clk rate-change notification + * for 'clk'. Passes a pointer to the struct clk and the previous + * and current rates to the notifier callback. Intended to be called by + * internal clock code only. Returns NOTIFY_DONE from the last driver + * called if all went well, or NOTIFY_STOP or NOTIFY_BAD immediately if + * a driver returns that. + */ +static int __clk_notify(struct clk *clk, unsigned long msg, + unsigned long old_rate, unsigned long new_rate) +{ + struct clk_notifier *cn; + struct clk_notifier_data cnd; + int ret = NOTIFY_DONE; + + cnd.clk = clk; + cnd.old_rate = old_rate; + cnd.new_rate = new_rate; + + list_for_each_entry(cn, &clk_notifier_list, node) { + if (cn->clk == clk) { + ret = srcu_notifier_call_chain(&cn->notifier_head, msg, + &cnd); + break; + } + } + + return ret; +} + void __clk_unprepare(struct clk *clk) { if (!clk) @@ -550,6 +586,7 @@ void clk_unprepare(struct clk *clk) { mutex_lock(&prepare_lock); __clk_unprepare(clk); + __clk_notify(clk, CLK_UNPREPARED, clk->rate, clk->rate); mutex_unlock(&prepare_lock); } EXPORT_SYMBOL_GPL(clk_unprepare); @@ -598,6 +635,8 @@ int clk_prepare(struct clk *clk) mutex_lock(&prepare_lock); ret = __clk_prepare(clk); + if (!ret) + __clk_notify(clk, CLK_PREPARED, clk->rate, clk->rate); mutex_unlock(&prepare_lock); return ret; @@ -749,42 +788,6 @@ long clk_round_rate(struct clk *clk, unsigned long rate) EXPORT_SYMBOL_GPL(clk_round_rate); /** - * __clk_notify - call clk notifier chain - * @clk: struct clk * that is changing rate - * @msg: clk notifier type (see include/linux/clk.h) - * @old_rate: old clk rate - * @new_rate: new clk rate - * - * Triggers a notifier call chain on the clk rate-change notification - * for 'clk'. Passes a pointer to the struct clk and the previous - * and current rates to the notifier callback. Intended to be called by - * internal clock code only. Returns NOTIFY_DONE from the last driver - * called if all went well, or NOTIFY_STOP or NOTIFY_BAD immediately if - * a driver returns that. - */ -static int __clk_notify(struct clk *clk, unsigned long msg, - unsigned long old_rate, unsigned long new_rate) -{ - struct clk_notifier *cn; - struct clk_notifier_data cnd; - int ret = NOTIFY_DONE; - - cnd.clk = clk; - cnd.old_rate = old_rate; - cnd.new_rate = new_rate; - - list_for_each_entry(cn, &clk_notifier_list, node) { - if (cn->clk == clk) { - ret = srcu_notifier_call_chain(&cn->notifier_head, msg, - &cnd); - break; - } - } - - return ret; -} - -/** * __clk_recalc_rates * @clk: first clk in the subtree * @msg: notification type (see include/linux/clk.h) diff --git a/include/linux/clk.h b/include/linux/clk.h index b3ac22d..16c1d92 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -43,6 +43,8 @@ struct clk; #define PRE_RATE_CHANGE BIT(0) #define POST_RATE_CHANGE BIT(1) #define ABORT_RATE_CHANGE BIT(2) +#define CLK_PREPARED BIT(3) +#define CLK_UNPREPARED BIT(4) /** * struct clk_notifier - associate a clk with a notifier