Skip to contentSkip to conversation

media: ov5640: updates

PATCH Superseded Benoit Parrot 3 participants 12 messages Oct 2, 2019 – Oct 3, 2019

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover media: ov5640: updates

This patch series is a collection of patches we have been carrying for a while.

First, it adds support for PIXEL_RATE control which is used by some CSI2 receiver driver to properly set-up their DPHY.

Then we fix an issue related to having extra sensor enable/disable in the register array for the 1920x1080 mode.

Finally we restrict the largest resolution which should only be available at the lowest FPS.

Changes since v1:
- Addressed comment from Sakari.
added a function to calculate the pixel rate and remove the need to cache its value

Benoit Parrot (3):
media: ov5640: add PIXEL_RATE control
media: ov5640: Fix 1920x1080 mode to remove extra enable/disable
media: ov5640: Make 2592x1944 mode only available at 15 fps

 drivers/media/i2c/ov5640.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 media: ov5640: add PIXEL_RATE control

Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration.

---
 drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/media/i2c/ov5640.c +25 -0
index 500d9bbff10b..5198dc887400 100644
@@ -193,6 +193,9 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
 	struct v4l2_ctrl_handler handler;
+	struct {
+		struct v4l2_ctrl *pixel_rate;
+	};
 	struct {
 		struct v4l2_ctrl *auto_exp;
 		struct v4l2_ctrl *exposure;
@@ -2194,6 +2197,16 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+	u64 rate;
+
+	rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+	rate *= ov5640_framerates[sensor->current_fr];
+
+	return rate;
+}
+
 static int ov5640_set_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -2233,6 +2246,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+				 ov5640_calc_pixel_rate(sensor));
 out:
 	mutex_unlock(&sensor->lock);
 	return ret;
@@ -2657,6 +2672,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
 	/* we can use our own mutex for the ctrl lock */
 	hdl->lock = &sensor->lock;
 
+	/* Clock related controls */
+	ctrls->pixel_rate =
+		v4l2_ctrl_new_std(hdl, ops,
+				  V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1,
+				  ov5640_calc_pixel_rate(sensor));
+	ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
 	/* Auto/manual white balance */
 	ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
 					   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2838,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 		sensor->frame_interval = fi->interval;
 		sensor->current_mode = mode;
 		sensor->pending_mode_change = true;
+
+		__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+					 ov5640_calc_pixel_rate(sensor));
 	}
 out:
 	mutex_unlock(&sensor->lock);
Signature · 1 line
2.17.1
#2 lore raw

Re: [Patch v2 1/3] media: ov5640: add PIXEL_RATE control

Hi Benoit,

Quoted 14 lines · Benoit Parrot

Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration.

---
 drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 500d9bbff10b..5198dc887400 100644

