[PATCH v4] arm: omap3evm: Add support for an MT9M032 based camera board.

2011-12-17 Thread Martin Hostettler
Adds board support for an MT9M032 based camera to omap3evm.

Signed-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 arch/arm/mach-omap2/Makefile|3 +-
 arch/arm/mach-omap2/board-omap3evm-camera.c |  159 +++
 arch/arm/mach-omap2/board-omap3evm.c|4 +
 3 files changed, 165 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-omap2/board-omap3evm-camera.c

Changes in V4
 * Fix includes
 * Add comment to clearify that the mux is a seperate gpio controlled chip.
 * remove useless variable initialisation.

Changes in V3
 * Added missing copyright and attribution.
 * switched to gpio_request_array for gpio init.
 * removed device_initcall and added call to omap3_evm_camera_init into 
omap3_evm_init

Changes in V2:
 * ported to current mainline
 * Style fixes
 * Fix error handling

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index b009f17..6045789 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -196,7 +196,8 @@ obj-$(CONFIG_MACH_OMAP3530_LV_SOM)  += 
board-omap3logic.o
 obj-$(CONFIG_MACH_OMAP3_TORPEDO)+= board-omap3logic.o
 obj-$(CONFIG_MACH_ENCORE)  += board-omap3encore.o
 obj-$(CONFIG_MACH_OVERO)   += board-overo.o
-obj-$(CONFIG_MACH_OMAP3EVM)+= board-omap3evm.o
+obj-$(CONFIG_MACH_OMAP3EVM)+= board-omap3evm.o \
+  board-omap3evm-camera.o
 obj-$(CONFIG_MACH_OMAP3_PANDORA)   += board-omap3pandora.o
 obj-$(CONFIG_MACH_OMAP_3430SDP)+= board-3430sdp.o
 obj-$(CONFIG_MACH_NOKIA_N8X0)  += board-n8x0.o
