Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp603492ima; Fri, 15 Mar 2019 09:46:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqx61aPLd6n6gVkIJ92iHRPMHZDpDjoplaWOWzJ2NLUVaalBwzvb62vPN2slaWoesToEY+qI X-Received: by 2002:a65:60cb:: with SMTP id r11mr4391608pgv.143.1552668394649; Fri, 15 Mar 2019 09:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552668394; cv=none; d=google.com; s=arc-20160816; b=fIsmk9bumSq2Hl+3ZEJ4OtbBzHAB7TzIlrFY0Ad1cwzU6kOF1R5yerW08LzvZer/z/ /BlGRfeap/paJTO/2LGT2CS9V5NzOt+isjxjs0mLym62sH6Yy/wXv6GBAUOcE3+pEVPV 4V2I7kvs613M7uogo2wJbjpA9dQm5S4SMUcEmKsmoLJUp8FoboBCJzADeIBakMtxLUi7 QCoaa8aUYsJ20LyKnX7FPT8cAboQbK/FtIWsWex/1+GqfHAJAxvEjQzX1YIwx+QXTuuK 9+ZHV8YE/s3SE1XJB/kI6ULUMBjHKWJsEB/+PvPHjtFvbswiaCNRYEdmfdYBybdfjlRM UE3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=GHtvAb/I+C5sNJPrzddgnRPjuXRygt+V2x7MAU3fF/4=; b=qhT82eMlLzDmGGUY47jB9bXih7DyTCH4s+On2h+YmTwOkgIaaNjQ4g0kGVvCWjjP0+ PnGVlydSmbhnO7iArybi8jY1GGH++tC+W6KS8FrYpbOVWM+82IXik6olu4xZnJVVA7hf Zy7+lmnebnQMQL/iOdF5cPwv8xjv40LJ2V7dbrXrtuXter/PEuN0wIYKwrH+xUeqDc0s zqqib4IH/lHHH1TKinLNkbwTtgeBN2Xqa82Vt592y9lxLypFQZpMOOMVAjLjmsrqeLzy T9yvlARS9R3SyYjCtRkfrtfS3uW+N0FVib3qmMWi8frngk0r86JpbyS7xjjQ9m+i01Wq v3Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si2374110pfi.286.2019.03.15.09.46.19; Fri, 15 Mar 2019 09:46:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729767AbfCOQpY (ORCPT + 99 others); Fri, 15 Mar 2019 12:45:24 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49020 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729750AbfCOQpW (ORCPT ); Fri, 15 Mar 2019 12:45:22 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 76E1C260215 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, hverkuil@xs4all.nl, helen.koike@collabora.com, lucmaga@gmail.com, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: [PATCH 07/16] media: vimc: cap: Add handler for singleplanar fmt ioctls Date: Fri, 15 Mar 2019 13:43:50 -0300 Message-Id: <20190315164359.626-8-andrealmeid@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190315164359.626-1-andrealmeid@collabora.com> References: <20190315164359.626-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since multiplanar is a superset of single planar formats, instead of having different implementations for them, treat all formats as multiplanar. If we need to work with single planar formats, convert them to multiplanar (with num_planes = 1), re-use the multiplanar code, and transform them back to single planar. This is implemented with v4l2_fmt_sp2mp_func(). Signed-off-by: André Almeida --- drivers/media/platform/vimc/vimc-capture.c | 63 +++++++++++++++++----- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c index a93241d53953..47acf50f1ad2 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c @@ -127,7 +127,7 @@ static int vimc_cap_g_fmt_vid_cap(struct file *file, void *priv, static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct v4l2_pix_format *format = &f->fmt.pix; + struct v4l2_pix_format_mplane *format = &f->fmt.pix_mp; format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH, VIMC_FRAME_MAX_WIDTH) & ~1; @@ -145,20 +145,58 @@ static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv, if (!v4l2_format_info(format->pixelformat)) format->pixelformat = fmt_default.fmt.pix.pixelformat; - return v4l2_fill_pixfmt(format, format->pixelformat, + return v4l2_fill_pixfmt_mp(format, format->pixelformat, format->width, format->height); } -static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, +static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_fmtdesc *f) +{ + if (f->index >= ARRAY_SIZE(vimc_cap_supported_pixfmt)) + return -EINVAL; + + f->pixelformat = vimc_cap_supported_pixfmt[f->index]; + strncpy(f->description, v4l2_get_fourcc_name(f->pixelformat), 4); + f->description[4] = '\0'; + + return 0; +} + +/* + * VIDIOC FMT handlers for single-planar + */ + +static int vimc_cap_g_fmt_vid_cap_sp(struct file *file, void *priv, + struct v4l2_format *f) +{ + if (multiplanar) + return -EINVAL; + + return vimc_cap_g_fmt_vid_cap(file, priv, f); +} + +static int vimc_cap_try_fmt_vid_cap_sp(struct file *file, void *priv, + struct v4l2_format *f) +{ + if (multiplanar) + return -EINVAL; + + return v4l2_fmt_sp2mp_func(file, priv, f, vimc_cap_try_fmt_vid_cap); +} + +static int vimc_cap_s_fmt_vid_cap_sp(struct file *file, void *priv, struct v4l2_format *f) { struct vimc_cap_device *vcap = video_drvdata(file); + if (multiplanar) + return -EINVAL; + /* Do not change the format while stream is on */ if (vb2_is_busy(&vcap->queue)) return -EBUSY; - vimc_cap_try_fmt_vid_cap(file, priv, f); + v4l2_fmt_sp2mp_func(file, priv, f, vimc_cap_try_fmt_vid_cap); dev_dbg(vcap->dev, "%s: format update: " "old:%dx%d (0x%x, %d, %d, %d, %d) " @@ -181,15 +219,13 @@ static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, return 0; } -static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv, +static int vimc_cap_enum_fmt_vid_cap_sp(struct file *file, void *priv, struct v4l2_fmtdesc *f) { - if (f->index >= ARRAY_SIZE(vimc_cap_supported_pixfmt)) + if (multiplanar) return -EINVAL; - f->pixelformat = vimc_cap_supported_pixfmt[f->index]; - - return 0; + return vimc_cap_enum_fmt_vid_cap(file, priv, f); } static bool vimc_cap_is_pixfmt_supported(u32 pixelformat) @@ -235,10 +271,11 @@ static const struct v4l2_file_operations vimc_cap_fops = { static const struct v4l2_ioctl_ops vimc_cap_ioctl_ops = { .vidioc_querycap = vimc_cap_querycap, - .vidioc_g_fmt_vid_cap = vimc_cap_g_fmt_vid_cap, - .vidioc_s_fmt_vid_cap = vimc_cap_s_fmt_vid_cap, - .vidioc_try_fmt_vid_cap = vimc_cap_try_fmt_vid_cap, - .vidioc_enum_fmt_vid_cap = vimc_cap_enum_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = vimc_cap_g_fmt_vid_cap_sp, + .vidioc_s_fmt_vid_cap = vimc_cap_s_fmt_vid_cap_sp, + .vidioc_try_fmt_vid_cap = vimc_cap_try_fmt_vid_cap_sp, + .vidioc_enum_fmt_vid_cap = vimc_cap_enum_fmt_vid_cap_sp, + .vidioc_enum_framesizes = vimc_cap_enum_framesizes, .vidioc_reqbufs = vb2_ioctl_reqbufs, -- 2.21.0