From patchwork Fri Mar 15 14:27:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2278261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 072C2DF24C for ; Fri, 15 Mar 2013 14:31:37 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UGVcS-0007I7-EA; Fri, 15 Mar 2013 14:28:28 +0000 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UGVbO-0006wR-1P for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2013 14:27:24 +0000 Received: by mail-wi0-f175.google.com with SMTP id l13so567881wie.2 for ; Fri, 15 Mar 2013 07:27:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=XFoh42gUJcfFiuRogMj9RUYw6mLUf+Y4ndv2I67RAb0=; b=mDQPcxIoU14sP7zQgwCR8wBfhKDe7NgqctFK/48T2n0Y63rZJ4TI7MH4pLrtRDIR+Q QBZ6tzrt0KPJuW7ztW66lHYpJfMG6LmAUQwoFddt/ypfSo6vBHAcFkM9BGBJQplDUbSW +WTfAfUo+feNS5ldBkEm6SsERd040xMk3UtFMWtXwam6hpxkRMMMP+XxwL1daGSVwpb7 ZjQironS4en5PadtAoLo4o4rCE60fe3aDC44gf/BWNphIeiR0MCBOYcHRe+6U1xmFvvS 4S+N03sT2jkTeT+VLG6PwJm6AOqKUg7xPceE/ocsERAmHZyqaFjmMbdGNnjcr4MCLE5j XYNg== X-Received: by 10.180.84.165 with SMTP id a5mr3406273wiz.6.1363357639671; Fri, 15 Mar 2013 07:27:19 -0700 (PDT) Received: from mai.home (AToulouse-654-1-276-229.w90-5.abo.wanadoo.fr. [90.5.59.229]) by mx.google.com with ESMTPS id fv2sm3486696wib.6.2013.03.15.07.27.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Mar 2013 07:27:18 -0700 (PDT) From: Daniel Lezcano To: linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [RFC patch 02/11] cpuidle / arm : a single cpuidle driver Date: Fri, 15 Mar 2013 15:27:01 +0100 Message-Id: <1363357630-22214-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363357630-22214-1-git-send-email-daniel.lezcano@linaro.org> References: <1363357630-22214-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQm6lcCRWmL0AJP46AyBRqInUMJWQTE6f48WMxxgyS8xBaAkhCbQ12xxUtL50H/myw7yUGa1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130315_102722_385623_0DBCB2EC X-CRM114-Status: GOOD ( 17.31 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: andrew@lunn.ch, magnus.damm@gmail.com, ben-linux@fluff.org, nsekhar@ti.com, nicolas.ferre@atmel.com, rob.herring@calxeda.com, rjw@sisk.pl, kevin.hilman@linaro.org, horms@verge.net.au, kernel@pengutronix.de, kgene.kim@samsung.com, plagnioj@jcrosoft.com, linux@maxim.org.za, jason@lakedaemon.net, lenb@kernel.org 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 The cpuidle drivers are duplicating a lot of code and in most of the case there is a common pattern we can factor out: * setup the broadcast timers * register the driver * register the devices This arm driver is the common part between all the ARM cpuidle drivers, with the code factored out. It does not handle the coupled idle state for now but it is the first step to have everyone to converge to the same code pattern. Signed-off-by: Daniel Lezcano --- MAINTAINERS | 6 +++ arch/arm/include/asm/cpuidle.h | 3 ++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/arm-idle.c | 112 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 drivers/cpuidle/arm-idle.c diff --git a/MAINTAINERS b/MAINTAINERS index 9561658..2c13cf3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2212,6 +2212,12 @@ S: Maintained F: arch/x86/kernel/cpuid.c F: arch/x86/kernel/msr.c +CPUIDLE FOR ARM +M: Daniel Lezcano +L: linux-pm@vger.kernel.org +S: Maintained +F: drivers/cpuidle/arm-idle.c + CPU POWER MONITORING SUBSYSTEM M: Dominik Brodowski M: Thomas Renninger diff --git a/arch/arm/include/asm/cpuidle.h b/arch/arm/include/asm/cpuidle.h index 2fca60a..107cf23 100644 --- a/arch/arm/include/asm/cpuidle.h +++ b/arch/arm/include/asm/cpuidle.h @@ -9,6 +9,9 @@ static inline int arm_cpuidle_simple_enter(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { return -ENODEV; } #endif +extern int arm_idle_init(struct cpuidle_driver *drv); +extern void arm_idle_exit(struct cpuidle_driver *drv); + /* Common ARM WFI state */ #define ARM_CPUIDLE_WFI_STATE_PWR(p) {\ .enter = arm_cpuidle_simple_enter,\ diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index d1aba71..4816a78 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -5,5 +5,6 @@ obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o +obj-$(CONFIG_ARM) += arm-idle.o obj-$(CONFIG_ARCH_HIGHBANK) += cpuidle-calxeda.o obj-$(CONFIG_ARCH_KIRKWOOD) += cpuidle-kirkwood.o diff --git a/drivers/cpuidle/arm-idle.c b/drivers/cpuidle/arm-idle.c new file mode 100644 index 0000000..397ff4c --- /dev/null +++ b/drivers/cpuidle/arm-idle.c @@ -0,0 +1,112 @@ +/* + * Copyright 2012 Linaro Ltd: : Daniel Lezcano + * + * The code contained herein is licensed under the GNU General Public + * License. You may obtain a copy of the GNU General Public License + * Version 2 or later at the following locations: + * + * http://www.opensource.org/licenses/gpl-license.html + * http://www.gnu.org/copyleft/gpl.html + */ + +#include +#include +#include + +static DEFINE_PER_CPU(struct cpuidle_device, cpuidle_device); +static bool use_broadcast_timer = false; + +#ifdef CONFIG_GENERIC_CLOCKEVENTS +static void setup_broadcast_timer(void *arg) +{ + int cpu = smp_processor_id(); + clockevents_notify((int)(arg), &cpu); +} + +static bool __init arm_idle_use_broadcast(struct cpuidle_driver *drv) +{ + int i; + + for (i = 0; i < drv->state_count; i++) + if (drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP) + return true; + return false; +} + +static inline void arm_idle_timer_broadcast(bool enable) +{ + on_each_cpu(setup_broadcast_timer, enable ? + (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON: + (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1); +} +#else +static inline bool __init arm_idle_use_broadcast(struct cpuidle_driver *drv) +{ + return false; +} + +static inline void arm_idle_timer_broadcast(bool enable) +{ + ; +} +#endif + +int __init arm_idle_init(struct cpuidle_driver *drv) +{ + int ret, cpu; + struct cpuidle_device *device; + + use_broadcast_timer = arm_idle_use_broadcast(drv); + + if (use_broadcast_timer) + arm_idle_timer_broadcast(true); + + ret = cpuidle_register_driver(drv); + if (ret) { + printk(KERN_ERR "failed to register idle driver '%s'\n", + drv->name); + return ret; + } + + for_each_online_cpu(cpu) { + + device = &per_cpu(cpuidle_device, cpu); + device->cpu = cpu; + ret = cpuidle_register_device(device); + if (ret) { + printk(KERN_ERR "Failed to register cpuidle " + "device for cpu%d\n", cpu); + goto out_unregister; + } + } + +out: + return ret; + +out_unregister: + for_each_online_cpu(cpu) { + device = &per_cpu(cpuidle_device, cpu); + cpuidle_unregister_device(device); + } + + cpuidle_unregister_driver(drv); + goto out; +} +EXPORT_SYMBOL_GPL(arm_idle_init); + +void __exit arm_idle_exit(struct cpuidle_driver *drv) +{ + int cpu; + struct cpuidle_device *device; + + for_each_online_cpu(cpu) { + device = &per_cpu(cpuidle_device, cpu); + cpuidle_unregister_device(device); + } + + cpuidle_unregister_driver(drv); + + if (use_broadcast_timer) + arm_idle_timer_broadcast(false); +} +EXPORT_SYMBOL_GPL(arm_idle_exit);