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 OV8856_REG_VALUE_08BIT 1
15 #define OV8856_REG_VALUE_16BIT 2
16 #define OV8856_REG_VALUE_24BIT 3
18 #define OV8856_LINK_FREQ_360MHZ 360000000ULL
19 #define OV8856_LINK_FREQ_180MHZ 180000000ULL
20 #define OV8856_SCLK 144000000ULL
21 #define OV8856_MCLK 19200000
22 #define OV8856_DATA_LANES 4
23 #define OV8856_RGB_DEPTH 10
25 #define OV8856_REG_CHIP_ID 0x300a
26 #define OV8856_CHIP_ID 0x00885a
28 #define OV8856_REG_MODE_SELECT 0x0100
29 #define OV8856_MODE_STANDBY 0x00
30 #define OV8856_MODE_STREAMING 0x01
32 /* vertical-timings from sensor */
33 #define OV8856_REG_VTS 0x380e
34 #define OV8856_VTS_MAX 0x7fff
36 /* horizontal-timings from sensor */
37 #define OV8856_REG_HTS 0x380c
39 /* Exposure controls from sensor */
40 #define OV8856_REG_EXPOSURE 0x3500
41 #define OV8856_EXPOSURE_MIN 6
42 #define OV8856_EXPOSURE_MAX_MARGIN 6
43 #define OV8856_EXPOSURE_STEP 1
45 /* Analog gain controls from sensor */
46 #define OV8856_REG_ANALOG_GAIN 0x3508
47 #define OV8856_ANAL_GAIN_MIN 128
48 #define OV8856_ANAL_GAIN_MAX 2047
49 #define OV8856_ANAL_GAIN_STEP 1
51 /* Digital gain controls from sensor */
52 #define OV8856_REG_MWB_R_GAIN 0x5019
53 #define OV8856_REG_MWB_G_GAIN 0x501b
54 #define OV8856_REG_MWB_B_GAIN 0x501d
55 #define OV8856_DGTL_GAIN_MIN 0
56 #define OV8856_DGTL_GAIN_MAX 4095
57 #define OV8856_DGTL_GAIN_STEP 1
58 #define OV8856_DGTL_GAIN_DEFAULT 1024
60 /* Test Pattern Control */
61 #define OV8856_REG_TEST_PATTERN 0x5e00
62 #define OV8856_TEST_PATTERN_ENABLE BIT(7)
63 #define OV8856_TEST_PATTERN_BAR_SHIFT 2
65 #define to_ov8856(_sd) container_of(_sd, struct ov8856, sd)
68 OV8856_LINK_FREQ_720MBPS,
69 OV8856_LINK_FREQ_360MBPS,
77 struct ov8856_reg_list {
79 const struct ov8856_reg *regs;
82 struct ov8856_link_freq_config {
83 const struct ov8856_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 ov8856_reg_list reg_list;
109 static const struct ov8856_reg mipi_data_rate_720mbps[] = {
119 static const struct ov8856_reg mipi_data_rate_360mbps[] = {
129 static const struct ov8856_reg mode_3280x2464_regs[] = {
319 static const struct ov8856_reg mode_1640x1232_regs[] = {
509 static const char * const ov8856_test_pattern_menu[] = {
511 "Standard Color Bar",
512 "Top-Bottom Darker Color Bar",
513 "Right-Left Darker Color Bar",
514 "Bottom-Top Darker Color Bar"
517 static const s64 link_freq_menu_items[] = {
518 OV8856_LINK_FREQ_360MHZ,
519 OV8856_LINK_FREQ_180MHZ
522 static const struct ov8856_link_freq_config link_freq_configs[] = {
523 [OV8856_LINK_FREQ_720MBPS] = {
525 .num_of_regs = ARRAY_SIZE(mipi_data_rate_720mbps),
526 .regs = mipi_data_rate_720mbps,
529 [OV8856_LINK_FREQ_360MBPS] = {
531 .num_of_regs = ARRAY_SIZE(mipi_data_rate_360mbps),
532 .regs = mipi_data_rate_360mbps,
537 static const struct ov8856_mode supported_modes[] = {
545 .num_of_regs = ARRAY_SIZE(mode_3280x2464_regs),
546 .regs = mode_3280x2464_regs,
548 .link_freq_index = OV8856_LINK_FREQ_720MBPS,
557 .num_of_regs = ARRAY_SIZE(mode_1640x1232_regs),
558 .regs = mode_1640x1232_regs,
560 .link_freq_index = OV8856_LINK_FREQ_360MBPS,
565 struct v4l2_subdev sd;
566 struct media_pad pad;
567 struct v4l2_ctrl_handler ctrl_handler;
570 struct v4l2_ctrl *link_freq;
571 struct v4l2_ctrl *pixel_rate;
572 struct v4l2_ctrl *vblank;
573 struct v4l2_ctrl *hblank;
574 struct v4l2_ctrl *exposure;
577 const struct ov8856_mode *cur_mode;
579 /* To serialize asynchronus callbacks */
582 /* Streaming on/off */
586 static u64 to_pixel_rate(u32 f_index)
588 u64 pixel_rate = link_freq_menu_items[f_index] * 2 * OV8856_DATA_LANES;
590 do_div(pixel_rate, OV8856_RGB_DEPTH);
595 static u64 to_pixels_per_line(u32 hts, u32 f_index)
597 u64 ppl = hts * to_pixel_rate(f_index);
599 do_div(ppl, OV8856_SCLK);
604 static int ov8856_read_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 *val)
606 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
607 struct i2c_msg msgs[2];
609 u8 data_buf[4] = {0};
615 put_unaligned_be16(reg, addr_buf);
616 msgs[0].addr = client->addr;
618 msgs[0].len = sizeof(addr_buf);
619 msgs[0].buf = addr_buf;
620 msgs[1].addr = client->addr;
621 msgs[1].flags = I2C_M_RD;
623 msgs[1].buf = &data_buf[4 - len];
625 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
626 if (ret != ARRAY_SIZE(msgs))
629 *val = get_unaligned_be32(data_buf);
634 static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 val)
636 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
642 put_unaligned_be16(reg, buf);
643 put_unaligned_be32(val << 8 * (4 - len), buf + 2);
644 if (i2c_master_send(client, buf, len + 2) != len + 2)
650 static int ov8856_write_reg_list(struct ov8856 *ov8856,
651 const struct ov8856_reg_list *r_list)
653 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
657 for (i = 0; i < r_list->num_of_regs; i++) {
658 ret = ov8856_write_reg(ov8856, r_list->regs[i].address, 1,
659 r_list->regs[i].val);
661 dev_err_ratelimited(&client->dev,
662 "failed to write reg 0x%4.4x. error = %d",
663 r_list->regs[i].address, ret);
671 static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain)
675 ret = ov8856_write_reg(ov8856, OV8856_REG_MWB_R_GAIN,
676 OV8856_REG_VALUE_16BIT, d_gain);
680 ret = ov8856_write_reg(ov8856, OV8856_REG_MWB_G_GAIN,
681 OV8856_REG_VALUE_16BIT, d_gain);
685 return ov8856_write_reg(ov8856, OV8856_REG_MWB_B_GAIN,
686 OV8856_REG_VALUE_16BIT, d_gain);
689 static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern)
692 pattern = (pattern - 1) << OV8856_TEST_PATTERN_BAR_SHIFT |
693 OV8856_TEST_PATTERN_ENABLE;
695 return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN,
696 OV8856_REG_VALUE_08BIT, pattern);
699 static int ov8856_set_ctrl(struct v4l2_ctrl *ctrl)
701 struct ov8856 *ov8856 = container_of(ctrl->handler,
702 struct ov8856, ctrl_handler);
703 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
707 /* Propagate change of current control to all related controls */
708 if (ctrl->id == V4L2_CID_VBLANK) {
709 /* Update max exposure while meeting expected vblanking */
710 exposure_max = ov8856->cur_mode->height + ctrl->val -
711 OV8856_EXPOSURE_MAX_MARGIN;
712 __v4l2_ctrl_modify_range(ov8856->exposure,
713 ov8856->exposure->minimum,
714 exposure_max, ov8856->exposure->step,
718 /* V4L2 controls values will be applied only when power is already up */
719 if (!pm_runtime_get_if_in_use(&client->dev))
723 case V4L2_CID_ANALOGUE_GAIN:
724 ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN,
725 OV8856_REG_VALUE_16BIT, ctrl->val);
728 case V4L2_CID_DIGITAL_GAIN:
729 ret = ov8856_update_digital_gain(ov8856, ctrl->val);
732 case V4L2_CID_EXPOSURE:
733 /* 4 least significant bits of expsoure are fractional part */
734 ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE,
735 OV8856_REG_VALUE_24BIT, ctrl->val << 4);
738 case V4L2_CID_VBLANK:
739 ret = ov8856_write_reg(ov8856, OV8856_REG_VTS,
740 OV8856_REG_VALUE_16BIT,
741 ov8856->cur_mode->height + ctrl->val);
744 case V4L2_CID_TEST_PATTERN:
745 ret = ov8856_test_pattern(ov8856, ctrl->val);
753 pm_runtime_put(&client->dev);
758 static const struct v4l2_ctrl_ops ov8856_ctrl_ops = {
759 .s_ctrl = ov8856_set_ctrl,
762 static int ov8856_init_controls(struct ov8856 *ov8856)
764 struct v4l2_ctrl_handler *ctrl_hdlr;
765 s64 exposure_max, h_blank;
768 ctrl_hdlr = &ov8856->ctrl_handler;
769 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
773 ctrl_hdlr->lock = &ov8856->mutex;
774 ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops,
776 ARRAY_SIZE(link_freq_menu_items) - 1,
777 0, link_freq_menu_items);
778 if (ov8856->link_freq)
779 ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
781 ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
782 V4L2_CID_PIXEL_RATE, 0,
783 to_pixel_rate(OV8856_LINK_FREQ_720MBPS),
785 to_pixel_rate(OV8856_LINK_FREQ_720MBPS));
786 ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
788 ov8856->cur_mode->vts_min - ov8856->cur_mode->height,
789 OV8856_VTS_MAX - ov8856->cur_mode->height, 1,
790 ov8856->cur_mode->vts_def - ov8856->cur_mode->height);
791 h_blank = to_pixels_per_line(ov8856->cur_mode->hts,
792 ov8856->cur_mode->link_freq_index) - ov8856->cur_mode->width;
793 ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
794 V4L2_CID_HBLANK, h_blank, h_blank, 1,
797 ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
799 v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
800 OV8856_ANAL_GAIN_MIN, OV8856_ANAL_GAIN_MAX,
801 OV8856_ANAL_GAIN_STEP, OV8856_ANAL_GAIN_MIN);
802 v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
803 OV8856_DGTL_GAIN_MIN, OV8856_DGTL_GAIN_MAX,
804 OV8856_DGTL_GAIN_STEP, OV8856_DGTL_GAIN_DEFAULT);
805 exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN;
806 ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
808 OV8856_EXPOSURE_MIN, exposure_max,
809 OV8856_EXPOSURE_STEP,
811 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov8856_ctrl_ops,
812 V4L2_CID_TEST_PATTERN,
813 ARRAY_SIZE(ov8856_test_pattern_menu) - 1,
814 0, 0, ov8856_test_pattern_menu);
815 if (ctrl_hdlr->error)
816 return ctrl_hdlr->error;
818 ov8856->sd.ctrl_handler = ctrl_hdlr;
823 static void ov8856_update_pad_format(const struct ov8856_mode *mode,
824 struct v4l2_mbus_framefmt *fmt)
826 fmt->width = mode->width;
827 fmt->height = mode->height;
828 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
829 fmt->field = V4L2_FIELD_NONE;
832 static int ov8856_start_streaming(struct ov8856 *ov8856)
834 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
835 const struct ov8856_reg_list *reg_list;
836 int link_freq_index, ret;
838 link_freq_index = ov8856->cur_mode->link_freq_index;
839 reg_list = &link_freq_configs[link_freq_index].reg_list;
840 ret = ov8856_write_reg_list(ov8856, reg_list);
842 dev_err(&client->dev, "failed to set plls");
846 reg_list = &ov8856->cur_mode->reg_list;
847 ret = ov8856_write_reg_list(ov8856, reg_list);
849 dev_err(&client->dev, "failed to set mode");
853 ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler);
857 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
858 OV8856_REG_VALUE_08BIT, OV8856_MODE_STREAMING);
860 dev_err(&client->dev, "failed to set stream");
867 static void ov8856_stop_streaming(struct ov8856 *ov8856)
869 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
871 if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
872 OV8856_REG_VALUE_08BIT, OV8856_MODE_STANDBY))
873 dev_err(&client->dev, "failed to set stream");
876 static int ov8856_set_stream(struct v4l2_subdev *sd, int enable)
878 struct ov8856 *ov8856 = to_ov8856(sd);
879 struct i2c_client *client = v4l2_get_subdevdata(sd);
882 if (ov8856->streaming == enable)
885 mutex_lock(&ov8856->mutex);
887 ret = pm_runtime_get_sync(&client->dev);
889 pm_runtime_put_noidle(&client->dev);
890 mutex_unlock(&ov8856->mutex);
894 ret = ov8856_start_streaming(ov8856);
897 ov8856_stop_streaming(ov8856);
898 pm_runtime_put(&client->dev);
901 ov8856_stop_streaming(ov8856);
902 pm_runtime_put(&client->dev);
905 ov8856->streaming = enable;
906 mutex_unlock(&ov8856->mutex);
911 static int __maybe_unused ov8856_suspend(struct device *dev)
913 struct i2c_client *client = to_i2c_client(dev);
914 struct v4l2_subdev *sd = i2c_get_clientdata(client);
915 struct ov8856 *ov8856 = to_ov8856(sd);
917 mutex_lock(&ov8856->mutex);
918 if (ov8856->streaming)
919 ov8856_stop_streaming(ov8856);
921 mutex_unlock(&ov8856->mutex);
926 static int __maybe_unused ov8856_resume(struct device *dev)
928 struct i2c_client *client = to_i2c_client(dev);
929 struct v4l2_subdev *sd = i2c_get_clientdata(client);
930 struct ov8856 *ov8856 = to_ov8856(sd);
933 mutex_lock(&ov8856->mutex);
934 if (ov8856->streaming) {
935 ret = ov8856_start_streaming(ov8856);
937 ov8856->streaming = false;
938 ov8856_stop_streaming(ov8856);
939 mutex_unlock(&ov8856->mutex);
944 mutex_unlock(&ov8856->mutex);
949 static int ov8856_set_format(struct v4l2_subdev *sd,
950 struct v4l2_subdev_pad_config *cfg,
951 struct v4l2_subdev_format *fmt)
953 struct ov8856 *ov8856 = to_ov8856(sd);
954 const struct ov8856_mode *mode;
955 s32 vblank_def, h_blank;
957 mode = v4l2_find_nearest_size(supported_modes,
958 ARRAY_SIZE(supported_modes), width,
959 height, fmt->format.width,
962 mutex_lock(&ov8856->mutex);
963 ov8856_update_pad_format(mode, &fmt->format);
964 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
965 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
967 ov8856->cur_mode = mode;
968 __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index);
969 __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate,
970 to_pixel_rate(mode->link_freq_index));
972 /* Update limits and set FPS to default */
973 vblank_def = mode->vts_def - mode->height;
974 __v4l2_ctrl_modify_range(ov8856->vblank,
975 mode->vts_min - mode->height,
976 OV8856_VTS_MAX - mode->height, 1,
978 __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def);
979 h_blank = to_pixels_per_line(mode->hts, mode->link_freq_index) -
981 __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1,
985 mutex_unlock(&ov8856->mutex);
990 static int ov8856_get_format(struct v4l2_subdev *sd,
991 struct v4l2_subdev_pad_config *cfg,
992 struct v4l2_subdev_format *fmt)
994 struct ov8856 *ov8856 = to_ov8856(sd);
996 mutex_lock(&ov8856->mutex);
997 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
998 fmt->format = *v4l2_subdev_get_try_format(&ov8856->sd, cfg,
1001 ov8856_update_pad_format(ov8856->cur_mode, &fmt->format);
1003 mutex_unlock(&ov8856->mutex);
1008 static int ov8856_enum_mbus_code(struct v4l2_subdev *sd,
1009 struct v4l2_subdev_pad_config *cfg,
1010 struct v4l2_subdev_mbus_code_enum *code)
1012 /* Only one bayer order GRBG is supported */
1013 if (code->index > 0)
1016 code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
1021 static int ov8856_enum_frame_size(struct v4l2_subdev *sd,
1022 struct v4l2_subdev_pad_config *cfg,
1023 struct v4l2_subdev_frame_size_enum *fse)
1025 if (fse->index >= ARRAY_SIZE(supported_modes))
1028 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
1031 fse->min_width = supported_modes[fse->index].width;
1032 fse->max_width = fse->min_width;
1033 fse->min_height = supported_modes[fse->index].height;
1034 fse->max_height = fse->min_height;
1039 static int ov8856_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1041 struct ov8856 *ov8856 = to_ov8856(sd);
1043 mutex_lock(&ov8856->mutex);
1044 ov8856_update_pad_format(&supported_modes[0],
1045 v4l2_subdev_get_try_format(sd, fh->pad, 0));
1046 mutex_unlock(&ov8856->mutex);
1051 static const struct v4l2_subdev_video_ops ov8856_video_ops = {
1052 .s_stream = ov8856_set_stream,
1055 static const struct v4l2_subdev_pad_ops ov8856_pad_ops = {
1056 .set_fmt = ov8856_set_format,
1057 .get_fmt = ov8856_get_format,
1058 .enum_mbus_code = ov8856_enum_mbus_code,
1059 .enum_frame_size = ov8856_enum_frame_size,
1062 static const struct v4l2_subdev_ops ov8856_subdev_ops = {
1063 .video = &ov8856_video_ops,
1064 .pad = &ov8856_pad_ops,
1067 static const struct media_entity_operations ov8856_subdev_entity_ops = {
1068 .link_validate = v4l2_subdev_link_validate,
1071 static const struct v4l2_subdev_internal_ops ov8856_internal_ops = {
1072 .open = ov8856_open,
1075 static int ov8856_identify_module(struct ov8856 *ov8856)
1077 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1081 ret = ov8856_read_reg(ov8856, OV8856_REG_CHIP_ID,
1082 OV8856_REG_VALUE_24BIT, &val);
1086 if (val != OV8856_CHIP_ID) {
1087 dev_err(&client->dev, "chip id mismatch: %x!=%x",
1088 OV8856_CHIP_ID, val);
1095 static int ov8856_check_hwcfg(struct device *dev)
1097 struct fwnode_handle *ep;
1098 struct fwnode_handle *fwnode = dev_fwnode(dev);
1099 struct v4l2_fwnode_endpoint bus_cfg = {
1100 .bus_type = V4L2_MBUS_CSI2_DPHY
1109 fwnode_property_read_u32(fwnode, "clock-frequency", &mclk);
1110 if (mclk != OV8856_MCLK) {
1111 dev_err(dev, "external clock %d is not supported", mclk);
1115 ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
1119 ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
1120 fwnode_handle_put(ep);
1124 if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV8856_DATA_LANES) {
1125 dev_err(dev, "number of CSI2 data lanes %d is not supported",
1126 bus_cfg.bus.mipi_csi2.num_data_lanes);
1128 goto check_hwcfg_error;
1131 if (!bus_cfg.nr_of_link_frequencies) {
1132 dev_err(dev, "no link frequencies defined");
1134 goto check_hwcfg_error;
1137 for (i = 0; i < ARRAY_SIZE(link_freq_menu_items); i++) {
1138 for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
1139 if (link_freq_menu_items[i] ==
1140 bus_cfg.link_frequencies[j])
1144 if (j == bus_cfg.nr_of_link_frequencies) {
1145 dev_err(dev, "no link frequency %lld supported",
1146 link_freq_menu_items[i]);
1148 goto check_hwcfg_error;
1153 v4l2_fwnode_endpoint_free(&bus_cfg);
1158 static int ov8856_remove(struct i2c_client *client)
1160 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1161 struct ov8856 *ov8856 = to_ov8856(sd);
1163 v4l2_async_unregister_subdev(sd);
1164 media_entity_cleanup(&sd->entity);
1165 v4l2_ctrl_handler_free(sd->ctrl_handler);
1166 pm_runtime_disable(&client->dev);
1167 mutex_destroy(&ov8856->mutex);
1172 static int ov8856_probe(struct i2c_client *client)
1174 struct ov8856 *ov8856;
1177 ret = ov8856_check_hwcfg(&client->dev);
1179 dev_err(&client->dev, "failed to check HW configuration: %d",
1184 ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL);
1188 v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops);
1189 ret = ov8856_identify_module(ov8856);
1191 dev_err(&client->dev, "failed to find sensor: %d", ret);
1195 mutex_init(&ov8856->mutex);
1196 ov8856->cur_mode = &supported_modes[0];
1197 ret = ov8856_init_controls(ov8856);
1199 dev_err(&client->dev, "failed to init controls: %d", ret);
1200 goto probe_error_v4l2_ctrl_handler_free;
1203 ov8856->sd.internal_ops = &ov8856_internal_ops;
1204 ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1205 ov8856->sd.entity.ops = &ov8856_subdev_entity_ops;
1206 ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1207 ov8856->pad.flags = MEDIA_PAD_FL_SOURCE;
1208 ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad);
1210 dev_err(&client->dev, "failed to init entity pads: %d", ret);
1211 goto probe_error_v4l2_ctrl_handler_free;
1214 ret = v4l2_async_register_subdev_sensor_common(&ov8856->sd);
1216 dev_err(&client->dev, "failed to register V4L2 subdev: %d",
1218 goto probe_error_media_entity_cleanup;
1222 * Device is already turned on by i2c-core with ACPI domain PM.
1223 * Enable runtime PM and turn off the device.
1225 pm_runtime_set_active(&client->dev);
1226 pm_runtime_enable(&client->dev);
1227 pm_runtime_idle(&client->dev);
1231 probe_error_media_entity_cleanup:
1232 media_entity_cleanup(&ov8856->sd.entity);
1234 probe_error_v4l2_ctrl_handler_free:
1235 v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler);
1236 mutex_destroy(&ov8856->mutex);
1241 static const struct dev_pm_ops ov8856_pm_ops = {
1242 SET_SYSTEM_SLEEP_PM_OPS(ov8856_suspend, ov8856_resume)
1246 static const struct acpi_device_id ov8856_acpi_ids[] = {
1251 MODULE_DEVICE_TABLE(acpi, ov8856_acpi_ids);
1254 static struct i2c_driver ov8856_i2c_driver = {
1257 .pm = &ov8856_pm_ops,
1258 .acpi_match_table = ACPI_PTR(ov8856_acpi_ids),
1260 .probe_new = ov8856_probe,
1261 .remove = ov8856_remove,
1264 module_i2c_driver(ov8856_i2c_driver);
1267 MODULE_DESCRIPTION("OmniVision OV8856 sensor driver");
1268 MODULE_LICENSE("GPL v2");