Re: [PATCH] media: jpeg: add driver for a version 2.x of jpeg H/W

2012-03-03 Thread Sylwester Nawrocki
Hi 송영목,

On 03/02/2012 12:46 AM, 송영목 wrote:
 This patch add a driver for a version 2.x of jpeg H/W

s/add/adds
 in ths Samsung Exynos5 Soc.

s/ths/the
 A jpeg H/W version of Exynos4 SoC is 3.0
 
 1. Encoding
   - input format : V4L2_PIX_FMT_RGB565X and V4L2_PIX_FMT_YUYV
 
 2. Decoding
   - output format : V4L2_PIX_FMT_YUYV and V4L2_PIX_FMT_YUV420

Please consider reworking this patch so it can be applied on the latest 
s5p-jpeg driver 
changes adding JPEG controls:
http://git.infradead.org/users/kmpark/linux-2.6-samsung/shortlog/refs/heads/media-for-next
 

 Signed-off-by: youngmok songym.s...@samsung.com

Normally the full name starts with capital letters.

 ---
   drivers/media/video/Kconfig   |   17 +
   drivers/media/video/s5p-jpeg/Makefile |5 +-
   drivers/media/video/s5p-jpeg/jpeg-core.c  |  303 +---
   drivers/media/video/s5p-jpeg/jpeg-hw-common.h |   34 +++
   drivers/media/video/s5p-jpeg/jpeg-hw-v2x.h|  387 
 +
   drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h  |  150 ++
   drivers/media/video/s5p-jpeg/jpeg-v2x.c   |  129 
   drivers/media/video/s5p-jpeg/jpeg-v3.c|  340 ++
   8 files changed, 1066 insertions(+), 299 deletions(-)
   create mode 100644 drivers/media/video/s5p-jpeg/jpeg-hw-common.h
   create mode 100644 drivers/media/video/s5p-jpeg/jpeg-hw-v2x.h
   create mode 100644 drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
   create mode 100644 drivers/media/video/s5p-jpeg/jpeg-v2x.c
   create mode 100644 drivers/media/video/s5p-jpeg/jpeg-v3.c
 
 diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
 index 9adada0..551f925 100644
 --- a/drivers/media/video/Kconfig
 +++ b/drivers/media/video/Kconfig
 @@ -1167,6 +1167,23 @@ config VIDEO_SAMSUNG_S5P_JPEG
   select V4L2_MEM2MEM_DEV
   ---help---
 This is a v4l2 driver for Samsung S5P and EXYNOS4 JPEG codec
 +choice
 + prompt JPEG V4L2 Driver
 + default S5P_JPEG_V3
 + depends on VIDEO_SAMSUNG_S5P_JPEG
 + ---help---
 +   Select version of MFC driver

MFC  ?

 +config S5P_JPEG_V3
 + bool JPEG 3.x
 + ---help---
 +   Use JPEG 3.x V4L2 Driver
 +
 +config S5P_JPEG_V2
 + bool JPEG 2.x
 + ---help---
 +   Use JPEG 2.x V4L2 Driver
 +endchoice

How the user is supposed to know which JPEG IP version applies to which SoC ?

Generally, resolving the hardware differences at compile time is not something 
that
we would want. I suggest using struct platform_device_id for handling different 
H/W 
variants, like it is done for example in drivers/dma/imx-sdma.c (see 
sdma_devtypes 
table). It will ease the driver's adaptation to instantiation from the device 
tree, which
is important, since the exynos5 is supposed to be a DT only platform.

Probably even function pointers at the variant data structure wouldn't hurt, if 
there
is too many differences to handle them through single flags. From a quick 
review it 
feels like the code could be consolidated more, but I'm going to leave 
commenting
on the details for Andrzej.

Please have a look at the JPEG controls:
http://git.infradead.org/users/kmpark/linux-samsung/commitdiff/e0122eabd2be3f0a3a9ff635df81e5c2509c4700
and feel free to propose anything you think is missing there (the Huffman and 
the 
quantization tables will need their own ioctl(s)).

As a side note, please don't use Korean characters in the patch message. This 
implies
the character set other than ascii/utf-8 and and makes patches impossible to 
apply.

 --

Regards,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 09/10] v4l: Aptina-style sensor PLL support

2012-03-03 Thread Laurent Pinchart
Hi Sakari,

Thanks for the review.

On Friday 02 March 2012 20:46:21 Sakari Ailus wrote:
 On Fri, Mar 02, 2012 at 11:44:06AM +0100, Laurent Pinchart wrote:
  Add a generic helper function to compute PLL parameters for PLL found in
  several Aptina sensors.
  
  Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
  
   drivers/media/video/Kconfig  |4 +
   drivers/media/video/Makefile |4 +
   drivers/media/video/aptina-pll.c |  120
   ++ drivers/media/video/aptina-pll.h
   |   55 +
   4 files changed, 183 insertions(+), 0 deletions(-)
   create mode 100644 drivers/media/video/aptina-pll.c
   create mode 100644 drivers/media/video/aptina-pll.h
  
  diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
  index 80acb78..e1dfdbc 100644
  --- a/drivers/media/video/Kconfig
  +++ b/drivers/media/video/Kconfig
  @@ -133,6 +133,9 @@ menu Encoders, decoders, sensors and other helper
  chips 
   comment Audio decoders, processors and mixers
  
  +config VIDEO_APTINA_PLL
  +   tristate
  +
  
   config VIDEO_TVAUDIO
   
  tristate Simple audio decoder chips
  depends on VIDEO_V4L2  I2C
 
 Wouldn't it make sense to create another section for these to separate them
 from the reset? This isn't audio decoder, processor nor mixer. :-)

I'm not sure if a separate section is really needed. The option won't show up 
during configuration, it will be selected automatically by other drivers. I'll 
move it to the Camera sensor devices section anyway, as it's more logical to 
group it with the sensor drivers.

  @@ -946,6 +949,7 @@ config SOC_CAMERA_MT9M001
  
   config VIDEO_MT9M032
   
  tristate MT9M032 camera sensor support
  depends on I2C  VIDEO_V4L2
  
  +   select VIDEO_APTINA_PLL
  
  help
  
This driver supports MT9M032 cameras from Micron, monochrome
models only.
 
 This should be in another patch, shouldn't it?

