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 soc_camera_device
*icd
)
143 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
144 struct mt9v022
*mt9v022
= to_mt9v022(client
);
147 /* Almost the default mode: master, parallel, simultaneous, and an
148 * undocumented bit 0x200, which is present in table 7, but not in 8,
149 * plus snapshot mode to disable scan for now */
150 mt9v022
->chip_control
|= 0x10;
151 ret
= reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
);
153 ret
= reg_write(client
, MT9V022_READ_MODE
, 0x300);
158 ret
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x3);
160 ret
= reg_write(client
, MT9V022_MAX_TOTAL_SHUTTER_WIDTH
, 480);
163 ret
= reg_clear(client
, MT9V022_BLACK_LEVEL_CALIB_CTRL
, 1);
165 ret
= reg_write(client
, MT9V022_DIGITAL_TEST_PATTERN
, 0);
170 static int mt9v022_s_stream(struct v4l2_subdev
*sd
, int enable
)
172 struct i2c_client
*client
= sd
->priv
;
173 struct mt9v022
*mt9v022
= to_mt9v022(client
);
176 /* Switch to master "normal" mode */
177 mt9v022
->chip_control
&= ~0x10;
179 /* Switch to snapshot mode */
180 mt9v022
->chip_control
|= 0x10;
182 if (reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
) < 0)
187 static int mt9v022_set_bus_param(struct soc_camera_device
*icd
,
190 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
191 struct mt9v022
*mt9v022
= to_mt9v022(client
);
192 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
193 unsigned int width_flag
= flags
& SOCAM_DATAWIDTH_MASK
;
197 /* Only one width bit may be set */
198 if (!is_power_of_2(width_flag
))
201 if (icl
->set_bus_param
) {
202 ret
= icl
->set_bus_param(icl
, width_flag
);
207 * Without board specific bus width settings we only support the
208 * sensors native bus width
210 if (width_flag
!= SOCAM_DATAWIDTH_10
)
214 flags
= soc_camera_apply_sensor_flags(icl
, flags
);
216 if (flags
& SOCAM_PCLK_SAMPLE_RISING
)
219 if (!(flags
& SOCAM_HSYNC_ACTIVE_HIGH
))
222 if (!(flags
& SOCAM_VSYNC_ACTIVE_HIGH
))
225 ret
= reg_write(client
, MT9V022_PIXCLK_FV_LV
, pixclk
);
229 if (!(flags
& SOCAM_MASTER
))
230 mt9v022
->chip_control
&= ~0x8;
232 ret
= reg_write(client
, MT9V022_CHIP_CONTROL
, mt9v022
->chip_control
);
236 dev_dbg(&client
->dev
, "Calculated pixclk 0x%x, chip control 0x%x\n",
237 pixclk
, mt9v022
->chip_control
);
242 static unsigned long mt9v022_query_bus_param(struct soc_camera_device
*icd
)
244 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
245 unsigned int width_flag
;
247 if (icl
->query_bus_param
)
248 width_flag
= icl
->query_bus_param(icl
) &
249 SOCAM_DATAWIDTH_MASK
;
251 width_flag
= SOCAM_DATAWIDTH_10
;
253 return SOCAM_PCLK_SAMPLE_RISING
| SOCAM_PCLK_SAMPLE_FALLING
|
254 SOCAM_HSYNC_ACTIVE_HIGH
| SOCAM_HSYNC_ACTIVE_LOW
|
255 SOCAM_VSYNC_ACTIVE_HIGH
| SOCAM_VSYNC_ACTIVE_LOW
|
256 SOCAM_DATA_ACTIVE_HIGH
| SOCAM_MASTER
| SOCAM_SLAVE
|
260 static int mt9v022_s_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
262 struct i2c_client
*client
= sd
->priv
;
263 struct mt9v022
*mt9v022
= to_mt9v022(client
);
264 struct v4l2_rect rect
= a
->c
;
265 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
268 /* Bayer format - even size lengths */
269 if (mt9v022
->fourcc
== V4L2_PIX_FMT_SBGGR8
||
270 mt9v022
->fourcc
== V4L2_PIX_FMT_SBGGR16
) {
271 rect
.width
= ALIGN(rect
.width
, 2);
272 rect
.height
= ALIGN(rect
.height
, 2);
273 /* Let the user play with the starting pixel */
276 soc_camera_limit_side(&rect
.left
, &rect
.width
,
277 MT9V022_COLUMN_SKIP
, MT9V022_MIN_WIDTH
, MT9V022_MAX_WIDTH
);
279 soc_camera_limit_side(&rect
.top
, &rect
.height
,
280 MT9V022_ROW_SKIP
, MT9V022_MIN_HEIGHT
, MT9V022_MAX_HEIGHT
);
282 /* Like in example app. Contradicts the datasheet though */
283 ret
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
285 if (ret
& 1) /* Autoexposure */
286 ret
= reg_write(client
, MT9V022_MAX_TOTAL_SHUTTER_WIDTH
,
287 rect
.height
+ icd
->y_skip_top
+ 43);
289 ret
= reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
,
290 rect
.height
+ icd
->y_skip_top
+ 43);
292 /* Setup frame format: defaults apart from width and height */
294 ret
= reg_write(client
, MT9V022_COLUMN_START
, rect
.left
);
296 ret
= reg_write(client
, MT9V022_ROW_START
, rect
.top
);
298 /* Default 94, Phytec driver says:
299 * "width + horizontal blank >= 660" */
300 ret
= reg_write(client
, MT9V022_HORIZONTAL_BLANKING
,
301 rect
.width
> 660 - 43 ? 43 :
304 ret
= reg_write(client
, MT9V022_VERTICAL_BLANKING
, 45);
306 ret
= reg_write(client
, MT9V022_WINDOW_WIDTH
, rect
.width
);
308 ret
= reg_write(client
, MT9V022_WINDOW_HEIGHT
,
309 rect
.height
+ icd
->y_skip_top
);
314 dev_dbg(&client
->dev
, "Frame %ux%u pixel\n", rect
.width
, rect
.height
);
316 mt9v022
->rect
= rect
;
321 static int mt9v022_g_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
323 struct i2c_client
*client
= sd
->priv
;
324 struct mt9v022
*mt9v022
= to_mt9v022(client
);
326 a
->c
= mt9v022
->rect
;
327 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
332 static int mt9v022_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*a
)
334 a
->bounds
.left
= MT9V022_COLUMN_SKIP
;
335 a
->bounds
.top
= MT9V022_ROW_SKIP
;
336 a
->bounds
.width
= MT9V022_MAX_WIDTH
;
337 a
->bounds
.height
= MT9V022_MAX_HEIGHT
;
338 a
->defrect
= a
->bounds
;
339 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
340 a
->pixelaspect
.numerator
= 1;
341 a
->pixelaspect
.denominator
= 1;
346 static int mt9v022_g_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
348 struct i2c_client
*client
= sd
->priv
;
349 struct mt9v022
*mt9v022
= to_mt9v022(client
);
350 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
352 pix
->width
= mt9v022
->rect
.width
;
353 pix
->height
= mt9v022
->rect
.height
;
354 pix
->pixelformat
= mt9v022
->fourcc
;
355 pix
->field
= V4L2_FIELD_NONE
;
356 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
361 static int mt9v022_s_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
363 struct i2c_client
*client
= sd
->priv
;
364 struct mt9v022
*mt9v022
= to_mt9v022(client
);
365 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
366 struct v4l2_crop a
= {
368 .left
= mt9v022
->rect
.left
,
369 .top
= mt9v022
->rect
.top
,
371 .height
= pix
->height
,
376 /* The caller provides a supported format, as verified per call to
377 * icd->try_fmt(), datawidth is from our supported format list */
378 switch (pix
->pixelformat
) {
379 case V4L2_PIX_FMT_GREY
:
380 case V4L2_PIX_FMT_Y16
:
381 if (mt9v022
->model
!= V4L2_IDENT_MT9V022IX7ATM
)
384 case V4L2_PIX_FMT_SBGGR8
:
385 case V4L2_PIX_FMT_SBGGR16
:
386 if (mt9v022
->model
!= V4L2_IDENT_MT9V022IX7ATC
)
390 /* No format change, only geometry */
396 /* No support for scaling on this camera, just crop. */
397 ret
= mt9v022_s_crop(sd
, &a
);
399 pix
->width
= mt9v022
->rect
.width
;
400 pix
->height
= mt9v022
->rect
.height
;
401 mt9v022
->fourcc
= pix
->pixelformat
;
407 static int mt9v022_try_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
409 struct i2c_client
*client
= sd
->priv
;
410 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
411 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
412 int align
= pix
->pixelformat
== V4L2_PIX_FMT_SBGGR8
||
413 pix
->pixelformat
== V4L2_PIX_FMT_SBGGR16
;
415 v4l_bound_align_image(&pix
->width
, MT9V022_MIN_WIDTH
,
416 MT9V022_MAX_WIDTH
, align
,
417 &pix
->height
, MT9V022_MIN_HEIGHT
+ icd
->y_skip_top
,
418 MT9V022_MAX_HEIGHT
+ icd
->y_skip_top
, align
, 0);
423 static int mt9v022_g_chip_ident(struct v4l2_subdev
*sd
,
424 struct v4l2_dbg_chip_ident
*id
)
426 struct i2c_client
*client
= sd
->priv
;
427 struct mt9v022
*mt9v022
= to_mt9v022(client
);
429 if (id
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
)
432 if (id
->match
.addr
!= client
->addr
)
435 id
->ident
= mt9v022
->model
;
441 #ifdef CONFIG_VIDEO_ADV_DEBUG
442 static int mt9v022_g_register(struct v4l2_subdev
*sd
,
443 struct v4l2_dbg_register
*reg
)
445 struct i2c_client
*client
= sd
->priv
;
447 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
450 if (reg
->match
.addr
!= client
->addr
)
454 reg
->val
= reg_read(client
, reg
->reg
);
456 if (reg
->val
> 0xffff)
462 static int mt9v022_s_register(struct v4l2_subdev
*sd
,
463 struct v4l2_dbg_register
*reg
)
465 struct i2c_client
*client
= sd
->priv
;
467 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
470 if (reg
->match
.addr
!= client
->addr
)
473 if (reg_write(client
, reg
->reg
, reg
->val
) < 0)
480 static const struct v4l2_queryctrl mt9v022_controls
[] = {
482 .id
= V4L2_CID_VFLIP
,
483 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
484 .name
= "Flip Vertically",
490 .id
= V4L2_CID_HFLIP
,
491 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
492 .name
= "Flip Horizontally",
499 .type
= V4L2_CTRL_TYPE_INTEGER
,
500 .name
= "Analog Gain",
505 .flags
= V4L2_CTRL_FLAG_SLIDER
,
507 .id
= V4L2_CID_EXPOSURE
,
508 .type
= V4L2_CTRL_TYPE_INTEGER
,
513 .default_value
= 255,
514 .flags
= V4L2_CTRL_FLAG_SLIDER
,
516 .id
= V4L2_CID_AUTOGAIN
,
517 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
518 .name
= "Automatic Gain",
524 .id
= V4L2_CID_EXPOSURE_AUTO
,
525 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
526 .name
= "Automatic Exposure",
534 static struct soc_camera_ops mt9v022_ops
= {
535 .init
= mt9v022_init
,
536 .set_bus_param
= mt9v022_set_bus_param
,
537 .query_bus_param
= mt9v022_query_bus_param
,
538 .controls
= mt9v022_controls
,
539 .num_controls
= ARRAY_SIZE(mt9v022_controls
),
542 static int mt9v022_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
544 struct i2c_client
*client
= sd
->priv
;
549 data
= reg_read(client
, MT9V022_READ_MODE
);
552 ctrl
->value
= !!(data
& 0x10);
555 data
= reg_read(client
, MT9V022_READ_MODE
);
558 ctrl
->value
= !!(data
& 0x20);
560 case V4L2_CID_EXPOSURE_AUTO
:
561 data
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
564 ctrl
->value
= !!(data
& 0x1);
566 case V4L2_CID_AUTOGAIN
:
567 data
= reg_read(client
, MT9V022_AEC_AGC_ENABLE
);
570 ctrl
->value
= !!(data
& 0x2);
576 static int mt9v022_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
579 struct i2c_client
*client
= sd
->priv
;
580 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
581 const struct v4l2_queryctrl
*qctrl
;
583 qctrl
= soc_camera_find_qctrl(&mt9v022_ops
, ctrl
->id
);
590 data
= reg_set(client
, MT9V022_READ_MODE
, 0x10);
592 data
= reg_clear(client
, MT9V022_READ_MODE
, 0x10);
598 data
= reg_set(client
, MT9V022_READ_MODE
, 0x20);
600 data
= reg_clear(client
, MT9V022_READ_MODE
, 0x20);
605 /* mt9v022 has minimum == default */
606 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
609 unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
610 /* Datasheet says 16 to 64. autogain only works properly
611 * after setting gain to maximum 14. Larger values
612 * produce "white fly" noise effect. On the whole,
613 * manually setting analog gain does no good. */
614 unsigned long gain
= ((ctrl
->value
- qctrl
->minimum
) *
615 10 + range
/ 2) / range
+ 4;
618 /* The user wants to set gain manually, hope, she
619 * knows, what she's doing... Switch AGC off. */
621 if (reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x2) < 0)
624 dev_info(&client
->dev
, "Setting gain from %d to %lu\n",
625 reg_read(client
, MT9V022_ANALOG_GAIN
), gain
);
626 if (reg_write(client
, MT9V022_ANALOG_GAIN
, gain
) < 0)
628 icd
->gain
= ctrl
->value
;
631 case V4L2_CID_EXPOSURE
:
632 /* mt9v022 has maximum == default */
633 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
636 unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
637 unsigned long shutter
= ((ctrl
->value
- qctrl
->minimum
) *
638 479 + range
/ 2) / range
+ 1;
639 /* The user wants to set shutter width manually, hope,
640 * she knows, what she's doing... Switch AEC off. */
642 if (reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x1) < 0)
645 dev_dbg(&client
->dev
, "Shutter width from %d to %lu\n",
646 reg_read(client
, MT9V022_TOTAL_SHUTTER_WIDTH
),
648 if (reg_write(client
, MT9V022_TOTAL_SHUTTER_WIDTH
,
651 icd
->exposure
= ctrl
->value
;
654 case V4L2_CID_AUTOGAIN
:
656 data
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x2);
658 data
= reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x2);
662 case V4L2_CID_EXPOSURE_AUTO
:
664 data
= reg_set(client
, MT9V022_AEC_AGC_ENABLE
, 0x1);
666 data
= reg_clear(client
, MT9V022_AEC_AGC_ENABLE
, 0x1);
674 /* Interface active, can use i2c. If it fails, it can indeed mean, that
675 * this wasn't our capture interface, so, we wait for the right one */
676 static int mt9v022_video_probe(struct soc_camera_device
*icd
,
677 struct i2c_client
*client
)
679 struct mt9v022
*mt9v022
= to_mt9v022(client
);
680 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
685 if (!icd
->dev
.parent
||
686 to_soc_camera_host(icd
->dev
.parent
)->nr
!= icd
->iface
)
689 /* Read out the chip version register */
690 data
= reg_read(client
, MT9V022_CHIP_VERSION
);
692 /* must be 0x1311 or 0x1313 */
693 if (data
!= 0x1311 && data
!= 0x1313) {
695 dev_info(&client
->dev
, "No MT9V022 found, ID register 0x%x\n",
701 ret
= reg_write(client
, MT9V022_RESET
, 1);
704 /* 15 clock cycles */
706 if (reg_read(client
, MT9V022_RESET
)) {
707 dev_err(&client
->dev
, "Resetting MT9V022 failed!\n");
713 /* Set monochrome or colour sensor type */
714 if (sensor_type
&& (!strcmp("colour", sensor_type
) ||
715 !strcmp("color", sensor_type
))) {
716 ret
= reg_write(client
, MT9V022_PIXEL_OPERATION_MODE
, 4 | 0x11);
717 mt9v022
->model
= V4L2_IDENT_MT9V022IX7ATC
;
718 icd
->formats
= mt9v022_colour_formats
;
720 ret
= reg_write(client
, MT9V022_PIXEL_OPERATION_MODE
, 0x11);
721 mt9v022
->model
= V4L2_IDENT_MT9V022IX7ATM
;
722 icd
->formats
= mt9v022_monochrome_formats
;
728 icd
->num_formats
= 0;
731 * This is a 10bit sensor, so by default we only allow 10bit.
732 * The platform may support different bus widths due to
733 * different routing of the data lines.
735 if (icl
->query_bus_param
)
736 flags
= icl
->query_bus_param(icl
);
738 flags
= SOCAM_DATAWIDTH_10
;
740 if (flags
& SOCAM_DATAWIDTH_10
)
745 if (flags
& SOCAM_DATAWIDTH_8
)
748 mt9v022
->fourcc
= icd
->formats
->fourcc
;
750 dev_info(&client
->dev
, "Detected a MT9V022 chip ID %x, %s sensor\n",
751 data
, mt9v022
->model
== V4L2_IDENT_MT9V022IX7ATM
?
752 "monochrome" : "colour");
758 static void mt9v022_video_remove(struct soc_camera_device
*icd
)
760 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
762 dev_dbg(&icd
->dev
, "Video removed: %p, %p\n",
763 icd
->dev
.parent
, icd
->vdev
);
768 static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops
= {
769 .g_ctrl
= mt9v022_g_ctrl
,
770 .s_ctrl
= mt9v022_s_ctrl
,
771 .g_chip_ident
= mt9v022_g_chip_ident
,
772 #ifdef CONFIG_VIDEO_ADV_DEBUG
773 .g_register
= mt9v022_g_register
,
774 .s_register
= mt9v022_s_register
,
778 static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops
= {
779 .s_stream
= mt9v022_s_stream
,
780 .s_fmt
= mt9v022_s_fmt
,
781 .g_fmt
= mt9v022_g_fmt
,
782 .try_fmt
= mt9v022_try_fmt
,
783 .s_crop
= mt9v022_s_crop
,
784 .g_crop
= mt9v022_g_crop
,
785 .cropcap
= mt9v022_cropcap
,
788 static struct v4l2_subdev_ops mt9v022_subdev_ops
= {
789 .core
= &mt9v022_subdev_core_ops
,
790 .video
= &mt9v022_subdev_video_ops
,
793 static int mt9v022_probe(struct i2c_client
*client
,
794 const struct i2c_device_id
*did
)
796 struct mt9v022
*mt9v022
;
797 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
798 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
799 struct soc_camera_link
*icl
;
803 dev_err(&client
->dev
, "MT9V022: missing soc-camera data!\n");
807 icl
= to_soc_camera_link(icd
);
809 dev_err(&client
->dev
, "MT9V022 driver needs platform data\n");
813 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
)) {
814 dev_warn(&adapter
->dev
,
815 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
819 mt9v022
= kzalloc(sizeof(struct mt9v022
), GFP_KERNEL
);
823 v4l2_i2c_subdev_init(&mt9v022
->subdev
, client
, &mt9v022_subdev_ops
);
825 mt9v022
->chip_control
= MT9V022_CHIP_CONTROL_DEFAULT
;
827 icd
->ops
= &mt9v022_ops
;
830 mt9v022
->rect
.left
= MT9V022_COLUMN_SKIP
;
831 mt9v022
->rect
.top
= MT9V022_ROW_SKIP
;
832 mt9v022
->rect
.width
= MT9V022_MAX_WIDTH
;
833 mt9v022
->rect
.height
= MT9V022_MAX_HEIGHT
;
835 ret
= mt9v022_video_probe(icd
, client
);
838 i2c_set_clientdata(client
, NULL
);
845 static int mt9v022_remove(struct i2c_client
*client
)
847 struct mt9v022
*mt9v022
= to_mt9v022(client
);
848 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
851 mt9v022_video_remove(icd
);
852 i2c_set_clientdata(client
, NULL
);
853 client
->driver
= NULL
;
858 static const struct i2c_device_id mt9v022_id
[] = {
862 MODULE_DEVICE_TABLE(i2c
, mt9v022_id
);
864 static struct i2c_driver mt9v022_i2c_driver
= {
868 .probe
= mt9v022_probe
,
869 .remove
= mt9v022_remove
,
870 .id_table
= mt9v022_id
,
873 static int __init
mt9v022_mod_init(void)
875 return i2c_add_driver(&mt9v022_i2c_driver
);
878 static void __exit
mt9v022_mod_exit(void)
880 i2c_del_driver(&mt9v022_i2c_driver
);
883 module_init(mt9v022_mod_init
);
884 module_exit(mt9v022_mod_exit
);
886 MODULE_DESCRIPTION("Micron MT9V022 Camera driver");
887 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
888 MODULE_LICENSE("GPL");