1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2023 Intel Corporation.
6 #include <asm/unaligned.h>
8 #include <linux/acpi.h>
9 #include <linux/bitfield.h>
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/pm_runtime.h>
14 #include <media/v4l2-ctrls.h>
15 #include <media/v4l2-device.h>
16 #include <media/v4l2-event.h>
17 #include <media/v4l2-fwnode.h>
19 #define OV01A10_LINK_FREQ_400MHZ 400000000ULL
20 #define OV01A10_SCLK 40000000LL
21 #define OV01A10_DATA_LANES 1
23 #define OV01A10_REG_CHIP_ID 0x300a
24 #define OV01A10_CHIP_ID 0x560141
26 #define OV01A10_REG_MODE_SELECT 0x0100
27 #define OV01A10_MODE_STANDBY 0x00
28 #define OV01A10_MODE_STREAMING 0x01
31 #define OV01A10_PIXEL_ARRAY_WIDTH 1296
32 #define OV01A10_PIXEL_ARRAY_HEIGHT 816
33 #define OV01A10_ACITVE_WIDTH 1280
34 #define OV01A10_ACITVE_HEIGHT 800
36 /* vertical and horizontal timings */
37 #define OV01A10_REG_VTS 0x380e
38 #define OV01A10_VTS_DEF 0x0380
39 #define OV01A10_VTS_MIN 0x0380
40 #define OV01A10_VTS_MAX 0xffff
41 #define OV01A10_HTS_DEF 1488
43 /* exposure controls */
44 #define OV01A10_REG_EXPOSURE 0x3501
45 #define OV01A10_EXPOSURE_MIN 4
46 #define OV01A10_EXPOSURE_MAX_MARGIN 8
47 #define OV01A10_EXPOSURE_STEP 1
49 /* analog gain controls */
50 #define OV01A10_REG_ANALOG_GAIN 0x3508
51 #define OV01A10_ANAL_GAIN_MIN 0x100
52 #define OV01A10_ANAL_GAIN_MAX 0xffff
53 #define OV01A10_ANAL_GAIN_STEP 1
55 /* digital gain controls */
56 #define OV01A10_REG_DIGITAL_GAIN_B 0x350a
57 #define OV01A10_REG_DIGITAL_GAIN_GB 0x3510
58 #define OV01A10_REG_DIGITAL_GAIN_GR 0x3513
59 #define OV01A10_REG_DIGITAL_GAIN_R 0x3516
60 #define OV01A10_DGTL_GAIN_MIN 0
61 #define OV01A10_DGTL_GAIN_MAX 0x3ffff
62 #define OV01A10_DGTL_GAIN_STEP 1
63 #define OV01A10_DGTL_GAIN_DEFAULT 1024
65 /* test pattern control */
66 #define OV01A10_REG_TEST_PATTERN 0x4503
67 #define OV01A10_TEST_PATTERN_ENABLE BIT(7)
68 #define OV01A10_LINK_FREQ_400MHZ_INDEX 0
70 /* flip and mirror control */
71 #define OV01A10_REG_FORMAT1 0x3820
72 #define OV01A10_VFLIP_MASK BIT(4)
73 #define OV01A10_HFLIP_MASK BIT(3)
76 #define OV01A10_REG_X_WIN 0x3811
77 #define OV01A10_REG_Y_WIN 0x3813
84 struct ov01a10_reg_list {
86 const struct ov01a10_reg *regs;
89 struct ov01a10_link_freq_config {
90 const struct ov01a10_reg_list reg_list;
101 const struct ov01a10_reg_list reg_list;
104 static const struct ov01a10_reg mipi_data_rate_720mbps[] = {
120 static const struct ov01a10_reg sensor_1280x800_setting[] = {
241 static const char * const ov01a10_test_pattern_menu[] = {
244 "Top-Bottom Darker Color Bar",
245 "Right-Left Darker Color Bar",
249 static const s64 link_freq_menu_items[] = {
250 OV01A10_LINK_FREQ_400MHZ,
253 static const struct ov01a10_link_freq_config link_freq_configs[] = {
254 [OV01A10_LINK_FREQ_400MHZ_INDEX] = {
256 .num_of_regs = ARRAY_SIZE(mipi_data_rate_720mbps),
257 .regs = mipi_data_rate_720mbps,
262 static const struct ov01a10_mode supported_modes[] = {
264 .width = OV01A10_ACITVE_WIDTH,
265 .height = OV01A10_ACITVE_HEIGHT,
266 .hts = OV01A10_HTS_DEF,
267 .vts_def = OV01A10_VTS_DEF,
268 .vts_min = OV01A10_VTS_MIN,
270 .num_of_regs = ARRAY_SIZE(sensor_1280x800_setting),
271 .regs = sensor_1280x800_setting,
273 .link_freq_index = OV01A10_LINK_FREQ_400MHZ_INDEX,
278 struct v4l2_subdev sd;
279 struct media_pad pad;
280 struct v4l2_ctrl_handler ctrl_handler;
283 struct v4l2_ctrl *link_freq;
284 struct v4l2_ctrl *pixel_rate;
285 struct v4l2_ctrl *vblank;
286 struct v4l2_ctrl *hblank;
287 struct v4l2_ctrl *exposure;
289 const struct ov01a10_mode *cur_mode;
291 /* streaming state */
295 static inline struct ov01a10 *to_ov01a10(struct v4l2_subdev *subdev)
297 return container_of(subdev, struct ov01a10, sd);
300 static int ov01a10_read_reg(struct ov01a10 *ov01a10, u16 reg, u16 len, u32 *val)
302 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
303 struct i2c_msg msgs[2];
305 u8 data_buf[4] = {0};
308 if (len > sizeof(data_buf))
311 put_unaligned_be16(reg, addr_buf);
312 msgs[0].addr = client->addr;
314 msgs[0].len = sizeof(addr_buf);
315 msgs[0].buf = addr_buf;
316 msgs[1].addr = client->addr;
317 msgs[1].flags = I2C_M_RD;
319 msgs[1].buf = &data_buf[sizeof(data_buf) - len];
321 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
323 if (ret != ARRAY_SIZE(msgs))
324 return ret < 0 ? ret : -EIO;
326 *val = get_unaligned_be32(data_buf);
331 static int ov01a10_write_reg(struct ov01a10 *ov01a10, u16 reg, u16 len, u32 val)
333 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
340 put_unaligned_be16(reg, buf);
341 put_unaligned_be32(val << 8 * (4 - len), buf + 2);
343 ret = i2c_master_send(client, buf, len + 2);
345 return ret < 0 ? ret : -EIO;
350 static int ov01a10_write_reg_list(struct ov01a10 *ov01a10,
351 const struct ov01a10_reg_list *r_list)
353 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
357 for (i = 0; i < r_list->num_of_regs; i++) {
358 ret = ov01a10_write_reg(ov01a10, r_list->regs[i].address, 1,
359 r_list->regs[i].val);
361 dev_err_ratelimited(&client->dev,
362 "write reg 0x%4.4x err = %d\n",
363 r_list->regs[i].address, ret);
371 static int ov01a10_update_digital_gain(struct ov01a10 *ov01a10, u32 d_gain)
373 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
374 u32 real = d_gain << 6;
377 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_DIGITAL_GAIN_B, 3, real);
379 dev_err(&client->dev, "failed to set DIGITAL_GAIN_B\n");
383 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_DIGITAL_GAIN_GB, 3, real);
385 dev_err(&client->dev, "failed to set DIGITAL_GAIN_GB\n");
389 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_DIGITAL_GAIN_GR, 3, real);
391 dev_err(&client->dev, "failed to set DIGITAL_GAIN_GR\n");
395 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_DIGITAL_GAIN_R, 3, real);
397 dev_err(&client->dev, "failed to set DIGITAL_GAIN_R\n");
402 static int ov01a10_test_pattern(struct ov01a10 *ov01a10, u32 pattern)
407 pattern = (pattern - 1) | OV01A10_TEST_PATTERN_ENABLE;
409 return ov01a10_write_reg(ov01a10, OV01A10_REG_TEST_PATTERN, 1, pattern);
412 /* for vflip and hflip, use 0x9 as window offset to keep the bayer */
413 static int ov01a10_set_hflip(struct ov01a10 *ov01a10, u32 hflip)
418 offset = hflip ? 0x9 : 0x8;
419 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_X_WIN, 1, offset);
423 ret = ov01a10_read_reg(ov01a10, OV01A10_REG_FORMAT1, 1, &val);
427 val = hflip ? val | FIELD_PREP(OV01A10_HFLIP_MASK, 0x1) :
428 val & ~OV01A10_HFLIP_MASK;
430 return ov01a10_write_reg(ov01a10, OV01A10_REG_FORMAT1, 1, val);
433 static int ov01a10_set_vflip(struct ov01a10 *ov01a10, u32 vflip)
438 offset = vflip ? 0x9 : 0x8;
439 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_Y_WIN, 1, offset);
443 ret = ov01a10_read_reg(ov01a10, OV01A10_REG_FORMAT1, 1, &val);
447 val = vflip ? val | FIELD_PREP(OV01A10_VFLIP_MASK, 0x1) :
448 val & ~OV01A10_VFLIP_MASK;
450 return ov01a10_write_reg(ov01a10, OV01A10_REG_FORMAT1, 1, val);
453 static int ov01a10_set_ctrl(struct v4l2_ctrl *ctrl)
455 struct ov01a10 *ov01a10 = container_of(ctrl->handler,
456 struct ov01a10, ctrl_handler);
457 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
461 if (ctrl->id == V4L2_CID_VBLANK) {
462 exposure_max = ov01a10->cur_mode->height + ctrl->val -
463 OV01A10_EXPOSURE_MAX_MARGIN;
464 __v4l2_ctrl_modify_range(ov01a10->exposure,
465 ov01a10->exposure->minimum,
466 exposure_max, ov01a10->exposure->step,
470 if (!pm_runtime_get_if_in_use(&client->dev))
474 case V4L2_CID_ANALOGUE_GAIN:
475 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_ANALOG_GAIN, 2,
479 case V4L2_CID_DIGITAL_GAIN:
480 ret = ov01a10_update_digital_gain(ov01a10, ctrl->val);
483 case V4L2_CID_EXPOSURE:
484 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_EXPOSURE, 2,
488 case V4L2_CID_VBLANK:
489 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_VTS, 2,
490 ov01a10->cur_mode->height + ctrl->val);
493 case V4L2_CID_TEST_PATTERN:
494 ret = ov01a10_test_pattern(ov01a10, ctrl->val);
498 ov01a10_set_hflip(ov01a10, ctrl->val);
502 ov01a10_set_vflip(ov01a10, ctrl->val);
510 pm_runtime_put(&client->dev);
515 static const struct v4l2_ctrl_ops ov01a10_ctrl_ops = {
516 .s_ctrl = ov01a10_set_ctrl,
519 static int ov01a10_init_controls(struct ov01a10 *ov01a10)
521 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
522 struct v4l2_fwnode_device_properties props;
523 u32 vblank_min, vblank_max, vblank_default;
524 struct v4l2_ctrl_handler *ctrl_hdlr;
525 const struct ov01a10_mode *cur_mode;
526 s64 exposure_max, h_blank;
530 ret = v4l2_fwnode_device_parse(&client->dev, &props);
534 ctrl_hdlr = &ov01a10->ctrl_handler;
535 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12);
539 cur_mode = ov01a10->cur_mode;
540 size = ARRAY_SIZE(link_freq_menu_items);
542 ov01a10->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
546 link_freq_menu_items);
547 if (ov01a10->link_freq)
548 ov01a10->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
550 ov01a10->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops,
551 V4L2_CID_PIXEL_RATE, 0,
552 OV01A10_SCLK, 1, OV01A10_SCLK);
554 vblank_min = cur_mode->vts_min - cur_mode->height;
555 vblank_max = OV01A10_VTS_MAX - cur_mode->height;
556 vblank_default = cur_mode->vts_def - cur_mode->height;
557 ov01a10->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops,
558 V4L2_CID_VBLANK, vblank_min,
559 vblank_max, 1, vblank_default);
561 h_blank = cur_mode->hts - cur_mode->width;
562 ov01a10->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops,
563 V4L2_CID_HBLANK, h_blank, h_blank,
566 ov01a10->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
568 v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
569 OV01A10_ANAL_GAIN_MIN, OV01A10_ANAL_GAIN_MAX,
570 OV01A10_ANAL_GAIN_STEP, OV01A10_ANAL_GAIN_MIN);
571 v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
572 OV01A10_DGTL_GAIN_MIN, OV01A10_DGTL_GAIN_MAX,
573 OV01A10_DGTL_GAIN_STEP, OV01A10_DGTL_GAIN_DEFAULT);
575 exposure_max = cur_mode->vts_def - OV01A10_EXPOSURE_MAX_MARGIN;
576 ov01a10->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops,
578 OV01A10_EXPOSURE_MIN,
580 OV01A10_EXPOSURE_STEP,
583 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov01a10_ctrl_ops,
584 V4L2_CID_TEST_PATTERN,
585 ARRAY_SIZE(ov01a10_test_pattern_menu) - 1,
586 0, 0, ov01a10_test_pattern_menu);
588 v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops, V4L2_CID_HFLIP,
590 v4l2_ctrl_new_std(ctrl_hdlr, &ov01a10_ctrl_ops, V4L2_CID_VFLIP,
593 ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &ov01a10_ctrl_ops,
598 if (ctrl_hdlr->error) {
599 ret = ctrl_hdlr->error;
603 ov01a10->sd.ctrl_handler = ctrl_hdlr;
607 v4l2_ctrl_handler_free(ctrl_hdlr);
612 static void ov01a10_update_pad_format(const struct ov01a10_mode *mode,
613 struct v4l2_mbus_framefmt *fmt)
615 fmt->width = mode->width;
616 fmt->height = mode->height;
617 fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
618 fmt->field = V4L2_FIELD_NONE;
619 fmt->colorspace = V4L2_COLORSPACE_RAW;
622 static int ov01a10_start_streaming(struct ov01a10 *ov01a10)
624 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
625 const struct ov01a10_reg_list *reg_list;
629 link_freq_index = ov01a10->cur_mode->link_freq_index;
630 reg_list = &link_freq_configs[link_freq_index].reg_list;
631 ret = ov01a10_write_reg_list(ov01a10, reg_list);
633 dev_err(&client->dev, "failed to set plls\n");
637 reg_list = &ov01a10->cur_mode->reg_list;
638 ret = ov01a10_write_reg_list(ov01a10, reg_list);
640 dev_err(&client->dev, "failed to set mode\n");
644 ret = __v4l2_ctrl_handler_setup(ov01a10->sd.ctrl_handler);
648 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_MODE_SELECT, 1,
649 OV01A10_MODE_STREAMING);
651 dev_err(&client->dev, "failed to start streaming\n");
656 static void ov01a10_stop_streaming(struct ov01a10 *ov01a10)
658 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
661 ret = ov01a10_write_reg(ov01a10, OV01A10_REG_MODE_SELECT, 1,
662 OV01A10_MODE_STANDBY);
664 dev_err(&client->dev, "failed to stop streaming\n");
667 static int ov01a10_set_stream(struct v4l2_subdev *sd, int enable)
669 struct ov01a10 *ov01a10 = to_ov01a10(sd);
670 struct i2c_client *client = v4l2_get_subdevdata(sd);
671 struct v4l2_subdev_state *state;
674 state = v4l2_subdev_lock_and_get_active_state(sd);
675 if (ov01a10->streaming == enable)
679 ret = pm_runtime_resume_and_get(&client->dev);
683 ret = ov01a10_start_streaming(ov01a10);
685 pm_runtime_put(&client->dev);
692 ov01a10_stop_streaming(ov01a10);
693 pm_runtime_put(&client->dev);
695 ov01a10->streaming = enable;
697 v4l2_subdev_unlock_state(state);
702 static int __maybe_unused ov01a10_suspend(struct device *dev)
704 struct i2c_client *client = to_i2c_client(dev);
705 struct v4l2_subdev *sd = i2c_get_clientdata(client);
706 struct ov01a10 *ov01a10 = to_ov01a10(sd);
707 struct v4l2_subdev_state *state;
709 state = v4l2_subdev_lock_and_get_active_state(sd);
710 if (ov01a10->streaming)
711 ov01a10_stop_streaming(ov01a10);
713 v4l2_subdev_unlock_state(state);
718 static int __maybe_unused ov01a10_resume(struct device *dev)
720 struct i2c_client *client = to_i2c_client(dev);
721 struct v4l2_subdev *sd = i2c_get_clientdata(client);
722 struct ov01a10 *ov01a10 = to_ov01a10(sd);
723 struct v4l2_subdev_state *state;
726 state = v4l2_subdev_lock_and_get_active_state(sd);
727 if (!ov01a10->streaming)
730 ret = ov01a10_start_streaming(ov01a10);
732 ov01a10->streaming = false;
733 ov01a10_stop_streaming(ov01a10);
737 v4l2_subdev_unlock_state(state);
742 static int ov01a10_set_format(struct v4l2_subdev *sd,
743 struct v4l2_subdev_state *sd_state,
744 struct v4l2_subdev_format *fmt)
746 struct ov01a10 *ov01a10 = to_ov01a10(sd);
747 const struct ov01a10_mode *mode;
748 struct v4l2_mbus_framefmt *format;
749 s32 vblank_def, h_blank;
751 mode = v4l2_find_nearest_size(supported_modes,
752 ARRAY_SIZE(supported_modes), width,
753 height, fmt->format.width,
756 ov01a10_update_pad_format(mode, &fmt->format);
758 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
759 ov01a10->cur_mode = mode;
760 __v4l2_ctrl_s_ctrl(ov01a10->link_freq, mode->link_freq_index);
761 __v4l2_ctrl_s_ctrl_int64(ov01a10->pixel_rate, OV01A10_SCLK);
763 vblank_def = mode->vts_def - mode->height;
764 __v4l2_ctrl_modify_range(ov01a10->vblank,
765 mode->vts_min - mode->height,
766 OV01A10_VTS_MAX - mode->height, 1,
768 __v4l2_ctrl_s_ctrl(ov01a10->vblank, vblank_def);
769 h_blank = mode->hts - mode->width;
770 __v4l2_ctrl_modify_range(ov01a10->hblank, h_blank, h_blank, 1,
774 format = v4l2_subdev_get_pad_format(sd, sd_state, fmt->stream);
775 *format = fmt->format;
780 static int ov01a10_init_cfg(struct v4l2_subdev *sd,
781 struct v4l2_subdev_state *state)
783 struct v4l2_subdev_format fmt = {
784 .which = V4L2_SUBDEV_FORMAT_TRY,
786 .width = OV01A10_ACITVE_WIDTH,
787 .height = OV01A10_ACITVE_HEIGHT,
791 ov01a10_set_format(sd, state, &fmt);
796 static int ov01a10_enum_mbus_code(struct v4l2_subdev *sd,
797 struct v4l2_subdev_state *sd_state,
798 struct v4l2_subdev_mbus_code_enum *code)
803 code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
808 static int ov01a10_enum_frame_size(struct v4l2_subdev *sd,
809 struct v4l2_subdev_state *sd_state,
810 struct v4l2_subdev_frame_size_enum *fse)
812 if (fse->index >= ARRAY_SIZE(supported_modes) ||
813 fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
816 fse->min_width = supported_modes[fse->index].width;
817 fse->max_width = fse->min_width;
818 fse->min_height = supported_modes[fse->index].height;
819 fse->max_height = fse->min_height;
824 static int ov01a10_get_selection(struct v4l2_subdev *sd,
825 struct v4l2_subdev_state *state,
826 struct v4l2_subdev_selection *sel)
828 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
831 switch (sel->target) {
832 case V4L2_SEL_TGT_NATIVE_SIZE:
833 case V4L2_SEL_TGT_CROP_BOUNDS:
836 sel->r.width = OV01A10_PIXEL_ARRAY_WIDTH;
837 sel->r.height = OV01A10_PIXEL_ARRAY_HEIGHT;
839 case V4L2_SEL_TGT_CROP:
840 case V4L2_SEL_TGT_CROP_DEFAULT:
841 sel->r.top = (OV01A10_PIXEL_ARRAY_HEIGHT -
842 OV01A10_ACITVE_HEIGHT) / 2;
843 sel->r.left = (OV01A10_PIXEL_ARRAY_WIDTH -
844 OV01A10_ACITVE_WIDTH) / 2;
845 sel->r.width = OV01A10_ACITVE_WIDTH;
846 sel->r.height = OV01A10_ACITVE_HEIGHT;
853 static const struct v4l2_subdev_core_ops ov01a10_core_ops = {
854 .log_status = v4l2_ctrl_subdev_log_status,
855 .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
856 .unsubscribe_event = v4l2_event_subdev_unsubscribe,
859 static const struct v4l2_subdev_video_ops ov01a10_video_ops = {
860 .s_stream = ov01a10_set_stream,
863 static const struct v4l2_subdev_pad_ops ov01a10_pad_ops = {
864 .init_cfg = ov01a10_init_cfg,
865 .set_fmt = ov01a10_set_format,
866 .get_fmt = v4l2_subdev_get_fmt,
867 .get_selection = ov01a10_get_selection,
868 .enum_mbus_code = ov01a10_enum_mbus_code,
869 .enum_frame_size = ov01a10_enum_frame_size,
872 static const struct v4l2_subdev_ops ov01a10_subdev_ops = {
873 .core = &ov01a10_core_ops,
874 .video = &ov01a10_video_ops,
875 .pad = &ov01a10_pad_ops,
878 static const struct media_entity_operations ov01a10_subdev_entity_ops = {
879 .link_validate = v4l2_subdev_link_validate,
882 static int ov01a10_identify_module(struct ov01a10 *ov01a10)
884 struct i2c_client *client = v4l2_get_subdevdata(&ov01a10->sd);
888 ret = ov01a10_read_reg(ov01a10, OV01A10_REG_CHIP_ID, 3, &val);
892 if (val != OV01A10_CHIP_ID) {
893 dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
894 OV01A10_CHIP_ID, val);
901 static void ov01a10_remove(struct i2c_client *client)
903 struct v4l2_subdev *sd = i2c_get_clientdata(client);
905 v4l2_async_unregister_subdev(sd);
906 media_entity_cleanup(&sd->entity);
907 v4l2_ctrl_handler_free(sd->ctrl_handler);
909 pm_runtime_disable(&client->dev);
912 static int ov01a10_probe(struct i2c_client *client)
914 struct device *dev = &client->dev;
915 struct ov01a10 *ov01a10;
918 ov01a10 = devm_kzalloc(dev, sizeof(*ov01a10), GFP_KERNEL);
922 v4l2_i2c_subdev_init(&ov01a10->sd, client, &ov01a10_subdev_ops);
924 ret = ov01a10_identify_module(ov01a10);
926 return dev_err_probe(dev, ret,
927 "failed to find sensor\n");
929 ov01a10->cur_mode = &supported_modes[0];
931 ret = ov01a10_init_controls(ov01a10);
933 dev_err(dev, "failed to init controls: %d\n", ret);
937 ov01a10->sd.state_lock = ov01a10->ctrl_handler.lock;
938 ov01a10->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
939 V4L2_SUBDEV_FL_HAS_EVENTS;
940 ov01a10->sd.entity.ops = &ov01a10_subdev_entity_ops;
941 ov01a10->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
942 ov01a10->pad.flags = MEDIA_PAD_FL_SOURCE;
944 ret = media_entity_pads_init(&ov01a10->sd.entity, 1, &ov01a10->pad);
946 dev_err(dev, "Failed to init entity pads: %d\n", ret);
947 goto err_handler_free;
950 ret = v4l2_subdev_init_finalize(&ov01a10->sd);
952 dev_err(dev, "Failed to allocate subdev state: %d\n", ret);
953 goto err_media_entity_cleanup;
956 ret = v4l2_async_register_subdev_sensor(&ov01a10->sd);
958 dev_err(dev, "Failed to register subdev: %d\n", ret);
959 goto err_media_entity_cleanup;
962 pm_runtime_enable(dev);
963 pm_runtime_idle(dev);
967 err_media_entity_cleanup:
968 media_entity_cleanup(&ov01a10->sd.entity);
971 v4l2_ctrl_handler_free(ov01a10->sd.ctrl_handler);
976 static const struct dev_pm_ops ov01a10_pm_ops = {
977 SET_SYSTEM_SLEEP_PM_OPS(ov01a10_suspend, ov01a10_resume)
981 static const struct acpi_device_id ov01a10_acpi_ids[] = {
986 MODULE_DEVICE_TABLE(acpi, ov01a10_acpi_ids);
989 static struct i2c_driver ov01a10_i2c_driver = {
992 .pm = &ov01a10_pm_ops,
993 .acpi_match_table = ACPI_PTR(ov01a10_acpi_ids),
995 .probe = ov01a10_probe,
996 .remove = ov01a10_remove,
999 module_i2c_driver(ov01a10_i2c_driver);
1001 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
1002 MODULE_AUTHOR("Wang Yating <yating.wang@intel.com>");
1003 MODULE_DESCRIPTION("OmniVision OV01A10 sensor driver");
1004 MODULE_LICENSE("GPL");