Lines Matching full:imx219

3  * A V4L2 driver for Sony IMX219 cameras.
142 /* IMX219 native and active pixel array size. */
315 struct imx219 { struct
320 struct clk *xclk; /* system clock to IMX219 */
340 static inline struct imx219 *to_imx219(struct v4l2_subdev *_sd) in to_imx219() argument
342 return container_of(_sd, struct imx219, sd); in to_imx219()
346 static u32 imx219_get_format_code(struct imx219 *imx219, u32 code) in imx219_get_format_code() argument
357 i = (i & ~3) | (imx219->vflip->val ? 2 : 0) | in imx219_get_format_code()
358 (imx219->hflip->val ? 1 : 0); in imx219_get_format_code()
369 struct imx219 *imx219 = in imx219_set_ctrl() local
370 container_of(ctrl->handler, struct imx219, ctrl_handler); in imx219_set_ctrl()
371 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_set_ctrl()
376 state = v4l2_subdev_get_locked_active_state(&imx219->sd); in imx219_set_ctrl()
386 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_ctrl()
387 imx219->exposure->minimum, in imx219_set_ctrl()
388 exposure_max, imx219->exposure->step, in imx219_set_ctrl()
401 cci_write(imx219->regmap, IMX219_REG_ANALOG_GAIN, in imx219_set_ctrl()
405 cci_write(imx219->regmap, IMX219_REG_EXPOSURE, in imx219_set_ctrl()
409 cci_write(imx219->regmap, IMX219_REG_DIGITAL_GAIN, in imx219_set_ctrl()
413 cci_write(imx219->regmap, IMX219_REG_TEST_PATTERN, in imx219_set_ctrl()
418 cci_write(imx219->regmap, IMX219_REG_ORIENTATION, in imx219_set_ctrl()
419 imx219->hflip->val | imx219->vflip->val << 1, &ret); in imx219_set_ctrl()
422 cci_write(imx219->regmap, IMX219_REG_VTS, in imx219_set_ctrl()
426 cci_write(imx219->regmap, IMX219_REG_TESTP_RED, in imx219_set_ctrl()
430 cci_write(imx219->regmap, IMX219_REG_TESTP_GREENR, in imx219_set_ctrl()
434 cci_write(imx219->regmap, IMX219_REG_TESTP_BLUE, in imx219_set_ctrl()
438 cci_write(imx219->regmap, IMX219_REG_TESTP_GREENB, in imx219_set_ctrl()
458 static unsigned long imx219_get_pixel_rate(struct imx219 *imx219) in imx219_get_pixel_rate() argument
460 return (imx219->lanes == 2) ? IMX219_PIXEL_RATE : IMX219_PIXEL_RATE_4LANE; in imx219_get_pixel_rate()
464 static int imx219_init_controls(struct imx219 *imx219) in imx219_init_controls() argument
466 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_init_controls()
473 ctrl_hdlr = &imx219->ctrl_handler; in imx219_init_controls()
479 imx219->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
481 imx219_get_pixel_rate(imx219), in imx219_init_controls()
482 imx219_get_pixel_rate(imx219), 1, in imx219_init_controls()
483 imx219_get_pixel_rate(imx219)); in imx219_init_controls()
485 imx219->link_freq = in imx219_init_controls()
489 (imx219->lanes == 2) ? imx219_link_freq_menu : in imx219_init_controls()
491 if (imx219->link_freq) in imx219_init_controls()
492 imx219->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
495 imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
500 imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
503 if (imx219->hblank) in imx219_init_controls()
504 imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
508 imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
522 imx219->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
524 if (imx219->hflip) in imx219_init_controls()
525 imx219->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
527 imx219->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
529 if (imx219->vflip) in imx219_init_controls()
530 imx219->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
567 imx219->sd.ctrl_handler = ctrl_hdlr; in imx219_init_controls()
577 static void imx219_free_controls(struct imx219 *imx219) in imx219_free_controls() argument
579 v4l2_ctrl_handler_free(imx219->sd.ctrl_handler); in imx219_free_controls()
586 static int imx219_set_framefmt(struct imx219 *imx219, in imx219_set_framefmt() argument
615 cci_write(imx219->regmap, IMX219_REG_X_ADD_STA_A, in imx219_set_framefmt()
617 cci_write(imx219->regmap, IMX219_REG_X_ADD_END_A, in imx219_set_framefmt()
619 cci_write(imx219->regmap, IMX219_REG_Y_ADD_STA_A, in imx219_set_framefmt()
621 cci_write(imx219->regmap, IMX219_REG_Y_ADD_END_A, in imx219_set_framefmt()
644 cci_write(imx219->regmap, IMX219_REG_BINNING_MODE_H, bin_h, &ret); in imx219_set_framefmt()
645 cci_write(imx219->regmap, IMX219_REG_BINNING_MODE_V, bin_v, &ret); in imx219_set_framefmt()
647 cci_write(imx219->regmap, IMX219_REG_X_OUTPUT_SIZE, in imx219_set_framefmt()
649 cci_write(imx219->regmap, IMX219_REG_Y_OUTPUT_SIZE, in imx219_set_framefmt()
652 cci_write(imx219->regmap, IMX219_REG_TP_WINDOW_WIDTH, in imx219_set_framefmt()
654 cci_write(imx219->regmap, IMX219_REG_TP_WINDOW_HEIGHT, in imx219_set_framefmt()
657 cci_write(imx219->regmap, IMX219_REG_CSI_DATA_FORMAT_A, in imx219_set_framefmt()
659 cci_write(imx219->regmap, IMX219_REG_OPPXCK_DIV, bpp, &ret); in imx219_set_framefmt()
664 static int imx219_configure_lanes(struct imx219 *imx219) in imx219_configure_lanes() argument
666 return cci_write(imx219->regmap, IMX219_REG_CSI_LANE_MODE, in imx219_configure_lanes()
667 imx219->lanes == 2 ? IMX219_CSI_2_LANE_MODE : in imx219_configure_lanes()
671 static int imx219_start_streaming(struct imx219 *imx219, in imx219_start_streaming() argument
674 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_start_streaming()
682 ret = cci_multi_reg_write(imx219->regmap, imx219_common_regs, in imx219_start_streaming()
690 ret = imx219_configure_lanes(imx219); in imx219_start_streaming()
697 ret = imx219_set_framefmt(imx219, state); in imx219_start_streaming()
705 ret = __v4l2_ctrl_handler_setup(imx219->sd.ctrl_handler); in imx219_start_streaming()
710 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_start_streaming()
716 __v4l2_ctrl_grab(imx219->vflip, true); in imx219_start_streaming()
717 __v4l2_ctrl_grab(imx219->hflip, true); in imx219_start_streaming()
726 static void imx219_stop_streaming(struct imx219 *imx219) in imx219_stop_streaming() argument
728 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_stop_streaming()
732 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_stop_streaming()
737 __v4l2_ctrl_grab(imx219->vflip, false); in imx219_stop_streaming()
738 __v4l2_ctrl_grab(imx219->hflip, false); in imx219_stop_streaming()
745 struct imx219 *imx219 = to_imx219(sd); in imx219_set_stream() local
752 ret = imx219_start_streaming(imx219, state); in imx219_set_stream()
754 imx219_stop_streaming(imx219); in imx219_set_stream()
760 static void imx219_update_pad_format(struct imx219 *imx219, in imx219_update_pad_format() argument
765 fmt->code = imx219_get_format_code(imx219, code); in imx219_update_pad_format()
779 struct imx219 *imx219 = to_imx219(sd); in imx219_enum_mbus_code() local
784 code->code = imx219_get_format_code(imx219, imx219_mbus_formats[code->index * 4]); in imx219_enum_mbus_code()
793 struct imx219 *imx219 = to_imx219(sd); in imx219_enum_frame_size() local
799 code = imx219_get_format_code(imx219, fse->code); in imx219_enum_frame_size()
815 struct imx219 *imx219 = to_imx219(sd); in imx219_set_pad_format() local
826 imx219_update_pad_format(imx219, mode, &fmt->format, fmt->format.code); in imx219_set_pad_format()
850 __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, in imx219_set_pad_format()
853 __v4l2_ctrl_s_ctrl(imx219->vblank, in imx219_set_pad_format()
859 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_pad_format()
860 imx219->exposure->minimum, in imx219_set_pad_format()
861 exposure_max, imx219->exposure->step, in imx219_set_pad_format()
869 __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1, in imx219_set_pad_format()
959 struct imx219 *imx219 = to_imx219(sd); in imx219_power_on() local
963 imx219->supplies); in imx219_power_on()
970 ret = clk_prepare_enable(imx219->xclk); in imx219_power_on()
977 gpiod_set_value_cansleep(imx219->reset_gpio, 1); in imx219_power_on()
984 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_on()
992 struct imx219 *imx219 = to_imx219(sd); in imx219_power_off() local
994 gpiod_set_value_cansleep(imx219->reset_gpio, 0); in imx219_power_off()
995 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_off()
996 clk_disable_unprepare(imx219->xclk); in imx219_power_off()
1005 static int imx219_get_regulators(struct imx219 *imx219) in imx219_get_regulators() argument
1007 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_get_regulators()
1011 imx219->supplies[i].supply = imx219_supply_name[i]; in imx219_get_regulators()
1015 imx219->supplies); in imx219_get_regulators()
1019 static int imx219_identify_module(struct imx219 *imx219) in imx219_identify_module() argument
1021 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_identify_module()
1025 ret = cci_read(imx219->regmap, IMX219_REG_CHIP_ID, &val, NULL); in imx219_identify_module()
1039 static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219) in imx219_check_hwcfg() argument
1063 imx219->lanes = ep_cfg.bus.mipi_csi2.num_data_lanes; in imx219_check_hwcfg()
1073 (ep_cfg.link_frequencies[0] != ((imx219->lanes == 2) ? in imx219_check_hwcfg()
1093 struct imx219 *imx219; in imx219_probe() local
1096 imx219 = devm_kzalloc(&client->dev, sizeof(*imx219), GFP_KERNEL); in imx219_probe()
1097 if (!imx219) in imx219_probe()
1100 v4l2_i2c_subdev_init(&imx219->sd, client, &imx219_subdev_ops); in imx219_probe()
1101 imx219->sd.internal_ops = &imx219_internal_ops; in imx219_probe()
1104 if (imx219_check_hwcfg(dev, imx219)) in imx219_probe()
1107 imx219->regmap = devm_cci_regmap_init_i2c(client, 16); in imx219_probe()
1108 if (IS_ERR(imx219->regmap)) in imx219_probe()
1109 return dev_err_probe(dev, PTR_ERR(imx219->regmap), in imx219_probe()
1113 imx219->xclk = devm_clk_get(dev, NULL); in imx219_probe()
1114 if (IS_ERR(imx219->xclk)) in imx219_probe()
1115 return dev_err_probe(dev, PTR_ERR(imx219->xclk), in imx219_probe()
1118 imx219->xclk_freq = clk_get_rate(imx219->xclk); in imx219_probe()
1119 if (imx219->xclk_freq != IMX219_XCLK_FREQ) in imx219_probe()
1122 imx219->xclk_freq); in imx219_probe()
1124 ret = imx219_get_regulators(imx219); in imx219_probe()
1129 imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset", in imx219_probe()
1140 ret = imx219_identify_module(imx219); in imx219_probe()
1149 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_probe()
1157 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_probe()
1164 ret = imx219_init_controls(imx219); in imx219_probe()
1169 imx219->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in imx219_probe()
1171 imx219->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx219_probe()
1174 imx219->pad.flags = MEDIA_PAD_FL_SOURCE; in imx219_probe()
1176 ret = media_entity_pads_init(&imx219->sd.entity, 1, &imx219->pad); in imx219_probe()
1182 imx219->sd.state_lock = imx219->ctrl_handler.lock; in imx219_probe()
1183 ret = v4l2_subdev_init_finalize(&imx219->sd); in imx219_probe()
1189 ret = v4l2_async_register_subdev_sensor(&imx219->sd); in imx219_probe()
1204 v4l2_subdev_cleanup(&imx219->sd); in imx219_probe()
1207 media_entity_cleanup(&imx219->sd.entity); in imx219_probe()
1210 imx219_free_controls(imx219); in imx219_probe()
1221 struct imx219 *imx219 = to_imx219(sd); in imx219_remove() local
1226 imx219_free_controls(imx219); in imx219_remove()
1235 { .compatible = "sony,imx219" },
1246 .name = "imx219",
1257 MODULE_DESCRIPTION("Sony IMX219 sensor driver");