From patchwork Wed Jul 22 13:04:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 51347 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 1C3DB20323 for ; Wed, 22 Jul 2015 13:06:31 +0000 (UTC) Received: by lbvb1 with SMTP id b1sf57038000lbv.3 for ; Wed, 22 Jul 2015 06:06:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:cc:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=G7OvuWN4xfsDhX1xKH1cSfZ25010ChoGKfJgygomL1o=; b=W5H01inHGoATsxRd/xbNrav9hQGAlBUeBycEBZzq/XRiQatTjMW1ljsKfhswLONq1v GpGC33myUW9jCa2/X2e9v2GjO3nPaOLOxJhYyDBORHTWEVhVltjIx6AOU29jvzyEswE0 HUNMjjquOP8nasAWvMV+zHLQpngaBuxS0Rtkxb1tmf0pp1M9Qz4efqXkcR+XUyh7gJb7 wx7mT4G3lqe2Gk7jYS+cASGzotVejsEXrjrqNIZLzcVBNQOV0u9+kOX1P0P9qG+KYTT+ 5wmjIJd6bKtwROnwWrVy3YabLLD7KQEDJ/hpmU/TjpAAMYKHKpFMMtzSwHmFx/XH3kBO rN0w== X-Gm-Message-State: ALoCoQkf0TEhkTzdHcNl5SZCJN2zgCuZoOK752kweGn57gQTwiwx1XXm+nx2/9YGyoagWxtynK2Z X-Received: by 10.112.42.236 with SMTP id r12mr1194121lbl.2.1437570390107; Wed, 22 Jul 2015 06:06:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.227 with SMTP id n3ls87812lan.0.gmail; Wed, 22 Jul 2015 06:06:29 -0700 (PDT) X-Received: by 10.112.55.207 with SMTP id u15mr2284000lbp.88.1437570389951; Wed, 22 Jul 2015 06:06:29 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id jt6si1153915lab.77.2015.07.22.06.06.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jul 2015 06:06:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lblf12 with SMTP id f12so136180137lbl.2 for ; Wed, 22 Jul 2015 06:06:29 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr2233393lak.117.1437570389833; Wed, 22 Jul 2015 06:06:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2105790lba; Wed, 22 Jul 2015 06:06:28 -0700 (PDT) X-Received: by 10.202.86.215 with SMTP id k206mr2189423oib.13.1437570388202; Wed, 22 Jul 2015 06:06:28 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id k1si3732876pdr.179.2015.07.22.06.06.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jul 2015 06:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHtht-0006rG-Ph; Wed, 22 Jul 2015 13:05:09 +0000 Received: from mail-wi0-f179.google.com ([209.85.212.179]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHthT-0006Pq-0s for linux-arm-kernel@lists.infradead.org; Wed, 22 Jul 2015 13:04:43 +0000 Received: by wibxm9 with SMTP id xm9so162593215wib.0 for ; Wed, 22 Jul 2015 06:04:24 -0700 (PDT) X-Received: by 10.194.236.161 with SMTP id uv1mr5303195wjc.158.1437570264213; Wed, 22 Jul 2015 06:04:24 -0700 (PDT) Received: from localhost.localdomain (host81-129-173-55.range81-129.btcentralplus.com. [81.129.173.55]) by smtp.gmail.com with ESMTPSA id qq1sm2359327wjc.0.2015.07.22.06.04.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Jul 2015 06:04:23 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 3/5] clk: Supply the critical clock {init, enable, disable} framework Date: Wed, 22 Jul 2015 14:04:13 +0100 Message-Id: <1437570255-21049-4-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437570255-21049-1-git-send-email-lee.jones@linaro.org> References: <1437570255-21049-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150722_060443_226623_AD995596 X-CRM114-Status: GOOD ( 18.55 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.179 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.179 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: devicetree@vger.kernel.org, mturquette@linaro.org, kernel@stlinux.com, s.hauer@pengutronix.de, sboyd@codeaurora.org, geert@linux-m68k.org, maxime.ripard@free-electrons.com, Lee Jones MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 These new API calls will firstly provide a mechanisms to tag a clock as critical and secondly allow any knowledgeable driver to (un)gate clocks, even if they are marked as critical. Suggested-by: Maxime Ripard Signed-off-by: Lee Jones --- drivers/clk/clk.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 2 ++ include/linux/clk.h | 30 +++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 61c3fc5..486b1da 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -46,6 +46,21 @@ static struct clk_core *clk_core_lookup(const char *name); /*** private data structures ***/ +/** + * struct critical - Provides 'play' over critical clocks. A clock can be + * marked as critical, meaning that it should not be + * disabled. However, if a driver which is aware of the + * critical behaviour wants to control it, it can do so + * using clk_enable_critical() and clk_disable_critical(). + * + * @enabled Is clock critical? Once set, doesn't change + * @leave_on Self explanatory. Can be disabled by knowledgeable drivers + */ +struct critical { + bool enabled; + bool leave_on; +}; + struct clk_core { const char *name; const struct clk_ops *ops; @@ -75,6 +90,7 @@ struct clk_core { struct dentry *dentry; #endif struct kref ref; + struct critical critical; }; struct clk { @@ -995,6 +1011,10 @@ static void clk_core_disable(struct clk_core *clk) if (WARN_ON(clk->enable_count == 0)) return; + /* Refuse to turn off a critical clock */ + if (clk->enable_count == 1 && clk->critical.leave_on) + return; + if (--clk->enable_count > 0) return; @@ -1037,6 +1057,13 @@ void clk_disable(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_disable); +void clk_disable_critical(struct clk *clk) +{ + clk->core->critical.leave_on = false; + clk_disable(clk); +} +EXPORT_SYMBOL_GPL(clk_disable_critical); + static int clk_core_enable(struct clk_core *clk) { int ret = 0; @@ -1100,6 +1127,15 @@ int clk_enable(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_enable); +int clk_enable_critical(struct clk *clk) +{ + if (clk->core->critical.enabled) + clk->core->critical.leave_on = true; + + return clk_enable(clk); +} +EXPORT_SYMBOL_GPL(clk_enable_critical); + static unsigned long clk_core_round_rate_nolock(struct clk_core *clk, unsigned long rate, unsigned long min_rate, @@ -2482,6 +2518,15 @@ fail_out: } EXPORT_SYMBOL_GPL(clk_register); +void clk_init_critical(struct clk *clk) +{ + struct critical *critical = &clk->core->critical; + + critical->enabled = true; + critical->leave_on = true; +} +EXPORT_SYMBOL_GPL(clk_init_critical); + /* * Free memory allocated for a clock. * Caller must hold prepare_lock. diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 5591ea7..15ef8c9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -563,6 +563,8 @@ struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw); void clk_unregister(struct clk *clk); void devm_clk_unregister(struct device *dev, struct clk *clk); +void clk_init_critical(struct clk *clk); + /* helper functions */ const char *__clk_get_name(struct clk *clk); struct clk_hw *__clk_get_hw(struct clk *clk); diff --git a/include/linux/clk.h b/include/linux/clk.h index 8381bbf..9807f3b 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -231,6 +231,19 @@ struct clk *devm_clk_get(struct device *dev, const char *id); int clk_enable(struct clk *clk); /** + * clk_enable_critical - inform the system when the clock source should be + * running, even if clock is critical. + * @clk: clock source + * + * If the clock can not be enabled/disabled, this should return success. + * + * May be called from atomic contexts. + * + * Returns success (0) or negative errno. + */ +int clk_enable_critical(struct clk *clk); + +/** * clk_disable - inform the system when the clock source is no longer required. * @clk: clock source * @@ -247,6 +260,23 @@ int clk_enable(struct clk *clk); void clk_disable(struct clk *clk); /** + * clk_disable_critical - inform the system when the clock source is no + * longer required, even if clock is critical. + * @clk: clock source + * + * Inform the system that a clock source is no longer required by + * a driver and may be shut down. + * + * May be called from atomic contexts. + * + * Implementation detail: if the clock source is shared between + * multiple drivers, clk_enable_critical() calls must be balanced + * by the same number of clk_disable_critical() calls for the clock + * source to be disabled. + */ +void clk_disable_critical(struct clk *clk); + +/** * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. * This is only valid once the clock source has been enabled. * @clk: clock source