Lines Matching +full:vdddo +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
3 * imx214.c - imx214 sensor driver
17 #include <media/media-entity.h>
18 #include <media/v4l2-ctrls.h>
19 #include <media/v4l2-fwnode.h>
20 #include <media/v4l2-subdev.h>
50 "vdddo",
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()
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()
497 if (code->index > 0) in imx214_enum_mbus_code()
498 return -EINVAL; in imx214_enum_mbus_code()
500 code->code = IMX214_MBUS_CODE; in imx214_enum_mbus_code()
509 if (fse->code != IMX214_MBUS_CODE) in imx214_enum_frame_size()
510 return -EINVAL; in imx214_enum_frame_size()
512 if (fse->index >= ARRAY_SIZE(imx214_modes)) in imx214_enum_frame_size()
513 return -EINVAL; in imx214_enum_frame_size()
515 fse->min_width = fse->max_width = imx214_modes[fse->index].width; in imx214_enum_frame_size()
516 fse->min_height = fse->max_height = imx214_modes[fse->index].height; in imx214_enum_frame_size()
527 return regmap_write(imx214->regmap, reg->reg, reg->val); in imx214_s_register()
537 reg->size = 1; in imx214_g_register()
538 ret = regmap_read(imx214->regmap, reg->reg, &aux); in imx214_g_register()
539 reg->val = aux; in imx214_g_register()
562 return &imx214->fmt; in __imx214_get_pad_format()
574 mutex_lock(&imx214->mutex); in imx214_get_format()
575 format->format = *__imx214_get_pad_format(imx214, sd_state, in imx214_get_format()
576 format->pad, in imx214_get_format()
577 format->which); in imx214_get_format()
578 mutex_unlock(&imx214->mutex); in imx214_get_format()
592 return &imx214->crop; in __imx214_get_pad_crop()
607 mutex_lock(&imx214->mutex); in imx214_set_format()
609 __crop = __imx214_get_pad_crop(imx214, sd_state, format->pad, in imx214_set_format()
610 format->which); in imx214_set_format()
614 format->format.width, in imx214_set_format()
615 format->format.height); in imx214_set_format()
617 __crop->width = mode->width; in imx214_set_format()
618 __crop->height = mode->height; in imx214_set_format()
620 __format = __imx214_get_pad_format(imx214, sd_state, format->pad, in imx214_set_format()
621 format->which); in imx214_set_format()
622 __format->width = __crop->width; in imx214_set_format()
623 __format->height = __crop->height; in imx214_set_format()
624 __format->code = IMX214_MBUS_CODE; in imx214_set_format()
625 __format->field = V4L2_FIELD_NONE; in imx214_set_format()
626 __format->colorspace = V4L2_COLORSPACE_SRGB; in imx214_set_format()
627 __format->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(__format->colorspace); in imx214_set_format()
628 __format->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in imx214_set_format()
629 __format->colorspace, __format->ycbcr_enc); in imx214_set_format()
630 __format->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(__format->colorspace); in imx214_set_format()
632 format->format = *__format; in imx214_set_format()
634 mutex_unlock(&imx214->mutex); in imx214_set_format()
645 switch (sel->target) { in imx214_get_selection()
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()
649 sel->which); in imx214_get_selection()
650 mutex_unlock(&imx214->mutex); in imx214_get_selection()
654 sel->r.top = 0; in imx214_get_selection()
655 sel->r.left = 0; in imx214_get_selection()
656 sel->r.width = IMX214_NATIVE_WIDTH; in imx214_get_selection()
657 sel->r.height = IMX214_NATIVE_HEIGHT; in imx214_get_selection()
662 sel->r.top = IMX214_PIXEL_ARRAY_TOP; in imx214_get_selection()
663 sel->r.left = IMX214_PIXEL_ARRAY_LEFT; in imx214_get_selection()
664 sel->r.width = IMX214_PIXEL_ARRAY_WIDTH; in imx214_get_selection()
665 sel->r.height = IMX214_PIXEL_ARRAY_HEIGHT; in imx214_get_selection()
669 return -EINVAL; in imx214_get_selection()
688 struct imx214 *imx214 = container_of(ctrl->handler, in imx214_set_ctrl()
697 if (!pm_runtime_get_if_in_use(imx214->dev)) in imx214_set_ctrl()
700 switch (ctrl->id) { in imx214_set_ctrl()
702 vals[1] = ctrl->val; in imx214_set_ctrl()
703 vals[0] = ctrl->val >> 8; 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()
711 ret = -EINVAL; in imx214_set_ctrl()
714 pm_runtime_put(imx214->dev); in imx214_set_ctrl()
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()
752 ARRAY_SIZE(link_freq) - 1, 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()
781 ret = ctrl_hdlr->error; 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()
801 for (; table->addr != IMX214_TABLE_END ; table++) { in imx214_write_table()
802 if (table->addr == IMX214_TABLE_WAIT_MS) { in imx214_write_table()
803 usleep_range(table->val * 1000, in imx214_write_table()
804 table->val * 1000 + 500); in imx214_write_table()
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()
821 table += i - 1; in imx214_write_table()
832 mutex_lock(&imx214->mutex); 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()
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()
883 ret = pm_runtime_resume_and_get(imx214->dev); in imx214_s_stream()
894 pm_runtime_put(imx214->dev); in imx214_s_stream()
900 pm_runtime_put(imx214->dev); in imx214_s_stream()
912 if (fival->which != V4L2_SUBDEV_FORMAT_ACTIVE) in imx214_get_frame_interval()
913 return -EINVAL; in imx214_get_frame_interval()
915 fival->interval.numerator = 1; in imx214_get_frame_interval()
916 fival->interval.denominator = IMX214_FPS; in imx214_get_frame_interval()
927 if (fie->index != 0) in imx214_enum_frame_interval()
928 return -EINVAL; in imx214_enum_frame_interval()
932 fie->width, fie->height); in imx214_enum_frame_interval()
934 fie->code = IMX214_MBUS_CODE; in imx214_enum_frame_interval()
935 fie->width = mode->width; in imx214_enum_frame_interval()
936 fie->height = mode->height; in imx214_enum_frame_interval()
937 fie->interval.numerator = 1; in imx214_enum_frame_interval()
938 fie->interval.denominator = IMX214_FPS; in imx214_enum_frame_interval()
979 imx214->supplies[i].supply = imx214_supply_name[i]; in imx214_get_regulators()
982 imx214->supplies); in imx214_get_regulators()
997 return -EINVAL; in imx214_parse_fwnode()
1011 dev_err(dev, "link-frequencies %d not supported, Please review your DT\n", in imx214_parse_fwnode()
1013 ret = -EINVAL; in imx214_parse_fwnode()
1025 struct device *dev = &client->dev; in imx214_probe()
1035 return -ENOMEM; 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()
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()
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()
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()
1131 pm_runtime_disable(&client->dev); in imx214_remove()
1132 pm_runtime_set_suspended(&client->dev); in imx214_remove()
1134 mutex_destroy(&imx214->mutex); in imx214_remove()