Micron MT9M111 driver
These patches begin the cycle of Micron MT9M111 camera chip support. The driver is quite simple compared to the possibilities of the chip, but provides good ground for video capture with this chip.
These patches follow the patch serie about soc_camera and pxa_camera suspend/resume in Guennadi's tree.
Happy review.
--
Robert
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 1/2 Add Micron mt9m111 chip ID in V4L2 identifiers
--- include/media/v4l2-chip-ident.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/media/v4l2-chip-ident.h +1 -0
@@ -161,6 +161,7 @@ enum {/* Micron CMOS sensor chips: 45000-45099 */ V4L2_IDENT_MT9M001C12ST =45000 ,V4L2_IDENT_MT9M001C12STM =45005 , +V4L2_IDENT_MT9M111 =45007 ,V4L2_IDENT_MT9V022IX7ATC =45010 ,/* No way to detect "normal" I77ATx */ V4L2_IDENT_MT9V022IX7ATM = 45015, /* and "lead free" IA7ATx chips */ };
Signature · 6 lines
1.5.5.3 -- video4linux-list mailing list Unsubscribe mailto:[email protected]?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 2/2 Add support for Micron MT9M111 camera.
Adds support for Micron MT9M111 camera chip, with basic features :
- view rectangle configurable
- some output formats (bayer8, bayer10, rgb565, rgb555, ycbycr)
- autoexposure
- only highpower mode context used (ie. context B)
--- drivers/media/video/Kconfig | 6 + drivers/media/video/Makefile | 1 + drivers/media/video/mt9m111.c | 962 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 969 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/mt9m111.c
drivers/media/video/Kconfig +6 -0
@@ -938,6 +938,12 @@ config MT9M001_PCA9536_SWITCH Select this if your MT9M001 camera uses a PCA9536 I2C GPIO extender to switch between 8 and 10 bit datawidth modes +config SOC_CAMERA_MT9M111 + tristate "mt9m001 support" + depends on SOC_CAMERA && I2C + help + This driver supports MT9M111 cameras from Micron + config SOC_CAMERA_MT9V022 tristate "mt9v022 support" depends on SOC_CAMERA && I2C
drivers/media/video/Makefile +1 -0
@@ -137,6 +137,7 @@ obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o obj-$(CONFIG_SOC_CAMERA) += soc_camera.o obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o +obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o
drivers/media/video/mt9m111.c new file +962 -0
962 lines not on this page · raw message
Signature · 6 lines
1.5.5.3 -- video4linux-list mailing list Unsubscribe mailto:[email protected]?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list
Re: [PATCH 2/2] Add support for Micron MT9M111 camera.
Nice! Not knowing this specific camera, I can only provide a couple of nitpicks:
Quoted 19 lines · Robert Jarzmik
drivers/media/video/mt9m111.c new file +13
-0@@ -0,0 +1,962 @@ +/* +* Driver for MT9M111 CMOS Image Sensor from Micron +* +* Copyright (C) 2008, Robert Jarzmik <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#include <linux/videodev2.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include <linux/log2.h>
drivers/media/video/mt9m111.c line 23
Quoted 10 lines
drivers/media/video/mt9m111.c new file +10
-0+#include <linux/gpio.h> +#include <linux/delay.h> + +#include <media/v4l2-common.h> +#include <media/v4l2-chip-ident.h> +#include <media/soc_camera.h> + +/* mt9m111 i2c address is 0x5d or 0x48 (depending on SAddr pin) +* The platform has to define i2c_board_info +* and call i2c_register_board_info() */
Please reformat this comment to
/*
* mt9m111 i2c address is 0x5d or 0x48 (depending on SAddr pin)
* The platform has to define i2c_board_info
* and call i2c_register_board_info()
*/
or similar
Quoted 77 lines
drivers/media/video/mt9m111.c new file +77
-0+ +/* mt9m111: Sensor register addresses */ +#define MT9M111_CHIP_VERSION 0x000 +#define MT9M111_ROW_START 0x001 +#define MT9M111_COLUMN_START 0x002 +#define MT9M111_WINDOW_HEIGHT 0x003 +#define MT9M111_WINDOW_WIDTH 0x004 +#define MT9M111_HORIZONTAL_BLANKING_B 0x005 +#define MT9M111_VERTICAL_BLANKING_B 0x006 +#define MT9M111_HORIZONTAL_BLANKING_A 0x007 +#define MT9M111_VERTICAL_BLANKING_A 0x008 +#define MT9M111_SHUTTER_WIDTH 0x009 +#define MT9M111_ROW_SPEED 0x00a +#define MT9M111_EXTRA_DELAY 0x00b +#define MT9M111_SHUTTER_DELAY 0x00c +#define MT9M111_RESET 0x00d +#define MT9M111_READ_MODE_B 0x020 +#define MT9M111_READ_MODE_A 0x021 +#define MT9M111_FLASH_CONTROL 0x023 +#define MT9M111_GREEN1_GAIN 0x02b +#define MT9M111_BLUE_GAIN 0x02c +#define MT9M111_RED_GAIN 0x02d +#define MT9M111_GREEN2_GAIN 0x02e +#define MT9M111_GLOBAL_GAIN 0x02f +#define MT9M111_CONTEXT_CONTROL 0x0c8 +#define MT9M111_PAGE_MAP 0x0f0 +#define MT9M111_BYTE_WISE_ADDR 0x0f1 + +#define MT9M111_RESET_SYNC_CHANGES (1<<15) +#define MT9M111_RESET_RESTART_BAD_FRAME (1<<9) +#define MT9M111_RESET_SHOW_BAD_FRAMES (1<<8) +#define MT9M111_RESET_RESET_SOC (1<<5) +#define MT9M111_RESET_OUTPUT_DISABLE (1<<4) +#define MT9M111_RESET_CHIP_ENABLE (1<<3) +#define MT9M111_RESET_ANALOG_STANDBY (1<<2) +#define MT9M111_RESET_RESTART_FRAME (1<<1) +#define MT9M111_RESET_RESET_MODE (1<<0) + +#define MT9M111_RMB_MIRROR_COLS (1<<1) +#define MT9M111_RMB_MIRROR_ROWS (1<<0) +#define MT9M111_CTXT_CTRL_RESTART (1<<15) +#define MT9M111_CTXT_CTRL_DEFECTCOR_B (1<<12) +#define MT9M111_CTXT_CTRL_RESIZE_B (1<<10) +#define MT9M111_CTXT_CTRL_CTRL2_B (1<<9) +#define MT9M111_CTXT_CTRL_GAMMA_B (1<<8) +#define MT9M111_CTXT_CTRL_XENON_EN (1<<7) +#define MT9M111_CTXT_CTRL_READ_MODE_B (1<<3) +#define MT9M111_CTXT_CTRL_LED_FLASH_EN (1<<2) +#define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1<<1) +#define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1<<0) +/* +* mt9m111: Colorpipe register addresses (0x100..0x1ff) +*/ +#define MT9M111_OPER_MODE_CTRL 0x106 +#define MT9M111_OUTPUT_FORMAT_CTRL 0x108 +#define MT9M111_REDUCER_XZOOM_B 0x1a0 +#define MT9M111_REDUCER_XSIZE_B 0x1a1 +#define MT9M111_REDUCER_YZOOM_B 0x1a3 +#define MT9M111_REDUCER_YSIZE_B 0x1a4 +#define MT9M111_REDUCER_XZOOM_A 0x1a6 +#define MT9M111_REDUCER_XSIZE_A 0x1a7 +#define MT9M111_REDUCER_YZOOM_A 0x1a9 +#define MT9M111_REDUCER_YSIZE_A 0x1aa + +#define MT9M111_OUTPUT_FORMAT_CTRL2_A 0x13a +#define MT9M111_OUTPUT_FORMAT_CTRL2_B 0x19b + +#define MT9M111_OPMODE_AUTOEXPO_EN (1<<14) + + +#define MT9M111_OUTFMT_PROCESSED_BAYER (1<<14) +#define MT9M111_OUTFMT_BYPASS_IFP (1<<10) +#define MT9M111_OUTFMT_INV_PIX_CLOCK (1<<9) +#define MT9M111_OUTFMT_RGB (1<<8) +#define MT9M111_OUTFMT_RGB565 (0x0 << 6) +#define MT9M111_OUTFMT_RGB555 (0x1 << 6) +#define MT9M111_OUTFMT_RGB444x (0x2 << 6)
drivers/media/video/mt9m111.c line 110
Quoted 10 lines
drivers/media/video/mt9m111.c new file +10
-0+#define MT9M111_OUTFMT_RGBx444 (0x3 << 6) +#define MT9M111_OUTFMT_TST_RAMP_OFF (0x0 << 4) +#define MT9M111_OUTFMT_TST_RAMP_COL (0x1 << 4) +#define MT9M111_OUTFMT_TST_RAMP_ROW (0x2 << 4) +#define MT9M111_OUTFMT_TST_RAMP_FRAME (0x3 << 4) +#define MT9M111_OUTFMT_SHIFT_3_UP (1<<3) +#define MT9M111_OUTFMT_AVG_CHROMA (1<<2) +#define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1<<1) +#define MT9M111_OUTFMT_SWAP_RGB_EVEN (1<<1) +#define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1<<0)
Please, add spaces around the "<<" in all defines above (except where they are already there, of course:-))
[snip]
drivers/media/video/mt9m111.c line 137
Quoted 13 lines
drivers/media/video/mt9m111.c new file +13
-0+#define COL_FMT (_name, _depth, _fourcc, _colorspace) \ + { .name = _name, .depth = _depth, .fourcc = _fourcc, \ + .colorspace = _colorspace } +#define RGB_FMT (_name, _depth, _fourcc) \ + COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_SRGB) + +static const struct soc_camera_data_format mt9m111_colour_formats[] = { +COL_FMT ("YCrYCb 8 bit" ,8 ,V4L2_PIX_FMT_YUYV ,V4L2_COLORSPACE_JPEG ), +RGB_FMT ("RGB 565" ,16 ,V4L2_PIX_FMT_RGB565 ), +RGB_FMT ("RGB 555" ,16 ,V4L2_PIX_FMT_RGB555 ), +RGB_FMT ("Bayer (sRGB) 10 bit" ,10 ,V4L2_PIX_FMT_SBGGR16 ), +RGB_FMT ("Bayer (sRGB) 8 bit" ,8 ,V4L2_PIX_FMT_SBGGR8 ), +};
This is where you would add all those swapped pixel formats.
Quoted 34 lines
drivers/media/video/mt9m111.c new file +34
-0+static int mt9m111_enable (struct soc_camera_device *icd) +{ + struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); +int ret; + + ret =reg_set (RESET ,MT9M111_RESET_CHIP_ENABLE ); +if (ret >=0 ) + mt9m111->powered =1 ; +return ret; +} + +static int mt9m111_disable (struct soc_camera_device *icd) +{ + struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); +int ret; + + ret =reg_clear (RESET ,MT9M111_RESET_CHIP_ENABLE ); +if (ret >=0 ) + mt9m111->powered =0 ; +return ret; +} + +static int mt9m111_reset (struct soc_camera_device *icd) +{ +int ret; + + ret =reg_set (RESET ,MT9M111_RESET_RESET_MODE ); +if (ret >=0 ) + ret =reg_set (RESET ,MT9M111_RESET_RESET_SOC ); +if (ret >=0 ) + ret =reg_clear (RESET ,MT9M111_RESET_RESET_MODE + |MT9M111_RESET_RESET_SOC ); +return ret; +}
drivers/media/video/mt9m111.c line 398
Quoted 10 lines
drivers/media/video/mt9m111.c new file +10
-0+ +static int mt9m111_start_capture (struct soc_camera_device *icd) +{ +return 0 ; +} + +static int mt9m111_stop_capture (struct soc_camera_device *icd) +{ +return 0 ; +}
Is it really a good idea to keep the camera active all the time? Maybe only call enable / disable here, not on init / release?
[snip]
Quoted 21 lines
drivers/media/video/mt9m111.c new file +21
-0+static int mt9m111_set_pixfmt (struct soc_camera_device *icd,u32 pixfmt) +{ + struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); +int ret =0 ; + +switch (pixfmt) { +case V4L2_PIX_FMT_SBGGR8 : + ret =mt9m111_setfmt_bayer8 (icd); +break ; +case V4L2_PIX_FMT_SBGGR16 : + ret =mt9m111_setfmt_bayer10 (icd); +break ; +case V4L2_PIX_FMT_RGB555 : + ret =mt9m111_setfmt_rgb555 (icd); +break ; +case V4L2_PIX_FMT_RGB565 : + ret =mt9m111_setfmt_rgb565 (icd); +break ; +case V4L2_PIX_FMT_YUYV : + ret =mt9m111_setfmt_yuv (icd); +break ;
drivers/media/video/mt9m111.c line 442
Quoted 10 lines
drivers/media/video/mt9m111.c new file +10
-0+default : +dev_err (&icd->dev,"Pixel format not handled : %x\n" , pixfmt); + ret = -EINVAL ; + } + +if (ret >=0 ) + mt9m111->pixfmt = pixfmt; + +return ret; +}
And here you would support a few more formats.
[snip]
Quoted 16 lines
drivers/media/video/mt9m111.c new file +16
-0+static const struct v4l2_queryctrl mt9m111_controls[] = { + { + .id =V4L2_CID_VFLIP , + .type =V4L2_CTRL_TYPE_BOOLEAN , + .name ="Flip Verticaly" , + .minimum =0 , + .maximum =1 , + .step =1 , + .default_value =0 , + }, { + .id =V4L2_CID_HFLIP , + .type =V4L2_CTRL_TYPE_BOOLEAN , + .name ="Flip Horizontaly" , + .minimum =0 , + .maximum =1 , + .step =1 ,
drivers/media/video/mt9m111.c line 558
Quoted 10 lines
drivers/media/video/mt9m111.c new file +10
-0+ .default_value = 0, + }, { /* gain = 1/32*val (=>gain=1 if val==32) */ + .id = V4L2_CID_GAIN, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Gain", + .minimum = 0, + .maximum = 63*2*2, + .step = 1, + .default_value = 32, + .flags = V4L2_CTRL_FLAG_SLIDER,
Come on, be generous, add a couple of spaces around that multiplication above.
[snip]
Quoted 7 lines
drivers/media/video/mt9m111.c new file +7
-0+static int mt9m111_set_global_gain (struct soc_camera_device *icd,int gain) +{ +u16 val; + +if (gain >63 *2 *2 ) +return -EINVAL ; +
drivers/media/video/mt9m111.c line 654
Quoted 10 lines
drivers/media/video/mt9m111.c new file +10
-0+ icd->gain = gain; +if ((gain >=64 *2 ) && (gain <63 *2 *2 )) + val = (1 <<10 ) | (1 <<9 ) | (gain /4 ); +else if ((gain >=64 ) && (gain <64 *2 )) + val = (1 <<9 ) | (gain /2 ); +else + val = gain; + +return reg_write (GLOBAL_GAIN , val); +}
And here too, please.
[snip]
drivers/media/video/mt9m111.c line 806
Quoted 2 lines
drivers/media/video/mt9m111.c new file +2
-0+/* Interface active, can use i2c. If it fails, it can indeed mean, that +* this wasn't our capture interface, so, we wait for the right one */
Reformat the comment, please.
Thanks
Guennadi
---
Guennadi Liakhovetski
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Re: [PATCH 2/2] Add support for Micron MT9M111 camera.
Quoted 9 lines · Guennadi Liakhovetski
Nice! Not knowing this specific camera, I can only provide a couple of nitpicks:
Please reformat this comment to/*
* mt9m111 i2c address is0x5dor0x48(depending on SAddr pin)
* The platform has to definei2c_board_info
* and calli2c_register_board_info()
*/
OK for next submit.
Quoted 4 lines
Quoted 1 line
+#define
MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr(1<<0)Please, add spaces around the "<<" in all defines above (except where they are already there, of course:-))
OK for next submit.
Quoted 11 lines
drivers/media/video/mt9m111.c line 137
Quoted 9 lines
drivers/media/video/mt9m111.c new file +7
-0+static const struct soc_camera_data_format mt9m111_colour_formats[] = { +COL_FMT ("YCrYCb 8 bit" ,8 ,V4L2_PIX_FMT_YUYV ,V4L2_COLORSPACE_JPEG ), +RGB_FMT ("RGB 565" ,16 ,V4L2_PIX_FMT_RGB565 ), +RGB_FMT ("RGB 555" ,16 ,V4L2_PIX_FMT_RGB555 ), +RGB_FMT ("Bayer (sRGB) 10 bit" ,10 ,V4L2_PIX_FMT_SBGGR16 ), +RGB_FMT ("Bayer (sRGB) 8 bit" ,8 ,V4L2_PIX_FMT_SBGGR8 ), +};This is where you would add all those swapped pixel formats.
Let's finish the dicussion in the other thread "[RFC] soc-camera: endianness between camera and its host".
Quoted 2 lines
Is it really a good idea to keep the camera active all the time? Maybe only call enable / disable here, not on init / release?
Well, I think so.
The idea here is the camera evaluates its environment to adjust its internal gain values. This a kind of PLL which provides Automatic White Balance, Automatic Gamma, Automatic Defect Correction.
So, my idea is that once a user opens /dev/videoX, the camera gets activated and calculates the values. In that case, when he submits buffers to the V4L2 stack, the camera is really ready.
But I can change that to activate the camera only on capture, I'm not very set on this. The user can start capturing, and then wait a couple of seconds for the camera to settle. So what do you think, should I move camera activation into start_capture / stop_capture ?
Quoted 7 lines
drivers/media/video/mt9m111.c line 558
Quoted 4 lines
drivers/media/video/mt9m111.c new file +4
-0+ .maximum = 63*2*2, + .step = 1, + .default_value = 32, + .flags = V4L2_CTRL_FLAG_SLIDER,Come on, be generous, add a couple of spaces around that multiplication above.
OK for next submit.
Quoted 6 lines
[snip]
drivers/media/video/mt9m111.c line 648
Quoted 3 lines
drivers/media/video/mt9m111.c new file +3
-0+if ((gain >=64 *2 ) && (gain <63 *2 *2 )) + val = (1 <<10 ) | (1 <<9 ) | (gain /4 ); +else if ((gain >=64 ) && (gain <64 *2 ))And here too, please.
OK for next submit.
Quoted 7 lines
[snip]
Quoted 2 lines
+/* Interface active, can use i2c. If it fails, it can indeed mean, that
+ * this wasn't our capture interface, so, we wait for the right one */Reformat the comment, please.
OK for next submit.
--
Robert
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 1/1 Add support for Micron MT9M111 camera.
Adds support for Micron MT9M111 camera chip, with basic features :
- view rectangle configurable
- some output formats (bayer8, bayer10, rgb565, rgb555, ycbycr)
- autoexposure
- only highpower mode context used (ie. context B)
--- drivers/media/video/Kconfig | 6 + drivers/media/video/Makefile | 1 + drivers/media/video/mt9m111.c | 960 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 967 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/mt9m111.c
drivers/media/video/Kconfig +6 -0
@@ -938,6 +938,12 @@ config MT9M001_PCA9536_SWITCH Select this if your MT9M001 camera uses a PCA9536 I2C GPIO extender to switch between 8 and 10 bit datawidth modes +config SOC_CAMERA_MT9M111 + tristate "mt9m001 support" + depends on SOC_CAMERA && I2C + help + This driver supports MT9M111 cameras from Micron + config SOC_CAMERA_MT9V022 tristate "mt9v022 support" depends on SOC_CAMERA && I2C
drivers/media/video/Makefile +1 -0
@@ -137,6 +137,7 @@ obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o obj-$(CONFIG_SOC_CAMERA) += soc_camera.o obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o +obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o
drivers/media/video/mt9m111.c new file +960 -0
960 lines not on this page · raw message
Signature · 6 lines
1.5.6.3 -- video4linux-list mailing list Unsubscribe mailto:[email protected]?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list