diff --git a/arch/arm/mach-omap2/board-omap3evm-camera.c 
b/arch/arm/mach-omap2/board-omap3evm-camera.c
new file mode 100644
index 000..82a4ec2
--- /dev/null
+++ b/arch/arm/mach-omap2/board-omap3evm-camera.c
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2011 Texas Instruments Inc
+ * Copyright (C) 2010-2011 Lund Engineering
+ * Contact: Gil Lund gwl...@lundeng.com
+ * Authors:
+ *Vaibhav Hiremath hvaib...@ti.com
+ *Martin Hostettler mar...@neutronstar.dyndns.org
+ *
+ * Board intregration for a MT9M032 camera connected to IMAGE_CONN and I2C Bus 
2
+ *
+ * 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/i2c.h
+#include linux/init.h
+#include linux/platform_device.h
+
+#include linux/gpio.h
+#include plat/mux.h
+#include mux.h
+
+#include media/omap3isp.h
+#include media/mt9m032.h
+
+#include devices.h
+
+#define EVM_TWL_GPIO_BASE OMAP_MAX_GPIO_LINES
+#define GPIO98_VID_DEC_RES 98
+#define nCAM_VD_SEL157
+
+#define MT9M032_I2C_BUS_NUM2
+
+
+enum omap3evmdc_mux {
+   MUX_TVP5146,
+   MUX_CAMERA_SENSOR,
+   MUX_EXP_CAMERA_SENSOR,
+};
+
+/**
+ * omap3evm_set_mux - Sets mux to enable signal routing to
+ *   different peripherals present on new EVM board
+ * @mux_id: enum, mux id to enable
+ *
+ * Returns 0 for success or a negative error code
+ */
+static int omap3evm_set_mux(enum omap3evmdc_mux mux_id)
+{
+   /*
+* The video mux on the EVM board is controlled by various
+* GPIO pins.
+ */
+   /* Set GPIO6 = 1 */
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 6, 1);
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+
+   switch (mux_id) {
+   case MUX_TVP5146:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 1);
+   break;
+
+   case MUX_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 0);
+   break;
+
+   case MUX_EXP_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 1);
+   break;
+
+   default:
+   pr_err(omap3evm-camera: Invalid mux id #%d\n, mux_id);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static struct mt9m032_platform_data mt9m032_platform_data = {
+   .ext_clock = 1350,
+   .pll_pre_div = 6,
+   .pll_mul = 120,
+   .pll_out_div = 5,
+   .invert_pixclock = 1,
+};
+
+static struct i2c_board_info camera_i2c_devices[] = {
+   {
+   I2C_BOARD_INFO(MT9M032_NAME, MT9M032_I2C_ADDR),
+   .platform_data = mt9m032_platform_data

[PATCH v4] v4l: Add driver for Micron MT9M032 camera sensor

2011-12-17 Thread Martin Hostettler
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 |  837 +
 include/media/mt9m032.h   |   38 ++
 4 files changed, 883 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/mt9m032.c
 create mode 100644 include/media/mt9m032.h


Changes in V4
 * Use register(-value) constants from MT9P031 to fill in gaps
 * Use MT9M032_CHIP_VERSION_VALUE instead of magical number
 * Use i2c_smbus_{read,write}_word_swapped
 * Minor error return code handling fixes

Changes in V3
 * rebased to current mainline
 * removed unneeded includes
 * remove all translation code to hide black or active boundry sensor pixels. 
Userspace now needs to select
crop in original device coordinates.
 * remove useless consts, casts and defines
 * changed enum_frame_size to return min == max
 * removed duplicated input validation
 * validate crop rectangle on set_crop

Changes in V2
 * ported to current mainline
 * Moved dispatching for subdev ioctls VIDIOC_DBG_G_REGISTER and 
VIDIOC_DBG_S_REGISTER into v4l2-subdev
 * Removed VIDIOC_DBG_G_CHIP_IDENT support
 * moved header to media/
 * Fixed missing error handling
 * lowercase hex constants
 * moved v4l2_get_subdevdata to register access helpers
 * use div_u64 instead of do_div
 * moved all know register values into #define:ed constants
 * Fixed error reporting, used clamp instead of open coding.
 * lots of style fixes.
 * add try_ctrl to make sure user space sees rounded values
 * Fixed some problem in control framework usage.
 * Fixed set_format to force width and height setup via crop. Simplyfied code.

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index b303a3f..cf05d9b 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -820,6 +820,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 117f9c4..39c7455 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_VIDEO_ADP1653)   += adp1653.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..6f1968a
--- /dev/null
+++ b/drivers/media/video/mt9m032.c
@@ -0,0 +1,837 @@
+/*
+ * 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

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

2011-12-13 Thread Martin Hostettler
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 |  819 +
 include/media/mt9m032.h   |   38 ++
 4 files changed, 865 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/mt9m032.c
 create mode 100644 include/media/mt9m032.h

Changes in V3
 * rebased to current mainline
 * removed unneeded includes
 * remove all translation code to hide black or active boundry sensor pixels. 
Userspace now needs to select crop in original device coordinates.
 * remove useless consts, casts and defines
 * changed enum_frame_size to return min == max
 * removed duplicated input validation
 * validate crop rectangle on set_crop

Changes in V2
 * ported to current mainline
 * Moved dispatching for subdev ioctls VIDIOC_DBG_G_REGISTER and 
VIDIOC_DBG_S_REGISTER into v4l2-subdev
 * Removed VIDIOC_DBG_G_CHIP_IDENT support
 * moved header to media/
 * Fixed missing error handling
 * lowercase hex constants
 * moved v4l2_get_subdevdata to register access helpers
 * use div_u64 instead of do_div
 * moved all know register values into #define:ed constants
 * Fixed error reporting, used clamp instead of open coding.
 * lots of style fixes.
 * add try_ctrl to make sure user space sees rounded values
 * Fixed some problem in control framework usage.
 * Fixed set_format to force width and height setup via crop. Simplyfied code.

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index b303a3f..cf05d9b 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -820,6 +820,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 117f9c4..39c7455 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_VIDEO_ADP1653)   += adp1653.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..b4159c7
--- /dev/null
+++ b/drivers/media/video/mt9m032.c
@@ -0,0 +1,819 @@
+/*
+ * 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_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_RESTART

[PATCH v3] arm: omap3evm: Add support for an MT9M032 based camera board.

2011-12-13 Thread Martin Hostettler
Adds board support for an MT9M032 based camera to omap3evm.

Signed-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 arch/arm/mach-omap2/Makefile|3 +-
 arch/arm/mach-omap2/board-omap3evm-camera.c |  155 +++
 arch/arm/mach-omap2/board-omap3evm.c|4 +
 3 files changed, 161 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-omap2/board-omap3evm-camera.c

Changes in V3
 * Added missing copyright and attribution.
 * switched to gpio_request_array for gpio init.
 * removed device_initcall and added call to omap3_evm_camera_init into 
omap3_evm_init

Changes in V2:
 * ported to current mainline
 * Style fixes
 * Fix error handling

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index b009f17..6045789 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -196,7 +196,8 @@ obj-$(CONFIG_MACH_OMAP3530_LV_SOM)  += 
board-omap3logic.o
 obj-$(CONFIG_MACH_OMAP3_TORPEDO)+= board-omap3logic.o
 obj-$(CONFIG_MACH_ENCORE)  += board-omap3encore.o
 obj-$(CONFIG_MACH_OVERO)   += board-overo.o
-obj-$(CONFIG_MACH_OMAP3EVM)+= board-omap3evm.o
+obj-$(CONFIG_MACH_OMAP3EVM)+= board-omap3evm.o \
+  board-omap3evm-camera.o
 obj-$(CONFIG_MACH_OMAP3_PANDORA)   += board-omap3pandora.o
 obj-$(CONFIG_MACH_OMAP_3430SDP)+= board-3430sdp.o
 obj-$(CONFIG_MACH_NOKIA_N8X0)  += board-n8x0.o
diff --git a/arch/arm/mach-omap2/board-omap3evm-camera.c 
b/arch/arm/mach-omap2/board-omap3evm-camera.c
new file mode 100644
index 000..bffd5b8
--- /dev/null
+++ b/arch/arm/mach-omap2/board-omap3evm-camera.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2011 Texas Instruments Inc
+ * Copyright (C) 2010-2011 Lund Engineering
+ * Contact: Gil Lund gwl...@lundeng.com
+ * Authors:
+ *Vaibhav Hiremath hvaib...@ti.com
+ *Martin Hostettler mar...@neutronstar.dyndns.org
+ *
+ * Board intregration for a MT9M032 camera connected to IMAGE_CONN and I2C Bus 
2
+ *
+ * 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/i2c.h
+#include linux/init.h
+#include linux/platform_device.h
+
+#include linux/gpio.h
+#include plat/mux.h
+#include mux.h
+
+#include ../../../drivers/media/video/omap3isp/isp.h
+#include media/mt9m032.h
+
+#include devices.h
+
+#define EVM_TWL_GPIO_BASE OMAP_MAX_GPIO_LINES
+#define GPIO98_VID_DEC_RES 98
+#define nCAM_VD_SEL157
+
+#define MT9M032_I2C_BUS_NUM2
+
+
+enum omap3evmdc_mux {
+   MUX_TVP5146,
+   MUX_CAMERA_SENSOR,
+   MUX_EXP_CAMERA_SENSOR,
+};
+
+/**
+ * omap3evm_set_mux - Sets mux to enable signal routing to
+ *   different peripherals present on new EVM board
+ * @mux_id: enum, mux id to enable
+ *
+ * Returns 0 for success or a negative error code
+ */
+static int omap3evm_set_mux(enum omap3evmdc_mux mux_id)
+{
+   /* Set GPIO6 = 1 */
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 6, 1);
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+
+   switch (mux_id) {
+   case MUX_TVP5146:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 1);
+   break;
+
+   case MUX_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 0);
+   break;
+
+   case MUX_EXP_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 1);
+   break;
+
+   default:
+   pr_err(omap3evm-camera: Invalid mux id #%d\n, mux_id);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static struct mt9m032_platform_data mt9m032_platform_data = {
+   .ext_clock = 1350,
+   .pll_pre_div = 6,
+   .pll_mul = 120,
+   .pll_out_div = 5,
+   .invert_pixclock = 1,
+};
+
+static struct i2c_board_info camera_i2c_devices[] = {
+   {
+   I2C_BOARD_INFO(MT9M032_NAME, MT9M032_I2C_ADDR),
+   .platform_data = mt9m032_platform_data,
+   },
+};
+
+static struct isp_subdev_i2c_board_info camera_i2c_subdevs[] = {
+   {
+   .board_info = camera_i2c_devices[0],
+   .i2c_adapter_id = MT9M032_I2C_BUS_NUM,
+   },
+   {},
+};
+
+static

