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: 9739495 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 DF79F6034C for ; Sun, 21 May 2017 22:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFCA0285C9 for ; Sun, 21 May 2017 22:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4AFD285F3; Sun, 21 May 2017 22:01:07 +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 7A9F6285C9 for ; Sun, 21 May 2017 22:01:07 +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=yxYAtMkL/TUSa/DOHZ/hNscHxbDw4f03J/vGOeCeUzw=; b=ZgGRYlAXbd1jKrspNdLDWYD7iL U3mo6IyuaHAmkNJz1EDjEqJTTbYwSsGVpeCjbEVNAN5x/tbkKmq8lwONqZSB3RD53hvEZ0tIcJvNs OJL6/rpEnpUfFxEJ0OZxiEjnMBHzPWehD7QUzP5q8eLW8JbVsYa1vmrMjxtM4Fj/+tEAak2CbDDTH +vpcdH9gD0/mC3HBuF+Oz8T3xS/SRg8Q0AP4BXpJmbh56V7e1wViL8l9WxARFzDzEdPKn1MR4PT4P lHxw8XzZceJqpTYgbNUcSFXX/2Ez73f6xljeXTnp3OAaCgOmkUAC/ddieacojwocJI78UVoBOy6mA 3wVSzKvg==; 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 1dCYuH-0002hw-Ub; Sun, 21 May 2017 22:00:57 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dCYu1-0002Lz-5h for linux-amlogic@lists.infradead.org; Sun, 21 May 2017 22:00:44 +0000 Received: by mail-wm0-x22a.google.com with SMTP id 123so7276738wmg.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=EQkypU0feTgQDGUVDj7/iyn2LOraPoE6ovS6qUWp9Z5dEK37YUFf3WWU/csJVbsLz8 MGx7KuNsNqeqNbvlAMaFhGodPozjCcbAg0N4PCNI46DkI6BcRdWCvk5CzbY4e+J9h9PW Q/RuBw44PnLRUe9MUvm+dtrjg2Dz3bwyRQVgWp//I1KnVMe/o6uPT8Ik6mnh07SmQRJQ rsfLQiVq3zzcls8HHOvOlJ4wCmJBX1ePsmHM/f01XAVYm57Q9qefe13RZcIuW+QoJh7J 8JRIvC2V/GePqI3apUPHefT0vFeaqe7W0hkDg/gJIL3nTr+BdTf6VKt2IC6/qiMt4oqZ AcsQ== X-Gm-Message-State: AODbwcAy/8X/WaJX3e3S7KwMppE2UIRYxmOxyiCfKxoff5l+vJOF03SI NMQsFmduYgpoP7IZ 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170521_150041_627075_EA2565F2 X-CRM114-Status: GOOD ( 14.67 ) 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 , Linus Walleij , 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 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;