1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2022 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 <linux/version.h>
11 #include <media/v4l2-ctrls.h>
12 #include <media/v4l2-device.h>
13 #include <media/v4l2-fwnode.h>
14 #include <linux/vsc.h>
16 #define OV02C10_LINK_FREQ_400MHZ 400000000ULL
17 #define OV02C10_SCLK 80000000LL
18 #define OV02C10_MCLK 19200000
19 #define OV02C10_DATA_LANES 1
20 #define OV02C10_RGB_DEPTH 10
22 #define OV02C10_REG_CHIP_ID 0x300a
23 #define OV02C10_CHIP_ID 0x560243
25 #define OV02C10_REG_MODE_SELECT 0x0100
26 #define OV02C10_MODE_STANDBY 0x00
27 #define OV02C10_MODE_STREAMING 0x01
29 /* vertical-timings from sensor */
30 #define OV02C10_REG_VTS 0x380e
31 #define OV02C10_VTS_DEF 0x048c
32 #define OV02C10_VTS_MIN 0x048c
33 #define OV02C10_VTS_MAX 0x7fff
35 /* Exposure controls from sensor */
36 #define OV02C10_REG_EXPOSURE 0x3501
37 #define OV02C10_EXPOSURE_MIN 4
38 #define OV02C10_EXPOSURE_MAX_MARGIN 8
39 #define OV02C10_EXPOSURE_STEP 1
41 /* Analog gain controls from sensor */
42 #define OV02C10_REG_ANALOG_GAIN 0x3508
43 #define OV02C10_ANAL_GAIN_MIN 0x10
44 #define OV02C10_ANAL_GAIN_MAX 0xf8
45 #define OV02C10_ANAL_GAIN_STEP 1
46 #define OV02C10_ANAL_GAIN_DEFAULT 0x80
48 /* Digital gain controls from sensor */
49 #define OV02C10_REG_DIGILAL_GAIN 0x350a
50 #define OV02C10_DGTL_GAIN_MIN 0x0400
51 #define OV02C10_DGTL_GAIN_MAX 0x3fff
52 #define OV02C10_DGTL_GAIN_STEP 1
53 #define OV02C10_DGTL_GAIN_DEFAULT 0x0400
55 /* Test Pattern Control */
56 #define OV02C10_REG_TEST_PATTERN 0x4503
57 #define OV02C10_TEST_PATTERN_ENABLE BIT(7)
58 #define OV02C10_TEST_PATTERN_BAR_SHIFT 0
61 OV02C10_LINK_FREQ_400MHZ_INDEX
,
69 struct ov02c10_reg_list
{
71 const struct ov02c10_reg
*regs
;
74 struct ov02c10_link_freq_config
{
75 const struct ov02c10_reg_list reg_list
;
79 /* Frame width in pixels */
82 /* Frame height in pixels */
85 /* Horizontal timining size */
88 /* Default vertical timining size */
91 /* Min vertical timining size */
94 /* Link frequency needed for this resolution */
97 /* Sensor register settings for this resolution */
98 const struct ov02c10_reg_list reg_list
;
101 static const struct ov02c10_reg mipi_data_rate_960mbps
[] = {
104 static const struct ov02c10_reg sensor_1932x1092_1lane_30fps_setting
[] = {
105 // 1932x1092_GRBG_MIPI_MCLK19.2MHz_30fps_1Lane
327 // key setting for MCLK=19.2MCLK 1932x1092 GRBG 1 lane 30fps
351 static const char * const ov02c10_test_pattern_menu
[] = {
354 "Top-Bottom Darker Color Bar",
355 "Right-Left Darker Color Bar",
359 static const s64 link_freq_menu_items
[] = {
360 OV02C10_LINK_FREQ_400MHZ
,
363 static const struct ov02c10_link_freq_config link_freq_configs
[] = {
364 [OV02C10_LINK_FREQ_400MHZ_INDEX
] = {
366 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_960mbps
),
367 .regs
= mipi_data_rate_960mbps
,
372 static const struct ov02c10_mode supported_modes
[] = {
377 .vts_def
= OV02C10_VTS_DEF
,
378 .vts_min
= OV02C10_VTS_MIN
,
380 .num_of_regs
= ARRAY_SIZE(sensor_1932x1092_1lane_30fps_setting
),
381 .regs
= sensor_1932x1092_1lane_30fps_setting
,
383 .link_freq_index
= OV02C10_LINK_FREQ_400MHZ_INDEX
,
388 struct v4l2_subdev sd
;
389 struct media_pad pad
;
390 struct v4l2_ctrl_handler ctrl_handler
;
393 struct v4l2_ctrl
*link_freq
;
394 struct v4l2_ctrl
*pixel_rate
;
395 struct v4l2_ctrl
*vblank
;
396 struct v4l2_ctrl
*hblank
;
397 struct v4l2_ctrl
*exposure
;
398 struct v4l2_ctrl
*privacy_status
;
400 const struct ov02c10_mode
*cur_mode
;
402 /* To serialize asynchronus callbacks */
405 /* Streaming on/off */
409 static inline struct ov02c10
*to_ov02c10(struct v4l2_subdev
*subdev
)
411 return container_of(subdev
, struct ov02c10
, sd
);
414 static int ov02c10_read_reg(struct ov02c10
*ov02c10
, u16 reg
, u16 len
, u32
*val
)
416 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
417 struct i2c_msg msgs
[2];
419 u8 data_buf
[4] = {0};
422 if (len
> sizeof(data_buf
))
425 put_unaligned_be16(reg
, addr_buf
);
426 msgs
[0].addr
= client
->addr
;
428 msgs
[0].len
= sizeof(addr_buf
);
429 msgs
[0].buf
= addr_buf
;
430 msgs
[1].addr
= client
->addr
;
431 msgs
[1].flags
= I2C_M_RD
;
433 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
435 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
437 if (ret
!= ARRAY_SIZE(msgs
))
438 return ret
< 0 ? ret
: -EIO
;
440 *val
= get_unaligned_be32(data_buf
);
445 static int ov02c10_write_reg(struct ov02c10
*ov02c10
, u16 reg
, u16 len
, u32 val
)
447 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
454 put_unaligned_be16(reg
, buf
);
455 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
457 ret
= i2c_master_send(client
, buf
, len
+ 2);
459 return ret
< 0 ? ret
: -EIO
;
464 static int ov02c10_write_reg_list(struct ov02c10
*ov02c10
,
465 const struct ov02c10_reg_list
*r_list
)
467 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
471 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
472 ret
= ov02c10_write_reg(ov02c10
, r_list
->regs
[i
].address
, 1,
473 r_list
->regs
[i
].val
);
475 dev_err_ratelimited(&client
->dev
,
476 "write reg 0x%4.4x return err = %d",
477 r_list
->regs
[i
].address
, ret
);
485 static int ov02c10_test_pattern(struct ov02c10
*ov02c10
, u32 pattern
)
488 pattern
= (pattern
- 1) << OV02C10_TEST_PATTERN_BAR_SHIFT
|
489 OV02C10_TEST_PATTERN_ENABLE
;
491 return ov02c10_write_reg(ov02c10
, OV02C10_REG_TEST_PATTERN
, 1, pattern
);
494 static int ov02c10_set_ctrl(struct v4l2_ctrl
*ctrl
)
496 struct ov02c10
*ov02c10
= container_of(ctrl
->handler
,
497 struct ov02c10
, ctrl_handler
);
498 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
502 /* Propagate change of current control to all related controls */
503 if (ctrl
->id
== V4L2_CID_VBLANK
) {
504 /* Update max exposure while meeting expected vblanking */
505 exposure_max
= ov02c10
->cur_mode
->height
+ ctrl
->val
-
506 OV02C10_EXPOSURE_MAX_MARGIN
;
507 __v4l2_ctrl_modify_range(ov02c10
->exposure
,
508 ov02c10
->exposure
->minimum
,
509 exposure_max
, ov02c10
->exposure
->step
,
513 /* V4L2 controls values will be applied only when power is already up */
514 if (!pm_runtime_get_if_in_use(&client
->dev
))
518 case V4L2_CID_ANALOGUE_GAIN
:
519 ret
= ov02c10_write_reg(ov02c10
, OV02C10_REG_ANALOG_GAIN
, 2,
523 case V4L2_CID_DIGITAL_GAIN
:
524 ret
= ov02c10_write_reg(ov02c10
, OV02C10_REG_DIGILAL_GAIN
, 3,
528 case V4L2_CID_EXPOSURE
:
529 ret
= ov02c10_write_reg(ov02c10
, OV02C10_REG_EXPOSURE
, 2,
533 case V4L2_CID_VBLANK
:
534 ret
= ov02c10_write_reg(ov02c10
, OV02C10_REG_VTS
, 2,
535 ov02c10
->cur_mode
->height
+ ctrl
->val
);
538 case V4L2_CID_TEST_PATTERN
:
539 ret
= ov02c10_test_pattern(ov02c10
, ctrl
->val
);
542 case V4L2_CID_PRIVACY
:
543 dev_dbg(&client
->dev
, "set privacy to %d", ctrl
->val
);
551 pm_runtime_put(&client
->dev
);
556 static const struct v4l2_ctrl_ops ov02c10_ctrl_ops
= {
557 .s_ctrl
= ov02c10_set_ctrl
,
560 static int ov02c10_init_controls(struct ov02c10
*ov02c10
)
562 struct v4l2_ctrl_handler
*ctrl_hdlr
;
563 const struct ov02c10_mode
*cur_mode
;
564 s64 exposure_max
, h_blank
;
565 u32 vblank_min
, vblank_max
, vblank_default
;
569 ctrl_hdlr
= &ov02c10
->ctrl_handler
;
570 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 9);
574 ctrl_hdlr
->lock
= &ov02c10
->mutex
;
575 cur_mode
= ov02c10
->cur_mode
;
576 size
= ARRAY_SIZE(link_freq_menu_items
);
578 ov02c10
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
,
582 link_freq_menu_items
);
583 if (ov02c10
->link_freq
)
584 ov02c10
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
586 ov02c10
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
,
587 V4L2_CID_PIXEL_RATE
, 0,
588 OV02C10_SCLK
, 1, OV02C10_SCLK
);
590 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
591 vblank_max
= OV02C10_VTS_MAX
- cur_mode
->height
;
592 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
593 ov02c10
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
,
594 V4L2_CID_VBLANK
, vblank_min
,
595 vblank_max
, 1, vblank_default
);
597 h_blank
= cur_mode
->hts
- cur_mode
->width
;
598 ov02c10
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
,
599 V4L2_CID_HBLANK
, h_blank
, h_blank
,
602 ov02c10
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
603 ov02c10
->privacy_status
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
,
604 V4L2_CID_PRIVACY
, 0, 1, 1, 0);
606 v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
607 OV02C10_ANAL_GAIN_MIN
, OV02C10_ANAL_GAIN_MAX
,
608 OV02C10_ANAL_GAIN_STEP
, OV02C10_ANAL_GAIN_DEFAULT
);
609 v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
610 OV02C10_DGTL_GAIN_MIN
, OV02C10_DGTL_GAIN_MAX
,
611 OV02C10_DGTL_GAIN_STEP
, OV02C10_DGTL_GAIN_DEFAULT
);
612 exposure_max
= cur_mode
->vts_def
- OV02C10_EXPOSURE_MAX_MARGIN
;
613 ov02c10
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov02c10_ctrl_ops
,
615 OV02C10_EXPOSURE_MIN
,
617 OV02C10_EXPOSURE_STEP
,
619 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &ov02c10_ctrl_ops
,
620 V4L2_CID_TEST_PATTERN
,
621 ARRAY_SIZE(ov02c10_test_pattern_menu
) - 1,
622 0, 0, ov02c10_test_pattern_menu
);
623 if (ctrl_hdlr
->error
)
624 return ctrl_hdlr
->error
;
626 ov02c10
->sd
.ctrl_handler
= ctrl_hdlr
;
631 static void ov02c10_update_pad_format(const struct ov02c10_mode
*mode
,
632 struct v4l2_mbus_framefmt
*fmt
)
634 fmt
->width
= mode
->width
;
635 fmt
->height
= mode
->height
;
636 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
637 fmt
->field
= V4L2_FIELD_NONE
;
640 static void ov02c10_vsc_privacy_callback(void *handle
,
641 enum vsc_privacy_status status
)
643 struct ov02c10
*ov02c10
= handle
;
645 v4l2_ctrl_s_ctrl(ov02c10
->privacy_status
, !status
);
648 static int ov02c10_start_streaming(struct ov02c10
*ov02c10
)
650 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
651 const struct ov02c10_reg_list
*reg_list
;
654 struct vsc_mipi_config conf
;
655 struct vsc_camera_status status
;
657 conf
.lane_num
= OV02C10_DATA_LANES
;
658 /* frequency unit 100k */
659 conf
.freq
= OV02C10_LINK_FREQ_400MHZ
/ 100000;
660 ret
= vsc_acquire_camera_sensor(&conf
, ov02c10_vsc_privacy_callback
,
663 dev_err(&client
->dev
, "Acquire VSC failed");
666 __v4l2_ctrl_s_ctrl(ov02c10
->privacy_status
, !(status
.status
));
667 link_freq_index
= ov02c10
->cur_mode
->link_freq_index
;
668 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
669 ret
= ov02c10_write_reg_list(ov02c10
, reg_list
);
671 dev_err(&client
->dev
, "failed to set plls");
675 reg_list
= &ov02c10
->cur_mode
->reg_list
;
676 ret
= ov02c10_write_reg_list(ov02c10
, reg_list
);
678 dev_err(&client
->dev
, "failed to set mode");
682 ret
= __v4l2_ctrl_handler_setup(ov02c10
->sd
.ctrl_handler
);
686 ret
= ov02c10_write_reg(ov02c10
, OV02C10_REG_MODE_SELECT
, 1,
687 OV02C10_MODE_STREAMING
);
689 dev_err(&client
->dev
, "failed to start streaming");
694 static void ov02c10_stop_streaming(struct ov02c10
*ov02c10
)
696 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
698 struct vsc_camera_status status
;
700 ret
= ov02c10_write_reg(ov02c10
, OV02C10_REG_MODE_SELECT
, 1,
701 OV02C10_MODE_STANDBY
);
703 dev_err(&client
->dev
, "failed to stop streaming");
704 ret
= vsc_release_camera_sensor(&status
);
706 dev_err(&client
->dev
, "Release VSC failed");
709 static int ov02c10_set_stream(struct v4l2_subdev
*sd
, int enable
)
711 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
712 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
715 if (ov02c10
->streaming
== enable
)
718 mutex_lock(&ov02c10
->mutex
);
720 ret
= pm_runtime_get_sync(&client
->dev
);
722 pm_runtime_put_noidle(&client
->dev
);
723 mutex_unlock(&ov02c10
->mutex
);
727 ret
= ov02c10_start_streaming(ov02c10
);
730 ov02c10_stop_streaming(ov02c10
);
731 pm_runtime_put(&client
->dev
);
734 ov02c10_stop_streaming(ov02c10
);
735 pm_runtime_put(&client
->dev
);
738 ov02c10
->streaming
= enable
;
739 mutex_unlock(&ov02c10
->mutex
);
744 static int __maybe_unused
ov02c10_suspend(struct device
*dev
)
746 struct i2c_client
*client
= to_i2c_client(dev
);
747 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
748 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
750 mutex_lock(&ov02c10
->mutex
);
751 if (ov02c10
->streaming
)
752 ov02c10_stop_streaming(ov02c10
);
754 mutex_unlock(&ov02c10
->mutex
);
759 static int __maybe_unused
ov02c10_resume(struct device
*dev
)
761 struct i2c_client
*client
= to_i2c_client(dev
);
762 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
763 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
766 mutex_lock(&ov02c10
->mutex
);
767 if (!ov02c10
->streaming
)
770 ret
= ov02c10_start_streaming(ov02c10
);
772 ov02c10
->streaming
= false;
773 ov02c10_stop_streaming(ov02c10
);
777 mutex_unlock(&ov02c10
->mutex
);
781 static int ov02c10_set_format(struct v4l2_subdev
*sd
,
782 struct v4l2_subdev_state
*sd_state
,
783 struct v4l2_subdev_format
*fmt
)
785 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
786 const struct ov02c10_mode
*mode
;
787 s32 vblank_def
, h_blank
;
789 mode
= v4l2_find_nearest_size(supported_modes
,
790 ARRAY_SIZE(supported_modes
), width
,
791 height
, fmt
->format
.width
,
794 mutex_lock(&ov02c10
->mutex
);
795 ov02c10_update_pad_format(mode
, &fmt
->format
);
796 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
797 *v4l2_subdev_get_try_format(sd
, sd_state
, fmt
->pad
) = fmt
->format
;
799 ov02c10
->cur_mode
= mode
;
800 __v4l2_ctrl_s_ctrl(ov02c10
->link_freq
, mode
->link_freq_index
);
801 __v4l2_ctrl_s_ctrl_int64(ov02c10
->pixel_rate
, OV02C10_SCLK
);
803 /* Update limits and set FPS to default */
804 vblank_def
= mode
->vts_def
- mode
->height
;
805 __v4l2_ctrl_modify_range(ov02c10
->vblank
,
806 mode
->vts_min
- mode
->height
,
807 OV02C10_VTS_MAX
- mode
->height
, 1,
809 __v4l2_ctrl_s_ctrl(ov02c10
->vblank
, vblank_def
);
810 h_blank
= mode
->hts
- mode
->width
;
811 __v4l2_ctrl_modify_range(ov02c10
->hblank
, h_blank
, h_blank
, 1,
814 mutex_unlock(&ov02c10
->mutex
);
819 static int ov02c10_get_format(struct v4l2_subdev
*sd
,
820 struct v4l2_subdev_state
*sd_state
,
821 struct v4l2_subdev_format
*fmt
)
823 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
825 mutex_lock(&ov02c10
->mutex
);
826 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
827 fmt
->format
= *v4l2_subdev_get_try_format(&ov02c10
->sd
,
830 ov02c10_update_pad_format(ov02c10
->cur_mode
, &fmt
->format
);
832 mutex_unlock(&ov02c10
->mutex
);
837 static int ov02c10_enum_mbus_code(struct v4l2_subdev
*sd
,
838 struct v4l2_subdev_state
*sd_state
,
839 struct v4l2_subdev_mbus_code_enum
*code
)
844 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
849 static int ov02c10_enum_frame_size(struct v4l2_subdev
*sd
,
850 struct v4l2_subdev_state
*sd_state
,
851 struct v4l2_subdev_frame_size_enum
*fse
)
853 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
856 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
859 fse
->min_width
= supported_modes
[fse
->index
].width
;
860 fse
->max_width
= fse
->min_width
;
861 fse
->min_height
= supported_modes
[fse
->index
].height
;
862 fse
->max_height
= fse
->min_height
;
867 static int ov02c10_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
869 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
871 mutex_lock(&ov02c10
->mutex
);
872 ov02c10_update_pad_format(&supported_modes
[0],
873 v4l2_subdev_get_try_format(sd
, fh
->state
, 0));
874 mutex_unlock(&ov02c10
->mutex
);
879 static const struct v4l2_subdev_video_ops ov02c10_video_ops
= {
880 .s_stream
= ov02c10_set_stream
,
883 static const struct v4l2_subdev_pad_ops ov02c10_pad_ops
= {
884 .set_fmt
= ov02c10_set_format
,
885 .get_fmt
= ov02c10_get_format
,
886 .enum_mbus_code
= ov02c10_enum_mbus_code
,
887 .enum_frame_size
= ov02c10_enum_frame_size
,
890 static const struct v4l2_subdev_ops ov02c10_subdev_ops
= {
891 .video
= &ov02c10_video_ops
,
892 .pad
= &ov02c10_pad_ops
,
895 static const struct media_entity_operations ov02c10_subdev_entity_ops
= {
896 .link_validate
= v4l2_subdev_link_validate
,
899 static const struct v4l2_subdev_internal_ops ov02c10_internal_ops
= {
900 .open
= ov02c10_open
,
903 static int ov02c10_identify_module(struct ov02c10
*ov02c10
)
905 struct i2c_client
*client
= v4l2_get_subdevdata(&ov02c10
->sd
);
909 ret
= ov02c10_read_reg(ov02c10
, OV02C10_REG_CHIP_ID
, 3, &val
);
913 if (val
!= OV02C10_CHIP_ID
) {
914 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
915 OV02C10_CHIP_ID
, val
);
922 static int ov02c10_remove(struct i2c_client
*client
)
924 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
925 struct ov02c10
*ov02c10
= to_ov02c10(sd
);
927 v4l2_async_unregister_subdev(sd
);
928 media_entity_cleanup(&sd
->entity
);
929 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
930 pm_runtime_disable(&client
->dev
);
931 mutex_destroy(&ov02c10
->mutex
);
936 static int ov02c10_probe(struct i2c_client
*client
)
938 struct ov02c10
*ov02c10
;
940 struct vsc_mipi_config conf
;
941 struct vsc_camera_status status
;
943 conf
.lane_num
= OV02C10_DATA_LANES
;
944 /* frequency unit 100k */
945 conf
.freq
= OV02C10_LINK_FREQ_400MHZ
/ 100000;
946 ret
= vsc_acquire_camera_sensor(&conf
, NULL
, NULL
, &status
);
947 if (ret
== -EAGAIN
) {
948 dev_dbg(&client
->dev
, "VSC not ready, will re-probe");
949 return -EPROBE_DEFER
;
951 dev_err(&client
->dev
, "Acquire VSC failed");
954 ov02c10
= devm_kzalloc(&client
->dev
, sizeof(*ov02c10
), GFP_KERNEL
);
957 goto probe_error_ret
;
960 v4l2_i2c_subdev_init(&ov02c10
->sd
, client
, &ov02c10_subdev_ops
);
962 ret
= ov02c10_identify_module(ov02c10
);
964 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
965 goto probe_error_ret
;
968 mutex_init(&ov02c10
->mutex
);
969 ov02c10
->cur_mode
= &supported_modes
[0];
970 ret
= ov02c10_init_controls(ov02c10
);
972 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
973 goto probe_error_v4l2_ctrl_handler_free
;
976 ov02c10
->sd
.internal_ops
= &ov02c10_internal_ops
;
977 ov02c10
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
978 ov02c10
->sd
.entity
.ops
= &ov02c10_subdev_entity_ops
;
979 ov02c10
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
980 ov02c10
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
981 ret
= media_entity_pads_init(&ov02c10
->sd
.entity
, 1, &ov02c10
->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(&ov02c10
->sd
);
989 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
991 goto probe_error_media_entity_cleanup
;
994 vsc_release_camera_sensor(&status
);
996 * Device is already turned on by i2c-core with ACPI domain PM.
997 * Enable runtime PM and turn off the device.
999 pm_runtime_set_active(&client
->dev
);
1000 pm_runtime_enable(&client
->dev
);
1001 pm_runtime_idle(&client
->dev
);
1005 probe_error_media_entity_cleanup
:
1006 media_entity_cleanup(&ov02c10
->sd
.entity
);
1008 probe_error_v4l2_ctrl_handler_free
:
1009 v4l2_ctrl_handler_free(ov02c10
->sd
.ctrl_handler
);
1010 mutex_destroy(&ov02c10
->mutex
);
1013 vsc_release_camera_sensor(&status
);
1017 static const struct dev_pm_ops ov02c10_pm_ops
= {
1018 SET_SYSTEM_SLEEP_PM_OPS(ov02c10_suspend
, ov02c10_resume
)
1022 static const struct acpi_device_id ov02c10_acpi_ids
[] = {
1027 MODULE_DEVICE_TABLE(acpi
, ov02c10_acpi_ids
);
1030 static struct i2c_driver ov02c10_i2c_driver
= {
1033 .pm
= &ov02c10_pm_ops
,
1034 .acpi_match_table
= ACPI_PTR(ov02c10_acpi_ids
),
1036 .probe_new
= ov02c10_probe
,
1037 .remove
= ov02c10_remove
,
1040 module_i2c_driver(ov02c10_i2c_driver
);
1042 MODULE_AUTHOR("Hao Yao <hao.yao@intel.com>");
1043 MODULE_DESCRIPTION("OmniVision OV02C10 sensor driver");
1044 MODULE_LICENSE("GPL v2");