drivers/media/i2c/ov5640.c struct ov5640_mode_info { · line 198

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -193,6 +193,9 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
 	struct v4l2_ctrl_handler handler;
+	struct {
+		struct v4l2_ctrl *pixel_rate;
+	};

Do you need to wrap this v4l2_ctrl in it's own unnamed struct? Other controls here declared in this way are clustered and, if I'm not mistaken, using unnamed struct to wrap them is just a typographically nice way to convey that. I think your new control could be declared without a wrapping struct { }.

Quoted 7 lines
drivers/media/i2c/ov5640.c +0 -0
 	struct {
 		struct v4l2_ctrl *auto_exp;
 		struct v4l2_ctrl *exposure;
@@ -2194,6 +2197,16 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 

drivers/media/i2c/ov5640.c static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, · line 2209

Quoted 10 lines
drivers/media/i2c/ov5640.c +10 -0
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+	u64 rate;
+
+	rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+	rate *= ov5640_framerates[sensor->current_fr];
+
+	return rate;
+}
+

Just to point out this is the -theoretical- pixel rate, and might be quite different from the one calculated by the clock tree tuning procedure (which should be updated to match Hugues' latest findings).

Quoted 13 lines
drivers/media/i2c/ov5640.c +2 -0
 static int ov5640_set_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -2233,6 +2246,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+				 ov5640_calc_pixel_rate(sensor));
 out:
 	mutex_unlock(&sensor->lock);
 	return ret;

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2677

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -2657,6 +2672,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
 	/* we can use our own mutex for the ctrl lock */
 	hdl->lock = &sensor->lock;
 
+	/* Clock related controls */
+	ctrls->pixel_rate =
+		v4l2_ctrl_new_std(hdl, ops,

If you like it better, this could fit in 1 line

	ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
					      0, INT_MAX, 1,
					      ov5640_calc_pixel_rate(sensor)

Thanks
j

Quoted 22 lines
drivers/media/i2c/ov5640.c +4 -0
+				  V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1,
+				  ov5640_calc_pixel_rate(sensor));
 
 
+	ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
 	/* Auto/manual white balance */
drivers/media/i2c/ov5640.c +3 -1
 	ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
 					   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2838,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 		sensor->frame_interval = fi->interval;
 		sensor->current_mode = mode;
 		sensor->pending_mode_change = true;
+
+		__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+					 ov5640_calc_pixel_rate(sensor));
 	}
 out:
 	mutex_unlock(&sensor->lock);
--

2.17.1

maintainer
#3 lore raw

Re: [Patch v2 1/3] media: ov5640: add PIXEL_RATE control

Hi Jacopo, Benoit,

Quoted 37 lines · Jacopo Mondi

Hi Benoit,

Quoted 14 lines · Benoit Parrot

Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration.

---
 drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 500d9bbff10b..5198dc887400 100644

drivers/media/i2c/ov5640.c struct ov5640_mode_info { · line 198

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -193,6 +193,9 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
 	struct v4l2_ctrl_handler handler;
+	struct {
+		struct v4l2_ctrl *pixel_rate;
+	};

Do you need to wrap this v4l2_ctrl in it's own unnamed struct? Other controls here declared in this way are clustered and, if I'm not mistaken, using unnamed struct to wrap them is just a typographically nice way to convey that. I think your new control could be declared without a wrapping struct { }.

Quoted 7 lines
drivers/media/i2c/ov5640.c +0 -0
 	struct {
 		struct v4l2_ctrl *auto_exp;
 		struct v4l2_ctrl *exposure;
@@ -2194,6 +2197,16 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 
Quoted 14 lines

drivers/media/i2c/ov5640.c static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, · line 2209

Quoted 10 lines
drivers/media/i2c/ov5640.c +10 -0
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+	u64 rate;
+
+	rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+	rate *= ov5640_framerates[sensor->current_fr];
+
+	return rate;
+}
+

Just to point out this is the -theoretical- pixel rate, and might be quite different from the one calculated by the clock tree tuning procedure (which should be updated to match Hugues' latest findings).

Hmm. Considering the xclk rate may be pretty much anything, I'd suppose the value above would only be correct for a given xclk rate.

Could this be simply calculated from the clock tree configuration, to get the right value in all cases?

Quoted 27 lines
Quoted 14 lines
drivers/media/i2c/ov5640.c +2 -0
 static int ov5640_set_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -2233,6 +2246,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+				 ov5640_calc_pixel_rate(sensor));
 out:
 	mutex_unlock(&sensor->lock);
 	return ret;

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2677

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -2657,6 +2672,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
 	/* we can use our own mutex for the ctrl lock */
 	hdl->lock = &sensor->lock;
 
+	/* Clock related controls */
+	ctrls->pixel_rate =
+		v4l2_ctrl_new_std(hdl, ops,

If you like it better, this could fit in 1 line

	ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
					      0, INT_MAX, 1,
					      ov5640_calc_pixel_rate(sensor)
Quoted 8 lines

Thanks
j

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2680

Quoted 5 lines
drivers/media/i2c/ov5640.c +3 -0
+				  V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1,
+				  ov5640_calc_pixel_rate(sensor));
 
 
+	ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;

Note that ctrls->pixel_rate is NULL if e.g. memory allocation fails when creating the control.

Quoted 14 lines
Quoted 14 lines
drivers/media/i2c/ov5640.c +1 -0
+
 	/* Auto/manual white balance */
drivers/media/i2c/ov5640.c +3 -0
 	ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
 					   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2838,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 		sensor->frame_interval = fi->interval;
 		sensor->current_mode = mode;
 		sensor->pending_mode_change = true;
+
+		__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+					 ov5640_calc_pixel_rate(sensor));
 	}
 out:
 	mutex_unlock(&sensor->lock);
Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
#4 lore raw

