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