From patchwork Thu May 18 16:37: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: 9734799 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 CE613601C8 for ; Thu, 18 May 2017 16:38:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC89B2879E for ; Thu, 18 May 2017 16:38:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B11842883C; Thu, 18 May 2017 16:38:52 +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 62EE528833 for ; Thu, 18 May 2017 16:38:52 +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=S+f3cYiEiEKkWg4yFnQyH7WAwMgSV0ET1Ugjzo+UAZc=; b=cFCOdf4ygj+6IPcqcFgO5IqR74 snNLhTZqk8ON8+FO7F5wid2pIrQCAay5ichJT5uqLLA/aG8FJHlwRMJbQisvbQ/qnGCC3WWBQOn+o pql6GTCMt8ZK+wqqdMFm57I4Zjm/DbfWx3xShl8a5MpvHkBUUC6LTlXEzpFje3KLhSrdiPEvgMKiM wrqjZsXcfGP6e+BouqB0DchI2owVtTcvjwUSR0tAl8ieSPGhXaHSKEch8K4YfVdqhelG5mthdI9CL /cm8C/AbJxVzy6hRQRoUOw+5DTx3URNeth88/i+3CqobFnRE6rXrTAMEv0tztMvfjx87J1/FCs/zH v78hSx1A==; 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 1dBORm-0003OJ-Sr; Thu, 18 May 2017 16:38:42 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dBORc-0003Fy-PB for linux-amlogic@lists.infradead.org; Thu, 18 May 2017 16:38:37 +0000 Received: by mail-wm0-x235.google.com with SMTP id 70so53063597wmq.1 for ; Thu, 18 May 2017 09:38:13 -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=k6l9KArm0Wtvr75fuxjq6QDA9mTCWUBQldvolDelk7o=; b=ZSfa7Su69KHdFoES0pBgMfvaT6GwNFJfqJkIW4NU3E3D/IcMxEy0089X7Eqi3y0D1L LRB3qmVW+f8qqfws/iifxrxi+RHSf4JmPKA0+VRdWBnenjdii6XTx2dN2b6un0IZg9yf bIEH3OVy1ihj8fLB9nKONMctae9ej+3vdfxk6lkHKgNgqWld3wqKhakjgGJqM4ju/hyi HaQaxZUKdH0knoJB4llCXGNxvZFc6nwNkUoJAmzjRCaVxtlPDeY2et24h4VukpcQy4yo mUzTalMfUZmG/2M2/uDtNoGBdnr46sS/Ssm4zitzvW4FPhhzUOmbsWp8nkTbVhFTWD4r tSmg== 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=k6l9KArm0Wtvr75fuxjq6QDA9mTCWUBQldvolDelk7o=; b=UqkTVrnRjgub9srmSSAmf+5iS9iaDKsye6iM7wwMlMy1XPOy3v7GhJpdweAg07oVaq 1xaVXEapAXW1Y2+oOhOvnhrTk6Kg3ev9QtWhG11uba+X4r5ecOGhVUNVD7qzaWufR7zK i+IDGvHk3Qo9Qv4TxtlZGzdAz5/mrI550R5hFUh/X8q3DTUoDO4X/Q+zWIURwtxjitj9 lYZ0jWUv2jn8wYXaHBEKjjAjOuwOKiDnqZ2X7qg5XJYzs73HEPf1v67ZuC5aWonxIbdt 1GmwEtXtctdkRkm2lYyXdev8JpIiMhHAVOehRuouisEuqgRmtrKPKHF2j2Mb5aDh92AN uv4w== X-Gm-Message-State: AODbwcBVxkLtebbRGYMRYgieBbSo7x+ZhQHJLcC4rbWvMQ10pFV5xGNQ NjAOOpHzlrQROAth X-Received: by 10.28.29.17 with SMTP id d17mr3880984wmd.90.1495125492360; Thu, 18 May 2017 09:38:12 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id 4sm7357655wrv.33.2017.05.18.09.38.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 09:38:11 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , Kevin Hilman Subject: [PATCH 05/10] clk: add clk_set_rate_protect Date: Thu, 18 May 2017 18:37:59 +0200 Message-Id: <20170518163804.14123-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170518163804.14123-1-jbrunet@baylibre.com> References: <20170518163804.14123-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170518_093833_045586_A12F93DF X-CRM114-Status: GOOD ( 14.31 ) 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: Russell King , linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.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 9c15319bc454..132eb1a2938f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1781,6 +1781,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;