Re: [Patch v2 1/3] media: ov5640: add PIXEL_RATE control

Sakari Ailus <[email protected]> wrote on Thu [2019-Oct-03 10:22:51 +0300]:

Quoted 55 lines

Hi Jacopo, Benoit,

Quoted 37 lines · Jacopo Mondi

Hi Benoit,

Quoted 14 lines · Benoit Parrot

Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration.

---
 drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 500d9bbff10b..5198dc887400 100644

drivers/media/i2c/ov5640.c struct ov5640_mode_info { · line 198

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -193,6 +193,9 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
 	struct v4l2_ctrl_handler handler;
+	struct {
+		struct v4l2_ctrl *pixel_rate;
+	};

Do you need to wrap this v4l2_ctrl in it's own unnamed struct? Other controls here declared in this way are clustered and, if I'm not mistaken, using unnamed struct to wrap them is just a typographically nice way to convey that. I think your new control could be declared without a wrapping struct { }.

Quoted 7 lines
drivers/media/i2c/ov5640.c +0 -0
 	struct {
 		struct v4l2_ctrl *auto_exp;
 		struct v4l2_ctrl *exposure;
@@ -2194,6 +2197,16 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 
Quoted 14 lines

drivers/media/i2c/ov5640.c static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, · line 2209

Quoted 10 lines
drivers/media/i2c/ov5640.c +10 -0
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+	u64 rate;
+
+	rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+	rate *= ov5640_framerates[sensor->current_fr];
+
+	return rate;
+}
+

Just to point out this is the -theoretical- pixel rate, and might be quite different from the one calculated by the clock tree tuning procedure (which should be updated to match Hugues' latest findings).

Quoted 2 lines

Hmm. Considering the xclk rate may be pretty much anything, I'd suppose the value above would only be correct for a given xclk rate.

I am not sure about that, different xclk rate might yield slightly different byte clock, but all in all the resolution and framerate pretty much dictate the end result, no?

Quoted 3 lines

Could this be simply calculated from the clock tree configuration, to get the right value in all cases?

It probably could, and as I said earlier I gave it a try and failed, since the theoretical value worked for me that's what I went with. Those are the same values that Maxime's patch referred to. (dfbfb7aa832cdb media: ov5640:
Compute the clock rate at runtime).

Here I am just "publishing it".

Benoit

Quoted 60 lines
Quoted 28 lines
Quoted 15 lines
drivers/media/i2c/ov5640.c +2 -0
 static int ov5640_set_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -2233,6 +2246,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+				 ov5640_calc_pixel_rate(sensor));
 out:
 	mutex_unlock(&sensor->lock);
 	return ret;

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2677

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -2657,6 +2672,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
 	/* we can use our own mutex for the ctrl lock */
 	hdl->lock = &sensor->lock;
 
+	/* Clock related controls */
+	ctrls->pixel_rate =
+		v4l2_ctrl_new_std(hdl, ops,

If you like it better, this could fit in 1 line

	ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
					      0, INT_MAX, 1,
					      ov5640_calc_pixel_rate(sensor)
Quoted 8 lines

Thanks
j

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2680

Quoted 5 lines
drivers/media/i2c/ov5640.c +3 -0
+				  V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1,
+				  ov5640_calc_pixel_rate(sensor));
 
 
+	ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;

Note that ctrls->pixel_rate is NULL if e.g. memory allocation fails when creating the control.

Quoted 14 lines
Quoted 14 lines
drivers/media/i2c/ov5640.c +1 -0
+
 	/* Auto/manual white balance */
drivers/media/i2c/ov5640.c +3 -0
 	ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
 					   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2838,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 		sensor->frame_interval = fi->interval;
 		sensor->current_mode = mode;
 		sensor->pending_mode_change = true;
+
+		__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+					 ov5640_calc_pixel_rate(sensor));
 	}
 out:
 	mutex_unlock(&sensor->lock);
Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
maintainer
#5 lore raw

