From patchwork Sat Feb 10 15:28:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10210529 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 C8DB160236 for ; Sat, 10 Feb 2018 15:29:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9AA429165 for ; Sat, 10 Feb 2018 15:29:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE0C22965E; Sat, 10 Feb 2018 15:29:06 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 4924729165 for ; Sat, 10 Feb 2018 15:29:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751248AbeBJP3F (ORCPT ); Sat, 10 Feb 2018 10:29:05 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:39764 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751193AbeBJP3D (ORCPT ); Sat, 10 Feb 2018 10:29:03 -0500 Received: by mail-pg0-f67.google.com with SMTP id w17so5253199pgv.6 for ; Sat, 10 Feb 2018 07:29:03 -0800 (PST) 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=frjfn0yBxM8/kDRLUfRiCecDFhIiEYKuEABEY9CREQI=; b=gS0HD52jXCfrzjlNQ8q1xvx85Q9a2B3uPlmg+IrFgVnZTgfdHkeeqTeEjLtv/sWszz numLwLooBC08RjbeGAEd96+jCVpbS/9BIIabLRM8C1GswZ2nAvi/8wrp+d/q5Vx3/34R FbJpxCRaikwWur6O3KoJSbEIUvSzqJcremPtJWl54K3TLtbVdflI3uxkfs0amLDq3iA4 XEaLFOM9DPFhKwk9hPZsTGTk96aRmNu/swDokkqN72qmHCUuiX5+gnCKahIFFnKhTOf5 zfRzOvhKUuPhx4LMNyifsT9vDePOhwq85Rm1xG/umYcLwAvFhuUsSr/jAQf7ndMtV3Kp IQRg== 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=frjfn0yBxM8/kDRLUfRiCecDFhIiEYKuEABEY9CREQI=; b=q5hmIpRnajuqixjuMt7vzbf8+Cx96SA4WzdEk6G60Ohpy91tKsmuFV6RS69ol8W7/j XLoaPX+kv+3RjF8QRsIfuSRjDlXUrQLNNSi8/xmSUPbXQRqA2ONnz03cJERdiKha1gFv 8yHbd09QgkpeWrzWFJSddgJn7urQPVhlJR3utpAP9fMtVgn/MLNrKzP+aoQULxBxKrYd Mvteiln2a8E77XQ3XGRP/Fio9WrkLDyfMnpHCbSOzZAJdnDFCanIv4xPXS7HSn0jlCr0 nijJlRSqywlohw+1n0dRZae9WtcJfdpa4I7JXuHK+AKaIQ6gFxvmO10m6n35UQtskMnj 3WSg== X-Gm-Message-State: APf1xPDje/E1AAH0FO2MRGEqwbKHZPiA6X1GZFTsc8G85ryR+Ls+NBHH 9+2THv5MgL8YDQsohVwamSJW0Q== X-Google-Smtp-Source: AH8x227Hd3scyoifAgiuo6lFljdPLPZ/Fzc6qeksd899fKqh4jaeJ3rn2NlpThO5ph/tF8xHStybXQ== X-Received: by 10.99.36.65 with SMTP id k62mr5319138pgk.345.1518276543175; Sat, 10 Feb 2018 07:29:03 -0800 (PST) Received: from localhost.localdomain ([240f:4:c2bc:1:9d99:12e4:6b69:f07a]) by smtp.gmail.com with ESMTPSA id e189sm13144736pfa.4.2018.02.10.07.29.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Feb 2018 07:29:02 -0800 (PST) From: Akinobu Mita To: linux-media@vger.kernel.org Cc: Akinobu Mita , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH 2/2] media: ov2640: make s_ctrl() work in power-down mode Date: Sun, 11 Feb 2018 00:28:38 +0900 Message-Id: <1518276518-14034-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518276518-14034-1-git-send-email-akinobu.mita@gmail.com> References: <1518276518-14034-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 s_ctrl() operation can be called when the device is placed into power down mode. Then, applying controls to H/W should be postponed at this time. Instead the controls will be restored when the streaming is started. Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- drivers/media/i2c/ov2640.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/ov2640.c b/drivers/media/i2c/ov2640.c index 68a356d..beb7220 100644 --- a/drivers/media/i2c/ov2640.c +++ b/drivers/media/i2c/ov2640.c @@ -308,8 +308,9 @@ struct ov2640_priv { struct gpio_desc *resetb_gpio; struct gpio_desc *pwdn_gpio; - struct mutex lock; /* lock to protect streaming */ + struct mutex lock; /* lock to protect streaming and power_count */ bool streaming; + int power_count; }; /* @@ -712,9 +713,20 @@ static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl) struct v4l2_subdev *sd = &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev; struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov2640_priv *priv = to_ov2640(client); u8 val; int ret; + /* v4l2_ctrl_lock() locks our own mutex */ + + /* + * If the device is not powered up by the host driver, do not apply any + * controls to H/W at this time. Instead the controls will be restored + * when the streaming is started. + */ + if (!priv->power_count) + return 0; + ret = i2c_smbus_write_byte_data(client, BANK_SEL, BANK_SEL_SENS); if (ret < 0) return ret; @@ -766,12 +778,9 @@ static int ov2640_s_register(struct v4l2_subdev *sd, } #endif -static int ov2640_s_power(struct v4l2_subdev *sd, int on) +static void ov2640_set_power(struct ov2640_priv *priv, int on) { #ifdef CONFIG_GPIOLIB - struct i2c_client *client = v4l2_get_subdevdata(sd); - struct ov2640_priv *priv = to_ov2640(client); - if (priv->pwdn_gpio) gpiod_direction_output(priv->pwdn_gpio, !on); if (on && priv->resetb_gpio) { @@ -781,6 +790,25 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on) gpiod_set_value(priv->resetb_gpio, 0); } #endif +} + +static int ov2640_s_power(struct v4l2_subdev *sd, int on) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov2640_priv *priv = to_ov2640(client); + + mutex_lock(&priv->lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (priv->power_count == !on) + ov2640_set_power(priv, on); + priv->power_count += on ? 1 : -1; + WARN_ON(priv->power_count < 0); + mutex_unlock(&priv->lock); + return 0; } @@ -1005,6 +1033,8 @@ static int ov2640_s_stream(struct v4l2_subdev *sd, int on) if (on) { ret = ov2640_set_params(client, priv->win, priv->cfmt_code); + if (!ret) + ret = __v4l2_ctrl_handler_setup(&priv->hdl); } } if (!ret) @@ -1049,8 +1079,6 @@ static int ov2640_video_probe(struct i2c_client *client) "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", devname, pid, ver, midh, midl); - ret = v4l2_ctrl_handler_setup(&priv->hdl); - done: ov2640_s_power(&priv->subdev, 0); return ret; @@ -1158,6 +1186,7 @@ static int ov2640_probe(struct i2c_client *client, priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; mutex_init(&priv->lock); v4l2_ctrl_handler_init(&priv->hdl, 2); + priv->hdl.lock = &priv->lock; v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,