From patchwork Sun May 6 14:19:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10382829 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 D45C66053A for ; Sun, 6 May 2018 14:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C13652892B for ; Sun, 6 May 2018 14:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5E5428970; Sun, 6 May 2018 14:20:30 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 6957828ABF for ; Sun, 6 May 2018 14:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751829AbeEFOUY (ORCPT ); Sun, 6 May 2018 10:20:24 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:43293 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751822AbeEFOUX (ORCPT ); Sun, 6 May 2018 10:20:23 -0400 Received: by mail-pg0-f67.google.com with SMTP id k11-v6so17335566pgo.10; Sun, 06 May 2018 07:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aHW4ys2BrZzxClygrp8Kjkp2D++MdVIUBO9US12VlDs=; b=ovqrsD2PD05XKyFE28BUJTrwm8+UKLfhN6icZoTekLRB2HK/EQMbLSPWyxPkySGCCJ 6V9QHx9L7vZmTLWnUUXuLt5YEg9Vf730UFtVFYniVjH8wdhbLlOr6PCVvpkLCl1N1UBB sLN5aETDt/ALQ9Xn2pkJYV2KNjboRA/lJu/U0s1GmDJOtPcFXja9rt4C19NuCqIJGVBJ yvrrusaAQw354cARK4iuJgaueeXWV1LgbQlKwQ/Fe5FTLtjLQ0ZUmudkjcAqJB6xDgqg NA+DEp81s98cNLwc95Kzjag6i49swaRJoaWWWcHUqdX93bbJYT5Ksnzd3lB+AWgLhg1r m2xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aHW4ys2BrZzxClygrp8Kjkp2D++MdVIUBO9US12VlDs=; b=As5LFOvMHKNYGbFpe4BpELujbvnTcl4/kQ9FHbAvNX3XIgu7NhB8lMSXmhSe2nBSmL ajYGMD9+YQ/7Ht4OEKymizniTINsGLZ3HcKOivFra7PTXhw6Fndw80chWAiPSJ5ie63u sBHD5clKDzoHfDJUwGC+8dg2KcFTGhcqRnF66uaRmIkivhLySXRk5umzR1FvLpHmEygm ISJj8LM4cklMRcWCRizkEs1jdlTJL/xrksSEDmWWKR3fnbAVrLPrLisR6UZgY9ZCjTFU F4X4dge+OPKcsOeHQeiiS1ywcrufJMCvEGb5Y0vLgeVflHRP91F29I2CWYpJaYK7EHmu bG1Q== X-Gm-Message-State: ALQs6tB7Zavbgz/cjFyQfiKGaOADen6MjcAGyGm2LaAmleonWfBRZAKl RIGA8+C/+WfmNeDaQBZD97FEUw== X-Google-Smtp-Source: AB8JxZodwjIJnGTQ4Q+i6kk+ZTAWKQOm7YFW84gp4/DVGOtUgDKgQHWjStmwIeuYuSec0e74PJGDZg== X-Received: by 10.167.130.140 with SMTP id s12mr16897762pfm.136.1525616422697; Sun, 06 May 2018 07:20:22 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:141a:15e1:5268:11ce]) by smtp.gmail.com with ESMTPSA id s88sm58766771pfe.43.2018.05.06.07.20.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 06 May 2018 07:20:22 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org, devicetree@vger.kernel.org Cc: Akinobu Mita , Jacopo Mondi , Laurent Pinchart , Hans Verkuil , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH v5 13/14] media: ov772x: make set_fmt() and s_frame_interval() return -EBUSY while streaming Date: Sun, 6 May 2018 23:19:28 +0900 Message-Id: <1525616369-8843-14-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525616369-8843-1-git-send-email-akinobu.mita@gmail.com> References: <1525616369-8843-1-git-send-email-akinobu.mita@gmail.com> 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 ov772x driver is going to offer a V4L2 sub-device interface, so changing the output data format and the frame interval on this sub-device can be made anytime. However, these requests are preferred to fail while the video stream on the device is active. Cc: Jacopo Mondi Cc: Laurent Pinchart Cc: Hans Verkuil Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita Reviewed-by: Jacopo Mondi --- * v5: - Make s_frame_interval() return -EBUSY while streaming drivers/media/i2c/ov772x.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index 262a7e5..4b479f9 100644 --- a/drivers/media/i2c/ov772x.c +++ b/drivers/media/i2c/ov772x.c @@ -424,9 +424,10 @@ struct ov772x_priv { /* band_filter = COM8[5] ? 256 - BDBASE : 0 */ struct v4l2_ctrl *band_filter_ctrl; unsigned int fps; - /* lock to protect power_count */ + /* lock to protect power_count and streaming */ struct mutex lock; int power_count; + int streaming; #ifdef CONFIG_MEDIA_CONTROLLER struct media_pad pad; #endif @@ -603,18 +604,28 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int enable) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov772x_priv *priv = to_ov772x(sd); + int ret = 0; - if (!enable) { - ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE); - return 0; - } + mutex_lock(&priv->lock); - ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, 0); + if (priv->streaming == enable) + goto done; - dev_dbg(&client->dev, "format %d, win %s\n", - priv->cfmt->code, priv->win->name); + ret = ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, + enable ? 0 : SOFT_SLEEP_MODE); + if (ret) + goto done; - return 0; + if (enable) { + dev_dbg(&client->dev, "format %d, win %s\n", + priv->cfmt->code, priv->win->name); + } + priv->streaming = enable; + +done: + mutex_unlock(&priv->lock); + + return ret; } static unsigned int ov772x_select_fps(struct ov772x_priv *priv, @@ -743,9 +754,15 @@ static int ov772x_s_frame_interval(struct v4l2_subdev *sd, unsigned int fps; int ret = 0; + mutex_lock(&priv->lock); + + if (priv->streaming) { + ret = -EBUSY; + goto error; + } + fps = ov772x_select_fps(priv, tpf); - mutex_lock(&priv->lock); /* * If the device is not powered up by the host driver do * not apply any changes to H/W at this time. Instead @@ -1222,6 +1239,12 @@ static int ov772x_set_fmt(struct v4l2_subdev *sd, } mutex_lock(&priv->lock); + + if (priv->streaming) { + ret = -EBUSY; + goto error; + } + /* * If the device is not powered up by the host driver do * not apply any changes to H/W at this time. Instead