| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/pm.h | 
|  | 2 | * | 
|  | 3 | * Copyright (C) 2007 Google, Inc. | 
| Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 4 | * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5 | * Author: San Mehat <san@android.com> | 
|  | 6 | * | 
|  | 7 | * This software is licensed under the terms of the GNU General Public | 
|  | 8 | * License version 2, as published by the Free Software Foundation, and | 
|  | 9 | * may be copied, distributed, and modified under those terms. | 
|  | 10 | * | 
|  | 11 | * This program is distributed in the hope that it will be useful, | 
|  | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 14 | * GNU General Public License for more details. | 
|  | 15 | * | 
|  | 16 | */ | 
|  | 17 |  | 
|  | 18 | #ifndef __ARCH_ARM_MACH_MSM_PM_H | 
|  | 19 | #define __ARCH_ARM_MACH_MSM_PM_H | 
|  | 20 |  | 
|  | 21 | #include <linux/types.h> | 
|  | 22 | #include <linux/cpuidle.h> | 
|  | 23 |  | 
|  | 24 | #ifdef CONFIG_SMP | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | extern void msm_secondary_startup(void); | 
|  | 26 | #else | 
|  | 27 | #define msm_secondary_startup NULL | 
|  | 28 | #endif | 
|  | 29 |  | 
| Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 30 | DECLARE_PER_CPU(int,  power_collapsed); | 
| Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 31 |  | 
| Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 32 | struct msm_pm_irq_calls { | 
|  | 33 | unsigned int (*irq_pending)(void); | 
|  | 34 | int (*idle_sleep_allowed)(void); | 
|  | 35 | void (*enter_sleep1)(bool modem_wake, int from_idle, uint32_t | 
|  | 36 | *irq_mask); | 
|  | 37 | int (*enter_sleep2)(bool modem_wake, int from_idle); | 
|  | 38 | void (*exit_sleep1)(uint32_t irq_mask, uint32_t wakeup_reason, | 
|  | 39 | uint32_t pending_irqs); | 
|  | 40 | void (*exit_sleep2)(uint32_t irq_mask, uint32_t wakeup_reason, | 
|  | 41 | uint32_t pending_irqs); | 
|  | 42 | void (*exit_sleep3)(uint32_t irq_mask, uint32_t wakeup_reason, | 
|  | 43 | uint32_t pending_irqs); | 
|  | 44 | }; | 
|  | 45 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | enum msm_pm_sleep_mode { | 
| Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 47 | MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT = 0, | 
|  | 48 | MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT = 1, | 
|  | 49 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE = 2, | 
|  | 50 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE = 3, | 
|  | 51 | MSM_PM_SLEEP_MODE_APPS_SLEEP = 4, | 
|  | 52 | MSM_PM_SLEEP_MODE_RETENTION = MSM_PM_SLEEP_MODE_APPS_SLEEP, | 
|  | 53 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE_SUSPEND = 5, | 
|  | 54 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN = 6, | 
| Priyanka Mathur | 848bb4c | 2012-11-30 18:04:57 -0800 | [diff] [blame] | 55 | MSM_PM_SLEEP_MODE_NR = 7, | 
|  | 56 | MSM_PM_SLEEP_MODE_NOT_SELECTED, | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 57 | }; | 
|  | 58 |  | 
|  | 59 | #define MSM_PM_MODE(cpu, mode_nr)  ((cpu) * MSM_PM_SLEEP_MODE_NR + (mode_nr)) | 
|  | 60 |  | 
| Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 61 | struct msm_pm_time_params { | 
|  | 62 | uint32_t latency_us; | 
|  | 63 | uint32_t sleep_us; | 
|  | 64 | uint32_t next_event_us; | 
|  | 65 | uint32_t modified_time_us; | 
|  | 66 | }; | 
|  | 67 |  | 
| Anji Jonnala | f91d897 | 2013-02-26 17:55:50 +0530 | [diff] [blame] | 68 | struct msm_pm_sleep_status_data { | 
|  | 69 | void *base_addr; | 
|  | 70 | uint32_t cpu_offset; | 
|  | 71 | uint32_t mask; | 
|  | 72 | }; | 
|  | 73 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | struct msm_pm_platform_data { | 
|  | 75 | u8 idle_supported;   /* Allow device to enter mode during idle */ | 
|  | 76 | u8 suspend_supported; /* Allow device to enter mode during suspend */ | 
|  | 77 | u8 suspend_enabled;  /* enabled for suspend */ | 
|  | 78 | u8 idle_enabled;     /* enabled for idle low power */ | 
|  | 79 | u32 latency;         /* interrupt latency in microseconds when entering | 
|  | 80 | and exiting the low power mode */ | 
|  | 81 | u32 residency;       /* time threshold in microseconds beyond which | 
|  | 82 | staying in the low power mode saves power */ | 
|  | 83 | }; | 
|  | 84 |  | 
| Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 85 | extern struct msm_pm_platform_data msm_pm_sleep_modes[]; | 
|  | 86 |  | 
| Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 87 | struct msm_pm_sleep_ops { | 
|  | 88 | void *(*lowest_limits)(bool from_idle, | 
| Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 89 | enum msm_pm_sleep_mode sleep_mode, | 
|  | 90 | struct msm_pm_time_params *time_param, uint32_t *power); | 
| Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 91 | int (*enter_sleep)(uint32_t sclk_count, void *limits, | 
|  | 92 | bool from_idle, bool notify_rpm); | 
|  | 93 | void (*exit_sleep)(void *limits, bool from_idle, | 
|  | 94 | bool notify_rpm, bool collapsed); | 
|  | 95 | }; | 
|  | 96 |  | 
| Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 97 | enum msm_pm_pc_mode_type { | 
| Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 98 | MSM_PM_PC_TZ_L2_INT,   /*Power collapse terminates in TZ; | 
| Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 99 | integrated L2 cache controller */ | 
| Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 100 | MSM_PM_PC_NOTZ_L2_EXT, /* Power collapse doesn't terminate in | 
| Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 101 | TZ; external L2 cache controller */ | 
| Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 102 | MSM_PM_PC_TZ_L2_EXT,   /* Power collapse terminates in TZ; | 
| Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 103 | external L2 cache controller */ | 
|  | 104 | }; | 
|  | 105 |  | 
| Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 106 | struct msm_pm_cp15_save_data { | 
|  | 107 | bool save_cp15; | 
|  | 108 | uint32_t active_vdd; | 
|  | 109 | uint32_t qsb_pc_vdd; | 
|  | 110 | uint32_t reg_saved_state_size; | 
|  | 111 | uint32_t *reg_data; | 
|  | 112 | uint32_t *reg_val; | 
|  | 113 | }; | 
|  | 114 |  | 
| Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 115 | struct msm_pm_init_data_type { | 
|  | 116 | enum msm_pm_pc_mode_type pc_mode; | 
| Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 117 | bool retention_calls_tz; | 
|  | 118 | struct msm_pm_cp15_save_data cp15_data; | 
| Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 119 | bool use_sync_timer; | 
|  | 120 | }; | 
|  | 121 |  | 
| Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 122 | struct msm_pm_cpr_ops { | 
|  | 123 | void (*cpr_suspend)(void); | 
|  | 124 | void (*cpr_resume)(void); | 
|  | 125 | }; | 
|  | 126 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 127 | void msm_pm_set_platform_data(struct msm_pm_platform_data *data, int count); | 
| Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame] | 128 | enum msm_pm_sleep_mode msm_pm_idle_enter(struct cpuidle_device *dev, | 
| Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 129 | struct cpuidle_driver *drv, int index); | 
| Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 130 | void msm_pm_set_irq_extns(struct msm_pm_irq_calls *irq_calls); | 
| Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 131 | void msm_pm_cpu_enter_lowpower(unsigned int cpu); | 
| Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 132 | void __init msm_pm_set_tz_retention_flag(unsigned int flag); | 
| Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 133 | void msm_pm_enable_retention(bool enable); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 |  | 
| Matt Wagantall | 8c327c5 | 2012-02-01 16:51:03 -0800 | [diff] [blame] | 135 | #ifdef CONFIG_MSM_PM8X60 | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | void msm_pm_set_rpm_wakeup_irq(unsigned int irq); | 
| Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 137 | void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops); | 
| Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 138 | int msm_pm_wait_cpu_shutdown(unsigned int cpu); | 
| Mahesh Sivasubramanian | 59ffcb0 | 2013-05-31 15:08:15 -0600 | [diff] [blame] | 139 | void __init msm_pm_sleep_status_init(void); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | #else | 
|  | 141 | static inline void msm_pm_set_rpm_wakeup_irq(unsigned int irq) {} | 
| Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 142 | static inline void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops) {} | 
| Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 143 | static inline int msm_pm_wait_cpu_shutdown(unsigned int cpu) { return 0; } | 
| Mahesh Sivasubramanian | 59ffcb0 | 2013-05-31 15:08:15 -0600 | [diff] [blame] | 144 | static inline void msm_pm_sleep_status_init(void) {}; | 
| Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 145 | #endif | 
| Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 146 | #ifdef CONFIG_HOTPLUG_CPU | 
|  | 147 | int msm_platform_secondary_init(unsigned int cpu); | 
|  | 148 | #else | 
|  | 149 | static inline int msm_platform_secondary_init(unsigned int cpu) { return 0; } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 150 | #endif | 
| Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 151 |  | 
|  | 152 | enum msm_pm_time_stats_id { | 
|  | 153 | MSM_PM_STAT_REQUESTED_IDLE = 0, | 
|  | 154 | MSM_PM_STAT_IDLE_SPIN, | 
|  | 155 | MSM_PM_STAT_IDLE_WFI, | 
|  | 156 | MSM_PM_STAT_RETENTION, | 
|  | 157 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, | 
|  | 158 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE, | 
|  | 159 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, | 
|  | 160 | MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE, | 
|  | 161 | MSM_PM_STAT_SUSPEND, | 
|  | 162 | MSM_PM_STAT_FAILED_SUSPEND, | 
|  | 163 | MSM_PM_STAT_NOT_IDLE, | 
|  | 164 | MSM_PM_STAT_COUNT | 
|  | 165 | }; | 
|  | 166 |  | 
|  | 167 | #ifdef CONFIG_MSM_IDLE_STATS | 
|  | 168 | void msm_pm_add_stats(enum msm_pm_time_stats_id *enable_stats, int size); | 
|  | 169 | void msm_pm_add_stat(enum msm_pm_time_stats_id id, int64_t t); | 
|  | 170 | #else | 
|  | 171 | static inline void msm_pm_add_stats(enum msm_pm_time_stats_id *enable_stats, | 
|  | 172 | int size) {} | 
|  | 173 | static inline void msm_pm_add_stat(enum msm_pm_time_stats_id id, int64_t t) {} | 
|  | 174 | #endif | 
|  | 175 |  | 
| Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 176 | void msm_pm_set_cpr_ops(struct msm_pm_cpr_ops *ops); | 
| Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 177 | extern void *msm_pc_debug_counters; | 
|  | 178 | extern unsigned long msm_pc_debug_counters_phys; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 179 | #endif  /* __ARCH_ARM_MACH_MSM_PM_H */ |