]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/gpu/drm/drm_color_mgmt.c
Merge remote-tracking branch 'mkp-scsi/4.11/scsi-fixes' into fixes
[karo-tx-linux.git] / drivers / gpu / drm / drm_color_mgmt.c
index 6543ebde501a7f5c242917d3124512eb3d45cea8..cc23b9a505c0d946ee198b84bb8bc90d03358e85 100644 (file)
@@ -36,7 +36,7 @@
  * "DEGAMMA_LUT”:
  *     Blob property to set the degamma lookup table (LUT) mapping pixel data
  *     from the framebuffer before it is given to the transformation matrix.
- *     The data is interpreted as an array of struct &drm_color_lut elements.
+ *     The data is interpreted as an array of &struct drm_color_lut elements.
  *     Hardware might choose not to use the full precision of the LUT elements
  *     nor use all the elements of the LUT (for example the hardware might
  *     choose to interpolate between LUT[0] and LUT[4]).
@@ -65,7 +65,7 @@
  * “GAMMA_LUT”:
  *     Blob property to set the gamma lookup table (LUT) mapping pixel data
  *     after the transformation matrix to data sent to the connector. The
- *     data is interpreted as an array of struct &drm_color_lut elements.
+ *     data is interpreted as an array of &struct drm_color_lut elements.
  *     Hardware might choose not to use the full precision of the LUT elements
  *     nor use all the elements of the LUT (for example the hardware might
  *     choose to interpolate between LUT[0] and LUT[4]).
  * "GAMMA_LUT" property above.
  */
 
+/**
+ * drm_color_lut_extract - clamp and round LUT entries
+ * @user_input: input value
+ * @bit_precision: number of bits the hw LUT supports
+ *
+ * Extract a degamma/gamma LUT value provided by user (in the form of
+ * &drm_color_lut entries) and round it to the precision supported by the
+ * hardware.
+ */
+uint32_t drm_color_lut_extract(uint32_t user_input, uint32_t bit_precision)
+{
+       uint32_t val = user_input;
+       uint32_t max = 0xffff >> (16 - bit_precision);
+
+       /* Round only if we're not using full precision. */
+       if (bit_precision < 16) {
+               val += 1UL << (16 - bit_precision - 1);
+               val >>= 16 - bit_precision;
+       }
+
+       return clamp_val(val, 0, max);
+}
+EXPORT_SYMBOL(drm_color_lut_extract);
+
 /**
  * drm_crtc_enable_color_mgmt - enable color management properties
  * @crtc: DRM CRTC