linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xia Jiang <xia.jiang@mediatek.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Rick Chang <rick.chang@mediatek.com>
Cc: <linux-media@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Tomasz Figa <tfiga@chromium.org>, <srv_heupstream@mediatek.com>,
	<senozhatsky@chromium.org>, <mojahsu@chromium.org>,
	<drinkcat@chromium.org>, <maoguang.meng@mediatek.com>,
	Xia Jiang <xia.jiang@mediatek.com>
Subject: [PATCH v10 12/28] media: platform: Use generic rounding helpers
Date: Thu, 23 Jul 2020 11:04:35 +0800	[thread overview]
Message-ID: <20200723030451.5616-13-xia.jiang@mediatek.com> (raw)
In-Reply-To: <20200723030451.5616-1-xia.jiang@mediatek.com>

Use clamp() to replace mtk_jpeg_bound_align_image() and round() to
replace mtk_jpeg_align().

Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Xia Jiang <xia.jiang@mediatek.com>
---
v10: no changes
---
 .../media/platform/mtk-jpeg/mtk_jpeg_core.c   | 41 +++++--------------
 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c |  8 ++--
 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h |  5 ---
 3 files changed, 15 insertions(+), 39 deletions(-)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 0153d57af466..980500be027b 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -151,25 +151,6 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
 	return NULL;
 }
 
-static void mtk_jpeg_bound_align_image(u32 *w, unsigned int wmin,
-				       unsigned int wmax, unsigned int walign,
-				       u32 *h, unsigned int hmin,
-				       unsigned int hmax, unsigned int halign)
-{
-	int width, height, w_step, h_step;
-
-	width = *w;
-	height = *h;
-	w_step = 1 << walign;
-	h_step = 1 << halign;
-
-	v4l_bound_align_image(w, wmin, wmax, walign, h, hmin, hmax, halign, 0);
-	if (*w < width && (*w + w_step) <= wmax)
-		*w += w_step;
-	if (*h < height && (*h + h_step) <= hmax)
-		*h += h_step;
-}
-
 static void mtk_jpeg_adjust_fmt_mplane(struct mtk_jpeg_ctx *ctx,
 				       struct v4l2_format *f)
 {
@@ -211,24 +192,24 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
 	if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
 		struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
 
-		mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
-					   MTK_JPEG_MAX_WIDTH, 0,
-					   &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
-					   MTK_JPEG_MAX_HEIGHT, 0);
+		pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
+				       MTK_JPEG_MAX_HEIGHT);
+		pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
+				      MTK_JPEG_MAX_WIDTH);
 
 		pfmt->bytesperline = 0;
 		/* Source size must be aligned to 128 */
-		pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
+		pfmt->sizeimage = round_up(pfmt->sizeimage, 128);
 		if (pfmt->sizeimage == 0)
 			pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
 		goto end;
 	}
 
 	/* type is MTK_JPEG_FMT_TYPE_CAPTURE */
