^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2012 Calxeda, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2012 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2012 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Maintainer: Rob Herring <rob.herring@calxeda.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/cpuidle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/cpu_pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/psci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/cpuidle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <uapi/linux/psci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define CALXEDA_IDLE_PARAM \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ((0 << PSCI_0_2_POWER_STATE_ID_SHIFT) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) (0 << PSCI_0_2_POWER_STATE_AFFL_SHIFT) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) (PSCI_POWER_STATE_TYPE_POWER_DOWN << PSCI_0_2_POWER_STATE_TYPE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int calxeda_idle_finish(unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return psci_ops.cpu_suspend(CALXEDA_IDLE_PARAM, __pa(cpu_resume));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct cpuidle_driver *drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) cpu_pm_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) cpu_suspend(0, calxeda_idle_finish);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) cpu_pm_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct cpuidle_driver calxeda_idle_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .name = "calxeda_idle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .states = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ARM_CPUIDLE_WFI_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .name = "PG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .desc = "Power Gate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .exit_latency = 30,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .power_usage = 50,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .target_residency = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .enter = calxeda_pwrdown_idle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .state_count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int calxeda_cpuidle_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return cpuidle_register(&calxeda_idle_driver, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static struct platform_driver calxeda_cpuidle_plat_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .name = "cpuidle-calxeda",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .probe = calxeda_cpuidle_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) builtin_platform_driver(calxeda_cpuidle_plat_driver);