Re: [PATCH 2/2] media: i2c: Add driver for Aptina MT9V111

2018-06-11 Thread kbuild test robot
Hi Jacopo,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.17 next-20180608]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jacopo-Mondi/media-i2c-mt9v111-sensor-driver/20180611-233038
base:   git://linuxtv.org/media_tree.git master
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=sh 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers/media/i2c/mt9v111.c: In function 'mt9v111_set_format':
>> drivers/media/i2c/mt9v111.c:929:15: warning: 'idx' may be used uninitialized 
>> in this function [-Wmaybe-uninitialized]
 unsigned int idx;
  ^~~

vim +/idx +929 drivers/media/i2c/mt9v111.c

   920  
   921  static int mt9v111_set_format(struct v4l2_subdev *subdev,
   922struct v4l2_subdev_pad_config *cfg,
   923struct v4l2_subdev_format *format)
   924  {
   925  struct mt9v111_dev *mt9v111 = sd_to_mt9v111(subdev);
   926  struct v4l2_mbus_framefmt new_fmt;
   927  struct v4l2_mbus_framefmt *__fmt;
   928  unsigned int best_fit = ~0L;
 > 929  unsigned int idx;
   930  unsigned int i;
   931  
   932  mutex_lock(>stream_mutex);
   933  if (mt9v111->streaming) {
   934  mutex_unlock(>stream_mutex);
   935  return -EBUSY;
   936  }
   937  mutex_unlock(>stream_mutex);
   938  
   939  if (format->pad)
   940  return -EINVAL;
   941  
   942  /* Update mbus format code and sizes. */
   943  for (i = 0; i < ARRAY_SIZE(mt9v111_formats); i++) {
   944  if (format->format.code == mt9v111_formats[i].code) {
   945  new_fmt.code = mt9v111_formats[i].code;
   946  break;
   947  }
   948  }
   949  if (i == ARRAY_SIZE(mt9v111_formats))
   950  new_fmt.code = mt9v111_formats[0].code;
   951  
   952  for (i = 0; i < ARRAY_SIZE(mt9v111_frame_sizes); i++) {
   953  unsigned int fit = abs(mt9v111_frame_sizes[i].width -
   954 format->format.width) +
   955 abs(mt9v111_frame_sizes[i].height -
   956 format->format.height);
   957  if (fit < best_fit) {
   958  best_fit = fit;
   959  idx = i;
   960  
   961  if (fit == 0)
   962  break;
   963  }
   964  }
   965  new_fmt.width = mt9v111_frame_sizes[idx].width;
   966  new_fmt.height = mt9v111_frame_sizes[idx].height;
   967  
   968  /* Update the device (or pad) format if it has changed. */
   969  __fmt = __mt9v111_get_pad_format(mt9v111, cfg, format->pad,
   970   format->which);
   971  
   972  /* Format hasn't changed, stop here. */
   973  if (__fmt->code == new_fmt.code &&
   974  __fmt->width == new_fmt.width &&
   975  __fmt->height == new_fmt.height)
   976  goto done;
   977  
   978  /* Update the format and sizes, then  mark changes as pending. 
*/
   979  __fmt->code = new_fmt.code;
   980  __fmt->width = new_fmt.width;
   981  __fmt->height = new_fmt.height;
   982  
   983  if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
   984  mt9v111->pending = true;
   985  
   986  dev_info(mt9v111->dev, "%s: mbus_code: %x - (%ux%u)\n",
   987   __func__, __fmt->code, __fmt->width, __fmt->height);
   988  
   989  done:
   990  format->format = *__fmt;
   991  
   992  return 0;
   993  }
   994  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH 2/2] media: i2c: Add driver for Aptina MT9V111

2018-06-11 Thread Jacopo Mondi
Add V4L2 sensor driver for Aptina MT9V111 CMOS image sensor.

The MT9V111 is a 1/4-Inch CMOS image sensor based on MT9V011 with an
integrated Image Flow Processor.

Signed-off-by: Jacopo Mondi 
---
 MAINTAINERS |8 +
 drivers/media/i2c/Kconfig   |   12 +
 drivers/media/i2c/Makefile  |1 +
 drivers/media/i2c/mt9v111.c | 1297 +++
 4 files changed, 1318 insertions(+)
 create mode 100644 drivers/media/i2c/mt9v111.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a38e24a..2c2fe60 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9523,6 +9523,14 @@ F:   