-	mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
-				   MTK_JPEG_MAX_WIDTH, fmt->h_align,
-				   &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
-				   MTK_JPEG_MAX_HEIGHT, fmt->v_align);
+	pix_mp->height = clamp(round_up(pix_mp->height, fmt->v_align),
+			       MTK_JPEG_MIN_HEIGHT, MTK_JPEG_MAX_HEIGHT);
+	pix_mp->width = clamp(round_up(pix_mp->width, fmt->h_align),
+			      MTK_JPEG_MIN_WIDTH, MTK_JPEG_MAX_WIDTH);
 
 	for (i = 0; i < fmt->colplanes; i++) {
 		struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
@@ -711,8 +692,8 @@ static void mtk_jpeg_set_dec_src(struct mtk_jpeg_ctx *ctx,
 {
 	bs->str_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
 	bs->end_addr = bs->str_addr +
-			 mtk_jpeg_align(vb2_get_plane_payload(src_buf, 0), 16);
-	bs->size = mtk_jpeg_align(vb2_plane_size(src_buf, 0), 128);
+		       round_up(vb2_get_plane_payload(src_buf, 0), 16);
+	bs->size = round_up(vb2_plane_size(src_buf, 0), 128);
 }
 
 static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c
index ddf0dfa78e20..68abcfd7494d 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c
@@ -153,10 +153,10 @@ static int mtk_jpeg_calc_dst_size(struct mtk_jpeg_dec_param *param)
 				param->sampling_w[i];
 		/* output format is 420/422 */
 		param->comp_w[i] = padding_w >> brz_w[i];
-		param->comp_w[i] = mtk_jpeg_align(param->comp_w[i],
-						  MTK_JPEG_DCTSIZE);
-		param->img_stride[i] = i ? mtk_jpeg_align(param->comp_w[i], 16)
-					: mtk_jpeg_align(param->comp_w[i], 32);
+		param->comp_w[i] = round_up(param->comp_w[i],
+					    MTK_JPEG_DCTSIZE);
+		param->img_stride[i] = i ? round_up(param->comp_w[i], 16)
+					: round_up(param->comp_w[i], 32);
 		ds_row_h[i] = (MTK_JPEG_DCTSIZE * param->sampling_h[i]);
 	}
 	param->dec_w = param->img_stride[0];
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h
index 9c6584eaad99..7b0687f8f4b6 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h
@@ -54,11 +54,6 @@ struct mtk_jpeg_dec_param {
 	u8 uv_brz_w;
 };
 
-static inline u32 mtk_jpeg_align(u32 val, u32 align)
-{
-	return (val + align - 1) & ~(align - 1);
-}
-
 struct mtk_jpeg_bs {
 	dma_addr_t	str_addr;
 	dma_addr_t	end_addr;
-- 
2.18.0

  parent reply	other threads:[~2020-07-23  3:07 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23  3:04 [PATCH v10 00/28] Add support for mt2701 JPEG ENC support Xia Jiang
2020-07-23  3:04 ` [PATCH v10 01/28] media: platform: Improve subscribe event flow for bug fixing Xia Jiang
2020-07-23  3:04 ` [PATCH v10 02/28] media: platform: Improve queue set up " Xia Jiang
2020-07-23  3:04 ` [PATCH v10 03/28] media: platform: Improve getting and requesting irq " Xia Jiang
2020-07-23  3:04 ` [PATCH v10 04/28] media: platform: Change the fixed device node number to unfixed value Xia Jiang
2020-07-23  3:04 ` [PATCH v10 05/28] media: platform: Improve power on and power off flow Xia Jiang
2020-07-23  3:04 ` [PATCH v10 06/28] media: platform: Delete the resetting hardware flow in the system PM ops Xia Jiang
2020-07-23  3:04 ` [PATCH v10 07/28] media: platform: Improve the implementation of " Xia Jiang
2020-07-23  3:04 ` [PATCH v10 08/28] media: platform: Add mechanism to handle jpeg hardware's locking up Xia Jiang
2020-07-23  3:04 ` [PATCH v10 09/28] media: platform: Cancel the last frame handling flow Xia Jiang
2020-07-23  3:04 ` [PATCH v10 10/28] media: platform: Delete zeroing the reserved fields Xia Jiang
2020-07-23  3:04 ` [PATCH v10 11/28] media: platform: Stylistic changes for improving code quality Xia Jiang
2020-07-23  3:04 ` Xia Jiang [this message]
2020-07-23  3:04 ` [PATCH v10 13/28] media: platform: Change MTK_JPEG_COMP_MAX macro definition location Xia Jiang
2020-07-23  3:04 ` [PATCH v10 14/28] media: platform: Delete redundant code and add annotation for an enum Xia Jiang
2020-07-23  3:04 ` [PATCH v10 15/28] media: platform: Delete vidioc_s_selection ioctl of jpeg dec Xia Jiang
2020-07-23  3:04 ` [PATCH v10 16/28] media: platform: Change the maximum width and height supported by JPEG dec Xia Jiang
2020-07-23  3:04 ` [PATCH v10 17/28] media: platform: Refactor mtk_jpeg_try_fmt_mplane() Xia Jiang
2020-07-23  3:04 ` [PATCH v10 18/28] media: platform: Refactor mtk_jpeg_find_format() Xia Jiang
2020-07-23  3:04 ` [PATCH v10 19/28] media: platform: Redefinition of mtk_jpeg_q_data structure Xia Jiang
2020-07-23  3:04 ` [PATCH v10 20/28] media: platform: Change the colorspace of jpeg to the fixed value Xia Jiang
2020-07-23  3:04 ` [PATCH v10 21/28] media: platform: Refactor mtk_jpeg_set_default_params() Xia Jiang
2020-07-23  3:04 ` [PATCH v10 22/28] media: platform: Change the call functions of getting/enable/disable the jpeg's clock Xia Jiang
2020-07-30 16:34   ` Tomasz Figa
2020-07-31  3:20     ` Xia Jiang
2020-07-31 12:49       ` Tomasz Figa
2020-07-23  3:04 ` [PATCH v10 23/28] media: dt-bindings: Add jpeg enc device tree node document Xia Jiang
2020-07-23  3:04 ` [PATCH v10 24/28] arm: dts: mt2701: Add jpeg enc device tree node Xia Jiang
2020-07-23  3:04 ` [PATCH v10 25/28] media: platform: Rename jpeg dec file name Xia Jiang
2020-07-23  3:04 ` [PATCH v10 26/28] media: platform: Rename existing functions/defines/variables Xia Jiang
2020-07-23  3:04 ` [PATCH v10 27/28] media: platform: Using the variant structure to contain the varability between dec and enc Xia Jiang
2020-07-23  3:04 ` [PATCH v10 28/28] media: platform: Add jpeg enc feature Xia Jiang
2020-07-30 16:40 ` [PATCH v10 00/28] Add support for mt2701 JPEG ENC support Tomasz Figa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200723030451.5616-13-xia.jiang@mediatek.com \
    --to=xia.jiang@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maoguang.meng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab+samsung@kernel.org \
    --cc=mojahsu@chromium.org \
    --cc=rick.chang@mediatek.com \
    --cc=robh+dt@kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=srv_heupstream@mediatek.com \
    --cc=tfiga@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).