1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 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 OV2740_LINK_FREQ_360MHZ 360000000ULL
15 #define OV2740_SCLK 72000000LL
16 #define OV2740_MCLK 19200000
17 #define OV2740_DATA_LANES 2
18 #define OV2740_RGB_DEPTH 10
20 #define OV2740_REG_CHIP_ID 0x300a
21 #define OV2740_CHIP_ID 0x2740
23 #define OV2740_REG_MODE_SELECT 0x0100
24 #define OV2740_MODE_STANDBY 0x00
25 #define OV2740_MODE_STREAMING 0x01
27 /* vertical-timings from sensor */
28 #define OV2740_REG_VTS 0x380e
29 #define OV2740_VTS_DEF 0x088a
30 #define OV2740_VTS_MIN 0x0460
31 #define OV2740_VTS_MAX 0x7fff
33 /* horizontal-timings from sensor */
34 #define OV2740_REG_HTS 0x380c
36 /* Exposure controls from sensor */
37 #define OV2740_REG_EXPOSURE 0x3500
38 #define OV2740_EXPOSURE_MIN 8
39 #define OV2740_EXPOSURE_MAX_MARGIN 8
40 #define OV2740_EXPOSURE_STEP 1
42 /* Analog gain controls from sensor */
43 #define OV2740_REG_ANALOG_GAIN 0x3508
44 #define OV2740_ANAL_GAIN_MIN 128
45 #define OV2740_ANAL_GAIN_MAX 1983
46 #define OV2740_ANAL_GAIN_STEP 1
48 /* Digital gain controls from sensor */
49 #define OV2740_REG_MWB_R_GAIN 0x500a
50 #define OV2740_REG_MWB_G_GAIN 0x500c
51 #define OV2740_REG_MWB_B_GAIN 0x500e
52 #define OV2740_DGTL_GAIN_MIN 0
53 #define OV2740_DGTL_GAIN_MAX 4095
54 #define OV2740_DGTL_GAIN_STEP 1
55 #define OV2740_DGTL_GAIN_DEFAULT 1024
57 /* Test Pattern Control */
58 #define OV2740_REG_TEST_PATTERN 0x5040
59 #define OV2740_TEST_PATTERN_ENABLE BIT(7)
60 #define OV2740_TEST_PATTERN_BAR_SHIFT 2
63 OV2740_LINK_FREQ_360MHZ_INDEX
,
71 struct ov2740_reg_list
{
73 const struct ov2740_reg
*regs
;
76 struct ov2740_link_freq_config
{
77 const struct ov2740_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 ov2740_reg_list reg_list
;
103 static const struct ov2740_reg mipi_data_rate_720mbps
[] = {
112 static const struct ov2740_reg mode_1932x1092_regs
[] = {
265 static const char * const ov2740_test_pattern_menu
[] = {
268 "Top-Bottom Darker Color Bar",
269 "Right-Left Darker Color Bar",
270 "Bottom-Top Darker Color Bar",
273 static const s64 link_freq_menu_items
[] = {
274 OV2740_LINK_FREQ_360MHZ
,
277 static const struct ov2740_link_freq_config link_freq_configs
[] = {
278 [OV2740_LINK_FREQ_360MHZ_INDEX
] = {
280 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_720mbps
),
281 .regs
= mipi_data_rate_720mbps
,
286 static const struct ov2740_mode supported_modes
[] = {
291 .vts_def
= OV2740_VTS_DEF
,
292 .vts_min
= OV2740_VTS_MIN
,
294 .num_of_regs
= ARRAY_SIZE(mode_1932x1092_regs
),
295 .regs
= mode_1932x1092_regs
,
297 .link_freq_index
= OV2740_LINK_FREQ_360MHZ_INDEX
,
302 struct v4l2_subdev sd
;
303 struct media_pad pad
;
304 struct v4l2_ctrl_handler ctrl_handler
;
307 struct v4l2_ctrl
*link_freq
;
308 struct v4l2_ctrl
*pixel_rate
;
309 struct v4l2_ctrl
*vblank
;
310 struct v4l2_ctrl
*hblank
;
311 struct v4l2_ctrl
*exposure
;
314 const struct ov2740_mode
*cur_mode
;
316 /* To serialize asynchronus callbacks */
319 /* Streaming on/off */
323 static inline struct ov2740
*to_ov2740(struct v4l2_subdev
*subdev
)
325 return container_of(subdev
, struct ov2740
, sd
);
328 static u64
to_pixel_rate(u32 f_index
)
330 u64 pixel_rate
= link_freq_menu_items
[f_index
] * 2 * OV2740_DATA_LANES
;
332 do_div(pixel_rate
, OV2740_RGB_DEPTH
);
337 static u64
to_pixels_per_line(u32 hts
, u32 f_index
)
339 u64 ppl
= hts
* to_pixel_rate(f_index
);
341 do_div(ppl
, OV2740_SCLK
);
346 static int ov2740_read_reg(struct ov2740
*ov2740
, u16 reg
, u16 len
, u32
*val
)
348 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
349 struct i2c_msg msgs
[2];
351 u8 data_buf
[4] = {0};
354 if (len
> sizeof(data_buf
))
357 put_unaligned_be16(reg
, addr_buf
);
358 msgs
[0].addr
= client
->addr
;
360 msgs
[0].len
= sizeof(addr_buf
);
361 msgs
[0].buf
= addr_buf
;
362 msgs
[1].addr
= client
->addr
;
363 msgs
[1].flags
= I2C_M_RD
;
365 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
367 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
368 if (ret
!= ARRAY_SIZE(msgs
))
369 return ret
< 0 ? ret
: -EIO
;
371 *val
= get_unaligned_be32(data_buf
);
376 static int ov2740_write_reg(struct ov2740
*ov2740
, u16 reg
, u16 len
, u32 val
)
378 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
385 put_unaligned_be16(reg
, buf
);
386 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
388 ret
= i2c_master_send(client
, buf
, len
+ 2);
390 return ret
< 0 ? ret
: -EIO
;
395 static int ov2740_write_reg_list(struct ov2740
*ov2740
,
396 const struct ov2740_reg_list
*r_list
)
398 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
402 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
403 ret
= ov2740_write_reg(ov2740
, r_list
->regs
[i
].address
, 1,
404 r_list
->regs
[i
].val
);
406 dev_err_ratelimited(&client
->dev
,
407 "write reg 0x%4.4x return err = %d",
408 r_list
->regs
[i
].address
, ret
);
416 static int ov2740_update_digital_gain(struct ov2740
*ov2740
, u32 d_gain
)
420 ret
= ov2740_write_reg(ov2740
, OV2740_REG_MWB_R_GAIN
, 2, d_gain
);
424 ret
= ov2740_write_reg(ov2740
, OV2740_REG_MWB_G_GAIN
, 2, d_gain
);
428 return ov2740_write_reg(ov2740
, OV2740_REG_MWB_B_GAIN
, 2, d_gain
);
431 static int ov2740_test_pattern(struct ov2740
*ov2740
, u32 pattern
)
434 pattern
= (pattern
- 1) << OV2740_TEST_PATTERN_BAR_SHIFT
|
435 OV2740_TEST_PATTERN_ENABLE
;
437 return ov2740_write_reg(ov2740
, OV2740_REG_TEST_PATTERN
, 1, pattern
);
440 static int ov2740_set_ctrl(struct v4l2_ctrl
*ctrl
)
442 struct ov2740
*ov2740
= container_of(ctrl
->handler
,
443 struct ov2740
, ctrl_handler
);
444 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
448 /* Propagate change of current control to all related controls */
449 if (ctrl
->id
== V4L2_CID_VBLANK
) {
450 /* Update max exposure while meeting expected vblanking */
451 exposure_max
= ov2740
->cur_mode
->height
+ ctrl
->val
-
452 OV2740_EXPOSURE_MAX_MARGIN
;
453 __v4l2_ctrl_modify_range(ov2740
->exposure
,
454 ov2740
->exposure
->minimum
,
455 exposure_max
, ov2740
->exposure
->step
,
459 /* V4L2 controls values will be applied only when power is already up */
460 if (!pm_runtime_get_if_in_use(&client
->dev
))
464 case V4L2_CID_ANALOGUE_GAIN
:
465 ret
= ov2740_write_reg(ov2740
, OV2740_REG_ANALOG_GAIN
, 2,
469 case V4L2_CID_DIGITAL_GAIN
:
470 ret
= ov2740_update_digital_gain(ov2740
, ctrl
->val
);
473 case V4L2_CID_EXPOSURE
:
474 /* 4 least significant bits of expsoure are fractional part */
475 ret
= ov2740_write_reg(ov2740
, OV2740_REG_EXPOSURE
, 3,
479 case V4L2_CID_VBLANK
:
480 ret
= ov2740_write_reg(ov2740
, OV2740_REG_VTS
, 2,
481 ov2740
->cur_mode
->height
+ ctrl
->val
);
484 case V4L2_CID_TEST_PATTERN
:
485 ret
= ov2740_test_pattern(ov2740
, ctrl
->val
);
493 pm_runtime_put(&client
->dev
);
498 static const struct v4l2_ctrl_ops ov2740_ctrl_ops
= {
499 .s_ctrl
= ov2740_set_ctrl
,
502 static int ov2740_init_controls(struct ov2740
*ov2740
)
504 struct v4l2_ctrl_handler
*ctrl_hdlr
;
505 const struct ov2740_mode
*cur_mode
;
506 s64 exposure_max
, h_blank
, pixel_rate
;
507 u32 vblank_min
, vblank_max
, vblank_default
;
511 ctrl_hdlr
= &ov2740
->ctrl_handler
;
512 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
516 ctrl_hdlr
->lock
= &ov2740
->mutex
;
517 cur_mode
= ov2740
->cur_mode
;
518 size
= ARRAY_SIZE(link_freq_menu_items
);
520 ov2740
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
, &ov2740_ctrl_ops
,
523 link_freq_menu_items
);
524 if (ov2740
->link_freq
)
525 ov2740
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
527 pixel_rate
= to_pixel_rate(OV2740_LINK_FREQ_360MHZ_INDEX
);
528 ov2740
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov2740_ctrl_ops
,
529 V4L2_CID_PIXEL_RATE
, 0,
530 pixel_rate
, 1, pixel_rate
);
532 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
533 vblank_max
= OV2740_VTS_MAX
- cur_mode
->height
;
534 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
535 ov2740
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov2740_ctrl_ops
,
536 V4L2_CID_VBLANK
, vblank_min
,
537 vblank_max
, 1, vblank_default
);
539 h_blank
= to_pixels_per_line(cur_mode
->hts
, cur_mode
->link_freq_index
);
540 h_blank
-= cur_mode
->width
;
541 ov2740
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov2740_ctrl_ops
,
542 V4L2_CID_HBLANK
, h_blank
, h_blank
, 1,
545 ov2740
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
547 v4l2_ctrl_new_std(ctrl_hdlr
, &ov2740_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
548 OV2740_ANAL_GAIN_MIN
, OV2740_ANAL_GAIN_MAX
,
549 OV2740_ANAL_GAIN_STEP
, OV2740_ANAL_GAIN_MIN
);
550 v4l2_ctrl_new_std(ctrl_hdlr
, &ov2740_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
551 OV2740_DGTL_GAIN_MIN
, OV2740_DGTL_GAIN_MAX
,
552 OV2740_DGTL_GAIN_STEP
, OV2740_DGTL_GAIN_DEFAULT
);
553 exposure_max
= cur_mode
->vts_def
- OV2740_EXPOSURE_MAX_MARGIN
;
554 ov2740
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov2740_ctrl_ops
,
556 OV2740_EXPOSURE_MIN
, exposure_max
,
557 OV2740_EXPOSURE_STEP
,
559 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &ov2740_ctrl_ops
,
560 V4L2_CID_TEST_PATTERN
,
561 ARRAY_SIZE(ov2740_test_pattern_menu
) - 1,
562 0, 0, ov2740_test_pattern_menu
);
563 if (ctrl_hdlr
->error
)
564 return ctrl_hdlr
->error
;
566 ov2740
->sd
.ctrl_handler
= ctrl_hdlr
;
571 static void ov2740_update_pad_format(const struct ov2740_mode
*mode
,
572 struct v4l2_mbus_framefmt
*fmt
)
574 fmt
->width
= mode
->width
;
575 fmt
->height
= mode
->height
;
576 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
577 fmt
->field
= V4L2_FIELD_NONE
;
580 static int ov2740_start_streaming(struct ov2740
*ov2740
)
582 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
583 const struct ov2740_reg_list
*reg_list
;
587 link_freq_index
= ov2740
->cur_mode
->link_freq_index
;
588 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
589 ret
= ov2740_write_reg_list(ov2740
, reg_list
);
591 dev_err(&client
->dev
, "failed to set plls");
595 reg_list
= &ov2740
->cur_mode
->reg_list
;
596 ret
= ov2740_write_reg_list(ov2740
, reg_list
);
598 dev_err(&client
->dev
, "failed to set mode");
602 ret
= __v4l2_ctrl_handler_setup(ov2740
->sd
.ctrl_handler
);
606 ret
= ov2740_write_reg(ov2740
, OV2740_REG_MODE_SELECT
, 1,
607 OV2740_MODE_STREAMING
);
609 dev_err(&client
->dev
, "failed to start streaming");
614 static void ov2740_stop_streaming(struct ov2740
*ov2740
)
616 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
618 if (ov2740_write_reg(ov2740
, OV2740_REG_MODE_SELECT
, 1,
619 OV2740_MODE_STANDBY
))
620 dev_err(&client
->dev
, "failed to stop streaming");
623 static int ov2740_set_stream(struct v4l2_subdev
*sd
, int enable
)
625 struct ov2740
*ov2740
= to_ov2740(sd
);
626 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
629 if (ov2740
->streaming
== enable
)
632 mutex_lock(&ov2740
->mutex
);
634 ret
= pm_runtime_get_sync(&client
->dev
);
636 pm_runtime_put_noidle(&client
->dev
);
637 mutex_unlock(&ov2740
->mutex
);
641 ret
= ov2740_start_streaming(ov2740
);
644 ov2740_stop_streaming(ov2740
);
645 pm_runtime_put(&client
->dev
);
648 ov2740_stop_streaming(ov2740
);
649 pm_runtime_put(&client
->dev
);
652 ov2740
->streaming
= enable
;
653 mutex_unlock(&ov2740
->mutex
);
658 static int __maybe_unused
ov2740_suspend(struct device
*dev
)
660 struct i2c_client
*client
= to_i2c_client(dev
);
661 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
662 struct ov2740
*ov2740
= to_ov2740(sd
);
664 mutex_lock(&ov2740
->mutex
);
665 if (ov2740
->streaming
)
666 ov2740_stop_streaming(ov2740
);
668 mutex_unlock(&ov2740
->mutex
);
673 static int __maybe_unused
ov2740_resume(struct device
*dev
)
675 struct i2c_client
*client
= to_i2c_client(dev
);
676 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
677 struct ov2740
*ov2740
= to_ov2740(sd
);
680 mutex_lock(&ov2740
->mutex
);
681 if (!ov2740
->streaming
)
684 ret
= ov2740_start_streaming(ov2740
);
686 ov2740
->streaming
= false;
687 ov2740_stop_streaming(ov2740
);
691 mutex_unlock(&ov2740
->mutex
);
695 static int ov2740_set_format(struct v4l2_subdev
*sd
,
696 struct v4l2_subdev_pad_config
*cfg
,
697 struct v4l2_subdev_format
*fmt
)
699 struct ov2740
*ov2740
= to_ov2740(sd
);
700 const struct ov2740_mode
*mode
;
701 s32 vblank_def
, h_blank
;
703 mode
= v4l2_find_nearest_size(supported_modes
,
704 ARRAY_SIZE(supported_modes
), width
,
705 height
, fmt
->format
.width
,
708 mutex_lock(&ov2740
->mutex
);
709 ov2740_update_pad_format(mode
, &fmt
->format
);
710 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
711 *v4l2_subdev_get_try_format(sd
, cfg
, fmt
->pad
) = fmt
->format
;
713 ov2740
->cur_mode
= mode
;
714 __v4l2_ctrl_s_ctrl(ov2740
->link_freq
, mode
->link_freq_index
);
715 __v4l2_ctrl_s_ctrl_int64(ov2740
->pixel_rate
,
716 to_pixel_rate(mode
->link_freq_index
));
718 /* Update limits and set FPS to default */
719 vblank_def
= mode
->vts_def
- mode
->height
;
720 __v4l2_ctrl_modify_range(ov2740
->vblank
,
721 mode
->vts_min
- mode
->height
,
722 OV2740_VTS_MAX
- mode
->height
, 1,
724 __v4l2_ctrl_s_ctrl(ov2740
->vblank
, vblank_def
);
725 h_blank
= to_pixels_per_line(mode
->hts
, mode
->link_freq_index
) -
727 __v4l2_ctrl_modify_range(ov2740
->hblank
, h_blank
, h_blank
, 1,
730 mutex_unlock(&ov2740
->mutex
);
735 static int ov2740_get_format(struct v4l2_subdev
*sd
,
736 struct v4l2_subdev_pad_config
*cfg
,
737 struct v4l2_subdev_format
*fmt
)
739 struct ov2740
*ov2740
= to_ov2740(sd
);
741 mutex_lock(&ov2740
->mutex
);
742 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
743 fmt
->format
= *v4l2_subdev_get_try_format(&ov2740
->sd
, cfg
,
746 ov2740_update_pad_format(ov2740
->cur_mode
, &fmt
->format
);
748 mutex_unlock(&ov2740
->mutex
);
753 static int ov2740_enum_mbus_code(struct v4l2_subdev
*sd
,
754 struct v4l2_subdev_pad_config
*cfg
,
755 struct v4l2_subdev_mbus_code_enum
*code
)
760 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
765 static int ov2740_enum_frame_size(struct v4l2_subdev
*sd
,
766 struct v4l2_subdev_pad_config
*cfg
,
767 struct v4l2_subdev_frame_size_enum
*fse
)
769 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
772 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
775 fse
->min_width
= supported_modes
[fse
->index
].width
;
776 fse
->max_width
= fse
->min_width
;
777 fse
->min_height
= supported_modes
[fse
->index
].height
;
778 fse
->max_height
= fse
->min_height
;
783 static int ov2740_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
785 struct ov2740
*ov2740
= to_ov2740(sd
);
787 mutex_lock(&ov2740
->mutex
);
788 ov2740_update_pad_format(&supported_modes
[0],
789 v4l2_subdev_get_try_format(sd
, fh
->pad
, 0));
790 mutex_unlock(&ov2740
->mutex
);
795 static const struct v4l2_subdev_video_ops ov2740_video_ops
= {
796 .s_stream
= ov2740_set_stream
,
799 static const struct v4l2_subdev_pad_ops ov2740_pad_ops
= {
800 .set_fmt
= ov2740_set_format
,
801 .get_fmt
= ov2740_get_format
,
802 .enum_mbus_code
= ov2740_enum_mbus_code
,
803 .enum_frame_size
= ov2740_enum_frame_size
,
806 static const struct v4l2_subdev_ops ov2740_subdev_ops
= {
807 .video
= &ov2740_video_ops
,
808 .pad
= &ov2740_pad_ops
,
811 static const struct media_entity_operations ov2740_subdev_entity_ops
= {
812 .link_validate
= v4l2_subdev_link_validate
,
815 static const struct v4l2_subdev_internal_ops ov2740_internal_ops
= {
819 static int ov2740_identify_module(struct ov2740
*ov2740
)
821 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2740
->sd
);
825 ret
= ov2740_read_reg(ov2740
, OV2740_REG_CHIP_ID
, 3, &val
);
829 if (val
!= OV2740_CHIP_ID
) {
830 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
831 OV2740_CHIP_ID
, val
);
838 static int ov2740_check_hwcfg(struct device
*dev
)
840 struct fwnode_handle
*ep
;
841 struct fwnode_handle
*fwnode
= dev_fwnode(dev
);
842 struct v4l2_fwnode_endpoint bus_cfg
= {
843 .bus_type
= V4L2_MBUS_CSI2_DPHY
852 ret
= fwnode_property_read_u32(fwnode
, "clock-frequency", &mclk
);
856 if (mclk
!= OV2740_MCLK
) {
857 dev_err(dev
, "external clock %d is not supported", mclk
);
861 ep
= fwnode_graph_get_next_endpoint(fwnode
, NULL
);
865 ret
= v4l2_fwnode_endpoint_alloc_parse(ep
, &bus_cfg
);
866 fwnode_handle_put(ep
);
870 if (bus_cfg
.bus
.mipi_csi2
.num_data_lanes
!= OV2740_DATA_LANES
) {
871 dev_err(dev
, "number of CSI2 data lanes %d is not supported",
872 bus_cfg
.bus
.mipi_csi2
.num_data_lanes
);
874 goto check_hwcfg_error
;
877 if (!bus_cfg
.nr_of_link_frequencies
) {
878 dev_err(dev
, "no link frequencies defined");
880 goto check_hwcfg_error
;
883 for (i
= 0; i
< ARRAY_SIZE(link_freq_menu_items
); i
++) {
884 for (j
= 0; j
< bus_cfg
.nr_of_link_frequencies
; j
++) {
885 if (link_freq_menu_items
[i
] ==
886 bus_cfg
.link_frequencies
[j
])
890 if (j
== bus_cfg
.nr_of_link_frequencies
) {
891 dev_err(dev
, "no link frequency %lld supported",
892 link_freq_menu_items
[i
]);
894 goto check_hwcfg_error
;
899 v4l2_fwnode_endpoint_free(&bus_cfg
);
904 static int ov2740_remove(struct i2c_client
*client
)
906 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
907 struct ov2740
*ov2740
= to_ov2740(sd
);
909 v4l2_async_unregister_subdev(sd
);
910 media_entity_cleanup(&sd
->entity
);
911 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
912 pm_runtime_disable(&client
->dev
);
913 mutex_destroy(&ov2740
->mutex
);
918 static int ov2740_probe(struct i2c_client
*client
)
920 struct ov2740
*ov2740
;
923 ret
= ov2740_check_hwcfg(&client
->dev
);
925 dev_err(&client
->dev
, "failed to check HW configuration: %d",
930 ov2740
= devm_kzalloc(&client
->dev
, sizeof(*ov2740
), GFP_KERNEL
);
934 v4l2_i2c_subdev_init(&ov2740
->sd
, client
, &ov2740_subdev_ops
);
935 ret
= ov2740_identify_module(ov2740
);
937 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
941 mutex_init(&ov2740
->mutex
);
942 ov2740
->cur_mode
= &supported_modes
[0];
943 ret
= ov2740_init_controls(ov2740
);
945 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
946 goto probe_error_v4l2_ctrl_handler_free
;
949 ov2740
->sd
.internal_ops
= &ov2740_internal_ops
;
950 ov2740
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
951 ov2740
->sd
.entity
.ops
= &ov2740_subdev_entity_ops
;
952 ov2740
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
953 ov2740
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
954 ret
= media_entity_pads_init(&ov2740
->sd
.entity
, 1, &ov2740
->pad
);
956 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
957 goto probe_error_v4l2_ctrl_handler_free
;
960 ret
= v4l2_async_register_subdev_sensor_common(&ov2740
->sd
);
962 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
964 goto probe_error_media_entity_cleanup
;
968 * Device is already turned on by i2c-core with ACPI domain PM.
969 * Enable runtime PM and turn off the device.
971 pm_runtime_set_active(&client
->dev
);
972 pm_runtime_enable(&client
->dev
);
973 pm_runtime_idle(&client
->dev
);
977 probe_error_media_entity_cleanup
:
978 media_entity_cleanup(&ov2740
->sd
.entity
);
980 probe_error_v4l2_ctrl_handler_free
:
981 v4l2_ctrl_handler_free(ov2740
->sd
.ctrl_handler
);
982 mutex_destroy(&ov2740
->mutex
);
987 static const struct dev_pm_ops ov2740_pm_ops
= {
988 SET_SYSTEM_SLEEP_PM_OPS(ov2740_suspend
, ov2740_resume
)
992 static const struct acpi_device_id ov2740_acpi_ids
[] = {
997 MODULE_DEVICE_TABLE(acpi
, ov2740_acpi_ids
);
1000 static struct i2c_driver ov2740_i2c_driver
= {
1003 .pm
= &ov2740_pm_ops
,
1004 .acpi_match_table
= ACPI_PTR(ov2740_acpi_ids
),
1006 .probe_new
= ov2740_probe
,
1007 .remove
= ov2740_remove
,
1010 module_i2c_driver(ov2740_i2c_driver
);
1012 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
1013 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
1014 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
1015 MODULE_DESCRIPTION("OmniVision OV2740 sensor driver");
1016 MODULE_LICENSE("GPL v2");