Re: [Patch v2 1/3] media: ov5640: add PIXEL_RATE control

Hi Benoit,

Quoted 56 lines · Benoit Parrot

Sakari Ailus <[email protected]> wrote on Thu [2019-Oct-03 10:22:51 +0300]:

Quoted 55 lines

Hi Jacopo, Benoit,

Quoted 51 lines · Jacopo Mondi

Hi Benoit,

Quoted 14 lines · Benoit Parrot

Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration.

---
 drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 500d9bbff10b..5198dc887400 100644

drivers/media/i2c/ov5640.c struct ov5640_mode_info { · line 198

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -193,6 +193,9 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
 	struct v4l2_ctrl_handler handler;
+	struct {
+		struct v4l2_ctrl *pixel_rate;
+	};

Do you need to wrap this v4l2_ctrl in it's own unnamed struct? Other controls here declared in this way are clustered and, if I'm not mistaken, using unnamed struct to wrap them is just a typographically nice way to convey that. I think your new control could be declared without a wrapping struct { }.

Quoted 7 lines
drivers/media/i2c/ov5640.c +0 -0
 	struct {
 		struct v4l2_ctrl *auto_exp;
 		struct v4l2_ctrl *exposure;
@@ -2194,6 +2197,16 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 

drivers/media/i2c/ov5640.c static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, · line 2209

Quoted 10 lines
drivers/media/i2c/ov5640.c +10 -0
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+	u64 rate;
+
+	rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+	rate *= ov5640_framerates[sensor->current_fr];
+
+	return rate;
+}
+

Just to point out this is the -theoretical- pixel rate, and might be quite different from the one calculated by the clock tree tuning procedure (which should be updated to match Hugues' latest findings).

Quoted 6 lines
Quoted 2 lines

Hmm. Considering the xclk rate may be pretty much anything, I'd suppose the value above would only be correct for a given xclk rate.

I am not sure about that, different xclk rate might yield slightly different byte clock, but all in all the resolution and framerate pretty much dictate the end result, no?

Interestingly, the driver determines the PLL configuration based on the pixels per line and lines per frame (including blanking) and the frames per seconds. I guess it's always been like that in this driver.

So I agree the target frame rate can be used for this.

You could change ov5640_set_mode() to use this function as well to avoid doing the same calculation twice in different places in the driver. Up to you.

Quoted 74 lines
Quoted 4 lines

Could this be simply calculated from the clock tree configuration, to get the right value in all cases?

It probably could, and as I said earlier I gave it a try and failed, since the theoretical value worked for me that's what I went with. Those are the same values that Maxime's patch referred to. (dfbfb7aa832cdb media: ov5640:
Compute the clock rate at runtime).

Here I am just "publishing it".

Benoit

Quoted 60 lines
Quoted 28 lines
Quoted 15 lines
drivers/media/i2c/ov5640.c +2 -0
 static int ov5640_set_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -2233,6 +2246,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+				 ov5640_calc_pixel_rate(sensor));
 out:
 	mutex_unlock(&sensor->lock);
 	return ret;

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2677

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -2657,6 +2672,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
 	/* we can use our own mutex for the ctrl lock */
 	hdl->lock = &sensor->lock;
 
+	/* Clock related controls */
+	ctrls->pixel_rate =
+		v4l2_ctrl_new_std(hdl, ops,

If you like it better, this could fit in 1 line

	ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
					      0, INT_MAX, 1,
					      ov5640_calc_pixel_rate(sensor)
Quoted 8 lines

Thanks
j

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2680

Quoted 5 lines
drivers/media/i2c/ov5640.c +3 -0
+				  V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1,
+				  ov5640_calc_pixel_rate(sensor));
 
 
+	ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;

Note that ctrls->pixel_rate is NULL if e.g. memory allocation fails when creating the control.

Quoted 14 lines
Quoted 14 lines
drivers/media/i2c/ov5640.c +1 -0
+
 	/* Auto/manual white balance */
drivers/media/i2c/ov5640.c +3 -0
 	ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
 					   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2838,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 		sensor->frame_interval = fi->interval;
 		sensor->current_mode = mode;
 		sensor->pending_mode_change = true;
+
+		__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+					 ov5640_calc_pixel_rate(sensor));
 	}
 out:
 	mutex_unlock(&sensor->lock);
Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
Signature · 2 lines
Sakari Ailus
[email protected]
#6 lore raw