Documentation/devicetree/bindings/media/i2c/mt9v032.txt
 F: drivers/media/i2c/mt9v032.c
 F: include/media/i2c/mt9v032.h
 
+MT9V111 APTINA CAMERA SENSOR
+M: Jacopo Mondi 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: Documentation/devicetree/bindings/media/i2c/aptina,mt9v111.txt
+F: drivers/media/i2c/mt9v111.c
+
 MULTIFUNCTION DEVICES (MFD)
 M: Lee Jones 
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452f..0bd867d 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -841,6 +841,18 @@ config VIDEO_MT9V032
  This is a Video4Linux2 sensor-level driver for the Micron
  MT9V032 752x480 CMOS sensor.
 
+config VIDEO_MT9V111
+   tristate "Aptina MT9V111 sensor support"
+   depends on I2C && VIDEO_V4L2
+   depends on MEDIA_CAMERA_SUPPORT
+   depends on OF
+   help
+ This is a Video4Linux2 sensor-level driver for the Aptina/Micron
+ MT9V111 sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called mt9v111.
+
 config VIDEO_SR030PC30
tristate "Siliconfile SR030PC30 sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57..f0e8618 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_VIDEO_MT9T001) += mt9t001.o
 obj-$(CONFIG_VIDEO_MT9T112) += mt9t112.o
 obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o
 obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o
+obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o
 obj-$(CONFIG_VIDEO_SR030PC30)  += sr030pc30.o
 obj-$(CONFIG_VIDEO_NOON010PC30)+= noon010pc30.o
 obj-$(CONFIG_VIDEO_S5K6AA) += s5k6aa.o
diff --git a/drivers/media/i2c/mt9v111.c b/drivers/media/i2c/mt9v111.c
new file mode 100644
index 000..36e7424
--- /dev/null
+++ b/drivers/media/i2c/mt9v111.c
@@ -0,0 +1,1297 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * V4L2 sensor driver for Aptina MT9V111 image sensor
+ * Copyright (C) 2018 Jacopo Mondi 
+ *
+ * Based on mt9v032 driver
+ * Copyright (C) 2010, Laurent Pinchart 
+ * Copyright (C) 2008, Guennadi Liakhovetski 
+ *
+ * Base on mt9v011 driver
+ * Copyright (c) 2009 Mauro Carvalho Chehab 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * MT9V111 is a 1/4-Inch CMOS digital image sensor with an integrated
+ * Image Flow Processing (IFP) engine and a sensor core loosely based on
+ * MT9V011.
+ *
+ * The IFP can produce several output image formats from the sensor core
+ * output, this driver currently supports only YUYV format permutations.
+ *
+ * As the auto exposure algorithms controls exposure time and modifies the
+ * frame rate, this driver disables auto exposure control, auto white balancing
+ * and auto flickering avoidance to allow manual frame rate control through
+ * s_frame_interval subdev operation or V4L2_CID_V/HBLANK controls.
+ *
+ * While it seems possible to instruct the auto-exposure control algorithm to
+ * respect a programmed frame rate when adjusting the pixel integration time,
+ * registers controlling this feature are not documented in the public
+ * available sensor manual used to develop this driver (09005aef80e90084,
+ * MT9V111_1.fm - Rev. G 1/05 EN).
+ */
+
+#define MT9V111_CHIP_ID_HIGH   0x82
+#define MT9V111_CHIP_ID_LOW0x3a
+
+#define MT9V111_R01_ADDR_SPACE 0x01
+#define MT9V111_R01_IFP0x01
+#define MT9V111_R01_CORE   0x04
+
+#define MT9V111_IFP_R06_OPMODE_CTRL0x06
+#defineMT9V111_IFP_R06_OPMODE_CTRL_AWB_EN  BIT(1)
+#defineMT9V111_IFP_R06_OPMODE_CTRL_AE_EN   BIT(14)
+#define MT9V111_IFP_R07_IFP_RESET  0x07
+#defineMT9V111_IFP_R07_IFP_RESET_MASK  BIT(0)
+#define MT9V111_IFP_R08_OUTFMT_CTRL0x08
+#defineMT9V111_IFP_R08_OUTFMT_CTRL_FLICKER BIT(11)
+#defineMT9V111_IFP_R08_OUTFMT_CTRL_PCLKBIT(5)