From patchwork Mon May 7 21:16:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob X-Patchwork-Id: 8434 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 9151B23E49 for ; Mon, 7 May 2012 21:16:58 +0000 (UTC) Received: from mail-pb0-f52.google.com (mail-pb0-f52.google.com [209.85.160.52]) by fiordland.canonical.com (Postfix) with ESMTP id 1F82EA1879F for ; Mon, 7 May 2012 21:16:57 +0000 (UTC) Received: by pbbro8 with SMTP id ro8so8475725pbb.11 for ; Mon, 07 May 2012 14:16:57 -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=57AjAQsLpSV3OlKST+PuDU7iLOIw6nKcajEs9IyeGmU=; b=Xya6sXHDb/AUK+duWNn1xn7K0mSmiYDbeZc8iPks0l4Qku5OLPU5nEqIbO1fhw4dOB N4CeAPBQiRFVu7nQZU+ZPX6H3/6vz6G0gBLQn04r2y7ISPqryIpxtGng8lxQVUe+6Fus hXMiVcJD0/ukjl3ciOukKNvJvCzMq4CF1IjxAQU+156GNMOR6w4FXeUdEbAtLKveHd/j G89FztdsDSSLAnnI/oiStB7rRU5K1+O+xB0s4pXAYhtC5w/gLXYlV8fE3rm3S/JuobZj r/NiBUvITK7GBGWpHUB8BT4LGnjYlpca/giVswl7lg6UxnHxPm1ipRuu/WpJu4zKVnAa gGCA== Received: by 10.50.41.196 with SMTP id h4mr9191272igl.33.1336425417057; Mon, 07 May 2012 14:16:57 -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.73.147 with SMTP id q19csp154760ibj; Mon, 7 May 2012 14:16:56 -0700 (PDT) Received: by 10.236.76.226 with SMTP id b62mr5009255yhe.13.1336425415660; Mon, 07 May 2012 14:16:55 -0700 (PDT) Received: from mail-yx0-f178.google.com (mail-yx0-f178.google.com [209.85.213.178]) by mx.google.com with ESMTPS id d49si15528452yhl.28.2012.05.07.14.16.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 07 May 2012 14:16:55 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.213.178 is neither permitted nor denied by best guess record for domain of rob.lee@linaro.org) client-ip=209.85.213.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.213.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-yx0-f178.google.com with SMTP id l6so848468yen.37 for ; Mon, 07 May 2012 14:16:55 -0700 (PDT) Received: by 10.50.88.225 with SMTP id bj1mr9371883igb.42.1336425415112; Mon, 07 May 2012 14:16:55 -0700 (PDT) Received: from localhost.localdomain ([216.59.27.36]) by mx.google.com with ESMTPS id kn9sm6940883igc.8.2012.05.07.14.16.52 (version=SSLv3 cipher=OTHER); Mon, 07 May 2012 14:16:53 -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, jj@chaosbits.net Subject: [PATCH v3 1/3] ARM: imx: Add common imx cpuidle init functionality. Date: Mon, 7 May 2012 16:16:45 -0500 Message-Id: <1336425407-20308-2-git-send-email-rob.lee@linaro.org> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1336425407-20308-1-git-send-email-rob.lee@linaro.org> References: <1336425407-20308-1-git-send-email-rob.lee@linaro.org> X-Gm-Message-State: ALoCoQkvHaJnl6Mw9sEARgUDp3OjLkskAgAbLTAzclBFtX42z4/B0QZLzeeQ2YMHjbjBKcOqWhCf Add common cpuidle init functionality that can be used by various imx platforms. Signed-off-by: Robert Lee --- arch/arm/plat-mxc/Makefile | 1 + arch/arm/plat-mxc/cpuidle.c | 80 ++++++++++++++++++++++++++++++ arch/arm/plat-mxc/include/mach/cpuidle.h | 22 ++++++++ 3 files changed, 103 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..63b064b 100644 --- a/arch/arm/plat-mxc/Makefile +++ b/arch/arm/plat-mxc/Makefile @@ -16,6 +16,7 @@ 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..d4cb511 --- /dev/null +++ b/arch/arm/plat-mxc/cpuidle.c @@ -0,0 +1,80 @@ +/* + * 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 void __init 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); +} + +int __init imx_cpuidle_init(struct cpuidle_driver *drv) +{ + struct cpuidle_device *dev; + int cpu_id, ret; + + if (drv->state_count > CPUIDLE_STATE_MAX) { + pr_err("%s: state_count exceeds maximum\n", __func__); + return -EINVAL; + } + + ret = cpuidle_register_driver(drv); + if (ret) { + pr_err("%s: Failed to register cpuidle driver with error: %d\n", + __func__, ret); + 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, error: %d\n", + __func__, cpu_id, ret); + goto uninit; + } + } + + return 0; + +uninit: + imx_cpuidle_devices_uninit(); + +unregister_drv: + cpuidle_unregister_driver(drv); + return ret; +} 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..bc932d1 --- /dev/null +++ b/arch/arm/plat-mxc/include/mach/cpuidle.h @@ -0,0 +1,22 @@ +/* + * 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 + +#ifdef CONFIG_CPU_IDLE +extern int imx_cpuidle_init(struct cpuidle_driver *drv); +#else +static inline int imx_cpuidle_init(struct cpuidle_driver *drv) +{ + return -ENODEV; +} +#endif