Skip to contentSkip to conversation

ov5647 driver improvement

PATCH In review Roman Kovalivskyi 3 participants 15 messages May 19, 2020 – Jun 22, 2020 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover ov5647 driver improvement

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.

Changes since v1 [2]:
* Added DT bindings documentation for PWDN GPIO and non-continuous clock mode
* Patch 2: "media: ov5647: Add support for PWDN GPIO."
* Replaced msleep with usleep_range
* Patch 3: "media: ov5647: Add support for non-continuous clock mode"
* Added check if bus type is correct one
* Replaced storing of all flags to storing whether clock is continuous
* Added of_node_put(np) in case if v4l2_fwnode_endpoint_parse fails

[1] - https://github.com/raspberrypi/linux
[2] - https://lore.kernel.org/patchwork/cover/1223179/

Dave Stevenson (5):
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
media: dt-bindings: ov5647: Add property for PWDN control

Roman Kovalivskyi (1):
media: dt-bindings: ov5647: Add property for non-continuous clock

 .../devicetree/bindings/media/i2c/ov5647.txt  |  7 ++
 drivers/media/i2c/ov5647.c                    | 77 ++++++++++++++++++-
 2 files changed, 80 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/6 media: ov5647: Add set_fmt and get_fmt calls.

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/media/i2c/ov5647.c +22 -0
index e7d2e5b4ad4b..3e587eb0a30e 100644
@@ -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 = {
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.

Hi Dave,

Thanks for the patchset.

Quoted 20 lines · Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/media/i2c/ov5647.c +0 -0
index e7d2e5b4ad4b..3e587eb0a30e 100644
@@ -463,8 +463,30 @@ static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,
 	return 0;

drivers/media/i2c/ov5647.c static int ov5647_enum_mbus_code(struct v4l2_subdev *sd, · line 473

Quoted 10 lines
drivers/media/i2c/ov5647.c +8 -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;

No need to check the pad, the caller already has checked for it.

Quoted 19 lines
drivers/media/i2c/ov5647.c +14 -0
+
+	/* 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 = {
Signature · 3 lines
Kind regards,

Sakari Ailus
maintainer
#3 lore raw

Re: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.

Quoted 1 line · Sakari Ailus

Hi Dave,

I meant to say "Hi Roman".

Signature · 1 line
Sakari Ailus
#4 lore raw

PATCH v2 2/6 media: ov5647: Add support for PWDN GPIO.

In reply to Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/i2c/ov5647.c +33 -0
index 3e587eb0a30e..796cc80f8ee1 100644
@@ -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)
@@ -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;
 
Signature · 1 line
2.17.1
maintainer
#5 lore raw

Re: [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO.

Hi Roman,

Quoted 49 lines · Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/i2c/ov5647.c +9 -0
index 3e587eb0a30e..796cc80f8ee1 100644
@@ -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)

drivers/media/i2c/ov5647.c static inline struct ov5647 *to_state(struct v4l2_subdev *sd) · line 109

Quoted 8 lines
drivers/media/i2c/ov5647.c +5 -0
@@ -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);
+}
+

I think I mis-lead you with the comment I gave on v1, as I just notice the designated timeout is 20 msec, so msleep() is fine. Sorry about this, I thought we were dealing with a shorter interval.

If that's ok with you I'll send a v3 of this series with Sakari's comments addressed, rebased on top of the yaml version of the sensor bindings I sent out a few hours ago.

Thanks
j

Quoted 54 lines
drivers/media/i2c/ov5647.c +19 -1
 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

#6 lore raw

PATCH v2 3/6 media: ov5647: Add support for non-continuous clock mode

In reply to Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/media/i2c/ov5647.c +22 -3
index 796cc80f8ee1..10f35c637f91 100644
@@ -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;
+	bool				is_clock_contiguous;
 };
 
 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -274,9 +276,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->is_clock_contiguous)
+		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;
 
@@ -573,7 +581,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 ov5647 *sensor, struct device_node *np)
 {
 	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;
@@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
 
+	if (!ret) {
+		of_node_put(ep);
+		of_node_put(np);
+		return ret;
+	}
+
+	if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
+		|| bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)
+		sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
+			& V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
+
 	of_node_put(ep);
 	return ret;
 }
@@ -604,7 +623,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(sensor, np);
 		if (ret) {
 			dev_err(dev, "DT parsing error: %d\n", ret);
 			return ret;
Signature · 1 line
2.17.1
maintainer
#7 lore raw

Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

Hi Roman,

Quoted 60 lines · Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/media/i2c/ov5647.c +10 -2
index 796cc80f8ee1..10f35c637f91 100644
@@ -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;
+	bool				is_clock_contiguous;
 };
 
 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -274,9 +276,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->is_clock_contiguous)
+		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;
 
@@ -573,7 +581,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 ov5647 *sensor, struct device_node *np)
 {
 	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 596

Quoted 3 lines
drivers/media/i2c/ov5647.c +0 -0
@@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
 

Extra newline.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 599

Quoted 3 lines
drivers/media/i2c/ov5647.c +3 -0
+	if (!ret) {
+		of_node_put(ep);
+		of_node_put(np);

Why to put np as well?

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 600

Quoted 1 line
drivers/media/i2c/ov5647.c +1 -0
+		return ret;

Please add a label at the end; it makes error handling easier.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 604

Quoted 4 lines
drivers/media/i2c/ov5647.c +4 -0
+	}
+
+	if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
+		|| bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)

I bet this device is D-PHY only.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 606

Quoted 2 lines
drivers/media/i2c/ov5647.c +2 -0
+		sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
+			& V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;

Now that you're making use of bus specific parameters, please set the bus type first before calling v4l2_fwnode_endpoint_parse().

Quoted 13 lines
drivers/media/i2c/ov5647.c +2 -1
+
 	of_node_put(ep);
 	return ret;
 }
@@ -604,7 +623,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(sensor, np);
 		if (ret) {
 			dev_err(dev, "DT parsing error: %d\n", ret);
 			return ret;
Signature · 3 lines
Kind regards,

Sakari Ailus
maintainer
#8 lore raw

Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

Hi Roman, Sakari

Quoted 10 lines · Sakari Ailus

Hi Roman,

Quoted 7 lines · Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

not much to add to what Sakari said, apart for

Quoted 18 lines
Quoted 18 lines
---
 drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/media/i2c/ov5647.c +1 -0
index 796cc80f8ee1..10f35c637f91 100644
@@ -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)
 
Quoted 5 lines

drivers/media/i2c/ov5647.c struct ov5647 { · line 99

Quoted 5 lines
drivers/media/i2c/ov5647.c +1 -0
@@ -95,6 +96,7 @@ struct ov5647 {
 	int				power_count;
 	struct clk			*xclk;
 	struct gpio_desc		*pwdn;
+	bool				is_clock_contiguous;

the clock is 'continuous' not contigous :)

I plan to upport more ov5647 patches soon, Roman are you planning a resend of this series or should I do so (keeping your signoffs of course)

Thanks
j

Quoted 77 lines
Quoted 30 lines
drivers/media/i2c/ov5647.c +8 -2
 };
 
 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -274,9 +276,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->is_clock_contiguous)
+		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;
 
@@ -573,7 +581,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 ov5647 *sensor, struct device_node *np)
 {
 	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 596

Quoted 3 lines
drivers/media/i2c/ov5647.c +0 -0
@@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
 

Extra newline.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 599

Quoted 3 lines
drivers/media/i2c/ov5647.c +3 -0
+	if (!ret) {
+		of_node_put(ep);
+		of_node_put(np);

Why to put np as well?

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 600

Quoted 1 line
drivers/media/i2c/ov5647.c +1 -0
+		return ret;

Please add a label at the end; it makes error handling easier.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 604

Quoted 4 lines
drivers/media/i2c/ov5647.c +4 -0
+	}
+
+	if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
+		|| bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)

I bet this device is D-PHY only.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 606

Quoted 2 lines
drivers/media/i2c/ov5647.c +2 -0
+		sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
+			& V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;

Now that you're making use of bus specific parameters, please set the bus type first before calling v4l2_fwnode_endpoint_parse().

drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 629

Quoted 13 lines
drivers/media/i2c/ov5647.c +2 -1
+
 	of_node_put(ep);
 	return ret;
 }
@@ -604,7 +623,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(sensor, np);
 		if (ret) {
 			dev_err(dev, "DT parsing error: %d\n", ret);
 			return ret;

--
Kind regards,

Sakari Ailus

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#10 lore raw

Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

Hi Roman,

Quoted 47 lines · Roman Kovalivskyi

Hi Jacopo,

Quoted 44 lines · Jacopo Mondi

Hi Roman, Sakari

Quoted 10 lines · Sakari Ailus

Hi Roman,

Quoted 7 lines · Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

not much to add to what Sakari said, apart for

Quoted 18 lines
Quoted 18 lines
---
 drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/media/i2c/ov5647.c +1 -0
index 796cc80f8ee1..10f35c637f91 100644
@@ -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)
 
Quoted 5 lines

drivers/media/i2c/ov5647.c struct ov5647 { · line 99

Quoted 5 lines
drivers/media/i2c/ov5647.c +1 -0
@@ -95,6 +96,7 @@ struct ov5647 {
 	int				power_count;
 	struct clk			*xclk;
 	struct gpio_desc		*pwdn;
+	bool				is_clock_contiguous;

the clock is 'continuous' not contigous :)

I plan to upport more ov5647 patches soon, Roman are you planning a resend of this series or should I do so (keeping your signoffs of course)

Quoted 5 lines
Quoted 2 lines

Thanks
j

I would be grateful if someone more competent would continue with this patch series, so feel free to update it with v3.

I think you did a very good job, I just happen to have a bit more time to dedicate to this.

I'll make sure I'll cc you and the cc list from your series.

Thanks
j

Quoted 79 lines
Quoted 71 lines
Quoted 71 lines
Quoted 31 lines
drivers/media/i2c/ov5647.c +8 -2
 };
 
 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -274,9 +276,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->is_clock_contiguous)
+		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;
 
@@ -573,7 +581,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 ov5647 *sensor, struct device_node *np)
 {
 	struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
 	struct device_node *ep;

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 596

Quoted 3 lines
drivers/media/i2c/ov5647.c +0 -0
@@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
 

Extra newline.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 599

Quoted 3 lines
drivers/media/i2c/ov5647.c +3 -0
+	if (!ret) {
+		of_node_put(ep);
+		of_node_put(np);

Why to put np as well?

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 600

Quoted 1 line
drivers/media/i2c/ov5647.c +1 -0
+		return ret;

Please add a label at the end; it makes error handling easier.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 604

Quoted 4 lines
drivers/media/i2c/ov5647.c +4 -0
+	}
+
+	if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
+		|| bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)

I bet this device is D-PHY only.

drivers/media/i2c/ov5647.c static int ov5647_parse_dt(struct device_node *np) · line 606

Quoted 2 lines
drivers/media/i2c/ov5647.c +2 -0
+		sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
+			& V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;

Now that you're making use of bus specific parameters, please set the bus type first before calling v4l2_fwnode_endpoint_parse().

drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 629

Quoted 13 lines
drivers/media/i2c/ov5647.c +2 -1
+
 	of_node_put(ep);
 	return ret;
 }
@@ -604,7 +623,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(sensor, np);
 		if (ret) {
 			dev_err(dev, "DT parsing error: %d\n", ret);
 			return ret;

--
Kind regards,

Quoted 1 line
Quoted 1 line

Sakari Ailus

--

Best regards,
Roman Kovalivskyi

#11 lore raw

PATCH v2 4/6 media: ov5647: Use gpiod_set_value_cansleep

In reply to Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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.

---
 drivers/media/i2c/ov5647.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5647.c +4 -4
index 10f35c637f91..7600b4844f16 100644
@@ -378,7 +378,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_range(PWDN_ACTIVE_DELAY_MS);
 		}
 
@@ -420,7 +420,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. */
@@ -661,13 +661,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_range(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;
Signature · 1 line
2.17.1
maintainer
#12 lore raw

Re: [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep

Quoted 6 lines · Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

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).

Quoted 6 lines

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.

This needs to be merged with the 2nd patch.

Signature · 1 line
Sakari Ailus
#13 lore raw

PATCH v2 5/6 media: dt-bindings: ov5647: Add property for PWDN control

In reply to Roman Kovalivskyi

From: Dave Stevenson <[email protected]>

Add optional GPIO pwdn to connect to the PWDN line on the sensor.

---
 Documentation/devicetree/bindings/media/i2c/ov5647.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/media/i2c/ov5647.txt +4 -0
index 22e44945b661..70f06c24f470 100644
@@ -10,6 +10,9 @@ Required properties:
 - reg			: I2C slave address of the sensor.
 - clocks		: Reference to the xclk clock.
 
+Optional Properties:
+- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
+
 The common video interfaces bindings (see video-interfaces.txt) should be
 used to specify link to the image data receiver. The OV5647 device
 node should contain one 'port' child node with an 'endpoint' subnode.
@@ -26,6 +29,7 @@ Example:
 			compatible = "ovti,ov5647";
 			reg = <0x36>;
 			clocks = <&camera_clk>;
+			pwdn-gpios = <&pioE 29 GPIO_ACTIVE_HIGH>;
 			port {
 				camera_1: endpoint {
 					remote-endpoint = <&csi1_ep1>;
Signature · 1 line
2.17.1
#15 lore raw

PATCH v2 6/6 media: dt-bindings: ov5647: Add property for non-continuous clock

In reply to Roman Kovalivskyi

Add optional clock-noncontinuous property to configure whether the clock is continuous or not.

---
 Documentation/devicetree/bindings/media/i2c/ov5647.txt | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/media/i2c/ov5647.txt +3 -0
index 70f06c24f470..fefba0a69b07 100644
@@ -12,6 +12,8 @@ Required properties:
 
 Optional Properties:
 - pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
+- clock-noncontinuous: presence of this boolean property decides whether the
+		       MIPI CSI-2 clock is continuous or non-continuous.
 
 The common video interfaces bindings (see video-interfaces.txt) should be
 used to specify link to the image data receiver. The OV5647 device
@@ -33,6 +35,7 @@ Example:
 			port {
 				camera_1: endpoint {
 					remote-endpoint = <&csi1_ep1>;
+					clock-noncontinuous;
 				};
 			};
 		};
Signature · 1 line
2.17.1