Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 ARM Ltd. |
| 3 | * All Rights Reserved |
Matt Wagantall | 902c05e | 2012-01-31 16:39:22 -0800 | [diff] [blame^] | 4 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/smp.h> |
| 13 | |
| 14 | #include <asm/cacheflush.h> |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 15 | #include <asm/vfp.h> |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 16 | |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 17 | #include "pm.h" |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 18 | #include "qdss.h" |
| 19 | #include "spm.h" |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 20 | |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 21 | extern volatile int pen_release; |
| 22 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 23 | struct msm_hotplug_device { |
| 24 | struct completion cpu_killed; |
| 25 | unsigned int warm_boot; |
| 26 | }; |
| 27 | |
| 28 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct msm_hotplug_device, |
| 29 | msm_hotplug_devices); |
| 30 | |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 31 | static inline void cpu_enter_lowpower(void) |
| 32 | { |
| 33 | /* Just flush the cache. Changing the coherency is not yet |
| 34 | * available on msm. */ |
| 35 | flush_cache_all(); |
| 36 | } |
| 37 | |
| 38 | static inline void cpu_leave_lowpower(void) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | static inline void platform_do_lowpower(unsigned int cpu) |
| 43 | { |
| 44 | /* Just enter wfi for now. TODO: Properly shut off the cpu. */ |
| 45 | for (;;) { |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 46 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 47 | msm_pm_cpu_enter_lowpower(cpu); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 48 | if (pen_release == cpu) { |
| 49 | /* |
| 50 | * OK, proper wakeup, we're done |
| 51 | */ |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * getting here, means that we have come out of WFI without |
| 57 | * having been woken up - this shouldn't happen |
| 58 | * |
| 59 | * The trouble is, letting people know about this is not really |
| 60 | * possible, since we are currently running incoherently, and |
| 61 | * therefore cannot safely call printk() or anything else |
| 62 | */ |
| 63 | pr_debug("CPU%u: spurious wakeup call\n", cpu); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | int platform_cpu_kill(unsigned int cpu) |
| 68 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 69 | struct completion *killed = |
| 70 | &per_cpu(msm_hotplug_devices, cpu).cpu_killed; |
Matt Wagantall | 902c05e | 2012-01-31 16:39:22 -0800 | [diff] [blame^] | 71 | int ret; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 72 | |
Matt Wagantall | 902c05e | 2012-01-31 16:39:22 -0800 | [diff] [blame^] | 73 | ret = wait_for_completion_timeout(killed, HZ * 5); |
| 74 | if (ret) |
| 75 | return ret; |
| 76 | |
| 77 | return msm_pm_wait_cpu_shutdown(cpu); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /* |
| 81 | * platform-specific code to shutdown a CPU |
| 82 | * |
| 83 | * Called with IRQs disabled |
| 84 | */ |
| 85 | void platform_cpu_die(unsigned int cpu) |
| 86 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 87 | if (unlikely(cpu != smp_processor_id())) { |
| 88 | pr_crit("%s: running on %u, should be %u\n", |
| 89 | __func__, smp_processor_id(), cpu); |
| 90 | BUG(); |
| 91 | } |
| 92 | complete(&__get_cpu_var(msm_hotplug_devices).cpu_killed); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 93 | /* |
| 94 | * we're ready for shutdown now, so do it |
| 95 | */ |
| 96 | cpu_enter_lowpower(); |
| 97 | platform_do_lowpower(cpu); |
| 98 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 99 | pr_notice("CPU%u: %s: normal wakeup\n", cpu, __func__); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 100 | cpu_leave_lowpower(); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | int platform_cpu_disable(unsigned int cpu) |
| 104 | { |
| 105 | /* |
| 106 | * we don't allow CPU 0 to be shutdown (it is still too special |
| 107 | * e.g. clock tick interrupts) |
| 108 | */ |
| 109 | return cpu == 0 ? -EPERM : 0; |
| 110 | } |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 111 | |
| 112 | int msm_platform_secondary_init(unsigned int cpu) |
| 113 | { |
| 114 | int ret; |
| 115 | struct msm_hotplug_device *dev = &__get_cpu_var(msm_hotplug_devices); |
| 116 | |
| 117 | if (!dev->warm_boot) { |
| 118 | dev->warm_boot = 1; |
| 119 | init_completion(&dev->cpu_killed); |
| 120 | return 0; |
| 121 | } |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 122 | msm_jtag_restore_state(); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 123 | #ifdef CONFIG_VFP |
| 124 | vfp_reinit(); |
| 125 | #endif |
| 126 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 127 | |
| 128 | return ret; |
| 129 | } |