2 * Copyright 2021 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.
26 #include "core_types.h"
27 #include "clk_mgr_internal.h"
28 #include "reg_helper.h"
29 #include "dm_helpers.h"
30 #include "dcn316_smu.h"
31 #include "mp/mp_13_0_8_offset.h"
32 #include "mp/mp_13_0_8_sh_mask.h"
34 #define MAX_INSTANCE 7
37 struct IP_BASE_INSTANCE
39 unsigned int segment[MAX_SEGMENT];
44 struct IP_BASE_INSTANCE instance[MAX_INSTANCE];
47 static const struct IP_BASE MP0_BASE = { { { { 0x00016000, 0x00DC0000, 0x00E00000, 0x00E40000, 0x0243FC00, 0 } },
48 { { 0, 0, 0, 0, 0, 0 } },
49 { { 0, 0, 0, 0, 0, 0 } },
50 { { 0, 0, 0, 0, 0, 0 } },
51 { { 0, 0, 0, 0, 0, 0 } },
52 { { 0, 0, 0, 0, 0, 0 } },
53 { { 0, 0, 0, 0, 0, 0 } } } };
55 #define REG(reg_name) \
56 (MP0_BASE.instance[0].segment[reg ## reg_name ## _BASE_IDX] + reg ## reg_name)
58 #define FN(reg_name, field) \
59 FD(reg_name##__##field)
61 #define VBIOSSMC_MSG_TestMessage 0x01 ///< To check if PMFW is alive and responding. Requirement specified by PMFW team
62 #define VBIOSSMC_MSG_GetPmfwVersion 0x02 ///< Get PMFW version
63 #define VBIOSSMC_MSG_Spare0 0x03 ///< Spare0
64 #define VBIOSSMC_MSG_SetDispclkFreq 0x04 ///< Set display clock frequency in MHZ
65 #define VBIOSSMC_MSG_Spare1 0x05 ///< Spare1
66 #define VBIOSSMC_MSG_SetDppclkFreq 0x06 ///< Set DPP clock frequency in MHZ
67 #define VBIOSSMC_MSG_SetHardMinDcfclkByFreq 0x07 ///< Set DCF clock frequency hard min in MHZ
68 #define VBIOSSMC_MSG_SetMinDeepSleepDcfclk 0x08 ///< Set DCF clock minimum frequency in deep sleep in MHZ
69 #define VBIOSSMC_MSG_SetPhyclkVoltageByFreq 0x09 ///< Set display phy clock frequency in MHZ in case VMIN does not support phy frequency
70 #define VBIOSSMC_MSG_GetFclkFrequency 0x0A ///< Get FCLK frequency, return frequemcy in MHZ
71 #define VBIOSSMC_MSG_SetDisplayCount 0x0B ///< Inform PMFW of number of display connected
72 #define VBIOSSMC_MSG_SPARE 0x0C ///< SPARE
73 #define VBIOSSMC_MSG_UpdatePmeRestore 0x0D ///< To ask PMFW to write into Azalia for PME wake up event
74 #define VBIOSSMC_MSG_SetVbiosDramAddrHigh 0x0E ///< Set DRAM address high 32 bits for WM table transfer
75 #define VBIOSSMC_MSG_SetVbiosDramAddrLow 0x0F ///< Set DRAM address low 32 bits for WM table transfer
76 #define VBIOSSMC_MSG_TransferTableSmu2Dram 0x10 ///< Transfer table from PMFW SRAM to system DRAM
77 #define VBIOSSMC_MSG_TransferTableDram2Smu 0x11 ///< Transfer table from system DRAM to PMFW
78 #define VBIOSSMC_MSG_SetDisplayIdleOptimizations 0x12 ///< Set Idle state optimization for display off
79 #define VBIOSSMC_MSG_GetDprefclkFreq 0x13 ///< Get DPREF clock frequency. Return in MHZ
80 #define VBIOSSMC_MSG_GetDtbclkFreq 0x14 ///< Get DPREF clock frequency. Return in MHZ
81 #define VBIOSSMC_MSG_SetDtbclkFreq 0x15 ///< Inform PMFW to turn on/off DTB clock arg = 1, turn DTB clock on 600MHz/ arg = 0 turn DTB clock off
82 #define VBIOSSMC_Message_Count 0x16 ///< Total number of VBIS and DAL messages
84 #define VBIOSSMC_Status_BUSY 0x0
85 #define VBIOSSMC_Result_OK 0x01 ///< Message Response OK
86 #define VBIOSSMC_Result_Failed 0xFF ///< Message Response Failed
87 #define VBIOSSMC_Result_UnknownCmd 0xFE ///< Message Response Unknown Command
88 #define VBIOSSMC_Result_CmdRejectedPrereq 0xFD ///< Message Response Command Failed Prerequisite
89 #define VBIOSSMC_Result_CmdRejectedBusy 0xFC ///< Message Response Command Rejected due to PMFW is busy. Sender should retry sending this message
92 * Function to be used instead of REG_WAIT macro because the wait ends when
93 * the register is NOT EQUAL to zero, and because the translation in msg_if.h
94 * won't work with REG_WAIT.
96 static uint32_t dcn316_smu_wait_for_response(struct clk_mgr_internal *clk_mgr, unsigned int delay_us, unsigned int max_retries)
98 uint32_t res_val = VBIOSSMC_Status_BUSY;
101 res_val = REG_READ(MP1_SMN_C2PMSG_91);
102 if (res_val != VBIOSSMC_Status_BUSY)
105 if (delay_us >= 1000)
106 msleep(delay_us/1000);
107 else if (delay_us > 0)
109 } while (max_retries--);
114 static int dcn316_smu_send_msg_with_param(
115 struct clk_mgr_internal *clk_mgr,
116 unsigned int msg_id, unsigned int param)
120 result = dcn316_smu_wait_for_response(clk_mgr, 10, 200000);
121 ASSERT(result == VBIOSSMC_Result_OK);
123 if (result == VBIOSSMC_Status_BUSY) {
127 /* First clear response register */
128 REG_WRITE(MP1_SMN_C2PMSG_91, VBIOSSMC_Status_BUSY);
130 /* Set the parameter register for the SMU message, unit is Mhz */
131 REG_WRITE(MP1_SMN_C2PMSG_83, param);
133 /* Trigger the message transaction by writing the message ID */
134 REG_WRITE(MP1_SMN_C2PMSG_67, msg_id);
136 result = dcn316_smu_wait_for_response(clk_mgr, 10, 200000);
138 if (result == VBIOSSMC_Status_BUSY) {
140 dm_helpers_smu_timeout(CTX, msg_id, param, 10 * 200000);
143 return REG_READ(MP1_SMN_C2PMSG_83);
146 int dcn316_smu_get_smu_version(struct clk_mgr_internal *clk_mgr)
148 return dcn316_smu_send_msg_with_param(
150 VBIOSSMC_MSG_GetPmfwVersion,
155 int dcn316_smu_set_dispclk(struct clk_mgr_internal *clk_mgr, int requested_dispclk_khz)
157 int actual_dispclk_set_mhz = -1;
159 if (!clk_mgr->smu_present)
160 return requested_dispclk_khz;
162 /* Unit of SMU msg parameter is Mhz */
163 actual_dispclk_set_mhz = dcn316_smu_send_msg_with_param(
165 VBIOSSMC_MSG_SetDispclkFreq,
166 khz_to_mhz_ceil(requested_dispclk_khz));
168 return actual_dispclk_set_mhz * 1000;
171 int dcn316_smu_set_hard_min_dcfclk(struct clk_mgr_internal *clk_mgr, int requested_dcfclk_khz)
173 int actual_dcfclk_set_mhz = -1;
175 if (!clk_mgr->base.ctx->dc->debug.pstate_enabled)
178 if (!clk_mgr->smu_present)
179 return requested_dcfclk_khz;
181 actual_dcfclk_set_mhz = dcn316_smu_send_msg_with_param(
183 VBIOSSMC_MSG_SetHardMinDcfclkByFreq,
184 khz_to_mhz_ceil(requested_dcfclk_khz));
186 return actual_dcfclk_set_mhz * 1000;
189 int dcn316_smu_set_min_deep_sleep_dcfclk(struct clk_mgr_internal *clk_mgr, int requested_min_ds_dcfclk_khz)
191 int actual_min_ds_dcfclk_mhz = -1;
193 if (!clk_mgr->base.ctx->dc->debug.pstate_enabled)
196 if (!clk_mgr->smu_present)
197 return requested_min_ds_dcfclk_khz;
199 actual_min_ds_dcfclk_mhz = dcn316_smu_send_msg_with_param(
201 VBIOSSMC_MSG_SetMinDeepSleepDcfclk,
202 khz_to_mhz_ceil(requested_min_ds_dcfclk_khz));
204 return actual_min_ds_dcfclk_mhz * 1000;
207 int dcn316_smu_set_dppclk(struct clk_mgr_internal *clk_mgr, int requested_dpp_khz)
209 int actual_dppclk_set_mhz = -1;
211 if (!clk_mgr->smu_present)
212 return requested_dpp_khz;
214 actual_dppclk_set_mhz = dcn316_smu_send_msg_with_param(
216 VBIOSSMC_MSG_SetDppclkFreq,
217 khz_to_mhz_ceil(requested_dpp_khz));
219 return actual_dppclk_set_mhz * 1000;
222 void dcn316_smu_set_display_idle_optimization(struct clk_mgr_internal *clk_mgr, uint32_t idle_info)
224 if (!clk_mgr->base.ctx->dc->debug.pstate_enabled)
227 if (!clk_mgr->smu_present)
230 //TODO: Work with smu team to define optimization options.
231 dcn316_smu_send_msg_with_param(
233 VBIOSSMC_MSG_SetDisplayIdleOptimizations,
237 void dcn316_smu_enable_phy_refclk_pwrdwn(struct clk_mgr_internal *clk_mgr, bool enable)
239 union display_idle_optimization_u idle_info = { 0 };
241 if (!clk_mgr->smu_present)
245 idle_info.idle_info.df_request_disabled = 1;
246 idle_info.idle_info.phy_ref_clk_off = 1;
249 dcn316_smu_send_msg_with_param(
251 VBIOSSMC_MSG_SetDisplayIdleOptimizations,
255 void dcn316_smu_set_dram_addr_high(struct clk_mgr_internal *clk_mgr, uint32_t addr_high)
257 if (!clk_mgr->smu_present)
260 dcn316_smu_send_msg_with_param(clk_mgr,
261 VBIOSSMC_MSG_SetVbiosDramAddrHigh, addr_high);
264 void dcn316_smu_set_dram_addr_low(struct clk_mgr_internal *clk_mgr, uint32_t addr_low)
266 if (!clk_mgr->smu_present)
269 dcn316_smu_send_msg_with_param(clk_mgr,
270 VBIOSSMC_MSG_SetVbiosDramAddrLow, addr_low);
273 void dcn316_smu_transfer_dpm_table_smu_2_dram(struct clk_mgr_internal *clk_mgr)
275 if (!clk_mgr->smu_present)
278 dcn316_smu_send_msg_with_param(clk_mgr,
279 VBIOSSMC_MSG_TransferTableSmu2Dram, TABLE_DPMCLOCKS);
282 void dcn316_smu_transfer_wm_table_dram_2_smu(struct clk_mgr_internal *clk_mgr)
284 if (!clk_mgr->smu_present)
287 dcn316_smu_send_msg_with_param(clk_mgr,
288 VBIOSSMC_MSG_TransferTableDram2Smu, TABLE_WATERMARKS);
291 void dcn316_smu_enable_pme_wa(struct clk_mgr_internal *clk_mgr)
293 if (!clk_mgr->smu_present)
296 dcn316_smu_send_msg_with_param(
298 VBIOSSMC_MSG_UpdatePmeRestore,
302 /* Arg = 1: Turn DTB on; 0: Turn DTB CLK OFF. when it is on, it is 600MHZ */
303 void dcn316_smu_set_dtbclk(struct clk_mgr_internal *clk_mgr, bool enable)
305 if (!clk_mgr->smu_present)
308 dcn316_smu_send_msg_with_param(
310 VBIOSSMC_MSG_SetDtbclkFreq,
314 int dcn316_smu_get_dpref_clk(struct clk_mgr_internal *clk_mgr)
316 int dprefclk_get_mhz = -1;
318 if (clk_mgr->smu_present) {
319 dprefclk_get_mhz = dcn316_smu_send_msg_with_param(
321 VBIOSSMC_MSG_GetDprefclkFreq,
324 return (dprefclk_get_mhz * 1000);
327 int dcn316_smu_get_smu_fclk(struct clk_mgr_internal *clk_mgr)
329 int fclk_get_mhz = -1;
331 if (clk_mgr->smu_present) {
332 fclk_get_mhz = dcn316_smu_send_msg_with_param(
334 VBIOSSMC_MSG_GetFclkFrequency,
337 return (fclk_get_mhz * 1000);