From: michal.simek@xilinx.com (Michal Simek)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 10/10] arm: zynq: Add cpuidle support
Date: Mon, 25 Mar 2013 14:53:16 +0100 [thread overview]
Message-ID: <1364219596-4954-10-git-send-email-michal.simek@xilinx.com> (raw)
In-Reply-To: <1364219596-4954-1-git-send-email-michal.simek@xilinx.com>
Add support for cpuidle.
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---
arch/arm/mach-zynq/Makefile | 1 +
arch/arm/mach-zynq/cpuidle.c | 131 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 132 insertions(+)
create mode 100644 arch/arm/mach-zynq/cpuidle.c
diff --git a/arch/arm/mach-zynq/Makefile b/arch/arm/mach-zynq/Makefile
index 8e75490..a085d86 100644
--- a/arch/arm/mach-zynq/Makefile
+++ b/arch/arm/mach-zynq/Makefile
@@ -4,5 +4,6 @@
# Common support
obj-y := common.o slcr.o
+obj-$(CONFIG_CPU_IDLE) += cpuidle.o
obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
obj-$(CONFIG_SMP) += platsmp.o
diff --git a/arch/arm/mach-zynq/cpuidle.c b/arch/arm/mach-zynq/cpuidle.c
new file mode 100644
index 0000000..24f0333
--- /dev/null
+++ b/arch/arm/mach-zynq/cpuidle.c
@@ -0,0 +1,131 @@
+/*
+ * based on arch/arm/mach-at91/cpuidle.c
+ *
+ * CPU idle support for Xilinx
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ *
+ * The cpu idle uses wait-for-interrupt and RAM self refresh in order
+ * to implement two idle states -
+ * #1 wait-for-interrupt
+ * #2 wait-for-interrupt and RAM self refresh
+ *
+ * Note that this code is only intended as a prototype and is not tested
+ * well yet, or tuned for the Xilinx Cortex A9. Also note that for a
+ * tickless kernel, high res timers must not be turned on. The cpuidle
+ * framework must also be turned on in the kernel.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/cpuidle.h>
+#include <linux/io.h>
+#include <linux/export.h>
+#include <linux/clockchips.h>
+#include <linux/cpu_pm.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <asm/proc-fns.h>
+
+#define XILINX_MAX_STATES 1
+
+static DEFINE_PER_CPU(struct cpuidle_device, xilinx_cpuidle_device);
+
+/* Actual code that puts the SoC in different idle states */
+static int xilinx_enter_idle(struct cpuidle_device *dev,
+ struct cpuidle_driver *drv, int index)
+{
+ struct timeval before, after;
+ int idle_time;
+
+ local_irq_disable();
+ do_gettimeofday(&before);
+
+ if (index == 0)
+ /* Wait for interrupt state */
+ cpu_do_idle();
+
+ else if (index == 1) {
+ unsigned int cpu_id = smp_processor_id();
+
+ clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
+
+ /* Devices must be stopped here */
+ cpu_pm_enter();
+
+ /* Add code for DDR self refresh start */
+
+ cpu_do_idle();
+ /*cpu_suspend(foo, bar);*/
+
+ /* Add code for DDR self refresh stop */
+
+ cpu_pm_exit();
+
+ clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
+ }
+
+ do_gettimeofday(&after);
+ local_irq_enable();
+ idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
+ (after.tv_usec - before.tv_usec);
+
+ dev->last_residency = idle_time;
+ return index;
+}
+
+static struct cpuidle_driver xilinx_idle_driver = {
+ .name = "xilinx_idle",
+ .owner = THIS_MODULE,
+ .state_count = XILINX_MAX_STATES,
+ /* Wait for interrupt state */
+ .states[0] = {
+ .enter = xilinx_enter_idle,
+ .exit_latency = 1,
+ .target_residency = 10000,
+ .flags = CPUIDLE_FLAG_TIME_VALID,
+ .name = "WFI",
+ .desc = "Wait for interrupt",
+ },
+ /* Wait for interrupt and RAM self refresh state */
+ .states[1] = {
+ .enter = xilinx_enter_idle,
+ .exit_latency = 10,
+ .target_residency = 10000,
+ .flags = CPUIDLE_FLAG_TIME_VALID,
+ .name = "RAM_SR",
+ .desc = "WFI and RAM Self Refresh",
+ },
+};
+
+/* Initialize CPU idle by registering the idle states */
+static int xilinx_init_cpuidle(void)
+{
+ unsigned int cpu;
+ struct cpuidle_device *device;
+ int ret;
+
+ ret = cpuidle_register_driver(&xilinx_idle_driver);
+ if (ret) {
+ pr_err("Registering Xilinx CpuIdle Driver failed.\n");
+ return ret;
+ }
+
+ for_each_possible_cpu(cpu) {
+ device = &per_cpu(xilinx_cpuidle_device, cpu);
+ device->state_count = XILINX_MAX_STATES;
+ device->cpu = cpu;
+ ret = cpuidle_register_device(device);
+ if (ret) {
+ pr_err("xilinx_init_cpuidle: Failed registering\n");
+ return ret;
+ }
+ }
+
+ pr_info("Xilinx CpuIdle Driver started\n");
+ return 0;
+}
+device_initcall(xilinx_init_cpuidle);
--
1.7.9.7
prev parent reply other threads:[~2013-03-25 13:53 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-25 13:53 [PATCH 01/10] arm: zynq: Use standard timer binding Michal Simek
2013-03-25 13:53 ` [PATCH 02/10] arm: zynq: Move timer to clocksource interface Michal Simek
2013-03-25 13:53 ` [PATCH 03/10] arm: zynq: Move timer to generic location Michal Simek
2013-03-25 16:01 ` Steffen Trumtrar
2013-03-25 16:24 ` Michal Simek
2013-03-25 13:53 ` [PATCH 04/10] arm: zynq: Load scu baseaddress at run time Michal Simek
2013-03-25 14:06 ` Rob Herring
2013-03-25 14:51 ` Michal Simek
2013-03-25 15:37 ` Rob Herring
2013-03-25 16:07 ` Michal Simek
2013-03-25 22:34 ` Rob Herring
2013-03-26 10:45 ` Michal Simek
2013-03-26 12:28 ` Rob Herring
2013-03-26 12:33 ` Michal Simek
2013-04-02 16:40 ` Pawel Moll
[not found] ` <CAHTX3dKD4G0E8qoxTR2HnJVdagoeOerM+TiZzkJUPjcGwYdX_Q@mail.gmail.com>
2013-04-03 7:25 ` Steffen Trumtrar
2013-04-03 16:06 ` Pawel Moll
[not found] ` <CAHTX3dJMpp+E2u-cAeYbqtxC1WAYWpCeRx6W7G=dWDcgzUz5DA@mail.gmail.com>
2013-04-03 17:11 ` Pawel Moll
2013-03-25 13:53 ` [PATCH 05/10] arm: zynq: Move slcr initialization to separate file Michal Simek
2013-03-25 16:19 ` Steffen Trumtrar
2013-03-25 16:37 ` Michal Simek
2013-03-25 13:53 ` [PATCH 06/10] arm: zynq: Add support for system reset Michal Simek
2013-03-25 13:53 ` [PATCH 07/10] arm: zynq: Add support for pmu Michal Simek
2013-03-25 13:53 ` [PATCH 08/10] arm: zynq: Add smp support Michal Simek
2013-03-25 14:16 ` Rob Herring
2013-03-25 16:31 ` Michal Simek
2013-03-25 22:10 ` Rob Herring
2013-03-26 7:42 ` Michal Simek
2013-04-01 22:40 ` Rob Herring
2013-04-03 6:44 ` Michal Simek
2013-03-25 13:53 ` [PATCH 09/10] arm: zynq: Add hotplug support Michal Simek
2013-03-25 13:53 ` Michal Simek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364219596-4954-10-git-send-email-michal.simek@xilinx.com \
--to=michal.simek@xilinx.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).