Yes, That's already fixed :-)

  diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
  index 9b19533..8e037e9 100644
  --- a/drivers/media/video/Makefile
  +++ b/drivers/media/video/Makefile
  @@ -22,6 +22,10 @@ endif
  
   obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
  
  +# Helper modules
  +
  +obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
  +
  
   # All i2c modules must come first:
   
   obj-$(CONFIG_VIDEO_TUNER) += tuner.o
  
  diff --git a/drivers/media/video/aptina-pll.c
  b/drivers/media/video/aptina-pll.c new file mode 100644
  index 000..e4df9ec
  --- /dev/null
  +++ b/drivers/media/video/aptina-pll.c
  @@ -0,0 +1,120 @@
  +/*
  + * Aptina Sensor PLL Configuration
  + *
  + * Copyright (C) 2012 Laurent Pinchart
  laurent.pinch...@ideasonboard.com
  + *
  + * 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.
  + *
  + * You should have received a copy of the GNU General Public License
  + * along with this program; if not, write to the Free Software
  + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA
  + */
  +
  +#include linux/device.h
  +#include linux/gcd.h
  +#include linux/kernel.h
  +#include linux/module.h
  +
  +#include aptina-pll.h
  +
  +int aptina_pll_configure(struct device *dev, struct aptina_pll *pll,
  +const struct aptina_pll_limits *limits)
  +{
  +   unsigned int mf_min;
  +   unsigned int mf_max;
  +   unsigned int mf;
  +   unsigned int clock;
  +   unsigned int div;
  +   unsigned int p1;
  +   unsigned int n;
  +   unsigned int m;
  +
  +   if (pll-ext_clock  limits-ext_clock_min ||
  +   pll-ext_clock  limits-ext_clock_max) {
  +   dev_err(dev, pll: invalid external clock frequency.\n);
  +   return -EINVAL;
  +   }
  +
  +   if (pll-pix_clock  limits-pix_clock_max) {
  +   dev_err(dev, pll: invalid pixel clock frequency.\n);
  +   return -EINVAL;
  +   }
  +
  +   /* Compute the multiplier M and combined N*P1 divisor. */
  +   div = gcd(pll-pix_clock, pll-ext_clock);
  +   pll-m = pll-pix_clock / div;
  +   div = pll-ext_clock / div;
  +
  +   /* We now have the smallest M and N*P1 values that will result in the
  +* desired pixel clock frequency, but they might be out of the valid
  +* range. Compute the factor by which we should multiply them given 
the
  +* following constraints:
  +*
  +* - minimum/maximum multiplier
  +* - minimum/maximum multiplier output clock frequency assuming the
  +*   minimum/maximum N value
  +* - minimum/maximum combined N*P1 divisor
  +*/
  +   mf_min = 

[PATCH v3 09/10] v4l: Aptina-style sensor PLL support

2012-03-03 Thread Laurent Pinchart
Add a generic helper function to compute PLL parameters for PLL found in
several Aptina sensors.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/Kconfig  |3 +
 drivers/media/video/Makefile |4 +
 drivers/media/video/aptina-pll.c |  175 ++
 drivers/media/video/aptina-pll.h |   55 
 4 files changed, 237 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/aptina-pll.c
 create mode 100644 drivers/media/video/aptina-pll.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 80acb78..410baf2 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -459,6 +459,9 @@ config VIDEO_AK881X
 
 comment Camera sensor devices
 
+config VIDEO_APTINA_PLL
+   tristate
+
 config VIDEO_OV7670
tristate OmniVision OV7670 sensor support
depends on I2C  VIDEO_V4L2
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 9b19533..8e037e9 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -22,6 +22,10 @@ endif
 
 obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
 
+# Helper modules
+
+obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
+
 # All i2c modules must come first:
 
 obj-$(CONFIG_VIDEO_TUNER) += tuner.o
diff --git a/drivers/media/video/aptina-pll.c b/drivers/media/video/aptina-pll.c
new file mode 100644
index 000..55e4a40
--- /dev/null
+++ b/drivers/media/video/aptina-pll.c
@@ -0,0 +1,175 @@
+/*
+ * Aptina Sensor PLL Configuration
+ *
+ * Copyright (C) 2012 Laurent Pinchart laurent.pinch...@ideasonboard.com
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include linux/device.h
+#include linux/gcd.h
+#include linux/kernel.h
+#include linux/lcm.h
+#include linux/module.h
+
+#include aptina-pll.h
+
+int aptina_pll_configure(struct device *dev, struct aptina_pll *pll,
+const struct aptina_pll_limits *limits)
+{
+   unsigned int mf_min;
+   unsigned int mf_max;
+   unsigned int p1_min;
+   unsigned int p1_max;
+   unsigned int p1;
+   unsigned int div;
+
+   if (pll-ext_clock  limits-ext_clock_min ||
+   pll-ext_clock  limits-ext_clock_max) {
+   dev_err(dev, pll: invalid external clock frequency.\n);
+   return -EINVAL;
+   }
+
+   if (pll-pix_clock  limits-pix_clock_max) {
+   dev_err(dev, pll: invalid pixel clock frequency.\n);
+   return -EINVAL;
+   }
+
+   /* Compute the multiplier M and combined N*P1 divisor. */
+   div = gcd(pll-pix_clock, pll-ext_clock);
+   pll-m = pll-pix_clock / div;
+   div = pll-ext_clock / div;
+
+   /* We now have the smallest M and N*P1 values that will result in the
+* desired pixel clock frequency, but they might be out of the valid
+* range. Compute the factor by which we should multiply them given the
+* following constraints:
+*
+* - minimum/maximum multiplier
+* - minimum/maximum multiplier output clock frequency assuming the
+*   minimum/maximum N value
+* - minimum/maximum combined N*P1 divisor
+*/
+   mf_min = DIV_ROUND_UP(limits-m_min, pll-m);
+   mf_min = max(mf_min, limits-out_clock_min /
+(pll-ext_clock / limits-n_min * pll-m));
+   mf_min = max(mf_min, limits-n_min * limits-p1_min / div);
+   mf_max = limits-m_max / pll-m;
+   mf_max = min(mf_max, limits-out_clock_max /
+   (pll-ext_clock / limits-n_max * pll-m));
+   mf_max = min(mf_max, DIV_ROUND_UP(limits-n_max * limits-p1_max, div));
+
+   dev_dbg(dev, pll: mf min %u max %u\n, mf_min, mf_max);
+   if (mf_min  mf_max) {
+   dev_err(dev, pll: no valid combined N*P1 divisor.\n);
+   return -EINVAL;
+   }
+
+   /*
+* We're looking for the highest acceptable P1 value for which a
+* multiplier factor MF exists that fulfills the following conditions:
+*
+* 1. p1 is in the [p1_min, p1_max] range given by the limits and is
+*even
+* 2. mf is in the [mf_min, mf_max] range computed above
+* 3. div * mf is a multiple of p1, in order to compute
+*  n = div * mf / p1
+*  m = pll-m * mf
+* 4. 

[PATCH v3 05/10] mt9m032: Enclose to_dev() macro argument in brackets

2012-03-03 Thread Laurent Pinchart
To make the macro safer to use, enclose its argument in brackets in the
macro's body.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/mt9m032.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index a821b91..74f0cdd 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -121,7 +121,8 @@ struct mt9m032 {
 };
 
 #define to_mt9m032(sd) container_of(sd, struct mt9m032, subdev)
-#define to_dev(sensor) ((struct i2c_client 
*)v4l2_get_subdevdata(sensor-subdev))-dev
+#define to_dev(sensor) \
+   (((struct i2c_client *)v4l2_get_subdevdata((sensor)-subdev))-dev)
 
 static int mt9m032_read_reg(struct mt9m032 *sensor, u8 reg)
 {
-- 
1.7.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 01/10] v4l: Add driver for Micron MT9M032 camera sensor

2012-03-03 Thread Laurent Pinchart
From: Martin Hostettler mar...@neutronstar.dyndns.org

The MT9M032 is a parallel 1.6MP sensor from Micron controlled through I2C.

The driver creates a V4L2 subdevice. It currently supports cropping, gain,
exposure and v/h flipping controls in monochrome mode with an
external pixel clock.

Signed-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 drivers/media/video/Kconfig   |7 +
 drivers/media/video/Makefile  |1 +
 drivers/media/video/mt9m032.c |  832 +
 include/media/mt9m032.h   |   38 ++
 4 files changed, 878 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/mt9m032.c
 create mode 100644 include/media/mt9m032.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 9495b6a..80acb78 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -943,6 +943,13 @@ config SOC_CAMERA_MT9M001
  This driver supports MT9M001 cameras from Micron, monochrome
  and colour models.
 
+config VIDEO_MT9M032
+   tristate MT9M032 camera sensor support
+   depends on I2C  VIDEO_V4L2
+   help
+ This driver supports MT9M032 cameras from Micron, monochrome
+ models only.
+
 config SOC_CAMERA_MT9M111
tristate mt9m111, mt9m112 and mt9m131 support
depends on SOC_CAMERA  I2C
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 563443c..9b19533 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_VIDEO_AS3645A)   += as3645a.o
 
 obj-$(CONFIG_SOC_CAMERA_IMX074)+= imx074.o
 obj-$(CONFIG_SOC_CAMERA_MT9M001)   += mt9m001.o
+obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
 obj-$(CONFIG_SOC_CAMERA_MT9M111)   += mt9m111.o
 obj-$(CONFIG_SOC_CAMERA_MT9T031)   += mt9t031.o
 obj-$(CONFIG_SOC_CAMERA_MT9T112)   += mt9t112.o
diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
new file mode 100644
index 000..92495f7
--- /dev/null
+++ b/drivers/media/video/mt9m032.c
@@ -0,0 +1,832 @@
+/*
+ * Driver for MT9M032 CMOS Image Sensor from Micron
+ *
+ * Copyright (C) 2010-2011 Lund Engineering
+ * Contact: Gil Lund gwl...@lundeng.com
+ * Author: Martin Hostettler mar...@neutronstar.dyndns.org
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include linux/delay.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/kernel.h
+#include linux/math64.h
+#include linux/module.h
+#include linux/slab.h
+#include linux/v4l2-mediabus.h
+
+#include media/media-entity.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-device.h
+#include media/v4l2-subdev.h
+
+#include media/mt9m032.h
+
+#define MT9M032_CHIP_VERSION   0x00
+#define MT9M032_CHIP_VERSION_VALUE 0x1402
+#define MT9M032_ROW_START  0x01
+#define MT9M032_COLUMN_START   0x02
+#define MT9M032_ROW_SIZE   0x03
+#define MT9M032_COLUMN_SIZE0x04
+#define MT9M032_HBLANK 0x05
+#define MT9M032_VBLANK 0x06
+#define MT9M032_SHUTTER_WIDTH_HIGH 0x08
+#define MT9M032_SHUTTER_WIDTH_LOW  0x09
+#define MT9M032_PIX_CLK_CTRL   0x0a
+#define MT9M032_PIX_CLK_CTRL_INV_PIXCLK0x8000
+#define MT9M032_RESTART0x0b
+#define MT9M032_RESET  0x0d
+#define MT9M032_PLL_CONFIG10x11
+#define MT9M032_PLL_CONFIG1_OUTDIV_MASK0x3f
+#define MT9M032_PLL_CONFIG1_MUL_SHIFT  8
+#define MT9M032_READ_MODE1 0x1e
+#define MT9M032_READ_MODE2 0x20
+#define MT9M032_READ_MODE2_VFLIP_SHIFT 15
+#define MT9M032_READ_MODE2_HFLIP_SHIFT 14
+#define MT9M032_READ_MODE2_ROW_BLC 0x40
+#define MT9M032_GAIN_GREEN10x2b
+#define MT9M032_GAIN_BLUE  0x2c
+#define MT9M032_GAIN_RED   0x2d
+#define MT9M032_GAIN_GREEN20x2e
+/* write only */
+#define MT9M032_GAIN_ALL   0x35
+#define MT9M032_GAIN_DIGITAL_MASK  0x7f
+#define MT9M032_GAIN_DIGITAL_SHIFT 8
+#define MT9M032_GAIN_AMUL_SHIFT6
+#define MT9M032_GAIN_ANALOG_MASK   0x3f

[PATCH v3 02/10] mt9m032: Reorder code into section and whitespace cleanups

2012-03-03 Thread Laurent Pinchart
Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/mt9m032.c |  162 +---
 1 files changed, 85 insertions(+), 77 deletions(-)

diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index 92495f7..b6ef69f 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -30,12 +30,11 @@
 #include linux/v4l2-mediabus.h
 
 #include media/media-entity.h
+#include media/mt9m032.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-device.h
 #include media/v4l2-subdev.h
 
-#include media/mt9m032.h
-
 #define MT9M032_CHIP_VERSION   0x00
 #define MT9M032_CHIP_VERSION_VALUE 0x1402
 #define MT9M032_ROW_START  0x01
@@ -73,24 +72,18 @@
 #define MT9M032_FORMATTER2_DOUT_EN 0x1000
 #define MT9M032_FORMATTER2_PIXCLK_EN   0x2000
 
-#define MT9M032_MAX_BLANKING_ROWS  0x7ff
-
-
 /*
- * The availible MT9M032 datasheet is missing documentation for register 0x10
+ * The available MT9M032 datasheet is missing documentation for register 0x10
  * MT9P031 seems to be close enough, so use constants from that datasheet for
  * now.
  * But keep the name MT9P031 to remind us, that this isn't really confirmed
  * for this sensor.
  */
-
 #define MT9P031_PLL_CONTROL0x10
 #define MT9P031_PLL_CONTROL_PWROFF 0x0050
 #define MT9P031_PLL_CONTROL_PWRON  0x0051
 #define MT9P031_PLL_CONTROL_USEPLL 0x0052
 
-
-
 /*
  * width and height include active boundry and black parts
  *
@@ -108,9 +101,7 @@
 #define MT9M032_WIDTH  1600
 #define MT9M032_HEIGHT 1152
 #define MT9M032_MINIMALSIZE32
-
-#define to_mt9m032(sd) container_of(sd, struct mt9m032, subdev)
-#define to_dev(sensor) ((struct i2c_client 
*)v4l2_get_subdevdata(sensor-subdev))-dev
+#define MT9M032_MAX_BLANKING_ROWS  0x7ff
 
 struct mt9m032 {
struct v4l2_subdev subdev;
@@ -129,6 +120,8 @@ struct mt9m032 {
struct v4l2_ctrl *hflip, *vflip;
 };
 
+#define to_mt9m032(sd) container_of(sd, struct mt9m032, subdev)
+#define to_dev(sensor) ((struct i2c_client 
*)v4l2_get_subdevdata(sensor-subdev))-dev
 
 static int mt9m032_read_reg(struct mt9m032 *sensor, u8 reg)
 {
@@ -145,7 +138,6 @@ static int mt9m032_write_reg(struct mt9m032 *sensor, u8 reg,
return i2c_smbus_write_word_swapped(client, reg, data);
 }
 
-
 static unsigned long mt9m032_row_time(struct mt9m032 *sensor, int width)
 {
int effective_width;
@@ -173,23 +165,23 @@ static int mt9m032_update_timing(struct mt9m032 *sensor,
row_time = mt9m032_row_time(sensor, crop-width);
 
additional_blanking_rows = div_u64(((u64)10) * 
interval-numerator,
- ((u64)interval-denominator) * 
row_time)
-  - crop-height;
+ ((u64)interval-denominator) * 
row_time)
+  - crop-height;
 
if (additional_blanking_rows  MT9M032_MAX_BLANKING_ROWS) {
/* hardware limits to 11 bit values */
interval-denominator = 1000;
interval-numerator = div_u64((crop-height + 
MT9M032_MAX_BLANKING_ROWS)
- * ((u64)row_time) * 
interval-denominator,
+ * ((u64)row_time) * 
interval-denominator,
  10);
additional_blanking_rows = div_u64(((u64)10) * 
interval-numerator,
- ((u64)interval-denominator) * 
row_time)
-  - crop-height;
+ ((u64)interval-denominator) * 
row_time)
+  - crop-height;
}
/* enforce minimal 1.6ms blanking time. */
min_blank = 160 / row_time;
additional_blanking_rows = clamp(additional_blanking_rows,
-min_blank, MT9M032_MAX_BLANKING_ROWS);
+min_blank, MT9M032_MAX_BLANKING_ROWS);
 
