From patchwork Thu Sep 14 05:11:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou.Yang@microchip.com X-Patchwork-Id: 9952435 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 A665D6024A for ; Thu, 14 Sep 2017 05:14:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98EF6285A9 for ; Thu, 14 Sep 2017 05:14:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E05028973; Thu, 14 Sep 2017 05:14:27 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 101FB285A9 for ; Thu, 14 Sep 2017 05:14:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NDy5Bp9luDRj3hoFJePA16K+wBqSNqjYX197pDHdL6U=; b=rQKv+dC7qihzDT 1nSGueyVn790u8SIEWkDBEuLyecVsyiNP5xdzs2bguEiT+wNk0iIpAPZ+hGww2Q15TtHlnYPFdje5 hXIf8C4T357bbwWvbL5SeggqYVZ7ERr38E74Mm7W9gjVldW6blNi40/zPXAEhAbVdVFTs+a943X2b wH3NIZrKHXU+5dNXe6qDdoq7/5Q5oejP43+5JzahmWN02SxVH9+ADEdXC7fzRy7TpIEJj7tN8Tfvc 1rl2x/BCAz9UbMv2Kmt51Uh3jchE6qRthQ3oXqF4qUB29WCHI2R88E9b2ddN7UWpQWMX2oq28Dsai PInQgD3fY/HnD18OhqiQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dsMTk-0006OO-Nl; Thu, 14 Sep 2017 05:14:20 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dsMTh-0006NZ-A8 for linux-arm-kernel@bombadil.infradead.org; Thu, 14 Sep 2017 05:14:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JcWHEgnYdQ6lOVIurIsC7jEjGbZ2sIPLezxstrt7PJY=; b=pGBlEIWnSatgm81hx1MW9E0jH KuL4P1/IwW3KMLkRGcVCexCMNlyDXFNHL9AXhx5VDG3mWWnpO3TVCnQR5Jo83doeGM1/Ar1igc4ss 1gW1v/bMrspbqq8m/beXxfXN6/fBFPKlJjMWtRRLTUfNKKgv79vPthskz3AdCLFsMyjSG1p4V/R9J 2L81MXobOhmJ3m3x++o14ihqFohqYr/52L6fwMzUajnnJ02uT7sFneGYd5Ma55x6AopmmxvpKwpV7 mhFmkqVLj5Ufqs1tBwPzSAfMG4PTBRGseXy4DKk22h/DeHNnuXFRDGF9bReBmIcieZJyNcVHR8f/n Lf1SfH6jg==; Received: from nasmtp01.atmel.com ([192.199.1.245] helo=DVREDG01.corp.atmel.com) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dsMTd-00088A-TZ for linux-arm-kernel@lists.infradead.org; Thu, 14 Sep 2017 05:14:15 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by DVREDG01.corp.atmel.com (10.42.103.30) with Microsoft SMTP Server (TLS) id 14.3.235.1; Wed, 13 Sep 2017 23:12:57 -0600 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.3.235.1; Thu, 14 Sep 2017 13:17:21 +0800 From: Wenyou Yang To: Jonathan Corbet Subject: [PATCH v2 3/3] media: ov7670: Add the s_power operation Date: Thu, 14 Sep 2017 13:11:11 +0800 Message-ID: <20170914051111.18197-4-wenyou.yang@microchip.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170914051111.18197-1-wenyou.yang@microchip.com> References: <20170914051111.18197-1-wenyou.yang@microchip.com> MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wenyou Yang , linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , linux-arm-kernel@lists.infradead.org, Linux Media Mailing List Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add the s_power operation which is responsible for manipulating the power dowm mode through the PWDN pin and the reset operation through the RESET pin. Signed-off-by: Wenyou Yang --- Changes in v2: - Add the patch to support the get_fmt ops. - Remove the redundant invoking ov7670_init_gpio(). drivers/media/i2c/ov7670.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index efc738112e2a..d1211ae48f63 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -1530,6 +1530,22 @@ static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis } #endif +static int ov7670_s_power(struct v4l2_subdev *sd, int on) +{ + struct ov7670_info *info = to_state(sd); + + if (info->pwdn_gpio) + gpiod_direction_output(info->pwdn_gpio, !on); + if (on && info->resetb_gpio) { + gpiod_set_value(info->resetb_gpio, 1); + usleep_range(500, 1000); + gpiod_set_value(info->resetb_gpio, 0); + usleep_range(3000, 5000); + } + + return 0; +} + /* ----------------------------------------------------------------------- */ static const struct v4l2_subdev_core_ops ov7670_core_ops = { @@ -1539,6 +1555,7 @@ static const struct v4l2_subdev_core_ops ov7670_core_ops = { .g_register = ov7670_g_register, .s_register = ov7670_s_register, #endif + .s_power = ov7670_s_power, }; static const struct v4l2_subdev_video_ops ov7670_video_ops = { @@ -1645,23 +1662,25 @@ static int ov7670_probe(struct i2c_client *client, if (ret) return ret; - ret = ov7670_init_gpio(client, info); - if (ret) - goto clk_disable; - info->clock_speed = clk_get_rate(info->clk) / 1000000; if (info->clock_speed < 10 || info->clock_speed > 48) { ret = -EINVAL; goto clk_disable; } + ret = ov7670_init_gpio(client, info); + if (ret) + goto clk_disable; + + ov7670_s_power(sd, 1); + /* Make sure it's an ov7670 */ ret = ov7670_detect(sd); if (ret) { v4l_dbg(1, debug, client, "chip found @ 0x%x (%s) is not an ov7670 chip.\n", client->addr << 1, client->adapter->name); - goto clk_disable; + goto power_off; } v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); @@ -1734,6 +1753,8 @@ static int ov7670_probe(struct i2c_client *client, media_entity_cleanup(&info->sd.entity); hdl_free: v4l2_ctrl_handler_free(&info->hdl); +power_off: + ov7670_s_power(sd, 0); clk_disable: clk_disable_unprepare(info->clk); return ret; @@ -1749,6 +1770,7 @@ static int ov7670_remove(struct i2c_client *client) v4l2_ctrl_handler_free(&info->hdl); clk_disable_unprepare(info->clk); media_entity_cleanup(&info->sd.entity); + ov7670_s_power(sd, 0); return 0; }