Re: [Patch v2 1/3] media: ov5640: add PIXEL_RATE control

In reply to Jacopo Mondi

Jacopo Mondi <[email protected]> wrote on Thu [2019-Oct-03 09:17:14 +0200]:

Quoted 18 lines

Hi Benoit,

Quoted 15 lines · Benoit Parrot

Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration.

---
 drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 500d9bbff10b..5198dc887400 100644
@@ -193,6 +193,9 @@ struct ov5640_mode_info {
 
Quoted 11 lines

drivers/media/i2c/ov5640.c struct ov5640_mode_info { · line 198

Quoted 5 lines
drivers/media/i2c/ov5640.c +3 -0
 struct ov5640_ctrls {
 	struct v4l2_ctrl_handler handler;
+	struct {
+		struct v4l2_ctrl *pixel_rate;
+	};

Do you need to wrap this v4l2_ctrl in it's own unnamed struct? Other controls here declared in this way are clustered and, if I'm not mistaken, using unnamed struct to wrap them is just a typographically nice way to convey that. I think your new control could be declared without a wrapping struct { }.

Probably not, just tried to be consistent with the rest of code here.

Quoted 8 lines
Quoted 8 lines
drivers/media/i2c/ov5640.c +0 -0
 	struct {
 		struct v4l2_ctrl *auto_exp;
 		struct v4l2_ctrl *exposure;
@@ -2194,6 +2197,16 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 
Quoted 14 lines

drivers/media/i2c/ov5640.c static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, · line 2209

Quoted 10 lines
drivers/media/i2c/ov5640.c +10 -0
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+	u64 rate;
+
+	rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+	rate *= ov5640_framerates[sensor->current_fr];
+
+	return rate;
+}
+

Just to point out this is the -theoretical- pixel rate, and might be quite different from the one calculated by the clock tree tuning procedure (which should be updated to match Hugues' latest findings).

True, and to my surprise my receiver worked with all of those value even if some actual value maybe off, I guess in my case they were close enough.

Quoted 23 lines
Quoted 14 lines
drivers/media/i2c/ov5640.c +2 -0
 static int ov5640_set_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -2233,6 +2246,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+				 ov5640_calc_pixel_rate(sensor));
 out:
 	mutex_unlock(&sensor->lock);
 	return ret;

drivers/media/i2c/ov5640.c static int ov5640_init_controls(struct ov5640_dev *sensor) · line 2677

Quoted 6 lines
drivers/media/i2c/ov5640.c +3 -0
@@ -2657,6 +2672,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
 	/* we can use our own mutex for the ctrl lock */
 	hdl->lock = &sensor->lock;
 
+	/* Clock related controls */
+	ctrls->pixel_rate =
+		v4l2_ctrl_new_std(hdl, ops,

If you like it better, this could fit in 1 line

Quoted 4 lines
	ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
					      0, INT_MAX, 1,
					      ov5640_calc_pixel_rate(sensor)

Either way works for me.

Benoit

Quoted 25 lines

Thanks
j

Quoted 22 lines
drivers/media/i2c/ov5640.c +4 -0
+				  V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1,
+				  ov5640_calc_pixel_rate(sensor));
 
 
+	ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
 	/* Auto/manual white balance */
drivers/media/i2c/ov5640.c +3 -1
 	ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
 					   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2838,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 		sensor->frame_interval = fi->interval;
 		sensor->current_mode = mode;
 		sensor->pending_mode_change = true;
+
+		__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+					 ov5640_calc_pixel_rate(sensor));
 	}
 out:
 	mutex_unlock(&sensor->lock);
--

2.17.1

#7 lore raw

PATCH v2 2/3 media: ov5640: Fix 1920x1080 mode to remove extra enable/disable

In reply to Benoit Parrot

In the 1920x1080 register array an extra pair of reset ctrl disable re-enable was causing unwanted init delays.

---
 drivers/media/i2c/ov5640.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov5640.c +1 -2
index 5198dc887400..103a4e8f88e1 100644
@@ -492,7 +492,6 @@ static const struct reg_value ov5640_setting_720P_1280_720[] = {
 };
 
 static const struct reg_value ov5640_setting_1080P_1920_1080[] = {
-	{0x3008, 0x42, 0, 0},
 	{0x3c07, 0x08, 0, 0},
 	{0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
 	{0x3814, 0x11, 0, 0},
@@ -520,7 +519,7 @@ static const struct reg_value ov5640_setting_1080P_1920_1080[] = {
 	{0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0},
 	{0x3a15, 0x60, 0, 0}, {0x4407, 0x04, 0, 0},
 	{0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0},
-	{0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0},
+	{0x4005, 0x1a, 0, 0},
 };
 
 static const struct reg_value ov5640_setting_QSXGA_2592_1944[] = {
Signature · 1 line
2.17.1
Reviewed-by on v2 2/3
#8 lore raw

Re: [Patch v2 2/3] media: ov5640: Fix 1920x1080 mode to remove extra enable/disable

Hi Benoit,
good catch. I wonder why those power down/up sequences where only
set for this mode...

I also wonder which kind of power down mode do we enter, if the chip is set in 'software power down mode' with 0x3008=0x42 at the beginning of the register blob write sequence, and we still can successfully program registers..

In any case, assuming 720p still works:

Thanks
j

Quoted 32 lines · Benoit Parrot

In the 1920x1080 register array an extra pair of reset ctrl disable re-enable was causing unwanted init delays.

---
 drivers/media/i2c/ov5640.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov5640.c +1 -3
index 5198dc887400..103a4e8f88e1 100644
@@ -492,7 +492,6 @@ static const struct reg_value ov5640_setting_720P_1280_720[] = {
 };
 
 static const struct reg_value ov5640_setting_1080P_1920_1080[] = {
-	{0x3008, 0x42, 0, 0},
 	{0x3c07, 0x08, 0, 0},
 	{0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
 	{0x3814, 0x11, 0, 0},
@@ -520,7 +519,7 @@ static const struct reg_value ov5640_setting_1080P_1920_1080[] = {
 	{0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0},
 	{0x3a15, 0x60, 0, 0}, {0x4407, 0x04, 0, 0},
 	{0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0},
-	{0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0},
+	{0x4005, 0x1a, 0, 0},
 };
 
 static const struct reg_value ov5640_setting_QSXGA_2592_1944[] = {
--

2.17.1

#9 lore raw

PATCH v2 3/3 media: ov5640: Make 2592x1944 mode only available at 15 fps

In reply to Benoit Parrot

The sensor data sheet clearly state that 2592x1944 only works at 15 fps make sure we don't try to miss configure the pll out of acceptable range.

---
 drivers/media/i2c/ov5640.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/i2c/ov5640.c +5 -0
index 103a4e8f88e1..d5b0be2c7a0a 100644
@@ -1613,6 +1613,11 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr,
 	    !(mode->hact == 640 && mode->vact == 480))
 		return NULL;
 
+	/* 2592x1944 only works at 15fps */
+	if (fr != OV5640_15_FPS &&
+	    (mode->hact == 2592 && mode->vact == 1944))
+		return NULL;
+
 	return mode;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v2 3/3
#10 lore raw

Re: [Patch v2 3/3] media: ov5640: Make 2592x1944 mode only available at 15 fps

Hi Benoit,

Quoted 3 lines · Benoit Parrot

The sensor data sheet clearly state that 2592x1944 only works at 15 fps make sure we don't try to miss configure the pll out of acceptable range.

The datasheet clearly indicates that 15 fps is the maximum achievable rate with that resolution, so I guess preventing it from being set to anything faster than that it's acceptable.

Quoted 11 lines
---
 drivers/media/i2c/ov5640.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 103a4e8f88e1..d5b0be2c7a0a 100644

drivers/media/i2c/ov5640.c ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr, · line 1617

Quoted 5 lines
drivers/media/i2c/ov5640.c +2 -0
@@ -1613,6 +1613,11 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr,
 	    !(mode->hact == 640 && mode->vact == 480))
 		return NULL;
 
+	/* 2592x1944 only works at 15fps */
+	if (fr != OV5640_15_FPS &&

As long as 15 fps is the lower framerate declared in ov5640_framerates[] this is ok, but I would make this condition a check for "fr > OV5640_15_FPS" so that it's safe for future extensions.

(And I would check for the resolution first then FPS, so you check the most unlikely condition first, but that's really a minor optimization).

With the above small details addressed

Thanks
j

Quoted 9 lines
drivers/media/i2c/ov5640.c +3 -1
+	    (mode->hact == 2592 && mode->vact == 1944))
+		return NULL;
+
 	return mode;
 }
 
--

2.17.1

#11 lore raw

Re: [Patch v2 3/3] media: ov5640: Make 2592x1944 mode only available at 15 fps

Jacopo Mondi <[email protected]> wrote on Thu [2019-Oct-03 09:31:55 +0200]:

Quoted 32 lines

Hi Benoit,

Quoted 3 lines · Benoit Parrot

The sensor data sheet clearly state that 2592x1944 only works at 15 fps make sure we don't try to miss configure the pll out of acceptable range.

The datasheet clearly indicates that 15 fps is the maximum achievable rate with that resolution, so I guess preventing it from being set to anything faster than that it's acceptable.

Quoted 11 lines
---
 drivers/media/i2c/ov5640.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/i2c/ov5640.c +0 -0
index 103a4e8f88e1..d5b0be2c7a0a 100644

drivers/media/i2c/ov5640.c ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr, · line 1617

Quoted 5 lines
drivers/media/i2c/ov5640.c +2 -0
@@ -1613,6 +1613,11 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr,
 	    !(mode->hact == 640 && mode->vact == 480))
 		return NULL;
 
+	/* 2592x1944 only works at 15fps */
+	if (fr != OV5640_15_FPS &&

As long as 15 fps is the lower framerate declared in ov5640_framerates[] this is ok, but I would make this condition a check for "fr > OV5640_15_FPS" so that it's safe for future extensions.

Quoted 3 lines

(And I would check for the resolution first then FPS, so you check the most unlikely condition first, but that's really a minor optimization).

Ah, very good I'll change that.

Benoit

Quoted 16 lines

With the above small details addressed

Thanks
j

Quoted 9 lines
drivers/media/i2c/ov5640.c +3 -1
+	    (mode->hact == 2592 && mode->vact == 1944))
+		return NULL;
+
 	return mode;
 }
 
--

2.17.1