blob: 2d5b1bd52afa56c27fb4ed35d9fd5bf9d76bc195 [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 "tonga_smumgr.h"
28
Jammy Zhouc65444f2015-05-13 22:49:04 +080029MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
Alex Deucheraaa36a92015-04-20 17:31:14 -040030
31static void tonga_dpm_set_funcs(struct amdgpu_device *adev);
32
yanyang15fc3aee2015-05-22 14:39:35 -040033static int tonga_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 tonga_dpm_set_funcs(adev);
38
39 return 0;
40}
41
42static int tonga_dpm_init_microcode(struct amdgpu_device *adev)
43{
Jammy Zhouc65444f2015-05-13 22:49:04 +080044 char fw_name[30] = "amdgpu/tonga_smc.bin";
Alex Deucheraaa36a92015-04-20 17:31:14 -040045 int err;
Alex Deucheraaa36a92015-04-20 17:31:14 -040046 err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
47 if (err)
48 goto out;
49 err = amdgpu_ucode_validate(adev->pm.fw);
50
51out:
52 if (err) {
53 DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
54 release_firmware(adev->pm.fw);
55 adev->pm.fw = NULL;
56 }
57 return err;
58}
59
yanyang15fc3aee2015-05-22 14:39:35 -040060static int tonga_dpm_sw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040061{
62 int ret;
yanyang15fc3aee2015-05-22 14:39:35 -040063 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -040064
65 ret = tonga_dpm_init_microcode(adev);
66 if (ret)
67 return ret;
68
69 return 0;
70}
71
yanyang15fc3aee2015-05-22 14:39:35 -040072static int tonga_dpm_sw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040073{
74 return 0;
75}
76
yanyang15fc3aee2015-05-22 14:39:35 -040077static int tonga_dpm_hw_init(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -040078{
79 int ret;
yanyang15fc3aee2015-05-22 14:39:35 -040080 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Alex Deucheraaa36a92015-04-20 17:31:14 -040081
82 mutex_lock(&adev->pm.mutex);
83
84 ret = tonga_smu_init(adev);
85 if (ret) {
86 DRM_ERROR("SMU initialization failed\n");
87 goto fail;
88 }
89
90 ret = tonga_smu_start(adev);
91 if (ret) {
92 DRM_ERROR("SMU start failed\n");
93 goto fail;
94 }
95
96 mutex_unlock(&adev->pm.mutex);
97 return 0;
98
99fail:
100 adev->firmware.smu_load = false;
101 mutex_unlock(&adev->pm.mutex);
102 return -EINVAL;
103}
104
yanyang15fc3aee2015-05-22 14:39:35 -0400105static int tonga_dpm_hw_fini(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400106{
yanyang15fc3aee2015-05-22 14:39:35 -0400107 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
108
Alex Deucheraaa36a92015-04-20 17:31:14 -0400109 mutex_lock(&adev->pm.mutex);
110 tonga_smu_fini(adev);
111 mutex_unlock(&adev->pm.mutex);
112 return 0;
113}
114
yanyang15fc3aee2015-05-22 14:39:35 -0400115static int tonga_dpm_suspend(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400116{
yanyang15fc3aee2015-05-22 14:39:35 -0400117 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
118
Alex Deucheraaa36a92015-04-20 17:31:14 -0400119 tonga_dpm_hw_fini(adev);
120
121 return 0;
122}
123
yanyang15fc3aee2015-05-22 14:39:35 -0400124static int tonga_dpm_resume(void *handle)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400125{
yanyang15fc3aee2015-05-22 14:39:35 -0400126 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
127
Alex Deucheraaa36a92015-04-20 17:31:14 -0400128 tonga_dpm_hw_init(adev);
129
130 return 0;
131}
132
yanyang15fc3aee2015-05-22 14:39:35 -0400133static int tonga_dpm_set_clockgating_state(void *handle,
134 enum amd_clockgating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400135{
136 return 0;
137}
138
yanyang15fc3aee2015-05-22 14:39:35 -0400139static int tonga_dpm_set_powergating_state(void *handle,
140 enum amd_powergating_state state)
Alex Deucheraaa36a92015-04-20 17:31:14 -0400141{
142 return 0;
143}
144
yanyang15fc3aee2015-05-22 14:39:35 -0400145const struct amd_ip_funcs tonga_dpm_ip_funcs = {
Alex Deucheraaa36a92015-04-20 17:31:14 -0400146 .early_init = tonga_dpm_early_init,
147 .late_init = NULL,
148 .sw_init = tonga_dpm_sw_init,
149 .sw_fini = tonga_dpm_sw_fini,
150 .hw_init = tonga_dpm_hw_init,
151 .hw_fini = tonga_dpm_hw_fini,
152 .suspend = tonga_dpm_suspend,
153 .resume = tonga_dpm_resume,
154 .is_idle = NULL,
155 .wait_for_idle = NULL,
156 .soft_reset = NULL,
157 .print_status = NULL,
158 .set_clockgating_state = tonga_dpm_set_clockgating_state,
159 .set_powergating_state = tonga_dpm_set_powergating_state,
160};
161
162static 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,
168 .get_sclk = NULL,
169 .get_mclk = 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,
175};
176
177static void tonga_dpm_set_funcs(struct amdgpu_device *adev)
178{
179 if (NULL == adev->pm.funcs)
180 adev->pm.funcs = &tonga_dpm_funcs;
181}