Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4299848pxb; Sat, 6 Nov 2021 10:57:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyWQaxT5Y1V4fioh45H13hPnEQaCStXvUDVnyHe0qR5yH3eSMXhmfsOQ8XM+126hXFV8NE X-Received: by 2002:a05:6e02:1b8a:: with SMTP id h10mr46298040ili.219.1636221426981; Sat, 06 Nov 2021 10:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636221426; cv=none; d=google.com; s=arc-20160816; b=yMRlzrbrQgbMSYx3X4S3Rz4yZR5O28ivqu3SefcSQHlwTRJ3tMWgRoTZPmutOE3nX5 TM3FR51mlGdkA7/s0AGh8QxtJQwdEbF5QlphFzW8h5kPnnNGH1xImDpSf3d7O0oPpzyS ikxLJjGa5a8dyDR9ncOyEdHv0BJMul8q0Lwvv6wsvqR4ruToqm3qUPXFi5/0ExMkiblz 6BYcsxPvHUg9gdED79gGvJ2A+Db/YmK49HQTr4NKuz0erenhnRT6AyCGjOsC+hDdBOK0 HyrSoF/5oQ1ycpQKFnNH3kT2+TOxi3vWL431+qXG7at7KG5YvmSl0VZpezTiZARa2kye vj9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=m8wHab6566qURbj642hZQhjoNEVpnY3BwaarHDvq0L0=; b=aEP5wJ46IccIguifHnTifjSJZJdfSOXmufQ355HIO0ArOw19X4RuE4nusuAuMzfAPa 56mc0WrcOxk5rRdtrd7PtdzUsVdy5KNzoicM3iXAaP7FDo5q6XYYEeuDD+HE3ByODjT5 /updXKq4Q8FFYAijkcaDE7nKWx3YHzmzjGZKThH8u4pRb94jepOKtidZLKEc01WD4qDA +7vR6eJ3lWQXrd4h5Tgln/ka/uPyc14v3wDtXumb7XjMyARGJYKWzGWhlYrrYUeoMuqv k+yLi941qPwk6cNNro4dmul3roTHmv6BIYGmU+pcEtLCc0MDCIINTLvhdmEw60hpZnpG nESw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XND+wSBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d41si13533486jaa.115.2021.11.06.10.56.54; Sat, 06 Nov 2021 10:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XND+wSBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233587AbhKFNDf (ORCPT + 99 others); Sat, 6 Nov 2021 09:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbhKFNDe (ORCPT ); Sat, 6 Nov 2021 09:03:34 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DE1C061570 for ; Sat, 6 Nov 2021 06:00:52 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id t30so18070760wra.10 for ; Sat, 06 Nov 2021 06:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m8wHab6566qURbj642hZQhjoNEVpnY3BwaarHDvq0L0=; b=XND+wSBUuPYLMgjewQQ+ZfunYmZNgCh8WWfsCXD0+PsOEDkfOKExouoH06ea4qyP2R FB0MqJKNiVp76AcUeWDBaFrBCmucksujIKNWtlWQ5+zBIpYORG52udyGka7M2ZFGQ76q V0TcnCJwJfirAXNGLwFVEV69RebWVhDKwLPb16UmV4cHYfZyD5rlCkOq6mgP84tWVzDS X1LtVHIqZogdb3d9gwGkK3v1bmpVRt2HQaxrtf9Uqfp6EXssJtqwuhO+gWxqd0KOkYIb YCVFhO33SLioM8xwNMnieu74NedU5n2fWXbBeTBYVWLTmxv/YQ6ZO8EBkmez93iCZFGO 03Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m8wHab6566qURbj642hZQhjoNEVpnY3BwaarHDvq0L0=; b=v6/1I3qTOAheAmKgq9apaFHPJV3oLtdTwxhYFxG0t4pHrwPZeEIQTJIxDR83YXQZXw VwN4OP0pG0XXuPREbG6R/igeU5YfDJyyLbZ3UnLh/JmWBbTCAKmynv7xg6tV/4L5u0+H e+s3DmjwtUgLYuwgeqgJnOgGvo5XZ/VI+kMhA/s/z4ouM9IKBUdbxUAA3ArqXpsZNdIQ LpWMW/aErAyEhTTTWGh6JM1IQhtNlL+oftgZNLdyVQwu4u8yE4+oS3p0Xd/wPOl75GgZ J8mnBtbgBBS4sWTukLFi18Ff5J5OAwlxOf+1j8N9QBn0gy4pIiMR8JuHWXo2Ym1nYE6Q 6b3g== X-Gm-Message-State: AOAM532YHLCAgiO5HQD6Bke1sgLaXNOKenYgRXpcSxMZPbgn1qUIuAqa HfTc3q3Uqck1eUz9m7Ob4A== X-Received: by 2002:adf:efc3:: with SMTP id i3mr59891089wrp.103.1636203651372; Sat, 06 Nov 2021 06:00:51 -0700 (PDT) Received: from alex-ThinkPad-E480.. (ip5b435a69.dynamic.kabel-deutschland.de. [91.67.90.105]) by smtp.googlemail.com with ESMTPSA id h27sm15786674wmc.43.2021.11.06.06.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 06:00:51 -0700 (PDT) From: Alex Bee To: Neil Armstrong , Andrzej Hajda , Robert Foss , Laurent Pinchart Cc: Jonas Karlman , Jernej Skrabec , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Alex Bee Subject: [PATCH] drm: bridge: dw-hdmi: Fix RGB to YUV color space conversion Date: Sat, 6 Nov 2021 14:00:44 +0100 Message-Id: <20211106130044.63483-1-knaerzche@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As per CEA-861 quantization range is always limited in case of YUV output - indepentently which CEA mode it is or if it is an DMT mode. This is already correctly setup in HDMI AVI inforame, but we always do a RGB to YUV conversion which doesn't consider that RGB input can be full range as well. That leads to incorrect colors for all CEA modes except mode 1 for HDMI and always for DVI. To fix this, provide additional csc coefficents for converting from RGB full range to EITU601/EITU709 limited range and rename the existing arrays to clarify their meaning. Signed-off-by: Alex Bee --- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c index 62ae63565d3a..1cba08b70091 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -80,13 +80,25 @@ static const u16 csc_coeff_rgb_out_eitu709[3][4] = { { 0x2000, 0x0000, 0x3b61, 0x7e25 } }; -static const u16 csc_coeff_rgb_in_eitu601[3][4] = { +static const u16 csc_coeff_rgb_full_in_eitu601[3][4] = { + { 0x2044, 0x106f, 0x0644, 0x0040 }, + { 0xe677, 0x1c1c, 0xfd46, 0x0200 }, + { 0xed60, 0xf685, 0x1c1c, 0x0200 } +}; + +static const u16 csc_coeff_rgb_limited_in_eitu601[3][4] = { { 0x2591, 0x1322, 0x074b, 0x0000 }, { 0x6535, 0x2000, 0x7acc, 0x0200 }, { 0x6acd, 0x7534, 0x2000, 0x0200 } }; -static const u16 csc_coeff_rgb_in_eitu709[3][4] = { +static const u16 csc_coeff_rgb_full_in_eitu709[3][4] = { + { 0x2750, 0x0baf, 0x03f8, 0x0040 }, + { 0xe677, 0x1c1c, 0xfd6d, 0x0200 }, + { 0xea55, 0xf98f, 0x1c1c, 0x0200 } +}; + +static const u16 csc_coeff_rgb_limted_in_eitu709[3][4] = { { 0x2dc5, 0x0d9b, 0x049e, 0x0000 }, { 0x62f0, 0x2000, 0x7d11, 0x0200 }, { 0x6756, 0x78ab, 0x2000, 0x0200 } @@ -1023,9 +1035,13 @@ static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) csc_coeff = &csc_coeff_rgb_out_eitu709; } else if (is_input_rgb && !is_output_rgb) { if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) - csc_coeff = &csc_coeff_rgb_in_eitu601; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limited_in_eitu601 + : &csc_coeff_rgb_full_in_eitu601; else - csc_coeff = &csc_coeff_rgb_in_eitu709; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limted_in_eitu709 + : &csc_coeff_rgb_full_in_eitu709; csc_scale = 0; } else if (is_input_rgb && is_output_rgb && hdmi->hdmi_data.rgb_limited_range) { base-commit: 89636a06fa2ee7826a19c39c19a9bc99ab9340a9 -- 2.30.2