From patchwork Fri Dec 1 21:51:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120399 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1680063qgn; Fri, 1 Dec 2017 13:54:39 -0800 (PST) X-Google-Smtp-Source: AGs4zMYWmVPpQap48ANmQ3oKnFGkcmm5EzfMLPNSiuB+XMa2nf70SAke+QyfsNgIe9X84LXD3gpc X-Received: by 10.84.195.36 with SMTP id i33mr7620103pld.189.1512165279696; Fri, 01 Dec 2017 13:54:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165279; cv=none; d=google.com; s=arc-20160816; b=uf2nOVuU/yqw6q8RwhQBFwEcJ73oklM4fzJOfrmFO9y3r1d6LhrjxK3bbf7xszoEFY 9VyOw+86RrSvHHQyYPS8kG2sgRi0E9UtxspsaIdx+6EzTweg+qJv/K3XowEbDdQd8Y9j CWguE2r0OEo9UY+X7z6D3Test8dYiVl4HBwGT92Y737/bBhhBcRWTHVL+Zx+phDnW89f Q5vahr5OQkJdcZeETVsohiIEJF3P15ChF6nqEUK5K6b2LusdyxnUA7l1Z++pwcxSoVco l9iILRo4XfxFUcOzSizKuWPX+HyzS4yYUlBspjRvP/W/PDNTV+B1/zN3J2Hm3pNDzaCf duVA== 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=Lb3LUfd89pdtkjUVI6Uzl7AslXJpms42nE/cgnwC1uc=; b=OQhkm7huyLZHI8eMDnFj4hCZ9fqa4ytfVE4ADTysUkklnEB+9pgLq27z6mgZFRn8v9 a6+Qi/ypDFJMTl3RC5FWW9/uYk4dLY7Hz5aNLO4piVjjZ0r2vbvmiF8f5b2H1ZQDDbIv qz+n9yHCSsV13KsmWefh+qZzgIAEEbfZFkCN42cWMAtQof14H6EPvolzjnnxVY7aviRx /wUavXi4fcRTBn0qZBbCupoF9rIfI1yG1DMiTyuQbaioT8s3An0WnBTJITM4EMKUfyQt M1udKMHbd53ohKDy/ziScDKYd7XeLoy16jNAPXhDbiWnz3Y09R/0LNsrAjjEnkYjv/c0 DvyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=I02Oconm; 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 1si5540022plk.773.2017.12.01.13.54.39; Fri, 01 Dec 2017 13:54:39 -0800 (PST) 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=I02Oconm; 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 S1751827AbdLAVyh (ORCPT + 28 others); Fri, 1 Dec 2017 16:54:37 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:44344 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbdLAVwJ (ORCPT ); Fri, 1 Dec 2017 16:52:09 -0500 Received: by mail-wr0-f193.google.com with SMTP id l22so11504481wrc.11 for ; Fri, 01 Dec 2017 13:52:08 -0800 (PST) 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=Lb3LUfd89pdtkjUVI6Uzl7AslXJpms42nE/cgnwC1uc=; b=I02OconmEgPOMzUfeAiULRNhr1dT3v/+ScQPxcViZRvY2dp6pS95vaTvyd7An7/Pyi Ws4ZswBl9FH8OwQzjeTZi+1fscNqcRknB7g9nt1Pk3i3DYSSwCxm440xBmMS6Q2qItry 4V4Yr4+B2doMU1BRWZyphr1iC+RUlNCoSsiK0iRMcvMcrmW3q/FR4ph5IfBuObKj1SbA UDvMZskt88mj7SwhZaVYu6XggoPyZDA8wU1YzrIZM02fmEUmHro0TAt+bzDX5l6H+ALd nMS/RzF2GB0tdqUZ3+zaMnbQ2gRpeFX+dFSeouhhALRfvQGGAEPP7QptNU3SE2c4xy0v UZXA== 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=Lb3LUfd89pdtkjUVI6Uzl7AslXJpms42nE/cgnwC1uc=; b=meWOpBGYODIcZl6HIFziCSwEJgQzLFZfvySkRf5S0u9sLDRT3MLOo525f9Q2jkapM6 ZFm4qf+eFDNlGFGguWlkLEtShBBXBGQJd4qo38H+egcCfieYF8ihwW/xdxzVwSez7qbc 33oOYQP7hQnRb0C0MwFUgyJUjtIX3zsGO1O8TQUrmepE6JQyoKuaqzL5DZLh4R2yeWIf 9lsfADg43+zOAma0iE6KSMzLnEkvIX9hAuFT8cln5PdpDp6FTr6uVSfV9XqKTYeoiUcC Dwb/BeNroE8hfLV6CQLtybuyX+2BOKTNPzw2eq7v9163PnztQ55le8EMd4FY+KfUfyqE SxRw== X-Gm-Message-State: AJaThX4yvS7Mg1LDgiPKI7V4y+SUBq8Lweu1r5iEcSWR03DQGHSuQtOG pUPH4GJXXM7/3uqE9GfmESNDxA== X-Received: by 10.223.196.189 with SMTP id m58mr3954748wrf.7.1512165128117; Fri, 01 Dec 2017 13:52:08 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:07 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 01/10] clk: fix incorrect usage of ENOSYS Date: Fri, 1 Dec 2017 22:51:51 +0100 Message-Id: <20171201215200.23523-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 647d056df88c..5fe9e63b15c6 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1888,7 +1888,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 Fri Dec 1 21:51:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120390 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1678296qgn; Fri, 1 Dec 2017 13:52:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMaWgn0zRym9YcH67m2P+wt3/XfcnYDIa8PRaPaKPLGC/fnMe5o5T+ScOJpZWng/GZQOn6ZJ X-Received: by 10.84.254.69 with SMTP id a5mr7315001pln.353.1512165138147; Fri, 01 Dec 2017 13:52:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165138; cv=none; d=google.com; s=arc-20160816; b=REI7VDgCB4MmKuFvmtuw/FZizqM7TN+Kssjv0aqoenuq4n/HTQJJq6hhOeuZkjR15B kYBPaygcv2zUhavd3JJAzI/Xm4DcFO8EpyiKFhFY7HBFKMDtrO8LvM+0zHLvCkk1lr1Z 1HXXghN8I3aP+knVCi1ZlMBnRS9TCFxOcEsvbVbltJ9EbNzEhI8/IZXbCPgww0SZGlcE A9SeWJPm6yWNgiZ1YB4YfwA7wFNsWLUy4lwB3JGBeX6U4ab2hgVs6HDIVrigEZpBVy9I zMo6Wv6stKR1T8cpHRuXcwjqOs8WKV7fNl/FXl6o+bpdGZ89dtYZbTdCIFCy77ZzHNbq YzTg== 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=JX+ANM7LWkr5EmCur0w4rrtOjl0cs6Wy9uhqHqNivLE=; b=U+PDq6N13TOnleZZKNv0MQ97SIsr1uyDdpCKNXa7qrF01PMV+WrDEj5WTb1NOuKDOI WgcCIBFAG+Cut0x97OvJMN2KyZAym9Sx6C5yl/ny0z9oFdn2yuwLLMfDcILDANIeBUmz 6effkKt7Ky9z6Cf/9UNcPme35WpPvXcpA4OYQC7wPjHwRBLzYHTRD7WHQhB+Tt79C69v coELVHm6gZUtBeL9MMQrTmKJ35vo1fjVc8OWJgd1pbIRFoR/vPL4ZLGhmek7zP1BqEaX gLs5QjnkhyfQbIRdCoAoxeENVVkA9l4UsltDk1F2qFDobqXSJCh6VueU+alMaVvu94uz +cfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=TBRi0aZq; 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 f3si5421634pgn.40.2017.12.01.13.52.17; Fri, 01 Dec 2017 13:52:18 -0800 (PST) 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=TBRi0aZq; 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 S1751684AbdLAVwP (ORCPT + 28 others); Fri, 1 Dec 2017 16:52:15 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:41897 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751513AbdLAVwL (ORCPT ); Fri, 1 Dec 2017 16:52:11 -0500 Received: by mail-wr0-f193.google.com with SMTP id z18so11531856wrb.8 for ; Fri, 01 Dec 2017 13:52:10 -0800 (PST) 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=JX+ANM7LWkr5EmCur0w4rrtOjl0cs6Wy9uhqHqNivLE=; b=TBRi0aZq3XMEl5s7Zv3xcSvTUFl7W20rkvvC2OGC2ylblxcyYUi8m0SUNoJGeaNOmD DUIIickzfki/r9MVUCMBpAYgorKBgIexlppGtpEqrHhVDXANWK9FxJ5CX9xdh9/Y15iY uhS0yLztNWmyB8A++L3JS5/cKZmI196EPGi/f3ubQvXa2pdSFUkJ1xHgeQjXsZuliq2l l/cX4yMuJj/5fNOxIY332wcriQ7gGV/MsUXnRxqz63bsKDpWNXzSVb4Urvmty9Q47o34 x45FNsp4K+J7lStXp13cs865+q8TxKn3+UP6U8omDnR4blsvV4s95AhDEHb8m9+QwO5H OivA== 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=JX+ANM7LWkr5EmCur0w4rrtOjl0cs6Wy9uhqHqNivLE=; b=CqNkPLrjlvCM20S6YWHT46/VcZzyP/XztoeI0qoVnQfYOw7F8b6jCDn7zH1VBVdvmW sSlJLgI2sqXMHuUC5Z40Mme8yaPFU9AU5VG8K0hOFXToiO2QdkSSIEQ+6f2uuX//vLIm tQ5KE/g+ctwYzuRifJZu4o/n5cL/VSEAygG25Wn67Dkawzd3uLvDG6k7c+7LyCF8Goys gblTXfeZwduxz/4FLPu133xhlaRLpoY3LfyimtC68fi68p1zPNDxvsAn9bbo3WWrUnRL MXWZ0DBxaO5JWxoNTExevf+b1GwQr3+9GXuYNbGsaT50mCalvICxz6cSlSSp6OgndnPf KdAA== X-Gm-Message-State: AJaThX6n+eUplJL1BdKHkNIrHymTv/pBWjeK/XoLCGpU/Jt2di+8eAYP jTzI9fHeYpWii26bIbCXm6Kb7A== X-Received: by 10.223.184.197 with SMTP id c5mr6189452wrg.18.1512165129654; Fri, 01 Dec 2017 13:52:09 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:09 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 02/10] clk: take the prepare lock out of clk_core_set_parent Date: Fri, 1 Dec 2017 22:51:52 +0100 Message-Id: <20171201215200.23523-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 5fe9e63b15c6..e60b2a26b10b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1871,32 +1871,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) { @@ -1904,15 +1900,14 @@ 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; } ret = clk_pm_runtime_get(core); if (ret) - goto out; + return ret; /* propagate PRE_RATE_CHANGE notifications */ ret = __clk_speculate_rates(core, p_rate); @@ -1934,8 +1929,6 @@ static int clk_core_set_parent(struct clk_core *core, struct clk_core *parent) runtime_put: clk_pm_runtime_put(core); -out: - clk_prepare_unlock(); return ret; } @@ -1959,10 +1952,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); @@ -2851,7 +2851,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 Fri Dec 1 21:51:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120397 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1679696qgn; Fri, 1 Dec 2017 13:54:07 -0800 (PST) X-Google-Smtp-Source: AGs4zMZqjtt7+HDb/j2jCHdjxcBVl/dfJxT1Hz+hJBXflDS81ZIl6a4zrvaQrmRkcd2dhcl4gXcE X-Received: by 10.99.123.21 with SMTP id w21mr7104211pgc.67.1512165247713; Fri, 01 Dec 2017 13:54:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165247; cv=none; d=google.com; s=arc-20160816; b=mRe9ApyU/juVAt3Siqa7xaXO7jwjW52BbhytEzmE53M3uhRAqJjYT6mezAP/kvX09M OWuLduljcGhzKAHY3QUz/BcGpVPcl5t05MYjBz++vBKLWxvyqhMI88SLjegYUOBBkJzC e8PutYfulf1PJns9OVo3d8CFjEzCWQ8xHXH6wznWbU5qsgb9bOyF+nQ1lvV+svbD8Xrn NmUoO87RuCx1L0SW9am0KaxSR+huhVXn1/LWAvaGNKBiiuxD/arVNlm+hBzk1LVWe+xz drUU9VEpqU/+ED3+Nlpr1xILZDTQOoQLdfCsUwHPGc53Dz5KImIXfOsLWiyIqlJXjRpN toCQ== 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=tNPfVL6Tahd92psuj3PD1HLKZN+vrFb1bHg4SrV1els=; b=dr7JknlH1CfpDMTbhHoZ5e7hE/2DrWBALGlIeT+g4PF9T2svtQiRDzimMPD6//7Zcj eICjri0H9cv/opPeYgR6p9UrMfq89VOiwWrFQuyarjAhE+3LSkzYm4ysjMEMsuDveGA6 yGsz46TvFvu9LWoS1m2fnDOLIz8eiwia03LhAXS0gv5FpnwF4aGaI/MvQhRQ0Sbi2MAE 1t2TCq3773z2o0kbrzFmzZUcadqPliacuyOWNQR4SnmPC7Q3tMz+hK+oqyzhPntlm7CE NmJIU7dB1EXCj6Db2BLzNiIJqEAWEvKOZ3QPYYsn4FhekvcXkoCHpEvckJxMSzjTxSrG MQcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=vYoUz84W; 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 h72si5828118pfj.20.2017.12.01.13.54.07; Fri, 01 Dec 2017 13:54:07 -0800 (PST) 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=vYoUz84W; 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 S1752143AbdLAVyF (ORCPT + 28 others); Fri, 1 Dec 2017 16:54:05 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:32858 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751039AbdLAVwM (ORCPT ); Fri, 1 Dec 2017 16:52:12 -0500 Received: by mail-wm0-f67.google.com with SMTP id g130so7165529wme.0 for ; Fri, 01 Dec 2017 13:52:11 -0800 (PST) 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=tNPfVL6Tahd92psuj3PD1HLKZN+vrFb1bHg4SrV1els=; b=vYoUz84W59DimV8dVCOj+8yNAtDyxwd7oHxxu9KgKZ/IlA74uX3qc1xwT4oX4GKSFZ CgmsG2iSy++1I9zaRBvG5nrDDz03dV4omLkL2A+v9BVST8Sk6ODZnaGyULCyP9xr24ls tpzuGEZQ4VdUc7qBuwGuxFxp0qluHHOhX+c5aZ0x0RP90M0N0DVFyA9+7z09nfe8nuWg BphAOe1MOBoNqx07hXG2gnNqjxBgvQLuOR1MQEShRXKs26QXHplCLhqVC4fd0gsSAn6l Cf0PsRPO3dfm3vofbbu4ZKg9cS5cavIJ+fAy8IfCFtpI/hdto9VNGh6O2sVelWDqyk7J WyEw== 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=tNPfVL6Tahd92psuj3PD1HLKZN+vrFb1bHg4SrV1els=; b=tbpd12d6DGrbAFJBdwI4CGZBW/t/bFKTBIKKbyYOdXdqLvDFYdm1oFj6NvEArWzGtO EOpprKrPvE/O6PSBmH+yszZ7Rt9QUobXzzFLUetcQ7YpufqFU/NmxlVp5ZDIEmqQJLMv mUJv5G0H+bOmkde+hracS+NTXxicZiW4P2d8HZLwtXYB0iu9JM0JIezuc7tllw1w+S9i Wxb/sySETDCFGusmm+dpd81JcVH4DVEBS3Ac++jWD1sHX0KaKSF4WvxwebTRB37rKV5T eeLjknSyAcE83cVzh6By88t71bd6tcLLJMJ9hH9Y9vU+4J+qsTWI7ifGuG27xYPtuhQG NC6A== X-Gm-Message-State: AJaThX5y+a91REfknC7AOCub/E8DnRlZv9X9gAt+LVP8EZzDFAADnAdP 0E9NM+H1wgnvcPs5E0gRpMD41g== X-Received: by 10.28.214.70 with SMTP id n67mr2124378wmg.83.1512165130955; Fri, 01 Dec 2017 13:52:10 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:10 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 03/10] clk: add clk_core_set_phase_nolock function Date: Fri, 1 Dec 2017 22:51:53 +0100 Message-Id: <20171201215200.23523-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index e60b2a26b10b..7946a069ba2e 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1966,6 +1966,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 @@ -1988,7 +2007,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; @@ -1999,17 +2018,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 Fri Dec 1 21:51:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120398 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1679824qgn; Fri, 1 Dec 2017 13:54:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMa2/01BxvqWNTAcr9DvUZlZJe8VJMdRbJ8zCi+f8xWXcGyzRtCM2n1q41NviURl7C8fU7Hi X-Received: by 10.84.129.193 with SMTP id b59mr7426236plb.361.1512165259194; Fri, 01 Dec 2017 13:54:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165259; cv=none; d=google.com; s=arc-20160816; b=FJ9EZq+15uJa7ImiTyOLylVTcgyvrMkZTkeKPq7v0bQhiNH9QWs0eWMSA+G1hqhDPG Q846Y5vUaN3IvsBabdLD/Vs7CEZHAhb9FGLrGPt3XmW1Y5T+N3DqtaQqdIijhvVfpBdm bDc1wlJ74Qzy9XdTU1PYyRiGOcsbj70PM/eIsqKZ7L2yBDIufjhGFCFSoVvDCzTSDGPr gpVHfi7DXxpkabL7HMtDp8zQu6M4XhqGsoXX52ESIuBOv+GiSA37wvjK0zW0D1RY39uC 64vhjwvSajZ7u/XFSdGbzgumtWPV+Mw+oM3Mfqu/TwM4rjbXvKuA7PJ0qDC9y+NiYUBL uy5w== 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=PKgH4SvPhRiksHOdphmjG6SkWE4hUDKWP16hEgziMdo=; b=zgrrAwaKtmp7hBsv1P7FCan2F85DORavJbRLoWKCl3M3KaK6XHbbBeMrsfMg2nZeXq 8vA2/5IGB/yvOBhwd2dBOJmH9jBh/VV2LudL/jvES7HulxwMw+xUXQ6uXZb0iiwhd359 Rwa0uJz2d+GeyXdmV5cVKwd9Z0rzJx9Vpu0CgqoVjbZc7hpVQJRroUgQj21+KQ9ERTu7 E/PVMqqWLKUFmaeAKl2fMz6an3iOpprkwstpAPwJfzYDtFKbUpnL+ZTvJcCUIZKeC8ft Y0/b0EUaMAS+lwJnIMIMeib0KY9biym3XU+hVMXY5zS8f4w3sOcRM0o21XrvCMh0ZJnW g25w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=ktr3Kj0P; 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 r1si569301pgp.308.2017.12.01.13.54.18; Fri, 01 Dec 2017 13:54:19 -0800 (PST) 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=ktr3Kj0P; 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 S1752119AbdLAVyD (ORCPT + 28 others); Fri, 1 Dec 2017 16:54:03 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:45681 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbdLAVwN (ORCPT ); Fri, 1 Dec 2017 16:52:13 -0500 Received: by mail-wm0-f68.google.com with SMTP id 9so5863922wme.4 for ; Fri, 01 Dec 2017 13:52:12 -0800 (PST) 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=PKgH4SvPhRiksHOdphmjG6SkWE4hUDKWP16hEgziMdo=; b=ktr3Kj0P/1xSxnSPfBJgI73O549P0KvnpbZLoL92yeVltcsk4v1UuwfCwbZm4mefeM nx5a6QakrXNbd0w7klcjX5vd6gkEvuxTO7b53ph4d5mlAo/4i0P7TOYISHSetO3E6JJM HlcfA1Ccg4ktddm1pUSLCHeRZXe9b1ezqbbp8KTAtdSFpRynS+8fzkNnQgPyMnjoq2MZ ewukXESt+PDPmlLKit5JDFIBdt+jqoBBwNu8dLEyAXlwhTrLnWOcSsg4yrvBiB+8t9Yo djQqvny+tHZEZdGB7b0EHbL5mFEk+JJJe3oPZgqxceWMtYuV1q9mB0dP39pYOi07rU5H gVAg== 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=PKgH4SvPhRiksHOdphmjG6SkWE4hUDKWP16hEgziMdo=; b=oqT/4UlncDEvUawlf4FtsoBlirp8ap+tAUb8NbeWsTQhsYjrnaal4O8i6HXOyqhr9G ykfBYA/8F5PCOCtf6PVCQJpE00OS6pQ1LPwql5GYE/jHbqqjF1o6c0iTkPDlP5xkXFIg Vo2A84p71MZ+1YiZYEB8cyt4ICVIISON34Ar0McdotxzV4xkwi/i0YchiSvcxJW8jrZ+ ceQWntjyqEDQe0klLEZGHbH3mZx31SJb4ON9RetczIhHg6tgHCTm0b6sCgaGdrWRMQQR fFLSGXgauaF/nR670YIpPNa3e6i4jDEJSmpzfRdp2jeJcfaFbnVlbrRNd2dvSMmDftWa 8S1w== X-Gm-Message-State: AJaThX6CG7sXGH3kZXK1AqHvDfYQyl0ic/ZTPwNrKjCuDMsp4F8pSb/j 2FQNZ5+Bht179oaMRJlyruvEEEO5 X-Received: by 10.28.88.137 with SMTP id m131mr2237624wmb.48.1512165132296; Fri, 01 Dec 2017 13:52:12 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:11 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 04/10] clk: rework calls to round and determine rate callbacks Date: Fri, 1 Dec 2017 22:51:54 +0100 Message-Id: <20171201215200.23523-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 82 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 30 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7946a069ba2e..322d9ba7e5cd 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -905,10 +905,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); @@ -916,15 +915,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) { @@ -934,15 +924,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 @@ -1432,34 +1465,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 Fri Dec 1 21:51:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120391 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1678503qgn; Fri, 1 Dec 2017 13:52:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMbVtFRMjkDN2Cdc8zp3tD37ocQIww7Qanjd2i6PPpQFIGGYtfYLkxcyVv75stwe/MXR/wO9 X-Received: by 10.159.252.137 with SMTP id bb9mr3139768plb.184.1512165156966; Fri, 01 Dec 2017 13:52:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165156; cv=none; d=google.com; s=arc-20160816; b=xXe8/jJhjfbRHcLUYcrmADJPy7qiOCcQRhNDZ6+JgpPQpRI0Pzt6OaTKd87e7BuvpX Z3UZTxt/cXLaK3ble8Ob2hnculD4W+lxYjoxf2jr3pnn+qjGd489WXzbb7Ia4Wlw9g6t /i1xx0H1VB1G1AluH3hHp5F1CH4IT2dcExomo/HVycP0ZxvDkivriBTd0XN23u4H+vNC r+M2ffM2KQFLR+/qocg6ywch21qb+T2uOf4COhJ4cxL1AMYTu27pWikCLT2LucusDQNZ M3Dvyfe/7MshKiceOwudrtO800c2Hn398tqFFGa/BRjEujlPHa3a3ji0CuNVWtSkSkAZ Grkg== 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=oBzmsU2/C3dLtHuMuPFtaLteu8r7z7MLMuxecouCUEw=; b=WK5u7cUU4v1B9p7mJKDPnu5ULT/OPDpciu1zxIeP29XHGCzS4ulNXAzS1UfLtpVuLr X5UB2IeynLgCChhtEbNe9vnd59lCBd9eSquCEz0ASe51WXtYX4X6EMgWJHE95oC5+GDL /ltlwbvitfHVtCt87G++PmrkyoximQIIGwNgpbrIrNeaJfSs668NR9cN4d5Wnl1643ys XifAAoCAMDKaFQTQGKzG7jgMGCpXmKcDutGuEonYFb7FDn6YC+A/u6ytn5FnY5NjPF35 q537hBKL71qPAlOtCKFqXZYiB0m0OvB7EOpIOe+LpI8CXxtz1NVVqP5QpPaL3S0/30kN jA4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=AzSl2Mur; 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 x13si5422045pgq.460.2017.12.01.13.52.36; Fri, 01 Dec 2017 13:52:36 -0800 (PST) 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=AzSl2Mur; 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 S1751827AbdLAVwW (ORCPT + 28 others); Fri, 1 Dec 2017 16:52:22 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36185 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751607AbdLAVwO (ORCPT ); Fri, 1 Dec 2017 16:52:14 -0500 Received: by mail-wm0-f66.google.com with SMTP id b76so5666146wmg.1 for ; Fri, 01 Dec 2017 13:52:14 -0800 (PST) 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=oBzmsU2/C3dLtHuMuPFtaLteu8r7z7MLMuxecouCUEw=; b=AzSl2Mur6JKONPEj+FY4gfBL6koPFLsza4+SIDKV1L3R1UtA+SdiVc19woPTqoHSBZ Al7Gt3OwEwFh6VO/nBUV+7P8NgRQD0tGgUKTUNRP+lOZO1popt2OD8cMyjNaKPs/mw/n eDbZ+fosGj9cueQyzvADq2fCVwwqEV4oxZtdVmI0LEmNvMT0/BK6xMIiT5E7FLx33JG/ qGoIIj1HkSDRkPC0TOy7EbqylYey7a+ryqvpuqO8+zho9uEhc5RhHNiyRo+0c2H9UZhv 2J5KD+cu4LTVG8y9b5UWGDYt3ptjIvnRIn2ICdKfi34WqQH4O7ttdl4WSeSN9BrEyt7Q 163w== 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=oBzmsU2/C3dLtHuMuPFtaLteu8r7z7MLMuxecouCUEw=; b=MeYhLJCNhBkL1H1MdSUc5yhfrnlVvBRfPz9DN7MIQkOrw3S85RqHkfccoQ3w6sYmpY zazJyPIq+MCrQe0OoLm/OXzx8QdmmFIPNMJkURIbYDBgk8Z9l/0eqC5Nc3m0a0YqB53H MbfFsT/WfgxAmaPcm/V66jO6WvKuJyp5rgbG+N2Px962m2P3fU5dcoppLDRov2knqsHK /yNeoJktbgAqUu7onlyarrcxcjKOSZRR1lx+H9+Re0KbUbx2+R0o+zjrYdnU44ao3PLN NtmP7hIQJ/JvY+BXMOZXR4n3altkFwuc1KhL3qsS3tlemew2R7+lgxSiyGYdVxHpkyAl YcAg== X-Gm-Message-State: AKGB3mKBqUGjsY7/5HPDNVk3ydjUBA/ya/FPnIcFwyhNCW3vyG4VnGLn gJfys/pj6zURt7rt9stOqCKtRA== X-Received: by 10.28.12.18 with SMTP id 18mr2154824wmm.129.1512165133621; Fri, 01 Dec 2017 13:52:13 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:13 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 05/10] clk: use round rate to bail out early in set_rate Date: Fri, 1 Dec 2017 22:51:55 +0100 Message-Id: <20171201215200.23523-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 322d9ba7e5cd..bbe90babdae4 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1658,16 +1658,37 @@ 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; int ret = 0; 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; @@ -1676,7 +1697,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 Fri Dec 1 21:51:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120393 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1678924qgn; Fri, 1 Dec 2017 13:53:11 -0800 (PST) X-Google-Smtp-Source: AGs4zMY/eT0wDVbyabnQely91WFeZ33UcvX7clfu40V/U3+DzUZOj4TRKTAYcD0/RA3+Z8LcjE7i X-Received: by 10.84.217.206 with SMTP id d14mr7407142plj.132.1512165191341; Fri, 01 Dec 2017 13:53:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165191; cv=none; d=google.com; s=arc-20160816; b=HQH+HpuyHh0DPH+eBmx4/aEX0KGxI1XWFXqsRlLucK9CpMz3lu7h+Omx7B1MEa6OP1 ViLw75H4cWy9lKOSZAYjY4oP5wOoJhTaJC1DneixhvGQiU0XR4aZWV4AZqZXuSUcfp3A rVpX1B/uEqF8VBARIyU5vacNaXMJGu/HwWE6VlYK3GDKnRJHLuQmnpP+WXu7nLhjJolt 5RLaVGMsHQ/qbTscrv4V19v/jFmq8LqU+L6gtsAyez69IvodkyK9S1o3DMqZdVhB33d+ 1lyC7aRcvoR11u/gMUMOEAATEcAcLP2Hm9PtFt3UxnjmdEYH4jpW1xDV3zWj7y6HjRzh jrEA== 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=u7NJaAVbZhezob2/UUUtnFwXw+Kt142WNlZ8TlIbpG8=; b=s76Ba3YqCIQQFQ9CA4eAJuV1lu59Saf42pieZTSuihE4+wqJCb1l8yV1zWs3S33jms o4umIyrsAMykIHYhijSnpMEdV/GV+qUDQpFZBorbzuSvOHLJmb7z0AUJhX9a5VmRCDdM 5VYCSQAwIyytGcYxSuJ3/sMDlUaXnXtRbSHHhFipjp4Cp/9LRELjQIUlpWUiNSSWV1kJ sBUptvAo2ThsQQeCki1amFTyBIpI3clGZS632zLAHBNvf7WCBDctUH+LVNIYakVeEJ+0 on1ONWv7P+OElO6sZxtcx4uKUt1xfk38w+N7QNPgZYQklHO82yD3jc8SSBRpuHNB1ai9 WPsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=fiy4j37w; 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 v128si5443516pgv.276.2017.12.01.13.53.11; Fri, 01 Dec 2017 13:53:11 -0800 (PST) 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=fiy4j37w; 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 S1752104AbdLAVxJ (ORCPT + 28 others); Fri, 1 Dec 2017 16:53:09 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:43758 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbdLAVwQ (ORCPT ); Fri, 1 Dec 2017 16:52:16 -0500 Received: by mail-wm0-f67.google.com with SMTP id n138so5878548wmg.2 for ; Fri, 01 Dec 2017 13:52:15 -0800 (PST) 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=u7NJaAVbZhezob2/UUUtnFwXw+Kt142WNlZ8TlIbpG8=; b=fiy4j37wnvWi7Ga4uFaS+3Zoh6Gf93+tlbOEP95nZXB0hHvV/7GIAWtD8+Zxi+yo6n EgMmXbsO87bpf7sAcJg3AbLDERE8T0FMW5SEdvtH8L53JIrt5F831I0c4WNzJ7Fgvwzp FFydXykH+2CeFucWgD2NA7ZW1Oc4T7uKn+FjBovetncmsjewfDMsLYD4DhmPeE0vqV+t V8OkZPv3y2OUiy+wfGf2lKbmCTkitPertdNWr7UfOpGAdWK/XBTbXYVBUVsTkL2ueQNy VO2LNQhFANjts9sJhAIOP76UVbh4k2UAeVbhUpABMBirQYTfv6aoDrmWEaBr91T+rZtP Bvpg== 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=u7NJaAVbZhezob2/UUUtnFwXw+Kt142WNlZ8TlIbpG8=; b=LqnKH37444GyAEkZQSDGrbpRUrC6EXxsOxgPVRlTwV68I/xlWVUukDht6QkeZgFsDv fgWBQnF/FtsVI+cq6Kuav2Zx3Zd2fuP3Vnn635KsisbGSaSaIbgm/Uj7DxxQfIa1t68H SYwWVt5o8RLcTJ1QvuetHK0Gi+jDQARempvMSjNKDOox6+bDjrl2nl7V/0Evvs+2XxKq uXtkArj7BNzDgkBs8BMlo6Wyx9NVHuTcKxtibLX0KKBhG6/n7onR2aCsfDkFMwRS6W9S uPKWJVkFNhF7IChO8FN6HWcIXfJTRWMdcUAFXFaXqoS8TsTgQEae0Q/+UtVbBBo2MTKv DlxQ== X-Gm-Message-State: AJaThX4cH9Rv/FwiwBa7oD5qLh91dInSI9OiVxO0jqJ6iaMoDfthp0f8 JTUEMvBQEyRefZhY3o6jo0Z/7Q== X-Received: by 10.28.50.70 with SMTP id y67mr2136262wmy.159.1512165134948; Fri, 01 Dec 2017 13:52:14 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:14 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 06/10] clk: add clock protection mechanism to clk core Date: Fri, 1 Dec 2017 22:51:56 +0100 Message-Id: <20171201215200.23523-7-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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. Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 119 ++++++++++++++++++++++++++++++++++++++++--- include/linux/clk-provider.h | 1 + 2 files changed, 113 insertions(+), 7 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index bbe90babdae4..f69a2176cde1 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -62,6 +62,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; @@ -170,6 +171,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) { bool ret = false; @@ -381,6 +387,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); @@ -519,6 +530,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); @@ -915,7 +988,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, @@ -1661,7 +1736,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); @@ -1669,11 +1744,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; } @@ -1693,6 +1776,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; @@ -1937,6 +2024,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); @@ -2018,6 +2108,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) @@ -2148,11 +2241,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, @@ -2174,8 +2268,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(); @@ -2210,6 +2304,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)); @@ -2340,6 +2435,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) @@ -2911,6 +3011,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 7c925e6211f1..73ac87f34df9 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 Fri Dec 1 21:51:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120394 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1679075qgn; Fri, 1 Dec 2017 13:53:22 -0800 (PST) X-Google-Smtp-Source: AGs4zMbMaFB/en8ASuW0BZyq+9+hVrR9BCRfEmO5sCbacO4/WahjekqfOEdz81H9JESQv573CNxu X-Received: by 10.98.14.15 with SMTP id w15mr11792848pfi.222.1512165202583; Fri, 01 Dec 2017 13:53:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165202; cv=none; d=google.com; s=arc-20160816; b=iQylHA9/Sz906tvqLNfvN8wx0uIROQoeXC1jFyg/x7oowMc/nZRopw4Nm2b7gYtNhz p2uy1+7NVFhgdxBZPhlHnoMH2xbeTVgju/foOLf1ugzCUo+5DQTpL/zT6Ot+Cvs4bAwd kN/gLSMGdVWHR7t/eV4IKDOMrW9KSnL4A5QxtfqnAjuXDvPmf+ANEMth+6xRqMQX63O7 mfJTfDOBcgu5QLBVhi7LmDnT71SfO0vN214nkP5TTCYvcRxqfQ28nllboGSGNXZtWm7q C/zJyubw5OH4RtF6x+hMon6EvNP8VdjYALBaoHjoEw0wDYtF290DgB73VQzVbhq6SgJH nA3A== 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=jnz4V50o6phhEvPPwYy6NrUJLyV4M4M1sT34MJFZzb0=; b=g0HPQ6ODkiTBa/iVJOXaDBla9xtbLP42kDuO1/uzZOicWT2vWrNVr+6hgUP8k7SLgm PP6plnSAp0eYpcq0nSx0gTFg0kiC+gEsE6jstQGOrqgUIbq+cILZ1JCTJ+DK0uqdul41 5e88xoRZYpQ3uGmVYh3fXQBsq8rsDi9Y8i9v11jaxnB5Y12+FRg68J4qc/6wDEprKlce HvnNHhkMl97z7Ik/FflORZN7xJn2VPn4XJ2hCFKBgARZMnqfntbByskO10N9uSAz/ndn l8tfy/9Yq8d4PUktCDKu/3Z0xE1jyrKIhUO96zLeewc2CSwpCr1S0n9JZGP0nCeRpeAp sqiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JCFJingt; 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 y7si5378241pgp.166.2017.12.01.13.53.22; Fri, 01 Dec 2017 13:53:22 -0800 (PST) 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=JCFJingt; 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 S1752071AbdLAVxI (ORCPT + 28 others); Fri, 1 Dec 2017 16:53:08 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:46594 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbdLAVwR (ORCPT ); Fri, 1 Dec 2017 16:52:17 -0500 Received: by mail-wm0-f68.google.com with SMTP id r78so5883165wme.5 for ; Fri, 01 Dec 2017 13:52:17 -0800 (PST) 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=jnz4V50o6phhEvPPwYy6NrUJLyV4M4M1sT34MJFZzb0=; b=JCFJingtf0uWdr2IMitYLAETJNOSSwQJCHOOSQG25iEZBgX95S4oqwOJ60UA8dLMM+ e+iRYcKKz/+fHToz1l7AE6Qf6dvPekMVtfdfkkRO/vosTO0tFKn9L63sKIRkvq1vx85u Nvvr97R9MJcH+fbYmfxbXQFXN21iFCGCZGeZlEXMuKWolbma4KixsbD3JCOSWRJze1xJ C9wThNKInmEswss5/MP3H3MZYeyjj4RFXRBKFLpNUHdR9oLYGMblVzw/MsZBgRu3Yv7U +JMFQlCkSjg7dVjaMrDk+25zyCGbllN3SpJCZ/0uZttJu6y7gNu3V08bUoiL8KcpK400 eY+g== 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=jnz4V50o6phhEvPPwYy6NrUJLyV4M4M1sT34MJFZzb0=; b=dPMHZyYig5da0F6wlwen8gYc03bSp50bILM3fIgJ4HTBpKw4UEbnypgKvpZZmB65JJ jVXMnKMv+oHAEL3eHumsKBUMtWSH+H2SqG3iE//MsdziTqMFG/Fmiw2SEZ1pC4S5G9cs ulTdgpPwRrnydacyn/ZaC/uC/ZuG4w3f58QnPwSOjWoleIXlq5zBNynn9sIIhsip38ux ksU7h6/+VfIcUUmiGyJZQR03+3XiyjFp6oxeAtd4A1+6yl7Wq4RRybPOzDppHE1HvUli e2L5zxCjnJDw9AnkYf2bnutSMbQVY4pTRWpS5tv8CL58la1wXUllX1Re5O4EPq2atuEl zicg== X-Gm-Message-State: AJaThX5YKFNOJMq8V3ZOpYcqWlYEDmo1hgl/EhPGHlmUmssRfn2ZqoVY cs5Ttm8sFB48BStUgL4GKMA4hg== X-Received: by 10.28.6.2 with SMTP id 2mr2203372wmg.37.1512165136486; Fri, 01 Dec 2017 13:52:16 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:16 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 07/10] clk: cosmetic changes to clk_summary debugfs entry Date: Fri, 1 Dec 2017 22:51:57 +0100 Message-Id: <20171201215200.23523-8-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f69a2176cde1..f6fe5e5595ca 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2241,7 +2241,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, @@ -2268,8 +2268,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 Fri Dec 1 21:51:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120395 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1679278qgn; Fri, 1 Dec 2017 13:53:34 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ8XMeW9QVLY7IUUTBgJiTNS4ayRWN+rjfZLj58oe1g+6fxQnHzm/rG0hoCyLQU91NnuYPO X-Received: by 10.84.244.75 with SMTP id e11mr7438499plt.18.1512165214407; Fri, 01 Dec 2017 13:53:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165214; cv=none; d=google.com; s=arc-20160816; b=w0V+q/v0L5FrkR6d6udjpkzYPddPJkq7zHK7mfxhqXHnR5kdUIyfxe8L/60Af8GH97 SGI4X/DFKMv4sQEPvV68Zx5Vbr3virW/VrRCckk7Aalyc7O3gbwATJ6W6/vYr1AAe8ne 8QCFgllg7POoKTg1uEdp/I6iGzWDF3CSo9uHvgwpL5iZJVf5LUk6CBhzNrJx82PY2gcv HFp4IWsH6eljgzEAqSUlnK6tyg9bUC22nCdgYaWt7Us1M9AgOvgyKJvO4xOUGt6ZeZ7J CuH+Y3ov3i7H7wJIThsCbAbsCI8dbBGDyZU8fPhR3qIJa7SsXUNoMPV/J4zVLXMD41qv aJ2A== 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=KJR4qwAneXORHY/UbNAQJF03pza6vZBlFhsS1f5LygI=; b=FGYOhoa1I0hHjXCy0cs1hAG39SXmlDjy3KJEqPLp+a7KNXLt5E2k/OboAjOFsTucpp tSZRjoBeboW62b1FgJ2+il3r5+O2dJ4w7X0Z0sicKiO2Zg05DXC5bredjs+FHRWEw1Hc fn/K5AnlGeXGYrol8gM/3xc9kljsmdbmOfQPvxSgt+BcvW1QL8WqR/INup/pngriVP5B MOIsQEAVumeZwvKnGWkaUM+9hwWeScb0GDJCpBneOeB+qbjN8vPLaUEJ3ls1IRWkzOag AZM2BP8fQvYbmbqFNyRmheAIosfGKbfQ9Kg1DdjIXWVFWsLeEe9pHYwSCQd0v4pQtt83 l8BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=eJTLRaiB; 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 u3si5545160plb.713.2017.12.01.13.53.34; Fri, 01 Dec 2017 13:53:34 -0800 (PST) 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=eJTLRaiB; 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 S1752035AbdLAVxG (ORCPT + 28 others); Fri, 1 Dec 2017 16:53:06 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36955 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711AbdLAVwS (ORCPT ); Fri, 1 Dec 2017 16:52:18 -0500 Received: by mail-wm0-f66.google.com with SMTP id f140so5636116wmd.2 for ; Fri, 01 Dec 2017 13:52:18 -0800 (PST) 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=KJR4qwAneXORHY/UbNAQJF03pza6vZBlFhsS1f5LygI=; b=eJTLRaiB1Fe6gk3CiyB7x/jOCEGG9nrq137BHPeFOaohKYtMSYya5hqMMtuqwLa3K5 K/Khj+VnjHhgfT/3vKf1FHeIeRkr6K5lc1oTIe2jsWumxkvlXSteRyxtmbs7Ba11Ct2S VVsGq+B80nu7aYrB/obcicQuWxH5whD80GDYxvmhZFvAUD4BI08MIOnBIJwYtBmIU/jj SqcaezN7ascGD/8Kf31hyMmjq7sOje8GG2OJ1MIUVjAhrfLq2qfTBMMJ/FrGKx3TyGPn FOOfeK84p/aPw6j6orX3mSMgA9GKSSMuw25VaWOaNpYhu7r1wbE8/ccytun1mk0OIvcm SLUQ== 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=KJR4qwAneXORHY/UbNAQJF03pza6vZBlFhsS1f5LygI=; b=j1u2xzyrdzoUob8p47hPb2PvDGcjIW/rdfM604qmtSJ6UPHFYLa4+RnqSr87LzT8MI 2ZNVmgr6XUep1Z2VFxyar7TUh6c19PvMq+mYCc7gOeh40BoOXwPAIwImzY9jzlD2VNBA 3os5WlZY9i5frPF34WqkrMMkyYuF//vcLbB5ksNUREHWypNR/6CtOyAnSUNy2mukgysV LFZx3KldTB5g3yKYeIellxpadsYAU/w5fb++CudVX5hMfI2nfqj+zVxZYNLjKgJ2q7R0 DGjG7Q7IW39CmFBzIwzOQfl/BzgtzFRGr45kH6yYZ+BEJEaEzdQc4xEBq+wRRGrX4vCC sCWQ== X-Gm-Message-State: AKGB3mINySQXgL+pr0VN0u2BhuxgI8cPOALK+PxXci8MzPs6L2ryanw6 iBAWyMkeP412gxywjXa1qQ+MjC2m X-Received: by 10.28.69.197 with SMTP id l66mr2232973wmi.67.1512165137768; Fri, 01 Dec 2017 13:52:17 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:17 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 08/10] clk: fix CLK_SET_RATE_GATE with clock rate protection Date: Fri, 1 Dec 2017 22:51:58 +0100 Message-Id: <20171201215200.23523-9-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f6fe5e5595ca..1af843ae20ff 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -605,6 +605,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; @@ -679,6 +682,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; unprepare: clk_core_unprepare(core->parent); @@ -1780,9 +1793,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 Fri Dec 1 21:51:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120396 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1679424qgn; Fri, 1 Dec 2017 13:53:44 -0800 (PST) X-Google-Smtp-Source: AGs4zMb6zrUUUVtaiK0tutEsoYApKJbdgR1cqll2hW8oMcCnE+9dnGPpx2cn9ql9/hqDVF3rCksV X-Received: by 10.101.82.203 with SMTP id z11mr7180394pgp.404.1512165224692; Fri, 01 Dec 2017 13:53:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165224; cv=none; d=google.com; s=arc-20160816; b=xQ3qhRiz1SH5/EeK1GI0w8DjWOqI9VINkylkTjNyrgZSX7fEFJUqcAp8dGUnYdoPhv RrpZN4/aChrufYZHhFP8g3AbCgrw/J2aVtLMzag6LZxnlPhxkm4actMRcMiBeSi68hBI PUdQ4byPNnX9bOtcIfsVDpnt77BXJe7+TNqgT9ZQKc/7geKusS0/hfdhjUG7wIh+KEL/ aBFOTblxfWlfWh6W0XZOAgoSbIx2k63AMxlm0pPpxeE9cqD2fY6LM6HzXTGAebZDipWD fZ7amzdO3705HBwn8OlNANFlrjxw7fn/0kKX+22Ia/v8qWlJXF6ZEGA6Uo9SPaJO9tr/ r8EQ== 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=12sdR7BNlfXlbjnAiHs7Gvk4bg/Pr2uP3x7VvxQl4I8=; b=MHV1FY3OIR+mIIxkze2YCcnqnG7foT6bMMC+oL2RsUYrsRDKiF0hiQhEZgiPAMpIJ4 XMAoJi0CyMvyxRmn6y7JktZTQxROlQKHoYZXqsDNO0BodEAMky+Kdy94RUFOoZWQ6WiT +BTDYOBmXhIaVb7QRhw0KgvDcprGiEhSEd4z9gmg4WPrnn9VGSJQ4XrRUkhss3b8y7bv FMmfwjqrbk7PvRqYOckoWjIc/vi09DmYhdX6NUPEMpK+m2JJSEYslCWQSgT4vHGyEAfq fgQhNGyoAEZ5f/KxQCD7imr+QjqfaNRuVXRz7PYOHAysvop19a4pArVpXq3yJyo2l5Pp RlyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JHj2TGXp; 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 k33si1564656pld.119.2017.12.01.13.53.44; Fri, 01 Dec 2017 13:53:44 -0800 (PST) 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=JHj2TGXp; 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 S1751990AbdLAVxD (ORCPT + 28 others); Fri, 1 Dec 2017 16:53:03 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:39781 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751747AbdLAVwU (ORCPT ); Fri, 1 Dec 2017 16:52:20 -0500 Received: by mail-wm0-f65.google.com with SMTP id i11so5619893wmf.4 for ; Fri, 01 Dec 2017 13:52:19 -0800 (PST) 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=12sdR7BNlfXlbjnAiHs7Gvk4bg/Pr2uP3x7VvxQl4I8=; b=JHj2TGXpVqFHFsYtj2yt9HZKXJtuAMgEvZ1VgOvjgzmEJi7QoedgKciEUugXAqG0/9 wSFTSiRnQ/we2+2dAe4XIS/O+dJHe3dPrEo+n2AlE1I5T857yX/qoViw9raYksYqrSvn SmGmBOh6lmBhx1nc0zWObfG0caaxmkPIuhT2ZNPR86PZ5TRYwTNScFg5Qn8gDQsMd39o z+aqzPBJV0V7xCoN2oHe/TaJGZL+1Q1+z+9LoRcTvu7BCTER/tnfnoY+ENl9pqMvCFZF m2YcGwkeUc3s+sVUlDmwJbj0z84uRliafxaZ/HYe4qSl0VBgz0VqTTFCn9o2Nw3cFTRp Ouqw== 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=12sdR7BNlfXlbjnAiHs7Gvk4bg/Pr2uP3x7VvxQl4I8=; b=DN/vz3+z+1RgDIhB8eJuTXg1o7Wr/HZi/lG9Y8qHN1Q138XeVM0WS87gjrKirlc5NY oJwIqusn0BvcrGNTRIcYzuM5Ef1rchJcYeQThLo/CCC+BL9PIewBD3ErfRHh0RhRTimN YH8h1ZbjcEntzLJ4GxoBDAg2fVctHlxc8BK+FsxOoH3DKgoQtF+ZnmzaeYo2NjjVDcPA pEiGPlWR40RCjrs7v5J+SgzyH35Sp4CUFPYPgsknxfLBc1l2gs58/IgGsimRtKEQS8bw P3cn+H0mM8bRoZMljommYUMJ/Ix0ZtZoaNCZMxCkObcoT+p/W+SIbK/bdfPYOGO33kI7 64hQ== X-Gm-Message-State: AJaThX646ZC7h6TSOaS5drt2B2X55FoMWA5Lp62NZN4pvr+GUudWiG02 0dMvXHhCJ3aoZNh0ycWC6ltdSw== X-Received: by 10.28.62.5 with SMTP id l5mr2203702wma.47.1512165139198; Fri, 01 Dec 2017 13:52:19 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:18 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 09/10] clk: add clk_rate_exclusive api Date: Fri, 1 Dec 2017 22:51:59 +0100 Message-Id: <20171201215200.23523-10-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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 Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 62 +++++++++++++++++++ 2 files changed, 234 insertions(+) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 1af843ae20ff..edd965d8f41d 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -87,6 +87,7 @@ struct clk { const char *con_id; unsigned long min_rate; unsigned long max_rate; + unsigned int exclusive_count; struct hlist_node clks_node; }; @@ -565,6 +566,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); @@ -592,6 +632,38 @@ 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. + * Returns 0 on success, -EERROR otherwise + */ +int clk_rate_exclusive_get(struct clk *clk) +{ + if (!clk) + return 0; + + clk_prepare_lock(); + clk_core_rate_protect(clk->core); + clk->exclusive_count++; + clk_prepare_unlock(); + + return 0; +} +EXPORT_SYMBOL_GPL(clk_rate_exclusive_get); + static void clk_core_unprepare(struct clk_core *core) { lockdep_assert_held(&prepare_lock); @@ -1001,6 +1073,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) { @@ -1117,10 +1195,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) @@ -1853,14 +1938,67 @@ 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; } 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. + * + * Calls to clk_rate_exclusive_get() should be balanced with calls to + * clk_rate_exclusive_put(). + * + * 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 @@ -1885,12 +2023,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; @@ -2101,8 +2245,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; @@ -2164,7 +2316,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; @@ -3185,6 +3345,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..4c4ef9f34db3 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -331,6 +331,38 @@ 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. + * + * Returns success (0) or negative errno. + */ +int 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. @@ -472,6 +504,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 @@ -583,6 +632,14 @@ 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 int clk_rate_exclusive_get(struct clk *clk) +{ + return 0; +} + +static inline void clk_rate_exclusive_put(struct clk *clk) {} + static inline int clk_enable(struct clk *clk) { return 0; @@ -609,6 +666,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 Fri Dec 1 21:52:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120392 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1678631qgn; Fri, 1 Dec 2017 13:52:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMakUyptJMZOHKCSmEwggw563TJdWjEpM7PzJtP51bA1rf8Qy7i0sk1N9TLz0JCqeFQ5aD35 X-Received: by 10.99.123.14 with SMTP id w14mr7211883pgc.172.1512165167309; Fri, 01 Dec 2017 13:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165167; cv=none; d=google.com; s=arc-20160816; b=ynYblFmybIyFMjDSy6V1msSoHeILR62fNiH3AKONAwtpe7ebcA0C8xkGphIGAvUcIg hvP7yZpPq7IiTOl/TdUd4oBcrZP8Vl/f+XJexaSk++w5UtAEyhuktwLoZyFY4KmrejtN aZ4tuVXy5VwyfCG0mvXgMN7Ao3oAUfJsvZMA6VpWn5Lm4z+GhhnRVlv29n8bIHqF/sYu IT4+X47RfskW2LV0dmtXh89QG4fLQI6MwrprcThfLsHPURfQhMZqBGAEekkluZy+PlZf oYG2m7AVpb+Uz6Ngl+IZnNBOkHMb/3YPOkg2oNmwI5Kq18Xh5lI37OP5YnzK4jhKzNBo 2Kow== 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=x6/6Kk0+CmLoTS3WbV3hSeRPHiEDFQVvvOu9AJAJsos=; b=mJuoUaN37avBT0WGqj+YVg5QFwRtAWzEblEwxQCOIp4WLzu0qUl7j2beThjWY8dI/4 10t4Xfz3W2HpBTnevogLMWYKGcr/7i8knGhKlmUiOma7oIfdburJTAhrrjcZ2STAfSt4 m+MYicHeYbFx4ENc0e6NPu8Gd+L9/voAY1eB/Y4SEWfm8RezZIAFrDQl0E8hU1/QigAu mgjqd1bwtaLkO2D03FaFy0FwAm284bOGUyBaAL3NO5Tyf5mn2k0LGL9K2a3LmSTMKqag u8LNRrM0eTEgeyI1VoaqU+VoDzSXfDzgRFGv8CCOu3kauqJZqamkzulp+MY803Ga+TIt lP1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=G/8jQnkk; 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 1si5551759pls.720.2017.12.01.13.52.47; Fri, 01 Dec 2017 13:52:47 -0800 (PST) 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=G/8jQnkk; 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 S1751918AbdLAVwp (ORCPT + 28 others); Fri, 1 Dec 2017 16:52:45 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:42325 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751752AbdLAVwV (ORCPT ); Fri, 1 Dec 2017 16:52:21 -0500 Received: by mail-wm0-f67.google.com with SMTP id l141so5899243wmg.1 for ; Fri, 01 Dec 2017 13:52:21 -0800 (PST) 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=x6/6Kk0+CmLoTS3WbV3hSeRPHiEDFQVvvOu9AJAJsos=; b=G/8jQnkkUIARtqMjR5IQ/OdnRe10ys2QSwIosQg5Oln/p5ZYNCnacSC9OcYfNtvu7y I6SWvaeQuDVZ1wior9WvvqqdKvwYTFbvq6q83D3LIk1/A+FzDxIBT3chVEcXkHIteBsn QaUlINNx/Gr0MAYGkoLx8JTyEJOG6mKgusqZ39f6lQaESSbsHNJJHydwENpbCYlF9o2r +6U6B+cMqzc19wG9IleoY/f427Ert9OtgCYp0GrCWOJyvMI770lYm/NFq5Af/KoEzCGP ++FneF2qvuqSScgNgWmsd1fkoFzRC++8XbR2+oDpnFaL2W7AfBfcelvkaIj9wUbzD4dF 8A5g== 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=x6/6Kk0+CmLoTS3WbV3hSeRPHiEDFQVvvOu9AJAJsos=; b=N1KDmFUkNZFr9Ck8jHKKMfvkEhAYhKK4DI5Gx+6tCFcfAyeyNqKgBEyB/n+1hD+gXV zvZzP4sK+AdHDDPx/5gTLQcg5uKJ7yPM4w0J5r41WE2SzyA4FPr5kmfxqjrIfKKceiej AozuF0QxE/2rSqXitoTL26NB8tMqBXF8SMUOcvYA4GNUhqpTEp9g24cskQepaoDH5aK1 LmHjSUNkot/YMtA00BXD/23RfIobiIT6W8z3Ke2vEmaaE0eiGbFS5aFjfzYVm4SptLMu Jk3p9Fgvuggt/gmV2txzr0uSOuR9SY579cHu5Zy+wNeKcjq5okDCycyXnQ0gegbUNLJd MD/A== X-Gm-Message-State: AKGB3mJZ9756vG2xATr/iwAJxrtLCaVC2cTfdONZWVRK8UP58I9vtpUN K9pGzDzwi5Ti0eaDHH0CwudvFw== X-Received: by 10.28.8.67 with SMTP id 64mr2189604wmi.34.1512165140475; Fri, 01 Dec 2017 13:52:20 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:19 -0800 (PST) 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 , Maxime Ripard Subject: [PATCH v5 10/10] clk: fix set_rate_range when current rate is out of range Date: Fri, 1 Dec 2017 22:52:00 +0100 Message-Id: <20171201215200.23523-11-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-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") Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index edd965d8f41d..369933831705 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2010,6 +2010,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; @@ -2026,10 +2027,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)