2 * Copyright 2014 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.
24 #include <linux/firmware.h>
27 #include "tonga_smum.h"
29 MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
31 static void tonga_dpm_set_funcs(struct amdgpu_device
*adev
);
33 static int tonga_dpm_early_init(void *handle
)
35 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
37 tonga_dpm_set_funcs(adev
);
42 static int tonga_dpm_init_microcode(struct amdgpu_device
*adev
)
44 char fw_name
[30] = "amdgpu/tonga_smc.bin";
46 err
= request_firmware(&adev
->pm
.fw
, fw_name
, adev
->dev
);
49 err
= amdgpu_ucode_validate(adev
->pm
.fw
);
53 DRM_ERROR("Failed to load firmware \"%s\"", fw_name
);
54 release_firmware(adev
->pm
.fw
);
60 static int tonga_dpm_sw_init(void *handle
)
63 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
65 ret
= tonga_dpm_init_microcode(adev
);
72 static int tonga_dpm_sw_fini(void *handle
)
77 static int tonga_dpm_hw_init(void *handle
)
80 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
82 mutex_lock(&adev
->pm
.mutex
);
84 /* smu init only needs to be called at startup, not resume.
85 * It should be in sw_init, but requires the fw info gathered
86 * in sw_init from other IP modules.
88 ret
= tonga_smu_init(adev
);
90 DRM_ERROR("SMU initialization failed\n");
94 ret
= tonga_smu_start(adev
);
96 DRM_ERROR("SMU start failed\n");
100 mutex_unlock(&adev
->pm
.mutex
);
104 adev
->firmware
.smu_load
= false;
105 mutex_unlock(&adev
->pm
.mutex
);
109 static int tonga_dpm_hw_fini(void *handle
)
111 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
113 mutex_lock(&adev
->pm
.mutex
);
114 /* smu fini only needs to be called at teardown, not suspend.
115 * It should be in sw_fini, but we put it here for symmetry
118 tonga_smu_fini(adev
);
119 mutex_unlock(&adev
->pm
.mutex
);
123 static int tonga_dpm_suspend(void *handle
)
125 return tonga_dpm_hw_fini(handle
);
128 static int tonga_dpm_resume(void *handle
)
130 return tonga_dpm_hw_init(handle
);
133 static int tonga_dpm_set_clockgating_state(void *handle
,
134 enum amd_clockgating_state state
)
139 static int tonga_dpm_set_powergating_state(void *handle
,
140 enum amd_powergating_state state
)
145 const struct amd_ip_funcs tonga_dpm_ip_funcs
= {
147 .early_init
= tonga_dpm_early_init
,
149 .sw_init
= tonga_dpm_sw_init
,
150 .sw_fini
= tonga_dpm_sw_fini
,
151 .hw_init
= tonga_dpm_hw_init
,
152 .hw_fini
= tonga_dpm_hw_fini
,
153 .suspend
= tonga_dpm_suspend
,
154 .resume
= tonga_dpm_resume
,
156 .wait_for_idle
= NULL
,
158 .set_clockgating_state
= tonga_dpm_set_clockgating_state
,
159 .set_powergating_state
= tonga_dpm_set_powergating_state
,
162 static const struct amdgpu_dpm_funcs tonga_dpm_funcs
= {
163 .get_temperature
= NULL
,
164 .pre_set_power_state
= NULL
,
165 .set_power_state
= NULL
,
166 .post_set_power_state
= NULL
,
167 .display_configuration_changed
= NULL
,
170 .print_power_state
= NULL
,
171 .debugfs_print_current_performance_level
= NULL
,
172 .force_performance_level
= NULL
,
173 .vblank_too_short
= NULL
,
174 .powergate_uvd
= NULL
,
177 static void tonga_dpm_set_funcs(struct amdgpu_device
*adev
)
179 if (NULL
== adev
->pm
.funcs
)
180 adev
->pm
.funcs
= &tonga_dpm_funcs
;