From patchwork Fri Mar 11 07:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777582 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 600BEC433F5 for ; Fri, 11 Mar 2022 07:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XD0Nqy7yZFPf5Nu/1CcHFxQL4NB9XcmiLmzoIeuOsvY=; b=P3dFLBXJyoVqP9 b5YqDB8kooyO/Z+d/EpU+ARJgVXxuIDXxm+e/RTWezRd5dMPcNXvveGkoPs147LtUtqUTW8xhOfin /jF41YUht7Uk3/Hzf+S6xSLZy/CeI+8rpkFCw4Qp2fm56FzWqxnmXBwt8QiQZV3memgb4kaFLbm+m 9urwIeToLJkP1ANSLDpNfDdpx/aomjpomAklIxFZFq5DT8tdzHXk8OEJgiYwrTeSCXr2E5fy4pKJH 2myHVpHvsv9D/KuVUKMkch4vHQC5wRdGLNjW3Eex0NUvIaLu44QJiO20TC7wHlvPqkmlh5SQ2tTNC bzI9qFn07HEQYCpX9nbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa5T-00FP2q-0A; Fri, 11 Mar 2022 07:53:23 +0000 Received: from mail-vi1eur05on20607.outbound.protection.outlook.com ([2a01:111:f400:7d00::607] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4n-00FOj7-Kt for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fRm44I/AqO9i8oVtGjoAwz2HuHuwAZoKhtckuycJBZhd71WEL09F0m6U1Rw7HNZIHJxcoleGrlOLNN2rWU4aej574zb+tZkJvOXETmx/USo3SlemG2+UaAZyVkymAaqnousF/KQY+qHFDohpCrWzXyg9oTZtFTBOwlAIKyYOGfOXqmUhxY7IviTo4vcC719jdwv/zbm/ktO2JL6gS8QUEJaYFVuJnJawAYbKCQgeoDaUbygv/Tv5URN7nwLvsuia+zRI6FKHnWCfyncntESDb+51gusvS3Wu6+B0fkLEwiohjcm7gTOM8nkZM3DqjLJkE1FoDstlgrL90u4/19Zgow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1bUeLjEYNurmQmNiZYNV+D5rwdXTOYZz+osKmYIV90w=; b=Kg5MoKNn9rL2TRgKWNW7kQ1KSHK9H2ElYHjcRiPCNJ4ZwVld/3BU34Rqp5po99eFq2lW8HydXbi+VADQ4ze4bpstH+oVpw3ovBVr2n/UMDbiymlmsP2FczgIpFYUv2oIRdY8bhuy9dIQ4r7+ApUjmK3OUfxe14qIcKpAUwMVeNhufTqv1eKbYKIJEdukuCRpBMeGDInyMA/IxJ6kiATEC5VjFZwWfVgjTODNgZqWh142d1IMSzBOJNBwoDDB9pVXaMgPdc65vrJdb03rKqe61z+sxX0quokBmlFWecpa97VnZo1dmLKisY2D1He8wj0noeIA9xSC3OZZfy/SssIIOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1bUeLjEYNurmQmNiZYNV+D5rwdXTOYZz+osKmYIV90w=; b=PaiJ9PTGv3shDqUNYwUTVm6yaX0R9c65tbJYzLcltEz0UHBNMEVVtXepYZqL4mFDhGDhojyTIni86AAhUBoKAZOZn2E73Woi/GBB05ZaguVwxOcW/CAoYJ85sGk/y2tgDBc4vAbye2s+uluBygQlzsGIYxaVRwjmkHeHKhyumYg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:39 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5061.022; Fri, 11 Mar 2022 07:52:39 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/5] media: imx-jpeg: Handle source change in a function Date: Fri, 11 Mar 2022 15:51:46 +0800 Message-Id: <538ff8ce60241c4a0729f1a518ecf0ee74291cad.1646983646.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30850c2e-1e6e-419b-57dd-08da03341d59 X-MS-TrafficTypeDiagnostic: DB7PR04MB4443:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2+gU6ocIV+wTQVqOW8Ks62vZZwlmllE3GIasfR/y9d/wlb1Aim4oB54VHl66fJab/mRfKKf/gu4Aj0XZnDWflAlNBZ6JJwso2oe9XTvOkT7/Eoullt2XEO1c6gEhIm2KalfJROkss7cmoM/vEKaVKFfBeUU7a3nq456uzsmjAMGYqpCZJBzrKGUbMeX+AsDqqBs2o76teeqsorNklJObweuzJNkUTUdjx//R7qm6ml8YYrdyUPDBwS20kmGgY6dLke0MMpdymNmHtomXig4AZZderMO5tNou2u2CwiVgtFnJ2XcZOfGhvkivAC16fHUWZ5H0pH7tIcGd7kGBMWoiUk9VvRsrPgjGzixDL7G1+ZK8bXmG3j9kUxqgzKdebwlgg8B67NdgKdfabuanAlzOm06dhP3Ahl7xJlyHkLQwPhsV8mjcD93sFFQzbBFPdYd0EyT+zKNflRvR/pSQZPyfSs1OjKZH0haMi6zTXFyNq4Uf0ANMvwxC3ZJVEa8HAYdcWsGivDshDaIl7w1s60ZRH3SyTgPyTS7kgSvAnIcEt/SzVykGD1rBoR8dlXR3AovG2KrYqox+plmNWRxrz6LAMUA/cq/IaXO3idI2X+bq43iw4Xcigg0a204FAF7eEXMILjHZ6dTWLQRdClCiXAXmynbZFuluhXOUx24Rm6wWELHuCJlEJSZ3lAtjA7R6bQ187Lj9rjECtbp3qOLbYJPUWQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(6666004)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lSUSLUlp6c0ydu3iCkuC/4WxPiVYmJ5KJWB+Z6T5fCKZeJiR+ThR58vdFsAuB36/8t8/XBfA4ZHqXmFm96xvKGnxNzx0UJz4imTmwwd4dvVQJ6v+tgMVv+L92fqrfJ3C8I6YTlfDaBJGiGLbH4GqoCAkyvjjUrVEgKIgsew71c6cTcR8Bm9qCUZfvUREOMzHccrHclaT1ju8UPsTWpJ878tm3GRKP9Ttlx0ssl/UEeAkL5qGl3JiHNgZydCeiPB026Ppwq5f8Ob1FGTGGdCx5GfKGOhco1JVCms3Er4eB/e16n9dsoNTdUpV7P8xZFHwR0A8oNQguBG9B8WKkN91KG2mLVQPu2/85FCmBfTDZ09Cs8FqGzF+12ja/GF+nNf49bSfCF4mg4fY4I4uPTAr4Q/DdsdRNP4ZwStuJNyQFos/aVvS33RP2F3pbKQUcodFjEJ/2mAP0To7jZclnS3N7GeqXB/dCfmQOunXbLj38D9okJ5QynuOHQBddnyGELBp2TfMESjDAhvgoGjeWsJg4JgOwY5yYsPoqqiC4C3CJJr4L8udFu8bRI7PUtY01XUpS6nF9boiRrMQ8rVwKtDYMjL3K067vPSYwMbXnuPLnsXG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e-1e6e-419b-57dd-08da03341d59 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:39.3798 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: phK7j6usU1LQ3yOUbHD2nH32ciBcLJs8PaUD07oj/BsQFTM6TE3CFN9+lGM7GSKHX/jq3sxLiaKnEMgmNbQC1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235241_747550_EBA6CA3F X-CRM114-Status: GOOD ( 19.82 ) 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 Refine code to support dynamic resolution change Signed-off-by: Ming Qian --- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 114 ++++++++++++--------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index 9e8a4157ce2f..dbcb83ed86e4 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c @@ -315,6 +315,9 @@ struct mxc_jpeg_src_buf { /* mxc-jpeg specific */ bool dht_needed; bool jpeg_parse_error; + const struct mxc_jpeg_fmt *fmt; + int w; + int h; }; static inline struct mxc_jpeg_src_buf *vb2_to_mxc_buf(struct vb2_buffer *vb) @@ -327,6 +330,9 @@ static unsigned int debug; module_param(debug, int, 0644); MODULE_PARM_DESC(debug, "Debug level (0-3)"); +static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision); +static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q); + static void _bswap16(u16 *a) { *a = ((*a & 0x00FF) << 8) | ((*a & 0xFF00) >> 8); @@ -922,6 +928,59 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf, mxc_jpeg_set_desc(cfg_desc_handle, reg, slot); } +static bool mxc_jpeg_source_change(struct mxc_jpeg_ctx *ctx, + struct mxc_jpeg_src_buf *jpeg_src_buf) +{ + struct device *dev = ctx->mxc_jpeg->dev; + struct mxc_jpeg_q_data *q_data_cap; + bool src_chg = false; + + if (!jpeg_src_buf->fmt) + return src_chg; + + q_data_cap = mxc_jpeg_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); + if (q_data_cap->w != jpeg_src_buf->w || q_data_cap->h != jpeg_src_buf->h) { + dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n", + q_data_cap->w, q_data_cap->h, + jpeg_src_buf->w, jpeg_src_buf->h, + (jpeg_src_buf->fmt->fourcc & 0xff), + (jpeg_src_buf->fmt->fourcc >> 8) & 0xff, + (jpeg_src_buf->fmt->fourcc >> 16) & 0xff, + (jpeg_src_buf->fmt->fourcc >> 24) & 0xff); + + /* + * set-up the capture queue with the pixelformat and resolution + * detected from the jpeg output stream + */ + q_data_cap->w = jpeg_src_buf->w; + q_data_cap->h = jpeg_src_buf->h; + q_data_cap->fmt = jpeg_src_buf->fmt; + q_data_cap->w_adjusted = q_data_cap->w; + q_data_cap->h_adjusted = q_data_cap->h; + + /* + * align up the resolution for CAST IP, + * but leave the buffer resolution unchanged + */ + v4l_bound_align_image(&q_data_cap->w_adjusted, + q_data_cap->w_adjusted, /* adjust up */ + MXC_JPEG_MAX_WIDTH, + q_data_cap->fmt->h_align, + &q_data_cap->h_adjusted, + q_data_cap->h_adjusted, /* adjust up */ + MXC_JPEG_MAX_HEIGHT, + q_data_cap->fmt->v_align, + 0); + + /* setup bytesperline/sizeimage for capture queue */ + mxc_jpeg_bytesperline(q_data_cap, jpeg_src_buf->fmt->precision); + mxc_jpeg_sizeimage(q_data_cap); + notify_src_chg(ctx); + src_chg = true; + } + return src_chg; +} + static void mxc_jpeg_device_run(void *priv) { struct mxc_jpeg_ctx *ctx = priv; @@ -1209,8 +1268,7 @@ static u32 mxc_jpeg_get_image_format(struct device *dev, return fourcc; } -static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, - u32 precision) +static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision) { /* Bytes distance between the leftmost pixels in two adjacent lines */ if (q->fmt->fourcc == V4L2_PIX_FMT_JPEG) { @@ -1261,9 +1319,7 @@ static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q) static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) { struct device *dev = ctx->mxc_jpeg->dev; - struct mxc_jpeg_q_data *q_data_out, *q_data_cap; - enum v4l2_buf_type cap_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; - bool src_chg = false; + struct mxc_jpeg_q_data *q_data_out; u32 fourcc; struct v4l2_jpeg_header header; struct mxc_jpeg_sof *psof = NULL; @@ -1331,51 +1387,11 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) if (fourcc == 0) return -EINVAL; - /* - * set-up the capture queue with the pixelformat and resolution - * detected from the jpeg output stream - */ - q_data_cap = mxc_jpeg_get_q_data(ctx, cap_type); - if (q_data_cap->w != header.frame.width || - q_data_cap->h != header.frame.height) - src_chg = true; - q_data_cap->w = header.frame.width; - q_data_cap->h = header.frame.height; - q_data_cap->fmt = mxc_jpeg_find_format(ctx, fourcc); - q_data_cap->w_adjusted = q_data_cap->w; - q_data_cap->h_adjusted = q_data_cap->h; - /* - * align up the resolution for CAST IP, - * but leave the buffer resolution unchanged - */ - v4l_bound_align_image(&q_data_cap->w_adjusted, - q_data_cap->w_adjusted, /* adjust up */ - MXC_JPEG_MAX_WIDTH, - q_data_cap->fmt->h_align, - &q_data_cap->h_adjusted, - q_data_cap->h_adjusted, /* adjust up */ - MXC_JPEG_MAX_HEIGHT, - q_data_cap->fmt->v_align, - 0); - dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n", - q_data_cap->w, q_data_cap->h, - q_data_cap->w_adjusted, q_data_cap->h_adjusted, - (fourcc & 0xff), - (fourcc >> 8) & 0xff, - (fourcc >> 16) & 0xff, - (fourcc >> 24) & 0xff); - - /* setup bytesperline/sizeimage for capture queue */ - mxc_jpeg_bytesperline(q_data_cap, q_data_cap->fmt->precision); - mxc_jpeg_sizeimage(q_data_cap); + jpeg_src_buf->fmt = mxc_jpeg_find_format(ctx, fourcc); + jpeg_src_buf->w = header.frame.width; + jpeg_src_buf->h = header.frame.height; - /* - * if the CAPTURE format was updated with new values, regardless of - * whether they match the values set by the client or not, signal - * a source change event - */ - if (src_chg) - notify_src_chg(ctx); + mxc_jpeg_source_change(ctx, jpeg_src_buf); return 0; }