From patchwork Fri Jun 12 08:41:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Djakov X-Patchwork-Id: 49820 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8F08E20C81 for ; Fri, 12 Jun 2015 08:42:55 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf7954441lbb.0 for ; Fri, 12 Jun 2015 01:42:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=5fYZELfGqyayrTPARHE9OcZXzl75zQ7axHlefLNLOiI=; b=GNRCtTci3Z/PBvPsH1JcTwplee/XY7E7QFUM+cUmmk+R8FEPdGAJU4ZPr1dUZ/AVhd 1vQED5Rj294t7yBH7Gv1QszocBMZ617OUb58Trugr33vLDbyqL31MMJctFO6l7m1wfUs HEbM/9cSZNN/+B0hqyYEY4vWfZbUIsJW6JBfWWKr98dJAu6gGukCXK/i8RkiNQRr2SoE ShSXLRHGa82kRU529uBixHHgweUKhjcHhxS0mdc+MEh7Cd/Cm8gZwgj++2rkq2VRRFf5 nvIuxNHpcEkIs3/7hlBy3VW+ZJH1w2OdcSt3eAk2CmQ6yh+a36zu4FTIvjZSkMubszEp OS1Q== X-Gm-Message-State: ALoCoQmFQMf1Nth4DNoifIAtv2ykRlYCVU9uc95wLFzGNnPV5lfTpICQ+mtV1PCwh+EJT/0Y7dJh X-Received: by 10.180.198.172 with SMTP id jd12mr2928359wic.5.1434098573215; Fri, 12 Jun 2015 01:42:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.115.161 with SMTP id jp1ls500085lab.96.gmail; Fri, 12 Jun 2015 01:42:52 -0700 (PDT) X-Received: by 10.152.7.7 with SMTP id f7mr14176175laa.106.1434098572854; Fri, 12 Jun 2015 01:42:52 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id ew10si2851328lac.11.2015.06.12.01.42.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 01:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbtu8 with SMTP id tu8so15992681lbb.2 for ; Fri, 12 Jun 2015 01:42:52 -0700 (PDT) X-Received: by 10.152.7.7 with SMTP id f7mr14176171laa.106.1434098572738; Fri, 12 Jun 2015 01:42:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp385139lbb; Fri, 12 Jun 2015 01:42:51 -0700 (PDT) X-Received: by 10.66.249.168 with SMTP id yv8mr21707886pac.49.1434098567759; Fri, 12 Jun 2015 01:42:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bz4si4396041pab.196.2015.06.12.01.42.46; Fri, 12 Jun 2015 01:42:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753205AbbFLImm (ORCPT + 29 others); Fri, 12 Jun 2015 04:42:42 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:36358 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752765AbbFLIma (ORCPT ); Fri, 12 Jun 2015 04:42:30 -0400 Received: by wigg3 with SMTP id g3so10118693wig.1 for ; Fri, 12 Jun 2015 01:42:28 -0700 (PDT) X-Received: by 10.180.13.175 with SMTP id i15mr4733970wic.30.1434098548441; Fri, 12 Jun 2015 01:42:28 -0700 (PDT) Received: from mms.wifi.mm-sol.com ([37.157.136.206]) by mx.google.com with ESMTPSA id 12sm4751195wjw.17.2015.06.12.01.42.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 01:42:27 -0700 (PDT) From: Georgi Djakov To: sboyd@codeaurora.org, agross@codeaurora.org Cc: mturquette@linaro.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 2/5] clk: Add safe switch hook Date: Fri, 12 Jun 2015 11:41:56 +0300 Message-Id: <1434098519-26406-3-git-send-email-georgi.djakov@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1434098519-26406-1-git-send-email-georgi.djakov@linaro.org> References: <1434098519-26406-1-git-send-email-georgi.djakov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: georgi.djakov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Stephen Boyd Sometimes clocks can't accept their parent source turning off while the source is reprogrammed to a different rate. Most notably CPU clocks require a way to switch away from the current PLL they're running on, reprogram that PLL to a new rate, and then switch back to the PLL with the new rate once they're done. Add a hook that drivers can implement allowing them to return a 'safe parent' and 'safe frequency' that they can switch their parent to while the upstream source is reprogrammed to support this. Signed-off-by: Stephen Boyd [georgi: updated patch to support safe frequency] Signed-off-by: Georgi Djakov --- drivers/clk/clk.c | 76 +++++++++++++++++++++++++++++++++++++----- include/linux/clk-provider.h | 2 ++ 2 files changed, 70 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 1cf479b9f3b4..7ec74833612a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -50,9 +50,13 @@ struct clk_core { struct clk_core **parents; u8 num_parents; u8 new_parent_index; + u8 safe_parent_index; unsigned long rate; unsigned long req_rate; + unsigned long old_rate; unsigned long new_rate; + unsigned long safe_freq; + struct clk_core *safe_parent; struct clk_core *new_parent; struct clk_core *new_child; unsigned long flags; @@ -1224,7 +1228,9 @@ out: static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, struct clk_core *new_parent, u8 p_index) { - struct clk_core *child; + struct clk_core *child, *parent; + struct clk_hw *parent_hw; + unsigned long safe_freq; core->new_rate = new_rate; core->new_parent = new_parent; @@ -1234,6 +1240,23 @@ static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, if (new_parent && new_parent != core->parent) new_parent->new_child = core; + if (core->ops->get_safe_parent) { + parent_hw = core->ops->get_safe_parent(core->hw, &safe_freq); + if (parent_hw) { + parent = parent_hw->core; + p_index = clk_fetch_parent_index(core, parent); + core->safe_parent_index = p_index; + core->safe_parent = parent; + if (safe_freq) + core->safe_freq = safe_freq; + else + core->safe_freq = 0; + } + } else { + core->safe_parent = NULL; + core->safe_freq = 0; + } + hlist_for_each_entry(child, &core->children, child_node) { child->new_rate = clk_recalc(child, new_rate); clk_calc_subtree(child, child->new_rate, NULL, 0); @@ -1338,14 +1361,51 @@ static struct clk_core *clk_propagate_rate_change(struct clk_core *core, unsigned long event) { struct clk_core *child, *tmp_clk, *fail_clk = NULL; + struct clk_core *old_parent; int ret = NOTIFY_DONE; - if (core->rate == core->new_rate) + if (core->rate == core->new_rate && event != POST_RATE_CHANGE) return NULL; + switch (event) { + case PRE_RATE_CHANGE: + if (core->safe_parent) { + if (core->safe_freq) + core->ops->set_rate_and_parent(core->hw, + core->safe_freq, + core->safe_parent->rate, + core->safe_parent_index); + else + core->ops->set_parent(core->hw, + core->safe_parent_index); + } + core->old_rate = core->rate; + break; + case POST_RATE_CHANGE: + if (core->safe_parent) { + old_parent = __clk_set_parent_before(core, + core->new_parent); + if (core->ops->set_rate_and_parent) { + core->ops->set_rate_and_parent(core->hw, + core->new_rate, + core->new_parent ? + core->new_parent->rate : 0, + core->new_parent_index); + } else if (core->ops->set_parent) { + core->ops->set_parent(core->hw, + core->new_parent_index); + } + __clk_set_parent_after(core, core->new_parent, + old_parent); + } + break; + } + if (core->notifier_count) { - ret = __clk_notify(core, event, core->rate, core->new_rate); - if (ret & NOTIFY_STOP_MASK) + if (event != POST_RATE_CHANGE || core->old_rate != core->rate) + ret = __clk_notify(core, event, core->old_rate, + core->new_rate); + if (ret & NOTIFY_STOP_MASK && event != POST_RATE_CHANGE) fail_clk = core; } @@ -1388,7 +1448,8 @@ static void clk_change_rate(struct clk_core *core) else if (core->parent) best_parent_rate = core->parent->rate; - if (core->new_parent && core->new_parent != core->parent) { + if (core->new_parent && core->new_parent != core->parent && + !core->safe_parent) { old_parent = __clk_set_parent_before(core, core->new_parent); trace_clk_set_parent(core, core->new_parent); @@ -1414,9 +1475,6 @@ static void clk_change_rate(struct clk_core *core) core->rate = clk_recalc(core, best_parent_rate); - if (core->notifier_count && old_rate != core->rate) - __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); - /* * Use safe iteration, as change_rate can actually swap parents * for certain clock types. @@ -1469,6 +1527,8 @@ static int clk_core_set_rate_nolock(struct clk_core *core, core->req_rate = req_rate; + clk_propagate_rate_change(top, POST_RATE_CHANGE); + return ret; } diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 4a943d13625b..a1b1c1c74056 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -183,6 +183,8 @@ struct clk_ops { struct clk_hw **best_parent_hw); int (*set_parent)(struct clk_hw *hw, u8 index); u8 (*get_parent)(struct clk_hw *hw); + struct clk_hw *(*get_safe_parent)(struct clk_hw *hw, + unsigned long *safe_freq); int (*set_rate)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate); int (*set_rate_and_parent)(struct clk_hw *hw,