[PATCH v6 1/2] Add driver for Aptina (Micron) mt9p031 sensor.

2011-06-01 Thread Javier Martin
Clock frequency of 57MHz used in previous version was wrong since
when VDD_IO is 1.8V it can only support 48MHz.

Two new platform flags have been added:

- vdd_io: indicates whether the chip is powered with 1.8 or 2.8 VDD_IO.
So that it can use the maximum allowed frequency.
- version: monochrome and color versions of the chip have exactly
the same ID, so the only way to select one of them is through
platform data.

Internal PLL is now used to generate PIXCLK depending on VDD_IO.

Signed-off-by: Javier Martin 
---
 drivers/media/video/Kconfig   |7 +
 drivers/media/video/Makefile  |1 +
 drivers/media/video/mt9p031.c |  763 +
 include/media/mt9p031.h   |   23 ++
 4 files changed, 794 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/mt9p031.c
 create mode 100644 include/media/mt9p031.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 00f51dd..cb87e35 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -329,6 +329,13 @@ config VIDEO_OV7670
  OV7670 VGA camera.  It currently only works with the M88ALP01
  controller.
 
+config VIDEO_MT9P031
+   tristate "Aptina MT9P031 support"
+   depends on I2C && VIDEO_V4L2
+   ---help---
+This is a Video4Linux2 sensor-level driver for the Aptina
+(Micron) mt9p031 5 Mpixel camera.
+
 config VIDEO_MT9V011
tristate "Micron mt9v011 sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index ace5d8b..912b29b 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -65,6 +65,7 @@ obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
 obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
+obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o
 obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o
 obj-$(CONFIG_VIDEO_SR030PC30)  += sr030pc30.o
 obj-$(CONFIG_VIDEO_NOON010PC30)+= noon010pc30.o
diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c
new file mode 100644
index 000..cd830b1
--- /dev/null
+++ b/drivers/media/video/mt9p031.c
@@ -0,0 +1,763 @@
+/*
+ * Driver for MT9P031 CMOS Image Sensor from Aptina
+ *
+ * Copyright (C) 2011, Javier Martin 
+ *
+ * Copyright (C) 2011, Guennadi Liakhovetski 
+ *
+ * Based on the MT9V032 driver and Bastian Hecht's code.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define MT9P031_EXTCLK_FREQ2000
+
+#define MT9P031_CHIP_VERSION   0x00
+#defineMT9P031_CHIP_VERSION_VALUE  0x1801
+#define MT9P031_ROW_START  0x01
+#defineMT9P031_ROW_START_MIN   1
+#defineMT9P031_ROW_START_MAX   2004
+#defineMT9P031_ROW_START_DEF   54
+#define MT9P031_COLUMN_START   0x02
+#defineMT9P031_COLUMN_START_MIN1
+#defineMT9P031_COLUMN_START_MAX2750
+#defineMT9P031_COLUMN_START_DEF16
+#define MT9P031_WINDOW_HEIGHT  0x03
+#defineMT9P031_WINDOW_HEIGHT_MIN   2
+#defineMT9P031_WINDOW_HEIGHT_MAX   2003
+#defineMT9P031_WINDOW_HEIGHT_DEF   2003
+#define MT9P031_WINDOW_WIDTH   0x04
+#defineMT9P031_WINDOW_WIDTH_MIN18
+#defineMT9P031_WINDOW_WIDTH_MAX2751
+#defineMT9P031_WINDOW_WIDTH_DEF2751
+#define MT9P031_H_BLANKING 0x05
+#defineMT9P031_H_BLANKING_VALUE0
+#define MT9P031_V_BLANKING 0x06
+#defineMT9P031_V_BLANKING_VALUE25
+#define MT9P031_OUTPUT_CONTROL 0x07
+#defineMT9P031_OUTPUT_CONTROL_CEN  2
+#defineMT9P031_OUTPUT_CONTROL_SYN  1
+#define MT9P031_SHUTTER_WIDTH_UPPER0x08
+#define MT9P031_SHUTTER_WIDTH  0x09
+#defineMT9P031_PLL_CONTROL 0x10
+#defineMT9P031_PLL_CONTROL_PWROFF  0x0050
+#defineMT9P031_PLL_CONTROL_PWRON   0x0051
+#defineMT9P031_PLL_CONTROL_USEPLL  0x0052
+#defineMT9P031_PLL_CONFIG_10x11
+#defineMT9P031_PLL_CONFIG_1_M_48MHZ0x5000
+#defineMT9P031_PLL_CONFIG_1_N_48MHZ0x05
+#defineMT9P031_PLL_CONFIG_1_M_96MHZ0x3600
+#defineMT9P031_PLL_CONFIG_1_N_96MHZ0x05
+#defineMT9P031_PLL_CONFIG

Re: [PATCH v6 1/2] Add driver for Aptina (Micron) mt9p031 sensor.

2011-06-02 Thread Guennadi Liakhovetski
No technical review this time. Relying fully on Laurent and others to take 
care of that, just a couple of cosmetic points, which even checkpatch.pl 
failed to warn about:(

On Wed, 1 Jun 2011, Javier Martin wrote:

> Clock frequency of 57MHz used in previous version was wrong since
> when VDD_IO is 1.8V it can only support 48MHz.
> 
> Two new platform flags have been added:
> 
> - vdd_io: indicates whether the chip is powered with 1.8 or 2.8 VDD_IO.
> So that it can use the maximum allowed frequency.
> - version: monochrome and color versions of the chip have exactly
> the same ID, so the only way to select one of them is through
> platform data.
> 
> Internal PLL is now used to generate PIXCLK depending on VDD_IO.
> 
> Signed-off-by: Javier Martin 
> ---
>  drivers/media/video/Kconfig   |7 +
>  drivers/media/video/Makefile  |1 +
>  drivers/media/video/mt9p031.c |  763 
> +
>  include/media/mt9p031.h   |   23 ++
>  4 files changed, 794 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/media/video/mt9p031.c
>  create mode 100644 include/media/mt9p031.h
> 
> diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
> index 00f51dd..cb87e35 100644
> --- a/drivers/media/video/Kconfig
> +++ b/drivers/media/video/Kconfig
> @@ -329,6 +329,13 @@ config VIDEO_OV7670
> OV7670 VGA camera.  It currently only works with the M88ALP01
> controller.
>  
> +config VIDEO_MT9P031
> +   tristate "Aptina MT9P031 support"
> +   depends on I2C && VIDEO_V4L2
> +   ---help---
> +This is a Video4Linux2 sensor-level driver for the Aptina
> +(Micron) mt9p031 5 Mpixel camera.
> +

Please, use TABs, not spaces

>  config VIDEO_MT9V011
>   tristate "Micron mt9v011 sensor support"
>   depends on I2C && VIDEO_V4L2
> diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
> index ace5d8b..912b29b 100644
> --- a/drivers/media/video/Makefile
> +++ b/drivers/media/video/Makefile
> @@ -65,6 +65,7 @@ obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
>  obj-$(CONFIG_VIDEO_OV7670)   += ov7670.o
>  obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
>  obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
> +obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o
>  obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o
>  obj-$(CONFIG_VIDEO_SR030PC30)+= sr030pc30.o
>  obj-$(CONFIG_VIDEO_NOON010PC30)  += noon010pc30.o
> diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c
> new file mode 100644
> index 000..cd830b1
> --- /dev/null
> +++ b/drivers/media/video/mt9p031.c
> @@ -0,0 +1,763 @@
> +/*
> + * Driver for MT9P031 CMOS Image Sensor from Aptina
> + *
> + * Copyright (C) 2011, Javier Martin 
> + *
> + * Copyright (C) 2011, Guennadi Liakhovetski 
> + *
> + * Based on the MT9V032 driver and Bastian Hecht's code.
> + *
> + * 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.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MT9P031_EXTCLK_FREQ  2000
> +
> +#define MT9P031_CHIP_VERSION 0x00
> +#define  MT9P031_CHIP_VERSION_VALUE  0x1801
> +#define MT9P031_ROW_START0x01
> +#define  MT9P031_ROW_START_MIN   1
> +#define  MT9P031_ROW_START_MAX   2004
> +#define  MT9P031_ROW_START_DEF   54
> +#define MT9P031_COLUMN_START 0x02
> +#define  MT9P031_COLUMN_START_MIN1
> +#define  MT9P031_COLUMN_START_MAX2750
> +#define  MT9P031_COLUMN_START_DEF16
> +#define MT9P031_WINDOW_HEIGHT0x03
> +#define  MT9P031_WINDOW_HEIGHT_MIN   2
> +#define  MT9P031_WINDOW_HEIGHT_MAX   2003
> +#define  MT9P031_WINDOW_HEIGHT_DEF   2003
> +#define MT9P031_WINDOW_WIDTH 0x04
> +#define  MT9P031_WINDOW_WIDTH_MIN18
> +#define  MT9P031_WINDOW_WIDTH_MAX2751
> +#define  MT9P031_WINDOW_WIDTH_DEF2751
> +#define MT9P031_H_BLANKING   0x05
> +#define  MT9P031_H_BLANKING_VALUE0
> +#define MT9P031_V_BLANKING   0x06
> +#define  MT9P031_V_BLANKING_VALUE25
> +#define MT9P031_OUTPUT_CONTROL   0x07
> +#define  MT9P031_OUTPUT_CONTROL_CEN  2
> +#define  MT9P031_OUTPUT_CONTROL_SYN  1
> +#define MT9P031_SHUTTER_WIDTH_UPPER  0x08
> +#define MT9P031_SHUTTER_WIDTH0x09
> +#define  MT9P031_PLL_CONTROL 0x10
> +#define  MT9P031_PLL_CONTROL_PWROFF  0x0050
> +#define  M

Re: [PATCH v6 1/2] Add driver for Aptina (Micron) mt9p031 sensor.

2011-06-02 Thread javier Martin
OK Guennadi,
I'll fix those cosmetics issues in my next version where I will add
VFLIP and HFLIP control support (which I removed previously to make
the code less complex).

Now we talk about controls I have a question regarding controls
defined in video subdevices like mt9p031 or mt9v032:

What device node should I use to set these controls through an ioctl() ?
For instance, with mt9p031 + Beagleboard xM we have:

./media-ctl -r -l '"mt9p031 2-0048":0->"OMAP3 ISP CCDC":0[1], "OMAP3
ISP CCDC":1->"OMAP3 ISP CCDC output":0[1]'
./media-ctl -f '"mt9p031 2-0048":0[SGRBG12 320x240], "OMAP3 ISP
CCDC":0[SGRBG8 320x240], "OMAP3 ISP CCDC":1[SGRBG8 320x240]'
./yavta --stdout -f SGRBG8 -s 320x240 -n 4 --capture=100 --skip 3 -F
`./media-ctl -e "OMAP3 ISP CCDC output"` | nc 192.168.0.42 3000

Where

root@beagleboard:~# ./media-ctl -e "OMAP3 ISP CCDC output"
/dev/video2

However, if I try to set sensor controls using /dev/video2 I get an
error (invalid argument).

-- 
Javier Martin
Vista Silicon S.L.
CDTUC - FASE C - Oficina S-345
Avda de los Castros s/n
39005- Santander. Cantabria. Spain
+34 942 25 32 60
www.vista-silicon.com
--
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 v6 1/2] Add driver for Aptina (Micron) mt9p031 sensor.

2011-06-02 Thread Guennadi Liakhovetski
On Thu, 2 Jun 2011, javier Martin wrote:

> OK Guennadi,
> I'll fix those cosmetics issues in my next version where I will add
> VFLIP and HFLIP control support (which I removed previously to make
> the code less complex).

Please, don't. Let's first get the simple version of your driver in the 
mainline, then it can be extended. Just, please, make sure to address all 
remaining issues without changing anything else:)

Thanks
Guennadi

> 
> Now we talk about controls I have a question regarding controls
> defined in video subdevices like mt9p031 or mt9v032:
> 
> What device node should I use to set these controls through an ioctl() ?
> For instance, with mt9p031 + Beagleboard xM we have:
> 
> ./media-ctl -r -l '"mt9p031 2-0048":0->"OMAP3 ISP CCDC":0[1], "OMAP3
> ISP CCDC":1->"OMAP3 ISP CCDC output":0[1]'
> ./media-ctl -f '"mt9p031 2-0048":0[SGRBG12 320x240], "OMAP3 ISP
> CCDC":0[SGRBG8 320x240], "OMAP3 ISP CCDC":1[SGRBG8 320x240]'
> ./yavta --stdout -f SGRBG8 -s 320x240 -n 4 --capture=100 --skip 3 -F
> `./media-ctl -e "OMAP3 ISP CCDC output"` | nc 192.168.0.42 3000
> 
> Where
> 
> root@beagleboard:~# ./media-ctl -e "OMAP3 ISP CCDC output"
> /dev/video2
> 
> However, if I try to set sensor controls using /dev/video2 I get an
> error (invalid argument).
> 
> -- 
> Javier Martin
> Vista Silicon S.L.
> CDTUC - FASE C - Oficina S-345
> Avda de los Castros s/n
> 39005- Santander. Cantabria. Spain
> +34 942 25 32 60
> www.vista-silicon.com
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
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 v6 1/2] Add driver for Aptina (Micron) mt9p031 sensor.

2011-06-02 Thread javier Martin
On 2 June 2011 12:36, Guennadi Liakhovetski  wrote:
> On Thu, 2 Jun 2011, javier Martin wrote:
>
>> OK Guennadi,
>> I'll fix those cosmetics issues in my next version where I will add
>> VFLIP and HFLIP control support (which I removed previously to make
>> the code less complex).
>
> Please, don't. Let's first get the simple version of your driver in the
> mainline, then it can be extended. Just, please, make sure to address all
> remaining issues without changing anything else:)

Ok, thanks.


-- 
Javier Martin
Vista Silicon S.L.
CDTUC - FASE C - Oficina S-345
Avda de los Castros s/n
39005- Santander. Cantabria. Spain
+34 942 25 32 60
www.vista-silicon.com
--
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