Message ID | 20221005152809.3785786-9-dave.stevenson@raspberrypi.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Sakari Ailus |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1og6KU-00DXCG-8v; Wed, 05 Oct 2022 15:29:02 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbiJEP3A (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Wed, 5 Oct 2022 11:29:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbiJEP24 (ORCPT <rfc822;linux-media@vger.kernel.org>); Wed, 5 Oct 2022 11:28:56 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C6FD61709 for <linux-media@vger.kernel.org>; Wed, 5 Oct 2022 08:28:55 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b4so19544597wrs.1 for <linux-media@vger.kernel.org>; Wed, 05 Oct 2022 08:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=zlo94kx4d/0h4pXbHO90YkVJN9vv7NJ7f1xqV+w4aSk=; b=KFWC/4eYIFbRKVqKYeSpjXdMxe8bbzsgmkCvNXOTZxlaHJRhNtAmg025qHpy01gUxY LshgslbbW7zoGivy+zhuZs0YSKsY7hAGVbFmSbhVjKYOZ6mkDniwkFC33dx1ONTIqSbk 1ELDv5tkLMDi1kiYlht7+THObyTOLl2fhkUberKKWkqFv8z9fniR/FBv/zxyHUrQUZIu 2OWWAPeL7L/xzwezBQVeOahgG1oThXs7eQzPLzw+UozG4p3BYfiFYBs3l/y7WELKdQwd 0SUr/B6rQKa2KebKqCChJNs0mnyelGhdYWY4gQ42gk5p100qPvAxGham5CEfdxexqExh dCFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=zlo94kx4d/0h4pXbHO90YkVJN9vv7NJ7f1xqV+w4aSk=; b=NAC4GyUtu/j+4TWXqus0mSIFL3lROyViF5gQclcUaE1M2rAPDpmO1C8s1lOmdtfGLe YTA9Z+8ZypJKnBLI3agzzCYS+s6enDoXxWW8LmnHJ1b09iFksGsYR+33Bz+JzIe8sTv6 r0YNOb7EwXndiA0190YFLsZwlPbY+MezWorJYj7XdZdPGFEEPMbbzKOkcIhPp4Vka7Nw Zde4oCFF0s+Brwf0GBt3EIaBxi0sES6CcO14BvaQWAjRf81mY0UwhLHPQosat2eZe03i my+ampLmdT8QRQIW40F7m0PtEPhzyKKT7PB7w0/4QSJEF4XNDPyMkG/CwgKoJAYWhd7n vUFg== X-Gm-Message-State: ACrzQf1ioTBpmMNRoJik+Uagy/88fyz+5ux0JzWE+2GlwmfxIcM3b9Cr EgUb8nnp7JvtQXaGM1vH12Y6mA== X-Google-Smtp-Source: AMsMyM7L809sxZHq+IW2V016tulXRpQFYEM1C3I6vpQFyGdZm2spAMBAFEQT4BwhBYu4yfLMA35x+w== X-Received: by 2002:a05:6000:1f81:b0:22c:c692:5c49 with SMTP id bw1-20020a0560001f8100b0022cc6925c49mr194276wrb.630.1664983733614; Wed, 05 Oct 2022 08:28:53 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id y14-20020adfe6ce000000b0022c96d3b6f2sm19747237wrm.54.2022.10.05.08.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 08:28:53 -0700 (PDT) From: Dave Stevenson <dave.stevenson@raspberrypi.com> To: paul.j.murphy@intel.com, daniele.alessandrelli@intel.com, linux-media@vger.kernel.org Cc: Dave Stevenson <dave.stevenson@raspberrypi.com> Subject: [PATCH 08/16] media: i2c: ov9282: Add selection for CSI2 clock mode Date: Wed, 5 Oct 2022 16:28:01 +0100 Message-Id: <20221005152809.3785786-9-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221005152809.3785786-1-dave.stevenson@raspberrypi.com> References: <20221005152809.3785786-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
Updates to ov9282 sensor driver
|
|
Commit Message
Dave Stevenson
Oct. 5, 2022, 3:28 p.m. UTC
The sensor supports either having the CSI2 clock lane free
running, or gated when there is no packet to transmit.
The driver only selected gated (non-continuous) clock mode.
Add code to allow fwnode to configure whether the clock is
gated or free running.
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
drivers/media/i2c/ov9282.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
Comments
Hi Dave On Wed, Oct 05, 2022 at 04:28:01PM +0100, Dave Stevenson wrote: > The sensor supports either having the CSI2 clock lane free > running, or gated when there is no packet to transmit. > The driver only selected gated (non-continuous) clock mode. > > Add code to allow fwnode to configure whether the clock is > gated or free running. > > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> > --- > drivers/media/i2c/ov9282.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c > index abb1223c0260..334b31af34a4 100644 > --- a/drivers/media/i2c/ov9282.c > +++ b/drivers/media/i2c/ov9282.c > @@ -46,6 +46,9 @@ > /* Group hold register */ > #define OV9282_REG_HOLD 0x3308 > > +#define OV9282_REG_MIPI_CTRL00 0x4800 > +#define OV9282_GATED_CLOCK BIT(5) > + > /* Input clock rate */ > #define OV9282_INCLK_RATE 24000000 > > @@ -138,6 +141,7 @@ struct ov9282 { > struct clk *inclk; > struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; > struct v4l2_ctrl_handler ctrl_handler; > + bool noncontinuous_clock; Nit: I would move this down after the controls, where vblank is > struct v4l2_ctrl *link_freq_ctrl; > struct v4l2_ctrl *hblank_ctrl; > struct v4l2_ctrl *vblank_ctrl; > @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { > {0x4601, 0x04}, > {0x470f, 0x00}, > {0x4f07, 0x00}, > - {0x4800, 0x20}, > {0x5000, 0x9f}, > {0x5001, 0x00}, > {0x5e00, 0x00}, > @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) > return ret; > } > > + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, > + ov9282->noncontinuous_clock ? > + OV9282_GATED_CLOCK : 0); > + if (ret) { > + dev_err(ov9282->dev, "fail to write MIPI_CTRL00"); > + return ret; > + } > + > /* Write sensor mode registers */ > reg_list = &ov9282->cur_mode->reg_list; > ret = ov9282_write_regs(ov9282, reg_list->regs, reg_list->num_of_regs); > @@ -861,6 +872,9 @@ static int ov9282_parse_hw_config(struct ov9282 *ov9282) > if (ret) > return ret; > > + ov9282->noncontinuous_clock = > + bus_cfg.bus.mipi_csi2.flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; > + The patch looks good Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV9282_NUM_DATA_LANES) { > dev_err(ov9282->dev, > "number of CSI2 data lanes %d is not supported", > -- > 2.34.1 >
Hi Dave, On Wed, Oct 05, 2022 at 04:28:01PM +0100, Dave Stevenson wrote: > The sensor supports either having the CSI2 clock lane free > running, or gated when there is no packet to transmit. > The driver only selected gated (non-continuous) clock mode. > > Add code to allow fwnode to configure whether the clock is > gated or free running. > > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> > --- > drivers/media/i2c/ov9282.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c > index abb1223c0260..334b31af34a4 100644 > --- a/drivers/media/i2c/ov9282.c > +++ b/drivers/media/i2c/ov9282.c > @@ -46,6 +46,9 @@ > /* Group hold register */ > #define OV9282_REG_HOLD 0x3308 > > +#define OV9282_REG_MIPI_CTRL00 0x4800 > +#define OV9282_GATED_CLOCK BIT(5) > + > /* Input clock rate */ > #define OV9282_INCLK_RATE 24000000 > > @@ -138,6 +141,7 @@ struct ov9282 { > struct clk *inclk; > struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; > struct v4l2_ctrl_handler ctrl_handler; > + bool noncontinuous_clock; > struct v4l2_ctrl *link_freq_ctrl; > struct v4l2_ctrl *hblank_ctrl; > struct v4l2_ctrl *vblank_ctrl; > @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { > {0x4601, 0x04}, > {0x470f, 0x00}, > {0x4f07, 0x00}, > - {0x4800, 0x20}, > {0x5000, 0x9f}, > {0x5001, 0x00}, > {0x5e00, 0x00}, > @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) > return ret; > } > > + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, > + ov9282->noncontinuous_clock ? > + OV9282_GATED_CLOCK : 0); Wouldn't this better fit for power on? > + if (ret) { > + dev_err(ov9282->dev, "fail to write MIPI_CTRL00"); > + return ret; > + } > + > /* Write sensor mode registers */ > reg_list = &ov9282->cur_mode->reg_list; > ret = ov9282_write_regs(ov9282, reg_list->regs, reg_list->num_of_regs); > @@ -861,6 +872,9 @@ static int ov9282_parse_hw_config(struct ov9282 *ov9282) > if (ret) > return ret; > > + ov9282->noncontinuous_clock = > + bus_cfg.bus.mipi_csi2.flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; > + > if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV9282_NUM_DATA_LANES) { > dev_err(ov9282->dev, > "number of CSI2 data lanes %d is not supported",
Hi Sakari On Wed, 26 Oct 2022 at 08:21, Sakari Ailus <sakari.ailus@iki.fi> wrote: > > Hi Dave, > > On Wed, Oct 05, 2022 at 04:28:01PM +0100, Dave Stevenson wrote: > > The sensor supports either having the CSI2 clock lane free > > running, or gated when there is no packet to transmit. > > The driver only selected gated (non-continuous) clock mode. > > > > Add code to allow fwnode to configure whether the clock is > > gated or free running. > > > > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> > > --- > > drivers/media/i2c/ov9282.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c > > index abb1223c0260..334b31af34a4 100644 > > --- a/drivers/media/i2c/ov9282.c > > +++ b/drivers/media/i2c/ov9282.c > > @@ -46,6 +46,9 @@ > > /* Group hold register */ > > #define OV9282_REG_HOLD 0x3308 > > > > +#define OV9282_REG_MIPI_CTRL00 0x4800 > > +#define OV9282_GATED_CLOCK BIT(5) > > + > > /* Input clock rate */ > > #define OV9282_INCLK_RATE 24000000 > > > > @@ -138,6 +141,7 @@ struct ov9282 { > > struct clk *inclk; > > struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; > > struct v4l2_ctrl_handler ctrl_handler; > > + bool noncontinuous_clock; > > struct v4l2_ctrl *link_freq_ctrl; > > struct v4l2_ctrl *hblank_ctrl; > > struct v4l2_ctrl *vblank_ctrl; > > @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { > > {0x4601, 0x04}, > > {0x470f, 0x00}, > > {0x4f07, 0x00}, > > - {0x4800, 0x20}, > > {0x5000, 0x9f}, > > {0x5001, 0x00}, > > {0x5e00, 0x00}, > > @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) > > return ret; > > } > > > > + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, > > + ov9282->noncontinuous_clock ? > > + OV9282_GATED_CLOCK : 0); > > Wouldn't this better fit for power on? It can be done in ov9282_power_on, but is then totally redundantly set when powering the sensor up to read the ID during initial probe. Doing so also means there needs to be a great big warning never to change the driver and hit the software reset via writing 0x01 to register 0x0103 as part of any register array (very common in many other sensor drivers). I'll move it and add a comment before the register tables. Dave > > + if (ret) { > > + dev_err(ov9282->dev, "fail to write MIPI_CTRL00"); > > + return ret; > > + } > > + > > /* Write sensor mode registers */ > > reg_list = &ov9282->cur_mode->reg_list; > > ret = ov9282_write_regs(ov9282, reg_list->regs, reg_list->num_of_regs); > > @@ -861,6 +872,9 @@ static int ov9282_parse_hw_config(struct ov9282 *ov9282) > > if (ret) > > return ret; > > > > + ov9282->noncontinuous_clock = > > + bus_cfg.bus.mipi_csi2.flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; > > + > > if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV9282_NUM_DATA_LANES) { > > dev_err(ov9282->dev, > > "number of CSI2 data lanes %d is not supported", > > -- > Kind regards, > > Sakari Ailus
Hi Dave, On Fri, Oct 28, 2022 at 01:57:48PM +0100, Dave Stevenson wrote: > Hi Sakari > > On Wed, 26 Oct 2022 at 08:21, Sakari Ailus <sakari.ailus@iki.fi> wrote: > > > > Hi Dave, > > > > On Wed, Oct 05, 2022 at 04:28:01PM +0100, Dave Stevenson wrote: > > > The sensor supports either having the CSI2 clock lane free > > > running, or gated when there is no packet to transmit. > > > The driver only selected gated (non-continuous) clock mode. > > > > > > Add code to allow fwnode to configure whether the clock is > > > gated or free running. > > > > > > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> > > > --- > > > drivers/media/i2c/ov9282.c | 16 +++++++++++++++- > > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c > > > index abb1223c0260..334b31af34a4 100644 > > > --- a/drivers/media/i2c/ov9282.c > > > +++ b/drivers/media/i2c/ov9282.c > > > @@ -46,6 +46,9 @@ > > > /* Group hold register */ > > > #define OV9282_REG_HOLD 0x3308 > > > > > > +#define OV9282_REG_MIPI_CTRL00 0x4800 > > > +#define OV9282_GATED_CLOCK BIT(5) > > > + > > > /* Input clock rate */ > > > #define OV9282_INCLK_RATE 24000000 > > > > > > @@ -138,6 +141,7 @@ struct ov9282 { > > > struct clk *inclk; > > > struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; > > > struct v4l2_ctrl_handler ctrl_handler; > > > + bool noncontinuous_clock; > > > struct v4l2_ctrl *link_freq_ctrl; > > > struct v4l2_ctrl *hblank_ctrl; > > > struct v4l2_ctrl *vblank_ctrl; > > > @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { > > > {0x4601, 0x04}, > > > {0x470f, 0x00}, > > > {0x4f07, 0x00}, > > > - {0x4800, 0x20}, > > > {0x5000, 0x9f}, > > > {0x5001, 0x00}, > > > {0x5e00, 0x00}, > > > @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) > > > return ret; > > > } > > > > > > + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, > > > + ov9282->noncontinuous_clock ? > > > + OV9282_GATED_CLOCK : 0); > > > > Wouldn't this better fit for power on? > > It can be done in ov9282_power_on, but is then totally redundantly set > when powering the sensor up to read the ID during initial probe. This is the same also when streaming is enabled and disabled multiple times while the sensor is powered on. Although without autosuspend this may be unlikely. > Doing so also means there needs to be a great big warning never to > change the driver and hit the software reset via writing 0x01 to > register 0x0103 as part of any register array (very common in many > other sensor drivers). If there's a desire to reset the sensor after powering it up, that should be done as the first thing after power-up. Setting non-continuous clock isn't anything special here. But that's up to you. I guess lane configuration etc. is part of the big register lists. > > I'll move it and add a comment before the register tables. I think it's unnecessary.
Hi Sakari On Fri, 28 Oct 2022 at 15:30, Sakari Ailus <sakari.ailus@iki.fi> wrote: > > Hi Dave, > > On Fri, Oct 28, 2022 at 01:57:48PM +0100, Dave Stevenson wrote: > > Hi Sakari > > > > On Wed, 26 Oct 2022 at 08:21, Sakari Ailus <sakari.ailus@iki.fi> wrote: > > > > > > Hi Dave, > > > > > > On Wed, Oct 05, 2022 at 04:28:01PM +0100, Dave Stevenson wrote: > > > > The sensor supports either having the CSI2 clock lane free > > > > running, or gated when there is no packet to transmit. > > > > The driver only selected gated (non-continuous) clock mode. > > > > > > > > Add code to allow fwnode to configure whether the clock is > > > > gated or free running. > > > > > > > > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> > > > > --- > > > > drivers/media/i2c/ov9282.c | 16 +++++++++++++++- > > > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c > > > > index abb1223c0260..334b31af34a4 100644 > > > > --- a/drivers/media/i2c/ov9282.c > > > > +++ b/drivers/media/i2c/ov9282.c > > > > @@ -46,6 +46,9 @@ > > > > /* Group hold register */ > > > > #define OV9282_REG_HOLD 0x3308 > > > > > > > > +#define OV9282_REG_MIPI_CTRL00 0x4800 > > > > +#define OV9282_GATED_CLOCK BIT(5) > > > > + > > > > /* Input clock rate */ > > > > #define OV9282_INCLK_RATE 24000000 > > > > > > > > @@ -138,6 +141,7 @@ struct ov9282 { > > > > struct clk *inclk; > > > > struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; > > > > struct v4l2_ctrl_handler ctrl_handler; > > > > + bool noncontinuous_clock; > > > > struct v4l2_ctrl *link_freq_ctrl; > > > > struct v4l2_ctrl *hblank_ctrl; > > > > struct v4l2_ctrl *vblank_ctrl; > > > > @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { > > > > {0x4601, 0x04}, > > > > {0x470f, 0x00}, > > > > {0x4f07, 0x00}, > > > > - {0x4800, 0x20}, > > > > {0x5000, 0x9f}, > > > > {0x5001, 0x00}, > > > > {0x5e00, 0x00}, > > > > @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) > > > > return ret; > > > > } > > > > > > > > + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, > > > > + ov9282->noncontinuous_clock ? > > > > + OV9282_GATED_CLOCK : 0); > > > > > > Wouldn't this better fit for power on? > > > > It can be done in ov9282_power_on, but is then totally redundantly set > > when powering the sensor up to read the ID during initial probe. > > This is the same also when streaming is enabled and disabled multiple times > while the sensor is powered on. Although without autosuspend this may be > unlikely. > > > Doing so also means there needs to be a great big warning never to > > change the driver and hit the software reset via writing 0x01 to > > register 0x0103 as part of any register array (very common in many > > other sensor drivers). > > If there's a desire to reset the sensor after powering it up, that should > be done as the first thing after power-up. Setting non-continuous clock > isn't anything special here. I'm only looking at existing drivers in mainline as there is no clear documentation on do's and don't's within sensor drivers (I know writing good documentation is hard). ov7251 [1] reset in ov7251_global_init_setting ov8856 [2] reset in the lane config tables ov5695 [3] reset in ov5695_global_regs ov2740 [4] reset in mipi_data_rate_720mbps ov13858 [5] explicit reset in ov13858_start_streaming ov13b10 [6] explicit reset in ov13b10_start_streaming In my book that's a common enough pattern in mainline drivers for it to be worth warning against introducing it when it will cause quirky behaviour. [1] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov7251.c#L238 [2] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov8856.c#L167 [3] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov5695.c#L128 [4] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov2740.c#L127 [5] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov13858.c#L1421 [6] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov13b10.c#L1033 > But that's up to you. I guess lane configuration etc. is part of the big > register lists. Only 2 data lanes are currently supported by the driver. Bit 5 of 0x3039 in theory allows you to drop to 1 lane, but I've not got it to work. I suspect further clock tree changes are required. A 400MHz link freq (800Mbit/s/lane) is already required for the max 1280x800@120fps. Dropping to 1 lane therefore either requires reducing the max frame rate, or potentially running at 800MHz link freq, which is well in excess of the earlier versions of CSI-2 spec (500MHz or 1Gbit/s). IMHO It's not worth pursuing. Dave > > > > I'll move it and add a comment before the register tables. > > I think it's unnecessary. > > -- > Kind regards, > > Sakari Ailus
Hi Dave, On Fri, Oct 28, 2022 at 04:03:45PM +0100, Dave Stevenson wrote: > Hi Sakari > > On Fri, 28 Oct 2022 at 15:30, Sakari Ailus <sakari.ailus@iki.fi> wrote: > > > > Hi Dave, > > > > On Fri, Oct 28, 2022 at 01:57:48PM +0100, Dave Stevenson wrote: > > > Hi Sakari > > > > > > On Wed, 26 Oct 2022 at 08:21, Sakari Ailus <sakari.ailus@iki.fi> wrote: > > > > > > > > Hi Dave, > > > > > > > > On Wed, Oct 05, 2022 at 04:28:01PM +0100, Dave Stevenson wrote: > > > > > The sensor supports either having the CSI2 clock lane free > > > > > running, or gated when there is no packet to transmit. > > > > > The driver only selected gated (non-continuous) clock mode. > > > > > > > > > > Add code to allow fwnode to configure whether the clock is > > > > > gated or free running. > > > > > > > > > > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> > > > > > --- > > > > > drivers/media/i2c/ov9282.c | 16 +++++++++++++++- > > > > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c > > > > > index abb1223c0260..334b31af34a4 100644 > > > > > --- a/drivers/media/i2c/ov9282.c > > > > > +++ b/drivers/media/i2c/ov9282.c > > > > > @@ -46,6 +46,9 @@ > > > > > /* Group hold register */ > > > > > #define OV9282_REG_HOLD 0x3308 > > > > > > > > > > +#define OV9282_REG_MIPI_CTRL00 0x4800 > > > > > +#define OV9282_GATED_CLOCK BIT(5) > > > > > + > > > > > /* Input clock rate */ > > > > > #define OV9282_INCLK_RATE 24000000 > > > > > > > > > > @@ -138,6 +141,7 @@ struct ov9282 { > > > > > struct clk *inclk; > > > > > struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; > > > > > struct v4l2_ctrl_handler ctrl_handler; > > > > > + bool noncontinuous_clock; > > > > > struct v4l2_ctrl *link_freq_ctrl; > > > > > struct v4l2_ctrl *hblank_ctrl; > > > > > struct v4l2_ctrl *vblank_ctrl; > > > > > @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { > > > > > {0x4601, 0x04}, > > > > > {0x470f, 0x00}, > > > > > {0x4f07, 0x00}, > > > > > - {0x4800, 0x20}, > > > > > {0x5000, 0x9f}, > > > > > {0x5001, 0x00}, > > > > > {0x5e00, 0x00}, > > > > > @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) > > > > > return ret; > > > > > } > > > > > > > > > > + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, > > > > > + ov9282->noncontinuous_clock ? > > > > > + OV9282_GATED_CLOCK : 0); > > > > > > > > Wouldn't this better fit for power on? > > > > > > It can be done in ov9282_power_on, but is then totally redundantly set > > > when powering the sensor up to read the ID during initial probe. > > > > This is the same also when streaming is enabled and disabled multiple times > > while the sensor is powered on. Although without autosuspend this may be > > unlikely. > > > > > Doing so also means there needs to be a great big warning never to > > > change the driver and hit the software reset via writing 0x01 to > > > register 0x0103 as part of any register array (very common in many > > > other sensor drivers). > > > > If there's a desire to reset the sensor after powering it up, that should > > be done as the first thing after power-up. Setting non-continuous clock > > isn't anything special here. > > I'm only looking at existing drivers in mainline as there is no clear > documentation on do's and don't's within sensor drivers (I know > writing good documentation is hard). > ov7251 [1] reset in ov7251_global_init_setting > ov8856 [2] reset in the lane config tables > ov5695 [3] reset in ov5695_global_regs > ov2740 [4] reset in mipi_data_rate_720mbps > ov13858 [5] explicit reset in ov13858_start_streaming > ov13b10 [6] explicit reset in ov13b10_start_streaming > > In my book that's a common enough pattern in mainline drivers for it > to be worth warning against introducing it when it will cause quirky > behaviour. > > [1] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov7251.c#L238 > [2] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov8856.c#L167 > [3] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov5695.c#L128 > [4] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov2740.c#L127 > [5] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov13858.c#L1421 > [6] https://github.com/torvalds/linux/blob/master/drivers/media/i2c/ov13b10.c#L1033 Well, register list based sensor drivers are hardly exemplary in this respect. Some drivers reset the device after resuming it, some do not. As noted, it's up to you. > > > But that's up to you. I guess lane configuration etc. is part of the big > > register lists. > > Only 2 data lanes are currently supported by the driver. > Bit 5 of 0x3039 in theory allows you to drop to 1 lane, but I've not > got it to work. I suspect further clock tree changes are required. > > A 400MHz link freq (800Mbit/s/lane) is already required for the max > 1280x800@120fps. > Dropping to 1 lane therefore either requires reducing the max frame > rate, or potentially running at 800MHz link freq, which is well in > excess of the earlier versions of CSI-2 spec (500MHz or 1Gbit/s). IMHO > It's not worth pursuing. Works for me.
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index abb1223c0260..334b31af34a4 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -46,6 +46,9 @@ /* Group hold register */ #define OV9282_REG_HOLD 0x3308 +#define OV9282_REG_MIPI_CTRL00 0x4800 +#define OV9282_GATED_CLOCK BIT(5) + /* Input clock rate */ #define OV9282_INCLK_RATE 24000000 @@ -138,6 +141,7 @@ struct ov9282 { struct clk *inclk; struct regulator_bulk_data supplies[OV9282_NUM_SUPPLIES]; struct v4l2_ctrl_handler ctrl_handler; + bool noncontinuous_clock; struct v4l2_ctrl *link_freq_ctrl; struct v4l2_ctrl *hblank_ctrl; struct v4l2_ctrl *vblank_ctrl; @@ -211,7 +215,6 @@ static const struct ov9282_reg common_regs[] = { {0x4601, 0x04}, {0x470f, 0x00}, {0x4f07, 0x00}, - {0x4800, 0x20}, {0x5000, 0x9f}, {0x5001, 0x00}, {0x5e00, 0x00}, @@ -684,6 +687,14 @@ static int ov9282_start_streaming(struct ov9282 *ov9282) return ret; } + ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, + ov9282->noncontinuous_clock ? + OV9282_GATED_CLOCK : 0); + if (ret) { + dev_err(ov9282->dev, "fail to write MIPI_CTRL00"); + return ret; + } + /* Write sensor mode registers */ reg_list = &ov9282->cur_mode->reg_list; ret = ov9282_write_regs(ov9282, reg_list->regs, reg_list->num_of_regs); @@ -861,6 +872,9 @@ static int ov9282_parse_hw_config(struct ov9282 *ov9282) if (ret) return ret; + ov9282->noncontinuous_clock = + bus_cfg.bus.mipi_csi2.flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; + if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV9282_NUM_DATA_LANES) { dev_err(ov9282->dev, "number of CSI2 data lanes %d is not supported",