Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | */ |
Huang Rui | 7bd5542 | 2016-12-26 14:05:30 +0800 | [diff] [blame] | 23 | #include "pp_debug.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 24 | #include <linux/types.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/gfp.h> |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 27 | #include <linux/slab.h> |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 28 | #include "amd_shared.h" |
| 29 | #include "amd_powerplay.h" |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 30 | #include "pp_instance.h" |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 31 | #include "power_state.h" |
| 32 | #include "eventmanager.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 33 | |
Rex Zhu | af223df | 2016-07-28 16:51:47 +0800 | [diff] [blame] | 34 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 35 | static inline int pp_check(struct pp_instance *handle) |
| 36 | { |
| 37 | if (handle == NULL || handle->pp_valid != PP_VALID) |
| 38 | return -EINVAL; |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 39 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 40 | if (handle->smu_mgr == NULL || handle->smu_mgr->smumgr_funcs == NULL) |
| 41 | return -EINVAL; |
| 42 | |
| 43 | if (handle->pm_en == 0) |
| 44 | return PP_DPM_DISABLED; |
| 45 | |
| 46 | if (handle->hwmgr == NULL || handle->hwmgr->hwmgr_func == NULL |
| 47 | || handle->eventmgr == NULL) |
| 48 | return PP_DPM_DISABLED; |
| 49 | |
| 50 | return 0; |
| 51 | } |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 52 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 53 | static int pp_early_init(void *handle) |
| 54 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 55 | int ret; |
| 56 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 57 | |
| 58 | ret = smum_early_init(pp_handle); |
| 59 | if (ret) |
| 60 | return ret; |
| 61 | |
| 62 | if ((pp_handle->pm_en == 0) |
| 63 | || cgs_is_virtualization_enabled(pp_handle->device)) |
| 64 | return PP_DPM_DISABLED; |
| 65 | |
| 66 | ret = hwmgr_early_init(pp_handle); |
| 67 | if (ret) { |
| 68 | pp_handle->pm_en = 0; |
| 69 | return PP_DPM_DISABLED; |
| 70 | } |
| 71 | |
| 72 | ret = eventmgr_early_init(pp_handle); |
| 73 | if (ret) { |
| 74 | kfree(pp_handle->hwmgr); |
| 75 | pp_handle->hwmgr = NULL; |
| 76 | pp_handle->pm_en = 0; |
| 77 | return PP_DPM_DISABLED; |
| 78 | } |
| 79 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int pp_sw_init(void *handle) |
| 84 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 85 | struct pp_smumgr *smumgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 86 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 87 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 88 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 89 | ret = pp_check(pp_handle); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 90 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 91 | if (ret == 0 || ret == PP_DPM_DISABLED) { |
| 92 | smumgr = pp_handle->smu_mgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 93 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 94 | if (smumgr->smumgr_funcs->smu_init == NULL) |
| 95 | return -EINVAL; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 96 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 97 | ret = smumgr->smumgr_funcs->smu_init(smumgr); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 98 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 99 | pr_info("amdgpu: powerplay sw initialized\n"); |
Huang Rui | 167112b | 2016-12-14 16:26:54 +0800 | [diff] [blame] | 100 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 101 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static int pp_sw_fini(void *handle) |
| 105 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 106 | struct pp_smumgr *smumgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 107 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 108 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 109 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 110 | ret = pp_check(pp_handle); |
| 111 | if (ret == 0 || ret == PP_DPM_DISABLED) { |
| 112 | smumgr = pp_handle->smu_mgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 113 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 114 | if (smumgr->smumgr_funcs->smu_fini == NULL) |
| 115 | return -EINVAL; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 116 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 117 | ret = smumgr->smumgr_funcs->smu_fini(smumgr); |
| 118 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 119 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static int pp_hw_init(void *handle) |
| 123 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 124 | struct pp_smumgr *smumgr; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 125 | struct pp_eventmgr *eventmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 126 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 127 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 128 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 129 | ret = pp_check(pp_handle); |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 130 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 131 | if (ret == 0 || ret == PP_DPM_DISABLED) { |
| 132 | smumgr = pp_handle->smu_mgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 133 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 134 | if (smumgr->smumgr_funcs->start_smu == NULL) |
| 135 | return -EINVAL; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 136 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 137 | if(smumgr->smumgr_funcs->start_smu(smumgr)) { |
| 138 | pr_err("smc start failed\n"); |
| 139 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 140 | return -EINVAL;; |
| 141 | } |
| 142 | if (ret == PP_DPM_DISABLED) |
| 143 | return PP_DPM_DISABLED; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 144 | } |
| 145 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 146 | ret = hwmgr_hw_init(pp_handle); |
| 147 | if (ret) |
| 148 | goto err; |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 149 | |
| 150 | eventmgr = pp_handle->eventmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 151 | if (eventmgr->pp_eventmgr_init == NULL || |
| 152 | eventmgr->pp_eventmgr_init(eventmgr)) |
| 153 | goto err; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 154 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 155 | return 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 156 | err: |
| 157 | pp_handle->pm_en = 0; |
| 158 | kfree(pp_handle->eventmgr); |
| 159 | kfree(pp_handle->hwmgr); |
| 160 | pp_handle->hwmgr = NULL; |
| 161 | pp_handle->eventmgr = NULL; |
| 162 | return PP_DPM_DISABLED; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static int pp_hw_fini(void *handle) |
| 166 | { |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 167 | struct pp_eventmgr *eventmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 168 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 169 | int ret = 0; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 170 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 171 | ret = pp_check(pp_handle); |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 172 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 173 | if (ret == 0) { |
| 174 | eventmgr = pp_handle->eventmgr; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 175 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 176 | if (eventmgr->pp_eventmgr_fini != NULL) |
| 177 | eventmgr->pp_eventmgr_fini(eventmgr); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 178 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 179 | hwmgr_hw_fini(pp_handle); |
| 180 | } |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static bool pp_is_idle(void *handle) |
| 185 | { |
Edward O'Callaghan | ed5121a | 2016-07-12 10:17:52 +1000 | [diff] [blame] | 186 | return false; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static int pp_wait_for_idle(void *handle) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static int pp_sw_reset(void *handle) |
| 195 | { |
| 196 | return 0; |
| 197 | } |
| 198 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 199 | |
Rex Zhu | 465f96e | 2016-09-18 16:52:03 +0800 | [diff] [blame] | 200 | int amd_set_clockgating_by_smu(void *handle, uint32_t msg_id) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 201 | { |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 202 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 203 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 204 | int ret = 0; |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 205 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 206 | ret = pp_check(pp_handle); |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 207 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 208 | if (ret != 0) |
| 209 | return ret; |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 210 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 211 | hwmgr = pp_handle->hwmgr; |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 212 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 213 | if (hwmgr->hwmgr_func->update_clock_gatings == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 214 | pr_info("%s was not implemented.\n", __func__); |
Flora Cui | 538333f | 2016-02-15 15:45:59 +0800 | [diff] [blame] | 215 | return 0; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 216 | } |
Flora Cui | 538333f | 2016-02-15 15:45:59 +0800 | [diff] [blame] | 217 | |
Rex Zhu | 465f96e | 2016-09-18 16:52:03 +0800 | [diff] [blame] | 218 | return hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int pp_set_powergating_state(void *handle, |
| 222 | enum amd_powergating_state state) |
| 223 | { |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 224 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 225 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 226 | int ret = 0; |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 227 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 228 | ret = pp_check(pp_handle); |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 229 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 230 | if (ret != 0) |
| 231 | return ret; |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 232 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 233 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 234 | |
| 235 | if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 236 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 237 | return 0; |
| 238 | } |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 239 | |
| 240 | /* Enable/disable GFX per cu powergating through SMU */ |
| 241 | return hwmgr->hwmgr_func->enable_per_cu_power_gating(hwmgr, |
| 242 | state == AMD_PG_STATE_GATE ? true : false); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static int pp_suspend(void *handle) |
| 246 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 247 | struct pp_eventmgr *eventmgr; |
| 248 | struct pem_event_data event_data = { {0} }; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 249 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 250 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 251 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 252 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 253 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 254 | if (ret != 0) |
| 255 | return ret; |
| 256 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 257 | eventmgr = pp_handle->eventmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 258 | pem_handle_event(eventmgr, AMD_PP_EVENT_SUSPEND, &event_data); |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 259 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static int pp_resume(void *handle) |
| 264 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 265 | struct pp_eventmgr *eventmgr; |
| 266 | struct pem_event_data event_data = { {0} }; |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 267 | struct pp_smumgr *smumgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 268 | int ret, ret1; |
| 269 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 270 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 271 | ret1 = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 272 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 273 | if (ret1 != 0 && ret1 != PP_DPM_DISABLED) |
| 274 | return ret1; |
| 275 | |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 276 | smumgr = pp_handle->smu_mgr; |
| 277 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 278 | if (smumgr->smumgr_funcs->start_smu == NULL) |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 279 | return -EINVAL; |
| 280 | |
| 281 | ret = smumgr->smumgr_funcs->start_smu(smumgr); |
| 282 | if (ret) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 283 | pr_err("smc start failed\n"); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 284 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 285 | return ret; |
| 286 | } |
| 287 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 288 | if (ret1 == PP_DPM_DISABLED) |
Monk Liu | 8fdf269 | 2017-01-25 15:55:30 +0800 | [diff] [blame] | 289 | return 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 290 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 291 | eventmgr = pp_handle->eventmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 292 | |
| 293 | pem_handle_event(eventmgr, AMD_PP_EVENT_RESUME, &event_data); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 294 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | const struct amd_ip_funcs pp_ip_funcs = { |
Tom St Denis | 88a907d | 2016-05-04 14:28:35 -0400 | [diff] [blame] | 299 | .name = "powerplay", |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 300 | .early_init = pp_early_init, |
| 301 | .late_init = NULL, |
| 302 | .sw_init = pp_sw_init, |
| 303 | .sw_fini = pp_sw_fini, |
| 304 | .hw_init = pp_hw_init, |
| 305 | .hw_fini = pp_hw_fini, |
| 306 | .suspend = pp_suspend, |
| 307 | .resume = pp_resume, |
| 308 | .is_idle = pp_is_idle, |
| 309 | .wait_for_idle = pp_wait_for_idle, |
| 310 | .soft_reset = pp_sw_reset, |
Rex Zhu | 465f96e | 2016-09-18 16:52:03 +0800 | [diff] [blame] | 311 | .set_clockgating_state = NULL, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 312 | .set_powergating_state = pp_set_powergating_state, |
| 313 | }; |
| 314 | |
| 315 | static int pp_dpm_load_fw(void *handle) |
| 316 | { |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | static int pp_dpm_fw_loading_complete(void *handle) |
| 321 | { |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static int pp_dpm_force_performance_level(void *handle, |
| 326 | enum amd_dpm_forced_level level) |
| 327 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 328 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 329 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 330 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 331 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 332 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 333 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 334 | if (ret != 0) |
| 335 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 336 | |
| 337 | hwmgr = pp_handle->hwmgr; |
| 338 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 339 | if (hwmgr->hwmgr_func->force_dpm_level == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 340 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 341 | return 0; |
| 342 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 343 | |
| 344 | hwmgr->hwmgr_func->force_dpm_level(hwmgr, level); |
| 345 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 346 | return 0; |
| 347 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 348 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 349 | static enum amd_dpm_forced_level pp_dpm_get_performance_level( |
| 350 | void *handle) |
| 351 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 352 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 353 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 354 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 355 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 356 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 357 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 358 | if (ret != 0) |
| 359 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 360 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 361 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 362 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 363 | return hwmgr->dpm_level; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 364 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 365 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 366 | static int pp_dpm_get_sclk(void *handle, bool low) |
| 367 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 368 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 369 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 370 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 371 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 372 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 373 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 374 | if (ret != 0) |
| 375 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 376 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 377 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 378 | |
| 379 | if (hwmgr->hwmgr_func->get_sclk == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 380 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 381 | return 0; |
| 382 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 383 | |
| 384 | return hwmgr->hwmgr_func->get_sclk(hwmgr, low); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 385 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 386 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 387 | static int pp_dpm_get_mclk(void *handle, bool low) |
| 388 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 389 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 390 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 391 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 392 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 393 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 394 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 395 | if (ret != 0) |
| 396 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 397 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 398 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 399 | |
| 400 | if (hwmgr->hwmgr_func->get_mclk == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 401 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 402 | return 0; |
| 403 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 404 | |
| 405 | return hwmgr->hwmgr_func->get_mclk(hwmgr, low); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 406 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 407 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 408 | static int pp_dpm_powergate_vce(void *handle, bool gate) |
| 409 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 410 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 411 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 412 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 413 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 414 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 415 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 416 | if (ret != 0) |
| 417 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 418 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 419 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 420 | |
| 421 | if (hwmgr->hwmgr_func->powergate_vce == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 422 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 423 | return 0; |
| 424 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 425 | |
| 426 | return hwmgr->hwmgr_func->powergate_vce(hwmgr, gate); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 427 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 428 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 429 | static int pp_dpm_powergate_uvd(void *handle, bool gate) |
| 430 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 431 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 432 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 433 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 434 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 435 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 436 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 437 | if (ret != 0) |
| 438 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 439 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 440 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 441 | |
| 442 | if (hwmgr->hwmgr_func->powergate_uvd == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 443 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 444 | return 0; |
| 445 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 446 | |
| 447 | return hwmgr->hwmgr_func->powergate_uvd(hwmgr, gate); |
| 448 | } |
| 449 | |
| 450 | static enum PP_StateUILabel power_state_convert(enum amd_pm_state_type state) |
| 451 | { |
| 452 | switch (state) { |
| 453 | case POWER_STATE_TYPE_BATTERY: |
| 454 | return PP_StateUILabel_Battery; |
| 455 | case POWER_STATE_TYPE_BALANCED: |
| 456 | return PP_StateUILabel_Balanced; |
| 457 | case POWER_STATE_TYPE_PERFORMANCE: |
| 458 | return PP_StateUILabel_Performance; |
| 459 | default: |
| 460 | return PP_StateUILabel_None; |
| 461 | } |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 462 | } |
| 463 | |
Baoyou Xie | f8a4c11 | 2016-09-30 17:58:42 +0800 | [diff] [blame] | 464 | static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_event event_id, |
| 465 | void *input, void *output) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 466 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 467 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 468 | struct pem_event_data data = { {0} }; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 469 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 470 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 471 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 472 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 473 | if (ret != 0) |
| 474 | return ret; |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 475 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 476 | switch (event_id) { |
| 477 | case AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE: |
| 478 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 479 | break; |
| 480 | case AMD_PP_EVENT_ENABLE_USER_STATE: |
| 481 | { |
| 482 | enum amd_pm_state_type ps; |
| 483 | |
| 484 | if (input == NULL) |
| 485 | return -EINVAL; |
| 486 | ps = *(unsigned long *)input; |
| 487 | |
| 488 | data.requested_ui_label = power_state_convert(ps); |
| 489 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
Rex Zhu | dc26a2a | 2016-02-25 17:16:52 +0800 | [diff] [blame] | 490 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 491 | } |
Rex Zhu | dc26a2a | 2016-02-25 17:16:52 +0800 | [diff] [blame] | 492 | case AMD_PP_EVENT_COMPLETE_INIT: |
| 493 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 494 | break; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 495 | case AMD_PP_EVENT_READJUST_POWER_STATE: |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 496 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 497 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 498 | default: |
| 499 | break; |
| 500 | } |
| 501 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 502 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 503 | |
Baoyou Xie | f8a4c11 | 2016-09-30 17:58:42 +0800 | [diff] [blame] | 504 | static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 505 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 506 | struct pp_hwmgr *hwmgr; |
| 507 | struct pp_power_state *state; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 508 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 509 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 510 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 511 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 512 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 513 | if (ret != 0) |
| 514 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 515 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 516 | hwmgr = pp_handle->hwmgr; |
| 517 | |
| 518 | if (hwmgr->current_ps == NULL) |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 519 | return -EINVAL; |
| 520 | |
| 521 | state = hwmgr->current_ps; |
| 522 | |
| 523 | switch (state->classification.ui_label) { |
| 524 | case PP_StateUILabel_Battery: |
| 525 | return POWER_STATE_TYPE_BATTERY; |
| 526 | case PP_StateUILabel_Balanced: |
| 527 | return POWER_STATE_TYPE_BALANCED; |
| 528 | case PP_StateUILabel_Performance: |
| 529 | return POWER_STATE_TYPE_PERFORMANCE; |
| 530 | default: |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 531 | if (state->classification.flags & PP_StateClassificationFlag_Boot) |
| 532 | return POWER_STATE_TYPE_INTERNAL_BOOT; |
| 533 | else |
| 534 | return POWER_STATE_TYPE_DEFAULT; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 535 | } |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 536 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 537 | |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 538 | static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode) |
| 539 | { |
| 540 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 541 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 542 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 543 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 544 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 545 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 546 | if (ret != 0) |
| 547 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 548 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 549 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 550 | |
| 551 | if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 552 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 553 | return 0; |
| 554 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 555 | |
| 556 | return hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode); |
| 557 | } |
| 558 | |
| 559 | static int pp_dpm_get_fan_control_mode(void *handle) |
| 560 | { |
| 561 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 562 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 563 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 564 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 565 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 566 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 567 | if (ret != 0) |
| 568 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 569 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 570 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 571 | |
| 572 | if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 573 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 574 | return 0; |
| 575 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 576 | |
| 577 | return hwmgr->hwmgr_func->get_fan_control_mode(hwmgr); |
| 578 | } |
| 579 | |
| 580 | static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent) |
| 581 | { |
| 582 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 583 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 584 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 585 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 586 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 587 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 588 | if (ret != 0) |
| 589 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 590 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 591 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 592 | |
| 593 | if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 594 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 595 | return 0; |
| 596 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 597 | |
| 598 | return hwmgr->hwmgr_func->set_fan_speed_percent(hwmgr, percent); |
| 599 | } |
| 600 | |
| 601 | static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed) |
| 602 | { |
| 603 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 604 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 605 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 606 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 607 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 608 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 609 | if (ret != 0) |
| 610 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 611 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 612 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 613 | |
| 614 | if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 615 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 616 | return 0; |
| 617 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 618 | |
| 619 | return hwmgr->hwmgr_func->get_fan_speed_percent(hwmgr, speed); |
| 620 | } |
| 621 | |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 622 | static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm) |
| 623 | { |
| 624 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 625 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 626 | int ret = 0; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 627 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 628 | ret = pp_check(pp_handle); |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 629 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 630 | if (ret != 0) |
| 631 | return ret; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 632 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 633 | hwmgr = pp_handle->hwmgr; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 634 | |
| 635 | if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL) |
| 636 | return -EINVAL; |
| 637 | |
| 638 | return hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm); |
| 639 | } |
| 640 | |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 641 | static int pp_dpm_get_temperature(void *handle) |
| 642 | { |
| 643 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 644 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 645 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 646 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 647 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 648 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 649 | if (ret != 0) |
| 650 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 651 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 652 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 653 | |
| 654 | if (hwmgr->hwmgr_func->get_temperature == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 655 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 656 | return 0; |
| 657 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 658 | |
| 659 | return hwmgr->hwmgr_func->get_temperature(hwmgr); |
| 660 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 661 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 662 | static int pp_dpm_get_pp_num_states(void *handle, |
| 663 | struct pp_states_info *data) |
| 664 | { |
| 665 | struct pp_hwmgr *hwmgr; |
| 666 | int i; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 667 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 668 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 669 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 670 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 671 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 672 | if (ret != 0) |
| 673 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 674 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 675 | hwmgr = pp_handle->hwmgr; |
| 676 | |
| 677 | if (hwmgr->ps == NULL) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 678 | return -EINVAL; |
| 679 | |
| 680 | data->nums = hwmgr->num_ps; |
| 681 | |
| 682 | for (i = 0; i < hwmgr->num_ps; i++) { |
| 683 | struct pp_power_state *state = (struct pp_power_state *) |
| 684 | ((unsigned long)hwmgr->ps + i * hwmgr->ps_size); |
| 685 | switch (state->classification.ui_label) { |
| 686 | case PP_StateUILabel_Battery: |
| 687 | data->states[i] = POWER_STATE_TYPE_BATTERY; |
| 688 | break; |
| 689 | case PP_StateUILabel_Balanced: |
| 690 | data->states[i] = POWER_STATE_TYPE_BALANCED; |
| 691 | break; |
| 692 | case PP_StateUILabel_Performance: |
| 693 | data->states[i] = POWER_STATE_TYPE_PERFORMANCE; |
| 694 | break; |
| 695 | default: |
| 696 | if (state->classification.flags & PP_StateClassificationFlag_Boot) |
| 697 | data->states[i] = POWER_STATE_TYPE_INTERNAL_BOOT; |
| 698 | else |
| 699 | data->states[i] = POWER_STATE_TYPE_DEFAULT; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int pp_dpm_get_pp_table(void *handle, char **table) |
| 707 | { |
| 708 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 709 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 710 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 711 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 712 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 713 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 714 | if (ret != 0) |
| 715 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 716 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 717 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 718 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 719 | if (!hwmgr->soft_pp_table) |
| 720 | return -EINVAL; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 721 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 722 | *table = (char *)hwmgr->soft_pp_table; |
| 723 | |
| 724 | return hwmgr->soft_pp_table_size; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size) |
| 728 | { |
| 729 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 730 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 731 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 732 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 733 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 734 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 735 | if (ret != 0) |
| 736 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 737 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 738 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 739 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 740 | if (!hwmgr->hardcode_pp_table) { |
Edward O'Callaghan | efdf7a93 | 2016-09-04 12:36:19 +1000 | [diff] [blame] | 741 | hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table, |
| 742 | hwmgr->soft_pp_table_size, |
| 743 | GFP_KERNEL); |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 744 | |
| 745 | if (!hwmgr->hardcode_pp_table) |
| 746 | return -ENOMEM; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 747 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 748 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 749 | memcpy(hwmgr->hardcode_pp_table, buf, size); |
| 750 | |
| 751 | hwmgr->soft_pp_table = hwmgr->hardcode_pp_table; |
| 752 | |
| 753 | return amd_powerplay_reset(handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | static int pp_dpm_force_clock_level(void *handle, |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 757 | enum pp_clock_type type, uint32_t mask) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 758 | { |
| 759 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 760 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 761 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 762 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 763 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 764 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 765 | if (ret != 0) |
| 766 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 767 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 768 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 769 | |
| 770 | if (hwmgr->hwmgr_func->force_clock_level == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 771 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 772 | return 0; |
| 773 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 774 | |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 775 | return hwmgr->hwmgr_func->force_clock_level(hwmgr, type, mask); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | static int pp_dpm_print_clock_levels(void *handle, |
| 779 | enum pp_clock_type type, char *buf) |
| 780 | { |
| 781 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 782 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 783 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 784 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 785 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 786 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 787 | if (ret != 0) |
| 788 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 789 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 790 | hwmgr = pp_handle->hwmgr; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 791 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 792 | if (hwmgr->hwmgr_func->print_clock_levels == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 793 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 794 | return 0; |
| 795 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 796 | return hwmgr->hwmgr_func->print_clock_levels(hwmgr, type, buf); |
| 797 | } |
| 798 | |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 799 | static int pp_dpm_get_sclk_od(void *handle) |
| 800 | { |
| 801 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 802 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 803 | int ret = 0; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 804 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 805 | ret = pp_check(pp_handle); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 806 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 807 | if (ret != 0) |
| 808 | return ret; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 809 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 810 | hwmgr = pp_handle->hwmgr; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 811 | |
| 812 | if (hwmgr->hwmgr_func->get_sclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 813 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | return hwmgr->hwmgr_func->get_sclk_od(hwmgr); |
| 818 | } |
| 819 | |
| 820 | static int pp_dpm_set_sclk_od(void *handle, uint32_t value) |
| 821 | { |
| 822 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 823 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 824 | int ret = 0; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 825 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 826 | ret = pp_check(pp_handle); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 827 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 828 | if (ret != 0) |
| 829 | return ret; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 830 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 831 | hwmgr = pp_handle->hwmgr; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 832 | |
| 833 | if (hwmgr->hwmgr_func->set_sclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 834 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | return hwmgr->hwmgr_func->set_sclk_od(hwmgr, value); |
| 839 | } |
| 840 | |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 841 | static int pp_dpm_get_mclk_od(void *handle) |
| 842 | { |
| 843 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 844 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 845 | int ret = 0; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 846 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 847 | ret = pp_check(pp_handle); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 848 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 849 | if (ret != 0) |
| 850 | return ret; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 851 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 852 | hwmgr = pp_handle->hwmgr; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 853 | |
| 854 | if (hwmgr->hwmgr_func->get_mclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 855 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | return hwmgr->hwmgr_func->get_mclk_od(hwmgr); |
| 860 | } |
| 861 | |
| 862 | static int pp_dpm_set_mclk_od(void *handle, uint32_t value) |
| 863 | { |
| 864 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 865 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 866 | int ret = 0; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 867 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 868 | ret = pp_check(pp_handle); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 869 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 870 | if (ret != 0) |
| 871 | return ret; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 872 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 873 | hwmgr = pp_handle->hwmgr; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 874 | |
| 875 | if (hwmgr->hwmgr_func->set_mclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 876 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | return hwmgr->hwmgr_func->set_mclk_od(hwmgr, value); |
| 881 | } |
| 882 | |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame^] | 883 | static int pp_dpm_read_sensor(void *handle, int idx, |
| 884 | void *value, int *size) |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 885 | { |
| 886 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 887 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 888 | int ret = 0; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 889 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 890 | ret = pp_check(pp_handle); |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 891 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 892 | if (ret != 0) |
| 893 | return ret; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 894 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 895 | hwmgr = pp_handle->hwmgr; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 896 | |
| 897 | if (hwmgr->hwmgr_func->read_sensor == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 898 | pr_info("%s was not implemented.\n", __func__); |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame^] | 902 | return hwmgr->hwmgr_func->read_sensor(hwmgr, idx, value, size); |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 905 | static struct amd_vce_state* |
| 906 | pp_dpm_get_vce_clock_state(void *handle, unsigned idx) |
| 907 | { |
| 908 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 909 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 910 | int ret = 0; |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 911 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 912 | ret = pp_check(pp_handle); |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 913 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 914 | if (ret != 0) |
| 915 | return NULL; |
| 916 | |
| 917 | hwmgr = pp_handle->hwmgr; |
| 918 | |
| 919 | if (hwmgr && idx < hwmgr->num_vce_state_tables) |
| 920 | return &hwmgr->vce_states[idx]; |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 921 | return NULL; |
| 922 | } |
| 923 | |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 924 | static int pp_dpm_reset_power_profile_state(void *handle, |
| 925 | struct amd_pp_profile *request) |
| 926 | { |
| 927 | struct pp_hwmgr *hwmgr; |
| 928 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 929 | |
| 930 | if (!request || pp_check(pp_handle)) |
| 931 | return -EINVAL; |
| 932 | |
| 933 | hwmgr = pp_handle->hwmgr; |
| 934 | |
| 935 | if (hwmgr->hwmgr_func->set_power_profile_state == NULL) { |
| 936 | pr_info("%s was not implemented.\n", __func__); |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | if (request->type == AMD_PP_GFX_PROFILE) { |
| 941 | hwmgr->gfx_power_profile = hwmgr->default_gfx_power_profile; |
| 942 | return hwmgr->hwmgr_func->set_power_profile_state(hwmgr, |
| 943 | &hwmgr->gfx_power_profile); |
| 944 | } else if (request->type == AMD_PP_COMPUTE_PROFILE) { |
| 945 | hwmgr->compute_power_profile = |
| 946 | hwmgr->default_compute_power_profile; |
| 947 | return hwmgr->hwmgr_func->set_power_profile_state(hwmgr, |
| 948 | &hwmgr->compute_power_profile); |
| 949 | } else |
| 950 | return -EINVAL; |
| 951 | } |
| 952 | |
| 953 | static int pp_dpm_get_power_profile_state(void *handle, |
| 954 | struct amd_pp_profile *query) |
| 955 | { |
| 956 | struct pp_hwmgr *hwmgr; |
| 957 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 958 | |
| 959 | if (!query || pp_check(pp_handle)) |
| 960 | return -EINVAL; |
| 961 | |
| 962 | hwmgr = pp_handle->hwmgr; |
| 963 | |
| 964 | if (query->type == AMD_PP_GFX_PROFILE) |
| 965 | memcpy(query, &hwmgr->gfx_power_profile, |
| 966 | sizeof(struct amd_pp_profile)); |
| 967 | else if (query->type == AMD_PP_COMPUTE_PROFILE) |
| 968 | memcpy(query, &hwmgr->compute_power_profile, |
| 969 | sizeof(struct amd_pp_profile)); |
| 970 | else |
| 971 | return -EINVAL; |
| 972 | |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static int pp_dpm_set_power_profile_state(void *handle, |
| 977 | struct amd_pp_profile *request) |
| 978 | { |
| 979 | struct pp_hwmgr *hwmgr; |
| 980 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 981 | int ret = -1; |
| 982 | |
| 983 | if (!request || pp_check(pp_handle)) |
| 984 | return -EINVAL; |
| 985 | |
| 986 | hwmgr = pp_handle->hwmgr; |
| 987 | |
| 988 | if (hwmgr->hwmgr_func->set_power_profile_state == NULL) { |
| 989 | pr_info("%s was not implemented.\n", __func__); |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | if (request->min_sclk || |
| 994 | request->min_mclk || |
| 995 | request->activity_threshold || |
| 996 | request->up_hyst || |
| 997 | request->down_hyst) { |
| 998 | if (request->type == AMD_PP_GFX_PROFILE) |
| 999 | memcpy(&hwmgr->gfx_power_profile, request, |
| 1000 | sizeof(struct amd_pp_profile)); |
| 1001 | else if (request->type == AMD_PP_COMPUTE_PROFILE) |
| 1002 | memcpy(&hwmgr->compute_power_profile, request, |
| 1003 | sizeof(struct amd_pp_profile)); |
| 1004 | else |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | if (request->type == hwmgr->current_power_profile) |
| 1008 | ret = hwmgr->hwmgr_func->set_power_profile_state( |
| 1009 | hwmgr, |
| 1010 | request); |
| 1011 | } else { |
| 1012 | /* set power profile if it exists */ |
| 1013 | switch (request->type) { |
| 1014 | case AMD_PP_GFX_PROFILE: |
| 1015 | ret = hwmgr->hwmgr_func->set_power_profile_state( |
| 1016 | hwmgr, |
| 1017 | &hwmgr->gfx_power_profile); |
| 1018 | break; |
| 1019 | case AMD_PP_COMPUTE_PROFILE: |
| 1020 | ret = hwmgr->hwmgr_func->set_power_profile_state( |
| 1021 | hwmgr, |
| 1022 | &hwmgr->compute_power_profile); |
| 1023 | break; |
| 1024 | default: |
| 1025 | return -EINVAL; |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | if (!ret) |
| 1030 | hwmgr->current_power_profile = request->type; |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int pp_dpm_switch_power_profile(void *handle, |
| 1036 | enum amd_pp_profile_type type) |
| 1037 | { |
| 1038 | struct pp_hwmgr *hwmgr; |
| 1039 | struct amd_pp_profile request = {0}; |
| 1040 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1041 | |
| 1042 | if (pp_check(pp_handle)) |
| 1043 | return -EINVAL; |
| 1044 | |
| 1045 | hwmgr = pp_handle->hwmgr; |
| 1046 | |
| 1047 | if (hwmgr->current_power_profile != type) { |
| 1048 | request.type = type; |
| 1049 | pp_dpm_set_power_profile_state(handle, &request); |
| 1050 | } |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1055 | const struct amd_powerplay_funcs pp_dpm_funcs = { |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 1056 | .get_temperature = pp_dpm_get_temperature, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1057 | .load_firmware = pp_dpm_load_fw, |
| 1058 | .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete, |
| 1059 | .force_performance_level = pp_dpm_force_performance_level, |
| 1060 | .get_performance_level = pp_dpm_get_performance_level, |
| 1061 | .get_current_power_state = pp_dpm_get_current_power_state, |
| 1062 | .get_sclk = pp_dpm_get_sclk, |
| 1063 | .get_mclk = pp_dpm_get_mclk, |
| 1064 | .powergate_vce = pp_dpm_powergate_vce, |
| 1065 | .powergate_uvd = pp_dpm_powergate_uvd, |
| 1066 | .dispatch_tasks = pp_dpm_dispatch_tasks, |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 1067 | .set_fan_control_mode = pp_dpm_set_fan_control_mode, |
| 1068 | .get_fan_control_mode = pp_dpm_get_fan_control_mode, |
| 1069 | .set_fan_speed_percent = pp_dpm_set_fan_speed_percent, |
| 1070 | .get_fan_speed_percent = pp_dpm_get_fan_speed_percent, |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 1071 | .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm, |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1072 | .get_pp_num_states = pp_dpm_get_pp_num_states, |
| 1073 | .get_pp_table = pp_dpm_get_pp_table, |
| 1074 | .set_pp_table = pp_dpm_set_pp_table, |
| 1075 | .force_clock_level = pp_dpm_force_clock_level, |
| 1076 | .print_clock_levels = pp_dpm_print_clock_levels, |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 1077 | .get_sclk_od = pp_dpm_get_sclk_od, |
| 1078 | .set_sclk_od = pp_dpm_set_sclk_od, |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 1079 | .get_mclk_od = pp_dpm_get_mclk_od, |
| 1080 | .set_mclk_od = pp_dpm_set_mclk_od, |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 1081 | .read_sensor = pp_dpm_read_sensor, |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 1082 | .get_vce_clock_state = pp_dpm_get_vce_clock_state, |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 1083 | .reset_power_profile_state = pp_dpm_reset_power_profile_state, |
| 1084 | .get_power_profile_state = pp_dpm_get_power_profile_state, |
| 1085 | .set_power_profile_state = pp_dpm_set_power_profile_state, |
| 1086 | .switch_power_profile = pp_dpm_switch_power_profile, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1087 | }; |
| 1088 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1089 | int amd_powerplay_create(struct amd_pp_init *pp_init, |
| 1090 | void **handle) |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1091 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1092 | struct pp_instance *instance; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1093 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1094 | if (pp_init == NULL || handle == NULL) |
| 1095 | return -EINVAL; |
| 1096 | |
| 1097 | instance = kzalloc(sizeof(struct pp_instance), GFP_KERNEL); |
| 1098 | if (instance == NULL) |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1099 | return -ENOMEM; |
| 1100 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1101 | instance->pp_valid = PP_VALID; |
| 1102 | instance->chip_family = pp_init->chip_family; |
| 1103 | instance->chip_id = pp_init->chip_id; |
| 1104 | instance->pm_en = pp_init->pm_en; |
| 1105 | instance->feature_mask = pp_init->feature_mask; |
| 1106 | instance->device = pp_init->device; |
| 1107 | *handle = instance; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 1108 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1109 | return 0; |
| 1110 | } |
| 1111 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1112 | int amd_powerplay_destroy(void *handle) |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1113 | { |
| 1114 | struct pp_instance *instance = (struct pp_instance *)handle; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 1115 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1116 | if (instance->pm_en) { |
| 1117 | kfree(instance->eventmgr); |
| 1118 | kfree(instance->hwmgr); |
| 1119 | instance->hwmgr = NULL; |
| 1120 | instance->eventmgr = NULL; |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 1121 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 1122 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1123 | kfree(instance->smu_mgr); |
| 1124 | instance->smu_mgr = NULL; |
| 1125 | kfree(instance); |
| 1126 | instance = NULL; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1127 | return 0; |
| 1128 | } |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1129 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1130 | int amd_powerplay_reset(void *handle) |
| 1131 | { |
| 1132 | struct pp_instance *instance = (struct pp_instance *)handle; |
| 1133 | struct pp_eventmgr *eventmgr; |
| 1134 | struct pem_event_data event_data = { {0} }; |
| 1135 | int ret; |
| 1136 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1137 | if (cgs_is_virtualization_enabled(instance->smu_mgr->device)) |
| 1138 | return PP_DPM_DISABLED; |
| 1139 | |
| 1140 | ret = pp_check(instance); |
| 1141 | if (ret != 0) |
| 1142 | return ret; |
| 1143 | |
| 1144 | ret = pp_hw_fini(handle); |
| 1145 | if (ret) |
| 1146 | return ret; |
| 1147 | |
| 1148 | ret = hwmgr_hw_init(instance); |
| 1149 | if (ret) |
| 1150 | return PP_DPM_DISABLED; |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1151 | |
| 1152 | eventmgr = instance->eventmgr; |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1153 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1154 | if (eventmgr->pp_eventmgr_init == NULL) |
| 1155 | return PP_DPM_DISABLED; |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1156 | |
| 1157 | ret = eventmgr->pp_eventmgr_init(eventmgr); |
| 1158 | if (ret) |
| 1159 | return ret; |
| 1160 | |
| 1161 | return pem_handle_event(eventmgr, AMD_PP_EVENT_COMPLETE_INIT, &event_data); |
| 1162 | } |
| 1163 | |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1164 | /* export this function to DAL */ |
| 1165 | |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1166 | int amd_powerplay_display_configuration_change(void *handle, |
| 1167 | const struct amd_pp_display_configuration *display_config) |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1168 | { |
| 1169 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1170 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1171 | int ret = 0; |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1172 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1173 | ret = pp_check(pp_handle); |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1174 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1175 | if (ret != 0) |
| 1176 | return ret; |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1177 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1178 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 1179 | |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1180 | phm_store_dal_configuration_data(hwmgr, display_config); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 1181 | |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1184 | |
Vitaly Prosyak | 1c9a908 | 2015-12-03 10:27:57 -0500 | [diff] [blame] | 1185 | int amd_powerplay_get_display_power_level(void *handle, |
Rex Zhu | 4732913 | 2015-12-10 16:49:50 +0800 | [diff] [blame] | 1186 | struct amd_pp_simple_clock_info *output) |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1187 | { |
| 1188 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1189 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1190 | int ret = 0; |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1191 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1192 | ret = pp_check(pp_handle); |
| 1193 | |
| 1194 | if (ret != 0) |
| 1195 | return ret; |
| 1196 | |
| 1197 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1198 | |
| 1199 | if (output == NULL) |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1200 | return -EINVAL; |
| 1201 | |
Vitaly Prosyak | 1c9a908 | 2015-12-03 10:27:57 -0500 | [diff] [blame] | 1202 | return phm_get_dal_power_level(hwmgr, output); |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1203 | } |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1204 | |
| 1205 | int amd_powerplay_get_current_clocks(void *handle, |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1206 | struct amd_pp_clock_info *clocks) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1207 | { |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1208 | struct amd_pp_simple_clock_info simple_clocks; |
| 1209 | struct pp_clock_info hw_clocks; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1210 | struct pp_hwmgr *hwmgr; |
| 1211 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1212 | int ret = 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1213 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1214 | ret = pp_check(pp_handle); |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1215 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1216 | if (ret != 0) |
| 1217 | return ret; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1218 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1219 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 1220 | |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1221 | phm_get_dal_power_level(hwmgr, &simple_clocks); |
| 1222 | |
| 1223 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PowerContainment)) { |
| 1224 | if (0 != phm_get_clock_info(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks, PHM_PerformanceLevelDesignation_PowerContainment)) |
| 1225 | PP_ASSERT_WITH_CODE(0, "Error in PHM_GetPowerContainmentClockInfo", return -1); |
| 1226 | } else { |
| 1227 | if (0 != phm_get_clock_info(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks, PHM_PerformanceLevelDesignation_Activity)) |
| 1228 | PP_ASSERT_WITH_CODE(0, "Error in PHM_GetClockInfo", return -1); |
| 1229 | } |
| 1230 | |
| 1231 | clocks->min_engine_clock = hw_clocks.min_eng_clk; |
| 1232 | clocks->max_engine_clock = hw_clocks.max_eng_clk; |
| 1233 | clocks->min_memory_clock = hw_clocks.min_mem_clk; |
| 1234 | clocks->max_memory_clock = hw_clocks.max_mem_clk; |
| 1235 | clocks->min_bus_bandwidth = hw_clocks.min_bus_bandwidth; |
| 1236 | clocks->max_bus_bandwidth = hw_clocks.max_bus_bandwidth; |
| 1237 | |
| 1238 | clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk; |
| 1239 | clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk; |
| 1240 | |
| 1241 | clocks->max_clocks_state = simple_clocks.level; |
| 1242 | |
| 1243 | if (0 == phm_get_current_shallow_sleep_clocks(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks)) { |
| 1244 | clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk; |
| 1245 | clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk; |
| 1246 | } |
| 1247 | |
| 1248 | return 0; |
| 1249 | |
| 1250 | } |
| 1251 | |
| 1252 | int amd_powerplay_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struct amd_pp_clocks *clocks) |
| 1253 | { |
| 1254 | int result = -1; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1255 | struct pp_hwmgr *hwmgr; |
| 1256 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1257 | int ret = 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1258 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1259 | ret = pp_check(pp_handle); |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1260 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1261 | if (ret != 0) |
| 1262 | return ret; |
| 1263 | |
| 1264 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1265 | |
| 1266 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1267 | return -EINVAL; |
| 1268 | |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1269 | result = phm_get_clock_by_type(hwmgr, type, clocks); |
| 1270 | |
| 1271 | return result; |
| 1272 | } |
| 1273 | |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1274 | int amd_powerplay_get_display_mode_validation_clocks(void *handle, |
| 1275 | struct amd_pp_simple_clock_info *clocks) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1276 | { |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1277 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1278 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1279 | int ret = 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1280 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1281 | ret = pp_check(pp_handle); |
| 1282 | |
| 1283 | if (ret != 0) |
| 1284 | return ret; |
| 1285 | |
| 1286 | hwmgr = pp_handle->hwmgr; |
| 1287 | |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1288 | |
| 1289 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1290 | return -EINVAL; |
| 1291 | |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1292 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DynamicPatchPowerState)) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1293 | ret = phm_get_max_high_clocks(hwmgr, clocks); |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1294 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1295 | return ret; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1296 | } |
| 1297 | |