1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 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 HI556_REG_VALUE_08BIT 1
15 #define HI556_REG_VALUE_16BIT 2
16 #define HI556_REG_VALUE_24BIT 3
18 #define HI556_LINK_FREQ_437MHZ 437000000ULL
19 #define HI556_MCLK 19200000
20 #define HI556_DATA_LANES 2
21 #define HI556_RGB_DEPTH 10
23 #define HI556_REG_CHIP_ID 0x0f16
24 #define HI556_CHIP_ID 0x0556
26 #define HI556_REG_MODE_SELECT 0x0a00
27 #define HI556_MODE_STANDBY 0x0000
28 #define HI556_MODE_STREAMING 0x0100
30 /* vertical-timings from sensor */
31 #define HI556_REG_FLL 0x0006
32 #define HI556_FLL_30FPS 0x0814
33 #define HI556_FLL_30FPS_MIN 0x0814
34 #define HI556_FLL_MAX 0x7fff
36 /* horizontal-timings from sensor */
37 #define HI556_REG_LLP 0x0008
39 /* Exposure controls from sensor */
40 #define HI556_REG_EXPOSURE 0x0074
41 #define HI556_EXPOSURE_MIN 6
42 #define HI556_EXPOSURE_MAX_MARGIN 2
43 #define HI556_EXPOSURE_STEP 1
45 /* Analog gain controls from sensor */
46 #define HI556_REG_ANALOG_GAIN 0x0077
47 #define HI556_ANAL_GAIN_MIN 0
48 #define HI556_ANAL_GAIN_MAX 240
49 #define HI556_ANAL_GAIN_STEP 1
51 /* Digital gain controls from sensor */
52 #define HI556_REG_MWB_GR_GAIN 0x0078
53 #define HI556_REG_MWB_GB_GAIN 0x007a
54 #define HI556_REG_MWB_R_GAIN 0x007c
55 #define HI556_REG_MWB_B_GAIN 0x007e
56 #define HI556_DGTL_GAIN_MIN 0
57 #define HI556_DGTL_GAIN_MAX 2048
58 #define HI556_DGTL_GAIN_STEP 1
59 #define HI556_DGTL_GAIN_DEFAULT 256
61 /* Test Pattern Control */
62 #define HI556_REG_ISP 0X0a05
63 #define HI556_REG_ISP_TPG_EN 0x01
64 #define HI556_REG_TEST_PATTERN 0x0201
67 HI556_LINK_FREQ_437MHZ_INDEX
,
75 struct hi556_reg_list
{
77 const struct hi556_reg
*regs
;
80 struct hi556_link_freq_config
{
81 const struct hi556_reg_list reg_list
;
85 /* Frame width in pixels */
88 /* Frame height in pixels */
91 /* Horizontal timining size */
94 /* Default vertical timining size */
97 /* Min vertical timining size */
100 /* Link frequency needed for this resolution */
103 /* Sensor register settings for this resolution */
104 const struct hi556_reg_list reg_list
;
107 #define to_hi556(_sd) container_of(_sd, struct hi556, sd)
109 //SENSOR_INITIALIZATION
110 static const struct hi556_reg mipi_data_rate_874mbps
[] = {
336 static const struct hi556_reg mode_2592x1944_regs
[] = {
381 static const struct hi556_reg mode_1296x972_regs
[] = {
426 static const char * const hi556_test_pattern_menu
[] = {
430 "Fade To Grey Colour Bars",
432 "Gradient Horizontal",
438 static const s64 link_freq_menu_items
[] = {
439 HI556_LINK_FREQ_437MHZ
,
442 static const struct hi556_link_freq_config link_freq_configs
[] = {
443 [HI556_LINK_FREQ_437MHZ_INDEX
] = {
445 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_874mbps
),
446 .regs
= mipi_data_rate_874mbps
,
451 static const struct hi556_mode supported_modes
[] = {
455 .fll_def
= HI556_FLL_30FPS
,
456 .fll_min
= HI556_FLL_30FPS_MIN
,
459 .num_of_regs
= ARRAY_SIZE(mode_2592x1944_regs
),
460 .regs
= mode_2592x1944_regs
,
462 .link_freq_index
= HI556_LINK_FREQ_437MHZ_INDEX
,
467 .fll_def
= HI556_FLL_30FPS
,
468 .fll_min
= HI556_FLL_30FPS_MIN
,
471 .num_of_regs
= ARRAY_SIZE(mode_1296x972_regs
),
472 .regs
= mode_1296x972_regs
,
474 .link_freq_index
= HI556_LINK_FREQ_437MHZ_INDEX
,
479 struct v4l2_subdev sd
;
480 struct media_pad pad
;
481 struct v4l2_ctrl_handler ctrl_handler
;
484 struct v4l2_ctrl
*link_freq
;
485 struct v4l2_ctrl
*pixel_rate
;
486 struct v4l2_ctrl
*vblank
;
487 struct v4l2_ctrl
*hblank
;
488 struct v4l2_ctrl
*exposure
;
491 const struct hi556_mode
*cur_mode
;
493 /* To serialize asynchronus callbacks */
496 /* Streaming on/off */
500 static u64
to_pixel_rate(u32 f_index
)
502 u64 pixel_rate
= link_freq_menu_items
[f_index
] * 2 * HI556_DATA_LANES
;
504 do_div(pixel_rate
, HI556_RGB_DEPTH
);
509 static int hi556_read_reg(struct hi556
*hi556
, u16 reg
, u16 len
, u32
*val
)
511 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
512 struct i2c_msg msgs
[2];
514 u8 data_buf
[4] = {0};
520 put_unaligned_be16(reg
, addr_buf
);
521 msgs
[0].addr
= client
->addr
;
523 msgs
[0].len
= sizeof(addr_buf
);
524 msgs
[0].buf
= addr_buf
;
525 msgs
[1].addr
= client
->addr
;
526 msgs
[1].flags
= I2C_M_RD
;
528 msgs
[1].buf
= &data_buf
[4 - len
];
530 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
531 if (ret
!= ARRAY_SIZE(msgs
))
534 *val
= get_unaligned_be32(data_buf
);
539 static int hi556_write_reg(struct hi556
*hi556
, u16 reg
, u16 len
, u32 val
)
541 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
547 put_unaligned_be16(reg
, buf
);
548 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
549 if (i2c_master_send(client
, buf
, len
+ 2) != len
+ 2)
555 static int hi556_write_reg_list(struct hi556
*hi556
,
556 const struct hi556_reg_list
*r_list
)
558 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
562 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
563 ret
= hi556_write_reg(hi556
, r_list
->regs
[i
].address
,
564 HI556_REG_VALUE_16BIT
,
565 r_list
->regs
[i
].val
);
567 dev_err_ratelimited(&client
->dev
,
568 "failed to write reg 0x%4.4x. error = %d",
569 r_list
->regs
[i
].address
, ret
);
577 static int hi556_update_digital_gain(struct hi556
*hi556
, u32 d_gain
)
581 ret
= hi556_write_reg(hi556
, HI556_REG_MWB_GR_GAIN
,
582 HI556_REG_VALUE_16BIT
, d_gain
);
586 ret
= hi556_write_reg(hi556
, HI556_REG_MWB_GB_GAIN
,
587 HI556_REG_VALUE_16BIT
, d_gain
);
591 ret
= hi556_write_reg(hi556
, HI556_REG_MWB_R_GAIN
,
592 HI556_REG_VALUE_16BIT
, d_gain
);
596 return hi556_write_reg(hi556
, HI556_REG_MWB_B_GAIN
,
597 HI556_REG_VALUE_16BIT
, d_gain
);
600 static int hi556_test_pattern(struct hi556
*hi556
, u32 pattern
)
606 ret
= hi556_read_reg(hi556
, HI556_REG_ISP
,
607 HI556_REG_VALUE_08BIT
, &val
);
611 ret
= hi556_write_reg(hi556
, HI556_REG_ISP
,
612 HI556_REG_VALUE_08BIT
,
613 val
| HI556_REG_ISP_TPG_EN
);
618 return hi556_write_reg(hi556
, HI556_REG_TEST_PATTERN
,
619 HI556_REG_VALUE_08BIT
, pattern
);
622 static int hi556_set_ctrl(struct v4l2_ctrl
*ctrl
)
624 struct hi556
*hi556
= container_of(ctrl
->handler
,
625 struct hi556
, ctrl_handler
);
626 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
630 /* Propagate change of current control to all related controls */
631 if (ctrl
->id
== V4L2_CID_VBLANK
) {
632 /* Update max exposure while meeting expected vblanking */
633 exposure_max
= hi556
->cur_mode
->height
+ ctrl
->val
-
634 HI556_EXPOSURE_MAX_MARGIN
;
635 __v4l2_ctrl_modify_range(hi556
->exposure
,
636 hi556
->exposure
->minimum
,
637 exposure_max
, hi556
->exposure
->step
,
641 /* V4L2 controls values will be applied only when power is already up */
642 if (!pm_runtime_get_if_in_use(&client
->dev
))
646 case V4L2_CID_ANALOGUE_GAIN
:
647 ret
= hi556_write_reg(hi556
, HI556_REG_ANALOG_GAIN
,
648 HI556_REG_VALUE_16BIT
, ctrl
->val
);
651 case V4L2_CID_DIGITAL_GAIN
:
652 ret
= hi556_update_digital_gain(hi556
, ctrl
->val
);
655 case V4L2_CID_EXPOSURE
:
656 ret
= hi556_write_reg(hi556
, HI556_REG_EXPOSURE
,
657 HI556_REG_VALUE_16BIT
, ctrl
->val
);
660 case V4L2_CID_VBLANK
:
661 /* Update FLL that meets expected vertical blanking */
662 ret
= hi556_write_reg(hi556
, HI556_REG_FLL
,
663 HI556_REG_VALUE_16BIT
,
664 hi556
->cur_mode
->height
+ ctrl
->val
);
667 case V4L2_CID_TEST_PATTERN
:
668 ret
= hi556_test_pattern(hi556
, ctrl
->val
);
676 pm_runtime_put(&client
->dev
);
681 static const struct v4l2_ctrl_ops hi556_ctrl_ops
= {
682 .s_ctrl
= hi556_set_ctrl
,
685 static int hi556_init_controls(struct hi556
*hi556
)
687 struct v4l2_ctrl_handler
*ctrl_hdlr
;
688 s64 exposure_max
, h_blank
;
691 ctrl_hdlr
= &hi556
->ctrl_handler
;
692 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
696 ctrl_hdlr
->lock
= &hi556
->mutex
;
697 hi556
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
, &hi556_ctrl_ops
,
699 ARRAY_SIZE(link_freq_menu_items
) - 1,
700 0, link_freq_menu_items
);
701 if (hi556
->link_freq
)
702 hi556
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
704 hi556
->pixel_rate
= v4l2_ctrl_new_std
705 (ctrl_hdlr
, &hi556_ctrl_ops
,
706 V4L2_CID_PIXEL_RATE
, 0,
707 to_pixel_rate(HI556_LINK_FREQ_437MHZ_INDEX
),
709 to_pixel_rate(HI556_LINK_FREQ_437MHZ_INDEX
));
710 hi556
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &hi556_ctrl_ops
,
712 hi556
->cur_mode
->fll_min
-
713 hi556
->cur_mode
->height
,
715 hi556
->cur_mode
->height
, 1,
716 hi556
->cur_mode
->fll_def
-
717 hi556
->cur_mode
->height
);
719 h_blank
= hi556
->cur_mode
->llp
- hi556
->cur_mode
->width
;
721 hi556
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &hi556_ctrl_ops
,
722 V4L2_CID_HBLANK
, h_blank
, h_blank
, 1,
725 hi556
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
727 v4l2_ctrl_new_std(ctrl_hdlr
, &hi556_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
728 HI556_ANAL_GAIN_MIN
, HI556_ANAL_GAIN_MAX
,
729 HI556_ANAL_GAIN_STEP
, HI556_ANAL_GAIN_MIN
);
730 v4l2_ctrl_new_std(ctrl_hdlr
, &hi556_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
731 HI556_DGTL_GAIN_MIN
, HI556_DGTL_GAIN_MAX
,
732 HI556_DGTL_GAIN_STEP
, HI556_DGTL_GAIN_DEFAULT
);
733 exposure_max
= hi556
->cur_mode
->fll_def
- HI556_EXPOSURE_MAX_MARGIN
;
734 hi556
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &hi556_ctrl_ops
,
736 HI556_EXPOSURE_MIN
, exposure_max
,
739 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &hi556_ctrl_ops
,
740 V4L2_CID_TEST_PATTERN
,
741 ARRAY_SIZE(hi556_test_pattern_menu
) - 1,
742 0, 0, hi556_test_pattern_menu
);
743 if (ctrl_hdlr
->error
)
744 return ctrl_hdlr
->error
;
746 hi556
->sd
.ctrl_handler
= ctrl_hdlr
;
751 static void hi556_assign_pad_format(const struct hi556_mode
*mode
,
752 struct v4l2_mbus_framefmt
*fmt
)
754 fmt
->width
= mode
->width
;
755 fmt
->height
= mode
->height
;
756 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
757 fmt
->field
= V4L2_FIELD_NONE
;
760 static int hi556_start_streaming(struct hi556
*hi556
)
762 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
763 const struct hi556_reg_list
*reg_list
;
764 int link_freq_index
, ret
;
766 link_freq_index
= hi556
->cur_mode
->link_freq_index
;
767 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
768 ret
= hi556_write_reg_list(hi556
, reg_list
);
770 dev_err(&client
->dev
, "failed to set plls");
774 reg_list
= &hi556
->cur_mode
->reg_list
;
775 ret
= hi556_write_reg_list(hi556
, reg_list
);
777 dev_err(&client
->dev
, "failed to set mode");
781 ret
= __v4l2_ctrl_handler_setup(hi556
->sd
.ctrl_handler
);
785 ret
= hi556_write_reg(hi556
, HI556_REG_MODE_SELECT
,
786 HI556_REG_VALUE_16BIT
, HI556_MODE_STREAMING
);
789 dev_err(&client
->dev
, "failed to set stream");
796 static void hi556_stop_streaming(struct hi556
*hi556
)
798 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
800 if (hi556_write_reg(hi556
, HI556_REG_MODE_SELECT
,
801 HI556_REG_VALUE_16BIT
, HI556_MODE_STANDBY
))
802 dev_err(&client
->dev
, "failed to set stream");
805 static int hi556_set_stream(struct v4l2_subdev
*sd
, int enable
)
807 struct hi556
*hi556
= to_hi556(sd
);
808 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
811 if (hi556
->streaming
== enable
)
814 mutex_lock(&hi556
->mutex
);
816 ret
= pm_runtime_get_sync(&client
->dev
);
818 pm_runtime_put_noidle(&client
->dev
);
819 mutex_unlock(&hi556
->mutex
);
823 ret
= hi556_start_streaming(hi556
);
826 hi556_stop_streaming(hi556
);
827 pm_runtime_put(&client
->dev
);
830 hi556_stop_streaming(hi556
);
831 pm_runtime_put(&client
->dev
);
834 hi556
->streaming
= enable
;
835 mutex_unlock(&hi556
->mutex
);
840 static int __maybe_unused
hi556_suspend(struct device
*dev
)
842 struct v4l2_subdev
*sd
= dev_get_drvdata(dev
);
843 struct hi556
*hi556
= to_hi556(sd
);
845 mutex_lock(&hi556
->mutex
);
846 if (hi556
->streaming
)
847 hi556_stop_streaming(hi556
);
849 mutex_unlock(&hi556
->mutex
);
854 static int __maybe_unused
hi556_resume(struct device
*dev
)
856 struct v4l2_subdev
*sd
= dev_get_drvdata(dev
);
857 struct hi556
*hi556
= to_hi556(sd
);
860 mutex_lock(&hi556
->mutex
);
861 if (hi556
->streaming
) {
862 ret
= hi556_start_streaming(hi556
);
867 mutex_unlock(&hi556
->mutex
);
872 hi556_stop_streaming(hi556
);
873 hi556
->streaming
= 0;
874 mutex_unlock(&hi556
->mutex
);
878 static int hi556_set_format(struct v4l2_subdev
*sd
,
879 struct v4l2_subdev_pad_config
*cfg
,
880 struct v4l2_subdev_format
*fmt
)
882 struct hi556
*hi556
= to_hi556(sd
);
883 const struct hi556_mode
*mode
;
884 s32 vblank_def
, h_blank
;
886 mode
= v4l2_find_nearest_size(supported_modes
,
887 ARRAY_SIZE(supported_modes
), width
,
888 height
, fmt
->format
.width
,
891 mutex_lock(&hi556
->mutex
);
892 hi556_assign_pad_format(mode
, &fmt
->format
);
893 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
894 *v4l2_subdev_get_try_format(sd
, cfg
, fmt
->pad
) = fmt
->format
;
896 hi556
->cur_mode
= mode
;
897 __v4l2_ctrl_s_ctrl(hi556
->link_freq
, mode
->link_freq_index
);
898 __v4l2_ctrl_s_ctrl_int64(hi556
->pixel_rate
,
899 to_pixel_rate(mode
->link_freq_index
));
901 /* Update limits and set FPS to default */
902 vblank_def
= mode
->fll_def
- mode
->height
;
903 __v4l2_ctrl_modify_range(hi556
->vblank
,
904 mode
->fll_min
- mode
->height
,
905 HI556_FLL_MAX
- mode
->height
, 1,
907 __v4l2_ctrl_s_ctrl(hi556
->vblank
, vblank_def
);
909 h_blank
= hi556
->cur_mode
->llp
- hi556
->cur_mode
->width
;
911 __v4l2_ctrl_modify_range(hi556
->hblank
, h_blank
, h_blank
, 1,
915 mutex_unlock(&hi556
->mutex
);
920 static int hi556_get_format(struct v4l2_subdev
*sd
,
921 struct v4l2_subdev_pad_config
*cfg
,
922 struct v4l2_subdev_format
*fmt
)
924 struct hi556
*hi556
= to_hi556(sd
);
926 mutex_lock(&hi556
->mutex
);
927 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
928 fmt
->format
= *v4l2_subdev_get_try_format(&hi556
->sd
, cfg
,
931 hi556_assign_pad_format(hi556
->cur_mode
, &fmt
->format
);
933 mutex_unlock(&hi556
->mutex
);
938 static int hi556_enum_mbus_code(struct v4l2_subdev
*sd
,
939 struct v4l2_subdev_pad_config
*cfg
,
940 struct v4l2_subdev_mbus_code_enum
*code
)
945 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
950 static int hi556_enum_frame_size(struct v4l2_subdev
*sd
,
951 struct v4l2_subdev_pad_config
*cfg
,
952 struct v4l2_subdev_frame_size_enum
*fse
)
954 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
957 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
960 fse
->min_width
= supported_modes
[fse
->index
].width
;
961 fse
->max_width
= fse
->min_width
;
962 fse
->min_height
= supported_modes
[fse
->index
].height
;
963 fse
->max_height
= fse
->min_height
;
968 static int hi556_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
970 struct hi556
*hi556
= to_hi556(sd
);
972 mutex_lock(&hi556
->mutex
);
973 hi556_assign_pad_format(&supported_modes
[0],
974 v4l2_subdev_get_try_format(sd
, fh
->pad
, 0));
975 mutex_unlock(&hi556
->mutex
);
980 static const struct v4l2_subdev_video_ops hi556_video_ops
= {
981 .s_stream
= hi556_set_stream
,
984 static const struct v4l2_subdev_pad_ops hi556_pad_ops
= {
985 .set_fmt
= hi556_set_format
,
986 .get_fmt
= hi556_get_format
,
987 .enum_mbus_code
= hi556_enum_mbus_code
,
988 .enum_frame_size
= hi556_enum_frame_size
,
991 static const struct v4l2_subdev_ops hi556_subdev_ops
= {
992 .video
= &hi556_video_ops
,
993 .pad
= &hi556_pad_ops
,
996 static const struct media_entity_operations hi556_subdev_entity_ops
= {
997 .link_validate
= v4l2_subdev_link_validate
,
1000 static const struct v4l2_subdev_internal_ops hi556_internal_ops
= {
1004 static int hi556_identify_module(struct hi556
*hi556
)
1006 struct i2c_client
*client
= v4l2_get_subdevdata(&hi556
->sd
);
1010 ret
= hi556_read_reg(hi556
, HI556_REG_CHIP_ID
,
1011 HI556_REG_VALUE_16BIT
, &val
);
1015 if (val
!= HI556_CHIP_ID
) {
1016 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
1017 HI556_CHIP_ID
, val
);
1024 static int hi556_check_hwcfg(struct device
*dev
)
1026 struct fwnode_handle
*ep
;
1027 struct fwnode_handle
*fwnode
= dev_fwnode(dev
);
1028 struct v4l2_fwnode_endpoint bus_cfg
= {
1029 .bus_type
= V4L2_MBUS_CSI2_DPHY
1038 ret
= fwnode_property_read_u32(fwnode
, "clock-frequency", &mclk
);
1040 dev_err(dev
, "can't get clock frequency");
1044 if (mclk
!= HI556_MCLK
) {
1045 dev_err(dev
, "external clock %d is not supported", mclk
);
1049 ep
= fwnode_graph_get_next_endpoint(fwnode
, NULL
);
1053 ret
= v4l2_fwnode_endpoint_alloc_parse(ep
, &bus_cfg
);
1054 fwnode_handle_put(ep
);
1058 if (bus_cfg
.bus
.mipi_csi2
.num_data_lanes
!= 2) {
1059 dev_err(dev
, "number of CSI2 data lanes %d is not supported",
1060 bus_cfg
.bus
.mipi_csi2
.num_data_lanes
);
1062 goto check_hwcfg_error
;
1065 if (!bus_cfg
.nr_of_link_frequencies
) {
1066 dev_err(dev
, "no link frequencies defined");
1068 goto check_hwcfg_error
;
1071 for (i
= 0; i
< ARRAY_SIZE(link_freq_menu_items
); i
++) {
1072 for (j
= 0; j
< bus_cfg
.nr_of_link_frequencies
; j
++) {
1073 if (link_freq_menu_items
[i
] ==
1074 bus_cfg
.link_frequencies
[j
])
1078 if (j
== bus_cfg
.nr_of_link_frequencies
) {
1079 dev_err(dev
, "no link frequency %lld supported",
1080 link_freq_menu_items
[i
]);
1082 goto check_hwcfg_error
;
1087 v4l2_fwnode_endpoint_free(&bus_cfg
);
1092 static int hi556_remove(struct i2c_client
*client
)
1094 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1095 struct hi556
*hi556
= to_hi556(sd
);
1097 v4l2_async_unregister_subdev(sd
);
1098 media_entity_cleanup(&sd
->entity
);
1099 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
1100 pm_runtime_disable(&client
->dev
);
1101 mutex_destroy(&hi556
->mutex
);
1106 static int hi556_probe(struct i2c_client
*client
)
1108 struct hi556
*hi556
;
1111 ret
= hi556_check_hwcfg(&client
->dev
);
1113 dev_err(&client
->dev
, "failed to check HW configuration: %d",
1118 hi556
= devm_kzalloc(&client
->dev
, sizeof(*hi556
), GFP_KERNEL
);
1122 v4l2_i2c_subdev_init(&hi556
->sd
, client
, &hi556_subdev_ops
);
1123 ret
= hi556_identify_module(hi556
);
1125 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
1129 mutex_init(&hi556
->mutex
);
1130 hi556
->cur_mode
= &supported_modes
[0];
1131 ret
= hi556_init_controls(hi556
);
1133 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
1134 goto probe_error_v4l2_ctrl_handler_free
;
1137 hi556
->sd
.internal_ops
= &hi556_internal_ops
;
1138 hi556
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
1139 hi556
->sd
.entity
.ops
= &hi556_subdev_entity_ops
;
1140 hi556
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
1141 hi556
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1142 ret
= media_entity_pads_init(&hi556
->sd
.entity
, 1, &hi556
->pad
);
1144 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
1145 goto probe_error_v4l2_ctrl_handler_free
;
1148 ret
= v4l2_async_register_subdev_sensor_common(&hi556
->sd
);
1150 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
1152 goto probe_error_media_entity_cleanup
;
1155 pm_runtime_set_active(&client
->dev
);
1156 pm_runtime_enable(&client
->dev
);
1157 pm_runtime_idle(&client
->dev
);
1161 probe_error_media_entity_cleanup
:
1162 media_entity_cleanup(&hi556
->sd
.entity
);
1164 probe_error_v4l2_ctrl_handler_free
:
1165 v4l2_ctrl_handler_free(hi556
->sd
.ctrl_handler
);
1166 mutex_destroy(&hi556
->mutex
);
1171 static const struct dev_pm_ops hi556_pm_ops
= {
1172 SET_SYSTEM_SLEEP_PM_OPS(hi556_suspend
, hi556_resume
)
1176 static const struct acpi_device_id hi556_acpi_ids
[] = {
1181 MODULE_DEVICE_TABLE(acpi
, hi556_acpi_ids
);
1184 static struct i2c_driver hi556_i2c_driver
= {
1187 .pm
= &hi556_pm_ops
,
1188 .acpi_match_table
= ACPI_PTR(hi556_acpi_ids
),
1190 .probe_new
= hi556_probe
,
1191 .remove
= hi556_remove
,
1194 module_i2c_driver(hi556_i2c_driver
);
1196 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
1197 MODULE_DESCRIPTION("Hynix HI556 sensor driver");
1198 MODULE_LICENSE("GPL v2");