Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 1 | /* |
| 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 Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 19 | #include <linux/export.h> |
Robert Lee | 19976c2 | 2012-03-20 15:22:45 -0500 | [diff] [blame] | 20 | #include <asm/cpuidle.h> |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 21 | |
| 22 | #include <mach/cpuidle.h> |
Nicolas Pitre | 0020afb | 2011-07-05 22:52:57 -0400 | [diff] [blame] | 23 | #include <mach/ddr2.h> |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 24 | |
| 25 | #define DAVINCI_CPUIDLE_MAX_STATES 2 |
| 26 | |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 27 | static void __iomem *ddr2_reg_base; |
Daniel Lezcano | 5af4a21 | 2013-02-04 12:01:41 +0000 | [diff] [blame] | 28 | static bool ddr2_pdown; |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 29 | |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 30 | static void davinci_save_ddr_power(int enter, bool pdown) |
| 31 | { |
| 32 | u32 val; |
| 33 | |
| 34 | val = __raw_readl(ddr2_reg_base + DDR2_SDRCR_OFFSET); |
| 35 | |
| 36 | if (enter) { |
| 37 | if (pdown) |
| 38 | val |= DDR2_SRPD_BIT; |
| 39 | else |
| 40 | val &= ~DDR2_SRPD_BIT; |
| 41 | val |= DDR2_LPMODEN_BIT; |
| 42 | } else { |
| 43 | val &= ~(DDR2_SRPD_BIT | DDR2_LPMODEN_BIT); |
| 44 | } |
| 45 | |
| 46 | __raw_writel(val, ddr2_reg_base + DDR2_SDRCR_OFFSET); |
| 47 | } |
| 48 | |
Daniel Lezcano | 8d60143 | 2013-02-04 12:01:42 +0000 | [diff] [blame] | 49 | /* Actual code that puts the SoC in different idle states */ |
| 50 | static int davinci_enter_idle(struct cpuidle_device *dev, |
Daniel Lezcano | c062d44 | 2013-04-03 12:15:19 +0000 | [diff] [blame] | 51 | struct cpuidle_driver *drv, int index) |
Daniel Lezcano | 8d60143 | 2013-02-04 12:01:42 +0000 | [diff] [blame] | 52 | { |
Daniel Lezcano | 36ce8d4 | 2013-02-04 12:01:43 +0000 | [diff] [blame] | 53 | davinci_save_ddr_power(1, ddr2_pdown); |
Daniel Lezcano | c062d44 | 2013-04-03 12:15:19 +0000 | [diff] [blame] | 54 | cpu_do_idle(); |
Daniel Lezcano | 36ce8d4 | 2013-02-04 12:01:43 +0000 | [diff] [blame] | 55 | davinci_save_ddr_power(0, ddr2_pdown); |
Daniel Lezcano | 8d60143 | 2013-02-04 12:01:42 +0000 | [diff] [blame] | 56 | |
| 57 | return index; |
| 58 | } |
| 59 | |
| 60 | static struct cpuidle_driver davinci_idle_driver = { |
| 61 | .name = "cpuidle-davinci", |
| 62 | .owner = THIS_MODULE, |
Daniel Lezcano | 8d60143 | 2013-02-04 12:01:42 +0000 | [diff] [blame] | 63 | .states[0] = ARM_CPUIDLE_WFI_STATE, |
| 64 | .states[1] = { |
| 65 | .enter = davinci_enter_idle, |
| 66 | .exit_latency = 10, |
Daniel Lezcano | 7006b8a | 2013-06-28 12:09:09 +0200 | [diff] [blame] | 67 | .target_residency = 10000, |
Daniel Lezcano | 8d60143 | 2013-02-04 12:01:42 +0000 | [diff] [blame] | 68 | .name = "DDR SR", |
| 69 | .desc = "WFI and DDR Self Refresh", |
| 70 | }, |
| 71 | .state_count = DAVINCI_CPUIDLE_MAX_STATES, |
| 72 | }; |
| 73 | |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 74 | static int __init davinci_cpuidle_probe(struct platform_device *pdev) |
| 75 | { |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 76 | struct davinci_cpuidle_config *pdata = pdev->dev.platform_data; |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 77 | |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 78 | if (!pdata) { |
| 79 | dev_err(&pdev->dev, "cannot get platform data\n"); |
| 80 | return -ENOENT; |
| 81 | } |
| 82 | |
Sekhar Nori | 948c66d | 2009-11-16 17:21:37 +0530 | [diff] [blame] | 83 | ddr2_reg_base = pdata->ddr2_ctlr_base; |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 84 | |
Daniel Lezcano | 5af4a21 | 2013-02-04 12:01:41 +0000 | [diff] [blame] | 85 | ddr2_pdown = pdata->ddr2_pdown; |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 86 | |
Daniel Lezcano | 3aec034 | 2013-04-23 08:54:44 +0000 | [diff] [blame] | 87 | return cpuidle_register(&davinci_idle_driver, NULL); |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static struct platform_driver davinci_cpuidle_driver = { |
| 91 | .driver = { |
| 92 | .name = "cpuidle-davinci", |
Sekhar Nori | a6c0f6e | 2009-11-03 15:14:13 +0530 | [diff] [blame] | 93 | }, |
| 94 | }; |
| 95 | |
| 96 | static int __init davinci_cpuidle_init(void) |
| 97 | { |
| 98 | return platform_driver_probe(&davinci_cpuidle_driver, |
| 99 | davinci_cpuidle_probe); |
| 100 | } |
| 101 | device_initcall(davinci_cpuidle_init); |
| 102 | |