blob: 22d6d4acc8d914f5c522e162e4cda5a90e8662b5 [file] [log] [blame]
Sekhar Noria6c0f6e2009-11-03 15:14:13 +05301/*
2 * CPU idle for DaVinci SoCs
3 *
4 * Copyright (C) 2009 Texas Instruments Incorporated. http://www.ti.com/
5 *
6 * Derived from Marvell Kirkwood CPU idle code
7 * (arch/arm/mach-kirkwood/cpuidle.c)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/cpuidle.h>
18#include <linux/io.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040019#include <linux/export.h>
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053020#include <asm/proc-fns.h>
Robert Lee19976c22012-03-20 15:22:45 -050021#include <asm/cpuidle.h>
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053022
23#include <mach/cpuidle.h>
Nicolas Pitre0020afb2011-07-05 22:52:57 -040024#include <mach/ddr2.h>
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053025
26#define DAVINCI_CPUIDLE_MAX_STATES 2
27
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053028static DEFINE_PER_CPU(struct cpuidle_device, davinci_cpuidle_device);
29static void __iomem *ddr2_reg_base;
Daniel Lezcano5af4a212013-02-04 12:01:41 +000030static bool ddr2_pdown;
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053031
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053032static void davinci_save_ddr_power(int enter, bool pdown)
33{
34 u32 val;
35
36 val = __raw_readl(ddr2_reg_base + DDR2_SDRCR_OFFSET);
37
38 if (enter) {
39 if (pdown)
40 val |= DDR2_SRPD_BIT;
41 else
42 val &= ~DDR2_SRPD_BIT;
43 val |= DDR2_LPMODEN_BIT;
44 } else {
45 val &= ~(DDR2_SRPD_BIT | DDR2_LPMODEN_BIT);
46 }
47
48 __raw_writel(val, ddr2_reg_base + DDR2_SDRCR_OFFSET);
49}
50
Daniel Lezcano8d601432013-02-04 12:01:42 +000051/* Actual code that puts the SoC in different idle states */
52static int davinci_enter_idle(struct cpuidle_device *dev,
Daniel Lezcanoc062d442013-04-03 12:15:19 +000053 struct cpuidle_driver *drv, int index)
Daniel Lezcano8d601432013-02-04 12:01:42 +000054{
Daniel Lezcano36ce8d42013-02-04 12:01:43 +000055 davinci_save_ddr_power(1, ddr2_pdown);
Daniel Lezcanoc062d442013-04-03 12:15:19 +000056 cpu_do_idle();
Daniel Lezcano36ce8d42013-02-04 12:01:43 +000057 davinci_save_ddr_power(0, ddr2_pdown);
Daniel Lezcano8d601432013-02-04 12:01:42 +000058
59 return index;
60}
61
62static struct cpuidle_driver davinci_idle_driver = {
63 .name = "cpuidle-davinci",
64 .owner = THIS_MODULE,
65 .en_core_tk_irqen = 1,
66 .states[0] = ARM_CPUIDLE_WFI_STATE,
67 .states[1] = {
68 .enter = davinci_enter_idle,
69 .exit_latency = 10,
70 .target_residency = 100000,
71 .flags = CPUIDLE_FLAG_TIME_VALID,
72 .name = "DDR SR",
73 .desc = "WFI and DDR Self Refresh",
74 },
75 .state_count = DAVINCI_CPUIDLE_MAX_STATES,
76};
77
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053078static int __init davinci_cpuidle_probe(struct platform_device *pdev)
79{
80 int ret;
81 struct cpuidle_device *device;
82 struct davinci_cpuidle_config *pdata = pdev->dev.platform_data;
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053083
84 device = &per_cpu(davinci_cpuidle_device, smp_processor_id());
85
86 if (!pdata) {
87 dev_err(&pdev->dev, "cannot get platform data\n");
88 return -ENOENT;
89 }
90
Sekhar Nori948c66d2009-11-16 17:21:37 +053091 ddr2_reg_base = pdata->ddr2_ctlr_base;
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053092
Daniel Lezcano5af4a212013-02-04 12:01:41 +000093 ddr2_pdown = pdata->ddr2_pdown;
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053094
Sekhar Noria6c0f6e2009-11-03 15:14:13 +053095 ret = cpuidle_register_driver(&davinci_idle_driver);
96 if (ret) {
97 dev_err(&pdev->dev, "failed to register driver\n");
98 return ret;
99 }
100
Sekhar Noria6c0f6e2009-11-03 15:14:13 +0530101 ret = cpuidle_register_device(device);
102 if (ret) {
103 dev_err(&pdev->dev, "failed to register device\n");
Sekhar Nori948c66d2009-11-16 17:21:37 +0530104 cpuidle_unregister_driver(&davinci_idle_driver);
105 return ret;
Sekhar Noria6c0f6e2009-11-03 15:14:13 +0530106 }
107
108 return 0;
Sekhar Noria6c0f6e2009-11-03 15:14:13 +0530109}
110
111static struct platform_driver davinci_cpuidle_driver = {
112 .driver = {
113 .name = "cpuidle-davinci",
114 .owner = THIS_MODULE,
115 },
116};
117
118static int __init davinci_cpuidle_init(void)
119{
120 return platform_driver_probe(&davinci_cpuidle_driver,
121 davinci_cpuidle_probe);
122}
123device_initcall(davinci_cpuidle_init);
124