Lines Matching +full:pwdn +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0
16 #include <media/media-entity.h>
17 #include <media/v4l2-async.h>
18 #include <media/v4l2-ctrls.h>
19 #include <media/v4l2-subdev.h>
20 #include <media/v4l2-fwnode.h>
290 return -EINVAL; in ov4689_write_reg()
298 val_i = 4 - len; in ov4689_write_reg()
304 return -EIO; in ov4689_write_reg()
333 return -EINVAL; in ov4689_read_reg()
337 msgs[0].addr = client->addr; in ov4689_read_reg()
343 msgs[1].addr = client->addr; in ov4689_read_reg()
346 msgs[1].buf = &data_be_p[4 - len]; in ov4689_read_reg()
348 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in ov4689_read_reg()
350 return -EIO; in ov4689_read_reg()
360 fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov4689_fill_fmt()
361 fmt->width = mode->width; in ov4689_fill_fmt()
362 fmt->height = mode->height; in ov4689_fill_fmt()
363 fmt->field = V4L2_FIELD_NONE; in ov4689_fill_fmt()
370 struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; in ov4689_set_fmt()
374 ov4689_fill_fmt(ov4689->cur_mode, mbus_fmt); in ov4689_set_fmt()
383 struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; in ov4689_get_fmt()
387 ov4689_fill_fmt(ov4689->cur_mode, mbus_fmt); in ov4689_get_fmt()
396 if (code->index != 0) in ov4689_enum_mbus_code()
397 return -EINVAL; in ov4689_enum_mbus_code()
398 code->code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov4689_enum_mbus_code()
407 if (fse->index >= ARRAY_SIZE(supported_modes)) in ov4689_enum_frame_sizes()
408 return -EINVAL; in ov4689_enum_frame_sizes()
410 if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) in ov4689_enum_frame_sizes()
411 return -EINVAL; in ov4689_enum_frame_sizes()
413 fse->min_width = supported_modes[fse->index].width; in ov4689_enum_frame_sizes()
414 fse->max_width = supported_modes[fse->index].width; in ov4689_enum_frame_sizes()
415 fse->max_height = supported_modes[fse->index].height; in ov4689_enum_frame_sizes()
416 fse->min_height = supported_modes[fse->index].height; in ov4689_enum_frame_sizes()
426 val = (pattern - 1) | OV4689_TEST_PATTERN_ENABLE; in ov4689_enable_test_pattern()
430 return ov4689_write_reg(ov4689->client, OV4689_REG_TEST_PATTERN, in ov4689_enable_test_pattern()
438 const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; in ov4689_get_selection()
440 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov4689_get_selection()
441 return -EINVAL; in ov4689_get_selection()
443 switch (sel->target) { in ov4689_get_selection()
445 sel->r.top = 0; in ov4689_get_selection()
446 sel->r.left = 0; in ov4689_get_selection()
447 sel->r.width = mode->sensor_width; in ov4689_get_selection()
448 sel->r.height = mode->sensor_height; in ov4689_get_selection()
452 sel->r.top = mode->crop_top; in ov4689_get_selection()
453 sel->r.left = mode->crop_left; in ov4689_get_selection()
454 sel->r.width = mode->width; in ov4689_get_selection()
455 sel->r.height = mode->height; in ov4689_get_selection()
459 return -EINVAL; in ov4689_get_selection()
465 struct i2c_client *client = ov4689->client; in ov4689_s_stream()
468 mutex_lock(&ov4689->mutex); in ov4689_s_stream()
471 ret = pm_runtime_resume_and_get(&client->dev); in ov4689_s_stream()
475 ret = ov4689_write_array(ov4689->client, in ov4689_s_stream()
476 ov4689->cur_mode->reg_list); in ov4689_s_stream()
478 pm_runtime_put(&client->dev); in ov4689_s_stream()
482 ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); in ov4689_s_stream()
484 pm_runtime_put(&client->dev); in ov4689_s_stream()
488 ret = ov4689_write_reg(ov4689->client, OV4689_REG_CTRL_MODE, in ov4689_s_stream()
492 pm_runtime_put(&client->dev); in ov4689_s_stream()
496 ov4689_write_reg(ov4689->client, OV4689_REG_CTRL_MODE, in ov4689_s_stream()
499 pm_runtime_put(&client->dev); in ov4689_s_stream()
503 mutex_unlock(&ov4689->mutex); in ov4689_s_stream()
512 DIV_ROUND_UP(ov4689->clock_rate, 1000)); in ov4689_cal_delay()
522 ret = clk_prepare_enable(ov4689->xvclk); in ov4689_power_on()
528 gpiod_set_value_cansleep(ov4689->reset_gpio, 1); in ov4689_power_on()
531 ov4689->supplies); in ov4689_power_on()
537 gpiod_set_value_cansleep(ov4689->reset_gpio, 0); in ov4689_power_on()
539 gpiod_set_value_cansleep(ov4689->pwdn_gpio, 0); in ov4689_power_on()
548 clk_disable_unprepare(ov4689->xvclk); in ov4689_power_on()
558 gpiod_set_value_cansleep(ov4689->pwdn_gpio, 1); in ov4689_power_off()
559 clk_disable_unprepare(ov4689->xvclk); in ov4689_power_off()
560 gpiod_set_value_cansleep(ov4689->reset_gpio, 1); in ov4689_power_off()
562 ov4689->supplies); in ov4689_power_off()
571 mutex_lock(&ov4689->mutex); in ov4689_open()
573 try_fmt = v4l2_subdev_state_get_format(fh->state, 0); in ov4689_open()
577 mutex_unlock(&ov4689->mutex); in ov4689_open()
613 const struct device *dev = &ov4689->client->dev; in ov4689_map_gain()
626 return -EINVAL; in ov4689_map_gain()
631 *result = clamp(range->offset + (logical_gain) / range->divider, in ov4689_map_gain()
632 range->physical_min, range->physical_max); in ov4689_map_gain()
639 container_of(ctrl->handler, struct ov4689, ctrl_handler); in ov4689_set_ctrl()
640 struct i2c_client *client = ov4689->client; in ov4689_set_ctrl()
646 switch (ctrl->id) { in ov4689_set_ctrl()
649 max_expo = ov4689->cur_mode->height + ctrl->val - 4; in ov4689_set_ctrl()
650 __v4l2_ctrl_modify_range(ov4689->exposure, in ov4689_set_ctrl()
651 ov4689->exposure->minimum, max_expo, in ov4689_set_ctrl()
652 ov4689->exposure->step, in ov4689_set_ctrl()
653 ov4689->exposure->default_value); in ov4689_set_ctrl()
657 if (!pm_runtime_get_if_in_use(&client->dev)) in ov4689_set_ctrl()
660 switch (ctrl->id) { in ov4689_set_ctrl()
663 ret = ov4689_write_reg(ov4689->client, OV4689_REG_EXPOSURE, in ov4689_set_ctrl()
664 OV4689_REG_VALUE_24BIT, ctrl->val << 4); in ov4689_set_ctrl()
667 ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); in ov4689_set_ctrl()
670 ov4689_write_reg(ov4689->client, OV4689_REG_GAIN_H, in ov4689_set_ctrl()
675 ov4689_write_reg(ov4689->client, OV4689_REG_GAIN_L, in ov4689_set_ctrl()
680 ret = ov4689_write_reg(ov4689->client, OV4689_REG_VTS, in ov4689_set_ctrl()
682 ctrl->val + ov4689->cur_mode->height); in ov4689_set_ctrl()
685 ret = ov4689_enable_test_pattern(ov4689, ctrl->val); in ov4689_set_ctrl()
688 dev_warn(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", in ov4689_set_ctrl()
689 __func__, ctrl->id, ctrl->val); in ov4689_set_ctrl()
690 ret = -EINVAL; in ov4689_set_ctrl()
694 pm_runtime_put(&client->dev); in ov4689_set_ctrl()
705 struct i2c_client *client = v4l2_get_subdevdata(&ov4689->subdev); in ov4689_initialize_controls()
714 handler = &ov4689->ctrl_handler; in ov4689_initialize_controls()
715 mode = ov4689->cur_mode; in ov4689_initialize_controls()
719 handler->lock = &ov4689->mutex; in ov4689_initialize_controls()
724 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov4689_initialize_controls()
727 mode->pixel_rate, 1, mode->pixel_rate); in ov4689_initialize_controls()
729 h_blank_def = mode->hts_def - mode->width; in ov4689_initialize_controls()
733 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov4689_initialize_controls()
735 vblank_def = mode->vts_def - mode->height; in ov4689_initialize_controls()
737 vblank_def, OV4689_VTS_MAX - mode->height, 1, in ov4689_initialize_controls()
740 exposure_max = mode->vts_def - 4; in ov4689_initialize_controls()
741 ov4689->exposure = in ov4689_initialize_controls()
744 OV4689_EXPOSURE_STEP, mode->exp_def); in ov4689_initialize_controls()
748 ov4689_gain_ranges[ARRAY_SIZE(ov4689_gain_ranges) - 1] in ov4689_initialize_controls()
754 ARRAY_SIZE(ov4689_test_pattern_menu) - 1, in ov4689_initialize_controls()
757 if (handler->error) { in ov4689_initialize_controls()
758 ret = handler->error; in ov4689_initialize_controls()
759 dev_err(&ov4689->client->dev, "Failed to init controls(%d)\n", in ov4689_initialize_controls()
764 ret = v4l2_fwnode_device_parse(&client->dev, &props); in ov4689_initialize_controls()
773 ov4689->subdev.ctrl_handler = handler; in ov4689_initialize_controls()
786 struct device *dev = &ov4689->client->dev; in ov4689_check_sensor_id()
800 return -ENODEV; in ov4689_check_sensor_id()
813 ov4689->supplies[i].supply = ov4689_supply_names[i]; in ov4689_configure_regulators()
815 return devm_regulator_bulk_get(&ov4689->client->dev, in ov4689_configure_regulators()
817 ov4689->supplies); in ov4689_configure_regulators()
826 for (j = 0; j < ep->nr_of_link_frequencies; j++) in ov4689_check_link_frequency()
827 if (freqs[i] == ep->link_frequencies[j]) in ov4689_check_link_frequency()
845 return -EINVAL; in ov4689_check_hwcfg()
853 dev_err(dev, "Only a 4-lane CSI2 config is supported"); in ov4689_check_hwcfg()
854 ret = -EINVAL; in ov4689_check_hwcfg()
860 ret = -EINVAL; in ov4689_check_hwcfg()
871 struct device *dev = &client->dev; in ov4689_probe()
882 return -ENOMEM; in ov4689_probe()
884 ov4689->client = client; in ov4689_probe()
885 ov4689->cur_mode = &supported_modes[OV4689_MODE_2688_1520]; in ov4689_probe()
887 ov4689->xvclk = devm_clk_get_optional(dev, NULL); in ov4689_probe()
888 if (IS_ERR(ov4689->xvclk)) in ov4689_probe()
889 return dev_err_probe(dev, PTR_ERR(ov4689->xvclk), in ov4689_probe()
892 if (!ov4689->xvclk) { in ov4689_probe()
894 "No clock provided, using clock-frequency property\n"); in ov4689_probe()
895 device_property_read_u32(dev, "clock-frequency", in ov4689_probe()
896 &ov4689->clock_rate); in ov4689_probe()
898 ov4689->clock_rate = clk_get_rate(ov4689->xvclk); in ov4689_probe()
901 if (ov4689->clock_rate != OV4689_XVCLK_FREQ) { in ov4689_probe()
904 ov4689->clock_rate, OV4689_XVCLK_FREQ); in ov4689_probe()
905 return -EINVAL; in ov4689_probe()
908 ov4689->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov4689_probe()
910 if (IS_ERR(ov4689->reset_gpio)) { in ov4689_probe()
911 dev_err(dev, "Failed to get reset-gpios\n"); in ov4689_probe()
912 return PTR_ERR(ov4689->reset_gpio); in ov4689_probe()
915 ov4689->pwdn_gpio = devm_gpiod_get_optional(dev, "pwdn", GPIOD_OUT_LOW); in ov4689_probe()
916 if (IS_ERR(ov4689->pwdn_gpio)) { in ov4689_probe()
917 dev_err(dev, "Failed to get pwdn-gpios\n"); in ov4689_probe()
918 return PTR_ERR(ov4689->pwdn_gpio); in ov4689_probe()
926 mutex_init(&ov4689->mutex); in ov4689_probe()
928 sd = &ov4689->subdev; in ov4689_probe()
942 sd->internal_ops = &ov4689_internal_ops; in ov4689_probe()
943 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov4689_probe()
945 ov4689->pad.flags = MEDIA_PAD_FL_SOURCE; in ov4689_probe()
946 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov4689_probe()
947 ret = media_entity_pads_init(&sd->entity, 1, &ov4689->pad); in ov4689_probe()
964 media_entity_cleanup(&sd->entity); in ov4689_probe()
968 v4l2_ctrl_handler_free(&ov4689->ctrl_handler); in ov4689_probe()
970 mutex_destroy(&ov4689->mutex); in ov4689_probe()
981 media_entity_cleanup(&sd->entity); in ov4689_remove()
983 v4l2_ctrl_handler_free(&ov4689->ctrl_handler); in ov4689_remove()
984 mutex_destroy(&ov4689->mutex); in ov4689_remove()
986 pm_runtime_disable(&client->dev); in ov4689_remove()
987 if (!pm_runtime_status_suspended(&client->dev)) in ov4689_remove()
988 ov4689_power_off(&client->dev); in ov4689_remove()
989 pm_runtime_set_suspended(&client->dev); in ov4689_remove()