Commit e0ec6043 authored by Xia Jiang's avatar Xia Jiang Committed by Mauro Carvalho Chehab

media: platform: Use generic rounding helpers

Use clamp() to replace mtk_jpeg_bound_align_image() and round() to
replace mtk_jpeg_align().
Reviewed-by: default avatarTomasz Figa <tfiga@chromium.org>
Signed-off-by: default avatarXia Jiang <xia.jiang@mediatek.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent e6d51670
...@@ -151,25 +151,6 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx, ...@@ -151,25 +151,6 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
return NULL; 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, static void mtk_jpeg_adjust_fmt_mplane(struct mtk_jpeg_ctx *ctx,
struct v4l2_format *f) struct v4l2_format *f)
{ {
...@@ -211,24 +192,24 @@ static int mtk_jpeg_try_fmt_mplane(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) { if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0]; struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH, pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
MTK_JPEG_MAX_WIDTH, 0, MTK_JPEG_MAX_HEIGHT);
&pix_mp->height, MTK_JPEG_MIN_HEIGHT, pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
MTK_JPEG_MAX_HEIGHT, 0); MTK_JPEG_MAX_WIDTH);
pfmt->bytesperline = 0; pfmt->bytesperline = 0;
/* Source size must be aligned to 128 */ /* 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) if (pfmt->sizeimage == 0)
pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE; pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
goto end; goto end;
} }
/* type is MTK_JPEG_FMT_TYPE_CAPTURE */ /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH, pix_mp->height = clamp(round_up(pix_mp->height, fmt->v_align),
MTK_JPEG_MAX_WIDTH, fmt->h_align, MTK_JPEG_MIN_HEIGHT, MTK_JPEG_MAX_HEIGHT);
&pix_mp->height, MTK_JPEG_MIN_HEIGHT, pix_mp->width = clamp(round_up(pix_mp->width, fmt->h_align),
MTK_JPEG_MAX_HEIGHT, fmt->v_align); MTK_JPEG_MIN_WIDTH, MTK_JPEG_MAX_WIDTH);
for (i = 0; i < fmt->colplanes; i++) { for (i = 0; i < fmt->colplanes; i++) {
struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[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, ...@@ -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->str_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
bs->end_addr = bs->str_addr + bs->end_addr = bs->str_addr +
mtk_jpeg_align(vb2_get_plane_payload(src_buf, 0), 16); round_up(vb2_get_plane_payload(src_buf, 0), 16);
bs->size = mtk_jpeg_align(vb2_plane_size(src_buf, 0), 128); bs->size = round_up(vb2_plane_size(src_buf, 0), 128);
} }
static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx, static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
......
...@@ -153,10 +153,10 @@ static int mtk_jpeg_calc_dst_size(struct mtk_jpeg_dec_param *param) ...@@ -153,10 +153,10 @@ static int mtk_jpeg_calc_dst_size(struct mtk_jpeg_dec_param *param)
param->sampling_w[i]; param->sampling_w[i];
/* output format is 420/422 */ /* output format is 420/422 */
param->comp_w[i] = padding_w >> brz_w[i]; param->comp_w[i] = padding_w >> brz_w[i];
param->comp_w[i] = mtk_jpeg_align(param->comp_w[i], param->comp_w[i] = round_up(param->comp_w[i],
MTK_JPEG_DCTSIZE); MTK_JPEG_DCTSIZE);
param->img_stride[i] = i ? mtk_jpeg_align(param->comp_w[i], 16) param->img_stride[i] = i ? round_up(param->comp_w[i], 16)
: mtk_jpeg_align(param->comp_w[i], 32); : round_up(param->comp_w[i], 32);
ds_row_h[i] = (MTK_JPEG_DCTSIZE * param->sampling_h[i]); ds_row_h[i] = (MTK_JPEG_DCTSIZE * param->sampling_h[i]);
} }
param->dec_w = param->img_stride[0]; param->dec_w = param->img_stride[0];
......
...@@ -54,11 +54,6 @@ struct mtk_jpeg_dec_param { ...@@ -54,11 +54,6 @@ struct mtk_jpeg_dec_param {
u8 uv_brz_w; u8 uv_brz_w;
}; };
static inline u32 mtk_jpeg_align(u32 val, u32 align)
{
return (val + align - 1) & ~(align - 1);
}
struct mtk_jpeg_bs { struct mtk_jpeg_bs {
dma_addr_t str_addr; dma_addr_t str_addr;
dma_addr_t end_addr; dma_addr_t end_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment