From patchwork Mon Nov 9 16:49:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 321610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D32E9C388F7 for ; Mon, 9 Nov 2020 16:50:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A02DC20E65 for ; Mon, 9 Nov 2020 16:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730700AbgKIQuC (ORCPT ); Mon, 9 Nov 2020 11:50:02 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:39969 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730546AbgKIQuC (ORCPT ); Mon, 9 Nov 2020 11:50:02 -0500 X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 60C8D1BF203; Mon, 9 Nov 2020 16:49:58 +0000 (UTC) From: Jacopo Mondi To: linux-media@vger.kernel.org Cc: Jacopo Mondi , mchehab@kernel.org, sakari.ailus@linux.intel.com, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, roman.kovalivskyi@globallogic.com, dafna.hirschfeld@collabora.com, dave.stevenson@raspberrypi.org, naush@raspberrypi.com, erosca@de.adit-jv.com Subject: [PATCH v3 08/29] media: ov5647: Program mode at s_stream(1) time Date: Mon, 9 Nov 2020 17:49:13 +0100 Message-Id: <20201109164934.134919-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201109164934.134919-1-jacopo@jmondi.org> References: <20201109164934.134919-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Rename __sensor_init() function to ov5647_set_mode() as the function is a regular one and the double underscores prefix shall be removed, and then move it to program the mode at s_stream(1) time, not at sensor power up. Break out from __sensor_init() the stream_off() operation call at sensor power up to coax the lanes in LP-11 state. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/ov5647.c | 81 +++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c index c04ef44ccf2ab..b9f19165b3491 100644 --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c @@ -264,12 +264,54 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel) return ov5647_write(sd, OV5647_REG_MIPI_CTRL14, channel_id | (channel << 6)); } +static int ov5647_set_mode(struct v4l2_subdev *sd) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + u8 resetval, rdval; + int ret; + + ret = ov5647_read(sd, OV5647_SW_STANDBY, &rdval); + if (ret < 0) + return ret; + + ret = ov5647_write_array(sd, ov5647_640x480, + ARRAY_SIZE(ov5647_640x480)); + if (ret < 0) { + dev_err(&client->dev, "write sensor default regs error\n"); + return ret; + } + + ret = ov5647_set_virtual_channel(sd, 0); + if (ret < 0) + return ret; + + ret = ov5647_read(sd, OV5647_SW_STANDBY, &resetval); + if (ret < 0) + return ret; + + if (!(resetval & 0x01)) { + dev_err(&client->dev, "Device was in SW standby"); + ret = ov5647_write(sd, OV5647_SW_STANDBY, 0x01); + if (ret < 0) + return ret; + } + + return 0; +} + static int ov5647_stream_on(struct v4l2_subdev *sd) { + struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov5647 *ov5647 = to_state(sd); u8 val = MIPI_CTRL00_BUS_IDLE; int ret; + ret = ov5647_set_mode(sd); + if (ret) { + dev_err(&client->dev, "Failed to program sensor mode: %d\n", ret); + return ret; + } + if (ov5647->clock_ncont) val |= MIPI_CTRL00_CLOCK_LANE_GATE | MIPI_CTRL00_LINE_SYNC_ENABLE; @@ -318,42 +360,6 @@ static int set_sw_standby(struct v4l2_subdev *sd, bool standby) return ov5647_write(sd, OV5647_SW_STANDBY, rdval); } -static int __sensor_init(struct v4l2_subdev *sd) -{ - struct i2c_client *client = v4l2_get_subdevdata(sd); - u8 resetval, rdval; - int ret; - - ret = ov5647_read(sd, OV5647_SW_STANDBY, &rdval); - if (ret < 0) - return ret; - - ret = ov5647_write_array(sd, ov5647_640x480, - ARRAY_SIZE(ov5647_640x480)); - if (ret < 0) { - dev_err(&client->dev, "write sensor default regs error\n"); - return ret; - } - - ret = ov5647_set_virtual_channel(sd, 0); - if (ret < 0) - return ret; - - ret = ov5647_read(sd, OV5647_SW_STANDBY, &resetval); - if (ret < 0) - return ret; - - if (!(resetval & 0x01)) { - dev_err(&client->dev, "Device was in SW standby"); - ret = ov5647_write(sd, OV5647_SW_STANDBY, 0x01); - if (ret < 0) - return ret; - } - - /* Stream off to make the clock lane into LP-11 state. */ - return ov5647_stream_off(sd); -} - static int ov5647_sensor_power(struct v4l2_subdev *sd, int on) { struct i2c_client *client = v4l2_get_subdevdata(sd); @@ -385,7 +391,8 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on) goto out; } - ret = __sensor_init(sd); + /* Stream off to coax lanes into LP-11 state. */ + ret = ov5647_stream_off(sd); if (ret < 0) { clk_disable_unprepare(ov5647->xclk); dev_err(&client->dev,