Hi everyone, I'm new here. I downloaded the driver from http://repo.or.cz/r/microdia.git. This is a great driver! But the sensor initialize code of MT9M111 is incorrect. After the initialization the sensor's exposure can't be adjust any more.
I uploaded the MT9M111 specification to http://groups.google.com/group/microdia/web/301-6536-MT9M111.pdf In micron.c, the MT9M111 initialize sequence should be replaced with, /*****************************************************************/ struct sn9c20x_i2c_regs mt9m111_init[] = { /* R240:0 0X0F0 - PAGE MAP Bits 2:0 Page mapping register. Must be kept at 0 to be able to Page Map write to/read from sensor. Used in the SOC to access other pages with registers. */ {0xf0, 0x0000}, /* Reset sensor */ {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, 0x0001}, /* R58:1—0X13A - OUTPUT FORMAT CONTROL 2 (A) (R/W) Default 0x0200 Description Output Format Control 2 (A). Bit 14 Output processed Bayer data. Note that to have any effect, this also requires bit 8 of this register to be set. Bit 11 Enables embedding Rec. ITU-R BT.656 synchronization codes into the output data. Bit 10 Entire image processing is bypassed and raw bayer is output directly. In YCbCr or RGB mode: “1”—Bypass IFP and output Imager data directly (full 10 bits). The image data still passes through the camera I/f FIFO and the 10 bits are formatted into two output bytes through the camera interface; I.e. 8+2. Data rate is effectively the same as default 16-bit /per pixel modes. AE/AWB, etc. still function and control the sensor, though they are assuming some gain/correction through the colorpipe. Bit 9 Inverts output pixel clock. By default, this bit it asserted and data is launched off the falling edge of PIXCLK for capture by the receiver on the rising edge. Bit 8 Enables RGB output. “1”—Output RGB format data as defined by OutputFormatControl2AReg[7:6] (R58:1[7:6]). Bits 7:6 RGB output format: “00”—16-bit RGB565. “01”—15-bit RGB555. “10”—12-bit RGB444x. “11”—12-bit RGBx444. Bits 5:4 Test Ramp output: “00”—off. “01”—by column. “10”—by row. “11”—by frame. Bit 3 Outputs RGB or YCbCr values are shifted 3 bits up. Use with R58:1[5:4] to test LCDs with low color depth. Bit 2 Averages two nearby Chrominance bytes. Bit 1 In YCbCr mode swap C and Y bytes. In RGB mode, swap odd and even bytes. Bit 0 In YCbCr mode, swaps Cb and Cr channels. In RGB mode, swaps R and B channels. */ {0x3a, 0x7300}, /* R6:1—0X106 - OPERATING MODE CONTROL (R/W) Default 0x700E Description This register specifies the operating mode of the IFP. Bit 15 Enables manual white balance. User can set the base matrix and color channel gains. This bit must be asserted and de-asserted with a frame in between to force new color-correction settings to take effect. Bit 14 Enables Auto Exposure Bit 13 Enables on-the-fly defect correction Bit 12 Clips aperture corrections. Small aperture corrections (< 8) are attenuated to reduce noise amplification. Bit 11 Load color-correction matrix “1”—in manual white balance mode, triggers the loading of a new base matrix into color correction and the loading of new base sensor gain ratios. “0”—enables the matrix to be changed “off-line.” Bit 10 Enables lens shading correction. “1”—enables lens shading correction. Bit 7 Enables flicker detection. “1”—enables automatic flicker detection. Bit 4 Bypasses color-correction matrix. “1”— outputs “raw” color bypassing color correction. “0”— normal color processing. Bits 3:2 Auto Exposure back light compensation control. “00”—AE sampling window is specified by R38:2 and R39:2 (“large window”). “01”—AE sampling window is specified by R43:2 and R44:2 (“small window”). “1X”—AE sampling window is specified by the weighted sum of the “large window” and the “small window”, with the “small window” weighted four times more heavily. Bit 1 Enables auto white balance. “1”—enables auto white balance. “0”—freezes white balance at current values. Bit 0 Reserved for future expansion. */ {0x06, 0x708e}, /* Switch back to Page map 0x00 */ {0xf0, 0x0000}, {0xff, 0xffff}, }; /*****************************************************************/ Then the camera can be set to auto exposure mode. And MT9M111 sensor control functions are also missing in the repository. I attached the exposure control and white balance control function below. Anyone who can review the code and put it into the repository will be greatly appreciated. sn9c20x-dev.c /*****************************************************************/ int (*sn_probes[])(struct usb_sn9c20x *dev) = { mt9v011_probe, mt9v111_probe, mt9v112_probe, mt9m111_probe, }; ... case MT9M111_SENSOR: sn9c20x_write_i2c_array(dev, mt9m111_init, 1); dev->camera.set_exposure = mt9m111_set_exposure; dev->camera.set_auto_exposure = mt9m111_set_autoexposure; dev->camera.set_auto_whitebalance = mt9m111_set_autowhitebalance; dev->camera.hstart = 6; dev->camera.vstart = 2; UDIA_INFO("Detected MT9M111 Sensor.\n"); break; /*****************************************************************/ micron.h /*****************************************************************/ int mt9m111_probe(struct usb_sn9c20x *dev); int mt9m111_set_exposure(struct usb_sn9c20x *dev); int mt9m111_set_autoexposure(struct usb_sn9c20x *dev); int mt9m111_set_autowhitebalance(struct usb_sn9c20x *dev); /*****************************************************************/ micron.c /*****************************************************************/ int mt9m111_probe(struct usb_sn9c20x *dev) { __u16 buf; int ret = -EINVAL; dev->camera.address = 0x5d; ret = sn9c20x_read_i2c_data16(dev, 2, 0xff, &buf); if ((ret == 0) && (buf == 0x143a)) ret = MT9M111_SENSOR; return ret; } int mt9m111_set_exposure(struct usb_sn9c20x *dev) { int ret = 0; int page=0; int exposure; /* The exposure value can range from 0 to 65535. * If there is a lot of light, we can use zero, and there will be a super fast streaming. * If we use 65535, I/O will timeout. */ exposure=dev->vsettings.exposure*10; // from 0 to 2550 //UDIA_INFO("Set exposure %d\n",exposure); ret |= sn9c20x_write_i2c_data16(dev, 1, 0xF0, &page); // Change to page 0 ret |= sn9c20x_write_i2c_data16(dev, 1, 0x09, &exposure); return ret; } int mt9m111_set_autoexposure(struct usb_sn9c20x *dev) { __u16 buf[1]; int page = 0; int ret = 0; int data = 0x3080; /* Description This register specifies the operating mode of the IFP. Bit 15 Enables manual white balance. User can set the base matrix and color channel gains. This bit must be asserted and de-asserted with a frame in between to force new color-correction settings to take effect. Bit 14 Enables Auto Exposure Bit 13 Enables on-the-fly defect correction Bit 12 Clips aperture corrections. Small aperture corrections (< 8) are attenuated to reduce noise amplification. Bit 11 Load color-correction matrix “1”—in manual white balance mode, triggers the loading of a new base matrix into color correction and the loading of new base sensor gain ratios. “0”—enables the matrix to be changed “off-line.” Bit 10 Enables lens shading correction. “1”—enables lens shading correction. Bit 9 Reserved. Bit 8 Reserved. Bit 7 Enables flicker detection. “1”—enables automatic flicker detection. Bit 6 Reserved for future expansion. Bit 5 Reserved Bit 4 Bypasses color-correction matrix. “1”— outputs “raw” color bypassing color correction. “0”— normal color processing. Bits 3:2 Auto Exposure back light compensation control. “00”—AE sampling window is specified by R38:2 and R39:2 (“large window”). “01”—AE sampling window is specified by R43:2 and R44:2 (“small window”). “1X”—AE sampling window is specified by the weighted sum of the “large window” and the “small window”, with the “small window” weighted four times more heavily. Bit 1 Enables auto white balance. “1”—enables auto white balance. “0”—freezes white balance at current values. Bit 0 Reserved for future expansion. */ UDIA_INFO("Set auto exposure %d white balance %d\n",dev- >vsettings.auto_exposure,dev->vsettings.auto_whitebalance); /* Set new value for register 0x06: */ switch (dev->vsettings.auto_exposure) { case V4L2_EXPOSURE_AUTO: //enable auto exposure data|=0x7000; /*AE sampling window is specified by the weighted sum of the “large window” and the “small window”, with the “small window” weighted four times more heavily.*/ data|=0x000C; break; case V4L2_EXPOSURE_MANUAL: data&=~0x7000; break; case V4L2_EXPOSURE_SHUTTER_PRIORITY: //enable auto exposure data|=0x7000; //“00”—AE sampling window is specified by R38:2 and R39:2 (“large window”). data&=~0x000C; break; case V4L2_EXPOSURE_APERTURE_PRIORITY: //enable auto exposure data|=0x7000; //“01”—AE sampling window is specified by R43:2 and R44:2 (“small window”). data&=~0x000C; data|=0x0004; break; default: return -EINVAL; } if (dev->vsettings.auto_whitebalance == 1) { data|=0x0002; } else if (dev->vsettings.auto_whitebalance == 0) { data&=~0x0002; } page=1; ret |= sn9c20x_write_i2c_data16(dev, 1, 0xF0, &page); // Change to page 1 ret |= sn9c20x_write_i2c_data16(dev, 1, 0x06, &data); // Write register 0x106 page=0; ret |= sn9c20x_write_i2c_data16(dev, 1, 0xF0, &page); // Change to page 0 if (ret < 0) { UDIA_ERROR("Error: setting of auto exposure failed: " "error while writing to IFP-register 0x06\n"); return ret; } return 0; } int mt9m111_set_autowhitebalance(struct usb_sn9c20x *dev) { int ret = 0; ret = mt9m111_set_autoexposure(dev); return 0; } /*****************************************************************/ --~--~---------~--~----~------------~-------~--~----~ Lets make microdia webcams plug'n play, (currently plug'n pray) To post to this group, send email to [email protected] Visit us online https://groups.google.com/group/microdia -~----------~----~----~----~------~----~------~--~---
