• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012-16 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  * Authors: AMD
23  *
24  */
25 
26 #include "core_types.h"
27 #include "clk_mgr_internal.h"
28 #include "reg_helper.h"
29 #include <linux/delay.h>
30 
31 #include "renoir_ip_offset.h"
32 
33 #include "mp/mp_12_0_0_offset.h"
34 #include "mp/mp_12_0_0_sh_mask.h"
35 
36 #define REG(reg_name) \
37 	(MP0_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
38 
39 #define FN(reg_name, field) \
40 	FD(reg_name##__##field)
41 
42 #define VBIOSSMC_MSG_TestMessage                  0x1
43 #define VBIOSSMC_MSG_GetSmuVersion                0x2
44 #define VBIOSSMC_MSG_PowerUpGfx                   0x3
45 #define VBIOSSMC_MSG_SetDispclkFreq               0x4
46 #define VBIOSSMC_MSG_SetDprefclkFreq              0x5
47 #define VBIOSSMC_MSG_PowerDownGfx                 0x6
48 #define VBIOSSMC_MSG_SetDppclkFreq                0x7
49 #define VBIOSSMC_MSG_SetHardMinDcfclkByFreq       0x8
50 #define VBIOSSMC_MSG_SetMinDeepSleepDcfclk        0x9
51 #define VBIOSSMC_MSG_SetPhyclkVoltageByFreq       0xA
52 #define VBIOSSMC_MSG_GetFclkFrequency             0xB
53 #define VBIOSSMC_MSG_SetDisplayCount              0xC
54 #define VBIOSSMC_MSG_EnableTmdp48MHzRefclkPwrDown 0xD
55 #define VBIOSSMC_MSG_UpdatePmeRestore             0xE
56 #define VBIOSSMC_MSG_IsPeriodicRetrainingDisabled 0xF
57 
58 #define VBIOSSMC_Status_BUSY                      0x0
59 #define VBIOSSMC_Result_OK                        0x1
60 #define VBIOSSMC_Result_Failed                    0xFF
61 #define VBIOSSMC_Result_UnknownCmd                0xFE
62 #define VBIOSSMC_Result_CmdRejectedPrereq         0xFD
63 #define VBIOSSMC_Result_CmdRejectedBusy           0xFC
64 
65 /*
66  * Function to be used instead of REG_WAIT macro because the wait ends when
67  * the register is NOT EQUAL to zero, and because the translation in msg_if.h
68  * won't work with REG_WAIT.
69  */
rn_smu_wait_for_response(struct clk_mgr_internal * clk_mgr,unsigned int delay_us,unsigned int max_retries)70 static uint32_t rn_smu_wait_for_response(struct clk_mgr_internal *clk_mgr, unsigned int delay_us, unsigned int max_retries)
71 {
72 	uint32_t res_val = VBIOSSMC_Status_BUSY;
73 
74 	do {
75 		res_val = REG_READ(MP1_SMN_C2PMSG_91);
76 		if (res_val != VBIOSSMC_Status_BUSY)
77 			break;
78 
79 		if (delay_us >= 1000)
80 			msleep(delay_us/1000);
81 		else if (delay_us > 0)
82 			udelay(delay_us);
83 	} while (max_retries--);
84 
85 	return res_val;
86 }
87 
88 
rn_vbios_smu_send_msg_with_param(struct clk_mgr_internal * clk_mgr,unsigned int msg_id,unsigned int param)89 int rn_vbios_smu_send_msg_with_param(struct clk_mgr_internal *clk_mgr, unsigned int msg_id, unsigned int param)
90 {
91 	uint32_t result;
92 
93 	/* First clear response register */
94 	REG_WRITE(MP1_SMN_C2PMSG_91, VBIOSSMC_Status_BUSY);
95 
96 	/* Set the parameter register for the SMU message, unit is Mhz */
97 	REG_WRITE(MP1_SMN_C2PMSG_83, param);
98 
99 	/* Trigger the message transaction by writing the message ID */
100 	REG_WRITE(MP1_SMN_C2PMSG_67, msg_id);
101 
102 	result = rn_smu_wait_for_response(clk_mgr, 10, 1000);
103 
104 	ASSERT(result == VBIOSSMC_Result_OK || result == VBIOSSMC_Result_UnknownCmd);
105 
106 	/* Actual dispclk set is returned in the parameter register */
107 	return REG_READ(MP1_SMN_C2PMSG_83);
108 }
109 
rn_vbios_smu_get_smu_version(struct clk_mgr_internal * clk_mgr)110 int rn_vbios_smu_get_smu_version(struct clk_mgr_internal *clk_mgr)
111 {
112 	return rn_vbios_smu_send_msg_with_param(
113 			clk_mgr,
114 			VBIOSSMC_MSG_GetSmuVersion,
115 			0);
116 }
117 
118 
rn_vbios_smu_set_dispclk(struct clk_mgr_internal * clk_mgr,int requested_dispclk_khz)119 int rn_vbios_smu_set_dispclk(struct clk_mgr_internal *clk_mgr, int requested_dispclk_khz)
120 {
121 	int actual_dispclk_set_mhz = -1;
122 	struct dc *dc = clk_mgr->base.ctx->dc;
123 	struct dmcu *dmcu = dc->res_pool->dmcu;
124 
125 	/*  Unit of SMU msg parameter is Mhz */
126 	actual_dispclk_set_mhz = rn_vbios_smu_send_msg_with_param(
127 			clk_mgr,
128 			VBIOSSMC_MSG_SetDispclkFreq,
129 			requested_dispclk_khz / 1000);
130 
131 	if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
132 		if (dmcu && dmcu->funcs->is_dmcu_initialized(dmcu)) {
133 			if (clk_mgr->dfs_bypass_disp_clk != actual_dispclk_set_mhz)
134 				dmcu->funcs->set_psr_wait_loop(dmcu,
135 						actual_dispclk_set_mhz / 7);
136 		}
137 	}
138 
139 	return actual_dispclk_set_mhz * 1000;
140 }
141 
rn_vbios_smu_set_dprefclk(struct clk_mgr_internal * clk_mgr)142 int rn_vbios_smu_set_dprefclk(struct clk_mgr_internal *clk_mgr)
143 {
144 	int actual_dprefclk_set_mhz = -1;
145 
146 	actual_dprefclk_set_mhz = rn_vbios_smu_send_msg_with_param(
147 			clk_mgr,
148 			VBIOSSMC_MSG_SetDprefclkFreq,
149 			clk_mgr->base.dprefclk_khz / 1000);
150 
151 	/* TODO: add code for programing DP DTO, currently this is down by command table */
152 
153 	return actual_dprefclk_set_mhz * 1000;
154 }
155 
rn_vbios_smu_set_hard_min_dcfclk(struct clk_mgr_internal * clk_mgr,int requested_dcfclk_khz)156 int rn_vbios_smu_set_hard_min_dcfclk(struct clk_mgr_internal *clk_mgr, int requested_dcfclk_khz)
157 {
158 	int actual_dcfclk_set_mhz = -1;
159 
160 	if (clk_mgr->smu_ver < 0x370c00)
161 		return actual_dcfclk_set_mhz;
162 
163 	actual_dcfclk_set_mhz = rn_vbios_smu_send_msg_with_param(
164 			clk_mgr,
165 			VBIOSSMC_MSG_SetHardMinDcfclkByFreq,
166 			requested_dcfclk_khz / 1000);
167 
168 	return actual_dcfclk_set_mhz * 1000;
169 }
170 
rn_vbios_smu_set_min_deep_sleep_dcfclk(struct clk_mgr_internal * clk_mgr,int requested_min_ds_dcfclk_khz)171 int rn_vbios_smu_set_min_deep_sleep_dcfclk(struct clk_mgr_internal *clk_mgr, int requested_min_ds_dcfclk_khz)
172 {
173 	int actual_min_ds_dcfclk_mhz = -1;
174 
175 	if (clk_mgr->smu_ver < 0x370c00)
176 		return actual_min_ds_dcfclk_mhz;
177 
178 	actual_min_ds_dcfclk_mhz = rn_vbios_smu_send_msg_with_param(
179 			clk_mgr,
180 			VBIOSSMC_MSG_SetMinDeepSleepDcfclk,
181 			requested_min_ds_dcfclk_khz / 1000);
182 
183 	return actual_min_ds_dcfclk_mhz * 1000;
184 }
185 
rn_vbios_smu_set_phyclk(struct clk_mgr_internal * clk_mgr,int requested_phyclk_khz)186 void rn_vbios_smu_set_phyclk(struct clk_mgr_internal *clk_mgr, int requested_phyclk_khz)
187 {
188 	rn_vbios_smu_send_msg_with_param(
189 			clk_mgr,
190 			VBIOSSMC_MSG_SetPhyclkVoltageByFreq,
191 			requested_phyclk_khz / 1000);
192 }
193 
rn_vbios_smu_set_dppclk(struct clk_mgr_internal * clk_mgr,int requested_dpp_khz)194 int rn_vbios_smu_set_dppclk(struct clk_mgr_internal *clk_mgr, int requested_dpp_khz)
195 {
196 	int actual_dppclk_set_mhz = -1;
197 
198 	actual_dppclk_set_mhz = rn_vbios_smu_send_msg_with_param(
199 			clk_mgr,
200 			VBIOSSMC_MSG_SetDppclkFreq,
201 			requested_dpp_khz / 1000);
202 
203 	return actual_dppclk_set_mhz * 1000;
204 }
205 
rn_vbios_smu_set_dcn_low_power_state(struct clk_mgr_internal * clk_mgr,enum dcn_pwr_state state)206 void rn_vbios_smu_set_dcn_low_power_state(struct clk_mgr_internal *clk_mgr, enum dcn_pwr_state state)
207 {
208 	int disp_count;
209 
210 	if (state == DCN_PWR_STATE_LOW_POWER)
211 		disp_count = 0;
212 	else
213 		disp_count = 1;
214 
215 	rn_vbios_smu_send_msg_with_param(
216 		clk_mgr,
217 		VBIOSSMC_MSG_SetDisplayCount,
218 		disp_count);
219 }
220 
rn_vbios_smu_enable_48mhz_tmdp_refclk_pwrdwn(struct clk_mgr_internal * clk_mgr,bool enable)221 void rn_vbios_smu_enable_48mhz_tmdp_refclk_pwrdwn(struct clk_mgr_internal *clk_mgr, bool enable)
222 {
223 	rn_vbios_smu_send_msg_with_param(
224 			clk_mgr,
225 			VBIOSSMC_MSG_EnableTmdp48MHzRefclkPwrDown,
226 			enable);
227 }
228 
rn_vbios_smu_enable_pme_wa(struct clk_mgr_internal * clk_mgr)229 void rn_vbios_smu_enable_pme_wa(struct clk_mgr_internal *clk_mgr)
230 {
231 	rn_vbios_smu_send_msg_with_param(
232 			clk_mgr,
233 			VBIOSSMC_MSG_UpdatePmeRestore,
234 			0);
235 }
236 
rn_vbios_smu_is_periodic_retraining_disabled(struct clk_mgr_internal * clk_mgr)237 int rn_vbios_smu_is_periodic_retraining_disabled(struct clk_mgr_internal *clk_mgr)
238 {
239 	return rn_vbios_smu_send_msg_with_param(
240 			clk_mgr,
241 			VBIOSSMC_MSG_IsPeriodicRetrainingDisabled,
242 			0);
243 }
244