Merge tag 'soc-fixes-6.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-block.git] / drivers / cpuidle / cpuidle-kirkwood.c
CommitLineData
3bb16560 1// SPDX-License-Identifier: GPL-2.0-only
e50b6bef 2/*
e50b6bef
RK
3 * CPU idle Marvell Kirkwood SoCs
4 *
e50b6bef
RK
5 * The cpu idle uses wait-for-interrupt and DDR self refresh in order
6 * to implement two idle states -
7 * #1 wait-for-interrupt
8 * #2 wait-for-interrupt and DDR self refresh
a8e39c35
DL
9 *
10 * Maintainer: Jason Cooper <jason@lakedaemon.net>
11 * Maintainer: Andrew Lunn <andrew@lunn.ch>
e50b6bef
RK
12 */
13
14#include <linux/kernel.h>
9cfc94eb 15#include <linux/module.h>
e50b6bef
RK
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/cpuidle.h>
19#include <linux/io.h>
dc28094b 20#include <linux/export.h>
b334648d 21#include <asm/cpuidle.h>
e50b6bef
RK
22
23#define KIRKWOOD_MAX_STATES 2
24
9cfc94eb
AL
25static void __iomem *ddr_operation_base;
26
e50b6bef
RK
27/* Actual code that puts the SoC in different idle states */
28static int kirkwood_enter_idle(struct cpuidle_device *dev,
9cfc94eb 29 struct cpuidle_driver *drv,
e978aa7d 30 int index)
e50b6bef 31{
9cfc94eb 32 writel(0x7, ddr_operation_base);
b334648d 33 cpu_do_idle();
e978aa7d
DD
34
35 return index;
e50b6bef
RK
36}
37
b334648d
RL
38static struct cpuidle_driver kirkwood_idle_driver = {
39 .name = "kirkwood_idle",
40 .owner = THIS_MODULE,
b334648d
RL
41 .states[0] = ARM_CPUIDLE_WFI_STATE,
42 .states[1] = {
43 .enter = kirkwood_enter_idle,
44 .exit_latency = 10,
45 .target_residency = 100000,
b334648d
RL
46 .name = "DDR SR",
47 .desc = "WFI and DDR Self Refresh",
48 },
49 .state_count = KIRKWOOD_MAX_STATES,
50};
b334648d 51
e50b6bef 52/* Initialize CPU idle by registering the idle states */
9cfc94eb 53static int kirkwood_cpuidle_probe(struct platform_device *pdev)
e50b6bef 54{
85c3ebd4 55 ddr_operation_base = devm_platform_ioremap_resource(pdev, 0);
488540bf
SMP
56 if (IS_ERR(ddr_operation_base))
57 return PTR_ERR(ddr_operation_base);
e50b6bef 58
30dc72c6 59 return cpuidle_register(&kirkwood_idle_driver, NULL);
e50b6bef
RK
60}
61
75d6137d 62static int kirkwood_cpuidle_remove(struct platform_device *pdev)
9cfc94eb 63{
30dc72c6 64 cpuidle_unregister(&kirkwood_idle_driver);
9cfc94eb
AL
65 return 0;
66}
67
68static struct platform_driver kirkwood_cpuidle_driver = {
69 .probe = kirkwood_cpuidle_probe,
70 .remove = kirkwood_cpuidle_remove,
71 .driver = {
72 .name = "kirkwood_cpuidle",
9cfc94eb
AL
73 },
74};
75
76module_platform_driver(kirkwood_cpuidle_driver);
77
78MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
79MODULE_DESCRIPTION("Kirkwood cpu idle driver");
80MODULE_LICENSE("GPL v2");
81MODULE_ALIAS("platform:kirkwood-cpuidle");