1 /* 2 * Copyright 2019 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 #include "dmub_abm.h" 27 #include "dmub_abm_lcd.h" 28 #include "dc.h" 29 #include "core_types.h" 30 31 #define TO_DMUB_ABM(abm)\ 32 container_of(abm, struct dce_abm, base) 33 34 #define ABM_FEATURE_NO_SUPPORT 0 35 #define ABM_LCD_SUPPORT 1 36 37 static unsigned int abm_feature_support(struct abm *abm, unsigned int panel_inst) 38 { 39 struct dc_context *dc = abm->ctx; 40 struct dc_link *edp_links[MAX_NUM_EDP]; 41 int i; 42 int edp_num; 43 unsigned int ret = ABM_FEATURE_NO_SUPPORT; 44 45 dc_get_edp_links(dc->dc, edp_links, &edp_num); 46 47 for (i = 0; i < edp_num; i++) { 48 if (panel_inst == i) 49 break; 50 } 51 52 if (i < edp_num) { 53 ret = ABM_LCD_SUPPORT; 54 } 55 56 return ret; 57 } 58 59 static void dmub_abm_init_ex(struct abm *abm, uint32_t backlight) 60 { 61 dmub_abm_init(abm, backlight); 62 } 63 64 static unsigned int dmub_abm_get_current_backlight_ex(struct abm *abm) 65 { 66 return dmub_abm_get_current_backlight(abm); 67 } 68 69 static unsigned int dmub_abm_get_target_backlight_ex(struct abm *abm) 70 { 71 return dmub_abm_get_target_backlight(abm); 72 } 73 74 static bool dmub_abm_set_level_ex(struct abm *abm, uint32_t level) 75 { 76 bool ret = false; 77 unsigned int feature_support, i; 78 uint8_t panel_mask0 = 0; 79 80 for (i = 0; i < MAX_NUM_EDP; i++) { 81 feature_support = abm_feature_support(abm, i); 82 83 if (feature_support == ABM_LCD_SUPPORT) 84 panel_mask0 |= (0x01 << i); 85 } 86 87 if (panel_mask0) 88 ret = dmub_abm_set_level(abm, level, panel_mask0); 89 90 return ret; 91 } 92 93 static bool dmub_abm_init_config_ex(struct abm *abm, 94 const char *src, 95 unsigned int bytes, 96 unsigned int inst) 97 { 98 unsigned int feature_support; 99 100 feature_support = abm_feature_support(abm, inst); 101 102 if (feature_support == ABM_LCD_SUPPORT) 103 dmub_abm_init_config(abm, src, bytes, inst); 104 105 return true; 106 } 107 108 static bool dmub_abm_set_pause_ex(struct abm *abm, bool pause, unsigned int panel_inst, unsigned int stream_inst) 109 { 110 bool ret = false; 111 unsigned int feature_support; 112 113 feature_support = abm_feature_support(abm, panel_inst); 114 115 if (feature_support == ABM_LCD_SUPPORT) 116 ret = dmub_abm_set_pause(abm, pause, panel_inst, stream_inst); 117 118 return ret; 119 } 120 121 static bool dmub_abm_set_pipe_ex(struct abm *abm, uint32_t otg_inst, uint32_t option, uint32_t panel_inst) 122 { 123 bool ret = false; 124 unsigned int feature_support; 125 126 feature_support = abm_feature_support(abm, panel_inst); 127 128 if (feature_support == ABM_LCD_SUPPORT) 129 ret = dmub_abm_set_pipe(abm, otg_inst, option, panel_inst); 130 131 return ret; 132 } 133 134 static bool dmub_abm_set_event_ex(struct abm *abm, unsigned int full_screen, unsigned int video_mode, 135 unsigned int hdr_mode, unsigned int panel_inst) 136 { 137 bool ret = false; 138 unsigned int feature_support; 139 140 feature_support = abm_feature_support(abm, panel_inst); 141 142 return ret; 143 } 144 145 static bool dmub_abm_set_backlight_level_pwm_ex(struct abm *abm, 146 unsigned int backlight_pwm_u16_16, 147 unsigned int frame_ramp, 148 unsigned int controller_id, 149 unsigned int panel_inst) 150 { 151 bool ret = false; 152 unsigned int feature_support; 153 154 feature_support = abm_feature_support(abm, panel_inst); 155 156 if (feature_support == ABM_LCD_SUPPORT) 157 ret = dmub_abm_set_backlight_level(abm, backlight_pwm_u16_16, frame_ramp, panel_inst); 158 159 return ret; 160 } 161 162 static const struct abm_funcs abm_funcs = { 163 .abm_init = dmub_abm_init_ex, 164 .set_abm_level = dmub_abm_set_level_ex, 165 .get_current_backlight = dmub_abm_get_current_backlight_ex, 166 .get_target_backlight = dmub_abm_get_target_backlight_ex, 167 .init_abm_config = dmub_abm_init_config_ex, 168 .set_abm_pause = dmub_abm_set_pause_ex, 169 .set_pipe_ex = dmub_abm_set_pipe_ex, 170 .set_abm_event = dmub_abm_set_event_ex, 171 .set_backlight_level_pwm = dmub_abm_set_backlight_level_pwm_ex, 172 }; 173 174 static void dmub_abm_construct( 175 struct dce_abm *abm_dce, 176 struct dc_context *ctx, 177 const struct dce_abm_registers *regs, 178 const struct dce_abm_shift *abm_shift, 179 const struct dce_abm_mask *abm_mask) 180 { 181 struct abm *base = &abm_dce->base; 182 183 base->ctx = ctx; 184 base->funcs = &abm_funcs; 185 base->dmcu_is_running = false; 186 187 abm_dce->regs = regs; 188 abm_dce->abm_shift = abm_shift; 189 abm_dce->abm_mask = abm_mask; 190 } 191 192 struct abm *dmub_abm_create( 193 struct dc_context *ctx, 194 const struct dce_abm_registers *regs, 195 const struct dce_abm_shift *abm_shift, 196 const struct dce_abm_mask *abm_mask) 197 { 198 if (ctx->dc->caps.dmcub_support) { 199 struct dce_abm *abm_dce = kzalloc(sizeof(*abm_dce), GFP_KERNEL); 200 201 if (abm_dce == NULL) { 202 BREAK_TO_DEBUGGER(); 203 return NULL; 204 } 205 206 dmub_abm_construct(abm_dce, ctx, regs, abm_shift, abm_mask); 207 208 return &abm_dce->base; 209 } 210 return NULL; 211 } 212 213 void dmub_abm_destroy(struct abm **abm) 214 { 215 struct dce_abm *abm_dce = TO_DMUB_ABM(*abm); 216 217 kfree(abm_dce); 218 *abm = NULL; 219 } 220