2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/gfp.h>
26 #include <linux/slab.h>
27 #include "amd_shared.h"
28 #include "amd_powerplay.h"
29 #include "pp_instance.h"
31 static int pp_early_init(void *handle)
36 static int pp_sw_init(void *handle)
41 static int pp_sw_fini(void *handle)
46 static int pp_hw_init(void *handle)
48 struct pp_instance *pp_handle;
49 struct pp_smumgr *smumgr;
55 pp_handle = (struct pp_instance *)handle;
56 smumgr = pp_handle->smu_mgr;
58 if (smumgr == NULL || smumgr->smumgr_funcs == NULL ||
59 smumgr->smumgr_funcs->smu_init == NULL ||
60 smumgr->smumgr_funcs->start_smu == NULL)
63 ret = smumgr->smumgr_funcs->smu_init(smumgr);
65 printk(KERN_ERR "[ powerplay ] smc initialization failed\n");
69 ret = smumgr->smumgr_funcs->start_smu(smumgr);
71 printk(KERN_ERR "[ powerplay ] smc start failed\n");
72 smumgr->smumgr_funcs->smu_fini(smumgr);
78 static int pp_hw_fini(void *handle)
80 struct pp_instance *pp_handle;
81 struct pp_smumgr *smumgr;
86 pp_handle = (struct pp_instance *)handle;
87 smumgr = pp_handle->smu_mgr;
89 if (smumgr != NULL || smumgr->smumgr_funcs != NULL ||
90 smumgr->smumgr_funcs->smu_fini != NULL)
91 smumgr->smumgr_funcs->smu_fini(smumgr);
96 static bool pp_is_idle(void *handle)
101 static int pp_wait_for_idle(void *handle)
106 static int pp_sw_reset(void *handle)
111 static void pp_print_status(void *handle)
116 static int pp_set_clockgating_state(void *handle,
117 enum amd_clockgating_state state)
122 static int pp_set_powergating_state(void *handle,
123 enum amd_powergating_state state)
128 static int pp_suspend(void *handle)
133 static int pp_resume(void *handle)
138 const struct amd_ip_funcs pp_ip_funcs = {
139 .early_init = pp_early_init,
141 .sw_init = pp_sw_init,
142 .sw_fini = pp_sw_fini,
143 .hw_init = pp_hw_init,
144 .hw_fini = pp_hw_fini,
145 .suspend = pp_suspend,
147 .is_idle = pp_is_idle,
148 .wait_for_idle = pp_wait_for_idle,
149 .soft_reset = pp_sw_reset,
150 .print_status = pp_print_status,
151 .set_clockgating_state = pp_set_clockgating_state,
152 .set_powergating_state = pp_set_powergating_state,
155 static int pp_dpm_load_fw(void *handle)
160 static int pp_dpm_fw_loading_complete(void *handle)
165 static int pp_dpm_force_performance_level(void *handle,
166 enum amd_dpm_forced_level level)
170 static enum amd_dpm_forced_level pp_dpm_get_performance_level(
175 static int pp_dpm_get_sclk(void *handle, bool low)
179 static int pp_dpm_get_mclk(void *handle, bool low)
183 static int pp_dpm_powergate_vce(void *handle, bool gate)
187 static int pp_dpm_powergate_uvd(void *handle, bool gate)
192 int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_event event_id, void *input, void *output)
196 enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
201 pp_debugfs_print_current_performance_level(void *handle,
206 const struct amd_powerplay_funcs pp_dpm_funcs = {
207 .get_temperature = NULL,
208 .load_firmware = pp_dpm_load_fw,
209 .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,
210 .force_performance_level = pp_dpm_force_performance_level,
211 .get_performance_level = pp_dpm_get_performance_level,
212 .get_current_power_state = pp_dpm_get_current_power_state,
213 .get_sclk = pp_dpm_get_sclk,
214 .get_mclk = pp_dpm_get_mclk,
215 .powergate_vce = pp_dpm_powergate_vce,
216 .powergate_uvd = pp_dpm_powergate_uvd,
217 .dispatch_tasks = pp_dpm_dispatch_tasks,
218 .print_current_performance_level = pp_debugfs_print_current_performance_level,
221 static int amd_pp_instance_init(struct amd_pp_init *pp_init,
222 struct amd_powerplay *amd_pp)
225 struct pp_instance *handle;
227 handle = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
231 ret = smum_init(pp_init, handle);
235 amd_pp->pp_handle = handle;
239 static int amd_pp_instance_fini(void *handle)
241 struct pp_instance *instance = (struct pp_instance *)handle;
242 if (instance == NULL)
245 smum_fini(instance->smu_mgr);
251 int amd_powerplay_init(struct amd_pp_init *pp_init,
252 struct amd_powerplay *amd_pp)
256 if (pp_init == NULL || amd_pp == NULL)
259 ret = amd_pp_instance_init(pp_init, amd_pp);
264 amd_pp->ip_funcs = &pp_ip_funcs;
265 amd_pp->pp_funcs = &pp_dpm_funcs;
270 int amd_powerplay_fini(void *handle)
272 amd_pp_instance_fini(handle);