From patchwork Sat Jan 6 16:02:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 185656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp177235dyq; Sat, 6 Jan 2024 08:09:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGszoSQGlWtYncC3Mxny+2dhUVeaQVEreOEITPoSxALt+meIOfpJrG/aZokzY7rceUMtvNc X-Received: by 2002:a05:6e02:3883:b0:360:5cd9:a73e with SMTP id cn3-20020a056e02388300b003605cd9a73emr1941057ilb.6.1704557365346; Sat, 06 Jan 2024 08:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704557365; cv=none; d=google.com; s=arc-20160816; b=RqdRiE1Gw27alwVvpkYiUuFMWP+FMd/IV+ZbPJc/c4UylDlk/qSZCZ1w+NYOB/dBEZ ACM95VhGfYopdkoem1r/AHiDG35dhqx67EOQvnBnohj9a3pYfYK/vX5tgpqawRAlgvpX 7+AvYwyqgzGWN5Xdnbx9N3kPLhbwp5MXjN5iylzhuF/sKVKTTUCU53dCZYZZ/cV2aJWh Toz5Q62gz8afK0Jg3dHlJddIG88Ro8JJXcCH/XlPf9SSYCljqtQ+ckm9F9Sfj8bvk5yR bfRauJcXanvJOx45he+WopOaSxaWKE/1BdRCahVaNuXBXHvIFI1olSG2ar1YptQQrwti mfhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LBniWurhVJMg7RN5vSUiud6SLCDfADyTt0XrsrIV8P8=; fh=umSzPHAeNmSBhpDl7Ba4ElbET6cYzKRFPeRC9WGHErc=; b=Imp2YP7XiUMxTgMZNiOJSz09pEpNOk5sJ7IrrpwdNq6WH7phE4Ed7vopn9kzPAfYNB 27+Dhs95mFMSVIHFSZn+bmQGtzp7k2Y+PeyaDlJ9BqU/ZtQxBHJD6OkwaY7EHeSdONtG lxDRE+L12LwTB6ixbmxmeplqKr9mW/MjwQVIEHouICDZNCBF8vz0m72/xRO4cgiBc0+3 GHsTuLF6jVesTPzrjYapIA3P/0eyVCeV4TlD5jhBwfoFOe/z4nId2jsST/yV5TybQ/xP 0bcBa2/+Kt6HgQKNOVArIJm2jBcxCaOSCCiZQoCeLaDwHNNQi+V/cbibcIjh92R8/2OO yfWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=HWLmgqeb; spf=pass (google.com: domain of linux-kernel+bounces-18649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18649-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i188-20020a639dc5000000b005ce52da910asi3219604pgd.259.2024.01.06.08.09.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 08:09:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=HWLmgqeb; spf=pass (google.com: domain of linux-kernel+bounces-18649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18649-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D7F78B20AB0 for ; Sat, 6 Jan 2024 16:07:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD6D62D63A; Sat, 6 Jan 2024 16:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HWLmgqeb" X-Original-To: linux-kernel@vger.kernel.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1A99847B; Sat, 6 Jan 2024 16:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pyrite.hamster-moth.ts.net (unknown [IPv6:2001:268:c203:a8ee:6c57:4243:1eb3:6cb]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 67DB812E4; Sat, 6 Jan 2024 17:02:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1704556973; bh=K70IzSs6vgDWbdrp4Sy/MWQlESNUan8JBoy4snxEayc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HWLmgqebQOpbEax9JDjt/0c9uqPfpNQLkVU7nc6IMCWscDRvH6pM9uvXx/lxfTsCc vHNHltwgBjZmd/i3KA9EhEnf3v9tZ3l5Pz5BgALPdE/aXd0YsU0cmNWVJoMy+DlXKm Mr7YbGSmtMyGZ15fSQaLG0Z4ejgG8WjqHdQa95U0= From: Paul Elder To: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org Cc: kieran.bingham@ideasonboard.com, tomi.valkeinen@ideasonboard.com, umang.jain@ideasonboard.com, aford173@gmail.com, Paul Elder , Laurent Pinchart , Alexander Stein , Dafna Hirschfeld , Mauro Carvalho Chehab , Heiko Stuebner , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 10/10] media: rkisp1: Add UYVY as an output format Date: Sun, 7 Jan 2024 01:02:21 +0900 Message-Id: <20240106160221.4183409-11-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240106160221.4183409-1-paul.elder@ideasonboard.com> References: <20240106160221.4183409-1-paul.elder@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787357944325421458 X-GMAIL-MSGID: 1787357944325421458 Add support for UYVY as an output format. The uv_swap bit in the MI_XTD_FORMAT_CTRL register that is used for the NV formats does not work for packed YUV formats. Thus, UYVY support is implemented via byte-swapping. This method clearly does not work for implementing support for YVYU and VYUY. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Tested-by: Alexander Stein Tested-by: Adam Ford --- .../platform/rockchip/rkisp1/rkisp1-capture.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index bf63f78dc48c..813d4274f118 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -97,6 +97,12 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_mp_fmts[] = { .uv_swap = 0, .write_format = RKISP1_MI_CTRL_MP_WRITE_YUVINT, .mbus = MEDIA_BUS_FMT_YUYV8_2X8, + }, { + .fourcc = V4L2_PIX_FMT_UYVY, + .uv_swap = 0, + .yc_swap = 1, + .write_format = RKISP1_MI_CTRL_MP_WRITE_YUVINT, + .mbus = MEDIA_BUS_FMT_YUYV8_2X8, }, { .fourcc = V4L2_PIX_FMT_YUV422P, .uv_swap = 0, @@ -231,6 +237,13 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = { .write_format = RKISP1_MI_CTRL_SP_WRITE_INT, .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422, .mbus = MEDIA_BUS_FMT_YUYV8_2X8, + }, { + .fourcc = V4L2_PIX_FMT_UYVY, + .uv_swap = 0, + .yc_swap = 1, + .write_format = RKISP1_MI_CTRL_SP_WRITE_INT, + .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422, + .mbus = MEDIA_BUS_FMT_YUYV8_2X8, }, { .fourcc = V4L2_PIX_FMT_YUV422P, .uv_swap = 0, @@ -464,6 +477,20 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap) rkisp1_write(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL, reg); } + /* + * U/V swapping with the MI_XTD_FORMAT_CTRL register only works for + * NV12/NV21 and NV16/NV61, so instead use byte swap to support UYVY. + * YVYU and VYUY cannot be supported with this method. + */ + if (rkisp1->info->features & RKISP1_FEATURE_MI_OUTPUT_ALIGN) { + reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT); + if (cap->pix.cfg->yc_swap) + reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES; + else + reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES; + rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg); + } + rkisp1_mi_config_ctrl(cap); reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL); @@ -507,6 +534,20 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap) rkisp1_write(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL, reg); } + /* + * U/V swapping with the MI_XTD_FORMAT_CTRL register only works for + * NV12/NV21 and NV16/NV61, so instead use byte swap to support UYVY. + * YVYU and VYUY cannot be supported with this method. + */ + if (rkisp1->info->features & RKISP1_FEATURE_MI_OUTPUT_ALIGN) { + reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT); + if (cap->pix.cfg->yc_swap) + reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES; + else + reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES; + rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg); + } + rkisp1_mi_config_ctrl(cap); mi_ctrl = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL);