From patchwork Fri Feb 16 09:54:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 202044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp406859dyb; Fri, 16 Feb 2024 01:59:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdqN6cZKnDXSBv10i1BzamD7LD2ngNOTuRkwDV4JWLVcdx8XUP4anyeH+F2oLapcN2ymTXEn039KTCAMaerecgk+pPGQ== X-Google-Smtp-Source: AGHT+IF/wg3jp5Ku0wf9ZvrBaijtWMEAcX07S5j9TDEy+9rBO7vlu+y3iE9dh+gEZSQONJ9AGDm+ X-Received: by 2002:a05:620a:383:b0:787:21ed:6990 with SMTP id q3-20020a05620a038300b0078721ed6990mr11540726qkm.39.1708077584329; Fri, 16 Feb 2024 01:59:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708077584; cv=pass; d=google.com; s=arc-20160816; b=VHH5fmuiYAoqrESw3gsmVH53UdP/56+RFjLSq8/dCb1QFPXmxkTnAXAUtOPsAbGJBk ylociwUN0nELT5P9wJMuvd6KiYLSapTbGSfV9TjyhwUhT5C/fTl2JYEE0KFSZTCUW+El f7rvmVPgYyX+JUtPQuFmKMAQBN+yTbUmtuFA0Ezar357LzE8lZ8shUi7T7tSq5GM3Qjq ZGOK6PgB9iUWvkb8PQMEyW0H9KQrWorpmes2SgrhSOxwc+cuQ9izDRl6RLn1VPj7wZb9 HD6I8KtTkK6p5/joxiqMKE9Hv75LnI4naqwuTuRmvEDLAAL7zDMPdxOe4dF7aMECtOFa meiw== ARC-Message-Signature: i=2; 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=hXTmGYt9n5TKxrYtVMIvgmIa7bV7THuMizaLC5xaT2o=; fh=umSzPHAeNmSBhpDl7Ba4ElbET6cYzKRFPeRC9WGHErc=; b=fUkSr0t9g7Q4FYQZVs47UTh9+ou9ciuouPtN6YrzrXalBYgDvVdXXug3usWTam4Jqb OYG3ZXKwkqLP7gU3PWvepvrz9xySv8fi1Awk/xsQp4tAVZxSBjhq+Qb2iNmWUZ15ZNii VSOhRrnnVnhOXo/OgQNM0qd1HVHDeBaAn/d5Ktv5taMDMXrVavwhYutAUOK2AddTcRlO VYMXUJSMoyjZL6EeNKmJMJKGwaK5p1aAocPtFEnkd96tOekV8cPYK4U3YR2oCxi7i7q7 pWyD+gSdIcyBUvQwJStUmA+8HC+lr7/jfy1AenLA0Ow02dCwKt5FXXKyxj6cOY72SZai iQdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=oMj5iiiI; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-68393-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68393-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dt10-20020a05620a478a00b00785d846cf6asi3599870qkb.393.2024.02.16.01.59.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 01:59:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68393-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=oMj5iiiI; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-68393-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68393-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 23B271C2275D for ; Fri, 16 Feb 2024 09:59:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D83AB25774; Fri, 16 Feb 2024 09:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oMj5iiiI" 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 9D91925570; Fri, 16 Feb 2024 09:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708077371; cv=none; b=YVvpENWs5S0yIVcBi8g0Kihf44Fj2jRwxKpvmloVY3VthIyUP/VjJ+Rq/Sb0b1swF+8EKdwYoyoadKWyxn5kW/l3eRPO+NpB3C1iRGvHqryV91p0sDpR9wathsypOeGVZEwydlHwcmFTTVwHExJ5MNixukEnG9VKkx05Z0pQnaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708077371; c=relaxed/simple; bh=d66Y6jd0net+P9o8dHW4ATe683evbx/HzGSWqrs3izc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j3U6+HLnE/IfP9RNYrNLjYybyEzNhbqKK7331NxJDptRDbNnDUVCX7LNqU/8l+Qs9KY7vPbgSoZ4SmDKmUHpCDZl36g9+tioj0GchQgtkNC22IrsVIEUU5ayxtuUU9ksraOd03S4PA0dFxNuBcyV3SEtTj6nm2dDOyA6ezE8aV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=oMj5iiiI; arc=none smtp.client-ip=213.167.242.64 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 (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E115513AC; Fri, 16 Feb 2024 10:55:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708077364; bh=d66Y6jd0net+P9o8dHW4ATe683evbx/HzGSWqrs3izc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMj5iiiI6QfxgHjSF1ZDJFPCzlkYudGSB8RqP3LRTSM5/Y0gJdSaWY41J9KKFLsJ7 RiMO3dJ7kjJ8s33GnkGZxdd2teUjBONCnTmmhU1CW+ZN3CjMPjnQWH/XFQetHaMhN+ SWet91o+4D43Sqf/97/H78hj6qPGBvV4HMZqzQ2s= 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 v12 10/12] media: rkisp1: Add UYVY as an output format Date: Fri, 16 Feb 2024 18:54:56 +0900 Message-Id: <20240216095458.2919694-11-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240216095458.2919694-1-paul.elder@ideasonboard.com> References: <20240216095458.2919694-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: 1791049160958060843 X-GMAIL-MSGID: 1791049160958060843 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 --- Changes in v12: - replace MI_OUTPUT_FORMAT feature flag with MAIN_STRIDE --- .../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 99375e08b503..64b1d1104e20 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_has_feature(rkisp1, MAIN_STRIDE)) { + 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_has_feature(rkisp1, MAIN_STRIDE)) { + 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);