1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 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 OV5675_REG_VALUE_08BIT 1
15 #define OV5675_REG_VALUE_16BIT 2
16 #define OV5675_REG_VALUE_24BIT 3
18 #define OV5675_LINK_FREQ_450MHZ 450000000ULL
19 #define OV5675_SCLK 90000000LL
20 #define OV5675_MCLK 19200000
21 #define OV5675_DATA_LANES 2
22 #define OV5675_RGB_DEPTH 10
24 #define OV5675_REG_CHIP_ID 0x300a
25 #define OV5675_CHIP_ID 0x5675
27 #define OV5675_REG_MODE_SELECT 0x0100
28 #define OV5675_MODE_STANDBY 0x00
29 #define OV5675_MODE_STREAMING 0x01
31 /* vertical-timings from sensor */
32 #define OV5675_REG_VTS 0x380e
33 #define OV5675_VTS_30FPS 0x07e4
34 #define OV5675_VTS_30FPS_MIN 0x07e4
35 #define OV5675_VTS_MAX 0x7fff
37 /* horizontal-timings from sensor */
38 #define OV5675_REG_HTS 0x380c
40 /* Exposure controls from sensor */
41 #define OV5675_REG_EXPOSURE 0x3500
42 #define OV5675_EXPOSURE_MIN 4
43 #define OV5675_EXPOSURE_MAX_MARGIN 4
44 #define OV5675_EXPOSURE_STEP 1
46 /* Analog gain controls from sensor */
47 #define OV5675_REG_ANALOG_GAIN 0x3508
48 #define OV5675_ANAL_GAIN_MIN 128
49 #define OV5675_ANAL_GAIN_MAX 2047
50 #define OV5675_ANAL_GAIN_STEP 1
52 /* Digital gain controls from sensor */
53 #define OV5675_REG_MWB_R_GAIN 0x5019
54 #define OV5675_REG_MWB_G_GAIN 0x501b
55 #define OV5675_REG_MWB_B_GAIN 0x501d
56 #define OV5675_DGTL_GAIN_MIN 0
57 #define OV5675_DGTL_GAIN_MAX 4095
58 #define OV5675_DGTL_GAIN_STEP 1
59 #define OV5675_DGTL_GAIN_DEFAULT 1024
61 /* Test Pattern Control */
62 #define OV5675_REG_TEST_PATTERN 0x4503
63 #define OV5675_TEST_PATTERN_ENABLE BIT(7)
64 #define OV5675_TEST_PATTERN_BAR_SHIFT 2
66 #define to_ov5675(_sd) container_of(_sd, struct ov5675, sd)
69 OV5675_LINK_FREQ_900MBPS,
77 struct ov5675_reg_list {
79 const struct ov5675_reg *regs;
82 struct ov5675_link_freq_config {
83 const struct ov5675_reg_list reg_list;
87 /* Frame width in pixels */
90 /* Frame height in pixels */
93 /* Horizontal timining size */
96 /* Default vertical timining size */
99 /* Min vertical timining size */
102 /* Link frequency needed for this resolution */
105 /* Sensor register settings for this resolution */
106 const struct ov5675_reg_list reg_list;
109 static const struct ov5675_reg mipi_data_rate_900mbps[] = {
118 static const struct ov5675_reg mode_2592x1944_regs[] = {
271 static const struct ov5675_reg mode_1296x972_regs[] = {
424 static const char * const ov5675_test_pattern_menu[] = {
426 "Standard Color Bar",
427 "Top-Bottom Darker Color Bar",
428 "Right-Left Darker Color Bar",
429 "Bottom-Top Darker Color Bar"
432 static const s64 link_freq_menu_items[] = {
433 OV5675_LINK_FREQ_450MHZ,
436 static const struct ov5675_link_freq_config link_freq_configs[] = {
437 [OV5675_LINK_FREQ_900MBPS] = {
439 .num_of_regs = ARRAY_SIZE(mipi_data_rate_900mbps),
440 .regs = mipi_data_rate_900mbps,
445 static const struct ov5675_mode supported_modes[] = {
450 .vts_def = OV5675_VTS_30FPS,
451 .vts_min = OV5675_VTS_30FPS_MIN,
453 .num_of_regs = ARRAY_SIZE(mode_2592x1944_regs),
454 .regs = mode_2592x1944_regs,
456 .link_freq_index = OV5675_LINK_FREQ_900MBPS,
462 .vts_def = OV5675_VTS_30FPS,
463 .vts_min = OV5675_VTS_30FPS_MIN,
465 .num_of_regs = ARRAY_SIZE(mode_1296x972_regs),
466 .regs = mode_1296x972_regs,
468 .link_freq_index = OV5675_LINK_FREQ_900MBPS,
473 struct v4l2_subdev sd;
474 struct media_pad pad;
475 struct v4l2_ctrl_handler ctrl_handler;
478 struct v4l2_ctrl *link_freq;
479 struct v4l2_ctrl *pixel_rate;
480 struct v4l2_ctrl *vblank;
481 struct v4l2_ctrl *hblank;
482 struct v4l2_ctrl *exposure;
485 const struct ov5675_mode *cur_mode;
487 /* To serialize asynchronus callbacks */
490 /* Streaming on/off */
494 static u64 to_pixel_rate(u32 f_index)
496 u64 pixel_rate = link_freq_menu_items[f_index] * 2 * OV5675_DATA_LANES;
498 do_div(pixel_rate, OV5675_RGB_DEPTH);
503 static u64 to_pixels_per_line(u32 hts, u32 f_index)
505 u64 ppl = hts * to_pixel_rate(f_index);
507 do_div(ppl, OV5675_SCLK);
512 static int ov5675_read_reg(struct ov5675 *ov5675, u16 reg, u16 len, u32 *val)
514 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
515 struct i2c_msg msgs[2];
517 u8 data_buf[4] = {0};
523 put_unaligned_be16(reg, addr_buf);
524 msgs[0].addr = client->addr;
526 msgs[0].len = sizeof(addr_buf);
527 msgs[0].buf = addr_buf;
528 msgs[1].addr = client->addr;
529 msgs[1].flags = I2C_M_RD;
531 msgs[1].buf = &data_buf[4 - len];
533 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
534 if (ret != ARRAY_SIZE(msgs))
537 *val = get_unaligned_be32(data_buf);
542 static int ov5675_write_reg(struct ov5675 *ov5675, u16 reg, u16 len, u32 val)
544 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
550 put_unaligned_be16(reg, buf);
551 put_unaligned_be32(val << 8 * (4 - len), buf + 2);
552 if (i2c_master_send(client, buf, len + 2) != len + 2)
558 static int ov5675_write_reg_list(struct ov5675 *ov5675,
559 const struct ov5675_reg_list *r_list)
561 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
565 for (i = 0; i < r_list->num_of_regs; i++) {
566 ret = ov5675_write_reg(ov5675, r_list->regs[i].address, 1,
567 r_list->regs[i].val);
569 dev_err_ratelimited(&client->dev,
570 "failed to write reg 0x%4.4x. error = %d",
571 r_list->regs[i].address, ret);
579 static int ov5675_update_digital_gain(struct ov5675 *ov5675, u32 d_gain)
583 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_R_GAIN,
584 OV5675_REG_VALUE_16BIT, d_gain);
588 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_G_GAIN,
589 OV5675_REG_VALUE_16BIT, d_gain);
593 return ov5675_write_reg(ov5675, OV5675_REG_MWB_B_GAIN,
594 OV5675_REG_VALUE_16BIT, d_gain);
597 static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern)
600 pattern = (pattern - 1) << OV5675_TEST_PATTERN_BAR_SHIFT |
601 OV5675_TEST_PATTERN_ENABLE;
603 return ov5675_write_reg(ov5675, OV5675_REG_TEST_PATTERN,
604 OV5675_REG_VALUE_08BIT, pattern);
607 static int ov5675_set_ctrl(struct v4l2_ctrl *ctrl)
609 struct ov5675 *ov5675 = container_of(ctrl->handler,
610 struct ov5675, ctrl_handler);
611 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
615 /* Propagate change of current control to all related controls */
616 if (ctrl->id == V4L2_CID_VBLANK) {
617 /* Update max exposure while meeting expected vblanking */
618 exposure_max = (ov5675->cur_mode->height + ctrl->val -
619 OV5675_EXPOSURE_MAX_MARGIN) / 2;
620 __v4l2_ctrl_modify_range(ov5675->exposure,
621 ov5675->exposure->minimum,
622 exposure_max, ov5675->exposure->step,
626 /* V4L2 controls values will be applied only when power is already up */
627 if (!pm_runtime_get_if_in_use(&client->dev))
631 case V4L2_CID_ANALOGUE_GAIN:
632 ret = ov5675_write_reg(ov5675, OV5675_REG_ANALOG_GAIN,
633 OV5675_REG_VALUE_16BIT, ctrl->val);
636 case V4L2_CID_DIGITAL_GAIN:
637 ret = ov5675_update_digital_gain(ov5675, ctrl->val);
640 case V4L2_CID_EXPOSURE:
641 /* 3 least significant bits of expsoure are fractional part */
642 ret = ov5675_write_reg(ov5675, OV5675_REG_EXPOSURE,
643 OV5675_REG_VALUE_24BIT, ctrl->val << 3);
646 case V4L2_CID_VBLANK:
647 ret = ov5675_write_reg(ov5675, OV5675_REG_VTS,
648 OV5675_REG_VALUE_16BIT,
649 ov5675->cur_mode->height + ctrl->val +
653 case V4L2_CID_TEST_PATTERN:
654 ret = ov5675_test_pattern(ov5675, ctrl->val);
662 pm_runtime_put(&client->dev);
667 static const struct v4l2_ctrl_ops ov5675_ctrl_ops = {
668 .s_ctrl = ov5675_set_ctrl,
671 static int ov5675_init_controls(struct ov5675 *ov5675)
673 struct v4l2_ctrl_handler *ctrl_hdlr;
674 s64 exposure_max, h_blank;
677 ctrl_hdlr = &ov5675->ctrl_handler;
678 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
682 ctrl_hdlr->lock = &ov5675->mutex;
683 ov5675->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov5675_ctrl_ops,
685 ARRAY_SIZE(link_freq_menu_items) - 1,
686 0, link_freq_menu_items);
687 if (ov5675->link_freq)
688 ov5675->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
690 ov5675->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
691 V4L2_CID_PIXEL_RATE, 0,
692 to_pixel_rate(OV5675_LINK_FREQ_900MBPS),
694 to_pixel_rate(OV5675_LINK_FREQ_900MBPS));
695 ov5675->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
697 ov5675->cur_mode->vts_min - ov5675->cur_mode->height,
698 OV5675_VTS_MAX - ov5675->cur_mode->height, 1,
699 ov5675->cur_mode->vts_def - ov5675->cur_mode->height);
700 h_blank = to_pixels_per_line(ov5675->cur_mode->hts,
701 ov5675->cur_mode->link_freq_index) - ov5675->cur_mode->width;
702 ov5675->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
703 V4L2_CID_HBLANK, h_blank, h_blank, 1,
706 ov5675->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
708 v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
709 OV5675_ANAL_GAIN_MIN, OV5675_ANAL_GAIN_MAX,
710 OV5675_ANAL_GAIN_STEP, OV5675_ANAL_GAIN_MIN);
711 v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
712 OV5675_DGTL_GAIN_MIN, OV5675_DGTL_GAIN_MAX,
713 OV5675_DGTL_GAIN_STEP, OV5675_DGTL_GAIN_DEFAULT);
714 exposure_max = (ov5675->cur_mode->vts_def -
715 OV5675_EXPOSURE_MAX_MARGIN) / 2;
716 ov5675->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
718 OV5675_EXPOSURE_MIN, exposure_max,
719 OV5675_EXPOSURE_STEP,
721 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov5675_ctrl_ops,
722 V4L2_CID_TEST_PATTERN,
723 ARRAY_SIZE(ov5675_test_pattern_menu) - 1,
724 0, 0, ov5675_test_pattern_menu);
725 if (ctrl_hdlr->error)
726 return ctrl_hdlr->error;
728 ov5675->sd.ctrl_handler = ctrl_hdlr;
733 static void ov5675_update_pad_format(const struct ov5675_mode *mode,
734 struct v4l2_mbus_framefmt *fmt)
736 fmt->width = mode->width;
737 fmt->height = mode->height;
738 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
739 fmt->field = V4L2_FIELD_NONE;
742 static int ov5675_start_streaming(struct ov5675 *ov5675)
744 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
745 const struct ov5675_reg_list *reg_list;
746 int link_freq_index, ret;
748 link_freq_index = ov5675->cur_mode->link_freq_index;
749 reg_list = &link_freq_configs[link_freq_index].reg_list;
750 ret = ov5675_write_reg_list(ov5675, reg_list);
752 dev_err(&client->dev, "failed to set plls");
756 reg_list = &ov5675->cur_mode->reg_list;
757 ret = ov5675_write_reg_list(ov5675, reg_list);
759 dev_err(&client->dev, "failed to set mode");
763 ret = __v4l2_ctrl_handler_setup(ov5675->sd.ctrl_handler);
767 ret = ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT,
768 OV5675_REG_VALUE_08BIT, OV5675_MODE_STREAMING);
770 dev_err(&client->dev, "failed to set stream");
777 static void ov5675_stop_streaming(struct ov5675 *ov5675)
779 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
781 if (ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT,
782 OV5675_REG_VALUE_08BIT, OV5675_MODE_STANDBY))
783 dev_err(&client->dev, "failed to set stream");
786 static int ov5675_set_stream(struct v4l2_subdev *sd, int enable)
788 struct ov5675 *ov5675 = to_ov5675(sd);
789 struct i2c_client *client = v4l2_get_subdevdata(sd);
792 if (ov5675->streaming == enable)
795 mutex_lock(&ov5675->mutex);
797 ret = pm_runtime_get_sync(&client->dev);
799 pm_runtime_put_noidle(&client->dev);
800 mutex_unlock(&ov5675->mutex);
804 ret = ov5675_start_streaming(ov5675);
807 ov5675_stop_streaming(ov5675);
808 pm_runtime_put(&client->dev);
811 ov5675_stop_streaming(ov5675);
812 pm_runtime_put(&client->dev);
815 ov5675->streaming = enable;
816 mutex_unlock(&ov5675->mutex);
821 static int __maybe_unused ov5675_suspend(struct device *dev)
823 struct i2c_client *client = to_i2c_client(dev);
824 struct v4l2_subdev *sd = i2c_get_clientdata(client);
825 struct ov5675 *ov5675 = to_ov5675(sd);
827 mutex_lock(&ov5675->mutex);
828 if (ov5675->streaming)
829 ov5675_stop_streaming(ov5675);
831 mutex_unlock(&ov5675->mutex);
836 static int __maybe_unused ov5675_resume(struct device *dev)
838 struct i2c_client *client = to_i2c_client(dev);
839 struct v4l2_subdev *sd = i2c_get_clientdata(client);
840 struct ov5675 *ov5675 = to_ov5675(sd);
843 mutex_lock(&ov5675->mutex);
844 if (ov5675->streaming) {
845 ret = ov5675_start_streaming(ov5675);
847 ov5675->streaming = false;
848 ov5675_stop_streaming(ov5675);
849 mutex_unlock(&ov5675->mutex);
854 mutex_unlock(&ov5675->mutex);
859 static int ov5675_set_format(struct v4l2_subdev *sd,
860 struct v4l2_subdev_pad_config *cfg,
861 struct v4l2_subdev_format *fmt)
863 struct ov5675 *ov5675 = to_ov5675(sd);
864 const struct ov5675_mode *mode;
865 s32 vblank_def, h_blank;
867 mode = v4l2_find_nearest_size(supported_modes,
868 ARRAY_SIZE(supported_modes), width,
869 height, fmt->format.width,
872 mutex_lock(&ov5675->mutex);
873 ov5675_update_pad_format(mode, &fmt->format);
874 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
875 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
877 ov5675->cur_mode = mode;
878 __v4l2_ctrl_s_ctrl(ov5675->link_freq, mode->link_freq_index);
879 __v4l2_ctrl_s_ctrl_int64(ov5675->pixel_rate,
880 to_pixel_rate(mode->link_freq_index));
882 /* Update limits and set FPS to default */
883 vblank_def = mode->vts_def - mode->height;
884 __v4l2_ctrl_modify_range(ov5675->vblank,
885 mode->vts_min - mode->height,
886 OV5675_VTS_MAX - mode->height, 1,
888 __v4l2_ctrl_s_ctrl(ov5675->vblank, vblank_def);
889 h_blank = to_pixels_per_line(mode->hts, mode->link_freq_index) -
891 __v4l2_ctrl_modify_range(ov5675->hblank, h_blank, h_blank, 1,
895 mutex_unlock(&ov5675->mutex);
900 static int ov5675_get_format(struct v4l2_subdev *sd,
901 struct v4l2_subdev_pad_config *cfg,
902 struct v4l2_subdev_format *fmt)
904 struct ov5675 *ov5675 = to_ov5675(sd);
906 mutex_lock(&ov5675->mutex);
907 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
908 fmt->format = *v4l2_subdev_get_try_format(&ov5675->sd, cfg,
911 ov5675_update_pad_format(ov5675->cur_mode, &fmt->format);
913 mutex_unlock(&ov5675->mutex);
918 static int ov5675_enum_mbus_code(struct v4l2_subdev *sd,
919 struct v4l2_subdev_pad_config *cfg,
920 struct v4l2_subdev_mbus_code_enum *code)
925 code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
930 static int ov5675_enum_frame_size(struct v4l2_subdev *sd,
931 struct v4l2_subdev_pad_config *cfg,
932 struct v4l2_subdev_frame_size_enum *fse)
934 if (fse->index >= ARRAY_SIZE(supported_modes))
937 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
940 fse->min_width = supported_modes[fse->index].width;
941 fse->max_width = fse->min_width;
942 fse->min_height = supported_modes[fse->index].height;
943 fse->max_height = fse->min_height;
948 static int ov5675_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
950 struct ov5675 *ov5675 = to_ov5675(sd);
952 mutex_lock(&ov5675->mutex);
953 ov5675_update_pad_format(&supported_modes[0],
954 v4l2_subdev_get_try_format(sd, fh->pad, 0));
955 mutex_unlock(&ov5675->mutex);
960 static const struct v4l2_subdev_video_ops ov5675_video_ops = {
961 .s_stream = ov5675_set_stream,
964 static const struct v4l2_subdev_pad_ops ov5675_pad_ops = {
965 .set_fmt = ov5675_set_format,
966 .get_fmt = ov5675_get_format,
967 .enum_mbus_code = ov5675_enum_mbus_code,
968 .enum_frame_size = ov5675_enum_frame_size,
971 static const struct v4l2_subdev_ops ov5675_subdev_ops = {
972 .video = &ov5675_video_ops,
973 .pad = &ov5675_pad_ops,
976 static const struct media_entity_operations ov5675_subdev_entity_ops = {
977 .link_validate = v4l2_subdev_link_validate,
980 static const struct v4l2_subdev_internal_ops ov5675_internal_ops = {
984 static int ov5675_identify_module(struct ov5675 *ov5675)
986 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
990 ret = ov5675_read_reg(ov5675, OV5675_REG_CHIP_ID,
991 OV5675_REG_VALUE_24BIT, &val);
995 if (val != OV5675_CHIP_ID) {
996 dev_err(&client->dev, "chip id mismatch: %x!=%x",
997 OV5675_CHIP_ID, val);
1004 static int ov5675_check_hwcfg(struct device *dev)
1006 struct fwnode_handle *ep;
1007 struct fwnode_handle *fwnode = dev_fwnode(dev);
1008 struct v4l2_fwnode_endpoint bus_cfg = {
1009 .bus_type = V4L2_MBUS_CSI2_DPHY
1018 ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk);
1021 dev_err(dev, "can't get clock frequency");
1025 if (mclk != OV5675_MCLK) {
1026 dev_err(dev, "external clock %d is not supported", mclk);
1030 ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
1034 ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
1035 fwnode_handle_put(ep);
1039 if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV5675_DATA_LANES) {
1040 dev_err(dev, "number of CSI2 data lanes %d is not supported",
1041 bus_cfg.bus.mipi_csi2.num_data_lanes);
1043 goto check_hwcfg_error;
1046 if (!bus_cfg.nr_of_link_frequencies) {
1047 dev_err(dev, "no link frequencies defined");
1049 goto check_hwcfg_error;
1052 for (i = 0; i < ARRAY_SIZE(link_freq_menu_items); i++) {
1053 for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
1054 if (link_freq_menu_items[i] ==
1055 bus_cfg.link_frequencies[j])
1059 if (j == bus_cfg.nr_of_link_frequencies) {
1060 dev_err(dev, "no link frequency %lld supported",
1061 link_freq_menu_items[i]);
1063 goto check_hwcfg_error;
1068 v4l2_fwnode_endpoint_free(&bus_cfg);
1073 static int ov5675_remove(struct i2c_client *client)
1075 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1076 struct ov5675 *ov5675 = to_ov5675(sd);
1078 v4l2_async_unregister_subdev(sd);
1079 media_entity_cleanup(&sd->entity);
1080 v4l2_ctrl_handler_free(sd->ctrl_handler);
1081 pm_runtime_disable(&client->dev);
1082 mutex_destroy(&ov5675->mutex);
1087 static int ov5675_probe(struct i2c_client *client)
1089 struct ov5675 *ov5675;
1092 ret = ov5675_check_hwcfg(&client->dev);
1094 dev_err(&client->dev, "failed to check HW configuration: %d",
1099 ov5675 = devm_kzalloc(&client->dev, sizeof(*ov5675), GFP_KERNEL);
1103 v4l2_i2c_subdev_init(&ov5675->sd, client, &ov5675_subdev_ops);
1104 ret = ov5675_identify_module(ov5675);
1106 dev_err(&client->dev, "failed to find sensor: %d", ret);
1110 mutex_init(&ov5675->mutex);
1111 ov5675->cur_mode = &supported_modes[0];
1112 ret = ov5675_init_controls(ov5675);
1114 dev_err(&client->dev, "failed to init controls: %d", ret);
1115 goto probe_error_v4l2_ctrl_handler_free;
1118 ov5675->sd.internal_ops = &ov5675_internal_ops;
1119 ov5675->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1120 ov5675->sd.entity.ops = &ov5675_subdev_entity_ops;
1121 ov5675->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1122 ov5675->pad.flags = MEDIA_PAD_FL_SOURCE;
1123 ret = media_entity_pads_init(&ov5675->sd.entity, 1, &ov5675->pad);
1125 dev_err(&client->dev, "failed to init entity pads: %d", ret);
1126 goto probe_error_v4l2_ctrl_handler_free;
1129 ret = v4l2_async_register_subdev_sensor_common(&ov5675->sd);
1131 dev_err(&client->dev, "failed to register V4L2 subdev: %d",
1133 goto probe_error_media_entity_cleanup;
1137 * Device is already turned on by i2c-core with ACPI domain PM.
1138 * Enable runtime PM and turn off the device.
1140 pm_runtime_set_active(&client->dev);
1141 pm_runtime_enable(&client->dev);
1142 pm_runtime_idle(&client->dev);
1146 probe_error_media_entity_cleanup:
1147 media_entity_cleanup(&ov5675->sd.entity);
1149 probe_error_v4l2_ctrl_handler_free:
1150 v4l2_ctrl_handler_free(ov5675->sd.ctrl_handler);
1151 mutex_destroy(&ov5675->mutex);
1156 static const struct dev_pm_ops ov5675_pm_ops = {
1157 SET_SYSTEM_SLEEP_PM_OPS(ov5675_suspend, ov5675_resume)
1161 static const struct acpi_device_id ov5675_acpi_ids[] = {
1166 MODULE_DEVICE_TABLE(acpi, ov5675_acpi_ids);
1169 static struct i2c_driver ov5675_i2c_driver = {
1172 .pm = &ov5675_pm_ops,
1173 .acpi_match_table = ACPI_PTR(ov5675_acpi_ids),
1175 .probe_new = ov5675_probe,
1176 .remove = ov5675_remove,
1179 module_i2c_driver(ov5675_i2c_driver);
1181 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
1182 MODULE_DESCRIPTION("OmniVision OV5675 sensor driver");
1183 MODULE_LICENSE("GPL v2");