From patchwork Mon Jun 12 19:44:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9782701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 768CB602DA for ; Mon, 12 Jun 2017 19:45:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67FEF27F86 for ; Mon, 12 Jun 2017 19:45:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CC6E284EE; Mon, 12 Jun 2017 19:45:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0E42D27F86 for ; Mon, 12 Jun 2017 19:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pZpQlljEhaOG14GzouwdFb0Bx2TyQ5K4mbGYk5gEyKo=; b=pJwFn+KT84CEgek09r2VUBVv/B q+GQ/Ww8chfh+PDaTCG57AZFNhsOMCpmlNc11uyy1cuWgG4VeptbCOvGK9z5rE3fdY/i0ihlOf4U7 SuMUEUOJWZjWnkXBaVVzWGBylE0JCFgKhp5lLJzc76qocKmGsiF1MPbxx+tWmtXo+mXu7DGZIWz4W YM/C1qeJ5ZL7DNE4qMxOshfHAOnCpju1jwdEkAS9JEBK3RcRrpGmvTZWpoQpjkcsrWA7jovFG+Z9F 7rmYeCjWbjRfvyNz20fj2kMmCY3SVSz3CPzh00OWJLqso3Hm2cmWXEZwUIcQZ8hqrvffdyccdR0Yd orkFzedw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dKVH7-0004q3-4n; Mon, 12 Jun 2017 19:45:21 +0000 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKVH0-0003RP-Ug for linux-amlogic@lists.infradead.org; Mon, 12 Jun 2017 19:45:17 +0000 Received: by mail-wr0-x233.google.com with SMTP id q97so111395698wrb.2 for ; Mon, 12 Jun 2017 12:44:55 -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=lG2RQeqBcBwyywowkCrRdAdMRxTZ6gZ19JRxvoSh/Do=; b=biXnC7sIqR0iMHd4dWZ0t0Ms/+q34KVL8wzYT2FfyOgTegM1UQU+J/uP06cg5QCfzi hJesErONZeShe61DjrfR0pEBhNzBnkXteYw2u+h4h2MbfphZEy2xKyvFx1YPqiHvThy6 jPV4ysDSvqhND0C8pD+HLAIx62fpOYNmfKVXasfWmO9u8DvaB/3gyhfqla8c0FBuwPGp dtgn7KzLU6CikSXOlng1H86nd4BV8lxPKSQUKbVrHei029RATq8TKZmaOaOQrFqZ/IU/ SbgxymUMRwAsAjUylQAPORRAZoXGFAedxlkF6Yrl/6pO69jjjTTjJbFw/ZwPWspasCTS P5GA== 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=lG2RQeqBcBwyywowkCrRdAdMRxTZ6gZ19JRxvoSh/Do=; b=Tiqm8yyQHpI1L6pOXS3xZ8v8Zekl0I+5PmQJlDw0pcZubtGY6zM84dEDuwI6eQhOBW PCS5N3sgwbfncgIjd/CU70jMVmEQYEh+RmYAU9rVxynFEylR2kFnam2sXdP/bGba1rnu GPe+Lc40IsXsKTNwfqR+nUnq0ab7eciZ8xhhLe8rxmwl8tjz5E2IDrvKdiTXWNUCrDjx sR+TpyJHOEuXt0sqPshJnr+Ddwklt7H1tpdgnEC9IOTrDFaJQLVTqNq+BnyRui9GtUoO 42PiNImxK/ooLg1K4zCoXvf7pV8hGLzwZ/5LAca2RqcgBqAZQiu/G+QaszabQNXXD3mw rQHA== X-Gm-Message-State: AKS2vOw6DHNSg4u+wjqHuY1jcDZqmZ4HdFuPLIXxAJtct0/0CXq55VDd YDnZsIrffJdKPXNN X-Received: by 10.28.140.212 with SMTP id o203mr8716069wmd.66.1497296694227; Mon, 12 Jun 2017 12:44:54 -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 70sm13250797wmu.28.2017.06.12.12.44.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 12:44:53 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH v3 06/10] clk: add clk_set_rate_protect Date: Mon, 12 Jun 2017 21:44:34 +0200 Message-Id: <20170612194438.12298-7-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170612194438.12298-1-jbrunet@baylibre.com> References: <20170612194438.12298-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170612_124515_261192_F28E2ABE X-CRM114-Status: GOOD ( 14.50 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Kevin Hilman , Linus Walleij , Russell King , linux-amlogic@lists.infradead.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP clk_set_rate_protect is a combination of clk_set_rate and clk_rate_protect within a critical section. In case where several protecting consumers compete to set the rate of the same provider, it provides a way to make sure that at least one of them will be satisfied before the resource is locked. This is to avoid the unlikely situation where several consumers protect a clock provider and none actually get a rate it can work with. Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 14 ++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index d688b8f59a59..d91236e70a04 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1809,6 +1809,51 @@ int clk_set_rate(struct clk *clk, unsigned long rate) EXPORT_SYMBOL_GPL(clk_set_rate); /** + * clk_set_rate_protect - specify a new rate and protect it + * @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_protect within + * a critical section + * + * This can be used initially to ensure that at least 1 consumers is + * statisfied when several protecting consummers are competing for the + * same clock provider. + * + * The protection is not applied if setting the rate failed. + * + * Returns 0 on success, -EERROR otherwise. + */ +int clk_set_rate_protect(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 in 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->protect_count++; + } + + clk_prepare_unlock(); + + return ret; +} +EXPORT_SYMBOL_GPL(clk_set_rate_protect); + +/** * clk_set_rate_range - set a rate range for a clock source * @clk: clock source * @min: desired minimum clock rate in Hz, inclusive diff --git a/include/linux/clk.h b/include/linux/clk.h index b60c36f2e6b0..7a01b32f7029 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -497,6 +497,15 @@ long clk_round_rate(struct clk *clk, unsigned long rate); int clk_set_rate(struct clk *clk, unsigned long rate); /** + * clk_set_rate_protect - set and protect the clock rate for a clock source + * @clk: clock source + * @rate: desired clock rate in Hz + * + * Returns success (0) or negative errno. + */ +int clk_set_rate_protect(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 @@ -638,6 +647,11 @@ static inline int clk_set_rate(struct clk *clk, unsigned long rate) return 0; } +static inline int clk_set_rate_protect(struct clk *clk, unsigned long rate) +{ + return 0; +} + static inline long clk_round_rate(struct clk *clk, unsigned long rate) { return 0;