From patchwork Tue May 19 01:16:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 11556711 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41253739 for ; Tue, 19 May 2020 01:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29800207D8 for ; Tue, 19 May 2020 01:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=globallogic.com header.i=@globallogic.com header.b="YzLYBztL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728085AbgESBQ5 (ORCPT ); Mon, 18 May 2020 21:16:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726731AbgESBQ5 (ORCPT ); Mon, 18 May 2020 21:16:57 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5210C05BD09 for ; Mon, 18 May 2020 18:16:55 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id u15so11915290ljd.3 for ; Mon, 18 May 2020 18:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=7L2zG59TWGJfih0i/D2e6VuwseQDT/Gv+Tbho6jYsmg=; b=YzLYBztLRqdtpL6C1U4ECjFv/yADbBd35LwtGHVt/KxEz3fwqf9t/hnhDYp6XlcH67 cZwvtdNOweY6yzpU/HZ5jUVLcTjYHrKAi7cK4InMnRqWkOdsauygsNv4i3klzPFjbZg/ hnGi4LYHu/pxsK1XI+NuHpZcAlCb2eQTsCR8ZCwNYrQ6GQu9hEeP1EQ/ZXIhmgK3+GtL 3baaROyzKmSnzB7Z6wVi7HpzhhrpyNGrVR9034xiGdmgYCyWWPEnPr7ARHuWVbdpmaHV xuQVcpD56m2flFcJLiWFik5lUPi5h4v9OJaJJFjxLpknLQkVSJLWLuWnohjRZzb/nmN2 HYGg== 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:in-reply-to:references; bh=7L2zG59TWGJfih0i/D2e6VuwseQDT/Gv+Tbho6jYsmg=; b=dOMm8TCksibV8TQG2V2OZR3YxoertUe9S/2iHQ65idJLejFnI6u9OEkSMAbPJnvVz1 FdYQ8xP3C9Gti+A1SqbKEi1XNFwq5V5gJEyXsR6yvsylms10gS/sumV7q1d7Ditomvtr FG9DkReerA0mIMhvEHbLa3FscEh9gcIhaXjcnQazX8I2cbxxAN5+1NYEDr34wsuFupU3 Tp62+tL2xLGszTRwFepDK0NjOxfqXJkYcuINo3nThPuXq37EYlgpAYGIBpVjAhLPVcPo OfK45tTSFHMr0uQlBSGSTe0fNol6cSdYSMHAUzxLvixuyh7TuYVutcR17JNFccYtcyyt XKFQ== X-Gm-Message-State: AOAM530jchV57J9FrAC92SSauB+X9HEJzTuhUlk616ufIewI03CwJUTU Ea31uHyaAw39Oy4mF3u7uZO+yQ== X-Google-Smtp-Source: ABdhPJyeWgqpM3ZzdT87L7XvXU2AlmWEEpASGJl2ly6pgrw4CaVmYaYbFxX1LWcuTx/boW+LY6I5FA== X-Received: by 2002:a2e:6e13:: with SMTP id j19mr12219584ljc.292.1589851014166; Mon, 18 May 2020 18:16:54 -0700 (PDT) Received: from localhost.localdomain ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id i8sm4764244lfl.72.2020.05.18.18.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 18:16:52 -0700 (PDT) From: Roman Kovalivskyi To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: Luis Oliveira , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi , Michael Rodin , Mauro Carvalho Chehab , Sakari Ailus , Hugues Fruchet , Maxime Ripard , Adam Ford , Todor Tomov , Suresh Udipi , Andrew Gabbasov , Eugeniu Rosca , Dave Stevenson , Roman Kovalivskyi Subject: [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO. Date: Tue, 19 May 2020 04:16:17 +0300 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Dave Stevenson Add support for an optional GPIO connected to PWDN on the sensor. This allows the use of hardware standby mode where internal device clock and circuit activities are halted. Please nothe that power is off when PWDN is high. Signed-off-by: Dave Stevenson Signed-off-by: Roman Kovalivskyi --- drivers/media/i2c/ov5647.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c index 3e587eb0a30e..796cc80f8ee1 100644 --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,13 @@ #define SENSOR_NAME "ov5647" +/* + * From the datasheet, "20ms after PWDN goes low or 20ms after RESETB goes + * high if reset is inserted after PWDN goes high, host can access sensor's + * SCCB to initialize sensor." + */ +#define PWDN_ACTIVE_DELAY_MS 20 + #define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5) #define MIPI_CTRL00_BUS_IDLE BIT(2) #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0) @@ -86,6 +94,7 @@ struct ov5647 { unsigned int height; int power_count; struct clk *xclk; + struct gpio_desc *pwdn; }; static inline struct ov5647 *to_state(struct v4l2_subdev *sd) @@ -93,6 +102,11 @@ static inline struct ov5647 *to_state(struct v4l2_subdev *sd) return container_of(sd, struct ov5647, sd); } +static inline void msleep_range(unsigned int delay_base) +{ + usleep_range(delay_base * 1000, delay_base * 1000 + 5000); +} + static struct regval_list sensor_oe_disable_regs[] = { {0x3000, 0x00}, {0x3001, 0x00}, @@ -355,6 +369,11 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on) if (on && !ov5647->power_count) { dev_dbg(&client->dev, "OV5647 power on\n"); + if (ov5647->pwdn) { + gpiod_set_value(ov5647->pwdn, 0); + msleep_range(PWDN_ACTIVE_DELAY_MS); + } + ret = clk_prepare_enable(ov5647->xclk); if (ret < 0) { dev_err(&client->dev, "clk prepare enable failed\n"); @@ -392,6 +411,8 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on) dev_dbg(&client->dev, "soft stby failed\n"); clk_disable_unprepare(ov5647->xclk); + + gpiod_set_value(ov5647->pwdn, 1); } /* Update the power count. */ @@ -603,6 +624,10 @@ static int ov5647_probe(struct i2c_client *client) return -EINVAL; } + /* Request the power down GPIO asserted */ + sensor->pwdn = devm_gpiod_get_optional(&client->dev, "pwdn", + GPIOD_OUT_HIGH); + mutex_init(&sensor->lock); sd = &sensor->sd; @@ -616,7 +641,15 @@ static int ov5647_probe(struct i2c_client *client) if (ret < 0) goto mutex_remove; + if (sensor->pwdn) { + gpiod_set_value(sensor->pwdn, 0); + msleep_range(PWDN_ACTIVE_DELAY_MS); + } + ret = ov5647_detect(sd); + + gpiod_set_value(sensor->pwdn, 1); + if (ret < 0) goto error;