RE: media: ov8856: Add support for OV8856 sensor

2018-11-19 Thread Kao, Ben
Hi Sakari,

> Hi Ben,
> 
> On Thu, Nov 08, 2018 at 11:41:46AM +0800, Ben Kao wrote:
> > This patch adds driver for Omnivision's ov8856 sensor, the driver
> > supports following features:
> >
> > - manual exposure/gain(analog and digital) control support
> > - two link frequencies
> > - VBLANK/HBLANK support
> > - test pattern support
> > - media controller support
> > - runtime pm support
> > - supported resolutions
> >   + 3280x2464 at 30FPS
> >   + 1640x1232 at 30FPS
> >
> > Signed-off-by: Ben Kao 
> 
> I just realised the driver is missing the MAINTAINERS entry. Could you provide
> one? Just the diff is fine, I'll then squash it to the patch.
> 
> Thanks.
> 
> --
> Regards,
> 
> Sakari Ailus
> sakari.ai...@linux.intel.com

We are still waiting for Omnivision's approval.
Once if get Omnivision's approval, I will update patch with MAINTAINERS entry.

Thanks.

Regards,

Ben Kao


Re: media: ov8856: Add support for OV8856 sensor

2018-11-16 Thread Sakari Ailus
Hi Ben,

On Thu, Nov 08, 2018 at 11:41:46AM +0800, Ben Kao wrote:
> This patch adds driver for Omnivision's ov8856 sensor,
> the driver supports following features:
> 
> - manual exposure/gain(analog and digital) control support
> - two link frequencies
> - VBLANK/HBLANK support
> - test pattern support
> - media controller support
> - runtime pm support
> - supported resolutions
>   + 3280x2464 at 30FPS
>   + 1640x1232 at 30FPS
> 
> Signed-off-by: Ben Kao 

I just realised the driver is missing the MAINTAINERS entry. Could you
provide one? Just the diff is fine, I'll then squash it to the patch.

Thanks.

-- 
Regards,

Sakari Ailus
sakari.ai...@linux.intel.com


media: ov8856: Add support for OV8856 sensor

2018-11-07 Thread Ben Kao
This patch adds driver for Omnivision's ov8856 sensor,
the driver supports following features:

- manual exposure/gain(analog and digital) control support
- two link frequencies
- VBLANK/HBLANK support
- test pattern support
- media controller support
- runtime pm support
- supported resolutions
  + 3280x2464 at 30FPS
  + 1640x1232 at 30FPS

Signed-off-by: Ben Kao 
---
 drivers/media/i2c/Kconfig  |   12 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov8856.c | 1296 
 3 files changed, 1309 insertions(+)
 create mode 100644 drivers/media/i2c/ov8856.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 704af21..4fdcb92 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -806,6 +806,18 @@ config VIDEO_OV7740
  This is a Video4Linux2 sensor driver for the OmniVision
  OV7740 VGA camera sensor.
 
+config VIDEO_OV8856
+   tristate "OmniVision OV8856 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   select V4L2_FWNODE
+   help
+ This is a Video4Linux2 sensor driver for the OmniVision
+ OV8856 camera sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ov8856.
+
 config VIDEO_OV9650
tristate "OmniVision OV9650/OV9652 sensor support"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 260d4d9..47accb0 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
 obj-$(CONFIG_VIDEO_OV7740) += ov7740.o
+obj-$(CONFIG_VIDEO_OV8856) += ov8856.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
 obj-$(CONFIG_VIDEO_OV13858) += ov13858.o
 obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
diff --git a/drivers/media/i2c/ov8856.c b/drivers/media/i2c/ov8856.c
new file mode 100644
index 000..feae739
--- /dev/null
+++ b/drivers/media/i2c/ov8856.c
@@ -0,0 +1,1296 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018 Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifndef V4L2_CID_DIGITAL_GAIN
+#define V4L2_CID_DIGITAL_GAIN  V4L2_CID_GAIN
+#endif
+
+#define OV8856_REG_VALUE_08BIT 1
+#define OV8856_REG_VALUE_16BIT 2
+#define OV8856_REG_VALUE_24BIT 3
+
+#define OV8856_LINK_FREQ_360MHZ36000ULL
+#define OV8856_LINK_FREQ_180MHZ18000ULL
+#define OV8856_SCLK14400ULL
+#define OV8856_MCLK1920
+#define OV8856_DATA_LANES  4
+
+#define OV8856_REG_CHIP_ID 0x300a
+#define OV8856_CHIP_ID 0x00885a
+
+#define OV8856_REG_MODE_SELECT 0x0100
+#define OV8856_MODE_STANDBY0x00
+#define OV8856_MODE_STREAMING  0x01
+
+/* vertical-timings from sensor */
+#define OV8856_REG_VTS 0x380e
+#define OV8856_VTS_MAX 0x7fff
+
+/* horizontal-timings from sensor */
+#define OV8856_REG_HTS 0x380c
+
+/* Exposure controls from sensor */
+#define OV8856_REG_EXPOSURE0x3500
+#defineOV8856_EXPOSURE_MIN 6
+#define OV8856_EXPOSURE_MAX_MARGIN 6
+#defineOV8856_EXPOSURE_STEP1
+
+/* Analog gain controls from sensor */
+#define OV8856_REG_ANALOG_GAIN 0x3508
+#defineOV8856_ANAL_GAIN_MIN128
+#defineOV8856_ANAL_GAIN_MAX2047
+#defineOV8856_ANAL_GAIN_STEP   1
+
+/* Digital gain controls from sensor */
+#define OV8856_REG_MWB_R_GAIN  0x5019
+#define OV8856_REG_MWB_G_GAIN  0x501b
+#define OV8856_REG_MWB_B_GAIN  0x501d
+#define OV8856_DGTL_GAIN_MIN   0
+#define OV8856_DGTL_GAIN_MAX   4095
+#define OV8856_DGTL_GAIN_STEP  1
+#define OV8856_DGTL_GAIN_DEFAULT   1024
+
+/* Test Pattern Control */
+#define OV8856_REG_TEST_PATTERN0x5e00
+#define OV8856_TEST_PATTERN_ENABLE BIT(7)
+#define OV8856_TEST_PATTERN_BAR_SHIFT  2
+
+#define to_ov8856(_sd) container_of(_sd, struct ov8856, sd)
+
+enum {
+   OV8856_LINK_FREQ_720MBPS,
+   OV8856_LINK_FREQ_360MBPS,
+};
+
+struct ov8856_reg {
+   u16 address;
+   u8 val;
+};
+
+struct ov8856_reg_list {
+   u32 num_of_regs;
+   const struct ov8856_reg *regs;
+};
+
+struct ov8856_link_freq_config {
+   const struct ov8856_reg_list reg_list;
+};
+
+struct ov8856_mode {
+   /* Frame width in pixels */
+   u32 width;
+
+   /* Frame height in pixels */
+   u32 height;
+
+   /* Horizontal timining size */
+   u32 hts;
+
+   /* Default vertical timining size */
+   u32 vts_def;
+
+   /* Min vertical timining size