Lines Matching +full:gpio +full:- +full:ctrl2

1 // SPDX-License-Identifier: GPL-2.0
8 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
9 * Copyright (C) 2014-2017 Mentor Graphics Inc.
16 #include <linux/gpio/consumer.h>
25 #include <media/v4l2-cci.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-ctrls.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-subdev.h>
81 /* Fixed pre-div of 1/2 */
84 /* Pre-div configurable through reg 0x3080, left at its default of 0x02 : 1/2 */
91 /* Max exposure time is VTS - 8 */
97 /* For enum_frame_size() full-size + binned-/quarter-size */
194 /* MIPI PHY, 0x10 -> 0x1c enable bp_c_hs_en_lat and bp_d_hs_en_lat */
217 /* BLC CTRL00 0x01 -> 0x81 set avg_weight to 8 */
220 /* Set black level compensation range to 0 - 3 (default 0 - 11) */
224 /* VFIFO R2 0x00 -> 0x02 set Frame reset enable */
227 /* MIPI ctrl CLK PREPARE MIN change from 0x26 (38) -> 0x36 (54) */
230 /* MIPI ctrl CLK LPX P MIN change from 0x32 (50) -> 0x36 (54) */
233 /* R ISP CTRL2 0x20 -> 0x30, set sof_sel bit */
237 * Window CONTROL 0x00 -> 0x01, enable manual window control,
243 * DPC CTRL0 0x14 -> 0x3e, set enable_tail, enable_3x3_cluster
248 /* DPC MORE CONNECTION CASE THRE 0x0c (12) -> 0x02 (2) */
251 /* DPC GAIN LIST1 0x0f (15) -> 0x08 (8) */
254 /* DPC GAIN LIST2 0x3f (63) -> 0x0c (12) */
257 /* DPC THRE RATIO 0x04 (4) -> 0x00 (0) */
268 return &container_of(ctrl->handler, struct ov2680_dev, in ctrl_to_sd()
269 ctrls.handler)->sd; in ctrl_to_sd()
274 if (!sensor->pwdn_gpio) in ov2680_power_up()
277 gpiod_set_value(sensor->pwdn_gpio, 0); in ov2680_power_up()
283 if (!sensor->pwdn_gpio) in ov2680_power_down()
286 gpiod_set_value(sensor->pwdn_gpio, 1); in ov2680_power_down()
295 if (sensor->ctrls.vflip && sensor->ctrls.vflip->val) in ov2680_set_bayer_order()
298 if (sensor->ctrls.hflip && sensor->ctrls.hflip->val) in ov2680_set_bayer_order()
301 fmt->code = ov2680_hv_flip_bayer_order[hv_flip]; in ov2680_set_bayer_order()
313 return &sensor->mode.fmt; in __ov2680_get_pad_format()
325 return &sensor->mode.crop; in __ov2680_get_pad_crop()
333 fmt->width = width; in ov2680_fill_format()
334 fmt->height = height; in ov2680_fill_format()
335 fmt->field = V4L2_FIELD_NONE; in ov2680_fill_format()
336 fmt->colorspace = V4L2_COLORSPACE_SRGB; in ov2680_fill_format()
342 int width = sensor->mode.fmt.width; in ov2680_calc_mode()
343 int height = sensor->mode.fmt.height; in ov2680_calc_mode()
347 if (width <= (sensor->mode.crop.width / 2) && in ov2680_calc_mode()
348 height <= (sensor->mode.crop.height / 2)) { in ov2680_calc_mode()
349 sensor->mode.binning = true; in ov2680_calc_mode()
353 sensor->mode.binning = false; in ov2680_calc_mode()
356 sensor->mode.h_start = (sensor->mode.crop.left + in ov2680_calc_mode()
357 (sensor->mode.crop.width - width) / 2) & ~1; in ov2680_calc_mode()
358 sensor->mode.v_start = (sensor->mode.crop.top + in ov2680_calc_mode()
359 (sensor->mode.crop.height - height) / 2) & ~1; in ov2680_calc_mode()
360 sensor->mode.h_end = in ov2680_calc_mode()
361 min(sensor->mode.h_start + width - 1, OV2680_NATIVE_WIDTH - 1); in ov2680_calc_mode()
362 sensor->mode.v_end = in ov2680_calc_mode()
363 min(sensor->mode.v_start + height - 1, OV2680_NATIVE_HEIGHT - 1); in ov2680_calc_mode()
364 sensor->mode.h_output_size = orig_width; in ov2680_calc_mode()
365 sensor->mode.v_output_size = orig_height; in ov2680_calc_mode()
373 if (sensor->mode.binning) { in ov2680_set_mode()
385 cci_write(sensor->regmap, OV2680_REG_SENSOR_CTRL_0A, in ov2680_set_mode()
387 cci_write(sensor->regmap, OV2680_REG_HORIZONTAL_START, in ov2680_set_mode()
388 sensor->mode.h_start, &ret); in ov2680_set_mode()
389 cci_write(sensor->regmap, OV2680_REG_VERTICAL_START, in ov2680_set_mode()
390 sensor->mode.v_start, &ret); in ov2680_set_mode()
391 cci_write(sensor->regmap, OV2680_REG_HORIZONTAL_END, in ov2680_set_mode()
392 sensor->mode.h_end, &ret); in ov2680_set_mode()
393 cci_write(sensor->regmap, OV2680_REG_VERTICAL_END, in ov2680_set_mode()
394 sensor->mode.v_end, &ret); in ov2680_set_mode()
395 cci_write(sensor->regmap, OV2680_REG_HORIZONTAL_OUTPUT_SIZE, in ov2680_set_mode()
396 sensor->mode.h_output_size, &ret); in ov2680_set_mode()
397 cci_write(sensor->regmap, OV2680_REG_VERTICAL_OUTPUT_SIZE, in ov2680_set_mode()
398 sensor->mode.v_output_size, &ret); in ov2680_set_mode()
399 cci_write(sensor->regmap, OV2680_REG_TIMING_HTS, in ov2680_set_mode()
402 cci_write(sensor->regmap, OV2680_REG_ISP_X_WIN, 0, &ret); in ov2680_set_mode()
403 cci_write(sensor->regmap, OV2680_REG_ISP_Y_WIN, 0, &ret); in ov2680_set_mode()
404 cci_write(sensor->regmap, OV2680_REG_X_INC, inc, &ret); in ov2680_set_mode()
405 cci_write(sensor->regmap, OV2680_REG_Y_INC, inc, &ret); in ov2680_set_mode()
406 cci_write(sensor->regmap, OV2680_REG_X_WIN, in ov2680_set_mode()
407 sensor->mode.h_output_size, &ret); in ov2680_set_mode()
408 cci_write(sensor->regmap, OV2680_REG_Y_WIN, in ov2680_set_mode()
409 sensor->mode.v_output_size, &ret); in ov2680_set_mode()
410 cci_write(sensor->regmap, OV2680_REG_FORMAT1, fmt1, &ret); in ov2680_set_mode()
411 cci_write(sensor->regmap, OV2680_REG_FORMAT2, fmt2, &ret); in ov2680_set_mode()
420 if (sensor->is_streaming) in ov2680_set_vflip()
421 return -EBUSY; in ov2680_set_vflip()
423 ret = cci_update_bits(sensor->regmap, OV2680_REG_FORMAT1, in ov2680_set_vflip()
428 ov2680_set_bayer_order(sensor, &sensor->mode.fmt); in ov2680_set_vflip()
436 if (sensor->is_streaming) in ov2680_set_hflip()
437 return -EBUSY; in ov2680_set_hflip()
439 ret = cci_update_bits(sensor->regmap, OV2680_REG_FORMAT2, in ov2680_set_hflip()
444 ov2680_set_bayer_order(sensor, &sensor->mode.fmt); in ov2680_set_hflip()
453 return cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00, in ov2680_test_pattern_set()
456 cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00, in ov2680_test_pattern_set()
457 0x03, value - 1, &ret); in ov2680_test_pattern_set()
458 cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00, in ov2680_test_pattern_set()
466 return cci_write(sensor->regmap, OV2680_REG_GAIN_PK, gain, NULL); in ov2680_gain_set()
471 return cci_write(sensor->regmap, OV2680_REG_EXPOSURE_PK, exp << 4, in ov2680_exposure_set()
477 int exp_max = sensor->mode.fmt.height + sensor->ctrls.vblank->val - in ov2680_exposure_update_range()
480 return __v4l2_ctrl_modify_range(sensor->ctrls.exposure, 0, exp_max, in ov2680_exposure_update_range()
488 ret = cci_write(sensor->regmap, OV2680_REG_PLL_MULTIPLIER, in ov2680_stream_enable()
489 sensor->pll_mult, NULL); in ov2680_stream_enable()
493 ret = regmap_multi_reg_write(sensor->regmap, in ov2680_stream_enable()
504 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler); in ov2680_stream_enable()
508 return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 1, NULL); in ov2680_stream_enable()
513 return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 0, NULL); in ov2680_stream_disable()
518 clk_disable_unprepare(sensor->xvclk); in ov2680_power_off()
520 regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies); in ov2680_power_off()
528 ret = regulator_bulk_enable(OV2680_NUM_SUPPLIES, sensor->supplies); in ov2680_power_on()
530 dev_err(sensor->dev, "failed to enable regulators: %d\n", ret); in ov2680_power_on()
534 if (!sensor->pwdn_gpio) { in ov2680_power_on()
535 ret = cci_write(sensor->regmap, OV2680_REG_SOFT_RESET, 0x01, in ov2680_power_on()
538 dev_err(sensor->dev, "sensor soft reset failed\n"); in ov2680_power_on()
547 ret = clk_prepare_enable(sensor->xvclk); in ov2680_power_on()
554 regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies); in ov2680_power_on()
568 if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov2680_get_frame_interval()
569 return -EINVAL; in ov2680_get_frame_interval()
571 mutex_lock(&sensor->lock); in ov2680_get_frame_interval()
572 fi->interval = sensor->mode.frame_interval; in ov2680_get_frame_interval()
573 mutex_unlock(&sensor->lock); in ov2680_get_frame_interval()
583 mutex_lock(&sensor->lock); in ov2680_s_stream()
585 if (sensor->is_streaming == !!enable) in ov2680_s_stream()
589 ret = pm_runtime_resume_and_get(sensor->sd.dev); in ov2680_s_stream()
595 pm_runtime_put(sensor->sd.dev); in ov2680_s_stream()
600 pm_runtime_put(sensor->sd.dev); in ov2680_s_stream()
603 sensor->is_streaming = !!enable; in ov2680_s_stream()
606 mutex_unlock(&sensor->lock); in ov2680_s_stream()
617 if (code->index != 0) in ov2680_enum_mbus_code()
618 return -EINVAL; in ov2680_enum_mbus_code()
620 code->code = sensor->mode.fmt.code; in ov2680_enum_mbus_code()
632 fmt = __ov2680_get_pad_format(sensor, sd_state, format->pad, in ov2680_get_fmt()
633 format->which); in ov2680_get_fmt()
635 mutex_lock(&sensor->lock); in ov2680_get_fmt()
636 format->format = *fmt; in ov2680_get_fmt()
637 mutex_unlock(&sensor->lock); in ov2680_get_fmt()
652 crop = __ov2680_get_pad_crop(sensor, sd_state, format->pad, in ov2680_set_fmt()
653 format->which); in ov2680_set_fmt()
656 width = clamp_val(ALIGN(format->format.width, 2), in ov2680_set_fmt()
657 OV2680_MIN_CROP_WIDTH, crop->width); in ov2680_set_fmt()
658 height = clamp_val(ALIGN(format->format.height, 2), in ov2680_set_fmt()
659 OV2680_MIN_CROP_HEIGHT, crop->height); in ov2680_set_fmt()
661 ov2680_fill_format(sensor, &format->format, width, height); in ov2680_set_fmt()
663 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov2680_set_fmt()
665 *try_fmt = format->format; in ov2680_set_fmt()
669 mutex_lock(&sensor->lock); in ov2680_set_fmt()
671 if (sensor->is_streaming) { in ov2680_set_fmt()
672 ret = -EBUSY; in ov2680_set_fmt()
676 sensor->mode.fmt = format->format; in ov2680_set_fmt()
680 max = OV2680_MAX_VBLANK - height; in ov2680_set_fmt()
681 def = OV2680_LINES_PER_FRAME_30FPS - height; in ov2680_set_fmt()
682 ret = __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV2680_MIN_VBLANK, in ov2680_set_fmt()
687 ret = __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, def); in ov2680_set_fmt()
697 def = OV2680_PIXELS_PER_LINE - width; in ov2680_set_fmt()
698 ret = __v4l2_ctrl_modify_range(sensor->ctrls.hblank, def, def, 1, def); in ov2680_set_fmt()
701 mutex_unlock(&sensor->lock); in ov2680_set_fmt()
712 switch (sel->target) { in ov2680_get_selection()
714 mutex_lock(&sensor->lock); in ov2680_get_selection()
715 sel->r = *__ov2680_get_pad_crop(sensor, state, sel->pad, in ov2680_get_selection()
716 sel->which); in ov2680_get_selection()
717 mutex_unlock(&sensor->lock); in ov2680_get_selection()
721 sel->r.top = 0; in ov2680_get_selection()
722 sel->r.left = 0; in ov2680_get_selection()
723 sel->r.width = OV2680_NATIVE_WIDTH; in ov2680_get_selection()
724 sel->r.height = OV2680_NATIVE_HEIGHT; in ov2680_get_selection()
727 sel->r = ov2680_default_crop; in ov2680_get_selection()
730 return -EINVAL; in ov2680_get_selection()
745 if (sel->target != V4L2_SEL_TGT_CROP) in ov2680_set_selection()
746 return -EINVAL; in ov2680_set_selection()
753 rect.left = clamp_val(ALIGN(sel->r.left, 2), in ov2680_set_selection()
755 rect.top = clamp_val(ALIGN(sel->r.top, 2), in ov2680_set_selection()
757 rect.width = clamp_val(ALIGN(sel->r.width, 2), in ov2680_set_selection()
759 rect.height = clamp_val(ALIGN(sel->r.height, 2), in ov2680_set_selection()
764 OV2680_NATIVE_WIDTH - rect.left); in ov2680_set_selection()
766 OV2680_NATIVE_HEIGHT - rect.top); in ov2680_set_selection()
768 crop = __ov2680_get_pad_crop(sensor, state, sel->pad, sel->which); in ov2680_set_selection()
770 mutex_lock(&sensor->lock); in ov2680_set_selection()
771 if (rect.width != crop->width || rect.height != crop->height) { in ov2680_set_selection()
776 format = __ov2680_get_pad_format(sensor, state, sel->pad, in ov2680_set_selection()
777 sel->which); in ov2680_set_selection()
778 format->width = rect.width; in ov2680_set_selection()
779 format->height = rect.height; in ov2680_set_selection()
783 mutex_unlock(&sensor->lock); in ov2680_set_selection()
785 sel->r = rect; in ov2680_set_selection()
809 if (fse->index >= OV2680_FRAME_SIZES) in ov2680_enum_frame_size()
810 return -EINVAL; in ov2680_enum_frame_size()
812 crop = __ov2680_get_pad_crop(sensor, sd_state, fse->pad, fse->which); in ov2680_enum_frame_size()
814 return -EINVAL; in ov2680_enum_frame_size()
816 fse->min_width = crop->width / (fse->index + 1); in ov2680_enum_frame_size()
817 fse->min_height = crop->height / (fse->index + 1); in ov2680_enum_frame_size()
818 fse->max_width = fse->min_width; in ov2680_enum_frame_size()
819 fse->max_height = fse->min_height; in ov2680_enum_frame_size()
829 .pad = fie->pad, in ov2680_valid_frame_size()
830 .which = fie->which, in ov2680_valid_frame_size()
840 if (fie->width == fse.min_width && in ov2680_valid_frame_size()
841 fie->height == fse.min_height) in ov2680_valid_frame_size()
855 if (fie->index || !ov2680_valid_frame_size(sd, sd_state, fie)) in ov2680_enum_frame_interval()
856 return -EINVAL; in ov2680_enum_frame_interval()
858 fie->interval = sensor->mode.frame_interval; in ov2680_enum_frame_interval()
870 if (ctrl->id == V4L2_CID_VBLANK) { in ov2680_s_ctrl()
877 if (!pm_runtime_get_if_in_use(sensor->sd.dev)) { in ov2680_s_ctrl()
878 ov2680_set_bayer_order(sensor, &sensor->mode.fmt); in ov2680_s_ctrl()
882 switch (ctrl->id) { in ov2680_s_ctrl()
884 ret = ov2680_gain_set(sensor, ctrl->val); in ov2680_s_ctrl()
887 ret = ov2680_exposure_set(sensor, ctrl->val); in ov2680_s_ctrl()
890 ret = ov2680_set_vflip(sensor, ctrl->val); in ov2680_s_ctrl()
893 ret = ov2680_set_hflip(sensor, ctrl->val); in ov2680_s_ctrl()
896 ret = ov2680_test_pattern_set(sensor, ctrl->val); in ov2680_s_ctrl()
899 ret = cci_write(sensor->regmap, OV2680_REG_TIMING_VTS, in ov2680_s_ctrl()
900 sensor->mode.fmt.height + ctrl->val, NULL); in ov2680_s_ctrl()
903 ret = -EINVAL; in ov2680_s_ctrl()
907 pm_runtime_put(sensor->sd.dev); in ov2680_s_ctrl()
943 sensor->mode.crop = ov2680_default_crop; in ov2680_mode_init()
944 ov2680_fill_format(sensor, &sensor->mode.fmt, in ov2680_mode_init()
948 sensor->mode.frame_interval.denominator = OV2680_FRAME_RATE; in ov2680_mode_init()
949 sensor->mode.frame_interval.numerator = 1; in ov2680_mode_init()
956 struct i2c_client *client = to_i2c_client(sensor->dev); in ov2680_v4l2_register()
958 struct ov2680_ctrls *ctrls = &sensor->ctrls; in ov2680_v4l2_register()
959 struct v4l2_ctrl_handler *hdl = &ctrls->handler; in ov2680_v4l2_register()
963 v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_subdev_ops); in ov2680_v4l2_register()
964 sensor->sd.internal_ops = &ov2680_internal_ops; in ov2680_v4l2_register()
966 sensor->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; in ov2680_v4l2_register()
967 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in ov2680_v4l2_register()
968 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov2680_v4l2_register()
970 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); in ov2680_v4l2_register()
976 hdl->lock = &sensor->lock; in ov2680_v4l2_register()
978 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); in ov2680_v4l2_register()
979 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); in ov2680_v4l2_register()
981 ctrls->test_pattern = v4l2_ctrl_new_std_menu_items(hdl, in ov2680_v4l2_register()
983 ARRAY_SIZE(test_pattern_menu) - 1, in ov2680_v4l2_register()
986 max = OV2680_LINES_PER_FRAME_30FPS - OV2680_INTEGRATION_TIME_MARGIN; in ov2680_v4l2_register()
987 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, in ov2680_v4l2_register()
990 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, in ov2680_v4l2_register()
993 ctrls->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, in ov2680_v4l2_register()
994 0, 0, sensor->link_freq); in ov2680_v4l2_register()
995 ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, in ov2680_v4l2_register()
996 0, sensor->pixel_rate, in ov2680_v4l2_register()
997 1, sensor->pixel_rate); in ov2680_v4l2_register()
999 max = OV2680_MAX_VBLANK - OV2680_DEFAULT_HEIGHT; in ov2680_v4l2_register()
1000 def = OV2680_LINES_PER_FRAME_30FPS - OV2680_DEFAULT_HEIGHT; in ov2680_v4l2_register()
1001 ctrls->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, in ov2680_v4l2_register()
1004 def = OV2680_PIXELS_PER_LINE - OV2680_DEFAULT_WIDTH; in ov2680_v4l2_register()
1005 ctrls->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, in ov2680_v4l2_register()
1008 ret = v4l2_fwnode_device_parse(sensor->dev, &props); in ov2680_v4l2_register()
1014 if (hdl->error) { in ov2680_v4l2_register()
1015 ret = hdl->error; in ov2680_v4l2_register()
1019 ctrls->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in ov2680_v4l2_register()
1020 ctrls->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in ov2680_v4l2_register()
1021 ctrls->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov2680_v4l2_register()
1022 ctrls->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov2680_v4l2_register()
1024 sensor->sd.ctrl_handler = hdl; in ov2680_v4l2_register()
1026 ret = v4l2_async_register_subdev(&sensor->sd); in ov2680_v4l2_register()
1033 media_entity_cleanup(&sensor->sd.entity); in ov2680_v4l2_register()
1044 sensor->supplies[i].supply = ov2680_supply_name[i]; in ov2680_get_regulators()
1046 return devm_regulator_bulk_get(sensor->dev, in ov2680_get_regulators()
1047 OV2680_NUM_SUPPLIES, sensor->supplies); in ov2680_get_regulators()
1055 cci_read(sensor->regmap, OV2680_REG_CHIP_ID, &chip_id, &ret); in ov2680_check_id()
1056 cci_read(sensor->regmap, OV2680_REG_SC_CMMN_SUB_ID, &rev, &ret); in ov2680_check_id()
1058 dev_err(sensor->dev, "failed to read chip id\n"); in ov2680_check_id()
1063 dev_err(sensor->dev, "chip id: 0x%04llx does not match expected 0x%04x\n", in ov2680_check_id()
1065 return -ENODEV; in ov2680_check_id()
1068 dev_info(sensor->dev, "sensor_revision id = 0x%llx, rev= %lld\n", in ov2680_check_id()
1079 struct device *dev = sensor->dev; in ov2680_parse_dt()
1081 struct gpio_desc *gpio; in ov2680_parse_dt() local
1087 * Bridge drivers doing this may also add GPIO mappings, wait for this. in ov2680_parse_dt()
1091 return dev_err_probe(dev, -EPROBE_DEFER, in ov2680_parse_dt()
1101 * drivers have standardized on using "powerdown" as con-id name in ov2680_parse_dt()
1105 gpio = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH); in ov2680_parse_dt()
1106 if (!gpio) in ov2680_parse_dt()
1107 gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in ov2680_parse_dt()
1109 ret = PTR_ERR_OR_ZERO(gpio); in ov2680_parse_dt()
1111 dev_dbg(dev, "error while getting reset gpio: %d\n", ret); in ov2680_parse_dt()
1115 sensor->pwdn_gpio = gpio; in ov2680_parse_dt()
1117 sensor->xvclk = devm_clk_get_optional(dev, "xvclk"); in ov2680_parse_dt()
1118 if (IS_ERR(sensor->xvclk)) { in ov2680_parse_dt()
1119 ret = dev_err_probe(dev, PTR_ERR(sensor->xvclk), in ov2680_parse_dt()
1127 * have an external clock AND a clock-frequency property. Check for the in ov2680_parse_dt()
1128 * clock-frequency property and if found, set that rate if we managed in ov2680_parse_dt()
1133 ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", in ov2680_parse_dt()
1135 if (ret && !sensor->xvclk) { in ov2680_parse_dt()
1140 if (!ret && sensor->xvclk) { in ov2680_parse_dt()
1141 ret = clk_set_rate(sensor->xvclk, rate); in ov2680_parse_dt()
1148 sensor->xvclk_freq = rate ?: clk_get_rate(sensor->xvclk); in ov2680_parse_dt()
1151 if (sensor->xvclk_freq == ov2680_xvclk_freqs[i]) in ov2680_parse_dt()
1156 ret = dev_err_probe(dev, -EINVAL, in ov2680_parse_dt()
1158 sensor->xvclk_freq); in ov2680_parse_dt()
1162 sensor->pll_mult = ov2680_pll_multipliers[i]; in ov2680_parse_dt()
1164 sensor->link_freq[0] = sensor->xvclk_freq / OV2680_PLL_PREDIV0 / in ov2680_parse_dt()
1165 OV2680_PLL_PREDIV * sensor->pll_mult; in ov2680_parse_dt()
1167 /* CSI-2 is double data rate, bus-format is 10 bpp */ in ov2680_parse_dt()
1168 sensor->pixel_rate = sensor->link_freq[0] * 2; in ov2680_parse_dt()
1169 do_div(sensor->pixel_rate, 10); in ov2680_parse_dt()
1172 dev_warn(dev, "Consider passing 'link-frequencies' in DT\n"); in ov2680_parse_dt()
1177 if (bus_cfg.link_frequencies[i] == sensor->link_freq[0]) in ov2680_parse_dt()
1181 ret = dev_err_probe(dev, -EINVAL, in ov2680_parse_dt()
1183 sensor->link_freq[0]); in ov2680_parse_dt()
1196 struct device *dev = &client->dev; in ov2680_probe()
1202 return -ENOMEM; in ov2680_probe()
1204 sensor->dev = &client->dev; in ov2680_probe()
1206 sensor->regmap = devm_cci_regmap_init_i2c(client, 16); in ov2680_probe()
1207 if (IS_ERR(sensor->regmap)) in ov2680_probe()
1208 return PTR_ERR(sensor->regmap); in ov2680_probe()
1224 mutex_init(&sensor->lock); in ov2680_probe()
1238 pm_runtime_set_active(&client->dev); in ov2680_probe()
1239 pm_runtime_get_noresume(&client->dev); in ov2680_probe()
1240 pm_runtime_enable(&client->dev); in ov2680_probe()
1246 pm_runtime_set_autosuspend_delay(&client->dev, 1000); in ov2680_probe()
1247 pm_runtime_use_autosuspend(&client->dev); in ov2680_probe()
1248 pm_runtime_put_autosuspend(&client->dev); in ov2680_probe()
1253 pm_runtime_disable(&client->dev); in ov2680_probe()
1254 pm_runtime_put_noidle(&client->dev); in ov2680_probe()
1259 mutex_destroy(&sensor->lock); in ov2680_probe()
1269 v4l2_async_unregister_subdev(&sensor->sd); in ov2680_remove()
1270 mutex_destroy(&sensor->lock); in ov2680_remove()
1271 media_entity_cleanup(&sensor->sd.entity); in ov2680_remove()
1272 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov2680_remove()
1278 pm_runtime_disable(&client->dev); in ov2680_remove()
1279 if (!pm_runtime_status_suspended(&client->dev)) in ov2680_remove()
1281 pm_runtime_set_suspended(&client->dev); in ov2680_remove()
1289 if (sensor->is_streaming) in ov2680_suspend()
1305 if (sensor->is_streaming) { in ov2680_resume()
1315 sensor->is_streaming = false; in ov2680_resume()