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>
20 /* mt9t031 i2c address 0x5d
21 * The platform has to define i2c_board_info and link to it from
22 * struct soc_camera_link */
24 /* mt9t031 selected register addresses */
25 #define MT9T031_CHIP_VERSION 0x00
26 #define MT9T031_ROW_START 0x01
27 #define MT9T031_COLUMN_START 0x02
28 #define MT9T031_WINDOW_HEIGHT 0x03
29 #define MT9T031_WINDOW_WIDTH 0x04
30 #define MT9T031_HORIZONTAL_BLANKING 0x05
31 #define MT9T031_VERTICAL_BLANKING 0x06
32 #define MT9T031_OUTPUT_CONTROL 0x07
33 #define MT9T031_SHUTTER_WIDTH_UPPER 0x08
34 #define MT9T031_SHUTTER_WIDTH 0x09
35 #define MT9T031_PIXEL_CLOCK_CONTROL 0x0a
36 #define MT9T031_FRAME_RESTART 0x0b
37 #define MT9T031_SHUTTER_DELAY 0x0c
38 #define MT9T031_RESET 0x0d
39 #define MT9T031_READ_MODE_1 0x1e
40 #define MT9T031_READ_MODE_2 0x20
41 #define MT9T031_READ_MODE_3 0x21
42 #define MT9T031_ROW_ADDRESS_MODE 0x22
43 #define MT9T031_COLUMN_ADDRESS_MODE 0x23
44 #define MT9T031_GLOBAL_GAIN 0x35
45 #define MT9T031_CHIP_ENABLE 0xF8
47 #define MT9T031_MAX_HEIGHT 1536
48 #define MT9T031_MAX_WIDTH 2048
49 #define MT9T031_MIN_HEIGHT 2
50 #define MT9T031_MIN_WIDTH 2
51 #define MT9T031_HORIZONTAL_BLANK 142
52 #define MT9T031_VERTICAL_BLANK 25
53 #define MT9T031_COLUMN_SKIP 32
54 #define MT9T031_ROW_SKIP 20
56 #define MT9T031_BUS_PARAM (SOCAM_PCLK_SAMPLE_RISING | \
57 SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH | \
58 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH | \
59 SOCAM_MASTER | SOCAM_DATAWIDTH_10)
61 static const struct soc_camera_data_format mt9t031_colour_formats
[] = {
63 .name
= "Bayer (sRGB) 10 bit",
65 .fourcc
= V4L2_PIX_FMT_SGRBG10
,
66 .colorspace
= V4L2_COLORSPACE_SRGB
,
71 struct v4l2_subdev subdev
;
72 int model
; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */
73 unsigned char autoexposure
;
78 static struct mt9t031
*to_mt9t031(const struct i2c_client
*client
)
80 return container_of(i2c_get_clientdata(client
), struct mt9t031
, subdev
);
83 static int reg_read(struct i2c_client
*client
, const u8 reg
)
85 s32 data
= i2c_smbus_read_word_data(client
, reg
);
86 return data
< 0 ? data
: swab16(data
);
89 static int reg_write(struct i2c_client
*client
, const u8 reg
,
92 return i2c_smbus_write_word_data(client
, reg
, swab16(data
));
95 static int reg_set(struct i2c_client
*client
, const u8 reg
,
100 ret
= reg_read(client
, reg
);
103 return reg_write(client
, reg
, ret
| data
);
106 static int reg_clear(struct i2c_client
*client
, const u8 reg
,
111 ret
= reg_read(client
, reg
);
114 return reg_write(client
, reg
, ret
& ~data
);
117 static int set_shutter(struct i2c_client
*client
, const u32 data
)
121 ret
= reg_write(client
, MT9T031_SHUTTER_WIDTH_UPPER
, data
>> 16);
124 ret
= reg_write(client
, MT9T031_SHUTTER_WIDTH
, data
& 0xffff);
129 static int get_shutter(struct i2c_client
*client
, u32
*data
)
133 ret
= reg_read(client
, MT9T031_SHUTTER_WIDTH_UPPER
);
137 ret
= reg_read(client
, MT9T031_SHUTTER_WIDTH
);
138 *data
|= ret
& 0xffff;
140 return ret
< 0 ? ret
: 0;
143 static int mt9t031_idle(struct i2c_client
*client
)
147 /* Disable chip output, synchronous option update */
148 ret
= reg_write(client
, MT9T031_RESET
, 1);
150 ret
= reg_write(client
, MT9T031_RESET
, 0);
152 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 2);
154 return ret
>= 0 ? 0 : -EIO
;
157 static int mt9t031_disable(struct i2c_client
*client
)
159 /* Disable the chip */
160 reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 2);
165 static int mt9t031_init(struct soc_camera_device
*icd
)
167 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
169 return mt9t031_idle(client
);
172 static int mt9t031_release(struct soc_camera_device
*icd
)
174 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
176 return mt9t031_disable(client
);
179 static int mt9t031_s_stream(struct v4l2_subdev
*sd
, int enable
)
181 struct i2c_client
*client
= sd
->priv
;
185 /* Switch to master "normal" mode */
186 ret
= reg_set(client
, MT9T031_OUTPUT_CONTROL
, 2);
188 /* Stop sensor readout */
189 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 2);
197 static int mt9t031_set_bus_param(struct soc_camera_device
*icd
,
200 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
202 /* The caller should have queried our parameters, check anyway */
203 if (flags
& ~MT9T031_BUS_PARAM
)
206 if (flags
& SOCAM_PCLK_SAMPLE_FALLING
)
207 reg_clear(client
, MT9T031_PIXEL_CLOCK_CONTROL
, 0x8000);
209 reg_set(client
, MT9T031_PIXEL_CLOCK_CONTROL
, 0x8000);
214 static unsigned long mt9t031_query_bus_param(struct soc_camera_device
*icd
)
216 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
218 return soc_camera_apply_sensor_flags(icl
, MT9T031_BUS_PARAM
);
221 /* Round up minima and round down maxima */
222 static void recalculate_limits(struct soc_camera_device
*icd
,
223 u16 xskip
, u16 yskip
)
225 icd
->x_min
= (MT9T031_COLUMN_SKIP
+ xskip
- 1) / xskip
;
226 icd
->y_min
= (MT9T031_ROW_SKIP
+ yskip
- 1) / yskip
;
227 icd
->width_min
= (MT9T031_MIN_WIDTH
+ xskip
- 1) / xskip
;
228 icd
->height_min
= (MT9T031_MIN_HEIGHT
+ yskip
- 1) / yskip
;
229 icd
->width_max
= MT9T031_MAX_WIDTH
/ xskip
;
230 icd
->height_max
= MT9T031_MAX_HEIGHT
/ yskip
;
233 static int mt9t031_set_params(struct soc_camera_device
*icd
,
234 struct v4l2_rect
*rect
, u16 xskip
, u16 yskip
)
236 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
237 struct mt9t031
*mt9t031
= to_mt9t031(client
);
239 u16 xbin
, ybin
, width
, height
, left
, top
;
240 const u16 hblank
= MT9T031_HORIZONTAL_BLANK
,
241 vblank
= MT9T031_VERTICAL_BLANK
;
243 /* Make sure we don't exceed sensor limits */
244 if (rect
->left
+ rect
->width
> icd
->width_max
)
245 rect
->left
= (icd
->width_max
- rect
->width
) / 2 + icd
->x_min
;
247 if (rect
->top
+ rect
->height
> icd
->height_max
)
248 rect
->top
= (icd
->height_max
- rect
->height
) / 2 + icd
->y_min
;
250 width
= rect
->width
* xskip
;
251 height
= rect
->height
* yskip
;
252 left
= rect
->left
* xskip
;
253 top
= rect
->top
* yskip
;
255 xbin
= min(xskip
, (u16
)3);
256 ybin
= min(yskip
, (u16
)3);
258 dev_dbg(&icd
->dev
, "xskip %u, width %u/%u, yskip %u, height %u/%u\n",
259 xskip
, width
, rect
->width
, yskip
, height
, rect
->height
);
261 /* Could just do roundup(rect->left, [xy]bin * 2); but this is cheaper */
264 left
= (left
+ 3) & ~3;
267 left
= roundup(left
, 6);
272 top
= (top
+ 3) & ~3;
275 top
= roundup(top
, 6);
278 /* Disable register update, reconfigure atomically */
279 ret
= reg_set(client
, MT9T031_OUTPUT_CONTROL
, 1);
283 /* Blanking and start values - default... */
284 ret
= reg_write(client
, MT9T031_HORIZONTAL_BLANKING
, hblank
);
286 ret
= reg_write(client
, MT9T031_VERTICAL_BLANKING
, vblank
);
288 if (yskip
!= mt9t031
->yskip
|| xskip
!= mt9t031
->xskip
) {
289 /* Binning, skipping */
291 ret
= reg_write(client
, MT9T031_COLUMN_ADDRESS_MODE
,
292 ((xbin
- 1) << 4) | (xskip
- 1));
294 ret
= reg_write(client
, MT9T031_ROW_ADDRESS_MODE
,
295 ((ybin
- 1) << 4) | (yskip
- 1));
297 dev_dbg(&icd
->dev
, "new physical left %u, top %u\n", left
, top
);
299 /* The caller provides a supported format, as guaranteed by
300 * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() */
302 ret
= reg_write(client
, MT9T031_COLUMN_START
, left
);
304 ret
= reg_write(client
, MT9T031_ROW_START
, top
);
306 ret
= reg_write(client
, MT9T031_WINDOW_WIDTH
, width
- 1);
308 ret
= reg_write(client
, MT9T031_WINDOW_HEIGHT
,
309 height
+ icd
->y_skip_top
- 1);
310 if (ret
>= 0 && mt9t031
->autoexposure
) {
311 ret
= set_shutter(client
, height
+ icd
->y_skip_top
+ vblank
);
313 const u32 shutter_max
= MT9T031_MAX_HEIGHT
+ vblank
;
314 const struct v4l2_queryctrl
*qctrl
=
315 soc_camera_find_qctrl(icd
->ops
,
317 icd
->exposure
= (shutter_max
/ 2 + (height
+
318 icd
->y_skip_top
+ vblank
- 1) *
319 (qctrl
->maximum
- qctrl
->minimum
)) /
320 shutter_max
+ qctrl
->minimum
;
324 /* Re-enable register update, commit all changes */
326 ret
= reg_clear(client
, MT9T031_OUTPUT_CONTROL
, 1);
328 return ret
< 0 ? ret
: 0;
331 static int mt9t031_set_crop(struct soc_camera_device
*icd
,
332 struct v4l2_rect
*rect
)
334 struct i2c_client
*client
= to_i2c_client(to_soc_camera_control(icd
));
335 struct mt9t031
*mt9t031
= to_mt9t031(client
);
337 /* CROP - no change in scaling, or in limits */
338 return mt9t031_set_params(icd
, rect
, mt9t031
->xskip
, mt9t031
->yskip
);
341 static int mt9t031_s_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
343 struct i2c_client
*client
= sd
->priv
;
344 struct mt9t031
*mt9t031
= to_mt9t031(client
);
345 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
348 struct v4l2_rect rect
= {
349 .left
= icd
->x_current
,
350 .top
= icd
->y_current
,
351 .width
= f
->fmt
.pix
.width
,
352 .height
= f
->fmt
.pix
.height
,
356 * try_fmt has put rectangle within limits.
357 * S_FMT - use binning and skipping for scaling, recalculate
358 * limits, used for cropping
360 /* Is this more optimal than just a division? */
361 for (xskip
= 8; xskip
> 1; xskip
--)
362 if (rect
.width
* xskip
<= MT9T031_MAX_WIDTH
)
365 for (yskip
= 8; yskip
> 1; yskip
--)
366 if (rect
.height
* yskip
<= MT9T031_MAX_HEIGHT
)
369 recalculate_limits(icd
, xskip
, yskip
);
371 ret
= mt9t031_set_params(icd
, &rect
, xskip
, yskip
);
373 mt9t031
->xskip
= xskip
;
374 mt9t031
->yskip
= yskip
;
380 static int mt9t031_try_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*f
)
382 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
384 v4l_bound_align_image(
385 &pix
->width
, MT9T031_MIN_WIDTH
, MT9T031_MAX_WIDTH
, 1,
386 &pix
->height
, MT9T031_MIN_HEIGHT
, MT9T031_MAX_HEIGHT
, 1, 0);
391 static int mt9t031_g_chip_ident(struct v4l2_subdev
*sd
,
392 struct v4l2_dbg_chip_ident
*id
)
394 struct i2c_client
*client
= sd
->priv
;
395 struct mt9t031
*mt9t031
= to_mt9t031(client
);
397 if (id
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
)
400 if (id
->match
.addr
!= client
->addr
)
403 id
->ident
= mt9t031
->model
;
409 #ifdef CONFIG_VIDEO_ADV_DEBUG
410 static int mt9t031_g_register(struct v4l2_subdev
*sd
,
411 struct v4l2_dbg_register
*reg
)
413 struct i2c_client
*client
= sd
->priv
;
415 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
418 if (reg
->match
.addr
!= client
->addr
)
421 reg
->val
= reg_read(client
, reg
->reg
);
423 if (reg
->val
> 0xffff)
429 static int mt9t031_s_register(struct v4l2_subdev
*sd
,
430 struct v4l2_dbg_register
*reg
)
432 struct i2c_client
*client
= sd
->priv
;
434 if (reg
->match
.type
!= V4L2_CHIP_MATCH_I2C_ADDR
|| reg
->reg
> 0xff)
437 if (reg
->match
.addr
!= client
->addr
)
440 if (reg_write(client
, reg
->reg
, reg
->val
) < 0)
447 static const struct v4l2_queryctrl mt9t031_controls
[] = {
449 .id
= V4L2_CID_VFLIP
,
450 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
451 .name
= "Flip Vertically",
457 .id
= V4L2_CID_HFLIP
,
458 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
459 .name
= "Flip Horizontally",
466 .type
= V4L2_CTRL_TYPE_INTEGER
,
472 .flags
= V4L2_CTRL_FLAG_SLIDER
,
474 .id
= V4L2_CID_EXPOSURE
,
475 .type
= V4L2_CTRL_TYPE_INTEGER
,
480 .default_value
= 255,
481 .flags
= V4L2_CTRL_FLAG_SLIDER
,
483 .id
= V4L2_CID_EXPOSURE_AUTO
,
484 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
485 .name
= "Automatic Exposure",
493 static struct soc_camera_ops mt9t031_ops
= {
494 .init
= mt9t031_init
,
495 .release
= mt9t031_release
,
496 .set_crop
= mt9t031_set_crop
,
497 .set_bus_param
= mt9t031_set_bus_param
,
498 .query_bus_param
= mt9t031_query_bus_param
,
499 .controls
= mt9t031_controls
,
500 .num_controls
= ARRAY_SIZE(mt9t031_controls
),
503 static int mt9t031_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
505 struct i2c_client
*client
= sd
->priv
;
506 struct mt9t031
*mt9t031
= to_mt9t031(client
);
511 data
= reg_read(client
, MT9T031_READ_MODE_2
);
514 ctrl
->value
= !!(data
& 0x8000);
517 data
= reg_read(client
, MT9T031_READ_MODE_2
);
520 ctrl
->value
= !!(data
& 0x4000);
522 case V4L2_CID_EXPOSURE_AUTO
:
523 ctrl
->value
= mt9t031
->autoexposure
;
529 static int mt9t031_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
531 struct i2c_client
*client
= sd
->priv
;
532 struct mt9t031
*mt9t031
= to_mt9t031(client
);
533 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
534 const struct v4l2_queryctrl
*qctrl
;
537 qctrl
= soc_camera_find_qctrl(&mt9t031_ops
, ctrl
->id
);
545 data
= reg_set(client
, MT9T031_READ_MODE_2
, 0x8000);
547 data
= reg_clear(client
, MT9T031_READ_MODE_2
, 0x8000);
553 data
= reg_set(client
, MT9T031_READ_MODE_2
, 0x4000);
555 data
= reg_clear(client
, MT9T031_READ_MODE_2
, 0x4000);
560 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
562 /* See Datasheet Table 7, Gain settings. */
563 if (ctrl
->value
<= qctrl
->default_value
) {
564 /* Pack it into 0..1 step 0.125, register values 0..8 */
565 unsigned long range
= qctrl
->default_value
- qctrl
->minimum
;
566 data
= ((ctrl
->value
- qctrl
->minimum
) * 8 + range
/ 2) / range
;
568 dev_dbg(&icd
->dev
, "Setting gain %d\n", data
);
569 data
= reg_write(client
, MT9T031_GLOBAL_GAIN
, data
);
573 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
574 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
575 unsigned long range
= qctrl
->maximum
- qctrl
->default_value
- 1;
576 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
577 unsigned long gain
= ((ctrl
->value
- qctrl
->default_value
- 1) *
578 1015 + range
/ 2) / range
+ 9;
580 if (gain
<= 32) /* calculated gain 9..32 -> 9..32 */
582 else if (gain
<= 64) /* calculated gain 33..64 -> 0x51..0x60 */
583 data
= ((gain
- 32) * 16 + 16) / 32 + 80;
585 /* calculated gain 65..1024 -> (1..120) << 8 + 0x60 */
586 data
= (((gain
- 64 + 7) * 32) & 0xff00) | 0x60;
588 dev_dbg(&icd
->dev
, "Setting gain from 0x%x to 0x%x\n",
589 reg_read(client
, MT9T031_GLOBAL_GAIN
), data
);
590 data
= reg_write(client
, MT9T031_GLOBAL_GAIN
, data
);
596 icd
->gain
= ctrl
->value
;
598 case V4L2_CID_EXPOSURE
:
599 /* mt9t031 has maximum == default */
600 if (ctrl
->value
> qctrl
->maximum
|| ctrl
->value
< qctrl
->minimum
)
603 const unsigned long range
= qctrl
->maximum
- qctrl
->minimum
;
604 const u32 shutter
= ((ctrl
->value
- qctrl
->minimum
) * 1048 +
605 range
/ 2) / range
+ 1;
608 get_shutter(client
, &old
);
609 dev_dbg(&icd
->dev
, "Setting shutter width from %u to %u\n",
611 if (set_shutter(client
, shutter
) < 0)
613 icd
->exposure
= ctrl
->value
;
614 mt9t031
->autoexposure
= 0;
617 case V4L2_CID_EXPOSURE_AUTO
:
619 const u16 vblank
= MT9T031_VERTICAL_BLANK
;
620 const u32 shutter_max
= MT9T031_MAX_HEIGHT
+ vblank
;
621 if (set_shutter(client
, icd
->height
+
622 icd
->y_skip_top
+ vblank
) < 0)
624 qctrl
= soc_camera_find_qctrl(icd
->ops
, V4L2_CID_EXPOSURE
);
625 icd
->exposure
= (shutter_max
/ 2 + (icd
->height
+
626 icd
->y_skip_top
+ vblank
- 1) *
627 (qctrl
->maximum
- qctrl
->minimum
)) /
628 shutter_max
+ qctrl
->minimum
;
629 mt9t031
->autoexposure
= 1;
631 mt9t031
->autoexposure
= 0;
637 /* Interface active, can use i2c. If it fails, it can indeed mean, that
638 * this wasn't our capture interface, so, we wait for the right one */
639 static int mt9t031_video_probe(struct i2c_client
*client
)
641 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
642 struct mt9t031
*mt9t031
= to_mt9t031(client
);
645 /* We must have a parent by now. And it cannot be a wrong one.
646 * So this entire test is completely redundant. */
647 if (!icd
->dev
.parent
||
648 to_soc_camera_host(icd
->dev
.parent
)->nr
!= icd
->iface
)
651 /* Enable the chip */
652 data
= reg_write(client
, MT9T031_CHIP_ENABLE
, 1);
653 dev_dbg(&icd
->dev
, "write: %d\n", data
);
655 /* Read out the chip version register */
656 data
= reg_read(client
, MT9T031_CHIP_VERSION
);
660 mt9t031
->model
= V4L2_IDENT_MT9T031
;
661 icd
->formats
= mt9t031_colour_formats
;
662 icd
->num_formats
= ARRAY_SIZE(mt9t031_colour_formats
);
666 "No MT9T031 chip detected, register read %x\n", data
);
670 dev_info(&icd
->dev
, "Detected a MT9T031 chip ID %x\n", data
);
675 static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops
= {
676 .g_ctrl
= mt9t031_g_ctrl
,
677 .s_ctrl
= mt9t031_s_ctrl
,
678 .g_chip_ident
= mt9t031_g_chip_ident
,
679 #ifdef CONFIG_VIDEO_ADV_DEBUG
680 .g_register
= mt9t031_g_register
,
681 .s_register
= mt9t031_s_register
,
685 static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops
= {
686 .s_stream
= mt9t031_s_stream
,
687 .s_fmt
= mt9t031_s_fmt
,
688 .try_fmt
= mt9t031_try_fmt
,
691 static struct v4l2_subdev_ops mt9t031_subdev_ops
= {
692 .core
= &mt9t031_subdev_core_ops
,
693 .video
= &mt9t031_subdev_video_ops
,
696 static int mt9t031_probe(struct i2c_client
*client
,
697 const struct i2c_device_id
*did
)
699 struct mt9t031
*mt9t031
;
700 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
701 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
702 struct soc_camera_link
*icl
;
706 dev_err(&client
->dev
, "MT9T031: missing soc-camera data!\n");
710 icl
= to_soc_camera_link(icd
);
712 dev_err(&client
->dev
, "MT9T031 driver needs platform data\n");
716 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_WORD_DATA
)) {
717 dev_warn(&adapter
->dev
,
718 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
722 mt9t031
= kzalloc(sizeof(struct mt9t031
), GFP_KERNEL
);
726 v4l2_i2c_subdev_init(&mt9t031
->subdev
, client
, &mt9t031_subdev_ops
);
728 /* Second stage probe - when a capture adapter is there */
729 icd
->ops
= &mt9t031_ops
;
730 icd
->x_min
= MT9T031_COLUMN_SKIP
;
731 icd
->y_min
= MT9T031_ROW_SKIP
;
732 icd
->x_current
= icd
->x_min
;
733 icd
->y_current
= icd
->y_min
;
734 icd
->width_min
= MT9T031_MIN_WIDTH
;
735 icd
->width_max
= MT9T031_MAX_WIDTH
;
736 icd
->height_min
= MT9T031_MIN_HEIGHT
;
737 icd
->height_max
= MT9T031_MAX_HEIGHT
;
739 /* Simulated autoexposure. If enabled, we calculate shutter width
740 * ourselves in the driver based on vertical blanking and frame width */
741 mt9t031
->autoexposure
= 1;
746 mt9t031_idle(client
);
748 ret
= mt9t031_video_probe(client
);
750 mt9t031_disable(client
);
754 i2c_set_clientdata(client
, NULL
);
761 static int mt9t031_remove(struct i2c_client
*client
)
763 struct mt9t031
*mt9t031
= to_mt9t031(client
);
764 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
767 i2c_set_clientdata(client
, NULL
);
768 client
->driver
= NULL
;
774 static const struct i2c_device_id mt9t031_id
[] = {
778 MODULE_DEVICE_TABLE(i2c
, mt9t031_id
);
780 static struct i2c_driver mt9t031_i2c_driver
= {
784 .probe
= mt9t031_probe
,
785 .remove
= mt9t031_remove
,
786 .id_table
= mt9t031_id
,
789 static int __init
mt9t031_mod_init(void)
791 return i2c_add_driver(&mt9t031_i2c_driver
);
794 static void __exit
mt9t031_mod_exit(void)
796 i2c_del_driver(&mt9t031_i2c_driver
);
799 module_init(mt9t031_mod_init
);
800 module_exit(mt9t031_mod_exit
);
802 MODULE_DESCRIPTION("Micron MT9T031 Camera driver");
803 MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>");
804 MODULE_LICENSE("GPL v2");