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: 9782689 X-Patchwork-Delegate: sboyd@codeaurora.org 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 ADC22602DA for ; Mon, 12 Jun 2017 19:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FE81284EE for ; Mon, 12 Jun 2017 19:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94A08284F1; Mon, 12 Jun 2017 19:45:03 +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 8867B286B7 for ; Mon, 12 Jun 2017 19:45:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752705AbdFLTpC (ORCPT ); Mon, 12 Jun 2017 15:45:02 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:34373 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752697AbdFLTpB (ORCPT ); Mon, 12 Jun 2017 15:45:01 -0400 Received: by mail-wr0-f181.google.com with SMTP id g76so108159840wrd.1 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=A/cp+Aq4d0VQHLsSF33pGDtOSG+coEvdxEIlW+6DrqMA45wh4xF9QHJ+iyELGLCnTC sQpCEfAGXPE6Jj8ZlxDxekijYrX76cyaciXyJZOy1BnVSLbCdmJiVu33hT2t4PPZekwU jVRCPBtw9iRujx31eVy4YHFyBl/SVZRkuGJK56LxXoZi1n1iQ40sgMhrw11Y5wx2hE/v HcDnhICJC51JC3VJCtX1cPjVpYPZdPISvPv6SHUFQIFMQ7m3wxQh2IK6bp7sgRMduMYv loR5ZDLcfqhYKdr91HQb7ggEBkdkPFmRpjVHnc51e4MMcHWcuNpvBN3/QTpxiBCyQvks Pevg== X-Gm-Message-State: AKS2vOzTMOS+LyIkCXUlffyqTQ9pMKzQMp+eJj67lnT0NDhqhuGQyNUM SXZ+BKa1Cs0EAFUa 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 Cc: Jerome Brunet , Kevin Hilman , linux-amlogic@lists.infradead.org, Russell King , Linus Walleij , Boris Brezillon 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> 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 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;