1 // SPDX-License-Identifier: GPL-2.0
3 * Support for OmniVision OV2680 1080p HD camera sensor.
5 * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
6 * Copyright (c) 2023 Hans de Goede <hdegoede@redhat.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/acpi.h>
20 #include <linux/device.h>
21 #include <linux/gpio/consumer.h>
22 #include <linux/gpio/machine.h>
23 #include <linux/i2c.h>
24 #include <linux/module.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/types.h>
28 #include <media/ov_16bit_addr_reg_helpers.h>
29 #include <media/v4l2-device.h>
33 static const struct v4l2_rect ov2680_default_crop = {
34 .left = OV2680_ACTIVE_START_LEFT,
35 .top = OV2680_ACTIVE_START_TOP,
36 .width = OV2680_ACTIVE_WIDTH,
37 .height = OV2680_ACTIVE_HEIGHT,
40 static int ov2680_write_reg_array(struct i2c_client *client,
41 const struct ov2680_reg *reglist)
43 const struct ov2680_reg *next = reglist;
46 for (; next->reg != 0; next++) {
47 ret = ov_write_reg8(client, next->reg, next->val);
55 static void ov2680_set_bayer_order(struct ov2680_dev *sensor, struct v4l2_mbus_framefmt *fmt)
57 static const int ov2680_hv_flip_bayer_order[] = {
58 MEDIA_BUS_FMT_SBGGR10_1X10,
59 MEDIA_BUS_FMT_SGRBG10_1X10,
60 MEDIA_BUS_FMT_SGBRG10_1X10,
61 MEDIA_BUS_FMT_SRGGB10_1X10,
65 if (sensor->ctrls.vflip->val)
68 if (sensor->ctrls.hflip->val)
71 fmt->code = ov2680_hv_flip_bayer_order[hv_flip];
74 static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val)
78 if (sensor->is_streaming)
81 ret = ov_update_reg(sensor->client, OV2680_REG_FORMAT1, BIT(2), val ? BIT(2) : 0);
85 ov2680_set_bayer_order(sensor, &sensor->mode.fmt);
89 static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val)
93 if (sensor->is_streaming)
96 ret = ov_update_reg(sensor->client, OV2680_REG_FORMAT2, BIT(2), val ? BIT(2) : 0);
100 ov2680_set_bayer_order(sensor, &sensor->mode.fmt);
104 static int ov2680_exposure_set(struct ov2680_dev *sensor, u32 exp)
106 return ov_write_reg24(sensor->client, OV2680_REG_EXPOSURE_PK_HIGH, exp << 4);
109 static int ov2680_gain_set(struct ov2680_dev *sensor, u32 gain)
111 return ov_write_reg16(sensor->client, OV2680_REG_GAIN_PK, gain);
114 static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value)
119 return ov_update_reg(sensor->client, OV2680_REG_ISP_CTRL00, BIT(7), 0);
121 ret = ov_update_reg(sensor->client, OV2680_REG_ISP_CTRL00, 0x03, value - 1);
125 ret = ov_update_reg(sensor->client, OV2680_REG_ISP_CTRL00, BIT(7), BIT(7));
132 static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)
134 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
135 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
138 /* Only apply changes to the controls if the device is powered up */
139 if (!pm_runtime_get_if_in_use(sensor->sd.dev)) {
140 ov2680_set_bayer_order(sensor, &sensor->mode.fmt);
146 ret = ov2680_set_vflip(sensor, ctrl->val);
149 ret = ov2680_set_hflip(sensor, ctrl->val);
151 case V4L2_CID_EXPOSURE:
152 ret = ov2680_exposure_set(sensor, ctrl->val);
155 ret = ov2680_gain_set(sensor, ctrl->val);
157 case V4L2_CID_TEST_PATTERN:
158 ret = ov2680_test_pattern_set(sensor, ctrl->val);
164 pm_runtime_put(sensor->sd.dev);
168 static const struct v4l2_ctrl_ops ov2680_ctrl_ops = {
169 .s_ctrl = ov2680_s_ctrl,
172 static int ov2680_init_registers(struct v4l2_subdev *sd)
174 struct i2c_client *client = v4l2_get_subdevdata(sd);
177 ret = ov_write_reg8(client, OV2680_SW_RESET, 0x01);
179 /* Wait for sensor reset */
180 usleep_range(1000, 2000);
182 ret |= ov2680_write_reg_array(client, ov2680_global_setting);
187 static struct v4l2_mbus_framefmt *
188 __ov2680_get_pad_format(struct ov2680_dev *sensor, struct v4l2_subdev_state *state,
189 unsigned int pad, enum v4l2_subdev_format_whence which)
191 if (which == V4L2_SUBDEV_FORMAT_TRY)
192 return v4l2_subdev_get_try_format(&sensor->sd, state, pad);
194 return &sensor->mode.fmt;
197 static struct v4l2_rect *
198 __ov2680_get_pad_crop(struct ov2680_dev *sensor, struct v4l2_subdev_state *state,
199 unsigned int pad, enum v4l2_subdev_format_whence which)
201 if (which == V4L2_SUBDEV_FORMAT_TRY)
202 return v4l2_subdev_get_try_crop(&sensor->sd, state, pad);
204 return &sensor->mode.crop;
207 static void ov2680_fill_format(struct ov2680_dev *sensor,
208 struct v4l2_mbus_framefmt *fmt,
209 unsigned int width, unsigned int height)
211 memset(fmt, 0, sizeof(*fmt));
213 fmt->height = height;
214 fmt->field = V4L2_FIELD_NONE;
215 ov2680_set_bayer_order(sensor, fmt);
218 static void ov2680_calc_mode(struct ov2680_dev *sensor)
220 int width = sensor->mode.fmt.width;
221 int height = sensor->mode.fmt.height;
222 int orig_width = width;
223 int orig_height = height;
225 if (width <= (sensor->mode.crop.width / 2) &&
226 height <= (sensor->mode.crop.height / 2)) {
227 sensor->mode.binning = true;
231 sensor->mode.binning = false;
234 sensor->mode.h_start =
235 (sensor->mode.crop.left + (sensor->mode.crop.width - width) / 2) & ~1;
236 sensor->mode.v_start =
237 (sensor->mode.crop.top + (sensor->mode.crop.height - height) / 2) & ~1;
238 sensor->mode.h_end = min(sensor->mode.h_start + width + OV2680_END_MARGIN - 1,
239 OV2680_NATIVE_WIDTH - 1);
240 sensor->mode.v_end = min(sensor->mode.v_start + height + OV2680_END_MARGIN - 1,
241 OV2680_NATIVE_HEIGHT - 1);
242 sensor->mode.h_output_size = orig_width;
243 sensor->mode.v_output_size = orig_height;
244 sensor->mode.hts = OV2680_PIXELS_PER_LINE;
245 sensor->mode.vts = OV2680_LINES_PER_FRAME;
248 static int ov2680_set_mode(struct ov2680_dev *sensor)
250 struct i2c_client *client = sensor->client;
251 u8 sensor_ctrl_0a, inc, fmt1, fmt2;
254 if (sensor->mode.binning) {
255 sensor_ctrl_0a = 0x23;
260 sensor_ctrl_0a = 0x21;
266 ret = ov_write_reg8(client, OV2680_REG_SENSOR_CTRL_0A, sensor_ctrl_0a);
270 ret = ov_write_reg16(client, OV2680_HORIZONTAL_START_H, sensor->mode.h_start);
274 ret = ov_write_reg16(client, OV2680_VERTICAL_START_H, sensor->mode.v_start);
278 ret = ov_write_reg16(client, OV2680_HORIZONTAL_END_H, sensor->mode.h_end);
282 ret = ov_write_reg16(client, OV2680_VERTICAL_END_H, sensor->mode.v_end);
286 ret = ov_write_reg16(client, OV2680_HORIZONTAL_OUTPUT_SIZE_H,
287 sensor->mode.h_output_size);
291 ret = ov_write_reg16(client, OV2680_VERTICAL_OUTPUT_SIZE_H,
292 sensor->mode.v_output_size);
296 ret = ov_write_reg16(client, OV2680_HTS, sensor->mode.hts);
300 ret = ov_write_reg16(client, OV2680_VTS, sensor->mode.vts);
304 ret = ov_write_reg16(client, OV2680_ISP_X_WIN, 0);
308 ret = ov_write_reg16(client, OV2680_ISP_Y_WIN, 0);
312 ret = ov_write_reg8(client, OV2680_X_INC, inc);
316 ret = ov_write_reg8(client, OV2680_Y_INC, inc);
320 ret = ov_write_reg16(client, OV2680_X_WIN, sensor->mode.h_output_size);
324 ret = ov_write_reg16(client, OV2680_Y_WIN, sensor->mode.v_output_size);
328 ret = ov_write_reg8(client, OV2680_REG_FORMAT1, fmt1);
332 ret = ov_write_reg8(client, OV2680_REG_FORMAT2, fmt2);
339 static int ov2680_set_fmt(struct v4l2_subdev *sd,
340 struct v4l2_subdev_state *sd_state,
341 struct v4l2_subdev_format *format)
343 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
344 struct v4l2_mbus_framefmt *fmt;
345 const struct v4l2_rect *crop;
346 unsigned int width, height;
348 crop = __ov2680_get_pad_crop(sensor, sd_state, format->pad, format->which);
350 /* Limit set_fmt max size to crop width / height */
351 width = clamp_t(unsigned int, ALIGN(format->format.width, 2),
352 OV2680_MIN_CROP_WIDTH, crop->width);
353 height = clamp_t(unsigned int, ALIGN(format->format.height, 2),
354 OV2680_MIN_CROP_HEIGHT, crop->height);
356 fmt = __ov2680_get_pad_format(sensor, sd_state, format->pad, format->which);
357 ov2680_fill_format(sensor, fmt, width, height);
359 format->format = *fmt;
361 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
364 mutex_lock(&sensor->lock);
365 ov2680_calc_mode(sensor);
366 mutex_unlock(&sensor->lock);
370 static int ov2680_get_fmt(struct v4l2_subdev *sd,
371 struct v4l2_subdev_state *sd_state,
372 struct v4l2_subdev_format *format)
374 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
375 struct v4l2_mbus_framefmt *fmt;
377 fmt = __ov2680_get_pad_format(sensor, sd_state, format->pad, format->which);
378 format->format = *fmt;
382 static int ov2680_get_selection(struct v4l2_subdev *sd,
383 struct v4l2_subdev_state *state,
384 struct v4l2_subdev_selection *sel)
386 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
388 switch (sel->target) {
389 case V4L2_SEL_TGT_CROP:
390 mutex_lock(&sensor->lock);
391 sel->r = *__ov2680_get_pad_crop(sensor, state, sel->pad, sel->which);
392 mutex_unlock(&sensor->lock);
394 case V4L2_SEL_TGT_NATIVE_SIZE:
395 case V4L2_SEL_TGT_CROP_BOUNDS:
398 sel->r.width = OV2680_NATIVE_WIDTH;
399 sel->r.height = OV2680_NATIVE_HEIGHT;
401 case V4L2_SEL_TGT_CROP_DEFAULT:
402 sel->r.top = OV2680_ACTIVE_START_TOP;
403 sel->r.left = OV2680_ACTIVE_START_LEFT;
404 sel->r.width = OV2680_ACTIVE_WIDTH;
405 sel->r.height = OV2680_ACTIVE_HEIGHT;
414 static int ov2680_set_selection(struct v4l2_subdev *sd,
415 struct v4l2_subdev_state *state,
416 struct v4l2_subdev_selection *sel)
418 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
419 struct v4l2_mbus_framefmt *format;
420 struct v4l2_rect *__crop;
421 struct v4l2_rect rect;
423 if (sel->target != V4L2_SEL_TGT_CROP)
427 * Clamp the boundaries of the crop rectangle to the size of the sensor
428 * pixel array. Align to multiples of 2 to ensure Bayer pattern isn't
431 rect.left = clamp(ALIGN(sel->r.left, 2), OV2680_NATIVE_START_LEFT,
432 OV2680_NATIVE_WIDTH);
433 rect.top = clamp(ALIGN(sel->r.top, 2), OV2680_NATIVE_START_TOP,
434 OV2680_NATIVE_HEIGHT);
435 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
436 OV2680_MIN_CROP_WIDTH, OV2680_NATIVE_WIDTH);
437 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
438 OV2680_MIN_CROP_HEIGHT, OV2680_NATIVE_HEIGHT);
440 /* Make sure the crop rectangle isn't outside the bounds of the array */
441 rect.width = min_t(unsigned int, rect.width,
442 OV2680_NATIVE_WIDTH - rect.left);
443 rect.height = min_t(unsigned int, rect.height,
444 OV2680_NATIVE_HEIGHT - rect.top);
446 __crop = __ov2680_get_pad_crop(sensor, state, sel->pad, sel->which);
448 if (rect.width != __crop->width || rect.height != __crop->height) {
450 * Reset the output image size if the crop rectangle size has
453 format = __ov2680_get_pad_format(sensor, state, sel->pad, sel->which);
454 format->width = rect.width;
455 format->height = rect.height;
464 static int ov2680_init_cfg(struct v4l2_subdev *sd,
465 struct v4l2_subdev_state *sd_state)
467 struct v4l2_subdev_format fmt = {
468 .which = sd_state ? V4L2_SUBDEV_FORMAT_TRY
469 : V4L2_SUBDEV_FORMAT_ACTIVE,
476 sd_state->pads[0].try_crop = ov2680_default_crop;
478 return ov2680_set_fmt(sd, sd_state, &fmt);
481 static int ov2680_detect(struct i2c_client *client)
483 struct i2c_adapter *adapter = client->adapter;
484 u32 high = 0, low = 0;
489 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
492 ret = ov_read_reg8(client, OV2680_SC_CMMN_CHIP_ID_H, &high);
494 dev_err(&client->dev, "sensor_id_high read failed (%d)\n", ret);
497 ret = ov_read_reg8(client, OV2680_SC_CMMN_CHIP_ID_L, &low);
498 id = ((((u16)high) << 8) | (u16)low);
500 if (id != OV2680_ID) {
501 dev_err(&client->dev, "sensor ID error 0x%x\n", id);
505 ret = ov_read_reg8(client, OV2680_SC_CMMN_SUB_ID, &high);
506 revision = (u8)high & 0x0f;
508 dev_info(&client->dev, "sensor_revision id = 0x%x, rev= %d\n",
514 static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)
516 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
517 struct i2c_client *client = v4l2_get_subdevdata(sd);
520 mutex_lock(&sensor->lock);
522 if (sensor->is_streaming == enable) {
523 dev_warn(&client->dev, "stream already %s\n", enable ? "started" : "stopped");
528 ret = pm_runtime_get_sync(sensor->sd.dev);
530 goto error_power_down;
532 ret = ov2680_set_mode(sensor);
534 goto error_power_down;
536 /* Restore value of all ctrls */
537 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler);
539 goto error_power_down;
541 ret = ov_write_reg8(client, OV2680_SW_STREAM, OV2680_START_STREAMING);
543 goto error_power_down;
545 ov_write_reg8(client, OV2680_SW_STREAM, OV2680_STOP_STREAMING);
546 pm_runtime_put(sensor->sd.dev);
549 sensor->is_streaming = enable;
550 v4l2_ctrl_activate(sensor->ctrls.vflip, !enable);
551 v4l2_ctrl_activate(sensor->ctrls.hflip, !enable);
553 mutex_unlock(&sensor->lock);
557 pm_runtime_put(sensor->sd.dev);
558 sensor->is_streaming = false;
560 mutex_unlock(&sensor->lock);
564 static int ov2680_s_config(struct v4l2_subdev *sd)
566 struct i2c_client *client = v4l2_get_subdevdata(sd);
569 ret = pm_runtime_get_sync(&client->dev);
571 dev_err(&client->dev, "ov2680 power-up err.\n");
575 /* config & detect sensor */
576 ret = ov2680_detect(client);
578 dev_err(&client->dev, "ov2680_detect err s_config.\n");
581 pm_runtime_put(&client->dev);
585 static int ov2680_g_frame_interval(struct v4l2_subdev *sd,
586 struct v4l2_subdev_frame_interval *interval)
588 interval->interval.numerator = 1;
589 interval->interval.denominator = OV2680_FPS;
593 static int ov2680_enum_mbus_code(struct v4l2_subdev *sd,
594 struct v4l2_subdev_state *sd_state,
595 struct v4l2_subdev_mbus_code_enum *code)
597 /* We support only a single format */
601 code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
605 static int ov2680_enum_frame_size(struct v4l2_subdev *sd,
606 struct v4l2_subdev_state *sd_state,
607 struct v4l2_subdev_frame_size_enum *fse)
609 static const struct v4l2_frmsize_discrete ov2680_frame_sizes[] = {
619 int index = fse->index;
621 if (index >= ARRAY_SIZE(ov2680_frame_sizes))
624 fse->min_width = ov2680_frame_sizes[index].width;
625 fse->min_height = ov2680_frame_sizes[index].height;
626 fse->max_width = ov2680_frame_sizes[index].width;
627 fse->max_height = ov2680_frame_sizes[index].height;
632 static int ov2680_enum_frame_interval(struct v4l2_subdev *sd,
633 struct v4l2_subdev_state *sd_state,
634 struct v4l2_subdev_frame_interval_enum *fie)
636 /* Only 1 framerate */
640 fie->interval.numerator = 1;
641 fie->interval.denominator = OV2680_FPS;
645 static int ov2680_g_skip_frames(struct v4l2_subdev *sd, u32 *frames)
647 *frames = OV2680_SKIP_FRAMES;
651 static const struct v4l2_subdev_video_ops ov2680_video_ops = {
652 .s_stream = ov2680_s_stream,
653 .g_frame_interval = ov2680_g_frame_interval,
656 static const struct v4l2_subdev_sensor_ops ov2680_sensor_ops = {
657 .g_skip_frames = ov2680_g_skip_frames,
660 static const struct v4l2_subdev_pad_ops ov2680_pad_ops = {
661 .init_cfg = ov2680_init_cfg,
662 .enum_mbus_code = ov2680_enum_mbus_code,
663 .enum_frame_size = ov2680_enum_frame_size,
664 .enum_frame_interval = ov2680_enum_frame_interval,
665 .get_fmt = ov2680_get_fmt,
666 .set_fmt = ov2680_set_fmt,
667 .get_selection = ov2680_get_selection,
668 .set_selection = ov2680_set_selection,
671 static const struct v4l2_subdev_ops ov2680_ops = {
672 .video = &ov2680_video_ops,
673 .pad = &ov2680_pad_ops,
674 .sensor = &ov2680_sensor_ops,
677 static int ov2680_init_controls(struct ov2680_dev *sensor)
679 static const char * const test_pattern_menu[] = {
686 const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops;
687 struct ov2680_ctrls *ctrls = &sensor->ctrls;
688 struct v4l2_ctrl_handler *hdl = &ctrls->handler;
689 int exp_max = OV2680_LINES_PER_FRAME - OV2680_INTEGRATION_TIME_MARGIN;
691 v4l2_ctrl_handler_init(hdl, 4);
693 hdl->lock = &sensor->lock;
695 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
696 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
697 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE,
698 0, exp_max, 1, exp_max);
699 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN, 0, 1023, 1, 250);
700 ctrls->test_pattern =
701 v4l2_ctrl_new_std_menu_items(hdl,
702 &ov2680_ctrl_ops, V4L2_CID_TEST_PATTERN,
703 ARRAY_SIZE(test_pattern_menu) - 1,
704 0, 0, test_pattern_menu);
706 ctrls->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
707 ctrls->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
712 sensor->sd.ctrl_handler = hdl;
716 static void ov2680_remove(struct i2c_client *client)
718 struct v4l2_subdev *sd = i2c_get_clientdata(client);
719 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
721 dev_dbg(&client->dev, "ov2680_remove...\n");
723 v4l2_async_unregister_subdev(&sensor->sd);
724 media_entity_cleanup(&sensor->sd.entity);
725 v4l2_ctrl_handler_free(&sensor->ctrls.handler);
726 mutex_destroy(&sensor->lock);
727 fwnode_handle_put(sensor->ep_fwnode);
728 pm_runtime_disable(&client->dev);
731 static int ov2680_probe(struct i2c_client *client)
733 struct device *dev = &client->dev;
734 struct ov2680_dev *sensor;
737 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
741 mutex_init(&sensor->lock);
743 sensor->client = client;
744 v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_ops);
747 * Sometimes the fwnode graph is initialized by the bridge driver.
748 * Bridge drivers doing this may also add GPIO mappings, wait for this.
750 sensor->ep_fwnode = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
751 if (!sensor->ep_fwnode)
752 return dev_err_probe(dev, -EPROBE_DEFER, "waiting for fwnode graph endpoint\n");
754 sensor->powerdown = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH);
755 if (IS_ERR(sensor->powerdown)) {
756 fwnode_handle_put(sensor->ep_fwnode);
757 return dev_err_probe(dev, PTR_ERR(sensor->powerdown), "getting powerdown GPIO\n");
760 pm_runtime_set_suspended(dev);
761 pm_runtime_enable(dev);
762 pm_runtime_set_autosuspend_delay(dev, 1000);
763 pm_runtime_use_autosuspend(dev);
765 ret = ov2680_s_config(&sensor->sd);
767 ov2680_remove(client);
771 sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
772 sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
773 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
774 sensor->sd.fwnode = sensor->ep_fwnode;
776 ret = ov2680_init_controls(sensor);
778 ov2680_remove(client);
782 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad);
784 ov2680_remove(client);
788 sensor->mode.crop = ov2680_default_crop;
789 ov2680_fill_format(sensor, &sensor->mode.fmt, OV2680_NATIVE_WIDTH, OV2680_NATIVE_HEIGHT);
790 ov2680_calc_mode(sensor);
792 ret = v4l2_async_register_subdev_sensor(&sensor->sd);
794 ov2680_remove(client);
801 static int ov2680_suspend(struct device *dev)
803 struct v4l2_subdev *sd = dev_get_drvdata(dev);
804 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
806 gpiod_set_value_cansleep(sensor->powerdown, 1);
810 static int ov2680_resume(struct device *dev)
812 struct v4l2_subdev *sd = dev_get_drvdata(dev);
813 struct ov2680_dev *sensor = to_ov2680_sensor(sd);
815 /* according to DS, at least 5ms is needed after DOVDD (enabled by ACPI) */
816 usleep_range(5000, 6000);
818 gpiod_set_value_cansleep(sensor->powerdown, 0);
820 /* according to DS, 20ms is needed between PWDN and i2c access */
823 ov2680_init_registers(sd);
827 static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, NULL);
829 static const struct acpi_device_id ov2680_acpi_match[] = {
834 MODULE_DEVICE_TABLE(acpi, ov2680_acpi_match);
836 static struct i2c_driver ov2680_driver = {
839 .pm = pm_sleep_ptr(&ov2680_pm_ops),
840 .acpi_match_table = ov2680_acpi_match,
842 .probe = ov2680_probe,
843 .remove = ov2680_remove,
845 module_i2c_driver(ov2680_driver);
847 MODULE_AUTHOR("Jacky Wang <Jacky_wang@ovt.com>");
848 MODULE_DESCRIPTION("A low-level driver for OmniVision 2680 sensors");
849 MODULE_LICENSE("GPL");