From patchwork Tue Sep 1 20:30:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Stratiienko X-Patchwork-Id: 11749443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DA11618 for ; Tue, 1 Sep 2020 20:31:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 059D3207D3 for ; Tue, 1 Sep 2020 20:31:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="imGGS+C1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vWqoevsZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 059D3207D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=oSbmcqu0EHwzHaeLfbVDrQtT7zBl3CTq2m8o12vb7SI=; b=imGGS+C1QpubXnWKFP5wrlUX1t 2iP7oFtg+CdAP5UyFqvxKif7Lu6RUUHFwBsUGFD7j6stX/3Z48Hu6QOncFBmWyemhtEvpzwQbXiFd XUxFlWJR42+xinldpMmXI1Q3IwuJQUoosB2kligkLhzf+aZKowm4EVB6poJcc/d3pL2jhREkS92Z3 k1v9WJjYYhXBLhvT4GSLd+4jH2mDp6N9UouKLnt/WIa/ff/HwfpNF9fEGN8/mbBOg0swCQHAckYQh 4BFWIleTqgnHv7ZdYcbo1doEUbhajBjYEoxakiNge6zemXvJQNUuvPC8MMTXVZl4FyhMyCQbAQYJF WAFkxrKw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDCvl-0000Yo-6s; Tue, 01 Sep 2020 20:31:01 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDCvj-0000Y7-3v for linux-arm-kernel@lists.infradead.org; Tue, 01 Sep 2020 20:30:59 +0000 Received: by mail-lj1-x241.google.com with SMTP id e11so3166789ljn.6 for ; Tue, 01 Sep 2020 13:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=la4DhayotspIOU+5g3vlgWa+RmakeChJjrIIEgn/ogw=; b=vWqoevsZD5zI8pIeuO8Ca2MITs/+7hzQveMdlSNzHuhxVOK5oSTeVvD1gfPyZm7r74 huwNUkANsJTVTK2REuI0NafvjxEECEqlZiPV9M1fBW+GvUExz8VzGS390aQGzwtkylY3 MgHSMUFyVIjnYHSuSYGV7rNvNaq/SETtaLQT5jJi3zs6KVEbAN3vRRpYOZIpIBbuFkIL hsyvpdEBbcR40bjZ5ZAswN38z+oZRwWi/MAUhEIuSn7pNVbnJuZeEOobnFe2GQtZSfHc MsQX43/pXgEFu16AxmUKV4Tgp2EJHRB6m+TbUlIfE9/VE8cCM8ZspbTPLlX5EHXmm46E cotA== 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:mime-version :content-transfer-encoding; bh=la4DhayotspIOU+5g3vlgWa+RmakeChJjrIIEgn/ogw=; b=gEfsCgxTc/VOJvK7msIajY71iXGnQx96PhXpjD5DczFzfOABgEWMCD0IarPghf5EzR f2bXym000gsUYrl+7D5ySi9DaIT2y8ahu08z8Qxoi5x4y5m/sZQOeY8qH4yVCnSwlb+0 f1pZ2nZzmsGiQYaiZXdjFJrwjy0nWP5rRmXEg9/K/Nvl8dAlkQ7pPV/0JeRlSXk/NWeu TATiUTHGYX/D+EMjdlKBneoSpJNMHYGXMOh8ABag/8LXIvag69sxAHqZezkdfk+aN2/o V0G/gDasHb/FPDZCgBPrlM4Jmm3O2emozzruvB0QTAcnnxZCUxWyyDhUAQ3nx5IDVPGj jsXw== X-Gm-Message-State: AOAM531CTTLIp/lTUPbd+KcbebaZOflxG7Er10pOVqBSG+N7vheG16bQ peiiv9nH9wEi1i7pZ99KqM8= X-Google-Smtp-Source: ABdhPJx/W4RCS7rXI0/ehjeP/Ih206sqprvXQ3FMt1vaGuoqaB4m4MYMUMogPEZVR8ee9fxp/RYNag== X-Received: by 2002:a2e:9b8f:: with SMTP id z15mr1407054lji.215.1598992255760; Tue, 01 Sep 2020 13:30:55 -0700 (PDT) Received: from localhost.localdomain ([188.163.51.46]) by smtp.gmail.com with ESMTPSA id t1sm517996lfc.52.2020.09.01.13.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 13:30:55 -0700 (PDT) From: Roman Stratiienko To: jernej.skrabec@siol.net Subject: [PATCH] RFC: sun4i/drm: Swap back U and V channels for DRM_FORMAT_YVU4xx Date: Tue, 1 Sep 2020 23:30:47 +0300 Message-Id: <20200901203047.1110851-1-r.stratiienko@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200901_163059_179180_A50186AC X-CRM114-Status: GOOD ( 17.72 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:241 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [r.stratiienko[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: megous@megous.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-sunxi@googlegroups.com, jernej.skrabec@gmail.com, linux-arm-kernel@lists.infradead.org, Roman Stratiienko Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Fixes: e1ef9006663b ("drm/sun4i: Wire in DE2 YUV support") Signed-off-by: Roman Stratiienko --- CC: megous@megous.com CC: jernej.skrabec@gmail.com CC: linux-sunxi@googlegroups.com CC: dri-devel@lists.freedesktop.org CC: linux-arm-kernel@lists.infradead.org CC: linux-kernel@vger.kernel.org Hi, this patch fixes wrong colors during video playback for me. Implemented ugly for now, please review/suggest how to improve. --- drivers/gpu/drm/sun4i/sun8i_mixer.c | 8 +++++++- drivers/gpu/drm/sun4i/sun8i_mixer.h | 2 +- drivers/gpu/drm/sun4i/sun8i_ui_layer.c | 2 +- drivers/gpu/drm/sun4i/sun8i_vi_layer.c | 28 +++++++++++++++++++------- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun8i_mixer.c b/drivers/gpu/drm/sun4i/sun8i_mixer.c index dce40c430100..bbbeef44899a 100644 --- a/drivers/gpu/drm/sun4i/sun8i_mixer.c +++ b/drivers/gpu/drm/sun4i/sun8i_mixer.c @@ -31,6 +31,7 @@ struct de2_fmt_info { u32 drm_fmt; u32 de2_fmt; + bool swap_uv; }; static bool hw_preconfigured; @@ -219,14 +220,17 @@ static const struct de2_fmt_info de2_formats[] = { { .drm_fmt = DRM_FORMAT_YVU422, .de2_fmt = SUN8I_MIXER_FBFMT_YUV422, + .swap_uv = true, }, { .drm_fmt = DRM_FORMAT_YVU420, .de2_fmt = SUN8I_MIXER_FBFMT_YUV420, + .swap_uv = true, }, { .drm_fmt = DRM_FORMAT_YVU411, .de2_fmt = SUN8I_MIXER_FBFMT_YUV411, + .swap_uv = true, }, { .drm_fmt = DRM_FORMAT_P010, @@ -238,13 +242,15 @@ static const struct de2_fmt_info de2_formats[] = { }, }; -int sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format) +int sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format, bool *swap_uv) { unsigned int i; for (i = 0; i < ARRAY_SIZE(de2_formats); ++i) if (de2_formats[i].drm_fmt == format) { *hw_format = de2_formats[i].de2_fmt; + if (swap_uv) + *swap_uv = de2_formats[i].swap_uv; return 0; } diff --git a/drivers/gpu/drm/sun4i/sun8i_mixer.h b/drivers/gpu/drm/sun4i/sun8i_mixer.h index 79a74bca1ea3..6358ffd251f9 100644 --- a/drivers/gpu/drm/sun4i/sun8i_mixer.h +++ b/drivers/gpu/drm/sun4i/sun8i_mixer.h @@ -207,5 +207,5 @@ sun8i_channel_base(struct sun8i_mixer *mixer, int channel) return DE2_CH_BASE + channel * DE2_CH_SIZE; } -int sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format); +int sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format, bool *swap_uv); #endif /* _SUN8I_MIXER_H_ */ diff --git a/drivers/gpu/drm/sun4i/sun8i_ui_layer.c b/drivers/gpu/drm/sun4i/sun8i_ui_layer.c index a7f21f08ec89..57bbd9f1071c 100644 --- a/drivers/gpu/drm/sun4i/sun8i_ui_layer.c +++ b/drivers/gpu/drm/sun4i/sun8i_ui_layer.c @@ -215,7 +215,7 @@ static int sun8i_ui_layer_update_formats(struct sun8i_mixer *mixer, int channel, ch_base = sun8i_channel_base(mixer, channel); fmt = state->fb->format; - ret = sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt); + ret = sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt, NULL); if (ret || fmt->is_yuv) { DRM_DEBUG_DRIVER("Invalid format\n"); return -EINVAL; diff --git a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c index 3553e38ec642..4da51155c4d5 100644 --- a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c +++ b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c @@ -313,7 +313,7 @@ static int sun8i_vi_layer_update_formats(struct sun8i_mixer *mixer, int channel, ch_base = sun8i_channel_base(mixer, channel); fmt = state->fb->format; - ret = sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt); + ret = sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt, NULL); if (ret) { DRM_DEBUG_DRIVER("Invalid format\n"); return ret; @@ -368,8 +368,17 @@ static int sun8i_vi_layer_update_buffer(struct sun8i_mixer *mixer, int channel, struct drm_gem_cma_object *gem; u32 dx, dy, src_x, src_y; dma_addr_t paddr; + bool swap_uv; u32 ch_base; - int i; + u32 hw_fmt; + int ret; + int i, j; + + ret = sun8i_mixer_drm_format_to_hw(plane->state->fb->format->format, &hw_fmt, &swap_uv); + if (ret) { + DRM_DEBUG_DRIVER("Invalid format\n"); + return ret; + } ch_base = sun8i_channel_base(mixer, channel); @@ -377,7 +386,12 @@ static int sun8i_vi_layer_update_buffer(struct sun8i_mixer *mixer, int channel, src_x = (state->src.x1 >> 16) & ~(format->hsub - 1); src_y = (state->src.y1 >> 16) & ~(format->vsub - 1); - for (i = 0; i < format->num_planes; i++) { + for (j = 0; j < format->num_planes; j++) { + i = j; + if (swap_uv && i > 0 && format->num_planes == 3) { + i = j == 1 ? 2 : 1; + } + /* Get the physical address of the buffer in memory */ gem = drm_fb_cma_get_gem_obj(fb, i); @@ -400,18 +414,18 @@ static int sun8i_vi_layer_update_buffer(struct sun8i_mixer *mixer, int channel, /* Set the line width */ DRM_DEBUG_DRIVER("Layer %d. line width: %d bytes\n", - i + 1, fb->pitches[i]); + j + 1, fb->pitches[i]); regmap_write(mixer->engine.regs, SUN8I_MIXER_CHAN_VI_LAYER_PITCH(ch_base, - overlay, i), + overlay, j), fb->pitches[i]); DRM_DEBUG_DRIVER("Setting %d. buffer address to %pad\n", - i + 1, &paddr); + j + 1, &paddr); regmap_write(mixer->engine.regs, SUN8I_MIXER_CHAN_VI_LAYER_TOP_LADDR(ch_base, - overlay, i), + overlay, j), lower_32_bits(paddr)); }