14562236bSHarry Wentland /* 24562236bSHarry Wentland * Copyright 2015 Advanced Micro Devices, Inc. 34562236bSHarry Wentland * 44562236bSHarry Wentland * Permission is hereby granted, free of charge, to any person obtaining a 54562236bSHarry Wentland * copy of this software and associated documentation files (the "Software"), 64562236bSHarry Wentland * to deal in the Software without restriction, including without limitation 74562236bSHarry Wentland * the rights to use, copy, modify, merge, publish, distribute, sublicense, 84562236bSHarry Wentland * and/or sell copies of the Software, and to permit persons to whom the 94562236bSHarry Wentland * Software is furnished to do so, subject to the following conditions: 104562236bSHarry Wentland * 114562236bSHarry Wentland * The above copyright notice and this permission notice shall be included in 124562236bSHarry Wentland * all copies or substantial portions of the Software. 134562236bSHarry Wentland * 144562236bSHarry Wentland * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 154562236bSHarry Wentland * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 164562236bSHarry Wentland * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 174562236bSHarry Wentland * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 184562236bSHarry Wentland * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 194562236bSHarry Wentland * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 204562236bSHarry Wentland * OTHER DEALINGS IN THE SOFTWARE. 214562236bSHarry Wentland * 224562236bSHarry Wentland * Authors: AMD 234562236bSHarry Wentland * 244562236bSHarry Wentland */ 254562236bSHarry Wentland #include "dm_services.h" 264562236bSHarry Wentland #include "dc.h" 274562236bSHarry Wentland #include "dc_bios_types.h" 284562236bSHarry Wentland #include "core_types.h" 294562236bSHarry Wentland #include "core_status.h" 304562236bSHarry Wentland #include "resource.h" 314562236bSHarry Wentland #include "dm_helpers.h" 324562236bSHarry Wentland #include "dce110_hw_sequencer.h" 334562236bSHarry Wentland #include "dce110_timing_generator.h" 3498489c02SLeo (Sunpeng) Li #include "dce/dce_hwseq.h" 3587401969SAndrew Jiang #include "gpio_service_interface.h" 364562236bSHarry Wentland 373eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 381663ae1cSBhawanpreet Lakha #include "dce110_compressor.h" 391663ae1cSBhawanpreet Lakha #endif 401663ae1cSBhawanpreet Lakha 414562236bSHarry Wentland #include "bios/bios_parser_helper.h" 424562236bSHarry Wentland #include "timing_generator.h" 434562236bSHarry Wentland #include "mem_input.h" 444562236bSHarry Wentland #include "opp.h" 454562236bSHarry Wentland #include "ipp.h" 464562236bSHarry Wentland #include "transform.h" 474562236bSHarry Wentland #include "stream_encoder.h" 484562236bSHarry Wentland #include "link_encoder.h" 4987401969SAndrew Jiang #include "link_hwss.h" 504562236bSHarry Wentland #include "clock_source.h" 515e7773a2SAnthony Koo #include "abm.h" 524562236bSHarry Wentland #include "audio.h" 5308b16886SZeyu Fan #include "reg_helper.h" 544562236bSHarry Wentland 554562236bSHarry Wentland /* include DCE11 register header files */ 564562236bSHarry Wentland #include "dce/dce_11_0_d.h" 574562236bSHarry Wentland #include "dce/dce_11_0_sh_mask.h" 58e266fdf6SVitaly Prosyak #include "custom_float.h" 594562236bSHarry Wentland 604cac1e6dSYongqiang Sun #include "atomfirmware.h" 614cac1e6dSYongqiang Sun 6287401969SAndrew Jiang /* 6387401969SAndrew Jiang * All values are in milliseconds; 6487401969SAndrew Jiang * For eDP, after power-up/power/down, 6587401969SAndrew Jiang * 300/500 msec max. delay from LCDVCC to black video generation 6687401969SAndrew Jiang */ 6787401969SAndrew Jiang #define PANEL_POWER_UP_TIMEOUT 300 6887401969SAndrew Jiang #define PANEL_POWER_DOWN_TIMEOUT 500 6987401969SAndrew Jiang #define HPD_CHECK_INTERVAL 10 7087401969SAndrew Jiang 715eefbc40SYue Hin Lau #define CTX \ 725eefbc40SYue Hin Lau hws->ctx 731296423bSBhawanpreet Lakha #define DC_LOGGER \ 741296423bSBhawanpreet Lakha ctx->logger 755eefbc40SYue Hin Lau #define REG(reg)\ 765eefbc40SYue Hin Lau hws->regs->reg 775eefbc40SYue Hin Lau 785eefbc40SYue Hin Lau #undef FN 795eefbc40SYue Hin Lau #define FN(reg_name, field_name) \ 805eefbc40SYue Hin Lau hws->shifts->field_name, hws->masks->field_name 815eefbc40SYue Hin Lau 824562236bSHarry Wentland struct dce110_hw_seq_reg_offsets { 834562236bSHarry Wentland uint32_t crtc; 844562236bSHarry Wentland }; 854562236bSHarry Wentland 864562236bSHarry Wentland static const struct dce110_hw_seq_reg_offsets reg_offsets[] = { 874562236bSHarry Wentland { 884562236bSHarry Wentland .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL), 894562236bSHarry Wentland }, 904562236bSHarry Wentland { 914562236bSHarry Wentland .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL), 924562236bSHarry Wentland }, 934562236bSHarry Wentland { 944562236bSHarry Wentland .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL), 954562236bSHarry Wentland }, 964562236bSHarry Wentland { 974562236bSHarry Wentland .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL), 984562236bSHarry Wentland } 994562236bSHarry Wentland }; 1004562236bSHarry Wentland 1014562236bSHarry Wentland #define HW_REG_BLND(reg, id)\ 1024562236bSHarry Wentland (reg + reg_offsets[id].blnd) 1034562236bSHarry Wentland 1044562236bSHarry Wentland #define HW_REG_CRTC(reg, id)\ 1054562236bSHarry Wentland (reg + reg_offsets[id].crtc) 1064562236bSHarry Wentland 1074562236bSHarry Wentland #define MAX_WATERMARK 0xFFFF 1084562236bSHarry Wentland #define SAFE_NBP_MARK 0x7FFF 1094562236bSHarry Wentland 1104562236bSHarry Wentland /******************************************************************************* 1114562236bSHarry Wentland * Private definitions 1124562236bSHarry Wentland ******************************************************************************/ 1134562236bSHarry Wentland /***************************PIPE_CONTROL***********************************/ 1144562236bSHarry Wentland static void dce110_init_pte(struct dc_context *ctx) 1154562236bSHarry Wentland { 1164562236bSHarry Wentland uint32_t addr; 1174562236bSHarry Wentland uint32_t value = 0; 1184562236bSHarry Wentland uint32_t chunk_int = 0; 1194562236bSHarry Wentland uint32_t chunk_mul = 0; 1204562236bSHarry Wentland 1214562236bSHarry Wentland addr = mmUNP_DVMM_PTE_CONTROL; 1224562236bSHarry Wentland value = dm_read_reg(ctx, addr); 1234562236bSHarry Wentland 1244562236bSHarry Wentland set_reg_field_value( 1254562236bSHarry Wentland value, 1264562236bSHarry Wentland 0, 1274562236bSHarry Wentland DVMM_PTE_CONTROL, 1284562236bSHarry Wentland DVMM_USE_SINGLE_PTE); 1294562236bSHarry Wentland 1304562236bSHarry Wentland set_reg_field_value( 1314562236bSHarry Wentland value, 1324562236bSHarry Wentland 1, 1334562236bSHarry Wentland DVMM_PTE_CONTROL, 1344562236bSHarry Wentland DVMM_PTE_BUFFER_MODE0); 1354562236bSHarry Wentland 1364562236bSHarry Wentland set_reg_field_value( 1374562236bSHarry Wentland value, 1384562236bSHarry Wentland 1, 1394562236bSHarry Wentland DVMM_PTE_CONTROL, 1404562236bSHarry Wentland DVMM_PTE_BUFFER_MODE1); 1414562236bSHarry Wentland 1424562236bSHarry Wentland dm_write_reg(ctx, addr, value); 1434562236bSHarry Wentland 1444562236bSHarry Wentland addr = mmDVMM_PTE_REQ; 1454562236bSHarry Wentland value = dm_read_reg(ctx, addr); 1464562236bSHarry Wentland 1474562236bSHarry Wentland chunk_int = get_reg_field_value( 1484562236bSHarry Wentland value, 1494562236bSHarry Wentland DVMM_PTE_REQ, 1504562236bSHarry Wentland HFLIP_PTEREQ_PER_CHUNK_INT); 1514562236bSHarry Wentland 1524562236bSHarry Wentland chunk_mul = get_reg_field_value( 1534562236bSHarry Wentland value, 1544562236bSHarry Wentland DVMM_PTE_REQ, 1554562236bSHarry Wentland HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER); 1564562236bSHarry Wentland 1574562236bSHarry Wentland if (chunk_int != 0x4 || chunk_mul != 0x4) { 1584562236bSHarry Wentland 1594562236bSHarry Wentland set_reg_field_value( 1604562236bSHarry Wentland value, 1614562236bSHarry Wentland 255, 1624562236bSHarry Wentland DVMM_PTE_REQ, 1634562236bSHarry Wentland MAX_PTEREQ_TO_ISSUE); 1644562236bSHarry Wentland 1654562236bSHarry Wentland set_reg_field_value( 1664562236bSHarry Wentland value, 1674562236bSHarry Wentland 4, 1684562236bSHarry Wentland DVMM_PTE_REQ, 1694562236bSHarry Wentland HFLIP_PTEREQ_PER_CHUNK_INT); 1704562236bSHarry Wentland 1714562236bSHarry Wentland set_reg_field_value( 1724562236bSHarry Wentland value, 1734562236bSHarry Wentland 4, 1744562236bSHarry Wentland DVMM_PTE_REQ, 1754562236bSHarry Wentland HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER); 1764562236bSHarry Wentland 1774562236bSHarry Wentland dm_write_reg(ctx, addr, value); 1784562236bSHarry Wentland } 1794562236bSHarry Wentland } 1804562236bSHarry Wentland /**************************************************************************/ 1814562236bSHarry Wentland 1824562236bSHarry Wentland static void enable_display_pipe_clock_gating( 1834562236bSHarry Wentland struct dc_context *ctx, 1844562236bSHarry Wentland bool clock_gating) 1854562236bSHarry Wentland { 1864562236bSHarry Wentland /*TODO*/ 1874562236bSHarry Wentland } 1884562236bSHarry Wentland 1894562236bSHarry Wentland static bool dce110_enable_display_power_gating( 190fb3466a4SBhawanpreet Lakha struct dc *dc, 1914562236bSHarry Wentland uint8_t controller_id, 1924562236bSHarry Wentland struct dc_bios *dcb, 1934562236bSHarry Wentland enum pipe_gating_control power_gating) 1944562236bSHarry Wentland { 1954562236bSHarry Wentland enum bp_result bp_result = BP_RESULT_OK; 1964562236bSHarry Wentland enum bp_pipe_control_action cntl; 1974562236bSHarry Wentland struct dc_context *ctx = dc->ctx; 1984562236bSHarry Wentland unsigned int underlay_idx = dc->res_pool->underlay_pipe_index; 1994562236bSHarry Wentland 2004562236bSHarry Wentland if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment)) 2014562236bSHarry Wentland return true; 2024562236bSHarry Wentland 2034562236bSHarry Wentland if (power_gating == PIPE_GATING_CONTROL_INIT) 2044562236bSHarry Wentland cntl = ASIC_PIPE_INIT; 2054562236bSHarry Wentland else if (power_gating == PIPE_GATING_CONTROL_ENABLE) 2064562236bSHarry Wentland cntl = ASIC_PIPE_ENABLE; 2074562236bSHarry Wentland else 2084562236bSHarry Wentland cntl = ASIC_PIPE_DISABLE; 2094562236bSHarry Wentland 2104562236bSHarry Wentland if (controller_id == underlay_idx) 2114562236bSHarry Wentland controller_id = CONTROLLER_ID_UNDERLAY0 - 1; 2124562236bSHarry Wentland 2134562236bSHarry Wentland if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){ 2144562236bSHarry Wentland 2154562236bSHarry Wentland bp_result = dcb->funcs->enable_disp_power_gating( 2164562236bSHarry Wentland dcb, controller_id + 1, cntl); 2174562236bSHarry Wentland 2184562236bSHarry Wentland /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2 2194562236bSHarry Wentland * by default when command table is called 2204562236bSHarry Wentland * 2214562236bSHarry Wentland * Bios parser accepts controller_id = 6 as indicative of 2224562236bSHarry Wentland * underlay pipe in dce110. But we do not support more 2234562236bSHarry Wentland * than 3. 2244562236bSHarry Wentland */ 2254562236bSHarry Wentland if (controller_id < CONTROLLER_ID_MAX - 1) 2264562236bSHarry Wentland dm_write_reg(ctx, 2274562236bSHarry Wentland HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id), 2284562236bSHarry Wentland 0); 2294562236bSHarry Wentland } 2304562236bSHarry Wentland 2314562236bSHarry Wentland if (power_gating != PIPE_GATING_CONTROL_ENABLE) 2324562236bSHarry Wentland dce110_init_pte(ctx); 2334562236bSHarry Wentland 2344562236bSHarry Wentland if (bp_result == BP_RESULT_OK) 2354562236bSHarry Wentland return true; 2364562236bSHarry Wentland else 2374562236bSHarry Wentland return false; 2384562236bSHarry Wentland } 2394562236bSHarry Wentland 2404562236bSHarry Wentland static void build_prescale_params(struct ipp_prescale_params *prescale_params, 2413be5262eSHarry Wentland const struct dc_plane_state *plane_state) 2424562236bSHarry Wentland { 2434562236bSHarry Wentland prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED; 2444562236bSHarry Wentland 2453be5262eSHarry Wentland switch (plane_state->format) { 2464562236bSHarry Wentland case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888: 2478693049aSTony Cheng case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888: 2484562236bSHarry Wentland prescale_params->scale = 0x2020; 2494562236bSHarry Wentland break; 2504562236bSHarry Wentland case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010: 2514562236bSHarry Wentland case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010: 2524562236bSHarry Wentland prescale_params->scale = 0x2008; 2534562236bSHarry Wentland break; 2544562236bSHarry Wentland case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616: 2554562236bSHarry Wentland case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F: 2564562236bSHarry Wentland prescale_params->scale = 0x2000; 2574562236bSHarry Wentland break; 2584562236bSHarry Wentland default: 2594562236bSHarry Wentland ASSERT(false); 260d7194cf6SAric Cyr break; 2614562236bSHarry Wentland } 2624562236bSHarry Wentland } 2634562236bSHarry Wentland 264a6114e85SHarry Wentland static bool 265a6114e85SHarry Wentland dce110_set_input_transfer_func(struct pipe_ctx *pipe_ctx, 2663be5262eSHarry Wentland const struct dc_plane_state *plane_state) 2674562236bSHarry Wentland { 26886a66c4eSHarry Wentland struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp; 2697b0c470fSLeo (Sunpeng) Li const struct dc_transfer_func *tf = NULL; 27090e508baSAnthony Koo struct ipp_prescale_params prescale_params = { 0 }; 27190e508baSAnthony Koo bool result = true; 27290e508baSAnthony Koo 27390e508baSAnthony Koo if (ipp == NULL) 27490e508baSAnthony Koo return false; 27590e508baSAnthony Koo 2763be5262eSHarry Wentland if (plane_state->in_transfer_func) 2773be5262eSHarry Wentland tf = plane_state->in_transfer_func; 27890e508baSAnthony Koo 2793be5262eSHarry Wentland build_prescale_params(&prescale_params, plane_state); 28090e508baSAnthony Koo ipp->funcs->ipp_program_prescale(ipp, &prescale_params); 28190e508baSAnthony Koo 282405c50a0SAndrew Jiang if (plane_state->gamma_correction && dce_use_lut(plane_state->format)) 2833be5262eSHarry Wentland ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction); 284d7194cf6SAric Cyr 28590e508baSAnthony Koo if (tf == NULL) { 28690e508baSAnthony Koo /* Default case if no input transfer function specified */ 287a6114e85SHarry Wentland ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB); 2887b0c470fSLeo (Sunpeng) Li } else if (tf->type == TF_TYPE_PREDEFINED) { 2897b0c470fSLeo (Sunpeng) Li switch (tf->tf) { 29090e508baSAnthony Koo case TRANSFER_FUNCTION_SRGB: 291a6114e85SHarry Wentland ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB); 29290e508baSAnthony Koo break; 29390e508baSAnthony Koo case TRANSFER_FUNCTION_BT709: 294a6114e85SHarry Wentland ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC); 29590e508baSAnthony Koo break; 29690e508baSAnthony Koo case TRANSFER_FUNCTION_LINEAR: 297a6114e85SHarry Wentland ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS); 29890e508baSAnthony Koo break; 29990e508baSAnthony Koo case TRANSFER_FUNCTION_PQ: 30090e508baSAnthony Koo default: 30190e508baSAnthony Koo result = false; 302d7194cf6SAric Cyr break; 30390e508baSAnthony Koo } 3047b0c470fSLeo (Sunpeng) Li } else if (tf->type == TF_TYPE_BYPASS) { 30570063a59SAmy Zhang ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS); 30690e508baSAnthony Koo } else { 30790e508baSAnthony Koo /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/ 30890e508baSAnthony Koo result = false; 30990e508baSAnthony Koo } 31090e508baSAnthony Koo 31190e508baSAnthony Koo return result; 31290e508baSAnthony Koo } 31390e508baSAnthony Koo 314bd1be8e8SHarry Wentland static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted, 315fcd2f4bfSAmy Zhang struct curve_points *arr_points, 316fcd2f4bfSAmy Zhang uint32_t hw_points_num) 317fcd2f4bfSAmy Zhang { 318fcd2f4bfSAmy Zhang struct custom_float_format fmt; 319fcd2f4bfSAmy Zhang 320fcd2f4bfSAmy Zhang struct pwl_result_data *rgb = rgb_resulted; 321fcd2f4bfSAmy Zhang 322fcd2f4bfSAmy Zhang uint32_t i = 0; 323fcd2f4bfSAmy Zhang 324fcd2f4bfSAmy Zhang fmt.exponenta_bits = 6; 325fcd2f4bfSAmy Zhang fmt.mantissa_bits = 12; 326fcd2f4bfSAmy Zhang fmt.sign = true; 327fcd2f4bfSAmy Zhang 328bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(arr_points[0].x, &fmt, 329fcd2f4bfSAmy Zhang &arr_points[0].custom_float_x)) { 330fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 331fcd2f4bfSAmy Zhang return false; 332fcd2f4bfSAmy Zhang } 333fcd2f4bfSAmy Zhang 334bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(arr_points[0].offset, &fmt, 335fcd2f4bfSAmy Zhang &arr_points[0].custom_float_offset)) { 336fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 337fcd2f4bfSAmy Zhang return false; 338fcd2f4bfSAmy Zhang } 339fcd2f4bfSAmy Zhang 340bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(arr_points[0].slope, &fmt, 341fcd2f4bfSAmy Zhang &arr_points[0].custom_float_slope)) { 342fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 343fcd2f4bfSAmy Zhang return false; 344fcd2f4bfSAmy Zhang } 345fcd2f4bfSAmy Zhang 346fcd2f4bfSAmy Zhang fmt.mantissa_bits = 10; 347fcd2f4bfSAmy Zhang fmt.sign = false; 348fcd2f4bfSAmy Zhang 349bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(arr_points[1].x, &fmt, 350fcd2f4bfSAmy Zhang &arr_points[1].custom_float_x)) { 351fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 352fcd2f4bfSAmy Zhang return false; 353fcd2f4bfSAmy Zhang } 354fcd2f4bfSAmy Zhang 355bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(arr_points[1].y, &fmt, 356fcd2f4bfSAmy Zhang &arr_points[1].custom_float_y)) { 357fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 358fcd2f4bfSAmy Zhang return false; 359fcd2f4bfSAmy Zhang } 360fcd2f4bfSAmy Zhang 3614d06ccd0SHarry Wentland if (!convert_to_custom_float_format(arr_points[1].slope, &fmt, 3624d06ccd0SHarry Wentland &arr_points[1].custom_float_slope)) { 363fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 364fcd2f4bfSAmy Zhang return false; 365fcd2f4bfSAmy Zhang } 366fcd2f4bfSAmy Zhang 367fcd2f4bfSAmy Zhang fmt.mantissa_bits = 12; 368fcd2f4bfSAmy Zhang fmt.sign = true; 369fcd2f4bfSAmy Zhang 370fcd2f4bfSAmy Zhang while (i != hw_points_num) { 371bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(rgb->red, &fmt, 372fcd2f4bfSAmy Zhang &rgb->red_reg)) { 373fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 374fcd2f4bfSAmy Zhang return false; 375fcd2f4bfSAmy Zhang } 376fcd2f4bfSAmy Zhang 377bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(rgb->green, &fmt, 378fcd2f4bfSAmy Zhang &rgb->green_reg)) { 379fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 380fcd2f4bfSAmy Zhang return false; 381fcd2f4bfSAmy Zhang } 382fcd2f4bfSAmy Zhang 383bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(rgb->blue, &fmt, 384fcd2f4bfSAmy Zhang &rgb->blue_reg)) { 385fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 386fcd2f4bfSAmy Zhang return false; 387fcd2f4bfSAmy Zhang } 388fcd2f4bfSAmy Zhang 389bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(rgb->delta_red, &fmt, 390fcd2f4bfSAmy Zhang &rgb->delta_red_reg)) { 391fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 392fcd2f4bfSAmy Zhang return false; 393fcd2f4bfSAmy Zhang } 394fcd2f4bfSAmy Zhang 395bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(rgb->delta_green, &fmt, 396fcd2f4bfSAmy Zhang &rgb->delta_green_reg)) { 397fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 398fcd2f4bfSAmy Zhang return false; 399fcd2f4bfSAmy Zhang } 400fcd2f4bfSAmy Zhang 401bd1be8e8SHarry Wentland if (!convert_to_custom_float_format(rgb->delta_blue, &fmt, 402fcd2f4bfSAmy Zhang &rgb->delta_blue_reg)) { 403fcd2f4bfSAmy Zhang BREAK_TO_DEBUGGER(); 404fcd2f4bfSAmy Zhang return false; 405fcd2f4bfSAmy Zhang } 406fcd2f4bfSAmy Zhang 407fcd2f4bfSAmy Zhang ++rgb; 408fcd2f4bfSAmy Zhang ++i; 409fcd2f4bfSAmy Zhang } 410fcd2f4bfSAmy Zhang 411fcd2f4bfSAmy Zhang return true; 412fcd2f4bfSAmy Zhang } 413fcd2f4bfSAmy Zhang 41408616da5SLeo (Sunpeng) Li #define MAX_LOW_POINT 25 4158f8372c7SKrunoslav Kovac #define NUMBER_REGIONS 16 4168f8372c7SKrunoslav Kovac #define NUMBER_SW_SEGMENTS 16 4178f8372c7SKrunoslav Kovac 418b310b081SHarry Wentland static bool 419b310b081SHarry Wentland dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf, 420b310b081SHarry Wentland struct pwl_params *regamma_params) 421fcd2f4bfSAmy Zhang { 42223ae4f8eSAmy Zhang struct curve_points *arr_points; 42323ae4f8eSAmy Zhang struct pwl_result_data *rgb_resulted; 42423ae4f8eSAmy Zhang struct pwl_result_data *rgb; 42523ae4f8eSAmy Zhang struct pwl_result_data *rgb_plus_1; 426fcd2f4bfSAmy Zhang struct fixed31_32 y_r; 427fcd2f4bfSAmy Zhang struct fixed31_32 y_g; 428fcd2f4bfSAmy Zhang struct fixed31_32 y_b; 429fcd2f4bfSAmy Zhang struct fixed31_32 y1_min; 430fcd2f4bfSAmy Zhang struct fixed31_32 y3_max; 431fcd2f4bfSAmy Zhang 4328f8372c7SKrunoslav Kovac int32_t region_start, region_end; 4338f8372c7SKrunoslav Kovac uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points; 43423ae4f8eSAmy Zhang 435b310b081SHarry Wentland if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS) 43623ae4f8eSAmy Zhang return false; 43723ae4f8eSAmy Zhang 43823ae4f8eSAmy Zhang arr_points = regamma_params->arr_points; 43923ae4f8eSAmy Zhang rgb_resulted = regamma_params->rgb_resulted; 44023ae4f8eSAmy Zhang hw_points = 0; 441fcd2f4bfSAmy Zhang 442fcd2f4bfSAmy Zhang memset(regamma_params, 0, sizeof(struct pwl_params)); 443fcd2f4bfSAmy Zhang 444fcd2f4bfSAmy Zhang if (output_tf->tf == TRANSFER_FUNCTION_PQ) { 445534db198SAmy Zhang /* 16 segments 446fcd2f4bfSAmy Zhang * segments are from 2^-11 to 2^5 447fcd2f4bfSAmy Zhang */ 44808616da5SLeo (Sunpeng) Li region_start = -11; 44908616da5SLeo (Sunpeng) Li region_end = region_start + NUMBER_REGIONS; 450fcd2f4bfSAmy Zhang 4518f8372c7SKrunoslav Kovac for (i = 0; i < NUMBER_REGIONS; i++) 4528f8372c7SKrunoslav Kovac seg_distr[i] = 4; 453534db198SAmy Zhang 454fcd2f4bfSAmy Zhang } else { 455534db198SAmy Zhang /* 10 segments 456fcd2f4bfSAmy Zhang * segment is from 2^-10 to 2^0 457fcd2f4bfSAmy Zhang */ 4588f8372c7SKrunoslav Kovac region_start = -10; 4598f8372c7SKrunoslav Kovac region_end = 0; 460534db198SAmy Zhang 4618f8372c7SKrunoslav Kovac seg_distr[0] = 4; 462534db198SAmy Zhang seg_distr[1] = 4; 463534db198SAmy Zhang seg_distr[2] = 4; 464534db198SAmy Zhang seg_distr[3] = 4; 465534db198SAmy Zhang seg_distr[4] = 4; 466534db198SAmy Zhang seg_distr[5] = 4; 467534db198SAmy Zhang seg_distr[6] = 4; 468534db198SAmy Zhang seg_distr[7] = 4; 4698f8372c7SKrunoslav Kovac seg_distr[8] = 4; 4708f8372c7SKrunoslav Kovac seg_distr[9] = 4; 471534db198SAmy Zhang seg_distr[10] = -1; 472534db198SAmy Zhang seg_distr[11] = -1; 473534db198SAmy Zhang seg_distr[12] = -1; 474534db198SAmy Zhang seg_distr[13] = -1; 475534db198SAmy Zhang seg_distr[14] = -1; 476534db198SAmy Zhang seg_distr[15] = -1; 477fcd2f4bfSAmy Zhang } 478fcd2f4bfSAmy Zhang 479534db198SAmy Zhang for (k = 0; k < 16; k++) { 480534db198SAmy Zhang if (seg_distr[k] != -1) 481534db198SAmy Zhang hw_points += (1 << seg_distr[k]); 482534db198SAmy Zhang } 483534db198SAmy Zhang 484fcd2f4bfSAmy Zhang j = 0; 4858f8372c7SKrunoslav Kovac for (k = 0; k < (region_end - region_start); k++) { 486ec47734aSLeo (Sunpeng) Li increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]); 4878f8372c7SKrunoslav Kovac start_index = (region_start + k + MAX_LOW_POINT) * 4888f8372c7SKrunoslav Kovac NUMBER_SW_SEGMENTS; 4898f8372c7SKrunoslav Kovac for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS; 4908f8372c7SKrunoslav Kovac i += increment) { 491534db198SAmy Zhang if (j == hw_points - 1) 492fcd2f4bfSAmy Zhang break; 493fcd2f4bfSAmy Zhang rgb_resulted[j].red = output_tf->tf_pts.red[i]; 494fcd2f4bfSAmy Zhang rgb_resulted[j].green = output_tf->tf_pts.green[i]; 495fcd2f4bfSAmy Zhang rgb_resulted[j].blue = output_tf->tf_pts.blue[i]; 496fcd2f4bfSAmy Zhang j++; 497fcd2f4bfSAmy Zhang } 498534db198SAmy Zhang } 499534db198SAmy Zhang 500534db198SAmy Zhang /* last point */ 5018f8372c7SKrunoslav Kovac start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS; 502b310b081SHarry Wentland rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index]; 503b310b081SHarry Wentland rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index]; 504b310b081SHarry Wentland rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index]; 505fcd2f4bfSAmy Zhang 506fcd2f4bfSAmy Zhang arr_points[0].x = dal_fixed31_32_pow(dal_fixed31_32_from_int(2), 5078f8372c7SKrunoslav Kovac dal_fixed31_32_from_int(region_start)); 508fcd2f4bfSAmy Zhang arr_points[1].x = dal_fixed31_32_pow(dal_fixed31_32_from_int(2), 5098f8372c7SKrunoslav Kovac dal_fixed31_32_from_int(region_end)); 510fcd2f4bfSAmy Zhang 511fcd2f4bfSAmy Zhang y_r = rgb_resulted[0].red; 512fcd2f4bfSAmy Zhang y_g = rgb_resulted[0].green; 513fcd2f4bfSAmy Zhang y_b = rgb_resulted[0].blue; 514fcd2f4bfSAmy Zhang 515fcd2f4bfSAmy Zhang y1_min = dal_fixed31_32_min(y_r, dal_fixed31_32_min(y_g, y_b)); 516fcd2f4bfSAmy Zhang 517fcd2f4bfSAmy Zhang arr_points[0].y = y1_min; 518b310b081SHarry Wentland arr_points[0].slope = dal_fixed31_32_div(arr_points[0].y, 519fcd2f4bfSAmy Zhang arr_points[0].x); 520fcd2f4bfSAmy Zhang 521fcd2f4bfSAmy Zhang y_r = rgb_resulted[hw_points - 1].red; 522fcd2f4bfSAmy Zhang y_g = rgb_resulted[hw_points - 1].green; 523fcd2f4bfSAmy Zhang y_b = rgb_resulted[hw_points - 1].blue; 524fcd2f4bfSAmy Zhang 525fcd2f4bfSAmy Zhang /* see comment above, m_arrPoints[1].y should be the Y value for the 526fcd2f4bfSAmy Zhang * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1) 527fcd2f4bfSAmy Zhang */ 528fcd2f4bfSAmy Zhang y3_max = dal_fixed31_32_max(y_r, dal_fixed31_32_max(y_g, y_b)); 529fcd2f4bfSAmy Zhang 530fcd2f4bfSAmy Zhang arr_points[1].y = y3_max; 531fcd2f4bfSAmy Zhang 532fcd2f4bfSAmy Zhang arr_points[1].slope = dal_fixed31_32_zero; 533fcd2f4bfSAmy Zhang 534fcd2f4bfSAmy Zhang if (output_tf->tf == TRANSFER_FUNCTION_PQ) { 535fcd2f4bfSAmy Zhang /* for PQ, we want to have a straight line from last HW X point, 536fcd2f4bfSAmy Zhang * and the slope to be such that we hit 1.0 at 10000 nits. 537fcd2f4bfSAmy Zhang */ 538b310b081SHarry Wentland const struct fixed31_32 end_value = dal_fixed31_32_from_int(125); 539fcd2f4bfSAmy Zhang 540fcd2f4bfSAmy Zhang arr_points[1].slope = dal_fixed31_32_div( 541fcd2f4bfSAmy Zhang dal_fixed31_32_sub(dal_fixed31_32_one, arr_points[1].y), 542fcd2f4bfSAmy Zhang dal_fixed31_32_sub(end_value, arr_points[1].x)); 543fcd2f4bfSAmy Zhang } 544fcd2f4bfSAmy Zhang 545fcd2f4bfSAmy Zhang regamma_params->hw_points_num = hw_points; 546fcd2f4bfSAmy Zhang 547534db198SAmy Zhang i = 1; 548534db198SAmy Zhang for (k = 0; k < 16 && i < 16; k++) { 549534db198SAmy Zhang if (seg_distr[k] != -1) { 550b310b081SHarry Wentland regamma_params->arr_curve_points[k].segments_num = seg_distr[k]; 551534db198SAmy Zhang regamma_params->arr_curve_points[i].offset = 552b310b081SHarry Wentland regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]); 553fcd2f4bfSAmy Zhang } 554534db198SAmy Zhang i++; 555534db198SAmy Zhang } 556534db198SAmy Zhang 557534db198SAmy Zhang if (seg_distr[k] != -1) 558b310b081SHarry Wentland regamma_params->arr_curve_points[k].segments_num = seg_distr[k]; 559fcd2f4bfSAmy Zhang 56023ae4f8eSAmy Zhang rgb = rgb_resulted; 56123ae4f8eSAmy Zhang rgb_plus_1 = rgb_resulted + 1; 562fcd2f4bfSAmy Zhang 563fcd2f4bfSAmy Zhang i = 1; 564fcd2f4bfSAmy Zhang 565fcd2f4bfSAmy Zhang while (i != hw_points + 1) { 566fcd2f4bfSAmy Zhang if (dal_fixed31_32_lt(rgb_plus_1->red, rgb->red)) 567fcd2f4bfSAmy Zhang rgb_plus_1->red = rgb->red; 568fcd2f4bfSAmy Zhang if (dal_fixed31_32_lt(rgb_plus_1->green, rgb->green)) 569fcd2f4bfSAmy Zhang rgb_plus_1->green = rgb->green; 570fcd2f4bfSAmy Zhang if (dal_fixed31_32_lt(rgb_plus_1->blue, rgb->blue)) 571fcd2f4bfSAmy Zhang rgb_plus_1->blue = rgb->blue; 572fcd2f4bfSAmy Zhang 573b310b081SHarry Wentland rgb->delta_red = dal_fixed31_32_sub(rgb_plus_1->red, rgb->red); 574b310b081SHarry Wentland rgb->delta_green = dal_fixed31_32_sub(rgb_plus_1->green, rgb->green); 575b310b081SHarry Wentland rgb->delta_blue = dal_fixed31_32_sub(rgb_plus_1->blue, rgb->blue); 576fcd2f4bfSAmy Zhang 577fcd2f4bfSAmy Zhang ++rgb_plus_1; 578fcd2f4bfSAmy Zhang ++rgb; 579fcd2f4bfSAmy Zhang ++i; 580fcd2f4bfSAmy Zhang } 581fcd2f4bfSAmy Zhang 582fcd2f4bfSAmy Zhang convert_to_custom_float(rgb_resulted, arr_points, hw_points); 583fcd2f4bfSAmy Zhang 584fcd2f4bfSAmy Zhang return true; 585fcd2f4bfSAmy Zhang } 586fcd2f4bfSAmy Zhang 587a6114e85SHarry Wentland static bool 588a6114e85SHarry Wentland dce110_set_output_transfer_func(struct pipe_ctx *pipe_ctx, 5890971c40eSHarry Wentland const struct dc_stream_state *stream) 59090e508baSAnthony Koo { 59186a66c4eSHarry Wentland struct transform *xfm = pipe_ctx->plane_res.xfm; 5924562236bSHarry Wentland 5937a09f5beSYue Hin Lau xfm->funcs->opp_power_on_regamma_lut(xfm, true); 5947a09f5beSYue Hin Lau xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM; 5954562236bSHarry Wentland 5964fa086b9SLeo (Sunpeng) Li if (stream->out_transfer_func && 597efd52204SHarry Wentland stream->out_transfer_func->type == TF_TYPE_PREDEFINED && 598efd52204SHarry Wentland stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) { 5997a09f5beSYue Hin Lau xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB); 600efd52204SHarry Wentland } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func, 601efd52204SHarry Wentland &xfm->regamma_params)) { 6027a09f5beSYue Hin Lau xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params); 6037a09f5beSYue Hin Lau xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER); 6044562236bSHarry Wentland } else { 6057a09f5beSYue Hin Lau xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS); 6064562236bSHarry Wentland } 6074562236bSHarry Wentland 6087a09f5beSYue Hin Lau xfm->funcs->opp_power_on_regamma_lut(xfm, false); 6094562236bSHarry Wentland 610cc0cb445SLeon Elazar return true; 6114562236bSHarry Wentland } 6124562236bSHarry Wentland 6134562236bSHarry Wentland static enum dc_status bios_parser_crtc_source_select( 6144562236bSHarry Wentland struct pipe_ctx *pipe_ctx) 6154562236bSHarry Wentland { 6164562236bSHarry Wentland struct dc_bios *dcb; 6174562236bSHarry Wentland /* call VBIOS table to set CRTC source for the HW 6184562236bSHarry Wentland * encoder block 6194562236bSHarry Wentland * note: video bios clears all FMT setting here. */ 6204562236bSHarry Wentland struct bp_crtc_source_select crtc_source_select = {0}; 621b73a22d3SHarry Wentland const struct dc_sink *sink = pipe_ctx->stream->sink; 6224562236bSHarry Wentland 6238e9c4c8cSHarry Wentland crtc_source_select.engine_id = pipe_ctx->stream_res.stream_enc->id; 624e07f541fSYongqiang Sun crtc_source_select.controller_id = pipe_ctx->stream_res.tg->inst + 1; 6254562236bSHarry Wentland /*TODO: Need to un-hardcode color depth, dp_audio and account for 6264562236bSHarry Wentland * the case where signal and sink signal is different (translator 6274562236bSHarry Wentland * encoder)*/ 6284562236bSHarry Wentland crtc_source_select.signal = pipe_ctx->stream->signal; 6294562236bSHarry Wentland crtc_source_select.enable_dp_audio = false; 6304562236bSHarry Wentland crtc_source_select.sink_signal = pipe_ctx->stream->signal; 6311b7441b0SCharlene Liu 6321b7441b0SCharlene Liu switch (pipe_ctx->stream->timing.display_color_depth) { 6331b7441b0SCharlene Liu case COLOR_DEPTH_666: 6341b7441b0SCharlene Liu crtc_source_select.display_output_bit_depth = PANEL_6BIT_COLOR; 6351b7441b0SCharlene Liu break; 6361b7441b0SCharlene Liu case COLOR_DEPTH_888: 6374562236bSHarry Wentland crtc_source_select.display_output_bit_depth = PANEL_8BIT_COLOR; 6381b7441b0SCharlene Liu break; 6391b7441b0SCharlene Liu case COLOR_DEPTH_101010: 6401b7441b0SCharlene Liu crtc_source_select.display_output_bit_depth = PANEL_10BIT_COLOR; 6411b7441b0SCharlene Liu break; 6421b7441b0SCharlene Liu case COLOR_DEPTH_121212: 6431b7441b0SCharlene Liu crtc_source_select.display_output_bit_depth = PANEL_12BIT_COLOR; 6441b7441b0SCharlene Liu break; 6451b7441b0SCharlene Liu default: 6461b7441b0SCharlene Liu BREAK_TO_DEBUGGER(); 6471b7441b0SCharlene Liu crtc_source_select.display_output_bit_depth = PANEL_8BIT_COLOR; 6481b7441b0SCharlene Liu break; 6491b7441b0SCharlene Liu } 6504562236bSHarry Wentland 6514562236bSHarry Wentland dcb = sink->ctx->dc_bios; 6524562236bSHarry Wentland 6534562236bSHarry Wentland if (BP_RESULT_OK != dcb->funcs->crtc_source_select( 6544562236bSHarry Wentland dcb, 6554562236bSHarry Wentland &crtc_source_select)) { 6564562236bSHarry Wentland return DC_ERROR_UNEXPECTED; 6574562236bSHarry Wentland } 6584562236bSHarry Wentland 6594562236bSHarry Wentland return DC_OK; 6604562236bSHarry Wentland } 6614562236bSHarry Wentland 6624562236bSHarry Wentland void dce110_update_info_frame(struct pipe_ctx *pipe_ctx) 6634562236bSHarry Wentland { 66486e2e1beSHersen Wu ASSERT(pipe_ctx->stream); 66586e2e1beSHersen Wu 6668e9c4c8cSHarry Wentland if (pipe_ctx->stream_res.stream_enc == NULL) 66786e2e1beSHersen Wu return; /* this is not root pipe */ 66886e2e1beSHersen Wu 6694562236bSHarry Wentland if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) 6708e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets( 6718e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 67296c50c0dSHarry Wentland &pipe_ctx->stream_res.encoder_info_frame); 6734562236bSHarry Wentland else if (dc_is_dp_signal(pipe_ctx->stream->signal)) 6748e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets( 6758e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 67696c50c0dSHarry Wentland &pipe_ctx->stream_res.encoder_info_frame); 6774562236bSHarry Wentland } 6784562236bSHarry Wentland 6794562236bSHarry Wentland void dce110_enable_stream(struct pipe_ctx *pipe_ctx) 6804562236bSHarry Wentland { 6814562236bSHarry Wentland enum dc_lane_count lane_count = 682d0778ebfSHarry Wentland pipe_ctx->stream->sink->link->cur_link_settings.lane_count; 6834562236bSHarry Wentland 6844fa086b9SLeo (Sunpeng) Li struct dc_crtc_timing *timing = &pipe_ctx->stream->timing; 685d0778ebfSHarry Wentland struct dc_link *link = pipe_ctx->stream->sink->link; 6864562236bSHarry Wentland 687f215a57dSEric Yang 6884562236bSHarry Wentland uint32_t active_total_with_borders; 6894562236bSHarry Wentland uint32_t early_control = 0; 6906b670fa9SHarry Wentland struct timing_generator *tg = pipe_ctx->stream_res.tg; 6914562236bSHarry Wentland 692f215a57dSEric Yang /* For MST, there are multiply stream go to only one link. 693f215a57dSEric Yang * connect DIG back_end to front_end while enable_stream and 694f215a57dSEric Yang * disconnect them during disable_stream 695f215a57dSEric Yang * BY this, it is logic clean to separate stream and link */ 696f215a57dSEric Yang link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc, 697f215a57dSEric Yang pipe_ctx->stream_res.stream_enc->id, true); 698f215a57dSEric Yang 699f215a57dSEric Yang /* update AVI info frame (HDMI, DP)*/ 700f215a57dSEric Yang /* TODO: FPGA may change to hwss.update_info_frame */ 7014562236bSHarry Wentland dce110_update_info_frame(pipe_ctx); 702f215a57dSEric Yang 7034562236bSHarry Wentland /* enable early control to avoid corruption on DP monitor*/ 7044562236bSHarry Wentland active_total_with_borders = 7054562236bSHarry Wentland timing->h_addressable 7064562236bSHarry Wentland + timing->h_border_left 7074562236bSHarry Wentland + timing->h_border_right; 7084562236bSHarry Wentland 7094562236bSHarry Wentland if (lane_count != 0) 7104562236bSHarry Wentland early_control = active_total_with_borders % lane_count; 7114562236bSHarry Wentland 7124562236bSHarry Wentland if (early_control == 0) 7134562236bSHarry Wentland early_control = lane_count; 7144562236bSHarry Wentland 7154562236bSHarry Wentland tg->funcs->set_early_control(tg, early_control); 7164562236bSHarry Wentland 7174562236bSHarry Wentland /* enable audio only within mode set */ 718afaacef4SHarry Wentland if (pipe_ctx->stream_res.audio != NULL) { 7194562236bSHarry Wentland if (dc_is_dp_signal(pipe_ctx->stream->signal)) 7208e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc); 7214562236bSHarry Wentland } 7224562236bSHarry Wentland 723f215a57dSEric Yang 724f215a57dSEric Yang 7254562236bSHarry Wentland 7264562236bSHarry Wentland } 7274562236bSHarry Wentland 7285eefbc40SYue Hin Lau /*todo: cloned in stream enc, fix*/ 7295eefbc40SYue Hin Lau static bool is_panel_backlight_on(struct dce_hwseq *hws) 7305eefbc40SYue Hin Lau { 7315eefbc40SYue Hin Lau uint32_t value; 7325eefbc40SYue Hin Lau 7335eefbc40SYue Hin Lau REG_GET(LVTMA_PWRSEQ_CNTL, LVTMA_BLON, &value); 7345eefbc40SYue Hin Lau 7355eefbc40SYue Hin Lau return value; 7365eefbc40SYue Hin Lau } 7375eefbc40SYue Hin Lau 73887401969SAndrew Jiang static bool is_panel_powered_on(struct dce_hwseq *hws) 73987401969SAndrew Jiang { 740d03f3f63SEric Yang uint32_t pwr_seq_state, dig_on, dig_on_ovrd; 74187401969SAndrew Jiang 742d03f3f63SEric Yang 743d03f3f63SEric Yang REG_GET(LVTMA_PWRSEQ_STATE, LVTMA_PWRSEQ_TARGET_STATE_R, &pwr_seq_state); 744d03f3f63SEric Yang 745d03f3f63SEric Yang REG_GET_2(LVTMA_PWRSEQ_CNTL, LVTMA_DIGON, &dig_on, LVTMA_DIGON_OVRD, &dig_on_ovrd); 746d03f3f63SEric Yang 747d03f3f63SEric Yang return (pwr_seq_state == 1) || (dig_on == 1 && dig_on_ovrd == 1); 74887401969SAndrew Jiang } 74987401969SAndrew Jiang 7505eefbc40SYue Hin Lau static enum bp_result link_transmitter_control( 75187401969SAndrew Jiang struct dc_bios *bios, 7525eefbc40SYue Hin Lau struct bp_transmitter_control *cntl) 7535eefbc40SYue Hin Lau { 7545eefbc40SYue Hin Lau enum bp_result result; 7555eefbc40SYue Hin Lau 75687401969SAndrew Jiang result = bios->funcs->transmitter_control(bios, cntl); 7575eefbc40SYue Hin Lau 7585eefbc40SYue Hin Lau return result; 7595eefbc40SYue Hin Lau } 7605eefbc40SYue Hin Lau 76187401969SAndrew Jiang /* 76287401969SAndrew Jiang * @brief 76387401969SAndrew Jiang * eDP only. 76487401969SAndrew Jiang */ 76587401969SAndrew Jiang void hwss_edp_wait_for_hpd_ready( 766069d418fSAndrew Jiang struct dc_link *link, 76787401969SAndrew Jiang bool power_up) 76887401969SAndrew Jiang { 769069d418fSAndrew Jiang struct dc_context *ctx = link->ctx; 770069d418fSAndrew Jiang struct graphics_object_id connector = link->link_enc->connector; 77187401969SAndrew Jiang struct gpio *hpd; 77287401969SAndrew Jiang bool edp_hpd_high = false; 77387401969SAndrew Jiang uint32_t time_elapsed = 0; 77487401969SAndrew Jiang uint32_t timeout = power_up ? 77587401969SAndrew Jiang PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT; 77687401969SAndrew Jiang 77787401969SAndrew Jiang if (dal_graphics_object_id_get_connector_id(connector) 77887401969SAndrew Jiang != CONNECTOR_ID_EDP) { 77987401969SAndrew Jiang BREAK_TO_DEBUGGER(); 78087401969SAndrew Jiang return; 78187401969SAndrew Jiang } 78287401969SAndrew Jiang 78387401969SAndrew Jiang if (!power_up) 78487401969SAndrew Jiang /* 78587401969SAndrew Jiang * From KV, we will not HPD low after turning off VCC - 78687401969SAndrew Jiang * instead, we will check the SW timer in power_up(). 78787401969SAndrew Jiang */ 78887401969SAndrew Jiang return; 78987401969SAndrew Jiang 79087401969SAndrew Jiang /* 79187401969SAndrew Jiang * When we power on/off the eDP panel, 79287401969SAndrew Jiang * we need to wait until SENSE bit is high/low. 79387401969SAndrew Jiang */ 79487401969SAndrew Jiang 79587401969SAndrew Jiang /* obtain HPD */ 79687401969SAndrew Jiang /* TODO what to do with this? */ 79787401969SAndrew Jiang hpd = get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service); 79887401969SAndrew Jiang 79987401969SAndrew Jiang if (!hpd) { 80087401969SAndrew Jiang BREAK_TO_DEBUGGER(); 80187401969SAndrew Jiang return; 80287401969SAndrew Jiang } 80387401969SAndrew Jiang 80487401969SAndrew Jiang dal_gpio_open(hpd, GPIO_MODE_INTERRUPT); 80587401969SAndrew Jiang 80687401969SAndrew Jiang /* wait until timeout or panel detected */ 80787401969SAndrew Jiang 80887401969SAndrew Jiang do { 80987401969SAndrew Jiang uint32_t detected = 0; 81087401969SAndrew Jiang 81187401969SAndrew Jiang dal_gpio_get_value(hpd, &detected); 81287401969SAndrew Jiang 81387401969SAndrew Jiang if (!(detected ^ power_up)) { 81487401969SAndrew Jiang edp_hpd_high = true; 81587401969SAndrew Jiang break; 81687401969SAndrew Jiang } 81787401969SAndrew Jiang 81887401969SAndrew Jiang msleep(HPD_CHECK_INTERVAL); 81987401969SAndrew Jiang 82087401969SAndrew Jiang time_elapsed += HPD_CHECK_INTERVAL; 82187401969SAndrew Jiang } while (time_elapsed < timeout); 82287401969SAndrew Jiang 82387401969SAndrew Jiang dal_gpio_close(hpd); 82487401969SAndrew Jiang 82587401969SAndrew Jiang dal_gpio_destroy_irq(&hpd); 82687401969SAndrew Jiang 82787401969SAndrew Jiang if (false == edp_hpd_high) { 8281296423bSBhawanpreet Lakha DC_LOG_ERROR( 82987401969SAndrew Jiang "%s: wait timed out!\n", __func__); 83087401969SAndrew Jiang } 83187401969SAndrew Jiang } 83287401969SAndrew Jiang 83387401969SAndrew Jiang void hwss_edp_power_control( 834069d418fSAndrew Jiang struct dc_link *link, 83587401969SAndrew Jiang bool power_up) 83687401969SAndrew Jiang { 837069d418fSAndrew Jiang struct dc_context *ctx = link->ctx; 83887401969SAndrew Jiang struct dce_hwseq *hwseq = ctx->dc->hwseq; 83987401969SAndrew Jiang struct bp_transmitter_control cntl = { 0 }; 84087401969SAndrew Jiang enum bp_result bp_result; 84187401969SAndrew Jiang 84287401969SAndrew Jiang 843069d418fSAndrew Jiang if (dal_graphics_object_id_get_connector_id(link->link_enc->connector) 84487401969SAndrew Jiang != CONNECTOR_ID_EDP) { 84587401969SAndrew Jiang BREAK_TO_DEBUGGER(); 84687401969SAndrew Jiang return; 84787401969SAndrew Jiang } 84887401969SAndrew Jiang 84987401969SAndrew Jiang if (power_up != is_panel_powered_on(hwseq)) { 85087401969SAndrew Jiang /* Send VBIOS command to prompt eDP panel power */ 85187401969SAndrew Jiang 8521296423bSBhawanpreet Lakha DC_LOG_HW_RESUME_S3( 85387401969SAndrew Jiang "%s: Panel Power action: %s\n", 85487401969SAndrew Jiang __func__, (power_up ? "On":"Off")); 85587401969SAndrew Jiang 85687401969SAndrew Jiang cntl.action = power_up ? 85787401969SAndrew Jiang TRANSMITTER_CONTROL_POWER_ON : 85887401969SAndrew Jiang TRANSMITTER_CONTROL_POWER_OFF; 859069d418fSAndrew Jiang cntl.transmitter = link->link_enc->transmitter; 860069d418fSAndrew Jiang cntl.connector_obj_id = link->link_enc->connector; 86187401969SAndrew Jiang cntl.coherent = false; 86287401969SAndrew Jiang cntl.lanes_number = LANE_COUNT_FOUR; 863069d418fSAndrew Jiang cntl.hpd_sel = link->link_enc->hpd_source; 86487401969SAndrew Jiang 86587401969SAndrew Jiang bp_result = link_transmitter_control(ctx->dc_bios, &cntl); 86687401969SAndrew Jiang 86787401969SAndrew Jiang if (bp_result != BP_RESULT_OK) 8681296423bSBhawanpreet Lakha DC_LOG_ERROR( 86987401969SAndrew Jiang "%s: Panel Power bp_result: %d\n", 87087401969SAndrew Jiang __func__, bp_result); 87187401969SAndrew Jiang } else { 8721296423bSBhawanpreet Lakha DC_LOG_HW_RESUME_S3( 87387401969SAndrew Jiang "%s: Skipping Panel Power action: %s\n", 87487401969SAndrew Jiang __func__, (power_up ? "On":"Off")); 87587401969SAndrew Jiang } 87687401969SAndrew Jiang } 8775eefbc40SYue Hin Lau 8785eefbc40SYue Hin Lau /*todo: cloned in stream enc, fix*/ 8795eefbc40SYue Hin Lau /* 8805eefbc40SYue Hin Lau * @brief 8815eefbc40SYue Hin Lau * eDP only. Control the backlight of the eDP panel 8825eefbc40SYue Hin Lau */ 88387401969SAndrew Jiang void hwss_edp_backlight_control( 8845eefbc40SYue Hin Lau struct dc_link *link, 8855eefbc40SYue Hin Lau bool enable) 8865eefbc40SYue Hin Lau { 887069d418fSAndrew Jiang struct dc_context *ctx = link->ctx; 888069d418fSAndrew Jiang struct dce_hwseq *hws = ctx->dc->hwseq; 8895eefbc40SYue Hin Lau struct bp_transmitter_control cntl = { 0 }; 8905eefbc40SYue Hin Lau 891069d418fSAndrew Jiang if (dal_graphics_object_id_get_connector_id(link->link_enc->connector) 8925eefbc40SYue Hin Lau != CONNECTOR_ID_EDP) { 8935eefbc40SYue Hin Lau BREAK_TO_DEBUGGER(); 8945eefbc40SYue Hin Lau return; 8955eefbc40SYue Hin Lau } 8965eefbc40SYue Hin Lau 8975eefbc40SYue Hin Lau if (enable && is_panel_backlight_on(hws)) { 8981296423bSBhawanpreet Lakha DC_LOG_HW_RESUME_S3( 8995eefbc40SYue Hin Lau "%s: panel already powered up. Do nothing.\n", 9005eefbc40SYue Hin Lau __func__); 9015eefbc40SYue Hin Lau return; 9025eefbc40SYue Hin Lau } 9035eefbc40SYue Hin Lau 9045eefbc40SYue Hin Lau /* Send VBIOS command to control eDP panel backlight */ 9055eefbc40SYue Hin Lau 9061296423bSBhawanpreet Lakha DC_LOG_HW_RESUME_S3( 9075eefbc40SYue Hin Lau "%s: backlight action: %s\n", 9085eefbc40SYue Hin Lau __func__, (enable ? "On":"Off")); 9095eefbc40SYue Hin Lau 9105eefbc40SYue Hin Lau cntl.action = enable ? 9115eefbc40SYue Hin Lau TRANSMITTER_CONTROL_BACKLIGHT_ON : 9125eefbc40SYue Hin Lau TRANSMITTER_CONTROL_BACKLIGHT_OFF; 91387401969SAndrew Jiang 9145eefbc40SYue Hin Lau /*cntl.engine_id = ctx->engine;*/ 9155eefbc40SYue Hin Lau cntl.transmitter = link->link_enc->transmitter; 9165eefbc40SYue Hin Lau cntl.connector_obj_id = link->link_enc->connector; 9175eefbc40SYue Hin Lau /*todo: unhardcode*/ 9185eefbc40SYue Hin Lau cntl.lanes_number = LANE_COUNT_FOUR; 9195eefbc40SYue Hin Lau cntl.hpd_sel = link->link_enc->hpd_source; 920cf1835f0SCharlene Liu cntl.signal = SIGNAL_TYPE_EDP; 9215eefbc40SYue Hin Lau 9225eefbc40SYue Hin Lau /* For eDP, the following delays might need to be considered 9235eefbc40SYue Hin Lau * after link training completed: 9245eefbc40SYue Hin Lau * idle period - min. accounts for required BS-Idle pattern, 9255eefbc40SYue Hin Lau * max. allows for source frame synchronization); 9265eefbc40SYue Hin Lau * 50 msec max. delay from valid video data from source 9275eefbc40SYue Hin Lau * to video on dislpay or backlight enable. 9285eefbc40SYue Hin Lau * 9295eefbc40SYue Hin Lau * Disable the delay for now. 9305eefbc40SYue Hin Lau * Enable it in the future if necessary. 9315eefbc40SYue Hin Lau */ 9325eefbc40SYue Hin Lau /* dc_service_sleep_in_milliseconds(50); */ 9335180d4a4SCharlene Liu /*edp 1.2*/ 9345180d4a4SCharlene Liu if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON) 9355180d4a4SCharlene Liu edp_receiver_ready_T7(link); 936069d418fSAndrew Jiang link_transmitter_control(ctx->dc_bios, &cntl); 93769b9723aSCharlene Liu /*edp 1.2*/ 9385180d4a4SCharlene Liu if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF) 93969b9723aSCharlene Liu edp_receiver_ready_T9(link); 9405eefbc40SYue Hin Lau } 9415eefbc40SYue Hin Lau 9424176664bSCharlene Liu void dce110_disable_stream(struct pipe_ctx *pipe_ctx, int option) 9434562236bSHarry Wentland { 9440971c40eSHarry Wentland struct dc_stream_state *stream = pipe_ctx->stream; 945d0778ebfSHarry Wentland struct dc_link *link = stream->sink->link; 9464176664bSCharlene Liu struct dc *dc = pipe_ctx->stream->ctx->dc; 9474562236bSHarry Wentland 9482b7c97d6SCharlene Liu if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) 9492b7c97d6SCharlene Liu pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets( 9502b7c97d6SCharlene Liu pipe_ctx->stream_res.stream_enc); 9512b7c97d6SCharlene Liu 9522b7c97d6SCharlene Liu if (dc_is_dp_signal(pipe_ctx->stream->signal)) 9532b7c97d6SCharlene Liu pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets( 9542b7c97d6SCharlene Liu pipe_ctx->stream_res.stream_enc); 9552b7c97d6SCharlene Liu 9562b7c97d6SCharlene Liu pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control( 9572b7c97d6SCharlene Liu pipe_ctx->stream_res.stream_enc, true); 958afaacef4SHarry Wentland if (pipe_ctx->stream_res.audio) { 9597c357e61SCharlene Liu if (option != KEEP_ACQUIRED_RESOURCE || 9607c357e61SCharlene Liu !dc->debug.az_endpoint_mute_only) { 9617c357e61SCharlene Liu /*only disalbe az_endpoint if power down or free*/ 962afaacef4SHarry Wentland pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio); 9637c357e61SCharlene Liu } 9644562236bSHarry Wentland 9654562236bSHarry Wentland if (dc_is_dp_signal(pipe_ctx->stream->signal)) 9668e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable( 9678e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc); 9684562236bSHarry Wentland else 9698e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable( 9708e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc); 9714176664bSCharlene Liu /*don't free audio if it is from retrain or internal disable stream*/ 9724176664bSCharlene Liu if (option == FREE_ACQUIRED_RESOURCE && dc->caps.dynamic_audio == true) { 9734176664bSCharlene Liu /*we have to dynamic arbitrate the audio endpoints*/ 9744176664bSCharlene Liu pipe_ctx->stream_res.audio = NULL; 9754176664bSCharlene Liu /*we free the resource, need reset is_audio_acquired*/ 9764176664bSCharlene Liu update_audio_usage(&dc->current_state->res_ctx, dc->res_pool, pipe_ctx->stream_res.audio, false); 9774176664bSCharlene Liu } 9784562236bSHarry Wentland 9794562236bSHarry Wentland /* TODO: notify audio driver for if audio modes list changed 9804562236bSHarry Wentland * add audio mode list change flag */ 9814562236bSHarry Wentland /* dal_audio_disable_azalia_audio_jack_presence(stream->audio, 9824562236bSHarry Wentland * stream->stream_engine_id); 9834562236bSHarry Wentland */ 9844562236bSHarry Wentland } 9854562236bSHarry Wentland 986904623eeSYongqiang Sun 9874562236bSHarry Wentland link->link_enc->funcs->connect_dig_be_to_fe( 9884562236bSHarry Wentland link->link_enc, 9898e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->id, 9904562236bSHarry Wentland false); 9914562236bSHarry Wentland 9924562236bSHarry Wentland } 9934562236bSHarry Wentland 9944562236bSHarry Wentland void dce110_unblank_stream(struct pipe_ctx *pipe_ctx, 9954562236bSHarry Wentland struct dc_link_settings *link_settings) 9964562236bSHarry Wentland { 9974562236bSHarry Wentland struct encoder_unblank_param params = { { 0 } }; 99841b49742SCharlene Liu struct dc_stream_state *stream = pipe_ctx->stream; 99941b49742SCharlene Liu struct dc_link *link = stream->sink->link; 10004562236bSHarry Wentland 10014562236bSHarry Wentland /* only 3 items below are used by unblank */ 10026235b23cSTony Cheng params.pixel_clk_khz = 10034fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->timing.pix_clk_khz; 10044562236bSHarry Wentland params.link_settings.link_rate = link_settings->link_rate; 100541b49742SCharlene Liu 100641b49742SCharlene Liu if (dc_is_dp_signal(pipe_ctx->stream->signal)) 10078e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(pipe_ctx->stream_res.stream_enc, ¶ms); 100841b49742SCharlene Liu 100941b49742SCharlene Liu if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) 101041b49742SCharlene Liu link->dc->hwss.edp_backlight_control(link, true); 101141b49742SCharlene Liu } 101241b49742SCharlene Liu void dce110_blank_stream(struct pipe_ctx *pipe_ctx) 101341b49742SCharlene Liu { 101441b49742SCharlene Liu struct dc_stream_state *stream = pipe_ctx->stream; 101541b49742SCharlene Liu struct dc_link *link = stream->sink->link; 101641b49742SCharlene Liu 101741b49742SCharlene Liu if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) 101841b49742SCharlene Liu link->dc->hwss.edp_backlight_control(link, false); 101941b49742SCharlene Liu 102041b49742SCharlene Liu if (dc_is_dp_signal(pipe_ctx->stream->signal)) 102141b49742SCharlene Liu pipe_ctx->stream_res.stream_enc->funcs->dp_blank(pipe_ctx->stream_res.stream_enc); 10224562236bSHarry Wentland } 10234562236bSHarry Wentland 102415e17335SCharlene Liu 102515e17335SCharlene Liu void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable) 102615e17335SCharlene Liu { 10278e9c4c8cSHarry Wentland if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL) 10288e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable); 102915e17335SCharlene Liu } 103015e17335SCharlene Liu 10314562236bSHarry Wentland static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id) 10324562236bSHarry Wentland { 10334562236bSHarry Wentland switch (crtc_id) { 10344562236bSHarry Wentland case CONTROLLER_ID_D0: 10354562236bSHarry Wentland return DTO_SOURCE_ID0; 10364562236bSHarry Wentland case CONTROLLER_ID_D1: 10374562236bSHarry Wentland return DTO_SOURCE_ID1; 10384562236bSHarry Wentland case CONTROLLER_ID_D2: 10394562236bSHarry Wentland return DTO_SOURCE_ID2; 10404562236bSHarry Wentland case CONTROLLER_ID_D3: 10414562236bSHarry Wentland return DTO_SOURCE_ID3; 10424562236bSHarry Wentland case CONTROLLER_ID_D4: 10434562236bSHarry Wentland return DTO_SOURCE_ID4; 10444562236bSHarry Wentland case CONTROLLER_ID_D5: 10454562236bSHarry Wentland return DTO_SOURCE_ID5; 10464562236bSHarry Wentland default: 10474562236bSHarry Wentland return DTO_SOURCE_UNKNOWN; 10484562236bSHarry Wentland } 10494562236bSHarry Wentland } 10504562236bSHarry Wentland 10514562236bSHarry Wentland static void build_audio_output( 1052ab8db3e1SAndrey Grodzovsky struct dc_state *state, 10534562236bSHarry Wentland const struct pipe_ctx *pipe_ctx, 10544562236bSHarry Wentland struct audio_output *audio_output) 10554562236bSHarry Wentland { 10560971c40eSHarry Wentland const struct dc_stream_state *stream = pipe_ctx->stream; 10578e9c4c8cSHarry Wentland audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id; 10584562236bSHarry Wentland 10594562236bSHarry Wentland audio_output->signal = pipe_ctx->stream->signal; 10604562236bSHarry Wentland 10614562236bSHarry Wentland /* audio_crtc_info */ 10624562236bSHarry Wentland 10634562236bSHarry Wentland audio_output->crtc_info.h_total = 10644fa086b9SLeo (Sunpeng) Li stream->timing.h_total; 10654562236bSHarry Wentland 10664562236bSHarry Wentland /* 10674562236bSHarry Wentland * Audio packets are sent during actual CRTC blank physical signal, we 10684562236bSHarry Wentland * need to specify actual active signal portion 10694562236bSHarry Wentland */ 10704562236bSHarry Wentland audio_output->crtc_info.h_active = 10714fa086b9SLeo (Sunpeng) Li stream->timing.h_addressable 10724fa086b9SLeo (Sunpeng) Li + stream->timing.h_border_left 10734fa086b9SLeo (Sunpeng) Li + stream->timing.h_border_right; 10744562236bSHarry Wentland 10754562236bSHarry Wentland audio_output->crtc_info.v_active = 10764fa086b9SLeo (Sunpeng) Li stream->timing.v_addressable 10774fa086b9SLeo (Sunpeng) Li + stream->timing.v_border_top 10784fa086b9SLeo (Sunpeng) Li + stream->timing.v_border_bottom; 10794562236bSHarry Wentland 10804562236bSHarry Wentland audio_output->crtc_info.pixel_repetition = 1; 10814562236bSHarry Wentland 10824562236bSHarry Wentland audio_output->crtc_info.interlaced = 10834fa086b9SLeo (Sunpeng) Li stream->timing.flags.INTERLACE; 10844562236bSHarry Wentland 10854562236bSHarry Wentland audio_output->crtc_info.refresh_rate = 10864fa086b9SLeo (Sunpeng) Li (stream->timing.pix_clk_khz*1000)/ 10874fa086b9SLeo (Sunpeng) Li (stream->timing.h_total*stream->timing.v_total); 10884562236bSHarry Wentland 10894562236bSHarry Wentland audio_output->crtc_info.color_depth = 10904fa086b9SLeo (Sunpeng) Li stream->timing.display_color_depth; 10914562236bSHarry Wentland 10924562236bSHarry Wentland audio_output->crtc_info.requested_pixel_clock = 109310688217SHarry Wentland pipe_ctx->stream_res.pix_clk_params.requested_pix_clk; 10944562236bSHarry Wentland 10954562236bSHarry Wentland audio_output->crtc_info.calculated_pixel_clock = 109610688217SHarry Wentland pipe_ctx->stream_res.pix_clk_params.requested_pix_clk; 10974562236bSHarry Wentland 109887b58768SCharlene Liu /*for HDMI, audio ACR is with deep color ratio factor*/ 109987b58768SCharlene Liu if (dc_is_hdmi_signal(pipe_ctx->stream->signal) && 110087b58768SCharlene Liu audio_output->crtc_info.requested_pixel_clock == 11014fa086b9SLeo (Sunpeng) Li stream->timing.pix_clk_khz) { 110210688217SHarry Wentland if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) { 110387b58768SCharlene Liu audio_output->crtc_info.requested_pixel_clock = 110487b58768SCharlene Liu audio_output->crtc_info.requested_pixel_clock/2; 110587b58768SCharlene Liu audio_output->crtc_info.calculated_pixel_clock = 110610688217SHarry Wentland pipe_ctx->stream_res.pix_clk_params.requested_pix_clk/2; 110787b58768SCharlene Liu 110887b58768SCharlene Liu } 110987b58768SCharlene Liu } 111087b58768SCharlene Liu 11114562236bSHarry Wentland if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT || 11124562236bSHarry Wentland pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) { 11134562236bSHarry Wentland audio_output->pll_info.dp_dto_source_clock_in_khz = 1114ab8db3e1SAndrey Grodzovsky state->dis_clk->funcs->get_dp_ref_clk_frequency( 1115ab8db3e1SAndrey Grodzovsky state->dis_clk); 11164562236bSHarry Wentland } 11174562236bSHarry Wentland 11184562236bSHarry Wentland audio_output->pll_info.feed_back_divider = 11194562236bSHarry Wentland pipe_ctx->pll_settings.feedback_divider; 11204562236bSHarry Wentland 11214562236bSHarry Wentland audio_output->pll_info.dto_source = 11224562236bSHarry Wentland translate_to_dto_source( 1123e07f541fSYongqiang Sun pipe_ctx->stream_res.tg->inst + 1); 11244562236bSHarry Wentland 11254562236bSHarry Wentland /* TODO hard code to enable for now. Need get from stream */ 11264562236bSHarry Wentland audio_output->pll_info.ss_enabled = true; 11274562236bSHarry Wentland 11284562236bSHarry Wentland audio_output->pll_info.ss_percentage = 11294562236bSHarry Wentland pipe_ctx->pll_settings.ss_percentage; 11304562236bSHarry Wentland } 11314562236bSHarry Wentland 11324562236bSHarry Wentland static void get_surface_visual_confirm_color(const struct pipe_ctx *pipe_ctx, 11334562236bSHarry Wentland struct tg_color *color) 11344562236bSHarry Wentland { 11352a54bd6eSJerry (Fangzhi) Zuo uint32_t color_value = MAX_TG_COLOR_VALUE * (4 - pipe_ctx->stream_res.tg->inst) / 4; 11364562236bSHarry Wentland 11376702a9acSHarry Wentland switch (pipe_ctx->plane_res.scl_data.format) { 11384562236bSHarry Wentland case PIXEL_FORMAT_ARGB8888: 11394562236bSHarry Wentland /* set boarder color to red */ 11404562236bSHarry Wentland color->color_r_cr = color_value; 11414562236bSHarry Wentland break; 11424562236bSHarry Wentland 11434562236bSHarry Wentland case PIXEL_FORMAT_ARGB2101010: 11444562236bSHarry Wentland /* set boarder color to blue */ 11454562236bSHarry Wentland color->color_b_cb = color_value; 11464562236bSHarry Wentland break; 114787449a90SAnthony Koo case PIXEL_FORMAT_420BPP8: 11484562236bSHarry Wentland /* set boarder color to green */ 11494562236bSHarry Wentland color->color_g_y = color_value; 11504562236bSHarry Wentland break; 115187449a90SAnthony Koo case PIXEL_FORMAT_420BPP10: 115287449a90SAnthony Koo /* set boarder color to yellow */ 115387449a90SAnthony Koo color->color_g_y = color_value; 115487449a90SAnthony Koo color->color_r_cr = color_value; 115587449a90SAnthony Koo break; 11564562236bSHarry Wentland case PIXEL_FORMAT_FP16: 11574562236bSHarry Wentland /* set boarder color to white */ 11584562236bSHarry Wentland color->color_r_cr = color_value; 11594562236bSHarry Wentland color->color_b_cb = color_value; 11604562236bSHarry Wentland color->color_g_y = color_value; 11614562236bSHarry Wentland break; 11624562236bSHarry Wentland default: 11634562236bSHarry Wentland break; 11644562236bSHarry Wentland } 11654562236bSHarry Wentland } 11664562236bSHarry Wentland 1167fb3466a4SBhawanpreet Lakha static void program_scaler(const struct dc *dc, 11684562236bSHarry Wentland const struct pipe_ctx *pipe_ctx) 11694562236bSHarry Wentland { 11704562236bSHarry Wentland struct tg_color color = {0}; 11714562236bSHarry Wentland 1172ff5ef992SAlex Deucher #if defined(CONFIG_DRM_AMD_DC_DCN1_0) 1173ff5ef992SAlex Deucher /* TOFPGA */ 117486a66c4eSHarry Wentland if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL) 1175ff5ef992SAlex Deucher return; 1176ff5ef992SAlex Deucher #endif 1177ff5ef992SAlex Deucher 1178fb3466a4SBhawanpreet Lakha if (dc->debug.surface_visual_confirm) 11794562236bSHarry Wentland get_surface_visual_confirm_color(pipe_ctx, &color); 11804562236bSHarry Wentland else 11814562236bSHarry Wentland color_space_to_black_color(dc, 11824fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->output_color_space, 11834562236bSHarry Wentland &color); 11844562236bSHarry Wentland 118586a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth( 118686a66c4eSHarry Wentland pipe_ctx->plane_res.xfm, 11876702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.lb_params.depth, 11884562236bSHarry Wentland &pipe_ctx->stream->bit_depth_params); 11894562236bSHarry Wentland 11906b670fa9SHarry Wentland if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) 11916b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color( 11926b670fa9SHarry Wentland pipe_ctx->stream_res.tg, 11934562236bSHarry Wentland &color); 11944562236bSHarry Wentland 119586a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm, 11966702a9acSHarry Wentland &pipe_ctx->plane_res.scl_data); 11974562236bSHarry Wentland } 11984562236bSHarry Wentland 11994b5e7d62SHersen Wu static enum dc_status dce110_prog_pixclk_crtc_otg( 12004562236bSHarry Wentland struct pipe_ctx *pipe_ctx, 1201608ac7bbSJerry Zuo struct dc_state *context, 1202fb3466a4SBhawanpreet Lakha struct dc *dc) 12034562236bSHarry Wentland { 12040971c40eSHarry Wentland struct dc_stream_state *stream = pipe_ctx->stream; 1205608ac7bbSJerry Zuo struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx. 12064562236bSHarry Wentland pipe_ctx[pipe_ctx->pipe_idx]; 12074562236bSHarry Wentland struct tg_color black_color = {0}; 12084562236bSHarry Wentland 12094562236bSHarry Wentland if (!pipe_ctx_old->stream) { 12104562236bSHarry Wentland 12114562236bSHarry Wentland /* program blank color */ 12124562236bSHarry Wentland color_space_to_black_color(dc, 12134fa086b9SLeo (Sunpeng) Li stream->output_color_space, &black_color); 12146b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->set_blank_color( 12156b670fa9SHarry Wentland pipe_ctx->stream_res.tg, 12164562236bSHarry Wentland &black_color); 12174b5e7d62SHersen Wu 12184562236bSHarry Wentland /* 12194562236bSHarry Wentland * Must blank CRTC after disabling power gating and before any 12204562236bSHarry Wentland * programming, otherwise CRTC will be hung in bad state 12214562236bSHarry Wentland */ 12226b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true); 12234562236bSHarry Wentland 12244562236bSHarry Wentland if (false == pipe_ctx->clock_source->funcs->program_pix_clk( 12254562236bSHarry Wentland pipe_ctx->clock_source, 122610688217SHarry Wentland &pipe_ctx->stream_res.pix_clk_params, 12274562236bSHarry Wentland &pipe_ctx->pll_settings)) { 12284562236bSHarry Wentland BREAK_TO_DEBUGGER(); 12294562236bSHarry Wentland return DC_ERROR_UNEXPECTED; 12304562236bSHarry Wentland } 12314562236bSHarry Wentland 12326b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->program_timing( 12336b670fa9SHarry Wentland pipe_ctx->stream_res.tg, 12344fa086b9SLeo (Sunpeng) Li &stream->timing, 12354562236bSHarry Wentland true); 123694267b3dSSylvia Tsai 12376b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->set_static_screen_control( 12386b670fa9SHarry Wentland pipe_ctx->stream_res.tg, 123994267b3dSSylvia Tsai 0x182); 12404562236bSHarry Wentland } 12414562236bSHarry Wentland 12424562236bSHarry Wentland if (!pipe_ctx_old->stream) { 12436b670fa9SHarry Wentland if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc( 12446b670fa9SHarry Wentland pipe_ctx->stream_res.tg)) { 12454562236bSHarry Wentland BREAK_TO_DEBUGGER(); 12464562236bSHarry Wentland return DC_ERROR_UNEXPECTED; 12474562236bSHarry Wentland } 12484562236bSHarry Wentland } 12494562236bSHarry Wentland 125094267b3dSSylvia Tsai 125194267b3dSSylvia Tsai 12524562236bSHarry Wentland return DC_OK; 12534562236bSHarry Wentland } 12544562236bSHarry Wentland 12554562236bSHarry Wentland static enum dc_status apply_single_controller_ctx_to_hw( 12564562236bSHarry Wentland struct pipe_ctx *pipe_ctx, 1257608ac7bbSJerry Zuo struct dc_state *context, 1258fb3466a4SBhawanpreet Lakha struct dc *dc) 12594562236bSHarry Wentland { 12600971c40eSHarry Wentland struct dc_stream_state *stream = pipe_ctx->stream; 1261608ac7bbSJerry Zuo struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx. 12624562236bSHarry Wentland pipe_ctx[pipe_ctx->pipe_idx]; 12634562236bSHarry Wentland 12644562236bSHarry Wentland /* */ 12654562236bSHarry Wentland dc->hwss.prog_pixclk_crtc_otg(pipe_ctx, context, dc); 12664562236bSHarry Wentland 1267f0c4d997SCorbin McElhanney /* FPGA does not program backend */ 1268f0c4d997SCorbin McElhanney if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) { 1269a6a6cb34SHarry Wentland pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion( 1270a6a6cb34SHarry Wentland pipe_ctx->stream_res.opp, 12714562236bSHarry Wentland COLOR_SPACE_YCBCR601, 12724fa086b9SLeo (Sunpeng) Li stream->timing.display_color_depth, 12734562236bSHarry Wentland pipe_ctx->stream->signal); 12744562236bSHarry Wentland 1275a6a6cb34SHarry Wentland pipe_ctx->stream_res.opp->funcs->opp_program_fmt( 1276a6a6cb34SHarry Wentland pipe_ctx->stream_res.opp, 12774562236bSHarry Wentland &stream->bit_depth_params, 12784562236bSHarry Wentland &stream->clamping); 12794562236bSHarry Wentland return DC_OK; 1280181a888fSCharlene Liu } 12814562236bSHarry Wentland /* TODO: move to stream encoder */ 12824562236bSHarry Wentland if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL) 12834562236bSHarry Wentland if (DC_OK != bios_parser_crtc_source_select(pipe_ctx)) { 12844562236bSHarry Wentland BREAK_TO_DEBUGGER(); 12854562236bSHarry Wentland return DC_ERROR_UNEXPECTED; 12864562236bSHarry Wentland } 1287f0c4d997SCorbin McElhanney pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion( 1288f0c4d997SCorbin McElhanney pipe_ctx->stream_res.opp, 1289f0c4d997SCorbin McElhanney COLOR_SPACE_YCBCR601, 1290f0c4d997SCorbin McElhanney stream->timing.display_color_depth, 1291f0c4d997SCorbin McElhanney pipe_ctx->stream->signal); 12924562236bSHarry Wentland 12934562236bSHarry Wentland if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL) 12944562236bSHarry Wentland stream->sink->link->link_enc->funcs->setup( 12954562236bSHarry Wentland stream->sink->link->link_enc, 12964562236bSHarry Wentland pipe_ctx->stream->signal); 12974562236bSHarry Wentland 1298ab3c1798SVitaly Prosyak if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL) 12998e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync( 13008e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 13016b670fa9SHarry Wentland pipe_ctx->stream_res.tg->inst, 13024fa086b9SLeo (Sunpeng) Li stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE); 1303ab3c1798SVitaly Prosyak 1304ab3c1798SVitaly Prosyak 1305a6a6cb34SHarry Wentland pipe_ctx->stream_res.opp->funcs->opp_program_fmt( 1306a6a6cb34SHarry Wentland pipe_ctx->stream_res.opp, 1307181a888fSCharlene Liu &stream->bit_depth_params, 1308181a888fSCharlene Liu &stream->clamping); 1309603767f9STony Cheng 13104562236bSHarry Wentland if (dc_is_dp_signal(pipe_ctx->stream->signal)) 13118e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute( 13128e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 13134fa086b9SLeo (Sunpeng) Li &stream->timing, 13144fa086b9SLeo (Sunpeng) Li stream->output_color_space); 13154562236bSHarry Wentland 13164562236bSHarry Wentland if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) 13178e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute( 13188e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 13194fa086b9SLeo (Sunpeng) Li &stream->timing, 13204562236bSHarry Wentland stream->phy_pix_clk, 1321afaacef4SHarry Wentland pipe_ctx->stream_res.audio != NULL); 13224562236bSHarry Wentland 13234562236bSHarry Wentland if (dc_is_dvi_signal(pipe_ctx->stream->signal)) 13248e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute( 13258e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 13264fa086b9SLeo (Sunpeng) Li &stream->timing, 13274562236bSHarry Wentland (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ? 13284562236bSHarry Wentland true : false); 13294562236bSHarry Wentland 133015e17335SCharlene Liu resource_build_info_frame(pipe_ctx); 13313639fa68SZeyu Fan dce110_update_info_frame(pipe_ctx); 1332f0362823SYongqiang Sun if (!pipe_ctx_old->stream) 1333ab8db3e1SAndrey Grodzovsky core_link_enable_stream(context, pipe_ctx); 13344562236bSHarry Wentland 13356702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0; 13364562236bSHarry Wentland 133794267b3dSSylvia Tsai pipe_ctx->stream->sink->link->psr_enabled = false; 133894267b3dSSylvia Tsai 13394562236bSHarry Wentland return DC_OK; 13404562236bSHarry Wentland } 13414562236bSHarry Wentland 13424562236bSHarry Wentland /******************************************************************************/ 13434562236bSHarry Wentland 1344fb3466a4SBhawanpreet Lakha static void power_down_encoders(struct dc *dc) 13454562236bSHarry Wentland { 13464562236bSHarry Wentland int i; 1347a0c38ebaSCharlene Liu enum connector_id connector_id; 134868d77dd8SAndrew Jiang enum signal_type signal = SIGNAL_TYPE_NONE; 1349b9b171ffSHersen Wu 1350b9b171ffSHersen Wu /* do not know BIOS back-front mapping, simply blank all. It will not 1351b9b171ffSHersen Wu * hurt for non-DP 1352b9b171ffSHersen Wu */ 1353b9b171ffSHersen Wu for (i = 0; i < dc->res_pool->stream_enc_count; i++) { 1354b9b171ffSHersen Wu dc->res_pool->stream_enc[i]->funcs->dp_blank( 1355b9b171ffSHersen Wu dc->res_pool->stream_enc[i]); 1356b9b171ffSHersen Wu } 1357b9b171ffSHersen Wu 13584562236bSHarry Wentland for (i = 0; i < dc->link_count; i++) { 1359a0c38ebaSCharlene Liu connector_id = dal_graphics_object_id_get_connector_id(dc->links[i]->link_id); 1360a0c38ebaSCharlene Liu if ((connector_id == CONNECTOR_ID_DISPLAY_PORT) || 1361a0c38ebaSCharlene Liu (connector_id == CONNECTOR_ID_EDP)) { 1362a0c38ebaSCharlene Liu 1363a0c38ebaSCharlene Liu if (!dc->links[i]->wa_flags.dp_keep_receiver_powered) 1364a0c38ebaSCharlene Liu dp_receiver_power_ctrl(dc->links[i], false); 1365904623eeSYongqiang Sun if (connector_id == CONNECTOR_ID_EDP) 136668d77dd8SAndrew Jiang signal = SIGNAL_TYPE_EDP; 1367a0c38ebaSCharlene Liu } 1368a0c38ebaSCharlene Liu 13694562236bSHarry Wentland dc->links[i]->link_enc->funcs->disable_output( 1370069d418fSAndrew Jiang dc->links[i]->link_enc, signal); 13714562236bSHarry Wentland } 13724562236bSHarry Wentland } 13734562236bSHarry Wentland 1374fb3466a4SBhawanpreet Lakha static void power_down_controllers(struct dc *dc) 13754562236bSHarry Wentland { 13764562236bSHarry Wentland int i; 13774562236bSHarry Wentland 13784562236bSHarry Wentland for (i = 0; i < dc->res_pool->pipe_count; i++) { 13794562236bSHarry Wentland dc->res_pool->timing_generators[i]->funcs->disable_crtc( 13804562236bSHarry Wentland dc->res_pool->timing_generators[i]); 13814562236bSHarry Wentland } 13824562236bSHarry Wentland } 13834562236bSHarry Wentland 1384fb3466a4SBhawanpreet Lakha static void power_down_clock_sources(struct dc *dc) 13854562236bSHarry Wentland { 13864562236bSHarry Wentland int i; 13874562236bSHarry Wentland 13884562236bSHarry Wentland if (dc->res_pool->dp_clock_source->funcs->cs_power_down( 13894562236bSHarry Wentland dc->res_pool->dp_clock_source) == false) 13904562236bSHarry Wentland dm_error("Failed to power down pll! (dp clk src)\n"); 13914562236bSHarry Wentland 13924562236bSHarry Wentland for (i = 0; i < dc->res_pool->clk_src_count; i++) { 13934562236bSHarry Wentland if (dc->res_pool->clock_sources[i]->funcs->cs_power_down( 13944562236bSHarry Wentland dc->res_pool->clock_sources[i]) == false) 13954562236bSHarry Wentland dm_error("Failed to power down pll! (clk src index=%d)\n", i); 13964562236bSHarry Wentland } 13974562236bSHarry Wentland } 13984562236bSHarry Wentland 1399fb3466a4SBhawanpreet Lakha static void power_down_all_hw_blocks(struct dc *dc) 14004562236bSHarry Wentland { 14014562236bSHarry Wentland power_down_encoders(dc); 14024562236bSHarry Wentland 14034562236bSHarry Wentland power_down_controllers(dc); 14044562236bSHarry Wentland 14054562236bSHarry Wentland power_down_clock_sources(dc); 14061663ae1cSBhawanpreet Lakha 14073eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 14082f3bfb27SRoman Li if (dc->fbc_compressor) 14091663ae1cSBhawanpreet Lakha dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor); 14101663ae1cSBhawanpreet Lakha #endif 14114562236bSHarry Wentland } 14124562236bSHarry Wentland 14134562236bSHarry Wentland static void disable_vga_and_power_gate_all_controllers( 1414fb3466a4SBhawanpreet Lakha struct dc *dc) 14154562236bSHarry Wentland { 14164562236bSHarry Wentland int i; 14174562236bSHarry Wentland struct timing_generator *tg; 14184562236bSHarry Wentland struct dc_context *ctx = dc->ctx; 14194562236bSHarry Wentland 14204562236bSHarry Wentland for (i = 0; i < dc->res_pool->pipe_count; i++) { 14214562236bSHarry Wentland tg = dc->res_pool->timing_generators[i]; 14224562236bSHarry Wentland 14230a87425aSTony Cheng if (tg->funcs->disable_vga) 14244562236bSHarry Wentland tg->funcs->disable_vga(tg); 14254562236bSHarry Wentland 14264562236bSHarry Wentland /* Enable CLOCK gating for each pipe BEFORE controller 14274562236bSHarry Wentland * powergating. */ 14284562236bSHarry Wentland enable_display_pipe_clock_gating(ctx, 14294562236bSHarry Wentland true); 14304562236bSHarry Wentland 1431e6c258cbSYongqiang Sun dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i; 14327f914a62SYongqiang Sun dc->hwss.disable_plane(dc, 1433e6c258cbSYongqiang Sun &dc->current_state->res_ctx.pipe_ctx[i]); 14344562236bSHarry Wentland } 14354562236bSHarry Wentland } 14364562236bSHarry Wentland 1437cf1835f0SCharlene Liu static struct dc_link *get_link_for_edp_not_in_use( 143825292028SYongqiang Sun struct dc *dc, 143925292028SYongqiang Sun struct dc_state *context) 144025292028SYongqiang Sun { 144125292028SYongqiang Sun int i; 144225292028SYongqiang Sun struct dc_link *link = NULL; 144325292028SYongqiang Sun 144425292028SYongqiang Sun /* check if eDP panel is suppose to be set mode, if yes, no need to disable */ 144525292028SYongqiang Sun for (i = 0; i < context->stream_count; i++) { 144625292028SYongqiang Sun if (context->streams[i]->signal == SIGNAL_TYPE_EDP) 144725292028SYongqiang Sun return NULL; 144825292028SYongqiang Sun } 144925292028SYongqiang Sun 145025292028SYongqiang Sun /* check if there is an eDP panel not in use */ 145125292028SYongqiang Sun for (i = 0; i < dc->link_count; i++) { 145225292028SYongqiang Sun if (dc->links[i]->local_sink && 145325292028SYongqiang Sun dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) { 145425292028SYongqiang Sun link = dc->links[i]; 145525292028SYongqiang Sun break; 145625292028SYongqiang Sun } 145725292028SYongqiang Sun } 145825292028SYongqiang Sun 145925292028SYongqiang Sun return link; 146025292028SYongqiang Sun } 146125292028SYongqiang Sun 14624562236bSHarry Wentland /** 14634562236bSHarry Wentland * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need: 14644562236bSHarry Wentland * 1. Power down all DC HW blocks 14654562236bSHarry Wentland * 2. Disable VGA engine on all controllers 14664562236bSHarry Wentland * 3. Enable power gating for controller 14674562236bSHarry Wentland * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS) 14684562236bSHarry Wentland */ 146925292028SYongqiang Sun void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context) 14704562236bSHarry Wentland { 1471c5fc7f59SCharlene Liu struct dc_bios *dcb = dc->ctx->dc_bios; 14724562236bSHarry Wentland 14734cac1e6dSYongqiang Sun /* vbios already light up eDP, so we can leverage vbios and skip eDP 14744cac1e6dSYongqiang Sun * programming 14754cac1e6dSYongqiang Sun */ 14764cac1e6dSYongqiang Sun bool can_eDP_fast_boot_optimize = 14774cac1e6dSYongqiang Sun (dcb->funcs->get_vga_enabled_displays(dc->ctx->dc_bios) == ATOM_DISPLAY_LCD1_ACTIVE); 14784cac1e6dSYongqiang Sun 14794cac1e6dSYongqiang Sun /* if OS doesn't light up eDP and eDP link is available, we want to disable */ 14804cac1e6dSYongqiang Sun struct dc_link *edp_link_to_turnoff = NULL; 14814cac1e6dSYongqiang Sun 14824cac1e6dSYongqiang Sun if (can_eDP_fast_boot_optimize) { 14834cac1e6dSYongqiang Sun edp_link_to_turnoff = get_link_for_edp_not_in_use(dc, context); 14844cac1e6dSYongqiang Sun 14854cac1e6dSYongqiang Sun if (!edp_link_to_turnoff) 14864cac1e6dSYongqiang Sun dc->apply_edp_fast_boot_optimization = true; 14874cac1e6dSYongqiang Sun } 14884cac1e6dSYongqiang Sun 14894cac1e6dSYongqiang Sun if (!dc->apply_edp_fast_boot_optimization) { 14904cac1e6dSYongqiang Sun if (edp_link_to_turnoff) { 14914cac1e6dSYongqiang Sun /*turn off backlight before DP_blank and encoder powered down*/ 14924cac1e6dSYongqiang Sun dc->hwss.edp_backlight_control(edp_link_to_turnoff, false); 1493c5fc7f59SCharlene Liu } 1494c5fc7f59SCharlene Liu /*resume from S3, no vbios posting, no need to power down again*/ 149525292028SYongqiang Sun power_down_all_hw_blocks(dc); 14964562236bSHarry Wentland disable_vga_and_power_gate_all_controllers(dc); 1497cf1835f0SCharlene Liu if (edp_link_to_turnoff) 1498cf1835f0SCharlene Liu dc->hwss.edp_power_control(edp_link_to_turnoff, false); 1499c5fc7f59SCharlene Liu } 15004562236bSHarry Wentland bios_set_scratch_acc_mode_change(dc->ctx->dc_bios); 15014562236bSHarry Wentland } 15024562236bSHarry Wentland 15034562236bSHarry Wentland static uint32_t compute_pstate_blackout_duration( 15044562236bSHarry Wentland struct bw_fixed blackout_duration, 15050971c40eSHarry Wentland const struct dc_stream_state *stream) 15064562236bSHarry Wentland { 15074562236bSHarry Wentland uint32_t total_dest_line_time_ns; 15084562236bSHarry Wentland uint32_t pstate_blackout_duration_ns; 15094562236bSHarry Wentland 15104562236bSHarry Wentland pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24; 15114562236bSHarry Wentland 15124562236bSHarry Wentland total_dest_line_time_ns = 1000000UL * 15134fa086b9SLeo (Sunpeng) Li stream->timing.h_total / 15144fa086b9SLeo (Sunpeng) Li stream->timing.pix_clk_khz + 15154562236bSHarry Wentland pstate_blackout_duration_ns; 15164562236bSHarry Wentland 15174562236bSHarry Wentland return total_dest_line_time_ns; 15184562236bSHarry Wentland } 15194562236bSHarry Wentland 1520f774b339SEric Yang static void dce110_set_displaymarks( 1521fb3466a4SBhawanpreet Lakha const struct dc *dc, 1522608ac7bbSJerry Zuo struct dc_state *context) 15234562236bSHarry Wentland { 15244562236bSHarry Wentland uint8_t i, num_pipes; 15254562236bSHarry Wentland unsigned int underlay_idx = dc->res_pool->underlay_pipe_index; 15264562236bSHarry Wentland 15274562236bSHarry Wentland for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) { 15284562236bSHarry Wentland struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 15294562236bSHarry Wentland uint32_t total_dest_line_time_ns; 15304562236bSHarry Wentland 15314562236bSHarry Wentland if (pipe_ctx->stream == NULL) 15324562236bSHarry Wentland continue; 15334562236bSHarry Wentland 15344562236bSHarry Wentland total_dest_line_time_ns = compute_pstate_blackout_duration( 153577a4ea53SBhawanpreet Lakha dc->bw_vbios->blackout_duration, pipe_ctx->stream); 153686a66c4eSHarry Wentland pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks( 153786a66c4eSHarry Wentland pipe_ctx->plane_res.mi, 15389037d802SDmytro Laktyushkin context->bw.dce.nbp_state_change_wm_ns[num_pipes], 15399037d802SDmytro Laktyushkin context->bw.dce.stutter_exit_wm_ns[num_pipes], 15409037d802SDmytro Laktyushkin context->bw.dce.urgent_wm_ns[num_pipes], 15414562236bSHarry Wentland total_dest_line_time_ns); 15424562236bSHarry Wentland if (i == underlay_idx) { 15434562236bSHarry Wentland num_pipes++; 154486a66c4eSHarry Wentland pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks( 154586a66c4eSHarry Wentland pipe_ctx->plane_res.mi, 15469037d802SDmytro Laktyushkin context->bw.dce.nbp_state_change_wm_ns[num_pipes], 15479037d802SDmytro Laktyushkin context->bw.dce.stutter_exit_wm_ns[num_pipes], 15489037d802SDmytro Laktyushkin context->bw.dce.urgent_wm_ns[num_pipes], 15494562236bSHarry Wentland total_dest_line_time_ns); 15504562236bSHarry Wentland } 15514562236bSHarry Wentland num_pipes++; 15524562236bSHarry Wentland } 15534562236bSHarry Wentland } 15544562236bSHarry Wentland 1555a2b8659dSTony Cheng static void set_safe_displaymarks( 1556a2b8659dSTony Cheng struct resource_context *res_ctx, 1557a2b8659dSTony Cheng const struct resource_pool *pool) 15584562236bSHarry Wentland { 15594562236bSHarry Wentland int i; 1560a2b8659dSTony Cheng int underlay_idx = pool->underlay_pipe_index; 15619037d802SDmytro Laktyushkin struct dce_watermarks max_marks = { 15624562236bSHarry Wentland MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK }; 15639037d802SDmytro Laktyushkin struct dce_watermarks nbp_marks = { 15644562236bSHarry Wentland SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK }; 15654562236bSHarry Wentland 15664562236bSHarry Wentland for (i = 0; i < MAX_PIPES; i++) { 15678feabd03SYue Hin Lau if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL) 15684562236bSHarry Wentland continue; 15694562236bSHarry Wentland 157086a66c4eSHarry Wentland res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks( 157186a66c4eSHarry Wentland res_ctx->pipe_ctx[i].plane_res.mi, 15724562236bSHarry Wentland nbp_marks, 15734562236bSHarry Wentland max_marks, 15744562236bSHarry Wentland max_marks, 15754562236bSHarry Wentland MAX_WATERMARK); 15768feabd03SYue Hin Lau 15774562236bSHarry Wentland if (i == underlay_idx) 157886a66c4eSHarry Wentland res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks( 157986a66c4eSHarry Wentland res_ctx->pipe_ctx[i].plane_res.mi, 15804562236bSHarry Wentland nbp_marks, 15814562236bSHarry Wentland max_marks, 15824562236bSHarry Wentland max_marks, 15834562236bSHarry Wentland MAX_WATERMARK); 15848feabd03SYue Hin Lau 15854562236bSHarry Wentland } 15864562236bSHarry Wentland } 15874562236bSHarry Wentland 15884562236bSHarry Wentland /******************************************************************************* 15894562236bSHarry Wentland * Public functions 15904562236bSHarry Wentland ******************************************************************************/ 15914562236bSHarry Wentland 15924562236bSHarry Wentland static void set_drr(struct pipe_ctx **pipe_ctx, 15934562236bSHarry Wentland int num_pipes, int vmin, int vmax) 15944562236bSHarry Wentland { 15954562236bSHarry Wentland int i = 0; 15964562236bSHarry Wentland struct drr_params params = {0}; 15974562236bSHarry Wentland 15984562236bSHarry Wentland params.vertical_total_max = vmax; 15994562236bSHarry Wentland params.vertical_total_min = vmin; 16004562236bSHarry Wentland 16014562236bSHarry Wentland /* TODO: If multiple pipes are to be supported, you need 16024562236bSHarry Wentland * some GSL stuff 16034562236bSHarry Wentland */ 16044562236bSHarry Wentland 16054562236bSHarry Wentland for (i = 0; i < num_pipes; i++) { 16066b670fa9SHarry Wentland pipe_ctx[i]->stream_res.tg->funcs->set_drr(pipe_ctx[i]->stream_res.tg, ¶ms); 16074562236bSHarry Wentland } 16084562236bSHarry Wentland } 16094562236bSHarry Wentland 161072ada5f7SEric Cook static void get_position(struct pipe_ctx **pipe_ctx, 161172ada5f7SEric Cook int num_pipes, 161272ada5f7SEric Cook struct crtc_position *position) 161372ada5f7SEric Cook { 161472ada5f7SEric Cook int i = 0; 161572ada5f7SEric Cook 161672ada5f7SEric Cook /* TODO: handle pipes > 1 161772ada5f7SEric Cook */ 161872ada5f7SEric Cook for (i = 0; i < num_pipes; i++) 16196b670fa9SHarry Wentland pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position); 162072ada5f7SEric Cook } 162172ada5f7SEric Cook 16224562236bSHarry Wentland static void set_static_screen_control(struct pipe_ctx **pipe_ctx, 162394267b3dSSylvia Tsai int num_pipes, const struct dc_static_screen_events *events) 16244562236bSHarry Wentland { 16254562236bSHarry Wentland unsigned int i; 162694267b3dSSylvia Tsai unsigned int value = 0; 162794267b3dSSylvia Tsai 162894267b3dSSylvia Tsai if (events->overlay_update) 162994267b3dSSylvia Tsai value |= 0x100; 163094267b3dSSylvia Tsai if (events->surface_update) 163194267b3dSSylvia Tsai value |= 0x80; 163294267b3dSSylvia Tsai if (events->cursor_update) 163394267b3dSSylvia Tsai value |= 0x2; 1634ed8462acSCharlene Liu if (events->force_trigger) 1635ed8462acSCharlene Liu value |= 0x1; 16364562236bSHarry Wentland 16373eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 1638c3aa1d67SBhawanpreet Lakha value |= 0x84; 1639c3aa1d67SBhawanpreet Lakha #endif 1640c3aa1d67SBhawanpreet Lakha 16414562236bSHarry Wentland for (i = 0; i < num_pipes; i++) 16426b670fa9SHarry Wentland pipe_ctx[i]->stream_res.tg->funcs-> 16436b670fa9SHarry Wentland set_static_screen_control(pipe_ctx[i]->stream_res.tg, value); 16444562236bSHarry Wentland } 16454562236bSHarry Wentland 16464562236bSHarry Wentland /* unit: in_khz before mode set, get pixel clock from context. ASIC register 16474562236bSHarry Wentland * may not be programmed yet. 16484562236bSHarry Wentland * TODO: after mode set, pre_mode_set = false, 16494562236bSHarry Wentland * may read PLL register to get pixel clock 16504562236bSHarry Wentland */ 16514562236bSHarry Wentland static uint32_t get_max_pixel_clock_for_all_paths( 1652fb3466a4SBhawanpreet Lakha struct dc *dc, 1653608ac7bbSJerry Zuo struct dc_state *context, 16544562236bSHarry Wentland bool pre_mode_set) 16554562236bSHarry Wentland { 16564562236bSHarry Wentland uint32_t max_pix_clk = 0; 16574562236bSHarry Wentland int i; 16584562236bSHarry Wentland 16594562236bSHarry Wentland if (!pre_mode_set) { 16604562236bSHarry Wentland /* TODO: read ASIC register to get pixel clock */ 16614562236bSHarry Wentland ASSERT(0); 16624562236bSHarry Wentland } 16634562236bSHarry Wentland 16644562236bSHarry Wentland for (i = 0; i < MAX_PIPES; i++) { 16654562236bSHarry Wentland struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 16664562236bSHarry Wentland 16674562236bSHarry Wentland if (pipe_ctx->stream == NULL) 16684562236bSHarry Wentland continue; 16694562236bSHarry Wentland 16704562236bSHarry Wentland /* do not check under lay */ 16714562236bSHarry Wentland if (pipe_ctx->top_pipe) 16724562236bSHarry Wentland continue; 16734562236bSHarry Wentland 167410688217SHarry Wentland if (pipe_ctx->stream_res.pix_clk_params.requested_pix_clk > max_pix_clk) 16754562236bSHarry Wentland max_pix_clk = 167610688217SHarry Wentland pipe_ctx->stream_res.pix_clk_params.requested_pix_clk; 16774562236bSHarry Wentland } 16784562236bSHarry Wentland 16794562236bSHarry Wentland if (max_pix_clk == 0) 16804562236bSHarry Wentland ASSERT(0); 16814562236bSHarry Wentland 16824562236bSHarry Wentland return max_pix_clk; 16834562236bSHarry Wentland } 16844562236bSHarry Wentland 1685f6baff4dSHarry Wentland /* 1686f6baff4dSHarry Wentland * Find clock state based on clock requested. if clock value is 0, simply 16874562236bSHarry Wentland * set clock state as requested without finding clock state by clock value 16884562236bSHarry Wentland */ 1689f6baff4dSHarry Wentland 16904562236bSHarry Wentland static void apply_min_clocks( 1691fb3466a4SBhawanpreet Lakha struct dc *dc, 1692608ac7bbSJerry Zuo struct dc_state *context, 1693e9c58bb4SDmytro Laktyushkin enum dm_pp_clocks_state *clocks_state, 16944562236bSHarry Wentland bool pre_mode_set) 16954562236bSHarry Wentland { 16964562236bSHarry Wentland struct state_dependent_clocks req_clocks = {0}; 16974562236bSHarry Wentland 16984562236bSHarry Wentland if (!pre_mode_set) { 16994562236bSHarry Wentland /* set clock_state without verification */ 1700ab8db3e1SAndrey Grodzovsky if (context->dis_clk->funcs->set_min_clocks_state) { 1701ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->set_min_clocks_state( 1702ab8db3e1SAndrey Grodzovsky context->dis_clk, *clocks_state); 17034562236bSHarry Wentland return; 17045d6d185fSDmytro Laktyushkin } 17054562236bSHarry Wentland 17062c8ad2d5SAlex Deucher /* TODO: This is incorrect. Figure out how to fix. */ 1707ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->apply_clock_voltage_request( 1708ab8db3e1SAndrey Grodzovsky context->dis_clk, 17092c8ad2d5SAlex Deucher DM_PP_CLOCK_TYPE_DISPLAY_CLK, 1710ab8db3e1SAndrey Grodzovsky context->dis_clk->cur_clocks_value.dispclk_in_khz, 17112c8ad2d5SAlex Deucher pre_mode_set, 17122c8ad2d5SAlex Deucher false); 17132c8ad2d5SAlex Deucher 1714ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->apply_clock_voltage_request( 1715ab8db3e1SAndrey Grodzovsky context->dis_clk, 17162c8ad2d5SAlex Deucher DM_PP_CLOCK_TYPE_PIXELCLK, 1717ab8db3e1SAndrey Grodzovsky context->dis_clk->cur_clocks_value.max_pixelclk_in_khz, 17182c8ad2d5SAlex Deucher pre_mode_set, 17192c8ad2d5SAlex Deucher false); 17202c8ad2d5SAlex Deucher 1721ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->apply_clock_voltage_request( 1722ab8db3e1SAndrey Grodzovsky context->dis_clk, 17232c8ad2d5SAlex Deucher DM_PP_CLOCK_TYPE_DISPLAYPHYCLK, 1724ab8db3e1SAndrey Grodzovsky context->dis_clk->cur_clocks_value.max_non_dp_phyclk_in_khz, 17252c8ad2d5SAlex Deucher pre_mode_set, 17262c8ad2d5SAlex Deucher false); 17272c8ad2d5SAlex Deucher return; 17284562236bSHarry Wentland } 17294562236bSHarry Wentland 17304562236bSHarry Wentland /* get the required state based on state dependent clocks: 17314562236bSHarry Wentland * display clock and pixel clock 17324562236bSHarry Wentland */ 17339037d802SDmytro Laktyushkin req_clocks.display_clk_khz = context->bw.dce.dispclk_khz; 17344562236bSHarry Wentland 17354562236bSHarry Wentland req_clocks.pixel_clk_khz = get_max_pixel_clock_for_all_paths( 17364562236bSHarry Wentland dc, context, true); 17374562236bSHarry Wentland 1738ab8db3e1SAndrey Grodzovsky if (context->dis_clk->funcs->get_required_clocks_state) { 1739ab8db3e1SAndrey Grodzovsky *clocks_state = context->dis_clk->funcs->get_required_clocks_state( 1740ab8db3e1SAndrey Grodzovsky context->dis_clk, &req_clocks); 1741ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->set_min_clocks_state( 1742ab8db3e1SAndrey Grodzovsky context->dis_clk, *clocks_state); 17434562236bSHarry Wentland } else { 1744ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->apply_clock_voltage_request( 1745ab8db3e1SAndrey Grodzovsky context->dis_clk, 17462c8ad2d5SAlex Deucher DM_PP_CLOCK_TYPE_DISPLAY_CLK, 17472c8ad2d5SAlex Deucher req_clocks.display_clk_khz, 17482c8ad2d5SAlex Deucher pre_mode_set, 17492c8ad2d5SAlex Deucher false); 17502c8ad2d5SAlex Deucher 1751ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->apply_clock_voltage_request( 1752ab8db3e1SAndrey Grodzovsky context->dis_clk, 17532c8ad2d5SAlex Deucher DM_PP_CLOCK_TYPE_PIXELCLK, 17542c8ad2d5SAlex Deucher req_clocks.pixel_clk_khz, 17552c8ad2d5SAlex Deucher pre_mode_set, 17562c8ad2d5SAlex Deucher false); 17572c8ad2d5SAlex Deucher 1758ab8db3e1SAndrey Grodzovsky context->dis_clk->funcs->apply_clock_voltage_request( 1759ab8db3e1SAndrey Grodzovsky context->dis_clk, 17602c8ad2d5SAlex Deucher DM_PP_CLOCK_TYPE_DISPLAYPHYCLK, 17612c8ad2d5SAlex Deucher req_clocks.pixel_clk_khz, 17622c8ad2d5SAlex Deucher pre_mode_set, 17632c8ad2d5SAlex Deucher false); 17644562236bSHarry Wentland } 17654562236bSHarry Wentland } 17664562236bSHarry Wentland 17673eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 1768690b5e39SRoman Li 1769690b5e39SRoman Li /* 1770690b5e39SRoman Li * Check if FBC can be enabled 1771690b5e39SRoman Li */ 17729c6569deSHarry Wentland static bool should_enable_fbc(struct dc *dc, 17733bc4aaa9SRoman Li struct dc_state *context, 17743bc4aaa9SRoman Li uint32_t *pipe_idx) 1775690b5e39SRoman Li { 17763bc4aaa9SRoman Li uint32_t i; 17773bc4aaa9SRoman Li struct pipe_ctx *pipe_ctx = NULL; 17783bc4aaa9SRoman Li struct resource_context *res_ctx = &context->res_ctx; 17793bc4aaa9SRoman Li 1780690b5e39SRoman Li 1781690b5e39SRoman Li ASSERT(dc->fbc_compressor); 1782690b5e39SRoman Li 1783690b5e39SRoman Li /* FBC memory should be allocated */ 1784690b5e39SRoman Li if (!dc->ctx->fbc_gpu_addr) 17859c6569deSHarry Wentland return false; 1786690b5e39SRoman Li 1787690b5e39SRoman Li /* Only supports single display */ 1788690b5e39SRoman Li if (context->stream_count != 1) 17899c6569deSHarry Wentland return false; 1790690b5e39SRoman Li 17913bc4aaa9SRoman Li for (i = 0; i < dc->res_pool->pipe_count; i++) { 17923bc4aaa9SRoman Li if (res_ctx->pipe_ctx[i].stream) { 17933bc4aaa9SRoman Li pipe_ctx = &res_ctx->pipe_ctx[i]; 17943bc4aaa9SRoman Li *pipe_idx = i; 17953bc4aaa9SRoman Li break; 17963bc4aaa9SRoman Li } 17973bc4aaa9SRoman Li } 17983bc4aaa9SRoman Li 1799690b5e39SRoman Li /* Only supports eDP */ 1800690b5e39SRoman Li if (pipe_ctx->stream->sink->link->connector_signal != SIGNAL_TYPE_EDP) 18019c6569deSHarry Wentland return false; 1802690b5e39SRoman Li 1803690b5e39SRoman Li /* PSR should not be enabled */ 1804690b5e39SRoman Li if (pipe_ctx->stream->sink->link->psr_enabled) 18059c6569deSHarry Wentland return false; 1806690b5e39SRoman Li 180793984bbcSShirish S /* Nothing to compress */ 180893984bbcSShirish S if (!pipe_ctx->plane_state) 18099c6569deSHarry Wentland return false; 181093984bbcSShirish S 181105230fa9SRoman Li /* Only for non-linear tiling */ 181205230fa9SRoman Li if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL) 18139c6569deSHarry Wentland return false; 181405230fa9SRoman Li 18159c6569deSHarry Wentland return true; 1816690b5e39SRoman Li } 1817690b5e39SRoman Li 1818690b5e39SRoman Li /* 1819690b5e39SRoman Li * Enable FBC 1820690b5e39SRoman Li */ 18219c6569deSHarry Wentland static void enable_fbc(struct dc *dc, 1822608ac7bbSJerry Zuo struct dc_state *context) 1823690b5e39SRoman Li { 18243bc4aaa9SRoman Li uint32_t pipe_idx = 0; 18253bc4aaa9SRoman Li 18263bc4aaa9SRoman Li if (should_enable_fbc(dc, context, &pipe_idx)) { 1827690b5e39SRoman Li /* Program GRPH COMPRESSED ADDRESS and PITCH */ 1828690b5e39SRoman Li struct compr_addr_and_pitch_params params = {0, 0, 0}; 1829690b5e39SRoman Li struct compressor *compr = dc->fbc_compressor; 18303bc4aaa9SRoman Li struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx]; 18313bc4aaa9SRoman Li 1832690b5e39SRoman Li 18339c6569deSHarry Wentland params.source_view_width = pipe_ctx->stream->timing.h_addressable; 18349c6569deSHarry Wentland params.source_view_height = pipe_ctx->stream->timing.v_addressable; 1835690b5e39SRoman Li 1836690b5e39SRoman Li compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr; 1837690b5e39SRoman Li 1838690b5e39SRoman Li compr->funcs->surface_address_and_pitch(compr, ¶ms); 1839690b5e39SRoman Li compr->funcs->set_fbc_invalidation_triggers(compr, 1); 1840690b5e39SRoman Li 1841690b5e39SRoman Li compr->funcs->enable_fbc(compr, ¶ms); 1842690b5e39SRoman Li } 1843690b5e39SRoman Li } 1844690b5e39SRoman Li #endif 1845690b5e39SRoman Li 184654e8695eSDmytro Laktyushkin static void dce110_reset_hw_ctx_wrap( 1847fb3466a4SBhawanpreet Lakha struct dc *dc, 1848608ac7bbSJerry Zuo struct dc_state *context) 18494562236bSHarry Wentland { 18504562236bSHarry Wentland int i; 18514562236bSHarry Wentland 18524562236bSHarry Wentland /* Reset old context */ 18534562236bSHarry Wentland /* look up the targets that have been removed since last commit */ 1854a2b8659dSTony Cheng for (i = 0; i < MAX_PIPES; i++) { 18554562236bSHarry Wentland struct pipe_ctx *pipe_ctx_old = 1856608ac7bbSJerry Zuo &dc->current_state->res_ctx.pipe_ctx[i]; 18574562236bSHarry Wentland struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 18584562236bSHarry Wentland 18594562236bSHarry Wentland /* Note: We need to disable output if clock sources change, 18604562236bSHarry Wentland * since bios does optimization and doesn't apply if changing 18614562236bSHarry Wentland * PHY when not already disabled. 18624562236bSHarry Wentland */ 18634562236bSHarry Wentland 18644562236bSHarry Wentland /* Skip underlay pipe since it will be handled in commit surface*/ 18654562236bSHarry Wentland if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe) 18664562236bSHarry Wentland continue; 18674562236bSHarry Wentland 18684562236bSHarry Wentland if (!pipe_ctx->stream || 186954e8695eSDmytro Laktyushkin pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) { 187021e67d4dSHarry Wentland struct clock_source *old_clk = pipe_ctx_old->clock_source; 187121e67d4dSHarry Wentland 1872827f11e9SLeo (Sunpeng) Li /* Disable if new stream is null. O/w, if stream is 1873827f11e9SLeo (Sunpeng) Li * disabled already, no need to disable again. 1874827f11e9SLeo (Sunpeng) Li */ 1875827f11e9SLeo (Sunpeng) Li if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) 18764176664bSCharlene Liu core_link_disable_stream(pipe_ctx_old, FREE_ACQUIRED_RESOURCE); 1877d050f8edSHersen Wu 18786b670fa9SHarry Wentland pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true); 18796b670fa9SHarry Wentland if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) { 188054e8695eSDmytro Laktyushkin dm_error("DC: failed to blank crtc!\n"); 188154e8695eSDmytro Laktyushkin BREAK_TO_DEBUGGER(); 188254e8695eSDmytro Laktyushkin } 18836b670fa9SHarry Wentland pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg); 188486a66c4eSHarry Wentland pipe_ctx_old->plane_res.mi->funcs->free_mem_input( 1885608ac7bbSJerry Zuo pipe_ctx_old->plane_res.mi, dc->current_state->stream_count); 188654e8695eSDmytro Laktyushkin 188721e67d4dSHarry Wentland if (old_clk) 188821e67d4dSHarry Wentland old_clk->funcs->cs_power_down(old_clk); 188921e67d4dSHarry Wentland 18907f914a62SYongqiang Sun dc->hwss.disable_plane(dc, pipe_ctx_old); 189154e8695eSDmytro Laktyushkin 189254e8695eSDmytro Laktyushkin pipe_ctx_old->stream = NULL; 189354e8695eSDmytro Laktyushkin } 18944562236bSHarry Wentland } 18954562236bSHarry Wentland } 18964562236bSHarry Wentland 1897cf437593SDmytro Laktyushkin 18984562236bSHarry Wentland enum dc_status dce110_apply_ctx_to_hw( 1899fb3466a4SBhawanpreet Lakha struct dc *dc, 1900608ac7bbSJerry Zuo struct dc_state *context) 19014562236bSHarry Wentland { 19024562236bSHarry Wentland struct dc_bios *dcb = dc->ctx->dc_bios; 19034562236bSHarry Wentland enum dc_status status; 19044562236bSHarry Wentland int i; 1905e9c58bb4SDmytro Laktyushkin enum dm_pp_clocks_state clocks_state = DM_PP_CLOCKS_STATE_INVALID; 19064562236bSHarry Wentland 19074562236bSHarry Wentland /* Reset old context */ 19084562236bSHarry Wentland /* look up the targets that have been removed since last commit */ 19094562236bSHarry Wentland dc->hwss.reset_hw_ctx_wrap(dc, context); 19104562236bSHarry Wentland 19114562236bSHarry Wentland /* Skip applying if no targets */ 1912ab2541b6SAric Cyr if (context->stream_count <= 0) 19134562236bSHarry Wentland return DC_OK; 19144562236bSHarry Wentland 19154562236bSHarry Wentland /* Apply new context */ 19164562236bSHarry Wentland dcb->funcs->set_scratch_critical_state(dcb, true); 19174562236bSHarry Wentland 19184562236bSHarry Wentland /* below is for real asic only */ 1919a2b8659dSTony Cheng for (i = 0; i < dc->res_pool->pipe_count; i++) { 19204562236bSHarry Wentland struct pipe_ctx *pipe_ctx_old = 1921608ac7bbSJerry Zuo &dc->current_state->res_ctx.pipe_ctx[i]; 19224562236bSHarry Wentland struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 19234562236bSHarry Wentland 19244562236bSHarry Wentland if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe) 19254562236bSHarry Wentland continue; 19264562236bSHarry Wentland 19274562236bSHarry Wentland if (pipe_ctx->stream == pipe_ctx_old->stream) { 19284562236bSHarry Wentland if (pipe_ctx_old->clock_source != pipe_ctx->clock_source) 19294562236bSHarry Wentland dce_crtc_switch_to_clk_src(dc->hwseq, 19304562236bSHarry Wentland pipe_ctx->clock_source, i); 19314562236bSHarry Wentland continue; 19324562236bSHarry Wentland } 19334562236bSHarry Wentland 19344562236bSHarry Wentland dc->hwss.enable_display_power_gating( 19354562236bSHarry Wentland dc, i, dc->ctx->dc_bios, 19364562236bSHarry Wentland PIPE_GATING_CONTROL_DISABLE); 19374562236bSHarry Wentland } 19384562236bSHarry Wentland 1939a2b8659dSTony Cheng set_safe_displaymarks(&context->res_ctx, dc->res_pool); 19401663ae1cSBhawanpreet Lakha 19413eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 19422f3bfb27SRoman Li if (dc->fbc_compressor) 19431663ae1cSBhawanpreet Lakha dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor); 19441663ae1cSBhawanpreet Lakha #endif 19454562236bSHarry Wentland /*TODO: when pplib works*/ 19464562236bSHarry Wentland apply_min_clocks(dc, context, &clocks_state, true); 19474562236bSHarry Wentland 1948ff5ef992SAlex Deucher #if defined(CONFIG_DRM_AMD_DC_DCN1_0) 19493639fa68SZeyu Fan if (dc->ctx->dce_version >= DCN_VERSION_1_0) { 19509037d802SDmytro Laktyushkin if (context->bw.dcn.calc_clk.fclk_khz 1951608ac7bbSJerry Zuo > dc->current_state->bw.dcn.cur_clk.fclk_khz) { 1952ff5ef992SAlex Deucher struct dm_pp_clock_for_voltage_req clock; 1953ff5ef992SAlex Deucher 1954ff5ef992SAlex Deucher clock.clk_type = DM_PP_CLOCK_TYPE_FCLK; 19559037d802SDmytro Laktyushkin clock.clocks_in_khz = context->bw.dcn.calc_clk.fclk_khz; 1956ff5ef992SAlex Deucher dm_pp_apply_clock_for_voltage_request(dc->ctx, &clock); 1957608ac7bbSJerry Zuo dc->current_state->bw.dcn.cur_clk.fclk_khz = clock.clocks_in_khz; 1958c66a54dcSDmytro Laktyushkin context->bw.dcn.cur_clk.fclk_khz = clock.clocks_in_khz; 1959ff5ef992SAlex Deucher } 19609037d802SDmytro Laktyushkin if (context->bw.dcn.calc_clk.dcfclk_khz 1961608ac7bbSJerry Zuo > dc->current_state->bw.dcn.cur_clk.dcfclk_khz) { 1962ff5ef992SAlex Deucher struct dm_pp_clock_for_voltage_req clock; 1963ff5ef992SAlex Deucher 1964ff5ef992SAlex Deucher clock.clk_type = DM_PP_CLOCK_TYPE_DCFCLK; 19659037d802SDmytro Laktyushkin clock.clocks_in_khz = context->bw.dcn.calc_clk.dcfclk_khz; 1966ff5ef992SAlex Deucher dm_pp_apply_clock_for_voltage_request(dc->ctx, &clock); 1967608ac7bbSJerry Zuo dc->current_state->bw.dcn.cur_clk.dcfclk_khz = clock.clocks_in_khz; 1968c66a54dcSDmytro Laktyushkin context->bw.dcn.cur_clk.dcfclk_khz = clock.clocks_in_khz; 1969ff5ef992SAlex Deucher } 1970c66a54dcSDmytro Laktyushkin if (context->bw.dcn.calc_clk.dispclk_khz 1971608ac7bbSJerry Zuo > dc->current_state->bw.dcn.cur_clk.dispclk_khz) { 1972c66a54dcSDmytro Laktyushkin dc->res_pool->display_clock->funcs->set_clock( 1973c66a54dcSDmytro Laktyushkin dc->res_pool->display_clock, 1974c66a54dcSDmytro Laktyushkin context->bw.dcn.calc_clk.dispclk_khz); 1975608ac7bbSJerry Zuo dc->current_state->bw.dcn.cur_clk.dispclk_khz = 1976c66a54dcSDmytro Laktyushkin context->bw.dcn.calc_clk.dispclk_khz; 1977c66a54dcSDmytro Laktyushkin context->bw.dcn.cur_clk.dispclk_khz = 1978c66a54dcSDmytro Laktyushkin context->bw.dcn.calc_clk.dispclk_khz; 1979c66a54dcSDmytro Laktyushkin } 1980c66a54dcSDmytro Laktyushkin } else 1981ff5ef992SAlex Deucher #endif 19829037d802SDmytro Laktyushkin if (context->bw.dce.dispclk_khz 1983608ac7bbSJerry Zuo > dc->current_state->bw.dce.dispclk_khz) { 1984a2b8659dSTony Cheng dc->res_pool->display_clock->funcs->set_clock( 1985a2b8659dSTony Cheng dc->res_pool->display_clock, 19869037d802SDmytro Laktyushkin context->bw.dce.dispclk_khz * 115 / 100); 19871ce71fcdSCharlene Liu } 1988ab8812a3SHersen Wu /* program audio wall clock. use HDMI as clock source if HDMI 1989ab8812a3SHersen Wu * audio active. Otherwise, use DP as clock source 1990ab8812a3SHersen Wu * first, loop to find any HDMI audio, if not, loop find DP audio 1991ab8812a3SHersen Wu */ 19924562236bSHarry Wentland /* Setup audio rate clock source */ 19934562236bSHarry Wentland /* Issue: 19944562236bSHarry Wentland * Audio lag happened on DP monitor when unplug a HDMI monitor 19954562236bSHarry Wentland * 19964562236bSHarry Wentland * Cause: 19974562236bSHarry Wentland * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL 19984562236bSHarry Wentland * is set to either dto0 or dto1, audio should work fine. 19994562236bSHarry Wentland * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1, 20004562236bSHarry Wentland * set to dto0 will cause audio lag. 20014562236bSHarry Wentland * 20024562236bSHarry Wentland * Solution: 20034562236bSHarry Wentland * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx, 20044562236bSHarry Wentland * find first available pipe with audio, setup audio wall DTO per topology 20054562236bSHarry Wentland * instead of per pipe. 20064562236bSHarry Wentland */ 2007a2b8659dSTony Cheng for (i = 0; i < dc->res_pool->pipe_count; i++) { 2008ab8812a3SHersen Wu struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 2009ab8812a3SHersen Wu 2010ab8812a3SHersen Wu if (pipe_ctx->stream == NULL) 2011ab8812a3SHersen Wu continue; 2012ab8812a3SHersen Wu 2013ab8812a3SHersen Wu if (pipe_ctx->top_pipe) 2014ab8812a3SHersen Wu continue; 2015ab8812a3SHersen Wu 2016ab8812a3SHersen Wu if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A) 2017ab8812a3SHersen Wu continue; 2018ab8812a3SHersen Wu 2019afaacef4SHarry Wentland if (pipe_ctx->stream_res.audio != NULL) { 2020ab8812a3SHersen Wu struct audio_output audio_output; 2021ab8812a3SHersen Wu 2022ab8db3e1SAndrey Grodzovsky build_audio_output(context, pipe_ctx, &audio_output); 2023ab8812a3SHersen Wu 2024afaacef4SHarry Wentland pipe_ctx->stream_res.audio->funcs->wall_dto_setup( 2025afaacef4SHarry Wentland pipe_ctx->stream_res.audio, 2026ab8812a3SHersen Wu pipe_ctx->stream->signal, 2027ab8812a3SHersen Wu &audio_output.crtc_info, 2028ab8812a3SHersen Wu &audio_output.pll_info); 2029ab8812a3SHersen Wu break; 2030ab8812a3SHersen Wu } 2031ab8812a3SHersen Wu } 2032ab8812a3SHersen Wu 2033ab8812a3SHersen Wu /* no HDMI audio is found, try DP audio */ 2034a2b8659dSTony Cheng if (i == dc->res_pool->pipe_count) { 2035a2b8659dSTony Cheng for (i = 0; i < dc->res_pool->pipe_count; i++) { 2036ab8812a3SHersen Wu struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 2037ab8812a3SHersen Wu 2038ab8812a3SHersen Wu if (pipe_ctx->stream == NULL) 2039ab8812a3SHersen Wu continue; 2040ab8812a3SHersen Wu 2041ab8812a3SHersen Wu if (pipe_ctx->top_pipe) 2042ab8812a3SHersen Wu continue; 2043ab8812a3SHersen Wu 2044ab8812a3SHersen Wu if (!dc_is_dp_signal(pipe_ctx->stream->signal)) 2045ab8812a3SHersen Wu continue; 2046ab8812a3SHersen Wu 2047afaacef4SHarry Wentland if (pipe_ctx->stream_res.audio != NULL) { 2048ab8812a3SHersen Wu struct audio_output audio_output; 2049ab8812a3SHersen Wu 2050ab8db3e1SAndrey Grodzovsky build_audio_output(context, pipe_ctx, &audio_output); 2051ab8812a3SHersen Wu 2052afaacef4SHarry Wentland pipe_ctx->stream_res.audio->funcs->wall_dto_setup( 2053afaacef4SHarry Wentland pipe_ctx->stream_res.audio, 2054ab8812a3SHersen Wu pipe_ctx->stream->signal, 2055ab8812a3SHersen Wu &audio_output.crtc_info, 2056ab8812a3SHersen Wu &audio_output.pll_info); 2057ab8812a3SHersen Wu break; 2058ab8812a3SHersen Wu } 2059ab8812a3SHersen Wu } 2060ab8812a3SHersen Wu } 2061ab8812a3SHersen Wu 2062a2b8659dSTony Cheng for (i = 0; i < dc->res_pool->pipe_count; i++) { 2063ab8812a3SHersen Wu struct pipe_ctx *pipe_ctx_old = 2064608ac7bbSJerry Zuo &dc->current_state->res_ctx.pipe_ctx[i]; 2065ab8812a3SHersen Wu struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 2066ab8812a3SHersen Wu 2067ab8812a3SHersen Wu if (pipe_ctx->stream == NULL) 2068ab8812a3SHersen Wu continue; 2069ab8812a3SHersen Wu 2070ab8812a3SHersen Wu if (pipe_ctx->stream == pipe_ctx_old->stream) 2071ab8812a3SHersen Wu continue; 2072ab8812a3SHersen Wu 20735b92d9d4SHarry Wentland if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) 2074313bf4ffSYongqiang Sun continue; 2075313bf4ffSYongqiang Sun 2076ab8812a3SHersen Wu if (pipe_ctx->top_pipe) 2077ab8812a3SHersen Wu continue; 2078ab8812a3SHersen Wu 2079afaacef4SHarry Wentland if (context->res_ctx.pipe_ctx[i].stream_res.audio != NULL) { 2080ab8812a3SHersen Wu 20814562236bSHarry Wentland struct audio_output audio_output; 20824562236bSHarry Wentland 2083ab8db3e1SAndrey Grodzovsky build_audio_output(context, pipe_ctx, &audio_output); 20844562236bSHarry Wentland 20854562236bSHarry Wentland if (dc_is_dp_signal(pipe_ctx->stream->signal)) 20868e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup( 20878e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 2088afaacef4SHarry Wentland pipe_ctx->stream_res.audio->inst, 20894fa086b9SLeo (Sunpeng) Li &pipe_ctx->stream->audio_info); 20904562236bSHarry Wentland else 20918e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup( 20928e9c4c8cSHarry Wentland pipe_ctx->stream_res.stream_enc, 2093afaacef4SHarry Wentland pipe_ctx->stream_res.audio->inst, 20944fa086b9SLeo (Sunpeng) Li &pipe_ctx->stream->audio_info, 20954562236bSHarry Wentland &audio_output.crtc_info); 20964562236bSHarry Wentland 2097afaacef4SHarry Wentland pipe_ctx->stream_res.audio->funcs->az_configure( 2098afaacef4SHarry Wentland pipe_ctx->stream_res.audio, 20994562236bSHarry Wentland pipe_ctx->stream->signal, 21004562236bSHarry Wentland &audio_output.crtc_info, 21014fa086b9SLeo (Sunpeng) Li &pipe_ctx->stream->audio_info); 21024562236bSHarry Wentland } 21034562236bSHarry Wentland 21044562236bSHarry Wentland status = apply_single_controller_ctx_to_hw( 21054562236bSHarry Wentland pipe_ctx, 21064562236bSHarry Wentland context, 21074562236bSHarry Wentland dc); 21084562236bSHarry Wentland 21094562236bSHarry Wentland if (DC_OK != status) 21104562236bSHarry Wentland return status; 21114562236bSHarry Wentland } 21124562236bSHarry Wentland 21134562236bSHarry Wentland /* to save power */ 21144562236bSHarry Wentland apply_min_clocks(dc, context, &clocks_state, false); 21154562236bSHarry Wentland 21164562236bSHarry Wentland dcb->funcs->set_scratch_critical_state(dcb, false); 21174562236bSHarry Wentland 21183eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 2119690b5e39SRoman Li if (dc->fbc_compressor) 2120690b5e39SRoman Li enable_fbc(dc, context); 2121690b5e39SRoman Li 2122690b5e39SRoman Li #endif 2123cf437593SDmytro Laktyushkin 21244562236bSHarry Wentland return DC_OK; 21254562236bSHarry Wentland } 21264562236bSHarry Wentland 21274562236bSHarry Wentland /******************************************************************************* 21284562236bSHarry Wentland * Front End programming 21294562236bSHarry Wentland ******************************************************************************/ 21304562236bSHarry Wentland static void set_default_colors(struct pipe_ctx *pipe_ctx) 21314562236bSHarry Wentland { 21324562236bSHarry Wentland struct default_adjustment default_adjust = { 0 }; 21334562236bSHarry Wentland 21344562236bSHarry Wentland default_adjust.force_hw_default = false; 213534996173SHarry Wentland default_adjust.in_color_space = pipe_ctx->plane_state->color_space; 213634996173SHarry Wentland default_adjust.out_color_space = pipe_ctx->stream->output_color_space; 21374562236bSHarry Wentland default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW; 21386702a9acSHarry Wentland default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format; 21394562236bSHarry Wentland 21404562236bSHarry Wentland /* display color depth */ 21414562236bSHarry Wentland default_adjust.color_depth = 21424fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->timing.display_color_depth; 21434562236bSHarry Wentland 21444562236bSHarry Wentland /* Lb color depth */ 21456702a9acSHarry Wentland default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth; 21464562236bSHarry Wentland 214786a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default( 214886a66c4eSHarry Wentland pipe_ctx->plane_res.xfm, &default_adjust); 21494562236bSHarry Wentland } 21504562236bSHarry Wentland 2151b06b7680SLeon Elazar 2152b06b7680SLeon Elazar /******************************************************************************* 2153b06b7680SLeon Elazar * In order to turn on/off specific surface we will program 2154b06b7680SLeon Elazar * Blender + CRTC 2155b06b7680SLeon Elazar * 2156b06b7680SLeon Elazar * In case that we have two surfaces and they have a different visibility 2157b06b7680SLeon Elazar * we can't turn off the CRTC since it will turn off the entire display 2158b06b7680SLeon Elazar * 2159b06b7680SLeon Elazar * |----------------------------------------------- | 2160b06b7680SLeon Elazar * |bottom pipe|curr pipe | | | 2161b06b7680SLeon Elazar * |Surface |Surface | Blender | CRCT | 2162b06b7680SLeon Elazar * |visibility |visibility | Configuration| | 2163b06b7680SLeon Elazar * |------------------------------------------------| 2164b06b7680SLeon Elazar * | off | off | CURRENT_PIPE | blank | 2165b06b7680SLeon Elazar * | off | on | CURRENT_PIPE | unblank | 2166b06b7680SLeon Elazar * | on | off | OTHER_PIPE | unblank | 2167b06b7680SLeon Elazar * | on | on | BLENDING | unblank | 2168b06b7680SLeon Elazar * -------------------------------------------------| 2169b06b7680SLeon Elazar * 2170b06b7680SLeon Elazar ******************************************************************************/ 2171fb3466a4SBhawanpreet Lakha static void program_surface_visibility(const struct dc *dc, 21724562236bSHarry Wentland struct pipe_ctx *pipe_ctx) 21734562236bSHarry Wentland { 21744562236bSHarry Wentland enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE; 2175b06b7680SLeon Elazar bool blank_target = false; 21764562236bSHarry Wentland 21774562236bSHarry Wentland if (pipe_ctx->bottom_pipe) { 2178b06b7680SLeon Elazar 2179b06b7680SLeon Elazar /* For now we are supporting only two pipes */ 2180b06b7680SLeon Elazar ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL); 2181b06b7680SLeon Elazar 21823be5262eSHarry Wentland if (pipe_ctx->bottom_pipe->plane_state->visible) { 21833be5262eSHarry Wentland if (pipe_ctx->plane_state->visible) 21844562236bSHarry Wentland blender_mode = BLND_MODE_BLENDING; 21854562236bSHarry Wentland else 21864562236bSHarry Wentland blender_mode = BLND_MODE_OTHER_PIPE; 2187b06b7680SLeon Elazar 21883be5262eSHarry Wentland } else if (!pipe_ctx->plane_state->visible) 2189b06b7680SLeon Elazar blank_target = true; 2190b06b7680SLeon Elazar 21913be5262eSHarry Wentland } else if (!pipe_ctx->plane_state->visible) 2192b06b7680SLeon Elazar blank_target = true; 2193b06b7680SLeon Elazar 2194e07f541fSYongqiang Sun dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode); 21956b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target); 2196b06b7680SLeon Elazar 21974562236bSHarry Wentland } 21984562236bSHarry Wentland 21991bf56e62SZeyu Fan static void program_gamut_remap(struct pipe_ctx *pipe_ctx) 22001bf56e62SZeyu Fan { 2201146a9f63SKrunoslav Kovac int i = 0; 22021bf56e62SZeyu Fan struct xfm_grph_csc_adjustment adjust; 22031bf56e62SZeyu Fan memset(&adjust, 0, sizeof(adjust)); 22041bf56e62SZeyu Fan adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS; 22051bf56e62SZeyu Fan 22061bf56e62SZeyu Fan 22074fa086b9SLeo (Sunpeng) Li if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) { 22081bf56e62SZeyu Fan adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW; 2209146a9f63SKrunoslav Kovac 2210146a9f63SKrunoslav Kovac for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++) 2211146a9f63SKrunoslav Kovac adjust.temperature_matrix[i] = 2212146a9f63SKrunoslav Kovac pipe_ctx->stream->gamut_remap_matrix.matrix[i]; 22131bf56e62SZeyu Fan } 22141bf56e62SZeyu Fan 221586a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust); 22161bf56e62SZeyu Fan } 22171bf56e62SZeyu Fan 22184562236bSHarry Wentland /** 22194562236bSHarry Wentland * TODO REMOVE, USE UPDATE INSTEAD 22204562236bSHarry Wentland */ 22214562236bSHarry Wentland static void set_plane_config( 2222fb3466a4SBhawanpreet Lakha const struct dc *dc, 22234562236bSHarry Wentland struct pipe_ctx *pipe_ctx, 22244562236bSHarry Wentland struct resource_context *res_ctx) 22254562236bSHarry Wentland { 222686a66c4eSHarry Wentland struct mem_input *mi = pipe_ctx->plane_res.mi; 22273be5262eSHarry Wentland struct dc_plane_state *plane_state = pipe_ctx->plane_state; 22284562236bSHarry Wentland struct xfm_grph_csc_adjustment adjust; 22294562236bSHarry Wentland struct out_csc_color_matrix tbl_entry; 22304562236bSHarry Wentland unsigned int i; 22314562236bSHarry Wentland 22324562236bSHarry Wentland memset(&adjust, 0, sizeof(adjust)); 22334562236bSHarry Wentland memset(&tbl_entry, 0, sizeof(tbl_entry)); 22344562236bSHarry Wentland adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS; 22354562236bSHarry Wentland 2236e07f541fSYongqiang Sun dce_enable_fe_clock(dc->hwseq, mi->inst, true); 22374562236bSHarry Wentland 22384562236bSHarry Wentland set_default_colors(pipe_ctx); 223956ef6ed9SAnthony Koo if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) { 22404562236bSHarry Wentland tbl_entry.color_space = 22414fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->output_color_space; 22424562236bSHarry Wentland 22434562236bSHarry Wentland for (i = 0; i < 12; i++) 22444562236bSHarry Wentland tbl_entry.regval[i] = 22454fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->csc_color_matrix.matrix[i]; 22464562236bSHarry Wentland 224786a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment 224886a66c4eSHarry Wentland (pipe_ctx->plane_res.xfm, &tbl_entry); 22494562236bSHarry Wentland } 22504562236bSHarry Wentland 22514fa086b9SLeo (Sunpeng) Li if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) { 22524562236bSHarry Wentland adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW; 2253146a9f63SKrunoslav Kovac 2254146a9f63SKrunoslav Kovac for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++) 2255146a9f63SKrunoslav Kovac adjust.temperature_matrix[i] = 2256146a9f63SKrunoslav Kovac pipe_ctx->stream->gamut_remap_matrix.matrix[i]; 22574562236bSHarry Wentland } 22584562236bSHarry Wentland 225986a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust); 22604562236bSHarry Wentland 22616702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0; 22624562236bSHarry Wentland program_scaler(dc, pipe_ctx); 22634562236bSHarry Wentland 2264b06b7680SLeon Elazar program_surface_visibility(dc, pipe_ctx); 22654562236bSHarry Wentland 22664562236bSHarry Wentland mi->funcs->mem_input_program_surface_config( 22674562236bSHarry Wentland mi, 22683be5262eSHarry Wentland plane_state->format, 22693be5262eSHarry Wentland &plane_state->tiling_info, 22703be5262eSHarry Wentland &plane_state->plane_size, 22713be5262eSHarry Wentland plane_state->rotation, 22724562236bSHarry Wentland NULL, 22734b28b76bSDmytro Laktyushkin false); 22744b28b76bSDmytro Laktyushkin if (mi->funcs->set_blank) 22753be5262eSHarry Wentland mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible); 22764562236bSHarry Wentland 2277fb3466a4SBhawanpreet Lakha if (dc->config.gpu_vm_support) 22784562236bSHarry Wentland mi->funcs->mem_input_program_pte_vm( 227986a66c4eSHarry Wentland pipe_ctx->plane_res.mi, 22803be5262eSHarry Wentland plane_state->format, 22813be5262eSHarry Wentland &plane_state->tiling_info, 22823be5262eSHarry Wentland plane_state->rotation); 22834562236bSHarry Wentland } 22844562236bSHarry Wentland 2285fb3466a4SBhawanpreet Lakha static void update_plane_addr(const struct dc *dc, 22864562236bSHarry Wentland struct pipe_ctx *pipe_ctx) 22874562236bSHarry Wentland { 22883be5262eSHarry Wentland struct dc_plane_state *plane_state = pipe_ctx->plane_state; 22894562236bSHarry Wentland 22903be5262eSHarry Wentland if (plane_state == NULL) 22914562236bSHarry Wentland return; 22924562236bSHarry Wentland 229386a66c4eSHarry Wentland pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr( 229486a66c4eSHarry Wentland pipe_ctx->plane_res.mi, 22953be5262eSHarry Wentland &plane_state->address, 22963be5262eSHarry Wentland plane_state->flip_immediate); 22974562236bSHarry Wentland 22983be5262eSHarry Wentland plane_state->status.requested_address = plane_state->address; 22994562236bSHarry Wentland } 23004562236bSHarry Wentland 2301f774b339SEric Yang static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx) 23024562236bSHarry Wentland { 23033be5262eSHarry Wentland struct dc_plane_state *plane_state = pipe_ctx->plane_state; 23044562236bSHarry Wentland 23053be5262eSHarry Wentland if (plane_state == NULL) 23064562236bSHarry Wentland return; 23074562236bSHarry Wentland 23083be5262eSHarry Wentland plane_state->status.is_flip_pending = 230986a66c4eSHarry Wentland pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending( 231086a66c4eSHarry Wentland pipe_ctx->plane_res.mi); 23114562236bSHarry Wentland 23123be5262eSHarry Wentland if (plane_state->status.is_flip_pending && !plane_state->visible) 231386a66c4eSHarry Wentland pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address; 23144562236bSHarry Wentland 231586a66c4eSHarry Wentland plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address; 231686a66c4eSHarry Wentland if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO && 23176b670fa9SHarry Wentland pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) { 23183be5262eSHarry Wentland plane_state->status.is_right_eye =\ 23196b670fa9SHarry Wentland !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg); 23207f5c22d1SVitaly Prosyak } 23214562236bSHarry Wentland } 23224562236bSHarry Wentland 2323fb3466a4SBhawanpreet Lakha void dce110_power_down(struct dc *dc) 23244562236bSHarry Wentland { 23254562236bSHarry Wentland power_down_all_hw_blocks(dc); 23264562236bSHarry Wentland disable_vga_and_power_gate_all_controllers(dc); 23274562236bSHarry Wentland } 23284562236bSHarry Wentland 23294562236bSHarry Wentland static bool wait_for_reset_trigger_to_occur( 23304562236bSHarry Wentland struct dc_context *dc_ctx, 23314562236bSHarry Wentland struct timing_generator *tg) 23324562236bSHarry Wentland { 23334562236bSHarry Wentland bool rc = false; 23344562236bSHarry Wentland 23354562236bSHarry Wentland /* To avoid endless loop we wait at most 23364562236bSHarry Wentland * frames_to_wait_on_triggered_reset frames for the reset to occur. */ 23374562236bSHarry Wentland const uint32_t frames_to_wait_on_triggered_reset = 10; 23384562236bSHarry Wentland uint32_t i; 23394562236bSHarry Wentland 23404562236bSHarry Wentland for (i = 0; i < frames_to_wait_on_triggered_reset; i++) { 23414562236bSHarry Wentland 23424562236bSHarry Wentland if (!tg->funcs->is_counter_moving(tg)) { 23434562236bSHarry Wentland DC_ERROR("TG counter is not moving!\n"); 23444562236bSHarry Wentland break; 23454562236bSHarry Wentland } 23464562236bSHarry Wentland 23474562236bSHarry Wentland if (tg->funcs->did_triggered_reset_occur(tg)) { 23484562236bSHarry Wentland rc = true; 23494562236bSHarry Wentland /* usually occurs at i=1 */ 23504562236bSHarry Wentland DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n", 23514562236bSHarry Wentland i); 23524562236bSHarry Wentland break; 23534562236bSHarry Wentland } 23544562236bSHarry Wentland 23554562236bSHarry Wentland /* Wait for one frame. */ 23564562236bSHarry Wentland tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE); 23574562236bSHarry Wentland tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK); 23584562236bSHarry Wentland } 23594562236bSHarry Wentland 23604562236bSHarry Wentland if (false == rc) 23614562236bSHarry Wentland DC_ERROR("GSL: Timeout on reset trigger!\n"); 23624562236bSHarry Wentland 23634562236bSHarry Wentland return rc; 23644562236bSHarry Wentland } 23654562236bSHarry Wentland 23664562236bSHarry Wentland /* Enable timing synchronization for a group of Timing Generators. */ 23674562236bSHarry Wentland static void dce110_enable_timing_synchronization( 2368fb3466a4SBhawanpreet Lakha struct dc *dc, 23694562236bSHarry Wentland int group_index, 23704562236bSHarry Wentland int group_size, 23714562236bSHarry Wentland struct pipe_ctx *grouped_pipes[]) 23724562236bSHarry Wentland { 23734562236bSHarry Wentland struct dc_context *dc_ctx = dc->ctx; 23744562236bSHarry Wentland struct dcp_gsl_params gsl_params = { 0 }; 23754562236bSHarry Wentland int i; 23764562236bSHarry Wentland 23774562236bSHarry Wentland DC_SYNC_INFO("GSL: Setting-up...\n"); 23784562236bSHarry Wentland 23794562236bSHarry Wentland /* Designate a single TG in the group as a master. 23804562236bSHarry Wentland * Since HW doesn't care which one, we always assign 23814562236bSHarry Wentland * the 1st one in the group. */ 23824562236bSHarry Wentland gsl_params.gsl_group = 0; 23836b670fa9SHarry Wentland gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst; 23844562236bSHarry Wentland 23854562236bSHarry Wentland for (i = 0; i < group_size; i++) 23866b670fa9SHarry Wentland grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock( 23876b670fa9SHarry Wentland grouped_pipes[i]->stream_res.tg, &gsl_params); 23884562236bSHarry Wentland 23894562236bSHarry Wentland /* Reset slave controllers on master VSync */ 23904562236bSHarry Wentland DC_SYNC_INFO("GSL: enabling trigger-reset\n"); 23914562236bSHarry Wentland 23924562236bSHarry Wentland for (i = 1 /* skip the master */; i < group_size; i++) 23936b670fa9SHarry Wentland grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger( 2394fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg, 2395fa2123dbSMikita Lipski gsl_params.gsl_group); 23964562236bSHarry Wentland 23974562236bSHarry Wentland for (i = 1 /* skip the master */; i < group_size; i++) { 23984562236bSHarry Wentland DC_SYNC_INFO("GSL: waiting for reset to occur.\n"); 23996b670fa9SHarry Wentland wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg); 2400fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger( 2401fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg); 24024562236bSHarry Wentland } 24034562236bSHarry Wentland 24044562236bSHarry Wentland /* GSL Vblank synchronization is a one time sync mechanism, assumption 24054562236bSHarry Wentland * is that the sync'ed displays will not drift out of sync over time*/ 24064562236bSHarry Wentland DC_SYNC_INFO("GSL: Restoring register states.\n"); 24074562236bSHarry Wentland for (i = 0; i < group_size; i++) 24086b670fa9SHarry Wentland grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg); 24094562236bSHarry Wentland 24104562236bSHarry Wentland DC_SYNC_INFO("GSL: Set-up complete.\n"); 24114562236bSHarry Wentland } 24124562236bSHarry Wentland 2413fa2123dbSMikita Lipski static void dce110_enable_per_frame_crtc_position_reset( 2414fa2123dbSMikita Lipski struct dc *dc, 2415fa2123dbSMikita Lipski int group_size, 2416fa2123dbSMikita Lipski struct pipe_ctx *grouped_pipes[]) 2417fa2123dbSMikita Lipski { 2418fa2123dbSMikita Lipski struct dc_context *dc_ctx = dc->ctx; 2419fa2123dbSMikita Lipski struct dcp_gsl_params gsl_params = { 0 }; 2420fa2123dbSMikita Lipski int i; 2421fa2123dbSMikita Lipski 2422fa2123dbSMikita Lipski gsl_params.gsl_group = 0; 2423fa2123dbSMikita Lipski gsl_params.gsl_master = grouped_pipes[0]->stream->triggered_crtc_reset.event_source->status.primary_otg_inst; 2424fa2123dbSMikita Lipski 2425fa2123dbSMikita Lipski for (i = 0; i < group_size; i++) 2426fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock( 2427fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg, &gsl_params); 2428fa2123dbSMikita Lipski 2429fa2123dbSMikita Lipski DC_SYNC_INFO("GSL: enabling trigger-reset\n"); 2430fa2123dbSMikita Lipski 2431fa2123dbSMikita Lipski for (i = 1; i < group_size; i++) 2432fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset( 2433fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg, 2434fa2123dbSMikita Lipski gsl_params.gsl_master, 2435fa2123dbSMikita Lipski &grouped_pipes[i]->stream->triggered_crtc_reset); 2436fa2123dbSMikita Lipski 2437fa2123dbSMikita Lipski DC_SYNC_INFO("GSL: waiting for reset to occur.\n"); 2438fa2123dbSMikita Lipski for (i = 1; i < group_size; i++) 2439fa2123dbSMikita Lipski wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg); 2440fa2123dbSMikita Lipski 2441fa2123dbSMikita Lipski for (i = 0; i < group_size; i++) 2442fa2123dbSMikita Lipski grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg); 2443fa2123dbSMikita Lipski 2444fa2123dbSMikita Lipski } 2445fa2123dbSMikita Lipski 2446fb3466a4SBhawanpreet Lakha static void init_hw(struct dc *dc) 24474562236bSHarry Wentland { 24484562236bSHarry Wentland int i; 24494562236bSHarry Wentland struct dc_bios *bp; 24504562236bSHarry Wentland struct transform *xfm; 24515e7773a2SAnthony Koo struct abm *abm; 24524562236bSHarry Wentland 24534562236bSHarry Wentland bp = dc->ctx->dc_bios; 24544562236bSHarry Wentland for (i = 0; i < dc->res_pool->pipe_count; i++) { 24554562236bSHarry Wentland xfm = dc->res_pool->transforms[i]; 24564562236bSHarry Wentland xfm->funcs->transform_reset(xfm); 24574562236bSHarry Wentland 24584562236bSHarry Wentland dc->hwss.enable_display_power_gating( 24594562236bSHarry Wentland dc, i, bp, 24604562236bSHarry Wentland PIPE_GATING_CONTROL_INIT); 24614562236bSHarry Wentland dc->hwss.enable_display_power_gating( 24624562236bSHarry Wentland dc, i, bp, 24634562236bSHarry Wentland PIPE_GATING_CONTROL_DISABLE); 24644562236bSHarry Wentland dc->hwss.enable_display_pipe_clock_gating( 24654562236bSHarry Wentland dc->ctx, 24664562236bSHarry Wentland true); 24674562236bSHarry Wentland } 24684562236bSHarry Wentland 2469e166ad43SJulia Lawall dce_clock_gating_power_up(dc->hwseq, false); 24704562236bSHarry Wentland /***************************************/ 24714562236bSHarry Wentland 24724562236bSHarry Wentland for (i = 0; i < dc->link_count; i++) { 24734562236bSHarry Wentland /****************************************/ 24744562236bSHarry Wentland /* Power up AND update implementation according to the 24754562236bSHarry Wentland * required signal (which may be different from the 24764562236bSHarry Wentland * default signal on connector). */ 2477d0778ebfSHarry Wentland struct dc_link *link = dc->links[i]; 2478069d418fSAndrew Jiang 2479069d418fSAndrew Jiang if (link->link_enc->connector.id == CONNECTOR_ID_EDP) 2480069d418fSAndrew Jiang dc->hwss.edp_power_control(link, true); 2481069d418fSAndrew Jiang 24824562236bSHarry Wentland link->link_enc->funcs->hw_init(link->link_enc); 24834562236bSHarry Wentland } 24844562236bSHarry Wentland 24854562236bSHarry Wentland for (i = 0; i < dc->res_pool->pipe_count; i++) { 24864562236bSHarry Wentland struct timing_generator *tg = dc->res_pool->timing_generators[i]; 24874562236bSHarry Wentland 24884562236bSHarry Wentland tg->funcs->disable_vga(tg); 24894562236bSHarry Wentland 24904562236bSHarry Wentland /* Blank controller using driver code instead of 24914562236bSHarry Wentland * command table. */ 24924562236bSHarry Wentland tg->funcs->set_blank(tg, true); 24934b5e7d62SHersen Wu hwss_wait_for_blank_complete(tg); 24944562236bSHarry Wentland } 24954562236bSHarry Wentland 24964562236bSHarry Wentland for (i = 0; i < dc->res_pool->audio_count; i++) { 24974562236bSHarry Wentland struct audio *audio = dc->res_pool->audios[i]; 24984562236bSHarry Wentland audio->funcs->hw_init(audio); 24994562236bSHarry Wentland } 25005e7773a2SAnthony Koo 25015e7773a2SAnthony Koo abm = dc->res_pool->abm; 25026728b30cSAnthony Koo if (abm != NULL) { 25036728b30cSAnthony Koo abm->funcs->init_backlight(abm); 25045e7773a2SAnthony Koo abm->funcs->abm_init(abm); 25054562236bSHarry Wentland } 25063eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 25072f3bfb27SRoman Li if (dc->fbc_compressor) 25081663ae1cSBhawanpreet Lakha dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor); 25091663ae1cSBhawanpreet Lakha #endif 2510690b5e39SRoman Li 25116728b30cSAnthony Koo } 25124562236bSHarry Wentland 251328f72454SJordan Lazare void dce110_fill_display_configs( 2514608ac7bbSJerry Zuo const struct dc_state *context, 2515cf437593SDmytro Laktyushkin struct dm_pp_display_configuration *pp_display_cfg) 25164562236bSHarry Wentland { 2517cf437593SDmytro Laktyushkin int j; 2518cf437593SDmytro Laktyushkin int num_cfgs = 0; 2519cf437593SDmytro Laktyushkin 2520cf437593SDmytro Laktyushkin for (j = 0; j < context->stream_count; j++) { 2521cf437593SDmytro Laktyushkin int k; 2522cf437593SDmytro Laktyushkin 25230971c40eSHarry Wentland const struct dc_stream_state *stream = context->streams[j]; 2524cf437593SDmytro Laktyushkin struct dm_pp_single_disp_config *cfg = 2525cf437593SDmytro Laktyushkin &pp_display_cfg->disp_configs[num_cfgs]; 2526cf437593SDmytro Laktyushkin const struct pipe_ctx *pipe_ctx = NULL; 2527cf437593SDmytro Laktyushkin 2528cf437593SDmytro Laktyushkin for (k = 0; k < MAX_PIPES; k++) 2529cf437593SDmytro Laktyushkin if (stream == context->res_ctx.pipe_ctx[k].stream) { 2530cf437593SDmytro Laktyushkin pipe_ctx = &context->res_ctx.pipe_ctx[k]; 2531cf437593SDmytro Laktyushkin break; 25324562236bSHarry Wentland } 25334562236bSHarry Wentland 2534cf437593SDmytro Laktyushkin ASSERT(pipe_ctx != NULL); 2535cf437593SDmytro Laktyushkin 2536631aaa0aSHersen Wu /* only notify active stream */ 2537631aaa0aSHersen Wu if (stream->dpms_off) 2538631aaa0aSHersen Wu continue; 2539631aaa0aSHersen Wu 2540cf437593SDmytro Laktyushkin num_cfgs++; 2541cf437593SDmytro Laktyushkin cfg->signal = pipe_ctx->stream->signal; 2542e07f541fSYongqiang Sun cfg->pipe_idx = pipe_ctx->stream_res.tg->inst; 25434fa086b9SLeo (Sunpeng) Li cfg->src_height = stream->src.height; 25444fa086b9SLeo (Sunpeng) Li cfg->src_width = stream->src.width; 2545cf437593SDmytro Laktyushkin cfg->ddi_channel_mapping = 2546cf437593SDmytro Laktyushkin stream->sink->link->ddi_channel_mapping.raw; 2547cf437593SDmytro Laktyushkin cfg->transmitter = 2548cf437593SDmytro Laktyushkin stream->sink->link->link_enc->transmitter; 2549cf437593SDmytro Laktyushkin cfg->link_settings.lane_count = 2550d0778ebfSHarry Wentland stream->sink->link->cur_link_settings.lane_count; 2551cf437593SDmytro Laktyushkin cfg->link_settings.link_rate = 2552d0778ebfSHarry Wentland stream->sink->link->cur_link_settings.link_rate; 2553cf437593SDmytro Laktyushkin cfg->link_settings.link_spread = 2554d0778ebfSHarry Wentland stream->sink->link->cur_link_settings.link_spread; 2555cf437593SDmytro Laktyushkin cfg->sym_clock = stream->phy_pix_clk; 2556cf437593SDmytro Laktyushkin /* Round v_refresh*/ 25574fa086b9SLeo (Sunpeng) Li cfg->v_refresh = stream->timing.pix_clk_khz * 1000; 25584fa086b9SLeo (Sunpeng) Li cfg->v_refresh /= stream->timing.h_total; 25594fa086b9SLeo (Sunpeng) Li cfg->v_refresh = (cfg->v_refresh + stream->timing.v_total / 2) 25604fa086b9SLeo (Sunpeng) Li / stream->timing.v_total; 2561cf437593SDmytro Laktyushkin } 2562cf437593SDmytro Laktyushkin 2563cf437593SDmytro Laktyushkin pp_display_cfg->display_count = num_cfgs; 2564cf437593SDmytro Laktyushkin } 2565cf437593SDmytro Laktyushkin 2566608ac7bbSJerry Zuo uint32_t dce110_get_min_vblank_time_us(const struct dc_state *context) 2567cf437593SDmytro Laktyushkin { 2568cf437593SDmytro Laktyushkin uint8_t j; 2569cf437593SDmytro Laktyushkin uint32_t min_vertical_blank_time = -1; 2570cf437593SDmytro Laktyushkin 2571cf437593SDmytro Laktyushkin for (j = 0; j < context->stream_count; j++) { 25720971c40eSHarry Wentland struct dc_stream_state *stream = context->streams[j]; 2573cf437593SDmytro Laktyushkin uint32_t vertical_blank_in_pixels = 0; 2574cf437593SDmytro Laktyushkin uint32_t vertical_blank_time = 0; 2575cf437593SDmytro Laktyushkin 2576cf437593SDmytro Laktyushkin vertical_blank_in_pixels = stream->timing.h_total * 2577cf437593SDmytro Laktyushkin (stream->timing.v_total 2578cf437593SDmytro Laktyushkin - stream->timing.v_addressable); 2579cf437593SDmytro Laktyushkin 2580cf437593SDmytro Laktyushkin vertical_blank_time = vertical_blank_in_pixels 2581cf437593SDmytro Laktyushkin * 1000 / stream->timing.pix_clk_khz; 2582cf437593SDmytro Laktyushkin 2583cf437593SDmytro Laktyushkin if (min_vertical_blank_time > vertical_blank_time) 2584cf437593SDmytro Laktyushkin min_vertical_blank_time = vertical_blank_time; 2585cf437593SDmytro Laktyushkin } 2586cf437593SDmytro Laktyushkin 2587cf437593SDmytro Laktyushkin return min_vertical_blank_time; 2588cf437593SDmytro Laktyushkin } 2589cf437593SDmytro Laktyushkin 2590cf437593SDmytro Laktyushkin static int determine_sclk_from_bounding_box( 2591fb3466a4SBhawanpreet Lakha const struct dc *dc, 2592cf437593SDmytro Laktyushkin int required_sclk) 25934562236bSHarry Wentland { 25944562236bSHarry Wentland int i; 25954562236bSHarry Wentland 2596cf437593SDmytro Laktyushkin /* 2597cf437593SDmytro Laktyushkin * Some asics do not give us sclk levels, so we just report the actual 2598cf437593SDmytro Laktyushkin * required sclk 2599cf437593SDmytro Laktyushkin */ 2600cf437593SDmytro Laktyushkin if (dc->sclk_lvls.num_levels == 0) 2601cf437593SDmytro Laktyushkin return required_sclk; 26024562236bSHarry Wentland 2603cf437593SDmytro Laktyushkin for (i = 0; i < dc->sclk_lvls.num_levels; i++) { 2604cf437593SDmytro Laktyushkin if (dc->sclk_lvls.clocks_in_khz[i] >= required_sclk) 2605cf437593SDmytro Laktyushkin return dc->sclk_lvls.clocks_in_khz[i]; 2606cf437593SDmytro Laktyushkin } 2607cf437593SDmytro Laktyushkin /* 2608cf437593SDmytro Laktyushkin * even maximum level could not satisfy requirement, this 2609cf437593SDmytro Laktyushkin * is unexpected at this stage, should have been caught at 2610cf437593SDmytro Laktyushkin * validation time 2611cf437593SDmytro Laktyushkin */ 2612cf437593SDmytro Laktyushkin ASSERT(0); 2613cf437593SDmytro Laktyushkin return dc->sclk_lvls.clocks_in_khz[dc->sclk_lvls.num_levels - 1]; 26144562236bSHarry Wentland } 26154562236bSHarry Wentland 2616cf437593SDmytro Laktyushkin static void pplib_apply_display_requirements( 2617fb3466a4SBhawanpreet Lakha struct dc *dc, 2618608ac7bbSJerry Zuo struct dc_state *context) 2619cf437593SDmytro Laktyushkin { 2620cf437593SDmytro Laktyushkin struct dm_pp_display_configuration *pp_display_cfg = &context->pp_display_cfg; 2621cf437593SDmytro Laktyushkin 2622cf437593SDmytro Laktyushkin pp_display_cfg->all_displays_in_sync = 26239037d802SDmytro Laktyushkin context->bw.dce.all_displays_in_sync; 2624cf437593SDmytro Laktyushkin pp_display_cfg->nb_pstate_switch_disable = 26259037d802SDmytro Laktyushkin context->bw.dce.nbp_state_change_enable == false; 2626cf437593SDmytro Laktyushkin pp_display_cfg->cpu_cc6_disable = 26279037d802SDmytro Laktyushkin context->bw.dce.cpuc_state_change_enable == false; 2628cf437593SDmytro Laktyushkin pp_display_cfg->cpu_pstate_disable = 26299037d802SDmytro Laktyushkin context->bw.dce.cpup_state_change_enable == false; 2630cf437593SDmytro Laktyushkin pp_display_cfg->cpu_pstate_separation_time = 26319037d802SDmytro Laktyushkin context->bw.dce.blackout_recovery_time_us; 2632cf437593SDmytro Laktyushkin 26339037d802SDmytro Laktyushkin pp_display_cfg->min_memory_clock_khz = context->bw.dce.yclk_khz 2634cf437593SDmytro Laktyushkin / MEMORY_TYPE_MULTIPLIER; 2635cf437593SDmytro Laktyushkin 2636cf437593SDmytro Laktyushkin pp_display_cfg->min_engine_clock_khz = determine_sclk_from_bounding_box( 2637cf437593SDmytro Laktyushkin dc, 26389037d802SDmytro Laktyushkin context->bw.dce.sclk_khz); 2639cf437593SDmytro Laktyushkin 2640cf437593SDmytro Laktyushkin pp_display_cfg->min_engine_clock_deep_sleep_khz 26419037d802SDmytro Laktyushkin = context->bw.dce.sclk_deep_sleep_khz; 2642cf437593SDmytro Laktyushkin 2643cf437593SDmytro Laktyushkin pp_display_cfg->avail_mclk_switch_time_us = 264428f72454SJordan Lazare dce110_get_min_vblank_time_us(context); 2645cf437593SDmytro Laktyushkin /* TODO: dce11.2*/ 2646cf437593SDmytro Laktyushkin pp_display_cfg->avail_mclk_switch_time_in_disp_active_us = 0; 2647cf437593SDmytro Laktyushkin 26489037d802SDmytro Laktyushkin pp_display_cfg->disp_clk_khz = context->bw.dce.dispclk_khz; 2649cf437593SDmytro Laktyushkin 265028f72454SJordan Lazare dce110_fill_display_configs(context, pp_display_cfg); 2651cf437593SDmytro Laktyushkin 2652cf437593SDmytro Laktyushkin /* TODO: is this still applicable?*/ 2653cf437593SDmytro Laktyushkin if (pp_display_cfg->display_count == 1) { 2654cf437593SDmytro Laktyushkin const struct dc_crtc_timing *timing = 26554fa086b9SLeo (Sunpeng) Li &context->streams[0]->timing; 2656cf437593SDmytro Laktyushkin 2657cf437593SDmytro Laktyushkin pp_display_cfg->crtc_index = 2658cf437593SDmytro Laktyushkin pp_display_cfg->disp_configs[0].pipe_idx; 2659cf437593SDmytro Laktyushkin pp_display_cfg->line_time_in_us = timing->h_total * 1000 2660cf437593SDmytro Laktyushkin / timing->pix_clk_khz; 2661cf437593SDmytro Laktyushkin } 2662cf437593SDmytro Laktyushkin 2663cf437593SDmytro Laktyushkin if (memcmp(&dc->prev_display_config, pp_display_cfg, sizeof( 2664cf437593SDmytro Laktyushkin struct dm_pp_display_configuration)) != 0) 2665cf437593SDmytro Laktyushkin dm_pp_apply_display_requirements(dc->ctx, pp_display_cfg); 2666cf437593SDmytro Laktyushkin 2667cf437593SDmytro Laktyushkin dc->prev_display_config = *pp_display_cfg; 2668cf437593SDmytro Laktyushkin } 2669cf437593SDmytro Laktyushkin 2670cf437593SDmytro Laktyushkin static void dce110_set_bandwidth( 2671fb3466a4SBhawanpreet Lakha struct dc *dc, 2672608ac7bbSJerry Zuo struct dc_state *context, 2673cf437593SDmytro Laktyushkin bool decrease_allowed) 2674cf437593SDmytro Laktyushkin { 26752180e7ccSDmytro Laktyushkin dce110_set_displaymarks(dc, context); 2676cf437593SDmytro Laktyushkin 2677608ac7bbSJerry Zuo if (decrease_allowed || context->bw.dce.dispclk_khz > dc->current_state->bw.dce.dispclk_khz) { 2678a2b8659dSTony Cheng dc->res_pool->display_clock->funcs->set_clock( 2679a2b8659dSTony Cheng dc->res_pool->display_clock, 26809037d802SDmytro Laktyushkin context->bw.dce.dispclk_khz * 115 / 100); 2681608ac7bbSJerry Zuo dc->current_state->bw.dce.dispclk_khz = context->bw.dce.dispclk_khz; 2682cf437593SDmytro Laktyushkin } 2683cf437593SDmytro Laktyushkin 2684cf437593SDmytro Laktyushkin pplib_apply_display_requirements(dc, context); 26854562236bSHarry Wentland } 26864562236bSHarry Wentland 26874562236bSHarry Wentland static void dce110_program_front_end_for_pipe( 2688fb3466a4SBhawanpreet Lakha struct dc *dc, struct pipe_ctx *pipe_ctx) 26894562236bSHarry Wentland { 269086a66c4eSHarry Wentland struct mem_input *mi = pipe_ctx->plane_res.mi; 26914562236bSHarry Wentland struct pipe_ctx *old_pipe = NULL; 26923be5262eSHarry Wentland struct dc_plane_state *plane_state = pipe_ctx->plane_state; 26934562236bSHarry Wentland struct xfm_grph_csc_adjustment adjust; 26944562236bSHarry Wentland struct out_csc_color_matrix tbl_entry; 26954562236bSHarry Wentland unsigned int i; 26961296423bSBhawanpreet Lakha struct dc_context *ctx = dc->ctx; 26974562236bSHarry Wentland memset(&tbl_entry, 0, sizeof(tbl_entry)); 26984562236bSHarry Wentland 2699608ac7bbSJerry Zuo if (dc->current_state) 2700608ac7bbSJerry Zuo old_pipe = &dc->current_state->res_ctx.pipe_ctx[pipe_ctx->pipe_idx]; 27014562236bSHarry Wentland 27024562236bSHarry Wentland memset(&adjust, 0, sizeof(adjust)); 27034562236bSHarry Wentland adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS; 27044562236bSHarry Wentland 2705e07f541fSYongqiang Sun dce_enable_fe_clock(dc->hwseq, mi->inst, true); 27064562236bSHarry Wentland 27074562236bSHarry Wentland set_default_colors(pipe_ctx); 27084fa086b9SLeo (Sunpeng) Li if (pipe_ctx->stream->csc_color_matrix.enable_adjustment 27094562236bSHarry Wentland == true) { 27104562236bSHarry Wentland tbl_entry.color_space = 27114fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->output_color_space; 27124562236bSHarry Wentland 27134562236bSHarry Wentland for (i = 0; i < 12; i++) 27144562236bSHarry Wentland tbl_entry.regval[i] = 27154fa086b9SLeo (Sunpeng) Li pipe_ctx->stream->csc_color_matrix.matrix[i]; 27164562236bSHarry Wentland 271786a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment 271886a66c4eSHarry Wentland (pipe_ctx->plane_res.xfm, &tbl_entry); 27194562236bSHarry Wentland } 27204562236bSHarry Wentland 27214fa086b9SLeo (Sunpeng) Li if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) { 27224562236bSHarry Wentland adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW; 2723146a9f63SKrunoslav Kovac 2724146a9f63SKrunoslav Kovac for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++) 2725146a9f63SKrunoslav Kovac adjust.temperature_matrix[i] = 2726146a9f63SKrunoslav Kovac pipe_ctx->stream->gamut_remap_matrix.matrix[i]; 27274562236bSHarry Wentland } 27284562236bSHarry Wentland 272986a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust); 27304562236bSHarry Wentland 27316702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0; 2732c1473558SAndrey Grodzovsky 27334562236bSHarry Wentland program_scaler(dc, pipe_ctx); 27344562236bSHarry Wentland 27353eab7916SShirish S #if defined(CONFIG_DRM_AMD_DC_FBC) 2736e008b0bcSRoman Li if (dc->fbc_compressor && old_pipe->stream) { 2737e008b0bcSRoman Li if (plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL) 2738e008b0bcSRoman Li dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor); 2739e008b0bcSRoman Li else 2740e008b0bcSRoman Li enable_fbc(dc, dc->current_state); 2741e008b0bcSRoman Li } 2742e008b0bcSRoman Li #endif 2743e008b0bcSRoman Li 27444562236bSHarry Wentland mi->funcs->mem_input_program_surface_config( 27454562236bSHarry Wentland mi, 27463be5262eSHarry Wentland plane_state->format, 27473be5262eSHarry Wentland &plane_state->tiling_info, 27483be5262eSHarry Wentland &plane_state->plane_size, 27493be5262eSHarry Wentland plane_state->rotation, 2750624d7c47SYongqiang Sun NULL, 27514b28b76bSDmytro Laktyushkin false); 27524b28b76bSDmytro Laktyushkin if (mi->funcs->set_blank) 27533be5262eSHarry Wentland mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible); 27544562236bSHarry Wentland 2755fb3466a4SBhawanpreet Lakha if (dc->config.gpu_vm_support) 27564562236bSHarry Wentland mi->funcs->mem_input_program_pte_vm( 275786a66c4eSHarry Wentland pipe_ctx->plane_res.mi, 27583be5262eSHarry Wentland plane_state->format, 27593be5262eSHarry Wentland &plane_state->tiling_info, 27603be5262eSHarry Wentland plane_state->rotation); 27614562236bSHarry Wentland 2762067c878aSYongqiang Sun /* Moved programming gamma from dc to hwss */ 2763405c50a0SAndrew Jiang if (pipe_ctx->plane_state->update_flags.bits.full_update || 2764405c50a0SAndrew Jiang pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change || 2765405c50a0SAndrew Jiang pipe_ctx->plane_state->update_flags.bits.gamma_change) 2766a6114e85SHarry Wentland dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state); 2767405c50a0SAndrew Jiang 2768405c50a0SAndrew Jiang if (pipe_ctx->plane_state->update_flags.bits.full_update) 2769a6114e85SHarry Wentland dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream); 2770067c878aSYongqiang Sun 27711296423bSBhawanpreet Lakha DC_LOG_SURFACE( 27724562236bSHarry Wentland "Pipe:%d 0x%x: addr hi:0x%x, " 27734562236bSHarry Wentland "addr low:0x%x, " 27744562236bSHarry Wentland "src: %d, %d, %d," 27754562236bSHarry Wentland " %d; dst: %d, %d, %d, %d;" 27764562236bSHarry Wentland "clip: %d, %d, %d, %d\n", 27774562236bSHarry Wentland pipe_ctx->pipe_idx, 27783be5262eSHarry Wentland pipe_ctx->plane_state, 27793be5262eSHarry Wentland pipe_ctx->plane_state->address.grph.addr.high_part, 27803be5262eSHarry Wentland pipe_ctx->plane_state->address.grph.addr.low_part, 27813be5262eSHarry Wentland pipe_ctx->plane_state->src_rect.x, 27823be5262eSHarry Wentland pipe_ctx->plane_state->src_rect.y, 27833be5262eSHarry Wentland pipe_ctx->plane_state->src_rect.width, 27843be5262eSHarry Wentland pipe_ctx->plane_state->src_rect.height, 27853be5262eSHarry Wentland pipe_ctx->plane_state->dst_rect.x, 27863be5262eSHarry Wentland pipe_ctx->plane_state->dst_rect.y, 27873be5262eSHarry Wentland pipe_ctx->plane_state->dst_rect.width, 27883be5262eSHarry Wentland pipe_ctx->plane_state->dst_rect.height, 27893be5262eSHarry Wentland pipe_ctx->plane_state->clip_rect.x, 27903be5262eSHarry Wentland pipe_ctx->plane_state->clip_rect.y, 27913be5262eSHarry Wentland pipe_ctx->plane_state->clip_rect.width, 27923be5262eSHarry Wentland pipe_ctx->plane_state->clip_rect.height); 27934562236bSHarry Wentland 27941296423bSBhawanpreet Lakha DC_LOG_SURFACE( 27954562236bSHarry Wentland "Pipe %d: width, height, x, y\n" 27964562236bSHarry Wentland "viewport:%d, %d, %d, %d\n" 27974562236bSHarry Wentland "recout: %d, %d, %d, %d\n", 27984562236bSHarry Wentland pipe_ctx->pipe_idx, 27996702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.viewport.width, 28006702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.viewport.height, 28016702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.viewport.x, 28026702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.viewport.y, 28036702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.recout.width, 28046702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.recout.height, 28056702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.recout.x, 28066702a9acSHarry Wentland pipe_ctx->plane_res.scl_data.recout.y); 28074562236bSHarry Wentland } 28084562236bSHarry Wentland 28094562236bSHarry Wentland static void dce110_apply_ctx_for_surface( 2810fb3466a4SBhawanpreet Lakha struct dc *dc, 28113e9ad616SEric Yang const struct dc_stream_state *stream, 28123e9ad616SEric Yang int num_planes, 2813608ac7bbSJerry Zuo struct dc_state *context) 28144562236bSHarry Wentland { 28152194e3aeSRoman Li int i; 28164562236bSHarry Wentland 28173e9ad616SEric Yang if (num_planes == 0) 28184562236bSHarry Wentland return; 28194562236bSHarry Wentland 28203e9ad616SEric Yang for (i = 0; i < dc->res_pool->pipe_count; i++) { 28213dc780ecSYongqiang Sun struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 28223dc780ecSYongqiang Sun struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i]; 28233dc780ecSYongqiang Sun 28242194e3aeSRoman Li if (stream == pipe_ctx->stream) { 28253dc780ecSYongqiang Sun if (!pipe_ctx->top_pipe && 28263dc780ecSYongqiang Sun (pipe_ctx->plane_state || old_pipe_ctx->plane_state)) 28273dc780ecSYongqiang Sun dc->hwss.pipe_control_lock(dc, pipe_ctx, true); 28283e9ad616SEric Yang } 28293e9ad616SEric Yang } 28303e9ad616SEric Yang 2831a2b8659dSTony Cheng for (i = 0; i < dc->res_pool->pipe_count; i++) { 28324562236bSHarry Wentland struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 28334562236bSHarry Wentland 2834a2607aefSHarry Wentland if (pipe_ctx->stream != stream) 28354562236bSHarry Wentland continue; 28364562236bSHarry Wentland 28373b21b6d2SJerry Zuo /* Need to allocate mem before program front end for Fiji */ 28383b21b6d2SJerry Zuo pipe_ctx->plane_res.mi->funcs->allocate_mem_input( 28393b21b6d2SJerry Zuo pipe_ctx->plane_res.mi, 28403b21b6d2SJerry Zuo pipe_ctx->stream->timing.h_total, 28413b21b6d2SJerry Zuo pipe_ctx->stream->timing.v_total, 28423b21b6d2SJerry Zuo pipe_ctx->stream->timing.pix_clk_khz, 28433b21b6d2SJerry Zuo context->stream_count); 28443b21b6d2SJerry Zuo 28454562236bSHarry Wentland dce110_program_front_end_for_pipe(dc, pipe_ctx); 28464f804817SYongqiang Sun 28474f804817SYongqiang Sun dc->hwss.update_plane_addr(dc, pipe_ctx); 28484f804817SYongqiang Sun 2849b06b7680SLeon Elazar program_surface_visibility(dc, pipe_ctx); 28504562236bSHarry Wentland 28514562236bSHarry Wentland } 28523dc780ecSYongqiang Sun 28533dc780ecSYongqiang Sun for (i = 0; i < dc->res_pool->pipe_count; i++) { 28543dc780ecSYongqiang Sun struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i]; 28553dc780ecSYongqiang Sun struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i]; 28563dc780ecSYongqiang Sun 28573dc780ecSYongqiang Sun if ((stream == pipe_ctx->stream) && 28583dc780ecSYongqiang Sun (!pipe_ctx->top_pipe) && 28593dc780ecSYongqiang Sun (pipe_ctx->plane_state || old_pipe_ctx->plane_state)) 28603dc780ecSYongqiang Sun dc->hwss.pipe_control_lock(dc, pipe_ctx, false); 28613dc780ecSYongqiang Sun } 28624562236bSHarry Wentland } 28634562236bSHarry Wentland 2864e6c258cbSYongqiang Sun static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx) 28654562236bSHarry Wentland { 2866bc373a89SRoman Li int fe_idx = pipe_ctx->plane_res.mi ? 2867bc373a89SRoman Li pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx; 2868e6c258cbSYongqiang Sun 28697950f0f9SDmytro Laktyushkin /* Do not power down fe when stream is active on dce*/ 2870608ac7bbSJerry Zuo if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream) 28714562236bSHarry Wentland return; 28724562236bSHarry Wentland 28734562236bSHarry Wentland dc->hwss.enable_display_power_gating( 2874cfe4645eSDmytro Laktyushkin dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE); 2875cfe4645eSDmytro Laktyushkin 2876cfe4645eSDmytro Laktyushkin dc->res_pool->transforms[fe_idx]->funcs->transform_reset( 2877cfe4645eSDmytro Laktyushkin dc->res_pool->transforms[fe_idx]); 28784562236bSHarry Wentland } 28794562236bSHarry Wentland 28806be425f3SEric Yang static void dce110_wait_for_mpcc_disconnect( 2881fb3466a4SBhawanpreet Lakha struct dc *dc, 28826be425f3SEric Yang struct resource_pool *res_pool, 28836be425f3SEric Yang struct pipe_ctx *pipe_ctx) 2884b6762f0cSEric Yang { 2885b6762f0cSEric Yang /* do nothing*/ 2886b6762f0cSEric Yang } 2887b6762f0cSEric Yang 2888bdf9a1a0SYue Hin Lau static void program_csc_matrix(struct pipe_ctx *pipe_ctx, 2889bdf9a1a0SYue Hin Lau enum dc_color_space colorspace, 2890bdf9a1a0SYue Hin Lau uint16_t *matrix) 2891bdf9a1a0SYue Hin Lau { 2892bdf9a1a0SYue Hin Lau int i; 2893bdf9a1a0SYue Hin Lau struct out_csc_color_matrix tbl_entry; 2894bdf9a1a0SYue Hin Lau 2895bdf9a1a0SYue Hin Lau if (pipe_ctx->stream->csc_color_matrix.enable_adjustment 2896bdf9a1a0SYue Hin Lau == true) { 2897bdf9a1a0SYue Hin Lau enum dc_color_space color_space = 2898bdf9a1a0SYue Hin Lau pipe_ctx->stream->output_color_space; 2899bdf9a1a0SYue Hin Lau 2900bdf9a1a0SYue Hin Lau //uint16_t matrix[12]; 2901bdf9a1a0SYue Hin Lau for (i = 0; i < 12; i++) 2902bdf9a1a0SYue Hin Lau tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i]; 2903bdf9a1a0SYue Hin Lau 2904bdf9a1a0SYue Hin Lau tbl_entry.color_space = color_space; 2905bdf9a1a0SYue Hin Lau //tbl_entry.regval = matrix; 290686a66c4eSHarry Wentland pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(pipe_ctx->plane_res.xfm, &tbl_entry); 2907bdf9a1a0SYue Hin Lau } 2908bdf9a1a0SYue Hin Lau } 2909bdf9a1a0SYue Hin Lau 291033fd17d9SEric Yang void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx) 291133fd17d9SEric Yang { 291233fd17d9SEric Yang struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position; 291333fd17d9SEric Yang struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp; 291433fd17d9SEric Yang struct mem_input *mi = pipe_ctx->plane_res.mi; 291533fd17d9SEric Yang struct dc_cursor_mi_param param = { 291633fd17d9SEric Yang .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_khz, 291733fd17d9SEric Yang .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clock_inKhz, 291833fd17d9SEric Yang .viewport_x_start = pipe_ctx->plane_res.scl_data.viewport.x, 291933fd17d9SEric Yang .viewport_width = pipe_ctx->plane_res.scl_data.viewport.width, 292033fd17d9SEric Yang .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz 292133fd17d9SEric Yang }; 292233fd17d9SEric Yang 292333fd17d9SEric Yang if (pipe_ctx->plane_state->address.type 292433fd17d9SEric Yang == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE) 292533fd17d9SEric Yang pos_cpy.enable = false; 292633fd17d9SEric Yang 292733fd17d9SEric Yang if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state) 292833fd17d9SEric Yang pos_cpy.enable = false; 292933fd17d9SEric Yang 2930dc75dd70SRoman Li if (ipp->funcs->ipp_cursor_set_position) 293133fd17d9SEric Yang ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m); 2932dc75dd70SRoman Li if (mi->funcs->set_cursor_position) 293333fd17d9SEric Yang mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m); 293433fd17d9SEric Yang } 293533fd17d9SEric Yang 293633fd17d9SEric Yang void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx) 293733fd17d9SEric Yang { 293833fd17d9SEric Yang struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes; 293933fd17d9SEric Yang 2940d1aaad05SHarry Wentland if (pipe_ctx->plane_res.ipp && 2941d1aaad05SHarry Wentland pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes) 294233fd17d9SEric Yang pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes( 294333fd17d9SEric Yang pipe_ctx->plane_res.ipp, attributes); 294433fd17d9SEric Yang 2945d1aaad05SHarry Wentland if (pipe_ctx->plane_res.mi && 2946d1aaad05SHarry Wentland pipe_ctx->plane_res.mi->funcs->set_cursor_attributes) 294733fd17d9SEric Yang pipe_ctx->plane_res.mi->funcs->set_cursor_attributes( 294833fd17d9SEric Yang pipe_ctx->plane_res.mi, attributes); 294933fd17d9SEric Yang 2950d1aaad05SHarry Wentland if (pipe_ctx->plane_res.xfm && 2951d1aaad05SHarry Wentland pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes) 295233fd17d9SEric Yang pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes( 295333fd17d9SEric Yang pipe_ctx->plane_res.xfm, attributes); 295433fd17d9SEric Yang } 295533fd17d9SEric Yang 29566bf52028SHersen Wu static void ready_shared_resources(struct dc *dc, struct dc_state *context) {} 295741f97c07SHersen Wu 295841f97c07SHersen Wu static void optimize_shared_resources(struct dc *dc) {} 295941f97c07SHersen Wu 29604562236bSHarry Wentland static const struct hw_sequencer_funcs dce110_funcs = { 29611bf56e62SZeyu Fan .program_gamut_remap = program_gamut_remap, 2962bdf9a1a0SYue Hin Lau .program_csc_matrix = program_csc_matrix, 29634562236bSHarry Wentland .init_hw = init_hw, 29644562236bSHarry Wentland .apply_ctx_to_hw = dce110_apply_ctx_to_hw, 29654562236bSHarry Wentland .apply_ctx_for_surface = dce110_apply_ctx_for_surface, 29664562236bSHarry Wentland .set_plane_config = set_plane_config, 29674562236bSHarry Wentland .update_plane_addr = update_plane_addr, 29684562236bSHarry Wentland .update_pending_status = dce110_update_pending_status, 2969d7194cf6SAric Cyr .set_input_transfer_func = dce110_set_input_transfer_func, 297090e508baSAnthony Koo .set_output_transfer_func = dce110_set_output_transfer_func, 29714562236bSHarry Wentland .power_down = dce110_power_down, 29724562236bSHarry Wentland .enable_accelerated_mode = dce110_enable_accelerated_mode, 29734562236bSHarry Wentland .enable_timing_synchronization = dce110_enable_timing_synchronization, 2974fa2123dbSMikita Lipski .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset, 29754562236bSHarry Wentland .update_info_frame = dce110_update_info_frame, 29764562236bSHarry Wentland .enable_stream = dce110_enable_stream, 29774562236bSHarry Wentland .disable_stream = dce110_disable_stream, 29784562236bSHarry Wentland .unblank_stream = dce110_unblank_stream, 297941b49742SCharlene Liu .blank_stream = dce110_blank_stream, 29804562236bSHarry Wentland .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating, 29814562236bSHarry Wentland .enable_display_power_gating = dce110_enable_display_power_gating, 29827f914a62SYongqiang Sun .disable_plane = dce110_power_down_fe, 29834562236bSHarry Wentland .pipe_control_lock = dce_pipe_control_lock, 29844562236bSHarry Wentland .set_bandwidth = dce110_set_bandwidth, 29854562236bSHarry Wentland .set_drr = set_drr, 298672ada5f7SEric Cook .get_position = get_position, 29874562236bSHarry Wentland .set_static_screen_control = set_static_screen_control, 298854e8695eSDmytro Laktyushkin .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap, 29894b5e7d62SHersen Wu .prog_pixclk_crtc_otg = dce110_prog_pixclk_crtc_otg, 299015e17335SCharlene Liu .setup_stereo = NULL, 299115e17335SCharlene Liu .set_avmute = dce110_set_avmute, 299241f97c07SHersen Wu .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect, 299341f97c07SHersen Wu .ready_shared_resources = ready_shared_resources, 299441f97c07SHersen Wu .optimize_shared_resources = optimize_shared_resources, 2995631aaa0aSHersen Wu .pplib_apply_display_requirements = pplib_apply_display_requirements, 299687401969SAndrew Jiang .edp_backlight_control = hwss_edp_backlight_control, 299787401969SAndrew Jiang .edp_power_control = hwss_edp_power_control, 2998904623eeSYongqiang Sun .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready, 299933fd17d9SEric Yang .set_cursor_position = dce110_set_cursor_position, 300033fd17d9SEric Yang .set_cursor_attribute = dce110_set_cursor_attribute 30014562236bSHarry Wentland }; 30024562236bSHarry Wentland 3003c13b408bSDave Airlie void dce110_hw_sequencer_construct(struct dc *dc) 30044562236bSHarry Wentland { 30054562236bSHarry Wentland dc->hwss = dce110_funcs; 30064562236bSHarry Wentland } 30074562236bSHarry Wentland 3008