[PATCH v2] v4l subdev: add dispatching for VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER.

2011-09-19 Thread Martin Hostettler
Ioctls on the subdevs node currently don't dispatch the register access debug
driver callbacks. Add the dispatching with the same security checks are for
non subdev video nodes (i.e. only capable(CAP_SYS_ADMIN may call the register
access ioctls).

Sigend-off-by: Martin Hostettler martin at neutronstar.dyndns.org
---
 drivers/media/video/v4l2-subdev.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/v4l2-subdev.c 
b/drivers/media/video/v4l2-subdev.c
index b7967c9..179e20e 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -173,6 +173,25 @@ static long subdev_do_ioctl(struct file *file, unsigned 
int cmd, void *arg)
 
case VIDIOC_UNSUBSCRIBE_EVENT:
return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+   case VIDIOC_DBG_G_REGISTER:
+   {
+   struct v4l2_dbg_register *p = arg;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EPERM;
+   return v4l2_subdev_call(sd, core, g_register, p);
+   }
+   case VIDIOC_DBG_S_REGISTER:
+   {
+   struct v4l2_dbg_register *p = arg;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EPERM;
+   return v4l2_subdev_call(sd, core, s_register, p);
+   }
+#endif
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
case VIDIOC_SUBDEV_G_FMT: {
struct v4l2_subdev_format *format = arg;
-- 
1.7.2.5

--
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] v4l subdev: add dispatching for VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER.

2011-09-17 Thread Martin Hostettler
Ioctls on the subdevs node currently don't dispatch the register access debug 
driver callbacks. Add
the dispatching with the same security checks are for non subdev video nodes
(i.e. only capable(CAP_SYS_ADMIN may call the register access ioctls).
---
 drivers/media/video/v4l2-subdev.c |   20 
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/v4l2-subdev.c 
b/drivers/media/video/v4l2-subdev.c
index b7967c9..8bf8397 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -25,6 +25,7 @@
 #include linux/types.h
 #include linux/videodev2.h
 
+#include media/v4l2-chip-ident.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-device.h
 #include media/v4l2-ioctl.h
@@ -173,6 +174,25 @@ static long subdev_do_ioctl(struct file *file, unsigned 
int cmd, void *arg)
 
case VIDIOC_UNSUBSCRIBE_EVENT:
return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+   case VIDIOC_DBG_G_REGISTER:
+   {
+   struct v4l2_dbg_register *p = arg;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EPERM;
+   return v4l2_subdev_call(sd, core, g_register, p);
+   }
+   case VIDIOC_DBG_S_REGISTER:
+   {
+   struct v4l2_dbg_register *p = arg;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EPERM;
+   return v4l2_subdev_call(sd, core, s_register, p);
+   }
+#endif
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
case VIDIOC_SUBDEV_G_FMT: {
struct v4l2_subdev_format *format = arg;
-- 
1.7.2.5

--
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 v2] v4l: Add driver for Micron MT9M032 camera sensor

2011-09-17 Thread Martin Hostettler
The MT9M032 is a parallel 3MP 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   |  814 +++
 include/media/mt9m032.h |   38 ++
 include/media/v4l2-chip-ident.h |1 +
 5 files changed, 861 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/mt9m032.c
 create mode 100644 include/media/mt9m032.h

Changes in V2
 * ported to current mainline
 * Moved dispatching for subdev ioctls VIDIOC_DBG_G_REGISTER and 
VIDIOC_DBG_S_REGISTER into v4l2-subdev
 * Removed VIDIOC_DBG_G_CHIP_IDENT support
 * moved header to media/
 * Fixed missing error handling
 * lowercase hex constants
 * moved v4l2_get_subdevdata to register access helpers
 * use div_u64 instead of do_div
 * moved all know register values into #define:ed constants
 * Fixed error reporting, used clamp instead of open coding.
 * lots of style fixes.
 * add try_ctrl to make sure user space sees rounded values
 * Fixed some problem in control framework usage.
 * Fixed set_format to force width and height setup via crop. Simplyfied code.

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f574dc0..41c6c12 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -798,6 +798,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 2723900..0d86830 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -74,6 +74,7 @@ obj-$(CONFIG_VIDEO_ADP1653)   += adp1653.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..8a64193
--- /dev/null
+++ b/drivers/media/video/mt9m032.c
@@ -0,0 +1,814 @@
+/*
+ * 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-chip-ident.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_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

[PATCH v2] arm: omap3evm: Add support for an MT9M032 based camera board.

2011-09-17 Thread Martin Hostettler
Adds board support for an MT9M032 based camera to omap3evm.

Sigend-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 arch/arm/mach-omap2/Makefile|1 +
 arch/arm/mach-omap2/board-omap3evm-camera.c |  183 +++
 2 files changed, 184 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/board-omap3evm-camera.c

Changes in V2:
 * ported to current mainline
 * Style fixes
 * Fix error handling

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index f343365..8ae3d25 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -202,6 +202,7 @@ obj-$(CONFIG_MACH_OMAP3_TORPEDO)+= 
board-omap3logic.o \
 obj-$(CONFIG_MACH_OVERO)   += board-overo.o \
   hsmmc.o
 obj-$(CONFIG_MACH_OMAP3EVM)+= board-omap3evm.o \
+  board-omap3evm-camera.o \
   hsmmc.o
 obj-$(CONFIG_MACH_OMAP3_PANDORA)   += board-omap3pandora.o \
   hsmmc.o
diff --git a/arch/arm/mach-omap2/board-omap3evm-camera.c 
b/arch/arm/mach-omap2/board-omap3evm-camera.c
new file mode 100644
index 000..be987d9
--- /dev/null
+++ b/arch/arm/mach-omap2/board-omap3evm-camera.c
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2010-2011 Lund Engineering
+ * Contact: Gil Lund gwl...@lundeng.com
+ * Author: Martin Hostettler mar...@neutronstar.dyndns.org
+ *
+ * Board intregration for a MT9M032 camera connected to IMAGE_CONN and I2C Bus 
2
+ *
+ * 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/i2c.h
+#include linux/init.h
+#include linux/platform_device.h
+
+#include linux/gpio.h
+#include plat/mux.h
+#include mux.h
+
+#include ../../../drivers/media/video/omap3isp/isp.h
+#include media/mt9m032.h
+
+#include devices.h
+
+#define EVM_TWL_GPIO_BASE OMAP_MAX_GPIO_LINES
+#define GPIO98_VID_DEC_RES 98
+#define nCAM_VD_SEL157
+
+#define MT9M032_I2C_BUS_NUM2
+
+
+enum omap3evmdc_mux {
+   MUX_TVP5146,
+   MUX_CAMERA_SENSOR,
+   MUX_EXP_CAMERA_SENSOR,
+};
+
+/**
+ * omap3evm_set_mux - Sets mux to enable signal routing to
+ *   different peripherals present on new EVM board
+ * @mux_id: enum, mux id to enable
+ *
+ * Returns 0 for success or a negative error code
+ */
+static int omap3evm_set_mux(enum omap3evmdc_mux mux_id)
+{
+   /* Set GPIO6 = 1 */
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 6, 1);
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+
+   switch (mux_id) {
+   case MUX_TVP5146:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 1);
+   break;
+
+   case MUX_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 0);
+   break;
+
+   case MUX_EXP_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 1);
+   break;
+
+   default:
+   pr_err(omap3evm-camera: Invalid mux id #%d\n, mux_id);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static struct mt9m032_platform_data mt9m032_platform_data = {
+   .ext_clock = 1350,
+   .pll_pre_div = 6,
+   .pll_mul = 120,
+   .pll_out_div = 5,
+   .invert_pixclock = 1,
+};
+
+static struct i2c_board_info camera_i2c_devices[] = {
+   {
+   I2C_BOARD_INFO(MT9M032_NAME, MT9M032_I2C_ADDR),
+   .platform_data = mt9m032_platform_data,
+   },
+};
+
+static struct isp_subdev_i2c_board_info camera_i2c_subdevs[] = {
+   {
+   .board_info = camera_i2c_devices[0],
+   .i2c_adapter_id = MT9M032_I2C_BUS_NUM,
+   },
+   {},
+};
+
+static struct isp_v4l2_subdevs_group camera_subdevs[] = {
+   {
+   .subdevs = camera_i2c_subdevs,
+   .interface = ISP_INTERFACE_PARALLEL,
+   .bus = {
+   .parallel = {
+   .data_lane_shift = 1,
+   .clk_pol = 0,
+   .bridge = ISPCTRL_PAR_BRIDGE_DISABLE,
+   }
+   },
+   },
+   {},
+};
+
+static struct

