From patchwork Fri Mar 11 07:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 550644 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B4CEC433F5 for ; Fri, 11 Mar 2022 07:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347214AbiCKHxi (ORCPT ); Fri, 11 Mar 2022 02:53:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346780AbiCKHxi (ORCPT ); Fri, 11 Mar 2022 02:53:38 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2087.outbound.protection.outlook.com [40.107.22.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE4231DD0; Thu, 10 Mar 2022 23:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GqqsjVK28CfMfzRUQh86mLAsRHATIVXXSPsDZmYiZFf0fRYohIp9eVBnTC2eSZTpWBvMRq7ub+1WoAMYgkwOjLqzhl/pcVA5HojLdZPDKZq0/jtvaILXaPgcydbK26AinVA2VFZDZao73AOCj95pCR6NojCApMGzSwiqPOSzbAxiq99k7ur02S4HCsCgIIczbzY7fz3HlIO/3lIEfmGgPYakydAJtF7hWODZosQNFewW9yXQlcRHt+EEATsQeOHQvnz3cu1vShEX2DBAqG2BoUwOuxVUIeXxZ1mxmDIFu/NnRUf7ynR9GksjhNLKMXkfzM9l8PqoABEBGgJKHCEfqA== 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=VE9QcKGDoUZhfJe4o47yAi9yM9BKIcAXhlDwk+vQ/74=; b=hc4kelUFIYgdcRIeCXyCkNNdmUwnkIJCoWSf/vbMDv+UVxw9knVwHXf3LOg2zYq+afi0IhbQF9SSObQ46aMg3lGOXtq2AeXvHNsABsuLX6tUHynOhbUhYt06ucxrxcJY/9s6qzAa2fVD1S/A8YUPwNRm4DKHFddWeNBUToX6xlro3gSKvqOSX95sbT0n6zT53vsJVAZbQKdPa6y8z2nsjxn6VEwWn4b/S60kgkFxKGgmK9j+UBcAxdDO9RTTdu+J8os0LqbCc0X7W/HKq77+0qkMgM8i/uLqKQ6KnhzaMkM9PD/4Y5jf5v5YMpGQkgfeSD+OKx8g2PGtk/dgmwLB7A== 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=VE9QcKGDoUZhfJe4o47yAi9yM9BKIcAXhlDwk+vQ/74=; b=q729wGKZXwOSzoV74M1+sjgoVESnsyA0j17PtzGY3hvgaTlcToNxdSLovrDdYBfoc0Ofd21y0pJ9z+hlDkrd3Wl6rmgV86B39tw0OwWo1DZ09JGZI7x0Qk0qKR+aoFU9cOsYynhf6kgdRb4o9coAi0GQ+uiHbzBXMsQ5ihJ2Eqg= 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:31 +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:31 +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 2/5] media: imx-jpeg: Identify and handle precision correctly Date: Fri, 11 Mar 2022 15:51:44 +0800 Message-Id: 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: b88abc27-3188-4735-4e1f-08da033418b1 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: 1m9purfkm2vOqhSdvNO68oya4rtVBFVyXfZgLGEL9KA27NseaRMgGmfY+41POQ2Okrn2qwSh7G/ElYPHNQ1FsTVwCsOV4NnNSbYUibTXYEmNz4mXKh+Tv5lVC4u6UHVlcg53zZuad3QTvpBUmTdXnUa91TdxptrKJ/95WY+8XT8vtbaf1UwocHpqCvxNsezNzyCSdWKE4aldqjlEIhZ5WdZsCA8FlARqhYMDSZ9Bln0Px0CIdXQd2SQXmXFlrZQBpksFsaA89H+HzDDsi4131yJoLcE3kUNbYANdoupSkp6DPLsCkNebC9ebivCW4WF/eoo6uMOPZW6iFZ2rlpX4LchmrHkNZ4MazzXIMWTh2XLcf5h6AIktSsdbLeKaZRLq30haKXPN2wYbJmwuc9idzbpIcov6HOXSp0hFBSw001H16uGth7NRBhpYD8Tpk2ptXf0Kj4lAUcTxzVBaYqgGbTU040i13sxC8S6oNt7/UJYok0Je7Eotd5meoHtx69V1jA83hgq7Q8EPscZEF5fUCkNfA0lQi9gv5o3QX+KM7u9/8xItVaXp1fsxKaQ9Rus3PbuINGsOy8Uq23cr5RbgoJSgv6EjKd3WA61k2kRr6rv2EiesB+xD2dQpzOf60iPtH5vuRULBChK7ZsLqavZ5VrvtEPE9KesPD4teFZjL/3aHst3D9FnyzZc+YxNZ98T8V3/6l4N75Op+fSpxq0HNdA== 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: s2tVwOUIQznyeevss/SAUXbElkGAFHbjm+YyxPPI4Vn17GhwkvOkX6MsgYqeMiYawpcwJAL1jtJyUf7LYQ+R2Y+sYFR8/N6F9tL+PATGDsda97MGF+JG4mxkf5Sb7MRMY5MbbB4BvJA6aAQUJoUNSIo5wEbnlGRLvCV3s3vsf18r69UBpkRn9FGBvrcxX2Ay3hhvZavNvovhRnFvzPD3tsEzZsv0k6WvFx3uMot3BNZaDZG5H6WKfNQsZjU4KYOF3hGdewzkYm54OeZrN9asI0Cm3H66ifdoSGYGQKQHbJN+JTloncKRzW9AK/EhdKyKydVbW8Pbipw2dGZWfI+Kguxqcydsi/nE9S9QQGWHR8WG8AAisNmYvTO8TSTKcZXdUvrlqqH+FCoQnZKIaQE8ZV3ihpgmXJ6RMonQ+lXeEzfmZGqwdMkUohUWQ2OPLo8trwrDjcjbtNo3CL51G0RmGBy12lKdEpkhb4Ha8g7KX/9IWvHVF59wzHRITHWZUM8n7jeFAVA40XEMRJayvYS5Z3uihHEFyL6ALDMCeuKHSA0UC+1PbzaoCUZX0DcfJ2TwvkawmYxZk2eyYxphopjB+HC/RcxoXph2aLJNNQRzu1N8IMlGOUM8cu8w0ETEPI9tjCtKAS75wkU/oXAba+0GnsJHoixWTau0SHt6iPgl4gcx34mpEpOdhEiuoW742IV9zqyGMh21xi/xbzobJpj4cKhIzJB/waeJzB9FviG9tXe92zXy37uGZg5xAchcL6LItPhhAGwHwgoNj2jii9L4AbZz2Dqy3pmyY6Bj4u/zWA6+nfTImFP3fTLfeDOdy6cujNzkRYIeu78mlFpX7FcuoYy7NLipFDURn71DB1p4rz2pQMtjht7Nfuk7jVgb4iTaHT9fndxkykwFjyOWUfTvLE6smNZhAxoRDakNfvD+ev8eBNnzYQGjxrtWcg8KzYjlNTSpZ2bkJOhSShodszhSpU6qOwDgY/IPFxF6CfJwAosiQhMRcx3NiWaRbEinhI8czqHdlP+0PRzins9DEjcerarcblvZxHlmzTe+qFjJdjhw4GP/PanNPqcg6vIBEzDY4k+3UdWX933Js2gNvzEhIC4+fR9XQGXzoo1gi8ywqzCR8SXOAFulRPw6H8mlfMkyCBtcVetJDnyihZT2yAgTv31od7w1GqPnoXsdVM/7ftxVZtEYWgRWKg5Ee+EdpCzee5FrGKcSKSnaM8cNMAJlRy2yE7QMcIkjdTtUzXG5oICVMuhYoP+6LH/dXYdMQ8CtGVBM9zcL8UaHhEQW36VvZS+dTNeAafFkx8rasRfG/iik7vcrpsNuxx/hs8y7e1OVwJtcsnmLqzLQSOdr8YTEnriIsyo2xS3AULM6YJjoyrjRwdghTDOrCUJ5/EEQt5b3zcl7EcBtikSWkKLUJYmScZARWWO5kMFG0qlqGG2BmNhQ2s1yRYYJgfpJ+4ueNL4LQNsGOzWYvWVJhCDQD2sZSenduwMrOlOc+/0zzCR6Pe4WiYF2HIV9HrwOUjCXzEIod+zndyXS+kvVXya6HgdDZWpTJNfKnSWPhgYcROYv/J8/zElxWOR2MvRm3hNoMshQAQUPgLzulPatMpwNVDyGskH6Z0QR5KQ2L5D9KwSs36I= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b88abc27-3188-4735-4e1f-08da033418b1 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:31.5364 (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: xZXK1wC0UGnSNHHR9C/qVzIe/Y3VBfRGvpegw45uJazzQ/E7tfDIujyBZ7ZzujCh6kZfiGL6bVkppVz1nrNHDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The decoder will save the precision that was detected from jpeg header and use it later, when choosing the pixel format and also calculate bytesperline according to precision. The 12bit jpeg is not supported yet, but driver shouldn't led to serious problem if user enqueue a 12 bit jpeg. And the 12bit jpeg is supported by hardware, driver may support it later. Signed-off-by: Ming Qian --- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 37 +++++++++++++++------- drivers/media/platform/imx-jpeg/mxc-jpeg.h | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index d8d24c19f423..82b9b4630d9c 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c @@ -82,6 +82,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "ARGB", /* ARGBARGB packed format */ @@ -93,6 +94,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV420", /* 1st plane = Y, 2nd plane = UV */ @@ -104,6 +106,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 4, .v_align = 4, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV422", /* YUYV */ @@ -115,6 +118,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 4, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV444", /* YUVYUV */ @@ -126,6 +130,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "Gray", /* Gray (Y8/Y12) or Single Comp */ @@ -137,6 +142,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, }; @@ -1175,14 +1181,17 @@ static u32 mxc_jpeg_get_image_format(struct device *dev, for (i = 0; i < MXC_JPEG_NUM_FORMATS; i++) if (mxc_formats[i].subsampling == header->frame.subsampling && - mxc_formats[i].nc == header->frame.num_components) { + mxc_formats[i].nc == header->frame.num_components && + mxc_formats[i].precision == header->frame.precision) { fourcc = mxc_formats[i].fourcc; break; } if (fourcc == 0) { - dev_err(dev, "Could not identify image format nc=%d, subsampling=%d\n", + dev_err(dev, + "Could not identify image format nc=%d, subsampling=%d, precision=%d\n", header->frame.num_components, - header->frame.subsampling); + header->frame.subsampling, + header->frame.precision); return fourcc; } /* @@ -1208,18 +1217,22 @@ static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, /* bytesperline unused for compressed formats */ q->bytesperline[0] = 0; q->bytesperline[1] = 0; - } else if (q->fmt->fourcc == V4L2_PIX_FMT_NV12M) { + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420) { /* When the image format is planar the bytesperline value * applies to the first plane and is divided by the same factor * as the width field for the other planes */ - q->bytesperline[0] = q->w * (precision / 8) * - (q->fmt->depth / 8); + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8); q->bytesperline[1] = q->bytesperline[0]; + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_422) { + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8) * 2; + q->bytesperline[1] = 0; + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_444) { + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8) * q->fmt->nc; + q->bytesperline[1] = 0; } else { - /* single plane formats */ - q->bytesperline[0] = q->w * (precision / 8) * - (q->fmt->depth / 8); + /* grayscale */ + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8); q->bytesperline[1] = 0; } } @@ -1353,7 +1366,7 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) (fourcc >> 24) & 0xff); /* setup bytesperline/sizeimage for capture queue */ - mxc_jpeg_bytesperline(q_data_cap, header.frame.precision); + mxc_jpeg_bytesperline(q_data_cap, q_data_cap->fmt->precision); mxc_jpeg_sizeimage(q_data_cap); /* @@ -1509,7 +1522,7 @@ static void mxc_jpeg_set_default_params(struct mxc_jpeg_ctx *ctx) q[i]->h = MXC_JPEG_DEFAULT_HEIGHT; q[i]->w_adjusted = MXC_JPEG_DEFAULT_WIDTH; q[i]->h_adjusted = MXC_JPEG_DEFAULT_HEIGHT; - mxc_jpeg_bytesperline(q[i], 8); + mxc_jpeg_bytesperline(q[i], q[i]->fmt->precision); mxc_jpeg_sizeimage(q[i]); } } @@ -1651,7 +1664,7 @@ static int mxc_jpeg_try_fmt(struct v4l2_format *f, const struct mxc_jpeg_fmt *fm } /* calculate bytesperline & sizeimage into the tmp_q */ - mxc_jpeg_bytesperline(&tmp_q, 8); + mxc_jpeg_bytesperline(&tmp_q, fmt->precision); mxc_jpeg_sizeimage(&tmp_q); /* adjust user format according to our calculations */ diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/imx-jpeg/mxc-jpeg.h index f53f004ba851..82b38cc2dfab 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.h @@ -60,6 +60,7 @@ struct mxc_jpeg_fmt { int h_align; int v_align; u32 flags; + u8 precision; }; struct mxc_jpeg_desc { 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: 550643 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A62BCC43217 for ; Fri, 11 Mar 2022 07:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347282AbiCKHxq (ORCPT ); Fri, 11 Mar 2022 02:53:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347277AbiCKHxo (ORCPT ); Fri, 11 Mar 2022 02:53:44 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2063.outbound.protection.outlook.com [40.107.22.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25554BB577; Thu, 10 Mar 2022 23:52:42 -0800 (PST) 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/dCfmQOunXbLj38D9okJ5QynuOHQBddnyGELBp2TfMESjDAhvgoGjeWsJg4JgOwY5yYsPoqqiC4C3CJJr4L8udFu8bRI7PUtY01XUpS6nF9boiRrMQ8rVwKtDYMjL3K067vPSYwMbXnuPLnsXGw2YXj453rlAe2LsmSmPi+Nx7YeQxuhwhDPqUf6hcVO9tFzKUc28z/A+ltT0cLjJvs4B8JC3ZQbA3jVrOidgCmVMzFIdemk6engvNosz/YsJo2b4Y6fi56YjzBIDU1QiNGvBYKblS1IBmmaeolKGi+jgeY0TPl5Zzk8xk5vEK3Q+ajc2ZaiQSQPtJUBHwRbjYMpA3OKtlVHZFNeK8I+LkcGWVUUstadQgUFTMELrpEhemMBSesyhOcmcuIpXMp/Nnw696oGWaBxidiGSyWtWLAU635NSnt0yejNIbunsviDHErVnBGC3CR8N6snNA0BtAXNbCtqF20S/2Qu+zwsqI/ZkUmBb5TyGUW8OKQVGN98bg6BsFUZHl/hXaNVI95k0QJ2mE7s+9USi8K2RcAb2cyGTJAH6oGryQdVXisTbrxACBkzjl5Oc2zp+hTK0Ro8c6U9c/IhL0cTvfFGW60WkzK7BqGZYS1Ib+QiojEpNgmzBbDzAVZHpW6110ebct+k/q/e03ytt/X6IvHeft0nGrZB/IJbQQpr/ZIJW2zrUP6+6qLAckY1WPJpOUHQHEaALVIRmW5fR3tXAF6oT+o4klVyRyz6mEzAkZk/DgW2lGEUlQOjSJ0/ogWV+mmIsbPe7f6yjK/BTw/dER6dfIAD8eFHFpi4PUrtk4TZmK1T39n6LVVb3K7cl42UetyjhGF0hIQHHuq81tz71Vv5rHrHrl7/JcMBf5hyP8FewnACsHNK8eAc4PU3Q4o8vxd41W3+RNvE3ECqhQxhh4LO9vco9OjY4+bAo0jwPz/hMEUIdc4jTscMjZbQZCxT41hLmQNQOxUnXfq31mFhEi81f5dmP3xo2zwcU02QPBIoO0bLOPFQV8Xk66sScbfq/VI8HZ/Lwl65COVklj6gNhncMmqZ4hs7C64MSnczLSJrTVG0gdspPJ8zeLRY8mN0S/D3MMoptJy6SvtYm0+r2Niwl3nOBqXTRVPOeE0rrvbRVNWRgXhlunIP3/TiqUYpLKRZF4iNo= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30850c2e-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 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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; }