From patchwork Sun Sep 24 20:00:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114154 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1855619qgf; Sun, 24 Sep 2017 13:02:43 -0700 (PDT) X-Received: by 10.99.161.17 with SMTP id b17mr5461933pgf.292.1506283363868; Sun, 24 Sep 2017 13:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283363; cv=none; d=google.com; s=arc-20160816; b=LXfjEfGYAgytSWGa/pLLZRz32LpdENg9XGYX+zrKvLi+FXapFP8ndPZKgUGzvduWRc slxMSzY1GdkmviIOmTy60SVVAF7y0okaJ/NBpwNLNpoMk2tyis1lOgJimb/ixyiNv5Z8 y6PpSji1eigW9vx7Nf9f7JFt4Eo9W+FPLaRbSsM2Gdu41xpooyTwk956LmDEyZ/3EGmG lBQRdi5VOG8MoZcE/SwKR04BYr867B9uHzI7vhmV/bUAAP26EGAu5Sll1e6wo3BdqQmC S72PI5rbjVaNGFJiYPO0T8YR9VQiOSryJRjhiy+xR5sb51FvXFK+u0+jmncQfKbMLwZ/ Q59Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=3P7JlM6POjK64UT8NYdIWaw2weeZcXFr/vritVB4nPA=; b=rAbUdIZCq2V1yWMrWfbl4KTsRhQxY8Gb4TJvSUsIw3FtiZdLh2fC96I1ut9e8dbLCB 3BpcCJhAW6ZPq3iqHg+QuVqlsvVVUO86+rU7sHuR0oJrP9vnzznd29G9aqb0NHr2k/pm SzXk3zxxhpPG3UW6zqXHRNfCFzFEVx/hQ8fMJoD+ympC2KJWWr4R+FWL9Mij0XXlaXQv yiBnEBbGOaCHCM0uD/pgzRk4X00xgEdB4TyPcPqdtn1Is45KPCFil9/CbKLP/tq0D+xn 4pvVR/MXO5cpytbIdKKSrlp1/UQJaxZKNFe6EZi0tO6DCFhq/JN5qI+6fuqTxSigYB1y UvEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hljpkgRF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17si2908350pfk.531.2017.09.24.13.02.43; Sun, 24 Sep 2017 13:02:43 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hljpkgRF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753189AbdIXUCl (ORCPT + 26 others); Sun, 24 Sep 2017 16:02:41 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:46582 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752872AbdIXUAi (ORCPT ); Sun, 24 Sep 2017 16:00:38 -0400 Received: by mail-wm0-f44.google.com with SMTP id m72so14326771wmc.1 for ; Sun, 24 Sep 2017 13:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3P7JlM6POjK64UT8NYdIWaw2weeZcXFr/vritVB4nPA=; b=hljpkgRFLitMHmPk9qXDrCU2RxcbzKedIg4n6QUKtYaiLUJjo0SHaWur4eCtg3906L 1KemCfTNQwu4JeepAQuF8E6PZH9LlW0dXQsxYm3g7AlQEh4Lghx4o0lJtSMZZ92XVshd Og/tQ/LHd3KLQYrnjpyIOt85pd4qBfB71weA4gEcdGthWu7+WiC3mq0JALVq9oUF8if2 FHSBK7PadFzAF+gOL0//bxji7rv3nLK8FQdy00FWngQgZuvuXGVgtitXt6VQ3A259ZgE 5+hvYu82fRRZgRuuBSIjnourLwsr1YgxP2sMPWTRWsVTNfEl3jQf4RpN9wlT9ISjGjLC d+mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3P7JlM6POjK64UT8NYdIWaw2weeZcXFr/vritVB4nPA=; b=EivzcRhd6RTI7VsuFf2gSySlE/G8HLEuHAztI/E3lddNFpxGD1IjPoQBikr+S/WHfP Ee1j5q9Wk2jZWWvFJt8A9/WzTHbpst/lQrZtVpqO0h7HW9tcdWMz0CzYEnFYiOg4o0cu KPzturL1OgGAwrG2uk5RZWab+rEge13QQ3TqGF4Z5sMPCTWicKz1XCjlY42nBXHKpUGw lRddGS1R/OlQv/ldjdzLVDsp8GW/3J4t4OUheDXC4qKWApf3Kv7sKcBn3ezw5Ux4h4BC OhdPKYSoOw7p7F+88AB2ySuRyFL/Gijqut2TX3srSVbw9MRWWLG4Gl1Nrw2Qmky42vv/ 0XZA== X-Gm-Message-State: AHPjjUiiLir2MjH+S7gzSrxkjgm0MXdBaFI6VHOxNB8066jZVg8UUJli 3coHX1aEbK8hBpIutbhA9sRKAA== X-Google-Smtp-Source: AOwi7QCBUTBQDULfoLqpOEHhcSY3wIgA5dAkhQz1C6l6n+d9WozkWCB00ZRW3V9Zbt14oq/rw3H9sA== X-Received: by 10.28.153.85 with SMTP id b82mr7524117wme.121.1506283237746; Sun, 24 Sep 2017 13:00:37 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:37 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 01/10] clk: fix incorrect usage of ENOSYS Date: Sun, 24 Sep 2017 22:00:21 +0200 Message-Id: <20170924200030.6227-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ENOSYS is special and should only be used for incorrect syscall number. It does not seem to be the case here. Reported by checkpatch.pl while working on clock protection. Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c8d83acda006..b31e56b09e25 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1804,7 +1804,7 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) /* verify ops for for multi-parent clks */ if ((core->num_parents > 1) && (!core->ops->set_parent)) { - ret = -ENOSYS; + ret = -EPERM; goto out; } From patchwork Sun Sep 24 20:00:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114145 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1853844qgf; Sun, 24 Sep 2017 13:00:47 -0700 (PDT) X-Received: by 10.99.115.28 with SMTP id o28mr5545469pgc.374.1506283246650; Sun, 24 Sep 2017 13:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283246; cv=none; d=google.com; s=arc-20160816; b=bWgACg5dq26Qk5x1zfXa2R/ggbC7y60n9uJcYpCpPoSKCY2Mjl1cEWiNHTfMUT4oZv 7IVkfc7DuFBZ0iEoh91jqMZN6b2iYwIiuuktGjmSEMh2N4MW53QwV2WNuFpOQkYxcG1s xkRyS3tm50J/CLj93mEBC6DqtEHA/VY0dzVTeh/4TOJvYG04808c04zGaOLrs7VYCkzl wjEKNoBK3XH+bmYWM8x4JVHoQDZm8baaptTa5jJ1Na3FGcnvFDjLrnczYAoFESuvSFHk FTKj2GLspfmgFCT3tl+SZPPqoEFiF9mzxOUhF9as+jg8jMwJH7Q9Xb5I7GNW2AwddKyz 4wqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=AfhENWZl2LANeZabV4mdMhMwMkfHVkaU4FKcufEJiec=; b=gTf7vKT7Btg/Z0LAbr+tGESAXp2wq7ml+Pbh5eAqrpiTmJxaL4utOVWV+YTRGGKdrg 7q6WVUl4yFZdeTY5grD58Q4yEQ9RNr+gzXotPqwjNsBQh9epFVkKoVQ401APe5xl3cSx 8PPgCf1jSKoGsU2t2F7RgpZgK8H4mvAZLFXlq310aO/eyqaEhnr2tyvqGKTHgwwxOXNM JOSIhN+Sj4grWwyzPzLyImbypqDrEcHpV4Tv1hO5vqQWpYYxASrtZY4eHcr5DkKvrF5d luEz5vTFe4aaLAwLNU3//nIcACgdWG0VfPt3Soe1OrfUa3HFgBkN7DC5APv0UJzWTbT5 2W0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=ekYRbl3k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o61si3049815pld.215.2017.09.24.13.00.46; Sun, 24 Sep 2017 13:00:46 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=ekYRbl3k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752918AbdIXUAo (ORCPT + 26 others); Sun, 24 Sep 2017 16:00:44 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:55222 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752884AbdIXUAk (ORCPT ); Sun, 24 Sep 2017 16:00:40 -0400 Received: by mail-wr0-f179.google.com with SMTP id g29so4612266wrg.11 for ; Sun, 24 Sep 2017 13:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AfhENWZl2LANeZabV4mdMhMwMkfHVkaU4FKcufEJiec=; b=ekYRbl3kpCAuq7B4OQgRGpoK3sIrNUXgi0detlRWJbmARS7GgOhvNEc1I1e0aKTb8e CGDCwb9xYgy6rqEB5wxl9MteBMTkwK9Lh3nxNwzrAS221SnnSbQ8vQR/cV6TTgj27Lwb cNsymjWBEzUZ5nQartM1NjCGLxd99aITaSX6ft7kFOWWf14A7Q0nt8NAORLG6FAVD5xo zO/SLyKqlfXwbkN/TcFE+nfZr4P87txRSRo96+T+jZ+UTy409oI/XZAyY6PsZdozXJnb EjOQRleTMATn2S01DfKG5+07x0ZQImhQGpit/LrCpkeVEY5KPyUHaS5ylnAPETYhYoYu IStg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AfhENWZl2LANeZabV4mdMhMwMkfHVkaU4FKcufEJiec=; b=FrxP8OGrM0LYutWvi0uFFeTsxoD6QmBm5De4/3neCmkkiaDdWCu/g8aIATFv13pbCt 2T2BiYrQ4e7jrxxtuyfE1vfph8DMonevsO90o2gI0zaqCvjxmEsrtcu/lni6pToCiWHC yx30i4xWDcAzi0rBx4IuH2qS9M4TxMw5eWFx65+JwOpiEhFwHwfkXR2PVBFJDrcnDwgK 91uyDUacw2Zrw8XaCbmx7m+nVVIG1OD0qMEROMsd2SS73mcKjHHJ5+aotbVlk8jwH7WJ PmEG47uScHsVGv/c6Mh9BD8rntC1o2jvJt0o4c2BSduMBiJnNrdDWUH4beC8NCdpqS2/ ahBg== X-Gm-Message-State: AHPjjUhCdDoKdtEV0dJUFM5oLepB6bBOh5zN2I/IfaJ9C8lusHaLfHtM CCIBHIaXrASKggohEc1LCshHqQ== X-Google-Smtp-Source: AOwi7QDTkwzfQrB8onMF+LHQJ3c3teY8Evjf2CaIpCikXRVCtrC/hjti1grv0ZNYbDqMKXvo+vg2hg== X-Received: by 10.223.157.142 with SMTP id p14mr3817079wre.104.1506283238993; Sun, 24 Sep 2017 13:00:38 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:38 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 02/10] clk: take the prepare lock out of clk_core_set_parent Date: Sun, 24 Sep 2017 22:00:22 +0200 Message-Id: <20170924200030.6227-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rework set_parent core function so it can be called when the prepare lock is already held by the caller. This rework is done to ease the integration of the "protected" clock functionality. Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b31e56b09e25..3518f251cfd5 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1787,32 +1787,28 @@ bool clk_has_parent(struct clk *clk, struct clk *parent) } EXPORT_SYMBOL_GPL(clk_has_parent); -static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) +static int clk_core_set_parent_nolock(struct clk_core *core, + struct clk_core *parent) { int ret = 0; int p_index = 0; unsigned long p_rate = 0; + lockdep_assert_held(&prepare_lock); + if (!core) return 0; - /* prevent racing with updates to the clock topology */ - clk_prepare_lock(); - if (core->parent == parent) - goto out; + return 0; /* verify ops for for multi-parent clks */ - if ((core->num_parents > 1) && (!core->ops->set_parent)) { - ret = -EPERM; - goto out; - } + if (core->num_parents > 1 && !core->ops->set_parent) + return -EPERM; /* check that we are allowed to re-parent if the clock is in use */ - if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { - ret = -EBUSY; - goto out; - } + if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) + return -EBUSY; /* try finding the new parent index */ if (parent) { @@ -1820,8 +1816,7 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) if (p_index < 0) { pr_debug("%s: clk %s can not be parent of clk %s\n", __func__, parent->name, core->name); - ret = p_index; - goto out; + return p_index; } p_rate = parent->rate; } @@ -1831,7 +1826,7 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) /* abort if a driver objects */ if (ret & NOTIFY_STOP_MASK) - goto out; + return ret; /* do the re-parent */ ret = __clk_set_parent(core, parent, p_index); @@ -1844,9 +1839,6 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) __clk_recalc_accuracies(core); } -out: - clk_prepare_unlock(); - return ret; } @@ -1869,10 +1861,17 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) */ int clk_set_parent(struct clk *clk, struct clk *parent) { + int ret; + if (!clk) return 0; - return clk_core_set_parent(clk->core, parent ? parent->core : NULL); + clk_prepare_lock(); + ret = clk_core_set_parent_nolock(clk->core, + parent ? parent->core : NULL); + clk_prepare_unlock(); + + return ret; } EXPORT_SYMBOL_GPL(clk_set_parent); @@ -2753,7 +2752,7 @@ void clk_unregister(struct clk *clk) /* Reparent all children to the orphan list. */ hlist_for_each_entry_safe(child, t, &clk->core->children, child_node) - clk_core_set_parent(child, NULL); + clk_core_set_parent_nolock(child, NULL); } hlist_del_init(&clk->core->child_node); From patchwork Sun Sep 24 20:00:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114153 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1855377qgf; Sun, 24 Sep 2017 13:02:24 -0700 (PDT) X-Received: by 10.99.50.70 with SMTP id y67mr5339772pgy.291.1506283344900; Sun, 24 Sep 2017 13:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283344; cv=none; d=google.com; s=arc-20160816; b=CtJU8VlbhF8chXBk6cctUM0T5bh1Lkhi6gp1IkAW5LFHJybDJJCTHR2/wwj+2SkkUh 8Q9S9OuadV6ZxphjrtLZxGkGIpY206gnbSE8y603GBb8tF+pCiBa0+eS96KGw60D+o3C 7+ZYyTe+oyZJAk55O1V7Z+M2rCrtK07nwSb0nF5YTvtY8v4uucf6LnlxCdVI8SPb0yDj 57s3/6sNh//we2JbtowKO+t5NKjnIH6a9NLJC9GxchQjPuUhz8gfVuHqkQEjSLgX6zFX WMy3d8EuMQ3MYMB35rXG81GIasNembzzuHN+JNtqDsYLFMejehA/d1C6gCUBXr4mH+V6 zhwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=xjAYP0CK6vKJPEtTQHybVtFPqkV1q540d7q3mgd06n8=; b=XWbMHjRSzei/xMsCz/gVhKCETiciRz8LmDuLMEV0epLyE8TEphyOHqoAR9QzpggHsW VZ3E8zu1BtwnNL2tm7Xw4GhnFpWpBN+b+mzoKBkCxy3ZhR+NXQF+6y/+/kGtPxzfOtCt 89x1AREt8l88D5wl658ovpoHa5YM4kxKw4zllq4sFjAOTwkiaLsszqgqch3BZtuopDQI dO1bgIQqpHc0RzOdApAoDk5Taa8ge1oNWAxiqh50dIIwW4vsRpkwlTlL8QrvS1e8sNQj 51YFE83D+azIqq0yI1fm2zvgAzQ16prtvbUF4vFBNXwZY49h0slyhXH7CDNk5cOtWIHL /Jmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=L0DrMMhJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j89si2894585pfk.421.2017.09.24.13.02.24; Sun, 24 Sep 2017 13:02:24 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=L0DrMMhJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753163AbdIXUCV (ORCPT + 26 others); Sun, 24 Sep 2017 16:02:21 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:47323 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752893AbdIXUAl (ORCPT ); Sun, 24 Sep 2017 16:00:41 -0400 Received: by mail-wm0-f41.google.com with SMTP id r136so14357459wmf.2 for ; Sun, 24 Sep 2017 13:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xjAYP0CK6vKJPEtTQHybVtFPqkV1q540d7q3mgd06n8=; b=L0DrMMhJnPNDJ0DkG957VqRmbo9GB7HyO+DkKSUnm6oYvEGI9RG6lgP0jwD13CkJm+ ibIiY3r5MoOg9f183NysS9mFqx2ZPUOX3wdeCqAUUC1RCuhiJz9YWhnfT5L0sSaNF9FN nz2AoYIc+mYV4/+hjg2suSx+LgGgg5YBvoZKecPeWJ4y2W+cM7n17OJUtWIElnBJS65k c/dRApFmUWOiflB6XisUcx1hNdaKwjPtydpVRt/2L0btLWUFIg0sie/l2HipTAcs0SuI 5QAMg/T7qVhShq3+4Z2kctXzaI0KbAo0p3FCiUKoEMjiONMJEsdeAt7C5NWVST3xadct +FoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xjAYP0CK6vKJPEtTQHybVtFPqkV1q540d7q3mgd06n8=; b=BPfC6HP6MBW0jEzrX3RDOuung8Wy/ECiocJdAZazTBNGa1ZcUBLUX32gt3e77dxWXZ Y9g5tcYW5Q9jL/mT0VWwFtVkYeQwc+OBZW6XuqomjX9z5eN5bnrA/5A5kSsPqvTO7csc D0Vl8eig6EWWeu5HOnc+LMNlSeLMfa+CtnOZ8T3iWzFqTXtqkNleENvyLoESsEuPG482 FxiNOGV6N1SSzqMEgBjy2v5OK8151SWVN1I1rlpmUME8dVAjOt06xyv3RswK8MT3XDma aE7N0dHnMoQI/7wHR2F2m48FfUpEh6x2LyLuV6wAncnnnQoO1LRq3zJNE0+2Pb9ugf1R BHDA== X-Gm-Message-State: AHPjjUgGb0hsjSNdOjoLfcqhAAVuu94DGu9tKqso+NS81UGwChpi0O9u qzIqHQ0CR8P9UTKdK7pTyt+H2w== X-Google-Smtp-Source: AOwi7QDv0lTIaV9z1KMm4b3kBdFyRDiKK4sqkyhsst3WY+ZakgYJIGy9jDKl3afBamRWXi7Jii7Utg== X-Received: by 10.28.232.138 with SMTP id f10mr8004425wmi.130.1506283240172; Sun, 24 Sep 2017 13:00:40 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:39 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 03/10] clk: add clk_core_set_phase_nolock function Date: Sun, 24 Sep 2017 22:00:23 +0200 Message-Id: <20170924200030.6227-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a core function for set_phase, as it is done for set_rate and set_parent. This rework is done to ease the integration of "protected" clock functionality. Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 3518f251cfd5..0913688dacb0 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1875,6 +1875,25 @@ int clk_set_parent(struct clk *clk, struct clk *parent) } EXPORT_SYMBOL_GPL(clk_set_parent); +static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) +{ + int ret = -EINVAL; + + lockdep_assert_held(&prepare_lock); + + if (!core) + return 0; + + trace_clk_set_phase(core, degrees); + + if (core->ops->set_phase) + ret = core->ops->set_phase(core->hw, degrees); + + trace_clk_set_phase_complete(core, degrees); + + return ret; +} + /** * clk_set_phase - adjust the phase shift of a clock signal * @clk: clock signal source @@ -1897,7 +1916,7 @@ EXPORT_SYMBOL_GPL(clk_set_parent); */ int clk_set_phase(struct clk *clk, int degrees) { - int ret = -EINVAL; + int ret; if (!clk) return 0; @@ -1908,17 +1927,7 @@ int clk_set_phase(struct clk *clk, int degrees) degrees += 360; clk_prepare_lock(); - - trace_clk_set_phase(clk->core, degrees); - - if (clk->core->ops->set_phase) - ret = clk->core->ops->set_phase(clk->core->hw, degrees); - - trace_clk_set_phase_complete(clk->core, degrees); - - if (!ret) - clk->core->phase = degrees; - + ret = clk_core_set_phase_nolock(clk->core, degrees); clk_prepare_unlock(); return ret; From patchwork Sun Sep 24 20:00:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114152 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1855187qgf; Sun, 24 Sep 2017 13:02:11 -0700 (PDT) X-Received: by 10.98.70.137 with SMTP id o9mr5385919pfi.173.1506283331458; Sun, 24 Sep 2017 13:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283331; cv=none; d=google.com; s=arc-20160816; b=EBVEjzj/gZBGU8hNEDiUf9+EqcLPeCmpjYv7INXVqTVHKB6RjmcQYBbfUpinac/HBa 3rF6pIEFefQh8dXXebU5lbJAyPMSy/JiNWXdXQxD8rX37gL1N40YUsWxmtsrmq8b91mV 478ArF7MJDtuTJ5M8R9vEs4j/b316MV+0rzC2Qmf8KEWm5yWYPj7KejrldIK1IBMoCtX ZRQhVQx4t9I2RM2mjkZgepqikAHTsO404GptBIaGMFUofCiCDzbZkMfBRVj+MwEN7mvd svM6Wvzi7p4hRHt1zzYtdu+lASuxn4fKrWMJFkLfgjuVx08a4RCY5av+MmvZtlM9ogrG WdNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=y05AWxwwzaziUJ8pCZoL9SnezJMN/Sm3ZMoU593tH5o=; b=0IDmvPfSuo0kK6Gqniks/8Q9Aj6rnFk+fdMmScH5v1KHdq/pjB0hhPshUqOUfqFO7e Cv9M6eFJvb7K2T0AAYdrUuIrIydjefLBPtoQ1DuiI54zKGGHdPdjcWoWv80AZtKPDZBZ hEXE4ukwg5k9kPlgZVIjGJkc+V3kVvbaBloGa579DwS+BqNlzpIblHsZkNeogRJ+ohNL v0tnjsIiMxQmcNp+Wm4lmnjC6KeT263DxCmXEGeJXlAO+dJU7+HSfDHP61G8hot2EZ8S 9hUCGgLx2BNY5hdaFBNbCTAtZB7/OG/H9NSu8QlPk54k6A4qAfTwbBv4CkwFRgo1Eyf4 g2tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hzYZPrP6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si3032740ply.91.2017.09.24.13.02.11; Sun, 24 Sep 2017 13:02:11 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hzYZPrP6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753150AbdIXUCI (ORCPT + 26 others); Sun, 24 Sep 2017 16:02:08 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:48611 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752900AbdIXUAm (ORCPT ); Sun, 24 Sep 2017 16:00:42 -0400 Received: by mail-wm0-f52.google.com with SMTP id m127so14363903wmm.3 for ; Sun, 24 Sep 2017 13:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y05AWxwwzaziUJ8pCZoL9SnezJMN/Sm3ZMoU593tH5o=; b=hzYZPrP6BgbH2JxawfdImDq+QqbzDgrnP2ErEQcGV9BFhSJbTZE/vVxWLbohLYFnS3 qBIpwhNxByzHdI3TKW5b7KtSJ//Y148nxNASgBn/r/IqBSwvaVRncfto378tXXjScalz s181uiKOznoE8mhyLB/liyt+Ma6mb9znu2LtEs1Z2wp1A1KdE3ptiowsmuj6hNHGMH0P 5fZR/Iuc9SLw912CSdHaf7Vtgt42RaFhAVma5MB4nyAxH8tLHYL/k4HXzFK1SCPVsoI1 WELCz8vXtFTBNIQf4ea0kUZ7IzyZ2qJN0/4i47BwAJPvrNO8D74UsLk0VCaMbFpVyWHW eX8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y05AWxwwzaziUJ8pCZoL9SnezJMN/Sm3ZMoU593tH5o=; b=LUxSWTh2K2Bfdsls6eEiz+expaDRsc1CyWRtdvOS7I+dnuTwYSRrmn/5uaH2hLheib mfQ9iKbsb6kP3luWLwc33Htdmmic8eEdFs8Pif3OOVjEPwhNXCeicXqc4cNOuJCHj6Ex qz0s8lfVWee3PhzcU7gmYe37M+XoMDatC1l2Md6g68u9dILhKVhVJYQbrXWPCg+GRvuN oHig5cXlEOmL/HJi0hQSgYkWbnvR1DUif/LFURAMg1WR5HFaqCktWP+CZHUbUrpnajEC GYAvUy68dk40w7DyEzmXNqUAgZyBOGF7IfP+gq1GqSFUNtQui2KrUVw1IOqxECxk39SP v2vQ== X-Gm-Message-State: AHPjjUjHOXO27i33Aytw0W4sNw/QtKlaSXZsqQLOnCKJD5MV5ObFonmu t5/J46S+rbspRfaQ18agqleXkA== X-Google-Smtp-Source: AOwi7QB3avSopLm97A/OvkmSrUlQokMwpCFHpSwEHZYc5MMia+s26OGEts4/7fln2BeRTjHZqjfVhw== X-Received: by 10.28.58.136 with SMTP id h130mr7875764wma.56.1506283241380; Sun, 24 Sep 2017 13:00:41 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:40 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 04/10] clk: rework calls to round and determine rate callbacks Date: Sun, 24 Sep 2017 22:00:24 +0200 Message-Id: <20170924200030.6227-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rework the way the callbacks round_rate() and determine_rate() are called. The goal is to do this at a single point and make it easier to add conditions before calling them. Because of this factorization, rate returned by determine_rate() is also checked against the min and max rate values This rework is done to ease the integration of "protected" clock functionality. Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 82 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 30 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 0913688dacb0..0905139a1893 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -833,10 +833,9 @@ static int clk_disable_unused(void) } late_initcall_sync(clk_disable_unused); -static int clk_core_round_rate_nolock(struct clk_core *core, - struct clk_rate_request *req) +static int clk_core_determine_round_nolock(struct clk_core *core, + struct clk_rate_request *req) { - struct clk_core *parent; long rate; lockdep_assert_held(&prepare_lock); @@ -844,15 +843,6 @@ static int clk_core_round_rate_nolock(struct clk_core *core, if (!core) return 0; - parent = core->parent; - if (parent) { - req->best_parent_hw = parent->hw; - req->best_parent_rate = parent->rate; - } else { - req->best_parent_hw = NULL; - req->best_parent_rate = 0; - } - if (core->ops->determine_rate) { return core->ops->determine_rate(core->hw, req); } else if (core->ops->round_rate) { @@ -862,15 +852,58 @@ static int clk_core_round_rate_nolock(struct clk_core *core, return rate; req->rate = rate; - } else if (core->flags & CLK_SET_RATE_PARENT) { - return clk_core_round_rate_nolock(parent, req); } else { - req->rate = core->rate; + return -EINVAL; } return 0; } +static void clk_core_init_rate_req(struct clk_core * const core, + struct clk_rate_request *req) +{ + struct clk_core *parent; + + if (WARN_ON(!core || !req)) + return; + + parent = core->parent; + if (parent) { + req->best_parent_hw = parent->hw; + req->best_parent_rate = parent->rate; + } else { + req->best_parent_hw = NULL; + req->best_parent_rate = 0; + } +} + +static bool clk_core_can_round(struct clk_core * const core) +{ + if (core->ops->determine_rate || core->ops->round_rate) + return true; + + return false; +} + +static int clk_core_round_rate_nolock(struct clk_core *core, + struct clk_rate_request *req) +{ + lockdep_assert_held(&prepare_lock); + + if (!core) + return 0; + + clk_core_init_rate_req(core, req); + + if (clk_core_can_round(core)) + return clk_core_determine_round_nolock(core, req); + else if (core->flags & CLK_SET_RATE_PARENT) + return clk_core_round_rate_nolock(core->parent, req); + + req->rate = core->rate; + return 0; +} + /** * __clk_determine_rate - get the closest rate actually supported by a clock * @hw: determine the rate of this clock @@ -1356,34 +1389,23 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core, clk_core_get_boundaries(core, &min_rate, &max_rate); /* find the closest rate and parent clk/rate */ - if (core->ops->determine_rate) { + if (clk_core_can_round(core)) { struct clk_rate_request req; req.rate = rate; req.min_rate = min_rate; req.max_rate = max_rate; - if (parent) { - req.best_parent_hw = parent->hw; - req.best_parent_rate = parent->rate; - } else { - req.best_parent_hw = NULL; - req.best_parent_rate = 0; - } - ret = core->ops->determine_rate(core->hw, &req); + clk_core_init_rate_req(core, &req); + + ret = clk_core_determine_round_nolock(core, &req); if (ret < 0) return NULL; best_parent_rate = req.best_parent_rate; new_rate = req.rate; parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; - } else if (core->ops->round_rate) { - ret = core->ops->round_rate(core->hw, rate, - &best_parent_rate); - if (ret < 0) - return NULL; - new_rate = ret; if (new_rate < min_rate || new_rate > max_rate) return NULL; } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { From patchwork Sun Sep 24 20:00:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114149 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1854496qgf; Sun, 24 Sep 2017 13:01:25 -0700 (PDT) X-Received: by 10.98.237.18 with SMTP id u18mr5339194pfh.251.1506283285626; Sun, 24 Sep 2017 13:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283285; cv=none; d=google.com; s=arc-20160816; b=pzKPDXE56/UqtVwKVO7smhgtgRia9+mxROMG/QEReABPKGdek7pJK/FvgQCkoCH/F4 ekDnp5tcOVKRIVVRXbVFcHnpZki8ZT1EXz7ty8VURefFenvDIjzD/0Z/pGOVs34eG44+ Kc8k9gR59q/SBnX+pr2f86jOQceMpSHA6NhkLzFQcP/K9EYoysgT3/LTuV9XUxbmlCkc m1P5fEJdC/thj/fuTa2U0MlzJJdtM9/XKQ9rrJ0Cer8aJAVJPTQie2N91bb0JLg5llKx BlbiPWLdMPLQ66cVybs7gy5RepPV3Xi10wujp+265CKTbra0RcKq78+5HjRaqtHdV9Xb pyaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1XJ5txoH3FfDeXms2SPHVoUXCF7dKj5iGGdchcRZZH0=; b=uxOweclbuLLqbp0HFPbl5f1EXAAK0QnMtIdo4TQivl8JGgoQ9Kyr4BDg4RFhLRx3f0 QYIGfBB8UCU+7HPk1kLbMZoA8wSz+C5kAjphZNZI281eSQv1KnGUbR9TuewpkMk2VV9q rWX7mvH6hxKxId0YVb+kf49/Vb0BH9350x72ajW3UqD+bDdKMKqYtQhPFzoa6EpZ79WP rnRkFMsAQX5inBlw8rESgHjK3lZ51D0zHi2HCOpGKawTdt/Js39vZW9oMv3UY8ANAQMi 1FATFisbDbvYWVvkgwGvxfNTy0ISxbl8jjmeOMHc36UqaC1EETru1PDcrAR3y9t5OWr6 oPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JaXr+rVf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si3054647plm.785.2017.09.24.13.01.25; Sun, 24 Sep 2017 13:01:25 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JaXr+rVf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752945AbdIXUAs (ORCPT + 26 others); Sun, 24 Sep 2017 16:00:48 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:48614 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbdIXUAn (ORCPT ); Sun, 24 Sep 2017 16:00:43 -0400 Received: by mail-wm0-f45.google.com with SMTP id m127so14363975wmm.3 for ; Sun, 24 Sep 2017 13:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1XJ5txoH3FfDeXms2SPHVoUXCF7dKj5iGGdchcRZZH0=; b=JaXr+rVf8MLFfrqncoxU7+JvYAaGZZjIlLyHZzefeZo4z+84psFX2ZzC6XXZuZkUk5 H+TlAMs7GTigMK4C5C2P07gZz7uqrS47EvcD5MgYDhETQRuvLozUzvmtzNFPBTB1KN90 636q287vX4M0XzdJE0u5iHRtLVfsbt5WZLxLfTCLbf97qFOTbJtKnvRFeg7SKwHGxFnQ tC/1k341/m9+Joz4EHveOzl2jutu4MnH4lqSFL80sy4OvHN8y5ohduHfGIwNeazHsLQA Ym2r1yv5ltTHhjtxDIlAK+EJxRuOgP2eq9T5y3/HbR2RSGRfMu2/c7G3q5sM109+hno2 NtmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1XJ5txoH3FfDeXms2SPHVoUXCF7dKj5iGGdchcRZZH0=; b=MKd3KtKV8vJj7TmVplQfkfX4iJdrttgASe3sdHEsSvFpaZbYwXdEcIBo5B4kVp2JbF x3qKVMHaitk3TYIZDTXDO9HDc/o7DhMmf4kqSXeRr5WZ/fEFdkPEBrE6zWtrl6hQKliX 3nLcLyi/6sB5mLbPA2LWt1hzlZeiGdsAEwyWUmi8AMN7aimfxZRJLFlkH1e3Q1pWmcqP 9xe5o2l4YmowUMeO0Yy0fAfWKZhxckO4WTWGUTwQf5idcOhnaGnMY6bMMbWT5nGx1LvR P66mjt3P0U/StgfdY1jrTrleSojHKFWV9U3iGt9Z4NTnbNsulQyWHleBeP5U7mN6mq5v 8/Kw== X-Gm-Message-State: AHPjjUg/73ZjjI2QZ2s1qgaJhkQt6ZiWLM02bNjzY5bF75KCSyeQEob7 XQiA3WAHG5X0oyt18A4zAXik1w== X-Google-Smtp-Source: AOwi7QB1pUc4od7iGlxfjb3oV8YVk6pKCmtnxD+y5u/Qc89fnu/1YNKVqPlG87H6kO4H+7y2OZ7ysw== X-Received: by 10.28.18.210 with SMTP id 201mr7656430wms.135.1506283242513; Sun, 24 Sep 2017 13:00:42 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:42 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 05/10] clk: use round rate to bail out early in set_rate Date: Sun, 24 Sep 2017 22:00:25 +0200 Message-Id: <20170924200030.6227-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of clk_core_set_rate_nolock() bails out early if the requested rate is exactly the same as the one set. It should bail out if the request would not result in a rate a change. This is important when the rate is not exactly what is requested, which is fairly common with PLLs. Ex: provider able to give any rate with steps of 100Hz - 1st consumer request 48000Hz and gets it. - 2nd consumer request 48010Hz as well. If we were to perform the usual mechanism, we would get 48000Hz as well. The clock would not change so there is no point performing any checks to make sure the clock can change, we know it won't. This is important to prepare the addition of the clock protection mechanism Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 0905139a1893..44022299741a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1582,15 +1582,36 @@ static void clk_change_rate(struct clk_core *core) clk_change_rate(core->new_child); } +static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, + unsigned long req_rate) +{ + int ret; + struct clk_rate_request req; + + lockdep_assert_held(&prepare_lock); + + if (!core) + return 0; + + clk_core_get_boundaries(core, &req.min_rate, &req.max_rate); + req.rate = req_rate; + + ret = clk_core_round_rate_nolock(core, &req); + + return ret ? 0 : req.rate; +} + static int clk_core_set_rate_nolock(struct clk_core *core, unsigned long req_rate) { struct clk_core *top, *fail_clk; - unsigned long rate = req_rate; + unsigned long rate; if (!core) return 0; + rate = clk_core_req_round_rate_nolock(core, req_rate); + /* bail early if nothing to do */ if (rate == clk_core_get_rate_nolock(core)) return 0; @@ -1599,7 +1620,7 @@ static int clk_core_set_rate_nolock(struct clk_core *core, return -EBUSY; /* calculate new rates and get the topmost changed clock */ - top = clk_calc_new_rates(core, rate); + top = clk_calc_new_rates(core, req_rate); if (!top) return -EINVAL; From patchwork Sun Sep 24 20:00:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114146 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1853938qgf; Sun, 24 Sep 2017 13:00:53 -0700 (PDT) X-Received: by 10.84.132.104 with SMTP id 95mr5549999ple.231.1506283253335; Sun, 24 Sep 2017 13:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283253; cv=none; d=google.com; s=arc-20160816; b=nmhUH5vN8X0Q0MUyEuG2UVAOC7vSAT4frH+u69tYf49GvUEKWCDyuiORrstfCi5WcX yavP2arsiqWkUbt5sc+YahLW8uDSN4VYB/i+mwAIMEGDI0EwTWwNYW7Y0d7t0X2/mc2Z zu5Hzki7bPKyHv2rhs7Kd6LuEfqFN/Mdax63t+ZpP+QjUyYbtpxgGt0KBvwEAkSJ8Hfr JSVVEYKhFZjB7Q1F/OARLOqOK2THqCKrdY80ceUwa5B0qHv3EoxvjXp/rHxRP8bYBmGv tAYQ4rT6bNHXSU8AbjAaDZSlz1PFKD3Y1Z/xe+uVR2Zhz2t62QoZnq54ZsinAKafpRqw JdlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=iaE7PxSH5wW5fB975G6L2rlKMRUJ2aj/nK+NcjD57mg=; b=Fu73VGwVmAXOPwt7oA1MtU4+t+U9trSelZt6T3772dvNztHsj7TNq7K+qLGRiuS0UL U8qwfARQXElE38KDr1epB11NiOu+Bxptdb8H0pOQz9PZc2GRdtX1u0oEQzxPH/+tq54m rf3NHbIIKhLiQdnMoS84GMKR8PB8EWJiKQsotoKmbjt9sfmsvkaBXq1TqVBkRsgKdwHd zypaV3HEdwX14cJ+7N1pG13d/R6sS+aOYv7LFguYYs5ZMB7SIW78WtOY0dzen2yJnKbu 112x20TfTMzLmjNIBCBLdTEejilWKj9zlSv4Y1hGF9G1cJvtx8KrPNyWxZ6c7guk5ftD w2uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=oAURrvBr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si2938674pfl.0.2017.09.24.13.00.53; Sun, 24 Sep 2017 13:00:53 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=oAURrvBr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752965AbdIXUAu (ORCPT + 26 others); Sun, 24 Sep 2017 16:00:50 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:53883 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752919AbdIXUAp (ORCPT ); Sun, 24 Sep 2017 16:00:45 -0400 Received: by mail-wr0-f170.google.com with SMTP id l22so4666469wrc.10 for ; Sun, 24 Sep 2017 13:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iaE7PxSH5wW5fB975G6L2rlKMRUJ2aj/nK+NcjD57mg=; b=oAURrvBrRY+aufJBijJ+60azHbweBGJBy1TDLstdy7/leTAnsoXJPt22D1NxRWuOz9 S17soN64MMFJrUGze2K+WeCCsrCYucu5k4WGYJ/GmhM/QIPPKObjcp+aVawSJGW5VsHO e0ANgqwbM9JzSB8vgICADjgATJegaD1u4ofdPQr+gAcEXLXghBlu2rjcjSOS1LFiWsU8 gZ2bvnnVTwkBKHikTYjmNtAQrQj5Apw+91bhCM0v/UaU0JHwNlcdnazlVa3X6PFUculZ 80UXPyNHsyFNbY0roez/9qg4nU23WGwRMnBVQK7V7ABy1bYCdABx8g7YWLUNcXkHePki +ygg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iaE7PxSH5wW5fB975G6L2rlKMRUJ2aj/nK+NcjD57mg=; b=ozZ0r6QQASwQTNj6eGE8zIlmd2XQFGTOKBvR+1bTIrwO4RbSlvGbAiU82wzueMSiyz Mra5TlY/9n5pQ5yCV+mAS9W0PE8pLuGosOmZedEO6yrM2NTAYaJzcYxFWwD3FV66/luS KULfWSv60NLK3pagPOqB/NKxZQGxRqMvDHKG1YTC8M4i9Zgo63dzGbJu0IYUNMMRLAEV VMJfRY6V145Qr9jrqlCnvcebtP/GTl5Up/zLv+oEBir9huOkN3rgLUlgOZSD4OD0kScg pft8RGTwF72ee98qFpmYnIfYmgkyJW9eW3pkoGnciIycY0ulD1cK/coeC3PjGY4UoAwB MF2g== X-Gm-Message-State: AHPjjUik/LJxl/FbaVcSqCiO+C1iJ4YaDggDG8byfrrvP/6MsECh1EPw 4h/qaQO/xEtdgXlQwEUmjqPC5w== X-Google-Smtp-Source: AOwi7QAIdzcewS8LJenfZ9F93CaRvBssCD7f/y4C5GgKuNNUADaPmJAaOBEvR2cAkqceVobf+We5FA== X-Received: by 10.223.160.170 with SMTP id m39mr3894501wrm.174.1506283243813; Sun, 24 Sep 2017 13:00:43 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:43 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 06/10] clk: add clock protection mechanism to clk core Date: Sun, 24 Sep 2017 22:00:26 +0200 Message-Id: <20170924200030.6227-7-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch adds clk_core_protect and clk_core_unprotect to the internal CCF API. These functions allow to set a new constraint along the clock tree to prevent any change, even indirect, which may result in rate change or glitch. Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 119 ++++++++++++++++++++++++++++++++++++++++--- include/linux/clk-provider.h | 1 + 2 files changed, 113 insertions(+), 7 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 44022299741a..9d371088bb24 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -60,6 +60,7 @@ struct clk_core { bool orphan; unsigned int enable_count; unsigned int prepare_count; + unsigned int protect_count; unsigned long min_rate; unsigned long max_rate; unsigned long accuracy; @@ -148,6 +149,11 @@ static void clk_enable_unlock(unsigned long flags) spin_unlock_irqrestore(&enable_lock, flags); } +static bool clk_core_rate_is_protected(struct clk_core *core) +{ + return core->protect_count; +} + static bool clk_core_is_prepared(struct clk_core *core) { /* @@ -328,6 +334,11 @@ bool clk_hw_is_prepared(const struct clk_hw *hw) return clk_core_is_prepared(hw->core); } +bool clk_hw_rate_is_protected(const struct clk_hw *hw) +{ + return clk_core_rate_is_protected(hw->core); +} + bool clk_hw_is_enabled(const struct clk_hw *hw) { return clk_core_is_enabled(hw->core); @@ -466,6 +477,68 @@ EXPORT_SYMBOL_GPL(__clk_mux_determine_rate_closest); /*** clk api ***/ +static void clk_core_rate_unprotect(struct clk_core *core) +{ + lockdep_assert_held(&prepare_lock); + + if (!core) + return; + + if (WARN_ON(core->protect_count == 0)) + return; + + if (--core->protect_count > 0) + return; + + clk_core_rate_unprotect(core->parent); +} + +static int clk_core_rate_nuke_protect(struct clk_core *core) +{ + int ret; + + lockdep_assert_held(&prepare_lock); + + if (!core) + return -EINVAL; + + if (core->protect_count == 0) + return 0; + + ret = core->protect_count; + core->protect_count = 1; + clk_core_rate_unprotect(core); + + return ret; +} + +static void clk_core_rate_protect(struct clk_core *core) +{ + lockdep_assert_held(&prepare_lock); + + if (!core) + return; + + if (core->protect_count == 0) + clk_core_rate_protect(core->parent); + + core->protect_count++; +} + +static void clk_core_rate_restore_protect(struct clk_core *core, int count) +{ + lockdep_assert_held(&prepare_lock); + + if (!core) + return; + + if (count == 0) + return; + + clk_core_rate_protect(core); + core->protect_count = count; +} + static void clk_core_unprepare(struct clk_core *core) { lockdep_assert_held(&prepare_lock); @@ -843,7 +916,9 @@ static int clk_core_determine_round_nolock(struct clk_core *core, if (!core) return 0; - if (core->ops->determine_rate) { + if (clk_core_rate_is_protected(core)) { + req->rate = core->rate; + } else if (core->ops->determine_rate) { return core->ops->determine_rate(core->hw, req); } else if (core->ops->round_rate) { rate = core->ops->round_rate(core->hw, req->rate, @@ -1585,7 +1660,7 @@ static void clk_change_rate(struct clk_core *core) static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, unsigned long req_rate) { - int ret; + int ret, cnt; struct clk_rate_request req; lockdep_assert_held(&prepare_lock); @@ -1593,11 +1668,19 @@ static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, if (!core) return 0; + /* simulate what the rate would be if it could be freely set */ + cnt = clk_core_rate_nuke_protect(core); + if (cnt < 0) + return cnt; + clk_core_get_boundaries(core, &req.min_rate, &req.max_rate); req.rate = req_rate; ret = clk_core_round_rate_nolock(core, &req); + /* restore the protection */ + clk_core_rate_restore_protect(core, cnt); + return ret ? 0 : req.rate; } @@ -1616,6 +1699,10 @@ static int clk_core_set_rate_nolock(struct clk_core *core, if (rate == clk_core_get_rate_nolock(core)) return 0; + /* fail on a direct rate set of a protected provider */ + if (clk_core_rate_is_protected(core)) + return -EBUSY; + if ((core->flags & CLK_SET_RATE_GATE) && core->prepare_count) return -EBUSY; @@ -1853,6 +1940,9 @@ static int clk_core_set_parent_nolock(struct clk_core *core, if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) return -EBUSY; + if (clk_core_rate_is_protected(core)) + return -EBUSY; + /* try finding the new parent index */ if (parent) { p_index = clk_fetch_parent_index(core, parent); @@ -1927,6 +2017,9 @@ static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) if (!core) return 0; + if (clk_core_rate_is_protected(core)) + return -EBUSY; + trace_clk_set_phase(core, degrees); if (core->ops->set_phase) @@ -2057,11 +2150,12 @@ static void clk_summary_show_one(struct seq_file *s, struct clk_core *c, if (!c) return; - seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu %-3d\n", + seq_printf(s, "%*s%-*s %11d %12d %12d %11lu %10lu %-3d\n", level * 3 + 1, "", 30 - level * 3, c->name, - c->enable_count, c->prepare_count, clk_core_get_rate(c), - clk_core_get_accuracy(c), clk_core_get_phase(c)); + c->enable_count, c->prepare_count, c->protect_count, + clk_core_get_rate(c), clk_core_get_accuracy(c), + clk_core_get_phase(c)); } static void clk_summary_show_subtree(struct seq_file *s, struct clk_core *c, @@ -2083,8 +2177,8 @@ static int clk_summary_show(struct seq_file *s, void *data) struct clk_core *c; struct hlist_head **lists = (struct hlist_head **)s->private; - seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n"); - seq_puts(s, "----------------------------------------------------------------------------------------\n"); + seq_puts(s, " clock enable_cnt prepare_cnt protect_cnt rate accuracy phase\n"); + seq_puts(s, "----------------------------------------------------------------------------------------------------\n"); clk_prepare_lock(); @@ -2119,6 +2213,7 @@ static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level) seq_printf(s, "\"%s\": { ", c->name); seq_printf(s, "\"enable_count\": %d,", c->enable_count); seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); + seq_printf(s, "\"protect_count\": %d,", c->protect_count); seq_printf(s, "\"rate\": %lu,", clk_core_get_rate(c)); seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy(c)); seq_printf(s, "\"phase\": %d", clk_core_get_phase(c)); @@ -2249,6 +2344,11 @@ static int clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) if (!d) goto err_out; + d = debugfs_create_u32("clk_protect_count", S_IRUGO, core->dentry, + (u32 *)&core->protect_count); + if (!d) + goto err_out; + d = debugfs_create_u32("clk_notifier_count", S_IRUGO, core->dentry, (u32 *)&core->notifier_count); if (!d) @@ -2812,6 +2912,11 @@ void clk_unregister(struct clk *clk) if (clk->core->prepare_count) pr_warn("%s: unregistering prepared clock: %s\n", __func__, clk->core->name); + + if (clk->core->protect_count) + pr_warn("%s: unregistering protected clock: %s\n", + __func__, clk->core->name); + kref_put(&clk->core->ref, __clk_release); unlock: clk_prepare_unlock(); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 5100ec1b5d55..2a225a820cfe 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -744,6 +744,7 @@ unsigned long clk_hw_get_rate(const struct clk_hw *hw); unsigned long __clk_get_flags(struct clk *clk); unsigned long clk_hw_get_flags(const struct clk_hw *hw); bool clk_hw_is_prepared(const struct clk_hw *hw); +bool clk_hw_rate_is_protected(const struct clk_hw *hw); bool clk_hw_is_enabled(const struct clk_hw *hw); bool __clk_is_enabled(struct clk *clk); struct clk *__clk_lookup(const char *name); From patchwork Sun Sep 24 20:00:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114151 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1854882qgf; Sun, 24 Sep 2017 13:01:48 -0700 (PDT) X-Received: by 10.98.79.157 with SMTP id f29mr5408402pfj.9.1506283308144; Sun, 24 Sep 2017 13:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283308; cv=none; d=google.com; s=arc-20160816; b=ntGxNDEcqp3MWW9NYAgMZA4TmSHpkAmVtk7BvdTJR9lH/kPkmpNt07Ri44g6w/7lO/ mqDyLYZDgis0+5QeCIJ183q6BUBt3Wm1KfCQJCXmMUd4SX3p8vhCngbotlxHydHn3Kb9 GMUFtd0IRxf4kUI4JQyyTCRqfXSUIUqCz8Rd5oaBtHtW6kgzgBw8PhFCTxyUDaxI8pQh hHKv1baOm+iVyVOE6s7Qym+sVt65eCnxD78xze+f6UiQMinO8r/BSUqaWxjIosNiwfW3 KSwXJE46cbq6LXlWBJV3yNBD/JedZ5BtW5wVGvI/SaSlVIkMVlrmAKkdwUsoutvFPYql elXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Z7jxGc+sSe2/sAo8NyeM6/yfNWgiSW/bDrjIpnEllvA=; b=eKvtTHT2+7GcJm3yYlNT4wnIUwfCP4L/Ms6BjDXz1g+72LUSiUwRLXlZHeFIm7lYYJ 2ncZLayyuZbu6IO2COM45OguoSi0iUdC1iTVVNdgh2rYf8uwj/9BR1fXgAn02AwpD3A1 S/zCQ895hT3z6cC2vyM+14fH/22h3pk1K5QHWtgY15o1CNQlY88iI5+iZaMVoHNPTBf0 gvqzHtRPECT0bSw3FVMijTeGA7oRgzs+T4X1hA/94jwzbMRmfmzOJXOkdR0LDDphAuWl a3NGCF9bOZRr2dMIkf9GbLnd5aEIo+M0J3vgxjIMOuD/0zRjc+XnRzhBINmliEaJJR8A 2fCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=gv72TBUv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si3011308pge.537.2017.09.24.13.01.47; Sun, 24 Sep 2017 13:01:48 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=gv72TBUv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753097AbdIXUBq (ORCPT + 26 others); Sun, 24 Sep 2017 16:01:46 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:57192 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752924AbdIXUAq (ORCPT ); Sun, 24 Sep 2017 16:00:46 -0400 Received: by mail-wr0-f181.google.com with SMTP id r74so4608392wrb.13 for ; Sun, 24 Sep 2017 13:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Z7jxGc+sSe2/sAo8NyeM6/yfNWgiSW/bDrjIpnEllvA=; b=gv72TBUvkps70Yrqi0dSs4PFk7SAOgOOtUpoKchXl/E6uKJ6ggHNWop6DrV2CSvj8Q o/nn1CzhOklErTvYPuOefC4b1BbE2gFcUYGGzLVCuzCZheeLm9CRjSkOD3hKHxXo6z6y ClV54lY1gCw8WMDTrmEqIxreOOF4EVqFpWYr8StBqywRGqwQru6j8yDYhqUZjQtdv8Wo DvE+6Z9FQMvYi1H3u17WCBel/5CCIS+/+3Xvo/5jJ1lvTqCQ8DvyXRwgA+7l/+4dNLCh hxi2e/9Xo56INGZd8XpYTZkcsehle+F9smVF6o6tEh8/uwWdgZs+tEuzjQlYSyKFbKHU mReg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Z7jxGc+sSe2/sAo8NyeM6/yfNWgiSW/bDrjIpnEllvA=; b=leZn3lR2C56jye/7skE5qEOGSFYkHyhiQiy2GF+S7pro+xNad/9XtJUy6HXyzm9xwN 1rUgIZLx6KOJHKSaXJ+4H7cLW0yVqf11FMXhA/swGfc1IHK70DY8VFu/rRhCwhaG4F2I iJlgQ2vRZoQ+3C3KScBNAoVAucZYQJBMjHbbDI1f5wVJB3602gK99PfJXyvFyLLVus97 SbOESDbxS7eMkwKThTGdD+cvEWu+bnjZ/E3Fr7kX5wh1FrujMTrVq5QfNOTgB4RhQCPa w+NxEBTZ4F8RubCe3/eRBk2e7/uHHiAyCYoWIq9HbTsmJd77cq9ci2E114DqkMMByNVw doZQ== X-Gm-Message-State: AHPjjUi+dmSkD1tBlddqzyGvHwDQcjYCgJFmHgsNX3mvia2i99EoBUGR ZcpFE8GEbKLZTGO5RDSGJAp+1A== X-Google-Smtp-Source: AOwi7QBongu5Gw4y1GTay3jA9+WEWgOPEl3hEYLBHK2PMqpi4n9/RTD1WGb8mDvI5LOXulzD/gjWwQ== X-Received: by 10.223.166.21 with SMTP id k21mr3907430wrc.261.1506283245229; Sun, 24 Sep 2017 13:00:45 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:44 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 07/10] clk: cosmetic changes to clk_summary debugfs entry Date: Sun, 24 Sep 2017 22:00:27 +0200 Message-Id: <20170924200030.6227-8-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org clk_summary debugfs entry was already well over the traditional 80 characters per line limit but it grew even larger with the addition of clock protection. clock enable_cnt prepare_cnt protect_cnt rate accuracy phase ---------------------------------------------------------------------------------------------------- wifi32k 1 1 0 32768 0 0 vcpu 0 0 0 2016000000 0 0 xtal 5 5 0 24000000 0 0 This patch reduce the width a bit: enable prepare protect clock count count count rate accuracy phase ---------------------------------------------------------------------------------------- wifi32k 1 1 0 32768 0 0 vcpu 0 0 0 2016000000 0 0 xtal 5 5 0 24000000 0 0 Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 9d371088bb24..4693d5e20327 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2150,7 +2150,7 @@ static void clk_summary_show_one(struct seq_file *s, struct clk_core *c, if (!c) return; - seq_printf(s, "%*s%-*s %11d %12d %12d %11lu %10lu %-3d\n", + seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu %-3d\n", level * 3 + 1, "", 30 - level * 3, c->name, c->enable_count, c->prepare_count, c->protect_count, @@ -2177,8 +2177,9 @@ static int clk_summary_show(struct seq_file *s, void *data) struct clk_core *c; struct hlist_head **lists = (struct hlist_head **)s->private; - seq_puts(s, " clock enable_cnt prepare_cnt protect_cnt rate accuracy phase\n"); - seq_puts(s, "----------------------------------------------------------------------------------------------------\n"); + seq_puts(s, " enable prepare protect \n"); + seq_puts(s, " clock count count count rate accuracy phase\n"); + seq_puts(s, "----------------------------------------------------------------------------------------\n"); clk_prepare_lock(); From patchwork Sun Sep 24 20:00:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114150 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1854670qgf; Sun, 24 Sep 2017 13:01:34 -0700 (PDT) X-Received: by 10.99.96.75 with SMTP id u72mr5369335pgb.178.1506283294778; Sun, 24 Sep 2017 13:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283294; cv=none; d=google.com; s=arc-20160816; b=VPL4Oge3TdJYxvOsXoujBkUhKthyQt77ZOTYzOUTTbGxrf4uFD8Ot1Amf1tlgukUlM FBcYdSq3U352rcrPR/Zhww2HNv8SHPl3YGOed4BLlncjhWJKLz9CYPhjgbllSN4LLMyo 17aubzTxvcm51I30ZS3cQ55tzcfqbuXDAcf/PQBMfonVBIm2JpXJdKhQheZ3AAHfLNAa Db+nyYwVuOfRA4h5OTVOZLqwR2AxY4zdyYu94JlUFYhSX0ZENDo7+5P8807iEtyWF3SL /LFt4JA2psHOg09DZwLS/sCV+PWmr6s0qko2Gn11tXTOQiRiiUfZQ/FcF7xOBO/hpZ0v uSBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=/7Csb6egYLxWHN7fH1w9p0UP7+fYBSJZSIfCHGL15tg=; b=QdxQ6Mb17Sf2YQSfwXLidOtSklPybwf9Xwor3P3Byl2pou7rHhYmxbOKn/TkPNN4le LGe0tQ3o10+SqNyNBIFnWDEUBWu38NZWArD0BTXUdgON4b+vvqULxNrRvlMJUFvYi05Y pd9xFbIn0LJIHtJmV5tgByWtcJCfEaJisFyrxoodjncmhnoGA0YOWcrU4gZEA/N5tv56 C7/VXrr/Gd7vsjvksWHl0iaJlhmO+6aOmLEzHgq/sCK9jDbF9WUwxrqS3rntcpdSz5V6 RO/vQunotd2wtuxprubCDwF5+1+hFzNB5gwiNYkJrF+iwY6fWl44WUr1YtF9u93XZme4 tz9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=O5E/bx9J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si1525478pgp.214.2017.09.24.13.01.34; Sun, 24 Sep 2017 13:01:34 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=O5E/bx9J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753066AbdIXUBc (ORCPT + 26 others); Sun, 24 Sep 2017 16:01:32 -0400 Received: from mail-wr0-f175.google.com ([209.85.128.175]:49209 "EHLO mail-wr0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752921AbdIXUAr (ORCPT ); Sun, 24 Sep 2017 16:00:47 -0400 Received: by mail-wr0-f175.google.com with SMTP id u96so4612012wrb.6 for ; Sun, 24 Sep 2017 13:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/7Csb6egYLxWHN7fH1w9p0UP7+fYBSJZSIfCHGL15tg=; b=O5E/bx9JK1h4zfmFDXACW8R70rFxhBcs5kOrdAkbI7JowgCtSEOpTYYxFARQCHju6C hb5bMbpczwr11I7ICSgs48aue4yIWfaNfTcdNFPgQe7DCz07KnxdQVc1MBKvutRPr5W2 52+xkjKlNJf0Im9pLtj9uQqXLIqlxwp3efHHFenLwmdXdRf2vSOe9OBbA27O4yLerGhT m2AlnAoL6b4ihLeoqafk5XdKyD5hN+ZUxQyf+/ujb2RtVE6rHRoKho0MWOXQQ22G2Q32 TFZDpe8GSyrVCKVhSW4jtoFl7/wwJDiPQuUxzPbhR3vCtnZtQSvylzkC3XvXtd6lEqmA TdUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/7Csb6egYLxWHN7fH1w9p0UP7+fYBSJZSIfCHGL15tg=; b=Lbg8O03VxNeNOmLp9zPk0U4rwzAy2B0zUevfe7hr3nwHLG3DPAy2ibVdvEWq4vWRBu +2tvkC4UbIR0GUB9Z6Xrfe0yoHqO2Ji0TKTkOEEJI/BkjzOc1ozX87wFrICyUPCJ2wvV FiyV/J3j1bz/B/l0mqAltPvzLOFGoijef9hHzvKfYdv6hm9ak+87azsUkq2EyYxkmjjd 2PqEIUQkWllH9F1KT97r1cEHKrKN4ZDMpyiXi+GrtQLucmkEnIu2tebSTrTFHORMoC9f ZedhnJ0jcSACseoJYb0AFUE0jAjHkP7afXUqv4t3KrbAu9cHpu1XSJWf1RnUiP7Cc++N h+/Q== X-Gm-Message-State: AHPjjUhPJ1bQz0fbRenfUtbkBONCUpUxBJU1IF3XBj5DB6gL7iYGilIW yDJFGvYyxmfgHX8Y33igjYrhsw== X-Google-Smtp-Source: AOwi7QAYteOyKbb1dXezK4tlPIM6X/lY0Ct9qyJ4mv7VyiNp2pYERM9b+sQzqS5UdqVIaaOLa+tL0g== X-Received: by 10.223.182.71 with SMTP id i7mr4012903wre.43.1506283246380; Sun, 24 Sep 2017 13:00:46 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:45 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 08/10] clk: fix CLK_SET_RATE_GATE with clock rate protection Date: Sun, 24 Sep 2017 22:00:28 +0200 Message-Id: <20170924200030.6227-9-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using clock rate protection, we can now enforce CLK_SET_RATE_GATE along the clock tree Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 4693d5e20327..f990ef127a83 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -552,6 +552,9 @@ static void clk_core_unprepare(struct clk_core *core) if (WARN_ON(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL)) return; + if (core->flags & CLK_SET_RATE_GATE) + clk_core_rate_unprotect(core); + if (--core->prepare_count > 0) return; @@ -622,6 +625,16 @@ static int clk_core_prepare(struct clk_core *core) core->prepare_count++; + /* + * CLK_SET_RATE_GATE is a special case of clock protection + * Instead of a consumer claiming exclusive rate control, it is + * actually the provider which prevents any consumer from making any + * operation which could result in a rate change or rate glitch while + * the clock is prepared. + */ + if (core->flags & CLK_SET_RATE_GATE) + clk_core_rate_protect(core); + return 0; } @@ -1703,9 +1716,6 @@ static int clk_core_set_rate_nolock(struct clk_core *core, if (clk_core_rate_is_protected(core)) return -EBUSY; - if ((core->flags & CLK_SET_RATE_GATE) && core->prepare_count) - return -EBUSY; - /* calculate new rates and get the topmost changed clock */ top = clk_calc_new_rates(core, req_rate); if (!top) From patchwork Sun Sep 24 20:00:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114148 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1854287qgf; Sun, 24 Sep 2017 13:01:13 -0700 (PDT) X-Received: by 10.98.12.134 with SMTP id 6mr5398122pfm.30.1506283273153; Sun, 24 Sep 2017 13:01:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283273; cv=none; d=google.com; s=arc-20160816; b=nI6NBYPjXN17U7yqiqDe8bG1W7xDKp8zkhAdYCPgXQSd98muQdYf09SIQX7Ou1f1Jv upFrV+EHLGIV21mxY9asiIQaSTZpm5bjLfZOc7kia9oXHm3496AfsjrTOf2Mw4An6KSD hA31zYta4YGnv6rGHINn5NavDh70H8NqSeePEBWciIVo8uEgeJmnCU/a7gxUq6lPhicG ywtDU2XALy2qe4AQ1Gx3SxUKkTbrxbYYprgNVMw+EZKZFMDrdJhuwCbctC7cIfaeC6Pt CHZQtOVAQiutpmYuGoBXnz4bUIVXp7dM8xHttPY2/h8nazO5ln3rTxwVyxzNRE/Fe86u Evxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=RW4Rrix1IPJlQp3Evo/kM1QRoq0yUSi+qlgaVRgPnb0=; b=S5lujkHZwYOOZHEIJUMpZynYCIYBHwtDpfYAlbCGfu9es3EH99vLoluMHalI5Bk14p U5YE4xdu/bXYUw0ZgS9GOmyi9qzCkPG8acPa/C3l5/yZnkRYYZnqmRiphXF2lj83XJBb BvjKLEbkiPIqEjbSPa7ToIXoEkkB0tlWC+l9j9cTMtUaCZbl4ZVhy0VHFrDSsebqyAA8 myqPwKGUTcXTLn8mUZR/LB37D3MR7ufX1/cWA1cJq2ZM0fehBpq7KhlVxq95nMeUfI4q lqtEBomZoR58zQhnP5pkHrio5R9mr6kUVRilwQKq5tHSqafMX4dYoGBFz6oJj3GZJwXe BvXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=sRQEXxB1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q25si1593499pgc.595.2017.09.24.13.01.12; Sun, 24 Sep 2017 13:01:13 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=sRQEXxB1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753025AbdIXUBL (ORCPT + 26 others); Sun, 24 Sep 2017 16:01:11 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:52345 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752922AbdIXUAt (ORCPT ); Sun, 24 Sep 2017 16:00:49 -0400 Received: by mail-wr0-f180.google.com with SMTP id c23so4609845wrg.9 for ; Sun, 24 Sep 2017 13:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RW4Rrix1IPJlQp3Evo/kM1QRoq0yUSi+qlgaVRgPnb0=; b=sRQEXxB1eDpJBIza+yOlekQg2az3X/s77GdrRVQX+KduvHoUQRrkImM2mSI0ximKz5 RrkhTdJwie2CQJ+JM/GgWNR9L92JoqIo+WqiH1D5HyZxVIUdsadm7g3cLsFPds8nO1Rn 5c3iClw3lmXIzMWRdP1Vo8B6lK+/F0R2Yi8hzR6lUB6VLCxByFhBRZo2RrPqu8RP5IMQ P3iJpWIgCLK8j2PllZS9yrOJmiQnn3uT7Snc5q+yKKrpwHU0YeVws/9ldpBom0FwwFdy h1mvLcppAUCJ2mGY0PvQTzq2bZ7voa998SxUPoXANirjZenjRvCZi2tAROSIjRHp7cbU J+ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RW4Rrix1IPJlQp3Evo/kM1QRoq0yUSi+qlgaVRgPnb0=; b=O1XSrAzCk3ILxD7a80uX7dxYYz9B/NxrIHjxaSvkOuWbtSGfWL7u8L9yA/LVs38B9k 1QT7B2Ph2NDi3Ues7e5yLOYwBrk02Aw5NL7oxzu1SQlqQje48+XJgB2fiU3h53BWhgiP KAvIxhHUnRJEOWhV9Jwy8Jdd1AF78vzt6UN/VxozKxh8cLw097NLRW7zz5Mq7D4hx9Wb R1mm/DS7CWAE4xqqS54fpYW+9uGIv7ljY8gaG3u3YU+nJgoQa+xZhi4cF4wIFTBZjmzR 92PqSAs7vSORUqUlUUVmbFGnX49xjzwG7E6TT7OsI0hXG5ukqN/sQdC2h5lZaEkpeIQ1 ixhg== X-Gm-Message-State: AHPjjUj/gBhp3UzyQFSfB1ru/hF7Qil6jfsFqs8FZ/PDaULfABeDN3lm MvU13tUyo+fFt1WAghuE57LPbQ== X-Google-Smtp-Source: AOwi7QD8sBM7ZV/8hXkIhaJRex2UShroHWJaKiS9IKFThwxEnvILRfNL7+kPErjznP1uzjpau+ywMg== X-Received: by 10.223.138.153 with SMTP id y25mr3957385wry.59.1506283247704; Sun, 24 Sep 2017 13:00:47 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:47 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 09/10] clk: add clk_rate_exclusive api Date: Sun, 24 Sep 2017 22:00:29 +0200 Message-Id: <20170924200030.6227-10-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using clock rate protection, we can now provide a way for clock consumer to claim exclusive control over the rate of a producer So far, rate change operations have been a "last write wins" affair. This changes allows drivers to explicitly protect against this behavior, if required. Of course, if exclusivity over a producer is claimed more than once, the rate is effectively locked as exclusivity cannot be preempted Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 57 ++++++++++++++++++ 2 files changed, 224 insertions(+) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f990ef127a83..cbfff541ec8a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -85,6 +85,7 @@ struct clk { const char *con_id; unsigned long min_rate; unsigned long max_rate; + unsigned int exclusive_count; struct hlist_node clks_node; }; @@ -512,6 +513,45 @@ static int clk_core_rate_nuke_protect(struct clk_core *core) return ret; } +/** + * clk_rate_exclusive_put - release exclusivity over clock rate control + * @clk: the clk over which the exclusivity is released + * + * clk_rate_exclusive_put() completes a critical section during which a clock + * consumer cannot tolerate any other consumer making any operation on the + * clock which could result in a rate change or rate glitch. Exclusive clocks + * cannot have their rate changed, either directly or indirectly due to changes + * further up the parent chain of clocks. As a result, clocks up parent chain + * also get under exclusive control of the calling consumer. + * + * If exlusivity is claimed more than once on clock, even by the same consumer, + * the rate effectively gets locked as exclusivity can't be preempted. + * + * Calls to clk_rate_exclusive_put() must be balanced with calls to + * clk_rate_exclusive_get(). Calls to this function may sleep, and do not return + * error status. + */ +void clk_rate_exclusive_put(struct clk *clk) +{ + if (!clk) + return; + + clk_prepare_lock(); + + /* + * if there is something wrong with this consumer protect count, stop + * here before messing with the provider + */ + if (WARN_ON(clk->exclusive_count <= 0)) + goto out; + + clk_core_rate_unprotect(clk->core); + clk->exclusive_count--; +out: + clk_prepare_unlock(); +} +EXPORT_SYMBOL_GPL(clk_rate_exclusive_put); + static void clk_core_rate_protect(struct clk_core *core) { lockdep_assert_held(&prepare_lock); @@ -539,6 +579,36 @@ static void clk_core_rate_restore_protect(struct clk_core *core, int count) core->protect_count = count; } +/** + * clk_rate_exclusive_get - get exclusivity over the clk rate control + * @clk: the clk over which the exclusity of rate control is requested + * + * clk_rate_exlusive_get() begins a critical section during which a clock + * consumer cannot tolerate any other consumer making any operation on the + * clock which could result in a rate change or rate glitch. Exclusive clocks + * cannot have their rate changed, either directly or indirectly due to changes + * further up the parent chain of clocks. As a result, clocks up parent chain + * also get under exclusive control of the calling consumer. + * + * If exlusivity is claimed more than once on clock, even by the same consumer, + * the rate effectively gets locked as exclusivity can't be preempted. + * + * Calls to clk_rate_exclusive_get() should be balanced with calls to + * clk_rate_exclusive_put(). Calls to this function may sleep, and do not + * return error status. + */ +void clk_rate_exclusive_get(struct clk *clk) +{ + if (!clk) + return; + + clk_prepare_lock(); + clk_core_rate_protect(clk->core); + clk->exclusive_count++; + clk_prepare_unlock(); +} +EXPORT_SYMBOL_GPL(clk_rate_exclusive_get); + static void clk_core_unprepare(struct clk_core *core) { lockdep_assert_held(&prepare_lock); @@ -929,6 +999,12 @@ static int clk_core_determine_round_nolock(struct clk_core *core, if (!core) return 0; + /* + * At this point, core protection will be disabled if + * - if the provider is not protected at all + * - if the calling consumer is the only one which has exclusivity + * over the provider + */ if (clk_core_rate_is_protected(core)) { req->rate = core->rate; } else if (core->ops->determine_rate) { @@ -1045,10 +1121,17 @@ long clk_round_rate(struct clk *clk, unsigned long rate) clk_prepare_lock(); + if (clk->exclusive_count) + clk_core_rate_unprotect(clk->core); + clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate); req.rate = rate; ret = clk_core_round_rate_nolock(clk->core, &req); + + if (clk->exclusive_count) + clk_core_rate_protect(clk->core); + clk_prepare_unlock(); if (ret) @@ -1769,8 +1852,14 @@ int clk_set_rate(struct clk *clk, unsigned long rate) /* prevent racing with updates to the clock topology */ clk_prepare_lock(); + if (clk->exclusive_count) + clk_core_rate_unprotect(clk->core); + ret = clk_core_set_rate_nolock(clk->core, rate); + if (clk->exclusive_count) + clk_core_rate_protect(clk->core); + clk_prepare_unlock(); return ret; @@ -1778,6 +1867,50 @@ int clk_set_rate(struct clk *clk, unsigned long rate) EXPORT_SYMBOL_GPL(clk_set_rate); /** + * clk_set_rate_exclusive - specify a new rate get exclusive control + * @clk: the clk whose rate is being changed + * @rate: the new rate for clk + * + * This is a combination of clk_set_rate() and clk_rate_exclusive_get() + * within a critical section + * + * This can be used initially to ensure that at least 1 consumer is + * statisfied when several consumers are competing for exclusivity over the + * same clock provider. + * + * The exclusivity is not applied if setting the rate failed. + * + * Returns 0 on success, -EERROR otherwise. + */ +int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) +{ + int ret; + + if (!clk) + return 0; + + /* prevent racing with updates to the clock topology */ + clk_prepare_lock(); + + /* + * The temporary protection removal is not here, on purpose + * This function is meant to be used instead of clk_rate_protect, + * so before the consumer code path protect the clock provider + */ + + ret = clk_core_set_rate_nolock(clk->core, rate); + if (!ret) { + clk_core_rate_protect(clk->core); + clk->exclusive_count++; + } + + clk_prepare_unlock(); + + return ret; +} +EXPORT_SYMBOL_GPL(clk_set_rate_exclusive); + +/** * clk_set_rate_range - set a rate range for a clock source * @clk: clock source * @min: desired minimum clock rate in Hz, inclusive @@ -1801,12 +1934,18 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) clk_prepare_lock(); + if (clk->exclusive_count) + clk_core_rate_unprotect(clk->core); + if (min != clk->min_rate || max != clk->max_rate) { clk->min_rate = min; clk->max_rate = max; ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate); } + if (clk->exclusive_count) + clk_core_rate_protect(clk->core); + clk_prepare_unlock(); return ret; @@ -2010,8 +2149,16 @@ int clk_set_parent(struct clk *clk, struct clk *parent) return 0; clk_prepare_lock(); + + if (clk->exclusive_count) + clk_core_rate_unprotect(clk->core); + ret = clk_core_set_parent_nolock(clk->core, parent ? parent->core : NULL); + + if (clk->exclusive_count) + clk_core_rate_protect(clk->core); + clk_prepare_unlock(); return ret; @@ -2073,7 +2220,15 @@ int clk_set_phase(struct clk *clk, int degrees) degrees += 360; clk_prepare_lock(); + + if (clk->exclusive_count) + clk_core_rate_unprotect(clk->core); + ret = clk_core_set_phase_nolock(clk->core, degrees); + + if (clk->exclusive_count) + clk_core_rate_protect(clk->core); + clk_prepare_unlock(); return ret; @@ -3086,6 +3241,18 @@ void __clk_put(struct clk *clk) clk_prepare_lock(); + /* + * Before calling clk_put, all calls to clk_rate_exclusive_get() from a + * given user should be balanced with calls to clk_rate_exclusive_put() + * and by that same consumer + */ + if (WARN_ON(clk->exclusive_count)) { + /* We voiced our concern, let's sanitize the situation */ + clk->core->protect_count -= (clk->exclusive_count - 1); + clk_core_rate_unprotect(clk->core); + clk->exclusive_count = 0; + } + hlist_del(&clk->clks_node); if (clk->min_rate > clk->core->req_rate || clk->max_rate < clk->core->req_rate) diff --git a/include/linux/clk.h b/include/linux/clk.h index 12c96d94d1fa..fdababf80420 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -331,6 +331,36 @@ struct clk *devm_clk_get(struct device *dev, const char *id); */ struct clk *devm_get_clk_from_child(struct device *dev, struct device_node *np, const char *con_id); +/** + * clk_rate_exclusive_get - get exclusivity over the rate control of a + * producer + * @clk: clock source + * + * This function allows drivers to get exclusive control over the rate of a + * provider. It prevents any other consumer to execute, even indirectly, + * opereation which could alter the rate of the provider or cause glitches + * + * If exlusivity is claimed more than once on clock, even by the same driver, + * the rate effectively gets locked as exclusivity can't be preempted. + * + * Must not be called from within atomic context. + */ +void clk_rate_exclusive_get(struct clk *clk); + +/** + * clk_rate_exclusive_put - release exclusivity over the rate control of a + * producer + * @clk: clock source + * + * This function allows drivers to release the exclusivity it previously got + * from clk_rate_exclusive_get() + * + * The caller must balance the number of clk_rate_exclusive_get() and + * clk_rate_exclusive_put() calls. + * + * Must not be called from within atomic context. + */ +void clk_rate_exclusive_put(struct clk *clk); /** * clk_enable - inform the system when the clock source should be running. @@ -473,6 +503,23 @@ long clk_round_rate(struct clk *clk, unsigned long rate); int clk_set_rate(struct clk *clk, unsigned long rate); /** + * clk_set_rate_exclusive- set the clock rate and claim exclusivity over + * clock source + * @clk: clock source + * @rate: desired clock rate in Hz + * + * This helper function allows drivers to atomically set the rate of a producer + * and claim exclusivity over the rate control of the producer. + * + * It is essentially a combination of clk_set_rate() and + * clk_rate_exclusite_get(). Caller must balance this call with a call to + * clk_rate_exclusive_put() + * + * Returns success (0) or negative errno. + */ +int clk_set_rate_exclusive(struct clk *clk, unsigned long rate); + +/** * clk_has_parent - check if a clock is a possible parent for another * @clk: clock source * @parent: parent clock source @@ -583,6 +630,11 @@ static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {} static inline void devm_clk_put(struct device *dev, struct clk *clk) {} + +static inline void clk_exclusive_get(struct clk *clk) {} + +static inline void clk_exclusive_put(struct clk *clk) {} + static inline int clk_enable(struct clk *clk) { return 0; @@ -609,6 +661,11 @@ static inline int clk_set_rate(struct clk *clk, unsigned long rate) return 0; } +static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) +{ + return 0; +} + static inline long clk_round_rate(struct clk *clk, unsigned long rate) { return 0; From patchwork Sun Sep 24 20:00:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114147 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1853996qgf; Sun, 24 Sep 2017 13:00:56 -0700 (PDT) X-Received: by 10.99.186.3 with SMTP id k3mr5575166pgf.149.1506283256208; Sun, 24 Sep 2017 13:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283256; cv=none; d=google.com; s=arc-20160816; b=h7ShQHPB+nbjNUXkwNy929W5WUamYFFsd3YXt9jXKDW6vZA9+t8XgM2eB1r4LK7mdu Tj1qZA5Bfxu4T83xeKLfkP8q1pMAzIAbyE2jAIcDj9vC01oh1+HJrSC+RZlUSm9s6V9i QTgqu+1XgcsMnIJmVQJONaR1zo7femL9jlDDQF5HaiRku7pZ/md2oEj6gQummqahqLpF Y7ACZgBStJvnbnD9rYYeifsSe312aIaPzkYfWyb4YF3pGnk5VpOTddjIO77LpXZJGc/S nVRmC9yPJMCnfDyCSOncrlCm6qfeFrj5j7hvJd2zw9uhL273LSOE3+IV9qxs+eAY1s0q tJ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=pIEP+YwainmQWJKJm1uzwYSWTEK7GuU+iJJ9nbaoAuo=; b=j3USsrgxS5aAOjwdmADEMBEtSVO8PN5paxpHbmdSHqhGOZvzyROS9oVzuLDPrSjNKm /2y0borUJitoOeRDIqO8fj82bAg0qbKYO1xL7T+aw77UTOns7IJnGO9f0ACYDFp4gASS 9XWwYCloziLVDbG01dJbxoe+ZxiFUQwruicB1hHRw1qX6hDLwN2jTX2rvZ+9Mrd5SkMl 2Zr5ZORFDKdQGC240OJXqWIUfdak2DRL/izDw67VfQZWi1J9gbucRlnQXkcvWA8fPX+1 bZfARJCm0+/pVBY/DGxZ//8HFMlg7eUCH25DHZz/dDJiOdbU+qTWNZKVM/h4IyK/rC7M nThQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=deYVan6x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18si3015104pgn.485.2017.09.24.13.00.55; Sun, 24 Sep 2017 13:00:56 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=deYVan6x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752982AbdIXUAx (ORCPT + 26 others); Sun, 24 Sep 2017 16:00:53 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:47345 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752948AbdIXUAu (ORCPT ); Sun, 24 Sep 2017 16:00:50 -0400 Received: by mail-wm0-f53.google.com with SMTP id r136so14357987wmf.2 for ; Sun, 24 Sep 2017 13:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pIEP+YwainmQWJKJm1uzwYSWTEK7GuU+iJJ9nbaoAuo=; b=deYVan6xhEQpkED1mtWAzNwkby6bFD0Q2Ztp876yEC/GN+zg0Fi5pCEZPJkxwT110S ktNED25hrxPtlns8u0pvqL1VJAOa+zPoqQyY5OcdFCDgv6eX2pzZKUmgrS4Vj9oaDTyH /HrIcuU+6Y/ZGzNayCcQgB0J0aQQXCG2KFq63Ey/UTOL8Dq49TVZg0mF5qlBkou17AK1 yui+2Ija/oWV8eqe1j5xqvr7Q4BVzk57S8sIMUdk6gvH+OgVH86lUAJavSJAJvjfhZLw 33kkdwfslg01tyecmmKgeSX7N7HB9LE4iKQo4YPgpkz5hBBEBLMqs+B33sXi2p3OpByC YdnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pIEP+YwainmQWJKJm1uzwYSWTEK7GuU+iJJ9nbaoAuo=; b=jO9u+gjbarZATC4LOfTYqBWOHo/9e9TiYwRsD7T2zxFzmR25snQvgE1wWonrAU61GV zrIE04Ard3FkciOh+YQJGR+TSkRmOKFf9X41Q517gjCZG4GK2Osav+L3GWsc+f9LR2ob HnFfqcxhRdzJirznPtfJFU4ZVH4BW3T08j1pWA4FCGQKEZaOnMnflSO8/GIiQTz4jDmL sc2vk4NYkX5UPFXQd1IguwJEzdTIjyA1FLLYC3dNRufepgmFg17Iql4zNMUPEoeRVldm YYPzbpPtCscdzQiyRDdmxTuXlSq90cAYkwcfuqjxDHRoB5U3nxfUhW5CTGHFkyOJ9WXO zfXA== X-Gm-Message-State: AHPjjUhwK+jkiRYovZBoBWOiXiS+i58P2P0Qtx8xB5NOgCg3vy+ry+F1 /6ikbrzh4lRyPSq54T4tnwkiYA== X-Google-Smtp-Source: AOwi7QCIFlfchcQpSZ1ljfRR5XsxQcg3QkSNL9JDCj25HdOQRTbCCKU5LFB+CAydoSVDuSiGz8w7fQ== X-Received: by 10.28.164.68 with SMTP id n65mr7939302wme.23.1506283248909; Sun, 24 Sep 2017 13:00:48 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:48 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman , Peter De Schrijver Subject: [PATCH v4 10/10] clk: fix set_rate_range when current rate is out of range Date: Sun, 24 Sep 2017 22:00:30 +0200 Message-Id: <20170924200030.6227-11-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Calling clk_core_set_rate() with core->req_rate is basically a no-op because of the early bail-out mechanism. This may leave the clock in inconsistent state if the rate is out the requested range. Calling clk_core_set_rate() with the closest rate limit could solve the problem but: - The underlying determine_rate() callback needs to account for this corner case (rounding within the range, if possible) - if only round_rate() is available, we rely on luck unfortunately. Fixes: 1c8e600440c7 ("clk: Add rate constraints to clocks") Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index cbfff541ec8a..8bc3d9d4c7ff 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1921,6 +1921,7 @@ EXPORT_SYMBOL_GPL(clk_set_rate_exclusive); int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) { int ret = 0; + unsigned long old_min, old_max, rate; if (!clk) return 0; @@ -1937,10 +1938,38 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) if (clk->exclusive_count) clk_core_rate_unprotect(clk->core); - if (min != clk->min_rate || max != clk->max_rate) { - clk->min_rate = min; - clk->max_rate = max; - ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate); + /* Save the current values in case we need to rollback the change */ + old_min = clk->min_rate; + old_max = clk->max_rate; + clk->min_rate = min; + clk->max_rate = max; + + rate = clk_core_get_rate_nolock(clk->core); + if (rate < min || rate > max) { + /* + * FIXME: + * We are in bit of trouble here, current rate is outside the + * the requested range. We are going try to request appropriate + * range boundary but there is a catch. It may fail for the + * usual reason (clock broken, clock protected, etc) but also + * because: + * - round_rate() was not favorable and fell on the wrong + * side of the boundary + * - the determine_rate() callback does not really check for + * this corner case when determining the rate + */ + + if (rate < min) + rate = min; + else + rate = max; + + ret = clk_core_set_rate_nolock(clk->core, rate); + if (ret) { + /* rollback the changes */ + clk->min_rate = old_min; + clk->max_rate = old_max; + } } if (clk->exclusive_count)