Skip to contentSkip to conversation

media: i2c: ov2659: maintenance series

PATCH Superseded Benoit Parrot 3 participants 12 messages Sep 24, 2019 – Sep 27, 2019

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover media: i2c: ov2659: maintenance series

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

It includes a few sensor register fixes which would cause visual artifacts at lower resolution and also at 720p.

Also on some board the 'powerdown' and /or 'reset' pins are not tied so we need to add support for optional gpios to handle these.

Since these camera are removable on some board we also need the driver to actually fail when there is no hardware present so the driver is actually removed.

Also added a patch to check and propagate errors on s_stream invocation.

Finally, we update the licensing statement to use SPDX licensing.

Changes since v2:
- Addressed review comment from Sakari
- Reworked the "media: i2c: ov2659: Add powerdown/reset gpio handling" to use pm_runtime if it is available but not to make it depend on it.
- Cleaned up the gpio related calls to remove the unnecessary NULL check

Changes since v1:
- Addressed review comment from Prabhakar
- Added support for reset-gpios
- Rework the power setting to use pm_runtime instead of s_power as based on discussion with Sakari it would be the prefered method
- Added a patch to reduce the number explicit include files to the minimum necessary instead of the previous kitchen sink approach

Benoit Parrot (8):
media: i2c: ov2659: Fix for image wrap-around in lower resolution
media: i2c: ov2659: Fix sensor detection to actually fail when device
is not present
media: i2c: ov2659: Cleanup include file list
media: i2c: ov2659: fix s_stream return value
media: dt-bindings: ov2659: add powerdown/reset-gpios optional
property
media: i2c: ov2659: Add powerdown/reset gpio handling
media: i2c: ov2659: Fix missing 720p register config
media: i2c: ov2659: Switch to SPDX Licensing

 .../devicetree/bindings/media/i2c/ov2659.txt  |   9 ++
 drivers/media/i2c/Kconfig                     |   2 +-
 drivers/media/i2c/ov2659.c                    | 135 +++++++++++++-----
 3 files changed, 109 insertions(+), 37 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/8 media: i2c: ov2659: Fix for image wrap-around in lower resolution

Based on recently found sensor configuration examples, it was discovered that when scaling and binning are used for the lower resolutions (i.e. 640x480, 320x240) the read offset has to be increased otherwise the image appears to be wrapped around.

---
 drivers/media/i2c/ov2659.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ov2659.c +2 -2
index f4ded0669ff9..17573257097d 100644
@@ -661,7 +661,7 @@ static struct sensor_register ov2659_vga[] = {
 	{ REG_TIMING_HORIZ_FORMAT, 0x01 },
 	{ 0x370a, 0x52 },
 	{ REG_VFIFO_READ_START_H, 0x00 },
-	{ REG_VFIFO_READ_START_L, 0x80 },
+	{ REG_VFIFO_READ_START_L, 0xa0 },
 	{ REG_ISP_CTRL02, 0x10 },
 	{ REG_NULL, 0x00 },
 };
@@ -709,7 +709,7 @@ static  struct sensor_register ov2659_qvga[] = {
 	{ REG_TIMING_HORIZ_FORMAT, 0x01 },
 	{ 0x370a, 0x52 },
 	{ REG_VFIFO_READ_START_H, 0x00 },
-	{ REG_VFIFO_READ_START_L, 0x80 },
+	{ REG_VFIFO_READ_START_L, 0xa0 },
 	{ REG_ISP_CTRL02, 0x10 },
 	{ REG_NULL, 0x00 },
 };
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/8 media: i2c: ov2659: Fix sensor detection to actually fail when device is not present

In reply to Benoit Parrot

Make sure that if the expected sensor device id register is not recognized properly the failure is propagated up so devices are not left partially initialized.

---
 drivers/media/i2c/ov2659.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/ov2659.c +3 -2
index 17573257097d..efbe6dc720e2 100644
@@ -1330,11 +1330,12 @@ static int ov2659_detect(struct v4l2_subdev *sd)
 		unsigned short id;
 
 		id = OV265X_ID(pid, ver);
