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 #define OV9734_REG_GROUP_ACCESS 0x3208
65 #define OV9734_GROUP_HOLD_START 0x0
66 #define OV9734_GROUP_HOLD_END 0x10
67 #define OV9734_GROUP_HOLD_LAUNCH 0xa0
70 OV9734_LINK_FREQ_180MHZ_INDEX,
78 struct ov9734_reg_list {
80 const struct ov9734_reg *regs;
83 struct ov9734_link_freq_config {
84 const struct ov9734_reg_list reg_list;
88 /* Frame width in pixels */
91 /* Frame height in pixels */
94 /* Horizontal timining size */
97 /* Default vertical timining size */
100 /* Min vertical timining size */
103 /* Link frequency needed for this resolution */
106 /* Sensor register settings for this resolution */
107 const struct ov9734_reg_list reg_list;
110 static const struct ov9734_reg mipi_data_rate_360mbps[] = {
125 static const struct ov9734_reg mode_1296x734_regs[] = {
287 static const char * const ov9734_test_pattern_menu[] = {
289 "Standard Color Bar",
290 "Top-Bottom Darker Color Bar",
291 "Right-Left Darker Color Bar",
292 "Bottom-Top Darker Color Bar",
295 static const s64 link_freq_menu_items[] = {
296 OV9734_LINK_FREQ_180MHZ,
299 static const struct ov9734_link_freq_config link_freq_configs[] = {
300 [OV9734_LINK_FREQ_180MHZ_INDEX] = {
302 .num_of_regs = ARRAY_SIZE(mipi_data_rate_360mbps),
303 .regs = mipi_data_rate_360mbps,
308 static const struct ov9734_mode supported_modes[] = {
313 .vts_def = OV9734_VTS_30FPS,
314 .vts_min = OV9734_VTS_30FPS_MIN,
316 .num_of_regs = ARRAY_SIZE(mode_1296x734_regs),
317 .regs = mode_1296x734_regs,
319 .link_freq_index = OV9734_LINK_FREQ_180MHZ_INDEX,
324 struct v4l2_subdev sd;
325 struct media_pad pad;
326 struct v4l2_ctrl_handler ctrl_handler;
329 struct v4l2_ctrl *link_freq;
330 struct v4l2_ctrl *pixel_rate;
331 struct v4l2_ctrl *vblank;
332 struct v4l2_ctrl *hblank;
333 struct v4l2_ctrl *exposure;
336 const struct ov9734_mode *cur_mode;
338 /* To serialize asynchronus callbacks */
341 /* Streaming on/off */
345 static inline struct ov9734 *to_ov9734(struct v4l2_subdev *subdev)
347 return container_of(subdev, struct ov9734, sd);
350 static u64 to_pixel_rate(u32 f_index)
352 u64 pixel_rate = link_freq_menu_items[f_index] * 2 * OV9734_DATA_LANES;
354 do_div(pixel_rate, OV9734_RGB_DEPTH);
359 static u64 to_pixels_per_line(u32 hts, u32 f_index)
361 u64 ppl = hts * to_pixel_rate(f_index);
363 do_div(ppl, OV9734_SCLK);
368 static int ov9734_read_reg(struct ov9734 *ov9734, u16 reg, u16 len, u32 *val)
370 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
371 struct i2c_msg msgs[2];
373 u8 data_buf[4] = {0};
376 if (len > sizeof(data_buf))
379 put_unaligned_be16(reg, addr_buf);
380 msgs[0].addr = client->addr;
382 msgs[0].len = sizeof(addr_buf);
383 msgs[0].buf = addr_buf;
384 msgs[1].addr = client->addr;
385 msgs[1].flags = I2C_M_RD;
387 msgs[1].buf = &data_buf[sizeof(data_buf) - len];
389 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
390 if (ret != ARRAY_SIZE(msgs))
391 return ret < 0 ? ret : -EIO;
393 *val = get_unaligned_be32(data_buf);
398 static int ov9734_write_reg(struct ov9734 *ov9734, u16 reg, u16 len, u32 val)
400 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
407 put_unaligned_be16(reg, buf);
408 put_unaligned_be32(val << 8 * (4 - len), buf + 2);
410 ret = i2c_master_send(client, buf, len + 2);
412 return ret < 0 ? ret : -EIO;
417 static int ov9734_write_reg_list(struct ov9734 *ov9734,
418 const struct ov9734_reg_list *r_list)
420 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
424 for (i = 0; i < r_list->num_of_regs; i++) {
425 ret = ov9734_write_reg(ov9734, r_list->regs[i].address, 1,
426 r_list->regs[i].val);
428 dev_err_ratelimited(&client->dev,
429 "write reg 0x%4.4x return err = %d",
430 r_list->regs[i].address, ret);
438 static int ov9734_update_digital_gain(struct ov9734 *ov9734, u32 d_gain)
442 ret = ov9734_write_reg(ov9734, OV9734_REG_GROUP_ACCESS, 1,
443 OV9734_GROUP_HOLD_START);
447 ret = ov9734_write_reg(ov9734, OV9734_REG_MWB_R_GAIN, 2, d_gain);
451 ret = ov9734_write_reg(ov9734, OV9734_REG_MWB_G_GAIN, 2, d_gain);
455 ret = ov9734_write_reg(ov9734, OV9734_REG_MWB_B_GAIN, 2, d_gain);
459 ret = ov9734_write_reg(ov9734, OV9734_REG_GROUP_ACCESS, 1,
460 OV9734_GROUP_HOLD_END);
464 ret = ov9734_write_reg(ov9734, OV9734_REG_GROUP_ACCESS, 1,
465 OV9734_GROUP_HOLD_LAUNCH);
469 static int ov9734_test_pattern(struct ov9734 *ov9734, u32 pattern)
472 pattern = (pattern - 1) << OV9734_TEST_PATTERN_BAR_SHIFT |
473 OV9734_TEST_PATTERN_ENABLE;
475 return ov9734_write_reg(ov9734, OV9734_REG_TEST_PATTERN, 1, pattern);
478 static int ov9734_set_ctrl(struct v4l2_ctrl *ctrl)
480 struct ov9734 *ov9734 = container_of(ctrl->handler,
481 struct ov9734, ctrl_handler);
482 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
486 /* Propagate change of current control to all related controls */
487 if (ctrl->id == V4L2_CID_VBLANK) {
488 /* Update max exposure while meeting expected vblanking */
489 exposure_max = ov9734->cur_mode->height + ctrl->val -
490 OV9734_EXPOSURE_MAX_MARGIN;
491 __v4l2_ctrl_modify_range(ov9734->exposure,
492 ov9734->exposure->minimum,
493 exposure_max, ov9734->exposure->step,
497 /* V4L2 controls values will be applied only when power is already up */
498 if (!pm_runtime_get_if_in_use(&client->dev))
502 case V4L2_CID_ANALOGUE_GAIN:
503 ret = ov9734_write_reg(ov9734, OV9734_REG_ANALOG_GAIN,
507 case V4L2_CID_DIGITAL_GAIN:
508 ret = ov9734_update_digital_gain(ov9734, ctrl->val);
511 case V4L2_CID_EXPOSURE:
512 /* 4 least significant bits of expsoure are fractional part */
513 ret = ov9734_write_reg(ov9734, OV9734_REG_EXPOSURE,
517 case V4L2_CID_VBLANK:
518 ret = ov9734_write_reg(ov9734, OV9734_REG_VTS, 2,
519 ov9734->cur_mode->height + ctrl->val);
522 case V4L2_CID_TEST_PATTERN:
523 ret = ov9734_test_pattern(ov9734, ctrl->val);
531 pm_runtime_put(&client->dev);
536 static const struct v4l2_ctrl_ops ov9734_ctrl_ops = {
537 .s_ctrl = ov9734_set_ctrl,
540 static int ov9734_init_controls(struct ov9734 *ov9734)
542 struct v4l2_ctrl_handler *ctrl_hdlr;
543 const struct ov9734_mode *cur_mode;
544 s64 exposure_max, h_blank, pixel_rate;
545 u32 vblank_min, vblank_max, vblank_default;
548 ctrl_hdlr = &ov9734->ctrl_handler;
549 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
553 ctrl_hdlr->lock = &ov9734->mutex;
554 cur_mode = ov9734->cur_mode;
555 size = ARRAY_SIZE(link_freq_menu_items);
556 ov9734->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov9734_ctrl_ops,
559 link_freq_menu_items);
560 if (ov9734->link_freq)
561 ov9734->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
563 pixel_rate = to_pixel_rate(OV9734_LINK_FREQ_180MHZ_INDEX);
564 ov9734->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
565 V4L2_CID_PIXEL_RATE, 0,
566 pixel_rate, 1, pixel_rate);
567 vblank_min = cur_mode->vts_min - cur_mode->height;
568 vblank_max = OV9734_VTS_MAX - cur_mode->height;
569 vblank_default = cur_mode->vts_def - cur_mode->height;
570 ov9734->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
571 V4L2_CID_VBLANK, vblank_min,
572 vblank_max, 1, vblank_default);
573 h_blank = to_pixels_per_line(cur_mode->hts, cur_mode->link_freq_index);
574 h_blank -= cur_mode->width;
575 ov9734->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
576 V4L2_CID_HBLANK, h_blank, h_blank, 1,
579 ov9734->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
581 v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
582 OV9734_ANAL_GAIN_MIN, OV9734_ANAL_GAIN_MAX,
583 OV9734_ANAL_GAIN_STEP, OV9734_ANAL_GAIN_MIN);
584 v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
585 OV9734_DGTL_GAIN_MIN, OV9734_DGTL_GAIN_MAX,
586 OV9734_DGTL_GAIN_STEP, OV9734_DGTL_GAIN_DEFAULT);
587 exposure_max = ov9734->cur_mode->vts_def - OV9734_EXPOSURE_MAX_MARGIN;
588 ov9734->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov9734_ctrl_ops,
590 OV9734_EXPOSURE_MIN, exposure_max,
591 OV9734_EXPOSURE_STEP,
593 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov9734_ctrl_ops,
594 V4L2_CID_TEST_PATTERN,
595 ARRAY_SIZE(ov9734_test_pattern_menu) - 1,
596 0, 0, ov9734_test_pattern_menu);
597 if (ctrl_hdlr->error)
598 return ctrl_hdlr->error;
600 ov9734->sd.ctrl_handler = ctrl_hdlr;
605 static void ov9734_update_pad_format(const struct ov9734_mode *mode,
606 struct v4l2_mbus_framefmt *fmt)
608 fmt->width = mode->width;
609 fmt->height = mode->height;
610 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
611 fmt->field = V4L2_FIELD_NONE;
614 static int ov9734_start_streaming(struct ov9734 *ov9734)
616 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
617 const struct ov9734_reg_list *reg_list;
618 int link_freq_index, ret;
620 link_freq_index = ov9734->cur_mode->link_freq_index;
621 reg_list = &link_freq_configs[link_freq_index].reg_list;
622 ret = ov9734_write_reg_list(ov9734, reg_list);
624 dev_err(&client->dev, "failed to set plls");
628 reg_list = &ov9734->cur_mode->reg_list;
629 ret = ov9734_write_reg_list(ov9734, reg_list);
631 dev_err(&client->dev, "failed to set mode");
635 ret = __v4l2_ctrl_handler_setup(ov9734->sd.ctrl_handler);
639 ret = ov9734_write_reg(ov9734, OV9734_REG_MODE_SELECT,
640 1, OV9734_MODE_STREAMING);
642 dev_err(&client->dev, "failed to start stream");
647 static void ov9734_stop_streaming(struct ov9734 *ov9734)
649 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
651 if (ov9734_write_reg(ov9734, OV9734_REG_MODE_SELECT,
652 1, OV9734_MODE_STANDBY))
653 dev_err(&client->dev, "failed to stop stream");
656 static int ov9734_set_stream(struct v4l2_subdev *sd, int enable)
658 struct ov9734 *ov9734 = to_ov9734(sd);
659 struct i2c_client *client = v4l2_get_subdevdata(sd);
662 mutex_lock(&ov9734->mutex);
663 if (ov9734->streaming == enable) {
664 mutex_unlock(&ov9734->mutex);
669 ret = pm_runtime_resume_and_get(&client->dev);
671 mutex_unlock(&ov9734->mutex);
675 ret = ov9734_start_streaming(ov9734);
678 ov9734_stop_streaming(ov9734);
679 pm_runtime_put(&client->dev);
682 ov9734_stop_streaming(ov9734);
683 pm_runtime_put(&client->dev);
686 ov9734->streaming = enable;
687 mutex_unlock(&ov9734->mutex);
692 static int __maybe_unused ov9734_suspend(struct device *dev)
694 struct i2c_client *client = to_i2c_client(dev);
695 struct v4l2_subdev *sd = i2c_get_clientdata(client);
696 struct ov9734 *ov9734 = to_ov9734(sd);
698 mutex_lock(&ov9734->mutex);
699 if (ov9734->streaming)
700 ov9734_stop_streaming(ov9734);
702 mutex_unlock(&ov9734->mutex);
707 static int __maybe_unused ov9734_resume(struct device *dev)
709 struct i2c_client *client = to_i2c_client(dev);
710 struct v4l2_subdev *sd = i2c_get_clientdata(client);
711 struct ov9734 *ov9734 = to_ov9734(sd);
714 mutex_lock(&ov9734->mutex);
715 if (!ov9734->streaming)
718 ret = ov9734_start_streaming(ov9734);
720 ov9734->streaming = false;
721 ov9734_stop_streaming(ov9734);
725 mutex_unlock(&ov9734->mutex);
729 static int ov9734_set_format(struct v4l2_subdev *sd,
730 struct v4l2_subdev_state *sd_state,
731 struct v4l2_subdev_format *fmt)
733 struct ov9734 *ov9734 = to_ov9734(sd);
734 const struct ov9734_mode *mode;
735 s32 vblank_def, h_blank;
737 mode = v4l2_find_nearest_size(supported_modes,
738 ARRAY_SIZE(supported_modes), width,
739 height, fmt->format.width,
742 mutex_lock(&ov9734->mutex);
743 ov9734_update_pad_format(mode, &fmt->format);
744 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
745 *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format;
747 ov9734->cur_mode = mode;
748 __v4l2_ctrl_s_ctrl(ov9734->link_freq, mode->link_freq_index);
749 __v4l2_ctrl_s_ctrl_int64(ov9734->pixel_rate,
750 to_pixel_rate(mode->link_freq_index));
752 /* Update limits and set FPS to default */
753 vblank_def = mode->vts_def - mode->height;
754 __v4l2_ctrl_modify_range(ov9734->vblank,
755 mode->vts_min - mode->height,
756 OV9734_VTS_MAX - mode->height, 1,
758 __v4l2_ctrl_s_ctrl(ov9734->vblank, vblank_def);
759 h_blank = to_pixels_per_line(mode->hts, mode->link_freq_index) -
761 __v4l2_ctrl_modify_range(ov9734->hblank, h_blank, h_blank, 1,
765 mutex_unlock(&ov9734->mutex);
770 static int ov9734_get_format(struct v4l2_subdev *sd,
771 struct v4l2_subdev_state *sd_state,
772 struct v4l2_subdev_format *fmt)
774 struct ov9734 *ov9734 = to_ov9734(sd);
776 mutex_lock(&ov9734->mutex);
777 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
778 fmt->format = *v4l2_subdev_get_try_format(&ov9734->sd,
782 ov9734_update_pad_format(ov9734->cur_mode, &fmt->format);
784 mutex_unlock(&ov9734->mutex);
789 static int ov9734_enum_mbus_code(struct v4l2_subdev *sd,
790 struct v4l2_subdev_state *sd_state,
791 struct v4l2_subdev_mbus_code_enum *code)
796 code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
801 static int ov9734_enum_frame_size(struct v4l2_subdev *sd,
802 struct v4l2_subdev_state *sd_state,
803 struct v4l2_subdev_frame_size_enum *fse)
805 if (fse->index >= ARRAY_SIZE(supported_modes))
808 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
811 fse->min_width = supported_modes[fse->index].width;
812 fse->max_width = fse->min_width;
813 fse->min_height = supported_modes[fse->index].height;
814 fse->max_height = fse->min_height;
819 static int ov9734_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
821 struct ov9734 *ov9734 = to_ov9734(sd);
823 mutex_lock(&ov9734->mutex);
824 ov9734_update_pad_format(&supported_modes[0],
825 v4l2_subdev_get_try_format(sd, fh->state, 0));
826 mutex_unlock(&ov9734->mutex);
831 static const struct v4l2_subdev_video_ops ov9734_video_ops = {
832 .s_stream = ov9734_set_stream,
835 static const struct v4l2_subdev_pad_ops ov9734_pad_ops = {
836 .set_fmt = ov9734_set_format,
837 .get_fmt = ov9734_get_format,
838 .enum_mbus_code = ov9734_enum_mbus_code,
839 .enum_frame_size = ov9734_enum_frame_size,
842 static const struct v4l2_subdev_ops ov9734_subdev_ops = {
843 .video = &ov9734_video_ops,
844 .pad = &ov9734_pad_ops,
847 static const struct media_entity_operations ov9734_subdev_entity_ops = {
848 .link_validate = v4l2_subdev_link_validate,
851 static const struct v4l2_subdev_internal_ops ov9734_internal_ops = {
855 static int ov9734_identify_module(struct ov9734 *ov9734)
857 struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd);
861 ret = ov9734_read_reg(ov9734, OV9734_REG_CHIP_ID, 2, &val);
865 if (val != OV9734_CHIP_ID) {
866 dev_err(&client->dev, "chip id mismatch: %x!=%x",
867 OV9734_CHIP_ID, val);
874 static int ov9734_check_hwcfg(struct device *dev)
876 struct fwnode_handle *ep;
877 struct fwnode_handle *fwnode = dev_fwnode(dev);
878 struct v4l2_fwnode_endpoint bus_cfg = {
879 .bus_type = V4L2_MBUS_CSI2_DPHY
888 ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk);
892 if (mclk != OV9734_MCLK) {
893 dev_err(dev, "external clock %d is not supported", mclk);
897 ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
901 ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
902 fwnode_handle_put(ep);
906 if (!bus_cfg.nr_of_link_frequencies) {
907 dev_err(dev, "no link frequencies defined");
909 goto check_hwcfg_error;
912 for (i = 0; i < ARRAY_SIZE(link_freq_menu_items); i++) {
913 for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
914 if (link_freq_menu_items[i] ==
915 bus_cfg.link_frequencies[j])
919 if (j == bus_cfg.nr_of_link_frequencies) {
920 dev_err(dev, "no link frequency %lld supported",
921 link_freq_menu_items[i]);
923 goto check_hwcfg_error;
928 v4l2_fwnode_endpoint_free(&bus_cfg);
933 static void ov9734_remove(struct i2c_client *client)
935 struct v4l2_subdev *sd = i2c_get_clientdata(client);
936 struct ov9734 *ov9734 = to_ov9734(sd);
938 v4l2_async_unregister_subdev(sd);
939 media_entity_cleanup(&sd->entity);
940 v4l2_ctrl_handler_free(sd->ctrl_handler);
941 pm_runtime_disable(&client->dev);
942 mutex_destroy(&ov9734->mutex);
945 static int ov9734_probe(struct i2c_client *client)
947 struct ov9734 *ov9734;
950 ret = ov9734_check_hwcfg(&client->dev);
952 dev_err(&client->dev, "failed to check HW configuration: %d",
957 ov9734 = devm_kzalloc(&client->dev, sizeof(*ov9734), GFP_KERNEL);
961 v4l2_i2c_subdev_init(&ov9734->sd, client, &ov9734_subdev_ops);
962 ret = ov9734_identify_module(ov9734);
964 dev_err(&client->dev, "failed to find sensor: %d", ret);
968 mutex_init(&ov9734->mutex);
969 ov9734->cur_mode = &supported_modes[0];
970 ret = ov9734_init_controls(ov9734);
972 dev_err(&client->dev, "failed to init controls: %d", ret);
973 goto probe_error_v4l2_ctrl_handler_free;
976 ov9734->sd.internal_ops = &ov9734_internal_ops;
977 ov9734->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
978 ov9734->sd.entity.ops = &ov9734_subdev_entity_ops;
979 ov9734->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
980 ov9734->pad.flags = MEDIA_PAD_FL_SOURCE;
981 ret = media_entity_pads_init(&ov9734->sd.entity, 1, &ov9734->pad);
983 dev_err(&client->dev, "failed to init entity pads: %d", ret);
984 goto probe_error_v4l2_ctrl_handler_free;
987 ret = v4l2_async_register_subdev_sensor(&ov9734->sd);
989 dev_err(&client->dev, "failed to register V4L2 subdev: %d",
991 goto probe_error_media_entity_cleanup;
995 * Device is already turned on by i2c-core with ACPI domain PM.
996 * Enable runtime PM and turn off the device.
998 pm_runtime_set_active(&client->dev);
999 pm_runtime_enable(&client->dev);
1000 pm_runtime_idle(&client->dev);
1004 probe_error_media_entity_cleanup:
1005 media_entity_cleanup(&ov9734->sd.entity);
1007 probe_error_v4l2_ctrl_handler_free:
1008 v4l2_ctrl_handler_free(ov9734->sd.ctrl_handler);
1009 mutex_destroy(&ov9734->mutex);
1014 static const struct dev_pm_ops ov9734_pm_ops = {
1015 SET_SYSTEM_SLEEP_PM_OPS(ov9734_suspend, ov9734_resume)
1018 static const struct acpi_device_id ov9734_acpi_ids[] = {
1023 MODULE_DEVICE_TABLE(acpi, ov9734_acpi_ids);
1025 static struct i2c_driver ov9734_i2c_driver = {
1028 .pm = &ov9734_pm_ops,
1029 .acpi_match_table = ov9734_acpi_ids,
1031 .probe_new = ov9734_probe,
1032 .remove = ov9734_remove,
1035 module_i2c_driver(ov9734_i2c_driver);
1039 MODULE_DESCRIPTION("OmniVision OV9734 sensor driver");
1040 MODULE_LICENSE("GPL v2");