From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796544661; b=T1c+QsRH7mxPP4eXiukxA+2ERacAZuoEVDLYO0npQ7b1dT2wV3v4x6j8G6yCSVxCMKW/ qt0ZKxOCB/1zkBSmzGNHS7HVO/KHieOPNCWkuNCPNUQ97TlLFgi+9hD6G34maanfwWesq sEhLBbDCCg6v5fuG6/Lnc8pQo4ES7jQNkpDc2dsRZ37hIPCFyiF7vGsabPcpAyK7sYvxx YzjCWrMQNw8qYznGmouI/+TjcY2FDD0P3hPccMTPOsl93ZiEwxTuS4k5gTcj3bduU13Yj s2j53+Aboaduk5gJOK/PKxjNL8kKGi9gRJOz99PnYX11TqkHmhby90p6nHzHVrAJ+3g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796544661; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=ZUwtGVnCkM35Mugta/xiDisiQ8tZglibgUGQLJv4I/4=; b=OofG+zlNuEgA8pzcHHQWANM8/NRUPX0Z0XSQSPZhDzauKlY5cNugIYGXWiejm4xSyzlF R/cBoVstUCv++VsXewWn0w56qHoeHiOPetrFbberxpMt/bhSTucDYOzb/0PufnU5CeNtR NodW7b8GUboBVYA+rh4nUWeTptNf7MQ3ehSeJkaAPCzCU3puoKNlPvb9WuH5LAYga5pRO XfwK7AQZkgFxpjrflPqmyuW8ONtscWBlsHhzDHn346IQWRzs+zJ/8dwkK5pS2YSTAeysV LdWjgwPWzlzxXiTaqVJ9jUe4FAm8QI35ZXcZy30T42yd3fDbZHRLVrn9H8HtELN/JgA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kFob26fz; arc=none smtp.remote-ip=209.85.210.182 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D109606A31F for ; Sun, 6 Dec 2026 08:11:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9D109606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kFob26fz Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8e0fb8ca55aso107542b3a.3 for ; Sun, 06 Dec 2026 00:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796544660; x=1797149460; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZUwtGVnCkM35Mugta/xiDisiQ8tZglibgUGQLJv4I/4=; b=kFob26fz+qvqhUUf6CE31uHEcv6eNyL7Qf481pp7YaLhHhnlUSgDosSkabDcm22uRc PbaKoKkMWUSPJmpHpSCttqvCyWiOcAHWG/CLdZfh2VDpRiRNjr+3wzBK/gs7RND754vZ wdeBp20SLdnZcAHfcBECrIoJ7sZmWrkATAqUACu9LsAqY2xi89a+wbE3ryNXW/sfIZLc 7golnyFKNoPy401dzBSiLvZYDNjDvEABN9Pofn6Xt1OMsD2gwK/PgomX697LhSlrHcVw w6bndVPN9Ou0O2Bz+XYls0JZbNOweejAZe/d3uiA7tbhazhpE4UxN3hLMtb3dJetLjU3 MJug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796544660; x=1797149460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZUwtGVnCkM35Mugta/xiDisiQ8tZglibgUGQLJv4I/4=; b=hPvcOAjSlX1TqSpI2Hi6I2UTY2qezO/eoVRUJL7/KXqf+HPU3KHve7j15VgRa22BkH F/kawMqqakJOMtFA0sSsBhTnPiEBasGTWKz3tpsBuR8deoZTMLAzfKElmr4XUdHPOs8Z XlIJwDaJzdEiS7neXFqW4URm9Xg7Le5SBKDzBR5wEcYMy1oJ4vwC/f9ngIlhW1ejedv2 fN8BdLzy9vPZmJui3bJsiDFtboWIUWizN4Px/ta9HUaPg22SMKX+SbUVTZ+aMTslSKEv WMKpdl4Z+rvLbmJK+PCsjX4V/UyrCsXDLNFY6MbN/WbGaUBoVfE90Csvmjr6nU8WP/VF dsIg== X-Forwarded-Encrypted: i=1; AL+hErG1ZRcuNXqYfeGQj/Owznm4ia0DoUnnKXJ1VmLM1dItv6IGUrOu8tCdq2TeOrO5ahocZD41mKL2bOCoA4w=@vger.kernel.org X-Gm-Message-State: AB4q+uHt5aW2h+gWK+J02t/sHZ9JjY1rSuqXrTmoWzBYX43kLsKxzdu7 zYB+mri3dV8YHDRAaKR76D2AiiuLAPrGw9KTGJ7LI+r44pq1o0kISDzy X-Gm-Gg: AZFdTZey9ZFqSV0HGviYAIKdSf+TCcvH0I8qMCY4xxZaOWZ7PuxHpKKg9qWqT2L6Fui aJvhBYFupIK3ygXSEbGW5XdImnQjBxgAzstzBDaiEME2xA/R7i1RBSNQnKrqtnjlRafe7fBvthp inIG2PGCZAhU77WRgsGHzSkg8b3+uPvAcSurGbZD6KDu6G5JnYN0c+uFhpfvnD1wW3vNfEm1zsN A6eJlM3RT/HWan7OI3srQpt/h2IRj0Fd5m3leedku0haxw6PMJz66bsphuhkXl1FS41Z1Mvha7i xhQMEaqS7UZQbcTHjazbRN/o0b7xuK2uIuNNUBSp4xGfudQ2+OLG9jwD7u6uqSR8D7AbTZBcGSW m02PLhCMyCb8x8ThSYJNx1vQOksxxEfhPBjqpJDqqcOUslHJ9MRMwJP043tmpyghfPn7dvZR+hO 8Bs1jUJSZWjQ1UEC1X1YfgDnx6QtNvTfeh3ar1OsNBue8wZQs5wLBsLl9a/YYy9V6IZU52IgbrH 18Xhg5fk1HmBlr13FoNlMfrvt7ZDFx4aqIDoOvPFXf4CnrajS8+WDwGYC2d911XkfODPCMmDzAV VSWV2ANNk06Mk7RmrJSVTidGeiMCKKaE/5xNpZzs90TqwCTHncLz3V28oGaOF+wJO235fhR3/Sr xaCV93Z6SLvYXLLJQVhhmlp2MbKkxwoE3PMYGgwcheH4pwqunrVhNPgXnEsHMrw== X-Received: by 2002:a17:90a:e703:b0:3b4:c66c:ba01 with SMTP id 98e67ed59e1d1-3b5e06a4485mr6694869a91.50.1796544659931; Sun, 06 Dec 2026 00:10:59 -0800 (PST) Received: from hostname.tail4fb79.ts.net ([2401:7400:c804:b668:a144:150d:733a:5ba2]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d78d88sm17613202a91.13.2026.12.06.00.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 00:10:59 -0800 (PST) From: Ho Jie Feng To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , linux-kernel@vger.kernel.org Subject: [PATCH v4 1/4] drm/format-helper: Add XRGB8888 to UYVY conversion Date: Sun, 6 Dec 2026 16:10:11 +0800 Message-ID: <20261206081017.109737-2-hjf3108@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261206081017.109737-1-hjf3108@gmail.com> References: <20261206081017.109737-1-hjf3108@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a helper for devices that use packed UYVY but accept XRGB8888 framebuffers. Signed-off-by: Ho Jie Feng --- drivers/gpu/drm/drm_format_helper.c | 50 +++++++++++++++++++++++++++ drivers/gpu/drm/drm_format_internal.h | 19 ++++++++++ include/drm/drm_format_helper.h | 4 +++ 3 files changed, 73 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index 6cddf05c493b..7e5cbb60508e 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -1379,3 +1379,53 @@ void drm_fb_xrgb8888_to_gray2(struct iosys_map *dst, const unsigned int *dst_pit } EXPORT_SYMBOL(drm_fb_xrgb8888_to_gray2); +static void drm_fb_xrgb8888_to_uyvy_line(void *dbuf, const void *sbuf, unsigned int pixels) +{ + __le32 *dbuf32 = dbuf; + const __le32 *sbuf32 = sbuf; + const __le32 *send32 = sbuf32 + pixels; + + while (sbuf32 < send32) { + u32 pix1 = le32_to_cpup(sbuf32); + u32 pix2 = le32_to_cpup(sbuf32 + 1); + u32 val32 = drm_pixel_xrgb8888_to_uyvy_bt601(pix1, pix2); + + *dbuf32++ = cpu_to_le32(val32); + sbuf32 += 2; + } +} + +/** + * drm_fb_xrgb8888_to_uyvy - Convert XRGB8888 to UYVY clip buffer + * @dst: Array of UYVY destination buffers + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines + * within @dst; can be NULL if scanlines are stored next to each other. + * @src: Array of XRGB8888 source buffers + * @fb: DRM framebuffer + * @clip: Clip rectangle area to copy; x1 and x2 must be even + * @state: Transform and conversion state + * + * This function copies parts of a framebuffer to display memory and converts the + * color format during the process. The parameters @dst, @dst_pitch and @src refer + * to arrays. Each array must have at least as many entries as there are planes in + * @fb's format. Each entry stores the value for the format's respective color plane + * at the same index. + * + * This function does not apply clipping on @dst (i.e. the destination is at the + * top-left corner). + * + * Drivers can use this function for UYVY devices that don't support XRGB8888 + * natively. ITU BT.601 is being used for the RGB -> YUV conversion. + */ +void drm_fb_xrgb8888_to_uyvy(struct iosys_map *dst, const unsigned int *dst_pitch, + const struct iosys_map *src, const struct drm_framebuffer *fb, + const struct drm_rect *clip, struct drm_format_conv_state *state) +{ + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { + 2, + }; + + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state, + drm_fb_xrgb8888_to_uyvy_line); +} +EXPORT_SYMBOL(drm_fb_xrgb8888_to_uyvy); diff --git a/drivers/gpu/drm/drm_format_internal.h b/drivers/gpu/drm/drm_format_internal.h index ce29dd05bcc5..41875656e59e 100644 --- a/drivers/gpu/drm/drm_format_internal.h +++ b/drivers/gpu/drm/drm_format_internal.h @@ -159,6 +159,25 @@ static inline u32 drm_pixel_xrgb8888_to_abgr2101010(u32 pix) drm_pixel_xrgb8888_to_xbgr2101010(pix); } +static inline u32 drm_pixel_xrgb8888_to_uyvy_bt601(u32 pix1, u32 pix2) +{ + u32 r1 = (pix1 & 0x00ff0000) >> 16; + u32 g1 = (pix1 & 0x0000ff00) >> 8; + u32 b1 = pix1 & 0x000000ff; + u32 r2 = (pix2 & 0x00ff0000) >> 16; + u32 g2 = (pix2 & 0x0000ff00) >> 8; + u32 b2 = pix2 & 0x000000ff; + u32 r = r1 + r2; + u32 g = g1 + g2; + u32 b = b1 + b2; + u32 y1 = ((16U << 16) + 16829 * r1 + 33039 * g1 + 6416 * b1 + 32768) >> 16; + u32 y2 = ((16U << 16) + 16829 * r2 + 33039 * g2 + 6416 * b2 + 32768) >> 16; + u32 u = ((128U << 17) - 9714 * r - 19071 * g + 28784 * b + 65536) >> 17; + u32 v = ((128U << 17) + 28784 * r - 24103 * g - 4681 * b + 65536) >> 17; + + return u | (y1 << 8) | (v << 16) | (y2 << 24); +} + /* * Conversion from ARGB8888 */ diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h index 2b5c1aef80b0..e50f96e07484 100644 --- a/include/drm/drm_format_helper.h +++ b/include/drm/drm_format_helper.h @@ -136,4 +136,8 @@ void drm_fb_xrgb8888_to_gray2(struct iosys_map *dst, const unsigned int *dst_pit const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip, struct drm_format_conv_state *state); +void drm_fb_xrgb8888_to_uyvy(struct iosys_map *dst, const unsigned int *dst_pitch, + const struct iosys_map *src, const struct drm_framebuffer *fb, + const struct drm_rect *clip, struct drm_format_conv_state *state); + #endif /* __LINUX_DRM_FORMAT_HELPER_H */ -- 2.55.0