Lines Matching +full:solid +full:- +full:state

1 // SPDX-License-Identifier: GPL-2.0
25 #include <media/v4l2-cci.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-fwnode.h>
28 #include <media/v4l2-subdev.h>
68 "No Pattern", "Solid Black", "Colour Bar", "Solid White",
69 "Solid Red", "Solid Green", "Solid Blue", "Solid Yellow",
594 gc08a3->supplies); in gc08a3_power_on()
596 dev_err(gc08a3->dev, "failed to enable regulators: %d\n", ret); in gc08a3_power_on()
600 ret = clk_prepare_enable(gc08a3->xclk); in gc08a3_power_on()
603 gc08a3->supplies); in gc08a3_power_on()
604 dev_err(gc08a3->dev, "clk prepare enable failed\n"); in gc08a3_power_on()
610 gpiod_set_value_cansleep(gc08a3->reset_gpio, 0); in gc08a3_power_on()
621 clk_disable_unprepare(gc08a3->xclk); in gc08a3_power_off()
622 gpiod_set_value_cansleep(gc08a3->reset_gpio, 1); in gc08a3_power_off()
624 gc08a3->supplies); in gc08a3_power_off()
633 if (code->index > 0) in gc08a3_enum_mbus_code()
634 return -EINVAL; in gc08a3_enum_mbus_code()
636 code->code = GC08A3_MBUS_CODE; in gc08a3_enum_mbus_code()
645 if (fse->code != GC08A3_MBUS_CODE) in gc08a3_enum_frame_size()
646 return -EINVAL; in gc08a3_enum_frame_size()
648 if (fse->index >= ARRAY_SIZE(gc08a3_modes)) in gc08a3_enum_frame_size()
649 return -EINVAL; in gc08a3_enum_frame_size()
651 fse->min_width = gc08a3_modes[fse->index].width; in gc08a3_enum_frame_size()
652 fse->max_width = gc08a3_modes[fse->index].width; in gc08a3_enum_frame_size()
653 fse->min_height = gc08a3_modes[fse->index].height; in gc08a3_enum_frame_size()
654 fse->max_height = gc08a3_modes[fse->index].height; in gc08a3_enum_frame_size()
665 ret = __v4l2_ctrl_modify_range(gc08a3->vblank, in gc08a3_update_cur_mode_controls()
666 mode->vts_min - mode->height, in gc08a3_update_cur_mode_controls()
667 GC08A3_VTS_MAX - mode->height, 1, in gc08a3_update_cur_mode_controls()
668 mode->vts_def - mode->height); in gc08a3_update_cur_mode_controls()
670 dev_err(gc08a3->dev, "VB ctrl range update failed\n"); in gc08a3_update_cur_mode_controls()
674 h_blank = mode->hts - mode->width; in gc08a3_update_cur_mode_controls()
675 ret = __v4l2_ctrl_modify_range(gc08a3->hblank, h_blank, h_blank, 1, in gc08a3_update_cur_mode_controls()
678 dev_err(gc08a3->dev, "HB ctrl range update failed\n"); in gc08a3_update_cur_mode_controls()
682 exposure_max = mode->vts_def - GC08A3_EXP_MARGIN; in gc08a3_update_cur_mode_controls()
683 ret = __v4l2_ctrl_modify_range(gc08a3->exposure, GC08A3_EXP_MIN, in gc08a3_update_cur_mode_controls()
687 dev_err(gc08a3->dev, "exposure ctrl range update failed\n"); in gc08a3_update_cur_mode_controls()
698 fmt->width = mode->width; in gc08a3_update_pad_format()
699 fmt->height = mode->height; in gc08a3_update_pad_format()
700 fmt->code = GC08A3_MBUS_CODE; in gc08a3_update_pad_format()
701 fmt->field = V4L2_FIELD_NONE; in gc08a3_update_pad_format()
702 fmt->colorspace = V4L2_COLORSPACE_RAW; in gc08a3_update_pad_format()
703 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in gc08a3_update_pad_format()
704 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in gc08a3_update_pad_format()
705 fmt->xfer_func = V4L2_XFER_FUNC_NONE; in gc08a3_update_pad_format()
709 struct v4l2_subdev_state *state, in gc08a3_set_format() argument
718 width, height, fmt->format.width, in gc08a3_set_format()
719 fmt->format.height); in gc08a3_set_format()
721 /* update crop info to subdev state */ in gc08a3_set_format()
722 crop = v4l2_subdev_state_get_crop(state, 0); in gc08a3_set_format()
723 crop->width = mode->width; in gc08a3_set_format()
724 crop->height = mode->height; in gc08a3_set_format()
726 /* update fmt info to subdev state */ in gc08a3_set_format()
727 gc08a3_update_pad_format(gc08a3, mode, &fmt->format); in gc08a3_set_format()
728 mbus_fmt = v4l2_subdev_state_get_format(state, 0); in gc08a3_set_format()
729 *mbus_fmt = fmt->format; in gc08a3_set_format()
731 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) in gc08a3_set_format()
734 gc08a3->cur_mode = mode; in gc08a3_set_format()
741 struct v4l2_subdev_state *state, in gc08a3_get_selection() argument
744 switch (sel->target) { in gc08a3_get_selection()
747 sel->r = *v4l2_subdev_state_get_crop(state, 0); in gc08a3_get_selection()
750 sel->r.top = 0; in gc08a3_get_selection()
751 sel->r.left = 0; in gc08a3_get_selection()
752 sel->r.width = GC08A3_NATIVE_WIDTH; in gc08a3_get_selection()
753 sel->r.height = GC08A3_NATIVE_HEIGHT; in gc08a3_get_selection()
756 return -EINVAL; in gc08a3_get_selection()
763 struct v4l2_subdev_state *state) in gc08a3_init_state() argument
775 gc08a3_set_format(sd, state, &fmt); in gc08a3_init_state()
785 ret = cci_read(gc08a3->regmap, GC08A3_FLIP_REG, &val, NULL); in gc08a3_set_ctrl_hflip()
787 dev_err(gc08a3->dev, "read hflip register failed: %d\n", ret); in gc08a3_set_ctrl_hflip()
791 return cci_update_bits(gc08a3->regmap, GC08A3_FLIP_REG, in gc08a3_set_ctrl_hflip()
801 ret = cci_read(gc08a3->regmap, GC08A3_FLIP_REG, &val, NULL); in gc08a3_set_ctrl_vflip()
803 dev_err(gc08a3->dev, "read vflip register failed: %d\n", ret); in gc08a3_set_ctrl_vflip()
807 return cci_update_bits(gc08a3->regmap, GC08A3_FLIP_REG, in gc08a3_set_ctrl_vflip()
837 ret = cci_write(gc08a3->regmap, GC08A3_REG_TEST_PATTERN_IDX, in gc08a3_test_pattern()
842 return cci_write(gc08a3->regmap, GC08A3_REG_TEST_PATTERN_EN, in gc08a3_test_pattern()
845 return cci_write(gc08a3->regmap, GC08A3_REG_TEST_PATTERN_EN, in gc08a3_test_pattern()
853 container_of(ctrl->handler, struct gc08a3, ctrls); in gc08a3_set_ctrl()
856 struct v4l2_subdev_state *state; in gc08a3_set_ctrl() local
859 state = v4l2_subdev_get_locked_active_state(&gc08a3->sd); in gc08a3_set_ctrl()
860 format = v4l2_subdev_state_get_format(state, 0); in gc08a3_set_ctrl()
862 if (ctrl->id == V4L2_CID_VBLANK) { in gc08a3_set_ctrl()
864 exposure_max = format->height + ctrl->val - GC08A3_EXP_MARGIN; in gc08a3_set_ctrl()
865 __v4l2_ctrl_modify_range(gc08a3->exposure, in gc08a3_set_ctrl()
866 gc08a3->exposure->minimum, in gc08a3_set_ctrl()
867 exposure_max, gc08a3->exposure->step, in gc08a3_set_ctrl()
875 if (!pm_runtime_get_if_active(gc08a3->dev)) in gc08a3_set_ctrl()
878 switch (ctrl->id) { in gc08a3_set_ctrl()
880 ret = cci_write(gc08a3->regmap, GC08A3_EXP_REG, in gc08a3_set_ctrl()
881 ctrl->val, NULL); in gc08a3_set_ctrl()
885 ret = cci_write(gc08a3->regmap, GC08A3_AGAIN_REG, in gc08a3_set_ctrl()
886 ctrl->val, NULL); in gc08a3_set_ctrl()
890 ret = cci_write(gc08a3->regmap, GC08A3_FRAME_LENGTH_REG, in gc08a3_set_ctrl()
891 gc08a3->cur_mode->height + ctrl->val, NULL); in gc08a3_set_ctrl()
895 ret = gc08a3_set_ctrl_hflip(gc08a3, ctrl->val); in gc08a3_set_ctrl()
899 ret = gc08a3_set_ctrl_vflip(gc08a3, ctrl->val); in gc08a3_set_ctrl()
903 ret = gc08a3_test_pattern(gc08a3, ctrl->val); in gc08a3_set_ctrl()
910 pm_runtime_put(gc08a3->dev); in gc08a3_set_ctrl()
925 ret = pm_runtime_resume_and_get(gc08a3->dev); in gc08a3_start_streaming()
929 ret = cci_multi_reg_write(gc08a3->regmap, in gc08a3_start_streaming()
935 mode = gc08a3->cur_mode; in gc08a3_start_streaming()
936 reg_list = &mode->reg_list; in gc08a3_start_streaming()
937 ret = cci_multi_reg_write(gc08a3->regmap, in gc08a3_start_streaming()
938 reg_list->regs, reg_list->num_of_regs, NULL); in gc08a3_start_streaming()
942 ret = __v4l2_ctrl_handler_setup(&gc08a3->ctrls); in gc08a3_start_streaming()
944 dev_err(gc08a3->dev, "could not sync v4l2 controls\n"); in gc08a3_start_streaming()
948 ret = cci_write(gc08a3->regmap, GC08A3_STREAMING_REG, 1, NULL); in gc08a3_start_streaming()
950 dev_err(gc08a3->dev, "write STREAMING_REG failed: %d\n", ret); in gc08a3_start_streaming()
957 pm_runtime_put(gc08a3->dev); in gc08a3_start_streaming()
965 ret = cci_write(gc08a3->regmap, GC08A3_STREAMING_REG, 0, NULL); in gc08a3_stop_streaming()
967 dev_err(gc08a3->dev, "could not sent stop streaming %d\n", ret); in gc08a3_stop_streaming()
969 pm_runtime_put(gc08a3->dev); in gc08a3_stop_streaming()
976 struct v4l2_subdev_state *state; in gc08a3_s_stream() local
979 state = v4l2_subdev_lock_and_get_active_state(subdev); in gc08a3_s_stream()
986 v4l2_subdev_unlock_state(state); in gc08a3_s_stream()
1017 gc08a3->supplies[i].supply = gc08a3_supply_name[i]; in gc08a3_get_regulators()
1020 gc08a3->supplies); in gc08a3_get_regulators()
1030 struct device *dev = gc08a3->dev; in gc08a3_parse_fwnode()
1037 return -EINVAL; in gc08a3_parse_fwnode()
1050 &gc08a3->link_freq_bitmap); in gc08a3_parse_fwnode()
1070 struct i2c_client *client = v4l2_get_subdevdata(&gc08a3->sd); in gc08a3_init_controls()
1078 ctrl_hdlr = &gc08a3->ctrls; in gc08a3_init_controls()
1083 gc08a3->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1085 gc08a3->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1087 v4l2_ctrl_cluster(2, &gc08a3->hflip); in gc08a3_init_controls()
1089 gc08a3->link_freq = in gc08a3_init_controls()
1093 ARRAY_SIZE(gc08a3_link_freq_menu_items) - 1, in gc08a3_init_controls()
1096 if (gc08a3->link_freq) in gc08a3_init_controls()
1097 gc08a3->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc08a3_init_controls()
1099 gc08a3->pixel_rate = in gc08a3_init_controls()
1107 gc08a3->vblank = in gc08a3_init_controls()
1110 mode->vts_min - mode->height, in gc08a3_init_controls()
1111 GC08A3_VTS_MAX - mode->height, 1, in gc08a3_init_controls()
1112 mode->vts_def - mode->height); in gc08a3_init_controls()
1114 h_blank = mode->hts - mode->width; in gc08a3_init_controls()
1115 gc08a3->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1118 if (gc08a3->hblank) in gc08a3_init_controls()
1119 gc08a3->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc08a3_init_controls()
1126 exposure_max = mode->vts_def - GC08A3_EXP_MARGIN; in gc08a3_init_controls()
1127 gc08a3->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1134 ARRAY_SIZE(gc08a3_test_pattern_menu) - 1, in gc08a3_init_controls()
1138 ret = v4l2_fwnode_device_parse(&client->dev, &props); in gc08a3_init_controls()
1146 if (ctrl_hdlr->error) { in gc08a3_init_controls()
1147 ret = ctrl_hdlr->error; in gc08a3_init_controls()
1151 gc08a3->sd.ctrl_handler = ctrl_hdlr; in gc08a3_init_controls()
1166 ret = cci_read(gc08a3->regmap, GC08A3_REG_CHIP_ID, &val, NULL); in gc08a3_identify_module()
1168 dev_err(gc08a3->dev, "failed to read chip id"); in gc08a3_identify_module()
1173 dev_err(gc08a3->dev, "chip id mismatch: 0x%x!=0x%llx", in gc08a3_identify_module()
1175 return -ENXIO; in gc08a3_identify_module()
1183 struct device *dev = &client->dev; in gc08a3_probe()
1189 return -ENOMEM; in gc08a3_probe()
1191 gc08a3->dev = dev; in gc08a3_probe()
1197 gc08a3->regmap = devm_cci_regmap_init_i2c(client, 16); in gc08a3_probe()
1198 if (IS_ERR(gc08a3->regmap)) in gc08a3_probe()
1199 return dev_err_probe(dev, PTR_ERR(gc08a3->regmap), in gc08a3_probe()
1202 gc08a3->xclk = devm_clk_get(dev, NULL); in gc08a3_probe()
1203 if (IS_ERR(gc08a3->xclk)) in gc08a3_probe()
1204 return dev_err_probe(dev, PTR_ERR(gc08a3->xclk), in gc08a3_probe()
1207 ret = clk_set_rate(gc08a3->xclk, GC08A3_DEFAULT_CLK_FREQ); in gc08a3_probe()
1217 gc08a3->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in gc08a3_probe()
1218 if (IS_ERR(gc08a3->reset_gpio)) in gc08a3_probe()
1219 return dev_err_probe(dev, PTR_ERR(gc08a3->reset_gpio), in gc08a3_probe()
1222 v4l2_i2c_subdev_init(&gc08a3->sd, client, &gc08a3_subdev_ops); in gc08a3_probe()
1223 gc08a3->sd.internal_ops = &gc08a3_internal_ops; in gc08a3_probe()
1224 gc08a3->cur_mode = &gc08a3_modes[0]; in gc08a3_probe()
1226 ret = gc08a3_power_on(gc08a3->dev); in gc08a3_probe()
1233 dev_err(&client->dev, "failed to find sensor: %d\n", ret); in gc08a3_probe()
1239 dev_err(&client->dev, "failed to init controls: %d", ret); in gc08a3_probe()
1243 gc08a3->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in gc08a3_probe()
1244 gc08a3->pad.flags = MEDIA_PAD_FL_SOURCE; in gc08a3_probe()
1245 gc08a3->sd.dev = &client->dev; in gc08a3_probe()
1246 gc08a3->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in gc08a3_probe()
1248 ret = media_entity_pads_init(&gc08a3->sd.entity, 1, &gc08a3->pad); in gc08a3_probe()
1254 gc08a3->sd.state_lock = gc08a3->ctrls.lock; in gc08a3_probe()
1255 ret = v4l2_subdev_init_finalize(&gc08a3->sd); in gc08a3_probe()
1261 pm_runtime_set_active(gc08a3->dev); in gc08a3_probe()
1262 pm_runtime_enable(gc08a3->dev); in gc08a3_probe()
1263 pm_runtime_set_autosuspend_delay(gc08a3->dev, 1000); in gc08a3_probe()
1264 pm_runtime_use_autosuspend(gc08a3->dev); in gc08a3_probe()
1265 pm_runtime_idle(gc08a3->dev); in gc08a3_probe()
1267 ret = v4l2_async_register_subdev_sensor(&gc08a3->sd); in gc08a3_probe()
1276 pm_runtime_disable(gc08a3->dev); in gc08a3_probe()
1277 v4l2_subdev_cleanup(&gc08a3->sd); in gc08a3_probe()
1280 media_entity_cleanup(&gc08a3->sd.entity); in gc08a3_probe()
1283 v4l2_ctrl_handler_free(gc08a3->sd.ctrl_handler); in gc08a3_probe()
1286 gc08a3_power_off(gc08a3->dev); in gc08a3_probe()
1296 v4l2_async_unregister_subdev(&gc08a3->sd); in gc08a3_remove()
1298 media_entity_cleanup(&gc08a3->sd.entity); in gc08a3_remove()
1299 v4l2_ctrl_handler_free(&gc08a3->ctrls); in gc08a3_remove()
1301 pm_runtime_disable(&client->dev); in gc08a3_remove()
1302 if (!pm_runtime_status_suspended(&client->dev)) in gc08a3_remove()
1303 gc08a3_power_off(gc08a3->dev); in gc08a3_remove()
1304 pm_runtime_set_suspended(&client->dev); in gc08a3_remove()