Skip to content

Commit 9452977

Browse files
ckborahemersion
authored andcommitted
drm: Add helper to extract lut from struct drm_color_lut32
Add helper to extract lut values in 32-bit precision needed by hardware. Signed-off-by: Alex Hung <alex.hung@amd.com> Signed-off-by: Uma Shankar <uma.shankar@intel.com> Signed-off-by: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com> Reviewed-by: Sebastian Wick <sebastian.wick@redhat.com> Signed-off-by: Simon Ser <contact@emersion.fr> Link: https://patch.msgid.link/20251115000237.3561250-37-alex.hung@amd.com
1 parent 621c45c commit 9452977

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

include/drm/drm_color_mgmt.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ static inline u32 drm_color_lut_extract(u32 user_input, int bit_precision)
5050
(1 << 16) - 1);
5151
}
5252

53+
/**
54+
* drm_color_lut32_extract - clamp and round LUT entries
55+
* @user_input: input value
56+
* @bit_precision: number of bits the hw LUT supports
57+
*
58+
* Extract U0.bit_precision from a U0.32 LUT value.
59+
*
60+
*/
61+
static inline u32 drm_color_lut32_extract(u32 user_input, int bit_precision)
62+
{
63+
u64 max = (bit_precision >= 64) ? ~0ULL : (1ULL << bit_precision) - 1;
64+
65+
return DIV_ROUND_CLOSEST_ULL((u64)user_input * max,
66+
(1ULL << 32) - 1);
67+
}
68+
5369
u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 n);
5470

5571
void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,

0 commit comments

Comments
 (0)