Lines Matching +full:ep +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0
13 #include <media/media-entity.h>
14 #include <media/v4l2-async.h>
15 #include <media/v4l2-ctrls.h>
16 #include <media/v4l2-fwnode.h>
17 #include <media/v4l2-subdev.h>
275 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_write_array()
279 for (i = 0; i < r_list->num_of_regs; i++) { in ov02a10_write_array()
280 ret = i2c_smbus_write_byte_data(client, r_list->regs[i].addr, in ov02a10_write_array()
281 r_list->regs[i].val); in ov02a10_write_array()
292 fmt->width = mode->width; in ov02a10_fill_fmt()
293 fmt->height = mode->height; in ov02a10_fill_fmt()
294 fmt->field = V4L2_FIELD_NONE; in ov02a10_fill_fmt()
302 struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; in ov02a10_set_fmt()
306 mutex_lock(&ov02a10->mutex); in ov02a10_set_fmt()
308 if (ov02a10->streaming && fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in ov02a10_set_fmt()
309 ret = -EBUSY; in ov02a10_set_fmt()
314 mbus_fmt->code = ov02a10->fmt.code; in ov02a10_set_fmt()
315 ov02a10_fill_fmt(ov02a10->cur_mode, mbus_fmt); in ov02a10_set_fmt()
317 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) in ov02a10_set_fmt()
320 frame_fmt = &ov02a10->fmt; in ov02a10_set_fmt()
325 mutex_unlock(&ov02a10->mutex); in ov02a10_set_fmt()
334 struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; in ov02a10_get_fmt()
336 mutex_lock(&ov02a10->mutex); in ov02a10_get_fmt()
338 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in ov02a10_get_fmt()
339 fmt->format = *v4l2_subdev_state_get_format(sd_state, in ov02a10_get_fmt()
340 fmt->pad); in ov02a10_get_fmt()
342 fmt->format = ov02a10->fmt; in ov02a10_get_fmt()
343 mbus_fmt->code = ov02a10->fmt.code; in ov02a10_get_fmt()
344 ov02a10_fill_fmt(ov02a10->cur_mode, mbus_fmt); in ov02a10_get_fmt()
347 mutex_unlock(&ov02a10->mutex); in ov02a10_get_fmt()
358 if (code->index != 0) in ov02a10_enum_mbus_code()
359 return -EINVAL; in ov02a10_enum_mbus_code()
361 code->code = ov02a10->fmt.code; in ov02a10_enum_mbus_code()
370 if (fse->index >= ARRAY_SIZE(supported_modes)) in ov02a10_enum_frame_sizes()
371 return -EINVAL; in ov02a10_enum_frame_sizes()
373 fse->min_width = supported_modes[fse->index].width; in ov02a10_enum_frame_sizes()
374 fse->max_width = supported_modes[fse->index].width; in ov02a10_enum_frame_sizes()
375 fse->max_height = supported_modes[fse->index].height; in ov02a10_enum_frame_sizes()
376 fse->min_height = supported_modes[fse->index].height; in ov02a10_enum_frame_sizes()
383 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_check_sensor_id()
395 dev_err(&client->dev, "unexpected sensor id(0x%04x)\n", chip_id); in ov02a10_check_sensor_id()
396 return -EINVAL; in ov02a10_check_sensor_id()
409 gpiod_set_value_cansleep(ov02a10->rst_gpio, 1); in ov02a10_power_on()
410 gpiod_set_value_cansleep(ov02a10->pd_gpio, 1); in ov02a10_power_on()
412 ret = clk_prepare_enable(ov02a10->eclk); in ov02a10_power_on()
419 ov02a10->supplies); in ov02a10_power_on()
426 gpiod_set_value_cansleep(ov02a10->pd_gpio, 0); in ov02a10_power_on()
429 gpiod_set_value_cansleep(ov02a10->rst_gpio, 0); in ov02a10_power_on()
440 ov02a10->supplies); in ov02a10_power_on()
442 clk_disable_unprepare(ov02a10->eclk); in ov02a10_power_on()
453 gpiod_set_value_cansleep(ov02a10->rst_gpio, 1); in ov02a10_power_off()
454 clk_disable_unprepare(ov02a10->eclk); in ov02a10_power_off()
455 gpiod_set_value_cansleep(ov02a10->pd_gpio, 1); in ov02a10_power_off()
457 ov02a10->supplies); in ov02a10_power_off()
464 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in __ov02a10_start_stream()
469 reg_list = &ov02a10->cur_mode->reg_list; in __ov02a10_start_stream()
475 ret = __v4l2_ctrl_handler_setup(ov02a10->subdev.ctrl_handler); in __ov02a10_start_stream()
480 if (ov02a10->upside_down) { in __ov02a10_start_stream()
484 dev_err(&client->dev, "failed to set orientation\n"); in __ov02a10_start_stream()
494 if (ov02a10->mipi_clock_voltage != OV02A10_MIPI_TX_SPEED_DEFAULT) { in __ov02a10_start_stream()
496 ov02a10->mipi_clock_voltage); in __ov02a10_start_stream()
508 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in __ov02a10_stop_stream()
533 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_s_stream()
536 mutex_lock(&ov02a10->mutex); in ov02a10_s_stream()
538 if (ov02a10->streaming == on) { in ov02a10_s_stream()
544 ret = pm_runtime_resume_and_get(&client->dev); in ov02a10_s_stream()
551 ov02a10->streaming = !on; in ov02a10_s_stream()
556 pm_runtime_put(&client->dev); in ov02a10_s_stream()
559 ov02a10->streaming = on; in ov02a10_s_stream()
560 mutex_unlock(&ov02a10->mutex); in ov02a10_s_stream()
565 pm_runtime_put(&client->dev); in ov02a10_s_stream()
567 mutex_unlock(&ov02a10->mutex); in ov02a10_s_stream()
578 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_set_exposure()
600 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_set_gain()
617 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_set_vblank()
618 u32 vts = val + ov02a10->cur_mode->height - OV02A10_BASE_LINES; in ov02a10_set_vblank()
640 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_set_test_pattern()
663 struct ov02a10 *ov02a10 = container_of(ctrl->handler, in ov02a10_set_ctrl()
665 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_set_ctrl()
670 if (ctrl->id == V4L2_CID_VBLANK) { in ov02a10_set_ctrl()
672 max_expo = ov02a10->cur_mode->height + ctrl->val - in ov02a10_set_ctrl()
674 __v4l2_ctrl_modify_range(ov02a10->exposure, in ov02a10_set_ctrl()
675 ov02a10->exposure->minimum, max_expo, in ov02a10_set_ctrl()
676 ov02a10->exposure->step, in ov02a10_set_ctrl()
677 ov02a10->exposure->default_value); in ov02a10_set_ctrl()
681 if (!pm_runtime_get_if_in_use(&client->dev)) in ov02a10_set_ctrl()
684 switch (ctrl->id) { in ov02a10_set_ctrl()
686 ret = ov02a10_set_exposure(ov02a10, ctrl->val); in ov02a10_set_ctrl()
689 ret = ov02a10_set_gain(ov02a10, ctrl->val); in ov02a10_set_ctrl()
692 ret = ov02a10_set_vblank(ov02a10, ctrl->val); in ov02a10_set_ctrl()
695 ret = ov02a10_set_test_pattern(ov02a10, ctrl->val); in ov02a10_set_ctrl()
698 ret = -EINVAL; in ov02a10_set_ctrl()
702 pm_runtime_put(&client->dev); in ov02a10_set_ctrl()
737 struct i2c_client *client = v4l2_get_subdevdata(&ov02a10->subdev); in ov02a10_initialize_controls()
747 handler = &ov02a10->ctrl_handler; in ov02a10_initialize_controls()
748 mode = ov02a10->cur_mode; in ov02a10_initialize_controls()
753 handler->lock = &ov02a10->mutex; in ov02a10_initialize_controls()
758 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov02a10_initialize_controls()
764 h_blank = mode->hts_def - mode->width; in ov02a10_initialize_controls()
768 vblank_def = mode->vts_def - mode->height; in ov02a10_initialize_controls()
770 vblank_def, OV02A10_VTS_MAX - mode->height, 1, in ov02a10_initialize_controls()
773 exposure_max = mode->vts_def - 4; in ov02a10_initialize_controls()
774 ov02a10->exposure = v4l2_ctrl_new_std(handler, &ov02a10_ctrl_ops, in ov02a10_initialize_controls()
779 mode->exp_def); in ov02a10_initialize_controls()
788 ARRAY_SIZE(ov02a10_test_pattern_menu) - 1, in ov02a10_initialize_controls()
791 if (handler->error) { in ov02a10_initialize_controls()
792 ret = handler->error; in ov02a10_initialize_controls()
793 dev_err(&client->dev, "failed to init controls(%d)\n", ret); in ov02a10_initialize_controls()
797 ov02a10->subdev.ctrl_handler = handler; in ov02a10_initialize_controls()
809 struct fwnode_handle *ep; in ov02a10_check_hwcfg() local
819 return -EINVAL; in ov02a10_check_hwcfg()
821 ep = fwnode_graph_get_next_endpoint(fwnode, NULL); in ov02a10_check_hwcfg()
822 if (!ep) in ov02a10_check_hwcfg()
823 return -ENXIO; in ov02a10_check_hwcfg()
825 ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); in ov02a10_check_hwcfg()
826 fwnode_handle_put(ep); in ov02a10_check_hwcfg()
831 ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage", in ov02a10_check_hwcfg()
835 ov02a10->mipi_clock_voltage = clk_volt; in ov02a10_check_hwcfg()
847 ret = -EINVAL; in ov02a10_check_hwcfg()
859 struct device *dev = &client->dev; in ov02a10_probe()
867 return -ENOMEM; in ov02a10_probe()
874 v4l2_i2c_subdev_init(&ov02a10->subdev, client, &ov02a10_subdev_ops); in ov02a10_probe()
875 ov02a10->subdev.internal_ops = &ov02a10_internal_ops; in ov02a10_probe()
877 ov02a10->mipi_clock_voltage = OV02A10_MIPI_TX_SPEED_DEFAULT; in ov02a10_probe()
878 ov02a10->fmt.code = MEDIA_BUS_FMT_SBGGR10_1X10; in ov02a10_probe()
884 ov02a10->upside_down = true; in ov02a10_probe()
885 ov02a10->fmt.code = MEDIA_BUS_FMT_SRGGB10_1X10; in ov02a10_probe()
888 ov02a10->eclk = devm_clk_get(dev, "eclk"); in ov02a10_probe()
889 if (IS_ERR(ov02a10->eclk)) in ov02a10_probe()
890 return dev_err_probe(dev, PTR_ERR(ov02a10->eclk), in ov02a10_probe()
893 ret = device_property_read_u32(dev, "clock-frequency", in ov02a10_probe()
894 &ov02a10->eclk_freq); in ov02a10_probe()
899 ret = clk_set_rate(ov02a10->eclk, ov02a10->eclk_freq); in ov02a10_probe()
904 if (clk_get_rate(ov02a10->eclk) != OV02A10_ECLK_FREQ) in ov02a10_probe()
907 ov02a10->pd_gpio = devm_gpiod_get(dev, "powerdown", GPIOD_OUT_HIGH); in ov02a10_probe()
908 if (IS_ERR(ov02a10->pd_gpio)) in ov02a10_probe()
909 return dev_err_probe(dev, PTR_ERR(ov02a10->pd_gpio), in ov02a10_probe()
910 "failed to get powerdown-gpios\n"); in ov02a10_probe()
912 ov02a10->rst_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); in ov02a10_probe()
913 if (IS_ERR(ov02a10->rst_gpio)) in ov02a10_probe()
914 return dev_err_probe(dev, PTR_ERR(ov02a10->rst_gpio), in ov02a10_probe()
915 "failed to get reset-gpios\n"); in ov02a10_probe()
918 ov02a10->supplies[i].supply = ov02a10_supply_names[i]; in ov02a10_probe()
921 ov02a10->supplies); in ov02a10_probe()
925 mutex_init(&ov02a10->mutex); in ov02a10_probe()
928 ov02a10->cur_mode = &supported_modes[0]; in ov02a10_probe()
937 ov02a10->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov02a10_probe()
938 ov02a10->subdev.entity.ops = &ov02a10_subdev_entity_ops; in ov02a10_probe()
939 ov02a10->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov02a10_probe()
940 ov02a10->pad.flags = MEDIA_PAD_FL_SOURCE; in ov02a10_probe()
942 ret = media_entity_pads_init(&ov02a10->subdev.entity, 1, &ov02a10->pad); in ov02a10_probe()
957 ret = v4l2_async_register_subdev(&ov02a10->subdev); in ov02a10_probe()
971 media_entity_cleanup(&ov02a10->subdev.entity); in ov02a10_probe()
973 v4l2_ctrl_handler_free(ov02a10->subdev.ctrl_handler); in ov02a10_probe()
975 mutex_destroy(&ov02a10->mutex); in ov02a10_probe()
986 media_entity_cleanup(&sd->entity); in ov02a10_remove()
987 v4l2_ctrl_handler_free(sd->ctrl_handler); in ov02a10_remove()
988 pm_runtime_disable(&client->dev); in ov02a10_remove()
989 if (!pm_runtime_status_suspended(&client->dev)) in ov02a10_remove()
990 ov02a10_power_off(&client->dev); in ov02a10_remove()
991 pm_runtime_set_suspended(&client->dev); in ov02a10_remove()
992 mutex_destroy(&ov02a10->mutex); in ov02a10_remove()