From patchwork Sun May 21 21:59: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: 9739465 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 019686034C for ; Sun, 21 May 2017 22:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6F9F285C9 for ; Sun, 21 May 2017 22:00:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA6672863D; Sun, 21 May 2017 22:00:22 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C74C1285DB for ; Sun, 21 May 2017 22:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756927AbdEUWAV (ORCPT ); Sun, 21 May 2017 18:00:21 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:34142 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756798AbdEUWAU (ORCPT ); Sun, 21 May 2017 18:00:20 -0400 Received: by mail-wm0-f47.google.com with SMTP id 123so7276739wmg.1 for ; Sun, 21 May 2017 15:00:20 -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=7NSPmFbluQ7ZF8G4SPON7ttBS9Z4U4wPVtlTcyOVuIU=; b=qvEed7lnBCFQYfIl5/Sv4kMqs0PRAbSDrz6IC63SlQiKUgFUy7364ueakN096S1Ufr yfvyII0TaWklYBUpFXaKCqLyKCft8w0CNyPeS/E8fAb80+ctaZaEdVwp5OexPUwdoRL+ rYsvYAvNeNucQLQTPSKWctBVyVfh/9fAFGRayUzaLxamWN96G8ScbTlggVkgmm9T64sw PEYp0B0ue3vaRCkdG+3mnoo4ycGZLF5qKxaAaSDCS6toCZEM7Y4eWiOuEvWRZ2+ggfWO JlOqkrAtGTmAzCSaomyesvmKU+c6x3GgDOe2H07B2oieRUoBgxLxo4fnR7Uy5wLzvfHD Rx/Q== 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=7NSPmFbluQ7ZF8G4SPON7ttBS9Z4U4wPVtlTcyOVuIU=; b=DtPRRm7ni1fWYkGeAilB/OzimlNhWR42p+uQp2m6X2vz9XyStEhreTcNfJXzW/pa+F enMwRHcdG1newj1pc2CaY7CcshNp2qBv3aZoJHAGULEkPbPDnuVifihfnzLzQB8hLlkp fs+ctlVrg5cIAchun55t9OaoQziaaUeoGks4ezQI5dqc9zdb+vbb41si8smkeHAmGFS+ 5iTzsgtFegiD3wES++gcnPrrHggo9n1CLBWEqGrCRWEZNn3s08plqz0BhNU877gNIJXg xJU2iv6UyLu85vRnOG1Yq9Y08bwJAyAsWagDtPvz2zTJNR8J4pRdNxQp6DhgviN6BE48 zDfw== X-Gm-Message-State: AODbwcBm8oC8lMDQbM1JRsj6V24aWdEP/T9n58lhUARR046O8XLj/sDf m0xxXElsQQbY0XKvyPY= X-Received: by 10.28.215.13 with SMTP id o13mr13187941wmg.126.1495404019403; Sun, 21 May 2017 15:00:19 -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 a73sm12812579wrc.58.2017.05.21.15.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 May 2017 15:00:18 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , Kevin Hilman Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org, Russell King , Linus Walleij , Boris Brezillon Subject: [PATCH v2 06/11] clk: add clk_set_rate_protect Date: Sun, 21 May 2017 23:59:53 +0200 Message-Id: <20170521215958.19743-7-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170521215958.19743-1-jbrunet@baylibre.com> References: <20170521215958.19743-1-jbrunet@baylibre.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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 a0524e3bfaca..33ec990b2e97 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 85d73e02df40..d3c299d23ae7 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -388,6 +388,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 @@ -506,6 +515,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;