-		if (id != OV2659_ID)
+		if (id != OV2659_ID) {
 			dev_err(&client->dev,
 				"Sensor detection failed (%04X, %d)\n",
 				id, ret);
-		else {
+			ret = -ENODEV;
+		} else {
 			dev_info(&client->dev, "Found OV%04X sensor\n", id);
 			ret = ov2659_init(sd, 0);
 		}
Signature · 1 line
2.17.1
#3 lore raw

PATCH v3 3/8 media: i2c: ov2659: Cleanup include file list

In reply to Benoit Parrot

Several of include files listed are not explicitly needed. If they are need then they are implicitly included.

Reduce the list of includes to an easier to manage list.

---
 drivers/media/i2c/ov2659.c | 14 --------------
 1 file changed, 14 deletions(-)
drivers/media/i2c/ov2659.c +0 -14
index efbe6dc720e2..f77320e8a60d 100644
@@ -22,29 +22,15 @@
 
 #include <linux/clk.h>
 #include <linux/delay.h>
-#include <linux/err.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
 #include <linux/i2c.h>
-#include <linux/kernel.h>
-#include <linux/media.h>
 #include <linux/module.h>
-#include <linux/of.h>
 #include <linux/of_graph.h>
-#include <linux/slab.h>
-#include <linux/uaccess.h>
-#include <linux/videodev2.h>
 
-#include <media/media-entity.h>
 #include <media/i2c/ov2659.h>
-#include <media/v4l2-common.h>
 #include <media/v4l2-ctrls.h>
-#include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-fwnode.h>
 #include <media/v4l2-image-sizes.h>
-#include <media/v4l2-mediabus.h>
 #include <media/v4l2-subdev.h>
 
 #define DRIVER_NAME "ov2659"
Signature · 1 line
2.17.1
#4 lore raw

PATCH v3 4/8 media: i2c: ov2659: fix s_stream return value

In reply to Benoit Parrot

In ov2659_s_stream() return value for invoked function should be checked and propagated.

---
 drivers/media/i2c/ov2659.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2659.c +7 -4
index f77320e8a60d..cd4625432264 100644
@@ -1187,10 +1187,13 @@ static int ov2659_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock;
 	}
 
-	ov2659_set_pixel_clock(ov2659);
-	ov2659_set_frame_size(ov2659);
-	ov2659_set_format(ov2659);
-	ov2659_set_streaming(ov2659, 1);
+	ret = ov2659_set_pixel_clock(ov2659);
+	if (!ret)
+		ret = ov2659_set_frame_size(ov2659);
+	if (!ret)
+		ret = ov2659_set_format(ov2659);
+	if (!ret)
+		ov2659_set_streaming(ov2659, 1);
 	ov2659->streaming = on;
 
 unlock:
Signature · 1 line
2.17.1
#5 lore raw

PATCH v3 5/8 media: dt-bindings: ov2659: add powerdown/reset-gpios optional property

In reply to Benoit Parrot

Add powerdown-gpios and reset-gpios to the list of optional properties for the OV2659 camera sensor.

---
 Documentation/devicetree/bindings/media/i2c/ov2659.txt | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/media/i2c/ov2659.txt +9 -0
index cabc7d827dfb..92989a619f29 100644
@@ -12,6 +12,12 @@ Required Properties:
 - clock-names: should be "xvclk".
 - link-frequencies: target pixel clock frequency.
 
+Optional Properties:
+- powerdown-gpios: reference to the GPIO connected to the pwdn pin, if any.
+  Active high with internal pull down resistor.
+- reset-gpios: reference to the GPIO connected to the resetb pin, if any.
+  Active low with internal pull up resistor.
+
 For further reading on port node refer to
 Documentation/devicetree/bindings/media/video-interfaces.txt.
 
@@ -27,6 +33,9 @@ Example:
 			clocks = <&clk_ov2659 0>;
 			clock-names = "xvclk";
 
