1f1e2f66cSDaniel Vetter /* 2f1e2f66cSDaniel Vetter * Copyright (c) 2016 Intel Corporation 3f1e2f66cSDaniel Vetter * 4f1e2f66cSDaniel Vetter * Permission to use, copy, modify, distribute, and sell this software and its 5f1e2f66cSDaniel Vetter * documentation for any purpose is hereby granted without fee, provided that 6f1e2f66cSDaniel Vetter * the above copyright notice appear in all copies and that both that copyright 7f1e2f66cSDaniel Vetter * notice and this permission notice appear in supporting documentation, and 8f1e2f66cSDaniel Vetter * that the name of the copyright holders not be used in advertising or 9f1e2f66cSDaniel Vetter * publicity pertaining to distribution of the software without specific, 10f1e2f66cSDaniel Vetter * written prior permission. The copyright holders make no representations 11f1e2f66cSDaniel Vetter * about the suitability of this software for any purpose. It is provided "as 12f1e2f66cSDaniel Vetter * is" without express or implied warranty. 13f1e2f66cSDaniel Vetter * 14f1e2f66cSDaniel Vetter * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15f1e2f66cSDaniel Vetter * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16f1e2f66cSDaniel Vetter * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17f1e2f66cSDaniel Vetter * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18f1e2f66cSDaniel Vetter * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19f1e2f66cSDaniel Vetter * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 20f1e2f66cSDaniel Vetter * OF THIS SOFTWARE. 21f1e2f66cSDaniel Vetter */ 22f1e2f66cSDaniel Vetter 23f1e2f66cSDaniel Vetter #ifndef __DRM_COLOR_MGMT_H__ 24f1e2f66cSDaniel Vetter #define __DRM_COLOR_MGMT_H__ 25f1e2f66cSDaniel Vetter 26f1e2f66cSDaniel Vetter #include <linux/ctype.h> 27f1e2f66cSDaniel Vetter 28f1e2f66cSDaniel Vetter void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, 29f1e2f66cSDaniel Vetter uint degamma_lut_size, 30f1e2f66cSDaniel Vetter bool has_ctm, 31f1e2f66cSDaniel Vetter uint gamma_lut_size); 32f1e2f66cSDaniel Vetter 33f1e2f66cSDaniel Vetter int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, 34f1e2f66cSDaniel Vetter int gamma_size); 35f1e2f66cSDaniel Vetter 36f1e2f66cSDaniel Vetter /* 37f1e2f66cSDaniel Vetter * Extract a degamma/gamma LUT value provided by user and round it to the 38f1e2f66cSDaniel Vetter * precision supported by the hardware. 39f1e2f66cSDaniel Vetter */ 40f1e2f66cSDaniel Vetter static inline uint32_t drm_color_lut_extract(uint32_t user_input, 41f1e2f66cSDaniel Vetter uint32_t bit_precision) 42f1e2f66cSDaniel Vetter { 43f1e2f66cSDaniel Vetter uint32_t val = user_input; 44f1e2f66cSDaniel Vetter uint32_t max = 0xffff >> (16 - bit_precision); 45f1e2f66cSDaniel Vetter 46f1e2f66cSDaniel Vetter /* Round only if we're not using full precision. */ 47f1e2f66cSDaniel Vetter if (bit_precision < 16) { 48f1e2f66cSDaniel Vetter val += 1UL << (16 - bit_precision - 1); 49f1e2f66cSDaniel Vetter val >>= 16 - bit_precision; 50f1e2f66cSDaniel Vetter } 51f1e2f66cSDaniel Vetter 52f1e2f66cSDaniel Vetter return clamp_val(val, 0, max); 53f1e2f66cSDaniel Vetter } 54f1e2f66cSDaniel Vetter 55f1e2f66cSDaniel Vetter 56f1e2f66cSDaniel Vetter #endif 57