From patchwork Mon Mar 25 17:55:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 15616 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 7515423E2C for ; Mon, 25 Mar 2013 17:56:00 +0000 (UTC) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by fiordland.canonical.com (Postfix) with ESMTP id 1BC23A194B3 for ; Mon, 25 Mar 2013 17:56:00 +0000 (UTC) Received: by mail-vc0-f171.google.com with SMTP id ha11so4992272vcb.30 for ; Mon, 25 Mar 2013 10:55:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=SAUOepdS9cGrGxKKvS7SAwCftdbLNDR7SvwC7BOENhc=; b=dM+IpEgnORt7mRE+TkJY/o2YiM6wjHjgb8/vAd4JLeeIZpI+N8eVmrw6/UkO3PESbG 3B0ViLQIAxlt/lC7x/qfpexqmRr5+mm/uki3fSJziRThQAshiFeCmBiqv8yevho0nJq3 0SCn/K69DKyxgvyQl9dVWpH1vmaHoOtuNap5jz35VoJAkclx+EWYyyw3YZpJ69YjQQ/x RFw1a1GbeB82mSrDQmWbIifl+ckBgI1FCdsu749/Nz96ZnQXFJHrBKQnXCigBeZPnWXZ UoJM1VxNJdvQpwVwcgcihaPzLKEAEhrn8jR0rGl6M4dSgxIAUQUtXkKG+pscGcjz/Fb5 L6/Q== X-Received: by 10.220.106.14 with SMTP id v14mr376161vco.2.1364234159578; Mon, 25 Mar 2013 10:55:59 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp37231ved; Mon, 25 Mar 2013 10:55:58 -0700 (PDT) X-Received: by 10.194.235.196 with SMTP id uo4mr19691993wjc.30.1364234158559; Mon, 25 Mar 2013 10:55:58 -0700 (PDT) Received: from mail-we0-x22f.google.com ([2a00:1450:400c:c03::22f]) by mx.google.com with ESMTPS id mw8si2574819wic.19.2013.03.25.10.55.58 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Mar 2013 10:55:58 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22f is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=2a00:1450:400c:c03::22f; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c03::22f is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: by mail-we0-f175.google.com with SMTP id t11so3318414wey.34 for ; Mon, 25 Mar 2013 10:55:58 -0700 (PDT) X-Received: by 10.181.11.164 with SMTP id ej4mr19282453wid.29.1364234158090; Mon, 25 Mar 2013 10:55:58 -0700 (PDT) Received: from mai.home (AToulouse-654-1-426-131.w2-6.abo.wanadoo.fr. [2.6.209.131]) by mx.google.com with ESMTPS id s2sm23927749wib.4.2013.03.25.10.55.55 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Mar 2013 10:55:57 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl, tglx@linutronix.de Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux@maxim.org.za, nicolas.ferre@atmel.com, plagnioj@jcrosoft.com, lenb@kernel.org, nsekhar@ti.com, kevin.hilman@linaro.org, horms@verge.net.au, magnus.damm@gmail.com, kernel@pengutronix.de, ben-linux@fluff.org, kgene.kim@samsung.com, rob.herring@calxeda.com, jason@lakedaemon.net, andrew@lunn.ch, linus.walleij@linaro.org, linux@arm.linux.org.uk Subject: [PATCH 07/15] ARM: cpuidle: add init/exit routine Date: Mon, 25 Mar 2013 18:55:32 +0100 Message-Id: <1364234140-514-8-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1364234140-514-1-git-send-email-daniel.lezcano@linaro.org> References: <1364234140-514-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQlJB8IYqtAmLCFgvYk2CHcXI3J1JdKm+XN5kqVdmxyXFjG5FLZlKWyo9Jc9ab/3c8FdZNDp The init and exit routine for most of the drivers are the same, that is register the driver and register the device. Provide a common function to do that in the cpuidle driver for ARM, so we can get rid of a lot of code duplication in the different SOC cpuidle drivers. Signed-off-by: Daniel Lezcano --- arch/arm/include/asm/cpuidle.h | 4 +++ arch/arm/kernel/cpuidle.c | 57 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/cpuidle.h b/arch/arm/include/asm/cpuidle.h index 7367787..83a38ac 100644 --- a/arch/arm/include/asm/cpuidle.h +++ b/arch/arm/include/asm/cpuidle.h @@ -4,6 +4,10 @@ extern int arm_cpuidle_simple_enter(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index); +extern int arm_cpuidle_init(struct cpuidle_driver *drv); + +extern void arm_cpuidle_exit(struct cpuidle_driver *drv); + /* Common ARM WFI state */ #define ARM_CPUIDLE_WFI_STATE_PWR(p) {\ .enter = arm_cpuidle_simple_enter,\ diff --git a/arch/arm/kernel/cpuidle.c b/arch/arm/kernel/cpuidle.c index 89545f6..13cfe3e 100644 --- a/arch/arm/kernel/cpuidle.c +++ b/arch/arm/kernel/cpuidle.c @@ -9,13 +9,68 @@ * http://www.gnu.org/copyleft/gpl.html */ +#include #include #include +static DEFINE_PER_CPU(struct cpuidle_device, cpuidle_device); + int arm_cpuidle_simple_enter(struct cpuidle_device *dev, - struct cpuidle_driver *drv, int index) + struct cpuidle_driver *drv, int index) { cpu_do_idle(); return index; } + +int __init arm_cpuidle_init(struct cpuidle_driver *drv) +{ + int ret, cpu; + struct cpuidle_device *device; + + 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_cpuidle_init); + +void __exit arm_cpuidle_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); +} +EXPORT_SYMBOL_GPL(arm_cpuidle_exit);