From patchwork Thu Jun 4 07:27:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xia Jiang X-Patchwork-Id: 11587103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 615BA14E3 for ; Thu, 4 Jun 2020 07:29:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DFE62075B for ; Thu, 4 Jun 2020 07:29:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="J3xlykka" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728129AbgFDH3h (ORCPT ); Thu, 4 Jun 2020 03:29:37 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:35370 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728098AbgFDH3g (ORCPT ); Thu, 4 Jun 2020 03:29:36 -0400 X-UUID: aab39f65e80848b9b96fce1efd134f6e-20200604 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=CwLZiApyK6bUNwQh1RXzmg2IHc9+21e/FaYfMkX4XA8=; b=J3xlykkaeI+DxysbbwQ3WgoKfgWO5PeShtwYQhsSHjpmpDFzokr93R3p3YV7adL8xUO6N/S35riQ3eJVKo4IDObY6z6ue3QAFUcKMMJ4jeN2fyi7t2kpRZGrklI4bHW9va4B1urbpjCbfdAA9pBQ1u3DkzYdbQKkhmSvX+96hME=; X-UUID: aab39f65e80848b9b96fce1efd134f6e-20200604 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1597120258; Thu, 04 Jun 2020 15:29:30 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Jun 2020 15:29:26 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 4 Jun 2020 15:29:25 +0800 From: Xia Jiang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Rick Chang CC: , , , , , Marek Szyprowski , Tomasz Figa , , , , , , , Xia Jiang Subject: [PATCH v9 11/18] media: platform: Use generic rounding helpers Date: Thu, 4 Jun 2020 15:27:01 +0800 Message-ID: <20200604072708.9468-12-xia.jiang@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200604072708.9468-1-xia.jiang@mediatek.com> References: <20200604072708.9468-1-xia.jiang@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use clamp() to replace mtk_jpeg_bound_align_image() and round() to replace mtk_jpeg_align(). Reviewed-by: Tomasz Figa Signed-off-by: Xia Jiang --- v9: change the patch title description --- .../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 bd1cc58324c6..c9c0357b2d6c 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]; @@ -734,8 +715,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;