blob: 4b773f29167ae2f88f90053cd867c48eebbc8742 [file] [log] [blame]
Alex Deucheraaa36a92015-04-20 17:31:14 -04001/*
2 * Copyright 2014 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 */
23
24#include <linux/firmware.h>
25#include "drmP.h"
26#include "amdgpu.h"
27#include "iceland_smumgr.h"
28
Jammy Zhouc65444f2015-05-13 22:49:04 +080029MODULE_FIRMWARE("amdgpu/topaz_smc.bin");
Alex Deucheraaa36a92015-04-20 17:31:14 -040030
31static void iceland_dpm_set_funcs(struct amdgpu_device *adev);
32
yanyang15fc3aee2015-05-22 14:39:35 -040033static int iceland_dpm_early_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040034{
yanyang15fc3aee2015-05-22 14:39:35 -040035 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
36
Alex Deucheraaa36a92015-04-20 17:31:14 -040037 iceland_dpm_set_funcs(adev);
38
39 return 0;
40}
41
42static int iceland_dpm_init_microcode(struct amdgpu_device *adev)
43{
Jammy Zhouc65444f2015-05-13 22:49:04 +080044 char fw_name[30] = "amdgpu/topaz_smc.bin";
Alex Deucheraaa36a92015-04-20 17:31:14 -040045 int err;
46
47 err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
48 if (err)
49 goto out;
50 err = amdgpu_ucode_validate(adev->pm.fw);
51
52out:
53 if (err) {
54 DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
55 release_firmware(adev->pm.fw);
56 adev->pm.fw = NULL;
57 }
58 return err;
59}
60
yanyang15fc3aee2015-05-22 14:39:35 -040061static int iceland_dpm_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040062{
63 int ret;
yanyang15fc3aee2015-05-22 14:39:35 -040064 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -040065
66 ret = iceland_dpm_init_microcode(adev);
67 if (ret)
68 return ret;
69
70 return 0;
71}
72
yanyang15fc3aee2015-05-22 14:39:35 -040073static int iceland_dpm_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040074{
75 return 0;
76}
77
yanyang15fc3aee2015-05-22 14:39:35 -040078static int iceland_dpm_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040079{
80 int ret;
yanyang15fc3aee2015-05-22 14:39:35 -040081 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -040082
83 mutex_lock(&adev->pm.mutex);
84
85 ret = iceland_smu_init(adev);
86 if (ret) {
87 DRM_ERROR("SMU initialization failed\n");
88 goto fail;
89 }
90
91 ret = iceland_smu_start(adev);
92 if (ret) {
93 DRM_ERROR("SMU start failed\n");
94 goto fail;
95 }
96
97 mutex_unlock(&adev->pm.mutex);
98 return 0;
99
100fail:
101 adev->firmware.smu_load = false;
102 mutex_unlock(&adev->pm.mutex);
103 return -EINVAL;
104}
105
yanyang15fc3aee2015-05-22 14:39:35 -0400106static int iceland_dpm_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400107{
yanyang15fc3aee2015-05-22 14:39:35 -0400108 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
109
Alex Deucheraaa36a92015-04-20 17:31:14 -0400110 mutex_lock(&adev->pm.mutex);
111 iceland_smu_fini(adev);
112 mutex_unlock(&adev->pm.mutex);
113 return 0;
114}
115
yanyang15fc3aee2015-05-22 14:39:35 -0400116static int iceland_dpm_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400117{
yanyang15fc3aee2015-05-22 14:39:35 -0400118 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
119
Alex Deucheraaa36a92015-04-20 17:31:14 -0400120 iceland_dpm_hw_fini(adev);
121
122 return 0;
123}
124
yanyang15fc3aee2015-05-22 14:39:35 -0400125static int iceland_dpm_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400126{
yanyang15fc3aee2015-05-22 14:39:35 -0400127 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
128
Alex Deucheraaa36a92015-04-20 17:31:14 -0400129 iceland_dpm_hw_init(adev);
130
131 return 0;
132}
133
yanyang15fc3aee2015-05-22 14:39:35 -0400134static int iceland_dpm_set_clockgating_state(void *handle,
135 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400136{
137 return 0;
138}
139
yanyang15fc3aee2015-05-22 14:39:35 -0400140static int iceland_dpm_set_powergating_state(void *handle,
141 enum amd_powergating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400142{
143 return 0;
144}
145
yanyang15fc3aee2015-05-22 14:39:35 -0400146const struct amd_ip_funcs iceland_dpm_ip_funcs = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400147 .early_init = iceland_dpm_early_init,
148 .late_init = NULL,
149 .sw_init = iceland_dpm_sw_init,
150 .sw_fini = iceland_dpm_sw_fini,
151 .hw_init = iceland_dpm_hw_init,
152 .hw_fini = iceland_dpm_hw_fini,
153 .suspend = iceland_dpm_suspend,
154 .resume = iceland_dpm_resume,
155 .is_idle = NULL,
156 .wait_for_idle = NULL,
157 .soft_reset = NULL,
158 .print_status = NULL,
159 .set_clockgating_state = iceland_dpm_set_clockgating_state,
160 .set_powergating_state = iceland_dpm_set_powergating_state,
161};
162
163static const struct amdgpu_dpm_funcs iceland_dpm_funcs = {
164 .get_temperature = NULL,
165 .pre_set_power_state = NULL,
166 .set_power_state = NULL,
167 .post_set_power_state = NULL,
168 .display_configuration_changed = NULL,
169 .get_sclk = NULL,
170 .get_mclk = NULL,
171 .print_power_state = NULL,
172 .debugfs_print_current_performance_level = NULL,
173 .force_performance_level = NULL,
174 .vblank_too_short = NULL,
175 .powergate_uvd = NULL,
176};
177
178static void iceland_dpm_set_funcs(struct amdgpu_device *adev)
179{
180 if (NULL == adev->pm.funcs)
181 adev->pm.funcs = &iceland_dpm_funcs;
182}