2 * Driver for MT9V022 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/delay.h>
15 #include <linux/log2.h>
17 #include <media/v4l2-subdev.h>
18 #include <media/v4l2-chip-ident.h>
19 #include <media/soc_camera.h>
21 /* mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c
22 * The platform has to define ctruct i2c_board_info objects and link to them
23 * from struct soc_camera_link */
25 static char *sensor_type
;
26 module_param(sensor_type
, charp
, S_IRUGO
);
27 MODULE_PARM_DESC(sensor_type
, "Sensor type: \"colour\" or \"monochrome\"");
29 /* mt9v022 selected register addresses */
30 #define MT9V022_CHIP_VERSION 0x00
31 #define MT9V022_COLUMN_START 0x01
32 #define MT9V022_ROW_START 0x02
33 #define MT9V022_WINDOW_HEIGHT 0x03
34 #define MT9V022_WINDOW_WIDTH 0x04
35 #define MT9V022_HORIZONTAL_BLANKING 0x05
36 #define MT9V022_VERTICAL_BLANKING 0x06
37 #define MT9V022_CHIP_CONTROL 0x07
38 #define MT9V022_SHUTTER_WIDTH1 0x08
39 #define MT9V022_SHUTTER_WIDTH2 0x09
40 #define MT9V022_SHUTTER_WIDTH_CTRL 0x0a
41 #define MT9V022_TOTAL_SHUTTER_WIDTH 0x0b
42 #define MT9V022_RESET 0x0c
43 #define MT9V022_READ_MODE 0x0d
44 #define MT9V022_MONITOR_MODE 0x0e
45 #define MT9V022_PIXEL_OPERATION_MODE 0x0f
46 #define MT9V022_LED_OUT_CONTROL 0x1b
47 #define MT9V022_ADC_MODE_CONTROL 0x1c
48 #define MT9V022_ANALOG_GAIN 0x34
49 #define MT9V022_BLACK_LEVEL_CALIB_CTRL 0x47
50 #define MT9V022_PIXCLK_FV_LV 0x74
51 #define MT9V022_DIGITAL_TEST_PATTERN 0x7f
52 #define MT9V022_AEC_AGC_ENABLE 0xAF
53 #define MT9V022_MAX_TOTAL_SHUTTER_WIDTH 0xBD
55 /* Progressive scan, master, defaults */
56 #define MT9V022_CHIP_CONTROL_DEFAULT 0x188
58 #define MT9V022_MAX_WIDTH 752
59 #define MT9V022_MAX_HEIGHT 480
60 #define MT9V022_MIN_WIDTH 48
61 #define MT9V022_MIN_HEIGHT 32
62 #define MT9V022_COLUMN_SKIP 1
63 #define MT9V022_ROW_SKIP 4
65 static const struct soc_camera_data_format mt9v022_colour_formats
[] = {
66 /* Order important: first natively supported,
67 * second supported with a GPIO extender */
69 .name
= "Bayer (sRGB) 10 bit",
71 .fourcc
= V4L2_PIX_FMT_SBGGR16
,
72 .colorspace
= V4L2_COLORSPACE_SRGB
,
74 .name
= "Bayer (sRGB) 8 bit",
76 .fourcc
= V4L2_PIX_FMT_SBGGR8
,
77 .colorspace
= V4L2_COLORSPACE_SRGB
,
81 static const struct soc_camera_data_format mt9v022_monochrome_formats
[] = {
82 /* Order important - see above */
84 .name
= "Monochrome 10 bit",
86 .fourcc
= V4L2_PIX_FMT_Y16
,
88 .name
= "Monochrome 8 bit",
90 .fourcc
= V4L2_PIX_FMT_GREY
,
95 struct v4l2_subdev subdev
;
96 struct v4l2_rect rect
; /* Sensor window */
98 int model
; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */
102 static struct mt9v022
*to_mt9v022(const struct i2c_client
*client
)
104 return container_of(i2c_get_clientdata(client
), struct mt9v022
, subdev
);
107 static int reg_read(struct i2c_client
*client
, const u8 reg
)
109 s32 data
= i2c_smbus_read_word_data(client
, reg
);
110 return data
< 0 ? data
: swab16(data
);
113 static int reg_write(struct i2c_client
*client
, const u8 reg
,
116 return i2c_smbus_write_word_data(client
, reg
, swab16(data
));
119 static int reg_set(struct i2c_client
*client
, const u8 reg
,
124 ret
= reg_read(client
, reg
);
127 return reg_write(client
, reg
, ret
| data
);
130 static int reg_clear(struct i2c_client
*client
, const u8 reg
,
135 ret
= reg_read(client
, reg
);
138 return reg_write(client
, reg
, ret
& ~data
);
141 static int mt9v022_init(struct i2c_client
*client
)
143 struct mt9v022
*mt9v022
= to_mt9v022(client
);
146 /* Almost the default mode: master, parallel, simultaneous, and an
147 * undocumented bit 0x200, which is present in table 7, but not in 8,
148 * plus snapshot mode to disable scan for now */
149 mt9v022
->chip_control
|= 0x10;
150 ret
= reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
);
152 ret
= reg_write(client
, MT9V022_READ_MODE
, 0x300);
157 ret
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x3);
159 ret
= reg_write(client
, MT9V022_MAX_TOTAL_SHUTTER_WIDTH
, 480);
162 ret
= reg_clear(client
, MT9V022_BLACK_LEVEL_CALIB_CTRL
, 1);
164 ret
= reg_write(client
, MT9V022_DIGITAL_TEST_PATTERN
, 0);
169 static int mt9v022_s_stream(struct v4l2_subdev
*sd
, int enable
)
171 struct i2c_client
*client
= sd
->priv
;
172 struct mt9v022
*mt9v022
= to_mt9v022(client
);
175 /* Switch to master "normal" mode */
176 mt9v022
->chip_control
&= ~0x10;
178 /* Switch to snapshot mode */
179 mt9v022
->chip_control
|= 0x10;
181 if (reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
) < 0)
186 static int mt9v022_set_bus_param(struct soc_camera_device
*icd
,
189 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
190 struct mt9v022
*mt9v022
= to_mt9v022(client
);
191 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
192 unsigned int width_flag
= flags
& SOCAM_DATAWIDTH_MASK
;
196 /* Only one width bit may be set */
197 if (!is_power_of_2(width_flag
))
200 if (icl
->set_bus_param
) {
201 ret
= icl
->set_bus_param(icl
, width_flag
);
206 * Without board specific bus width settings we only support the
207 * sensors native bus width
209 if (width_flag
!= SOCAM_DATAWIDTH_10
)
213 flags
= soc_camera_apply_sensor_flags(icl
, flags
);
215 if (flags
& SOCAM_PCLK_SAMPLE_RISING
)
218 if (!(flags
& SOCAM_HSYNC_ACTIVE_HIGH
))
221 if (!(flags
& SOCAM_VSYNC_ACTIVE_HIGH
))
224 ret
= reg_write(client
, MT9V022_PIXCLK_FV_LV
, pixclk
);
228 if (!(flags
& SOCAM_MASTER
))
229 mt9v022
->chip_control
&= ~0x8;
231 ret
= reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
);
235 dev_dbg(&client
->dev
, "Calculated pixclk 0x%x, chip control 0x%x\n",
236 pixclk
, mt9v022
->chip_control
);
241 static unsigned long mt9v022_query_bus_param(struct soc_camera_device
*icd
)
243 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
244 unsigned int width_flag
;
246 if (icl
->query_bus_param
)
247 width_flag
= icl
->query_bus_param(icl
) &
248 SOCAM_DATAWIDTH_MASK
;
250 width_flag
= SOCAM_DATAWIDTH_10
;
252 return SOCAM_PCLK_SAMPLE_RISING
| SOCAM_PCLK_SAMPLE_FALLING
|
253 SOCAM_HSYNC_ACTIVE_HIGH
| SOCAM_HSYNC_ACTIVE_LOW
|
254 SOCAM_VSYNC_ACTIVE_HIGH
| SOCAM_VSYNC_ACTIVE_LOW
|
255 SOCAM_DATA_ACTIVE_HIGH
| SOCAM_MASTER
| SOCAM_SLAVE
|
259 static int mt9v022_s_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
261 struct i2c_client
*client
= sd
->priv
;
262 struct mt9v022
*mt9v022
= to_mt9v022(client
);
263 struct v4l2_rect rect
= a
->c
;
264 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
267 /* Bayer format - even size lengths */
268 if (mt9v022
->fourcc
== V4L2_PIX_FMT_SBGGR8
||
269 mt9v022
->fourcc
== V4L2_PIX_FMT_SBGGR16
) {
270 rect
.width
= ALIGN(rect
.width
, 2);
271 rect
.height
= ALIGN(rect
.height
, 2);
272 /* Let the user play with the starting pixel */
275 soc_camera_limit_side(&rect
.left
, &rect
.width
,
276 MT9V022_COLUMN_SKIP
, MT9V022_MIN_WIDTH
, MT9V022_MAX_WIDTH
);
278 soc_camera_limit_side(&rect
.top
, &rect
.height
,
279 MT9V022_ROW_SKIP
, MT9V022_MIN_HEIGHT
, MT9V022_MAX_HEIGHT
);
281 /* Like in example app. Contradicts the datasheet though */
282 ret
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
284 if (ret
& 1) /* Autoexposure */
285 ret
= reg_write(client
, MT9V022_MAX_TOTAL_SHUTTER_WIDTH
,
286 rect
.height
+ icd
->y_skip_top
+ 43);
288 ret
= reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
,
289 rect
.height
+ icd
->y_skip_top
+ 43);
291 /* Setup frame format: defaults apart from width and height */
293 ret
= reg_write(client
, MT9V022_COLUMN_START
, rect
.left
);
295 ret
= reg_write(client
, MT9V022_ROW_START
, rect
.top
);
297 /* Default 94, Phytec driver says:
298 * "width + horizontal blank >= 660" */
299 ret
= reg_write(client
, MT9V022_HORIZONTAL_BLANKING
,
300 rect
.width
> 660 - 43 ? 43 :
303 ret
= reg_write(client
, MT9V022_VERTICAL_BLANKING
, 45);
305 ret
= reg_write(client
, MT9V022_WINDOW_WIDTH
, rect
.width
);
307 ret
= reg_write(client
, MT9V022_WINDOW_HEIGHT
,
308 rect
.height
+ icd
->y_skip_top
);
313 dev_dbg(&client
->dev
, "Frame %ux%u pixel\n", rect
.width
, rect
.height
);
315 mt9v022
->rect
= rect
;
320 static int mt9v022_g_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
322 struct i2c_client
*client
= sd
->priv
;
323 struct mt9v022
*mt9v022
= to_mt9v022(client
);
325 a
->c
= mt9v022
->rect
;
326 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
331 static int mt9v022_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*a
)
333 a
->bounds
.left
= MT9V022_COLUMN_SKIP
;
334 a
->bounds
.top
= MT9V022_ROW_SKIP
;
335 a
->bounds
.width
= MT9V022_MAX_WIDTH
;
336 a
->bounds
.height
= MT9V022_MAX_HEIGHT
;
337 a
->defrect
= a
->bounds
;
338 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
339 a
->pixelaspect
.numerator
= 1;
340 a
->pixelaspect
.denominator
= 1;
345 static int mt9v022_g_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
347 struct i2c_client
*client
= sd
->priv
;
348 struct mt9v022
*mt9v022
= to_mt9v022(client
);
349 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
351 pix
->width
= mt9v022
->rect
.width
;
352 pix
->height
= mt9v022
->rect
.height
;
353 pix
->pixelformat
= mt9v022
->fourcc
;
354 pix
->field
= V4L2_FIELD_NONE
;
355 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
360 static int mt9v022_s_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
362 struct i2c_client
*client
= sd
->priv
;
363 struct mt9v022
*mt9v022
= to_mt9v022(client
);
364 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
365 struct v4l2_crop a
= {
367 .left
= mt9v022
->rect
.left
,
368 .top
= mt9v022
->rect
.top
,
370 .height
= pix
->height
,
375 /* The caller provides a supported format, as verified per call to
376 * icd->try_fmt(), datawidth is from our supported format list */
377 switch (pix
->pixelformat
) {
378 case V4L2_PIX_FMT_GREY
:
379 case V4L2_PIX_FMT_Y16
:
380 if (mt9v022
->model
!= V4L2_IDENT_MT9V022IX7ATM
)
383 case V4L2_PIX_FMT_SBGGR8
:
384 case V4L2_PIX_FMT_SBGGR16
:
385 if (mt9v022
->model
!= V4L2_IDENT_MT9V022IX7ATC
)
389 /* No format change, only geometry */
395 /* No support for scaling on this camera, just crop. */
396 ret
= mt9v022_s_crop(sd
, &a
);
398 pix
->width
= mt9v022
->rect
.width
;
399 pix
->height
= mt9v022
->rect
.height
;
400 mt9v022
->fourcc
= pix
->pixelformat
;
406 static int mt9v022_try_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
408 struct i2c_client
*client
= sd
->priv
;
409 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
410 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
411 int align
= pix
->pixelformat
== V4L2_PIX_FMT_SBGGR8
||
412 pix
->pixelformat
== V4L2_PIX_FMT_SBGGR16
;
414 v4l_bound_align_image(&pix
->width
, MT9V022_MIN_WIDTH
,
415 MT9V022_MAX_WIDTH
, align
,
416 &pix
->height
, MT9V022_MIN_HEIGHT
+ icd
->y_skip_top
,
417 MT9V022_MAX_HEIGHT
+ icd
->y_skip_top
, align
, 0);
422 static int mt9v022_g_chip_ident(struct v4l2_subdev
*sd
,
423 struct v4l2_dbg_chip_ident
*id
)
425 struct i2c_client
*client
= sd
->priv
;
426 struct mt9v022
*mt9v022
= to_mt9v022(client
);
428 if (id
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
)
431 if (id
->match
.addr
!= client
->addr
)
434 id
->ident
= mt9v022
->model
;
440 #ifdef CONFIG_VIDEO_ADV_DEBUG
441 static int mt9v022_g_register(struct v4l2_subdev
*sd
,
442 struct v4l2_dbg_register
*reg
)
444 struct i2c_client
*client
= sd
->priv
;
446 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
449 if (reg
->match
.addr
!= client
->addr
)
453 reg
->val
= reg_read(client
, reg
->reg
);
455 if (reg
->val
> 0xffff)
461 static int mt9v022_s_register(struct v4l2_subdev
*sd
,
462 struct v4l2_dbg_register
*reg
)
464 struct i2c_client
*client
= sd
->priv
;
466 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
469 if (reg
->match
.addr
!= client
->addr
)
472 if (reg_write(client
, reg
->reg
, reg
->val
) < 0)
479 static const struct v4l2_queryctrl mt9v022_controls
[] = {
481 .id
= V4L2_CID_VFLIP
,
482 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
483 .name
= "Flip Vertically",
489 .id
= V4L2_CID_HFLIP
,
490 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
491 .name
= "Flip Horizontally",
498 .type
= V4L2_CTRL_TYPE_INTEGER
,
499 .name
= "Analog Gain",
504 .flags
= V4L2_CTRL_FLAG_SLIDER
,
506 .id
= V4L2_CID_EXPOSURE
,
507 .type
= V4L2_CTRL_TYPE_INTEGER
,
512 .default_value
= 255,
513 .flags
= V4L2_CTRL_FLAG_SLIDER
,
515 .id
= V4L2_CID_AUTOGAIN
,
516 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
517 .name
= "Automatic Gain",
523 .id
= V4L2_CID_EXPOSURE_AUTO
,
524 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
525 .name
= "Automatic Exposure",
533 static struct soc_camera_ops mt9v022_ops
= {
534 .set_bus_param
= mt9v022_set_bus_param
,
535 .query_bus_param
= mt9v022_query_bus_param
,
536 .controls
= mt9v022_controls
,
537 .num_controls
= ARRAY_SIZE(mt9v022_controls
),
540 static int mt9v022_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
542 struct i2c_client
*client
= sd
->priv
;
547 data
= reg_read(client
, MT9V022_READ_MODE
);
550 ctrl
->value
= !!(data
& 0x10);
553 data
= reg_read(client
, MT9V022_READ_MODE
);
556 ctrl
->value
= !!(data
& 0x20);
558 case V4L2_CID_EXPOSURE_AUTO
:
559 data
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
562 ctrl
->value
= !!(data
& 0x1);
564 case V4L2_CID_AUTOGAIN
:
565 data
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
568 ctrl
->value
= !!(data
& 0x2);
574 static int mt9v022_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
577 struct i2c_client
*client
= sd
->priv
;
578 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
579 const struct v4l2_queryctrl
*qctrl
;
581 qctrl
= soc_camera_find_qctrl(&mt9v022_ops
, ctrl
->id
);
588 data
= reg_set(client
, MT9V022_READ_MODE
, 0x10);
590 data
= reg_clear(client
, MT9V022_READ_MODE
, 0x10);
596 data
= reg_set(client
, MT9V022_READ_MODE
, 0x20);
598 data
= reg_clear(client
, MT9V022_READ_MODE
, 0x20);
603 /* mt9v022 has minimum == default */
604 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
607 unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
608 /* Datasheet says 16 to 64. autogain only works properly
609 * after setting gain to maximum 14. Larger values
610 * produce "white fly" noise effect. On the whole,
611 * manually setting analog gain does no good. */
612 unsigned long gain
= ((ctrl
->value
- qctrl
->minimum
) *
613 10 + range
/ 2) / range
+ 4;
616 /* The user wants to set gain manually, hope, she
617 * knows, what she's doing... Switch AGC off. */
619 if (reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x2) < 0)
622 dev_info(&client
->dev
, "Setting gain from %d to %lu\n",
623 reg_read(client
, MT9V022_ANALOG_GAIN
), gain
);
624 if (reg_write(client
, MT9V022_ANALOG_GAIN
, gain
) < 0)
626 icd
->gain
= ctrl
->value
;
629 case V4L2_CID_EXPOSURE
:
630 /* mt9v022 has maximum == default */
631 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
634 unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
635 unsigned long shutter
= ((ctrl
->value
- qctrl
->minimum
) *
636 479 + range
/ 2) / range
+ 1;
637 /* The user wants to set shutter width manually, hope,
638 * she knows, what she's doing... Switch AEC off. */
640 if (reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x1) < 0)
643 dev_dbg(&client
->dev
, "Shutter width from %d to %lu\n",
644 reg_read(client
, MT9V022_TOTAL_SHUTTER_WIDTH
),
646 if (reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
,
649 icd
->exposure
= ctrl
->value
;
652 case V4L2_CID_AUTOGAIN
:
654 data
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x2);
656 data
= reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x2);
660 case V4L2_CID_EXPOSURE_AUTO
:
662 data
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x1);
664 data
= reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x1);
672 /* Interface active, can use i2c. If it fails, it can indeed mean, that
673 * this wasn't our capture interface, so, we wait for the right one */
674 static int mt9v022_video_probe(struct soc_camera_device
*icd
,
675 struct i2c_client
*client
)
677 struct mt9v022
*mt9v022
= to_mt9v022(client
);
678 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
683 if (!icd
->dev
.parent
||
684 to_soc_camera_host(icd
->dev
.parent
)->nr
!= icd
->iface
)
687 /* Read out the chip version register */
688 data
= reg_read(client
, MT9V022_CHIP_VERSION
);
690 /* must be 0x1311 or 0x1313 */
691 if (data
!= 0x1311 && data
!= 0x1313) {
693 dev_info(&client
->dev
, "No MT9V022 found, ID register 0x%x\n",
699 ret
= reg_write(client
, MT9V022_RESET
, 1);
702 /* 15 clock cycles */
704 if (reg_read(client
, MT9V022_RESET
)) {
705 dev_err(&client
->dev
, "Resetting MT9V022 failed!\n");
711 /* Set monochrome or colour sensor type */
712 if (sensor_type
&& (!strcmp("colour", sensor_type
) ||
713 !strcmp("color", sensor_type
))) {
714 ret
= reg_write(client
, MT9V022_PIXEL_OPERATION_MODE
, 4 | 0x11);
715 mt9v022
->model
= V4L2_IDENT_MT9V022IX7ATC
;
716 icd
->formats
= mt9v022_colour_formats
;
718 ret
= reg_write(client
, MT9V022_PIXEL_OPERATION_MODE
, 0x11);
719 mt9v022
->model
= V4L2_IDENT_MT9V022IX7ATM
;
720 icd
->formats
= mt9v022_monochrome_formats
;
726 icd
->num_formats
= 0;
729 * This is a 10bit sensor, so by default we only allow 10bit.
730 * The platform may support different bus widths due to
731 * different routing of the data lines.
733 if (icl
->query_bus_param
)
734 flags
= icl
->query_bus_param(icl
);
736 flags
= SOCAM_DATAWIDTH_10
;
738 if (flags
& SOCAM_DATAWIDTH_10
)
743 if (flags
& SOCAM_DATAWIDTH_8
)
746 mt9v022
->fourcc
= icd
->formats
->fourcc
;
748 dev_info(&client
->dev
, "Detected a MT9V022 chip ID %x, %s sensor\n",
749 data
, mt9v022
->model
== V4L2_IDENT_MT9V022IX7ATM
?
750 "monochrome" : "colour");
752 ret
= mt9v022_init(client
);
754 dev_err(&client
->dev
, "Failed to initialise the camera\n");
760 static void mt9v022_video_remove(struct soc_camera_device
*icd
)
762 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
764 dev_dbg(&icd
->dev
, "Video removed: %p, %p\n",
765 icd
->dev
.parent
, icd
->vdev
);
770 static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops
= {
771 .g_ctrl
= mt9v022_g_ctrl
,
772 .s_ctrl
= mt9v022_s_ctrl
,
773 .g_chip_ident
= mt9v022_g_chip_ident
,
774 #ifdef CONFIG_VIDEO_ADV_DEBUG
775 .g_register
= mt9v022_g_register
,
776 .s_register
= mt9v022_s_register
,
780 static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops
= {
781 .s_stream
= mt9v022_s_stream
,
782 .s_fmt
= mt9v022_s_fmt
,
783 .g_fmt
= mt9v022_g_fmt
,
784 .try_fmt
= mt9v022_try_fmt
,
785 .s_crop
= mt9v022_s_crop
,
786 .g_crop
= mt9v022_g_crop
,
787 .cropcap
= mt9v022_cropcap
,
790 static struct v4l2_subdev_ops mt9v022_subdev_ops
= {
791 .core
= &mt9v022_subdev_core_ops
,
792 .video
= &mt9v022_subdev_video_ops
,
795 static int mt9v022_probe(struct i2c_client
*client
,
796 const struct i2c_device_id
*did
)
798 struct mt9v022
*mt9v022
;
799 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
800 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
801 struct soc_camera_link
*icl
;
805 dev_err(&client
->dev
, "MT9V022: missing soc-camera data!\n");
809 icl
= to_soc_camera_link(icd
);
811 dev_err(&client
->dev
, "MT9V022 driver needs platform data\n");
815 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
)) {
816 dev_warn(&adapter
->dev
,
817 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
821 mt9v022
= kzalloc(sizeof(struct mt9v022
), GFP_KERNEL
);
825 v4l2_i2c_subdev_init(&mt9v022
->subdev
, client
, &mt9v022_subdev_ops
);
827 mt9v022
->chip_control
= MT9V022_CHIP_CONTROL_DEFAULT
;
829 icd
->ops
= &mt9v022_ops
;
832 mt9v022
->rect
.left
= MT9V022_COLUMN_SKIP
;
833 mt9v022
->rect
.top
= MT9V022_ROW_SKIP
;
834 mt9v022
->rect
.width
= MT9V022_MAX_WIDTH
;
835 mt9v022
->rect
.height
= MT9V022_MAX_HEIGHT
;
837 ret
= mt9v022_video_probe(icd
, client
);
840 i2c_set_clientdata(client
, NULL
);
847 static int mt9v022_remove(struct i2c_client
*client
)
849 struct mt9v022
*mt9v022
= to_mt9v022(client
);
850 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
853 mt9v022_video_remove(icd
);
854 i2c_set_clientdata(client
, NULL
);
855 client
->driver
= NULL
;
860 static const struct i2c_device_id mt9v022_id
[] = {
864 MODULE_DEVICE_TABLE(i2c
, mt9v022_id
);
866 static struct i2c_driver mt9v022_i2c_driver
= {
870 .probe
= mt9v022_probe
,
871 .remove
= mt9v022_remove
,
872 .id_table
= mt9v022_id
,
875 static int __init
mt9v022_mod_init(void)
877 return i2c_add_driver(&mt9v022_i2c_driver
);
880 static void __exit
mt9v022_mod_exit(void)
882 i2c_del_driver(&mt9v022_i2c_driver
);
885 module_init(mt9v022_mod_init
);
886 module_exit(mt9v022_mod_exit
);
888 MODULE_DESCRIPTION("Micron MT9V022 Camera driver");
889 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
890 MODULE_LICENSE("GPL");