From patchwork Fri Aug 16 02:24:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 2845359 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26C43BF546 for ; Fri, 16 Aug 2013 02:26:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2865120208 for ; Fri, 16 Aug 2013 02:26:49 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C0C82027C for ; Fri, 16 Aug 2013 02:26:48 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VA9kH-0002I6-4b; Fri, 16 Aug 2013 02:26:33 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VA9k9-0006Qx-RY; Fri, 16 Aug 2013 02:26:25 +0000 Received: from mail-pd0-f175.google.com ([209.85.192.175]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VA9k4-0006PQ-GW for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2013 02:26:22 +0000 Received: by mail-pd0-f175.google.com with SMTP id q10so1583394pdj.20 for ; Thu, 15 Aug 2013 19:25:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=fg8KA7o/qPQzvOxetAtwbUN56rk/3HlnVJUwuiu+U3g=; b=BaZYNGP1nKKhNs47KyWtLPa296X2ER8ZkykCmvmwptNYAACR5j708G0PkpiyjezCbd BGnvEVX42uh4ySl96xhzdyEzwGHw/tM3iWsw80RaUj81WT1n3FFKnzajpSepkc2rutnM 674/MB45RxsBDxQSxxmi/HxvTTsxuxbY5EH3wn01LE8LJPV+wSDYqmNpGUwkEUCmFYSQ vNVVX4iSlzca8+ECJa/KtxDc/QMiNrYeB/bBwhiJh+iQ/92VTXI62ICwV54chChLjdIe J4MQ4TgLgYi+t2UjX8tPqgSbmc9ROmi0BPJHacHbUZvTDdpATW+aiXQBAXUPcVogRNqM ggTw== X-Gm-Message-State: ALoCoQlhREIBfvjBZPCG7dozUJFKlD+8+GHM3QW7kHJ+vT2eaQ3pbhl6zz7oAMKAPzyyjhqcGS0b X-Received: by 10.68.219.33 with SMTP id pl1mr11594198pbc.147.1376619958264; Thu, 15 Aug 2013 19:25:58 -0700 (PDT) Received: from localhost ([122.172.193.46]) by mx.google.com with ESMTPSA id om2sm2685749pbc.30.2013.08.15.19.25.49 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 15 Aug 2013 19:25:57 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Subject: [PATCH 01/34] cpufreq: move freq change notifications to cpufreq core Date: Fri, 16 Aug 2013 07:54:58 +0530 Message-Id: <8d083bb5c2d167aa0b52f48c3f17a1320b3e0249.1376619363.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130815_222620_796030_BCA26E7D X-CRM114-Status: GOOD ( 15.48 ) X-Spam-Score: -1.9 (-) Cc: Andrew Lunn , Steven Miao , Viresh Kumar , Linus Walleij , Sekhar Nori , sparclinux@vger.kernel.org, Hans-Christian Egtvedt , Jesper Nilsson , Kukjin Kim , Russell King , Dmitry Eremin-Solenikov , patches@linaro.org, cpufreq@vger.kernel.org, linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, spear-devel@list.st.com, Mikael Starvik , Stephen Warren , linux-arm-kernel@lists.infradead.org, John Crispin , Tony Luck , Eric Miao , linux-cris-kernel@axis.com, linux-kernel@vger.kernel.org, Santosh Shilimkar , Shawn Guo , "David S. Miller" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 Most of the drivers do following in their ->target_index() routines: struct cpufreq_freqs freqs; freqs.old = old freq... freqs.new = new freq... cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); /* Change rate here */ cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); This is replicated over all cpufreq drivers today and there doesn't exists a good enough reason why this shouldn't be moved to cpufreq core instead. There are few special cases though, like exynos5440, which doesn't do everything on the call to ->target_index() routine and call some kind of bottom halves for doing this work, work/tasklet/etc.. They may continue doing notification from their own code and so this patch introduces another flag: CPUFREQ_NO_NOTIFICATION, which will be set by such drivers. Cc: Andrew Lunn Cc: David S. Miller Cc: Dmitry Eremin-Solenikov Cc: Eric Miao Cc: Hans-Christian Egtvedt Cc: Jesper Nilsson Cc: John Crispin Cc: Kukjin Kim Cc: Linus Walleij Cc: linux-cris-kernel@axis.com Cc: Mikael Starvik Cc: Russell King Cc: Santosh Shilimkar Cc: Sekhar Nori Cc: Shawn Guo Cc: sparclinux@vger.kernel.org Cc: spear-devel@list.st.com Cc: Stephen Warren Cc: Steven Miao Cc: Tony Luck Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/cpufreq.h | 6 ++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a7a1d3e..2782949 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1673,6 +1673,9 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, retval = cpufreq_driver->target(policy, target_freq, relation); else if (cpufreq_driver->target_index) { struct cpufreq_frequency_table *freq_table; + struct cpufreq_freqs freqs; + unsigned long flags; + bool notify; int index; freq_table = cpufreq_frequency_get_table(policy->cpu); @@ -1691,7 +1694,38 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (freq_table[index].frequency == policy->cur) return 0; + read_lock_irqsave(&cpufreq_driver_lock, flags); + notify = !(cpufreq_driver->flags | CPUFREQ_NO_NOTIFICATION); + read_unlock_irqrestore(&cpufreq_driver_lock, flags); + + if (notify) { + freqs.old = policy->cur; + freqs.new = freq_table[index].frequency; + + pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", + __func__, policy->cpu, freqs.old, + freqs.new); + + cpufreq_notify_transition(policy, &freqs, + CPUFREQ_PRECHANGE); + } + retval = cpufreq_driver->target_index(policy, index); + if (retval) + pr_err("%s: Failed to change cpu frequency: %d\n", + __func__, retval); + + if (notify) { + /* + * Notify with old freq in case we failed to change + * frequency + */ + if (retval) + freqs.new = freqs.old; + + cpufreq_notify_transition(policy, &freqs, + CPUFREQ_POSTCHANGE); + } } return retval; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index ff9c8df..62ce478 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -221,6 +221,12 @@ struct cpufreq_driver { * frequency transitions */ #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed * mismatches */ +/* + * Driver will call cpufreq_notify_transition() in its target_index() routine + * and so cpufreq core must not call it. Only useful for drivers that implement + * target_index(), unused otherwise. + */ +#define CPUFREQ_NO_NOTIFICATION 0x08 int cpufreq_register_driver(struct cpufreq_driver *driver_data); int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);