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
);
204 /* target must be _even_ */
205 static u16
mt9t031_skip(s32
*source
, s32 target
, s32 max
)
209 if (*source
< target
+ target
/ 2) {
214 skip
= min(max
, *source
+ target
/ 2) / target
;
217 *source
= target
* skip
;
222 /* rect is the sensor rectangle, the caller guarantees parameter validity */
223 static int mt9t031_set_params(struct soc_camera_device
*icd
,
224 struct v4l2_rect
*rect
, u16 xskip
, u16 yskip
)
226 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
227 struct mt9t031
*mt9t031
= to_mt9t031(client
);
230 const u16 hblank
= MT9T031_HORIZONTAL_BLANK
,
231 vblank
= MT9T031_VERTICAL_BLANK
;
233 xbin
= min(xskip
, (u16
)3);
234 ybin
= min(yskip
, (u16
)3);
237 * Could just do roundup(rect->left, [xy]bin * 2); but this is cheaper.
238 * There is always a valid suitably aligned value. The worst case is
239 * xbin = 3, width = 2048. Then we will start at 36, the last read out
240 * pixel will be 2083, which is < 2085 - first black pixel.
242 * MT9T031 datasheet imposes window left border alignment, depending on
243 * the selected xskip. Failing to conform to this requirement produces
244 * dark horizontal stripes in the image. However, even obeying to this
245 * requirement doesn't eliminate the stripes in all configurations. They
246 * appear "locally reproducibly," but can differ between tests under
247 * different lighting conditions.
257 rect
->left
= rect
->left
> roundup(MT9T031_COLUMN_SKIP
, 6) ?
258 (rect
->left
/ 6) * 6 : roundup(MT9T031_COLUMN_SKIP
, 6);
263 dev_dbg(&client
->dev
, "skip %u:%u, rect %ux%u@%u:%u\n",
264 xskip
, yskip
, rect
->width
, rect
->height
, rect
->left
, rect
->top
);
266 /* Disable register update, reconfigure atomically */
267 ret
= reg_set(client
, MT9T031_OUTPUT_CONTROL
, 1);
271 /* Blanking and start values - default... */
272 ret
= reg_write(client
, MT9T031_HORIZONTAL_BLANKING
, hblank
);
274 ret
= reg_write(client
, MT9T031_VERTICAL_BLANKING
, vblank
);
276 if (yskip
!= mt9t031
->yskip
|| xskip
!= mt9t031
->xskip
) {
277 /* Binning, skipping */
279 ret
= reg_write(client
, MT9T031_COLUMN_ADDRESS_MODE
,
280 ((xbin
- 1) << 4) | (xskip
- 1));
282 ret
= reg_write(client
, MT9T031_ROW_ADDRESS_MODE
,
283 ((ybin
- 1) << 4) | (yskip
- 1));
285 dev_dbg(&client
->dev
, "new physical left %u, top %u\n",
286 rect
->left
, rect
->top
);
289 * The caller provides a supported format, as guaranteed by
290 * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap()
293 ret
= reg_write(client
, MT9T031_COLUMN_START
, rect
->left
);
295 ret
= reg_write(client
, MT9T031_ROW_START
, rect
->top
);
297 ret
= reg_write(client
, MT9T031_WINDOW_WIDTH
, rect
->width
- 1);
299 ret
= reg_write(client
, MT9T031_WINDOW_HEIGHT
,
300 rect
->height
+ mt9t031
->y_skip_top
- 1);
301 if (ret
>= 0 && mt9t031
->autoexposure
) {
302 unsigned int total_h
= rect
->height
+ mt9t031
->y_skip_top
+ vblank
;
303 ret
= set_shutter(client
, total_h
);
305 const u32 shutter_max
= MT9T031_MAX_HEIGHT
+ vblank
;
306 const struct v4l2_queryctrl
*qctrl
=
307 soc_camera_find_qctrl(icd
->ops
,
309 mt9t031
->exposure
= (shutter_max
/ 2 + (total_h
- 1) *
310 (qctrl
->maximum
- qctrl
->minimum
)) /
311 shutter_max
+ qctrl
->minimum
;
315 /* Re-enable register update, commit all changes */
317 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 1);
320 mt9t031
->rect
= *rect
;
321 mt9t031
->xskip
= xskip
;
322 mt9t031
->yskip
= yskip
;
325 return ret
< 0 ? ret
: 0;
328 static int mt9t031_s_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
330 struct v4l2_rect rect
= a
->c
;
331 struct i2c_client
*client
= sd
->priv
;
332 struct mt9t031
*mt9t031
= to_mt9t031(client
);
333 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
335 rect
.width
= ALIGN(rect
.width
, 2);
336 rect
.height
= ALIGN(rect
.height
, 2);
338 soc_camera_limit_side(&rect
.left
, &rect
.width
,
339 MT9T031_COLUMN_SKIP
, MT9T031_MIN_WIDTH
, MT9T031_MAX_WIDTH
);
341 soc_camera_limit_side(&rect
.top
, &rect
.height
,
342 MT9T031_ROW_SKIP
, MT9T031_MIN_HEIGHT
, MT9T031_MAX_HEIGHT
);
344 return mt9t031_set_params(icd
, &rect
, mt9t031
->xskip
, mt9t031
->yskip
);
347 static int mt9t031_g_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
349 struct i2c_client
*client
= sd
->priv
;
350 struct mt9t031
*mt9t031
= to_mt9t031(client
);
352 a
->c
= mt9t031
->rect
;
353 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
358 static int mt9t031_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*a
)
360 a
->bounds
.left
= MT9T031_COLUMN_SKIP
;
361 a
->bounds
.top
= MT9T031_ROW_SKIP
;
362 a
->bounds
.width
= MT9T031_MAX_WIDTH
;
363 a
->bounds
.height
= MT9T031_MAX_HEIGHT
;
364 a
->defrect
= a
->bounds
;
365 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
366 a
->pixelaspect
.numerator
= 1;
367 a
->pixelaspect
.denominator
= 1;
372 static int mt9t031_g_fmt(struct v4l2_subdev
*sd
,
373 struct v4l2_mbus_framefmt
*mf
)
375 struct i2c_client
*client
= sd
->priv
;
376 struct mt9t031
*mt9t031
= to_mt9t031(client
);
378 mf
->width
= mt9t031
->rect
.width
/ mt9t031
->xskip
;
379 mf
->height
= mt9t031
->rect
.height
/ mt9t031
->yskip
;
380 mf
->code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
381 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
382 mf
->field
= V4L2_FIELD_NONE
;
387 static int mt9t031_s_fmt(struct v4l2_subdev
*sd
,
388 struct v4l2_mbus_framefmt
*mf
)
390 struct i2c_client
*client
= sd
->priv
;
391 struct mt9t031
*mt9t031
= to_mt9t031(client
);
392 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
394 struct v4l2_rect rect
= mt9t031
->rect
;
397 * try_fmt has put width and height within limits.
398 * S_FMT: use binning and skipping for scaling
400 xskip
= mt9t031_skip(&rect
.width
, mf
->width
, MT9T031_MAX_WIDTH
);
401 yskip
= mt9t031_skip(&rect
.height
, mf
->height
, MT9T031_MAX_HEIGHT
);
403 mf
->code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
404 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
406 /* mt9t031_set_params() doesn't change width and height */
407 return mt9t031_set_params(icd
, &rect
, xskip
, yskip
);
411 * If a user window larger than sensor window is requested, we'll increase the
414 static int mt9t031_try_fmt(struct v4l2_subdev
*sd
,
415 struct v4l2_mbus_framefmt
*mf
)
417 v4l_bound_align_image(
418 &mf
->width
, MT9T031_MIN_WIDTH
, MT9T031_MAX_WIDTH
, 1,
419 &mf
->height
, MT9T031_MIN_HEIGHT
, MT9T031_MAX_HEIGHT
, 1, 0);
421 mf
->code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
422 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
427 static int mt9t031_g_chip_ident(struct v4l2_subdev
*sd
,
428 struct v4l2_dbg_chip_ident
*id
)
430 struct i2c_client
*client
= sd
->priv
;
431 struct mt9t031
*mt9t031
= to_mt9t031(client
);
433 if (id
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
)
436 if (id
->match
.addr
!= client
->addr
)
439 id
->ident
= mt9t031
->model
;
445 #ifdef CONFIG_VIDEO_ADV_DEBUG
446 static int mt9t031_g_register(struct v4l2_subdev
*sd
,
447 struct v4l2_dbg_register
*reg
)
449 struct i2c_client
*client
= sd
->priv
;
451 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
454 if (reg
->match
.addr
!= client
->addr
)
457 reg
->val
= reg_read(client
, reg
->reg
);
459 if (reg
->val
> 0xffff)
465 static int mt9t031_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 mt9t031_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
,
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_EXPOSURE_AUTO
,
520 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
521 .name
= "Automatic Exposure",
529 static struct soc_camera_ops mt9t031_ops
= {
530 .set_bus_param
= mt9t031_set_bus_param
,
531 .query_bus_param
= mt9t031_query_bus_param
,
532 .controls
= mt9t031_controls
,
533 .num_controls
= ARRAY_SIZE(mt9t031_controls
),
536 static int mt9t031_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
538 struct i2c_client
*client
= sd
->priv
;
539 struct mt9t031
*mt9t031
= to_mt9t031(client
);
544 data
= reg_read(client
, MT9T031_READ_MODE_2
);
547 ctrl
->value
= !!(data
& 0x8000);
550 data
= reg_read(client
, MT9T031_READ_MODE_2
);
553 ctrl
->value
= !!(data
& 0x4000);
555 case V4L2_CID_EXPOSURE_AUTO
:
556 ctrl
->value
= mt9t031
->autoexposure
;
559 ctrl
->value
= mt9t031
->gain
;
561 case V4L2_CID_EXPOSURE
:
562 ctrl
->value
= mt9t031
->exposure
;
568 static int mt9t031_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
570 struct i2c_client
*client
= sd
->priv
;
571 struct mt9t031
*mt9t031
= to_mt9t031(client
);
572 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
573 const struct v4l2_queryctrl
*qctrl
;
576 qctrl
= soc_camera_find_qctrl(&mt9t031_ops
, ctrl
->id
);
584 data
= reg_set(client
, MT9T031_READ_MODE_2
, 0x8000);
586 data
= reg_clear(client
, MT9T031_READ_MODE_2
, 0x8000);
592 data
= reg_set(client
, MT9T031_READ_MODE_2
, 0x4000);
594 data
= reg_clear(client
, MT9T031_READ_MODE_2
, 0x4000);
599 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
601 /* See Datasheet Table 7, Gain settings. */
602 if (ctrl
->value
<= qctrl
->default_value
) {
603 /* Pack it into 0..1 step 0.125, register values 0..8 */
604 unsigned long range
= qctrl
->default_value
- qctrl
->minimum
;
605 data
= ((ctrl
->value
- qctrl
->minimum
) * 8 + range
/ 2) / range
;
607 dev_dbg(&client
->dev
, "Setting gain %d\n", data
);
608 data
= reg_write(client
, MT9T031_GLOBAL_GAIN
, data
);
612 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
613 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
614 unsigned long range
= qctrl
->maximum
- qctrl
->default_value
- 1;
615 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
616 unsigned long gain
= ((ctrl
->value
- qctrl
->default_value
- 1) *
617 1015 + range
/ 2) / range
+ 9;
619 if (gain
<= 32) /* calculated gain 9..32 -> 9..32 */
621 else if (gain
<= 64) /* calculated gain 33..64 -> 0x51..0x60 */
622 data
= ((gain
- 32) * 16 + 16) / 32 + 80;
624 /* calculated gain 65..1024 -> (1..120) << 8 + 0x60 */
625 data
= (((gain
- 64 + 7) * 32) & 0xff00) | 0x60;
627 dev_dbg(&client
->dev
, "Set gain from 0x%x to 0x%x\n",
628 reg_read(client
, MT9T031_GLOBAL_GAIN
), data
);
629 data
= reg_write(client
, MT9T031_GLOBAL_GAIN
, data
);
635 mt9t031
->gain
= ctrl
->value
;
637 case V4L2_CID_EXPOSURE
:
638 /* mt9t031 has maximum == default */
639 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
642 const unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
643 const u32 shutter
= ((ctrl
->value
- qctrl
->minimum
) * 1048 +
644 range
/ 2) / range
+ 1;
647 get_shutter(client
, &old
);
648 dev_dbg(&client
->dev
, "Set shutter from %u to %u\n",
650 if (set_shutter(client
, shutter
) < 0)
652 mt9t031
->exposure
= ctrl
->value
;
653 mt9t031
->autoexposure
= 0;
656 case V4L2_CID_EXPOSURE_AUTO
:
658 const u16 vblank
= MT9T031_VERTICAL_BLANK
;
659 const u32 shutter_max
= MT9T031_MAX_HEIGHT
+ vblank
;
660 unsigned int total_h
= mt9t031
->rect
.height
+
661 mt9t031
->y_skip_top
+ vblank
;
663 if (set_shutter(client
, total_h
) < 0)
665 qctrl
= soc_camera_find_qctrl(icd
->ops
, V4L2_CID_EXPOSURE
);
666 mt9t031
->exposure
= (shutter_max
/ 2 + (total_h
- 1) *
667 (qctrl
->maximum
- qctrl
->minimum
)) /
668 shutter_max
+ qctrl
->minimum
;
669 mt9t031
->autoexposure
= 1;
671 mt9t031
->autoexposure
= 0;
678 * Interface active, can use i2c. If it fails, it can indeed mean, that
679 * this wasn't our capture interface, so, we wait for the right one
681 static int mt9t031_video_probe(struct i2c_client
*client
)
683 struct mt9t031
*mt9t031
= to_mt9t031(client
);
687 /* Enable the chip */
688 data
= reg_write(client
, MT9T031_CHIP_ENABLE
, 1);
689 dev_dbg(&client
->dev
, "write: %d\n", data
);
691 /* Read out the chip version register */
692 data
= reg_read(client
, MT9T031_CHIP_VERSION
);
696 mt9t031
->model
= V4L2_IDENT_MT9T031
;
699 dev_err(&client
->dev
,
700 "No MT9T031 chip detected, register read %x\n", data
);
704 dev_info(&client
->dev
, "Detected a MT9T031 chip ID %x\n", data
);
706 ret
= mt9t031_idle(client
);
708 dev_err(&client
->dev
, "Failed to initialise the camera\n");
710 /* mt9t031_idle() has reset the chip to default. */
711 mt9t031
->exposure
= 255;
717 static int mt9t031_g_skip_top_lines(struct v4l2_subdev
*sd
, u32
*lines
)
719 struct i2c_client
*client
= sd
->priv
;
720 struct mt9t031
*mt9t031
= to_mt9t031(client
);
722 *lines
= mt9t031
->y_skip_top
;
727 static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops
= {
728 .g_ctrl
= mt9t031_g_ctrl
,
729 .s_ctrl
= mt9t031_s_ctrl
,
730 .g_chip_ident
= mt9t031_g_chip_ident
,
731 #ifdef CONFIG_VIDEO_ADV_DEBUG
732 .g_register
= mt9t031_g_register
,
733 .s_register
= mt9t031_s_register
,
737 static int mt9t031_enum_fmt(struct v4l2_subdev
*sd
, int index
,
738 enum v4l2_mbus_pixelcode
*code
)
743 *code
= V4L2_MBUS_FMT_SBGGR10_1X10
;
747 static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops
= {
748 .s_stream
= mt9t031_s_stream
,
749 .s_mbus_fmt
= mt9t031_s_fmt
,
750 .g_mbus_fmt
= mt9t031_g_fmt
,
751 .try_mbus_fmt
= mt9t031_try_fmt
,
752 .s_crop
= mt9t031_s_crop
,
753 .g_crop
= mt9t031_g_crop
,
754 .cropcap
= mt9t031_cropcap
,
755 .enum_mbus_fmt
= mt9t031_enum_fmt
,
758 static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops
= {
759 .g_skip_top_lines
= mt9t031_g_skip_top_lines
,
762 static struct v4l2_subdev_ops mt9t031_subdev_ops
= {
763 .core
= &mt9t031_subdev_core_ops
,
764 .video
= &mt9t031_subdev_video_ops
,
765 .sensor
= &mt9t031_subdev_sensor_ops
,
768 static int mt9t031_probe(struct i2c_client
*client
,
769 const struct i2c_device_id
*did
)
771 struct mt9t031
*mt9t031
;
772 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
773 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
774 struct soc_camera_link
*icl
;
778 dev_err(&client
->dev
, "MT9T031: missing soc-camera data!\n");
782 icl
= to_soc_camera_link(icd
);
784 dev_err(&client
->dev
, "MT9T031 driver needs platform data\n");
788 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
)) {
789 dev_warn(&adapter
->dev
,
790 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
794 mt9t031
= kzalloc(sizeof(struct mt9t031
), GFP_KERNEL
);
798 v4l2_i2c_subdev_init(&mt9t031
->subdev
, client
, &mt9t031_subdev_ops
);
800 /* Second stage probe - when a capture adapter is there */
801 icd
->ops
= &mt9t031_ops
;
803 mt9t031
->y_skip_top
= 0;
804 mt9t031
->rect
.left
= MT9T031_COLUMN_SKIP
;
805 mt9t031
->rect
.top
= MT9T031_ROW_SKIP
;
806 mt9t031
->rect
.width
= MT9T031_MAX_WIDTH
;
807 mt9t031
->rect
.height
= MT9T031_MAX_HEIGHT
;
810 * Simulated autoexposure. If enabled, we calculate shutter width
811 * ourselves in the driver based on vertical blanking and frame width
813 mt9t031
->autoexposure
= 1;
818 mt9t031_idle(client
);
820 ret
= mt9t031_video_probe(client
);
822 mt9t031_disable(client
);
826 i2c_set_clientdata(client
, NULL
);
833 static int mt9t031_remove(struct i2c_client
*client
)
835 struct mt9t031
*mt9t031
= to_mt9t031(client
);
836 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
839 i2c_set_clientdata(client
, NULL
);
840 client
->driver
= NULL
;
846 static const struct i2c_device_id mt9t031_id
[] = {
850 MODULE_DEVICE_TABLE(i2c
, mt9t031_id
);
852 static struct i2c_driver mt9t031_i2c_driver
= {
856 .probe
= mt9t031_probe
,
857 .remove
= mt9t031_remove
,
858 .id_table
= mt9t031_id
,
861 static int __init
mt9t031_mod_init(void)
863 return i2c_add_driver(&mt9t031_i2c_driver
);
866 static void __exit
mt9t031_mod_exit(void)
868 i2c_del_driver(&mt9t031_i2c_driver
);
871 module_init(mt9t031_mod_init
);
872 module_exit(mt9t031_mod_exit
);
874 MODULE_DESCRIPTION("Micron MT9T031 Camera driver");
875 MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>");
876 MODULE_LICENSE("GPL v2");