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 <media/v4l2-ctrls.h>
11 #include <media/v4l2-device.h>
12 #include <media/v4l2-fwnode.h>
13 #include "power_ctrl_logic.h"
15 #define HM11B1_LINK_FREQ_384MHZ 384000000ULL
16 #define HM11B1_SCLK 72000000LL
17 #define HM11B1_MCLK 19200000
18 #define HM11B1_DATA_LANES 1
19 #define HM11B1_RGB_DEPTH 10
21 #define HM11B1_REG_CHIP_ID 0x0000
22 #define HM11B1_CHIP_ID 0x11B1
24 #define HM11B1_REG_MODE_SELECT 0x0100
25 #define HM11B1_MODE_STANDBY 0x00
26 #define HM11B1_MODE_STREAMING 0x01
28 /* vertical-timings from sensor */
29 #define HM11B1_REG_VTS 0x3402
30 #define HM11B1_VTS_DEF 0x037d
31 #define HM11B1_VTS_MIN 0x0346
32 #define HM11B1_VTS_MAX 0xffff
34 /* horizontal-timings from sensor */
35 #define HM11B1_REG_HTS 0x3404
37 /* Exposure controls from sensor */
38 #define HM11B1_REG_EXPOSURE 0x0202
39 #define HM11B1_EXPOSURE_MIN 2
40 #define HM11B1_EXPOSURE_MAX_MARGIN 2
41 #define HM11B1_EXPOSURE_STEP 1
43 /* Analog gain controls from sensor */
44 #define HM11B1_REG_ANALOG_GAIN 0x0205
45 #define HM11B1_ANAL_GAIN_MIN 0
46 #define HM11B1_ANAL_GAIN_MAX 0x50
47 #define HM11B1_ANAL_GAIN_STEP 1
49 /* Digital gain controls from sensor */
50 #define HM11B1_REG_DGTL_GAIN 0x0207
51 #define HM11B1_DGTL_GAIN_MIN 0x0
52 #define HM11B1_DGTL_GAIN_MAX 0x0200
53 #define HM11B1_DGTL_GAIN_STEP 1
54 #define HM11B1_DGTL_GAIN_DEFAULT 0x0100
56 /* Test Pattern Control */
57 #define HM11B1_REG_TEST_PATTERN 0x0601
58 #define HM11B1_TEST_PATTERN_ENABLE 1
59 #define HM11B1_TEST_PATTERN_BAR_SHIFT 1
62 HM11B1_LINK_FREQ_384MHZ_INDEX
,
70 struct hm11b1_reg_list
{
72 const struct hm11b1_reg
*regs
;
75 struct hm11b1_link_freq_config
{
76 const struct hm11b1_reg_list reg_list
;
80 /* Frame width in pixels */
83 /* Frame height in pixels */
86 /* Horizontal timining size */
89 /* Default vertical timining size */
92 /* Min vertical timining size */
95 /* Link frequency needed for this resolution */
98 /* Sensor register settings for this resolution */
99 const struct hm11b1_reg_list reg_list
;
102 static const struct hm11b1_reg mipi_data_rate_384mbps
[] = {
105 //RAW 10bit 1292x800_30fps_MIPI 384Mbps/lane
106 static const struct hm11b1_reg sensor_1292x800_30fps_setting
[] = {
398 //RAW 10bit 1292x800_60fps_MIPI 384Mbps/lane
399 static const struct hm11b1_reg sensor_1292x800_60fps_setting
[] = {
691 static const char * const hm11b1_test_pattern_menu
[] = {
695 "Color Bar Blending",
699 static const s64 link_freq_menu_items
[] = {
700 HM11B1_LINK_FREQ_384MHZ
,
703 static const struct hm11b1_link_freq_config link_freq_configs
[] = {
704 [HM11B1_LINK_FREQ_384MHZ_INDEX
] = {
706 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_384mbps
),
707 .regs
= mipi_data_rate_384mbps
,
712 static const struct hm11b1_mode supported_modes
[] = {
717 .vts_def
= HM11B1_VTS_DEF
,
718 .vts_min
= HM11B1_VTS_MIN
,
721 ARRAY_SIZE(sensor_1292x800_30fps_setting
),
722 .regs
= sensor_1292x800_30fps_setting
,
724 .link_freq_index
= HM11B1_LINK_FREQ_384MHZ_INDEX
,
729 struct v4l2_subdev sd
;
730 struct media_pad pad
;
731 struct v4l2_ctrl_handler ctrl_handler
;
734 struct v4l2_ctrl
*link_freq
;
735 struct v4l2_ctrl
*pixel_rate
;
736 struct v4l2_ctrl
*vblank
;
737 struct v4l2_ctrl
*hblank
;
738 struct v4l2_ctrl
*exposure
;
741 const struct hm11b1_mode
*cur_mode
;
743 /* To serialize asynchronus callbacks */
746 /* Streaming on/off */
750 static inline struct hm11b1
*to_hm11b1(struct v4l2_subdev
*subdev
)
752 return container_of(subdev
, struct hm11b1
, sd
);
755 static u64
to_pixel_rate(u32 f_index
)
757 u64 pixel_rate
= link_freq_menu_items
[f_index
] * 2 * HM11B1_DATA_LANES
;
759 do_div(pixel_rate
, HM11B1_RGB_DEPTH
);
764 static u64
to_pixels_per_line(u32 hts
, u32 f_index
)
766 u64 ppl
= hts
* to_pixel_rate(f_index
);
768 do_div(ppl
, HM11B1_SCLK
);
773 static int hm11b1_read_reg(struct hm11b1
*hm11b1
, u16 reg
, u16 len
, u32
*val
)
775 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
776 struct i2c_msg msgs
[2];
778 u8 data_buf
[4] = {0};
781 if (len
> sizeof(data_buf
))
784 put_unaligned_be16(reg
, addr_buf
);
785 msgs
[0].addr
= client
->addr
;
787 msgs
[0].len
= sizeof(addr_buf
);
788 msgs
[0].buf
= addr_buf
;
789 msgs
[1].addr
= client
->addr
;
790 msgs
[1].flags
= I2C_M_RD
;
792 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
794 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
795 if (ret
!= ARRAY_SIZE(msgs
))
796 return ret
< 0 ? ret
: -EIO
;
798 *val
= get_unaligned_be32(data_buf
);
803 static int hm11b1_write_reg(struct hm11b1
*hm11b1
, u16 reg
, u16 len
, u32 val
)
805 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
812 put_unaligned_be16(reg
, buf
);
813 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
815 ret
= i2c_master_send(client
, buf
, len
+ 2);
817 return ret
< 0 ? ret
: -EIO
;
822 static int hm11b1_write_reg_list(struct hm11b1
*hm11b1
,
823 const struct hm11b1_reg_list
*r_list
)
825 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
829 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
830 ret
= hm11b1_write_reg(hm11b1
, r_list
->regs
[i
].address
, 1,
831 r_list
->regs
[i
].val
);
833 dev_err_ratelimited(&client
->dev
,
834 "write reg 0x%4.4x return err = %d",
835 r_list
->regs
[i
].address
, ret
);
843 static int hm11b1_update_digital_gain(struct hm11b1
*hm11b1
, u32 d_gain
)
845 return hm11b1_write_reg(hm11b1
, HM11B1_REG_DGTL_GAIN
, 2, d_gain
);
848 static int hm11b1_test_pattern(struct hm11b1
*hm11b1
, u32 pattern
)
851 pattern
= pattern
<< HM11B1_TEST_PATTERN_BAR_SHIFT
|
852 HM11B1_TEST_PATTERN_ENABLE
;
854 return hm11b1_write_reg(hm11b1
, HM11B1_REG_TEST_PATTERN
, 1, pattern
);
857 static int hm11b1_set_ctrl(struct v4l2_ctrl
*ctrl
)
859 struct hm11b1
*hm11b1
= container_of(ctrl
->handler
,
860 struct hm11b1
, ctrl_handler
);
861 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
865 /* Propagate change of current control to all related controls */
866 if (ctrl
->id
== V4L2_CID_VBLANK
) {
867 /* Update max exposure while meeting expected vblanking */
868 exposure_max
= hm11b1
->cur_mode
->height
+ ctrl
->val
-
869 HM11B1_EXPOSURE_MAX_MARGIN
;
870 __v4l2_ctrl_modify_range(hm11b1
->exposure
,
871 hm11b1
->exposure
->minimum
,
872 exposure_max
, hm11b1
->exposure
->step
,
876 /* V4L2 controls values will be applied only when power is already up */
877 if (!pm_runtime_get_if_in_use(&client
->dev
))
881 case V4L2_CID_ANALOGUE_GAIN
:
882 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_ANALOG_GAIN
, 1,
886 case V4L2_CID_DIGITAL_GAIN
:
887 ret
= hm11b1_update_digital_gain(hm11b1
, ctrl
->val
);
890 case V4L2_CID_EXPOSURE
:
891 /* 4 least significant bits of expsoure are fractional part */
892 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_EXPOSURE
, 2,
896 case V4L2_CID_VBLANK
:
897 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_VTS
, 2,
898 hm11b1
->cur_mode
->height
+ ctrl
->val
);
901 case V4L2_CID_TEST_PATTERN
:
902 ret
= hm11b1_test_pattern(hm11b1
, ctrl
->val
);
910 pm_runtime_put(&client
->dev
);
915 static const struct v4l2_ctrl_ops hm11b1_ctrl_ops
= {
916 .s_ctrl
= hm11b1_set_ctrl
,
919 static int hm11b1_init_controls(struct hm11b1
*hm11b1
)
921 struct v4l2_ctrl_handler
*ctrl_hdlr
;
922 const struct hm11b1_mode
*cur_mode
;
923 s64 exposure_max
, h_blank
, pixel_rate
;
924 u32 vblank_min
, vblank_max
, vblank_default
;
928 ctrl_hdlr
= &hm11b1
->ctrl_handler
;
929 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
933 ctrl_hdlr
->lock
= &hm11b1
->mutex
;
934 cur_mode
= hm11b1
->cur_mode
;
935 size
= ARRAY_SIZE(link_freq_menu_items
);
937 hm11b1
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
, &hm11b1_ctrl_ops
,
940 link_freq_menu_items
);
941 if (hm11b1
->link_freq
)
942 hm11b1
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
944 pixel_rate
= to_pixel_rate(HM11B1_LINK_FREQ_384MHZ_INDEX
);
945 hm11b1
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
946 V4L2_CID_PIXEL_RATE
, 0,
947 pixel_rate
, 1, pixel_rate
);
949 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
950 vblank_max
= HM11B1_VTS_MAX
- cur_mode
->height
;
951 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
952 hm11b1
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
953 V4L2_CID_VBLANK
, vblank_min
,
954 vblank_max
, 1, vblank_default
);
956 h_blank
= to_pixels_per_line(cur_mode
->hts
, cur_mode
->link_freq_index
);
957 h_blank
-= cur_mode
->width
;
958 hm11b1
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
959 V4L2_CID_HBLANK
, h_blank
, h_blank
, 1,
962 hm11b1
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
964 v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
965 HM11B1_ANAL_GAIN_MIN
, HM11B1_ANAL_GAIN_MAX
,
966 HM11B1_ANAL_GAIN_STEP
, HM11B1_ANAL_GAIN_MIN
);
967 v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
968 HM11B1_DGTL_GAIN_MIN
, HM11B1_DGTL_GAIN_MAX
,
969 HM11B1_DGTL_GAIN_STEP
, HM11B1_DGTL_GAIN_DEFAULT
);
970 exposure_max
= cur_mode
->vts_def
- HM11B1_EXPOSURE_MAX_MARGIN
;
971 hm11b1
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
973 HM11B1_EXPOSURE_MIN
, exposure_max
,
974 HM11B1_EXPOSURE_STEP
,
976 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &hm11b1_ctrl_ops
,
977 V4L2_CID_TEST_PATTERN
,
978 ARRAY_SIZE(hm11b1_test_pattern_menu
) - 1,
979 0, 0, hm11b1_test_pattern_menu
);
980 if (ctrl_hdlr
->error
)
981 return ctrl_hdlr
->error
;
983 hm11b1
->sd
.ctrl_handler
= ctrl_hdlr
;
988 static void hm11b1_update_pad_format(const struct hm11b1_mode
*mode
,
989 struct v4l2_mbus_framefmt
*fmt
)
991 fmt
->width
= mode
->width
;
992 fmt
->height
= mode
->height
;
993 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
994 fmt
->field
= V4L2_FIELD_NONE
;
997 static int hm11b1_start_streaming(struct hm11b1
*hm11b1
)
999 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
1000 const struct hm11b1_reg_list
*reg_list
;
1001 int link_freq_index
;
1004 power_ctrl_logic_set_power(1);
1005 link_freq_index
= hm11b1
->cur_mode
->link_freq_index
;
1006 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
1007 ret
= hm11b1_write_reg_list(hm11b1
, reg_list
);
1009 dev_err(&client
->dev
, "failed to set plls");
1013 reg_list
= &hm11b1
->cur_mode
->reg_list
;
1014 ret
= hm11b1_write_reg_list(hm11b1
, reg_list
);
1016 dev_err(&client
->dev
, "failed to set mode");
1020 ret
= __v4l2_ctrl_handler_setup(hm11b1
->sd
.ctrl_handler
);
1024 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_MODE_SELECT
, 1,
1025 HM11B1_MODE_STREAMING
);
1027 dev_err(&client
->dev
, "failed to start streaming");
1032 static void hm11b1_stop_streaming(struct hm11b1
*hm11b1
)
1034 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
1036 if (hm11b1_write_reg(hm11b1
, HM11B1_REG_MODE_SELECT
, 1,
1037 HM11B1_MODE_STANDBY
))
1038 dev_err(&client
->dev
, "failed to stop streaming");
1039 power_ctrl_logic_set_power(0);
1042 static int hm11b1_set_stream(struct v4l2_subdev
*sd
, int enable
)
1044 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1045 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1048 if (hm11b1
->streaming
== enable
)
1051 mutex_lock(&hm11b1
->mutex
);
1053 ret
= pm_runtime_get_sync(&client
->dev
);
1055 pm_runtime_put_noidle(&client
->dev
);
1056 mutex_unlock(&hm11b1
->mutex
);
1060 ret
= hm11b1_start_streaming(hm11b1
);
1063 hm11b1_stop_streaming(hm11b1
);
1064 pm_runtime_put(&client
->dev
);
1067 hm11b1_stop_streaming(hm11b1
);
1068 pm_runtime_put(&client
->dev
);
1071 hm11b1
->streaming
= enable
;
1072 mutex_unlock(&hm11b1
->mutex
);
1077 static int __maybe_unused
hm11b1_suspend(struct device
*dev
)
1079 struct i2c_client
*client
= to_i2c_client(dev
);
1080 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1081 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1083 mutex_lock(&hm11b1
->mutex
);
1084 if (hm11b1
->streaming
)
1085 hm11b1_stop_streaming(hm11b1
);
1087 mutex_unlock(&hm11b1
->mutex
);
1092 static int __maybe_unused
hm11b1_resume(struct device
*dev
)
1094 struct i2c_client
*client
= to_i2c_client(dev
);
1095 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1096 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1099 mutex_lock(&hm11b1
->mutex
);
1100 if (!hm11b1
->streaming
)
1103 ret
= hm11b1_start_streaming(hm11b1
);
1105 hm11b1
->streaming
= false;
1106 hm11b1_stop_streaming(hm11b1
);
1110 mutex_unlock(&hm11b1
->mutex
);
1114 static int hm11b1_set_format(struct v4l2_subdev
*sd
,
1115 struct v4l2_subdev_pad_config
*cfg
,
1116 struct v4l2_subdev_format
*fmt
)
1118 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1119 const struct hm11b1_mode
*mode
;
1120 s32 vblank_def
, h_blank
;
1122 mode
= v4l2_find_nearest_size(supported_modes
,
1123 ARRAY_SIZE(supported_modes
), width
,
1124 height
, fmt
->format
.width
,
1125 fmt
->format
.height
);
1127 mutex_lock(&hm11b1
->mutex
);
1128 hm11b1_update_pad_format(mode
, &fmt
->format
);
1129 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
1130 *v4l2_subdev_get_try_format(sd
, cfg
, fmt
->pad
) = fmt
->format
;
1132 hm11b1
->cur_mode
= mode
;
1133 __v4l2_ctrl_s_ctrl(hm11b1
->link_freq
, mode
->link_freq_index
);
1134 __v4l2_ctrl_s_ctrl_int64(hm11b1
->pixel_rate
,
1135 to_pixel_rate(mode
->link_freq_index
));
1137 /* Update limits and set FPS to default */
1138 vblank_def
= mode
->vts_def
- mode
->height
;
1139 __v4l2_ctrl_modify_range(hm11b1
->vblank
,
1140 mode
->vts_min
- mode
->height
,
1141 HM11B1_VTS_MAX
- mode
->height
, 1,
1143 __v4l2_ctrl_s_ctrl(hm11b1
->vblank
, vblank_def
);
1144 h_blank
= to_pixels_per_line(mode
->hts
, mode
->link_freq_index
) -
1146 __v4l2_ctrl_modify_range(hm11b1
->hblank
, h_blank
, h_blank
, 1,
1149 mutex_unlock(&hm11b1
->mutex
);
1154 static int hm11b1_get_format(struct v4l2_subdev
*sd
,
1155 struct v4l2_subdev_pad_config
*cfg
,
1156 struct v4l2_subdev_format
*fmt
)
1158 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1160 mutex_lock(&hm11b1
->mutex
);
1161 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
1162 fmt
->format
= *v4l2_subdev_get_try_format(&hm11b1
->sd
, cfg
,
1165 hm11b1_update_pad_format(hm11b1
->cur_mode
, &fmt
->format
);
1167 mutex_unlock(&hm11b1
->mutex
);
1172 static int hm11b1_enum_mbus_code(struct v4l2_subdev
*sd
,
1173 struct v4l2_subdev_pad_config
*cfg
,
1174 struct v4l2_subdev_mbus_code_enum
*code
)
1176 if (code
->index
> 0)
1179 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
1184 static int hm11b1_enum_frame_size(struct v4l2_subdev
*sd
,
1185 struct v4l2_subdev_pad_config
*cfg
,
1186 struct v4l2_subdev_frame_size_enum
*fse
)
1188 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
1191 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
1194 fse
->min_width
= supported_modes
[fse
->index
].width
;
1195 fse
->max_width
= fse
->min_width
;
1196 fse
->min_height
= supported_modes
[fse
->index
].height
;
1197 fse
->max_height
= fse
->min_height
;
1202 static int hm11b1_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
1204 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1206 mutex_lock(&hm11b1
->mutex
);
1207 hm11b1_update_pad_format(&supported_modes
[0],
1208 v4l2_subdev_get_try_format(sd
, fh
->pad
, 0));
1209 mutex_unlock(&hm11b1
->mutex
);
1214 static const struct v4l2_subdev_video_ops hm11b1_video_ops
= {
1215 .s_stream
= hm11b1_set_stream
,
1218 static const struct v4l2_subdev_pad_ops hm11b1_pad_ops
= {
1219 .set_fmt
= hm11b1_set_format
,
1220 .get_fmt
= hm11b1_get_format
,
1221 .enum_mbus_code
= hm11b1_enum_mbus_code
,
1222 .enum_frame_size
= hm11b1_enum_frame_size
,
1225 static const struct v4l2_subdev_ops hm11b1_subdev_ops
= {
1226 .video
= &hm11b1_video_ops
,
1227 .pad
= &hm11b1_pad_ops
,
1230 static const struct media_entity_operations hm11b1_subdev_entity_ops
= {
1231 .link_validate
= v4l2_subdev_link_validate
,
1234 static const struct v4l2_subdev_internal_ops hm11b1_internal_ops
= {
1235 .open
= hm11b1_open
,
1238 static int hm11b1_identify_module(struct hm11b1
*hm11b1
)
1240 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
1244 ret
= hm11b1_read_reg(hm11b1
, HM11B1_REG_CHIP_ID
, 2, &val
);
1248 if (val
!= HM11B1_CHIP_ID
) {
1249 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
1250 HM11B1_CHIP_ID
, val
);
1257 static int hm11b1_remove(struct i2c_client
*client
)
1259 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1260 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
1262 v4l2_async_unregister_subdev(sd
);
1263 media_entity_cleanup(&sd
->entity
);
1264 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
1265 pm_runtime_disable(&client
->dev
);
1266 mutex_destroy(&hm11b1
->mutex
);
1271 static int hm11b1_probe(struct i2c_client
*client
)
1273 struct hm11b1
*hm11b1
;
1276 hm11b1
= devm_kzalloc(&client
->dev
, sizeof(*hm11b1
), GFP_KERNEL
);
1280 v4l2_i2c_subdev_init(&hm11b1
->sd
, client
, &hm11b1_subdev_ops
);
1281 power_ctrl_logic_set_power(0);
1282 power_ctrl_logic_set_power(1);
1283 ret
= hm11b1_identify_module(hm11b1
);
1285 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
1289 mutex_init(&hm11b1
->mutex
);
1290 hm11b1
->cur_mode
= &supported_modes
[0];
1291 ret
= hm11b1_init_controls(hm11b1
);
1293 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
1294 goto probe_error_v4l2_ctrl_handler_free
;
1297 hm11b1
->sd
.internal_ops
= &hm11b1_internal_ops
;
1298 hm11b1
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
1299 hm11b1
->sd
.entity
.ops
= &hm11b1_subdev_entity_ops
;
1300 hm11b1
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
1301 hm11b1
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1302 ret
= media_entity_pads_init(&hm11b1
->sd
.entity
, 1, &hm11b1
->pad
);
1304 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
1305 goto probe_error_v4l2_ctrl_handler_free
;
1308 ret
= v4l2_async_register_subdev_sensor_common(&hm11b1
->sd
);
1310 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
1312 goto probe_error_media_entity_cleanup
;
1316 * Device is already turned on by i2c-core with ACPI domain PM.
1317 * Enable runtime PM and turn off the device.
1319 pm_runtime_set_active(&client
->dev
);
1320 pm_runtime_enable(&client
->dev
);
1321 pm_runtime_idle(&client
->dev
);
1323 power_ctrl_logic_set_power(0);
1326 probe_error_media_entity_cleanup
:
1327 media_entity_cleanup(&hm11b1
->sd
.entity
);
1329 probe_error_v4l2_ctrl_handler_free
:
1330 v4l2_ctrl_handler_free(hm11b1
->sd
.ctrl_handler
);
1331 mutex_destroy(&hm11b1
->mutex
);
1336 static const struct dev_pm_ops hm11b1_pm_ops
= {
1337 SET_SYSTEM_SLEEP_PM_OPS(hm11b1_suspend
, hm11b1_resume
)
1341 static const struct acpi_device_id hm11b1_acpi_ids
[] = {
1346 MODULE_DEVICE_TABLE(acpi
, hm11b1_acpi_ids
);
1349 static struct i2c_driver hm11b1_i2c_driver
= {
1352 .pm
= &hm11b1_pm_ops
,
1353 .acpi_match_table
= ACPI_PTR(hm11b1_acpi_ids
),
1355 .probe_new
= hm11b1_probe
,
1356 .remove
= hm11b1_remove
,
1359 module_i2c_driver(hm11b1_i2c_driver
);
1361 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
1362 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
1363 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
1364 MODULE_AUTHOR("Lai, Jim <jim.lai@intel.com>");
1365 MODULE_DESCRIPTION("Himax HM11B1 sensor driver");
1366 MODULE_LICENSE("GPL v2");