Another thing I wanted to do for a long time:
This patch merges the initilization functions for micron_sensors.

GWater

Vasily Khoruzhick schrieb:
On 23 November 2008 17:42:16 GWater wrote:
And here comes the final version (note the slightly different name ;) ).

Please test it - I hope to get this into origin/development soon - this
stuff is the base for new sensors, formats etc.

GWater

Breaks nothing for me.
Here's one more small patch to disable AGC for ov9650 sensor. With AGC enabled image became too noisy, as result compression ratio in videoconf apps are low. It's better to increase exposure value than use AGC.

Regards
Vasily

From a7df65ab27c69295ed58a5b203773495dccf8b44 Mon Sep 17 00:00:00 2001
From: GWater <[EMAIL PROTECTED]>
Date: Sun, 23 Nov 2008 21:44:56 +0100
Subject: [PATCH] Introduce unified micron_initialize() function

        Finally the micron.c merge pays off.

Signed-off-by: GWater <[EMAIL PROTECTED]>
---
 microdia-dev.c |    8 +-
 micron.c       |  520 +++++++++++++++++++++++++-------------------------------
 micron.h       |    6 +-
 3 files changed, 237 insertions(+), 297 deletions(-)

diff --git a/microdia-dev.c b/microdia-dev.c
index a1d6d7f..b276cf2 100644
--- a/microdia-dev.c
+++ b/microdia-dev.c
@@ -87,7 +87,7 @@ static struct sensor_info sensors[] = {
                .id = MT9V111_SENSOR,
                .name = "MT9V111",
                .address = 0x5c,
-               .initialize = mt9v111_initialize,
+               .initialize = micron_initialize,
                .set_hvflip = mt9v111_set_hvflip,
                .set_exposure = mt9v111_set_exposure,
                .set_auto_exposure = mt9v111_set_autoexposure,
@@ -98,7 +98,7 @@ static struct sensor_info sensors[] = {
                .id = MT9M111_SENSOR,
                .name = "MT9M111",
                .address = 0x5d,
-               .initialize = mt9m111_initialize,
+               .initialize = micron_initialize,
                .set_yuv422 = mt9m111_set_yuv422,
                .set_bayer = mt9m111_set_raw,
                .hstart = 6,
@@ -108,7 +108,7 @@ static struct sensor_info sensors[] = {
                .id = MT9V011_SENSOR,
                .name = "MT9V011",
                .address = 0x5d,
-               .initialize = mt9v011_initialize,
+               .initialize = micron_initialize,
                .set_hvflip = mt9v011_set_hvflip,
                .set_exposure = mt9v011_set_exposure,
                .hstart = 2,
@@ -118,7 +118,7 @@ static struct sensor_info sensors[] = {
                .id = MT9M001_SENSOR,
                .name = "MT9M001",
                .address = 0x5d,
-               .initialize = mt9m001_initialize,
+               .initialize = micron_initialize,
                .hstart = 2,
                .vstart = 2,
        },
diff --git a/micron.c b/micron.c
index 664bbba..646f3ac 100644
--- a/micron.c
+++ b/micron.c
@@ -29,361 +29,367 @@
 #include "sn9c20x.h"
 #include "micron.h"
 
-static __u8 mt9v111_init[][3] = {
+struct micron_init {
+       __u8 address;
+       __u16 value;
+};
+
+static struct micron_init mt9v111_init[] = {
                /* 0x0d: Color Correction Register 8 */
-       {0x0d, 0x00, 0x01},
+       {0x0d, 0x0001},
                /* 0x0d: Color Correction Register 8 */
-       {0x0d, 0x00, 0x00},     /* ??? */
+       {0x0d, 0x0000}, /* ??? */
                /* 0x02: Color Correction Register 1 */
-       {0x01, 0x00, 0x01},     /* select IFP address space */
-       {0x02, 0x00, 0x16},     /* ??? */
+       {0x01, 0x0001}, /* select IFP address space */
+       {0x02, 0x0016}, /* ??? */
                /* 0x03: Color Correction Register 3 */
                /* 0x04: Color Correction Register 4 */
-       {0x03, 0x01, 0xe1},     /* ??? */
-       {0x04, 0x02, 0x81},     /* ??? */
+       {0x03, 0x01e1}, /* ??? */
+       {0x04, 0x0281}, /* ??? */
                /* 0x05: Aperture Correction (Sharpening) */
                /* 0x06: Operating Mode Control */
-       {0x05, 0x00, 0x04},     /* 100% sharpening,
+       {0x05, 0x0004}, /* 100% sharpening,
                no automatic sharpness reduction at low light: no sharpening */
-       {0x06, 0x00, 0x00},     /* stop AWB at the current values,
+       {0x06, 0x0000}, /* stop AWB at the current values,
                        no on-the-fly defect correction, no auto exposure */
                /* 0x07: IFP Soft Reset */
                /* 0x08: Output Format Control */
-       {0x07, 0x30, 0x02},     /* reset */
-       {0x08, 0x04, 0x80},     /* bypass entire image processing,
+       {0x07, 0x3002}, /* reset */
+       {0x08, 0x0480}, /* bypass entire image processing,
                                raw 8+2 Bayer data output directly */
-       {0x01, 0x00, 0x04},     /* select sensor address space */
-       {0x02, 0x00, 0x16},     /* start with column 22 */
+       {0x01, 0x0004}, /* select sensor address space */
+       {0x02, 0x0016}, /* start with column 22 */
                /* 0x03: Window Height */
                /* 0x04: Window Width */
-       {0x03, 0x01, 0xe6},     /* 486 */
-       {0x04, 0x02, 0x86},     /* 646 */
+       {0x03, 0x01e6}, /* 486 */
+       {0x04, 0x0286}, /* 646 */
                /* 0x05: Horizontal Blanking */
                /* 0x06: Vertical Blanking */
-       {0x05, 0x00, 0x04},     /* 4 columns (pixel clocks) */
-       {0x06, 0x00, 0x00},     /* 0 rows */
+       {0x05, 0x0004}, /* 4 columns (pixel clocks) */
+       {0x06, 0x0000}, /* 0 rows */
                /* 0x07: Output Control */
                /* 0x08: Row Start */
-       {0x07, 0x30, 0x02},     /* normal operation + chip enable*/
-       {0x08, 0x00, 0x08},     /* row 8 */
+       {0x07, 0x3002}, /* normal operation + chip enable*/
+       {0x08, 0x0008}, /* row 8 */
                /* 0x0c: Shutter Delay */
                /* 0x0d: Reset (Soft) */
-       {0x0c, 0x00, 0x00},     /* 0 master clocks */
-       {0x0d, 0x00, 0x00},     /* return to normal operation */
-       {0x0e, 0x00, 0x00},
-       {0x0f, 0x00, 0x00},
-       {0x10, 0x00, 0x00},
-       {0x11, 0x00, 0x00},
+       {0x0c, 0x0000}, /* 0 master clocks */
+       {0x0d, 0x0000}, /* return to normal operation */
+       {0x0e, 0x0000},
+       {0x0f, 0x0000},
+       {0x10, 0x0000},
+       {0x11, 0x0000},
                /* 0x12: 2X Zoom Col Start
                        => 0x1e bit 0 must be set to activate zoom */
                /* 0x13: 2X Zoom Row Start
                        => 0x1e bit 0 must be set to activate zoom */
-       {0x12, 0x00, 0xb0},     /* column 176 */
-       {0x13, 0x00, 0x7c},     /* row 124 */
-       {0x14, 0x00, 0x00},
-       {0x15, 0x00, 0x00},
-       {0x16, 0x00, 0x00},
-       {0x17, 0x00, 0x00},
-       {0x18, 0x00, 0x00},
-       {0x19, 0x00, 0x00},
-       {0x1a, 0x00, 0x00},
-       {0x1b, 0x00, 0x00},
-       {0x1c, 0x00, 0x00},
-       {0x1d, 0x00, 0x00},
-       {0x30, 0x00, 0x00},
-       {0x30, 0x00, 0x05},
-       {0x31, 0x00, 0x00},
+       {0x12, 0x00b0}, /* column 176 */
+       {0x13, 0x007c}, /* row 124 */
+       {0x14, 0x0000},
+       {0x15, 0x0000},
+       {0x16, 0x0000},
+       {0x17, 0x0000},
+       {0x18, 0x0000},
+       {0x19, 0x0000},
+       {0x1a, 0x0000},
+       {0x1b, 0x0000},
+       {0x1c, 0x0000},
+       {0x1d, 0x0000},
+       {0x30, 0x0000},
+       {0x30, 0x0005},
+       {0x31, 0x0000},
                /* 0x02: Column Start */
                /* 0x03: Window Height */
-       {0x02, 0x00, 0x16},     /* coulmn 22 */
-       {0x03, 0x01, 0xe1},     /* 481 */
+       {0x02, 0x0016}, /* coulmn 22 */
+       {0x03, 0x01e1}, /* 481 */
                /* 0x04: Window Width */
                /* 0x05: Horizontal Blanking */
-       {0x04, 0x02, 0x81},     /* 641 */
-       {0x05, 0x00, 0x04},     /* 4 columns (pixel clocks) */
+       {0x04, 0x0281}, /* 641 */
+       {0x05, 0x0004}, /* 4 columns (pixel clocks) */
                /* 0x06: Vertical Blanking */
                /* 0x07: Output Control */
-       {0x06, 0x00, 0x00},     /* 0 rows */
-       {0x07, 0x30, 0x02},     /* normal operation + chip enable */
+       {0x06, 0x0000}, /* 0 rows */
+       {0x07, 0x3002}, /* normal operation + chip enable */
                /* 0x06: Vertical Blanking */
-       {0x06, 0x00, 0x2d},     /* 45 rows */
+       {0x06, 0x002d}, /* 45 rows */
                /* 0x05: Horizontal Blanking */
-       {0x05, 0x00, 0x04},     /* 4 columns (pixel clocks) */
+       {0x05, 0x0004}, /* 4 columns (pixel clocks) */
                /* 0x09: Shutter Width */
-       {0x09, 0x00, 0x64},     /* integration of 100 rows */
+       {0x09, 0x0064}, /* integration of 100 rows */
                /* 0x2b: Green 1 Gain */
                /* 0x2c: Blue Gain */
-       {0x2b, 0x00, 0xa0},     /* 32*0.03125*2 = 2 */
-       {0x2c, 0x00, 0xa0},     /* 32*0.03125*2 = 2 */
+       {0x2b, 0x00a0}, /* 32*0.03125*2 = 2 */
+       {0x2c, 0x00a0}, /* 32*0.03125*2 = 2 */
                /* 0x2d: Red Gain */
                /* 0x2e: Green 2 Gain */
-       {0x2d, 0x00, 0xa0},     /* 32*0.03125*2 = 2 */
-       {0x2e, 0x00, 0xa0},     /* 32*0.03125*2 = 2 */
+       {0x2d, 0x00a0}, /* 32*0.03125*2 = 2 */
+       {0x2e, 0x00a0}, /* 32*0.03125*2 = 2 */
                /* 0x02: Column Start */
                /* 0x03: Window Hight */
-       {0x02, 0x00, 0x16},     /* coulmn 22 */
-       {0x03, 0x01, 0xe1},     /* 481 */
+       {0x02, 0x0016}, /* coulmn 22 */
+       {0x03, 0x01e1}, /* 481 */
                /* 0x04: Window Width */
                /* 0x05: Horizontal Blanking */
-       {0x04, 0x02, 0x81},     /* 641 */
-       {0x05, 0x00, 0x04},     /* 4 columns (pixel clocks) */
+       {0x04, 0x0281}, /* 641 */
+       {0x05, 0x0004}, /* 4 columns (pixel clocks) */
                /* 0x06: Vertical Blanking */
                /* 0x07: Output Control */
-       {0x06, 0x00, 0x2d},     /* 45 rows */
-       {0x07, 0x30, 0x02},     /* RESERVED options */
+       {0x06, 0x002d}, /* 45 rows */
+       {0x07, 0x3002}, /* RESERVED options */
                /* Writes to0x0e: UNDOCUMENTED */
-       {0x0e, 0x00, 0x08},
+       {0x0e, 0x0008},
                /* 0x06: Vertical Blanking */
-       {0x06, 0x00, 0x2d},     /* 45 rows */
+       {0x06, 0x002d}, /* 45 rows */
                /* 0x05: Horizontal Blanking */
-       {0x05, 0x00, 0x04},     /* 4 columns (pixel clocks) */
+       {0x05, 0x0004}, /* 4 columns (pixel clocks) */
 };
 
-static __u8 mt9v011_init[][3] = {
+static struct micron_init mt9v011_init[] = {
        /* 0x07: Output Control */
-       {0x07, 0x00, 0x02},     /*  chip enable, normal operation */
+       {0x07, 0x0002}, /*  chip enable, normal operation */
        /* 0x0d: Soft Reset */
-       {0x0d, 0x00, 0x01},     /*  reset */
+       {0x0d, 0x0001}, /*  reset */
        /* 0x0d: Soft Reset */
-       {0x0d, 0x00, 0x00},     /*  resume operation */
+       {0x0d, 0x0000}, /*  resume operation */
        /* 0x01: Row start */
        /* 0x02: Column Start */
-       {0x01, 0x00, 0x08},     /*  start with row 8 */
-       {0x02, 0x00, 0x16},     /*  start with column 22 */
+       {0x01, 0x0008}, /*  start with row 8 */
+       {0x02, 0x0016}, /*  start with column 22 */
        /* 0x03: Window Height */
        /* 0x04: Window Width */
-       {0x03, 0x01, 0xe1},     /*  481 */
-       {0x04, 0x02, 0x81},     /*  641 */
+       {0x03, 0x01e1}, /*  481 */
+       {0x04, 0x0281}, /*  641 */
        /* 0x05: Horizontal Blanking */
        /* 0x06: Vertical Blanking */
-       {0x05, 0x00, 0x83},     /*  131 columns (pixel clocks) */
-       {0x06, 0x00, 0x06},     /*  6 rows */
+       {0x05, 0x0083}, /*  131 columns (pixel clocks) */
+       {0x06, 0x0006}, /*  6 rows */
        /* 0x0d: Soft Reset */
-       {0x0d, 0x00, 0x02},     /*  UNKNOWN */
+       {0x0d, 0x0002}, /*  UNKNOWN */
        /* 0x0a: Pixel Clock Speed */
        /* 0x0b: Frame Restart */
-       {0x0a, 0x00, 0x00},     /*  default */
-       {0x0b, 0x00, 0x00},     /*  (has no effect/no restart) */
+       {0x0a, 0x0000}, /*  default */
+       {0x0b, 0x0000}, /*  (has no effect/no restart) */
        /* 0x0c: Shutter Delay */
        /* 0x0d: Soft Reset */
-       {0x0c, 0x00, 0x00},     /*  0 master clocks */
-       {0x0d, 0x00, 0x00},     /*  resume operation */
-       {0x0e, 0x00, 0x00},
-       {0x0f, 0x00, 0x00},
-       {0x10, 0x00, 0x00},
-       {0x11, 0x00, 0x00},
+       {0x0c, 0x0000}, /*  0 master clocks */
+       {0x0d, 0x0000}, /*  resume operation */
+       {0x0e, 0x0000},
+       {0x0f, 0x0000},
+       {0x10, 0x0000},
+       {0x11, 0x0000},
        /* 0x12: 2X Zoom Column Start (from MT9V111 datasheet) */
        /* 0x13: 2X Zoom Row Start (from MT9V111 datasheet) */
-       {0x12, 0x00, 0x00},
+       {0x12, 0x0000},
        /*  column 0 => bit0 of reg 0x1e must be set to activate zoom */
-       {0x13, 0x00, 0x00},
+       {0x13, 0x0000},
        /*  row 0    => bit0 of reg 0x1e must be set to activate zoom */
-       {0x14, 0x00, 0x00},
-       {0x15, 0x00, 0x00},
-       {0x16, 0x00, 0x00},
-       {0x17, 0x00, 0x00},
-       {0x18, 0x00, 0x00},
-       {0x19, 0x00, 0x00},
-       {0x1a, 0x00, 0x00},
-       {0x1b, 0x00, 0x00},
-       {0x1c, 0x00, 0x00},
-       {0x1d, 0x00, 0x00},
-       {0x32, 0x00, 0x00},
+       {0x14, 0x0000},
+       {0x15, 0x0000},
+       {0x16, 0x0000},
+       {0x17, 0x0000},
+       {0x18, 0x0000},
+       {0x19, 0x0000},
+       {0x1a, 0x0000},
+       {0x1b, 0x0000},
+       {0x1c, 0x0000},
+       {0x1d, 0x0000},
+       {0x32, 0x0000},
        /* 0x20: Read Mode */
-       {0x20, 0x11, 0x01},     /*  output all frames (including bad frames) */
-       {0x21, 0x00, 0x00},
-       {0x22, 0x00, 0x00},
-       {0x23, 0x00, 0x00},
-       {0x24, 0x00, 0x00},
-       {0x25, 0x00, 0x00},
-       {0x26, 0x00, 0x00},
-       {0x27, 0x00, 0x24},
-       {0x2f, 0xf7, 0xb0},
-       {0x30, 0x00, 0x05},
-       {0x31, 0x00, 0x00},
-       {0x32, 0x00, 0x00},
-       {0x33, 0x00, 0x00},
-       {0x34, 0x01, 0x00},
-       {0x3d, 0x06, 0x8f},
-       {0x40, 0x01, 0xe0},
-       {0x41, 0x00, 0xd1},
-       {0x44, 0x00, 0x82},
-       {0x5a, 0x00, 0x00},
-       {0x5b, 0x00, 0x00},
-       {0x5c, 0x00, 0x00},
-       {0x5d, 0x00, 0x00},
-       {0x5e, 0x00, 0x00},
-       {0x5f, 0xa3, 0x1d},
-       {0x62, 0x06, 0x11},
+       {0x20, 0x1101}, /*  output all frames (including bad frames) */
+       {0x21, 0x0000},
+       {0x22, 0x0000},
+       {0x23, 0x0000},
+       {0x24, 0x0000},
+       {0x25, 0x0000},
+       {0x26, 0x0000},
+       {0x27, 0x0024},
+       {0x2f, 0xf7b0},
+       {0x30, 0x0005},
+       {0x31, 0x0000},
+       {0x32, 0x0000},
+       {0x33, 0x0000},
+       {0x34, 0x0100},
+       {0x3d, 0x068f},
+       {0x40, 0x01e0},
+       {0x41, 0x00d1},
+       {0x44, 0x0082},
+       {0x5a, 0x0000},
+       {0x5b, 0x0000},
+       {0x5c, 0x0000},
+       {0x5d, 0x0000},
+       {0x5e, 0x0000},
+       {0x5f, 0xa31d},
+       {0x62, 0x0611},
        /* 0x0a: Pixel Clock Speed */
-       {0x0a, 0x00, 0x00},     /*  default */
+       {0x0a, 0x0000}, /*  default */
        /* 0x06: Vertical Blanking */
-       {0x06, 0x00, 0x29},     /*  41 rows */
+       {0x06, 0x0029}, /*  41 rows */
        /* 0x05: Horizontal Blanking */
-       {0x05, 0x00, 0x09},     /*  9 columns (pixel clocks) */
+       {0x05, 0x0009}, /*  9 columns (pixel clocks) */
        /* 0x20: Read Mode */
-       {0x20, 0x11, 0x01},     /*  output all frames (including bad ones) */
+       {0x20, 0x1101}, /*  output all frames (including bad ones) */
        /* 0x20: Read Mode */
-       {0x20, 0x11, 0x01},     /*  output all frames (including bad ones) */
+       {0x20, 0x1101}, /*  output all frames (including bad ones) */
        /* 0x09: Shutter Width */
-       {0x09, 0x00, 0x64},     /*  integration of 100 rows */
+       {0x09, 0x0064}, /*  integration of 100 rows */
        /* 0x07: Output Control */
-       {0x07, 0x00, 0x03},
+       {0x07, 0x0003},
        /*  dont update changes until bit0=0, chip enable, normal operation */
        /* 0x2b: Green 1 Gain */
        /* 0x2c: Blue Gain */
-       {0x2b, 0x00, 0x33},     /*  51*0.03125*1 = 1.59375 */
-       {0x2c, 0x00, 0xa0},     /*  32*0.03125*2 = 2 */
+       {0x2b, 0x0033}, /*  51*0.03125*1 = 1.59375 */
+       {0x2c, 0x00a0}, /*  32*0.03125*2 = 2 */
        /* 0x2d: Red Gain */
        /* 0x2e: Green 2 Gain */
-       {0x2d, 0x00, 0xa0},     /*  32*0.03125*2 = 2 */
-       {0x2e, 0x00, 0x33},     /*  51*0.03125*1 = 1.59375 */
+       {0x2d, 0x00a0}, /*  32*0.03125*2 = 2 */
+       {0x2e, 0x0033}, /*  51*0.03125*1 = 1.59375 */
        /* 0x07: Output Control */
-       {0x07, 0x00, 0x02},     /*  chip enable, normal operation */
+       {0x07, 0x0002}, /*  chip enable, normal operation */
        /* 0x0a: Pixel Clock Speed */
-       {0x06, 0x00, 0x00},     /*  default */
+       {0x06, 0x0000}, /*  default */
        /* 0x06: Vertical Blanking */
-       {0x06, 0x00, 0x29},     /*  41 rows */
+       {0x06, 0x0029}, /*  41 rows */
        /* 0x05: Horizontal Blanking */
-       {0x05, 0x00, 0x09},     /*  9 columns (pixel clocks) */
+       {0x05, 0x0009}, /*  9 columns (pixel clocks) */
 };
 
-static __u8 mt9m111_init[][3] = {
+static struct micron_init mt9m111_init[] = {
        /* Reset sensor */
-       {0x0d, 0x00, 0x08},
-       {0x0d, 0x00, 0x09},
-       {0x0d, 0x00, 0x08},
+       {0x0d, 0x0008},
+       {0x0d, 0x0009},
+       {0x0d, 0x0008},
        /* Select Page map 0x01
         * This means  all new writes now have the address prefix 0x1.
         * Example: 0x3a becomes 0x13a. */
-       {0xf0, 0x00, 0x01},
+       {0xf0, 0x0001},
        /** Select output format:
         * - output raw bayer (8+2 bit)
         * FIXME: There are nearly all YUV and RGB variants possible.
         * Maybe we should use them.
         */
-       {0x3a, 0x73, 0x00},
+       {0x3a, 0x7300},
        /* measure atoexposure through a mix of both possible windows */
-       {0x06, 0x30, 0x8c},
+       {0x06, 0x308c},
        /* Switch back to Page map 0x00 */
-       {0xf0, 0x00, 0x00},
+       {0xf0, 0x0000},
        /* The following set the resoutiona and window size.
         * It's a bit more than SXGA.
         * VSTART */
-       {0x01, 0x00, 0x0e},
+       {0x01, 0x000e},
        /* HSTART */
-       {0x02, 0x00, 0x14},
+       {0x02, 0x0014},
        /* VSIZE */
-       {0x03, 0x03, 0xc4},
+       {0x03, 0x03c4},
        /* HSIZE */
-       {0x04, 0x05, 0x14},
+       {0x04, 0x0514},
        /* Blanking */
-       {0xc8, 0x00, 0x03},
-       {0x0a, 0x00, 0x01},
-       {0x06, 0x00, 0x29},
-       {0x05, 0x00, 0x72},
-       {0x20, 0x00, 0x00},
-       {0x20, 0x00, 0x00},
+       {0xc8, 0x0003},
+       {0x0a, 0x0001},
+       {0x06, 0x0029},
+       {0x05, 0x0072},
+       {0x20, 0x0000},
+       {0x20, 0x0000},
        /* Shutter width */
-       {0x09, 0x01, 0x90},
+       {0x09, 0x0190},
        /* Protect settings */
-       {0x0d, 0x80, 0x08},
+       {0x0d, 0x8008},
        /* Green 1 gain */
-       {0x2b, 0x01, 0x88},
+       {0x2b, 0x0188},
        /* Blue gain */
-       {0x2c, 0x01, 0x88},
+       {0x2c, 0x0188},
        /* Red gain */
-       {0x2d, 0x01, 0x88},
+       {0x2d, 0x0188},
        /* Green 2 gain */
-       {0x2e, 0x01, 0x88},
+       {0x2e, 0x0188},
        /* Blanking (again?) */
-       {0x0a, 0x00, 0x01},
-       {0x06, 0x00, 0x29},
-       {0x05, 0x00, 0x72},
+       {0x0a, 0x0001},
+       {0x06, 0x0029},
+       {0x05, 0x0072},
 };
 
-static __u8 mt9m001_init[][3] = {
-       {0x07, 0x00, 0x00}, {0x07, 0x00, 0x02}, {0x0d, 0x00, 0x01},
-       {0x0d, 0x00, 0x00}, {0x01, 0x00, 0x0e}, {0x02, 0x00, 0x14},
-       {0x03, 0x03, 0xc1}, {0x04, 0x05, 0x01}, {0x05, 0x00, 0x83},
-       {0x06, 0x00, 0x06}, {0x0d, 0x00, 0x02}, {0x09, 0x00, 0x00},
-       {0x0a, 0x00, 0x00}, {0x0b, 0x00, 0x00}, {0x0c, 0x00, 0x00},
-       {0x11, 0x00, 0x00}, {0x1e, 0x80, 0x00}, {0x20, 0x11, 0x05},
-       {0x2b, 0x00, 0x08}, {0x2c, 0x00, 0x10}, {0x2d, 0x00, 0x14},
-       {0x2e, 0x00, 0x08}, {0x5f, 0x89, 0x04}, {0x60, 0x00, 0x00},
-       {0x61, 0x00, 0x00}, {0x62, 0x04, 0x98}, {0x63, 0x00, 0x00},
-       {0x68, 0x00, 0x00}, {0x20, 0x11, 0x1d}, {0x06, 0x00, 0xf2},
-       {0x05, 0x00, 0x13}, {0x20, 0x11, 0x1d}, {0x20, 0x11, 0x1d},
-       {0x07, 0x00, 0x03}, {0x2b, 0x00, 0x10}, {0x2c, 0x00, 0x10},
-       {0x2d, 0x00, 0x10}, {0x2e, 0x00, 0x10}, {0x07, 0x00, 0x02},
-       {0x07, 0x00, 0x03}, {0x2c, 0x00, 0x1d}, {0x2d, 0x00, 0x1d},
-       {0x07, 0x00, 0x02}, {0x06, 0x00, 0xf2}, {0x05, 0x00, 0x13},
-       {0x09, 0x03, 0x87}, {0x07, 0x00, 0x03}, {0x2b, 0x00, 0x28},
-       {0x2c, 0x00, 0x3f}, {0x2d, 0x00, 0x3f}, {0x2e, 0x00, 0x28},
-       {0x07, 0x00, 0x02}, {0x09, 0x04, 0xf1}, {0x07, 0x00, 0x03},
-       {0x2b, 0x00, 0x24}, {0x2c, 0x00, 0x39}, {0x2d, 0x00, 0x39},
-       {0x2e, 0x00, 0x24}, {0x07, 0x00, 0x02},
+static struct micron_init mt9m001_init[] = {
+       {0x07, 0x0000}, {0x07, 0x0002}, {0x0d, 0x0001}, {0x0d, 0x0000},
+       {0x01, 0x000e}, {0x02, 0x0014}, {0x03, 0x03c1}, {0x04, 0x0501},
+       {0x05, 0x0083}, {0x06, 0x0006}, {0x0d, 0x0002}, {0x09, 0x0000},
+       {0x0a, 0x0000}, {0x0b, 0x0000}, {0x0c, 0x0000}, {0x11, 0x0000},
+       {0x1e, 0x8000}, {0x20, 0x1105}, {0x2b, 0x0008}, {0x2c, 0x0010},
+       {0x2d, 0x0014}, {0x2e, 0x0008}, {0x5f, 0x8904}, {0x60, 0x0000},
+       {0x61, 0x0000}, {0x62, 0x0498}, {0x63, 0x0000}, {0x68, 0x0000},
+       {0x20, 0x111d}, {0x06, 0x00f2}, {0x05, 0x0013}, {0x20, 0x111d},
+       {0x20, 0x111d}, {0x07, 0x0003}, {0x2b, 0x0010}, {0x2c, 0x0010},
+       {0x2d, 0x0010}, {0x2e, 0x0010}, {0x07, 0x0002}, {0x07, 0x0003},
+       {0x2c, 0x001d}, {0x2d, 0x001d}, {0x07, 0x0002}, {0x06, 0x00f2},
+       {0x05, 0x0013}, {0x09, 0x0387}, {0x07, 0x0003}, {0x2b, 0x0028},
+       {0x2c, 0x003f}, {0x2d, 0x003f}, {0x2e, 0x0028}, {0x07, 0x0002},
+       {0x09, 0x04f1}, {0x07, 0x0003}, {0x2b, 0x0024}, {0x2c, 0x0039},
+       {0x2d, 0x0039}, {0x2e, 0x0024}, {0x07, 0x0002},
 };
 
 /**
- * @brief Initialize mt9v011 sensors
+ * @brief Initialize micron sensors
  *
  * @param dev Pointer to device structure
  *
  * @return 0 or negative error code
  *
  */
-int  mt9v011_initialize(struct usb_microdia *dev)
+int micron_initialize(struct usb_microdia *dev)
 {
        int i;
        int ret = 0;
-       __u8 value[2], reg;
-       for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) {
-               reg = mt9v011_init[i][0];
-               value[0] = mt9v011_init[i][1];
-               value[1] = mt9v011_init[i][2];
-               ret = sn9c20x_write_i2c_data(dev, 2, reg, value);
-               if (ret < 0) {
-                       UDIA_WARNING("Sensor Init Error (%d). "
-                               "line %d\n", ret, i);
-                       break;
+       __u16 value;
+
+       switch (dev->camera.sensor->id) {
+       case MT9V111_SENSOR:
+               mt9v111_select_address_space(dev, MT9V111_ADDRESSSPACE_IFP);
+               for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) {
+                       ret = sn9c20x_write_i2c_data16(dev, 1,
+                               mt9v111_init[i].address,
+                               &(mt9v111_init[i].value));
+                       if (ret < 0)
+                               goto err;
                }
-       }
-
-       return ret;
-}
-
-/**
- * @brief Initialize mt9v111 sensors
- *
- * @param dev Pointer to device structure
- *
- * @return 0 or negative error code
- *
- */
-int  mt9v111_initialize(struct usb_microdia *dev)
-{
-       int i;
-       int ret = 0;
-       __u8 value[2], reg;
-       mt9v111_select_address_space(dev, MT9V111_ADDRESSSPACE_IFP);
-
-       for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) {
-               reg = mt9v111_init[i][0];
-               value[0] = mt9v111_init[i][1];
-               value[1] = mt9v111_init[i][2];
-               ret = sn9c20x_write_i2c_data(dev, 2, reg, value);
-               if (ret < 0) {
-                       UDIA_WARNING("Sensor Init Error (%d). "
-                               "line %d\n", ret, i);
-                       break;
+               mt9v111_setup_autoexposure(dev);
+               mt9v111_setup_autowhitebalance(dev);
+               mt9v111_set_autocorrections(dev, 1);
+       break;
+       case MT9M111_SENSOR:
+               value = 0x0000;
+               sn9c20x_write_i2c_data16(dev, 2, 0xf0, &value);
+               for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) {
+                       ret = sn9c20x_write_i2c_data16(dev, 1,
+                               mt9m111_init[i].address,
+                               &(mt9m111_init[i].value));
+                       if (ret < 0)
+                               goto err;
+               }
+       break;
+       case MT9V011_SENSOR:
+               for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) {
+                       ret = sn9c20x_write_i2c_data16(dev, 1,
+                               mt9v011_init[i].address,
+                               &(mt9v011_init[i].value));
+                       if (ret < 0)
+                               goto err;
                }
+       break;
+       case MT9M001_SENSOR:
+               for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
+                       ret = sn9c20x_write_i2c_data16(dev, 1,
+                               mt9m001_init[i].address,
+                               &(mt9m001_init[i].value));
+                       if (ret < 0)
+                               goto err;
+               }
+       break;
+       default:
+               return -EINVAL;
        }
 
-       mt9v111_setup_autoexposure(dev);
-       mt9v111_setup_autowhitebalance(dev);
-       mt9v111_set_autocorrections(dev, 1);
+       return ret;
 
+err:
+       UDIA_ERROR("Sensor Init failed (%d)! - line %d\n", ret, i);
        return ret;
 }
 
@@ -484,68 +490,6 @@ int micron_probe(struct usb_microdia *dev)
        return -EINVAL;
 }
 
-/**
- * @brief Initialize mt9m111 sensors
- *
- * @param dev Pointer to device structure
- *
- * @return 0 or negative error code
- *
- */
-int mt9m001_initialize(struct usb_microdia *dev)
-{
-       int i;
-       int ret = 0;
-       __u8 value[2], reg;
-
-       for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
-               reg = mt9m001_init[i][0];
-               value[0] = mt9m001_init[i][1];
-               value[1] = mt9m001_init[i][2];
-               ret = sn9c20x_write_i2c_data(dev, 2, reg, value);
-               if (ret < 0) {
-                       UDIA_WARNING("Sensor Init Error (%d). "
-                               "line %d\n", ret, i);
-                       break;
-               }
-       }
-
-       return ret;
-}
-
-/**
- * @brief Initialize mt9m111 sensors
- *
- * @param dev Pointer to device structure
- *
- * @return 0 or negative error code
- *
- */
-int mt9m111_initialize(struct usb_microdia *dev)
-{
-       int i;
-       int ret = 0;
-       __u8 reg;
-       __u8 value[2] = {0x00, 0x00};
-
-       /* Select address-space: Sensor */
-       sn9c20x_write_i2c_data(dev, 2, 0xf0, value);
-
-       for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) {
-               reg = mt9m111_init[i][0];
-               value[0] = mt9m111_init[i][1];
-               value[1] = mt9m111_init[i][2];
-               ret = sn9c20x_write_i2c_data(dev, 2, reg, value);
-               if (ret < 0) {
-                       UDIA_WARNING("Sensor Init Error (%d). "
-                               "line %d\n", ret, i);
-                       break;
-               }
-       }
-
-       return ret;
-}
-
 int mt9m111_set_raw(struct usb_microdia *dev)
 {
        __u16 buf;
diff --git a/micron.h b/micron.h
index ea3cac6..2824e6b 100644
--- a/micron.h
+++ b/micron.h
@@ -98,7 +98,6 @@
 #define MT9V111_IFP_AWB_WINBOUNDARY_BOTTOM(x)          (((x/32) & 0xf) << 12)  
/* bottom boundary of AWB meas. window */
 
 int mt9v111_select_address_space(struct usb_microdia *dev, __u8 address_space);
-int mt9v111_initialize(struct usb_microdia *dev);
 int mt9v111_setup_autoexposure(struct usb_microdia *dev);
 int mt9v111_setup_autowhitebalance(struct usb_microdia *dev);
 int mt9v111_set_exposure(struct usb_microdia *dev);
@@ -109,13 +108,10 @@ int mt9v111_set_autocorrections(struct usb_microdia *dev, 
int enable);
 
 int mt9v011_set_exposure(struct usb_microdia *dev);
 int mt9v011_set_hvflip(struct usb_microdia *dev);
-int mt9v011_initialize(struct usb_microdia *dev);
 
 int mt9m111_set_raw(struct usb_microdia *dev);
 int mt9m111_set_yuv422(struct usb_microdia *dev);
-int mt9m111_initialize(struct usb_microdia *dev);
-
-int mt9m001_initialize(struct usb_microdia *dev);
 
 int micron_probe(struct usb_microdia *dev);
+int micron_initialize(struct usb_microdia *dev);
 #endif
-- 
1.5.6.5

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to