Lines Matching full:imx214

3  * imx214.c - imx214 sensor driver
39 /* IMX214 native and active pixel array size */
55 struct imx214 { struct
444 static inline struct imx214 *to_imx214(struct v4l2_subdev *sd) in to_imx214()
446 return container_of(sd, struct imx214, sd); in to_imx214()
453 struct imx214 *imx214 = to_imx214(sd); in imx214_power_on() local
456 ret = regulator_bulk_enable(IMX214_NUM_SUPPLIES, imx214->supplies); in imx214_power_on()
458 dev_err(imx214->dev, "failed to enable regulators: %d\n", ret); in imx214_power_on()
464 ret = clk_prepare_enable(imx214->xclk); in imx214_power_on()
466 regulator_bulk_disable(IMX214_NUM_SUPPLIES, imx214->supplies); in imx214_power_on()
467 dev_err(imx214->dev, "clk prepare enable failed\n"); in imx214_power_on()
471 gpiod_set_value_cansleep(imx214->enable_gpio, 1); in imx214_power_on()
481 struct imx214 *imx214 = to_imx214(sd); in imx214_power_off() local
483 gpiod_set_value_cansleep(imx214->enable_gpio, 0); in imx214_power_off()
485 clk_disable_unprepare(imx214->xclk); in imx214_power_off()
487 regulator_bulk_disable(IMX214_NUM_SUPPLIES, imx214->supplies); in imx214_power_off()
525 struct imx214 *imx214 = container_of(subdev, struct imx214, sd); in imx214_s_register() local
527 return regmap_write(imx214->regmap, reg->reg, reg->val); in imx214_s_register()
533 struct imx214 *imx214 = container_of(subdev, struct imx214, sd); in imx214_g_register() local
538 ret = regmap_read(imx214->regmap, reg->reg, &aux); in imx214_g_register()
553 __imx214_get_pad_format(struct imx214 *imx214, in __imx214_get_pad_format() argument
562 return &imx214->fmt; in __imx214_get_pad_format()
572 struct imx214 *imx214 = to_imx214(sd); in imx214_get_format() local
574 mutex_lock(&imx214->mutex); in imx214_get_format()
575 format->format = *__imx214_get_pad_format(imx214, sd_state, in imx214_get_format()
578 mutex_unlock(&imx214->mutex); in imx214_get_format()
584 __imx214_get_pad_crop(struct imx214 *imx214, in __imx214_get_pad_crop() argument
592 return &imx214->crop; in __imx214_get_pad_crop()
602 struct imx214 *imx214 = to_imx214(sd); in imx214_set_format() local
607 mutex_lock(&imx214->mutex); in imx214_set_format()
609 __crop = __imx214_get_pad_crop(imx214, sd_state, format->pad, in imx214_set_format()
620 __format = __imx214_get_pad_format(imx214, sd_state, format->pad, in imx214_set_format()
634 mutex_unlock(&imx214->mutex); in imx214_set_format()
643 struct imx214 *imx214 = to_imx214(sd); in imx214_get_selection() local
647 mutex_lock(&imx214->mutex); in imx214_get_selection()
648 sel->r = *__imx214_get_pad_crop(imx214, sd_state, sel->pad, in imx214_get_selection()
650 mutex_unlock(&imx214->mutex); in imx214_get_selection()
688 struct imx214 *imx214 = container_of(ctrl->handler, in imx214_set_ctrl() local
689 struct imx214, ctrls); in imx214_set_ctrl()
697 if (!pm_runtime_get_if_in_use(imx214->dev)) in imx214_set_ctrl()
704 ret = regmap_bulk_write(imx214->regmap, IMX214_REG_EXPOSURE, vals, 2); in imx214_set_ctrl()
706 dev_err(imx214->dev, "Error %d\n", ret); in imx214_set_ctrl()
714 pm_runtime_put(imx214->dev); in imx214_set_ctrl()
723 static int imx214_ctrls_init(struct imx214 *imx214) in imx214_ctrls_init() argument
736 ret = v4l2_fwnode_device_parse(imx214->dev, &props); in imx214_ctrls_init()
740 ctrl_hdlr = &imx214->ctrls; in imx214_ctrls_init()
741 ret = v4l2_ctrl_handler_init(&imx214->ctrls, 6); in imx214_ctrls_init()
745 imx214->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, NULL, in imx214_ctrls_init()
750 imx214->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, NULL, in imx214_ctrls_init()
754 if (imx214->link_freq) in imx214_ctrls_init()
755 imx214->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx214_ctrls_init()
767 imx214->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx214_ctrl_ops, in imx214_ctrls_init()
774 imx214->unit_size = v4l2_ctrl_new_std_compound(ctrl_hdlr, in imx214_ctrls_init()
784 dev_err(imx214->dev, "failed to add controls: %d\n", ret); in imx214_ctrls_init()
788 imx214->sd.ctrl_handler = ctrl_hdlr; in imx214_ctrls_init()
794 static int imx214_write_table(struct imx214 *imx214, in imx214_write_table() argument
814 ret = regmap_bulk_write(imx214->regmap, table->addr, vals, i); in imx214_write_table()
817 dev_err(imx214->dev, "write_table error: %d\n", ret); in imx214_write_table()
827 static int imx214_start_streaming(struct imx214 *imx214) in imx214_start_streaming() argument
832 mutex_lock(&imx214->mutex); in imx214_start_streaming()
833 ret = imx214_write_table(imx214, mode_table_common); in imx214_start_streaming()
835 dev_err(imx214->dev, "could not sent common table %d\n", ret); in imx214_start_streaming()
841 imx214->fmt.width, imx214->fmt.height); in imx214_start_streaming()
842 ret = imx214_write_table(imx214, mode->reg_table); in imx214_start_streaming()
844 dev_err(imx214->dev, "could not sent mode table %d\n", ret); in imx214_start_streaming()
847 ret = __v4l2_ctrl_handler_setup(&imx214->ctrls); in imx214_start_streaming()
849 dev_err(imx214->dev, "could not sync v4l2 controls\n"); in imx214_start_streaming()
852 ret = regmap_write(imx214->regmap, IMX214_REG_MODE_SELECT, IMX214_MODE_STREAMING); in imx214_start_streaming()
854 dev_err(imx214->dev, "could not sent start table %d\n", ret); in imx214_start_streaming()
858 mutex_unlock(&imx214->mutex); in imx214_start_streaming()
862 mutex_unlock(&imx214->mutex); in imx214_start_streaming()
866 static int imx214_stop_streaming(struct imx214 *imx214) in imx214_stop_streaming() argument
870 ret = regmap_write(imx214->regmap, IMX214_REG_MODE_SELECT, IMX214_MODE_STANDBY); in imx214_stop_streaming()
872 dev_err(imx214->dev, "could not sent stop table %d\n", ret); in imx214_stop_streaming()
879 struct imx214 *imx214 = to_imx214(subdev); in imx214_s_stream() local
883 ret = pm_runtime_resume_and_get(imx214->dev); in imx214_s_stream()
887 ret = imx214_start_streaming(imx214); in imx214_s_stream()
891 ret = imx214_stop_streaming(imx214); in imx214_s_stream()
894 pm_runtime_put(imx214->dev); in imx214_s_stream()
900 pm_runtime_put(imx214->dev); in imx214_s_stream()
974 static int imx214_get_regulators(struct device *dev, struct imx214 *imx214) in imx214_get_regulators() argument
979 imx214->supplies[i].supply = imx214_supply_name[i]; in imx214_get_regulators()
982 imx214->supplies); in imx214_get_regulators()
1026 struct imx214 *imx214; in imx214_probe() local
1033 imx214 = devm_kzalloc(dev, sizeof(*imx214), GFP_KERNEL); in imx214_probe()
1034 if (!imx214) in imx214_probe()
1037 imx214->dev = dev; in imx214_probe()
1039 imx214->xclk = devm_clk_get(dev, NULL); in imx214_probe()
1040 if (IS_ERR(imx214->xclk)) { in imx214_probe()
1042 return PTR_ERR(imx214->xclk); in imx214_probe()
1045 ret = clk_set_rate(imx214->xclk, IMX214_DEFAULT_CLK_FREQ); in imx214_probe()
1051 ret = imx214_get_regulators(dev, imx214); in imx214_probe()
1057 imx214->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); in imx214_probe()
1058 if (IS_ERR(imx214->enable_gpio)) { in imx214_probe()
1060 return PTR_ERR(imx214->enable_gpio); in imx214_probe()
1063 imx214->regmap = devm_regmap_init_i2c(client, &sensor_regmap_config); in imx214_probe()
1064 if (IS_ERR(imx214->regmap)) { in imx214_probe()
1066 return PTR_ERR(imx214->regmap); in imx214_probe()
1069 v4l2_i2c_subdev_init(&imx214->sd, client, &imx214_subdev_ops); in imx214_probe()
1070 imx214->sd.internal_ops = &imx214_internal_ops; in imx214_probe()
1076 imx214_power_on(imx214->dev); in imx214_probe()
1078 pm_runtime_set_active(imx214->dev); in imx214_probe()
1079 pm_runtime_enable(imx214->dev); in imx214_probe()
1080 pm_runtime_idle(imx214->dev); in imx214_probe()
1082 ret = imx214_ctrls_init(imx214); in imx214_probe()
1086 mutex_init(&imx214->mutex); in imx214_probe()
1087 imx214->ctrls.lock = &imx214->mutex; in imx214_probe()
1089 imx214->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx214_probe()
1090 imx214->pad.flags = MEDIA_PAD_FL_SOURCE; in imx214_probe()
1091 imx214->sd.dev = &client->dev; in imx214_probe()
1092 imx214->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx214_probe()
1094 ret = media_entity_pads_init(&imx214->sd.entity, 1, &imx214->pad); in imx214_probe()
1100 imx214_entity_init_state(&imx214->sd, NULL); in imx214_probe()
1102 ret = v4l2_async_register_subdev_sensor(&imx214->sd); in imx214_probe()
1111 media_entity_cleanup(&imx214->sd.entity); in imx214_probe()
1113 mutex_destroy(&imx214->mutex); in imx214_probe()
1114 v4l2_ctrl_handler_free(&imx214->ctrls); in imx214_probe()
1116 pm_runtime_disable(imx214->dev); in imx214_probe()
1117 regulator_bulk_disable(IMX214_NUM_SUPPLIES, imx214->supplies); in imx214_probe()
1125 struct imx214 *imx214 = to_imx214(sd); in imx214_remove() local
1127 v4l2_async_unregister_subdev(&imx214->sd); in imx214_remove()
1128 media_entity_cleanup(&imx214->sd.entity); in imx214_remove()
1129 v4l2_ctrl_handler_free(&imx214->ctrls); in imx214_remove()
1134 mutex_destroy(&imx214->mutex); in imx214_remove()
1138 { .compatible = "sony,imx214" },
1151 .name = "imx214",
1159 MODULE_DESCRIPTION("Sony IMX214 Camera driver");