+			powerdown-gpios = <&gpio6 14 GPIO_ACTIVE_HIGH>;
+			reset-gpios = <&gpio6 15 GPIO_ACTIVE_LOW>;
+
 			port {
 				ov2659_0: endpoint {
 					remote-endpoint = <&vpfe_ep>;
Signature · 1 line
2.17.1
maintainer Reviewed-by on v3 5/8
#6 lore raw

Re: [Patch v3 5/8] media: dt-bindings: ov2659: add powerdown/reset-gpios optional property

Quoted 8 lines · Benoit Parrot

Add powerdown-gpios and reset-gpios to the list of optional properties for the OV2659 camera sensor.

---
 Documentation/devicetree/bindings/media/i2c/ov2659.txt | 9 +++++++++
 1 file changed, 9 insertions(+)
#7 lore raw

PATCH v3 6/8 media: i2c: ov2659: Add powerdown/reset gpio handling

In reply to Benoit Parrot

On some board it is possible that the sensor 'powerdown' and or 'reset' pin might be controlled by gpio instead of being tied.

To implement we add pm_runtime support which will handle the power up/down sequence when it is available otherwise the sensor will be powered on at module insertion/probe and powered off at module removal.

Now originally the driver assumed that the sensor would always stay powered and keep its register setting. We cannot assume this anymore, so every time we "power up" we need to re-program the initial registers configuration first. This was previously done only at probe time.

---
 drivers/media/i2c/Kconfig  |  2 +-
 drivers/media/i2c/ov2659.c | 85 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 3 deletions(-)
drivers/media/i2c/Kconfig +1 -1
index 7eee1812bba3..315c1d8bdb7b 100644
@@ -634,7 +634,7 @@ config VIDEO_OV2640
 config VIDEO_OV2659
 	tristate "OmniVision OV2659 sensor support"
 	depends on VIDEO_V4L2 && I2C
-	depends on MEDIA_CAMERA_SUPPORT
+	depends on MEDIA_CAMERA_SUPPORT && GPIOLIB
 	select V4L2_FWNODE
 	help
 	  This is a Video4Linux2 sensor driver for the OmniVision
drivers/media/i2c/ov2659.c +83 -2

158 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#8 lore raw

Re: [Patch v3 6/8] media: i2c: ov2659: Add powerdown/reset gpio handling

Hi Benoit,

Quoted 7 lines · Benoit Parrot

On some board it is possible that the sensor 'powerdown' and or 'reset' pin might be controlled by gpio instead of being tied.

To implement we add pm_runtime support which will handle the power up/down sequence when it is available otherwise the sensor will be powered on at module insertion/probe and powered off at module removal.

Quoted 6 lines

Now originally the driver assumed that the sensor would always stay powered and keep its register setting. We cannot assume this anymore, so every time we "power up" we need to re-program the initial registers configuration first. This was previously done only at probe time.

Thanks for the update.

I missed the control interface is accessible also when the device is not streaming, and the driver doesn't appear to power on the sensor for that, leading to a failing I²C write.

Could you address that as well, either here or as a separate patch? E.g. the smiapp driver does this.

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
#9 lore raw

Re: [Patch v3 6/8] media: i2c: ov2659: Add powerdown/reset gpio handling

Sakari Ailus <[email protected]> wrote on Wed [2019-Sep-25 12:51:54 +0300]:

Quoted 17 lines

Hi Benoit,

Quoted 7 lines · Benoit Parrot

On some board it is possible that the sensor 'powerdown' and or 'reset' pin might be controlled by gpio instead of being tied.

To implement we add pm_runtime support which will handle the power up/down sequence when it is available otherwise the sensor will be powered on at module insertion/probe and powered off at module removal.

Quoted 6 lines

Now originally the driver assumed that the sensor would always stay powered and keep its register setting. We cannot assume this anymore, so every time we "power up" we need to re-program the initial registers configuration first. This was previously done only at probe time.

Quoted 8 lines

Thanks for the update.

I missed the control interface is accessible also when the device is not streaming, and the driver doesn't appear to power on the sensor for that, leading to a failing I²C write.

Could you address that as well, either here or as a separate patch? E.g. the smiapp driver does this.

Yes, I missed that also.
I'll add a check in .s_ctrl().

Benoit

Quoted 6 lines
Signature · 5 lines
-- 
Kind regards,

Sakari Ailus
[email protected]
#10 lore raw

PATCH v3 7/8 media: i2c: ov2659: Fix missing 720p register config

In reply to Benoit Parrot

The initial registers sequence is only loaded at probe time. Afterward only the resolution and format specific register are modified. Care must be taken to make sure registers modified by one resolution setting are reverted back when another resolution is programmed.

This was not done properly for the 720p case.

---
 drivers/media/i2c/ov2659.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/ov2659.c +4 -0
index 0e026b810de5..23f161fd69bb 100644
@@ -412,10 +412,14 @@ static struct sensor_register ov2659_720p[] = {
 	{ REG_TIMING_YINC, 0x11 },
 	{ REG_TIMING_VERT_FORMAT, 0x80 },
 	{ REG_TIMING_HORIZ_FORMAT, 0x00 },
+	{ 0x370a, 0x12 },
 	{ 0x3a03, 0xe8 },
 	{ 0x3a09, 0x6f },
 	{ 0x3a0b, 0x5d },
 	{ 0x3a15, 0x9a },
+	{ REG_VFIFO_READ_START_H, 0x00 },
+	{ REG_VFIFO_READ_START_L, 0x80 },
+	{ REG_ISP_CTRL02, 0x00 },
 	{ REG_NULL, 0x00 },
 };
 
Signature · 1 line
2.17.1
#11 lore raw

PATCH v3 8/8 media: i2c: ov2659: Switch to SPDX Licensing

In reply to Benoit Parrot

Switch to SPDX licensing and drop the redundant GPL text.

---
 drivers/media/i2c/ov2659.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/media/i2c/ov2659.c +1 -13
index 23f161fd69bb..6b5fb2cf7f71 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Omnivision OV2659 CMOS Image Sensor driver
  *
@@ -5,19 +6,6 @@
  *
  * Benoit Parrot <[email protected]>
  * Lad, Prabhakar <[email protected]>
- *
- * This program is free software; you may redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
  */
 
 #include <linux/clk.h>
Signature · 1 line
2.17.1