dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Maxime Ripard <maxime@cerno.tech>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Daniel Vetter <daniel.vetter@intel.com>,
	David Airlie <airlied@linux.ie>,
	Jernej Skrabec <jernej.skrabec@siol.net>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Jonas Karlman <jonas@kwiboo.se>
Cc: Tim Gover <tim.gover@raspberrypi.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	dri-devel@lists.freedesktop.org,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	Phil Elwell <phil@raspberrypi.com>
Subject: Re: [PATCH 16/18] drm/vc4: hdmi: Support HDMI YUV output
Date: Thu, 15 Apr 2021 08:43:50 +0200	[thread overview]
Message-ID: <11d0002f-8bfe-286b-cc1a-81b2e4aa0837@suse.de> (raw)
In-Reply-To: <20210317154352.732095-17-maxime@cerno.tech>


[-- Attachment #1.1.1: Type: text/plain, Size: 9384 bytes --]



Am 17.03.21 um 16:43 schrieb Maxime Ripard:
> The HDMI controllers in the BCM2711 support YUV444 and YUV420 outputs,
> let's add support for it.
> 
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---
>   drivers/gpu/drm/vc4/vc4_hdmi.c      | 73 +++++++++++++++++++++++++++--
>   drivers/gpu/drm/vc4/vc4_hdmi_regs.h |  6 +++
>   drivers/gpu/drm/vc4/vc4_regs.h      | 16 +++++++
>   3 files changed, 90 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> index 83e44cf44d65..407b468dab67 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> @@ -33,6 +33,7 @@
>   
>   #include <drm/drm_atomic_helper.h>
>   #include <drm/drm_edid.h>
> +#include <drm/drm_hdmi.h>
>   #include <drm/drm_probe_helper.h>
>   #include <drm/drm_simple_kms_helper.h>
>   #include <linux/clk.h>
> @@ -388,6 +389,8 @@ static void vc4_hdmi_set_avi_infoframe(struct vc4_hdmi *vc4_hdmi,
>   	struct drm_connector *connector = &vc4_hdmi->connector;
>   	struct drm_connector_state *cstate =
>   		drm_atomic_get_new_connector_state(state, connector);
> +	struct drm_bridge_state *bstate =
> +		drm_atomic_get_new_bridge_state(state, &vc4_hdmi->bridge.base);
>   	struct drm_crtc *crtc = encoder->crtc;
>   	const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
>   	union hdmi_infoframe frame;
> @@ -407,6 +410,7 @@ static void vc4_hdmi_set_avi_infoframe(struct vc4_hdmi *vc4_hdmi,
>   					   HDMI_QUANTIZATION_RANGE_LIMITED);
>   
>   	drm_hdmi_avi_infoframe_bars(&frame.avi, cstate);
> +	drm_hdmi_avi_infoframe_output_colorspace(&frame.avi, &bstate->output_bus_cfg);
>   
>   	vc4_hdmi_write_infoframe(vc4_hdmi, &frame);
>   }
> @@ -558,6 +562,38 @@ static const u16 vc5_hdmi_csc_full_rgb_to_limited_rgb[3][4] = {
>   	{ 0x0000, 0x0000, 0x1b80, 0x0400 },
>   };
>   
> +/*
> + * Conversion between Full Range RGB and Full Range YUV422 using the
> + * BT.709 Colorspace
> + *
> + * [  0.212639  0.715169  0.072192  0   ]
> + * [ -0.117208 -0.394207  0.511416  128 ]
> + * [  0.511416 -0.464524 -0.046891  128 ]
> + *
> + * Matrix is signed 2p13 fixed point, with signed 9p6 offsets
> + */
> +static const u16 vc5_hdmi_csc_full_rgb_to_full_yuv422_bt709[3][4] = {
> +	{ 0x06ce, 0x16e3, 0x024f, 0x0000 },
> +	{ 0xfc41, 0xf364, 0x105e, 0x2000 },
> +	{ 0x105e, 0xf124, 0xfe81, 0x2000 },
> +};
> +
> +/*
> + * Conversion between Full Range RGB and Full Range YUV444 using the
> + * BT.709 Colorspace
> + *
> + * [ -0.117208 -0.394207  0.511416  128 ]
> + * [  0.511416 -0.464524 -0.046891  128 ]
> + * [  0.212639  0.715169  0.072192  0   ]
> + *
> + * Matrix is signed 2p13 fixed point, with signed 9p6 offsets
> + */
> +static const u16 vc5_hdmi_csc_full_rgb_to_full_yuv444_bt709[3][4] = {
> +	{ 0xfc41, 0xf364, 0x105e, 0x2000 },
> +	{ 0x105e, 0xf124, 0xfe81, 0x2000 },
> +	{ 0x06ce, 0x16e3, 0x024f, 0x0000 },
> +};
> +
>   static void vc5_hdmi_set_csc_coeffs(struct vc4_hdmi *vc4_hdmi,
>   				    const u16 coeffs[3][4])
>   {
> @@ -573,16 +609,42 @@ static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi,
>   			       struct drm_atomic_state *state,
>   			       const struct drm_display_mode *mode)
>   {
> +	struct drm_bridge *bridge = &vc4_hdmi->bridge.base;
> +	struct drm_bridge_state *bridge_state =
> +		drm_atomic_get_new_bridge_state(state, bridge);
> +	u32 if_cfg = 0;
> +	u32 if_xbar = 0x543210;
> +	u32 csc_chan_ctl = 0;
>   	u32 csc_ctl = VC5_MT_CP_CSC_CTL_ENABLE | VC4_SET_FIELD(VC4_HD_CSC_CTL_MODE_CUSTOM,
>   							       VC5_MT_CP_CSC_CTL_MODE);
>   
> -	HDMI_WRITE(HDMI_VEC_INTERFACE_XBAR, 0x354021);
> +	if (drm_hdmi_bus_fmt_is_yuv422(bridge_state->output_bus_cfg.format)) {
> +		csc_ctl |= VC4_SET_FIELD(VC5_MT_CP_CSC_CTL_FILTER_MODE_444_TO_422_STANDARD,
> +					 VC5_MT_CP_CSC_CTL_FILTER_MODE_444_TO_422) |
> +			VC5_MT_CP_CSC_CTL_USE_444_TO_422 |
> +			VC5_MT_CP_CSC_CTL_USE_RNG_SUPPRESSION;

Indention appears to be wrong.

>   
> -	if (vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode))
> -		vc5_hdmi_set_csc_coeffs(vc4_hdmi, &vc5_hdmi_csc_full_rgb_unity);
> -	else
> -		vc5_hdmi_set_csc_coeffs(vc4_hdmi, &vc5_hdmi_csc_full_rgb_to_limited_rgb);
> +		csc_chan_ctl |= VC4_SET_FIELD(VC5_MT_CP_CHANNEL_CTL_OUTPUT_REMAP_LEGACY_STYLE,
> +					      VC5_MT_CP_CHANNEL_CTL_OUTPUT_REMAP);
>   
> +		if_cfg |= VC4_SET_FIELD(VC5_DVP_HT_VEC_INTERFACE_CFG_SEL_422_FORMAT_422_LEGACY,
> +					VC5_DVP_HT_VEC_INTERFACE_CFG_SEL_422);
> +
> +		vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_to_full_yuv422_bt709);
> +	} else if (drm_hdmi_bus_fmt_is_yuv444(bridge_state->output_bus_cfg.format)) {
> +		vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_to_full_yuv444_bt709);
> +	} else if (drm_hdmi_bus_fmt_is_rgb(bridge_state->output_bus_cfg.format)) {
> +		if_xbar = 0x354021;
> +
> +		if (vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode))
> +			vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_unity);
> +		else
> +			vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_to_limited_rgb);
> +	}
> +
> +	HDMI_WRITE(HDMI_VEC_INTERFACE_CFG, if_cfg);
> +	HDMI_WRITE(HDMI_VEC_INTERFACE_XBAR, if_xbar);
> +	HDMI_WRITE(HDMI_CSC_CHANNEL_CTL, csc_chan_ctl);
>   	HDMI_WRITE(HDMI_CSC_CTL, csc_ctl);
>   }
>   
> @@ -1012,6 +1074,7 @@ static const struct drm_bridge_funcs vc4_hdmi_bridge_funcs = {
>   	.atomic_check =	vc4_hdmi_bridge_atomic_check,
>   	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
>   	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
> +	.atomic_get_output_bus_fmts = drm_atomic_helper_bridge_hdmi_get_output_bus_fmts,
>   	.atomic_reset = drm_atomic_helper_bridge_reset,
>   	.mode_valid =	vc4_hdmi_bridge_mode_valid,
>   };
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi_regs.h b/drivers/gpu/drm/vc4/vc4_hdmi_regs.h
> index e1b58eac766f..d03b9ad72412 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi_regs.h
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi_regs.h
> @@ -52,6 +52,7 @@ enum vc4_hdmi_field {
>   	HDMI_CSC_24_23,
>   	HDMI_CSC_32_31,
>   	HDMI_CSC_34_33,
> +	HDMI_CSC_CHANNEL_CTL,
>   	HDMI_CSC_CTL,
>   
>   	/*
> @@ -116,6 +117,7 @@ enum vc4_hdmi_field {
>   	HDMI_TX_PHY_POWERDOWN_CTL,
>   	HDMI_TX_PHY_RESET_CTL,
>   	HDMI_TX_PHY_TMDS_CLK_WORD_SEL,
> +	HDMI_VEC_INTERFACE_CFG,
>   	HDMI_VEC_INTERFACE_XBAR,
>   	HDMI_VERTA0,
>   	HDMI_VERTA1,
> @@ -240,6 +242,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi0_fields[] = {
>   	VC4_HDMI_REG(HDMI_HOTPLUG, 0x1a8),
>   
>   	VC5_DVP_REG(HDMI_CLOCK_STOP, 0x0bc),
> +	VC5_DVP_REG(HDMI_VEC_INTERFACE_CFG, 0x0ec),
>   	VC5_DVP_REG(HDMI_VEC_INTERFACE_XBAR, 0x0f0),
>   
>   	VC5_PHY_REG(HDMI_TX_PHY_RESET_CTL, 0x000),
> @@ -285,6 +288,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi0_fields[] = {
>   	VC5_CSC_REG(HDMI_CSC_24_23, 0x010),
>   	VC5_CSC_REG(HDMI_CSC_32_31, 0x014),
>   	VC5_CSC_REG(HDMI_CSC_34_33, 0x018),
> +	VC5_CSC_REG(HDMI_CSC_CHANNEL_CTL, 0x02c),
>   };
>   
>   static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi1_fields[] = {
> @@ -319,6 +323,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi1_fields[] = {
>   	VC4_HDMI_REG(HDMI_HOTPLUG, 0x1a8),
>   
>   	VC5_DVP_REG(HDMI_CLOCK_STOP, 0x0bc),
> +	VC5_DVP_REG(HDMI_VEC_INTERFACE_CFG, 0x0ec),
>   	VC5_DVP_REG(HDMI_VEC_INTERFACE_XBAR, 0x0f0),
>   
>   	VC5_PHY_REG(HDMI_TX_PHY_RESET_CTL, 0x000),
> @@ -364,6 +369,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi1_fields[] = {
>   	VC5_CSC_REG(HDMI_CSC_24_23, 0x010),
>   	VC5_CSC_REG(HDMI_CSC_32_31, 0x014),
>   	VC5_CSC_REG(HDMI_CSC_34_33, 0x018),
> +	VC5_CSC_REG(HDMI_CSC_CHANNEL_CTL, 0x02c),
>   };
>   
>   static inline
> diff --git a/drivers/gpu/drm/vc4/vc4_regs.h b/drivers/gpu/drm/vc4/vc4_regs.h
> index 9d7c034c8b4f..ff5c5faa019e 100644
> --- a/drivers/gpu/drm/vc4/vc4_regs.h
> +++ b/drivers/gpu/drm/vc4/vc4_regs.h
> @@ -744,11 +744,27 @@
>   # define VC4_HD_CSC_CTL_RGB2YCC			BIT(1)
>   # define VC4_HD_CSC_CTL_ENABLE			BIT(0)
>   
> +# define VC5_MT_CP_CSC_CTL_USE_444_TO_422	BIT(6)
> +# define VC5_MT_CP_CSC_CTL_FILTER_MODE_444_TO_422_MASK \
> +						VC4_MASK(5, 4)
> +# define VC5_MT_CP_CSC_CTL_FILTER_MODE_444_TO_422_STANDARD \
> +						3

These defines should fit onto a single 100-character line. (?) Here and 
below.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>

> +# define VC5_MT_CP_CSC_CTL_USE_RNG_SUPPRESSION	BIT(3)
>   # define VC5_MT_CP_CSC_CTL_ENABLE		BIT(2)
>   # define VC5_MT_CP_CSC_CTL_MODE_MASK		VC4_MASK(1, 0)
>   
> +# define VC5_MT_CP_CHANNEL_CTL_OUTPUT_REMAP_MASK \
> +						VC4_MASK(7, 6)
> +# define VC5_MT_CP_CHANNEL_CTL_OUTPUT_REMAP_LEGACY_STYLE \
> +						2
> +
>   # define VC4_DVP_HT_CLOCK_STOP_PIXEL		BIT(1)
>   
> +# define VC5_DVP_HT_VEC_INTERFACE_CFG_SEL_422_MASK \
> +						VC4_MASK(3, 2)
> +# define VC5_DVP_HT_VEC_INTERFACE_CFG_SEL_422_FORMAT_422_LEGACY \
> +						2
> +
>   /* HVS display list information. */
>   #define HVS_BOOTLOADER_DLIST_END                32
>   
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2021-04-15  6:43 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 15:43 [PATCH 00/18] drm/vc4: hdmi: Add Support for the YUV output Maxime Ripard
2021-03-17 15:43 ` [PATCH 01/18] drm: Introduce new HDMI helpers Maxime Ripard
2021-04-09  7:16   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 02/18] drm/bridge: Add HDMI output fmt helper Maxime Ripard
2021-03-17 16:08   ` Neil Armstrong
2021-03-18 18:31     ` Jernej Škrabec
2021-03-19  9:44       ` Neil Armstrong
2021-03-19 10:09         ` Maxime Ripard
2021-04-09  8:03   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 03/18] drm/bridge: dw-hdmi: Use helpers Maxime Ripard
2021-04-09  8:05   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 04/18] drm/vc4: txp: Properly set the possible_crtcs mask Maxime Ripard
2021-04-09  8:07   ` Thomas Zimmermann
2021-04-09  8:11   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 05/18] drm/vc4: crtc: Skip the TXP Maxime Ripard
2021-04-09  8:10   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 06/18] drm/vc4: Rework the encoder retrieval code Maxime Ripard
2021-04-09  8:54   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 07/18] drm/vc4: hdmi: Add full range RGB helper Maxime Ripard
2021-04-12  9:44   ` Thomas Zimmermann
2021-04-14 13:48     ` Maxime Ripard
2021-03-17 15:43 ` [PATCH 08/18] drm/vc4: hdmi: Use full range helper in csc functions Maxime Ripard
2021-04-12  9:45   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 09/18] drm/vc4: hdmi: Remove limited_rgb_range Maxime Ripard
2021-04-12 10:19   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 10/18] drm/vc4: hdmi: Convert to bridge Maxime Ripard
2021-04-12 10:21   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 11/18] drm/vc4: hdmi: Move XBAR setup to csc_setup Maxime Ripard
2021-04-12 10:28   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 12/18] drm/vc4: hdmi: Replace CSC_CTL hardcoded value by defines Maxime Ripard
2021-04-12 10:28   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 13/18] drm/vc4: hdmi: Define colorspace matrices Maxime Ripard
2021-04-14 13:54   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 14/18] drm/vc4: hdmi: Change CSC callback prototype Maxime Ripard
2021-04-14 13:56   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 15/18] drm/vc4: hdmi: Rework the infoframe prototype Maxime Ripard
2021-04-14 13:58   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 16/18] drm/vc4: hdmi: Support HDMI YUV output Maxime Ripard
2021-04-15  6:43   ` Thomas Zimmermann [this message]
2021-03-17 15:43 ` [PATCH 17/18] drm/vc4: hdmi: Move the pixel rate calculation to a helper Maxime Ripard
2021-04-15  7:19   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 18/18] drm/vc4: hdmi: Force YUV422 if the rate is too high Maxime Ripard
2021-04-15  7:24   ` Thomas Zimmermann
2021-03-18 18:16 ` [PATCH 00/18] drm/vc4: hdmi: Add Support for the YUV output Jernej Škrabec
2021-03-19 10:13   ` Maxime Ripard
2021-04-09  9:47   ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11d0002f-8bfe-286b-cc1a-81b2e4aa0837@suse.de \
    --to=tzimmermann@suse.de \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=a.hajda@samsung.com \
    --cc=airlied@linux.ie \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=daniel.vetter@intel.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@siol.net \
    --cc=jonas@kwiboo.se \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maxime@cerno.tech \
    --cc=narmstrong@baylibre.com \
    --cc=phil@raspberrypi.com \
    --cc=tim.gover@raspberrypi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).