Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amd/display: Increase precision for backlight curve

[Why]
We are currently losing precision when we convert from
16 bit --> 8 bit --> 16 bit.

[How]
We shouldn't down convert unnecessarily and lose precision.
Keep values at 16 bit and use directly.

Signed-off-by: Anthony Koo <Anthony.Koo@amd.com>
Reviewed-by: Aric Cyr <Aric.Cyr@amd.com>
Acked-by: Leo Li <sunpeng.li@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Anthony Koo and committed by
Alex Deucher
c19bd82f ce72741b

+4 -19
+4 -19
drivers/gpu/drm/amd/display/modules/power/power_helpers.c
··· 165 165 }; 166 166 #pragma pack(pop) 167 167 168 - static uint16_t backlight_8_to_16(unsigned int backlight_8bit) 169 - { 170 - return (uint16_t)(backlight_8bit * 0x101); 171 - } 172 - 173 168 static void fill_backlight_transform_table(struct dmcu_iram_parameters params, 174 169 struct iram_table_v_2 *table) 175 170 { 176 171 unsigned int i; 177 172 unsigned int num_entries = NUM_BL_CURVE_SEGS; 178 - unsigned int query_input_8bit; 179 - unsigned int query_output_8bit; 180 173 unsigned int lut_index; 181 174 182 175 table->backlight_thresholds[0] = 0; ··· 187 194 * format U4.10. 188 195 */ 189 196 for (i = 1; i+1 < num_entries; i++) { 190 - query_input_8bit = DIV_ROUNDUP((i * 256), num_entries); 191 - 192 197 lut_index = (params.backlight_lut_array_size - 1) * i / (num_entries - 1); 193 198 ASSERT(lut_index < params.backlight_lut_array_size); 194 - query_output_8bit = params.backlight_lut_array[lut_index] >> 8; 195 199 196 200 table->backlight_thresholds[i] = 197 - backlight_8_to_16(query_input_8bit); 201 + cpu_to_be16(DIV_ROUNDUP((i * 65536), num_entries)); 198 202 table->backlight_offsets[i] = 199 - backlight_8_to_16(query_output_8bit); 203 + cpu_to_be16(params.backlight_lut_array[lut_index]); 200 204 } 201 205 } 202 206 ··· 202 212 { 203 213 unsigned int i; 204 214 unsigned int num_entries = NUM_BL_CURVE_SEGS; 205 - unsigned int query_input_8bit; 206 - unsigned int query_output_8bit; 207 215 unsigned int lut_index; 208 216 209 217 table->backlight_thresholds[0] = 0; ··· 219 231 * format U4.10. 220 232 */ 221 233 for (i = 1; i+1 < num_entries; i++) { 222 - query_input_8bit = DIV_ROUNDUP((i * 256), num_entries); 223 - 224 234 lut_index = (params.backlight_lut_array_size - 1) * i / (num_entries - 1); 225 235 ASSERT(lut_index < params.backlight_lut_array_size); 226 - query_output_8bit = params.backlight_lut_array[lut_index] >> 8; 227 236 228 237 table->backlight_thresholds[i] = 229 - backlight_8_to_16(query_input_8bit); 238 + cpu_to_be16(DIV_ROUNDUP((i * 65536), num_entries)); 230 239 table->backlight_offsets[i] = 231 - backlight_8_to_16(query_output_8bit); 240 + cpu_to_be16(params.backlight_lut_array[lut_index]); 232 241 } 233 242 } 234 243