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 0x35
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_ANALOG_GAIN
, 16);
161 ret
= reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
, 480);
163 ret
= reg_write(client
, MT9V022_MAX_TOTAL_SHUTTER_WIDTH
, 480);
166 ret
= reg_clear(client
, MT9V022_BLACK_LEVEL_CALIB_CTRL
, 1);
168 ret
= reg_write(client
, MT9V022_DIGITAL_TEST_PATTERN
, 0);
173 static int mt9v022_s_stream(struct v4l2_subdev
*sd
, int enable
)
175 struct i2c_client
*client
= sd
->priv
;
176 struct mt9v022
*mt9v022
= to_mt9v022(client
);
179 /* Switch to master "normal" mode */
180 mt9v022
->chip_control
&= ~0x10;
182 /* Switch to snapshot mode */
183 mt9v022
->chip_control
|= 0x10;
185 if (reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
) < 0)
190 static int mt9v022_set_bus_param(struct soc_camera_device
*icd
,
193 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
194 struct mt9v022
*mt9v022
= to_mt9v022(client
);
195 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
196 unsigned int width_flag
= flags
& SOCAM_DATAWIDTH_MASK
;
200 /* Only one width bit may be set */
201 if (!is_power_of_2(width_flag
))
204 if (icl
->set_bus_param
) {
205 ret
= icl
->set_bus_param(icl
, width_flag
);
210 * Without board specific bus width settings we only support the
211 * sensors native bus width
213 if (width_flag
!= SOCAM_DATAWIDTH_10
)
217 flags
= soc_camera_apply_sensor_flags(icl
, flags
);
219 if (flags
& SOCAM_PCLK_SAMPLE_RISING
)
222 if (!(flags
& SOCAM_HSYNC_ACTIVE_HIGH
))
225 if (!(flags
& SOCAM_VSYNC_ACTIVE_HIGH
))
228 ret
= reg_write(client
, MT9V022_PIXCLK_FV_LV
, pixclk
);
232 if (!(flags
& SOCAM_MASTER
))
233 mt9v022
->chip_control
&= ~0x8;
235 ret
= reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
);
239 dev_dbg(&client
->dev
, "Calculated pixclk 0x%x, chip control 0x%x\n",
240 pixclk
, mt9v022
->chip_control
);
245 static unsigned long mt9v022_query_bus_param(struct soc_camera_device
*icd
)
247 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
248 unsigned int width_flag
;
250 if (icl
->query_bus_param
)
251 width_flag
= icl
->query_bus_param(icl
) &
252 SOCAM_DATAWIDTH_MASK
;
254 width_flag
= SOCAM_DATAWIDTH_10
;
256 return SOCAM_PCLK_SAMPLE_RISING
| SOCAM_PCLK_SAMPLE_FALLING
|
257 SOCAM_HSYNC_ACTIVE_HIGH
| SOCAM_HSYNC_ACTIVE_LOW
|
258 SOCAM_VSYNC_ACTIVE_HIGH
| SOCAM_VSYNC_ACTIVE_LOW
|
259 SOCAM_DATA_ACTIVE_HIGH
| SOCAM_MASTER
| SOCAM_SLAVE
|
263 static int mt9v022_s_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
265 struct i2c_client
*client
= sd
->priv
;
266 struct mt9v022
*mt9v022
= to_mt9v022(client
);
267 struct v4l2_rect rect
= a
->c
;
268 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
271 /* Bayer format - even size lengths */
272 if (mt9v022
->fourcc
== V4L2_PIX_FMT_SBGGR8
||
273 mt9v022
->fourcc
== V4L2_PIX_FMT_SBGGR16
) {
274 rect
.width
= ALIGN(rect
.width
, 2);
275 rect
.height
= ALIGN(rect
.height
, 2);
276 /* Let the user play with the starting pixel */
279 soc_camera_limit_side(&rect
.left
, &rect
.width
,
280 MT9V022_COLUMN_SKIP
, MT9V022_MIN_WIDTH
, MT9V022_MAX_WIDTH
);
282 soc_camera_limit_side(&rect
.top
, &rect
.height
,
283 MT9V022_ROW_SKIP
, MT9V022_MIN_HEIGHT
, MT9V022_MAX_HEIGHT
);
285 /* Like in example app. Contradicts the datasheet though */
286 ret
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
288 if (ret
& 1) /* Autoexposure */
289 ret
= reg_write(client
, MT9V022_MAX_TOTAL_SHUTTER_WIDTH
,
290 rect
.height
+ icd
->y_skip_top
+ 43);
292 ret
= reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
,
293 rect
.height
+ icd
->y_skip_top
+ 43);
295 /* Setup frame format: defaults apart from width and height */
297 ret
= reg_write(client
, MT9V022_COLUMN_START
, rect
.left
);
299 ret
= reg_write(client
, MT9V022_ROW_START
, rect
.top
);
301 /* Default 94, Phytec driver says:
302 * "width + horizontal blank >= 660" */
303 ret
= reg_write(client
, MT9V022_HORIZONTAL_BLANKING
,
304 rect
.width
> 660 - 43 ? 43 :
307 ret
= reg_write(client
, MT9V022_VERTICAL_BLANKING
, 45);
309 ret
= reg_write(client
, MT9V022_WINDOW_WIDTH
, rect
.width
);
311 ret
= reg_write(client
, MT9V022_WINDOW_HEIGHT
,
312 rect
.height
+ icd
->y_skip_top
);
317 dev_dbg(&client
->dev
, "Frame %ux%u pixel\n", rect
.width
, rect
.height
);
319 mt9v022
->rect
= rect
;
324 static int mt9v022_g_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
326 struct i2c_client
*client
= sd
->priv
;
327 struct mt9v022
*mt9v022
= to_mt9v022(client
);
329 a
->c
= mt9v022
->rect
;
330 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
335 static int mt9v022_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*a
)
337 a
->bounds
.left
= MT9V022_COLUMN_SKIP
;
338 a
->bounds
.top
= MT9V022_ROW_SKIP
;
339 a
->bounds
.width
= MT9V022_MAX_WIDTH
;
340 a
->bounds
.height
= MT9V022_MAX_HEIGHT
;
341 a
->defrect
= a
->bounds
;
342 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
343 a
->pixelaspect
.numerator
= 1;
344 a
->pixelaspect
.denominator
= 1;
349 static int mt9v022_g_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
351 struct i2c_client
*client
= sd
->priv
;
352 struct mt9v022
*mt9v022
= to_mt9v022(client
);
353 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
355 pix
->width
= mt9v022
->rect
.width
;
356 pix
->height
= mt9v022
->rect
.height
;
357 pix
->pixelformat
= mt9v022
->fourcc
;
358 pix
->field
= V4L2_FIELD_NONE
;
359 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
364 static int mt9v022_s_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
366 struct i2c_client
*client
= sd
->priv
;
367 struct mt9v022
*mt9v022
= to_mt9v022(client
);
368 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
369 struct v4l2_crop a
= {
371 .left
= mt9v022
->rect
.left
,
372 .top
= mt9v022
->rect
.top
,
374 .height
= pix
->height
,
379 /* The caller provides a supported format, as verified per call to
380 * icd->try_fmt(), datawidth is from our supported format list */
381 switch (pix
->pixelformat
) {
382 case V4L2_PIX_FMT_GREY
:
383 case V4L2_PIX_FMT_Y16
:
384 if (mt9v022
->model
!= V4L2_IDENT_MT9V022IX7ATM
)
387 case V4L2_PIX_FMT_SBGGR8
:
388 case V4L2_PIX_FMT_SBGGR16
:
389 if (mt9v022
->model
!= V4L2_IDENT_MT9V022IX7ATC
)
393 /* No format change, only geometry */
399 /* No support for scaling on this camera, just crop. */
400 ret
= mt9v022_s_crop(sd
, &a
);
402 pix
->width
= mt9v022
->rect
.width
;
403 pix
->height
= mt9v022
->rect
.height
;
404 mt9v022
->fourcc
= pix
->pixelformat
;
410 static int mt9v022_try_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
412 struct i2c_client
*client
= sd
->priv
;
413 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
414 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
415 int align
= pix
->pixelformat
== V4L2_PIX_FMT_SBGGR8
||
416 pix
->pixelformat
== V4L2_PIX_FMT_SBGGR16
;
418 v4l_bound_align_image(&pix
->width
, MT9V022_MIN_WIDTH
,
419 MT9V022_MAX_WIDTH
, align
,
420 &pix
->height
, MT9V022_MIN_HEIGHT
+ icd
->y_skip_top
,
421 MT9V022_MAX_HEIGHT
+ icd
->y_skip_top
, align
, 0);
426 static int mt9v022_g_chip_ident(struct v4l2_subdev
*sd
,
427 struct v4l2_dbg_chip_ident
*id
)
429 struct i2c_client
*client
= sd
->priv
;
430 struct mt9v022
*mt9v022
= to_mt9v022(client
);
432 if (id
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
)
435 if (id
->match
.addr
!= client
->addr
)
438 id
->ident
= mt9v022
->model
;
444 #ifdef CONFIG_VIDEO_ADV_DEBUG
445 static int mt9v022_g_register(struct v4l2_subdev
*sd
,
446 struct v4l2_dbg_register
*reg
)
448 struct i2c_client
*client
= sd
->priv
;
450 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
453 if (reg
->match
.addr
!= client
->addr
)
457 reg
->val
= reg_read(client
, reg
->reg
);
459 if (reg
->val
> 0xffff)
465 static int mt9v022_s_register(struct v4l2_subdev
*sd
,
466 struct v4l2_dbg_register
*reg
)
468 struct i2c_client
*client
= sd
->priv
;
470 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
473 if (reg
->match
.addr
!= client
->addr
)
476 if (reg_write(client
, reg
->reg
, reg
->val
) < 0)
483 static const struct v4l2_queryctrl mt9v022_controls
[] = {
485 .id
= V4L2_CID_VFLIP
,
486 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
487 .name
= "Flip Vertically",
493 .id
= V4L2_CID_HFLIP
,
494 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
495 .name
= "Flip Horizontally",
502 .type
= V4L2_CTRL_TYPE_INTEGER
,
503 .name
= "Analog Gain",
508 .flags
= V4L2_CTRL_FLAG_SLIDER
,
510 .id
= V4L2_CID_EXPOSURE
,
511 .type
= V4L2_CTRL_TYPE_INTEGER
,
516 .default_value
= 255,
517 .flags
= V4L2_CTRL_FLAG_SLIDER
,
519 .id
= V4L2_CID_AUTOGAIN
,
520 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
521 .name
= "Automatic Gain",
527 .id
= V4L2_CID_EXPOSURE_AUTO
,
528 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
529 .name
= "Automatic Exposure",
537 static struct soc_camera_ops mt9v022_ops
= {
538 .set_bus_param
= mt9v022_set_bus_param
,
539 .query_bus_param
= mt9v022_query_bus_param
,
540 .controls
= mt9v022_controls
,
541 .num_controls
= ARRAY_SIZE(mt9v022_controls
),
544 static int mt9v022_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
546 struct i2c_client
*client
= sd
->priv
;
547 const struct v4l2_queryctrl
*qctrl
;
551 qctrl
= soc_camera_find_qctrl(&mt9v022_ops
, ctrl
->id
);
555 data
= reg_read(client
, MT9V022_READ_MODE
);
558 ctrl
->value
= !!(data
& 0x10);
561 data
= reg_read(client
, MT9V022_READ_MODE
);
564 ctrl
->value
= !!(data
& 0x20);
566 case V4L2_CID_EXPOSURE_AUTO
:
567 data
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
570 ctrl
->value
= !!(data
& 0x1);
572 case V4L2_CID_AUTOGAIN
:
573 data
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
576 ctrl
->value
= !!(data
& 0x2);
579 data
= reg_read(client
, MT9V022_ANALOG_GAIN
);
583 range
= qctrl
->maximum
- qctrl
->minimum
;
584 ctrl
->value
= ((data
- 16) * range
+ 24) / 48 + qctrl
->minimum
;
587 case V4L2_CID_EXPOSURE
:
588 data
= reg_read(client
, MT9V022_TOTAL_SHUTTER_WIDTH
);
592 range
= qctrl
->maximum
- qctrl
->minimum
;
593 ctrl
->value
= ((data
- 1) * range
+ 239) / 479 + qctrl
->minimum
;
600 static int mt9v022_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
603 struct i2c_client
*client
= sd
->priv
;
604 const struct v4l2_queryctrl
*qctrl
;
606 qctrl
= soc_camera_find_qctrl(&mt9v022_ops
, ctrl
->id
);
613 data
= reg_set(client
, MT9V022_READ_MODE
, 0x10);
615 data
= reg_clear(client
, MT9V022_READ_MODE
, 0x10);
621 data
= reg_set(client
, MT9V022_READ_MODE
, 0x20);
623 data
= reg_clear(client
, MT9V022_READ_MODE
, 0x20);
628 /* mt9v022 has minimum == default */
629 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
632 unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
633 /* Valid values 16 to 64, 32 to 64 must be even. */
634 unsigned long gain
= ((ctrl
->value
- qctrl
->minimum
) *
635 48 + range
/ 2) / range
+ 16;
638 /* The user wants to set gain manually, hope, she
639 * knows, what she's doing... Switch AGC off. */
641 if (reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x2) < 0)
644 dev_dbg(&client
->dev
, "Setting gain from %d to %lu\n",
645 reg_read(client
, MT9V022_ANALOG_GAIN
), gain
);
646 if (reg_write(client
, MT9V022_ANALOG_GAIN
, gain
) < 0)
650 case V4L2_CID_EXPOSURE
:
651 /* mt9v022 has maximum == default */
652 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
655 unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
656 unsigned long shutter
= ((ctrl
->value
- qctrl
->minimum
) *
657 479 + range
/ 2) / range
+ 1;
658 /* The user wants to set shutter width manually, hope,
659 * she knows, what she's doing... Switch AEC off. */
661 if (reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x1) < 0)
664 dev_dbg(&client
->dev
, "Shutter width from %d to %lu\n",
665 reg_read(client
, MT9V022_TOTAL_SHUTTER_WIDTH
),
667 if (reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
,
672 case V4L2_CID_AUTOGAIN
:
674 data
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x2);
676 data
= reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x2);
680 case V4L2_CID_EXPOSURE_AUTO
:
682 data
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x1);
684 data
= reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x1);
692 /* Interface active, can use i2c. If it fails, it can indeed mean, that
693 * this wasn't our capture interface, so, we wait for the right one */
694 static int mt9v022_video_probe(struct soc_camera_device
*icd
,
695 struct i2c_client
*client
)
697 struct mt9v022
*mt9v022
= to_mt9v022(client
);
698 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
703 if (!icd
->dev
.parent
||
704 to_soc_camera_host(icd
->dev
.parent
)->nr
!= icd
->iface
)
707 /* Read out the chip version register */
708 data
= reg_read(client
, MT9V022_CHIP_VERSION
);
710 /* must be 0x1311 or 0x1313 */
711 if (data
!= 0x1311 && data
!= 0x1313) {
713 dev_info(&client
->dev
, "No MT9V022 found, ID register 0x%x\n",
719 ret
= reg_write(client
, MT9V022_RESET
, 1);
722 /* 15 clock cycles */
724 if (reg_read(client
, MT9V022_RESET
)) {
725 dev_err(&client
->dev
, "Resetting MT9V022 failed!\n");
731 /* Set monochrome or colour sensor type */
732 if (sensor_type
&& (!strcmp("colour", sensor_type
) ||
733 !strcmp("color", sensor_type
))) {
734 ret
= reg_write(client
, MT9V022_PIXEL_OPERATION_MODE
, 4 | 0x11);
735 mt9v022
->model
= V4L2_IDENT_MT9V022IX7ATC
;
736 icd
->formats
= mt9v022_colour_formats
;
738 ret
= reg_write(client
, MT9V022_PIXEL_OPERATION_MODE
, 0x11);
739 mt9v022
->model
= V4L2_IDENT_MT9V022IX7ATM
;
740 icd
->formats
= mt9v022_monochrome_formats
;
746 icd
->num_formats
= 0;
749 * This is a 10bit sensor, so by default we only allow 10bit.
750 * The platform may support different bus widths due to
751 * different routing of the data lines.
753 if (icl
->query_bus_param
)
754 flags
= icl
->query_bus_param(icl
);
756 flags
= SOCAM_DATAWIDTH_10
;
758 if (flags
& SOCAM_DATAWIDTH_10
)
763 if (flags
& SOCAM_DATAWIDTH_8
)
766 mt9v022
->fourcc
= icd
->formats
->fourcc
;
768 dev_info(&client
->dev
, "Detected a MT9V022 chip ID %x, %s sensor\n",
769 data
, mt9v022
->model
== V4L2_IDENT_MT9V022IX7ATM
?
770 "monochrome" : "colour");
772 ret
= mt9v022_init(client
);
774 dev_err(&client
->dev
, "Failed to initialise the camera\n");
780 static void mt9v022_video_remove(struct soc_camera_device
*icd
)
782 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
784 dev_dbg(&icd
->dev
, "Video removed: %p, %p\n",
785 icd
->dev
.parent
, icd
->vdev
);
790 static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops
= {
791 .g_ctrl
= mt9v022_g_ctrl
,
792 .s_ctrl
= mt9v022_s_ctrl
,
793 .g_chip_ident
= mt9v022_g_chip_ident
,
794 #ifdef CONFIG_VIDEO_ADV_DEBUG
795 .g_register
= mt9v022_g_register
,
796 .s_register
= mt9v022_s_register
,
800 static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops
= {
801 .s_stream
= mt9v022_s_stream
,
802 .s_fmt
= mt9v022_s_fmt
,
803 .g_fmt
= mt9v022_g_fmt
,
804 .try_fmt
= mt9v022_try_fmt
,
805 .s_crop
= mt9v022_s_crop
,
806 .g_crop
= mt9v022_g_crop
,
807 .cropcap
= mt9v022_cropcap
,
810 static struct v4l2_subdev_ops mt9v022_subdev_ops
= {
811 .core
= &mt9v022_subdev_core_ops
,
812 .video
= &mt9v022_subdev_video_ops
,
815 static int mt9v022_probe(struct i2c_client
*client
,
816 const struct i2c_device_id
*did
)
818 struct mt9v022
*mt9v022
;
819 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
820 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
821 struct soc_camera_link
*icl
;
825 dev_err(&client
->dev
, "MT9V022: missing soc-camera data!\n");
829 icl
= to_soc_camera_link(icd
);
831 dev_err(&client
->dev
, "MT9V022 driver needs platform data\n");
835 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
)) {
836 dev_warn(&adapter
->dev
,
837 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
841 mt9v022
= kzalloc(sizeof(struct mt9v022
), GFP_KERNEL
);
845 v4l2_i2c_subdev_init(&mt9v022
->subdev
, client
, &mt9v022_subdev_ops
);
847 mt9v022
->chip_control
= MT9V022_CHIP_CONTROL_DEFAULT
;
849 icd
->ops
= &mt9v022_ops
;
851 * MT9V022 _really_ corrupts the first read out line.
852 * TODO: verify on i.MX31
856 mt9v022
->rect
.left
= MT9V022_COLUMN_SKIP
;
857 mt9v022
->rect
.top
= MT9V022_ROW_SKIP
;
858 mt9v022
->rect
.width
= MT9V022_MAX_WIDTH
;
859 mt9v022
->rect
.height
= MT9V022_MAX_HEIGHT
;
861 ret
= mt9v022_video_probe(icd
, client
);
864 i2c_set_clientdata(client
, NULL
);
871 static int mt9v022_remove(struct i2c_client
*client
)
873 struct mt9v022
*mt9v022
= to_mt9v022(client
);
874 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
877 mt9v022_video_remove(icd
);
878 i2c_set_clientdata(client
, NULL
);
879 client
->driver
= NULL
;
884 static const struct i2c_device_id mt9v022_id
[] = {
888 MODULE_DEVICE_TABLE(i2c
, mt9v022_id
);
890 static struct i2c_driver mt9v022_i2c_driver
= {
894 .probe
= mt9v022_probe
,
895 .remove
= mt9v022_remove
,
896 .id_table
= mt9v022_id
,
899 static int __init
mt9v022_mod_init(void)
901 return i2c_add_driver(&mt9v022_i2c_driver
);
904 static void __exit
mt9v022_mod_exit(void)
906 i2c_del_driver(&mt9v022_i2c_driver
);
909 module_init(mt9v022_mod_init
);
910 module_exit(mt9v022_mod_exit
);
912 MODULE_DESCRIPTION("Micron MT9V022 Camera driver");
913 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
914 MODULE_LICENSE("GPL");