From patchwork Sat Aug 17 22:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Walklin X-Patchwork-Id: 13767253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29D49C531DF for ; Sat, 17 Aug 2024 23:09:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=13AqpIHPg5Y1XhIqrtTCrpm+qCMBR2w7AqF/IsKkc6E=; b=Q11j/8qq6LAUyNDvaA7dcWCgDn pqEYtf1R5zPtYKP6UyEIP/SH0UM/AZAX+CGNIeyX6NNw9XRz1SZQMoxiJ1C7NdqgdE1QkCWJYNuq5 ZMaE40zILu3ErJTYjLIWT0gS0IYfk0KmveBWHdVDlryvO3IpaMU79niaTaI199lii4TgRlM8HNk7l jwtcVXRFqdTL4YnlwX7WovPdQIotTVXIIHDaKJQ/fYQ3HkY72trnvN6WBrrS5y2gsjygpYGo8gGUO cfK+poQ8/MklD0hbZgNMrqpeEtAwzWy6rQ+XQIO2IeyOcVW9LM4qldT/29/pYRHchEGxx9fzItRpt w+Jif9fQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfSY4-0000000FqdL-0jYW; Sat, 17 Aug 2024 23:09:28 +0000 Received: from fhigh1-smtp.messagingengine.com ([103.168.172.152]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfSUx-0000000Fq0K-1EVz for linux-arm-kernel@lists.infradead.org; Sat, 17 Aug 2024 23:06:16 +0000 Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9B4AF114A9F2; Sat, 17 Aug 2024 19:06:14 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sat, 17 Aug 2024 19:06:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=testtoast.com; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1723935974; x= 1724022374; bh=13AqpIHPg5Y1XhIqrtTCrpm+qCMBR2w7AqF/IsKkc6E=; b=B aXyCQKV2JipwzFvleAkjSGUDaJH7y+LccL+grDlSK8W6fNF7GK79f1SBxc+yBJqH P0ueBauR6KA7cQMRI3d4BEX1hFjSOvwQIH+1ZKcGweIIxQCZWIdu9kXVrVBJMH8d oKV0E+wkP/qt1l08s6R7tu5NPIoJ3ZPmeGkM0hHPo78xbzOZKXogjmqcN4KcUsr2 sat6SPxmPZ64LLXSXJrCPdbAzaVxh69t1Dn7oCWREUePzrz9h/vB6XWEqSjtO5rB iRXpRK1o7ErQaCyYgphXRripb1NsKcCe+ij81soK0A0FRNnAE81p1gavOi6T+0Vv kTydbA5KJUeXUuvKHL9Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1723935974; x= 1724022374; bh=13AqpIHPg5Y1XhIqrtTCrpm+qCMBR2w7AqF/IsKkc6E=; b=n p9AK9AHxPSNiUhwcr1MXMdxddBMcW7gNtxVlHycDxQIuufVH4ogqRKlZ+OZisDgS 2R+2uC/ijxFmSEARa5MGf980b9Vx3tJ7OXmgAQv9q5oj6eqiMtIdjYyqkIyCQULu RhnPZhC5vUUPkDjAZSCIlPl1u8sMWcN0wwpuKB9tSHOcokGfsyKQLDB/pYI0ZU63 aAACSumdXIgQwU5F19ZpLxpBRg8kv/bZ40gqQ0iJykkI/uNTAAP7fPqgbuLu0H3s 7mi7+RjaHEnBD0PP+f9/SMYFR6gfvUC9f8l2ig05GyHvF5zk3YCbuvlHHhyAzmNw WU/uyxFw9OMpNN3G8mSQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduuddgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheptfihrghnucghrghlkhhlihhnuceorhihrghnsehtvghsthhtohgrshhtrd gtohhmqeenucggtffrrghtthgvrhhnpeffheeiffegtdfgffejteevgeefkeelieelkeev ueetffetteduffevgeeiieehteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehrhigrnhesthgvshhtthhorghsthdrtghomhdpnhgspghrtghp thhtohepvddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmrhhiphgrrhguse hkvghrnhgvlhdrohhrghdprhgtphhtthhopeifvghnshestghsihgvrdhorhhgpdhrtghp thhtohepmhgrrghrthgvnhdrlhgrnhhkhhhorhhstheslhhinhhugidrihhnthgvlhdrtg homhdprhgtphhtthhopehtiihimhhmvghrmhgrnhhnsehsuhhsvgdruggvpdhrtghpthht oheprghirhhlihgvugesghhmrghilhdrtghomhdprhgtphhtthhopegurghnihgvlhesfh hffihllhdrtghhpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhl rdgtohhmpdhrtghpthhtohepshgrmhhuvghlsehshhholhhlrghnugdrohhrghdprhgtph htthhopehrohgshheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: idc0145fc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 17 Aug 2024 19:06:07 -0400 (EDT) From: Ryan Walklin To: Maxime Ripard , Chen-Yu Tsai , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jernej Skrabec , Samuel Holland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Turquette , Stephen Boyd Cc: Andre Przywara , Chris Morgan , John Watts , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, Ryan Walklin Subject: [PATCH v3 05/26] drm: sun4i: de3: Add YUV formatter module Date: Sun, 18 Aug 2024 10:45:52 +1200 Message-ID: <20240817230503.158889-6-ryan@testtoast.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240817230503.158889-1-ryan@testtoast.com> References: <20240817230503.158889-1-ryan@testtoast.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240817_160615_513092_548055BA X-CRM114-Status: GOOD ( 15.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jernej Skrabec The display engine formatter (FMT) module is present in the DE3 engine and provides YUV444 to YUV422/YUV420 conversion, format re-mapping and color depth conversion. Add support for this module. Signed-off-by: Jernej Skrabec Signed-off-by: Ryan Walklin --- drivers/gpu/drm/sun4i/Makefile | 3 +- drivers/gpu/drm/sun4i/sun50i_fmt.c | 82 ++++++++++++++++++++++++++++++ drivers/gpu/drm/sun4i/sun50i_fmt.h | 32 ++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/sun4i/sun50i_fmt.c create mode 100644 drivers/gpu/drm/sun4i/sun50i_fmt.h diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile index bad7497a0d11e..3f516329f51ee 100644 --- a/drivers/gpu/drm/sun4i/Makefile +++ b/drivers/gpu/drm/sun4i/Makefile @@ -16,7 +16,8 @@ sun8i-drm-hdmi-y += sun8i_hdmi_phy_clk.o sun8i-mixer-y += sun8i_mixer.o sun8i_ui_layer.o \ sun8i_vi_layer.o sun8i_ui_scaler.o \ - sun8i_vi_scaler.o sun8i_csc.o + sun8i_vi_scaler.o sun8i_csc.o \ + sun50i_fmt.o sun4i-tcon-y += sun4i_crtc.o sun4i-tcon-y += sun4i_tcon_dclk.o diff --git a/drivers/gpu/drm/sun4i/sun50i_fmt.c b/drivers/gpu/drm/sun4i/sun50i_fmt.c new file mode 100644 index 0000000000000..050a8716ae862 --- /dev/null +++ b/drivers/gpu/drm/sun4i/sun50i_fmt.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) Jernej Skrabec + */ + +#include + +#include "sun50i_fmt.h" + +static bool sun50i_fmt_is_10bit(u32 format) +{ + switch (format) { + case MEDIA_BUS_FMT_RGB101010_1X30: + case MEDIA_BUS_FMT_YUV10_1X30: + case MEDIA_BUS_FMT_UYYVYY10_0_5X30: + case MEDIA_BUS_FMT_UYVY10_1X20: + return true; + default: + return false; + } +} + +static u32 sun50i_fmt_get_colorspace(u32 format) +{ + switch (format) { + case MEDIA_BUS_FMT_UYYVYY8_0_5X24: + case MEDIA_BUS_FMT_UYYVYY10_0_5X30: + return SUN50I_FMT_CS_YUV420; + case MEDIA_BUS_FMT_UYVY8_1X16: + case MEDIA_BUS_FMT_UYVY10_1X20: + return SUN50I_FMT_CS_YUV422; + default: + return SUN50I_FMT_CS_YUV444RGB; + } +} + +static void sun50i_fmt_de3_limits(u32 *limits, u32 colorspace, bool bit10) +{ + if (colorspace != SUN50I_FMT_CS_YUV444RGB) { + limits[0] = SUN50I_FMT_LIMIT(64, 940); + limits[1] = SUN50I_FMT_LIMIT(64, 960); + limits[2] = SUN50I_FMT_LIMIT(64, 960); + } else if (bit10) { + limits[0] = SUN50I_FMT_LIMIT(0, 1023); + limits[1] = SUN50I_FMT_LIMIT(0, 1023); + limits[2] = SUN50I_FMT_LIMIT(0, 1023); + } else { + limits[0] = SUN50I_FMT_LIMIT(0, 1021); + limits[1] = SUN50I_FMT_LIMIT(0, 1021); + limits[2] = SUN50I_FMT_LIMIT(0, 1021); + } +} + +void sun50i_fmt_setup(struct sun8i_mixer *mixer, u16 width, + u16 height, u32 format) +{ + u32 colorspace, limit[3], base; + struct regmap *regs; + bool bit10; + + colorspace = sun50i_fmt_get_colorspace(format); + bit10 = sun50i_fmt_is_10bit(format); + base = SUN50I_FMT_DE3; + regs = sun8i_blender_regmap(mixer); + + sun50i_fmt_de3_limits(limit, colorspace, bit10); + + regmap_write(regs, SUN50I_FMT_CTRL(base), 0); + + regmap_write(regs, SUN50I_FMT_SIZE(base), + SUN8I_MIXER_SIZE(width, height)); + regmap_write(regs, SUN50I_FMT_SWAP(base), 0); + regmap_write(regs, SUN50I_FMT_DEPTH(base), bit10); + regmap_write(regs, SUN50I_FMT_FORMAT(base), colorspace); + regmap_write(regs, SUN50I_FMT_COEF(base), 0); + + regmap_write(regs, SUN50I_FMT_LMT_Y(base), limit[0]); + regmap_write(regs, SUN50I_FMT_LMT_C0(base), limit[1]); + regmap_write(regs, SUN50I_FMT_LMT_C1(base), limit[2]); + + regmap_write(regs, SUN50I_FMT_CTRL(base), 1); +} diff --git a/drivers/gpu/drm/sun4i/sun50i_fmt.h b/drivers/gpu/drm/sun4i/sun50i_fmt.h new file mode 100644 index 0000000000000..4127f7206aade --- /dev/null +++ b/drivers/gpu/drm/sun4i/sun50i_fmt.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) Jernej Skrabec + */ + +#ifndef _SUN50I_FMT_H_ +#define _SUN50I_FMT_H_ + +#include "sun8i_mixer.h" + +#define SUN50I_FMT_DE3 0xa8000 + +#define SUN50I_FMT_CTRL(base) ((base) + 0x00) +#define SUN50I_FMT_SIZE(base) ((base) + 0x04) +#define SUN50I_FMT_SWAP(base) ((base) + 0x08) +#define SUN50I_FMT_DEPTH(base) ((base) + 0x0c) +#define SUN50I_FMT_FORMAT(base) ((base) + 0x10) +#define SUN50I_FMT_COEF(base) ((base) + 0x14) +#define SUN50I_FMT_LMT_Y(base) ((base) + 0x20) +#define SUN50I_FMT_LMT_C0(base) ((base) + 0x24) +#define SUN50I_FMT_LMT_C1(base) ((base) + 0x28) + +#define SUN50I_FMT_LIMIT(low, high) (((high) << 16) | (low)) + +#define SUN50I_FMT_CS_YUV444RGB 0 +#define SUN50I_FMT_CS_YUV422 1 +#define SUN50I_FMT_CS_YUV420 2 + +void sun50i_fmt_setup(struct sun8i_mixer *mixer, u16 width, + u16 height, u32 format); + +#endif