dce_clocks.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. #include "dce_clocks.h"
  26. #include "dm_services.h"
  27. #include "reg_helper.h"
  28. #include "fixed31_32.h"
  29. #include "bios_parser_interface.h"
  30. #include "dc.h"
  31. #include "dmcu.h"
  32. #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
  33. #include "dcn_calcs.h"
  34. #endif
  35. #include "core_types.h"
  36. #include "dc_types.h"
  37. #include "dal_asic_id.h"
  38. #define TO_DCE_CLOCKS(clocks)\
  39. container_of(clocks, struct dce_disp_clk, base)
  40. #define REG(reg) \
  41. (clk_dce->regs->reg)
  42. #undef FN
  43. #define FN(reg_name, field_name) \
  44. clk_dce->clk_shift->field_name, clk_dce->clk_mask->field_name
  45. #define CTX \
  46. clk_dce->base.ctx
  47. #define DC_LOGGER \
  48. clk->ctx->logger
  49. /* Max clock values for each state indexed by "enum clocks_state": */
  50. static const struct state_dependent_clocks dce80_max_clks_by_state[] = {
  51. /* ClocksStateInvalid - should not be used */
  52. { .display_clk_khz = 0, .pixel_clk_khz = 0 },
  53. /* ClocksStateUltraLow - not expected to be used for DCE 8.0 */
  54. { .display_clk_khz = 0, .pixel_clk_khz = 0 },
  55. /* ClocksStateLow */
  56. { .display_clk_khz = 352000, .pixel_clk_khz = 330000},
  57. /* ClocksStateNominal */
  58. { .display_clk_khz = 600000, .pixel_clk_khz = 400000 },
  59. /* ClocksStatePerformance */
  60. { .display_clk_khz = 600000, .pixel_clk_khz = 400000 } };
  61. static const struct state_dependent_clocks dce110_max_clks_by_state[] = {
  62. /*ClocksStateInvalid - should not be used*/
  63. { .display_clk_khz = 0, .pixel_clk_khz = 0 },
  64. /*ClocksStateUltraLow - currently by HW design team not supposed to be used*/
  65. { .display_clk_khz = 352000, .pixel_clk_khz = 330000 },
  66. /*ClocksStateLow*/
  67. { .display_clk_khz = 352000, .pixel_clk_khz = 330000 },
  68. /*ClocksStateNominal*/
  69. { .display_clk_khz = 467000, .pixel_clk_khz = 400000 },
  70. /*ClocksStatePerformance*/
  71. { .display_clk_khz = 643000, .pixel_clk_khz = 400000 } };
  72. static const struct state_dependent_clocks dce112_max_clks_by_state[] = {
  73. /*ClocksStateInvalid - should not be used*/
  74. { .display_clk_khz = 0, .pixel_clk_khz = 0 },
  75. /*ClocksStateUltraLow - currently by HW design team not supposed to be used*/
  76. { .display_clk_khz = 389189, .pixel_clk_khz = 346672 },
  77. /*ClocksStateLow*/
  78. { .display_clk_khz = 459000, .pixel_clk_khz = 400000 },
  79. /*ClocksStateNominal*/
  80. { .display_clk_khz = 667000, .pixel_clk_khz = 600000 },
  81. /*ClocksStatePerformance*/
  82. { .display_clk_khz = 1132000, .pixel_clk_khz = 600000 } };
  83. static const struct state_dependent_clocks dce120_max_clks_by_state[] = {
  84. /*ClocksStateInvalid - should not be used*/
  85. { .display_clk_khz = 0, .pixel_clk_khz = 0 },
  86. /*ClocksStateUltraLow - currently by HW design team not supposed to be used*/
  87. { .display_clk_khz = 0, .pixel_clk_khz = 0 },
  88. /*ClocksStateLow*/
  89. { .display_clk_khz = 460000, .pixel_clk_khz = 400000 },
  90. /*ClocksStateNominal*/
  91. { .display_clk_khz = 670000, .pixel_clk_khz = 600000 },
  92. /*ClocksStatePerformance*/
  93. { .display_clk_khz = 1133000, .pixel_clk_khz = 600000 } };
  94. /* Starting point for each divider range.*/
  95. enum dce_divider_range_start {
  96. DIVIDER_RANGE_01_START = 200, /* 2.00*/
  97. DIVIDER_RANGE_02_START = 1600, /* 16.00*/
  98. DIVIDER_RANGE_03_START = 3200, /* 32.00*/
  99. DIVIDER_RANGE_SCALE_FACTOR = 100 /* Results are scaled up by 100.*/
  100. };
  101. /* Ranges for divider identifiers (Divider ID or DID)
  102. mmDENTIST_DISPCLK_CNTL.DENTIST_DISPCLK_WDIVIDER*/
  103. enum dce_divider_id_register_setting {
  104. DIVIDER_RANGE_01_BASE_DIVIDER_ID = 0X08,
  105. DIVIDER_RANGE_02_BASE_DIVIDER_ID = 0X40,
  106. DIVIDER_RANGE_03_BASE_DIVIDER_ID = 0X60,
  107. DIVIDER_RANGE_MAX_DIVIDER_ID = 0X80
  108. };
  109. /* Step size between each divider within a range.
  110. Incrementing the DENTIST_DISPCLK_WDIVIDER by one
  111. will increment the divider by this much.*/
  112. enum dce_divider_range_step_size {
  113. DIVIDER_RANGE_01_STEP_SIZE = 25, /* 0.25*/
  114. DIVIDER_RANGE_02_STEP_SIZE = 50, /* 0.50*/
  115. DIVIDER_RANGE_03_STEP_SIZE = 100 /* 1.00 */
  116. };
  117. static bool dce_divider_range_construct(
  118. struct dce_divider_range *div_range,
  119. int range_start,
  120. int range_step,
  121. int did_min,
  122. int did_max)
  123. {
  124. div_range->div_range_start = range_start;
  125. div_range->div_range_step = range_step;
  126. div_range->did_min = did_min;
  127. div_range->did_max = did_max;
  128. if (div_range->div_range_step == 0) {
  129. div_range->div_range_step = 1;
  130. /*div_range_step cannot be zero*/
  131. BREAK_TO_DEBUGGER();
  132. }
  133. /* Calculate this based on the other inputs.*/
  134. /* See DividerRange.h for explanation of */
  135. /* the relationship between divider id (DID) and a divider.*/
  136. /* Number of Divider IDs = (Maximum Divider ID - Minimum Divider ID)*/
  137. /* Maximum divider identified in this range =
  138. * (Number of Divider IDs)*Step size between dividers
  139. * + The start of this range.*/
  140. div_range->div_range_end = (did_max - did_min) * range_step
  141. + range_start;
  142. return true;
  143. }
  144. static int dce_divider_range_calc_divider(
  145. struct dce_divider_range *div_range,
  146. int did)
  147. {
  148. /* Is this DID within our range?*/
  149. if ((did < div_range->did_min) || (did >= div_range->did_max))
  150. return INVALID_DIVIDER;
  151. return ((did - div_range->did_min) * div_range->div_range_step)
  152. + div_range->div_range_start;
  153. }
  154. static int dce_divider_range_get_divider(
  155. struct dce_divider_range *div_range,
  156. int ranges_num,
  157. int did)
  158. {
  159. int div = INVALID_DIVIDER;
  160. int i;
  161. for (i = 0; i < ranges_num; i++) {
  162. /* Calculate divider with given divider ID*/
  163. div = dce_divider_range_calc_divider(&div_range[i], did);
  164. /* Found a valid return divider*/
  165. if (div != INVALID_DIVIDER)
  166. break;
  167. }
  168. return div;
  169. }
  170. static int dce_clocks_get_dp_ref_freq(struct display_clock *clk)
  171. {
  172. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(clk);
  173. int dprefclk_wdivider;
  174. int dprefclk_src_sel;
  175. int dp_ref_clk_khz = 600000;
  176. int target_div = INVALID_DIVIDER;
  177. /* ASSERT DP Reference Clock source is from DFS*/
  178. REG_GET(DPREFCLK_CNTL, DPREFCLK_SRC_SEL, &dprefclk_src_sel);
  179. ASSERT(dprefclk_src_sel == 0);
  180. /* Read the mmDENTIST_DISPCLK_CNTL to get the currently
  181. * programmed DID DENTIST_DPREFCLK_WDIVIDER*/
  182. REG_GET(DENTIST_DISPCLK_CNTL, DENTIST_DPREFCLK_WDIVIDER, &dprefclk_wdivider);
  183. /* Convert DENTIST_DPREFCLK_WDIVIDERto actual divider*/
  184. target_div = dce_divider_range_get_divider(
  185. clk_dce->divider_ranges,
  186. DIVIDER_RANGE_MAX,
  187. dprefclk_wdivider);
  188. if (target_div != INVALID_DIVIDER) {
  189. /* Calculate the current DFS clock, in kHz.*/
  190. dp_ref_clk_khz = (DIVIDER_RANGE_SCALE_FACTOR
  191. * clk_dce->dentist_vco_freq_khz) / target_div;
  192. }
  193. /* SW will adjust DP REF Clock average value for all purposes
  194. * (DP DTO / DP Audio DTO and DP GTC)
  195. if clock is spread for all cases:
  196. -if SS enabled on DP Ref clock and HW de-spreading enabled with SW
  197. calculations for DS_INCR/DS_MODULO (this is planned to be default case)
  198. -if SS enabled on DP Ref clock and HW de-spreading enabled with HW
  199. calculations (not planned to be used, but average clock should still
  200. be valid)
  201. -if SS enabled on DP Ref clock and HW de-spreading disabled
  202. (should not be case with CIK) then SW should program all rates
  203. generated according to average value (case as with previous ASICs)
  204. */
  205. if (clk_dce->ss_on_dprefclk && clk_dce->dprefclk_ss_divider != 0) {
  206. struct fixed31_32 ss_percentage = dc_fixpt_div_int(
  207. dc_fixpt_from_fraction(
  208. clk_dce->dprefclk_ss_percentage,
  209. clk_dce->dprefclk_ss_divider), 200);
  210. struct fixed31_32 adj_dp_ref_clk_khz;
  211. ss_percentage = dc_fixpt_sub(dc_fixpt_one,
  212. ss_percentage);
  213. adj_dp_ref_clk_khz =
  214. dc_fixpt_mul_int(
  215. ss_percentage,
  216. dp_ref_clk_khz);
  217. dp_ref_clk_khz = dc_fixpt_floor(adj_dp_ref_clk_khz);
  218. }
  219. return dp_ref_clk_khz;
  220. }
  221. /* TODO: This is DCN DPREFCLK: it could be program by DENTIST by VBIOS
  222. * or CLK0_CLK11 by SMU. For DCE120, it is wlays 600Mhz. Will re-visit
  223. * clock implementation
  224. */
  225. static int dce_clocks_get_dp_ref_freq_wrkaround(struct display_clock *clk)
  226. {
  227. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(clk);
  228. int dp_ref_clk_khz = 600000;
  229. if (clk_dce->ss_on_dprefclk && clk_dce->dprefclk_ss_divider != 0) {
  230. struct fixed31_32 ss_percentage = dc_fixpt_div_int(
  231. dc_fixpt_from_fraction(
  232. clk_dce->dprefclk_ss_percentage,
  233. clk_dce->dprefclk_ss_divider), 200);
  234. struct fixed31_32 adj_dp_ref_clk_khz;
  235. ss_percentage = dc_fixpt_sub(dc_fixpt_one,
  236. ss_percentage);
  237. adj_dp_ref_clk_khz =
  238. dc_fixpt_mul_int(
  239. ss_percentage,
  240. dp_ref_clk_khz);
  241. dp_ref_clk_khz = dc_fixpt_floor(adj_dp_ref_clk_khz);
  242. }
  243. return dp_ref_clk_khz;
  244. }
  245. static enum dm_pp_clocks_state dce_get_required_clocks_state(
  246. struct display_clock *clk,
  247. struct state_dependent_clocks *req_clocks)
  248. {
  249. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(clk);
  250. int i;
  251. enum dm_pp_clocks_state low_req_clk;
  252. /* Iterate from highest supported to lowest valid state, and update
  253. * lowest RequiredState with the lowest state that satisfies
  254. * all required clocks
  255. */
  256. for (i = clk->max_clks_state; i >= DM_PP_CLOCKS_STATE_ULTRA_LOW; i--)
  257. if (req_clocks->display_clk_khz >
  258. clk_dce->max_clks_by_state[i].display_clk_khz
  259. || req_clocks->pixel_clk_khz >
  260. clk_dce->max_clks_by_state[i].pixel_clk_khz)
  261. break;
  262. low_req_clk = i + 1;
  263. if (low_req_clk > clk->max_clks_state) {
  264. DC_LOG_WARNING("%s: clocks unsupported disp_clk %d pix_clk %d",
  265. __func__,
  266. req_clocks->display_clk_khz,
  267. req_clocks->pixel_clk_khz);
  268. low_req_clk = DM_PP_CLOCKS_STATE_INVALID;
  269. }
  270. return low_req_clk;
  271. }
  272. static bool dce_clock_set_min_clocks_state(
  273. struct display_clock *clk,
  274. enum dm_pp_clocks_state clocks_state)
  275. {
  276. struct dm_pp_power_level_change_request level_change_req = {
  277. clocks_state };
  278. if (clocks_state > clk->max_clks_state) {
  279. /*Requested state exceeds max supported state.*/
  280. DC_LOG_WARNING("Requested state exceeds max supported state");
  281. return false;
  282. } else if (clocks_state == clk->cur_min_clks_state) {
  283. /*if we're trying to set the same state, we can just return
  284. * since nothing needs to be done*/
  285. return true;
  286. }
  287. /* get max clock state from PPLIB */
  288. if (dm_pp_apply_power_level_change_request(clk->ctx, &level_change_req))
  289. clk->cur_min_clks_state = clocks_state;
  290. return true;
  291. }
  292. static int dce_set_clock(
  293. struct display_clock *clk,
  294. int requested_clk_khz)
  295. {
  296. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(clk);
  297. struct bp_pixel_clock_parameters pxl_clk_params = { 0 };
  298. struct dc_bios *bp = clk->ctx->dc_bios;
  299. int actual_clock = requested_clk_khz;
  300. /* Make sure requested clock isn't lower than minimum threshold*/
  301. if (requested_clk_khz > 0)
  302. requested_clk_khz = max(requested_clk_khz,
  303. clk_dce->dentist_vco_freq_khz / 64);
  304. /* Prepare to program display clock*/
  305. pxl_clk_params.target_pixel_clock = requested_clk_khz;
  306. pxl_clk_params.pll_id = CLOCK_SOURCE_ID_DFS;
  307. bp->funcs->program_display_engine_pll(bp, &pxl_clk_params);
  308. if (clk_dce->dfs_bypass_enabled) {
  309. /* Cache the fixed display clock*/
  310. clk_dce->dfs_bypass_disp_clk =
  311. pxl_clk_params.dfs_bypass_display_clock;
  312. actual_clock = pxl_clk_params.dfs_bypass_display_clock;
  313. }
  314. /* from power down, we need mark the clock state as ClocksStateNominal
  315. * from HWReset, so when resume we will call pplib voltage regulator.*/
  316. if (requested_clk_khz == 0)
  317. clk->cur_min_clks_state = DM_PP_CLOCKS_STATE_NOMINAL;
  318. return actual_clock;
  319. }
  320. static int dce_psr_set_clock(
  321. struct display_clock *clk,
  322. int requested_clk_khz)
  323. {
  324. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(clk);
  325. struct dc_context *ctx = clk_dce->base.ctx;
  326. struct dc *core_dc = ctx->dc;
  327. struct dmcu *dmcu = core_dc->res_pool->dmcu;
  328. int actual_clk_khz = requested_clk_khz;
  329. actual_clk_khz = dce_set_clock(clk, requested_clk_khz);
  330. dmcu->funcs->set_psr_wait_loop(dmcu, actual_clk_khz / 1000 / 7);
  331. return actual_clk_khz;
  332. }
  333. static int dce112_set_clock(
  334. struct display_clock *clk,
  335. int requested_clk_khz)
  336. {
  337. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(clk);
  338. struct bp_set_dce_clock_parameters dce_clk_params;
  339. struct dc_bios *bp = clk->ctx->dc_bios;
  340. struct dc *core_dc = clk->ctx->dc;
  341. struct dmcu *dmcu = core_dc->res_pool->dmcu;
  342. int actual_clock = requested_clk_khz;
  343. /* Prepare to program display clock*/
  344. memset(&dce_clk_params, 0, sizeof(dce_clk_params));
  345. /* Make sure requested clock isn't lower than minimum threshold*/
  346. if (requested_clk_khz > 0)
  347. requested_clk_khz = max(requested_clk_khz,
  348. clk_dce->dentist_vco_freq_khz / 62);
  349. dce_clk_params.target_clock_frequency = requested_clk_khz;
  350. dce_clk_params.pll_id = CLOCK_SOURCE_ID_DFS;
  351. dce_clk_params.clock_type = DCECLOCK_TYPE_DISPLAY_CLOCK;
  352. bp->funcs->set_dce_clock(bp, &dce_clk_params);
  353. actual_clock = dce_clk_params.target_clock_frequency;
  354. /* from power down, we need mark the clock state as ClocksStateNominal
  355. * from HWReset, so when resume we will call pplib voltage regulator.*/
  356. if (requested_clk_khz == 0)
  357. clk->cur_min_clks_state = DM_PP_CLOCKS_STATE_NOMINAL;
  358. /*Program DP ref Clock*/
  359. /*VBIOS will determine DPREFCLK frequency, so we don't set it*/
  360. dce_clk_params.target_clock_frequency = 0;
  361. dce_clk_params.clock_type = DCECLOCK_TYPE_DPREFCLK;
  362. if (!ASICREV_IS_VEGA20_P(clk->ctx->asic_id.hw_internal_rev))
  363. dce_clk_params.flags.USE_GENLOCK_AS_SOURCE_FOR_DPREFCLK =
  364. (dce_clk_params.pll_id ==
  365. CLOCK_SOURCE_COMBO_DISPLAY_PLL0);
  366. else
  367. dce_clk_params.flags.USE_GENLOCK_AS_SOURCE_FOR_DPREFCLK = false;
  368. bp->funcs->set_dce_clock(bp, &dce_clk_params);
  369. if (!IS_FPGA_MAXIMUS_DC(core_dc->ctx->dce_environment)) {
  370. if (clk_dce->dfs_bypass_disp_clk != actual_clock)
  371. dmcu->funcs->set_psr_wait_loop(dmcu,
  372. actual_clock / 1000 / 7);
  373. }
  374. clk_dce->dfs_bypass_disp_clk = actual_clock;
  375. return actual_clock;
  376. }
  377. static void dce_clock_read_integrated_info(struct dce_disp_clk *clk_dce)
  378. {
  379. struct dc_debug *debug = &clk_dce->base.ctx->dc->debug;
  380. struct dc_bios *bp = clk_dce->base.ctx->dc_bios;
  381. struct integrated_info info = { { { 0 } } };
  382. struct dc_firmware_info fw_info = { { 0 } };
  383. int i;
  384. if (bp->integrated_info)
  385. info = *bp->integrated_info;
  386. clk_dce->dentist_vco_freq_khz = info.dentist_vco_freq;
  387. if (clk_dce->dentist_vco_freq_khz == 0) {
  388. bp->funcs->get_firmware_info(bp, &fw_info);
  389. clk_dce->dentist_vco_freq_khz =
  390. fw_info.smu_gpu_pll_output_freq;
  391. if (clk_dce->dentist_vco_freq_khz == 0)
  392. clk_dce->dentist_vco_freq_khz = 3600000;
  393. }
  394. /*update the maximum display clock for each power state*/
  395. for (i = 0; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
  396. enum dm_pp_clocks_state clk_state = DM_PP_CLOCKS_STATE_INVALID;
  397. switch (i) {
  398. case 0:
  399. clk_state = DM_PP_CLOCKS_STATE_ULTRA_LOW;
  400. break;
  401. case 1:
  402. clk_state = DM_PP_CLOCKS_STATE_LOW;
  403. break;
  404. case 2:
  405. clk_state = DM_PP_CLOCKS_STATE_NOMINAL;
  406. break;
  407. case 3:
  408. clk_state = DM_PP_CLOCKS_STATE_PERFORMANCE;
  409. break;
  410. default:
  411. clk_state = DM_PP_CLOCKS_STATE_INVALID;
  412. break;
  413. }
  414. /*Do not allow bad VBIOS/SBIOS to override with invalid values,
  415. * check for > 100MHz*/
  416. if (info.disp_clk_voltage[i].max_supported_clk >= 100000)
  417. clk_dce->max_clks_by_state[clk_state].display_clk_khz =
  418. info.disp_clk_voltage[i].max_supported_clk;
  419. }
  420. if (!debug->disable_dfs_bypass && bp->integrated_info)
  421. if (bp->integrated_info->gpu_cap_info & DFS_BYPASS_ENABLE)
  422. clk_dce->dfs_bypass_enabled = true;
  423. clk_dce->use_max_disp_clk = debug->max_disp_clk;
  424. }
  425. static void dce_clock_read_ss_info(struct dce_disp_clk *clk_dce)
  426. {
  427. struct dc_bios *bp = clk_dce->base.ctx->dc_bios;
  428. int ss_info_num = bp->funcs->get_ss_entry_number(
  429. bp, AS_SIGNAL_TYPE_GPU_PLL);
  430. if (ss_info_num) {
  431. struct spread_spectrum_info info = { { 0 } };
  432. enum bp_result result = bp->funcs->get_spread_spectrum_info(
  433. bp, AS_SIGNAL_TYPE_GPU_PLL, 0, &info);
  434. /* Based on VBIOS, VBIOS will keep entry for GPU PLL SS
  435. * even if SS not enabled and in that case
  436. * SSInfo.spreadSpectrumPercentage !=0 would be sign
  437. * that SS is enabled
  438. */
  439. if (result == BP_RESULT_OK &&
  440. info.spread_spectrum_percentage != 0) {
  441. clk_dce->ss_on_dprefclk = true;
  442. clk_dce->dprefclk_ss_divider = info.spread_percentage_divider;
  443. if (info.type.CENTER_MODE == 0) {
  444. /* TODO: Currently for DP Reference clock we
  445. * need only SS percentage for
  446. * downspread */
  447. clk_dce->dprefclk_ss_percentage =
  448. info.spread_spectrum_percentage;
  449. }
  450. return;
  451. }
  452. result = bp->funcs->get_spread_spectrum_info(
  453. bp, AS_SIGNAL_TYPE_DISPLAY_PORT, 0, &info);
  454. /* Based on VBIOS, VBIOS will keep entry for DPREFCLK SS
  455. * even if SS not enabled and in that case
  456. * SSInfo.spreadSpectrumPercentage !=0 would be sign
  457. * that SS is enabled
  458. */
  459. if (result == BP_RESULT_OK &&
  460. info.spread_spectrum_percentage != 0) {
  461. clk_dce->ss_on_dprefclk = true;
  462. clk_dce->dprefclk_ss_divider = info.spread_percentage_divider;
  463. if (info.type.CENTER_MODE == 0) {
  464. /* Currently for DP Reference clock we
  465. * need only SS percentage for
  466. * downspread */
  467. clk_dce->dprefclk_ss_percentage =
  468. info.spread_spectrum_percentage;
  469. }
  470. }
  471. }
  472. }
  473. static bool dce_apply_clock_voltage_request(
  474. struct display_clock *clk,
  475. enum dm_pp_clock_type clocks_type,
  476. int clocks_in_khz,
  477. bool pre_mode_set,
  478. bool update_dp_phyclk)
  479. {
  480. bool send_request = false;
  481. struct dm_pp_clock_for_voltage_req clock_voltage_req = {0};
  482. switch (clocks_type) {
  483. case DM_PP_CLOCK_TYPE_DISPLAY_CLK:
  484. case DM_PP_CLOCK_TYPE_PIXELCLK:
  485. case DM_PP_CLOCK_TYPE_DISPLAYPHYCLK:
  486. break;
  487. default:
  488. BREAK_TO_DEBUGGER();
  489. return false;
  490. }
  491. clock_voltage_req.clk_type = clocks_type;
  492. clock_voltage_req.clocks_in_khz = clocks_in_khz;
  493. /* to pplib */
  494. if (pre_mode_set) {
  495. switch (clocks_type) {
  496. case DM_PP_CLOCK_TYPE_DISPLAY_CLK:
  497. if (clocks_in_khz > clk->cur_clocks_value.dispclk_in_khz) {
  498. clk->cur_clocks_value.dispclk_notify_pplib_done = true;
  499. send_request = true;
  500. } else
  501. clk->cur_clocks_value.dispclk_notify_pplib_done = false;
  502. /* no matter incrase or decrase clock, update current clock value */
  503. clk->cur_clocks_value.dispclk_in_khz = clocks_in_khz;
  504. break;
  505. case DM_PP_CLOCK_TYPE_PIXELCLK:
  506. if (clocks_in_khz > clk->cur_clocks_value.max_pixelclk_in_khz) {
  507. clk->cur_clocks_value.pixelclk_notify_pplib_done = true;
  508. send_request = true;
  509. } else
  510. clk->cur_clocks_value.pixelclk_notify_pplib_done = false;
  511. /* no matter incrase or decrase clock, update current clock value */
  512. clk->cur_clocks_value.max_pixelclk_in_khz = clocks_in_khz;
  513. break;
  514. case DM_PP_CLOCK_TYPE_DISPLAYPHYCLK:
  515. if (clocks_in_khz > clk->cur_clocks_value.max_non_dp_phyclk_in_khz) {
  516. clk->cur_clocks_value.phyclk_notigy_pplib_done = true;
  517. send_request = true;
  518. } else
  519. clk->cur_clocks_value.phyclk_notigy_pplib_done = false;
  520. /* no matter incrase or decrase clock, update current clock value */
  521. clk->cur_clocks_value.max_non_dp_phyclk_in_khz = clocks_in_khz;
  522. break;
  523. default:
  524. ASSERT(0);
  525. break;
  526. }
  527. } else {
  528. switch (clocks_type) {
  529. case DM_PP_CLOCK_TYPE_DISPLAY_CLK:
  530. if (!clk->cur_clocks_value.dispclk_notify_pplib_done)
  531. send_request = true;
  532. break;
  533. case DM_PP_CLOCK_TYPE_PIXELCLK:
  534. if (!clk->cur_clocks_value.pixelclk_notify_pplib_done)
  535. send_request = true;
  536. break;
  537. case DM_PP_CLOCK_TYPE_DISPLAYPHYCLK:
  538. if (!clk->cur_clocks_value.phyclk_notigy_pplib_done)
  539. send_request = true;
  540. break;
  541. default:
  542. ASSERT(0);
  543. break;
  544. }
  545. }
  546. if (send_request) {
  547. #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
  548. if (clk->ctx->dce_version >= DCN_VERSION_1_0) {
  549. struct dc *core_dc = clk->ctx->dc;
  550. /*use dcfclk request voltage*/
  551. clock_voltage_req.clk_type = DM_PP_CLOCK_TYPE_DCFCLK;
  552. clock_voltage_req.clocks_in_khz =
  553. dcn_find_dcfclk_suits_all(core_dc, &clk->cur_clocks_value);
  554. }
  555. #endif
  556. dm_pp_apply_clock_for_voltage_request(
  557. clk->ctx, &clock_voltage_req);
  558. }
  559. if (update_dp_phyclk && (clocks_in_khz >
  560. clk->cur_clocks_value.max_dp_phyclk_in_khz))
  561. clk->cur_clocks_value.max_dp_phyclk_in_khz = clocks_in_khz;
  562. return true;
  563. }
  564. static const struct display_clock_funcs dce120_funcs = {
  565. .get_dp_ref_clk_frequency = dce_clocks_get_dp_ref_freq_wrkaround,
  566. .apply_clock_voltage_request = dce_apply_clock_voltage_request,
  567. .set_clock = dce112_set_clock
  568. };
  569. static const struct display_clock_funcs dce112_funcs = {
  570. .get_dp_ref_clk_frequency = dce_clocks_get_dp_ref_freq,
  571. .get_required_clocks_state = dce_get_required_clocks_state,
  572. .set_min_clocks_state = dce_clock_set_min_clocks_state,
  573. .set_clock = dce112_set_clock
  574. };
  575. static const struct display_clock_funcs dce110_funcs = {
  576. .get_dp_ref_clk_frequency = dce_clocks_get_dp_ref_freq,
  577. .get_required_clocks_state = dce_get_required_clocks_state,
  578. .set_min_clocks_state = dce_clock_set_min_clocks_state,
  579. .set_clock = dce_psr_set_clock
  580. };
  581. static const struct display_clock_funcs dce_funcs = {
  582. .get_dp_ref_clk_frequency = dce_clocks_get_dp_ref_freq,
  583. .get_required_clocks_state = dce_get_required_clocks_state,
  584. .set_min_clocks_state = dce_clock_set_min_clocks_state,
  585. .set_clock = dce_set_clock
  586. };
  587. static void dce_disp_clk_construct(
  588. struct dce_disp_clk *clk_dce,
  589. struct dc_context *ctx,
  590. const struct dce_disp_clk_registers *regs,
  591. const struct dce_disp_clk_shift *clk_shift,
  592. const struct dce_disp_clk_mask *clk_mask)
  593. {
  594. struct display_clock *base = &clk_dce->base;
  595. base->ctx = ctx;
  596. base->funcs = &dce_funcs;
  597. clk_dce->regs = regs;
  598. clk_dce->clk_shift = clk_shift;
  599. clk_dce->clk_mask = clk_mask;
  600. clk_dce->dfs_bypass_disp_clk = 0;
  601. clk_dce->dprefclk_ss_percentage = 0;
  602. clk_dce->dprefclk_ss_divider = 1000;
  603. clk_dce->ss_on_dprefclk = false;
  604. base->max_clks_state = DM_PP_CLOCKS_STATE_NOMINAL;
  605. base->cur_min_clks_state = DM_PP_CLOCKS_STATE_INVALID;
  606. dce_clock_read_integrated_info(clk_dce);
  607. dce_clock_read_ss_info(clk_dce);
  608. dce_divider_range_construct(
  609. &clk_dce->divider_ranges[DIVIDER_RANGE_01],
  610. DIVIDER_RANGE_01_START,
  611. DIVIDER_RANGE_01_STEP_SIZE,
  612. DIVIDER_RANGE_01_BASE_DIVIDER_ID,
  613. DIVIDER_RANGE_02_BASE_DIVIDER_ID);
  614. dce_divider_range_construct(
  615. &clk_dce->divider_ranges[DIVIDER_RANGE_02],
  616. DIVIDER_RANGE_02_START,
  617. DIVIDER_RANGE_02_STEP_SIZE,
  618. DIVIDER_RANGE_02_BASE_DIVIDER_ID,
  619. DIVIDER_RANGE_03_BASE_DIVIDER_ID);
  620. dce_divider_range_construct(
  621. &clk_dce->divider_ranges[DIVIDER_RANGE_03],
  622. DIVIDER_RANGE_03_START,
  623. DIVIDER_RANGE_03_STEP_SIZE,
  624. DIVIDER_RANGE_03_BASE_DIVIDER_ID,
  625. DIVIDER_RANGE_MAX_DIVIDER_ID);
  626. }
  627. struct display_clock *dce_disp_clk_create(
  628. struct dc_context *ctx,
  629. const struct dce_disp_clk_registers *regs,
  630. const struct dce_disp_clk_shift *clk_shift,
  631. const struct dce_disp_clk_mask *clk_mask)
  632. {
  633. struct dce_disp_clk *clk_dce = kzalloc(sizeof(*clk_dce), GFP_KERNEL);
  634. if (clk_dce == NULL) {
  635. BREAK_TO_DEBUGGER();
  636. return NULL;
  637. }
  638. memcpy(clk_dce->max_clks_by_state,
  639. dce80_max_clks_by_state,
  640. sizeof(dce80_max_clks_by_state));
  641. dce_disp_clk_construct(
  642. clk_dce, ctx, regs, clk_shift, clk_mask);
  643. return &clk_dce->base;
  644. }
  645. struct display_clock *dce110_disp_clk_create(
  646. struct dc_context *ctx,
  647. const struct dce_disp_clk_registers *regs,
  648. const struct dce_disp_clk_shift *clk_shift,
  649. const struct dce_disp_clk_mask *clk_mask)
  650. {
  651. struct dce_disp_clk *clk_dce = kzalloc(sizeof(*clk_dce), GFP_KERNEL);
  652. if (clk_dce == NULL) {
  653. BREAK_TO_DEBUGGER();
  654. return NULL;
  655. }
  656. memcpy(clk_dce->max_clks_by_state,
  657. dce110_max_clks_by_state,
  658. sizeof(dce110_max_clks_by_state));
  659. dce_disp_clk_construct(
  660. clk_dce, ctx, regs, clk_shift, clk_mask);
  661. clk_dce->base.funcs = &dce110_funcs;
  662. return &clk_dce->base;
  663. }
  664. struct display_clock *dce112_disp_clk_create(
  665. struct dc_context *ctx,
  666. const struct dce_disp_clk_registers *regs,
  667. const struct dce_disp_clk_shift *clk_shift,
  668. const struct dce_disp_clk_mask *clk_mask)
  669. {
  670. struct dce_disp_clk *clk_dce = kzalloc(sizeof(*clk_dce), GFP_KERNEL);
  671. if (clk_dce == NULL) {
  672. BREAK_TO_DEBUGGER();
  673. return NULL;
  674. }
  675. memcpy(clk_dce->max_clks_by_state,
  676. dce112_max_clks_by_state,
  677. sizeof(dce112_max_clks_by_state));
  678. dce_disp_clk_construct(
  679. clk_dce, ctx, regs, clk_shift, clk_mask);
  680. clk_dce->base.funcs = &dce112_funcs;
  681. return &clk_dce->base;
  682. }
  683. struct display_clock *dce120_disp_clk_create(struct dc_context *ctx)
  684. {
  685. struct dce_disp_clk *clk_dce = kzalloc(sizeof(*clk_dce), GFP_KERNEL);
  686. struct dm_pp_clock_levels_with_voltage clk_level_info = {0};
  687. if (clk_dce == NULL) {
  688. BREAK_TO_DEBUGGER();
  689. return NULL;
  690. }
  691. memcpy(clk_dce->max_clks_by_state,
  692. dce120_max_clks_by_state,
  693. sizeof(dce120_max_clks_by_state));
  694. dce_disp_clk_construct(
  695. clk_dce, ctx, NULL, NULL, NULL);
  696. clk_dce->base.funcs = &dce120_funcs;
  697. /* new in dce120 */
  698. if (!ctx->dc->debug.disable_pplib_clock_request &&
  699. dm_pp_get_clock_levels_by_type_with_voltage(
  700. ctx, DM_PP_CLOCK_TYPE_DISPLAY_CLK, &clk_level_info)
  701. && clk_level_info.num_levels)
  702. clk_dce->max_displ_clk_in_khz =
  703. clk_level_info.data[clk_level_info.num_levels - 1].clocks_in_khz;
  704. else
  705. clk_dce->max_displ_clk_in_khz = 1133000;
  706. return &clk_dce->base;
  707. }
  708. void dce_disp_clk_destroy(struct display_clock **disp_clk)
  709. {
  710. struct dce_disp_clk *clk_dce = TO_DCE_CLOCKS(*disp_clk);
  711. kfree(clk_dce);
  712. *disp_clk = NULL;
  713. }