linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] ov5647 driver improvement
@ 2020-04-13  9:17 Roman Kovalivskyi
       [not found] ` <cover.1586759968.git.roman.kovalivskyi@globallogic.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Roman Kovalivskyi @ 2020-04-13  9:17 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, 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

Driver for ov5647 camera sensor lacks some important functionality, such
as ability to query device format and resolution or operations with
power down mode. Patches from Raspberry kernel source tree[1] fixes
those issues and improves quality of mentioned driver.

[1] - https://github.com/raspberrypi/linux

Dave Stevenson (4):
  media: ov5647: Add set_fmt and get_fmt calls.
  media: ov5647: Add support for PWDN GPIO.
  media: ov5647: Add support for non-continuous clock mode
  media: ov5647: Use gpiod_set_value_cansleep

 drivers/media/i2c/ov5647.c | 67 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 3 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] media: ov5647: Add set_fmt and get_fmt calls.
       [not found] ` <cover.1586759968.git.roman.kovalivskyi@globallogic.com>
@ 2020-04-13  9:17   ` Roman Kovalivskyi
  2020-04-15 12:11     ` Jacopo Mondi
  2020-04-13  9:17   ` [PATCH 2/4] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Roman Kovalivskyi @ 2020-04-13  9:17 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, 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

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

There's no way to query the subdevice for the supported
resolutions. Add set_fmt and get_fmt implementations. Since there's
only one format supported set_fmt does nothing and get returns single
format.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 drivers/media/i2c/ov5647.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index e7d2e5b4ad4b..3e587eb0a30e 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -463,8 +463,30 @@ static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int ov5647_set_get_fmt(struct v4l2_subdev *sd,
+			      struct v4l2_subdev_pad_config *cfg,
+			      struct v4l2_subdev_format *format)
+{
+	struct v4l2_mbus_framefmt *fmt = &format->format;
+
+	if (format->pad != 0)
+		return -EINVAL;
+
+	/* Only one format is supported, so return that */
+	memset(fmt, 0, sizeof(*fmt));
+	fmt->code = MEDIA_BUS_FMT_SBGGR8_1X8;
+	fmt->colorspace = V4L2_COLORSPACE_SRGB;
+	fmt->field = V4L2_FIELD_NONE;
+	fmt->width = 640;
+	fmt->height = 480;
+
+	return 0;
+}
+
 static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = {
 	.enum_mbus_code = ov5647_enum_mbus_code,
+	.set_fmt =	  ov5647_set_get_fmt,
+	.get_fmt =	  ov5647_set_get_fmt,
 };
 
 static const struct v4l2_subdev_ops ov5647_subdev_ops = {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] media: ov5647: Add support for PWDN GPIO.
       [not found] ` <cover.1586759968.git.roman.kovalivskyi@globallogic.com>
  2020-04-13  9:17   ` [PATCH 1/4] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
@ 2020-04-13  9:17   ` Roman Kovalivskyi
  2020-04-15 12:38     ` Jacopo Mondi
  2020-04-13  9:17   ` [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
  2020-04-13  9:17   ` [PATCH 4/4] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
  3 siblings, 1 reply; 10+ messages in thread
From: Roman Kovalivskyi @ 2020-04-13  9:17 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, 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

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

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 <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 drivers/media/i2c/ov5647.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 3e587eb0a30e..c39e3d20e3ef 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -21,6 +21,7 @@
 
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/io.h>
@@ -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)
@@ -355,6 +364,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(PWDN_ACTIVE_DELAY_MS);
+		}
+
 		ret = clk_prepare_enable(ov5647->xclk);
 		if (ret < 0) {
 			dev_err(&client->dev, "clk prepare enable failed\n");
@@ -392,6 +406,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 +619,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 +636,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(PWDN_ACTIVE_DELAY_MS);
+	}
+
 	ret = ov5647_detect(sd);
+
+	gpiod_set_value(sensor->pwdn, 1);
+
 	if (ret < 0)
 		goto error;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode
       [not found] ` <cover.1586759968.git.roman.kovalivskyi@globallogic.com>
  2020-04-13  9:17   ` [PATCH 1/4] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
  2020-04-13  9:17   ` [PATCH 2/4] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
@ 2020-04-13  9:17   ` Roman Kovalivskyi
  2020-04-15 13:17     ` Jacopo Mondi
  2020-04-23  7:47     ` Sakari Ailus
  2020-04-13  9:17   ` [PATCH 4/4] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
  3 siblings, 2 replies; 10+ messages in thread
From: Roman Kovalivskyi @ 2020-04-13  9:17 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, 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

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

The driver was only supporting continuous clock mode
although this was not stated anywhere.
Non-continuous clock saves a small amount of power and
on some SoCs is easier to interface with.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 drivers/media/i2c/ov5647.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index c39e3d20e3ef..8a1a515388e0 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -44,6 +44,7 @@
 #define PWDN_ACTIVE_DELAY_MS	20
 
 #define MIPI_CTRL00_CLOCK_LANE_GATE		BIT(5)
+#define MIPI_CTRL00_LINE_SYNC_ENABLE		BIT(4)
 #define MIPI_CTRL00_BUS_IDLE			BIT(2)
 #define MIPI_CTRL00_CLOCK_LANE_DISABLE		BIT(0)
 
@@ -95,6 +96,7 @@ struct ov5647 {
 	int				power_count;
 	struct clk			*xclk;
 	struct gpio_desc		*pwdn;
+	unsigned int			flags;
 };
 
 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -269,9 +271,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
 
 static int ov5647_stream_on(struct v4l2_subdev *sd)
 {
+	struct ov5647 *ov5647 = to_state(sd);
+	u8 val = MIPI_CTRL00_BUS_IDLE;
 	int ret;
 
-	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
+	if (ov5647->flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK)
+		val |= MIPI_CTRL00_CLOCK_LANE_GATE |
+		       MIPI_CTRL00_LINE_SYNC_ENABLE;
+
+	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
 	if (ret < 0)
 		return ret;
 
@@ -568,7 +576,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
 	.open = ov5647_open,
 };
 
-static int ov5647_parse_dt(struct device_node *np)
+static int ov5647_parse_dt(struct device_node *np, struct ov5647 *sensor)
 {
 	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;
@@ -581,6 +589,9 @@ static int ov5647_parse_dt(struct device_node *np)
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
 
+	if (!ret)
+		sensor->flags = bus_cfg.bus.mipi_csi2.flags;
+
 	of_node_put(ep);
 	return ret;
 }
@@ -599,7 +610,7 @@ static int ov5647_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	if (IS_ENABLED(CONFIG_OF) && np) {
-		ret = ov5647_parse_dt(np);
+		ret = ov5647_parse_dt(np, sensor);
 		if (ret) {
 			dev_err(dev, "DT parsing error: %d\n", ret);
 			return ret;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] media: ov5647: Use gpiod_set_value_cansleep
       [not found] ` <cover.1586759968.git.roman.kovalivskyi@globallogic.com>
                     ` (2 preceding siblings ...)
  2020-04-13  9:17   ` [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
@ 2020-04-13  9:17   ` Roman Kovalivskyi
  2020-04-23  7:55     ` Sakari Ailus
  3 siblings, 1 reply; 10+ messages in thread
From: Roman Kovalivskyi @ 2020-04-13  9:17 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, 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

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

All calls to the gpio library are in contexts that can sleep,
therefore there is no issue with having those GPIOs controlled
by controllers which require sleeping (eg I2C GPIO expanders).

Switch to using gpiod_set_value_cansleep instead of gpiod_set_value
to avoid triggering the warning in gpiolib should the GPIO
controller need to sleep.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 drivers/media/i2c/ov5647.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 8a1a515388e0..07550377be2e 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -373,7 +373,7 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
 		dev_dbg(&client->dev, "OV5647 power on\n");
 
 		if (ov5647->pwdn) {
-			gpiod_set_value(ov5647->pwdn, 0);
+			gpiod_set_value_cansleep(ov5647->pwdn, 0);
 			msleep(PWDN_ACTIVE_DELAY_MS);
 		}
 
@@ -415,7 +415,7 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
 
 		clk_disable_unprepare(ov5647->xclk);
 
-		gpiod_set_value(ov5647->pwdn, 1);
+		gpiod_set_value_cansleep(ov5647->pwdn, 1);
 	}
 
 	/* Update the power count. */
@@ -648,13 +648,13 @@ static int ov5647_probe(struct i2c_client *client)
 		goto mutex_remove;
 
 	if (sensor->pwdn) {
-		gpiod_set_value(sensor->pwdn, 0);
+		gpiod_set_value_cansleep(sensor->pwdn, 0);
 		msleep(PWDN_ACTIVE_DELAY_MS);
 	}
 
 	ret = ov5647_detect(sd);
 
-	gpiod_set_value(sensor->pwdn, 1);
+	gpiod_set_value_cansleep(sensor->pwdn, 1);
 
 	if (ret < 0)
 		goto error;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] media: ov5647: Add set_fmt and get_fmt calls.
  2020-04-13  9:17   ` [PATCH 1/4] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
@ 2020-04-15 12:11     ` Jacopo Mondi
  0 siblings, 0 replies; 10+ messages in thread
From: Jacopo Mondi @ 2020-04-15 12:11 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Michael Rodin, Mauro Carvalho Chehab,
	Sakari Ailus, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hello Roman,

On Mon, Apr 13, 2020 at 12:17:44PM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
>
> There's no way to query the subdevice for the supported
> resolutions. Add set_fmt and get_fmt implementations. Since there's
> only one format supported set_fmt does nothing and get returns single
> format.
>
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>

Looks good to me
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> ---
>  drivers/media/i2c/ov5647.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index e7d2e5b4ad4b..3e587eb0a30e 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -463,8 +463,30 @@ static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,
>  	return 0;
>  }
>
> +static int ov5647_set_get_fmt(struct v4l2_subdev *sd,
> +			      struct v4l2_subdev_pad_config *cfg,
> +			      struct v4l2_subdev_format *format)
> +{
> +	struct v4l2_mbus_framefmt *fmt = &format->format;
> +
> +	if (format->pad != 0)
> +		return -EINVAL;
> +
> +	/* Only one format is supported, so return that */
> +	memset(fmt, 0, sizeof(*fmt));
> +	fmt->code = MEDIA_BUS_FMT_SBGGR8_1X8;
> +	fmt->colorspace = V4L2_COLORSPACE_SRGB;
> +	fmt->field = V4L2_FIELD_NONE;
> +	fmt->width = 640;
> +	fmt->height = 480;
> +
> +	return 0;
> +}
> +
>  static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = {
>  	.enum_mbus_code = ov5647_enum_mbus_code,
> +	.set_fmt =	  ov5647_set_get_fmt,
> +	.get_fmt =	  ov5647_set_get_fmt,
>  };
>
>  static const struct v4l2_subdev_ops ov5647_subdev_ops = {
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] media: ov5647: Add support for PWDN GPIO.
  2020-04-13  9:17   ` [PATCH 2/4] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
@ 2020-04-15 12:38     ` Jacopo Mondi
  0 siblings, 0 replies; 10+ messages in thread
From: Jacopo Mondi @ 2020-04-15 12:38 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Michael Rodin, Mauro Carvalho Chehab,
	Sakari Ailus, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Roman,
   this patch requires the device bindings document to be updated
to report an optional 'powerdown-gpios' property is available and that
it's active HIGH.

On Mon, Apr 13, 2020 at 12:17:45PM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
>
> 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 <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
> ---
>  drivers/media/i2c/ov5647.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index 3e587eb0a30e..c39e3d20e3ef 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -21,6 +21,7 @@
>
>  #include <linux/clk.h>
>  #include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/i2c.h>
>  #include <linux/init.h>
>  #include <linux/io.h>
> @@ -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)
> @@ -355,6 +364,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(PWDN_ACTIVE_DELAY_MS);

please use usleep_range() according to Documentation/timers/timers-howto.rst

Thanks
   j
> +		}
> +
>  		ret = clk_prepare_enable(ov5647->xclk);
>  		if (ret < 0) {
>  			dev_err(&client->dev, "clk prepare enable failed\n");
> @@ -392,6 +406,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 +619,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 +636,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(PWDN_ACTIVE_DELAY_MS);
> +	}
> +
>  	ret = ov5647_detect(sd);
> +
> +	gpiod_set_value(sensor->pwdn, 1);
> +
>  	if (ret < 0)
>  		goto error;
>
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode
  2020-04-13  9:17   ` [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
@ 2020-04-15 13:17     ` Jacopo Mondi
  2020-04-23  7:47     ` Sakari Ailus
  1 sibling, 0 replies; 10+ messages in thread
From: Jacopo Mondi @ 2020-04-15 13:17 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Michael Rodin, Mauro Carvalho Chehab,
	Sakari Ailus, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Roman,

On Mon, Apr 13, 2020 at 12:17:46PM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
>
> The driver was only supporting continuous clock mode
> although this was not stated anywhere.
> Non-continuous clock saves a small amount of power and
> on some SoCs is easier to interface with.

As per the previous patch, you should update bindings reporting this
property is now optionally supported

>
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
> ---
>  drivers/media/i2c/ov5647.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index c39e3d20e3ef..8a1a515388e0 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -44,6 +44,7 @@
>  #define PWDN_ACTIVE_DELAY_MS	20
>
>  #define MIPI_CTRL00_CLOCK_LANE_GATE		BIT(5)
> +#define MIPI_CTRL00_LINE_SYNC_ENABLE		BIT(4)
>  #define MIPI_CTRL00_BUS_IDLE			BIT(2)
>  #define MIPI_CTRL00_CLOCK_LANE_DISABLE		BIT(0)
>
> @@ -95,6 +96,7 @@ struct ov5647 {
>  	int				power_count;
>  	struct clk			*xclk;
>  	struct gpio_desc		*pwdn;
> +	unsigned int			flags;
>  };
>
>  static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> @@ -269,9 +271,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
>
>  static int ov5647_stream_on(struct v4l2_subdev *sd)
>  {
> +	struct ov5647 *ov5647 = to_state(sd);
> +	u8 val = MIPI_CTRL00_BUS_IDLE;
>  	int ret;
>
> -	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
> +	if (ov5647->flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK)
> +		val |= MIPI_CTRL00_CLOCK_LANE_GATE |
> +		       MIPI_CTRL00_LINE_SYNC_ENABLE;
> +
> +	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
>  	if (ret < 0)
>  		return ret;
>
> @@ -568,7 +576,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
>  	.open = ov5647_open,
>  };
>
> -static int ov5647_parse_dt(struct device_node *np)
> +static int ov5647_parse_dt(struct device_node *np, struct ov5647 *sensor)

nit: I would provide the driver structure first

>  {
>  	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
>  	struct device_node *ep;
> @@ -581,6 +589,9 @@ static int ov5647_parse_dt(struct device_node *np)
>
>  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
>
> +	if (!ret)
> +		sensor->flags = bus_cfg.bus.mipi_csi2.flags;
> +

There is a huge space for improvements here, this function didn't do
anything before this.

I would:
        check the v4l2_fwnode_endpoint_parse() return value, and
        put(np) and fail loudly

        make sure the detected bus type is CSI-2

        cache the flags as you're doing here. As you're only
        interested in clock continuous you could store only that
        information in your driver structure.

>  	of_node_put(ep);
>  	return ret;
>  }
> @@ -599,7 +610,7 @@ static int ov5647_probe(struct i2c_client *client)
>  		return -ENOMEM;
>
>  	if (IS_ENABLED(CONFIG_OF) && np) {
> -		ret = ov5647_parse_dt(np);
> +		ret = ov5647_parse_dt(np, sensor);
>  		if (ret) {
>  			dev_err(dev, "DT parsing error: %d\n", ret);
>  			return ret;
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode
  2020-04-13  9:17   ` [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
  2020-04-15 13:17     ` Jacopo Mondi
@ 2020-04-23  7:47     ` Sakari Ailus
  1 sibling, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2020-04-23  7:47 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Roman,

On Mon, Apr 13, 2020 at 12:17:46PM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> The driver was only supporting continuous clock mode
> although this was not stated anywhere.
> Non-continuous clock saves a small amount of power and
> on some SoCs is easier to interface with.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
> ---
>  drivers/media/i2c/ov5647.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index c39e3d20e3ef..8a1a515388e0 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -44,6 +44,7 @@
>  #define PWDN_ACTIVE_DELAY_MS	20
>  
>  #define MIPI_CTRL00_CLOCK_LANE_GATE		BIT(5)
> +#define MIPI_CTRL00_LINE_SYNC_ENABLE		BIT(4)
>  #define MIPI_CTRL00_BUS_IDLE			BIT(2)
>  #define MIPI_CTRL00_CLOCK_LANE_DISABLE		BIT(0)
>  
> @@ -95,6 +96,7 @@ struct ov5647 {
>  	int				power_count;
>  	struct clk			*xclk;
>  	struct gpio_desc		*pwdn;
> +	unsigned int			flags;
>  };
>  
>  static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> @@ -269,9 +271,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
>  
>  static int ov5647_stream_on(struct v4l2_subdev *sd)
>  {
> +	struct ov5647 *ov5647 = to_state(sd);
> +	u8 val = MIPI_CTRL00_BUS_IDLE;
>  	int ret;
>  
> -	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
> +	if (ov5647->flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK)
> +		val |= MIPI_CTRL00_CLOCK_LANE_GATE |
> +		       MIPI_CTRL00_LINE_SYNC_ENABLE;
> +
> +	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -568,7 +576,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
>  	.open = ov5647_open,
>  };
>  
> -static int ov5647_parse_dt(struct device_node *np)
> +static int ov5647_parse_dt(struct device_node *np, struct ov5647 *sensor)
>  {
>  	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };

The bus type should be set to V4L2_MBUS_CSI2_DPHY here; 0 is just for
compatibility with the old heuristics.

>  	struct device_node *ep;
> @@ -581,6 +589,9 @@ static int ov5647_parse_dt(struct device_node *np)
>  
>  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
>  
> +	if (!ret)
> +		sensor->flags = bus_cfg.bus.mipi_csi2.flags;
> +
>  	of_node_put(ep);
>  	return ret;
>  }
> @@ -599,7 +610,7 @@ static int ov5647_probe(struct i2c_client *client)
>  		return -ENOMEM;
>  
>  	if (IS_ENABLED(CONFIG_OF) && np) {
> -		ret = ov5647_parse_dt(np);
> +		ret = ov5647_parse_dt(np, sensor);
>  		if (ret) {
>  			dev_err(dev, "DT parsing error: %d\n", ret);
>  			return ret;

-- 
Kind regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] media: ov5647: Use gpiod_set_value_cansleep
  2020-04-13  9:17   ` [PATCH 4/4] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
@ 2020-04-23  7:55     ` Sakari Ailus
  0 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2020-04-23  7:55 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Roman,

On Mon, Apr 13, 2020 at 12:17:47PM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> All calls to the gpio library are in contexts that can sleep,
> therefore there is no issue with having those GPIOs controlled
> by controllers which require sleeping (eg I2C GPIO expanders).
> 
> Switch to using gpiod_set_value_cansleep instead of gpiod_set_value
> to avoid triggering the warning in gpiolib should the GPIO
> controller need to sleep.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>

This should be merged with the second patch.

> ---
>  drivers/media/i2c/ov5647.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index 8a1a515388e0..07550377be2e 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -373,7 +373,7 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
>  		dev_dbg(&client->dev, "OV5647 power on\n");
>  
>  		if (ov5647->pwdn) {
> -			gpiod_set_value(ov5647->pwdn, 0);
> +			gpiod_set_value_cansleep(ov5647->pwdn, 0);
>  			msleep(PWDN_ACTIVE_DELAY_MS);
>  		}
>  
> @@ -415,7 +415,7 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
>  
>  		clk_disable_unprepare(ov5647->xclk);
>  
> -		gpiod_set_value(ov5647->pwdn, 1);
> +		gpiod_set_value_cansleep(ov5647->pwdn, 1);
>  	}
>  
>  	/* Update the power count. */
> @@ -648,13 +648,13 @@ static int ov5647_probe(struct i2c_client *client)
>  		goto mutex_remove;
>  
>  	if (sensor->pwdn) {
> -		gpiod_set_value(sensor->pwdn, 0);
> +		gpiod_set_value_cansleep(sensor->pwdn, 0);
>  		msleep(PWDN_ACTIVE_DELAY_MS);
>  	}
>  
>  	ret = ov5647_detect(sd);
>  
> -	gpiod_set_value(sensor->pwdn, 1);
> +	gpiod_set_value_cansleep(sensor->pwdn, 1);
>  
>  	if (ret < 0)
>  		goto error;
> -- 
> 2.17.1
> 

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-04-23  7:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13  9:17 [PATCH 0/4] ov5647 driver improvement Roman Kovalivskyi
     [not found] ` <cover.1586759968.git.roman.kovalivskyi@globallogic.com>
2020-04-13  9:17   ` [PATCH 1/4] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
2020-04-15 12:11     ` Jacopo Mondi
2020-04-13  9:17   ` [PATCH 2/4] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
2020-04-15 12:38     ` Jacopo Mondi
2020-04-13  9:17   ` [PATCH 3/4] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
2020-04-15 13:17     ` Jacopo Mondi
2020-04-23  7:47     ` Sakari Ailus
2020-04-13  9:17   ` [PATCH 4/4] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
2020-04-23  7:55     ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).