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

Configure Feed

Select the types of activity you want to include in your feed.

drm/i915/display: Add CASF strength and winsize

Add register definitions for sharpness strength and
filter window size used by CASF. Provide functions to
read and write these fields.

The sharpness strength value is determined by user input,
while the winsize is based on the resolution. The casf_enable
flag should be set if the platform supports sharpness adjustments
and the user API strength is not zero. Once sharpness is
enabled, update the strength bit of the register whenever
the user changes the strength value, as the enable bit and
winsize bit remain constant.

Introduce helper to enable, disable and update strength.
Add relavant strength and winsize in both enable and disable.

v2: Introduce get_config for casf[Ankit]
v3: Replace 0 with FILTER_STRENGTH_MASK[Ankit]
v4: After updating strength add win_sz register
v5: Replace u16 with u32 for total_pixel
v6: Add casf logging
v7: Add helper for enable and disable casf

Signed-off-by: Nemesa Garg <nemesa.garg@intel.com>
Reviewed-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
Link: https://patch.msgid.link/20251028120747.3027332-4-ankit.k.nautiyal@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

authored by

Nemesa Garg and committed by
Jani Nikula
74ad9ec9 72a583c2

+184
+1
drivers/gpu/drm/i915/Makefile
··· 234 234 display/intel_bios.o \ 235 235 display/intel_bo.o \ 236 236 display/intel_bw.o \ 237 + display/intel_casf.o \ 237 238 display/intel_cdclk.o \ 238 239 display/intel_cmtg.o \ 239 240 display/intel_color.o \
+128
drivers/gpu/drm/i915/display/intel_casf.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* Copyright © 2025 Intel Corporation */ 3 + 4 + #include <drm/drm_print.h> 5 + 6 + #include "i915_reg.h" 7 + #include "intel_casf.h" 8 + #include "intel_casf_regs.h" 9 + #include "intel_de.h" 10 + #include "intel_display_regs.h" 11 + #include "intel_display_types.h" 12 + 13 + #define MAX_PIXELS_FOR_3_TAP_FILTER (1920 * 1080) 14 + #define MAX_PIXELS_FOR_5_TAP_FILTER (3840 * 2160) 15 + 16 + /** 17 + * DOC: Content Adaptive Sharpness Filter (CASF) 18 + * 19 + * Starting from LNL the display engine supports an 20 + * adaptive sharpening filter, enhancing the image 21 + * quality. The display hardware utilizes the second 22 + * pipe scaler for implementing CASF. 23 + * If sharpness is being enabled then pipe scaling 24 + * cannot be used. 25 + * This filter operates on a region of pixels based 26 + * on the tap size. Coefficients are used to generate 27 + * an alpha value which blends the sharpened image to 28 + * original image. 29 + */ 30 + 31 + void intel_casf_update_strength(struct intel_crtc_state *crtc_state) 32 + { 33 + struct intel_display *display = to_intel_display(crtc_state); 34 + struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 35 + int win_size; 36 + 37 + intel_de_rmw(display, SHARPNESS_CTL(crtc->pipe), FILTER_STRENGTH_MASK, 38 + FILTER_STRENGTH(crtc_state->hw.casf_params.strength)); 39 + 40 + win_size = intel_de_read(display, SKL_PS_WIN_SZ(crtc->pipe, 1)); 41 + 42 + intel_de_write_fw(display, SKL_PS_WIN_SZ(crtc->pipe, 1), win_size); 43 + } 44 + 45 + static void intel_casf_compute_win_size(struct intel_crtc_state *crtc_state) 46 + { 47 + const struct drm_display_mode *mode = &crtc_state->hw.adjusted_mode; 48 + u32 total_pixels = mode->hdisplay * mode->vdisplay; 49 + 50 + if (total_pixels <= MAX_PIXELS_FOR_3_TAP_FILTER) 51 + crtc_state->hw.casf_params.win_size = SHARPNESS_FILTER_SIZE_3X3; 52 + else if (total_pixels <= MAX_PIXELS_FOR_5_TAP_FILTER) 53 + crtc_state->hw.casf_params.win_size = SHARPNESS_FILTER_SIZE_5X5; 54 + else 55 + crtc_state->hw.casf_params.win_size = SHARPNESS_FILTER_SIZE_7X7; 56 + } 57 + 58 + int intel_casf_compute_config(struct intel_crtc_state *crtc_state) 59 + { 60 + struct intel_display *display = to_intel_display(crtc_state); 61 + 62 + if (!HAS_CASF(display)) 63 + return 0; 64 + 65 + if (crtc_state->uapi.sharpness_strength == 0) { 66 + crtc_state->hw.casf_params.casf_enable = false; 67 + crtc_state->hw.casf_params.strength = 0; 68 + return 0; 69 + } 70 + 71 + crtc_state->hw.casf_params.casf_enable = true; 72 + 73 + /* 74 + * HW takes a value in form (1.0 + strength) in 4.4 fixed format. 75 + * Strength is from 0.0-14.9375 ie from 0-239. 76 + * User can give value from 0-255 but is clamped to 239. 77 + * Ex. User gives 85 which is 5.3125 and adding 1.0 gives 6.3125. 78 + * 6.3125 in 4.4 format is b01100101 which is equal to 101. 79 + * Also 85 + 16 = 101. 80 + */ 81 + crtc_state->hw.casf_params.strength = 82 + min(crtc_state->uapi.sharpness_strength, 0xEF) + 0x10; 83 + 84 + intel_casf_compute_win_size(crtc_state); 85 + 86 + return 0; 87 + } 88 + 89 + void intel_casf_sharpness_get_config(struct intel_crtc_state *crtc_state) 90 + { 91 + struct intel_display *display = to_intel_display(crtc_state); 92 + struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 93 + u32 sharp; 94 + 95 + sharp = intel_de_read(display, SHARPNESS_CTL(crtc->pipe)); 96 + if (sharp & FILTER_EN) { 97 + if (drm_WARN_ON(display->drm, 98 + REG_FIELD_GET(FILTER_STRENGTH_MASK, sharp) < 16)) 99 + crtc_state->hw.casf_params.strength = 0; 100 + else 101 + crtc_state->hw.casf_params.strength = 102 + REG_FIELD_GET(FILTER_STRENGTH_MASK, sharp); 103 + crtc_state->hw.casf_params.casf_enable = true; 104 + crtc_state->hw.casf_params.win_size = 105 + REG_FIELD_GET(FILTER_SIZE_MASK, sharp); 106 + } 107 + } 108 + 109 + void intel_casf_enable(struct intel_crtc_state *crtc_state) 110 + { 111 + struct intel_display *display = to_intel_display(crtc_state); 112 + struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 113 + u32 sharpness_ctl; 114 + 115 + sharpness_ctl = FILTER_EN | FILTER_STRENGTH(crtc_state->hw.casf_params.strength); 116 + 117 + sharpness_ctl |= crtc_state->hw.casf_params.win_size; 118 + 119 + intel_de_write(display, SHARPNESS_CTL(crtc->pipe), sharpness_ctl); 120 + } 121 + 122 + void intel_casf_disable(const struct intel_crtc_state *crtc_state) 123 + { 124 + struct intel_display *display = to_intel_display(crtc_state); 125 + struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 126 + 127 + intel_de_write(display, SHARPNESS_CTL(crtc->pipe), 0); 128 + }
+19
drivers/gpu/drm/i915/display/intel_casf.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2025 Intel Corporation 4 + */ 5 + 6 + #ifndef __INTEL_CASF_H__ 7 + #define __INTEL_CASF_H__ 8 + 9 + #include <linux/types.h> 10 + 11 + struct intel_crtc_state; 12 + 13 + int intel_casf_compute_config(struct intel_crtc_state *crtc_state); 14 + void intel_casf_update_strength(struct intel_crtc_state *new_crtc_state); 15 + void intel_casf_sharpness_get_config(struct intel_crtc_state *crtc_state); 16 + void intel_casf_enable(struct intel_crtc_state *crtc_state); 17 + void intel_casf_disable(const struct intel_crtc_state *crtc_state); 18 + 19 + #endif /* __INTEL_CASF_H__ */
+22
drivers/gpu/drm/i915/display/intel_casf_regs.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2025 Intel Corporation 4 + */ 5 + 6 + #ifndef __INTEL_CASF_REGS_H__ 7 + #define __INTEL_CASF_REGS_H__ 8 + 9 + #include "intel_display_reg_defs.h" 10 + 11 + #define _SHARPNESS_CTL_A 0x682B0 12 + #define _SHARPNESS_CTL_B 0x68AB0 13 + #define SHARPNESS_CTL(pipe) _MMIO_PIPE(pipe, _SHARPNESS_CTL_A, _SHARPNESS_CTL_B) 14 + #define FILTER_EN REG_BIT(31) 15 + #define FILTER_STRENGTH_MASK REG_GENMASK(15, 8) 16 + #define FILTER_STRENGTH(x) REG_FIELD_PREP(FILTER_STRENGTH_MASK, (x)) 17 + #define FILTER_SIZE_MASK REG_GENMASK(1, 0) 18 + #define SHARPNESS_FILTER_SIZE_3X3 REG_FIELD_PREP(FILTER_SIZE_MASK, 0) 19 + #define SHARPNESS_FILTER_SIZE_5X5 REG_FIELD_PREP(FILTER_SIZE_MASK, 1) 20 + #define SHARPNESS_FILTER_SIZE_7X7 REG_FIELD_PREP(FILTER_SIZE_MASK, 2) 21 + 22 + #endif /* __INTEL_CASF_REGS__ */
+5
drivers/gpu/drm/i915/display/intel_crtc_state_dump.c
··· 372 372 373 373 intel_vdsc_state_dump(&p, 0, pipe_config); 374 374 375 + drm_printf(&p, "sharpness strength: %d, sharpness tap size: %d, sharpness enable: %d\n", 376 + pipe_config->hw.casf_params.strength, 377 + pipe_config->hw.casf_params.win_size, 378 + pipe_config->hw.casf_params.casf_enable); 379 + 375 380 dump_planes: 376 381 if (!state) 377 382 return;
+7
drivers/gpu/drm/i915/display/intel_display_types.h
··· 961 961 INTEL_DP_PANEL_REPLAY_DSC_SELECTIVE_UPDATE, 962 962 }; 963 963 964 + struct intel_casf { 965 + u8 strength; 966 + u8 win_size; 967 + bool casf_enable; 968 + }; 969 + 964 970 struct intel_crtc_state { 965 971 /* 966 972 * uapi (drm) state. This is the software state shown to userspace. ··· 1003 997 struct drm_property_blob *degamma_lut, *gamma_lut, *ctm; 1004 998 struct drm_display_mode mode, pipe_mode, adjusted_mode; 1005 999 enum drm_scaling_filter scaling_filter; 1000 + struct intel_casf casf_params; 1006 1001 } hw; 1007 1002 1008 1003 /* actual state of LUTs */
+1
drivers/gpu/drm/i915/display/skl_scaler.c
··· 6 6 #include <drm/drm_print.h> 7 7 8 8 #include "i915_utils.h" 9 + #include "intel_casf_regs.h" 9 10 #include "intel_de.h" 10 11 #include "intel_display_regs.h" 11 12 #include "intel_display_trace.h"
+1
drivers/gpu/drm/xe/Makefile
··· 231 231 i915-display/intel_backlight.o \ 232 232 i915-display/intel_bios.o \ 233 233 i915-display/intel_bw.o \ 234 + i915-display/intel_casf.o \ 234 235 i915-display/intel_cdclk.o \ 235 236 i915-display/intel_cmtg.o \ 236 237 i915-display/intel_color.o \