From patchwork Mon Sep 22 14:15:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 4948041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 15E9F9F2BB for ; Mon, 22 Sep 2014 14:19:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B254720125 for ; Mon, 22 Sep 2014 14:19:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6E3720121 for ; Mon, 22 Sep 2014 14:19:03 +0000 (UTC) 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 1XW4QO-0001JT-NU; Mon, 22 Sep 2014 14:17:08 +0000 Received: from mail-wg0-x22d.google.com ([2a00:1450:400c:c00::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XW4Q0-0000ji-4C for linux-arm-kernel@lists.infradead.org; Mon, 22 Sep 2014 14:16:45 +0000 Received: by mail-wg0-f45.google.com with SMTP id x13so2311781wgg.16 for ; Mon, 22 Sep 2014 07:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nYzahs9J9nsQTb6tVffuOzA6TvRgSf8f6v2LNhB47xk=; b=BLso7N/mD5vs4XAVL9lWH+PnS7XrIt9npxKuvXuKzJ1E+BMw4WYLCvQaxVTlF2QZII fhfnUhEyhv9lFbG1ympmLnK2T6MB1o8K0HuFEacRdOjDB5XPZxS9WAVe9iQfDPuIPXHQ mdOsDbfx1JyQIRVaAaacRz2qc4tPxaix5QTAhnPv6cz1RjA62K0fGu53kz76Sl2mosfv 6RJAjgrFt/5zr0LFQW8VQFsxQfuZs1gNa7w8FsYmHSqdN8Nj4wUbXsZ13USYSTTazlKu 8nFaDSfBqaYOc/suCWYb5tMypfoRxelra556m1MY10pyYOIoPncTrsJTbKLOXW6/fBdx sdfg== X-Received: by 10.181.13.14 with SMTP id eu14mr15499201wid.43.1411395382049; Mon, 22 Sep 2014 07:16:22 -0700 (PDT) Received: from cizrna.lan (37-48-36-100.tmcz.cz. [37.48.36.100]) by mx.google.com with ESMTPSA id t9sm12442274wjf.41.2014.09.22.07.16.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Sep 2014 07:16:19 -0700 (PDT) From: Tomeu Vizoso To: Mike Turquette Subject: [PATCH v12 06/10] clk: Add floor and ceiling constraints to clock rates Date: Mon, 22 Sep 2014 16:15:49 +0200 Message-Id: <1411395353-3189-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1411395353-3189-1-git-send-email-tomeu.vizoso@collabora.com> References: <1411395124-2476-1-git-send-email-tomeu.vizoso@collabora.com> <1411395353-3189-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140922_071644_467320_4FB9AC39 X-CRM114-Status: GOOD ( 18.80 ) X-Spam-Score: -0.7 (/) Cc: Tomeu Vizoso , Stephen Warren , Peter De Schrijver , linux-kernel@vger.kernel.org, tomasz.figa@gmail.com, rabin@rab.in, Thierry Reding , Javier Martinez Canillas , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds a way for clock consumers to set maximum and minimum rates. This can be used for thermal drivers to set ceiling rates, or by misc. drivers to set floor rates to assure a minimum performance level. Signed-off-by: Tomeu Vizoso Tested-by: Heiko Stuebner --- v9: * Apply first all the floor constraints, then the ceiling constraints. * WARN on ceiling constraints below the current floor, for a given user clk v5: * Move the storage of constraints to the per-user clk struct, as suggested by Stephen Warren. --- drivers/clk/clk.c | 43 +++++++++++++++++++++++++++++++++++++++++++ drivers/clk/clk.h | 1 + drivers/clk/clkdev.c | 2 +- include/linux/clk-private.h | 5 +++++ include/linux/clk.h | 18 ++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 5658bf4..119e825 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -560,6 +560,8 @@ struct clk *__clk_create_clk(struct clk_core *clk_core, const char *dev, clk->dev_id = dev; clk->con_id = con; + hlist_add_head(&clk->child_node, &clk_core->per_user_clks); + return clk; } @@ -1625,6 +1627,7 @@ static void clk_change_rate(struct clk_core *clk) int clk_provider_set_rate(struct clk_core *clk, unsigned long rate) { struct clk_core *top, *fail_clk; + struct clk *clk_user; int ret = 0; if (!clk) @@ -1633,6 +1636,15 @@ int clk_provider_set_rate(struct clk_core *clk, unsigned long rate) /* prevent racing with updates to the clock topology */ clk_prepare_lock(); + hlist_for_each_entry(clk_user, &clk->per_user_clks, child_node) { + rate = max(rate, clk_user->floor_constraint); + } + + hlist_for_each_entry(clk_user, &clk->per_user_clks, child_node) { + if (clk_user->ceiling_constraint > 0) + rate = min(rate, clk_user->ceiling_constraint); + } + /* bail early if nothing to do */ if (rate == clk_provider_get_rate(clk)) goto out; @@ -1699,6 +1711,29 @@ int clk_set_rate(struct clk *clk_user, unsigned long rate) } EXPORT_SYMBOL_GPL(clk_set_rate); +int clk_set_floor_rate(struct clk *clk_user, unsigned long rate) +{ + struct clk_core *clk = clk_to_clk_core(clk_user); + + clk_user->floor_constraint = rate; + return clk_provider_set_rate(clk, clk_provider_get_rate(clk)); +} +EXPORT_SYMBOL_GPL(clk_set_floor_rate); + +int clk_set_ceiling_rate(struct clk *clk_user, unsigned long rate) +{ + struct clk_core *clk = clk_to_clk_core(clk_user); + + WARN(rate > 0 && rate < clk_user->floor_constraint, + "clk %s dev %s con %s: new ceiling %lu lower than existing floor %lu\n", + __clk_get_name(clk), clk_user->dev_id, clk_user->con_id, rate, + clk_user->floor_constraint); + + clk_user->ceiling_constraint = rate; + return clk_provider_set_rate(clk, clk_provider_get_rate(clk)); +} +EXPORT_SYMBOL_GPL(clk_set_ceiling_rate); + struct clk_core *clk_provider_get_parent(struct clk_core *clk) { struct clk_core *parent; @@ -2043,6 +2078,8 @@ int __clk_init(struct device *dev, struct clk_core *clk) } } + INIT_HLIST_HEAD(&clk->per_user_clks); + /* * optional platform-specific magic * @@ -2495,6 +2532,12 @@ int clk_notifier_unregister(struct clk *clk_user, struct notifier_block *nb) } EXPORT_SYMBOL_GPL(clk_notifier_unregister); +void __clk_free_clk(struct clk *clk_user) +{ + hlist_del(&clk_user->child_node); + kfree(clk_user); +} + #ifdef CONFIG_OF /** * struct of_clk_provider - Clock provider registration structure diff --git a/drivers/clk/clk.h b/drivers/clk/clk.h index 49eff38..005deb3 100644 --- a/drivers/clk/clk.h +++ b/drivers/clk/clk.h @@ -21,4 +21,5 @@ void of_clk_unlock(void); #if defined(CONFIG_COMMON_CLK) struct clk *__clk_create_clk(struct clk_core *clk_core, const char *dev, const char *con); +void __clk_free_clk(struct clk *clk_user); #endif diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 99ea87f..267b63a 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -271,7 +271,7 @@ void clk_put(struct clk *clk) #if defined(CONFIG_COMMON_CLK) clk_core_t *core = clk_to_clk_core(clk); - kfree(clk); + __clk_free_clk(clk); __clk_put(core); #else __clk_put(clk); diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index ce6a528..8126046 100644 --- a/include/linux/clk-private.h +++ b/include/linux/clk-private.h @@ -48,6 +48,7 @@ struct clk_core { unsigned long accuracy; struct hlist_head children; struct hlist_node child_node; + struct hlist_head per_user_clks; unsigned int notifier_count; #ifdef CONFIG_DEBUG_FS struct dentry *dentry; @@ -62,6 +63,10 @@ struct clk { unsigned int enable_count; void *last_disable; + + unsigned long floor_constraint; + unsigned long ceiling_constraint; + struct hlist_node child_node; }; /* diff --git a/include/linux/clk.h b/include/linux/clk.h index f46a2eb..066b100 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -275,6 +275,24 @@ long clk_round_rate(struct clk *clk, unsigned long rate); int clk_set_rate(struct clk *clk, unsigned long rate); /** + * clk_set_floor_rate - set a minimum clock rate for a clock source + * @clk: clock source + * @rate: desired minimum clock rate in Hz + * + * Returns success (0) or negative errno. + */ +int clk_set_floor_rate(struct clk *clk, unsigned long rate); + +/** + * clk_set_ceiling_rate - set a maximum clock rate for a clock source + * @clk: clock source + * @rate: desired maximum clock rate in Hz + * + * Returns success (0) or negative errno. + */ +int clk_set_ceiling_rate(struct clk *clk, unsigned long rate); + +/** * clk_set_parent - set the parent clock source for this clock * @clk: clock source * @parent: parent clock source