Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3109714ybk; Mon, 18 May 2020 18:18:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBnmZit3eKWaRqQhyEwCUpkiPPy5gzfEENWn2orJRsJC50EUTWE7FM2iuMmf1gl9N6WsVc X-Received: by 2002:a17:907:2711:: with SMTP id w17mr16556834ejk.8.1589851127562; Mon, 18 May 2020 18:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589851127; cv=none; d=google.com; s=arc-20160816; b=ljsSOIDRpTtbmytmYCaJ1TEQWze7IxHqqnCNkNmRZH5SQV1byFzgKa4nAL9AUb3JtG pY1pkwbcAKEeyY0yhV8zLs1zksdtT+WqN07NMtYOlXEgDiA1bwoeeNNtEc1p0ZFD1bBG Edb6WLmrbpNOi0ISUxn509KZI3DX85qAHsBSnBGcHdDFgSnbZFbGR8fDaiSo0QtKOz7j bzt0c2HdBwBjyf7PwJVjufF25DXPkoztX5TJXffWqV5GLWc3npxSg81eFpezxMPDw9u/ LeXA2d57Z78r3hHdwGiZUizgIp0Lz4p9Xs9yhTg8nHRYpYxQtYglCcU8UOLw3YDcNZiV fYCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=7L2zG59TWGJfih0i/D2e6VuwseQDT/Gv+Tbho6jYsmg=; b=L8J1RjWaIrgAqa7OLNQQwOH3luOkSycBONXBjcI1I4dVI6gkuZZMIql16+MW+/ERFx 3L9v5cnGpwqw36K3FUnIoIwylWl3RtpkdTLR2L9O/Nd0IkaC/FGpKva1CIbMGWF8PXq7 W4UoEuKHiXT3HjKD6INq58pysEtq3Dr3KWTKvc/w3aWPZO5hLtAkGJER4E5W4N/vjmaP EqgOPufbAsCYyLPho7wHYRmMK5Z5/IEoAbzlJW8Hl/2dgrn655m6cj/GhRFBfAswDcPn PH00BPgPDMihgL47qyNaL6AUktEpH0+X/jDgJ0Y6JB2Khc4cyPMP3hHzpDSmt6Jx8HjU Y7CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@globallogic.com header.s=google header.b=YzLYBztL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=globallogic.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c21si7810319edx.105.2020.05.18.18.18.24; Mon, 18 May 2020 18:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@globallogic.com header.s=google header.b=YzLYBztL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=globallogic.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728111AbgESBQ6 (ORCPT + 99 others); Mon, 18 May 2020 21:16:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728061AbgESBQ5 (ORCPT ); Mon, 18 May 2020 21:16:57 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2C78C05BD0A for ; Mon, 18 May 2020 18:16:55 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id l19so11911840lje.10 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=fh//qnj2f8oq9v53+RWk7AKNbKbcr3v3EoqXhAAxDyIqnNhaolj8gKKTCfTh1OH4SB JpGIqxJnvyBWvt7Up/dl/YmHKXSMgai4xodJskXPXF3ktNEm43Um4PXBVqyIQHZHl1rA Qyt1oK0LorpfSGytgQu129/gEMXjGOIjOqJ/8tUceTFGTmPxhswAiZrAzHcUiYjt4/bn lHf1E/oFCNUcZjahmXRIiWftf9G2wcOsy6KqKWwzNx/qw5wHdVzzLafbb/IEA3QemvO0 7zKz455Ffs3dNcuOotweHFhbUFZJ9QJ2on2aXTxYbcqavmyeFrE2dv4HoyyejXsI7QMU w0Bw== X-Gm-Message-State: AOAM530ihF/ZWa2nzkW7G1KRm25M0PhrDetmuPfphkSGYfkd/vJHxukt bjboNlm2sBWESrLUn07W8T83u2nHPYnNqw== 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=20S=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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; -- 2.17.1