Abhijeet Dharmapurikar | 0db555f | 2012-08-23 15:51:58 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | #ifndef _ARCH_ARM_MACH_MSM_MSM_DCVS_H |
| 14 | #define _ARCH_ARM_MACH_MSM_MSM_DCVS_H |
| 15 | |
| 16 | #include <mach/msm_dcvs_scm.h> |
| 17 | |
| 18 | #define CORE_NAME_MAX (32) |
| 19 | #define CORES_MAX (10) |
| 20 | |
Abhijeet Dharmapurikar | 0db555f | 2012-08-23 15:51:58 -0700 | [diff] [blame] | 21 | #define CPU_OFFSET 1 /* used to notify TZ the core number */ |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 22 | #define GPU_OFFSET (CORES_MAX * 2/3) /* there will be more cpus than gpus, |
| 23 | * let the GPU be assigned fewer core |
| 24 | * elements and start later |
| 25 | */ |
Abhijeet Dharmapurikar | 0db555f | 2012-08-23 15:51:58 -0700 | [diff] [blame] | 26 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 27 | enum msm_core_idle_state { |
| 28 | MSM_DCVS_IDLE_ENTER, |
| 29 | MSM_DCVS_IDLE_EXIT, |
| 30 | }; |
| 31 | |
| 32 | enum msm_core_control_event { |
| 33 | MSM_DCVS_ENABLE_IDLE_PULSE, |
| 34 | MSM_DCVS_DISABLE_IDLE_PULSE, |
| 35 | MSM_DCVS_ENABLE_HIGH_LATENCY_MODES, |
| 36 | MSM_DCVS_DISABLE_HIGH_LATENCY_MODES, |
| 37 | }; |
| 38 | |
Steve Muckle | f9a8749 | 2012-11-02 15:41:00 -0700 | [diff] [blame] | 39 | struct msm_dcvs_sync_rule { |
| 40 | unsigned long cpu_khz; |
| 41 | unsigned long gpu_floor_khz; |
| 42 | }; |
| 43 | |
| 44 | struct msm_dcvs_platform_data { |
| 45 | struct msm_dcvs_sync_rule *sync_rules; |
| 46 | unsigned num_sync_rules; |
Steve Muckle | 749f301 | 2012-11-21 10:12:39 -0800 | [diff] [blame] | 47 | unsigned long gpu_max_nom_khz; |
Steve Muckle | f9a8749 | 2012-11-02 15:41:00 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Abhijeet Dharmapurikar | c1ed66c | 2012-09-10 16:03:39 -0700 | [diff] [blame] | 50 | struct msm_gov_platform_data { |
| 51 | struct msm_dcvs_core_info *info; |
| 52 | int latency; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /** |
Steve Muckle | f9a8749 | 2012-11-02 15:41:00 -0700 | [diff] [blame] | 56 | * msm_dcvs_register_cpu_freq |
| 57 | * @freq: the frequency value to register |
| 58 | * @voltage: the operating voltage (in mV) associated with the above frequency |
| 59 | * |
| 60 | * Register a cpu frequency and its operating voltage with dcvs. |
| 61 | */ |
| 62 | #ifdef CONFIG_MSM_DCVS |
| 63 | void msm_dcvs_register_cpu_freq(uint32_t freq, uint32_t voltage); |
| 64 | #else |
| 65 | static inline void msm_dcvs_register_cpu_freq(uint32_t freq, uint32_t voltage) |
| 66 | {} |
| 67 | #endif |
| 68 | |
| 69 | /** |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 70 | * msm_dcvs_idle |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 71 | * @dcvs_core_id: The id returned by msm_dcvs_register_core |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 72 | * @state: The enter/exit idle state the core is in |
| 73 | * @iowaited: iowait in us |
| 74 | * on iMSM_DCVS_IDLE_EXIT. |
| 75 | * @return: |
| 76 | * 0 on success, |
| 77 | * -ENOSYS, |
| 78 | * -EINVAL, |
| 79 | * SCM return values |
| 80 | * |
| 81 | * Send idle state notifications to the msm_dcvs driver |
| 82 | */ |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 83 | int msm_dcvs_idle(int dcvs_core_id, enum msm_core_idle_state state, |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 84 | uint32_t iowaited); |
| 85 | |
| 86 | /** |
| 87 | * struct msm_dcvs_core_info |
| 88 | * |
| 89 | * Core specific information used by algorithm. Need to provide this |
| 90 | * before the sink driver can be registered. |
| 91 | */ |
| 92 | struct msm_dcvs_core_info { |
Abhijeet Dharmapurikar | fc7dca4 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 93 | int num_cores; |
| 94 | int *sensors; |
Abhijeet Dharmapurikar | 80add42 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 95 | int thermal_poll_ms; |
Abhijeet Dharmapurikar | 4445166 | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 96 | struct msm_dcvs_freq_entry *freq_tbl; |
| 97 | struct msm_dcvs_core_param core_param; |
| 98 | struct msm_dcvs_algo_param algo_param; |
| 99 | struct msm_dcvs_energy_curve_coeffs energy_coeffs; |
| 100 | struct msm_dcvs_power_params power_param; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * msm_dcvs_register_core |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 105 | * @type: whether this is a CPU or a GPU |
| 106 | * @type_core_num: The number of the core for a type |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 107 | * @info: The core specific algorithm parameters. |
Abhijeet Dharmapurikar | fc7dca4 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 108 | * @sensor: The thermal sensor number of the core in question |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 109 | * @return : |
| 110 | * 0 on success, |
| 111 | * -ENOSYS, |
| 112 | * -ENOMEM |
| 113 | * |
| 114 | * Register the core with msm_dcvs driver. Done once at init before calling |
| 115 | * msm_dcvs_freq_sink_register |
| 116 | * Cores that need to run synchronously must share the same group id. |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 117 | */ |
Abhijeet Dharmapurikar | 6913411 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 118 | extern int msm_dcvs_register_core( |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 119 | enum msm_dcvs_core_type type, |
| 120 | int type_core_num, |
Abhijeet Dharmapurikar | 6913411 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 121 | struct msm_dcvs_core_info *info, |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 122 | int (*set_frequency)(int type_core_num, unsigned int freq), |
| 123 | unsigned int (*get_frequency)(int type_core_num), |
| 124 | int (*idle_enable)(int type_core_num, |
| 125 | enum msm_core_control_event event), |
Steve Muckle | 682c7a0 | 2012-11-12 14:20:39 -0800 | [diff] [blame] | 126 | int (*set_floor_frequency)(int type_core_num, unsigned int freq), |
Abhijeet Dharmapurikar | 6913411 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 127 | int sensor); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 128 | |
| 129 | /** |
Abhijeet Dharmapurikar | 6913411 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 130 | * msm_dcvs_freq_sink_start |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 131 | * @drv: The sink driver |
| 132 | * @return: Handle unique to the core. |
| 133 | * |
| 134 | * Register the clock driver code with the msm_dvs driver to get notified about |
| 135 | * frequency change requests. |
| 136 | */ |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 137 | extern int msm_dcvs_freq_sink_start(int dcvs_core_id); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
Abhijeet Dharmapurikar | 6913411 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 140 | * msm_dcvs_freq_sink_stop |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 141 | * @drv: The sink driver |
| 142 | * @return: |
| 143 | * 0 on success, |
| 144 | * -EINVAL |
| 145 | * |
| 146 | * Unregister the sink driver for the core. This will cause the source driver |
| 147 | * for the core to stop sending idle pulses. |
| 148 | */ |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 149 | extern int msm_dcvs_freq_sink_stop(int dcvs_core_id); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 150 | |
Abhijeet Dharmapurikar | 68c970e | 2012-08-31 20:42:53 -0700 | [diff] [blame] | 151 | /** |
| 152 | * msm_dcvs_update_limits |
| 153 | * @drv: The sink driver |
| 154 | * |
| 155 | * Update the frequency known to dcvs when the limits are changed. |
| 156 | */ |
Abhijeet Dharmapurikar | 1bbc032 | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 157 | extern void msm_dcvs_update_limits(int dcvs_core_id); |
Steve Muckle | 749f301 | 2012-11-21 10:12:39 -0800 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * msm_dcvs_apply_gpu_floor |
| 161 | * @cpu_freq: CPU frequency to compare to GPU sync rules |
| 162 | * |
| 163 | * Apply a GPU floor frequency if the corresponding CPU frequency, |
| 164 | * or the number of CPUs online, requires it. |
| 165 | */ |
| 166 | extern void msm_dcvs_apply_gpu_floor(unsigned long cpu_freq); |
Steve Muckle | c48381e | 2012-11-21 15:47:15 -0800 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * msm_dcvs_update_algo_params |
| 170 | * @return: |
| 171 | * 0 on success, < 0 on error |
| 172 | * |
| 173 | * Updates the DCVS algorithm with parameters depending on the |
| 174 | * number of CPUs online. |
| 175 | */ |
| 176 | extern int msm_dcvs_update_algo_params(void); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 177 | #endif |