Lines Matching +full:ovdd +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
19 #include <media/v4l2-ctrls.h>
20 #include <media/v4l2-fwnode.h>
21 #include <media/v4l2-subdev.h>
190 "ovdd",
222 ret = regmap_raw_read(sensor->regmap, addr & IMX296_REG_ADDR_MASK, data, in imx296_read()
238 ret = regmap_raw_write(sensor->regmap, addr & IMX296_REG_ADDR_MASK, in imx296_write()
241 dev_err(sensor->dev, "%u-bit write to 0x%04x failed: %d\n", in imx296_write()
255 ret = regulator_bulk_enable(ARRAY_SIZE(sensor->supplies), in imx296_power_on()
256 sensor->supplies); in imx296_power_on()
262 ret = gpiod_direction_output(sensor->reset, 0); in imx296_power_on()
268 ret = clk_prepare_enable(sensor->clk); in imx296_power_on()
275 * mentions a delay of 20µs in 4-wire mode, but tests showed that a in imx296_power_on()
284 gpiod_direction_output(sensor->reset, 1); in imx296_power_on()
286 regulator_bulk_disable(ARRAY_SIZE(sensor->supplies), sensor->supplies); in imx296_power_on()
292 clk_disable_unprepare(sensor->clk); in imx296_power_off()
293 gpiod_direction_output(sensor->reset, 1); in imx296_power_off()
294 regulator_bulk_disable(ARRAY_SIZE(sensor->supplies), sensor->supplies); in imx296_power_off()
297 /* -----------------------------------------------------------------------------
316 struct imx296 *sensor = container_of(ctrl->handler, struct imx296, ctrls); in imx296_s_ctrl()
322 if (!pm_runtime_get_if_in_use(sensor->dev)) in imx296_s_ctrl()
325 state = v4l2_subdev_get_locked_active_state(&sensor->subdev); in imx296_s_ctrl()
328 switch (ctrl->id) { in imx296_s_ctrl()
331 vmax = format->height + sensor->vblank->cur.val; in imx296_s_ctrl()
332 ctrl->val = min_t(int, ctrl->val, vmax); in imx296_s_ctrl()
333 imx296_write(sensor, IMX296_SHS1, vmax - ctrl->val, &ret); in imx296_s_ctrl()
337 imx296_write(sensor, IMX296_GAIN, ctrl->val, &ret); in imx296_s_ctrl()
341 imx296_write(sensor, IMX296_VMAX, format->height + ctrl->val, in imx296_s_ctrl()
346 if (ctrl->val) { in imx296_s_ctrl()
362 IMX296_PGCTRL_MODE(ctrl->val - 1), &ret); in imx296_s_ctrl()
373 ret = -EINVAL; in imx296_s_ctrl()
377 pm_runtime_put(sensor->dev); in imx296_s_ctrl()
392 ret = v4l2_fwnode_device_parse(sensor->dev, &props); in imx296_ctrls_init()
396 v4l2_ctrl_handler_init(&sensor->ctrls, 9); in imx296_ctrls_init()
398 v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops, in imx296_ctrls_init()
400 v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops, in imx296_ctrls_init()
411 - IMX296_PIXEL_ARRAY_WIDTH; in imx296_ctrls_init()
412 sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops, in imx296_ctrls_init()
415 if (sensor->hblank) in imx296_ctrls_init()
416 sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx296_ctrls_init()
418 sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops, in imx296_ctrls_init()
420 1048575 - IMX296_PIXEL_ARRAY_HEIGHT, in imx296_ctrls_init()
429 v4l2_ctrl_new_std(&sensor->ctrls, NULL, V4L2_CID_PIXEL_RATE, in imx296_ctrls_init()
431 v4l2_ctrl_new_std_menu_items(&sensor->ctrls, &imx296_ctrl_ops, in imx296_ctrls_init()
433 ARRAY_SIZE(imx296_test_pattern_menu) - 1, in imx296_ctrls_init()
436 v4l2_ctrl_new_fwnode_properties(&sensor->ctrls, &imx296_ctrl_ops, in imx296_ctrls_init()
439 if (sensor->ctrls.error) { in imx296_ctrls_init()
440 dev_err(sensor->dev, "failed to add controls (%d)\n", in imx296_ctrls_init()
441 sensor->ctrls.error); in imx296_ctrls_init()
442 v4l2_ctrl_handler_free(&sensor->ctrls); in imx296_ctrls_init()
443 return sensor->ctrls.error; in imx296_ctrls_init()
446 sensor->subdev.ctrl_handler = &sensor->ctrls; in imx296_ctrls_init()
451 /* -----------------------------------------------------------------------------
457 * first register write is required to activate the CSI-2 output. The other
476 { IMX296_REG_8BIT(0x31c8), 0xf3 }, /* Exposure-related */
477 { IMX296_REG_8BIT(0x31d0), 0xf4 }, /* Exposure-related */
521 if (crop->width != IMX296_PIXEL_ARRAY_WIDTH || in imx296_setup()
522 crop->height != IMX296_PIXEL_ARRAY_HEIGHT) { in imx296_setup()
525 imx296_write(sensor, IMX296_FID0_ROIPH1, crop->left, &ret); in imx296_setup()
526 imx296_write(sensor, IMX296_FID0_ROIPV1, crop->top, &ret); in imx296_setup()
527 imx296_write(sensor, IMX296_FID0_ROIWH1, crop->width, &ret); in imx296_setup()
528 imx296_write(sensor, IMX296_FID0_ROIWV1, crop->height, &ret); in imx296_setup()
534 (crop->width != format->width ? in imx296_setup()
536 (crop->height != format->height ? in imx296_setup()
550 * - one line for the FS packet in imx296_setup()
551 * - two lines of embedded data (DT 0x12) in imx296_setup()
552 * - six null lines (DT 0x10) in imx296_setup()
553 * - four lines of vertical effective optical black (DT 0x37) in imx296_setup()
554 * - 8 to 1088 lines of active image data (RAW10, DT 0x2b) in imx296_setup()
555 * - one line for the FE packet in imx296_setup()
556 * - 16 or more lines of vertical blanking in imx296_setup()
560 format->height + sensor->vblank->cur.val, &ret); in imx296_setup()
562 for (i = 0; i < ARRAY_SIZE(sensor->clk_params->incksel); ++i) in imx296_setup()
564 sensor->clk_params->incksel[i], &ret); in imx296_setup()
566 imx296_write(sensor, IMX296_CTRL418C, sensor->clk_params->ctrl418c, in imx296_setup()
607 pm_runtime_mark_last_busy(sensor->dev); in imx296_s_stream()
608 pm_runtime_put_autosuspend(sensor->dev); in imx296_s_stream()
613 ret = pm_runtime_resume_and_get(sensor->dev); in imx296_s_stream()
621 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls); in imx296_s_stream()
639 pm_runtime_put_sync(sensor->dev); in imx296_s_stream()
650 if (code->index != 0) in imx296_enum_mbus_code()
651 return -EINVAL; in imx296_enum_mbus_code()
653 code->code = sensor->mono ? MEDIA_BUS_FMT_Y10_1X10 in imx296_enum_mbus_code()
665 format = v4l2_subdev_state_get_format(state, fse->pad); in imx296_enum_frame_size()
667 if (fse->index >= 2 || fse->code != format->code) in imx296_enum_frame_size()
668 return -EINVAL; in imx296_enum_frame_size()
670 fse->min_width = IMX296_PIXEL_ARRAY_WIDTH / (fse->index + 1); in imx296_enum_frame_size()
671 fse->max_width = fse->min_width; in imx296_enum_frame_size()
672 fse->min_height = IMX296_PIXEL_ARRAY_HEIGHT / (fse->index + 1); in imx296_enum_frame_size()
673 fse->max_height = fse->min_height; in imx296_enum_frame_size()
686 crop = v4l2_subdev_state_get_crop(state, fmt->pad); in imx296_set_format()
687 format = v4l2_subdev_state_get_format(state, fmt->pad); in imx296_set_format()
691 * documentation. This should be double-checked. in imx296_set_format()
693 if (crop->width == IMX296_PIXEL_ARRAY_WIDTH && in imx296_set_format()
694 crop->height == IMX296_PIXEL_ARRAY_HEIGHT) { in imx296_set_format()
701 width = clamp_t(unsigned int, fmt->format.width, in imx296_set_format()
702 crop->width / 2, crop->width); in imx296_set_format()
703 height = clamp_t(unsigned int, fmt->format.height, in imx296_set_format()
704 crop->height / 2, crop->height); in imx296_set_format()
706 hratio = DIV_ROUND_CLOSEST(crop->width, width); in imx296_set_format()
707 vratio = DIV_ROUND_CLOSEST(crop->height, height); in imx296_set_format()
709 format->width = crop->width / hratio; in imx296_set_format()
710 format->height = crop->height / vratio; in imx296_set_format()
712 format->width = crop->width; in imx296_set_format()
713 format->height = crop->height; in imx296_set_format()
716 format->code = sensor->mono ? MEDIA_BUS_FMT_Y10_1X10 in imx296_set_format()
718 format->field = V4L2_FIELD_NONE; in imx296_set_format()
719 format->colorspace = V4L2_COLORSPACE_RAW; in imx296_set_format()
720 format->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in imx296_set_format()
721 format->quantization = V4L2_QUANTIZATION_FULL_RANGE; in imx296_set_format()
722 format->xfer_func = V4L2_XFER_FUNC_NONE; in imx296_set_format()
724 fmt->format = *format; in imx296_set_format()
733 switch (sel->target) { in imx296_get_selection()
735 sel->r = *v4l2_subdev_state_get_crop(state, sel->pad); in imx296_get_selection()
741 sel->r.left = 0; in imx296_get_selection()
742 sel->r.top = 0; in imx296_get_selection()
743 sel->r.width = IMX296_PIXEL_ARRAY_WIDTH; in imx296_get_selection()
744 sel->r.height = IMX296_PIXEL_ARRAY_HEIGHT; in imx296_get_selection()
748 return -EINVAL; in imx296_get_selection()
762 if (sel->target != V4L2_SEL_TGT_CROP) in imx296_set_selection()
763 return -EINVAL; in imx296_set_selection()
769 rect.left = clamp(ALIGN(sel->r.left, 4), 0, in imx296_set_selection()
770 IMX296_PIXEL_ARRAY_WIDTH - IMX296_FID0_ROIWH1_MIN); in imx296_set_selection()
771 rect.top = clamp(ALIGN(sel->r.top, 4), 0, in imx296_set_selection()
772 IMX296_PIXEL_ARRAY_HEIGHT - IMX296_FID0_ROIWV1_MIN); in imx296_set_selection()
773 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 4), in imx296_set_selection()
775 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 4), in imx296_set_selection()
779 IMX296_PIXEL_ARRAY_WIDTH - rect.left); in imx296_set_selection()
781 IMX296_PIXEL_ARRAY_HEIGHT - rect.top); in imx296_set_selection()
783 crop = v4l2_subdev_state_get_crop(state, sel->pad); in imx296_set_selection()
785 if (rect.width != crop->width || rect.height != crop->height) { in imx296_set_selection()
790 format = v4l2_subdev_state_get_format(state, sel->pad); in imx296_set_selection()
791 format->width = rect.width; in imx296_set_selection()
792 format->height = rect.height; in imx296_set_selection()
796 sel->r = rect; in imx296_set_selection()
846 struct i2c_client *client = to_i2c_client(sensor->dev); in imx296_subdev_init()
849 v4l2_i2c_subdev_init(&sensor->subdev, client, &imx296_subdev_ops); in imx296_subdev_init()
850 sensor->subdev.internal_ops = &imx296_internal_ops; in imx296_subdev_init()
856 sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx296_subdev_init()
857 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in imx296_subdev_init()
858 sensor->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx296_subdev_init()
859 ret = media_entity_pads_init(&sensor->subdev.entity, 1, &sensor->pad); in imx296_subdev_init()
861 v4l2_ctrl_handler_free(&sensor->ctrls); in imx296_subdev_init()
865 sensor->subdev.state_lock = sensor->subdev.ctrl_handler->lock; in imx296_subdev_init()
867 v4l2_subdev_init_finalize(&sensor->subdev); in imx296_subdev_init()
874 media_entity_cleanup(&sensor->subdev.entity); in imx296_subdev_cleanup()
875 v4l2_ctrl_handler_free(&sensor->ctrls); in imx296_subdev_cleanup()
878 /* -----------------------------------------------------------------------------
906 /* -----------------------------------------------------------------------------
925 /* T(°C) = 246.312 - 0.304 * TMDOUT */; in imx296_read_temperature()
926 *temp = 246312 - 304 * tmdout; in imx296_read_temperature()
937 model = (uintptr_t)of_device_get_match_data(sensor->dev); in imx296_identify_model()
939 dev_dbg(sensor->dev, in imx296_identify_model()
940 "sensor model auto-detection disabled, forcing 0x%04x\n", in imx296_identify_model()
942 sensor->mono = model & IMX296_SENSOR_INFO_MONO; in imx296_identify_model()
948 * is not the case of the sensor info register :-( in imx296_identify_model()
952 dev_err(sensor->dev, in imx296_identify_model()
959 dev_err(sensor->dev, "failed to read sensor information (%d)\n", in imx296_identify_model()
968 sensor->mono = ret & IMX296_SENSOR_INFO_MONO; in imx296_identify_model()
976 dev_err(sensor->dev, "invalid device model 0x%04x\n", ret); in imx296_identify_model()
977 ret = -ENODEV; in imx296_identify_model()
985 dev_info(sensor->dev, "found IMX%u%s (%u.%uC)\n", model, in imx296_identify_model()
986 sensor->mono ? "LL" : "LQ", temp / 1000, (temp / 100) % 10); in imx296_identify_model()
1010 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); in imx296_probe()
1017 dev_warn(&adapter->dev, in imx296_probe()
1018 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE\n"); in imx296_probe()
1019 return -EIO; in imx296_probe()
1022 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); in imx296_probe()
1024 return -ENOMEM; in imx296_probe()
1026 sensor->dev = &client->dev; in imx296_probe()
1029 for (i = 0; i < ARRAY_SIZE(sensor->supplies); ++i) in imx296_probe()
1030 sensor->supplies[i].supply = imx296_supply_names[i]; in imx296_probe()
1032 ret = devm_regulator_bulk_get(sensor->dev, ARRAY_SIZE(sensor->supplies), in imx296_probe()
1033 sensor->supplies); in imx296_probe()
1035 dev_err_probe(sensor->dev, ret, "failed to get supplies\n"); in imx296_probe()
1039 sensor->reset = devm_gpiod_get_optional(sensor->dev, "reset", in imx296_probe()
1041 if (IS_ERR(sensor->reset)) in imx296_probe()
1042 return dev_err_probe(sensor->dev, PTR_ERR(sensor->reset), in imx296_probe()
1045 sensor->clk = devm_clk_get(sensor->dev, "inck"); in imx296_probe()
1046 if (IS_ERR(sensor->clk)) in imx296_probe()
1047 return dev_err_probe(sensor->dev, PTR_ERR(sensor->clk), in imx296_probe()
1050 clk_rate = clk_get_rate(sensor->clk); in imx296_probe()
1053 sensor->clk_params = &imx296_clk_params[i]; in imx296_probe()
1058 if (!sensor->clk_params) { in imx296_probe()
1059 dev_err(sensor->dev, "unsupported clock rate %lu\n", clk_rate); in imx296_probe()
1060 return -EINVAL; in imx296_probe()
1063 sensor->regmap = devm_regmap_init_i2c(client, &imx296_regmap_config); in imx296_probe()
1064 if (IS_ERR(sensor->regmap)) in imx296_probe()
1065 return PTR_ERR(sensor->regmap); in imx296_probe()
1089 pm_runtime_set_active(sensor->dev); in imx296_probe()
1090 pm_runtime_get_noresume(sensor->dev); in imx296_probe()
1091 pm_runtime_enable(sensor->dev); in imx296_probe()
1094 ret = v4l2_async_register_subdev(&sensor->subdev); in imx296_probe()
1103 pm_runtime_set_autosuspend_delay(sensor->dev, 1000); in imx296_probe()
1104 pm_runtime_use_autosuspend(sensor->dev); in imx296_probe()
1105 pm_runtime_put_autosuspend(sensor->dev); in imx296_probe()
1110 pm_runtime_disable(sensor->dev); in imx296_probe()
1111 pm_runtime_put_noidle(sensor->dev); in imx296_probe()
1131 pm_runtime_disable(sensor->dev); in imx296_remove()
1132 if (!pm_runtime_status_suspended(sensor->dev)) in imx296_remove()
1134 pm_runtime_set_suspended(sensor->dev); in imx296_remove()