1 // SPDX-License-Identifier: GPL-2.0
3 * Omnivision OV2680 CMOS Image Sensor driver
5 * Copyright (C) 2018 Linaro Ltd
7 * Based on OV5640 Sensor Driver
8 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
9 * Copyright (C) 2014-2017 Mentor Graphics Inc.
13 #include <linux/clk.h>
14 #include <linux/delay.h>
15 #include <linux/err.h>
16 #include <linux/gpio/consumer.h>
17 #include <linux/i2c.h>
18 #include <linux/init.h>
19 #include <linux/mod_devicetable.h>
20 #include <linux/module.h>
21 #include <linux/pm_runtime.h>
22 #include <linux/regmap.h>
23 #include <linux/regulator/consumer.h>
25 #include <media/v4l2-cci.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-ctrls.h>
28 #include <media/v4l2-subdev.h>
30 #define OV2680_XVCLK_VALUE 24000000
32 #define OV2680_CHIP_ID 0x2680
34 #define OV2680_REG_STREAM_CTRL CCI_REG8(0x0100)
35 #define OV2680_REG_SOFT_RESET CCI_REG8(0x0103)
37 #define OV2680_REG_CHIP_ID CCI_REG16(0x300a)
39 #define OV2680_REG_EXPOSURE_PK CCI_REG24(0x3500)
40 #define OV2680_REG_R_MANUAL CCI_REG8(0x3503)
41 #define OV2680_REG_GAIN_PK CCI_REG16(0x350a)
42 #define OV2680_REG_TIMING_HTS CCI_REG16(0x380c)
43 #define OV2680_REG_TIMING_VTS CCI_REG16(0x380e)
44 #define OV2680_REG_FORMAT1 CCI_REG8(0x3820)
45 #define OV2680_REG_FORMAT2 CCI_REG8(0x3821)
47 #define OV2680_REG_ISP_CTRL00 CCI_REG8(0x5080)
49 #define OV2680_FRAME_RATE 30
51 #define OV2680_WIDTH_MAX 1600
52 #define OV2680_HEIGHT_MAX 1200
54 #define OV2680_DEFAULT_WIDTH 800
55 #define OV2680_DEFAULT_HEIGHT 600
58 OV2680_MODE_QUXGA_800_600,
59 OV2680_MODE_720P_1280_720,
60 OV2680_MODE_UXGA_1600_1200,
64 static const char * const ov2680_supply_name[] = {
70 #define OV2680_NUM_SUPPLIES ARRAY_SIZE(ov2680_supply_name)
72 struct ov2680_mode_info {
74 enum ov2680_mode_id id;
77 const struct reg_sequence *reg_data;
82 struct v4l2_ctrl_handler handler;
83 struct v4l2_ctrl *exposure;
84 struct v4l2_ctrl *gain;
85 struct v4l2_ctrl *hflip;
86 struct v4l2_ctrl *vflip;
87 struct v4l2_ctrl *test_pattern;
92 struct regmap *regmap;
93 struct v4l2_subdev sd;
98 struct regulator_bulk_data supplies[OV2680_NUM_SUPPLIES];
100 struct gpio_desc *reset_gpio;
101 struct mutex lock; /* protect members */
106 struct ov2680_ctrls ctrls;
107 struct v4l2_mbus_framefmt fmt;
108 struct v4l2_fract frame_interval;
110 const struct ov2680_mode_info *current_mode;
113 static const char * const test_pattern_menu[] = {
121 static const int ov2680_hv_flip_bayer_order[] = {
122 MEDIA_BUS_FMT_SBGGR10_1X10,
123 MEDIA_BUS_FMT_SGRBG10_1X10,
124 MEDIA_BUS_FMT_SGBRG10_1X10,
125 MEDIA_BUS_FMT_SRGGB10_1X10,
128 static const struct reg_sequence ov2680_setting_30fps_QUXGA_800_600[] = {
129 {0x3086, 0x01}, {0x370a, 0x23}, {0x3808, 0x03}, {0x3809, 0x20},
130 {0x380a, 0x02}, {0x380b, 0x58}, {0x380c, 0x06}, {0x380d, 0xac},
131 {0x380e, 0x02}, {0x380f, 0x84}, {0x3811, 0x04}, {0x3813, 0x04},
132 {0x3814, 0x31}, {0x3815, 0x31}, {0x3820, 0xc0}, {0x4008, 0x00},
133 {0x4009, 0x03}, {0x4837, 0x1e}, {0x3501, 0x4e}, {0x3502, 0xe0},
137 static const struct reg_sequence ov2680_setting_30fps_720P_1280_720[] = {
138 {0x3086, 0x00}, {0x3808, 0x05}, {0x3809, 0x00}, {0x380a, 0x02},
139 {0x380b, 0xd0}, {0x380c, 0x06}, {0x380d, 0xa8}, {0x380e, 0x05},
140 {0x380f, 0x0e}, {0x3811, 0x08}, {0x3813, 0x06}, {0x3814, 0x11},
141 {0x3815, 0x11}, {0x3820, 0xc0}, {0x4008, 0x00},
144 static const struct reg_sequence ov2680_setting_30fps_UXGA_1600_1200[] = {
145 {0x3086, 0x00}, {0x3501, 0x4e}, {0x3502, 0xe0}, {0x3808, 0x06},
146 {0x3809, 0x40}, {0x380a, 0x04}, {0x380b, 0xb0}, {0x380c, 0x06},
147 {0x380d, 0xa8}, {0x380e, 0x05}, {0x380f, 0x0e}, {0x3811, 0x00},
148 {0x3813, 0x00}, {0x3814, 0x11}, {0x3815, 0x11}, {0x3820, 0xc0},
149 {0x4008, 0x00}, {0x4837, 0x18}
152 static const struct ov2680_mode_info ov2680_mode_init_data = {
153 "mode_quxga_800_600", OV2680_MODE_QUXGA_800_600, 800, 600,
154 ov2680_setting_30fps_QUXGA_800_600,
155 ARRAY_SIZE(ov2680_setting_30fps_QUXGA_800_600),
158 static const struct ov2680_mode_info ov2680_mode_data[OV2680_MODE_MAX] = {
159 {"mode_quxga_800_600", OV2680_MODE_QUXGA_800_600,
160 800, 600, ov2680_setting_30fps_QUXGA_800_600,
161 ARRAY_SIZE(ov2680_setting_30fps_QUXGA_800_600)},
162 {"mode_720p_1280_720", OV2680_MODE_720P_1280_720,
163 1280, 720, ov2680_setting_30fps_720P_1280_720,
164 ARRAY_SIZE(ov2680_setting_30fps_720P_1280_720)},
165 {"mode_uxga_1600_1200", OV2680_MODE_UXGA_1600_1200,
166 1600, 1200, ov2680_setting_30fps_UXGA_1600_1200,
167 ARRAY_SIZE(ov2680_setting_30fps_UXGA_1600_1200)},
170 static struct ov2680_dev *to_ov2680_dev(struct v4l2_subdev *sd)
172 return container_of(sd, struct ov2680_dev, sd);
175 static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
177 return &container_of(ctrl->handler, struct ov2680_dev,
181 static void ov2680_power_up(struct ov2680_dev *sensor)
183 if (!sensor->reset_gpio)
186 gpiod_set_value(sensor->reset_gpio, 0);
187 usleep_range(5000, 10000);
190 static void ov2680_power_down(struct ov2680_dev *sensor)
192 if (!sensor->reset_gpio)
195 gpiod_set_value(sensor->reset_gpio, 1);
196 usleep_range(5000, 10000);
199 static void ov2680_set_bayer_order(struct ov2680_dev *sensor,
200 struct v4l2_mbus_framefmt *fmt)
204 if (sensor->ctrls.vflip && sensor->ctrls.vflip->val)
207 if (sensor->ctrls.hflip && sensor->ctrls.hflip->val)
210 fmt->code = ov2680_hv_flip_bayer_order[hv_flip];
213 static void ov2680_fill_format(struct ov2680_dev *sensor,
214 struct v4l2_mbus_framefmt *fmt,
215 unsigned int width, unsigned int height)
217 memset(fmt, 0, sizeof(*fmt));
219 fmt->height = height;
220 fmt->field = V4L2_FIELD_NONE;
221 fmt->colorspace = V4L2_COLORSPACE_SRGB;
222 ov2680_set_bayer_order(sensor, fmt);
225 static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val)
229 if (sensor->is_streaming)
232 ret = cci_update_bits(sensor->regmap, OV2680_REG_FORMAT1,
233 BIT(2), val ? BIT(2) : 0, NULL);
237 ov2680_set_bayer_order(sensor, &sensor->fmt);
241 static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val)
245 if (sensor->is_streaming)
248 ret = cci_update_bits(sensor->regmap, OV2680_REG_FORMAT2,
249 BIT(2), val ? BIT(2) : 0, NULL);
253 ov2680_set_bayer_order(sensor, &sensor->fmt);
257 static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value)
262 return cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00,
265 cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00,
266 0x03, value - 1, &ret);
267 cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00,
268 BIT(7), BIT(7), &ret);
273 static int ov2680_gain_set(struct ov2680_dev *sensor, u32 gain)
275 return cci_write(sensor->regmap, OV2680_REG_GAIN_PK, gain, NULL);
278 static int ov2680_exposure_set(struct ov2680_dev *sensor, u32 exp)
280 return cci_write(sensor->regmap, OV2680_REG_EXPOSURE_PK, exp << 4,
284 static int ov2680_stream_enable(struct ov2680_dev *sensor)
288 ret = regmap_multi_reg_write(sensor->regmap,
289 ov2680_mode_init_data.reg_data,
290 ov2680_mode_init_data.reg_data_size);
294 ret = regmap_multi_reg_write(sensor->regmap,
295 sensor->current_mode->reg_data,
296 sensor->current_mode->reg_data_size);
300 /* Restore value of all ctrls */
301 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler);
305 return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 1, NULL);
308 static int ov2680_stream_disable(struct ov2680_dev *sensor)
310 return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 0, NULL);
313 static int ov2680_power_off(struct ov2680_dev *sensor)
315 if (!sensor->is_enabled)
318 clk_disable_unprepare(sensor->xvclk);
319 ov2680_power_down(sensor);
320 regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies);
321 sensor->is_enabled = false;
326 static int ov2680_power_on(struct ov2680_dev *sensor)
330 if (sensor->is_enabled)
333 ret = regulator_bulk_enable(OV2680_NUM_SUPPLIES, sensor->supplies);
335 dev_err(sensor->dev, "failed to enable regulators: %d\n", ret);
339 if (!sensor->reset_gpio) {
340 ret = cci_write(sensor->regmap, OV2680_REG_SOFT_RESET, 0x01,
343 dev_err(sensor->dev, "sensor soft reset failed\n");
344 goto err_disable_regulators;
346 usleep_range(1000, 2000);
348 ov2680_power_down(sensor);
349 ov2680_power_up(sensor);
352 ret = clk_prepare_enable(sensor->xvclk);
354 goto err_disable_regulators;
356 sensor->is_enabled = true;
360 err_disable_regulators:
361 regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies);
365 static int ov2680_s_g_frame_interval(struct v4l2_subdev *sd,
366 struct v4l2_subdev_frame_interval *fi)
368 struct ov2680_dev *sensor = to_ov2680_dev(sd);
370 mutex_lock(&sensor->lock);
371 fi->interval = sensor->frame_interval;
372 mutex_unlock(&sensor->lock);
377 static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)
379 struct ov2680_dev *sensor = to_ov2680_dev(sd);
382 mutex_lock(&sensor->lock);
384 if (sensor->is_streaming == !!enable)
388 ret = pm_runtime_resume_and_get(sensor->sd.dev);
392 ret = ov2680_stream_enable(sensor);
394 pm_runtime_put(sensor->sd.dev);
398 ret = ov2680_stream_disable(sensor);
399 pm_runtime_put(sensor->sd.dev);
402 sensor->is_streaming = !!enable;
405 mutex_unlock(&sensor->lock);
410 static int ov2680_enum_mbus_code(struct v4l2_subdev *sd,
411 struct v4l2_subdev_state *sd_state,
412 struct v4l2_subdev_mbus_code_enum *code)
414 struct ov2680_dev *sensor = to_ov2680_dev(sd);
416 if (code->pad != 0 || code->index != 0)
419 code->code = sensor->fmt.code;
424 static int ov2680_get_fmt(struct v4l2_subdev *sd,
425 struct v4l2_subdev_state *sd_state,
426 struct v4l2_subdev_format *format)
428 struct ov2680_dev *sensor = to_ov2680_dev(sd);
429 struct v4l2_mbus_framefmt *fmt = NULL;
431 if (format->pad != 0)
434 mutex_lock(&sensor->lock);
436 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
437 fmt = v4l2_subdev_get_try_format(&sensor->sd, sd_state,
443 format->format = *fmt;
445 mutex_unlock(&sensor->lock);
450 static int ov2680_set_fmt(struct v4l2_subdev *sd,
451 struct v4l2_subdev_state *sd_state,
452 struct v4l2_subdev_format *format)
454 struct ov2680_dev *sensor = to_ov2680_dev(sd);
455 struct v4l2_mbus_framefmt *try_fmt;
456 const struct ov2680_mode_info *mode;
459 if (format->pad != 0)
462 mode = v4l2_find_nearest_size(ov2680_mode_data,
463 ARRAY_SIZE(ov2680_mode_data),
465 format->format.width,
466 format->format.height);
470 ov2680_fill_format(sensor, &format->format, mode->width, mode->height);
472 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
473 try_fmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
474 *try_fmt = format->format;
478 mutex_lock(&sensor->lock);
480 if (sensor->is_streaming) {
485 sensor->current_mode = mode;
486 sensor->fmt = format->format;
489 mutex_unlock(&sensor->lock);
494 static int ov2680_init_cfg(struct v4l2_subdev *sd,
495 struct v4l2_subdev_state *sd_state)
497 struct ov2680_dev *sensor = to_ov2680_dev(sd);
499 ov2680_fill_format(sensor, &sd_state->pads[0].try_fmt,
500 OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT);
504 static int ov2680_enum_frame_size(struct v4l2_subdev *sd,
505 struct v4l2_subdev_state *sd_state,
506 struct v4l2_subdev_frame_size_enum *fse)
508 int index = fse->index;
510 if (index >= OV2680_MODE_MAX || index < 0)
513 fse->min_width = ov2680_mode_data[index].width;
514 fse->min_height = ov2680_mode_data[index].height;
515 fse->max_width = ov2680_mode_data[index].width;
516 fse->max_height = ov2680_mode_data[index].height;
521 static int ov2680_enum_frame_interval(struct v4l2_subdev *sd,
522 struct v4l2_subdev_state *sd_state,
523 struct v4l2_subdev_frame_interval_enum *fie)
525 struct v4l2_fract tpf;
527 if (fie->index >= OV2680_MODE_MAX || fie->width > OV2680_WIDTH_MAX ||
528 fie->height > OV2680_HEIGHT_MAX ||
529 fie->which > V4L2_SUBDEV_FORMAT_ACTIVE)
532 tpf.denominator = OV2680_FRAME_RATE;
540 static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)
542 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
543 struct ov2680_dev *sensor = to_ov2680_dev(sd);
545 if (!sensor->is_enabled)
550 return ov2680_gain_set(sensor, ctrl->val);
551 case V4L2_CID_EXPOSURE:
552 return ov2680_exposure_set(sensor, ctrl->val);
554 return ov2680_set_vflip(sensor, ctrl->val);
556 return ov2680_set_hflip(sensor, ctrl->val);
557 case V4L2_CID_TEST_PATTERN:
558 return ov2680_test_pattern_set(sensor, ctrl->val);
566 static const struct v4l2_ctrl_ops ov2680_ctrl_ops = {
567 .s_ctrl = ov2680_s_ctrl,
570 static const struct v4l2_subdev_video_ops ov2680_video_ops = {
571 .g_frame_interval = ov2680_s_g_frame_interval,
572 .s_frame_interval = ov2680_s_g_frame_interval,
573 .s_stream = ov2680_s_stream,
576 static const struct v4l2_subdev_pad_ops ov2680_pad_ops = {
577 .init_cfg = ov2680_init_cfg,
578 .enum_mbus_code = ov2680_enum_mbus_code,
579 .get_fmt = ov2680_get_fmt,
580 .set_fmt = ov2680_set_fmt,
581 .enum_frame_size = ov2680_enum_frame_size,
582 .enum_frame_interval = ov2680_enum_frame_interval,
585 static const struct v4l2_subdev_ops ov2680_subdev_ops = {
586 .video = &ov2680_video_ops,
587 .pad = &ov2680_pad_ops,
590 static int ov2680_mode_init(struct ov2680_dev *sensor)
592 const struct ov2680_mode_info *init_mode;
594 /* set initial mode */
595 ov2680_fill_format(sensor, &sensor->fmt,
596 OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT);
598 sensor->frame_interval.denominator = OV2680_FRAME_RATE;
599 sensor->frame_interval.numerator = 1;
601 init_mode = &ov2680_mode_init_data;
603 sensor->current_mode = init_mode;
608 static int ov2680_v4l2_register(struct ov2680_dev *sensor)
610 struct i2c_client *client = to_i2c_client(sensor->dev);
611 const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops;
612 struct ov2680_ctrls *ctrls = &sensor->ctrls;
613 struct v4l2_ctrl_handler *hdl = &ctrls->handler;
616 v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_subdev_ops);
618 sensor->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
619 sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
620 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
622 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad);
626 v4l2_ctrl_handler_init(hdl, 5);
628 hdl->lock = &sensor->lock;
630 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
631 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
633 ctrls->test_pattern = v4l2_ctrl_new_std_menu_items(hdl,
634 &ov2680_ctrl_ops, V4L2_CID_TEST_PATTERN,
635 ARRAY_SIZE(test_pattern_menu) - 1,
636 0, 0, test_pattern_menu);
638 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE,
641 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN, 0, 2047, 1, 0);
648 ctrls->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
649 ctrls->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
651 sensor->sd.ctrl_handler = hdl;
653 ret = v4l2_async_register_subdev(&sensor->sd);
660 media_entity_cleanup(&sensor->sd.entity);
661 v4l2_ctrl_handler_free(hdl);
666 static int ov2680_get_regulators(struct ov2680_dev *sensor)
670 for (i = 0; i < OV2680_NUM_SUPPLIES; i++)
671 sensor->supplies[i].supply = ov2680_supply_name[i];
673 return devm_regulator_bulk_get(sensor->dev,
674 OV2680_NUM_SUPPLIES, sensor->supplies);
677 static int ov2680_check_id(struct ov2680_dev *sensor)
682 ret = cci_read(sensor->regmap, OV2680_REG_CHIP_ID, &chip_id, NULL);
684 dev_err(sensor->dev, "failed to read chip id\n");
688 if (chip_id != OV2680_CHIP_ID) {
689 dev_err(sensor->dev, "chip id: 0x%04llx does not match expected 0x%04x\n",
690 chip_id, OV2680_CHIP_ID);
697 static int ov2680_parse_dt(struct ov2680_dev *sensor)
699 struct device *dev = sensor->dev;
702 sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset",
704 ret = PTR_ERR_OR_ZERO(sensor->reset_gpio);
706 dev_dbg(dev, "error while getting reset gpio: %d\n", ret);
710 sensor->xvclk = devm_clk_get(dev, "xvclk");
711 if (IS_ERR(sensor->xvclk)) {
712 dev_err(dev, "xvclk clock missing or invalid\n");
713 return PTR_ERR(sensor->xvclk);
716 sensor->xvclk_freq = clk_get_rate(sensor->xvclk);
717 if (sensor->xvclk_freq != OV2680_XVCLK_VALUE) {
718 dev_err(dev, "wrong xvclk frequency %d HZ, expected: %d Hz\n",
719 sensor->xvclk_freq, OV2680_XVCLK_VALUE);
726 static int ov2680_probe(struct i2c_client *client)
728 struct device *dev = &client->dev;
729 struct ov2680_dev *sensor;
732 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
736 sensor->dev = &client->dev;
738 sensor->regmap = devm_cci_regmap_init_i2c(client, 16);
739 if (IS_ERR(sensor->regmap))
740 return PTR_ERR(sensor->regmap);
742 ret = ov2680_parse_dt(sensor);
746 ret = ov2680_mode_init(sensor);
750 ret = ov2680_get_regulators(sensor);
752 dev_err(dev, "failed to get regulators\n");
756 mutex_init(&sensor->lock);
759 * Power up and verify the chip now, so that if runtime pm is
760 * disabled the chip is left on and streaming will work.
762 ret = ov2680_power_on(sensor);
766 ret = ov2680_check_id(sensor);
770 pm_runtime_set_active(&client->dev);
771 pm_runtime_get_noresume(&client->dev);
772 pm_runtime_enable(&client->dev);
774 ret = ov2680_v4l2_register(sensor);
778 pm_runtime_set_autosuspend_delay(&client->dev, 1000);
779 pm_runtime_use_autosuspend(&client->dev);
780 pm_runtime_put_autosuspend(&client->dev);
782 dev_info(dev, "ov2680 init correctly\n");
787 pm_runtime_disable(&client->dev);
788 pm_runtime_put_noidle(&client->dev);
790 ov2680_power_off(sensor);
792 dev_err(dev, "ov2680 init fail: %d\n", ret);
793 mutex_destroy(&sensor->lock);
798 static void ov2680_remove(struct i2c_client *client)
800 struct v4l2_subdev *sd = i2c_get_clientdata(client);
801 struct ov2680_dev *sensor = to_ov2680_dev(sd);
803 v4l2_async_unregister_subdev(&sensor->sd);
804 mutex_destroy(&sensor->lock);
805 media_entity_cleanup(&sensor->sd.entity);
806 v4l2_ctrl_handler_free(&sensor->ctrls.handler);
809 * Disable runtime PM. In case runtime PM is disabled in the kernel,
810 * make sure to turn power off manually.
812 pm_runtime_disable(&client->dev);
813 if (!pm_runtime_status_suspended(&client->dev))
814 ov2680_power_off(sensor);
815 pm_runtime_set_suspended(&client->dev);
818 static int ov2680_suspend(struct device *dev)
820 struct v4l2_subdev *sd = dev_get_drvdata(dev);
821 struct ov2680_dev *sensor = to_ov2680_dev(sd);
823 if (sensor->is_streaming)
824 ov2680_stream_disable(sensor);
826 return ov2680_power_off(sensor);
829 static int ov2680_resume(struct device *dev)
831 struct v4l2_subdev *sd = dev_get_drvdata(dev);
832 struct ov2680_dev *sensor = to_ov2680_dev(sd);
835 ret = ov2680_power_on(sensor);
839 if (sensor->is_streaming) {
840 ret = ov2680_stream_enable(sensor);
848 ov2680_stream_disable(sensor);
849 sensor->is_streaming = false;
854 static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume,
857 static const struct of_device_id ov2680_dt_ids[] = {
858 { .compatible = "ovti,ov2680" },
861 MODULE_DEVICE_TABLE(of, ov2680_dt_ids);
863 static struct i2c_driver ov2680_i2c_driver = {
866 .pm = pm_sleep_ptr(&ov2680_pm_ops),
867 .of_match_table = ov2680_dt_ids,
869 .probe = ov2680_probe,
870 .remove = ov2680_remove,
872 module_i2c_driver(ov2680_i2c_driver);
874 MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
875 MODULE_DESCRIPTION("OV2680 CMOS Image Sensor driver");
876 MODULE_LICENSE("GPL v2");