command_table2.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /*
  2. * Copyright 2012-15 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 "dm_services.h"
  26. #include "ObjectID.h"
  27. #include "atomfirmware.h"
  28. #include "atom.h"
  29. #include "include/bios_parser_interface.h"
  30. #include "command_table2.h"
  31. #include "command_table_helper2.h"
  32. #include "bios_parser_helper.h"
  33. #include "bios_parser_types_internal2.h"
  34. #include "amdgpu.h"
  35. #define DC_LOGGER \
  36. bp->base.ctx->logger
  37. #define GET_INDEX_INTO_MASTER_TABLE(MasterOrData, FieldName)\
  38. (((char *)(&((\
  39. struct atom_master_list_of_##MasterOrData##_functions_v2_1 *)0)\
  40. ->FieldName)-(char *)0)/sizeof(uint16_t))
  41. #define EXEC_BIOS_CMD_TABLE(fname, params)\
  42. (amdgpu_atom_execute_table(((struct amdgpu_device *)bp->base.ctx->driver_context)->mode_info.atom_context, \
  43. GET_INDEX_INTO_MASTER_TABLE(command, fname), \
  44. (uint32_t *)&params) == 0)
  45. #define BIOS_CMD_TABLE_REVISION(fname, frev, crev)\
  46. amdgpu_atom_parse_cmd_header(((struct amdgpu_device *)bp->base.ctx->driver_context)->mode_info.atom_context, \
  47. GET_INDEX_INTO_MASTER_TABLE(command, fname), &frev, &crev)
  48. #define BIOS_CMD_TABLE_PARA_REVISION(fname)\
  49. bios_cmd_table_para_revision(bp->base.ctx->driver_context, \
  50. GET_INDEX_INTO_MASTER_TABLE(command, fname))
  51. static void init_dig_encoder_control(struct bios_parser *bp);
  52. static void init_transmitter_control(struct bios_parser *bp);
  53. static void init_set_pixel_clock(struct bios_parser *bp);
  54. static void init_set_crtc_timing(struct bios_parser *bp);
  55. static void init_select_crtc_source(struct bios_parser *bp);
  56. static void init_enable_crtc(struct bios_parser *bp);
  57. static void init_external_encoder_control(struct bios_parser *bp);
  58. static void init_enable_disp_power_gating(struct bios_parser *bp);
  59. static void init_set_dce_clock(struct bios_parser *bp);
  60. static void init_get_smu_clock_info(struct bios_parser *bp);
  61. void dal_firmware_parser_init_cmd_tbl(struct bios_parser *bp)
  62. {
  63. init_dig_encoder_control(bp);
  64. init_transmitter_control(bp);
  65. init_set_pixel_clock(bp);
  66. init_set_crtc_timing(bp);
  67. init_select_crtc_source(bp);
  68. init_enable_crtc(bp);
  69. init_external_encoder_control(bp);
  70. init_enable_disp_power_gating(bp);
  71. init_set_dce_clock(bp);
  72. init_get_smu_clock_info(bp);
  73. }
  74. static uint32_t bios_cmd_table_para_revision(void *dev,
  75. uint32_t index)
  76. {
  77. struct amdgpu_device *adev = dev;
  78. uint8_t frev, crev;
  79. if (amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context,
  80. index,
  81. &frev, &crev))
  82. return crev;
  83. else
  84. return 0;
  85. }
  86. /******************************************************************************
  87. ******************************************************************************
  88. **
  89. ** D I G E N C O D E R C O N T R O L
  90. **
  91. ******************************************************************************
  92. *****************************************************************************/
  93. static enum bp_result encoder_control_digx_v1_5(
  94. struct bios_parser *bp,
  95. struct bp_encoder_control *cntl);
  96. static void init_dig_encoder_control(struct bios_parser *bp)
  97. {
  98. uint32_t version =
  99. BIOS_CMD_TABLE_PARA_REVISION(digxencodercontrol);
  100. switch (version) {
  101. case 5:
  102. bp->cmd_tbl.dig_encoder_control = encoder_control_digx_v1_5;
  103. break;
  104. default:
  105. dm_output_to_console("Don't have dig_encoder_control for v%d\n", version);
  106. bp->cmd_tbl.dig_encoder_control = NULL;
  107. break;
  108. }
  109. }
  110. static enum bp_result encoder_control_digx_v1_5(
  111. struct bios_parser *bp,
  112. struct bp_encoder_control *cntl)
  113. {
  114. enum bp_result result = BP_RESULT_FAILURE;
  115. struct dig_encoder_stream_setup_parameters_v1_5 params = {0};
  116. params.digid = (uint8_t)(cntl->engine_id);
  117. params.action = bp->cmd_helper->encoder_action_to_atom(cntl->action);
  118. params.pclk_10khz = cntl->pixel_clock / 10;
  119. params.digmode =
  120. (uint8_t)(bp->cmd_helper->encoder_mode_bp_to_atom(
  121. cntl->signal,
  122. cntl->enable_dp_audio));
  123. params.lanenum = (uint8_t)(cntl->lanes_number);
  124. switch (cntl->color_depth) {
  125. case COLOR_DEPTH_888:
  126. params.bitpercolor = PANEL_8BIT_PER_COLOR;
  127. break;
  128. case COLOR_DEPTH_101010:
  129. params.bitpercolor = PANEL_10BIT_PER_COLOR;
  130. break;
  131. case COLOR_DEPTH_121212:
  132. params.bitpercolor = PANEL_12BIT_PER_COLOR;
  133. break;
  134. case COLOR_DEPTH_161616:
  135. params.bitpercolor = PANEL_16BIT_PER_COLOR;
  136. break;
  137. default:
  138. break;
  139. }
  140. if (cntl->signal == SIGNAL_TYPE_HDMI_TYPE_A)
  141. switch (cntl->color_depth) {
  142. case COLOR_DEPTH_101010:
  143. params.pclk_10khz =
  144. (params.pclk_10khz * 30) / 24;
  145. break;
  146. case COLOR_DEPTH_121212:
  147. params.pclk_10khz =
  148. (params.pclk_10khz * 36) / 24;
  149. break;
  150. case COLOR_DEPTH_161616:
  151. params.pclk_10khz =
  152. (params.pclk_10khz * 48) / 24;
  153. break;
  154. default:
  155. break;
  156. }
  157. if (EXEC_BIOS_CMD_TABLE(digxencodercontrol, params))
  158. result = BP_RESULT_OK;
  159. return result;
  160. }
  161. /*****************************************************************************
  162. ******************************************************************************
  163. **
  164. ** TRANSMITTER CONTROL
  165. **
  166. ******************************************************************************
  167. *****************************************************************************/
  168. static enum bp_result transmitter_control_v1_6(
  169. struct bios_parser *bp,
  170. struct bp_transmitter_control *cntl);
  171. static void init_transmitter_control(struct bios_parser *bp)
  172. {
  173. uint8_t frev;
  174. uint8_t crev;
  175. if (BIOS_CMD_TABLE_REVISION(dig1transmittercontrol, frev, crev) == false)
  176. BREAK_TO_DEBUGGER();
  177. switch (crev) {
  178. case 6:
  179. bp->cmd_tbl.transmitter_control = transmitter_control_v1_6;
  180. break;
  181. default:
  182. dm_output_to_console("Don't have transmitter_control for v%d\n", crev);
  183. bp->cmd_tbl.transmitter_control = NULL;
  184. break;
  185. }
  186. }
  187. static enum bp_result transmitter_control_v1_6(
  188. struct bios_parser *bp,
  189. struct bp_transmitter_control *cntl)
  190. {
  191. enum bp_result result = BP_RESULT_FAILURE;
  192. const struct command_table_helper *cmd = bp->cmd_helper;
  193. struct dig_transmitter_control_ps_allocation_v1_6 ps = { { 0 } };
  194. ps.param.phyid = cmd->phy_id_to_atom(cntl->transmitter);
  195. ps.param.action = (uint8_t)cntl->action;
  196. if (cntl->action == TRANSMITTER_CONTROL_SET_VOLTAGE_AND_PREEMPASIS)
  197. ps.param.mode_laneset.dplaneset = (uint8_t)cntl->lane_settings;
  198. else
  199. ps.param.mode_laneset.digmode =
  200. cmd->signal_type_to_atom_dig_mode(cntl->signal);
  201. ps.param.lanenum = (uint8_t)cntl->lanes_number;
  202. ps.param.hpdsel = cmd->hpd_sel_to_atom(cntl->hpd_sel);
  203. ps.param.digfe_sel = cmd->dig_encoder_sel_to_atom(cntl->engine_id);
  204. ps.param.connobj_id = (uint8_t)cntl->connector_obj_id.id;
  205. ps.param.symclk_10khz = cntl->pixel_clock/10;
  206. if (cntl->action == TRANSMITTER_CONTROL_ENABLE ||
  207. cntl->action == TRANSMITTER_CONTROL_ACTIAVATE ||
  208. cntl->action == TRANSMITTER_CONTROL_DEACTIVATE) {
  209. DC_LOG_BIOS("%s:ps.param.symclk_10khz = %d\n",\
  210. __func__, ps.param.symclk_10khz);
  211. }
  212. /*color_depth not used any more, driver has deep color factor in the Phyclk*/
  213. if (EXEC_BIOS_CMD_TABLE(dig1transmittercontrol, ps))
  214. result = BP_RESULT_OK;
  215. return result;
  216. }
  217. /******************************************************************************
  218. ******************************************************************************
  219. **
  220. ** SET PIXEL CLOCK
  221. **
  222. ******************************************************************************
  223. *****************************************************************************/
  224. static enum bp_result set_pixel_clock_v7(
  225. struct bios_parser *bp,
  226. struct bp_pixel_clock_parameters *bp_params);
  227. static void init_set_pixel_clock(struct bios_parser *bp)
  228. {
  229. switch (BIOS_CMD_TABLE_PARA_REVISION(setpixelclock)) {
  230. case 7:
  231. bp->cmd_tbl.set_pixel_clock = set_pixel_clock_v7;
  232. break;
  233. default:
  234. dm_output_to_console("Don't have set_pixel_clock for v%d\n",
  235. BIOS_CMD_TABLE_PARA_REVISION(setpixelclock));
  236. bp->cmd_tbl.set_pixel_clock = NULL;
  237. break;
  238. }
  239. }
  240. static enum bp_result set_pixel_clock_v7(
  241. struct bios_parser *bp,
  242. struct bp_pixel_clock_parameters *bp_params)
  243. {
  244. enum bp_result result = BP_RESULT_FAILURE;
  245. struct set_pixel_clock_parameter_v1_7 clk;
  246. uint8_t controller_id;
  247. uint32_t pll_id;
  248. memset(&clk, 0, sizeof(clk));
  249. if (bp->cmd_helper->clock_source_id_to_atom(bp_params->pll_id, &pll_id)
  250. && bp->cmd_helper->controller_id_to_atom(bp_params->
  251. controller_id, &controller_id)) {
  252. /* Note: VBIOS still wants to use ucCRTC name which is now
  253. * 1 byte in ULONG
  254. *typedef struct _CRTC_PIXEL_CLOCK_FREQ
  255. *{
  256. * target the pixel clock to drive the CRTC timing.
  257. * ULONG ulPixelClock:24;
  258. * 0 means disable PPLL/DCPLL. Expanded to 24 bits comparing to
  259. * previous version.
  260. * ATOM_CRTC1~6, indicate the CRTC controller to
  261. * ULONG ucCRTC:8;
  262. * drive the pixel clock. not used for DCPLL case.
  263. *}CRTC_PIXEL_CLOCK_FREQ;
  264. *union
  265. *{
  266. * pixel clock and CRTC id frequency
  267. * CRTC_PIXEL_CLOCK_FREQ ulCrtcPclkFreq;
  268. * ULONG ulDispEngClkFreq; dispclk frequency
  269. *};
  270. */
  271. clk.crtc_id = controller_id;
  272. clk.pll_id = (uint8_t) pll_id;
  273. clk.encoderobjid =
  274. bp->cmd_helper->encoder_id_to_atom(
  275. dal_graphics_object_id_get_encoder_id(
  276. bp_params->encoder_object_id));
  277. clk.encoder_mode = (uint8_t) bp->
  278. cmd_helper->encoder_mode_bp_to_atom(
  279. bp_params->signal_type, false);
  280. /* We need to convert from KHz units into 10KHz units */
  281. clk.pixclk_100hz = cpu_to_le32(bp_params->target_pixel_clock *
  282. 10);
  283. clk.deep_color_ratio =
  284. (uint8_t) bp->cmd_helper->
  285. transmitter_color_depth_to_atom(
  286. bp_params->color_depth);
  287. DC_LOG_BIOS("%s:program display clock = %d"\
  288. "colorDepth = %d\n", __func__,\
  289. bp_params->target_pixel_clock, bp_params->color_depth);
  290. if (bp_params->flags.FORCE_PROGRAMMING_OF_PLL)
  291. clk.miscinfo |= PIXEL_CLOCK_V7_MISC_FORCE_PROG_PPLL;
  292. if (bp_params->flags.PROGRAM_PHY_PLL_ONLY)
  293. clk.miscinfo |= PIXEL_CLOCK_V7_MISC_PROG_PHYPLL;
  294. if (bp_params->flags.SUPPORT_YUV_420)
  295. clk.miscinfo |= PIXEL_CLOCK_V7_MISC_YUV420_MODE;
  296. if (bp_params->flags.SET_XTALIN_REF_SRC)
  297. clk.miscinfo |= PIXEL_CLOCK_V7_MISC_REF_DIV_SRC_XTALIN;
  298. if (bp_params->flags.SET_GENLOCK_REF_DIV_SRC)
  299. clk.miscinfo |= PIXEL_CLOCK_V7_MISC_REF_DIV_SRC_GENLK;
  300. if (bp_params->signal_type == SIGNAL_TYPE_DVI_DUAL_LINK)
  301. clk.miscinfo |= PIXEL_CLOCK_V7_MISC_DVI_DUALLINK_EN;
  302. if (EXEC_BIOS_CMD_TABLE(setpixelclock, clk))
  303. result = BP_RESULT_OK;
  304. }
  305. return result;
  306. }
  307. /******************************************************************************
  308. ******************************************************************************
  309. **
  310. ** SET CRTC TIMING
  311. **
  312. ******************************************************************************
  313. *****************************************************************************/
  314. static enum bp_result set_crtc_using_dtd_timing_v3(
  315. struct bios_parser *bp,
  316. struct bp_hw_crtc_timing_parameters *bp_params);
  317. static void init_set_crtc_timing(struct bios_parser *bp)
  318. {
  319. uint32_t dtd_version =
  320. BIOS_CMD_TABLE_PARA_REVISION(setcrtc_usingdtdtiming);
  321. switch (dtd_version) {
  322. case 3:
  323. bp->cmd_tbl.set_crtc_timing =
  324. set_crtc_using_dtd_timing_v3;
  325. break;
  326. default:
  327. dm_output_to_console("Don't have set_crtc_timing for v%d\n", dtd_version);
  328. bp->cmd_tbl.set_crtc_timing = NULL;
  329. break;
  330. }
  331. }
  332. static enum bp_result set_crtc_using_dtd_timing_v3(
  333. struct bios_parser *bp,
  334. struct bp_hw_crtc_timing_parameters *bp_params)
  335. {
  336. enum bp_result result = BP_RESULT_FAILURE;
  337. struct set_crtc_using_dtd_timing_parameters params = {0};
  338. uint8_t atom_controller_id;
  339. if (bp->cmd_helper->controller_id_to_atom(
  340. bp_params->controller_id, &atom_controller_id))
  341. params.crtc_id = atom_controller_id;
  342. /* bios usH_Size wants h addressable size */
  343. params.h_size = cpu_to_le16((uint16_t)bp_params->h_addressable);
  344. /* bios usH_Blanking_Time wants borders included in blanking */
  345. params.h_blanking_time =
  346. cpu_to_le16((uint16_t)(bp_params->h_total -
  347. bp_params->h_addressable));
  348. /* bios usV_Size wants v addressable size */
  349. params.v_size = cpu_to_le16((uint16_t)bp_params->v_addressable);
  350. /* bios usV_Blanking_Time wants borders included in blanking */
  351. params.v_blanking_time =
  352. cpu_to_le16((uint16_t)(bp_params->v_total -
  353. bp_params->v_addressable));
  354. /* bios usHSyncOffset is the offset from the end of h addressable,
  355. * our horizontalSyncStart is the offset from the beginning
  356. * of h addressable
  357. */
  358. params.h_syncoffset =
  359. cpu_to_le16((uint16_t)(bp_params->h_sync_start -
  360. bp_params->h_addressable));
  361. params.h_syncwidth = cpu_to_le16((uint16_t)bp_params->h_sync_width);
  362. /* bios usHSyncOffset is the offset from the end of v addressable,
  363. * our verticalSyncStart is the offset from the beginning of
  364. * v addressable
  365. */
  366. params.v_syncoffset =
  367. cpu_to_le16((uint16_t)(bp_params->v_sync_start -
  368. bp_params->v_addressable));
  369. params.v_syncwidth = cpu_to_le16((uint16_t)bp_params->v_sync_width);
  370. /* we assume that overscan from original timing does not get bigger
  371. * than 255
  372. * we will program all the borders in the Set CRTC Overscan call below
  373. */
  374. if (bp_params->flags.HSYNC_POSITIVE_POLARITY == 0)
  375. params.modemiscinfo =
  376. cpu_to_le16(le16_to_cpu(params.modemiscinfo) |
  377. ATOM_HSYNC_POLARITY);
  378. if (bp_params->flags.VSYNC_POSITIVE_POLARITY == 0)
  379. params.modemiscinfo =
  380. cpu_to_le16(le16_to_cpu(params.modemiscinfo) |
  381. ATOM_VSYNC_POLARITY);
  382. if (bp_params->flags.INTERLACE) {
  383. params.modemiscinfo =
  384. cpu_to_le16(le16_to_cpu(params.modemiscinfo) |
  385. ATOM_INTERLACE);
  386. /* original DAL code has this condition to apply this
  387. * for non-TV/CV only
  388. * due to complex MV testing for possible impact
  389. * if ( pACParameters->signal != SignalType_YPbPr &&
  390. * pACParameters->signal != SignalType_Composite &&
  391. * pACParameters->signal != SignalType_SVideo)
  392. */
  393. {
  394. /* HW will deduct 0.5 line from 2nd feild.
  395. * i.e. for 1080i, it is 2 lines for 1st field,
  396. * 2.5 lines for the 2nd feild. we need input as 5
  397. * instead of 4.
  398. * but it is 4 either from Edid data (spec CEA 861)
  399. * or CEA timing table.
  400. */
  401. params.v_syncoffset =
  402. cpu_to_le16(le16_to_cpu(params.v_syncoffset) +
  403. 1);
  404. }
  405. }
  406. if (bp_params->flags.HORZ_COUNT_BY_TWO)
  407. params.modemiscinfo =
  408. cpu_to_le16(le16_to_cpu(params.modemiscinfo) |
  409. 0x100); /* ATOM_DOUBLE_CLOCK_MODE */
  410. if (EXEC_BIOS_CMD_TABLE(setcrtc_usingdtdtiming, params))
  411. result = BP_RESULT_OK;
  412. return result;
  413. }
  414. /******************************************************************************
  415. ******************************************************************************
  416. **
  417. ** SELECT CRTC SOURCE
  418. **
  419. ******************************************************************************
  420. *****************************************************************************/
  421. static enum bp_result select_crtc_source_v3(
  422. struct bios_parser *bp,
  423. struct bp_crtc_source_select *bp_params);
  424. static void init_select_crtc_source(struct bios_parser *bp)
  425. {
  426. switch (BIOS_CMD_TABLE_PARA_REVISION(selectcrtc_source)) {
  427. case 3:
  428. bp->cmd_tbl.select_crtc_source = select_crtc_source_v3;
  429. break;
  430. default:
  431. dm_output_to_console("Don't select_crtc_source enable_crtc for v%d\n",
  432. BIOS_CMD_TABLE_PARA_REVISION(selectcrtc_source));
  433. bp->cmd_tbl.select_crtc_source = NULL;
  434. break;
  435. }
  436. }
  437. static enum bp_result select_crtc_source_v3(
  438. struct bios_parser *bp,
  439. struct bp_crtc_source_select *bp_params)
  440. {
  441. bool result = BP_RESULT_FAILURE;
  442. struct select_crtc_source_parameters_v2_3 params;
  443. uint8_t atom_controller_id;
  444. uint32_t atom_engine_id;
  445. enum signal_type s = bp_params->signal;
  446. memset(&params, 0, sizeof(params));
  447. if (bp->cmd_helper->controller_id_to_atom(bp_params->controller_id,
  448. &atom_controller_id))
  449. params.crtc_id = atom_controller_id;
  450. else
  451. return result;
  452. if (bp->cmd_helper->engine_bp_to_atom(bp_params->engine_id,
  453. &atom_engine_id))
  454. params.encoder_id = (uint8_t)atom_engine_id;
  455. else
  456. return result;
  457. if (s == SIGNAL_TYPE_EDP ||
  458. (s == SIGNAL_TYPE_DISPLAY_PORT && bp_params->sink_signal ==
  459. SIGNAL_TYPE_LVDS))
  460. s = SIGNAL_TYPE_LVDS;
  461. params.encode_mode =
  462. bp->cmd_helper->encoder_mode_bp_to_atom(
  463. s, bp_params->enable_dp_audio);
  464. /* Needed for VBIOS Random Spatial Dithering feature */
  465. params.dst_bpc = (uint8_t)(bp_params->display_output_bit_depth);
  466. if (EXEC_BIOS_CMD_TABLE(selectcrtc_source, params))
  467. result = BP_RESULT_OK;
  468. return result;
  469. }
  470. /******************************************************************************
  471. ******************************************************************************
  472. **
  473. ** ENABLE CRTC
  474. **
  475. ******************************************************************************
  476. *****************************************************************************/
  477. static enum bp_result enable_crtc_v1(
  478. struct bios_parser *bp,
  479. enum controller_id controller_id,
  480. bool enable);
  481. static void init_enable_crtc(struct bios_parser *bp)
  482. {
  483. switch (BIOS_CMD_TABLE_PARA_REVISION(enablecrtc)) {
  484. case 1:
  485. bp->cmd_tbl.enable_crtc = enable_crtc_v1;
  486. break;
  487. default:
  488. dm_output_to_console("Don't have enable_crtc for v%d\n",
  489. BIOS_CMD_TABLE_PARA_REVISION(enablecrtc));
  490. bp->cmd_tbl.enable_crtc = NULL;
  491. break;
  492. }
  493. }
  494. static enum bp_result enable_crtc_v1(
  495. struct bios_parser *bp,
  496. enum controller_id controller_id,
  497. bool enable)
  498. {
  499. bool result = BP_RESULT_FAILURE;
  500. struct enable_crtc_parameters params = {0};
  501. uint8_t id;
  502. if (bp->cmd_helper->controller_id_to_atom(controller_id, &id))
  503. params.crtc_id = id;
  504. else
  505. return BP_RESULT_BADINPUT;
  506. if (enable)
  507. params.enable = ATOM_ENABLE;
  508. else
  509. params.enable = ATOM_DISABLE;
  510. if (EXEC_BIOS_CMD_TABLE(enablecrtc, params))
  511. result = BP_RESULT_OK;
  512. return result;
  513. }
  514. /******************************************************************************
  515. ******************************************************************************
  516. **
  517. ** DISPLAY PLL
  518. **
  519. ******************************************************************************
  520. *****************************************************************************/
  521. /******************************************************************************
  522. ******************************************************************************
  523. **
  524. ** EXTERNAL ENCODER CONTROL
  525. **
  526. ******************************************************************************
  527. *****************************************************************************/
  528. static enum bp_result external_encoder_control_v3(
  529. struct bios_parser *bp,
  530. struct bp_external_encoder_control *cntl);
  531. static void init_external_encoder_control(
  532. struct bios_parser *bp)
  533. {
  534. switch (BIOS_CMD_TABLE_PARA_REVISION(externalencodercontrol)) {
  535. case 3:
  536. bp->cmd_tbl.external_encoder_control =
  537. external_encoder_control_v3;
  538. break;
  539. default:
  540. bp->cmd_tbl.external_encoder_control = NULL;
  541. break;
  542. }
  543. }
  544. static enum bp_result external_encoder_control_v3(
  545. struct bios_parser *bp,
  546. struct bp_external_encoder_control *cntl)
  547. {
  548. /* TODO */
  549. return BP_RESULT_OK;
  550. }
  551. /******************************************************************************
  552. ******************************************************************************
  553. **
  554. ** ENABLE DISPLAY POWER GATING
  555. **
  556. ******************************************************************************
  557. *****************************************************************************/
  558. static enum bp_result enable_disp_power_gating_v2_1(
  559. struct bios_parser *bp,
  560. enum controller_id crtc_id,
  561. enum bp_pipe_control_action action);
  562. static void init_enable_disp_power_gating(
  563. struct bios_parser *bp)
  564. {
  565. switch (BIOS_CMD_TABLE_PARA_REVISION(enabledisppowergating)) {
  566. case 1:
  567. bp->cmd_tbl.enable_disp_power_gating =
  568. enable_disp_power_gating_v2_1;
  569. break;
  570. default:
  571. dm_output_to_console("Don't enable_disp_power_gating enable_crtc for v%d\n",
  572. BIOS_CMD_TABLE_PARA_REVISION(enabledisppowergating));
  573. bp->cmd_tbl.enable_disp_power_gating = NULL;
  574. break;
  575. }
  576. }
  577. static enum bp_result enable_disp_power_gating_v2_1(
  578. struct bios_parser *bp,
  579. enum controller_id crtc_id,
  580. enum bp_pipe_control_action action)
  581. {
  582. enum bp_result result = BP_RESULT_FAILURE;
  583. struct enable_disp_power_gating_ps_allocation ps = { { 0 } };
  584. uint8_t atom_crtc_id;
  585. if (bp->cmd_helper->controller_id_to_atom(crtc_id, &atom_crtc_id))
  586. ps.param.disp_pipe_id = atom_crtc_id;
  587. else
  588. return BP_RESULT_BADINPUT;
  589. ps.param.enable =
  590. bp->cmd_helper->disp_power_gating_action_to_atom(action);
  591. if (EXEC_BIOS_CMD_TABLE(enabledisppowergating, ps.param))
  592. result = BP_RESULT_OK;
  593. return result;
  594. }
  595. /******************************************************************************
  596. *******************************************************************************
  597. **
  598. ** SET DCE CLOCK
  599. **
  600. *******************************************************************************
  601. *******************************************************************************/
  602. static enum bp_result set_dce_clock_v2_1(
  603. struct bios_parser *bp,
  604. struct bp_set_dce_clock_parameters *bp_params);
  605. static void init_set_dce_clock(struct bios_parser *bp)
  606. {
  607. switch (BIOS_CMD_TABLE_PARA_REVISION(setdceclock)) {
  608. case 1:
  609. bp->cmd_tbl.set_dce_clock = set_dce_clock_v2_1;
  610. break;
  611. default:
  612. dm_output_to_console("Don't have set_dce_clock for v%d\n",
  613. BIOS_CMD_TABLE_PARA_REVISION(setdceclock));
  614. bp->cmd_tbl.set_dce_clock = NULL;
  615. break;
  616. }
  617. }
  618. static enum bp_result set_dce_clock_v2_1(
  619. struct bios_parser *bp,
  620. struct bp_set_dce_clock_parameters *bp_params)
  621. {
  622. enum bp_result result = BP_RESULT_FAILURE;
  623. struct set_dce_clock_ps_allocation_v2_1 params;
  624. uint32_t atom_pll_id;
  625. uint32_t atom_clock_type;
  626. const struct command_table_helper *cmd = bp->cmd_helper;
  627. memset(&params, 0, sizeof(params));
  628. if (!cmd->clock_source_id_to_atom(bp_params->pll_id, &atom_pll_id) ||
  629. !cmd->dc_clock_type_to_atom(bp_params->clock_type,
  630. &atom_clock_type))
  631. return BP_RESULT_BADINPUT;
  632. params.param.dceclksrc = atom_pll_id;
  633. params.param.dceclktype = atom_clock_type;
  634. if (bp_params->clock_type == DCECLOCK_TYPE_DPREFCLK) {
  635. if (bp_params->flags.USE_GENLOCK_AS_SOURCE_FOR_DPREFCLK)
  636. params.param.dceclkflag |=
  637. DCE_CLOCK_FLAG_PLL_REFCLK_SRC_GENLK;
  638. if (bp_params->flags.USE_PCIE_AS_SOURCE_FOR_DPREFCLK)
  639. params.param.dceclkflag |=
  640. DCE_CLOCK_FLAG_PLL_REFCLK_SRC_PCIE;
  641. if (bp_params->flags.USE_XTALIN_AS_SOURCE_FOR_DPREFCLK)
  642. params.param.dceclkflag |=
  643. DCE_CLOCK_FLAG_PLL_REFCLK_SRC_XTALIN;
  644. if (bp_params->flags.USE_GENERICA_AS_SOURCE_FOR_DPREFCLK)
  645. params.param.dceclkflag |=
  646. DCE_CLOCK_FLAG_PLL_REFCLK_SRC_GENERICA;
  647. } else
  648. /* only program clock frequency if display clock is used;
  649. * VBIOS will program DPREFCLK
  650. * We need to convert from KHz units into 10KHz units
  651. */
  652. params.param.dceclk_10khz = cpu_to_le32(
  653. bp_params->target_clock_frequency / 10);
  654. DC_LOG_BIOS("%s:target_clock_frequency = %d"\
  655. "clock_type = %d \n", __func__,\
  656. bp_params->target_clock_frequency,\
  657. bp_params->clock_type);
  658. if (EXEC_BIOS_CMD_TABLE(setdceclock, params)) {
  659. /* Convert from 10KHz units back to KHz */
  660. bp_params->target_clock_frequency = le32_to_cpu(
  661. params.param.dceclk_10khz) * 10;
  662. result = BP_RESULT_OK;
  663. }
  664. return result;
  665. }
  666. /******************************************************************************
  667. ******************************************************************************
  668. **
  669. ** GET SMU CLOCK INFO
  670. **
  671. ******************************************************************************
  672. *****************************************************************************/
  673. static unsigned int get_smu_clock_info_v3_1(struct bios_parser *bp, uint8_t id);
  674. static void init_get_smu_clock_info(struct bios_parser *bp)
  675. {
  676. /* TODO add switch for table vrsion */
  677. bp->cmd_tbl.get_smu_clock_info = get_smu_clock_info_v3_1;
  678. }
  679. static unsigned int get_smu_clock_info_v3_1(struct bios_parser *bp, uint8_t id)
  680. {
  681. struct atom_get_smu_clock_info_parameters_v3_1 smu_input = {0};
  682. struct atom_get_smu_clock_info_output_parameters_v3_1 smu_output;
  683. smu_input.command = GET_SMU_CLOCK_INFO_V3_1_GET_PLLVCO_FREQ;
  684. smu_input.syspll_id = id;
  685. /* Get Specific Clock */
  686. if (EXEC_BIOS_CMD_TABLE(getsmuclockinfo, smu_input)) {
  687. memmove(&smu_output, &smu_input, sizeof(
  688. struct atom_get_smu_clock_info_parameters_v3_1));
  689. return smu_output.atom_smu_outputclkfreq.syspllvcofreq_10khz;
  690. }
  691. return 0;
  692. }