[PATCH] media-ctl: subdev: add Y8 format.

2011-01-20 Thread Martin Hostettler
---
 subdev.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

This is a trivial patch for media-ctl to support monochrome 8bit video formats.


diff --git a/subdev.c b/subdev.c
index f36a8e7..6f4eb26 100644
--- a/subdev.c
+++ b/subdev.c
@@ -39,6 +39,7 @@ static struct {
 } mbus_formats[] = {
{ YUYV, V4L2_MBUS_FMT_YUYV8_1X16 },
{ UYVY, V4L2_MBUS_FMT_UYVY8_1X16 },
+   { Y8, V4L2_MBUS_FMT_Y8_1X8}, 
{ SGRBG10, V4L2_MBUS_FMT_SGRBG10_1X10 },
{ SGRBG10_DPCM8, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 },
 };
-- 
1.7.1

--
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] v4l: OMAP3 ISP CCDC: Add support for 8bit greyscale sensors

2011-01-20 Thread Martin Hostettler
On Thu, Jan 20, 2011 at 03:37:50PM +0100, Laurent Pinchart wrote:
 Hi Martin,
 
 On Wednesday 19 January 2011 18:47:59 mar...@neutronstar.dyndns.org wrote:
  But the only clean solution i can think of is setting it to 0
  unconditionally.
  I'm not sure what this default should acomplish, so maybe i'm missing
  something here, but i think the right value if dc substraction is needed
  would be highly sensor specific?
  I think all other of these postprocessing features for the CCDC default to
  off, so it would make sense to default this to off too.
  
  The overenginered solution would be to maintain a different value for each
  bus width and let the user change the setting for the buswidth of the
  currently linked sensor. In a way this would make sense,
  because the DC substraction is fundamentally dependent on the bus size i
  think. But i don't think anyone would want such complexity.
  
  But i think it wouldn't be nice if every user of an 8bit sensor needs to
  set this manually just to get the sensor working in a sane way (for 8bit
  substracting 64 is insane, for wider buses it's different)
  
  So how to proceed with this?
 
 My personal opinion (at least for now) is that we should set the default 
 value 
 to 0. I'll see if I can convince people at Nokia that it would be the right 
 way to go. If so I'll apply a patch for that.
 

Yes, that would be great, thanks.

I'll resend the patch with this part removed.

regards,
 - Martin Hostettler
--
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] v4l: OMAP3 ISP CCDC: Add support for 8bit greyscale sensors

