drm/radeon: separate UVD code v3
[deliverable/linux.git] / drivers / gpu / drm / radeon / trinity_smc.c
CommitLineData
d70229f7
AD
1/*
2 * Copyright 2012 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 "drmP.h"
25#include "radeon.h"
26#include "trinityd.h"
27#include "trinity_dpm.h"
28#include "ppsmc.h"
29
30struct trinity_ps *trinity_get_ps(struct radeon_ps *rps);
31struct trinity_power_info *trinity_get_pi(struct radeon_device *rdev);
32
33static int trinity_notify_message_to_smu(struct radeon_device *rdev, u32 id)
34{
35 int i;
36 u32 v = 0;
37
38 WREG32(SMC_MESSAGE_0, id);
39 for (i = 0; i < rdev->usec_timeout; i++) {
40 if (RREG32(SMC_RESP_0) != 0)
41 break;
42 udelay(1);
43 }
44 v = RREG32(SMC_RESP_0);
45
46 if (v != 1) {
47 if (v == 0xFF) {
48 DRM_ERROR("SMC failed to handle the message!\n");
49 return -EINVAL;
50 } else if (v == 0xFE) {
51 DRM_ERROR("Unknown SMC message!\n");
52 return -EINVAL;
53 }
54 }
55
56 return 0;
57}
58
59int trinity_dpm_config(struct radeon_device *rdev, bool enable)
60{
61 if (enable)
62 WREG32_SMC(SMU_SCRATCH0, 1);
63 else
64 WREG32_SMC(SMU_SCRATCH0, 0);
65
66 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_Config);
67}
68
69int trinity_dpm_force_state(struct radeon_device *rdev, u32 n)
70{
71 WREG32_SMC(SMU_SCRATCH0, n);
72
73 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_ForceState);
74}
75
9b5de596
AD
76int trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n)
77{
78 WREG32_SMC(SMU_SCRATCH0, n);
79
80 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_N_LevelsDisabled);
81}
82
0c4aaeae
AD
83int trinity_uvd_dpm_config(struct radeon_device *rdev)
84{
85 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_UVD_DPM_Config);
86}
87
d70229f7
AD
88int trinity_dpm_no_forced_level(struct radeon_device *rdev)
89{
90 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
91}
92
93int trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev,
94 bool enable)
95{
96 if (enable)
97 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_AllowVoltageAdjustment);
98 else
99 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_RemoveVoltageAdjustment);
100}
101
102int trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev)
103{
104 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_PG_SIMD_Config);
105}
106
107void trinity_acquire_mutex(struct radeon_device *rdev)
108{
109 int i;
110
111 WREG32(SMC_INT_REQ, 1);
112 for (i = 0; i < rdev->usec_timeout; i++) {
113 if ((RREG32(SMC_INT_REQ) & 0xffff) == 1)
114 break;
115 udelay(1);
116 }
117}
118
119void trinity_release_mutex(struct radeon_device *rdev)
120{
121 WREG32(SMC_INT_REQ, 0);
122}
This page took 0.045882 seconds and 5 git commands to generate.