From patchwork Mon Apr 16 23:50:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob X-Patchwork-Id: 7879 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 0807923E1D for ; Mon, 16 Apr 2012 23:50:33 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id C5D28A1806B for ; Mon, 16 Apr 2012 23:50:32 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so11131941iag.11 for ; Mon, 16 Apr 2012 16:50:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=/lpcvqaY5jqkQdk2oDOqqNuyVCrRyZqtrgebTbBs59s=; b=PimPD6Dhtd6Y5F5UPSz1jlzuW85cb8imLdLMyhnwcvZn5eu1rHXPUNcinh7uTw6933 v5/lNrV51v6N6fL6r8jqTOUQhG8wLBY+yUI40FwzBsPvpsPajKW4XoVfIVXTCbXCUXIS ffqXZqZuQoWr6UUPp11jFMk171Vmn8rqS9DkzgfmO564W3EzH/p8Za4WtSahGBC6emHF JlU9nbyZeAq/aHnE18beAClnIzWMl6kNPnuNV+CW5KpMcgjMOxioNpfcN7fOzxaFpfur /KcImtPkjXPUnLWJeuqcSBJkI2VGJDWFTAkkWMRtRPj7UFcXxuyrMQCugnYn6h7BGTr7 vfKg== Received: by 10.50.10.201 with SMTP id k9mr7516034igb.55.1334620232574; Mon, 16 Apr 2012 16:50:32 -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.231.137.198 with SMTP id x6csp112740ibt; Mon, 16 Apr 2012 16:50:32 -0700 (PDT) Received: by 10.60.7.196 with SMTP id l4mr18435140oea.8.1334620231831; Mon, 16 Apr 2012 16:50:31 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id ip10si10292889obb.147.2012.04.16.16.50.31 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Apr 2012 16:50:31 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of rob.lee@linaro.org) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of rob.lee@linaro.org) smtp.mail=rob.lee@linaro.org Received: by mail-ob0-f178.google.com with SMTP id k16so10343845obf.37 for ; Mon, 16 Apr 2012 16:50:31 -0700 (PDT) Received: by 10.182.86.165 with SMTP id q5mr18590002obz.0.1334620231580; Mon, 16 Apr 2012 16:50:31 -0700 (PDT) Received: from localhost.localdomain ([216.59.27.108]) by mx.google.com with ESMTPS id xb7sm21169537obb.10.2012.04.16.16.50.24 (version=SSLv3 cipher=OTHER); Mon, 16 Apr 2012 16:50:31 -0700 (PDT) From: Robert Lee To: kernel@pengutronix.de Cc: shawn.guo@linaro.org, amit.kucheria@linaro.org, daniel.lezcano@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, patches@linaro.org Subject: [PATCH 1/3] ARM: imx: Add common imx cpuidle init functionality. Date: Mon, 16 Apr 2012 18:50:12 -0500 Message-Id: <1334620214-25803-2-git-send-email-rob.lee@linaro.org> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1334620214-25803-1-git-send-email-rob.lee@linaro.org> References: <1334620214-25803-1-git-send-email-rob.lee@linaro.org> X-Gm-Message-State: ALoCoQnHzP72u/XSMrRBEDGEMGWxe66Q1wdX0DYA5nYEr79RRZdKitsEezWA98gLqI+sbjKlJG9/ Add common cpuidle init functionality that can be used by various imx platforms. Signed-off-by: Robert Lee --- arch/arm/plat-mxc/Makefile | 2 + arch/arm/plat-mxc/cpuidle.c | 89 ++++++++++++++++++++++++++++++ arch/arm/plat-mxc/include/mach/cpuidle.h | 26 +++++++++ 3 files changed, 117 insertions(+) create mode 100644 arch/arm/plat-mxc/cpuidle.c create mode 100644 arch/arm/plat-mxc/include/mach/cpuidle.h diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile index e81290c..7c9e05f 100644 --- a/arch/arm/plat-mxc/Makefile +++ b/arch/arm/plat-mxc/Makefile @@ -16,6 +16,8 @@ obj-$(CONFIG_MXC_ULPI) += ulpi.o obj-$(CONFIG_MXC_USE_EPIT) += epit.o obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o +obj-$(CONFIG_CPU_IDLE) += cpuidle.o + ifdef CONFIG_SND_IMX_SOC obj-y += ssi-fiq.o obj-y += ssi-fiq-ksym.o diff --git a/arch/arm/plat-mxc/cpuidle.c b/arch/arm/plat-mxc/cpuidle.c new file mode 100644 index 0000000..d1c9301 --- /dev/null +++ b/arch/arm/plat-mxc/cpuidle.c @@ -0,0 +1,89 @@ +/* + * Copyright 2012 Freescale Semiconductor, Inc. + * Copyright 2012 Linaro Ltd. + * + * 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 +#include +#include +#include + +static struct cpuidle_device __percpu * imx_cpuidle_devices; +static struct cpuidle_driver *drv; + +void __init imx_cpuidle_set_driver(struct cpuidle_driver *p) +{ + drv = p; +} + +void imx_cpuidle_devices_uninit(void) +{ + int cpu_id; + struct cpuidle_device *dev; + + for_each_possible_cpu(cpu_id) { + dev = per_cpu_ptr(imx_cpuidle_devices, cpu_id); + cpuidle_unregister_device(dev); + } + + free_percpu(imx_cpuidle_devices); +} + +static int __init imx_cpuidle_init(void) +{ + struct cpuidle_device *dev; + int cpu_id, ret; + + if (!drv || drv->state_count > CPUIDLE_STATE_MAX) { + pr_err("%s: Invalid Input\n", __func__); + return -EINVAL; + } + + ret = cpuidle_register_driver(drv); + + if (ret) { + pr_err("%s: Failed to register cpuidle driver\n", __func__); + return ret; + } + + imx_cpuidle_devices = alloc_percpu(struct cpuidle_device); + + if (imx_cpuidle_devices == NULL) { + ret = -ENOMEM; + goto unregister_drv; + } + + /* initialize state data for each cpuidle_device */ + for_each_possible_cpu(cpu_id) { + dev = per_cpu_ptr(imx_cpuidle_devices, cpu_id); + dev->cpu = cpu_id; + dev->state_count = drv->state_count; + + ret = cpuidle_register_device(dev); + if (ret) { + pr_err("%s: Failed to register cpu %u\n", + __func__, cpu_id); + goto uninit; + } + } + + return 0; + +uninit: + imx_cpuidle_devices_uninit(); + +unregister_drv: + cpuidle_unregister_driver(drv); + + return ret; +} +late_initcall(imx_cpuidle_init); diff --git a/arch/arm/plat-mxc/include/mach/cpuidle.h b/arch/arm/plat-mxc/include/mach/cpuidle.h new file mode 100644 index 0000000..6509f19 --- /dev/null +++ b/arch/arm/plat-mxc/include/mach/cpuidle.h @@ -0,0 +1,26 @@ +/* + * Copyright 2012 Freescale Semiconductor, Inc. + * Copyright 2012 Linaro Ltd. + * + * 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 + +extern int imx5_cpuidle_init(void); +extern int imx6q_cpuidle_init(void); + +#ifdef CONFIG_CPU_IDLE +extern void imx_cpuidle_devices_uninit(void); +extern void imx_cpuidle_set_driver(struct cpuidle_driver *p); +extern int imx5_cpuidle_init(void); +extern int imx6q_cpuidle_init(void); +#else +static inline void imx_cpuidle_devices_uninit(void) {} +static inline void imx_cpuidle_set_driver(struct cpuidle_driver *p) {} +#endif