From patchwork Tue Apr 2 21:09:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 15827 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 0B1094C13C2 for ; Tue, 2 Apr 2013 21:10:09 +0000 (UTC) Received: from mail-bk0-f69.google.com (mail-bk0-f69.google.com [209.85.214.69]) by fiordland.canonical.com (Postfix) with ESMTP id D728AA1A5D5 for ; Tue, 2 Apr 2013 21:10:08 +0000 (UTC) Received: by mail-bk0-f69.google.com with SMTP id i18sf1097663bkv.0 for ; Tue, 02 Apr 2013 14:10:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf: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:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=EhCbD6naMOGwJlcgerm8oWcPcNpoDjZTWNXpFhFIwrQ=; b=RyTezyOWrp8t59SsCD3rGtjbNOzzD0qhe5XUVEyqbFJBfSUP7bsA3jOzaUvQPKG6aa bprotuBydwI0i3ZC/I4Q77BIoTzuBgqpvEp4HciI2dNjhc6xh7A2FQPrYpx5fduJZs8D bH4yTrjXufqm2ImlLUOYZpCucBNoc+xR3x4zDWGX87pf8UFgpFe11w8gs5938FhOVs1p K+IT0IxHdlvzLpEDGmYcfc3Zx2FP+KCkYqGaUMyIfiTZ8yt1yVzl8k0euSvLVUx3HqiP 5cLK645krxCHxpT44Aue2t1krunFrGRUWnBkLZUejoUdmZN6HXTkfuVz7xBGcwEb/436 OQMg== X-Received: by 10.180.11.239 with SMTP id t15mr3466378wib.5.1364937008686; Tue, 02 Apr 2013 14:10:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.181.13.173 with SMTP id ez13ls379368wid.43.gmail; Tue, 02 Apr 2013 14:10:08 -0700 (PDT) X-Received: by 10.180.90.116 with SMTP id bv20mr7467256wib.32.1364937008631; Tue, 02 Apr 2013 14:10:08 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id p8si1344035wjz.3.2013.04.02.14.10.08 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Apr 2013 14:10:08 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id cy12so1103912veb.4 for ; Tue, 02 Apr 2013 14:10:07 -0700 (PDT) X-Received: by 10.58.223.134 with SMTP id qu6mr11176903vec.35.1364937007435; Tue, 02 Apr 2013 14:10:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp143066ved; Tue, 2 Apr 2013 14:10:06 -0700 (PDT) X-Received: by 10.14.173.67 with SMTP id u43mr53267252eel.22.1364937006079; Tue, 02 Apr 2013 14:10:06 -0700 (PDT) Received: from eu1sys200aog107.obsmtp.com (eu1sys200aog107.obsmtp.com [207.126.144.123]) by mx.google.com with SMTP id n9si5193746eem.251.2013.04.02.14.10.01 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Apr 2013 14:10:06 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.123 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.123; Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob107.postini.com ([207.126.147.11]) with SMTP ID DSNKUVtJKWHTdsAuKVbGi+2at6wj9MiWT2KL@postini.com; Tue, 02 Apr 2013 21:10:05 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 1772347; Tue, 2 Apr 2013 21:09:03 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id D4AA196; Tue, 2 Apr 2013 14:33:34 +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 relay1.stm.gmessaging.net (Postfix) with ESMTPS id AAE7424C07D; Tue, 2 Apr 2013 23:09:43 +0200 (CEST) Received: from steludxu1397.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.279.5; Tue, 2 Apr 2013 23:09:54 +0200 From: Ulf Hansson To: , Mike Turquette Cc: Linus Walleij , Par-Olof Hakansson , Ulf Hansson , Rajagopal Venkat Subject: [PATCH V4 2/3] clk: Fixup errorhandling for clk_set_parent Date: Tue, 2 Apr 2013 23:09:38 +0200 Message-ID: <1364936979-20805-3-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1364936979-20805-1-git-send-email-ulf.hansson@stericsson.com> References: <1364936979-20805-1-git-send-email-ulf.hansson@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnGc1ex1wo6RLSoMv6SS5w2ieB7wfAZ5dzkpjf3hkMR1cQrFoTiBL/qV/iCDOTpN25vK9vJ X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 013a3c7..c83e8e5 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1332,15 +1332,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); @@ -1360,11 +1355,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) @@ -1377,7 +1375,8 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) clk_enable_unlock(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 */ flags = clk_enable_lock(); @@ -1388,7 +1387,6 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) if (clk->prepare_count) __clk_unprepare(old_parent); -out: return ret; } @@ -1407,11 +1405,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 */ @@ -1420,19 +1421,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) {