1 // SPDX-License-Identifier: GPL-2.0-only
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)
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/cpuidle.h>
16 #include <linux/export.h>
17 #include <asm/cpuidle.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
)
31 val
= __raw_readl(ddr2_reg_base
+ DDR2_SDRCR_OFFSET
);
37 val
&= ~DDR2_SRPD_BIT
;
38 val
|= DDR2_LPMODEN_BIT
;
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
);
52 davinci_save_ddr_power(0, ddr2_pdown
);
57 static struct cpuidle_driver davinci_idle_driver
= {
58 .name
= "cpuidle-davinci",
60 .states
[0] = ARM_CPUIDLE_WFI_STATE
,
62 .enter
= davinci_enter_idle
,
64 .target_residency
= 10000,
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
;
76 dev_err(&pdev
->dev
, "cannot get platform data\n");
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
= {
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
);