return mt9m032_write_reg(sensor, MT9M032_VBLANK, 
additional_blanking_rows);
 }
@@ -224,17 +216,51 @@ static int update_formatter2(struct mt9m032 *sensor, bool 
streaming)
return mt9m032_write_reg(sensor, MT9M032_FORMATTER2, reg_val);
 }
 
-static int mt9m032_s_stream(struct v4l2_subdev *subdev, int streaming)
+static int mt9m032_setup_pll(struct mt9m032 *sensor)
 {
-   struct mt9m032 *sensor = to_mt9m032(subdev);
-   int ret;
+   struct mt9m032_platform_data* pdata = sensor-pdata;
+   u16 reg_pll1;
+   unsigned int pre_div;
+   int res, ret;
 
-   ret = update_formatter2(sensor, streaming);
+   /* TODO: also support other pre-div values */
+   if 

[PATCH v3 06/10] mt9m032: Pass an i2c_client pointer to the register read/write functions

2012-03-03 Thread Laurent Pinchart
Replace the mt9m032 * argument to register read/write functions with an
i2c_client *. As the register access functions are often called several
times in a single location, this removes several casts at runtime.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/mt9m032.c |   78 +
 1 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index 74f0cdd..cfed53a 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -124,18 +124,13 @@ struct mt9m032 {
 #define to_dev(sensor) \
(((struct i2c_client *)v4l2_get_subdevdata((sensor)-subdev))-dev)
 
-static int mt9m032_read_reg(struct mt9m032 *sensor, u8 reg)
+static int mt9m032_read_reg(struct i2c_client *client, u8 reg)
 {
-   struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
-
return i2c_smbus_read_word_swapped(client, reg);
 }
 
-static int mt9m032_write_reg(struct mt9m032 *sensor, u8 reg,
-const u16 data)
+static int mt9m032_write_reg(struct i2c_client *client, u8 reg, const u16 data)
 {
-   struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
-
return i2c_smbus_write_word_swapped(client, reg, data);
 }
 
@@ -153,6 +148,7 @@ static unsigned long mt9m032_row_time(struct mt9m032 
*sensor, int width)
 static int mt9m032_update_timing(struct mt9m032 *sensor,
 struct v4l2_fract *interval)
 {
+   struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
struct v4l2_rect *crop = sensor-crop;
unsigned long row_time;
int additional_blanking_rows;
@@ -182,24 +178,26 @@ static int mt9m032_update_timing(struct mt9m032 *sensor,
additional_blanking_rows = clamp(additional_blanking_rows,
 min_blank, MT9M032_MAX_BLANKING_ROWS);
 
-   return mt9m032_write_reg(sensor, MT9M032_VBLANK, 
additional_blanking_rows);
+   return mt9m032_write_reg(client, MT9M032_VBLANK,
+additional_blanking_rows);
 }
 
 static int mt9m032_update_geom_timing(struct mt9m032 *sensor)
 {
+   struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
int ret;
 
-   ret = mt9m032_write_reg(sensor, MT9M032_COLUMN_SIZE,
+   ret = mt9m032_write_reg(client, MT9M032_COLUMN_SIZE,
sensor-crop.width - 1);
if (!ret)
-   ret = mt9m032_write_reg(sensor, MT9M032_ROW_SIZE,
+   ret = mt9m032_write_reg(client, MT9M032_ROW_SIZE,
sensor-crop.height - 1);
/* offsets compensate for black border */
if (!ret)
-   ret = mt9m032_write_reg(sensor, MT9M032_COLUMN_START,
+   ret = mt9m032_write_reg(client, MT9M032_COLUMN_START,
sensor-crop.left);
if (!ret)
-   ret = mt9m032_write_reg(sensor, MT9M032_ROW_START,
+   ret = mt9m032_write_reg(client, MT9M032_ROW_START,
sensor-crop.top);
if (!ret)
ret = mt9m032_update_timing(sensor, NULL);
@@ -208,6 +206,7 @@ static int mt9m032_update_geom_timing(struct mt9m032 
*sensor)
 
 static int update_formatter2(struct mt9m032 *sensor, bool streaming)
 {
+   struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
u16 reg_val =   MT9M032_FORMATTER2_DOUT_EN
  | 0x0070;  /* parts reserved! */
 /* possibly for changing to 14-bit mode */
@@ -215,11 +214,12 @@ static int update_formatter2(struct mt9m032 *sensor, bool 
streaming)
if (streaming)
reg_val |= MT9M032_FORMATTER2_PIXCLK_EN;   /* pixclock enable */
 
-   return mt9m032_write_reg(sensor, MT9M032_FORMATTER2, reg_val);
+   return mt9m032_write_reg(client, MT9M032_FORMATTER2, reg_val);
 }
 
 static int mt9m032_setup_pll(struct mt9m032 *sensor)
 {
+   struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
struct mt9m032_platform_data* pdata = sensor-pdata;
u16 reg_pll1;
unsigned int pre_div;
@@ -239,21 +239,21 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
reg_pll1 = ((pdata-pll_out_div - 1)  MT9M032_PLL_CONFIG1_OUTDIV_MASK)
   | pdata-pll_mul  MT9M032_PLL_CONFIG1_MUL_SHIFT;
 
-   ret = mt9m032_write_reg(sensor, MT9M032_PLL_CONFIG1, reg_pll1);
+   ret = mt9m032_write_reg(client, MT9M032_PLL_CONFIG1, reg_pll1);
if (!ret)
-   ret = mt9m032_write_reg(sensor,
+   ret = mt9m032_write_reg(client,
MT9P031_PLL_CONTROL,
MT9P031_PLL_CONTROL_PWRON | 
MT9P031_PLL_CONTROL_USEPLL);
 
if (!ret)
-   ret = mt9m032_write_reg(sensor, MT9M032_READ_MODE1, 

[PATCH v3 07/10] mt9m032: Put HFLIP and VFLIP controls in a cluster

2012-03-03 Thread Laurent Pinchart
HFLIP and VFLIP are often set together to rotate the image by 180°.
Putting the controls in a cluster makes sure they will always be applied
together, getting rid of a race condition that could result in one bad
frame.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/mt9m032.c |   43 +++-
 1 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index cfed53a..6bd4280 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -107,7 +107,12 @@ struct mt9m032 {
struct v4l2_subdev subdev;
struct media_pad pad;
struct mt9m032_platform_data *pdata;
+
struct v4l2_ctrl_handler ctrls;
+   struct {
+   struct v4l2_ctrl *hflip;
+   struct v4l2_ctrl *vflip;
+   };
 
bool streaming;
 
@@ -116,8 +121,6 @@ struct mt9m032 {
struct v4l2_mbus_framefmt format;   /* height and width always the 
same as in crop */
struct v4l2_rect crop;
struct v4l2_fract frame_interval;
-
-   struct v4l2_ctrl *hflip, *vflip;
 };
 
 #define to_mt9m032(sd) container_of(sd, struct mt9m032, subdev)
@@ -503,23 +506,13 @@ static int update_read_mode2(struct mt9m032 *sensor, bool 
vflip, bool hflip)
 {
struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
int reg_val = (!!vflip)  MT9M032_READ_MODE2_VFLIP_SHIFT
- | (!!hflip)  MT9M032_READ_MODE2_HFLIP_SHIFT
- | MT9M032_READ_MODE2_ROW_BLC
- | 0x0007;
+   | (!!hflip)  MT9M032_READ_MODE2_HFLIP_SHIFT
+   | MT9M032_READ_MODE2_ROW_BLC
+   | 0x0007;
 
return mt9m032_write_reg(client, MT9M032_READ_MODE2, reg_val);
 }
 
-static int mt9m032_set_hflip(struct mt9m032 *sensor, s32 val)
-{
-   return update_read_mode2(sensor, sensor-vflip-cur.val, val);
-}
-
-static int mt9m032_set_vflip(struct mt9m032 *sensor, s32 val)
-{
-   return update_read_mode2(sensor, val, sensor-hflip-cur.val);
-}
-
 static int mt9m032_set_exposure(struct mt9m032 *sensor, s32 val)
 {
struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
@@ -581,17 +574,17 @@ static int mt9m032_try_ctrl(struct v4l2_ctrl *ctrl)
 
 static int mt9m032_set_ctrl(struct v4l2_ctrl *ctrl)
 {
-   struct mt9m032 *sensor = container_of(ctrl-handler, struct mt9m032, 
ctrls);
+   struct mt9m032 *sensor =
+   container_of(ctrl-handler, struct mt9m032, ctrls);
 
switch (ctrl-id) {
case V4L2_CID_GAIN:
return mt9m032_set_gain(sensor, ctrl-val);
 
case V4L2_CID_HFLIP:
-   return mt9m032_set_hflip(sensor, ctrl-val);
-
case V4L2_CID_VFLIP:
-   return mt9m032_set_vflip(sensor, ctrl-val);
+   return update_read_mode2(sensor, sensor-vflip-val,
+sensor-hflip-val);
 
case V4L2_CID_EXPOSURE:
return mt9m032_set_exposure(sensor, ctrl-val);
@@ -700,10 +693,14 @@ static int mt9m032_probe(struct i2c_client *client,
v4l2_ctrl_new_std(sensor-ctrls, mt9m032_ctrl_ops,
  V4L2_CID_GAIN, 0, 127, 1, 64);
 
-   sensor-hflip = v4l2_ctrl_new_std(sensor-ctrls, mt9m032_ctrl_ops,
- V4L2_CID_HFLIP, 0, 1, 1, 0);
-   sensor-vflip = v4l2_ctrl_new_std(sensor-ctrls, mt9m032_ctrl_ops,
- V4L2_CID_VFLIP, 0, 1, 1, 0);
+   sensor-hflip = v4l2_ctrl_new_std(sensor-ctrls,
+ mt9m032_ctrl_ops,
+ V4L2_CID_HFLIP, 0, 1, 1, 0);
+   sensor-vflip = v4l2_ctrl_new_std(sensor-ctrls,
+ mt9m032_ctrl_ops,
+ V4L2_CID_VFLIP, 0, 1, 1, 0);
+   v4l2_ctrl_cluster(2, sensor-hflip);
+
v4l2_ctrl_new_std(sensor-ctrls, mt9m032_ctrl_ops,
  V4L2_CID_EXPOSURE, 0, 8000, 1, 1700);/* 1.7ms */
 
-- 
1.7.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 08/10] mt9m032: Remove unneeded register read

2012-03-03 Thread Laurent Pinchart
There's not need to read register MT9M032_READ_MODE1 when setting up the
PLL. Remove the read call.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/mt9m032.c |5 +
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index 6bd4280..4cde779 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -226,7 +226,7 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
struct mt9m032_platform_data* pdata = sensor-pdata;
u16 reg_pll1;
unsigned int pre_div;
-   int res, ret;
+   int ret;
 
/* TODO: also support other pre-div values */
if (pdata-pll_pre_div != 6) {
@@ -253,9 +253,6 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
/* more reserved, 
Continuous */
/* Master Mode */
if (!ret)
-   res = mt9m032_read_reg(client, MT9M032_READ_MODE1);
-
-   if (!ret)
ret = mt9m032_write_reg(client, MT9M032_FORMATTER1, 0x111e);
/* Set 14-bit mode, select 7 divider */
 
-- 
1.7.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 10/10] mt9m032: Use generic PLL setup code

2012-03-03 Thread Laurent Pinchart
Compute the PLL parameters at runtime using the generic Aptina PLL
helper.

Remove the PLL parameters from platform data and pass the external clock
and desired internal clock frequencies instead.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/video/Kconfig   |1 +
 drivers/media/video/mt9m032.c |   56 +++--
 include/media/mt9m032.h   |4 +--
 3 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 410baf2..2b3f4b1 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -949,6 +949,7 @@ config SOC_CAMERA_MT9M001
 config VIDEO_MT9M032
tristate MT9M032 camera sensor support
depends on I2C  VIDEO_V4L2
+   select VIDEO_APTINA_PLL
help
  This driver supports MT9M032 cameras from Micron, monochrome
  models only.
diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index 4cde779..da69e12 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -35,6 +35,8 @@
 #include media/v4l2-device.h
 #include media/v4l2-subdev.h
 
+#include aptina-pll.h
+
 #define MT9M032_CHIP_VERSION   0x00
 #define MT9M032_CHIP_VERSION_VALUE 0x1402
 #define MT9M032_ROW_START  0x01
@@ -61,6 +63,7 @@
 #define MT9M032_GAIN_BLUE  0x2c
 #define MT9M032_GAIN_RED   0x2d
 #define MT9M032_GAIN_GREEN20x2e
+
 /* write only */
 #define MT9M032_GAIN_ALL   0x35
 #define MT9M032_GAIN_DIGITAL_MASK  0x7f
@@ -83,6 +86,8 @@
 #define MT9P031_PLL_CONTROL_PWROFF 0x0050
 #define MT9P031_PLL_CONTROL_PWRON  0x0051
 #define MT9P031_PLL_CONTROL_USEPLL 0x0052
+#define MT9P031_PLL_CONFIG20x11
+#define MT9P031_PLL_CONFIG2_P1_DIV_MASK0x1f
 
 /*
  * width and height include active boundry and black parts
@@ -222,32 +227,45 @@ static int update_formatter2(struct mt9m032 *sensor, bool 
streaming)
 
 static int mt9m032_setup_pll(struct mt9m032 *sensor)
 {
+   static const struct aptina_pll_limits limits = {
+   .ext_clock_min = 800,
+   .ext_clock_max = 1650,
+   .int_clock_min = 200,
+   .int_clock_max = 2400,
+   .out_clock_min = 32200,
+   .out_clock_max = 69300,
+   .pix_clock_max = 9900,
+   .n_min = 1,
+   .n_max = 64,
+   .m_min = 16,
+   .m_max = 255,
+   .p1_min = 1,
+   .p1_max = 128,
+   };
+
struct i2c_client *client = v4l2_get_subdevdata(sensor-subdev);
-   struct mt9m032_platform_data* pdata = sensor-pdata;
-   u16 reg_pll1;
-   unsigned int pre_div;
+   struct mt9m032_platform_data *pdata = sensor-pdata;
+   struct aptina_pll pll;
int ret;
 
-   /* TODO: also support other pre-div values */
-   if (pdata-pll_pre_div != 6) {
-   dev_warn(to_dev(sensor),
-   Unsupported PLL pre-divisor value %u, using default 
6\n,
-   pdata-pll_pre_div);
-   }
-   pre_div = 6;
+   pll.ext_clock = pdata-ext_clock;
+   pll.pix_clock = pdata-pix_clock;
 
-   sensor-pix_clock = pdata-ext_clock * pdata-pll_mul /
-   (pre_div * pdata-pll_out_div);
+   ret = aptina_pll_configure(client-dev, pll, limits);
+   if (ret  0)
+   return ret;
 
-   reg_pll1 = ((pdata-pll_out_div - 1)  MT9M032_PLL_CONFIG1_OUTDIV_MASK)
-  | pdata-pll_mul  MT9M032_PLL_CONFIG1_MUL_SHIFT;
+   sensor-pix_clock = pll.pix_clock;
 
-   ret = mt9m032_write_reg(client, MT9M032_PLL_CONFIG1, reg_pll1);
+   ret = mt9m032_write_reg(client, MT9M032_PLL_CONFIG1,
+   (pll.m  MT9M032_PLL_CONFIG1_MUL_SHIFT)
+   | (pll.p1 - 1));
if (!ret)
-   ret = mt9m032_write_reg(client,
-   MT9P031_PLL_CONTROL,
-   MT9P031_PLL_CONTROL_PWRON | 
MT9P031_PLL_CONTROL_USEPLL);
-
+   ret = mt9m032_write_reg(client, MT9P031_PLL_CONFIG2, pll.n - 1);
+   if (!ret)
+   ret = mt9m032_write_reg(client, MT9P031_PLL_CONTROL,
+   MT9P031_PLL_CONTROL_PWRON |
+   MT9P031_PLL_CONTROL_USEPLL);
if (!ret)
ret = mt9m032_write_reg(client, MT9M032_READ_MODE1, 0x8006);
/* more reserved, 
Continuous */
diff --git a/include/media/mt9m032.h b/include/media/mt9m032.h
index 94cefc5..804e0a5 100644
--- a/include/media/mt9m032.h
+++ b/include/media/mt9m032.h
@@ -29,9 +29,7 @@
 
 struct mt9m032_platform_data {

Re: [PATCH v3 09/10] v4l: Aptina-style sensor PLL support

2012-03-03 Thread Andy Walls
On Sat, 2012-03-03 at 16:28 +0100, Laurent Pinchart wrote:
 Add a generic helper function to compute PLL parameters for PLL found in
 several Aptina sensors.
 
 Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
 ---
  drivers/media/video/Kconfig  |3 +
  drivers/media/video/Makefile |4 +
  drivers/media/video/aptina-pll.c |  175 
 ++
  drivers/media/video/aptina-pll.h |   55 
  4 files changed, 237 insertions(+), 0 deletions(-)
  create mode 100644 drivers/media/video/aptina-pll.c
  create mode 100644 drivers/media/video/aptina-pll.h
 
 diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
 index 80acb78..410baf2 100644
 --- a/drivers/media/video/Kconfig
 +++ b/drivers/media/video/Kconfig
 @@ -459,6 +459,9 @@ config VIDEO_AK881X
  
  comment Camera sensor devices
  
 +config VIDEO_APTINA_PLL
 + tristate
 +
  config VIDEO_OV7670
   tristate OmniVision OV7670 sensor support
   depends on I2C  VIDEO_V4L2
 diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
 index 9b19533..8e037e9 100644
 --- a/drivers/media/video/Makefile
 +++ b/drivers/media/video/Makefile
 @@ -22,6 +22,10 @@ endif
  
  obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
  
 +# Helper modules
 +
 +obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
 +
  # All i2c modules must come first:
  
  obj-$(CONFIG_VIDEO_TUNER) += tuner.o
 diff --git a/drivers/media/video/aptina-pll.c 
 b/drivers/media/video/aptina-pll.c
 new file mode 100644
 index 000..55e4a40
 --- /dev/null
 +++ b/drivers/media/video/aptina-pll.c
 @@ -0,0 +1,175 @@
 +/*
 + * Aptina Sensor PLL Configuration
 + *
 + * Copyright (C) 2012 Laurent Pinchart laurent.pinch...@ideasonboard.com
 + *
 + * 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.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 + * 02110-1301 USA
 + */
 +
 +#include linux/device.h
 +#include linux/gcd.h
 +#include linux/kernel.h
 +#include linux/lcm.h
 +#include linux/module.h
 +
 +#include aptina-pll.h
 +
 +int aptina_pll_configure(struct device *dev, struct aptina_pll *pll,
 +  const struct aptina_pll_limits *limits)
 +{
 + unsigned int mf_min;
 + unsigned int mf_max;
 + unsigned int p1_min;
 + unsigned int p1_max;
 + unsigned int p1;
 + unsigned int div;
 +
 + if (pll-ext_clock  limits-ext_clock_min ||
 + pll-ext_clock  limits-ext_clock_max) {
 + dev_err(dev, pll: invalid external clock frequency.\n);
 + return -EINVAL;
 + }
 +
 + if (pll-pix_clock  limits-pix_clock_max) {
 + dev_err(dev, pll: invalid pixel clock frequency.\n);
 + return -EINVAL;
 + }
 +
 + /* Compute the multiplier M and combined N*P1 divisor. */
 + div = gcd(pll-pix_clock, pll-ext_clock);
 + pll-m = pll-pix_clock / div;
 + div = pll-ext_clock / div;
 +
 + /* We now have the smallest M and N*P1 values that will result in the
 +  * desired pixel clock frequency, but they might be out of the valid
 +  * range. Compute the factor by which we should multiply them given the
 +  * following constraints:
 +  *
 +  * - minimum/maximum multiplier
 +  * - minimum/maximum multiplier output clock frequency assuming the
 +  *   minimum/maximum N value
 +  * - minimum/maximum combined N*P1 divisor
 +  */
 + mf_min = DIV_ROUND_UP(limits-m_min, pll-m);
 + mf_min = max(mf_min, limits-out_clock_min /
 +  (pll-ext_clock / limits-n_min * pll-m));
 + mf_min = max(mf_min, limits-n_min * limits-p1_min / div);
 + mf_max = limits-m_max / pll-m;
 + mf_max = min(mf_max, limits-out_clock_max /
 + (pll-ext_clock / limits-n_max * pll-m));
 + mf_max = min(mf_max, DIV_ROUND_UP(limits-n_max * limits-p1_max, div));
 +
 + dev_dbg(dev, pll: mf min %u max %u\n, mf_min, mf_max);
 + if (mf_min  mf_max) {
 + dev_err(dev, pll: no valid combined N*P1 divisor.\n);
 + return -EINVAL;
 + }
 +
 + /*
 +  * We're looking for the highest acceptable P1 value 

Why the *highest* acceptable post-divide (P1) value?

 for which a
 +  * multiplier factor MF exists that fulfills the following conditions:
 +  *
 +  * 1. p1 is in the [p1_min, p1_max] range given by the limits and is
 +  *even
 +  * 2. mf is in the [mf_min, mf_max] range computed 

Re: [PATCH v3 09/10] v4l: Aptina-style sensor PLL support

2012-03-03 Thread Andy Walls
On Sat, 2012-03-03 at 12:35 -0500, Andy Walls wrote:
 On Sat, 2012-03-03 at 16:28 +0100, Laurent Pinchart wrote:
  Add a generic helper function to compute PLL parameters for PLL found in
  several Aptina sensors.
  
  Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
   drivers/media/video/Kconfig  |3 +
   drivers/media/video/Makefile |4 +
   drivers/media/video/aptina-pll.c |  175 
  ++
   drivers/media/video/aptina-pll.h |   55 
   4 files changed, 237 insertions(+), 0 deletions(-)
   create mode 100644 drivers/media/video/aptina-pll.c
   create mode 100644 drivers/media/video/aptina-pll.h
  
  diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
  index 80acb78..410baf2 100644
  --- a/drivers/media/video/Kconfig
  +++ b/drivers/media/video/Kconfig
  @@ -459,6 +459,9 @@ config VIDEO_AK881X
   
   comment Camera sensor devices
   
  +config VIDEO_APTINA_PLL
  +   tristate
  +
   config VIDEO_OV7670
  tristate OmniVision OV7670 sensor support
  depends on I2C  VIDEO_V4L2
  diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
  index 9b19533..8e037e9 100644
  --- a/drivers/media/video/Makefile
  +++ b/drivers/media/video/Makefile
  @@ -22,6 +22,10 @@ endif
   
   obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
   
  +# Helper modules
  +
  +obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
  +
   # All i2c modules must come first:
   
   obj-$(CONFIG_VIDEO_TUNER) += tuner.o
  diff --git a/drivers/media/video/aptina-pll.c 
  b/drivers/media/video/aptina-pll.c
  new file mode 100644
  index 000..55e4a40
  --- /dev/null
  +++ b/drivers/media/video/aptina-pll.c
  @@ -0,0 +1,175 @@
  +/*
  + * Aptina Sensor PLL Configuration
  + *
  + * Copyright (C) 2012 Laurent Pinchart laurent.pinch...@ideasonboard.com
  + *
  + * 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.
  + *
  + * You should have received a copy of the GNU General Public License
  + * along with this program; if not, write to the Free Software
  + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA
  + */
  +
  +#include linux/device.h
  +#include linux/gcd.h
  +#include linux/kernel.h
  +#include linux/lcm.h
  +#include linux/module.h
  +
  +#include aptina-pll.h
  +
  +int aptina_pll_configure(struct device *dev, struct aptina_pll *pll,
  +const struct aptina_pll_limits *limits)
  +{
  +   unsigned int mf_min;
  +   unsigned int mf_max;
  +   unsigned int p1_min;
  +   unsigned int p1_max;
  +   unsigned int p1;
  +   unsigned int div;
  +
  +   if (pll-ext_clock  limits-ext_clock_min ||
  +   pll-ext_clock  limits-ext_clock_max) {
  +   dev_err(dev, pll: invalid external clock frequency.\n);
  +   return -EINVAL;
  +   }
  +
  +   if (pll-pix_clock  limits-pix_clock_max) {
  +   dev_err(dev, pll: invalid pixel clock frequency.\n);
  +   return -EINVAL;
  +   }
  +
  +   /* Compute the multiplier M and combined N*P1 divisor. */
  +   div = gcd(pll-pix_clock, pll-ext_clock);
  +   pll-m = pll-pix_clock / div;
  +   div = pll-ext_clock / div;
  +
  +   /* We now have the smallest M and N*P1 values that will result in the
  +* desired pixel clock frequency, but they might be out of the valid
  +* range. Compute the factor by which we should multiply them given the
  +* following constraints:
  +*
  +* - minimum/maximum multiplier
  +* - minimum/maximum multiplier output clock frequency assuming the
  +*   minimum/maximum N value
  +* - minimum/maximum combined N*P1 divisor
  +*/
  +   mf_min = DIV_ROUND_UP(limits-m_min, pll-m);
  +   mf_min = max(mf_min, limits-out_clock_min /
  +(pll-ext_clock / limits-n_min * pll-m));
  +   mf_min = max(mf_min, limits-n_min * limits-p1_min / div);
  +   mf_max = limits-m_max / pll-m;
  +   mf_max = min(mf_max, limits-out_clock_max /
  +   (pll-ext_clock / limits-n_max * pll-m));
  +   mf_max = min(mf_max, DIV_ROUND_UP(limits-n_max * limits-p1_max, div));
  +
  +   dev_dbg(dev, pll: mf min %u max %u\n, mf_min, mf_max);
  +   if (mf_min  mf_max) {
  +   dev_err(dev, pll: no valid combined N*P1 divisor.\n);
  +   return -EINVAL;
  +   }
  +
  +   /*
  +* We're looking for the highest acceptable P1 value 
 
 Why the *highest* acceptable post-divide (P1) value?
 
  for which a
  +* multiplier factor MF exists that fulfills the following conditions:
  +*
  +* 1. p1 is in the [p1_min, p1_max] range given by the 

cron job: media_tree daily build: WARNINGS

2012-03-03 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:Sat Mar  3 19:00:19 CET 2012
git hash:e8ca6d20a65d9d94693a0ed99b12d95b882dc859
gcc version:  i686-linux-gcc (GCC) 4.6.2
host hardware:x86_64
host os:  3.1-2.slh.1-amd64

linux-git-arm-eabi-enoxys: WARNINGS
linux-git-arm-eabi-omap: WARNINGS
linux-git-armv5-ixp: WARNINGS
linux-git-i686: WARNINGS
linux-git-m32r: WARNINGS
linux-git-mips: WARNINGS
linux-git-powerpc64: WARNINGS
linux-git-x86_64: WARNINGS
linux-2.6.31.12-i686: WARNINGS
linux-2.6.32.6-i686: WARNINGS
linux-2.6.33-i686: WARNINGS
linux-2.6.34-i686: WARNINGS
linux-2.6.35.3-i686: WARNINGS
linux-2.6.36-i686: WARNINGS
linux-2.6.37-i686: WARNINGS
linux-2.6.38.2-i686: WARNINGS
linux-2.6.39.1-i686: WARNINGS
linux-3.0-i686: WARNINGS
linux-3.1-i686: WARNINGS
linux-3.2.1-i686: WARNINGS
linux-3.3-rc1-i686: WARNINGS
linux-2.6.31.12-x86_64: WARNINGS
linux-2.6.32.6-x86_64: WARNINGS
linux-2.6.33-x86_64: WARNINGS
linux-2.6.34-x86_64: WARNINGS
linux-2.6.35.3-x86_64: WARNINGS
linux-2.6.36-x86_64: WARNINGS
linux-2.6.37-x86_64: WARNINGS
linux-2.6.38.2-x86_64: WARNINGS
linux-2.6.39.1-x86_64: WARNINGS
linux-3.0-x86_64: WARNINGS
linux-3.1-x86_64: WARNINGS
linux-3.2.1-x86_64: WARNINGS
linux-3.3-rc1-x86_64: WARNINGS
apps: WARNINGS
spec-git: WARNINGS
sparse: ERRORS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Saturday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Saturday.tar.bz2

The V4L-DVB specification from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/media.html
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] media: fimc-lite: Add new driver for camera interface

2012-03-03 Thread Sylwester Nawrocki
Hi Sungchun,

On 02/15/2012 07:05 AM, Sungchun Kang wrote:
 This patch adds support fimc-lite device which is a new device
 for camera interface on EXYNOS5 SoCs.

It's also available in the Exynos4 SoC and I was planning adding
it at the s5p-fimc driver eventually. It may take some time though
since it is not described in the datasheets I have.

 This device supports the followings as key feature.
   1) Multiple input
- ITU-R BT 601 mode
- MIPI(CSI) mode
   2) Multiple output
- DMA mode
- Direct FIFO mode

 Signed-off-by: Sungchun Kangsungchun.k...@samsung.com

 NOTE : This patch is based on
 media: media-dev: Add media devices for EXYNOS5.
 ---
   drivers/media/video/Kconfig|3 +-
   drivers/media/video/Makefile   |2 +-
   drivers/media/video/exynos/Kconfig |   20 +
   drivers/media/video/exynos/Makefile|4 +
   drivers/media/video/exynos/fimc-lite/Kconfig   |   22 +
   drivers/media/video/exynos/fimc-lite/Makefile  |6 +
   .../media/video/exynos/fimc-lite/fimc-lite-core.c  | 1921 
 
   .../media/video/exynos/fimc-lite/fimc-lite-core.h  |  310 
   .../media/video/exynos/fimc-lite/fimc-lite-reg.c   |  332 
   .../media/video/exynos/fimc-lite/fimc-lite-reg.h   |  135 ++
   include/media/exynos_camera.h  |   59 +
   include/media/exynos_flite.h   |   39 +
   12 files changed, 2851 insertions(+), 2 deletions(-)
   create mode 100644 drivers/media/video/exynos/Kconfig
   create mode 100644 drivers/media/video/exynos/Makefile
   create mode 100644 drivers/media/video/exynos/fimc-lite/Kconfig
   create mode 100644 drivers/media/video/exynos/fimc-lite/Makefile
   create mode 100644 drivers/media/video/exynos/fimc-lite/fimc-lite-core.c
   create mode 100644 drivers/media/video/exynos/fimc-lite/fimc-lite-core.h
   create mode 100644 drivers/media/video/exynos/fimc-lite/fimc-lite-reg.c
   create mode 100644 drivers/media/video/exynos/fimc-lite/fimc-lite-reg.h
   create mode 100644 include/media/exynos_camera.h
   create mode 100644 include/media/exynos_flite.h

...
 +if VIDEO_EXYNOS_FIMC_LITE  VIDEOBUF2_CMA_PHYS
 +comment Reserved memory configurations
 +config VIDEO_SAMSUNG_MEMSIZE_FLITE0
 + int Memory size in kbytes for FLITE0
 + default 10240
 +
 +config VIDEO_SAMSUNG_MEMSIZE_FLITE1
 + int Memory size in kbytes for FLITE1
 + default 10240
 +endif

There is no VIDEOBUF2_CMA_PHYS allocator in the mainline and there 
should be no need for it. CMA should be used through the dma mapping
framework, see https://lkml.org/lkml/2012/2/22/309.

 diff --git a/drivers/media/video/exynos/fimc-lite/Makefile 
 b/drivers/media/video/exynos/fimc-lite/Makefile
 new file mode 100644
 index 000..431d199
 --- /dev/null
 +++ b/drivers/media/video/exynos/fimc-lite/Makefile
 @@ -0,0 +1,6 @@
 +ifeq ($(CONFIG_ARCH_EXYNOS5),y)
 +fimc-lite-objs := fimc-lite-core.o fimc-lite-reg.o
 +else
 +fimc-lite-objs := fimc-lite-core.o fimc-lite-reg.o
 +endif
 +obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += fimc-lite.o
 diff --git a/drivers/media/video/exynos/fimc-lite/fimc-lite-core.c 
 b/drivers/media/video/exynos/fimc-lite/fimc-lite-core.c
 new file mode 100644
 index 000..9bb1c88
 --- /dev/null
 +++ b/drivers/media/video/exynos/fimc-lite/fimc-lite-core.c
 @@ -0,0 +1,1921 @@
 +/*
 + * Register interface file for Samsung Camera Interface (FIMC-Lite) driver
 + *
 + * Copyright (c) 2011 Samsung Electronics

2011 - 2012 ?

 + *
 + * 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.
 +*/
 +
 +#includelinux/module.h
 +#includelinux/kernel.h
 +#includelinux/errno.h
 +#includelinux/interrupt.h
 +#includelinux/device.h
 +#includelinux/platform_device.h
 +#includelinux/slab.h
 +#includelinux/i2c.h
 +#includemedia/exynos_mc.h
 +#includemedia/videobuf2-dma-contig.h
 +
 +#include fimc-lite-core.h
 +
 +#define MODULE_NAME  exynos-fimc-lite
 +#define DEFAULT_FLITE_SINK_WIDTH 800
 +#define DEFAULT_FLITE_SINK_HEIGHT480
 +
 +static struct flite_fmt flite_formats[] = {
 + {
 + .name   = YUV422 8-bit 1 plane(UYVY),
 + .pixelformat= V4L2_PIX_FMT_UYVY,
 + .depth  = { 16 },
 + .code   = V4L2_MBUS_FMT_UYVY8_2X8,
 + .fmt_reg= FLITE_REG_CIGCTRL_YUV422_1P,
 + .is_yuv = 1,
 + }, {
 + .name   = YUV422 8-bit 1 plane(VYUY),
 + .pixelformat= V4L2_PIX_FMT_VYUY,
 + .depth  = { 16 },
 + .code   = V4L2_MBUS_FMT_VYUY8_2X8,
 + .fmt_reg= FLITE_REG_CIGCTRL_YUV422_1P,
 + .is_yuv = 1,
 + }, {
 + .name   = YUV422 8-bit 1 plane(YUYV),
 + .pixelformat= 

Re: [PATCH v3 09/10] v4l: Aptina-style sensor PLL support

2012-03-03 Thread Sakari Ailus
Hi Laurent,

Thanks for the patch!

On Sat, Mar 03, 2012 at 04:28:14PM +0100, Laurent Pinchart wrote:
 Add a generic helper function to compute PLL parameters for PLL found in
 several Aptina sensors.
 
 Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
 ---
  drivers/media/video/Kconfig  |3 +
  drivers/media/video/Makefile |4 +
  drivers/media/video/aptina-pll.c |  175 
 ++
  drivers/media/video/aptina-pll.h |   55 
  4 files changed, 237 insertions(+), 0 deletions(-)
  create mode 100644 drivers/media/video/aptina-pll.c
  create mode 100644 drivers/media/video/aptina-pll.h
 
 diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
 index 80acb78..410baf2 100644
 --- a/drivers/media/video/Kconfig
 +++ b/drivers/media/video/Kconfig
 @@ -459,6 +459,9 @@ config VIDEO_AK881X
  
  comment Camera sensor devices
  
 +config VIDEO_APTINA_PLL
 + tristate
 +

That's a much better place for this.

  config VIDEO_OV7670
   tristate OmniVision OV7670 sensor support
   depends on I2C  VIDEO_V4L2
 diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
 index 9b19533..8e037e9 100644
 --- a/drivers/media/video/Makefile
 +++ b/drivers/media/video/Makefile
 @@ -22,6 +22,10 @@ endif
  
  obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
  
 +# Helper modules
 +
 +obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
 +
  # All i2c modules must come first:
  
  obj-$(CONFIG_VIDEO_TUNER) += tuner.o
 diff --git a/drivers/media/video/aptina-pll.c 
 b/drivers/media/video/aptina-pll.c
 new file mode 100644
 index 000..55e4a40
 --- /dev/null
 +++ b/drivers/media/video/aptina-pll.c
 @@ -0,0 +1,175 @@
 +/*
 + * Aptina Sensor PLL Configuration
 + *
 + * Copyright (C) 2012 Laurent Pinchart laurent.pinch...@ideasonboard.com
 + *
 + * 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.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 + * 02110-1301 USA
 + */
 +
 +#include linux/device.h
 +#include linux/gcd.h
 +#include linux/kernel.h
 +#include linux/lcm.h
 +#include linux/module.h
 +
 +#include aptina-pll.h
 +
 +int aptina_pll_configure(struct device *dev, struct aptina_pll *pll,
 +  const struct aptina_pll_limits *limits)

I've done the same to the SMIA++ PLL: it can be used separately from the
driver now; it'll be part of the next patchset.

Do you think it could make sense to swap pll and limits parameters?

I call the function smiapp_pll_calculate().

 +{
 + unsigned int mf_min;
 + unsigned int mf_max;
 + unsigned int p1_min;
 + unsigned int p1_max;
 + unsigned int p1;
 + unsigned int div;
 +
 + if (pll-ext_clock  limits-ext_clock_min ||
 + pll-ext_clock  limits-ext_clock_max) {
 + dev_err(dev, pll: invalid external clock frequency.\n);
 + return -EINVAL;
 + }
 +
 + if (pll-pix_clock  limits-pix_clock_max) {
 + dev_err(dev, pll: invalid pixel clock frequency.\n);
 + return -EINVAL;
 + }

You could check that pix_clock isn't zero.

 + /* Compute the multiplier M and combined N*P1 divisor. */
 + div = gcd(pll-pix_clock, pll-ext_clock);
 + pll-m = pll-pix_clock / div;
 + div = pll-ext_clock / div;
 +
 + /* We now have the smallest M and N*P1 values that will result in the
 +  * desired pixel clock frequency, but they might be out of the valid
 +  * range. Compute the factor by which we should multiply them given the
 +  * following constraints:
 +  *
 +  * - minimum/maximum multiplier
 +  * - minimum/maximum multiplier output clock frequency assuming the
 +  *   minimum/maximum N value
 +  * - minimum/maximum combined N*P1 divisor
 +  */
 + mf_min = DIV_ROUND_UP(limits-m_min, pll-m);
 + mf_min = max(mf_min, limits-out_clock_min /
 +  (pll-ext_clock / limits-n_min * pll-m));
 + mf_min = max(mf_min, limits-n_min * limits-p1_min / div);
 + mf_max = limits-m_max / pll-m;
 + mf_max = min(mf_max, limits-out_clock_max /
 + (pll-ext_clock / limits-n_max * pll-m));
 + mf_max = min(mf_max, DIV_ROUND_UP(limits-n_max * limits-p1_max, div));
 +
 + dev_dbg(dev, pll: mf min %u max %u\n, mf_min, mf_max);
 + if (mf_min  mf_max) {
 + dev_err(dev, pll: no valid combined N*P1 divisor.\n);
 + return -EINVAL;
 + }
 +
 + /*
 +  * 

Re: My Microdia (SN9C201) webcam doesn't work properly in Linux anymore

2012-03-03 Thread Xavion
Hi Hans

Thanks for letting me know that this problem will be fixed in Linux
v3.3.  It could be several weeks before my distribution releases that
kernel.  Dropping back to Linux v3.1 isn't an option, as my NVIDIA
driver requires Linux v3.2.  Can the fix for this problem also be
applied to Linux v3.2.x manually?  If so, please email me the
corresponding patch file and I'll test it here.
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: My Microdia (SN9C201) webcam doesn't work properly in Linux anymore

2012-03-03 Thread Jean-Francois Moine
On Sun, 4 Mar 2012 11:25:19 +1100
Xavion xavio...@gmail.com wrote:

 Thanks for letting me know that this problem will be fixed in Linux
 v3.3.  It could be several weeks before my distribution releases that
 kernel.  Dropping back to Linux v3.1 isn't an option, as my NVIDIA
 driver requires Linux v3.2.  Can the fix for this problem also be
 applied to Linux v3.2.x manually?  If so, please email me the
 corresponding patch file and I'll test it here.

Hi,

You may take the gspca test version from my site: it is smaller.

-- 
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html