From 42662be7e857f8c948bc735f90d1ea7c7fbc55ab Mon Sep 17 00:00:00 2001 From: GWater Date: Tue, 28 Oct 2008 16:22:24 +0100 Subject: [PATCH] Resupport MT9M111 sensors (6242) Signed-off-by: GWater --- Makefile | 2 +- microdia-dev.c | 5 ++ microdia.h | 4 +- mt9m111.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ omnivision.c | 2 +- 5 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 mt9m111.c diff --git a/Makefile b/Makefile index 5778b13..cf15060 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include $(src)/.config microdia-objs := microdia-usb.o microdia-v4l.o microdia-sysfs.o microdia-objs += microdia-dev.o microdia-queue.o -microdia-objs += sn9c20x.o omnivision.o +microdia-objs += sn9c20x.o omnivision.o mt9m111.o ifeq ($(CONFIG_MICRODIA_DEBUGFS),y) microdia-objs += microdia-debugfs.o diff --git a/microdia-dev.c b/microdia-dev.c index 6a100dd..57e29cc 100644 --- a/microdia-dev.c +++ b/microdia-dev.c @@ -61,6 +61,11 @@ struct sensor_info sensors[] = { .name = "OV7670", .probe = ov_probe }, + { + .id = MT9M111_SENSOR, + .name = "MT9M111", + .probe = mt9m111_probe + }, }; /** diff --git a/microdia.h b/microdia.h index e70521e..73e15af 100644 --- a/microdia.h +++ b/microdia.h @@ -306,6 +306,7 @@ enum microdia_sensors { SOI968_SENSOR = 3, OV7660_SENSOR = 4, OV7670_SENSOR = 5, + MT9M111_SENSOR = 6, }; @@ -469,8 +470,9 @@ static inline int microdia_queue_streaming(struct microdia_video_queue *queue) return queue->flags & MICRODIA_QUEUE_STREAMING; } -/* Some general omnivison sensor functions which have no other home */ +/* Some general sensor functions which have no other home */ int ov_probe(struct usb_microdia *dev); int ov_initialize(struct usb_microdia *dev, __u8 ov_init[][2], int array_size); +int mt9m111_probe(struct usb_microdia *dev); #endif diff --git a/mt9m111.c b/mt9m111.c new file mode 100644 index 0000000..87c41af --- /dev/null +++ b/mt9m111.c @@ -0,0 +1,166 @@ +/** + * @file mt9m111.c + * @date 2008-10-28 + * + * @brief Common control functions for Omnivision Image Sensors. + * + * @par Licences + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "microdia.h" +#include "sn9c20x.h" + +static __u8 mt9m111_init[][3] = { + /* Reset sensor */ + {0x0d, 0x00, 0x08}, + {0x0d, 0x00, 0x09}, + {0x0d, 0x00, 0x08}, + /* Select Page map 0x01 + * This means all new writes now have the address prefix 0x1. + * Example: 0x3a becomes 0x13a. */ + {0xf0, 0x00, 0x01}, + /** 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}, + /* measure atoexposure through a mix of both possible windows */ + {0x06, 0x30, 0x8c}, + /* Switch back to Page map 0x00 */ + {0xf0, 0x00, 0x00}, + /* The following set the resoutiona and window size. + * It's a bit more than SXGA. + * VSTART */ + {0x01, 0x00, 0x0e}, + /* HSTART */ + {0x02, 0x00, 0x14}, + /* VSIZE */ + {0x03, 0x03, 0xc4}, + /* HSIZE */ + {0x04, 0x05, 0x14}, + /* Blanking */ + {0xc8, 0x00, 0x03}, + {0x0a, 0x00, 0x01}, + {0x06, 0x00, 0x29}, + {0x05, 0x00, 0x72}, + {0x20, 0x00, 0x00}, + {0x20, 0x00, 0x00}, + /* Shutter width */ + {0x09, 0x01, 0x90}, + /* Protect settings */ + {0x0d, 0x80, 0x08}, + /* Green 1 gain */ + {0x2b, 0x01, 0x88}, + /* Blue gain */ + {0x2c, 0x01, 0x88}, + /* Red gain */ + {0x2d, 0x01, 0x88}, + /* Green 2 gain */ + {0x2e, 0x01, 0x88}, + /* Blanking (again?) */ + {0x0a, 0x00, 0x01}, + {0x06, 0x00, 0x29}, + {0x05, 0x00, 0x72}, +}; + +struct microdia_video_format mt9m111_fmts[] = { + { + .pix_fmt = V4L2_PIX_FMT_SBGGR8, + .desc = "Bayer 8bit (BGGR)", + .depth = 8, + .set_format = sn9c20x_set_raw + }, + { + .pix_fmt = V4L2_PIX_FMT_JPEG, + .desc = "JPEG (YUV 4:2:2)", + .depth = 16, + .set_format = sn9c20x_set_jpeg + } +}; + +struct microdia_video_resolution mt9m111_resolutions[] = { + { + .width = 160, + .height = 120, + .scale = SN9C20X_1_4_SCALE, + .window = {6, 2, 640, 480} + }, + { + .width = 320, + .height = 240, + .scale = SN9C20X_1_2_SCALE, + .window = {6, 2, 640, 480} + }, + { + .width = 640, + .height = 480, + .scale = SN9C20X_NO_SCALE, + .window = {6, 2, 640, 480} + }, +}; + +/** + * @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 value[2], reg; + + 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_INFO("Sensor Init Error (%d). line %d\n", ret, i); + break; + } + } + + return ret; +} + +int mt9m111_probe(struct usb_microdia *dev) +{ + int ret; + __u8 buf[2]; + dev->camera.sensor_slave_address = 0x5d; + ret = sn9c20x_read_i2c_data(dev, 2, 0x00, buf); + if (ret == 0) { + if (buf[0] != 0x14) + return -EINVAL; + if (buf[1] == 0x3a) { + mt9m111_initialize(dev); + dev->camera.modes = mt9m111_resolutions; + dev->camera.nmodes = ARRAY_SIZE(mt9m111_resolutions); + dev->camera.fmts = mt9m111_fmts; + dev->camera.nfmts = ARRAY_SIZE(mt9m111_fmts); + return MT9M111_SENSOR; + } + } else { + UDIA_INFO("Failed on i2c read in mt9m111_probe\n"); + } + return -EINVAL; +} diff --git a/omnivision.c b/omnivision.c index 096dfa4..eb49acd 100644 --- a/omnivision.c +++ b/omnivision.c @@ -1,6 +1,6 @@ /** * @file omnivision.c - * @date 2008-108-27 + * @date 2008-10-27 * * @brief Common control functions for Omnivision Image Sensors. * -- 2.11.4.GIT