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/device.h>
12 #include <linux/i2c.h>
13 #include <linux/log2.h>
15 #include <linux/slab.h>
16 #include <linux/v4l2-mediabus.h>
17 #include <linux/videodev2.h>
18 #include <linux/module.h>
20 #include <media/soc_camera.h>
21 #include <media/v4l2-subdev.h>
22 #include <media/v4l2-ctrls.h>
25 * ATTENTION: this driver still cannot be used outside of the soc-camera
26 * framework because of its PM implementation, using the video_device node.
27 * If hardware becomes available for testing, alternative PM approaches shall
28 * be considered and tested.
32 * mt9t031 i2c address 0x5d
33 * The platform has to define struct i2c_board_info objects and link to them
34 * from struct soc_camera_host_desc
37 /* mt9t031 selected register addresses */
38 #define MT9T031_CHIP_VERSION 0x00
39 #define MT9T031_ROW_START 0x01
40 #define MT9T031_COLUMN_START 0x02
41 #define MT9T031_WINDOW_HEIGHT 0x03
42 #define MT9T031_WINDOW_WIDTH 0x04
43 #define MT9T031_HORIZONTAL_BLANKING 0x05
44 #define MT9T031_VERTICAL_BLANKING 0x06
45 #define MT9T031_OUTPUT_CONTROL 0x07
46 #define MT9T031_SHUTTER_WIDTH_UPPER 0x08
47 #define MT9T031_SHUTTER_WIDTH 0x09
48 #define MT9T031_PIXEL_CLOCK_CONTROL 0x0a
49 #define MT9T031_FRAME_RESTART 0x0b
50 #define MT9T031_SHUTTER_DELAY 0x0c
51 #define MT9T031_RESET 0x0d
52 #define MT9T031_READ_MODE_1 0x1e
53 #define MT9T031_READ_MODE_2 0x20
54 #define MT9T031_READ_MODE_3 0x21
55 #define MT9T031_ROW_ADDRESS_MODE 0x22
56 #define MT9T031_COLUMN_ADDRESS_MODE 0x23
57 #define MT9T031_GLOBAL_GAIN 0x35
58 #define MT9T031_CHIP_ENABLE 0xF8
60 #define MT9T031_MAX_HEIGHT 1536
61 #define MT9T031_MAX_WIDTH 2048
62 #define MT9T031_MIN_HEIGHT 2
63 #define MT9T031_MIN_WIDTH 18
64 #define MT9T031_HORIZONTAL_BLANK 142
65 #define MT9T031_VERTICAL_BLANK 25
66 #define MT9T031_COLUMN_SKIP 32
67 #define MT9T031_ROW_SKIP 20
70 struct v4l2_subdev subdev;
71 struct v4l2_ctrl_handler hdl;
73 /* exposure/auto-exposure cluster */
74 struct v4l2_ctrl *autoexposure;
75 struct v4l2_ctrl *exposure;
77 struct v4l2_rect rect; /* Sensor window */
81 unsigned short y_skip_top; /* Lines to skip at the top */
84 static struct mt9t031 *to_mt9t031(const struct i2c_client *client)
86 return container_of(i2c_get_clientdata(client), struct mt9t031, subdev);
89 static int reg_read(struct i2c_client *client, const u8 reg)
91 return i2c_smbus_read_word_swapped(client, reg);
94 static int reg_write(struct i2c_client *client, const u8 reg,
97 return i2c_smbus_write_word_swapped(client, reg, data);
100 static int reg_set(struct i2c_client *client, const u8 reg,
105 ret = reg_read(client, reg);
108 return reg_write(client, reg, ret | data);
111 static int reg_clear(struct i2c_client *client, const u8 reg,
116 ret = reg_read(client, reg);
119 return reg_write(client, reg, ret & ~data);
122 static int set_shutter(struct i2c_client *client, const u32 data)
126 ret = reg_write(client, MT9T031_SHUTTER_WIDTH_UPPER, data >> 16);
129 ret = reg_write(client, MT9T031_SHUTTER_WIDTH, data & 0xffff);
134 static int get_shutter(struct i2c_client *client, u32 *data)
138 ret = reg_read(client, MT9T031_SHUTTER_WIDTH_UPPER);
142 ret = reg_read(client, MT9T031_SHUTTER_WIDTH);
143 *data |= ret & 0xffff;
145 return ret < 0 ? ret : 0;
148 static int mt9t031_idle(struct i2c_client *client)
152 /* Disable chip output, synchronous option update */
153 ret = reg_write(client, MT9T031_RESET, 1);
155 ret = reg_write(client, MT9T031_RESET, 0);
157 ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2);
159 return ret >= 0 ? 0 : -EIO;
162 static int mt9t031_s_stream(struct v4l2_subdev *sd, int enable)
164 struct i2c_client *client = v4l2_get_subdevdata(sd);
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 /* target must be _even_ */
181 static u16 mt9t031_skip(s32 *source, s32 target, s32 max)
185 if (*source < target + target / 2) {
190 skip = min(max, *source + target / 2) / target;
193 *source = target * skip;
198 /* rect is the sensor rectangle, the caller guarantees parameter validity */
199 static int mt9t031_set_params(struct i2c_client *client,
200 struct v4l2_rect *rect, u16 xskip, u16 yskip)
202 struct mt9t031 *mt9t031 = to_mt9t031(client);
205 const u16 hblank = MT9T031_HORIZONTAL_BLANK,
206 vblank = MT9T031_VERTICAL_BLANK;
208 xbin = min(xskip, (u16)3);
209 ybin = min(yskip, (u16)3);
212 * Could just do roundup(rect->left, [xy]bin * 2); but this is cheaper.
213 * There is always a valid suitably aligned value. The worst case is
214 * xbin = 3, width = 2048. Then we will start at 36, the last read out
215 * pixel will be 2083, which is < 2085 - first black pixel.
217 * MT9T031 datasheet imposes window left border alignment, depending on
218 * the selected xskip. Failing to conform to this requirement produces
219 * dark horizontal stripes in the image. However, even obeying to this
220 * requirement doesn't eliminate the stripes in all configurations. They
221 * appear "locally reproducibly," but can differ between tests under
222 * different lighting conditions.
232 rect->left = rect->left > roundup(MT9T031_COLUMN_SKIP, 6) ?
233 (rect->left / 6) * 6 : roundup(MT9T031_COLUMN_SKIP, 6);
238 dev_dbg(&client->dev, "skip %u:%u, rect %ux%u@%u:%u\n",
239 xskip, yskip, rect->width, rect->height, rect->left, rect->top);
241 /* Disable register update, reconfigure atomically */
242 ret = reg_set(client, MT9T031_OUTPUT_CONTROL, 1);
246 /* Blanking and start values - default... */
247 ret = reg_write(client, MT9T031_HORIZONTAL_BLANKING, hblank);
249 ret = reg_write(client, MT9T031_VERTICAL_BLANKING, vblank);
251 if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) {
252 /* Binning, skipping */
254 ret = reg_write(client, MT9T031_COLUMN_ADDRESS_MODE,
255 ((xbin - 1) << 4) | (xskip - 1));
257 ret = reg_write(client, MT9T031_ROW_ADDRESS_MODE,
258 ((ybin - 1) << 4) | (yskip - 1));
260 dev_dbg(&client->dev, "new physical left %u, top %u\n",
261 rect->left, rect->top);
264 * The caller provides a supported format, as guaranteed by
265 * .try_mbus_fmt(), soc_camera_s_crop() and soc_camera_cropcap()
268 ret = reg_write(client, MT9T031_COLUMN_START, rect->left);
270 ret = reg_write(client, MT9T031_ROW_START, rect->top);
272 ret = reg_write(client, MT9T031_WINDOW_WIDTH, rect->width - 1);
274 ret = reg_write(client, MT9T031_WINDOW_HEIGHT,
275 rect->height + mt9t031->y_skip_top - 1);
276 if (ret >= 0 && v4l2_ctrl_g_ctrl(mt9t031->autoexposure) == V4L2_EXPOSURE_AUTO) {
277 mt9t031->total_h = rect->height + mt9t031->y_skip_top + vblank;
279 ret = set_shutter(client, mt9t031->total_h);
282 /* Re-enable register update, commit all changes */
284 ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 1);
287 mt9t031->rect = *rect;
288 mt9t031->xskip = xskip;
289 mt9t031->yskip = yskip;
292 return ret < 0 ? ret : 0;
295 static int mt9t031_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
297 struct v4l2_rect rect = a->c;
298 struct i2c_client *client = v4l2_get_subdevdata(sd);
299 struct mt9t031 *mt9t031 = to_mt9t031(client);
301 rect.width = ALIGN(rect.width, 2);
302 rect.height = ALIGN(rect.height, 2);
304 soc_camera_limit_side(&rect.left, &rect.width,
305 MT9T031_COLUMN_SKIP, MT9T031_MIN_WIDTH, MT9T031_MAX_WIDTH);
307 soc_camera_limit_side(&rect.top, &rect.height,
308 MT9T031_ROW_SKIP, MT9T031_MIN_HEIGHT, MT9T031_MAX_HEIGHT);
310 return mt9t031_set_params(client, &rect, mt9t031->xskip, mt9t031->yskip);
313 static int mt9t031_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
315 struct i2c_client *client = v4l2_get_subdevdata(sd);
316 struct mt9t031 *mt9t031 = to_mt9t031(client);
318 a->c = mt9t031->rect;
319 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
324 static int mt9t031_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
326 a->bounds.left = MT9T031_COLUMN_SKIP;
327 a->bounds.top = MT9T031_ROW_SKIP;
328 a->bounds.width = MT9T031_MAX_WIDTH;
329 a->bounds.height = MT9T031_MAX_HEIGHT;
330 a->defrect = a->bounds;
331 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
332 a->pixelaspect.numerator = 1;
333 a->pixelaspect.denominator = 1;
338 static int mt9t031_g_fmt(struct v4l2_subdev *sd,
339 struct v4l2_mbus_framefmt *mf)
341 struct i2c_client *client = v4l2_get_subdevdata(sd);
342 struct mt9t031 *mt9t031 = to_mt9t031(client);
344 mf->width = mt9t031->rect.width / mt9t031->xskip;
345 mf->height = mt9t031->rect.height / mt9t031->yskip;
346 mf->code = V4L2_MBUS_FMT_SBGGR10_1X10;
347 mf->colorspace = V4L2_COLORSPACE_SRGB;
348 mf->field = V4L2_FIELD_NONE;
353 static int mt9t031_s_fmt(struct v4l2_subdev *sd,
354 struct v4l2_mbus_framefmt *mf)
356 struct i2c_client *client = v4l2_get_subdevdata(sd);
357 struct mt9t031 *mt9t031 = to_mt9t031(client);
359 struct v4l2_rect rect = mt9t031->rect;
362 * try_fmt has put width and height within limits.
363 * S_FMT: use binning and skipping for scaling
365 xskip = mt9t031_skip(&rect.width, mf->width, MT9T031_MAX_WIDTH);
366 yskip = mt9t031_skip(&rect.height, mf->height, MT9T031_MAX_HEIGHT);
368 mf->code = V4L2_MBUS_FMT_SBGGR10_1X10;
369 mf->colorspace = V4L2_COLORSPACE_SRGB;
371 /* mt9t031_set_params() doesn't change width and height */
372 return mt9t031_set_params(client, &rect, xskip, yskip);
376 * If a user window larger than sensor window is requested, we'll increase the
379 static int mt9t031_try_fmt(struct v4l2_subdev *sd,
380 struct v4l2_mbus_framefmt *mf)
382 v4l_bound_align_image(
383 &mf->width, MT9T031_MIN_WIDTH, MT9T031_MAX_WIDTH, 1,
384 &mf->height, MT9T031_MIN_HEIGHT, MT9T031_MAX_HEIGHT, 1, 0);
386 mf->code = V4L2_MBUS_FMT_SBGGR10_1X10;
387 mf->colorspace = V4L2_COLORSPACE_SRGB;
392 #ifdef CONFIG_VIDEO_ADV_DEBUG
393 static int mt9t031_g_register(struct v4l2_subdev *sd,
394 struct v4l2_dbg_register *reg)
396 struct i2c_client *client = v4l2_get_subdevdata(sd);
401 reg->val = reg_read(client, reg->reg);
403 if (reg->val > 0xffff)
409 static int mt9t031_s_register(struct v4l2_subdev *sd,
410 const struct v4l2_dbg_register *reg)
412 struct i2c_client *client = v4l2_get_subdevdata(sd);
417 if (reg_write(client, reg->reg, reg->val) < 0)
424 static int mt9t031_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
426 struct mt9t031 *mt9t031 = container_of(ctrl->handler,
427 struct mt9t031, hdl);
428 const u32 shutter_max = MT9T031_MAX_HEIGHT + MT9T031_VERTICAL_BLANK;
432 case V4L2_CID_EXPOSURE_AUTO:
433 min = mt9t031->exposure->minimum;
434 max = mt9t031->exposure->maximum;
435 mt9t031->exposure->val =
436 (shutter_max / 2 + (mt9t031->total_h - 1) * (max - min))
443 static int mt9t031_s_ctrl(struct v4l2_ctrl *ctrl)
445 struct mt9t031 *mt9t031 = container_of(ctrl->handler,
446 struct mt9t031, hdl);
447 struct v4l2_subdev *sd = &mt9t031->subdev;
448 struct i2c_client *client = v4l2_get_subdevdata(sd);
449 struct v4l2_ctrl *exp = mt9t031->exposure;
455 data = reg_set(client, MT9T031_READ_MODE_2, 0x8000);
457 data = reg_clear(client, MT9T031_READ_MODE_2, 0x8000);
463 data = reg_set(client, MT9T031_READ_MODE_2, 0x4000);
465 data = reg_clear(client, MT9T031_READ_MODE_2, 0x4000);
470 /* See Datasheet Table 7, Gain settings. */
471 if (ctrl->val <= ctrl->default_value) {
472 /* Pack it into 0..1 step 0.125, register values 0..8 */
473 unsigned long range = ctrl->default_value - ctrl->minimum;
474 data = ((ctrl->val - ctrl->minimum) * 8 + range / 2) / range;
476 dev_dbg(&client->dev, "Setting gain %d\n", data);
477 data = reg_write(client, MT9T031_GLOBAL_GAIN, data);
481 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
482 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
483 unsigned long range = ctrl->maximum - ctrl->default_value - 1;
484 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
485 unsigned long gain = ((ctrl->val - ctrl->default_value - 1) *
486 1015 + range / 2) / range + 9;
488 if (gain <= 32) /* calculated gain 9..32 -> 9..32 */
490 else if (gain <= 64) /* calculated gain 33..64 -> 0x51..0x60 */
491 data = ((gain - 32) * 16 + 16) / 32 + 80;
493 /* calculated gain 65..1024 -> (1..120) << 8 + 0x60 */
494 data = (((gain - 64 + 7) * 32) & 0xff00) | 0x60;
496 dev_dbg(&client->dev, "Set gain from 0x%x to 0x%x\n",
497 reg_read(client, MT9T031_GLOBAL_GAIN), data);
498 data = reg_write(client, MT9T031_GLOBAL_GAIN, data);
504 case V4L2_CID_EXPOSURE_AUTO:
505 if (ctrl->val == V4L2_EXPOSURE_MANUAL) {
506 unsigned int range = exp->maximum - exp->minimum;
507 unsigned int shutter = ((exp->val - exp->minimum) * 1048 +
508 range / 2) / range + 1;
511 get_shutter(client, &old);
512 dev_dbg(&client->dev, "Set shutter from %u to %u\n",
514 if (set_shutter(client, shutter) < 0)
517 const u16 vblank = MT9T031_VERTICAL_BLANK;
518 mt9t031->total_h = mt9t031->rect.height +
519 mt9t031->y_skip_top + vblank;
521 if (set_shutter(client, mt9t031->total_h) < 0)
533 * This function does nothing for now but must be present for pm to work
535 static int mt9t031_runtime_suspend(struct device *dev)
542 * COLUMN_ADDRESS_MODE and ROW_ADDRESS_MODE are not rewritten if unchanged
543 * they are however changed at reset if the platform hook is present
544 * thus we rewrite them with the values stored by the driver
546 static int mt9t031_runtime_resume(struct device *dev)
548 struct video_device *vdev = to_video_device(dev);
549 struct v4l2_subdev *sd = soc_camera_vdev_to_subdev(vdev);
550 struct i2c_client *client = v4l2_get_subdevdata(sd);
551 struct mt9t031 *mt9t031 = to_mt9t031(client);
556 xbin = min(mt9t031->xskip, (u16)3);
557 ybin = min(mt9t031->yskip, (u16)3);
559 ret = reg_write(client, MT9T031_COLUMN_ADDRESS_MODE,
560 ((xbin - 1) << 4) | (mt9t031->xskip - 1));
564 ret = reg_write(client, MT9T031_ROW_ADDRESS_MODE,
565 ((ybin - 1) << 4) | (mt9t031->yskip - 1));
572 static struct dev_pm_ops mt9t031_dev_pm_ops = {
573 .runtime_suspend = mt9t031_runtime_suspend,
574 .runtime_resume = mt9t031_runtime_resume,
577 static struct device_type mt9t031_dev_type = {
579 .pm = &mt9t031_dev_pm_ops,
582 static int mt9t031_s_power(struct v4l2_subdev *sd, int on)
584 struct i2c_client *client = v4l2_get_subdevdata(sd);
585 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
586 struct video_device *vdev = soc_camera_i2c_to_vdev(client);
590 ret = soc_camera_power_on(&client->dev, ssdd);
593 vdev->dev.type = &mt9t031_dev_type;
595 vdev->dev.type = NULL;
596 soc_camera_power_off(&client->dev, ssdd);
603 * Interface active, can use i2c. If it fails, it can indeed mean, that
604 * this wasn't our capture interface, so, we wait for the right one
606 static int mt9t031_video_probe(struct i2c_client *client)
608 struct mt9t031 *mt9t031 = to_mt9t031(client);
612 ret = mt9t031_s_power(&mt9t031->subdev, 1);
616 ret = mt9t031_idle(client);
618 dev_err(&client->dev, "Failed to initialise the camera\n");
622 /* Read out the chip version register */
623 data = reg_read(client, MT9T031_CHIP_VERSION);
629 dev_err(&client->dev,
630 "No MT9T031 chip detected, register read %x\n", data);
635 dev_info(&client->dev, "Detected a MT9T031 chip ID %x\n", data);
637 ret = v4l2_ctrl_handler_setup(&mt9t031->hdl);
640 mt9t031_s_power(&mt9t031->subdev, 0);
645 static int mt9t031_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
647 struct i2c_client *client = v4l2_get_subdevdata(sd);
648 struct mt9t031 *mt9t031 = to_mt9t031(client);
650 *lines = mt9t031->y_skip_top;
655 static const struct v4l2_ctrl_ops mt9t031_ctrl_ops = {
656 .g_volatile_ctrl = mt9t031_g_volatile_ctrl,
657 .s_ctrl = mt9t031_s_ctrl,
660 static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
661 .s_power = mt9t031_s_power,
662 #ifdef CONFIG_VIDEO_ADV_DEBUG
663 .g_register = mt9t031_g_register,
664 .s_register = mt9t031_s_register,
668 static int mt9t031_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
669 enum v4l2_mbus_pixelcode *code)
674 *code = V4L2_MBUS_FMT_SBGGR10_1X10;
678 static int mt9t031_g_mbus_config(struct v4l2_subdev *sd,
679 struct v4l2_mbus_config *cfg)
681 struct i2c_client *client = v4l2_get_subdevdata(sd);
682 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
684 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
685 V4L2_MBUS_PCLK_SAMPLE_FALLING | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
686 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH;
687 cfg->type = V4L2_MBUS_PARALLEL;
688 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
693 static int mt9t031_s_mbus_config(struct v4l2_subdev *sd,
694 const struct v4l2_mbus_config *cfg)
696 struct i2c_client *client = v4l2_get_subdevdata(sd);
697 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
699 if (soc_camera_apply_board_flags(ssdd, cfg) &
700 V4L2_MBUS_PCLK_SAMPLE_FALLING)
701 return reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
703 return reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
706 static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
707 .s_stream = mt9t031_s_stream,
708 .s_mbus_fmt = mt9t031_s_fmt,
709 .g_mbus_fmt = mt9t031_g_fmt,
710 .try_mbus_fmt = mt9t031_try_fmt,
711 .s_crop = mt9t031_s_crop,
712 .g_crop = mt9t031_g_crop,
713 .cropcap = mt9t031_cropcap,
714 .enum_mbus_fmt = mt9t031_enum_fmt,
715 .g_mbus_config = mt9t031_g_mbus_config,
716 .s_mbus_config = mt9t031_s_mbus_config,
719 static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
720 .g_skip_top_lines = mt9t031_g_skip_top_lines,
723 static struct v4l2_subdev_ops mt9t031_subdev_ops = {
724 .core = &mt9t031_subdev_core_ops,
725 .video = &mt9t031_subdev_video_ops,
726 .sensor = &mt9t031_subdev_sensor_ops,
729 static int mt9t031_probe(struct i2c_client *client,
730 const struct i2c_device_id *did)
732 struct mt9t031 *mt9t031;
733 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
734 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
738 dev_err(&client->dev, "MT9T031 driver needs platform data\n");
742 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
743 dev_warn(&adapter->dev,
744 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
748 mt9t031 = devm_kzalloc(&client->dev, sizeof(struct mt9t031), GFP_KERNEL);
752 v4l2_i2c_subdev_init(&mt9t031->subdev, client, &mt9t031_subdev_ops);
753 v4l2_ctrl_handler_init(&mt9t031->hdl, 5);
754 v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
755 V4L2_CID_VFLIP, 0, 1, 1, 0);
756 v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
757 V4L2_CID_HFLIP, 0, 1, 1, 0);
758 v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
759 V4L2_CID_GAIN, 0, 127, 1, 64);
762 * Simulated autoexposure. If enabled, we calculate shutter width
763 * ourselves in the driver based on vertical blanking and frame width
765 mt9t031->autoexposure = v4l2_ctrl_new_std_menu(&mt9t031->hdl,
766 &mt9t031_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
768 mt9t031->exposure = v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
769 V4L2_CID_EXPOSURE, 1, 255, 1, 255);
771 mt9t031->subdev.ctrl_handler = &mt9t031->hdl;
772 if (mt9t031->hdl.error)
773 return mt9t031->hdl.error;
775 v4l2_ctrl_auto_cluster(2, &mt9t031->autoexposure,
776 V4L2_EXPOSURE_MANUAL, true);
778 mt9t031->y_skip_top = 0;
779 mt9t031->rect.left = MT9T031_COLUMN_SKIP;
780 mt9t031->rect.top = MT9T031_ROW_SKIP;
781 mt9t031->rect.width = MT9T031_MAX_WIDTH;
782 mt9t031->rect.height = MT9T031_MAX_HEIGHT;
787 ret = mt9t031_video_probe(client);
789 v4l2_ctrl_handler_free(&mt9t031->hdl);
794 static int mt9t031_remove(struct i2c_client *client)
796 struct mt9t031 *mt9t031 = to_mt9t031(client);
798 v4l2_device_unregister_subdev(&mt9t031->subdev);
799 v4l2_ctrl_handler_free(&mt9t031->hdl);
804 static const struct i2c_device_id mt9t031_id[] = {
808 MODULE_DEVICE_TABLE(i2c, mt9t031_id);
810 static struct i2c_driver mt9t031_i2c_driver = {
814 .probe = mt9t031_probe,
815 .remove = mt9t031_remove,
816 .id_table = mt9t031_id,
819 module_i2c_driver(mt9t031_i2c_driver);
821 MODULE_DESCRIPTION("Micron MT9T031 Camera driver");
822 MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>");
823 MODULE_LICENSE("GPL v2");