1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020-2021 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 OV01A10_LINK_FREQ_400MHZ 400000000ULL
17 #define OV01A10_SCLK 40000000LL
18 #define OV01A10_MCLK 19200000
19 #define OV01A10_DATA_LANES 1
20 #define OV01A10_RGB_DEPTH 10
22 #define OV01A10_REG_CHIP_ID 0x300a
23 #define OV01A10_CHIP_ID 0x560141
25 #define OV01A10_REG_MODE_SELECT 0x0100
26 #define OV01A10_MODE_STANDBY 0x00
27 #define OV01A10_MODE_STREAMING 0x01
29 /* vertical-timings from sensor */
30 #define OV01A10_REG_VTS 0x380e
31 #define OV01A10_VTS_DEF 0x0380
32 #define OV01A10_VTS_MIN 0x0380
33 #define OV01A10_VTS_MAX 0xffff
35 /* Exposure controls from sensor */
36 #define OV01A10_REG_EXPOSURE 0x3501
37 #define OV01A10_EXPOSURE_MIN 4
38 #define OV01A10_EXPOSURE_MAX_MARGIN 8
39 #define OV01A10_EXPOSURE_STEP 1
41 /* Analog gain controls from sensor */
42 #define OV01A10_REG_ANALOG_GAIN 0x3508
43 #define OV01A10_ANAL_GAIN_MIN 0x100
44 #define OV01A10_ANAL_GAIN_MAX 0xffff
45 #define OV01A10_ANAL_GAIN_STEP 1
47 /* Digital gain controls from sensor */
48 #define OV01A10_REG_DIGILAL_GAIN_B 0x350A
49 #define OV01A10_REG_DIGITAL_GAIN_GB 0x3510
50 #define OV01A10_REG_DIGITAL_GAIN_GR 0x3513
51 #define OV01A10_REG_DIGITAL_GAIN_R 0x3516
52 #define OV01A10_DGTL_GAIN_MIN 0
53 #define OV01A10_DGTL_GAIN_MAX 0x3ffff
54 #define OV01A10_DGTL_GAIN_STEP 1
55 #define OV01A10_DGTL_GAIN_DEFAULT 1024
57 /* Test Pattern Control */
58 #define OV01A10_REG_TEST_PATTERN 0x4503
59 #define OV01A10_TEST_PATTERN_ENABLE BIT(7)
60 #define OV01A10_TEST_PATTERN_BAR_SHIFT 0
63 OV01A10_LINK_FREQ_400MHZ_INDEX
,
71 struct ov01a10_reg_list
{
73 const struct ov01a10_reg
*regs
;
76 struct ov01a10_link_freq_config
{
77 const struct ov01a10_reg_list reg_list
;
81 /* Frame width in pixels */
84 /* Frame height in pixels */
87 /* Horizontal timining size */
90 /* Default vertical timining size */
93 /* Min vertical timining size */
96 /* Link frequency needed for this resolution */
99 /* Sensor register settings for this resolution */
100 const struct ov01a10_reg_list reg_list
;
103 static const struct ov01a10_reg mipi_data_rate_720mbps
[] = {
106 static const struct ov01a10_reg sensor_1280x800_setting
[] = {
242 static const char * const ov01a10_test_pattern_menu
[] = {
245 "Top-Bottom Darker Color Bar",
246 "Right-Left Darker Color Bar",
250 static const s64 link_freq_menu_items
[] = {
251 OV01A10_LINK_FREQ_400MHZ
,
254 static const struct ov01a10_link_freq_config link_freq_configs
[] = {
255 [OV01A10_LINK_FREQ_400MHZ_INDEX
] = {
257 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_720mbps
),
258 .regs
= mipi_data_rate_720mbps
,
263 static const struct ov01a10_mode supported_modes
[] = {
268 .vts_def
= OV01A10_VTS_DEF
,
269 .vts_min
= OV01A10_VTS_MIN
,
271 .num_of_regs
= ARRAY_SIZE(sensor_1280x800_setting
),
272 .regs
= sensor_1280x800_setting
,
274 .link_freq_index
= OV01A10_LINK_FREQ_400MHZ_INDEX
,
279 struct v4l2_subdev sd
;
280 struct media_pad pad
;
281 struct v4l2_ctrl_handler ctrl_handler
;
284 struct v4l2_ctrl
*link_freq
;
285 struct v4l2_ctrl
*pixel_rate
;
286 struct v4l2_ctrl
*vblank
;
287 struct v4l2_ctrl
*hblank
;
288 struct v4l2_ctrl
*exposure
;
291 const struct ov01a10_mode
*cur_mode
;
293 /* To serialize asynchronus callbacks */
296 /* Streaming on/off */
300 static inline struct ov01a10
*to_ov01a10(struct v4l2_subdev
*subdev
)
302 return container_of(subdev
, struct ov01a10
, sd
);
305 static int ov01a10_read_reg(struct ov01a10
*ov01a10
, u16 reg
, u16 len
, u32
*val
)
307 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
308 struct i2c_msg msgs
[2];
310 u8 data_buf
[4] = {0};
313 if (len
> sizeof(data_buf
))
316 put_unaligned_be16(reg
, addr_buf
);
317 msgs
[0].addr
= client
->addr
;
319 msgs
[0].len
= sizeof(addr_buf
);
320 msgs
[0].buf
= addr_buf
;
321 msgs
[1].addr
= client
->addr
;
322 msgs
[1].flags
= I2C_M_RD
;
324 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
326 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
328 if (ret
!= ARRAY_SIZE(msgs
))
329 return ret
< 0 ? ret
: -EIO
;
331 *val
= get_unaligned_be32(data_buf
);
336 static int ov01a10_write_reg(struct ov01a10
*ov01a10
, u16 reg
, u16 len
, u32 val
)
338 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
345 put_unaligned_be16(reg
, buf
);
346 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
348 ret
= i2c_master_send(client
, buf
, len
+ 2);
350 return ret
< 0 ? ret
: -EIO
;
355 static int ov01a10_write_reg_list(struct ov01a10
*ov01a10
,
356 const struct ov01a10_reg_list
*r_list
)
358 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
362 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
363 ret
= ov01a10_write_reg(ov01a10
, r_list
->regs
[i
].address
, 1,
364 r_list
->regs
[i
].val
);
366 dev_err_ratelimited(&client
->dev
,
367 "write reg 0x%4.4x return err = %d",
368 r_list
->regs
[i
].address
, ret
);
376 static int ov01a10_update_digital_gain(struct ov01a10
*ov01a10
, u32 d_gain
)
378 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
379 u32 real
= d_gain
<< 6;
382 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_DIGILAL_GAIN_B
, 3, real
);
384 dev_err(&client
->dev
, "failed to set OV01A10_REG_DIGITAL_GAIN_B");
387 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_DIGITAL_GAIN_GB
, 3, real
);
389 dev_err(&client
->dev
, "failed to set OV01A10_REG_DIGITAL_GAIN_GB");
392 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_DIGITAL_GAIN_GR
, 3, real
);
394 dev_err(&client
->dev
, "failed to set OV01A10_REG_DIGITAL_GAIN_GR");
398 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_DIGITAL_GAIN_R
, 3, real
);
400 dev_err(&client
->dev
, "failed to set OV01A10_REG_DIGITAL_GAIN_R");
406 static int ov01a10_test_pattern(struct ov01a10
*ov01a10
, u32 pattern
)
409 pattern
= (pattern
- 1) << OV01A10_TEST_PATTERN_BAR_SHIFT
|
410 OV01A10_TEST_PATTERN_ENABLE
;
412 return ov01a10_write_reg(ov01a10
, OV01A10_REG_TEST_PATTERN
, 1, pattern
);
415 static int ov01a10_set_ctrl(struct v4l2_ctrl
*ctrl
)
417 struct ov01a10
*ov01a10
= container_of(ctrl
->handler
,
418 struct ov01a10
, ctrl_handler
);
419 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
423 /* Propagate change of current control to all related controls */
424 if (ctrl
->id
== V4L2_CID_VBLANK
) {
425 /* Update max exposure while meeting expected vblanking */
426 exposure_max
= ov01a10
->cur_mode
->height
+ ctrl
->val
-
427 OV01A10_EXPOSURE_MAX_MARGIN
;
428 __v4l2_ctrl_modify_range(ov01a10
->exposure
,
429 ov01a10
->exposure
->minimum
,
430 exposure_max
, ov01a10
->exposure
->step
,
434 /* V4L2 controls values will be applied only when power is already up */
435 if (!pm_runtime_get_if_in_use(&client
->dev
))
439 case V4L2_CID_ANALOGUE_GAIN
:
440 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_ANALOG_GAIN
, 2,
444 case V4L2_CID_DIGITAL_GAIN
:
445 ret
= ov01a10_update_digital_gain(ov01a10
, ctrl
->val
);
448 case V4L2_CID_EXPOSURE
:
449 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_EXPOSURE
, 2,
453 case V4L2_CID_VBLANK
:
454 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_VTS
, 2,
455 ov01a10
->cur_mode
->height
+ ctrl
->val
);
458 case V4L2_CID_TEST_PATTERN
:
459 ret
= ov01a10_test_pattern(ov01a10
, ctrl
->val
);
467 pm_runtime_put(&client
->dev
);
472 static const struct v4l2_ctrl_ops ov01a10_ctrl_ops
= {
473 .s_ctrl
= ov01a10_set_ctrl
,
476 static int ov01a10_init_controls(struct ov01a10
*ov01a10
)
478 struct v4l2_ctrl_handler
*ctrl_hdlr
;
479 const struct ov01a10_mode
*cur_mode
;
480 s64 exposure_max
, h_blank
;
481 u32 vblank_min
, vblank_max
, vblank_default
;
485 ctrl_hdlr
= &ov01a10
->ctrl_handler
;
486 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
490 ctrl_hdlr
->lock
= &ov01a10
->mutex
;
491 cur_mode
= ov01a10
->cur_mode
;
492 size
= ARRAY_SIZE(link_freq_menu_items
);
494 ov01a10
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
,
498 link_freq_menu_items
);
499 if (ov01a10
->link_freq
)
500 ov01a10
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
502 ov01a10
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a10_ctrl_ops
,
503 V4L2_CID_PIXEL_RATE
, 0,
504 OV01A10_SCLK
, 1, OV01A10_SCLK
);
506 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
507 vblank_max
= OV01A10_VTS_MAX
- cur_mode
->height
;
508 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
509 ov01a10
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a10_ctrl_ops
,
510 V4L2_CID_VBLANK
, vblank_min
,
511 vblank_max
, 1, vblank_default
);
513 h_blank
= cur_mode
->hts
- cur_mode
->width
;
514 ov01a10
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a10_ctrl_ops
,
515 V4L2_CID_HBLANK
, h_blank
, h_blank
,
518 ov01a10
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
520 v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a10_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
521 OV01A10_ANAL_GAIN_MIN
, OV01A10_ANAL_GAIN_MAX
,
522 OV01A10_ANAL_GAIN_STEP
, OV01A10_ANAL_GAIN_MIN
);
523 v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a10_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
524 OV01A10_DGTL_GAIN_MIN
, OV01A10_DGTL_GAIN_MAX
,
525 OV01A10_DGTL_GAIN_STEP
, OV01A10_DGTL_GAIN_DEFAULT
);
526 exposure_max
= cur_mode
->vts_def
- OV01A10_EXPOSURE_MAX_MARGIN
;
527 ov01a10
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a10_ctrl_ops
,
529 OV01A10_EXPOSURE_MIN
,
531 OV01A10_EXPOSURE_STEP
,
533 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &ov01a10_ctrl_ops
,
534 V4L2_CID_TEST_PATTERN
,
535 ARRAY_SIZE(ov01a10_test_pattern_menu
) - 1,
536 0, 0, ov01a10_test_pattern_menu
);
537 if (ctrl_hdlr
->error
)
538 return ctrl_hdlr
->error
;
540 ov01a10
->sd
.ctrl_handler
= ctrl_hdlr
;
545 static void ov01a10_update_pad_format(const struct ov01a10_mode
*mode
,
546 struct v4l2_mbus_framefmt
*fmt
)
548 fmt
->width
= mode
->width
;
549 fmt
->height
= mode
->height
;
550 fmt
->code
= MEDIA_BUS_FMT_SBGGR10_1X10
;
551 fmt
->field
= V4L2_FIELD_NONE
;
554 static int ov01a10_start_streaming(struct ov01a10
*ov01a10
)
556 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
557 const struct ov01a10_reg_list
*reg_list
;
560 struct vsc_mipi_config conf
;
561 struct vsc_camera_status status
;
563 conf
.lane_num
= OV01A10_DATA_LANES
;
564 /* frequency unit 100k */
565 conf
.freq
= OV01A10_LINK_FREQ_400MHZ
/ 100000;
566 ret
= vsc_acquire_camera_sensor(&conf
, NULL
, NULL
, &status
);
568 dev_err(&client
->dev
, "Acquire VSC failed");
571 link_freq_index
= ov01a10
->cur_mode
->link_freq_index
;
572 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
573 ret
= ov01a10_write_reg_list(ov01a10
, reg_list
);
575 dev_err(&client
->dev
, "failed to set plls");
579 reg_list
= &ov01a10
->cur_mode
->reg_list
;
580 ret
= ov01a10_write_reg_list(ov01a10
, reg_list
);
582 dev_err(&client
->dev
, "failed to set mode");
586 ret
= __v4l2_ctrl_handler_setup(ov01a10
->sd
.ctrl_handler
);
590 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_MODE_SELECT
, 1,
591 OV01A10_MODE_STREAMING
);
593 dev_err(&client
->dev
, "failed to start streaming");
598 static void ov01a10_stop_streaming(struct ov01a10
*ov01a10
)
600 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
602 struct vsc_camera_status status
;
604 ret
= ov01a10_write_reg(ov01a10
, OV01A10_REG_MODE_SELECT
, 1,
605 OV01A10_MODE_STANDBY
);
607 dev_err(&client
->dev
, "failed to stop streaming");
608 ret
= vsc_release_camera_sensor(&status
);
610 dev_err(&client
->dev
, "Release VSC failed");
613 static int ov01a10_set_stream(struct v4l2_subdev
*sd
, int enable
)
615 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
616 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
619 if (ov01a10
->streaming
== enable
)
622 mutex_lock(&ov01a10
->mutex
);
624 ret
= pm_runtime_get_sync(&client
->dev
);
626 pm_runtime_put_noidle(&client
->dev
);
627 mutex_unlock(&ov01a10
->mutex
);
631 ret
= ov01a10_start_streaming(ov01a10
);
634 ov01a10_stop_streaming(ov01a10
);
635 pm_runtime_put(&client
->dev
);
638 ov01a10_stop_streaming(ov01a10
);
639 pm_runtime_put(&client
->dev
);
642 ov01a10
->streaming
= enable
;
643 mutex_unlock(&ov01a10
->mutex
);
648 static int __maybe_unused
ov01a10_suspend(struct device
*dev
)
650 struct i2c_client
*client
= to_i2c_client(dev
);
651 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
652 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
654 mutex_lock(&ov01a10
->mutex
);
655 if (ov01a10
->streaming
)
656 ov01a10_stop_streaming(ov01a10
);
658 mutex_unlock(&ov01a10
->mutex
);
663 static int __maybe_unused
ov01a10_resume(struct device
*dev
)
665 struct i2c_client
*client
= to_i2c_client(dev
);
666 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
667 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
670 mutex_lock(&ov01a10
->mutex
);
671 if (!ov01a10
->streaming
)
674 ret
= ov01a10_start_streaming(ov01a10
);
676 ov01a10
->streaming
= false;
677 ov01a10_stop_streaming(ov01a10
);
681 mutex_unlock(&ov01a10
->mutex
);
685 static int ov01a10_set_format(struct v4l2_subdev
*sd
,
686 struct v4l2_subdev_state
*sd_state
,
687 struct v4l2_subdev_format
*fmt
)
689 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
690 const struct ov01a10_mode
*mode
;
691 s32 vblank_def
, h_blank
;
693 mode
= v4l2_find_nearest_size(supported_modes
,
694 ARRAY_SIZE(supported_modes
), width
,
695 height
, fmt
->format
.width
,
698 mutex_lock(&ov01a10
->mutex
);
699 ov01a10_update_pad_format(mode
, &fmt
->format
);
700 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
701 *v4l2_subdev_get_try_format(sd
, sd_state
, fmt
->pad
) = fmt
->format
;
703 ov01a10
->cur_mode
= mode
;
704 __v4l2_ctrl_s_ctrl(ov01a10
->link_freq
, mode
->link_freq_index
);
705 __v4l2_ctrl_s_ctrl_int64(ov01a10
->pixel_rate
, OV01A10_SCLK
);
707 /* Update limits and set FPS to default */
708 vblank_def
= mode
->vts_def
- mode
->height
;
709 __v4l2_ctrl_modify_range(ov01a10
->vblank
,
710 mode
->vts_min
- mode
->height
,
711 OV01A10_VTS_MAX
- mode
->height
, 1,
713 __v4l2_ctrl_s_ctrl(ov01a10
->vblank
, vblank_def
);
714 h_blank
= mode
->hts
- mode
->width
;
715 __v4l2_ctrl_modify_range(ov01a10
->hblank
, h_blank
, h_blank
, 1,
718 mutex_unlock(&ov01a10
->mutex
);
723 static int ov01a10_get_format(struct v4l2_subdev
*sd
,
724 struct v4l2_subdev_state
*sd_state
,
725 struct v4l2_subdev_format
*fmt
)
727 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
729 mutex_lock(&ov01a10
->mutex
);
730 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
731 fmt
->format
= *v4l2_subdev_get_try_format(&ov01a10
->sd
,
734 ov01a10_update_pad_format(ov01a10
->cur_mode
, &fmt
->format
);
736 mutex_unlock(&ov01a10
->mutex
);
741 static int ov01a10_enum_mbus_code(struct v4l2_subdev
*sd
,
742 struct v4l2_subdev_state
*sd_state
,
743 struct v4l2_subdev_mbus_code_enum
*code
)
748 code
->code
= MEDIA_BUS_FMT_SBGGR10_1X10
;
753 static int ov01a10_enum_frame_size(struct v4l2_subdev
*sd
,
754 struct v4l2_subdev_state
*sd_state
,
755 struct v4l2_subdev_frame_size_enum
*fse
)
757 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
760 if (fse
->code
!= MEDIA_BUS_FMT_SBGGR10_1X10
)
763 fse
->min_width
= supported_modes
[fse
->index
].width
;
764 fse
->max_width
= fse
->min_width
;
765 fse
->min_height
= supported_modes
[fse
->index
].height
;
766 fse
->max_height
= fse
->min_height
;
771 static int ov01a10_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
773 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
775 mutex_lock(&ov01a10
->mutex
);
776 ov01a10_update_pad_format(&supported_modes
[0],
777 v4l2_subdev_get_try_format(sd
, fh
->state
, 0));
778 mutex_unlock(&ov01a10
->mutex
);
783 static const struct v4l2_subdev_video_ops ov01a10_video_ops
= {
784 .s_stream
= ov01a10_set_stream
,
787 static const struct v4l2_subdev_pad_ops ov01a10_pad_ops
= {
788 .set_fmt
= ov01a10_set_format
,
789 .get_fmt
= ov01a10_get_format
,
790 .enum_mbus_code
= ov01a10_enum_mbus_code
,
791 .enum_frame_size
= ov01a10_enum_frame_size
,
794 static const struct v4l2_subdev_ops ov01a10_subdev_ops
= {
795 .video
= &ov01a10_video_ops
,
796 .pad
= &ov01a10_pad_ops
,
799 static const struct media_entity_operations ov01a10_subdev_entity_ops
= {
800 .link_validate
= v4l2_subdev_link_validate
,
803 static const struct v4l2_subdev_internal_ops ov01a10_internal_ops
= {
804 .open
= ov01a10_open
,
807 static int ov01a10_identify_module(struct ov01a10
*ov01a10
)
809 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a10
->sd
);
813 ret
= ov01a10_read_reg(ov01a10
, OV01A10_REG_CHIP_ID
, 3, &val
);
817 if (val
!= OV01A10_CHIP_ID
) {
818 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
819 OV01A10_CHIP_ID
, val
);
826 static int ov01a10_remove(struct i2c_client
*client
)
828 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
829 struct ov01a10
*ov01a10
= to_ov01a10(sd
);
831 v4l2_async_unregister_subdev(sd
);
832 media_entity_cleanup(&sd
->entity
);
833 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
834 pm_runtime_disable(&client
->dev
);
835 mutex_destroy(&ov01a10
->mutex
);
840 static int ov01a10_probe(struct i2c_client
*client
)
842 struct ov01a10
*ov01a10
;
844 struct vsc_mipi_config conf
;
845 struct vsc_camera_status status
;
847 conf
.lane_num
= OV01A10_DATA_LANES
;
848 /* frequency unit 100k */
849 conf
.freq
= OV01A10_LINK_FREQ_400MHZ
/ 100000;
850 ret
= vsc_acquire_camera_sensor(&conf
, NULL
, NULL
, &status
);
851 if (ret
== -EAGAIN
) {
852 dev_dbg(&client
->dev
, "VSC not ready, will re-probe");
853 return -EPROBE_DEFER
;
855 dev_err(&client
->dev
, "Acquire VSC failed");
858 ov01a10
= devm_kzalloc(&client
->dev
, sizeof(*ov01a10
), GFP_KERNEL
);
861 goto probe_error_ret
;
864 v4l2_i2c_subdev_init(&ov01a10
->sd
, client
, &ov01a10_subdev_ops
);
866 ret
= ov01a10_identify_module(ov01a10
);
868 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
869 goto probe_error_ret
;
872 mutex_init(&ov01a10
->mutex
);
873 ov01a10
->cur_mode
= &supported_modes
[0];
874 ret
= ov01a10_init_controls(ov01a10
);
876 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
877 goto probe_error_v4l2_ctrl_handler_free
;
880 ov01a10
->sd
.internal_ops
= &ov01a10_internal_ops
;
881 ov01a10
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
882 ov01a10
->sd
.entity
.ops
= &ov01a10_subdev_entity_ops
;
883 ov01a10
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
884 ov01a10
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
885 ret
= media_entity_pads_init(&ov01a10
->sd
.entity
, 1, &ov01a10
->pad
);
887 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
888 goto probe_error_v4l2_ctrl_handler_free
;
891 ret
= v4l2_async_register_subdev_sensor(&ov01a10
->sd
);
893 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
895 goto probe_error_media_entity_cleanup
;
898 vsc_release_camera_sensor(&status
);
900 * Device is already turned on by i2c-core with ACPI domain PM.
901 * Enable runtime PM and turn off the device.
903 pm_runtime_set_active(&client
->dev
);
904 pm_runtime_enable(&client
->dev
);
905 pm_runtime_idle(&client
->dev
);
909 probe_error_media_entity_cleanup
:
910 media_entity_cleanup(&ov01a10
->sd
.entity
);
912 probe_error_v4l2_ctrl_handler_free
:
913 v4l2_ctrl_handler_free(ov01a10
->sd
.ctrl_handler
);
914 mutex_destroy(&ov01a10
->mutex
);
917 vsc_release_camera_sensor(&status
);
921 static const struct dev_pm_ops ov01a10_pm_ops
= {
922 SET_SYSTEM_SLEEP_PM_OPS(ov01a10_suspend
, ov01a10_resume
)
926 static const struct acpi_device_id ov01a10_acpi_ids
[] = {
931 MODULE_DEVICE_TABLE(acpi
, ov01a10_acpi_ids
);
934 static struct i2c_driver ov01a10_i2c_driver
= {
937 .pm
= &ov01a10_pm_ops
,
938 .acpi_match_table
= ACPI_PTR(ov01a10_acpi_ids
),
940 .probe_new
= ov01a10_probe
,
941 .remove
= ov01a10_remove
,
944 module_i2c_driver(ov01a10_i2c_driver
);
946 MODULE_AUTHOR("Wang Yating <yating.wang@intel.com>");
947 MODULE_DESCRIPTION("OmniVision OV01A10 sensor driver");
948 MODULE_LICENSE("GPL v2");