Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5010093ybf; Wed, 4 Mar 2020 15:27:11 -0800 (PST) X-Google-Smtp-Source: ADFU+vs/GQUvzsUE3QEDYK5jgNqjIeG5JtFiVfGjsfZwHO2V/Ub47hqjBqSgYWASiutjqzZV+7vH X-Received: by 2002:a05:6830:1e58:: with SMTP id e24mr4393503otj.267.1583364430780; Wed, 04 Mar 2020 15:27:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583364430; cv=none; d=google.com; s=arc-20160816; b=wgW1k6XB/VBnLFI7/JuGv4CiRzxjnV9+j8S+ExebsPAI4CgZ0HZRrVTiDhXrTr6Qj3 +UojEuelCVSf/U7ZiF7jzhi4f/4LsMuRDAN/3/StjgLPebzP+QXrwx1BYoo8XYB7SpcM lt4aZfLsUAaDm7eOQjxWdVZzaOFzykjtKllYgjEaNs4mtROLCx1ZEiwfePkR4O7NJrFB U+75++TXjrLXH1X5uQEoeAbTLJPjrulffeotL5D7j83G9hA0rvyToyxXb1WkCIKa0kiS l8byGXb8h6UAv6srNtREJNcapzIp6pAeM6anoktMr8+8oEuyYY6I+qdL66c2Qlx9LDWZ MEVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lgNiIfQoRLoAMNmkiAh87rf6V60DGktXqCmGh9gcS0k=; b=V2gqwyOwh9k8ZW+3xVK/FCxmPvIFZ/bbXO3uT7Cb8J9FtvNEKsLn65cj/poZdI6Q3M enmR17lGzoeQZxG63fAzgM8iVZeTJG7Fl89j6yFl8z5bfekY9bYRU/MwkDbWJbmaUf1R tELOk0BEEzKPWybYXiLJjSJ6HT9MHv28VxyYtDNup4uG7j2TWOX9mTBA//Z2O+6voLQ4 Ne8puOSsGLgGqi+KS2a33OrWFEYvBoWPJh9Pdi89coqSfIx11QHdO5flwOK/JPxTegwb yms/8FklTAE67KWBGpN7H74OUrG9PfaxB5U3DIhN5lcuAXW95YcrysXRB43sE3ohHbbC WN8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=siol.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a25si1942036oid.67.2020.03.04.15.26.59; Wed, 04 Mar 2020 15:27:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=siol.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388627AbgCDXZn (ORCPT + 99 others); Wed, 4 Mar 2020 18:25:43 -0500 Received: from mailoutvs63.siol.net ([185.57.226.254]:47934 "EHLO mail.siol.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388598AbgCDXZm (ORCPT ); Wed, 4 Mar 2020 18:25:42 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.siol.net (Postfix) with ESMTP id 21E205235DD; Thu, 5 Mar 2020 00:25:40 +0100 (CET) X-Virus-Scanned: amavisd-new at psrvmta11.zcs-production.pri Received: from mail.siol.net ([127.0.0.1]) by localhost (psrvmta11.zcs-production.pri [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ms9EoxqeVMCd; Thu, 5 Mar 2020 00:25:39 +0100 (CET) Received: from mail.siol.net (localhost [127.0.0.1]) by mail.siol.net (Postfix) with ESMTPS id A8D4952273A; Thu, 5 Mar 2020 00:25:39 +0100 (CET) Received: from localhost.localdomain (cpe-194-152-20-232.static.triera.net [194.152.20.232]) (Authenticated sender: 031275009) by mail.siol.net (Postfix) with ESMTPSA id 2FB6A5235DD; Thu, 5 Mar 2020 00:25:37 +0100 (CET) From: Jernej Skrabec To: a.hajda@samsung.com, narmstrong@baylibre.com Cc: Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@siol.net, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] drm/bridge: dw-hdmi: Add support for RGB limited range Date: Thu, 5 Mar 2020 00:25:11 +0100 Message-Id: <20200304232512.51616-4-jernej.skrabec@siol.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200304232512.51616-1-jernej.skrabec@siol.net> References: <20200304232512.51616-1-jernej.skrabec@siol.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CEA 861 standard requestis that RGB quantization range is "limited" for CEA modes. Support that by adding CSC matrix which downscales values. This allows proper color reproduction on TV and PC monitor at the same time. In future, override property can be added, like "Broadcast RGB" in i915 driver. Signed-off-by: Jernej Skrabec --- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 63 +++++++++++++++++------ 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/= bridge/synopsys/dw-hdmi.c index de2c7ec887c8..c8a02e5b5e1b 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -92,6 +92,12 @@ static const u16 csc_coeff_rgb_in_eitu709[3][4] =3D { { 0x6756, 0x78ab, 0x2000, 0x0200 } }; =20 +static const u16 csc_coeff_rgb_full_to_rgb_limited[3][4] =3D { + { 0x1b7c, 0x0000, 0x0000, 0x0020 }, + { 0x0000, 0x1b7c, 0x0000, 0x0020 }, + { 0x0000, 0x0000, 0x1b7c, 0x0020 } +}; + struct hdmi_vmode { bool mdataenablepolarity; =20 @@ -109,6 +115,7 @@ struct hdmi_data_info { unsigned int pix_repet_factor; unsigned int hdcp_enable; struct hdmi_vmode video_mode; + bool rgb_limited_range; }; =20 struct dw_hdmi_i2c { @@ -956,7 +963,11 @@ static void hdmi_video_sample(struct dw_hdmi *hdmi) =20 static int is_color_space_conversion(struct dw_hdmi *hdmi) { - return hdmi->hdmi_data.enc_in_bus_format !=3D hdmi->hdmi_data.enc_out_b= us_format; + return (hdmi->hdmi_data.enc_in_bus_format !=3D + hdmi->hdmi_data.enc_out_bus_format) || + (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format) && + hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) && + hdmi->hdmi_data.rgb_limited_range); } =20 static int is_color_space_decimation(struct dw_hdmi *hdmi) @@ -986,25 +997,27 @@ static int is_color_space_interpolation(struct dw_h= dmi *hdmi) static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) { const u16 (*csc_coeff)[3][4] =3D &csc_coeff_default; + bool is_input_rgb, is_output_rgb; unsigned i; u32 csc_scale =3D 1; =20 - if (is_color_space_conversion(hdmi)) { - if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { - if (hdmi->hdmi_data.enc_out_encoding =3D=3D - V4L2_YCBCR_ENC_601) - csc_coeff =3D &csc_coeff_rgb_out_eitu601; - else - csc_coeff =3D &csc_coeff_rgb_out_eitu709; - } else if (hdmi_bus_fmt_is_rgb( - hdmi->hdmi_data.enc_in_bus_format)) { - if (hdmi->hdmi_data.enc_out_encoding =3D=3D - V4L2_YCBCR_ENC_601) - csc_coeff =3D &csc_coeff_rgb_in_eitu601; - else - csc_coeff =3D &csc_coeff_rgb_in_eitu709; - csc_scale =3D 0; - } + is_input_rgb =3D hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format)= ; + is_output_rgb =3D hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_forma= t); + + if (!is_input_rgb && is_output_rgb) { + if (hdmi->hdmi_data.enc_out_encoding =3D=3D V4L2_YCBCR_ENC_601) + csc_coeff =3D &csc_coeff_rgb_out_eitu601; + else + csc_coeff =3D &csc_coeff_rgb_out_eitu709; + } else if (is_input_rgb && !is_output_rgb) { + if (hdmi->hdmi_data.enc_out_encoding =3D=3D V4L2_YCBCR_ENC_601) + csc_coeff =3D &csc_coeff_rgb_in_eitu601; + else + csc_coeff =3D &csc_coeff_rgb_in_eitu709; + csc_scale =3D 0; + } else if (is_input_rgb && is_output_rgb && + hdmi->hdmi_data.rgb_limited_range) { + csc_coeff =3D &csc_coeff_rgb_full_to_rgb_limited; } =20 /* The CSC registers are sequential, alternating MSB then LSB */ @@ -1614,6 +1627,18 @@ static void hdmi_config_AVI(struct dw_hdmi *hdmi, = struct drm_display_mode *mode) drm_hdmi_avi_infoframe_from_display_mode(&frame, &hdmi->connector, mode); =20 + if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { + drm_hdmi_avi_infoframe_quant_range(&frame, &hdmi->connector, + mode, + hdmi->hdmi_data.rgb_limited_range ? + HDMI_QUANTIZATION_RANGE_LIMITED : + HDMI_QUANTIZATION_RANGE_FULL); + } else { + frame.quantization_range =3D HDMI_QUANTIZATION_RANGE_DEFAULT; + frame.ycc_quantization_range =3D + HDMI_YCC_QUANTIZATION_RANGE_LIMITED; + } + if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) frame.colorspace =3D HDMI_COLORSPACE_YUV444; else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) @@ -2099,6 +2124,10 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi, str= uct drm_display_mode *mode) /* TOFIX: Default to RGB888 output format */ hdmi->hdmi_data.enc_out_bus_format =3D MEDIA_BUS_FMT_RGB888_1X24; =20 + hdmi->hdmi_data.rgb_limited_range =3D hdmi->sink_is_hdmi && + drm_default_rgb_quant_range(mode) =3D=3D + HDMI_QUANTIZATION_RANGE_LIMITED; + hdmi->hdmi_data.pix_repet_factor =3D 0; hdmi->hdmi_data.hdcp_enable =3D 0; hdmi->hdmi_data.video_mode.mdataenablepolarity =3D true; --=20 2.25.1