From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from comms.puri.sm (comms.puri.sm [159.203.221.185]) (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 0138F2C83 for ; Sun, 17 Oct 2021 11:08:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 88E56DFAAA; Sun, 17 Oct 2021 04:08:44 -0700 (PDT) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d2kKGqEIxJ38; Sun, 17 Oct 2021 04:08:43 -0700 (PDT) Date: Sun, 17 Oct 2021 13:08:37 +0200 From: Dorota Czaplejewicz To: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@puri.sm, phone-devel@vger.kernel.org Subject: [PATCHv2 4/4] media: imx: Use dedicated format handler for i.MX7/8 Message-ID: <20211017102904.756408-4-dorota.czaplejewicz@puri.sm> In-Reply-To: <20211017102904.756408-1-dorota.czaplejewicz@puri.sm> References: <20211017102904.756408-1-dorota.czaplejewicz@puri.sm> Organization: Purism Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/UChzlzgPs98xJxK1DilnSN2"; protocol="application/pgp-signature"; micalg=pgp-sha256 --Sig_/UChzlzgPs98xJxK1DilnSN2 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable This splits out a format handler which takes into account the capabilities of the i.MX7/8 video device, as opposed to the default handler compatible with both i.MX5/6 and i.MX7/8. Signed-off-by: Dorota Czaplejewicz --- drivers/staging/media/imx/imx-media-utils.c | 78 +++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/= media/imx/imx-media-utils.c index e124dd722107..938db2e2ddb1 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -516,10 +516,9 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framef= mt *tryfmt, } EXPORT_SYMBOL_GPL(imx_media_try_colorimetry); =20 -int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - const struct v4l2_mbus_framefmt *mbus, - const struct imx_media_pixfmt *cc, - enum imx_device_type type) +static int imx56_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, + const struct v4l2_mbus_framefmt *mbus, + const struct imx_media_pixfmt *cc) { u32 width; u32 stride; @@ -568,6 +567,77 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_form= at *pix, =20 return 0; } + +static int imx78_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, + const struct v4l2_mbus_framefmt *mbus, + const struct imx_media_pixfmt *cc) +{ + u32 width; + u32 stride; + u8 divisor; + + if (!cc) { + cc =3D imx_media_find_ipu_format(mbus->code, + PIXFMT_SEL_YUV_RGB); + if (!cc) + cc =3D imx_media_find_mbus_format(mbus->code, + PIXFMT_SEL_ANY); + if (!cc) + return -EINVAL; + } + + /* + * TODO: the IPU currently does not support the AYUV32 format, + * so until it does convert to a supported YUV format. + */ + if (cc->ipufmt && cc->cs =3D=3D IPUV3_COLORSPACE_YUV) { + u32 code; + + imx_media_enum_mbus_formats(&code, 0, PIXFMT_SEL_YUV); + cc =3D imx_media_find_mbus_format(code, PIXFMT_SEL_YUV); + } + + /* + * The hardware can handle line lengths divisible by 4 bytes, + * as long as the number of lines is even. + * Otherwise, use the value of 8 bytes recommended in the datasheet. + */ + divisor =3D 4 << (mbus->height % 2); + + width =3D round_up(mbus->width, divisor); + + if (cc->planar) + stride =3D round_up(width, 16); + else + stride =3D round_up((width * cc->bpp) >> 3, divisor); + + pix->width =3D width; + pix->height =3D mbus->height; + pix->pixelformat =3D cc->fourcc; + pix->colorspace =3D mbus->colorspace; + pix->xfer_func =3D mbus->xfer_func; + pix->ycbcr_enc =3D mbus->ycbcr_enc; + pix->quantization =3D mbus->quantization; + pix->field =3D mbus->field; + pix->bytesperline =3D stride; + pix->sizeimage =3D cc->planar ? ((stride * pix->height * cc->bpp) >> 3) : + stride * pix->height; + + return 0; +} + +int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, + const struct v4l2_mbus_framefmt *mbus, + const struct imx_media_pixfmt *cc, + enum imx_device_type type) { + switch (type) { + case DEVICE_TYPE_IMX56: + return imx56_media_mbus_fmt_to_pix_fmt(pix, mbus, cc); + case DEVICE_TYPE_IMX78: + return imx78_media_mbus_fmt_to_pix_fmt(pix, mbus, cc); + } + return -EINVAL; +} EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_pix_fmt); =20 void imx_media_free_dma_buf(struct device *dev, --=20 2.31.1 --Sig_/UChzlzgPs98xJxK1DilnSN2 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEExKRqtqfFqmh+lu1oADBpX4S8ZncFAmFsBDUACgkQADBpX4S8 Znd5lw/+IqabIiFF8Lz73MM9TgWmsrSufcFzhPHP1cFb/+I6o1hqNbn6XdPKexKR I0vGqlHHNV2eFOksDZThEHlKZihp8ZS3PEt+WISJGVjY636uKgQkZ/DYZT5AjV+P Cdf6mh4x1+Ma/QV1gtyQbAL/eLekP4LChUEq6vL3kRG1ZCRGpEWjyVf/qeKYWq45 si/324AOrvMm8/2bLjiY/SSsB0CIDAr6SwMSP2a6/kuNWbeOE1iCtlFRHsXPqZIH rPxM8m3yVOjwQaakw1pt5VSNLdpmaXHPLzgEb+N6UAceFWogHgVihTA6ZmvLAo5s VmwiySl3OPZAY4YFtQtys6vstQXsiWOiDoDkevCF4dM13qCAUjqsvHfk0uyQ35L7 bBF+q1I8FXzAxvwGiCixQeYwhGK6BGe9fjStd9G/GP/M4jHxMZ0rofIOIIVPqQGF CqQBNksvX9E2TwHcnIkWWP22PdnJImz77Scb2pH+uzgiydtJLrNWkrR8dKLFdJnB d39bvbxtab7QutBm4SsEvwweR+OnFwmmjcR3E34gnK9YrlaaDXY8EFD5sWkt5o4L Wu3xTs5J6a0jdg3YBBk1QoPhXNf/pFW29kXYhHvqjiOj8/kOnuiaheO9//twM3FR SNzUZ5Xk1/ut9E5zndrNyOTlCI/Y6Vks7uD6OzMlgstAqDBH64Q= =dYEO -----END PGP SIGNATURE----- --Sig_/UChzlzgPs98xJxK1DilnSN2-- From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E137C433EF for ; Sun, 17 Oct 2021 11:09:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DD69661245 for ; Sun, 17 Oct 2021 11:09:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD69661245 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=puri.sm Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:References:In-Reply-To:Message-ID:Subject:To:From:Date:Reply-To: Cc:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QoJO0rAW4MX8u/7TX0J2Ue9vEBmy1l5WCIHSHe82Vxg=; b=ZBzIYykbD1C6BIeu7+i9MrI5w0 tYUD8uKRhYlW0DgoJOt988AAFLrMhV5KYu0FOkz/VYY3GmlVGlbShTZAHbmU07RRGQYW+fZlpHzSI eKqLBIwxOwQxbBqM3pGGvgDJJWM66DayQefReC4HKAvhkNrwl/puGmEqU2xhzNY+bvKfGdcwhTXpC yg8Fu2APaKy4F0c1GvA7x0hyU7TXLg+5tz1uN3KvHPeiG5J+AfWf7yIqNSOErnal6ifLn89qe7SnZ m15wcjEscSyaQri99kkKT+lQ6BiP5NZplXoNzUh3ZMV/Q2N71IMY5BdkF4N012uHX/8TogzN+HL6h 5y4MGePg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc424-00CB6S-M2; Sun, 17 Oct 2021 11:08:48 +0000 Received: from comms.puri.sm ([159.203.221.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc420-00CB5E-Rl for linux-arm-kernel@lists.infradead.org; Sun, 17 Oct 2021 11:08:46 +0000 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 88E56DFAAA; Sun, 17 Oct 2021 04:08:44 -0700 (PDT) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d2kKGqEIxJ38; Sun, 17 Oct 2021 04:08:43 -0700 (PDT) Date: Sun, 17 Oct 2021 13:08:37 +0200 From: Dorota Czaplejewicz To: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@puri.sm, phone-devel@vger.kernel.org Subject: [PATCHv2 4/4] media: imx: Use dedicated format handler for i.MX7/8 Message-ID: <20211017102904.756408-4-dorota.czaplejewicz@puri.sm> In-Reply-To: <20211017102904.756408-1-dorota.czaplejewicz@puri.sm> References: <20211017102904.756408-1-dorota.czaplejewicz@puri.sm> Organization: Purism MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_040844_931154_07CAACEC X-CRM114-Status: GOOD ( 14.97 ) 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: , Content-Type: multipart/mixed; boundary="===============6423927073094526657==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============6423927073094526657== Content-Type: multipart/signed; boundary="Sig_/UChzlzgPs98xJxK1DilnSN2"; protocol="application/pgp-signature"; micalg=pgp-sha256 --Sig_/UChzlzgPs98xJxK1DilnSN2 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable This splits out a format handler which takes into account the capabilities of the i.MX7/8 video device, as opposed to the default handler compatible with both i.MX5/6 and i.MX7/8. Signed-off-by: Dorota Czaplejewicz --- drivers/staging/media/imx/imx-media-utils.c | 78 +++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/= media/imx/imx-media-utils.c index e124dd722107..938db2e2ddb1 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -516,10 +516,9 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framef= mt *tryfmt, } EXPORT_SYMBOL_GPL(imx_media_try_colorimetry); =20 -int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - const struct v4l2_mbus_framefmt *mbus, - const struct imx_media_pixfmt *cc, - enum imx_device_type type) +static int imx56_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, + const struct v4l2_mbus_framefmt *mbus, + const struct imx_media_pixfmt *cc) { u32 width; u32 stride; @@ -568,6 +567,77 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_form= at *pix, =20 return 0; } + +static int imx78_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, + const struct v4l2_mbus_framefmt *mbus, + const struct imx_media_pixfmt *cc) +{ + u32 width; + u32 stride; + u8 divisor; + + if (!cc) { + cc =3D imx_media_find_ipu_format(mbus->code, + PIXFMT_SEL_YUV_RGB); + if (!cc) + cc =3D imx_media_find_mbus_format(mbus->code, + PIXFMT_SEL_ANY); + if (!cc) + return -EINVAL; + } + + /* + * TODO: the IPU currently does not support the AYUV32 format, + * so until it does convert to a supported YUV format. + */ + if (cc->ipufmt && cc->cs =3D=3D IPUV3_COLORSPACE_YUV) { + u32 code; + + imx_media_enum_mbus_formats(&code, 0, PIXFMT_SEL_YUV); + cc =3D imx_media_find_mbus_format(code, PIXFMT_SEL_YUV); + } + + /* + * The hardware can handle line lengths divisible by 4 bytes, + * as long as the number of lines is even. + * Otherwise, use the value of 8 bytes recommended in the datasheet. + */ + divisor =3D 4 << (mbus->height % 2); + + width =3D round_up(mbus->width, divisor); + + if (cc->planar) + stride =3D round_up(width, 16); + else + stride =3D round_up((width * cc->bpp) >> 3, divisor); + + pix->width =3D width; + pix->height =3D mbus->height; + pix->pixelformat =3D cc->fourcc; + pix->colorspace =3D mbus->colorspace; + pix->xfer_func =3D mbus->xfer_func; + pix->ycbcr_enc =3D mbus->ycbcr_enc; + pix->quantization =3D mbus->quantization; + pix->field =3D mbus->field; + pix->bytesperline =3D stride; + pix->sizeimage =3D cc->planar ? ((stride * pix->height * cc->bpp) >> 3) : + stride * pix->height; + + return 0; +} + +int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, + const struct v4l2_mbus_framefmt *mbus, + const struct imx_media_pixfmt *cc, + enum imx_device_type type) { + switch (type) { + case DEVICE_TYPE_IMX56: + return imx56_media_mbus_fmt_to_pix_fmt(pix, mbus, cc); + case DEVICE_TYPE_IMX78: + return imx78_media_mbus_fmt_to_pix_fmt(pix, mbus, cc); + } + return -EINVAL; +} EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_pix_fmt); =20 void imx_media_free_dma_buf(struct device *dev, --=20 2.31.1 --Sig_/UChzlzgPs98xJxK1DilnSN2 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEExKRqtqfFqmh+lu1oADBpX4S8ZncFAmFsBDUACgkQADBpX4S8 Znd5lw/+IqabIiFF8Lz73MM9TgWmsrSufcFzhPHP1cFb/+I6o1hqNbn6XdPKexKR I0vGqlHHNV2eFOksDZThEHlKZihp8ZS3PEt+WISJGVjY636uKgQkZ/DYZT5AjV+P Cdf6mh4x1+Ma/QV1gtyQbAL/eLekP4LChUEq6vL3kRG1ZCRGpEWjyVf/qeKYWq45 si/324AOrvMm8/2bLjiY/SSsB0CIDAr6SwMSP2a6/kuNWbeOE1iCtlFRHsXPqZIH rPxM8m3yVOjwQaakw1pt5VSNLdpmaXHPLzgEb+N6UAceFWogHgVihTA6ZmvLAo5s VmwiySl3OPZAY4YFtQtys6vstQXsiWOiDoDkevCF4dM13qCAUjqsvHfk0uyQ35L7 bBF+q1I8FXzAxvwGiCixQeYwhGK6BGe9fjStd9G/GP/M4jHxMZ0rofIOIIVPqQGF CqQBNksvX9E2TwHcnIkWWP22PdnJImz77Scb2pH+uzgiydtJLrNWkrR8dKLFdJnB d39bvbxtab7QutBm4SsEvwweR+OnFwmmjcR3E34gnK9YrlaaDXY8EFD5sWkt5o4L Wu3xTs5J6a0jdg3YBBk1QoPhXNf/pFW29kXYhHvqjiOj8/kOnuiaheO9//twM3FR SNzUZ5Xk1/ut9E5zndrNyOTlCI/Y6Vks7uD6OzMlgstAqDBH64Q= =dYEO -----END PGP SIGNATURE----- --Sig_/UChzlzgPs98xJxK1DilnSN2-- --===============6423927073094526657== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============6423927073094526657==--