From patchwork Wed Mar 21 15:29:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 10299699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25CE9600F6 for ; Wed, 21 Mar 2018 15:34:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12F88285EF for ; Wed, 21 Mar 2018 15:34:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06F8D297A6; Wed, 21 Mar 2018 15:34:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4077F285EF for ; Wed, 21 Mar 2018 15:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To: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:List-Owner; bh=GZreTuNRqzFj8TzELXCb0DV9CuWNzpSX+RUbSlRz8T4=; b=dRzMP5e2HIH3nZwY76NTjY3OFY s1OhZjAG8XYmi9/7jMzRhp4H4d/7AuPy/WUvqBEkLfFnCOxWj7RO3NHqLgt9CoGbU5dImBpJ1m8nR XbfDyqeX+A5Lq50IKF1ygoFz0SwmwzqQXpZdnVDWNydUhcweGhJWfnlOZB0l1N7aRe+dZKma8IzjI +NbbbbAUqe0x41XwTkroY6qlrEL9mFt1GPbOmgyAtDZRzjP4/RHoTsQTjhHwwhYx6Zix9qP/kdttf kGP2XrbckqTXXqQdoZLafw8N5p6qjJ4OAuWdMicN0BrlVKcKiXtJ/uX70stg5g208Z1gKEJmR+fBO 7U3Nda9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyfka-0005u5-CP; Wed, 21 Mar 2018 15:34:04 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyfho-000481-Gb for linux-arm-kernel@lists.infradead.org; Wed, 21 Mar 2018 15:31:31 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 3512D208A6; Wed, 21 Mar 2018 16:30:47 +0100 (CET) Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id A34E4203B8; Wed, 21 Mar 2018 16:30:46 +0100 (CET) From: Paul Kocialkowski To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 06/10] drm/sun4i: Move and extend format-related helpers and tables Date: Wed, 21 Mar 2018 16:29:00 +0100 Message-Id: <20180321152904.22411-7-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180321152904.22411-1-paul.kocialkowski@bootlin.com> References: <20180321152904.22411-1-paul.kocialkowski@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180321_083114_012148_DC6336B3 X-CRM114-Status: GOOD ( 18.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Gustavo Padovan , Paul Kocialkowski , Chen-Yu Tsai , Sean Paul , Daniel Vetter , Maxime Ripard MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This moves the various helpers and tables related to format detection and conversion to a dedicated file, while adding a bunch of new helpers (especially for YUV and tiling support) along the way. Signed-off-by: Paul Kocialkowski --- drivers/gpu/drm/sun4i/Makefile | 1 + drivers/gpu/drm/sun4i/sun4i_backend.c | 54 ++-------- drivers/gpu/drm/sun4i/sun4i_format.c | 193 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/sun4i/sun4i_format.h | 35 ++++++ 4 files changed, 235 insertions(+), 48 deletions(-) create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.c create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.h diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile index 582607c0c488..c89c42ff803e 100644 --- a/drivers/gpu/drm/sun4i/Makefile +++ b/drivers/gpu/drm/sun4i/Makefile @@ -4,6 +4,7 @@ sun4i-frontend-y += sun4i_frontend.o sun4i-drm-y += sun4i_drv.o sun4i-drm-y += sun4i_framebuffer.o +sun4i-drm-y += sun4i_format.o sun4i-drm-hdmi-y += sun4i_hdmi_ddc_clk.o sun4i-drm-hdmi-y += sun4i_hdmi_enc.o diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index 1fad0714c70e..e8af9f3cf20b 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -29,6 +29,7 @@ #include "sun4i_drv.h" #include "sun4i_frontend.h" #include "sun4i_layer.h" +#include "sun4i_format.h" #include "sunxi_engine.h" struct sun4i_backend_quirks { @@ -36,50 +37,6 @@ struct sun4i_backend_quirks { bool needs_output_muxing; }; -static const u32 sunxi_rgb2yuv_coef[12] = { - 0x00000107, 0x00000204, 0x00000064, 0x00000108, - 0x00003f69, 0x00003ed6, 0x000001c1, 0x00000808, - 0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808 -}; - -static const u32 sunxi_bt601_yuv2rgb_coef[12] = { - 0x000004a7, 0x00001e6f, 0x00001cbf, 0x00000877, - 0x000004a7, 0x00000000, 0x00000662, 0x00003211, - 0x000004a7, 0x00000812, 0x00000000, 0x00002eb1, -}; - -static inline bool sun4i_backend_format_is_planar_yuv(uint32_t format) -{ - switch (format) { - case DRM_FORMAT_YUV411: - case DRM_FORMAT_YUV422: - case DRM_FORMAT_YUV444: - return true; - default: - return false; - } -} - -static inline bool sun4i_backend_format_is_packed_yuv422(uint32_t format) -{ - switch (format) { - case DRM_FORMAT_YUYV: - case DRM_FORMAT_YVYU: - case DRM_FORMAT_UYVY: - case DRM_FORMAT_VYUY: - return true; - - default: - return false; - } -} - -static inline bool sun4i_backend_format_is_yuv(uint32_t format) -{ - return sun4i_backend_format_is_planar_yuv(format) || - sun4i_backend_format_is_packed_yuv422(format); -} - static void sun4i_backend_apply_color_correction(struct sunxi_engine *engine) { int i; @@ -259,7 +216,7 @@ static int sun4i_backend_update_yuv_format(struct sun4i_backend *backend, SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN, SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN); - if (sun4i_backend_format_is_packed_yuv422(format)) + if (sun4i_format_is_packed_yuv422(format)) val |= SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422; else DRM_DEBUG_DRIVER("Unknown YUV format\n"); @@ -310,7 +267,7 @@ int sun4i_backend_update_layer_formats(struct sun4i_backend *backend, DRM_DEBUG_DRIVER("Switching display backend interlaced mode %s\n", interlaced ? "on" : "off"); - if (sun4i_backend_format_is_yuv(fb->format->format)) + if (sun4i_format_is_yuv(fb->format->format)) return sun4i_backend_update_yuv_format(backend, layer, plane); ret = sun4i_backend_drm_format_to_layer(fb->format->format, &val); @@ -404,7 +361,7 @@ int sun4i_backend_update_layer_buffer(struct sun4i_backend *backend, */ paddr -= PHYS_OFFSET; - if (sun4i_backend_format_is_yuv(fb->format->format)) + if (sun4i_format_is_yuv(fb->format->format)) return sun4i_backend_update_yuv_buffer(backend, fb, paddr); /* Write the 32 lower bits of the address (in bits) */ @@ -549,10 +506,11 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine, DRM_DEBUG_DRIVER("Plane FB format is %s\n", drm_get_format_name(fb->format->format, &format_name)); + if (fb->format->has_alpha) num_alpha_planes++; - if (sun4i_backend_format_is_yuv(fb->format->format)) { + if (sun4i_format_is_yuv(fb->format->format)) { DRM_DEBUG_DRIVER("Plane FB format is YUV\n"); num_yuv_planes++; } diff --git a/drivers/gpu/drm/sun4i/sun4i_format.c b/drivers/gpu/drm/sun4i/sun4i_format.c new file mode 100644 index 000000000000..3830767e6d5b --- /dev/null +++ b/drivers/gpu/drm/sun4i/sun4i_format.c @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2015-2018 Free Electrons/Bootlin + * + * Maxime Ripard + * Paul Kocialkowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "sun4i_drv.h" +#include "sun4i_format.h" + +const u32 sunxi_rgb2yuv_coef[12] = { + 0x00000107, 0x00000204, 0x00000064, 0x00000108, + 0x00003f69, 0x00003ed6, 0x000001c1, 0x00000808, + 0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808 +}; + +const u32 sunxi_bt601_yuv2rgb_coef[12] = { + 0x000004a7, 0x00001e6f, 0x00001cbf, 0x00000877, + 0x000004a7, 0x00000000, 0x00000662, 0x00003211, + 0x000004a7, 0x00000812, 0x00000000, 0x00002eb1, +}; + +bool sun4i_format_is_rgb(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_ARGB4444: + case DRM_FORMAT_RGBA4444: + case DRM_FORMAT_ARGB1555: + case DRM_FORMAT_RGBA5551: + case DRM_FORMAT_RGB888: + case DRM_FORMAT_RGB565: + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ARGB8888: + return true; + + default: + return false; + } +} + +bool sun4i_format_is_yuv(uint32_t format) +{ + return sun4i_format_is_yuv411(format) || + sun4i_format_is_yuv420(format) || + sun4i_format_is_yuv422(format) || + sun4i_format_is_yuv444(format); +} + +bool sun4i_format_is_yuv411(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_YUV411: + case DRM_FORMAT_YVU411: + return true; + + default: + return false; + } +} + +bool sun4i_format_is_yuv420(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV21: + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YVU420: + return true; + + default: + return false; + } +} + +bool sun4i_format_is_yuv422(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_YUYV: + case DRM_FORMAT_YVYU: + case DRM_FORMAT_UYVY: + case DRM_FORMAT_VYUY: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV61: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YVU422: + return true; + + default: + return false; + } +} + +bool sun4i_format_is_yuv444(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU444: + return true; + + default: + return false; + } +} + +bool sun4i_format_is_packed(uint32_t format) +{ + if (sun4i_format_is_rgb(format)) + return true; + + switch (format) { + case DRM_FORMAT_YUYV: + case DRM_FORMAT_YVYU: + case DRM_FORMAT_UYVY: + case DRM_FORMAT_VYUY: + return true; + + default: + return false; + } +} + +bool sun4i_format_is_semiplanar(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV24: + case DRM_FORMAT_NV42: + return true; + default: + return false; + } +} + +bool sun4i_format_is_planar(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_YUV410: + case DRM_FORMAT_YVU410: + case DRM_FORMAT_YUV411: + case DRM_FORMAT_YVU411: + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU444: + return true; + default: + return false; + } +} + +bool sun4i_format_supports_tiling(uint32_t format) +{ + switch (format) { + /* Semiplanar */ + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV61: + /* Planar */ + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YUV411: + case DRM_FORMAT_YVU411: + return true; + + default: + return false; + } +} diff --git a/drivers/gpu/drm/sun4i/sun4i_format.h b/drivers/gpu/drm/sun4i/sun4i_format.h new file mode 100644 index 000000000000..1d6364cd3681 --- /dev/null +++ b/drivers/gpu/drm/sun4i/sun4i_format.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015-2018 Free Electrons/Bootlin + * + * Maxime Ripard + * Paul Kocialkowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef _SUN4I_FORMAT_H_ +#define _SUN4I_FORMAT_H_ + +extern const u32 sunxi_rgb2yuv_coef[12]; +extern const u32 sunxi_bt601_yuv2rgb_coef[12]; + +bool sun4i_format_is_rgb(uint32_t format); +bool sun4i_format_is_yuv(uint32_t format); +bool sun4i_format_is_yuv411(uint32_t format); +bool sun4i_format_is_yuv420(uint32_t format); +bool sun4i_format_is_yuv422(uint32_t format); +bool sun4i_format_is_yuv444(uint32_t format); +bool sun4i_format_is_packed(uint32_t format); +bool sun4i_format_is_semiplanar(uint32_t format); +bool sun4i_format_is_planar(uint32_t format); +bool sun4i_format_supports_tiling(uint32_t format); + +static inline bool sun4i_format_is_packed_yuv422(uint32_t format) +{ + return sun4i_format_is_packed(format) && sun4i_format_is_yuv422(format); +} + +#endif /* _SUN4I_FORMAT_H_ */