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: 9734787 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 3A320601C8 for ; Thu, 18 May 2017 16:38:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 288CF28775 for ; Thu, 18 May 2017 16:38:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C02328833; Thu, 18 May 2017 16:38:18 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 E82EF28775 for ; Thu, 18 May 2017 16:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932325AbdERQiQ (ORCPT ); Thu, 18 May 2017 12:38:16 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:38896 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756640AbdERQiN (ORCPT ); Thu, 18 May 2017 12:38:13 -0400 Received: by mail-wm0-f53.google.com with SMTP id v15so58895775wmv.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=SjdZ0O2diwJOy1oxnFZ14T89PVxQU5jXKSxw/QSprKn2QfWgTA4us2re3IacvnplW1 LU0ChrbpRLHxWT5E+zS61AhtDlv4lEfxZ1ngPqKmGagehw/HXCfPS1JKC6/Yo51/6SoH 9qlyIZt3YqurvzL43ptSIlu8bo7BpHfBM6K/119c5xsCuLs6Wq1SVAv+fcsw57EL7C1U 5PKSBHZBgFiG4c3eOqAUNhDfibfIdSJsznwv7Iu4lnz+WRC/MpDB32jHA/KXSJbjvWv/ yKmCyJr4Vl4Syp71Fl+QHbQwuRLeoa4Ut2CV/2ikmYHhhxebPi3inFto2IitLl5z6dvj BQ6g== X-Gm-Message-State: AODbwcDPw/zoqwP06GWUQxnb1AQro/aSZcxBb+gm5tE+o6heh2kiy3+t 56ETk38eOGAYID1R 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 Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org, Russell King 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> 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 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;