From patchwork Sun Apr 29 17:13:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10370627 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 3956560384 for ; Sun, 29 Apr 2018 17:14:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28A7C28A18 for ; Sun, 29 Apr 2018 17:14:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D2FB28A25; Sun, 29 Apr 2018 17:14:16 +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 B289728A18 for ; Sun, 29 Apr 2018 17:14:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754062AbeD2RON (ORCPT ); Sun, 29 Apr 2018 13:14:13 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33830 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754059AbeD2ROL (ORCPT ); Sun, 29 Apr 2018 13:14:11 -0400 Received: by mail-pf0-f195.google.com with SMTP id a14so5007497pfi.1; Sun, 29 Apr 2018 10:14:10 -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=gL1sUXFVaJ30aRpTLQuMdoBVnWZQFaqNysaQyWnuXnE=; b=V3Co4x175Kz1XYskVoPMA1Kv/t18FLZuljMI60ggktc4xAl8RlHI5YYBLWursdBdSJ 8zsFILCkGKNTEsrIoUZO4ZdZEzB4+Mglm0z3WT4rU5IvowrYvHnhb5SWP2PvAPlgdTC+ lIcHVQi774gCSUFVb7a2hgkOjrfjWD0V53E7IyKBc+krWPexkqntuJoyTEp5osgQiPHa zW2D5b2t5WL6FAL6+UL+NTR1jlN1wdoQpGmOuRhWXsv793/y1wwK+h+2WBHF2GHhe0cH VHKNMTjmLfJ5TLkYcRoJUZJkKAFdkHSqEVcpa4P4w/8EReAwWeGvhaNpYF/4JAl5h/nr A2nA== 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=gL1sUXFVaJ30aRpTLQuMdoBVnWZQFaqNysaQyWnuXnE=; b=nLzHJUZfGRkHXDMDXq68jOSJParw0ejgEmSefGFssgxE16XekMovd9A0+7gg6BtgsC eVRbrakDVyAxfBB28a1NkHe0t6SyE0nvOktHsG+sAfdfkt3oIP+I6F/Fljd1EAxFbcW4 qx7GNLPcuCzUx8YbPVEk2m4HMKxm09ix/jv5D8qnjZq8A9impuxdryl+WoNYdnoNwweO lf8I8MryChS3/r5Ge9SAYELVVu++bEbCBnbkCintsQkEbFCuuxSeW6gPwooTfQdvzkXs XYsyBMyOxTGaWyjvyI3vrwcNNR8r8MiJTjcIeIxuf6w8I62D8/YBi/XX3WJbnhkuAFRx o9IQ== X-Gm-Message-State: ALQs6tBUbfOQJHgEbZQ35LCL5Je+ky8Q+LemWDHs5PYQ8FdoGUtWGqk3 K5RA9zFEfdrXOmL3noRXVtnsvQ== X-Google-Smtp-Source: AB8JxZru/8W8frctI+k04Lw5qdKavSQp1/YHLJhMxoQkahmhiPLwRbT6tLZ/kwa6DDoB9ZzH1FPBnA== X-Received: by 2002:a65:50cc:: with SMTP id s12-v6mr8115152pgp.313.1525022050429; Sun, 29 Apr 2018 10:14:10 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:754e:5a21:c35f:52a1]) by smtp.gmail.com with ESMTPSA id e10sm10168022pfn.67.2018.04.29.10.14.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Apr 2018 10:14:09 -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 v4 13/14] media: ov772x: make set_fmt() return -EBUSY while streaming Date: Mon, 30 Apr 2018 02:13:12 +0900 Message-Id: <1525021993-17789-14-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525021993-17789-1-git-send-email-akinobu.mita@gmail.com> References: <1525021993-17789-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 on this sub-device can be made anytime. However, the request is 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 --- * v4 - No changes drivers/media/i2c/ov772x.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index bd37169..f3c4f78 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, @@ -1222,6 +1233,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