Re: [PATCH v5 1/1] i2c: Add Omnivision OV5670 5M sensor support

2017-07-14 Thread Sakari Ailus
Hi Chiranjeevi,

On Thu, Jul 13, 2017 at 06:51:27PM -0700, Chiranjeevi Rapolu wrote:
> Provides single source pad with up to 2592x1944 pixels at 10-bit raw
> bayer format over MIPI CSI2 two lanes at 840Mbps/lane.
> The driver supports following features:
> - up to  30fps at 5M pixels
> - manual exposure
> - digital/analog gain
> - V-blank/H-blank
> - test pattern
> - media controller
> - runtime pm
> 
> Signed-off-by: Chiranjeevi Rapolu 

Thanks, applied with the following change:

diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
index 909095ac90a2..7de80645dd6f 100644
--- a/drivers/media/i2c/ov5670.c
+++ b/drivers/media/i2c/ov5670.c
@@ -2060,7 +2060,8 @@ static int ov5670_init_controls(struct ov5670 *ov5670)
   _ctrl_ops,
   V4L2_CID_LINK_FREQ,
   0, 0, link_freq_menu_items);
-   ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+   if (ov5670->link_freq)
+   ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
/* By default, V4L2_CID_PIXEL_RATE is read only */
ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, _ctrl_ops,

v4l2_ctrl_new_std() may return NULL, you always need to check for that if
you're using the returned result.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk


[PATCH v5 1/1] i2c: Add Omnivision OV5670 5M sensor support

2017-07-13 Thread Chiranjeevi Rapolu
Provides single source pad with up to 2592x1944 pixels at 10-bit raw
bayer format over MIPI CSI2 two lanes at 840Mbps/lane.
The driver supports following features:
- up to  30fps at 5M pixels
- manual exposure
- digital/analog gain
- V-blank/H-blank
- test pattern
- media controller
- runtime pm

Signed-off-by: Chiranjeevi Rapolu 
---
 drivers/media/i2c/Kconfig  |   12 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov5670.c | 2587 
 3 files changed, 2600 insertions(+)
 create mode 100644 drivers/media/i2c/ov5670.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 121b3b5..e0f2411 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -593,6 +593,18 @@ config VIDEO_OV5647
  To compile this driver as a module, choose M here: the
  module will be called ov5647.
 
+config VIDEO_OV5670
+   tristate "OmniVision OV5670 sensor support"
+   depends on I2C && VIDEO_V4L2
+   depends on MEDIA_CAMERA_SUPPORT
+   select V4L2_FWNODE
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV5670 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ov5670.
+
 config VIDEO_OV7640
tristate "OmniVision OV7640 sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 2c0868f..1fb3a1f 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_VIDEO_OV2640) += ov2640.o
 obj-$(CONFIG_VIDEO_OV5640) += ov5640.o
 obj-$(CONFIG_VIDEO_OV5645) += ov5645.o
 obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
+obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
new file mode 100644
index 000..909095a
--- /dev/null
+++ b/drivers/media/i2c/ov5670.c
@@ -0,0 +1,2587 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV5670_REG_CHIP_ID 0x300a
+#define OV5670_CHIP_ID 0x005670
+
+#define OV5670_REG_MODE_SELECT 0x0100
+#define OV5670_MODE_STANDBY0x00
+#define OV5670_MODE_STREAMING  0x01
+
+#define OV5670_REG_SOFTWARE_RST0x0103
+#define OV5670_SOFTWARE_RST0x01
+
+/* vertical-timings from sensor */
+#define OV5670_REG_VTS 0x380e
+#define OV5670_VTS_30FPS   0x0808 /* default for 30 fps */
+#define OV5670_VTS_MAX 0x
+#define OV5670_VBLANK_MIN  56
+
+/* horizontal-timings from sensor */
+#define OV5670_REG_HTS 0x380c
+#define OV5670_DEF_PPL 3360/* Default pixels per line */
+
+/* Exposure controls from sensor */
+#define OV5670_REG_EXPOSURE0x3500
+#defineOV5670_EXPOSURE_MIN 4
+#defineOV5670_EXPOSURE_STEP1
+
+/* Analog gain controls from sensor */
+#define OV5670_REG_ANALOG_GAIN 0x3508
+#defineANALOG_GAIN_MIN 0
+#defineANALOG_GAIN_MAX 8191
+#defineANALOG_GAIN_STEP1
+#defineANALOG_GAIN_DEFAULT 128
+
+/* Digital gain controls from sensor */
+#define OV5670_REG_R_DGTL_GAIN 0x5032
+#define OV5670_REG_G_DGTL_GAIN 0x5034
+#define OV5670_REG_B_DGTL_GAIN 0x5036
+#define OV5670_DGTL_GAIN_MIN   0
+#define OV5670_DGTL_GAIN_MAX   4095
+#define OV5670_DGTL_GAIN_STEP  1
+#define OV5670_DGTL_GAIN_DEFAULT   1024
+
+/* Test Pattern Control */
+#define OV5670_REG_TEST_PATTERN0x4303
+#define OV5670_TEST_PATTERN_ENABLE BIT(3)
+#define OV5670_REG_TEST_PATTERN_CTRL   0x4320
+
+#define OV5670_REG_VALUE_08BIT 1
+#define OV5670_REG_VALUE_16BIT 2
+#define OV5670_REG_VALUE_24BIT 3
+
+/* Initial number of frames to skip to avoid possible garbage */
+#define OV5670_NUM_OF_SKIP_FRAMES  2
+
+struct ov5670_reg {
+   u16 address;
+   u8 val;
+};
+
+struct ov5670_reg_list {
+   u32 num_of_regs;
+   const struct ov5670_reg *regs;
+};
+
+struct ov5670_link_freq_config {
+   u32 pixel_rate;
+   const struct ov5670_reg_list reg_list;
+};
+
+struct ov5670_mode {
+   /* Frame