2011-01-20 Thread Martin Hostettler
Adds support for V4L2_MBUS_FMT_Y8_1X8 format and 8bit data width in
synchronous interface.

When using V4L2_MBUS_FMT_Y8_1X8 (or possibly another 8bit per pixel) mode
set the CDCC to output 8bit per pixel instead of 16bit.

Signed-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 drivers/media/video/isp/ispccdc.c  |   15 ---
 drivers/media/video/isp/ispvideo.c |2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)

Changes since first version:
- forward ported to current media.git
Changes since second version:
- remove ccdc-clamp.dcsubval related changes

diff --git a/drivers/media/video/isp/ispccdc.c 
b/drivers/media/video/isp/ispccdc.c
index 578c8bf..7632bc1 100644
--- a/drivers/media/video/isp/ispccdc.c
+++ b/drivers/media/video/isp/ispccdc.c
@@ -43,6 +43,7 @@ __ccdc_get_format(struct isp_ccdc_device *ccdc, struct 
v4l2_subdev_fh *fh,
  unsigned int pad, enum v4l2_subdev_format_whence which);
 
 static const unsigned int ccdc_fmts[] = {
+   V4L2_MBUS_FMT_Y8_1X8,
V4L2_MBUS_FMT_SGRBG10_1X10,
V4L2_MBUS_FMT_SRGGB10_1X10,
V4L2_MBUS_FMT_SBGGR10_1X10,
@@ -1127,6 +1128,9 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
ccdc-syncif.datsz = pdata ? pdata-width : 10;
ispccdc_config_sync_if(ccdc, ccdc-syncif);
 
+   /* CCDC_PAD_SINK */
+   format = ccdc-formats[CCDC_PAD_SINK];
+
syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
 
/* Use the raw, unprocessed data when writing to memory. The H3A and
@@ -1144,10 +1148,15 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
else
syn_mode = ~ISPCCDC_SYN_MODE_SDR2RSZ;
 
-   isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
+   /* Use PACK8 mode for 1byte per pixel formats */
 
-   /* CCDC_PAD_SINK */
-   format = ccdc-formats[CCDC_PAD_SINK];
+   if (isp_video_format_info(format-code)-bpp = 8)
+   syn_mode |= ISPCCDC_SYN_MODE_PACK8;
+   else
+   syn_mode = ~ISPCCDC_SYN_MODE_PACK8;
+
+
+   isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
 
/* Mosaic filter */
switch (format-code) {
diff --git a/drivers/media/video/isp/ispvideo.c 
b/drivers/media/video/isp/ispvideo.c
index 5f984e4..cd3d331 100644
--- a/drivers/media/video/isp/ispvideo.c
+++ b/drivers/media/video/isp/ispvideo.c
@@ -221,6 +221,8 @@ isp_video_check_format(struct isp_video *video, struct 
isp_video_fh *vfh)
 }
 
 static struct isp_format_info formats[] = {
+   { V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
+ V4L2_MBUS_FMT_Y8_1X8, V4L2_PIX_FMT_GREY, 8, },
{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
  V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10DPCM8, 8, },
{ V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR10_1X10,
-- 
1.7.1

--
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 V2] v4l: OMAP3 ISP CCDC: Add support for 8bit greyscale sensors

2011-01-18 Thread Martin Hostettler
Adds support for V4L2_MBUS_FMT_Y8_1X8 format and 8bit data width in
synchronous interface.

When in 8bit mode don't apply DC substraction of 64 per default as this would
remove 1/4 of the sensor range.

When using V4L2_MBUS_FMT_Y8_1X8 (or possibly another 8bit per pixel) mode
set the CDCC to output 8bit per pixel instead of 16bit.

Signed-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 drivers/media/video/isp/ispccdc.c  |   22 ++
 drivers/media/video/isp/ispvideo.c |2 ++
 2 files changed, 20 insertions(+), 4 deletions(-)

Changes since first version:
- forward ported to current media.git

diff --git a/drivers/media/video/isp/ispccdc.c 
b/drivers/media/video/isp/ispccdc.c
index 578c8bf..c7397c9 100644
--- a/drivers/media/video/isp/ispccdc.c
+++ b/drivers/media/video/isp/ispccdc.c
@@ -43,6 +43,7 @@ __ccdc_get_format(struct isp_ccdc_device *ccdc, struct 
v4l2_subdev_fh *fh,
  unsigned int pad, enum v4l2_subdev_format_whence which);
 
 static const unsigned int ccdc_fmts[] = {
+   V4L2_MBUS_FMT_Y8_1X8,
V4L2_MBUS_FMT_SGRBG10_1X10,
V4L2_MBUS_FMT_SRGGB10_1X10,
V4L2_MBUS_FMT_SBGGR10_1X10,
@@ -1127,6 +1128,9 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
ccdc-syncif.datsz = pdata ? pdata-width : 10;
ispccdc_config_sync_if(ccdc, ccdc-syncif);
 
+   /* CCDC_PAD_SINK */
+   format = ccdc-formats[CCDC_PAD_SINK];
+
syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
 
/* Use the raw, unprocessed data when writing to memory. The H3A and
@@ -1144,10 +1148,15 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
else
syn_mode = ~ISPCCDC_SYN_MODE_SDR2RSZ;
 
-   isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
+   /* Use PACK8 mode for 1byte per pixel formats */
 
-   /* CCDC_PAD_SINK */
-   format = ccdc-formats[CCDC_PAD_SINK];
+   if (isp_video_format_info(format-code)-bpp = 8)
+   syn_mode |= ISPCCDC_SYN_MODE_PACK8;
+   else
+   syn_mode = ~ISPCCDC_SYN_MODE_PACK8;
+
+
+   isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
 
/* Mosaic filter */
switch (format-code) {
@@ -2244,7 +2253,12 @@ int isp_ccdc_init(struct isp_device *isp)
ccdc-syncif.vdpol = 0;
 
ccdc-clamp.oblen = 0;
-   ccdc-clamp.dcsubval = 64;
+
+   if (isp-pdata-subdevs-interface == ISP_INTERFACE_PARALLEL
+isp-pdata-subdevs-bus.parallel.width = 8)
+   ccdc-clamp.dcsubval = 0;
+   else
+   ccdc-clamp.dcsubval = 64;
 
ccdc-vpcfg.pixelclk = 0;
 
diff --git a/drivers/media/video/isp/ispvideo.c 
b/drivers/media/video/isp/ispvideo.c
index 5f984e4..cd3d331 100644
--- a/drivers/media/video/isp/ispvideo.c
+++ b/drivers/media/video/isp/ispvideo.c
@@ -221,6 +221,8 @@ isp_video_check_format(struct isp_video *video, struct 
isp_video_fh *vfh)
 }
 
 static struct isp_format_info formats[] = {
+   { V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
+ V4L2_MBUS_FMT_Y8_1X8, V4L2_PIX_FMT_GREY, 8, },
{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
  V4L2_MBUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10DPCM8, 8, },
{ V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_SBGGR10_1X10,
-- 
1.7.1

--
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] v4l: Add driver for Micron MT9M032 camera sensor

2011-01-18 Thread Martin Hostettler
The MT9M032 is a parallel 1284x812 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   |  834 +++
 drivers/media/video/mt9m032.h   |   38 ++
 include/media/v4l2-chip-ident.h |1 +
 5 files changed, 881 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/mt9m032.c
 create mode 100644 drivers/media/video/mt9m032.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 9fad1a6..f2d5f80 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -773,6 +773,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 8f70b06..3e7299f 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -70,6 +70,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_MT9M032) += mt9m032.o
 obj-$(CONFIG_VIDEO_MT9T001) += mt9t001.o
 obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o
 obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o
diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
new file mode 100644
index 000..fe6af7b
--- /dev/null
+++ b/drivers/media/video/mt9m032.c
@@ -0,0 +1,834 @@
+/*
+ * 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/module.h
+#include linux/slab.h
+#include linux/v4l2-mediabus.h
+
+#include media/media-entity.h
+#include media/v4l2-chip-ident.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-device.h
+#include media/v4l2-subdev.h
+
+#include mt9m032.h
+
+#define MT9M032_CHIP_VERSION   0x00
+#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_RESTART0x0B
+#define MT9M032_RESET  0x0D
+#define MT9M032_PLL_CONFIG10x11
+#define MT9M032_READ_MODE1 0x1E
+#define MT9M032_READ_MODE2 0x20
+#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_FORMATTER1 0x9E
+#define MT9M032_FORMATTER2 0x9F
+
+#define to_mt9m032(sd) container_of(sd, struct mt9m032, subdev)
+#define to_dev(sensor) ((struct i2c_client 
*)v4l2_get_subdevdata(sensor-subdev))-dev
+
+struct mt9m032 {
+   struct v4l2_subdev subdev;
+   struct media_pad pad;
+   struct mt9m032_platform_data *pdata;
+   struct v4l2_ctrl_handler ctrls;
+
+   bool streaming;
+
+   int pix_clock;
+
+   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, *gain, *exposure;
+};
+
+
+static int mt9m032_read_reg(struct i2c_client *client

[PATCH RFC] arm: omap3evm: Add support for an MT9M032 based camera board.

2011-01-18 Thread Martin Hostettler
Adds board support for an MT9M032 based camera to omap3evm.

Sigend-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 arch/arm/mach-omap2/Makefile|1 +
 arch/arm/mach-omap2/board-omap3evm-camera.c |  177 +++
 2 files changed, 178 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/board-omap3evm-camera.c

This patch depends on the recent not yet mainline media controller framework
and omap3-isp driver availible at git.linuxtv.org/pinchartl/media.git.

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 60e51bc..5f43cc5 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -132,6 +132,7 @@ obj-$(CONFIG_MACH_OMAP3_TORPEDO)+= 
board-omap3logic.o \
 obj-$(CONFIG_MACH_OVERO)   += board-overo.o \
   hsmmc.o
 obj-$(CONFIG_MACH_OMAP3EVM)+= board-omap3evm.o \
+  board-omap3evm-camera.o \
   hsmmc.o
 obj-$(CONFIG_MACH_OMAP3_PANDORA)   += board-omap3pandora.o \
   hsmmc.o
diff --git a/arch/arm/mach-omap2/board-omap3evm-camera.c 
b/arch/arm/mach-omap2/board-omap3evm-camera.c
new file mode 100644
index 000..ea82a49
--- /dev/null
+++ b/arch/arm/mach-omap2/board-omap3evm-camera.c
@@ -0,0 +1,177 @@
+/*
+ * 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/i2c.h
+#include linux/init.h
+#include linux/platform_device.h
+
+#include asm/gpio.h
+#include plat/mux.h
+#include mux.h
+
+#include ../../../drivers/media/video/isp/isp.h
+#include ../../../drivers/media/video/mt9m032.h
+
+#include devices.h
+
+#define EVM_TWL_GPIO_BASE OMAP_MAX_GPIO_LINES
+#define GPIO98_VID_DEC_RES 98
+#define nCAM_VD_SEL157
+
+#define MT9M032_I2C_BUS_NUM2
+
+
+enum omap3evmdc_mux {
+   MUX_TVP5146,
+   MUX_CAMERA_SENSOR,
+   MUX_EXP_CAMERA_SENSOR,
+};
+
+/**
+ * omap3evm_set_mux - Sets mux to enable signal routing to
+ *   different peripherals present on new EVM board
+ * @mux_id: enum, mux id to enable
+ *
+ * Returns 0 for success or a negative error code
+ */
+static int omap3evm_set_mux(enum omap3evmdc_mux mux_id)
+{
+   /* Set GPIO6 = 1 */
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 6, 1);
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+
+   switch (mux_id) {
+   case MUX_TVP5146:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 1);
+   break;
+
+   case MUX_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 0);
+   gpio_set_value(nCAM_VD_SEL, 0);
+   break;
+
+   case MUX_EXP_CAMERA_SENSOR:
+   gpio_set_value_cansleep(EVM_TWL_GPIO_BASE + 2, 1);
+   break;
+
+   default:
+   pr_err(omap3evm-camera: Invalid mux id #%d\n, mux_id);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static struct mt9m032_platform_data mt9m032_platform_data = {
+   .ext_clock = 1350,
+   .pll_pre_div = 6,
+   .pll_mul = 120,
+   .pll_out_div = 5,
+   .invert_pixclock = 1,
+};
+
+static struct i2c_board_info camera_i2c_devices[] = {
+   {
+   I2C_BOARD_INFO(MT9M032_NAME, MT9M032_I2C_ADDR),
+   .platform_data = mt9m032_platform_data,
+   },
+};
+
+static struct isp_subdev_i2c_board_info camera_i2c_subdevs[] = {
+   {
+   .board_info = camera_i2c_devices[0],
+   .i2c_adapter_id = MT9M032_I2C_BUS_NUM,
+   },
+   {},
+};
+
+static struct isp_v4l2_subdevs_group camera_subdevs[] = {
+   {
+   .subdevs = camera_i2c_subdevs,
+   .interface = ISP_INTERFACE_PARALLEL,
+   .bus = {
+   .parallel = {
+   .data_lane_shift = 1,
+   .clk_pol = 0,
+   .bridge = ISPCTRL_PAR_BRIDGE_DISABLE,
+   .width = 8

[PATCH] v4l: OMAP3 ISP CCDC: Add support for 8bit greyscale sensors

2010-12-14 Thread Martin Hostettler
Adds support for V4L2_MBUS_FMT_Y8_1X8 format and 8bit data width in
syncronous interface.

The data width is configured in the parallel interface part of the isp platform
data, defaulting to 10bit as before this commit. When i 8bit mode don't apply
DC substraction of 64 per default as this would remove 1/4 of the sensor range.

When using V4L2_MBUS_FMT_Y8_1X8 (or possibly another 8bit per pixel) mode
set the CDCC to output 8bit per pixel instead of 16bit.

Signed-off-by: Martin Hostettler mar...@neutronstar.dyndns.org
---
 drivers/media/video/isp/isp.h  |2 ++
 drivers/media/video/isp/ispccdc.c  |   21 -
 drivers/media/video/isp/ispvideo.c |7 +++
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/media/video/isp/isp.h b/drivers/media/video/isp/isp.h
index edc029c..76c09ed 100644
--- a/drivers/media/video/isp/isp.h
+++ b/drivers/media/video/isp/isp.h
@@ -132,11 +132,13 @@ struct isp_reg {
  * ISPCTRL_PAR_BRIDGE_DISABLE - Disable
  * ISPCTRL_PAR_BRIDGE_LENDIAN - Little endian
  * ISPCTRL_PAR_BRIDGE_BENDIAN - Big endian
+ * @datsz: Width of the data-bus in bits (8, 10, 11, 12, 13) or 0 for default 
(10bit)
  */
 struct isp_parallel_platform_data {
unsigned int data_lane_shift:2;
unsigned int clk_pol:1;
unsigned int bridge:4;
+   unsigned int data_bus_width;
 };
 
 /**
diff --git a/drivers/media/video/isp/ispccdc.c 
b/drivers/media/video/isp/ispccdc.c
index be4581e..bff217a 100644
--- a/drivers/media/video/isp/ispccdc.c
+++ b/drivers/media/video/isp/ispccdc.c
@@ -45,6 +45,7 @@ static const unsigned int ccdc_fmts[] = {
V4L2_MBUS_FMT_SRGGB10_1X10,
V4L2_MBUS_FMT_SBGGR10_1X10,
V4L2_MBUS_FMT_SGBRG10_1X10,
+   V4L2_MBUS_FMT_Y8_1X8,
 };
 
 /*
@@ -1069,6 +1070,10 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
isp_configure_bridge(isp, ccdc-input, pdata);
ispccdc_config_sync_if(ccdc, ccdc-syncif);
 
+   /* CCDC_PAD_SINK */
+   format = ccdc-formats[CCDC_PAD_SINK];
+   isp_video_mbus_to_pix(ccdc-video_out, format, pix);
+
syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
 
/* Use the raw, unprocessed data when writing to memory. The H3A and
@@ -1086,10 +1091,14 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
else
syn_mode = ~ISPCCDC_SYN_MODE_SDR2RSZ;
 
-   isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
+   /* Use PACK8 mode for 1byte per pixel formats */
+   if (pix.bytesperline  format-width * 2)
+   syn_mode |= ISPCCDC_SYN_MODE_PACK8;
+   else
+   syn_mode = ~ISPCCDC_SYN_MODE_PACK8;
 
-   /* CCDC_PAD_SINK */
-   format = ccdc-formats[CCDC_PAD_SINK];
+
+   isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
 
/* Mosaic filter */
switch (format-code) {
@@ -1128,7 +1137,6 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
 ISPCCDC_VERT_LINES_NLV_SHIFT,
   OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_LINES);
 
-   isp_video_mbus_to_pix(ccdc-video_out, format, pix);
ispccdc_config_outlineoffset(ccdc, pix.bytesperline, 0, 0);
 
/* CCDC_PAD_SOURCE_VP */
@@ -2164,6 +2172,9 @@ int isp_ccdc_init(struct isp_device *isp)
ccdc-syncif.ccdc_mastermode = 0;
ccdc-syncif.datapol = 0;
ccdc-syncif.datsz = 10;
+   if (isp-pdata-subdevs-interface == ISP_INTERFACE_PARALLEL
+isp-pdata-subdevs-bus.parallel.data_bus_width != 0)
+   ccdc-syncif.datsz = 
isp-pdata-subdevs-bus.parallel.data_bus_width;
ccdc-syncif.fldmode = 0;
ccdc-syncif.fldout = 0;
ccdc-syncif.fldpol = 0;
@@ -2172,7 +2183,7 @@ int isp_ccdc_init(struct isp_device *isp)
ccdc-syncif.vdpol = 0;
 
ccdc-clamp.oblen = 0;
-   ccdc-clamp.dcsubval = 64;
+   ccdc-clamp.dcsubval = (ccdc-syncif.datsz == 8) ? 0 : 64;
 
ccdc-vpcfg.pixelclk = 0;
 
diff --git a/drivers/media/video/isp/ispvideo.c 
b/drivers/media/video/isp/ispvideo.c
index 64068ff..35e8c72 100644
--- a/drivers/media/video/isp/ispvideo.c
+++ b/drivers/media/video/isp/ispvideo.c
@@ -228,6 +228,10 @@ void isp_video_mbus_to_pix(const struct isp_video *video,
pix-pixelformat = V4L2_PIX_FMT_YUYV;
pix-bytesperline = pix-width * 2;
break;
+   case V4L2_MBUS_FMT_Y8_1X8:
+   pix-pixelformat = V4L2_PIX_FMT_GREY;
+   pix-bytesperline = pix-width;
+   break;
case V4L2_MBUS_FMT_UYVY8_1X16:
default:
pix-pixelformat = V4L2_PIX_FMT_UYVY;
@@ -261,6 +265,9 @@ void isp_video_pix_to_mbus(const struct v4l2_pix_format 
*pix,
case V4L2_PIX_FMT_YUYV:
mbus-code = V4L2_MBUS_FMT_YUYV8_1X16;
break;
+   case V4L2_PIX_FMT_GREY:
+   mbus-code