Lines Matching refs:imx258

604 struct imx258 {  struct
631 static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd) in to_imx258() argument
633 return container_of(_sd, struct imx258, sd); in to_imx258()
637 static int imx258_read_reg(struct imx258 *imx258, u16 reg, u32 len, u32 *val) in imx258_read_reg() argument
639 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_read_reg()
670 static int imx258_write_reg(struct imx258 *imx258, u16 reg, u32 len, u32 val) in imx258_write_reg() argument
672 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_write_reg()
687 static int imx258_write_regs(struct imx258 *imx258, in imx258_write_regs() argument
690 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_write_regs()
695 ret = imx258_write_reg(imx258, regs[i].address, 1, in imx258_write_regs()
725 static int imx258_update_digital_gain(struct imx258 *imx258, u32 len, u32 val) in imx258_update_digital_gain() argument
729 ret = imx258_write_reg(imx258, IMX258_REG_GR_DIGITAL_GAIN, in imx258_update_digital_gain()
734 ret = imx258_write_reg(imx258, IMX258_REG_GB_DIGITAL_GAIN, in imx258_update_digital_gain()
739 ret = imx258_write_reg(imx258, IMX258_REG_R_DIGITAL_GAIN, in imx258_update_digital_gain()
744 ret = imx258_write_reg(imx258, IMX258_REG_B_DIGITAL_GAIN, in imx258_update_digital_gain()
754 struct imx258 *imx258 = in imx258_set_ctrl() local
755 container_of(ctrl->handler, struct imx258, ctrl_handler); in imx258_set_ctrl()
756 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_set_ctrl()
768 ret = imx258_write_reg(imx258, IMX258_REG_ANALOG_GAIN, in imx258_set_ctrl()
773 ret = imx258_write_reg(imx258, IMX258_REG_EXPOSURE, in imx258_set_ctrl()
778 ret = imx258_update_digital_gain(imx258, IMX258_REG_VALUE_16BIT, in imx258_set_ctrl()
782 ret = imx258_write_reg(imx258, IMX258_REG_TEST_PATTERN, in imx258_set_ctrl()
785 ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL, in imx258_set_ctrl()
792 ret = imx258_write_reg(imx258, IMX258_REG_HDR, in imx258_set_ctrl()
796 ret = imx258_write_reg(imx258, IMX258_REG_HDR, in imx258_set_ctrl()
801 ret = imx258_write_reg(imx258, IMX258_REG_HDR_RATIO, in imx258_set_ctrl()
863 static int __imx258_get_pad_format(struct imx258 *imx258, in __imx258_get_pad_format() argument
868 fmt->format = *v4l2_subdev_get_try_format(&imx258->sd, in __imx258_get_pad_format()
872 imx258_update_pad_format(imx258->cur_mode, fmt); in __imx258_get_pad_format()
881 struct imx258 *imx258 = to_imx258(sd); in imx258_get_pad_format() local
884 mutex_lock(&imx258->mutex); in imx258_get_pad_format()
885 ret = __imx258_get_pad_format(imx258, sd_state, fmt); in imx258_get_pad_format()
886 mutex_unlock(&imx258->mutex); in imx258_get_pad_format()
895 struct imx258 *imx258 = to_imx258(sd); in imx258_set_pad_format() local
904 mutex_lock(&imx258->mutex); in imx258_set_pad_format()
917 imx258->cur_mode = mode; in imx258_set_pad_format()
918 __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); in imx258_set_pad_format()
922 __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate); in imx258_set_pad_format()
924 vblank_def = imx258->cur_mode->vts_def - in imx258_set_pad_format()
925 imx258->cur_mode->height; in imx258_set_pad_format()
926 vblank_min = imx258->cur_mode->vts_min - in imx258_set_pad_format()
927 imx258->cur_mode->height; in imx258_set_pad_format()
929 imx258->vblank, vblank_min, in imx258_set_pad_format()
930 IMX258_VTS_MAX - imx258->cur_mode->height, 1, in imx258_set_pad_format()
932 __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def); in imx258_set_pad_format()
935 - imx258->cur_mode->width; in imx258_set_pad_format()
936 __v4l2_ctrl_modify_range(imx258->hblank, h_blank, in imx258_set_pad_format()
940 mutex_unlock(&imx258->mutex); in imx258_set_pad_format()
946 static int imx258_start_streaming(struct imx258 *imx258) in imx258_start_streaming() argument
948 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_start_streaming()
953 link_freq_index = imx258->cur_mode->link_freq_index; in imx258_start_streaming()
955 ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); in imx258_start_streaming()
962 reg_list = &imx258->cur_mode->reg_list; in imx258_start_streaming()
963 ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); in imx258_start_streaming()
970 ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL, in imx258_start_streaming()
979 ret = __v4l2_ctrl_handler_setup(imx258->sd.ctrl_handler); in imx258_start_streaming()
984 return imx258_write_reg(imx258, IMX258_REG_MODE_SELECT, in imx258_start_streaming()
990 static int imx258_stop_streaming(struct imx258 *imx258) in imx258_stop_streaming() argument
992 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_stop_streaming()
996 ret = imx258_write_reg(imx258, IMX258_REG_MODE_SELECT, in imx258_stop_streaming()
1011 struct imx258 *imx258 = to_imx258(sd); in imx258_power_on() local
1014 ret = clk_prepare_enable(imx258->clk); in imx258_power_on()
1024 struct imx258 *imx258 = to_imx258(sd); in imx258_power_off() local
1026 clk_disable_unprepare(imx258->clk); in imx258_power_off()
1033 struct imx258 *imx258 = to_imx258(sd); in imx258_set_stream() local
1037 mutex_lock(&imx258->mutex); in imx258_set_stream()
1038 if (imx258->streaming == enable) { in imx258_set_stream()
1039 mutex_unlock(&imx258->mutex); in imx258_set_stream()
1052 ret = imx258_start_streaming(imx258); in imx258_set_stream()
1056 imx258_stop_streaming(imx258); in imx258_set_stream()
1060 imx258->streaming = enable; in imx258_set_stream()
1061 mutex_unlock(&imx258->mutex); in imx258_set_stream()
1068 mutex_unlock(&imx258->mutex); in imx258_set_stream()
1076 struct imx258 *imx258 = to_imx258(sd); in imx258_suspend() local
1078 if (imx258->streaming) in imx258_suspend()
1079 imx258_stop_streaming(imx258); in imx258_suspend()
1087 struct imx258 *imx258 = to_imx258(sd); in imx258_resume() local
1090 if (imx258->streaming) { in imx258_resume()
1091 ret = imx258_start_streaming(imx258); in imx258_resume()
1099 imx258_stop_streaming(imx258); in imx258_resume()
1100 imx258->streaming = 0; in imx258_resume()
1105 static int imx258_identify_module(struct imx258 *imx258) in imx258_identify_module() argument
1107 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_identify_module()
1111 ret = imx258_read_reg(imx258, IMX258_REG_CHIP_ID, in imx258_identify_module()
1149 static int imx258_init_controls(struct imx258 *imx258) in imx258_init_controls() argument
1151 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_init_controls()
1161 ctrl_hdlr = &imx258->ctrl_handler; in imx258_init_controls()
1166 mutex_init(&imx258->mutex); in imx258_init_controls()
1167 ctrl_hdlr->lock = &imx258->mutex; in imx258_init_controls()
1168 imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, in imx258_init_controls()
1175 if (imx258->link_freq) in imx258_init_controls()
1176 imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx258_init_controls()
1192 imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, in imx258_init_controls()
1198 vblank_def = imx258->cur_mode->vts_def - imx258->cur_mode->height; in imx258_init_controls()
1199 vblank_min = imx258->cur_mode->vts_min - imx258->cur_mode->height; in imx258_init_controls()
1200 imx258->vblank = v4l2_ctrl_new_std( in imx258_init_controls()
1203 IMX258_VTS_MAX - imx258->cur_mode->height, 1, in imx258_init_controls()
1206 if (imx258->vblank) in imx258_init_controls()
1207 imx258->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx258_init_controls()
1209 imx258->hblank = v4l2_ctrl_new_std( in imx258_init_controls()
1211 IMX258_PPL_DEFAULT - imx258->cur_mode->width, in imx258_init_controls()
1212 IMX258_PPL_DEFAULT - imx258->cur_mode->width, in imx258_init_controls()
1214 IMX258_PPL_DEFAULT - imx258->cur_mode->width); in imx258_init_controls()
1216 if (imx258->hblank) in imx258_init_controls()
1217 imx258->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx258_init_controls()
1219 imx258->exposure = v4l2_ctrl_new_std( in imx258_init_controls()
1258 imx258->sd.ctrl_handler = ctrl_hdlr; in imx258_init_controls()
1264 mutex_destroy(&imx258->mutex); in imx258_init_controls()
1269 static void imx258_free_controls(struct imx258 *imx258) in imx258_free_controls() argument
1271 v4l2_ctrl_handler_free(imx258->sd.ctrl_handler); in imx258_free_controls()
1272 mutex_destroy(&imx258->mutex); in imx258_free_controls()
1277 struct imx258 *imx258; in imx258_probe() local
1281 imx258 = devm_kzalloc(&client->dev, sizeof(*imx258), GFP_KERNEL); in imx258_probe()
1282 if (!imx258) in imx258_probe()
1285 imx258->clk = devm_clk_get_optional(&client->dev, NULL); in imx258_probe()
1286 if (IS_ERR(imx258->clk)) in imx258_probe()
1287 return dev_err_probe(&client->dev, PTR_ERR(imx258->clk), in imx258_probe()
1289 if (!imx258->clk) { in imx258_probe()
1295 val = clk_get_rate(imx258->clk); in imx258_probe()
1303 v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops); in imx258_probe()
1311 ret = imx258_identify_module(imx258); in imx258_probe()
1316 imx258->cur_mode = &supported_modes[0]; in imx258_probe()
1318 ret = imx258_init_controls(imx258); in imx258_probe()
1323 imx258->sd.internal_ops = &imx258_internal_ops; in imx258_probe()
1324 imx258->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx258_probe()
1325 imx258->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx258_probe()
1328 imx258->pad.flags = MEDIA_PAD_FL_SOURCE; in imx258_probe()
1330 ret = media_entity_pads_init(&imx258->sd.entity, 1, &imx258->pad); in imx258_probe()
1334 ret = v4l2_async_register_subdev_sensor(&imx258->sd); in imx258_probe()
1345 media_entity_cleanup(&imx258->sd.entity); in imx258_probe()
1348 imx258_free_controls(imx258); in imx258_probe()
1359 struct imx258 *imx258 = to_imx258(sd); in imx258_remove() local
1363 imx258_free_controls(imx258); in imx258_remove()