1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* |
3 | * based on arch/arm/mach-kirkwood/cpuidle.c |
4 | * |
5 | * CPU idle support for AT91 SoC |
6 | * |
7 | * The cpu idle uses wait-for-interrupt and RAM self refresh in order |
8 | * to implement two idle states - |
9 | * #1 wait-for-interrupt |
10 | * #2 wait-for-interrupt and RAM self refresh |
11 | */ |
12 | |
13 | #include <linux/kernel.h> |
14 | #include <linux/init.h> |
15 | #include <linux/platform_device.h> |
16 | #include <linux/cpuidle.h> |
17 | #include <linux/io.h> |
18 | #include <linux/export.h> |
19 | #include <asm/cpuidle.h> |
20 | |
21 | #define AT91_MAX_STATES 2 |
22 | |
23 | static void (*at91_standby)(void); |
24 | |
25 | /* Actual code that puts the SoC in different idle states */ |
26 | static int at91_enter_idle(struct cpuidle_device *dev, |
27 | struct cpuidle_driver *drv, |
28 | int index) |
29 | { |
30 | at91_standby(); |
31 | return index; |
32 | } |
33 | |
34 | static struct cpuidle_driver at91_idle_driver = { |
35 | .name = "at91_idle" , |
36 | .owner = THIS_MODULE, |
37 | .states[0] = ARM_CPUIDLE_WFI_STATE, |
38 | .states[1] = { |
39 | .enter = at91_enter_idle, |
40 | .exit_latency = 10, |
41 | .target_residency = 10000, |
42 | .name = "RAM_SR" , |
43 | .desc = "WFI and DDR Self Refresh" , |
44 | }, |
45 | .state_count = AT91_MAX_STATES, |
46 | }; |
47 | |
48 | /* Initialize CPU idle by registering the idle states */ |
49 | static int at91_cpuidle_probe(struct platform_device *dev) |
50 | { |
51 | at91_standby = (void *)(dev->dev.platform_data); |
52 | |
53 | return cpuidle_register(drv: &at91_idle_driver, NULL); |
54 | } |
55 | |
56 | static struct platform_driver at91_cpuidle_driver = { |
57 | .driver = { |
58 | .name = "cpuidle-at91" , |
59 | }, |
60 | .probe = at91_cpuidle_probe, |
61 | }; |
62 | builtin_platform_driver(at91_cpuidle_driver); |
63 | |