Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * CPU idle Marvell Kirkwood SoCs
4 *
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
9 *
10 * Maintainer: Jason Cooper <jason@lakedaemon.net>
11 * Maintainer: Andrew Lunn <andrew@lunn.ch>
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/cpuidle.h>
19#include <linux/io.h>
20#include <linux/export.h>
21#include <asm/cpuidle.h>
22
23#define KIRKWOOD_MAX_STATES 2
24
25static void __iomem *ddr_operation_base;
26
27/* Actual code that puts the SoC in different idle states */
28static int kirkwood_enter_idle(struct cpuidle_device *dev,
29 struct cpuidle_driver *drv,
30 int index)
31{
32 writel(0x7, ddr_operation_base);
33 cpu_do_idle();
34
35 return index;
36}
37
38static struct cpuidle_driver kirkwood_idle_driver = {
39 .name = "kirkwood_idle",
40 .owner = THIS_MODULE,
41 .states[0] = ARM_CPUIDLE_WFI_STATE,
42 .states[1] = {
43 .enter = kirkwood_enter_idle,
44 .exit_latency = 10,
45 .target_residency = 100000,
46 .name = "DDR SR",
47 .desc = "WFI and DDR Self Refresh",
48 },
49 .state_count = KIRKWOOD_MAX_STATES,
50};
51
52/* Initialize CPU idle by registering the idle states */
53static int kirkwood_cpuidle_probe(struct platform_device *pdev)
54{
55 ddr_operation_base = devm_platform_ioremap_resource(pdev, 0);
56 if (IS_ERR(ddr_operation_base))
57 return PTR_ERR(ddr_operation_base);
58
59 return cpuidle_register(&kirkwood_idle_driver, NULL);
60}
61
62static int kirkwood_cpuidle_remove(struct platform_device *pdev)
63{
64 cpuidle_unregister(&kirkwood_idle_driver);
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",
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");
1/*
2 * CPU idle Marvell Kirkwood SoCs
3 *
4 * This file is licensed under the terms of the GNU General Public
5 * License version 2. This program is licensed "as is" without any
6 * warranty of any kind, whether express or implied.
7 *
8 * The cpu idle uses wait-for-interrupt and DDR self refresh in order
9 * to implement two idle states -
10 * #1 wait-for-interrupt
11 * #2 wait-for-interrupt and DDR self refresh
12 *
13 * Maintainer: Jason Cooper <jason@lakedaemon.net>
14 * Maintainer: Andrew Lunn <andrew@lunn.ch>
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/cpuidle.h>
22#include <linux/io.h>
23#include <linux/export.h>
24#include <asm/proc-fns.h>
25#include <asm/cpuidle.h>
26
27#define KIRKWOOD_MAX_STATES 2
28
29static void __iomem *ddr_operation_base;
30
31/* Actual code that puts the SoC in different idle states */
32static int kirkwood_enter_idle(struct cpuidle_device *dev,
33 struct cpuidle_driver *drv,
34 int index)
35{
36 writel(0x7, ddr_operation_base);
37 cpu_do_idle();
38
39 return index;
40}
41
42static struct cpuidle_driver kirkwood_idle_driver = {
43 .name = "kirkwood_idle",
44 .owner = THIS_MODULE,
45 .states[0] = ARM_CPUIDLE_WFI_STATE,
46 .states[1] = {
47 .enter = kirkwood_enter_idle,
48 .exit_latency = 10,
49 .target_residency = 100000,
50 .flags = CPUIDLE_FLAG_TIME_VALID,
51 .name = "DDR SR",
52 .desc = "WFI and DDR Self Refresh",
53 },
54 .state_count = KIRKWOOD_MAX_STATES,
55};
56
57/* Initialize CPU idle by registering the idle states */
58static int kirkwood_cpuidle_probe(struct platform_device *pdev)
59{
60 struct resource *res;
61
62 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
63 ddr_operation_base = devm_ioremap_resource(&pdev->dev, res);
64 if (IS_ERR(ddr_operation_base))
65 return PTR_ERR(ddr_operation_base);
66
67 return cpuidle_register(&kirkwood_idle_driver, NULL);
68}
69
70static int kirkwood_cpuidle_remove(struct platform_device *pdev)
71{
72 cpuidle_unregister(&kirkwood_idle_driver);
73 return 0;
74}
75
76static struct platform_driver kirkwood_cpuidle_driver = {
77 .probe = kirkwood_cpuidle_probe,
78 .remove = kirkwood_cpuidle_remove,
79 .driver = {
80 .name = "kirkwood_cpuidle",
81 .owner = THIS_MODULE,
82 },
83};
84
85module_platform_driver(kirkwood_cpuidle_driver);
86
87MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
88MODULE_DESCRIPTION("Kirkwood cpu idle driver");
89MODULE_LICENSE("GPL v2");
90MODULE_ALIAS("platform:kirkwood-cpuidle");