Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2020 Mauro Rossi <issor.oruam@gmail.com>
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #include "dm_services.h"
0027 
0028 /* include DCE6 register header files */
0029 #include "dce/dce_6_0_d.h"
0030 #include "dce/dce_6_0_sh_mask.h"
0031 
0032 #include "dc_types.h"
0033 
0034 #include "include/grph_object_id.h"
0035 #include "include/logger_interface.h"
0036 #include "../dce110/dce110_timing_generator.h"
0037 #include "dce60_timing_generator.h"
0038 
0039 #include "timing_generator.h"
0040 
0041 enum black_color_format {
0042     BLACK_COLOR_FORMAT_RGB_FULLRANGE = 0,   /* used as index in array */
0043     BLACK_COLOR_FORMAT_RGB_LIMITED,
0044     BLACK_COLOR_FORMAT_YUV_TV,
0045     BLACK_COLOR_FORMAT_YUV_CV,
0046     BLACK_COLOR_FORMAT_YUV_SUPER_AA,
0047 
0048     BLACK_COLOR_FORMAT_COUNT
0049 };
0050 
0051 static const struct dce110_timing_generator_offsets reg_offsets[] = {
0052 {
0053     .crtc = (mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL - mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL),
0054     .dcp = (mmDCP0_GRPH_CONTROL - mmDCP0_GRPH_CONTROL),
0055 },
0056 {
0057     .crtc = (mmCRTC1_DCFE_MEM_LIGHT_SLEEP_CNTL - mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL),
0058     .dcp = (mmDCP1_GRPH_CONTROL - mmDCP0_GRPH_CONTROL),
0059 },
0060 {
0061     .crtc = (mmCRTC2_DCFE_MEM_LIGHT_SLEEP_CNTL - mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL),
0062     .dcp = (mmDCP2_GRPH_CONTROL - mmDCP0_GRPH_CONTROL),
0063 },
0064 {
0065     .crtc = (mmCRTC3_DCFE_MEM_LIGHT_SLEEP_CNTL - mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL),
0066     .dcp = (mmDCP3_GRPH_CONTROL - mmDCP0_GRPH_CONTROL),
0067 },
0068 {
0069     .crtc = (mmCRTC4_DCFE_MEM_LIGHT_SLEEP_CNTL - mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL),
0070     .dcp = (mmDCP4_GRPH_CONTROL - mmDCP0_GRPH_CONTROL),
0071 },
0072 {
0073     .crtc = (mmCRTC5_DCFE_MEM_LIGHT_SLEEP_CNTL - mmCRTC0_DCFE_MEM_LIGHT_SLEEP_CNTL),
0074     .dcp = (mmDCP5_GRPH_CONTROL - mmDCP0_GRPH_CONTROL),
0075 }
0076 };
0077 
0078 #define NUMBER_OF_FRAME_TO_WAIT_ON_TRIGGERED_RESET 10
0079 
0080 #define MAX_H_TOTAL (CRTC_H_TOTAL__CRTC_H_TOTAL_MASK + 1)
0081 #define MAX_V_TOTAL (CRTC_V_TOTAL__CRTC_V_TOTAL_MASKhw + 1)
0082 
0083 #define CRTC_REG(reg) (reg + tg110->offsets.crtc)
0084 #define DCP_REG(reg) (reg + tg110->offsets.dcp)
0085 #define DMIF_REG(reg) (reg + tg110->offsets.dmif)
0086 
0087 static void program_pix_dur(struct timing_generator *tg, uint32_t pix_clk_100hz)
0088 {
0089     uint64_t pix_dur;
0090     uint32_t addr = mmDMIF_PG0_DPG_PIPE_ARBITRATION_CONTROL1
0091                     + DCE110TG_FROM_TG(tg)->offsets.dmif;
0092     uint32_t value = dm_read_reg(tg->ctx, addr);
0093 
0094     if (pix_clk_100hz == 0)
0095         return;
0096 
0097     pix_dur = div_u64(10000000000ull, pix_clk_100hz);
0098 
0099     set_reg_field_value(
0100         value,
0101         pix_dur,
0102         DPG_PIPE_ARBITRATION_CONTROL1,
0103         PIXEL_DURATION);
0104 
0105     dm_write_reg(tg->ctx, addr, value);
0106 }
0107 
0108 static void program_timing(struct timing_generator *tg,
0109     const struct dc_crtc_timing *timing,
0110     int vready_offset,
0111     int vstartup_start,
0112     int vupdate_offset,
0113     int vupdate_width,
0114     const enum signal_type signal,
0115     bool use_vbios)
0116 {
0117     if (!use_vbios)
0118         program_pix_dur(tg, timing->pix_clk_100hz);
0119 
0120     dce110_tg_program_timing(tg, timing, 0, 0, 0, 0, 0, use_vbios);
0121 }
0122 
0123 static void dce60_timing_generator_enable_advanced_request(
0124     struct timing_generator *tg,
0125     bool enable,
0126     const struct dc_crtc_timing *timing)
0127 {
0128     struct dce110_timing_generator *tg110 = DCE110TG_FROM_TG(tg);
0129     uint32_t addr = CRTC_REG(mmCRTC_START_LINE_CONTROL);
0130     uint32_t value = dm_read_reg(tg->ctx, addr);
0131     /* DCE6 has CRTC_PREFETCH_EN bit in CRTC_CONTROL register */
0132     uint32_t addr2 = CRTC_REG(mmCRTC_CONTROL);
0133     uint32_t value2 = dm_read_reg(tg->ctx, addr2);
0134 
0135     /* DCE6 does not support CRTC_LEGACY_REQUESTOR_EN bit
0136        so here is not possible to set bit based on enable argument */
0137 
0138     if ((timing->v_sync_width + timing->v_front_porch) <= 3) {
0139         set_reg_field_value(
0140             value,
0141             3,
0142             CRTC_START_LINE_CONTROL,
0143             CRTC_ADVANCED_START_LINE_POSITION);
0144         set_reg_field_value(
0145             value2,
0146             0,
0147             CRTC_CONTROL,
0148             CRTC_PREFETCH_EN);
0149     } else {
0150         set_reg_field_value(
0151             value,
0152             4,
0153             CRTC_START_LINE_CONTROL,
0154             CRTC_ADVANCED_START_LINE_POSITION);
0155         set_reg_field_value(
0156             value2,
0157             1,
0158             CRTC_CONTROL,
0159             CRTC_PREFETCH_EN);
0160     }
0161 
0162     set_reg_field_value(
0163         value,
0164         1,
0165         CRTC_START_LINE_CONTROL,
0166         CRTC_PROGRESSIVE_START_LINE_EARLY);
0167 
0168     set_reg_field_value(
0169         value,
0170         1,
0171         CRTC_START_LINE_CONTROL,
0172         CRTC_INTERLACE_START_LINE_EARLY);
0173 
0174     dm_write_reg(tg->ctx, addr, value);
0175     dm_write_reg(tg->ctx, addr2, value2);
0176 }
0177 
0178 static bool dce60_is_tg_enabled(struct timing_generator *tg)
0179 {
0180     uint32_t addr = 0;
0181     uint32_t value = 0;
0182     uint32_t field = 0;
0183     struct dce110_timing_generator *tg110 = DCE110TG_FROM_TG(tg);
0184 
0185     addr = CRTC_REG(mmCRTC_CONTROL);
0186     value = dm_read_reg(tg->ctx, addr);
0187     field = get_reg_field_value(value, CRTC_CONTROL,
0188                     CRTC_CURRENT_MASTER_EN_STATE);
0189     return field == 1;
0190 }
0191 
0192 static bool dce60_configure_crc(struct timing_generator *tg,
0193                 const struct crc_params *params)
0194 {
0195     /* Cannot configure crc on a CRTC that is disabled */
0196     if (!dce60_is_tg_enabled(tg))
0197         return false;
0198 
0199     /* DCE6 has no CRTC_CRC_CNTL register, nothing to do */
0200 
0201     return true;
0202 }
0203 
0204 static const struct timing_generator_funcs dce60_tg_funcs = {
0205         .validate_timing = dce110_tg_validate_timing,
0206         .program_timing = program_timing,
0207         .enable_crtc = dce110_timing_generator_enable_crtc,
0208         .disable_crtc = dce110_timing_generator_disable_crtc,
0209         .is_counter_moving = dce110_timing_generator_is_counter_moving,
0210         .get_position = dce110_timing_generator_get_position,
0211         .get_frame_count = dce110_timing_generator_get_vblank_counter,
0212         .get_scanoutpos = dce110_timing_generator_get_crtc_scanoutpos,
0213         .set_early_control = dce110_timing_generator_set_early_control,
0214         .wait_for_state = dce110_tg_wait_for_state,
0215         .set_blank = dce110_tg_set_blank,
0216         .is_blanked = dce110_tg_is_blanked,
0217         .set_colors = dce110_tg_set_colors,
0218         .set_overscan_blank_color =
0219                 dce110_timing_generator_set_overscan_color_black,
0220         .set_blank_color = dce110_timing_generator_program_blank_color,
0221         .disable_vga = dce110_timing_generator_disable_vga,
0222         .did_triggered_reset_occur =
0223                 dce110_timing_generator_did_triggered_reset_occur,
0224         .setup_global_swap_lock =
0225                 dce110_timing_generator_setup_global_swap_lock,
0226         .enable_reset_trigger = dce110_timing_generator_enable_reset_trigger,
0227         .disable_reset_trigger = dce110_timing_generator_disable_reset_trigger,
0228         .tear_down_global_swap_lock =
0229                 dce110_timing_generator_tear_down_global_swap_lock,
0230         .set_drr = dce110_timing_generator_set_drr,
0231         .set_static_screen_control =
0232             dce110_timing_generator_set_static_screen_control,
0233         .set_test_pattern = dce110_timing_generator_set_test_pattern,
0234         .arm_vert_intr = dce110_arm_vert_intr,
0235 
0236         /* DCE6.0 overrides */
0237         .enable_advanced_request =
0238                 dce60_timing_generator_enable_advanced_request,
0239         .configure_crc = dce60_configure_crc,
0240         .get_crc = dce110_get_crc,
0241 };
0242 
0243 void dce60_timing_generator_construct(
0244     struct dce110_timing_generator *tg110,
0245     struct dc_context *ctx,
0246     uint32_t instance,
0247     const struct dce110_timing_generator_offsets *offsets)
0248 {
0249     tg110->controller_id = CONTROLLER_ID_D0 + instance;
0250     tg110->base.inst = instance;
0251     tg110->offsets = *offsets;
0252     tg110->derived_offsets = reg_offsets[instance];
0253 
0254     tg110->base.funcs = &dce60_tg_funcs;
0255 
0256     tg110->base.ctx = ctx;
0257     tg110->base.bp = ctx->dc_bios;
0258 
0259     tg110->max_h_total = CRTC_H_TOTAL__CRTC_H_TOTAL_MASK + 1;
0260     tg110->max_v_total = CRTC_V_TOTAL__CRTC_V_TOTAL_MASK + 1;
0261 
0262     tg110->min_h_blank = 56;
0263     tg110->min_h_front_porch = 4;
0264     tg110->min_h_back_porch = 4;
0265 }
0266