0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/init.h>
0010 #include <linux/cpuidle.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/atomic.h>
0013 #include <linux/smp.h>
0014 #include <linux/mfd/dbx500-prcmu.h>
0015 #include <linux/platform_data/arm-ux500-pm.h>
0016 #include <linux/platform_device.h>
0017
0018 #include <asm/cpuidle.h>
0019
0020 static atomic_t master = ATOMIC_INIT(0);
0021 static DEFINE_SPINLOCK(master_lock);
0022
0023 static inline int ux500_enter_idle(struct cpuidle_device *dev,
0024 struct cpuidle_driver *drv, int index)
0025 {
0026 int this_cpu = smp_processor_id();
0027 bool recouple = false;
0028
0029 if (atomic_inc_return(&master) == num_online_cpus()) {
0030
0031
0032
0033 if (!spin_trylock(&master_lock))
0034 goto wfi;
0035
0036
0037 if (prcmu_gic_decouple()) {
0038 spin_unlock(&master_lock);
0039 goto out;
0040 }
0041
0042
0043
0044 recouple = true;
0045
0046
0047
0048
0049 if (!prcmu_is_cpu_in_wfi(this_cpu ? 0 : 1))
0050 goto out;
0051
0052
0053
0054 if (prcmu_copy_gic_settings())
0055 goto out;
0056
0057
0058
0059 if (prcmu_gic_pending_irq())
0060 goto out;
0061
0062
0063 if (prcmu_pending_irq())
0064 goto out;
0065
0066
0067
0068
0069 if (prcmu_set_power_state(PRCMU_AP_IDLE, true, true))
0070 goto out;
0071
0072
0073
0074 recouple = false;
0075
0076 spin_unlock(&master_lock);
0077 }
0078 wfi:
0079 cpu_do_idle();
0080 out:
0081 atomic_dec(&master);
0082
0083 if (recouple) {
0084 prcmu_gic_recouple();
0085 spin_unlock(&master_lock);
0086 }
0087
0088 return index;
0089 }
0090
0091 static struct cpuidle_driver ux500_idle_driver = {
0092 .name = "ux500_idle",
0093 .owner = THIS_MODULE,
0094 .states = {
0095 ARM_CPUIDLE_WFI_STATE,
0096 {
0097 .enter = ux500_enter_idle,
0098 .exit_latency = 70,
0099 .target_residency = 260,
0100 .flags = CPUIDLE_FLAG_TIMER_STOP,
0101 .name = "ApIdle",
0102 .desc = "ARM Retention",
0103 },
0104 },
0105 .safe_state_index = 0,
0106 .state_count = 2,
0107 };
0108
0109 static int dbx500_cpuidle_probe(struct platform_device *pdev)
0110 {
0111
0112 prcmu_enable_wakeups(PRCMU_WAKEUP(ARM) | PRCMU_WAKEUP(RTC) |
0113 PRCMU_WAKEUP(ABB));
0114
0115 return cpuidle_register(&ux500_idle_driver, NULL);
0116 }
0117
0118 static struct platform_driver dbx500_cpuidle_plat_driver = {
0119 .driver = {
0120 .name = "db8500-cpuidle",
0121 },
0122 .probe = dbx500_cpuidle_probe,
0123 };
0124 builtin_platform_driver(dbx500_cpuidle_plat_driver);