From patchwork Wed Mar 27 09:50:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 15686 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 31CAD23E10 for ; Wed, 27 Mar 2013 09:50:51 +0000 (UTC) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by fiordland.canonical.com (Postfix) with ESMTP id CC2BAA18146 for ; Wed, 27 Mar 2013 09:50:50 +0000 (UTC) Received: by mail-ve0-f172.google.com with SMTP id oz10so1593805veb.31 for ; Wed, 27 Mar 2013 02:50:50 -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:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type:x-gm-message-state; bh=s0RO9DAh0pyBF12hderodag7PMDKrTDbxNaFOEIjTsg=; b=CMoVlfYMJqSzXFUzrFfTMJPRWM2KObVeUazfojV3e1hRae4pIjXx+C2RE7rGIsGzC9 uVtdxDsQMaHuFkjLv4JuviglG260jlXLqG0fvgW0Qqsc08MM16ldRmzeGPohh22xatGh lyEgirS0gjIQsdePBRBWQkqEOLDmMk5mYT3eom4SBgrWQVr0tStzN+RuTwjSGhdKQyk+ 5mw30Hx7E98dsoC9AwRQlaVsOhe5JE7J6iQkzQGkiDL6MN/7MYGMgCNxaACyBcHAS2xP rfusfiE7ihyth7pUXmMIuP4EA7riryZ064JnOrluVSsQEhHfq0JBLLUlyLlOi8kXDjDV dBXA== X-Received: by 10.52.76.103 with SMTP id j7mr19499053vdw.90.1364377850357; Wed, 27 Mar 2013 02:50:50 -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.59.4.204 with SMTP id cg12csp108187ved; Wed, 27 Mar 2013 02:50:49 -0700 (PDT) X-Received: by 10.194.95.198 with SMTP id dm6mr30180189wjb.6.1364377848332; Wed, 27 Mar 2013 02:50:48 -0700 (PDT) Received: from eu1sys200aog123.obsmtp.com (eu1sys200aog123.obsmtp.com [207.126.144.155]) by mx.google.com with SMTP id d42si31647058eep.62.2013.03.27.02.50.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 27 Mar 2013 02:50:48 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.155 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.155; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.155 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) smtp.mail=ulf.hansson@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob123.postini.com ([207.126.147.11]) with SMTP ID DSNKUVLA7na3V476UvgZmEIor/E/S4dR1ay2@postini.com; Wed, 27 Mar 2013 09:50:48 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 4095E4E; Wed, 27 Mar 2013 09:49:45 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id AE55855; Wed, 27 Mar 2013 03:19:16 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 71EC7A8074; Wed, 27 Mar 2013 10:50:31 +0100 (CET) Received: from steludxu1397.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.279.5; Wed, 27 Mar 2013 10:50:35 +0100 From: Ulf Hansson To: , Mike Turquette Cc: Linus Walleij , Par-Olof Hakansson , Ulf Hansson , Rajagopal Venkat Subject: [PATCH V3 2/3] clk: Fixup errorhandling for clk_set_parent Date: Wed, 27 Mar 2013 10:50:24 +0100 Message-ID: <1364377825-6171-3-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1364377825-6171-1-git-send-email-ulf.hansson@stericsson.com> References: <1364377825-6171-1-git-send-email-ulf.hansson@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQko1kMOycs7wWDFjiZlsrlVNkQ90B4M+kFhgi0OT10QUAljUEh7EjVgbiBgwjXRwa0R54oH From: Ulf Hansson Fixup the broken feature of allowing reparent of a clk to the orhpan list and vice verse. When operating on a single-parent clk, the .set_parent callback for the clk hw is optional to implement, but for a multi-parent clk it is mandatory. Moreover improve the errorhandling by verifying the prerequisites before triggering clk notifiers. This will prevent unnecessary rollback with ABORT_RATE_CHANGE. Signed-off-by: Ulf Hansson Cc: Rajagopal Venkat --- drivers/clk/clk.c | 56 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 97d681b..6fa301b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1269,15 +1269,10 @@ void __clk_reparent(struct clk *clk, struct clk *new_parent) __clk_recalc_rates(clk, POST_RATE_CHANGE); } -static int __clk_set_parent(struct clk *clk, struct clk *parent) +static u8 clk_fetch_parent_index(struct clk *clk, struct clk *parent) { - struct clk *old_parent; - unsigned long flags; - int ret = -EINVAL; u8 i; - old_parent = clk->parent; - if (!clk->parents) clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), GFP_KERNEL); @@ -1297,11 +1292,14 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) } } - if (i == clk->num_parents) { - pr_debug("%s: clock %s is not a possible parent of clock %s\n", - __func__, parent->name, clk->name); - goto out; - } + return i; +} + +static int __clk_set_parent(struct clk *clk, struct clk *parent, u8 p_index) +{ + unsigned long flags; + int ret = 0; + struct clk *old_parent = clk->parent; /* migrate prepare and enable */ if (clk->prepare_count) @@ -1314,7 +1312,8 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) spin_unlock_irqrestore(&enable_lock, flags); /* change clock input source */ - ret = clk->ops->set_parent(clk->hw, i); + if (parent && clk->ops->set_parent) + ret = clk->ops->set_parent(clk->hw, p_index); /* clean up old prepare and enable */ spin_lock_irqsave(&enable_lock, flags); @@ -1325,7 +1324,6 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) if (clk->prepare_count) __clk_unprepare(old_parent); -out: return ret; } @@ -1344,11 +1342,14 @@ out: int clk_set_parent(struct clk *clk, struct clk *parent) { int ret = 0; + u8 p_index = 0; + unsigned long p_rate = 0; if (!clk || !clk->ops) return -EINVAL; - if (!clk->ops->set_parent) + /* verify ops for for multi-parent clks */ + if ((clk->num_parents > 1) && (!clk->ops->set_parent)) return -ENOSYS; /* prevent racing with updates to the clock topology */ @@ -1357,19 +1358,34 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (clk->parent == parent) goto out; + /* check that we are allowed to re-parent if the clock is in use */ + if ((clk->flags & CLK_SET_PARENT_GATE) && clk->prepare_count) { + ret = -EBUSY; + goto out; + } + + /* try finding the new parent index */ + if (parent) { + p_index = clk_fetch_parent_index(clk, parent); + p_rate = parent->rate; + if (p_index == clk->num_parents) { + pr_debug("%s: clk %s can not be parent of clk %s\n", + __func__, parent->name, clk->name); + ret = -EINVAL; + goto out; + } + } + /* propagate PRE_RATE_CHANGE notifications */ if (clk->notifier_count) - ret = __clk_speculate_rates(clk, parent->rate); + ret = __clk_speculate_rates(clk, p_rate); /* abort if a driver objects */ if (ret == NOTIFY_STOP) goto out; - /* only re-parent if the clock is not in use */ - if ((clk->flags & CLK_SET_PARENT_GATE) && clk->prepare_count) - ret = -EBUSY; - else - ret = __clk_set_parent(clk, parent); + /* do the re-parent */ + ret = __clk_set_parent(clk, parent, p_index); /* propagate ABORT_RATE_CHANGE if .set_parent failed */ if (ret) {