From patchwork Sun Apr 22 15:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10355637 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 11E7860388 for ; Sun, 22 Apr 2018 15:57:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02CBB2893D for ; Sun, 22 Apr 2018 15:57:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBCC72897A; Sun, 22 Apr 2018 15:57:13 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, URIBL_RHS_DOB 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 87FBE2893D for ; Sun, 22 Apr 2018 15:57:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754519AbeDVP5L (ORCPT ); Sun, 22 Apr 2018 11:57:11 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40150 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754492AbeDVP5G (ORCPT ); Sun, 22 Apr 2018 11:57:06 -0400 Received: by mail-pf0-f194.google.com with SMTP id a26so2159351pfi.7; Sun, 22 Apr 2018 08:57:06 -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=pUd1dBLinzLqpVOCzF6snnfTOKzMOScs7SiMh7mX0SU=; b=t8TQzPjhT175JSMEOpuOY8Pwt20VYNInYJ+c7yeRpGvHFfYtAXCfUGDuI0W+kshBk3 BDFhCkcUxic6LjoiD9EmxwMlv6nQMPxinte1hn1LbydV7p5Cb/82HoEaXGAOiM5VR95J 8IDx5AQAJNCxZAo6XtKmHaAPOXSvO/69VsVlNs5euEvd6WBDIi2RKnkQoPb/9AK3jeQZ CmFIfDChMdMBdWd1PNu21x3vyNSWu0hMvnAmx1dJKdnRPxKs7xikklbykE73dN7LNMCL LzyrR9f5rJcumRQ2EfuxV6S2KUqd/IuA4QuFp5u5pBXgmwBB3J2goKFJAgI6CeP9Gbgj LlWA== 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=pUd1dBLinzLqpVOCzF6snnfTOKzMOScs7SiMh7mX0SU=; b=LjG7WDxmgzjLvkqeQZdbmFdykhA6/HTj12l5MFitpzdcmqAytnoYyhA/npF69t3x4K /hFKhvC+rmZED3jT+H8HrhF5qFERdoMWQjsCH7adOMhDCv/kDb5U5kFYKHACARw+ilng 63inEio3/HNMZyHpi5oU2V15eWg4KLakevLB+EB5NgKt1O4DvSUvA32V0J4lA1gYyfd8 gGjWEOWXpHDSnKpzYfYKM6kmT+Zt8tFVmd5HG5W4ifEtfJThPcmLi4EXSBGOeRptUbBA ANDIiyRrVVay1PV+uO5xNR67A9wd2/cuMSUkbRRioeJdSETRL9id/FDI3ctxzLWDpquj Nh1w== X-Gm-Message-State: ALQs6tCPXz8GK+WDmWy1Cx+UN+qW/5hiJPOUbakjA/Nyd+Al/WROk9XD oc37olan/tnLclRJOzLk+TKCDQ== X-Google-Smtp-Source: AIpwx49HOpmR6zLwmbBOz1XVWg1JPo16KiZLUz9ztAC4UWb15LArKI9OgqCIrLEpQitxl6mhoZ2WoA== X-Received: by 10.98.87.150 with SMTP id i22mr17116069pfj.119.1524412625795; Sun, 22 Apr 2018 08:57:05 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:a9a1:96f3:29de:6e47]) by smtp.gmail.com with ESMTPSA id y29sm255461pff.42.2018.04.22.08.57.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 08:57:05 -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 v3 10/11] media: ov772x: make set_fmt() return -EBUSY while streaming Date: Mon, 23 Apr 2018 00:56:16 +0900 Message-Id: <1524412577-14419-11-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524412577-14419-1-git-send-email-akinobu.mita@gmail.com> References: <1524412577-14419-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 --- * v3 - New patch 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 96dd37a..c9fdc67 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 */ unsigned short band_filter; 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, @@ -1223,6 +1234,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