2 * Driver for MT9T031 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski, DENX Software Engineering <lg@denx.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/log2.h>
16 #include <media/v4l2-subdev.h>
17 #include <media/v4l2-chip-ident.h>
18 #include <media/soc_camera.h>
21 * mt9t031 i2c address 0x5d
22 * The platform has to define i2c_board_info and link to it from
23 * struct soc_camera_link
26 /* mt9t031 selected register addresses */
27 #define MT9T031_CHIP_VERSION 0x00
28 #define MT9T031_ROW_START 0x01
29 #define MT9T031_COLUMN_START 0x02
30 #define MT9T031_WINDOW_HEIGHT 0x03
31 #define MT9T031_WINDOW_WIDTH 0x04
32 #define MT9T031_HORIZONTAL_BLANKING 0x05
33 #define MT9T031_VERTICAL_BLANKING 0x06
34 #define MT9T031_OUTPUT_CONTROL 0x07
35 #define MT9T031_SHUTTER_WIDTH_UPPER 0x08
36 #define MT9T031_SHUTTER_WIDTH 0x09
37 #define MT9T031_PIXEL_CLOCK_CONTROL 0x0a
38 #define MT9T031_FRAME_RESTART 0x0b
39 #define MT9T031_SHUTTER_DELAY 0x0c
40 #define MT9T031_RESET 0x0d
41 #define MT9T031_READ_MODE_1 0x1e
42 #define MT9T031_READ_MODE_2 0x20
43 #define MT9T031_READ_MODE_3 0x21
44 #define MT9T031_ROW_ADDRESS_MODE 0x22
45 #define MT9T031_COLUMN_ADDRESS_MODE 0x23
46 #define MT9T031_GLOBAL_GAIN 0x35
47 #define MT9T031_CHIP_ENABLE 0xF8
49 #define MT9T031_MAX_HEIGHT 1536
50 #define MT9T031_MAX_WIDTH 2048
51 #define MT9T031_MIN_HEIGHT 2
52 #define MT9T031_MIN_WIDTH 18
53 #define MT9T031_HORIZONTAL_BLANK 142
54 #define MT9T031_VERTICAL_BLANK 25
55 #define MT9T031_COLUMN_SKIP 32
56 #define MT9T031_ROW_SKIP 20
58 #define MT9T031_BUS_PARAM (SOCAM_PCLK_SAMPLE_RISING | \
59 SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH | \
60 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH | \
61 SOCAM_MASTER | SOCAM_DATAWIDTH_10)
64 struct v4l2_subdev subdev
;
65 struct v4l2_rect rect
; /* Sensor window */
66 int model
; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */
70 unsigned short y_skip_top
; /* Lines to skip at the top */
71 unsigned int exposure
;
72 unsigned char autoexposure
;
75 static struct mt9t031
*to_mt9t031(const struct i2c_client
*client
)
77 return container_of(i2c_get_clientdata(client
), struct mt9t031
, subdev
);
80 static int reg_read(struct i2c_client
*client
, const u8 reg
)
82 s32 data
= i2c_smbus_read_word_data(client
, reg
);
83 return data
< 0 ? data
: swab16(data
);
86 static int reg_write(struct i2c_client
*client
, const u8 reg
,
89 return i2c_smbus_write_word_data(client
, reg
, swab16(data
));
92 static int reg_set(struct i2c_client
*client
, const u8 reg
,
97 ret
= reg_read(client
, reg
);
100 return reg_write(client
, reg
, ret
| data
);
103 static int reg_clear(struct i2c_client
*client
, const u8 reg
,
108 ret
= reg_read(client
, reg
);
111 return reg_write(client
, reg
, ret
& ~data
);
114 static int set_shutter(struct i2c_client
*client
, const u32 data
)
118 ret
= reg_write(client
, MT9T031_SHUTTER_WIDTH_UPPER
, data
>> 16);
121 ret
= reg_write(client
, MT9T031_SHUTTER_WIDTH
, data
& 0xffff);
126 static int get_shutter(struct i2c_client
*client
, u32
*data
)
130 ret
= reg_read(client
, MT9T031_SHUTTER_WIDTH_UPPER
);
134 ret
= reg_read(client
, MT9T031_SHUTTER_WIDTH
);
135 *data
|= ret
& 0xffff;
137 return ret
< 0 ? ret
: 0;
140 static int mt9t031_idle(struct i2c_client
*client
)
144 /* Disable chip output, synchronous option update */
145 ret
= reg_write(client
, MT9T031_RESET
, 1);
147 ret
= reg_write(client
, MT9T031_RESET
, 0);
149 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 2);
151 return ret
>= 0 ? 0 : -EIO
;
154 static int mt9t031_disable(struct i2c_client
*client
)
156 /* Disable the chip */
157 reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 2);
162 static int mt9t031_s_stream(struct v4l2_subdev
*sd
, int enable
)
164 struct i2c_client
*client
= sd
->priv
;
168 /* Switch to master "normal" mode */
169 ret
= reg_set(client
, MT9T031_OUTPUT_CONTROL
, 2);
171 /* Stop sensor readout */
172 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 2);
180 static int mt9t031_set_bus_param(struct soc_camera_device
*icd
,
183 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
185 /* The caller should have queried our parameters, check anyway */
186 if (flags
& ~MT9T031_BUS_PARAM
)
189 if (flags
& SOCAM_PCLK_SAMPLE_FALLING
)
190 reg_clear(client
, MT9T031_PIXEL_CLOCK_CONTROL
, 0x8000);
192 reg_set(client
, MT9T031_PIXEL_CLOCK_CONTROL
, 0x8000);
197 static unsigned long mt9t031_query_bus_param(struct soc_camera_device
*icd
)
199 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
201 return soc_camera_apply_sensor_flags(icl
, MT9T031_BUS_PARAM
);
208 MT9T031_CTRL_EXPOSURE
,
209 MT9T031_CTRL_EXPOSURE_AUTO
,
212 static const struct v4l2_queryctrl mt9t031_controls
[] = {
213 [MT9T031_CTRL_VFLIP
] = {
214 .id
= V4L2_CID_VFLIP
,
215 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
216 .name
= "Flip Vertically",
222 [MT9T031_CTRL_HFLIP
] = {
223 .id
= V4L2_CID_HFLIP
,
224 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
225 .name
= "Flip Horizontally",
231 [MT9T031_CTRL_GAIN
] = {
233 .type
= V4L2_CTRL_TYPE_INTEGER
,
239 .flags
= V4L2_CTRL_FLAG_SLIDER
,
241 [MT9T031_CTRL_EXPOSURE
] = {
242 .id
= V4L2_CID_EXPOSURE
,
243 .type
= V4L2_CTRL_TYPE_INTEGER
,
248 .default_value
= 255,
249 .flags
= V4L2_CTRL_FLAG_SLIDER
,
251 [MT9T031_CTRL_EXPOSURE_AUTO
] = {
252 .id
= V4L2_CID_EXPOSURE_AUTO
,
253 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
254 .name
= "Automatic Exposure",
262 static struct soc_camera_ops mt9t031_ops
= {
263 .set_bus_param
= mt9t031_set_bus_param
,
264 .query_bus_param
= mt9t031_query_bus_param
,
265 .controls
= mt9t031_controls
,
266 .num_controls
= ARRAY_SIZE(mt9t031_controls
),
269 /* target must be _even_ */
270 static u16
mt9t031_skip(s32
*source
, s32 target
, s32 max
)
274 if (*source
< target
+ target
/ 2) {
279 skip
= min(max
, *source
+ target
/ 2) / target
;
282 *source
= target
* skip
;
287 /* rect is the sensor rectangle, the caller guarantees parameter validity */
288 static int mt9t031_set_params(struct i2c_client
*client
,
289 struct v4l2_rect
*rect
, u16 xskip
, u16 yskip
)
291 struct mt9t031
*mt9t031
= to_mt9t031(client
);
294 const u16 hblank
= MT9T031_HORIZONTAL_BLANK
,
295 vblank
= MT9T031_VERTICAL_BLANK
;
297 xbin
= min(xskip
, (u16
)3);
298 ybin
= min(yskip
, (u16
)3);
301 * Could just do roundup(rect->left, [xy]bin * 2); but this is cheaper.
302 * There is always a valid suitably aligned value. The worst case is
303 * xbin = 3, width = 2048. Then we will start at 36, the last read out
304 * pixel will be 2083, which is < 2085 - first black pixel.
306 * MT9T031 datasheet imposes window left border alignment, depending on
307 * the selected xskip. Failing to conform to this requirement produces
308 * dark horizontal stripes in the image. However, even obeying to this
309 * requirement doesn't eliminate the stripes in all configurations. They
310 * appear "locally reproducibly," but can differ between tests under
311 * different lighting conditions.
321 rect
->left
= rect
->left
> roundup(MT9T031_COLUMN_SKIP
, 6) ?
322 (rect
->left
/ 6) * 6 : roundup(MT9T031_COLUMN_SKIP
, 6);
327 dev_dbg(&client
->dev
, "skip %u:%u, rect %ux%u@%u:%u\n",
328 xskip
, yskip
, rect
->width
, rect
->height
, rect
->left
, rect
->top
);
330 /* Disable register update, reconfigure atomically */
331 ret
= reg_set(client
, MT9T031_OUTPUT_CONTROL
, 1);
335 /* Blanking and start values - default... */
336 ret
= reg_write(client
, MT9T031_HORIZONTAL_BLANKING
, hblank
);
338 ret
= reg_write(client
, MT9T031_VERTICAL_BLANKING
, vblank
);
340 if (yskip
!= mt9t031
->yskip
|| xskip
!= mt9t031
->xskip
) {
341 /* Binning, skipping */
343 ret
= reg_write(client
, MT9T031_COLUMN_ADDRESS_MODE
,
344 ((xbin
- 1) << 4) | (xskip
- 1));
346 ret
= reg_write(client
, MT9T031_ROW_ADDRESS_MODE
,
347 ((ybin
- 1) << 4) | (yskip
- 1));
349 dev_dbg(&client
->dev
, "new physical left %u, top %u\n",
350 rect
->left
, rect
->top
);
353 * The caller provides a supported format, as guaranteed by
354 * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap()
357 ret
= reg_write(client
, MT9T031_COLUMN_START
, rect
->left
);
359 ret
= reg_write(client
, MT9T031_ROW_START
, rect
->top
);
361 ret
= reg_write(client
, MT9T031_WINDOW_WIDTH
, rect
->width
- 1);
363 ret
= reg_write(client
, MT9T031_WINDOW_HEIGHT
,
364 rect
->height
+ mt9t031
->y_skip_top
- 1);
365 if (ret
>= 0 && mt9t031
->autoexposure
) {
366 unsigned int total_h
= rect
->height
+ mt9t031
->y_skip_top
+ vblank
;
367 ret
= set_shutter(client
, total_h
);
369 const u32 shutter_max
= MT9T031_MAX_HEIGHT
+ vblank
;
370 const struct v4l2_queryctrl
*qctrl
=
371 &mt9t031_controls
[MT9T031_CTRL_EXPOSURE
];
372 mt9t031
->exposure
= (shutter_max
/ 2 + (total_h
- 1) *
373 (qctrl
->maximum
- qctrl
->minimum
)) /
374 shutter_max
+ qctrl
->minimum
;
378 /* Re-enable register update, commit all changes */
380 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 1);
383 mt9t031
->rect
= *rect
;
384 mt9t031
->xskip
= xskip
;
385 mt9t031
->yskip
= yskip
;
388 return ret
< 0 ? ret
: 0;
391 static int mt9t031_s_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
393 struct v4l2_rect rect
= a
->c
;
394 struct i2c_client
*client
= sd
->priv
;
395 struct mt9t031
*mt9t031
= to_mt9t031(client
);
397 rect
.width
= ALIGN(rect
.width
, 2);
398 rect
.height
= ALIGN(rect
.height
, 2);
400 soc_camera_limit_side(&rect
.left
, &rect
.width
,
401 MT9T031_COLUMN_SKIP
, MT9T031_MIN_WIDTH
, MT9T031_MAX_WIDTH
);
403 soc_camera_limit_side(&rect
.top
, &rect
.height
,
404 MT9T031_ROW_SKIP
, MT9T031_MIN_HEIGHT
, MT9T031_MAX_HEIGHT
);
406 return mt9t031_set_params(client
, &rect
, mt9t031
->xskip
, mt9t031
->yskip
);
409 static int mt9t031_g_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
411 struct i2c_client
*client
= sd
->priv
;
412 struct mt9t031
*mt9t031
= to_mt9t031(client
);
414 a
->c
= mt9t031
->rect
;
415 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
420 static int mt9t031_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*a
)
422 a
->bounds
.left
= MT9T031_COLUMN_SKIP
;
423 a
->bounds
.top
= MT9T031_ROW_SKIP
;
424 a
->bounds
.width
= MT9T031_MAX_WIDTH
;
425 a
->bounds
.height
= MT9T031_MAX_HEIGHT
;
426 a
->defrect
= a
->bounds
;
427 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
428 a
->pixelaspect
.numerator
= 1;
429 a
->pixelaspect
.denominator
= 1;
434 static int mt9t031_g_fmt(struct v4l2_subdev
*sd
,
435 struct v4l2_mbus_framefmt
*mf
)
437 struct i2c_client
*client
= sd
->priv
;
438 struct mt9t031
*mt9t031
= to_mt9t031(client
);
440 mf
->width
= mt9t031
->rect
.width
/ mt9t031
->xskip
;
441 mf
->height
= mt9t031
->rect
.height
/ mt9t031
->yskip
;
442 mf
->code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
443 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
444 mf
->field
= V4L2_FIELD_NONE
;
449 static int mt9t031_s_fmt(struct v4l2_subdev
*sd
,
450 struct v4l2_mbus_framefmt
*mf
)
452 struct i2c_client
*client
= sd
->priv
;
453 struct mt9t031
*mt9t031
= to_mt9t031(client
);
455 struct v4l2_rect rect
= mt9t031
->rect
;
458 * try_fmt has put width and height within limits.
459 * S_FMT: use binning and skipping for scaling
461 xskip
= mt9t031_skip(&rect
.width
, mf
->width
, MT9T031_MAX_WIDTH
);
462 yskip
= mt9t031_skip(&rect
.height
, mf
->height
, MT9T031_MAX_HEIGHT
);
464 mf
->code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
465 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
467 /* mt9t031_set_params() doesn't change width and height */
468 return mt9t031_set_params(client
, &rect
, xskip
, yskip
);
472 * If a user window larger than sensor window is requested, we'll increase the
475 static int mt9t031_try_fmt(struct v4l2_subdev
*sd
,
476 struct v4l2_mbus_framefmt
*mf
)
478 v4l_bound_align_image(
479 &mf
->width
, MT9T031_MIN_WIDTH
, MT9T031_MAX_WIDTH
, 1,
480 &mf
->height
, MT9T031_MIN_HEIGHT
, MT9T031_MAX_HEIGHT
, 1, 0);
482 mf
->code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
483 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
488 static int mt9t031_g_chip_ident(struct v4l2_subdev
*sd
,
489 struct v4l2_dbg_chip_ident
*id
)
491 struct i2c_client
*client
= sd
->priv
;
492 struct mt9t031
*mt9t031
= to_mt9t031(client
);
494 if (id
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
)
497 if (id
->match
.addr
!= client
->addr
)
500 id
->ident
= mt9t031
->model
;
506 #ifdef CONFIG_VIDEO_ADV_DEBUG
507 static int mt9t031_g_register(struct v4l2_subdev
*sd
,
508 struct v4l2_dbg_register
*reg
)
510 struct i2c_client
*client
= sd
->priv
;
512 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
515 if (reg
->match
.addr
!= client
->addr
)
518 reg
->val
= reg_read(client
, reg
->reg
);
520 if (reg
->val
> 0xffff)
526 static int mt9t031_s_register(struct v4l2_subdev
*sd
,
527 struct v4l2_dbg_register
*reg
)
529 struct i2c_client
*client
= sd
->priv
;
531 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
534 if (reg
->match
.addr
!= client
->addr
)
537 if (reg_write(client
, reg
->reg
, reg
->val
) < 0)
544 static int mt9t031_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
546 struct i2c_client
*client
= sd
->priv
;
547 struct mt9t031
*mt9t031
= to_mt9t031(client
);
552 data
= reg_read(client
, MT9T031_READ_MODE_2
);
555 ctrl
->value
= !!(data
& 0x8000);
558 data
= reg_read(client
, MT9T031_READ_MODE_2
);
561 ctrl
->value
= !!(data
& 0x4000);
563 case V4L2_CID_EXPOSURE_AUTO
:
564 ctrl
->value
= mt9t031
->autoexposure
;
567 ctrl
->value
= mt9t031
->gain
;
569 case V4L2_CID_EXPOSURE
:
570 ctrl
->value
= mt9t031
->exposure
;
576 static int mt9t031_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
578 struct i2c_client
*client
= sd
->priv
;
579 struct mt9t031
*mt9t031
= to_mt9t031(client
);
580 const struct v4l2_queryctrl
*qctrl
;
586 data
= reg_set(client
, MT9T031_READ_MODE_2
, 0x8000);
588 data
= reg_clear(client
, MT9T031_READ_MODE_2
, 0x8000);
594 data
= reg_set(client
, MT9T031_READ_MODE_2
, 0x4000);
596 data
= reg_clear(client
, MT9T031_READ_MODE_2
, 0x4000);
601 qctrl
= &mt9t031_controls
[MT9T031_CTRL_GAIN
];
602 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
604 /* See Datasheet Table 7, Gain settings. */
605 if (ctrl
->value
<= qctrl
->default_value
) {
606 /* Pack it into 0..1 step 0.125, register values 0..8 */
607 unsigned long range
= qctrl
->default_value
- qctrl
->minimum
;
608 data
= ((ctrl
->value
- qctrl
->minimum
) * 8 + range
/ 2) / range
;
610 dev_dbg(&client
->dev
, "Setting gain %d\n", data
);
611 data
= reg_write(client
, MT9T031_GLOBAL_GAIN
, data
);
615 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
616 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
617 unsigned long range
= qctrl
->maximum
- qctrl
->default_value
- 1;
618 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
619 unsigned long gain
= ((ctrl
->value
- qctrl
->default_value
- 1) *
620 1015 + range
/ 2) / range
+ 9;
622 if (gain
<= 32) /* calculated gain 9..32 -> 9..32 */
624 else if (gain
<= 64) /* calculated gain 33..64 -> 0x51..0x60 */
625 data
= ((gain
- 32) * 16 + 16) / 32 + 80;
627 /* calculated gain 65..1024 -> (1..120) << 8 + 0x60 */
628 data
= (((gain
- 64 + 7) * 32) & 0xff00) | 0x60;
630 dev_dbg(&client
->dev
, "Set gain from 0x%x to 0x%x\n",
631 reg_read(client
, MT9T031_GLOBAL_GAIN
), data
);
632 data
= reg_write(client
, MT9T031_GLOBAL_GAIN
, data
);
638 mt9t031
->gain
= ctrl
->value
;
640 case V4L2_CID_EXPOSURE
:
641 qctrl
= &mt9t031_controls
[MT9T031_CTRL_EXPOSURE
];
642 /* mt9t031 has maximum == default */
643 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
646 const unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
647 const u32 shutter
= ((ctrl
->value
- qctrl
->minimum
) * 1048 +
648 range
/ 2) / range
+ 1;
651 get_shutter(client
, &old
);
652 dev_dbg(&client
->dev
, "Set shutter from %u to %u\n",
654 if (set_shutter(client
, shutter
) < 0)
656 mt9t031
->exposure
= ctrl
->value
;
657 mt9t031
->autoexposure
= 0;
660 case V4L2_CID_EXPOSURE_AUTO
:
662 const u16 vblank
= MT9T031_VERTICAL_BLANK
;
663 const u32 shutter_max
= MT9T031_MAX_HEIGHT
+ vblank
;
664 unsigned int total_h
= mt9t031
->rect
.height
+
665 mt9t031
->y_skip_top
+ vblank
;
667 if (set_shutter(client
, total_h
) < 0)
669 qctrl
= &mt9t031_controls
[MT9T031_CTRL_EXPOSURE
];
670 mt9t031
->exposure
= (shutter_max
/ 2 + (total_h
- 1) *
671 (qctrl
->maximum
- qctrl
->minimum
)) /
672 shutter_max
+ qctrl
->minimum
;
673 mt9t031
->autoexposure
= 1;
675 mt9t031
->autoexposure
= 0;
684 * Interface active, can use i2c. If it fails, it can indeed mean, that
685 * this wasn't our capture interface, so, we wait for the right one
687 static int mt9t031_video_probe(struct i2c_client
*client
)
689 struct mt9t031
*mt9t031
= to_mt9t031(client
);
693 /* Enable the chip */
694 data
= reg_write(client
, MT9T031_CHIP_ENABLE
, 1);
695 dev_dbg(&client
->dev
, "write: %d\n", data
);
697 /* Read out the chip version register */
698 data
= reg_read(client
, MT9T031_CHIP_VERSION
);
702 mt9t031
->model
= V4L2_IDENT_MT9T031
;
705 dev_err(&client
->dev
,
706 "No MT9T031 chip detected, register read %x\n", data
);
710 dev_info(&client
->dev
, "Detected a MT9T031 chip ID %x\n", data
);
712 ret
= mt9t031_idle(client
);
714 dev_err(&client
->dev
, "Failed to initialise the camera\n");
716 /* mt9t031_idle() has reset the chip to default. */
717 mt9t031
->exposure
= 255;
723 static int mt9t031_g_skip_top_lines(struct v4l2_subdev
*sd
, u32
*lines
)
725 struct i2c_client
*client
= sd
->priv
;
726 struct mt9t031
*mt9t031
= to_mt9t031(client
);
728 *lines
= mt9t031
->y_skip_top
;
733 static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops
= {
734 .g_ctrl
= mt9t031_g_ctrl
,
735 .s_ctrl
= mt9t031_s_ctrl
,
736 .g_chip_ident
= mt9t031_g_chip_ident
,
737 #ifdef CONFIG_VIDEO_ADV_DEBUG
738 .g_register
= mt9t031_g_register
,
739 .s_register
= mt9t031_s_register
,
743 static int mt9t031_enum_fmt(struct v4l2_subdev
*sd
, int index
,
744 enum v4l2_mbus_pixelcode
*code
)
749 *code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
753 static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops
= {
754 .s_stream
= mt9t031_s_stream
,
755 .s_mbus_fmt
= mt9t031_s_fmt
,
756 .g_mbus_fmt
= mt9t031_g_fmt
,
757 .try_mbus_fmt
= mt9t031_try_fmt
,
758 .s_crop
= mt9t031_s_crop
,
759 .g_crop
= mt9t031_g_crop
,
760 .cropcap
= mt9t031_cropcap
,
761 .enum_mbus_fmt
= mt9t031_enum_fmt
,
764 static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops
= {
765 .g_skip_top_lines
= mt9t031_g_skip_top_lines
,
768 static struct v4l2_subdev_ops mt9t031_subdev_ops
= {
769 .core
= &mt9t031_subdev_core_ops
,
770 .video
= &mt9t031_subdev_video_ops
,
771 .sensor
= &mt9t031_subdev_sensor_ops
,
774 static int mt9t031_probe(struct i2c_client
*client
,
775 const struct i2c_device_id
*did
)
777 struct mt9t031
*mt9t031
;
778 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
779 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
783 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
785 dev_err(&client
->dev
, "MT9T031 driver needs platform data\n");
789 icd
->ops
= &mt9t031_ops
;
792 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
)) {
793 dev_warn(&adapter
->dev
,
794 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
798 mt9t031
= kzalloc(sizeof(struct mt9t031
), GFP_KERNEL
);
802 v4l2_i2c_subdev_init(&mt9t031
->subdev
, client
, &mt9t031_subdev_ops
);
804 mt9t031
->y_skip_top
= 0;
805 mt9t031
->rect
.left
= MT9T031_COLUMN_SKIP
;
806 mt9t031
->rect
.top
= MT9T031_ROW_SKIP
;
807 mt9t031
->rect
.width
= MT9T031_MAX_WIDTH
;
808 mt9t031
->rect
.height
= MT9T031_MAX_HEIGHT
;
811 * Simulated autoexposure. If enabled, we calculate shutter width
812 * ourselves in the driver based on vertical blanking and frame width
814 mt9t031
->autoexposure
= 1;
819 mt9t031_idle(client
);
821 ret
= mt9t031_video_probe(client
);
823 mt9t031_disable(client
);
828 i2c_set_clientdata(client
, NULL
);
835 static int mt9t031_remove(struct i2c_client
*client
)
837 struct mt9t031
*mt9t031
= to_mt9t031(client
);
838 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
842 i2c_set_clientdata(client
, NULL
);
843 client
->driver
= NULL
;
849 static const struct i2c_device_id mt9t031_id
[] = {
853 MODULE_DEVICE_TABLE(i2c
, mt9t031_id
);
855 static struct i2c_driver mt9t031_i2c_driver
= {
859 .probe
= mt9t031_probe
,
860 .remove
= mt9t031_remove
,
861 .id_table
= mt9t031_id
,
864 static int __init
mt9t031_mod_init(void)
866 return i2c_add_driver(&mt9t031_i2c_driver
);
869 static void __exit
mt9t031_mod_exit(void)
871 i2c_del_driver(&mt9t031_i2c_driver
);
874 module_init(mt9t031_mod_init
);
875 module_exit(mt9t031_mod_exit
);
877 MODULE_DESCRIPTION("Micron MT9T031 Camera driver");
878 MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>");
879 MODULE_LICENSE("GPL v2");