1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Intel Corporation.
4 #include <asm/unaligned.h>
5 #include <linux/acpi.h>
6 #include <linux/delay.h>
8 #include <linux/module.h>
9 #include <linux/pm_runtime.h>
10 #include <media/v4l2-ctrls.h>
11 #include <media/v4l2-device.h>
12 #include <media/v4l2-fwnode.h>
14 #define OV9734_LINK_FREQ_180MHZ 180000000ULL
15 #define OV9734_SCLK 36000000LL
16 #define OV9734_MCLK 19200000
17 /* ov9734 only support 1-lane mipi output */
18 #define OV9734_DATA_LANES 1
19 #define OV9734_RGB_DEPTH 10
21 #define OV9734_REG_CHIP_ID 0x300a
22 #define OV9734_CHIP_ID 0x9734
24 #define OV9734_REG_MODE_SELECT 0x0100
25 #define OV9734_MODE_STANDBY 0x00
26 #define OV9734_MODE_STREAMING 0x01
28 /* vertical-timings from sensor */
29 #define OV9734_REG_VTS 0x380e
30 #define OV9734_VTS_30FPS 0x0322
31 #define OV9734_VTS_30FPS_MIN 0x0322
32 #define OV9734_VTS_MAX 0x7fff
34 /* horizontal-timings from sensor */
35 #define OV9734_REG_HTS 0x380c
37 /* Exposure controls from sensor */
38 #define OV9734_REG_EXPOSURE 0x3500
39 #define OV9734_EXPOSURE_MIN 4
40 #define OV9734_EXPOSURE_MAX_MARGIN 4
41 #define OV9734_EXPOSURE_STEP 1
43 /* Analog gain controls from sensor */
44 #define OV9734_REG_ANALOG_GAIN 0x350a
45 #define OV9734_ANAL_GAIN_MIN 16
46 #define OV9734_ANAL_GAIN_MAX 248
47 #define OV9734_ANAL_GAIN_STEP 1
49 /* Digital gain controls from sensor */
50 #define OV9734_REG_MWB_R_GAIN 0x5180
51 #define OV9734_REG_MWB_G_GAIN 0x5182
52 #define OV9734_REG_MWB_B_GAIN 0x5184
53 #define OV9734_DGTL_GAIN_MIN 256
54 #define OV9734_DGTL_GAIN_MAX 1023
55 #define OV9734_DGTL_GAIN_STEP 1
56 #define OV9734_DGTL_GAIN_DEFAULT 256
58 /* Test Pattern Control */
59 #define OV9734_REG_TEST_PATTERN 0x5080
60 #define OV9734_TEST_PATTERN_ENABLE BIT(7)
61 #define OV9734_TEST_PATTERN_BAR_SHIFT 2
64 OV9734_LINK_FREQ_180MHZ_INDEX,
72 struct ov9734_reg_list {
74 const struct ov9734_reg *regs;
77 struct ov9734_link_freq_config {
78 const struct ov9734_reg_list reg_list;
82 /* Frame width in pixels */
85 /* Frame height in pixels */
88 /* Horizontal timining size */
91 /* Default vertical timining size */
94 /* Min vertical timining size */
97 /* Link frequency needed for this resolution */
100 /* Sensor register settings for this resolution */
101 const struct ov9734_reg_list reg_list;
104 static const struct ov9734_reg mipi_data_rate_360mbps[] = {
119 static const struct ov9734_reg mode_1296x734_regs[] = {
281 static const char * const ov9734_test_pattern_menu[] = {
283 "Standard Color Bar",
284 "Top-Bottom Darker Color Bar",
285 "Right-Left Darker Color Bar",
286 "Bottom-Top Darker Color Bar",
289 static const s64 link_freq_menu_items[] = {
290 OV9734_LINK_FREQ_180MHZ,
293 static const struct ov9734_link_freq_config link_freq_configs[] = {
294 [OV9734_LINK_FREQ_180MHZ_INDEX] = {
296 .num_of_regs = ARRAY_SIZE(mipi_data_rate_360mbps),
297 .regs = mipi_data_rate_360mbps,
302 static const struct ov9734_mode supported_modes[] = {
307 .vts_def = OV9734_VTS_30FPS,
308 .vts_min = OV9734_VTS_30FPS_MIN,
310 .num_of_regs = ARRAY_SIZE(mode_1296x734_regs),
311 .regs = mode_1296x734_regs,
313 .link_freq_index = OV9734_LINK_FREQ_180MHZ_INDEX,
318 struct v4l2_subdev sd;
319 struct media_pad pad;
320 struct v4l2_ctrl_handler ctrl_handler;
323 struct v4l2_ctrl *link_freq;
324 struct v4l2_ctrl *pixel_rate;
325 struct v4l2_ctrl *vblank;
326 struct v4l2_ctrl *hblank;
327 struct v4l2_ctrl *exposure;
330 const struct ov9734_mode *cur_mode;
332 /* To serialize asynchronus callbacks */
335 /* Streaming on/off */
339 static inline struct ov9734 *to_ov9734(struct v4l2_subdev *subdev)
341 return container_of(subdev, struct ov9734, sd);
344 static u64 to_pixel_rate(u32 f_index)
346 u64 pixel_rate = link_freq_menu_items[f_index] * 2 * OV9734_DATA_LANES;
348 do_div(pixel_rate, OV9734_RGB_DEPTH);
353 static u64 to_pixels_per_line(u32 hts, u32 f_index)
355 u64 ppl = hts * to_pixel_rate(f_index);
357 do_div(ppl, OV9734_SCLK);
362 static int ov9734_read_reg(struct ov9734 *ov9734, u16 reg, u16 len, u32 *val)
364 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
365 struct i2c_msg msgs[2];
367 u8 data_buf[4] = {0};
370 if (len > sizeof(data_buf))
373 put_unaligned_be16(reg, addr_buf);
374 msgs[0].addr = client->addr;
376 msgs[0].len = sizeof(addr_buf);
377 msgs[0].buf = addr_buf;
378 msgs[1].addr = client->addr;
379 msgs[1].flags = I2C_M_RD;
381 msgs[1].buf = &data_buf[sizeof(data_buf) - len];
383 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
384 if (ret != ARRAY_SIZE(msgs))
385 return ret < 0 ? ret : -EIO;
387 *val = get_unaligned_be32(data_buf);
392 static int ov9734_write_reg(struct ov9734 *ov9734, u16 reg, u16 len, u32 val)
394 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
401 put_unaligned_be16(reg, buf);
402 put_unaligned_be32(val << 8 * (4 - len), buf + 2);
404 ret = i2c_master_send(client, buf, len + 2);
406 return ret < 0 ? ret : -EIO;
411 static int ov9734_write_reg_list(struct ov9734 *ov9734,
412 const struct ov9734_reg_list *r_list)
414 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
418 for (i = 0; i < r_list->num_of_regs; i++) {
419 ret = ov9734_write_reg(ov9734, r_list->regs[i].address, 1,
420 r_list->regs[i].val);
422 dev_err_ratelimited(&client->dev,
423 "write reg 0x%4.4x return err = %d",
424 r_list->regs[i].address, ret);
432 static int ov9734_update_digital_gain(struct ov9734 *ov9734, u32 d_gain)
436 ret = ov9734_write_reg(ov9734, OV9734_REG_MWB_R_GAIN, 2, d_gain);
440 ret = ov9734_write_reg(ov9734, OV9734_REG_MWB_G_GAIN, 2, d_gain);
444 return ov9734_write_reg(ov9734, OV9734_REG_MWB_B_GAIN, 2, d_gain);
447 static int ov9734_test_pattern(struct ov9734 *ov9734, u32 pattern)
450 pattern = (pattern - 1) << OV9734_TEST_PATTERN_BAR_SHIFT |
451 OV9734_TEST_PATTERN_ENABLE;
453 return ov9734_write_reg(ov9734, OV9734_REG_TEST_PATTERN, 1, pattern);
456 static int ov9734_set_ctrl(struct v4l2_ctrl *ctrl)
458 struct ov9734 *ov9734 = container_of(ctrl->handler,
459 struct ov9734, ctrl_handler);
460 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
464 /* Propagate change of current control to all related controls */
465 if (ctrl->id == V4L2_CID_VBLANK) {
466 /* Update max exposure while meeting expected vblanking */
467 exposure_max = ov9734->cur_mode->height + ctrl->val -
468 OV9734_EXPOSURE_MAX_MARGIN;
469 __v4l2_ctrl_modify_range(ov9734->exposure,
470 ov9734->exposure->minimum,
471 exposure_max, ov9734->exposure->step,
475 /* V4L2 controls values will be applied only when power is already up */
476 if (!pm_runtime_get_if_in_use(&client->dev))
480 case V4L2_CID_ANALOGUE_GAIN:
481 ret = ov9734_write_reg(ov9734, OV9734_REG_ANALOG_GAIN,
485 case V4L2_CID_DIGITAL_GAIN:
486 ret = ov9734_update_digital_gain(ov9734, ctrl->val);
489 case V4L2_CID_EXPOSURE:
490 /* 4 least significant bits of expsoure are fractional part */
491 ret = ov9734_write_reg(ov9734, OV9734_REG_EXPOSURE,
495 case V4L2_CID_VBLANK:
496 ret = ov9734_write_reg(ov9734, OV9734_REG_VTS, 2,
497 ov9734->cur_mode->height + ctrl->val);
500 case V4L2_CID_TEST_PATTERN:
501 ret = ov9734_test_pattern(ov9734, ctrl->val);
509 pm_runtime_put(&client->dev);
514 static const struct v4l2_ctrl_ops ov9734_ctrl_ops = {
515 .s_ctrl = ov9734_set_ctrl,
518 static int ov9734_init_controls(struct ov9734 *ov9734)
520 struct v4l2_ctrl_handler *ctrl_hdlr;
521 const struct ov9734_mode *cur_mode;
522 s64 exposure_max, h_blank, pixel_rate;
523 u32 vblank_min, vblank_max, vblank_default;
526 ctrl_hdlr = &ov9734->ctrl_handler;
527 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
531 ctrl_hdlr->lock = &ov9734->mutex;
532 cur_mode = ov9734->cur_mode;
533 size = ARRAY_SIZE(link_freq_menu_items);
534 ov9734->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov9734_ctrl_ops,
537 link_freq_menu_items);
538 if (ov9734->link_freq)
539 ov9734->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
541 pixel_rate = to_pixel_rate(OV9734_LINK_FREQ_180MHZ_INDEX);
542 ov9734->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
543 V4L2_CID_PIXEL_RATE, 0,
544 pixel_rate, 1, pixel_rate);
545 vblank_min = cur_mode->vts_min - cur_mode->height;
546 vblank_max = OV9734_VTS_MAX - cur_mode->height;
547 vblank_default = cur_mode->vts_def - cur_mode->height;
548 ov9734->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
549 V4L2_CID_VBLANK, vblank_min,
550 vblank_max, 1, vblank_default);
551 h_blank = to_pixels_per_line(cur_mode->hts, cur_mode->link_freq_index);
552 h_blank -= cur_mode->width;
553 ov9734->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
554 V4L2_CID_HBLANK, h_blank, h_blank, 1,
557 ov9734->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
559 v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
560 OV9734_ANAL_GAIN_MIN, OV9734_ANAL_GAIN_MAX,
561 OV9734_ANAL_GAIN_STEP, OV9734_ANAL_GAIN_MIN);
562 v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
563 OV9734_DGTL_GAIN_MIN, OV9734_DGTL_GAIN_MAX,
564 OV9734_DGTL_GAIN_STEP, OV9734_DGTL_GAIN_DEFAULT);
565 exposure_max = ov9734->cur_mode->vts_def - OV9734_EXPOSURE_MAX_MARGIN;
566 ov9734->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
568 OV9734_EXPOSURE_MIN, exposure_max,
569 OV9734_EXPOSURE_STEP,
571 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov9734_ctrl_ops,
572 V4L2_CID_TEST_PATTERN,
573 ARRAY_SIZE(ov9734_test_pattern_menu) - 1,
574 0, 0, ov9734_test_pattern_menu);
575 if (ctrl_hdlr->error)
576 return ctrl_hdlr->error;
578 ov9734->sd.ctrl_handler = ctrl_hdlr;
583 static void ov9734_update_pad_format(const struct ov9734_mode *mode,
584 struct v4l2_mbus_framefmt *fmt)
586 fmt->width = mode->width;
587 fmt->height = mode->height;
588 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
589 fmt->field = V4L2_FIELD_NONE;
592 static int ov9734_start_streaming(struct ov9734 *ov9734)
594 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
595 const struct ov9734_reg_list *reg_list;
596 int link_freq_index, ret;
598 link_freq_index = ov9734->cur_mode->link_freq_index;
599 reg_list = &link_freq_configs[link_freq_index].reg_list;
600 ret = ov9734_write_reg_list(ov9734, reg_list);
602 dev_err(&client->dev, "failed to set plls");
606 reg_list = &ov9734->cur_mode->reg_list;
607 ret = ov9734_write_reg_list(ov9734, reg_list);
609 dev_err(&client->dev, "failed to set mode");
613 ret = __v4l2_ctrl_handler_setup(ov9734->sd.ctrl_handler);
617 ret = ov9734_write_reg(ov9734, OV9734_REG_MODE_SELECT,
618 1, OV9734_MODE_STREAMING);
620 dev_err(&client->dev, "failed to start stream");
625 static void ov9734_stop_streaming(struct ov9734 *ov9734)
627 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
629 if (ov9734_write_reg(ov9734, OV9734_REG_MODE_SELECT,
630 1, OV9734_MODE_STANDBY))
631 dev_err(&client->dev, "failed to stop stream");
634 static int ov9734_set_stream(struct v4l2_subdev *sd, int enable)
636 struct ov9734 *ov9734 = to_ov9734(sd);
637 struct i2c_client *client = v4l2_get_subdevdata(sd);
640 mutex_lock(&ov9734->mutex);
641 if (ov9734->streaming == enable) {
642 mutex_unlock(&ov9734->mutex);
647 ret = pm_runtime_get_sync(&client->dev);
649 pm_runtime_put_noidle(&client->dev);
650 mutex_unlock(&ov9734->mutex);
654 ret = ov9734_start_streaming(ov9734);
657 ov9734_stop_streaming(ov9734);
658 pm_runtime_put(&client->dev);
661 ov9734_stop_streaming(ov9734);
662 pm_runtime_put(&client->dev);
665 ov9734->streaming = enable;
666 mutex_unlock(&ov9734->mutex);
671 static int __maybe_unused ov9734_suspend(struct device *dev)
673 struct i2c_client *client = to_i2c_client(dev);
674 struct v4l2_subdev *sd = i2c_get_clientdata(client);
675 struct ov9734 *ov9734 = to_ov9734(sd);
677 mutex_lock(&ov9734->mutex);
678 if (ov9734->streaming)
679 ov9734_stop_streaming(ov9734);
681 mutex_unlock(&ov9734->mutex);
686 static int __maybe_unused ov9734_resume(struct device *dev)
688 struct i2c_client *client = to_i2c_client(dev);
689 struct v4l2_subdev *sd = i2c_get_clientdata(client);
690 struct ov9734 *ov9734 = to_ov9734(sd);
693 mutex_lock(&ov9734->mutex);
694 if (!ov9734->streaming)
697 ret = ov9734_start_streaming(ov9734);
699 ov9734->streaming = false;
700 ov9734_stop_streaming(ov9734);
704 mutex_unlock(&ov9734->mutex);
708 static int ov9734_set_format(struct v4l2_subdev *sd,
709 struct v4l2_subdev_pad_config *cfg,
710 struct v4l2_subdev_format *fmt)
712 struct ov9734 *ov9734 = to_ov9734(sd);
713 const struct ov9734_mode *mode;
714 s32 vblank_def, h_blank;
716 mode = v4l2_find_nearest_size(supported_modes,
717 ARRAY_SIZE(supported_modes), width,
718 height, fmt->format.width,
721 mutex_lock(&ov9734->mutex);
722 ov9734_update_pad_format(mode, &fmt->format);
723 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
724 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
726 ov9734->cur_mode = mode;
727 __v4l2_ctrl_s_ctrl(ov9734->link_freq, mode->link_freq_index);
728 __v4l2_ctrl_s_ctrl_int64(ov9734->pixel_rate,
729 to_pixel_rate(mode->link_freq_index));
731 /* Update limits and set FPS to default */
732 vblank_def = mode->vts_def - mode->height;
733 __v4l2_ctrl_modify_range(ov9734->vblank,
734 mode->vts_min - mode->height,
735 OV9734_VTS_MAX - mode->height, 1,
737 __v4l2_ctrl_s_ctrl(ov9734->vblank, vblank_def);
738 h_blank = to_pixels_per_line(mode->hts, mode->link_freq_index) -
740 __v4l2_ctrl_modify_range(ov9734->hblank, h_blank, h_blank, 1,
744 mutex_unlock(&ov9734->mutex);
749 static int ov9734_get_format(struct v4l2_subdev *sd,
750 struct v4l2_subdev_pad_config *cfg,
751 struct v4l2_subdev_format *fmt)
753 struct ov9734 *ov9734 = to_ov9734(sd);
755 mutex_lock(&ov9734->mutex);
756 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
757 fmt->format = *v4l2_subdev_get_try_format(&ov9734->sd, cfg,
760 ov9734_update_pad_format(ov9734->cur_mode, &fmt->format);
762 mutex_unlock(&ov9734->mutex);
767 static int ov9734_enum_mbus_code(struct v4l2_subdev *sd,
768 struct v4l2_subdev_pad_config *cfg,
769 struct v4l2_subdev_mbus_code_enum *code)
774 code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
779 static int ov9734_enum_frame_size(struct v4l2_subdev *sd,
780 struct v4l2_subdev_pad_config *cfg,
781 struct v4l2_subdev_frame_size_enum *fse)
783 if (fse->index >= ARRAY_SIZE(supported_modes))
786 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
789 fse->min_width = supported_modes[fse->index].width;
790 fse->max_width = fse->min_width;
791 fse->min_height = supported_modes[fse->index].height;
792 fse->max_height = fse->min_height;
797 static int ov9734_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
799 struct ov9734 *ov9734 = to_ov9734(sd);
801 mutex_lock(&ov9734->mutex);
802 ov9734_update_pad_format(&supported_modes[0],
803 v4l2_subdev_get_try_format(sd, fh->pad, 0));
804 mutex_unlock(&ov9734->mutex);
809 static const struct v4l2_subdev_video_ops ov9734_video_ops = {
810 .s_stream = ov9734_set_stream,
813 static const struct v4l2_subdev_pad_ops ov9734_pad_ops = {
814 .set_fmt = ov9734_set_format,
815 .get_fmt = ov9734_get_format,
816 .enum_mbus_code = ov9734_enum_mbus_code,
817 .enum_frame_size = ov9734_enum_frame_size,
820 static const struct v4l2_subdev_ops ov9734_subdev_ops = {
821 .video = &ov9734_video_ops,
822 .pad = &ov9734_pad_ops,
825 static const struct media_entity_operations ov9734_subdev_entity_ops = {
826 .link_validate = v4l2_subdev_link_validate,
829 static const struct v4l2_subdev_internal_ops ov9734_internal_ops = {
833 static int ov9734_identify_module(struct ov9734 *ov9734)
835 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
839 ret = ov9734_read_reg(ov9734, OV9734_REG_CHIP_ID, 2, &val);
843 if (val != OV9734_CHIP_ID) {
844 dev_err(&client->dev, "chip id mismatch: %x!=%x",
845 OV9734_CHIP_ID, val);
852 static int ov9734_check_hwcfg(struct device *dev)
854 struct fwnode_handle *ep;
855 struct fwnode_handle *fwnode = dev_fwnode(dev);
856 struct v4l2_fwnode_endpoint bus_cfg = {
857 .bus_type = V4L2_MBUS_CSI2_DPHY
866 ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk);
870 if (mclk != OV9734_MCLK) {
871 dev_err(dev, "external clock %d is not supported", mclk);
875 ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
879 ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
880 fwnode_handle_put(ep);
884 if (!bus_cfg.nr_of_link_frequencies) {
885 dev_err(dev, "no link frequencies defined");
887 goto check_hwcfg_error;
890 for (i = 0; i < ARRAY_SIZE(link_freq_menu_items); i++) {
891 for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
892 if (link_freq_menu_items[i] ==
893 bus_cfg.link_frequencies[j])
897 if (j == bus_cfg.nr_of_link_frequencies) {
898 dev_err(dev, "no link frequency %lld supported",
899 link_freq_menu_items[i]);
901 goto check_hwcfg_error;
906 v4l2_fwnode_endpoint_free(&bus_cfg);
911 static int ov9734_remove(struct i2c_client *client)
913 struct v4l2_subdev *sd = i2c_get_clientdata(client);
914 struct ov9734 *ov9734 = to_ov9734(sd);
916 v4l2_async_unregister_subdev(sd);
917 media_entity_cleanup(&sd->entity);
918 v4l2_ctrl_handler_free(sd->ctrl_handler);
919 pm_runtime_disable(&client->dev);
920 mutex_destroy(&ov9734->mutex);
925 static int ov9734_probe(struct i2c_client *client)
927 struct ov9734 *ov9734;
930 ret = ov9734_check_hwcfg(&client->dev);
932 dev_err(&client->dev, "failed to check HW configuration: %d",
937 ov9734 = devm_kzalloc(&client->dev, sizeof(*ov9734), GFP_KERNEL);
941 v4l2_i2c_subdev_init(&ov9734->sd, client, &ov9734_subdev_ops);
942 ret = ov9734_identify_module(ov9734);
944 dev_err(&client->dev, "failed to find sensor: %d", ret);
948 mutex_init(&ov9734->mutex);
949 ov9734->cur_mode = &supported_modes[0];
950 ret = ov9734_init_controls(ov9734);
952 dev_err(&client->dev, "failed to init controls: %d", ret);
953 goto probe_error_v4l2_ctrl_handler_free;
956 ov9734->sd.internal_ops = &ov9734_internal_ops;
957 ov9734->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
958 ov9734->sd.entity.ops = &ov9734_subdev_entity_ops;
959 ov9734->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
960 ov9734->pad.flags = MEDIA_PAD_FL_SOURCE;
961 ret = media_entity_pads_init(&ov9734->sd.entity, 1, &ov9734->pad);
963 dev_err(&client->dev, "failed to init entity pads: %d", ret);
964 goto probe_error_v4l2_ctrl_handler_free;
967 ret = v4l2_async_register_subdev_sensor_common(&ov9734->sd);
969 dev_err(&client->dev, "failed to register V4L2 subdev: %d",
971 goto probe_error_media_entity_cleanup;
975 * Device is already turned on by i2c-core with ACPI domain PM.
976 * Enable runtime PM and turn off the device.
978 pm_runtime_set_active(&client->dev);
979 pm_runtime_enable(&client->dev);
980 pm_runtime_idle(&client->dev);
984 probe_error_media_entity_cleanup:
985 media_entity_cleanup(&ov9734->sd.entity);
987 probe_error_v4l2_ctrl_handler_free:
988 v4l2_ctrl_handler_free(ov9734->sd.ctrl_handler);
989 mutex_destroy(&ov9734->mutex);
994 static const struct dev_pm_ops ov9734_pm_ops = {
995 SET_SYSTEM_SLEEP_PM_OPS(ov9734_suspend, ov9734_resume)
998 static const struct acpi_device_id ov9734_acpi_ids[] = {
1003 MODULE_DEVICE_TABLE(acpi, ov9734_acpi_ids);
1005 static struct i2c_driver ov9734_i2c_driver = {
1008 .pm = &ov9734_pm_ops,
1009 .acpi_match_table = ov9734_acpi_ids,
1011 .probe_new = ov9734_probe,
1012 .remove = ov9734_remove,
1015 module_i2c_driver(ov9734_i2c_driver);
1017 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
1018 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
1019 MODULE_DESCRIPTION("OmniVision OV9734 sensor driver");
1020 MODULE_LICENSE("GPL v2");