From patchwork Fri May 4 09:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10380269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A7F3060541 for ; Fri, 4 May 2018 09:32:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A44F2936D for ; Fri, 4 May 2018 09:32:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EDE029367; Fri, 4 May 2018 09:32:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D06329366 for ; Fri, 4 May 2018 09:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751399AbeEDJca (ORCPT ); Fri, 4 May 2018 05:32:30 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:44141 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750707AbeEDJca (ORCPT ); Fri, 4 May 2018 05:32:30 -0400 X-Originating-IP: 2.224.242.101 Received: from w540.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 8DCD720013; Fri, 4 May 2018 11:32:30 +0200 (CEST) From: Jacopo Mondi To: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl, mchehab@kernel.org, sakari.ailus@iki.fi Cc: Jacopo Mondi , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH] media: renesas-ceu: Set mbus_fmt on subdev operations Date: Fri, 4 May 2018 11:32:17 +0200 Message-Id: <1525426337-17636-1-git-send-email-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The renesas-ceu driver intializes the desired mbus_format at 'complete' time, inspecting the supported subdevice ones, and tuning some parameters to produce the requested memory format from what the sensor can produce. Although, the initially selected mbus_format was not provided to the subdevice during set_fmt and try_fmt operations, providing instead a '0' mbus format code. As long as the sensor defaults to a compatible mbus_format when an invalid code as '0' is provided, capture operations work correctly. If the subdevice defaults to an unsupported format (eg. some RGB permutations) capture does not work properly due to a mismatch on the expected and received image format on the wire. Fix that by re-using the initially selected mbus_format code during set_fmt and try_fmt subdevice operation calls. Tested by printing out the format selection procedure with ov7670 sensor. Before this patch: [ 0.866001] ov7670_try_fmt_internal -- Looking for mbus_code 0x0000 [ 0.870882] ov7670_try_fmt_internal -- Try mbus_code 0x2008 [ 0.876336] ov7670_try_fmt_internal -- Try mbus_code 0x1002 [ 0.881387] ov7670_try_fmt_internal -- Try mbus_code 0x1008 [ 0.886537] ov7670_try_fmt_internal -- Try mbus_code 0x3001 [ 0.891584] ov7670_try_fmt_internal -- mbus_code defaulted to 0x2008 With this patch applied: [ 0.867015] ov7670_try_fmt_internal -- Looking for mbus_code 0x2008 [ 0.873205] ov7670_try_fmt_internal -- Try mbus_code 0x2008: match Signed-off-by: Jacopo Mondi --- drivers/media/platform/renesas-ceu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/media/platform/renesas-ceu.c b/drivers/media/platform/renesas-ceu.c index 6599dba..dec1b35 100644 --- a/drivers/media/platform/renesas-ceu.c +++ b/drivers/media/platform/renesas-ceu.c @@ -777,8 +777,15 @@ static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt) const struct ceu_fmt *ceu_fmt; int ret; + /* + * Set format on sensor sub device: bus format used to produce memory + * format is selected at initialization time. + */ struct v4l2_subdev_format sd_format = { - .which = V4L2_SUBDEV_FORMAT_TRY, + .which = V4L2_SUBDEV_FORMAT_TRY, + .format = { + .code = ceu_sd->mbus_fmt.mbus_code, + }, }; switch (pix->pixelformat) { @@ -800,10 +807,6 @@ static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt) v4l_bound_align_image(&pix->width, 2, CEU_MAX_WIDTH, 4, &pix->height, 4, CEU_MAX_HEIGHT, 4, 0); - /* - * Set format on sensor sub device: bus format used to produce memory - * format is selected at initialization time. - */ v4l2_fill_mbus_format_mplane(&sd_format.format, pix); ret = v4l2_subdev_call(v4l2_sd, pad, set_fmt, &pad_cfg, &sd_format); if (ret) @@ -827,8 +830,15 @@ static int ceu_set_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt) struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd; int ret; + /* + * Set format on sensor sub device: bus format used to produce memory + * format is selected at initialization time. + */ struct v4l2_subdev_format format = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .format = { + .code = ceu_sd->mbus_fmt.mbus_code, + }, }; ret = ceu_try_fmt(ceudev, v4l2_fmt);