]> Gentwo Git Trees - linux/.git/commitdiff
drm: Add helper to extract lut from struct drm_color_lut32
authorChaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Sat, 15 Nov 2025 00:02:01 +0000 (17:02 -0700)
committerSimon Ser <contact@emersion.fr>
Wed, 26 Nov 2025 22:03:35 +0000 (23:03 +0100)
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
include/drm/drm_color_mgmt.h

index 527582c20885c4cc2b1675ee8903e460c8992e08..5140691f476a9a8b42a22c873c29252c36778406 100644 (file)
@@ -50,6 +50,22 @@ static inline u32 drm_color_lut_extract(u32 user_input, int bit_precision)
                                         (1 << 16) - 1);
 }
 
+/**
+ * drm_color_lut32_extract - clamp and round LUT entries
+ * @user_input: input value
+ * @bit_precision: number of bits the hw LUT supports
+ *
+ * Extract U0.bit_precision from a U0.32 LUT value.
+ *
+ */
+static inline u32 drm_color_lut32_extract(u32 user_input, int bit_precision)
+{
+       u64 max = (bit_precision >= 64) ? ~0ULL : (1ULL << bit_precision) - 1;
+
+       return DIV_ROUND_CLOSEST_ULL((u64)user_input * max,
+                                    (1ULL << 32) - 1);
+}
+
 u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 n);
 
 void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,