1bd831267SQingqing Zhuo /* SPDX-License-Identifier: MIT */
2bd831267SQingqing Zhuo /*
3bd831267SQingqing Zhuo * Copyright 2023 Advanced Micro Devices, Inc.
4bd831267SQingqing Zhuo *
5bd831267SQingqing Zhuo * Permission is hereby granted, free of charge, to any person obtaining a
6bd831267SQingqing Zhuo * copy of this software and associated documentation files (the "Software"),
7bd831267SQingqing Zhuo * to deal in the Software without restriction, including without limitation
8bd831267SQingqing Zhuo * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bd831267SQingqing Zhuo * and/or sell copies of the Software, and to permit persons to whom the
10bd831267SQingqing Zhuo * Software is furnished to do so, subject to the following conditions:
11bd831267SQingqing Zhuo *
12bd831267SQingqing Zhuo * The above copyright notice and this permission notice shall be included in
13bd831267SQingqing Zhuo * all copies or substantial portions of the Software.
14bd831267SQingqing Zhuo *
15bd831267SQingqing Zhuo * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bd831267SQingqing Zhuo * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bd831267SQingqing Zhuo * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18bd831267SQingqing Zhuo * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19bd831267SQingqing Zhuo * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20bd831267SQingqing Zhuo * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21bd831267SQingqing Zhuo * OTHER DEALINGS IN THE SOFTWARE.
22bd831267SQingqing Zhuo *
2378964fcaSStylon Wang * Authors: AMD
2478964fcaSStylon Wang *
25bd831267SQingqing Zhuo */
26bd831267SQingqing Zhuo
27bd831267SQingqing Zhuo #include "core_types.h"
2888867807SRevalla Hari Krishna #include "dcn35/dcn35_dpp.h"
29bd831267SQingqing Zhuo #include "reg_helper.h"
30bd831267SQingqing Zhuo
31bd831267SQingqing Zhuo #define REG(reg) dpp->tf_regs->reg
32bd831267SQingqing Zhuo
33bd831267SQingqing Zhuo #define CTX dpp->base.ctx
34bd831267SQingqing Zhuo
35bd831267SQingqing Zhuo #undef FN
36bd831267SQingqing Zhuo #define FN(reg_name, field_name) \
37bd831267SQingqing Zhuo ((const struct dcn35_dpp_shift *)(dpp->tf_shift))->field_name, \
38bd831267SQingqing Zhuo ((const struct dcn35_dpp_mask *)(dpp->tf_mask))->field_name
39bd831267SQingqing Zhuo
dpp35_dppclk_control(struct dpp * dpp_base,bool dppclk_div,bool enable)40c9c70395SDaniel Miess void dpp35_dppclk_control(
41c9c70395SDaniel Miess struct dpp *dpp_base,
42c9c70395SDaniel Miess bool dppclk_div,
43c9c70395SDaniel Miess bool enable)
44c9c70395SDaniel Miess {
45c9c70395SDaniel Miess struct dcn20_dpp *dpp = TO_DCN20_DPP(dpp_base);
46c9c70395SDaniel Miess
47c9c70395SDaniel Miess if (enable) {
48c9c70395SDaniel Miess if (dpp->tf_mask->DPPCLK_RATE_CONTROL)
49c9c70395SDaniel Miess REG_UPDATE_2(DPP_CONTROL,
50c9c70395SDaniel Miess DPPCLK_RATE_CONTROL, dppclk_div,
51c9c70395SDaniel Miess DPP_CLOCK_ENABLE, 1);
52c9c70395SDaniel Miess else
539bdcf2a5SYihan Zhu if (dpp->dispclk_r_gate_disable)
549bdcf2a5SYihan Zhu REG_UPDATE_2(DPP_CONTROL,
559bdcf2a5SYihan Zhu DPP_CLOCK_ENABLE, 1,
569bdcf2a5SYihan Zhu DISPCLK_R_GATE_DISABLE, 1);
579bdcf2a5SYihan Zhu else
58a6f59c04SCharlene Liu REG_UPDATE(DPP_CONTROL,
59a6f59c04SCharlene Liu DPP_CLOCK_ENABLE, 1);
60c9c70395SDaniel Miess } else
619bdcf2a5SYihan Zhu if (dpp->dispclk_r_gate_disable)
629bdcf2a5SYihan Zhu REG_UPDATE_2(DPP_CONTROL,
639bdcf2a5SYihan Zhu DPP_CLOCK_ENABLE, 0,
649bdcf2a5SYihan Zhu DISPCLK_R_GATE_DISABLE, 0);
659bdcf2a5SYihan Zhu else
66a6f59c04SCharlene Liu REG_UPDATE(DPP_CONTROL,
67a6f59c04SCharlene Liu DPP_CLOCK_ENABLE, 0);
68c9c70395SDaniel Miess }
69c9c70395SDaniel Miess
dpp35_program_bias_and_scale_fcnv(struct dpp * dpp_base,struct dc_bias_and_scale * params)70c83ecc0bSRelja Vojvodic void dpp35_program_bias_and_scale_fcnv(
71c83ecc0bSRelja Vojvodic struct dpp *dpp_base,
72c83ecc0bSRelja Vojvodic struct dc_bias_and_scale *params)
73c83ecc0bSRelja Vojvodic {
74c83ecc0bSRelja Vojvodic struct dcn20_dpp *dpp = TO_DCN20_DPP(dpp_base);
75c83ecc0bSRelja Vojvodic
76c83ecc0bSRelja Vojvodic if (!params->bias_and_scale_valid) {
77c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_BIAS_R, 0, FCNV_FP_BIAS_R, 0);
78c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_BIAS_G, 0, FCNV_FP_BIAS_G, 0);
79c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_BIAS_B, 0, FCNV_FP_BIAS_B, 0);
80c83ecc0bSRelja Vojvodic
81c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_SCALE_R, 0, FCNV_FP_SCALE_R, 0x1F000);
82c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_SCALE_G, 0, FCNV_FP_SCALE_G, 0x1F000);
83c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_SCALE_B, 0, FCNV_FP_SCALE_B, 0x1F000);
84c83ecc0bSRelja Vojvodic } else {
85c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_BIAS_R, 0, FCNV_FP_BIAS_R, params->bias_red);
86c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_BIAS_G, 0, FCNV_FP_BIAS_G, params->bias_green);
87c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_BIAS_B, 0, FCNV_FP_BIAS_B, params->bias_blue);
88c83ecc0bSRelja Vojvodic
89c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_SCALE_R, 0, FCNV_FP_SCALE_R, params->scale_red);
90c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_SCALE_G, 0, FCNV_FP_SCALE_G, params->scale_green);
91c83ecc0bSRelja Vojvodic REG_SET(FCNV_FP_SCALE_B, 0, FCNV_FP_SCALE_B, params->scale_blue);
92c83ecc0bSRelja Vojvodic }
93c83ecc0bSRelja Vojvodic }
94c83ecc0bSRelja Vojvodic
95c9c70395SDaniel Miess static struct dpp_funcs dcn35_dpp_funcs = {
96c9c70395SDaniel Miess .dpp_program_gamcor_lut = dpp3_program_gamcor_lut,
97c9c70395SDaniel Miess .dpp_read_state = dpp30_read_state,
98c9c70395SDaniel Miess .dpp_reset = dpp_reset,
99c9c70395SDaniel Miess .dpp_set_scaler = dpp1_dscl_set_scaler_manual_scale,
100c9c70395SDaniel Miess .dpp_get_optimal_number_of_taps = dpp3_get_optimal_number_of_taps,
101c9c70395SDaniel Miess .dpp_set_gamut_remap = dpp3_cm_set_gamut_remap,
102c9c70395SDaniel Miess .dpp_set_csc_adjustment = NULL,
103c9c70395SDaniel Miess .dpp_set_csc_default = NULL,
104c9c70395SDaniel Miess .dpp_program_regamma_pwl = NULL,
105c9c70395SDaniel Miess .dpp_set_pre_degam = dpp3_set_pre_degam,
106c9c70395SDaniel Miess .dpp_program_input_lut = NULL,
107c9c70395SDaniel Miess .dpp_full_bypass = dpp1_full_bypass,
108c9c70395SDaniel Miess .dpp_setup = dpp3_cnv_setup,
109c9c70395SDaniel Miess .dpp_program_degamma_pwl = NULL,
110c9c70395SDaniel Miess .dpp_program_cm_dealpha = dpp3_program_cm_dealpha,
111c9c70395SDaniel Miess .dpp_program_cm_bias = dpp3_program_cm_bias,
112c9c70395SDaniel Miess
113c9c70395SDaniel Miess .dpp_program_blnd_lut = NULL, // BLNDGAM is removed completely in DCN3.2 DPP
114c9c70395SDaniel Miess .dpp_program_shaper_lut = NULL, // CM SHAPER block is removed in DCN3.2 DPP, (it is in MPCC, programmable before or after BLND)
115c9c70395SDaniel Miess .dpp_program_3dlut = NULL, // CM 3DLUT block is removed in DCN3.2 DPP, (it is in MPCC, programmable before or after BLND)
116c9c70395SDaniel Miess
117c83ecc0bSRelja Vojvodic .dpp_program_bias_and_scale = dpp35_program_bias_and_scale_fcnv,
118c9c70395SDaniel Miess .dpp_cnv_set_alpha_keyer = dpp2_cnv_set_alpha_keyer,
119c9c70395SDaniel Miess .set_cursor_attributes = dpp3_set_cursor_attributes,
120c9c70395SDaniel Miess .set_cursor_position = dpp1_set_cursor_position,
121c9c70395SDaniel Miess .set_optional_cursor_attributes = dpp1_cnv_set_optional_cursor_attributes,
122c9c70395SDaniel Miess .dpp_dppclk_control = dpp35_dppclk_control,
123c9c70395SDaniel Miess .dpp_set_hdr_multiplier = dpp3_set_hdr_multiplier,
124c9c70395SDaniel Miess .dpp_get_gamut_remap = dpp3_cm_get_gamut_remap,
125c9c70395SDaniel Miess };
126c9c70395SDaniel Miess
127c9c70395SDaniel Miess
dpp35_construct(struct dcn3_dpp * dpp,struct dc_context * ctx,uint32_t inst,const struct dcn3_dpp_registers * tf_regs,const struct dcn35_dpp_shift * tf_shift,const struct dcn35_dpp_mask * tf_mask)128c9c70395SDaniel Miess bool dpp35_construct(
129c9c70395SDaniel Miess struct dcn3_dpp *dpp, struct dc_context *ctx,
130bd831267SQingqing Zhuo uint32_t inst, const struct dcn3_dpp_registers *tf_regs,
131bd831267SQingqing Zhuo const struct dcn35_dpp_shift *tf_shift,
132bd831267SQingqing Zhuo const struct dcn35_dpp_mask *tf_mask)
133bd831267SQingqing Zhuo {
134c9c70395SDaniel Miess bool ret = dpp32_construct(dpp, ctx, inst, tf_regs,
135bd831267SQingqing Zhuo (const struct dcn3_dpp_shift *)(tf_shift),
136bd831267SQingqing Zhuo (const struct dcn3_dpp_mask *)(tf_mask));
137c9c70395SDaniel Miess
138c9c70395SDaniel Miess dpp->base.funcs = &dcn35_dpp_funcs;
1399bdcf2a5SYihan Zhu
1409bdcf2a5SYihan Zhu // w/a for cursor memory stuck in LS by programming DISPCLK_R_GATE_DISABLE, limit w/a to some ASIC revs
141*b4db7971SOvidiu Bunea if (dpp->base.ctx->asic_id.hw_internal_rev < 0x40)
1429bdcf2a5SYihan Zhu dpp->dispclk_r_gate_disable = true;
143c9c70395SDaniel Miess return ret;
144bd831267SQingqing Zhuo }
145bd831267SQingqing Zhuo
dpp35_set_fgcg(struct dcn3_dpp * dpp,bool enable)146bd831267SQingqing Zhuo void dpp35_set_fgcg(struct dcn3_dpp *dpp, bool enable)
147bd831267SQingqing Zhuo {
148bd831267SQingqing Zhuo REG_UPDATE(DPP_CONTROL, DPP_FGCG_REP_DIS, !enable);
149bd831267SQingqing Zhuo }
150