dce_clocks.c 25 KB

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