Merge tag 'locking-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / arm / mach-davinci / cpuidle.c
blobdd38785536d51e933dc98f4d2c3ff0ae1f74741d
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * CPU idle for DaVinci SoCs
5 * Copyright (C) 2009 Texas Instruments Incorporated. https://www.ti.com/
7 * Derived from Marvell Kirkwood CPU idle code
8 * (arch/arm/mach-kirkwood/cpuidle.c)
9 */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/cpuidle.h>
15 #include <linux/io.h>
16 #include <linux/export.h>
17 #include <asm/cpuidle.h>
19 #include "cpuidle.h"
20 #include "ddr2.h"
22 #define DAVINCI_CPUIDLE_MAX_STATES 2
24 static void __iomem *ddr2_reg_base;
25 static bool ddr2_pdown;
27 static void davinci_save_ddr_power(int enter, bool pdown)
29 u32 val;
31 val = __raw_readl(ddr2_reg_base + DDR2_SDRCR_OFFSET);
33 if (enter) {
34 if (pdown)
35 val |= DDR2_SRPD_BIT;
36 else
37 val &= ~DDR2_SRPD_BIT;
38 val |= DDR2_LPMODEN_BIT;
39 } else {
40 val &= ~(DDR2_SRPD_BIT | DDR2_LPMODEN_BIT);
43 __raw_writel(val, ddr2_reg_base + DDR2_SDRCR_OFFSET);
46 /* Actual code that puts the SoC in different idle states */
47 static int davinci_enter_idle(struct cpuidle_device *dev,
48 struct cpuidle_driver *drv, int index)
50 davinci_save_ddr_power(1, ddr2_pdown);
51 cpu_do_idle();
52 davinci_save_ddr_power(0, ddr2_pdown);
54 return index;
57 static struct cpuidle_driver davinci_idle_driver = {
58 .name = "cpuidle-davinci",
59 .owner = THIS_MODULE,
60 .states[0] = ARM_CPUIDLE_WFI_STATE,
61 .states[1] = {
62 .enter = davinci_enter_idle,
63 .exit_latency = 10,
64 .target_residency = 10000,
65 .name = "DDR SR",
66 .desc = "WFI and DDR Self Refresh",
68 .state_count = DAVINCI_CPUIDLE_MAX_STATES,
71 static int __init davinci_cpuidle_probe(struct platform_device *pdev)
73 struct davinci_cpuidle_config *pdata = pdev->dev.platform_data;
75 if (!pdata) {
76 dev_err(&pdev->dev, "cannot get platform data\n");
77 return -ENOENT;
80 ddr2_reg_base = pdata->ddr2_ctlr_base;
82 ddr2_pdown = pdata->ddr2_pdown;
84 return cpuidle_register(&davinci_idle_driver, NULL);
87 static struct platform_driver davinci_cpuidle_driver = {
88 .driver = {
89 .name = "cpuidle-davinci",
93 static int __init davinci_cpuidle_init(void)
95 return platform_driver_probe(&davinci_cpuidle_driver,
96 davinci_cpuidle_probe);
98 device_initcall(davinci_cpuidle_init);