2 * Copyright 2018 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 "dcn10_clk_mgr.h"
28 #include "reg_helper.h"
29 #include "core_types.h"
31 #define TO_DCE_CLK_MGR(clocks)\
32 container_of(clocks, struct dce_clk_mgr, base)
35 (clk_mgr_dce->regs->reg)
38 #define FN(reg_name, field_name) \
39 clk_mgr_dce->clk_mgr_shift->field_name, clk_mgr_dce->clk_mgr_mask->field_name
46 void dcn1_pplib_apply_display_requirements(
48 struct dc_state *context)
50 struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg;
52 pp_display_cfg->min_engine_clock_khz = dc->res_pool->clk_mgr->clks.dcfclk_khz;
53 pp_display_cfg->min_memory_clock_khz = dc->res_pool->clk_mgr->clks.fclk_khz;
54 pp_display_cfg->min_engine_clock_deep_sleep_khz = dc->res_pool->clk_mgr->clks.dcfclk_deep_sleep_khz;
55 pp_display_cfg->min_dcfc_deep_sleep_clock_khz = dc->res_pool->clk_mgr->clks.dcfclk_deep_sleep_khz;
56 pp_display_cfg->min_dcfclock_khz = dc->res_pool->clk_mgr->clks.dcfclk_khz;
57 pp_display_cfg->disp_clk_khz = dc->res_pool->clk_mgr->clks.dispclk_khz;
58 dce110_fill_display_configs(context, pp_display_cfg);
60 dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg);
63 static int dcn1_determine_dppclk_threshold(struct clk_mgr *clk_mgr, struct dc_clocks *new_clocks)
65 bool request_dpp_div = new_clocks->dispclk_khz > new_clocks->dppclk_khz;
66 bool dispclk_increase = new_clocks->dispclk_khz > clk_mgr->clks.dispclk_khz;
67 int disp_clk_threshold = new_clocks->max_supported_dppclk_khz;
68 bool cur_dpp_div = clk_mgr->clks.dispclk_khz > clk_mgr->clks.dppclk_khz;
70 /* increase clock, looking for div is 0 for current, request div is 1*/
71 if (dispclk_increase) {
72 /* already divided by 2, no need to reach target clk with 2 steps*/
74 return new_clocks->dispclk_khz;
76 /* request disp clk is lower than maximum supported dpp clk,
77 * no need to reach target clk with two steps.
79 if (new_clocks->dispclk_khz <= disp_clk_threshold)
80 return new_clocks->dispclk_khz;
82 /* target dpp clk not request divided by 2, still within threshold */
84 return new_clocks->dispclk_khz;
87 /* decrease clock, looking for current dppclk divided by 2,
88 * request dppclk not divided by 2.
91 /* current dpp clk not divided by 2, no need to ramp*/
93 return new_clocks->dispclk_khz;
95 /* current disp clk is lower than current maximum dpp clk,
98 if (clk_mgr->clks.dispclk_khz <= disp_clk_threshold)
99 return new_clocks->dispclk_khz;
101 /* request dpp clk need to be divided by 2 */
103 return new_clocks->dispclk_khz;
106 return disp_clk_threshold;
109 static void dcn1_ramp_up_dispclk_with_dpp(struct clk_mgr *clk_mgr, struct dc_clocks *new_clocks)
111 struct dc *dc = clk_mgr->ctx->dc;
112 int dispclk_to_dpp_threshold = dcn1_determine_dppclk_threshold(clk_mgr, new_clocks);
113 bool request_dpp_div = new_clocks->dispclk_khz > new_clocks->dppclk_khz;
116 /* set disp clk to dpp clk threshold */
117 dce112_set_clock(clk_mgr, dispclk_to_dpp_threshold);
119 /* update request dpp clk division option */
120 for (i = 0; i < dc->res_pool->pipe_count; i++) {
121 struct pipe_ctx *pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
123 if (!pipe_ctx->plane_state)
126 pipe_ctx->plane_res.dpp->funcs->dpp_dppclk_control(
127 pipe_ctx->plane_res.dpp,
132 /* If target clk not same as dppclk threshold, set to target clock */
133 if (dispclk_to_dpp_threshold != new_clocks->dispclk_khz)
134 dce112_set_clock(clk_mgr, new_clocks->dispclk_khz);
136 clk_mgr->clks.dispclk_khz = new_clocks->dispclk_khz;
137 clk_mgr->clks.dppclk_khz = new_clocks->dppclk_khz;
138 clk_mgr->clks.max_supported_dppclk_khz = new_clocks->max_supported_dppclk_khz;
141 static int get_active_display_cnt(
143 struct dc_state *context)
145 int i, display_count;
148 for (i = 0; i < context->stream_count; i++) {
149 const struct dc_stream_state *stream = context->streams[i];
152 * Only notify active stream or virtual stream.
153 * Need to notify virtual stream to work around
154 * headless case. HPD does not fire when system is in
157 if (!stream->dpms_off || stream->signal == SIGNAL_TYPE_VIRTUAL)
161 return display_count;
164 static void notify_deep_sleep_dcfclk_to_smu(
165 struct pp_smu_funcs_rv *pp_smu, int min_dcef_deep_sleep_clk_khz)
167 int min_dcef_deep_sleep_clk_mhz; //minimum required DCEF Deep Sleep clock in mhz
169 * if function pointer not set up, this message is
170 * sent as part of pplib_apply_display_requirements.
173 if (!pp_smu || !pp_smu->set_min_deep_sleep_dcfclk)
176 min_dcef_deep_sleep_clk_mhz = (min_dcef_deep_sleep_clk_khz + 999) / 1000; //Round up
177 pp_smu->set_min_deep_sleep_dcfclk(&pp_smu->pp_smu, min_dcef_deep_sleep_clk_mhz);
180 static void notify_hard_min_dcfclk_to_smu(
181 struct pp_smu_funcs_rv *pp_smu, int min_dcf_clk_khz)
183 int min_dcf_clk_mhz; //minimum required DCF clock in mhz
186 * if function pointer not set up, this message is
187 * sent as part of pplib_apply_display_requirements.
190 if (!pp_smu || !pp_smu->set_hard_min_dcfclk_by_freq)
193 min_dcf_clk_mhz = min_dcf_clk_khz / 1000;
195 pp_smu->set_hard_min_dcfclk_by_freq(&pp_smu->pp_smu, min_dcf_clk_mhz);
198 static void notify_hard_min_fclk_to_smu(
199 struct pp_smu_funcs_rv *pp_smu, int min_f_clk_khz)
201 int min_f_clk_mhz; //minimum required F clock in mhz
204 * if function pointer not set up, this message is
205 * sent as part of pplib_apply_display_requirements.
208 if (!pp_smu || !pp_smu->set_hard_min_fclk_by_freq)
211 min_f_clk_mhz = min_f_clk_khz / 1000;
213 pp_smu->set_hard_min_fclk_by_freq(&pp_smu->pp_smu, min_f_clk_mhz);
216 static void dcn1_update_clocks(struct clk_mgr *clk_mgr,
217 struct dc_state *context,
220 struct dc *dc = clk_mgr->ctx->dc;
221 struct dc_clocks *new_clocks = &context->bw.dcn.clk;
222 struct pp_smu_display_requirement_rv *smu_req_cur =
223 &dc->res_pool->pp_smu_req;
224 struct pp_smu_display_requirement_rv smu_req = *smu_req_cur;
225 struct pp_smu_funcs_rv *pp_smu = dc->res_pool->pp_smu;
226 uint32_t requested_dcf_clock_in_khz = 0;
227 bool send_request_to_increase = false;
228 bool send_request_to_lower = false;
231 bool enter_display_off = false;
233 display_count = get_active_display_cnt(dc, context);
235 if (display_count == 0)
236 enter_display_off = true;
238 if (enter_display_off == safe_to_lower) {
240 * Notify SMU active displays
241 * if function pointer not set up, this message is
242 * sent as part of pplib_apply_display_requirements.
244 if (pp_smu->set_display_count)
245 pp_smu->set_display_count(&pp_smu->pp_smu, display_count);
247 smu_req.display_count = display_count;
251 if (new_clocks->dispclk_khz > clk_mgr->clks.dispclk_khz
252 || new_clocks->phyclk_khz > clk_mgr->clks.phyclk_khz
253 || new_clocks->fclk_khz > clk_mgr->clks.fclk_khz
254 || new_clocks->dcfclk_khz > clk_mgr->clks.dcfclk_khz)
255 send_request_to_increase = true;
257 if (should_set_clock(safe_to_lower, new_clocks->phyclk_khz, clk_mgr->clks.phyclk_khz)) {
258 clk_mgr->clks.phyclk_khz = new_clocks->phyclk_khz;
260 send_request_to_lower = true;
264 if (should_set_clock(safe_to_lower, new_clocks->fclk_khz, clk_mgr->clks.fclk_khz)) {
265 clk_mgr->clks.fclk_khz = new_clocks->fclk_khz;
266 smu_req.hard_min_fclk_mhz = new_clocks->fclk_khz / 1000;
268 notify_hard_min_fclk_to_smu(pp_smu, new_clocks->fclk_khz);
270 send_request_to_lower = true;
274 if (should_set_clock(safe_to_lower, new_clocks->dcfclk_khz, clk_mgr->clks.dcfclk_khz)) {
275 clk_mgr->clks.dcfclk_khz = new_clocks->dcfclk_khz;
276 smu_req.hard_min_dcefclk_mhz = new_clocks->dcfclk_khz / 1000;
278 send_request_to_lower = true;
281 if (should_set_clock(safe_to_lower,
282 new_clocks->dcfclk_deep_sleep_khz, clk_mgr->clks.dcfclk_deep_sleep_khz)) {
283 clk_mgr->clks.dcfclk_deep_sleep_khz = new_clocks->dcfclk_deep_sleep_khz;
284 smu_req.min_deep_sleep_dcefclk_mhz = new_clocks->dcfclk_deep_sleep_khz / 1000;
286 send_request_to_lower = true;
289 /* make sure dcf clk is before dpp clk to
290 * make sure we have enough voltage to run dpp clk
292 if (send_request_to_increase) {
293 /*use dcfclk to request voltage*/
294 requested_dcf_clock_in_khz = dcn_find_dcfclk_suits_all(dc, new_clocks);
296 notify_hard_min_dcfclk_to_smu(pp_smu, requested_dcf_clock_in_khz);
298 if (pp_smu->set_display_requirement)
299 pp_smu->set_display_requirement(&pp_smu->pp_smu, &smu_req);
301 notify_deep_sleep_dcfclk_to_smu(pp_smu, clk_mgr->clks.dcfclk_deep_sleep_khz);
302 dcn1_pplib_apply_display_requirements(dc, context);
305 /* dcn1 dppclk is tied to dispclk */
306 /* program dispclk on = as a w/a for sleep resume clock ramping issues */
307 if (should_set_clock(safe_to_lower, new_clocks->dispclk_khz, clk_mgr->clks.dispclk_khz)
308 || new_clocks->dispclk_khz == clk_mgr->clks.dispclk_khz) {
309 dcn1_ramp_up_dispclk_with_dpp(clk_mgr, new_clocks);
310 clk_mgr->clks.dispclk_khz = new_clocks->dispclk_khz;
312 send_request_to_lower = true;
315 if (!send_request_to_increase && send_request_to_lower) {
316 /*use dcfclk to request voltage*/
317 requested_dcf_clock_in_khz = dcn_find_dcfclk_suits_all(dc, new_clocks);
319 notify_hard_min_dcfclk_to_smu(pp_smu, requested_dcf_clock_in_khz);
321 if (pp_smu->set_display_requirement)
322 pp_smu->set_display_requirement(&pp_smu->pp_smu, &smu_req);
324 notify_deep_sleep_dcfclk_to_smu(pp_smu, clk_mgr->clks.dcfclk_deep_sleep_khz);
325 dcn1_pplib_apply_display_requirements(dc, context);
329 *smu_req_cur = smu_req;
331 static const struct clk_mgr_funcs dcn1_funcs = {
332 .get_dp_ref_clk_frequency = dce12_get_dp_ref_freq_khz,
333 .update_clocks = dcn1_update_clocks
335 struct clk_mgr *dcn1_clk_mgr_create(struct dc_context *ctx)
337 struct dc_debug_options *debug = &ctx->dc->debug;
338 struct dc_bios *bp = ctx->dc_bios;
339 struct dc_firmware_info fw_info = { { 0 } };
340 struct dce_clk_mgr *clk_mgr_dce = kzalloc(sizeof(*clk_mgr_dce), GFP_KERNEL);
342 if (clk_mgr_dce == NULL) {
347 clk_mgr_dce->base.ctx = ctx;
348 clk_mgr_dce->base.funcs = &dcn1_funcs;
350 clk_mgr_dce->dfs_bypass_disp_clk = 0;
352 clk_mgr_dce->dprefclk_ss_percentage = 0;
353 clk_mgr_dce->dprefclk_ss_divider = 1000;
354 clk_mgr_dce->ss_on_dprefclk = false;
356 clk_mgr_dce->dprefclk_khz = 600000;
357 if (bp->integrated_info)
358 clk_mgr_dce->dentist_vco_freq_khz = bp->integrated_info->dentist_vco_freq;
359 if (clk_mgr_dce->dentist_vco_freq_khz == 0) {
360 bp->funcs->get_firmware_info(bp, &fw_info);
361 clk_mgr_dce->dentist_vco_freq_khz = fw_info.smu_gpu_pll_output_freq;
362 if (clk_mgr_dce->dentist_vco_freq_khz == 0)
363 clk_mgr_dce->dentist_vco_freq_khz = 3600000;
366 if (!debug->disable_dfs_bypass && bp->integrated_info)
367 if (bp->integrated_info->gpu_cap_info & DFS_BYPASS_ENABLE)
368 clk_mgr_dce->dfs_bypass_enabled = true;
370 dce_clock_read_ss_info(clk_mgr_dce);
372 return &clk_mgr_dce->base;