1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Intel Corporation.
4 #include <linux/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 OV9734_LINK_FREQ_180MHZ 180000000ULL
15 #define OV9734_SCLK 36000000LL
16 #define OV9734_MCLK 19200000
17 /* ov9734 only support 1-lane mipi output */
18 #define OV9734_DATA_LANES 1
19 #define OV9734_RGB_DEPTH 10
21 #define OV9734_REG_CHIP_ID 0x300a
22 #define OV9734_CHIP_ID 0x9734
24 #define OV9734_REG_MODE_SELECT 0x0100
25 #define OV9734_MODE_STANDBY 0x00
26 #define OV9734_MODE_STREAMING 0x01
28 /* vertical-timings from sensor */
29 #define OV9734_REG_VTS 0x380e
30 #define OV9734_VTS_30FPS 0x0322
31 #define OV9734_VTS_30FPS_MIN 0x0322
32 #define OV9734_VTS_MAX 0x7fff
34 /* horizontal-timings from sensor */
35 #define OV9734_REG_HTS 0x380c
37 /* Exposure controls from sensor */
38 #define OV9734_REG_EXPOSURE 0x3500
39 #define OV9734_EXPOSURE_MIN 4
40 #define OV9734_EXPOSURE_MAX_MARGIN 4
41 #define OV9734_EXPOSURE_STEP 1
43 /* Analog gain controls from sensor */
44 #define OV9734_REG_ANALOG_GAIN 0x350a
45 #define OV9734_ANAL_GAIN_MIN 16
46 #define OV9734_ANAL_GAIN_MAX 248
47 #define OV9734_ANAL_GAIN_STEP 1
49 /* Digital gain controls from sensor */
50 #define OV9734_REG_MWB_R_GAIN 0x5180
51 #define OV9734_REG_MWB_G_GAIN 0x5182
52 #define OV9734_REG_MWB_B_GAIN 0x5184
53 #define OV9734_DGTL_GAIN_MIN 256
54 #define OV9734_DGTL_GAIN_MAX 1023
55 #define OV9734_DGTL_GAIN_STEP 1
56 #define OV9734_DGTL_GAIN_DEFAULT 256
58 /* Test Pattern Control */
59 #define OV9734_REG_TEST_PATTERN 0x5080
60 #define OV9734_TEST_PATTERN_ENABLE BIT(7)
61 #define OV9734_TEST_PATTERN_BAR_SHIFT 2
64 #define OV9734_REG_GROUP_ACCESS 0x3208
65 #define OV9734_GROUP_HOLD_START 0x0
66 #define OV9734_GROUP_HOLD_END 0x10
67 #define OV9734_GROUP_HOLD_LAUNCH 0xa0
70 OV9734_LINK_FREQ_180MHZ_INDEX
,
78 struct ov9734_reg_list
{
80 const struct ov9734_reg
*regs
;
83 struct ov9734_link_freq_config
{
84 const struct ov9734_reg_list reg_list
;
88 /* Frame width in pixels */
91 /* Frame height in pixels */
94 /* Horizontal timining size */
97 /* Default vertical timining size */
100 /* Min vertical timining size */
103 /* Link frequency needed for this resolution */
106 /* Sensor register settings for this resolution */
107 const struct ov9734_reg_list reg_list
;
110 static const struct ov9734_reg mipi_data_rate_360mbps
[] = {
125 static const struct ov9734_reg mode_1296x734_regs
[] = {
287 static const char * const ov9734_test_pattern_menu
[] = {
289 "Standard Color Bar",
290 "Top-Bottom Darker Color Bar",
291 "Right-Left Darker Color Bar",
292 "Bottom-Top Darker Color Bar",
295 static const s64 link_freq_menu_items
[] = {
296 OV9734_LINK_FREQ_180MHZ
,
299 static const struct ov9734_link_freq_config link_freq_configs
[] = {
300 [OV9734_LINK_FREQ_180MHZ_INDEX
] = {
302 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_360mbps
),
303 .regs
= mipi_data_rate_360mbps
,
308 static const struct ov9734_mode supported_modes
[] = {
313 .vts_def
= OV9734_VTS_30FPS
,
314 .vts_min
= OV9734_VTS_30FPS_MIN
,
316 .num_of_regs
= ARRAY_SIZE(mode_1296x734_regs
),
317 .regs
= mode_1296x734_regs
,
319 .link_freq_index
= OV9734_LINK_FREQ_180MHZ_INDEX
,
324 struct v4l2_subdev sd
;
325 struct media_pad pad
;
326 struct v4l2_ctrl_handler ctrl_handler
;
329 struct v4l2_ctrl
*link_freq
;
330 struct v4l2_ctrl
*pixel_rate
;
331 struct v4l2_ctrl
*vblank
;
332 struct v4l2_ctrl
*hblank
;
333 struct v4l2_ctrl
*exposure
;
336 const struct ov9734_mode
*cur_mode
;
338 /* To serialize asynchronous callbacks */
342 static inline struct ov9734
*to_ov9734(struct v4l2_subdev
*subdev
)
344 return container_of(subdev
, struct ov9734
, sd
);
347 static u64
to_pixel_rate(u32 f_index
)
349 u64 pixel_rate
= link_freq_menu_items
[f_index
] * 2 * OV9734_DATA_LANES
;
351 do_div(pixel_rate
, OV9734_RGB_DEPTH
);
356 static u64
to_pixels_per_line(u32 hts
, u32 f_index
)
358 u64 ppl
= hts
* to_pixel_rate(f_index
);
360 do_div(ppl
, OV9734_SCLK
);
365 static int ov9734_read_reg(struct ov9734
*ov9734
, u16 reg
, u16 len
, u32
*val
)
367 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
368 struct i2c_msg msgs
[2];
370 u8 data_buf
[4] = {0};
373 if (len
> sizeof(data_buf
))
376 put_unaligned_be16(reg
, addr_buf
);
377 msgs
[0].addr
= client
->addr
;
379 msgs
[0].len
= sizeof(addr_buf
);
380 msgs
[0].buf
= addr_buf
;
381 msgs
[1].addr
= client
->addr
;
382 msgs
[1].flags
= I2C_M_RD
;
384 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
386 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
387 if (ret
!= ARRAY_SIZE(msgs
))
388 return ret
< 0 ? ret
: -EIO
;
390 *val
= get_unaligned_be32(data_buf
);
395 static int ov9734_write_reg(struct ov9734
*ov9734
, u16 reg
, u16 len
, u32 val
)
397 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
404 put_unaligned_be16(reg
, buf
);
405 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
407 ret
= i2c_master_send(client
, buf
, len
+ 2);
409 return ret
< 0 ? ret
: -EIO
;
414 static int ov9734_write_reg_list(struct ov9734
*ov9734
,
415 const struct ov9734_reg_list
*r_list
)
417 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
421 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
422 ret
= ov9734_write_reg(ov9734
, r_list
->regs
[i
].address
, 1,
423 r_list
->regs
[i
].val
);
425 dev_err_ratelimited(&client
->dev
,
426 "write reg 0x%4.4x return err = %d",
427 r_list
->regs
[i
].address
, ret
);
435 static int ov9734_update_digital_gain(struct ov9734
*ov9734
, u32 d_gain
)
439 ret
= ov9734_write_reg(ov9734
, OV9734_REG_GROUP_ACCESS
, 1,
440 OV9734_GROUP_HOLD_START
);
444 ret
= ov9734_write_reg(ov9734
, OV9734_REG_MWB_R_GAIN
, 2, d_gain
);
448 ret
= ov9734_write_reg(ov9734
, OV9734_REG_MWB_G_GAIN
, 2, d_gain
);
452 ret
= ov9734_write_reg(ov9734
, OV9734_REG_MWB_B_GAIN
, 2, d_gain
);
456 ret
= ov9734_write_reg(ov9734
, OV9734_REG_GROUP_ACCESS
, 1,
457 OV9734_GROUP_HOLD_END
);
461 ret
= ov9734_write_reg(ov9734
, OV9734_REG_GROUP_ACCESS
, 1,
462 OV9734_GROUP_HOLD_LAUNCH
);
466 static int ov9734_test_pattern(struct ov9734
*ov9734
, u32 pattern
)
469 pattern
= (pattern
- 1) << OV9734_TEST_PATTERN_BAR_SHIFT
|
470 OV9734_TEST_PATTERN_ENABLE
;
472 return ov9734_write_reg(ov9734
, OV9734_REG_TEST_PATTERN
, 1, pattern
);
475 static int ov9734_set_ctrl(struct v4l2_ctrl
*ctrl
)
477 struct ov9734
*ov9734
= container_of(ctrl
->handler
,
478 struct ov9734
, ctrl_handler
);
479 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
483 /* Propagate change of current control to all related controls */
484 if (ctrl
->id
== V4L2_CID_VBLANK
) {
485 /* Update max exposure while meeting expected vblanking */
486 exposure_max
= ov9734
->cur_mode
->height
+ ctrl
->val
-
487 OV9734_EXPOSURE_MAX_MARGIN
;
488 __v4l2_ctrl_modify_range(ov9734
->exposure
,
489 ov9734
->exposure
->minimum
,
490 exposure_max
, ov9734
->exposure
->step
,
494 /* V4L2 controls values will be applied only when power is already up */
495 if (!pm_runtime_get_if_in_use(&client
->dev
))
499 case V4L2_CID_ANALOGUE_GAIN
:
500 ret
= ov9734_write_reg(ov9734
, OV9734_REG_ANALOG_GAIN
,
504 case V4L2_CID_DIGITAL_GAIN
:
505 ret
= ov9734_update_digital_gain(ov9734
, ctrl
->val
);
508 case V4L2_CID_EXPOSURE
:
509 /* 4 least significant bits of expsoure are fractional part */
510 ret
= ov9734_write_reg(ov9734
, OV9734_REG_EXPOSURE
,
514 case V4L2_CID_VBLANK
:
515 ret
= ov9734_write_reg(ov9734
, OV9734_REG_VTS
, 2,
516 ov9734
->cur_mode
->height
+ ctrl
->val
);
519 case V4L2_CID_TEST_PATTERN
:
520 ret
= ov9734_test_pattern(ov9734
, ctrl
->val
);
528 pm_runtime_put(&client
->dev
);
533 static const struct v4l2_ctrl_ops ov9734_ctrl_ops
= {
534 .s_ctrl
= ov9734_set_ctrl
,
537 static int ov9734_init_controls(struct ov9734
*ov9734
)
539 struct v4l2_ctrl_handler
*ctrl_hdlr
;
540 const struct ov9734_mode
*cur_mode
;
541 s64 exposure_max
, h_blank
, pixel_rate
;
542 u32 vblank_min
, vblank_max
, vblank_default
;
545 ctrl_hdlr
= &ov9734
->ctrl_handler
;
546 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
550 ctrl_hdlr
->lock
= &ov9734
->mutex
;
551 cur_mode
= ov9734
->cur_mode
;
552 size
= ARRAY_SIZE(link_freq_menu_items
);
553 ov9734
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
, &ov9734_ctrl_ops
,
556 link_freq_menu_items
);
557 if (ov9734
->link_freq
)
558 ov9734
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
560 pixel_rate
= to_pixel_rate(OV9734_LINK_FREQ_180MHZ_INDEX
);
561 ov9734
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov9734_ctrl_ops
,
562 V4L2_CID_PIXEL_RATE
, 0,
563 pixel_rate
, 1, pixel_rate
);
564 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
565 vblank_max
= OV9734_VTS_MAX
- cur_mode
->height
;
566 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
567 ov9734
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov9734_ctrl_ops
,
568 V4L2_CID_VBLANK
, vblank_min
,
569 vblank_max
, 1, vblank_default
);
570 h_blank
= to_pixels_per_line(cur_mode
->hts
, cur_mode
->link_freq_index
);
571 h_blank
-= cur_mode
->width
;
572 ov9734
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov9734_ctrl_ops
,
573 V4L2_CID_HBLANK
, h_blank
, h_blank
, 1,
576 ov9734
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
578 v4l2_ctrl_new_std(ctrl_hdlr
, &ov9734_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
579 OV9734_ANAL_GAIN_MIN
, OV9734_ANAL_GAIN_MAX
,
580 OV9734_ANAL_GAIN_STEP
, OV9734_ANAL_GAIN_MIN
);
581 v4l2_ctrl_new_std(ctrl_hdlr
, &ov9734_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
582 OV9734_DGTL_GAIN_MIN
, OV9734_DGTL_GAIN_MAX
,
583 OV9734_DGTL_GAIN_STEP
, OV9734_DGTL_GAIN_DEFAULT
);
584 exposure_max
= ov9734
->cur_mode
->vts_def
- OV9734_EXPOSURE_MAX_MARGIN
;
585 ov9734
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov9734_ctrl_ops
,
587 OV9734_EXPOSURE_MIN
, exposure_max
,
588 OV9734_EXPOSURE_STEP
,
590 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &ov9734_ctrl_ops
,
591 V4L2_CID_TEST_PATTERN
,
592 ARRAY_SIZE(ov9734_test_pattern_menu
) - 1,
593 0, 0, ov9734_test_pattern_menu
);
594 if (ctrl_hdlr
->error
)
595 return ctrl_hdlr
->error
;
597 ov9734
->sd
.ctrl_handler
= ctrl_hdlr
;
602 static void ov9734_update_pad_format(const struct ov9734_mode
*mode
,
603 struct v4l2_mbus_framefmt
*fmt
)
605 fmt
->width
= mode
->width
;
606 fmt
->height
= mode
->height
;
607 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
608 fmt
->field
= V4L2_FIELD_NONE
;
611 static int ov9734_start_streaming(struct ov9734
*ov9734
)
613 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
614 const struct ov9734_reg_list
*reg_list
;
615 int link_freq_index
, ret
;
617 link_freq_index
= ov9734
->cur_mode
->link_freq_index
;
618 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
619 ret
= ov9734_write_reg_list(ov9734
, reg_list
);
621 dev_err(&client
->dev
, "failed to set plls");
625 reg_list
= &ov9734
->cur_mode
->reg_list
;
626 ret
= ov9734_write_reg_list(ov9734
, reg_list
);
628 dev_err(&client
->dev
, "failed to set mode");
632 ret
= __v4l2_ctrl_handler_setup(ov9734
->sd
.ctrl_handler
);
636 ret
= ov9734_write_reg(ov9734
, OV9734_REG_MODE_SELECT
,
637 1, OV9734_MODE_STREAMING
);
639 dev_err(&client
->dev
, "failed to start stream");
644 static void ov9734_stop_streaming(struct ov9734
*ov9734
)
646 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
648 if (ov9734_write_reg(ov9734
, OV9734_REG_MODE_SELECT
,
649 1, OV9734_MODE_STANDBY
))
650 dev_err(&client
->dev
, "failed to stop stream");
653 static int ov9734_set_stream(struct v4l2_subdev
*sd
, int enable
)
655 struct ov9734
*ov9734
= to_ov9734(sd
);
656 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
659 mutex_lock(&ov9734
->mutex
);
662 ret
= pm_runtime_resume_and_get(&client
->dev
);
664 mutex_unlock(&ov9734
->mutex
);
668 ret
= ov9734_start_streaming(ov9734
);
671 ov9734_stop_streaming(ov9734
);
672 pm_runtime_put(&client
->dev
);
675 ov9734_stop_streaming(ov9734
);
676 pm_runtime_put(&client
->dev
);
679 mutex_unlock(&ov9734
->mutex
);
684 static int ov9734_set_format(struct v4l2_subdev
*sd
,
685 struct v4l2_subdev_state
*sd_state
,
686 struct v4l2_subdev_format
*fmt
)
688 struct ov9734
*ov9734
= to_ov9734(sd
);
689 const struct ov9734_mode
*mode
;
690 s32 vblank_def
, h_blank
;
692 mode
= v4l2_find_nearest_size(supported_modes
,
693 ARRAY_SIZE(supported_modes
), width
,
694 height
, fmt
->format
.width
,
697 mutex_lock(&ov9734
->mutex
);
698 ov9734_update_pad_format(mode
, &fmt
->format
);
699 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
700 *v4l2_subdev_state_get_format(sd_state
, fmt
->pad
) = fmt
->format
;
702 ov9734
->cur_mode
= mode
;
703 __v4l2_ctrl_s_ctrl(ov9734
->link_freq
, mode
->link_freq_index
);
704 __v4l2_ctrl_s_ctrl_int64(ov9734
->pixel_rate
,
705 to_pixel_rate(mode
->link_freq_index
));
707 /* Update limits and set FPS to default */
708 vblank_def
= mode
->vts_def
- mode
->height
;
709 __v4l2_ctrl_modify_range(ov9734
->vblank
,
710 mode
->vts_min
- mode
->height
,
711 OV9734_VTS_MAX
- mode
->height
, 1,
713 __v4l2_ctrl_s_ctrl(ov9734
->vblank
, vblank_def
);
714 h_blank
= to_pixels_per_line(mode
->hts
, mode
->link_freq_index
) -
716 __v4l2_ctrl_modify_range(ov9734
->hblank
, h_blank
, h_blank
, 1,
720 mutex_unlock(&ov9734
->mutex
);
725 static int ov9734_get_format(struct v4l2_subdev
*sd
,
726 struct v4l2_subdev_state
*sd_state
,
727 struct v4l2_subdev_format
*fmt
)
729 struct ov9734
*ov9734
= to_ov9734(sd
);
731 mutex_lock(&ov9734
->mutex
);
732 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
733 fmt
->format
= *v4l2_subdev_state_get_format(sd_state
,
736 ov9734_update_pad_format(ov9734
->cur_mode
, &fmt
->format
);
738 mutex_unlock(&ov9734
->mutex
);
743 static int ov9734_enum_mbus_code(struct v4l2_subdev
*sd
,
744 struct v4l2_subdev_state
*sd_state
,
745 struct v4l2_subdev_mbus_code_enum
*code
)
750 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
755 static int ov9734_enum_frame_size(struct v4l2_subdev
*sd
,
756 struct v4l2_subdev_state
*sd_state
,
757 struct v4l2_subdev_frame_size_enum
*fse
)
759 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
762 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
765 fse
->min_width
= supported_modes
[fse
->index
].width
;
766 fse
->max_width
= fse
->min_width
;
767 fse
->min_height
= supported_modes
[fse
->index
].height
;
768 fse
->max_height
= fse
->min_height
;
773 static int ov9734_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
775 struct ov9734
*ov9734
= to_ov9734(sd
);
777 mutex_lock(&ov9734
->mutex
);
778 ov9734_update_pad_format(&supported_modes
[0],
779 v4l2_subdev_state_get_format(fh
->state
, 0));
780 mutex_unlock(&ov9734
->mutex
);
785 static const struct v4l2_subdev_video_ops ov9734_video_ops
= {
786 .s_stream
= ov9734_set_stream
,
789 static const struct v4l2_subdev_pad_ops ov9734_pad_ops
= {
790 .set_fmt
= ov9734_set_format
,
791 .get_fmt
= ov9734_get_format
,
792 .enum_mbus_code
= ov9734_enum_mbus_code
,
793 .enum_frame_size
= ov9734_enum_frame_size
,
796 static const struct v4l2_subdev_ops ov9734_subdev_ops
= {
797 .video
= &ov9734_video_ops
,
798 .pad
= &ov9734_pad_ops
,
801 static const struct media_entity_operations ov9734_subdev_entity_ops
= {
802 .link_validate
= v4l2_subdev_link_validate
,
805 static const struct v4l2_subdev_internal_ops ov9734_internal_ops
= {
809 static int ov9734_identify_module(struct ov9734
*ov9734
)
811 struct i2c_client
*client
= v4l2_get_subdevdata(&ov9734
->sd
);
815 ret
= ov9734_read_reg(ov9734
, OV9734_REG_CHIP_ID
, 2, &val
);
819 if (val
!= OV9734_CHIP_ID
) {
820 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
821 OV9734_CHIP_ID
, val
);
828 static int ov9734_check_hwcfg(struct device
*dev
)
830 struct fwnode_handle
*ep
;
831 struct fwnode_handle
*fwnode
= dev_fwnode(dev
);
832 struct v4l2_fwnode_endpoint bus_cfg
= {
833 .bus_type
= V4L2_MBUS_CSI2_DPHY
842 ret
= fwnode_property_read_u32(fwnode
, "clock-frequency", &mclk
);
846 if (mclk
!= OV9734_MCLK
) {
847 dev_err(dev
, "external clock %d is not supported", mclk
);
851 ep
= fwnode_graph_get_next_endpoint(fwnode
, NULL
);
855 ret
= v4l2_fwnode_endpoint_alloc_parse(ep
, &bus_cfg
);
856 fwnode_handle_put(ep
);
860 if (!bus_cfg
.nr_of_link_frequencies
) {
861 dev_err(dev
, "no link frequencies defined");
863 goto check_hwcfg_error
;
866 for (i
= 0; i
< ARRAY_SIZE(link_freq_menu_items
); i
++) {
867 for (j
= 0; j
< bus_cfg
.nr_of_link_frequencies
; j
++) {
868 if (link_freq_menu_items
[i
] ==
869 bus_cfg
.link_frequencies
[j
])
873 if (j
== bus_cfg
.nr_of_link_frequencies
) {
874 dev_err(dev
, "no link frequency %lld supported",
875 link_freq_menu_items
[i
]);
877 goto check_hwcfg_error
;
882 v4l2_fwnode_endpoint_free(&bus_cfg
);
887 static void ov9734_remove(struct i2c_client
*client
)
889 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
890 struct ov9734
*ov9734
= to_ov9734(sd
);
892 v4l2_async_unregister_subdev(sd
);
893 media_entity_cleanup(&sd
->entity
);
894 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
895 pm_runtime_disable(&client
->dev
);
896 pm_runtime_set_suspended(&client
->dev
);
897 mutex_destroy(&ov9734
->mutex
);
900 static int ov9734_probe(struct i2c_client
*client
)
902 struct ov9734
*ov9734
;
905 ret
= ov9734_check_hwcfg(&client
->dev
);
907 dev_err(&client
->dev
, "failed to check HW configuration: %d",
912 ov9734
= devm_kzalloc(&client
->dev
, sizeof(*ov9734
), GFP_KERNEL
);
916 v4l2_i2c_subdev_init(&ov9734
->sd
, client
, &ov9734_subdev_ops
);
917 ret
= ov9734_identify_module(ov9734
);
919 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
923 mutex_init(&ov9734
->mutex
);
924 ov9734
->cur_mode
= &supported_modes
[0];
925 ret
= ov9734_init_controls(ov9734
);
927 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
928 goto probe_error_v4l2_ctrl_handler_free
;
931 ov9734
->sd
.internal_ops
= &ov9734_internal_ops
;
932 ov9734
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
933 ov9734
->sd
.entity
.ops
= &ov9734_subdev_entity_ops
;
934 ov9734
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
935 ov9734
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
936 ret
= media_entity_pads_init(&ov9734
->sd
.entity
, 1, &ov9734
->pad
);
938 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
939 goto probe_error_v4l2_ctrl_handler_free
;
943 * Device is already turned on by i2c-core with ACPI domain PM.
944 * Enable runtime PM and turn off the device.
946 pm_runtime_set_active(&client
->dev
);
947 pm_runtime_enable(&client
->dev
);
948 pm_runtime_idle(&client
->dev
);
950 ret
= v4l2_async_register_subdev_sensor(&ov9734
->sd
);
952 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
954 goto probe_error_media_entity_cleanup_pm
;
959 probe_error_media_entity_cleanup_pm
:
960 pm_runtime_disable(&client
->dev
);
961 pm_runtime_set_suspended(&client
->dev
);
962 media_entity_cleanup(&ov9734
->sd
.entity
);
964 probe_error_v4l2_ctrl_handler_free
:
965 v4l2_ctrl_handler_free(ov9734
->sd
.ctrl_handler
);
966 mutex_destroy(&ov9734
->mutex
);
971 static const struct acpi_device_id ov9734_acpi_ids
[] = {
976 MODULE_DEVICE_TABLE(acpi
, ov9734_acpi_ids
);
978 static struct i2c_driver ov9734_i2c_driver
= {
981 .acpi_match_table
= ov9734_acpi_ids
,
983 .probe
= ov9734_probe
,
984 .remove
= ov9734_remove
,
987 module_i2c_driver(ov9734_i2c_driver
);
989 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
990 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
991 MODULE_DESCRIPTION("OmniVision OV9734 sensor driver");
992 MODULE_LICENSE("GPL v2");