Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5235872ybl; Tue, 27 Aug 2019 01:17:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6JpKv4wTm++xm7PrAIT1YM233fl9zn/632As743X8r7RaX2JvU4C8+73C5UWNp1eHv9ST X-Received: by 2002:a17:902:f213:: with SMTP id gn19mr23269184plb.152.1566893852610; Tue, 27 Aug 2019 01:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893852; cv=none; d=google.com; s=arc-20160816; b=efw5w9pYzOHxZM7s/4/CKvKBDtczINlhPB35ipItzDUQ9PCDo6hklJx6fLO6j84MG6 jf9+/B7IXvthwasvdVtxxBgpctHJxR1tl1JHUlKrmK5nAZISi6SlV/mukHCoaywFXcWY RZ90N/IJN1n4HxDM0OuMhJLxfsV4HUxGudSmlQoKOD2ADF+qup3q+rfJw2EaMuwuKVf1 txuvIC80L2KjyQFb82N2ke1s7I1UHFokdYajRVvD858G25VU4e5vaNkVDl0983dnONd6 MNb4wlyMiaapsJDOOZXYYZvbQkdfSBbk7xTspg5dnMQwdhFbWjuRmh3iC/XOqJI9njlO h5XQ== 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 :dkim-signature; bh=XlAPuwfMX1K7TzaZ6rYnkrkcwMJ84axgoy/tibVraho=; b=atkrlBltkP5Ae30sKn7xPp+xQQWTmjbMLCaXwSrIj+xo0s7Loc2mg+57+mz+j9ZyQJ VmFDAUTmV2ES6J6NAjRG4UiO6u/kYrWAqcZrKXEqQzNxjiB7fBe35Gah7GYVRh/Kk/he Z6TZWodF211Og3U1obAVJqFdyRLIX15V/T2SP3AaMNL08FToqMUUE4dv687RoNoHNGp1 CvakrplMn8X1gRVtb+MMVC5+4IAiK0UjVbBZ/XWaz/uK7qGOuVTgk6an/Rp7jXkOOd1r Hg8+AVazny8eymRCifUDmsPyQpZJ2gQlj6JYGOLrCoQ2zZsWzvNt+wbD+oJfa9FmOb0w DSxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="nLlf//Ni"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3si11268567pgn.467.2019.08.27.01.17.17; Tue, 27 Aug 2019 01:17:32 -0700 (PDT) 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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="nLlf//Ni"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731926AbfH0IOk (ORCPT + 99 others); Tue, 27 Aug 2019 04:14:40 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43191 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729988AbfH0IOi (ORCPT ); Tue, 27 Aug 2019 04:14:38 -0400 Received: by mail-wr1-f68.google.com with SMTP id y8so17794406wrn.10 for ; Tue, 27 Aug 2019 01:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XlAPuwfMX1K7TzaZ6rYnkrkcwMJ84axgoy/tibVraho=; b=nLlf//Ni6jo2mEfmXX3t38EOU3L2gqea0aZyOJhBDtUMhzmTfiMQ1JdSpUsrZc/z0I Ir4+xupvw/G1VUEI60axwlTmXATRJhrY0POFJAmsMXv56dXuJLyKPZNXdrnDOkaglErR 5knX4qsRqJMxXFbHAsLIWC9piloJPcyCJKeG6p3Ub0RrlayGbekus6+6UYzu4eLcnpJ3 0m4ziy1zPBADal5YSIQ3O2Hq8r/OVh7EL/Dknzt+5HcG4sO06mOMa7iTBdtc4fgJJe5N Txuqpoqpw+M7uzyT7/NQYACTqXyuZddvqSxRwwXLDeLPDi9GBvRR/SY7ysz9kIyZ2Vw8 GhQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XlAPuwfMX1K7TzaZ6rYnkrkcwMJ84axgoy/tibVraho=; b=L7SP0SOkrExKGlv3qEYRtyQyaPBtBMFeawaCDxPaXfOcRsVXm/pFp7Zxr2v8acOh+X +44BRkKvxqvtsNg7wfjVWrBiGDFRG2CYw5w/Q2JOY6BxOBm4ir1b0NbJ2v1AIeMgBEaU 6qCdSUTH5ico5Xkn/TyUcYcjNVuTesiwbfC3jSe/BKzFz2HXJAqe+780fj05vz38OhfA CZOxkOeWkHAtGA1Y6x4MdBusEOeHApZ7ifCFECXDCwf1KUU/LqaKRr1b7OmwvosLbc/q OwHsWeL7RjOjTxHbXkjiFWHz1lBzQQ+ax/FuMNncZPWlfFkk6kf5EawtM1yibStoSgat zyAQ== X-Gm-Message-State: APjAAAW5WuvJY7sFy2hfVaAWxSEdOgI8MGtSkb7p3tMEj6USFc6c2++R MTGggtx7aIMOfoZvXoE6ALS3lA== X-Received: by 2002:a05:6000:110f:: with SMTP id z15mr26219779wrw.162.1566893675175; Tue, 27 Aug 2019 01:14:35 -0700 (PDT) Received: from bender.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id f18sm11911792wrx.85.2019.08.27.01.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2019 01:14:34 -0700 (PDT) From: Neil Armstrong To: a.hajda@samsung.com, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@siol.net, boris.brezillon@collabora.com Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v2 8/8] drm/meson: Add YUV420 output support Date: Tue, 27 Aug 2019 10:14:25 +0200 Message-Id: <20190827081425.15011-9-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190827081425.15011-1-narmstrong@baylibre.com> References: <20190827081425.15011-1-narmstrong@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support for the YUV420 output from the Amlogic Meson SoCs Video Processing Unit to the HDMI Controller. The YUV420 is obtained by generating a YUV444 pixel stream like the classic HDMI display modes, but then the Video Encoder output can be configured to down-sample the YUV444 pixel stream to a YUV420 stream. In addition if pixel stream down-sampling, the Y Cb Cr components must also be mapped differently to align with the HDMI2.0 specifications. This mode needs a different clock generation scheme since the TMDS PHY clock must match the 10x ration with the YUV420 pixel clock, but the video encoder must run at 2x the pixel clock. This patch enables the bridge bus format negociation, and handles the YUV420 case if selected by the negociation. Signed-off-by: Neil Armstrong --- drivers/gpu/drm/meson/meson_dw_hdmi.c | 85 +++++++++++++++++++++------ 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c b/drivers/gpu/drm/meson/meson_dw_hdmi.c index 38316c6cac26..10223aa27f7c 100644 --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c @@ -148,6 +148,7 @@ struct meson_dw_hdmi { struct regulator *hdmi_supply; u32 irq_stat; struct dw_hdmi *hdmi; + unsigned long output_bus_fmt; }; #define encoder_to_meson_dw_hdmi(x) \ container_of(x, struct meson_dw_hdmi, encoder) @@ -297,6 +298,10 @@ static void meson_hdmi_phy_setup_mode(struct meson_dw_hdmi *dw_hdmi, struct meson_drm *priv = dw_hdmi->priv; unsigned int pixel_clock = mode->clock; + /* For 420, pixel clock is half unlike venc clock */ + if (dw_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24) + pixel_clock /= 2; + if (dw_hdmi_is_compatible(dw_hdmi, "amlogic,meson-gxl-dw-hdmi") || dw_hdmi_is_compatible(dw_hdmi, "amlogic,meson-gxm-dw-hdmi")) { if (pixel_clock >= 371250) { @@ -379,6 +384,10 @@ static void dw_hdmi_set_vclk(struct meson_dw_hdmi *dw_hdmi, vclk_freq = mode->clock; + /* For 420, pixel clock is half unlike venc clock */ + if (dw_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24) + vclk_freq /= 2; + /* TMDS clock is pixel_clock * 10 */ phy_freq = vclk_freq * 10; @@ -388,13 +397,16 @@ static void dw_hdmi_set_vclk(struct meson_dw_hdmi *dw_hdmi, return; } + /* 480i/576i needs global pixel doubling */ if (mode->flags & DRM_MODE_FLAG_DBLCLK) vclk_freq *= 2; venc_freq = vclk_freq; hdmi_freq = vclk_freq; - if (meson_venc_hdmi_venc_repeat(vic)) + /* VENC double pixels for 1080i, 720p and YUV420 modes */ + if (meson_venc_hdmi_venc_repeat(vic) || + dw_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24) venc_freq *= 2; vclk_freq = max(venc_freq, hdmi_freq); @@ -441,8 +453,9 @@ static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data, /* Enable normal output to PHY */ dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_BIST_CNTL, BIT(12)); - /* TMDS pattern setup (TOFIX Handle the YUV420 case) */ - if (mode->clock > 340000) { + /* TMDS pattern setup */ + if (mode->clock > 340000 && + dw_hdmi->output_bus_fmt == MEDIA_BUS_FMT_YUV8_1X24) { dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_01, 0); dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_23, @@ -617,6 +630,7 @@ dw_hdmi_mode_valid(struct drm_connector *connector, const struct drm_display_mode *mode) { struct meson_drm *priv = connector->dev->dev_private; + bool is_hdmi2_sink = connector->display_info.hdmi.scdc.supported; unsigned int phy_freq; unsigned int vclk_freq; unsigned int venc_freq; @@ -626,9 +640,11 @@ dw_hdmi_mode_valid(struct drm_connector *connector, DRM_DEBUG_DRIVER("Modeline " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode)); - /* If sink max TMDS clock, we reject the mode */ + /* If sink does not support 540MHz, reject the non-420 HDMI2 modes */ if (connector->display_info.max_tmds_clock && - mode->clock > connector->display_info.max_tmds_clock) + mode->clock > connector->display_info.max_tmds_clock && + !drm_mode_is_420_only(&connector->display_info, mode) && + !drm_mode_is_420_also(&connector->display_info, mode)) return MODE_BAD; /* Check against non-VIC supported modes */ @@ -644,6 +660,12 @@ dw_hdmi_mode_valid(struct drm_connector *connector, vclk_freq = mode->clock; + /* For 420, pixel clock is half unlike venc clock */ + if (drm_mode_is_420_only(&connector->display_info, mode) || + (!is_hdmi2_sink && + drm_mode_is_420_also(&connector->display_info, mode))) + vclk_freq /= 2; + /* TMDS clock is pixel_clock * 10 */ phy_freq = vclk_freq * 10; @@ -654,8 +676,11 @@ dw_hdmi_mode_valid(struct drm_connector *connector, venc_freq = vclk_freq; hdmi_freq = vclk_freq; - /* VENC double pixels for 1080i and 720p modes */ - if (meson_venc_hdmi_venc_repeat(vic)) + /* VENC double pixels for 1080i, 720p and YUV420 modes */ + if (meson_venc_hdmi_venc_repeat(vic) || + drm_mode_is_420_only(&connector->display_info, mode) || + (!is_hdmi2_sink && + drm_mode_is_420_also(&connector->display_info, mode))) venc_freq *= 2; vclk_freq = max(venc_freq, hdmi_freq); @@ -673,6 +698,7 @@ dw_hdmi_mode_valid(struct drm_connector *connector, static const u32 meson_dw_hdmi_out_bus_fmts[] = { MEDIA_BUS_FMT_YUV8_1X24, + MEDIA_BUS_FMT_UYYVYY8_0_5X24, }; static void meson_venc_hdmi_encoder_destroy(struct drm_encoder *encoder) @@ -708,13 +734,19 @@ meson_venc_hdmi_encoder_get_inp_bus_fmts(struct drm_bridge *bridge, unsigned int *num_input_fmts, u32 *input_fmts) { - if (output_fmt == meson_dw_hdmi_out_bus_fmts[0]) { - *num_input_fmts = 1; - if (input_fmts) - input_fmts[0] = output_fmt; + int i; + + *num_input_fmts = 0; + + for (i = 0 ; i < ARRAY_SIZE(meson_dw_hdmi_out_bus_fmts) ; ++i) { + if (output_fmt == meson_dw_hdmi_out_bus_fmts[i]) { + *num_input_fmts = 1; + if (input_fmts) + input_fmts[0] = output_fmt; + + break; + } } - else - *num_input_fmts = 0; } static int meson_venc_hdmi_encoder_atomic_check(struct drm_bridge *bridge, @@ -722,6 +754,13 @@ static int meson_venc_hdmi_encoder_atomic_check(struct drm_bridge *bridge, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { + struct drm_encoder *encoder = bridge_to_encoder(bridge); + struct meson_dw_hdmi *dw_hdmi = encoder_to_meson_dw_hdmi(encoder); + + dw_hdmi->output_bus_fmt = bridge_state->output_bus_cfg.fmt; + + DRM_DEBUG_DRIVER("output_bus_fmt %lx\n", dw_hdmi->output_bus_fmt); + return 0; } @@ -762,18 +801,29 @@ static void meson_venc_hdmi_encoder_mode_set(struct drm_bridge *bridge, struct meson_dw_hdmi *dw_hdmi = encoder_to_meson_dw_hdmi(encoder); struct meson_drm *priv = dw_hdmi->priv; int vic = drm_match_cea_mode(mode); + unsigned int ycrcb_map = VPU_HDMI_OUTPUT_CBYCR; + bool yuv420_mode = false; DRM_DEBUG_DRIVER("\"%s\" vic %d\n", mode->name, vic); + if (dw_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24) { + ycrcb_map = VPU_HDMI_OUTPUT_CRYCB; + yuv420_mode = true; + } + /* VENC + VENC-DVI Mode setup */ - meson_venc_hdmi_mode_set(priv, vic, ycrcb_map, false, - VPU_HDMI_OUTPUT_CBYCR); + meson_venc_hdmi_mode_set(priv, vic, ycrcb_map, yuv420_mode, mode); /* VCLK Set clock */ dw_hdmi_set_vclk(dw_hdmi, mode); - /* Setup YUV444 to HDMI-TX, no 10bit diphering */ - writel_relaxed(0, priv->io_base + _REG(VPU_HDMI_FMT_CTRL)); + if (dw_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24) + /* Setup YUV420 to HDMI-TX, no 10bit diphering */ + writel_relaxed(2 | (2 << 2), + priv->io_base + _REG(VPU_HDMI_FMT_CTRL)); + else + /* Setup YUV444 to HDMI-TX, no 10bit diphering */ + writel_relaxed(0, priv->io_base + _REG(VPU_HDMI_FMT_CTRL)); } static const struct drm_bridge_funcs meson_venc_hdmi_encoder_bridge_funcs = { @@ -1017,6 +1067,7 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, dw_plat_data->phy_name = "meson_dw_hdmi_phy"; dw_plat_data->phy_data = meson_dw_hdmi; dw_plat_data->input_bus_encoding = V4L2_YCBCR_ENC_709; + dw_plat_data->ycbcr_420_allowed = true; platform_set_drvdata(pdev, meson_dw_hdmi); -- 2.22.0