Lines Matching +full:left +full:- +full:aligned

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Author: Ping-Hsun Wu <ping-hsun.wu@mediatek.com>
7 #include <media/v4l2-common.h>
8 #include <media/videobuf2-v4l2.h>
9 #include <media/videobuf2-dma-contig.h>
10 #include "mtk-mdp3-core.h"
11 #include "mtk-mdp3-regs.h"
12 #include "mtk-mdp3-m2m.h"
15 * All 10-bit related formats are not added in the basic format list,
292 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; in mdp_map_ycbcr_prof_mplane()
297 switch (pix_mp->colorspace) { in mdp_map_ycbcr_prof_mplane()
302 if (pix_mp->quantization == V4L2_QUANTIZATION_FULL_RANGE) in mdp_map_ycbcr_prof_mplane()
306 if (pix_mp->quantization == V4L2_QUANTIZATION_FULL_RANGE) in mdp_map_ycbcr_prof_mplane()
310 if (pix_mp->quantization == V4L2_QUANTIZATION_FULL_RANGE) in mdp_map_ycbcr_prof_mplane()
324 v4l_bound_align_image(w, s->min_width, s->max_width, s->step_width, in mdp_bound_align_image()
325 h, s->min_height, s->max_height, s->step_height, in mdp_bound_align_image()
328 s->min_width = org_w; in mdp_bound_align_image()
329 s->min_height = org_h; in mdp_bound_align_image()
338 return -ERANGE; in mdp_clamp_align()
340 /* Bits that must be zero to be aligned */ in mdp_clamp_align()
341 mask = ~((1 << align) - 1); in mdp_clamp_align()
346 return -ERANGE; in mdp_clamp_align()
348 /* Clamp to aligned min and max */ in mdp_clamp_align()
351 /* Round to nearest aligned value */ in mdp_clamp_align()
353 *x = (*x + (1 << (align - 1))) & mask; in mdp_clamp_align()
361 fmt = mdp_find_fmt_by_index(f->index, f->type); in mdp_enum_fmt_mplane()
363 return -EINVAL; in mdp_enum_fmt_mplane()
365 f->pixelformat = fmt->pixelformat; in mdp_enum_fmt_mplane()
373 struct device *dev = &param->ctx->mdp_dev->pdev->dev; in mdp_try_fmt_mplane()
374 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; in mdp_try_fmt_mplane()
381 fmt = mdp_find_fmt(pix_mp->pixelformat, f->type); in mdp_try_fmt_mplane()
383 fmt = mdp_find_fmt_by_index(0, f->type); in mdp_try_fmt_mplane()
386 (pix_mp->pixelformat & 0xff), in mdp_try_fmt_mplane()
387 (pix_mp->pixelformat >> 8) & 0xff, in mdp_try_fmt_mplane()
388 (pix_mp->pixelformat >> 16) & 0xff, in mdp_try_fmt_mplane()
389 (pix_mp->pixelformat >> 24) & 0xff); in mdp_try_fmt_mplane()
394 pix_mp->field = V4L2_FIELD_NONE; in mdp_try_fmt_mplane()
395 pix_mp->flags = 0; in mdp_try_fmt_mplane()
396 pix_mp->pixelformat = fmt->pixelformat; in mdp_try_fmt_mplane()
397 if (V4L2_TYPE_IS_CAPTURE(f->type)) { in mdp_try_fmt_mplane()
398 pix_mp->colorspace = param->colorspace; in mdp_try_fmt_mplane()
399 pix_mp->xfer_func = param->xfer_func; in mdp_try_fmt_mplane()
400 pix_mp->ycbcr_enc = param->ycbcr_enc; in mdp_try_fmt_mplane()
401 pix_mp->quantization = param->quant; in mdp_try_fmt_mplane()
404 pix_limit = V4L2_TYPE_IS_OUTPUT(f->type) ? &param->limit->out_limit : in mdp_try_fmt_mplane()
405 &param->limit->cap_limit; in mdp_try_fmt_mplane()
406 s.min_width = pix_limit->wmin; in mdp_try_fmt_mplane()
407 s.max_width = pix_limit->wmax; in mdp_try_fmt_mplane()
408 s.step_width = fmt->walign; in mdp_try_fmt_mplane()
409 s.min_height = pix_limit->hmin; in mdp_try_fmt_mplane()
410 s.max_height = pix_limit->hmax; in mdp_try_fmt_mplane()
411 s.step_height = fmt->halign; in mdp_try_fmt_mplane()
412 org_w = pix_mp->width; in mdp_try_fmt_mplane()
413 org_h = pix_mp->height; in mdp_try_fmt_mplane()
415 mdp_bound_align_image(&pix_mp->width, &pix_mp->height, &s, fmt->salign); in mdp_try_fmt_mplane()
416 if (org_w != pix_mp->width || org_h != pix_mp->height) in mdp_try_fmt_mplane()
418 org_w, org_h, pix_mp->width, pix_mp->height); in mdp_try_fmt_mplane()
420 if (pix_mp->num_planes && pix_mp->num_planes != fmt->num_planes) in mdp_try_fmt_mplane()
422 pix_mp->num_planes, fmt->num_planes); in mdp_try_fmt_mplane()
423 pix_mp->num_planes = fmt->num_planes; in mdp_try_fmt_mplane()
425 for (i = 0; i < pix_mp->num_planes; ++i) { in mdp_try_fmt_mplane()
426 u32 min_bpl = (pix_mp->width * fmt->row_depth[i]) >> 3; in mdp_try_fmt_mplane()
427 u32 max_bpl = (pix_limit->wmax * fmt->row_depth[i]) >> 3; in mdp_try_fmt_mplane()
428 u32 bpl = pix_mp->plane_fmt[i].bytesperline; in mdp_try_fmt_mplane()
430 u32 si = pix_mp->plane_fmt[i].sizeimage; in mdp_try_fmt_mplane()
433 pix_mp->plane_fmt[i].bytesperline = bpl; in mdp_try_fmt_mplane()
435 min_si = (bpl * pix_mp->height * fmt->depth[i]) / in mdp_try_fmt_mplane()
436 fmt->row_depth[i]; in mdp_try_fmt_mplane()
437 max_si = (bpl * s.max_height * fmt->depth[i]) / in mdp_try_fmt_mplane()
438 fmt->row_depth[i]; in mdp_try_fmt_mplane()
441 pix_mp->plane_fmt[i].sizeimage = si; in mdp_try_fmt_mplane()
473 struct device *dev = &ctx->mdp_dev->pdev->dev; in mdp_try_crop()
474 s32 left, top, right, bottom; in mdp_try_crop() local
478 dev_dbg(dev, "%d target:%d, set:(%d,%d) %ux%u", ctx->id, in mdp_try_crop()
479 s->target, s->r.left, s->r.top, s->r.width, s->r.height); in mdp_try_crop()
481 left = s->r.left; in mdp_try_crop()
482 top = s->r.top; in mdp_try_crop()
483 right = s->r.left + s->r.width; in mdp_try_crop()
484 bottom = s->r.top + s->r.height; in mdp_try_crop()
485 framew = frame->format.fmt.pix_mp.width; in mdp_try_crop()
486 frameh = frame->format.fmt.pix_mp.height; in mdp_try_crop()
488 if (mdp_target_is_crop(s->target)) { in mdp_try_crop()
492 walign = frame->mdp_fmt->walign; in mdp_try_crop()
493 halign = frame->mdp_fmt->halign; in mdp_try_crop()
496 dev_dbg(dev, "%d align:%u,%u, bound:%ux%u", ctx->id, in mdp_try_crop()
499 ret = mdp_clamp_start(&left, 0, right, walign, s->flags); in mdp_try_crop()
502 ret = mdp_clamp_start(&top, 0, bottom, halign, s->flags); in mdp_try_crop()
505 ret = mdp_clamp_end(&right, left, framew, walign, s->flags); in mdp_try_crop()
508 ret = mdp_clamp_end(&bottom, top, frameh, halign, s->flags); in mdp_try_crop()
512 r->left = left; in mdp_try_crop()
513 r->top = top; in mdp_try_crop()
514 r->width = right - left; in mdp_try_crop()
515 r->height = bottom - top; in mdp_try_crop()
517 dev_dbg(dev, "%d crop:(%d,%d) %ux%u", ctx->id, in mdp_try_crop()
518 r->left, r->top, r->width, r->height); in mdp_try_crop()
528 crop_w = crop->width; in mdp_check_scaling_ratio()
529 crop_h = crop->height; in mdp_check_scaling_ratio()
531 comp_w = compose->height; in mdp_check_scaling_ratio()
532 comp_h = compose->width; in mdp_check_scaling_ratio()
534 comp_w = compose->width; in mdp_check_scaling_ratio()
535 comp_h = compose->height; in mdp_check_scaling_ratio()
538 if ((crop_w / comp_w) > limit->h_scale_down_max || in mdp_check_scaling_ratio()
539 (crop_h / comp_h) > limit->v_scale_down_max || in mdp_check_scaling_ratio()
540 (comp_w / crop_w) > limit->h_scale_up_max || in mdp_check_scaling_ratio()
541 (comp_h / crop_h) > limit->v_scale_up_max) in mdp_check_scaling_ratio()
542 return -ERANGE; in mdp_check_scaling_ratio()
550 enum mdp_color c = fmt->mdp_color; in mdp_fmt_get_stride()
554 / fmt->row_depth[0]; in mdp_fmt_get_stride()
569 enum mdp_color c = fmt->mdp_color; in mdp_fmt_get_stride_contig()
587 enum mdp_color c = fmt->mdp_color; in mdp_fmt_get_plane_size()
590 bytesperline = (stride * fmt->row_depth[0]) in mdp_fmt_get_plane_size()
606 struct v4l2_pix_format_mplane *pix_mp = &frame->format.fmt.pix_mp; in mdp_prepare_buffer()
609 b->format.colorformat = frame->mdp_fmt->mdp_color; in mdp_prepare_buffer()
610 b->format.ycbcr_prof = frame->ycbcr_prof; in mdp_prepare_buffer()
611 for (i = 0; i < pix_mp->num_planes; ++i) { in mdp_prepare_buffer()
612 u32 stride = mdp_fmt_get_stride(frame->mdp_fmt, in mdp_prepare_buffer()
613 pix_mp->plane_fmt[i].bytesperline, i); in mdp_prepare_buffer()
615 b->format.plane_fmt[i].stride = stride; in mdp_prepare_buffer()
616 b->format.plane_fmt[i].size = in mdp_prepare_buffer()
617 mdp_fmt_get_plane_size(frame->mdp_fmt, stride, in mdp_prepare_buffer()
618 pix_mp->height, i); in mdp_prepare_buffer()
619 b->iova[i] = vb2_dma_contig_plane_dma_addr(vb, i); in mdp_prepare_buffer()
621 for (; i < MDP_COLOR_GET_PLANE_COUNT(b->format.colorformat); ++i) { in mdp_prepare_buffer()
622 u32 stride = mdp_fmt_get_stride_contig(frame->mdp_fmt, in mdp_prepare_buffer()
623 b->format.plane_fmt[0].stride, i); in mdp_prepare_buffer()
625 b->format.plane_fmt[i].stride = stride; in mdp_prepare_buffer()
626 b->format.plane_fmt[i].size = in mdp_prepare_buffer()
627 mdp_fmt_get_plane_size(frame->mdp_fmt, stride, in mdp_prepare_buffer()
628 pix_mp->height, i); in mdp_prepare_buffer()
629 b->iova[i] = b->iova[i - 1] + b->format.plane_fmt[i - 1].size; in mdp_prepare_buffer()
631 b->usage = frame->usage; in mdp_prepare_buffer()
637 in->buffer.format.width = frame->format.fmt.pix_mp.width; in mdp_set_src_config()
638 in->buffer.format.height = frame->format.fmt.pix_mp.height; in mdp_set_src_config()
639 mdp_prepare_buffer(&in->buffer, frame, vb); in mdp_set_src_config()
646 if (f->denominator == 0) { in mdp_to_fixed()
651 q = f->numerator / f->denominator; in mdp_to_fixed()
652 *r = div_u64(((u64)f->numerator - q * f->denominator) << in mdp_to_fixed()
653 IMG_SUBPIXEL_SHIFT, f->denominator); in mdp_to_fixed()
659 c->left = crop->c.left in mdp_set_src_crop()
660 + mdp_to_fixed(&c->left_subpix, &crop->left_subpix); in mdp_set_src_crop()
661 c->top = crop->c.top in mdp_set_src_crop()
662 + mdp_to_fixed(&c->top_subpix, &crop->top_subpix); in mdp_set_src_crop()
663 c->width = crop->c.width in mdp_set_src_crop()
664 + mdp_to_fixed(&c->width_subpix, &crop->width_subpix); in mdp_set_src_crop()
665 c->height = crop->c.height in mdp_set_src_crop()
666 + mdp_to_fixed(&c->height_subpix, &crop->height_subpix); in mdp_set_src_crop()
679 * a 180-degree rotation with a horizontal flip in mdp_set_orientation()
685 out->rotation = rotation % 360; in mdp_set_orientation()
687 out->flags |= IMG_CTRL_FLAG_HFLIP; in mdp_set_orientation()
689 out->flags &= ~IMG_CTRL_FLAG_HFLIP; in mdp_set_orientation()
695 out->buffer.format.width = frame->compose.width; in mdp_set_dst_config()
696 out->buffer.format.height = frame->compose.height; in mdp_set_dst_config()
697 mdp_prepare_buffer(&out->buffer, frame, vb); in mdp_set_dst_config()
698 mdp_set_src_crop(&out->crop, &frame->crop); in mdp_set_dst_config()
699 mdp_set_orientation(out, frame->rotation, frame->hflip, frame->vflip); in mdp_set_dst_config()
707 return -EINVAL; in mdp_frameparam_init()
709 INIT_LIST_HEAD(&param->list); in mdp_frameparam_init()
710 param->limit = &mdp_def_limit; in mdp_frameparam_init()
711 param->type = MDP_STREAM_TYPE_BITBLT; in mdp_frameparam_init()
713 frame = &param->output; in mdp_frameparam_init()
714 frame->format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in mdp_frameparam_init()
715 frame->mdp_fmt = mdp_try_fmt_mplane(&frame->format, param, 0); in mdp_frameparam_init()
716 frame->ycbcr_prof = in mdp_frameparam_init()
717 mdp_map_ycbcr_prof_mplane(&frame->format, in mdp_frameparam_init()
718 frame->mdp_fmt->mdp_color); in mdp_frameparam_init()
719 frame->usage = MDP_BUFFER_USAGE_HW_READ; in mdp_frameparam_init()
721 param->num_captures = 1; in mdp_frameparam_init()
722 frame = &param->captures[0]; in mdp_frameparam_init()
723 frame->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in mdp_frameparam_init()
724 frame->mdp_fmt = mdp_try_fmt_mplane(&frame->format, param, 0); in mdp_frameparam_init()
725 frame->ycbcr_prof = in mdp_frameparam_init()
726 mdp_map_ycbcr_prof_mplane(&frame->format, in mdp_frameparam_init()
727 frame->mdp_fmt->mdp_color); in mdp_frameparam_init()
728 frame->usage = MDP_BUFFER_USAGE_MDP; in mdp_frameparam_init()
729 frame->crop.c.width = param->output.format.fmt.pix_mp.width; in mdp_frameparam_init()
730 frame->crop.c.height = param->output.format.fmt.pix_mp.height; in mdp_frameparam_init()
731 frame->compose.width = frame->format.fmt.pix_mp.width; in mdp_frameparam_init()
732 frame->compose.height = frame->format.fmt.pix_mp.height; in mdp_frameparam_init()