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-event.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-subdev.h>
69 "No Pattern", "Solid Black", "Colour Bar", "Solid White",
70 "Solid Red", "Solid Green", "Solid Blue", "Solid Yellow",
595 gc08a3->supplies); in gc08a3_power_on()
597 dev_err(gc08a3->dev, "failed to enable regulators: %d\n", ret); in gc08a3_power_on()
601 ret = clk_prepare_enable(gc08a3->xclk); in gc08a3_power_on()
604 gc08a3->supplies); in gc08a3_power_on()
605 dev_err(gc08a3->dev, "clk prepare enable failed\n"); in gc08a3_power_on()
611 gpiod_set_value_cansleep(gc08a3->reset_gpio, 0); in gc08a3_power_on()
622 clk_disable_unprepare(gc08a3->xclk); in gc08a3_power_off()
623 gpiod_set_value_cansleep(gc08a3->reset_gpio, 1); in gc08a3_power_off()
625 gc08a3->supplies); in gc08a3_power_off()
634 if (code->index > 0) in gc08a3_enum_mbus_code()
635 return -EINVAL; in gc08a3_enum_mbus_code()
637 code->code = GC08A3_MBUS_CODE; in gc08a3_enum_mbus_code()
646 if (fse->code != GC08A3_MBUS_CODE) in gc08a3_enum_frame_size()
647 return -EINVAL; in gc08a3_enum_frame_size()
649 if (fse->index >= ARRAY_SIZE(gc08a3_modes)) in gc08a3_enum_frame_size()
650 return -EINVAL; in gc08a3_enum_frame_size()
652 fse->min_width = gc08a3_modes[fse->index].width; in gc08a3_enum_frame_size()
653 fse->max_width = gc08a3_modes[fse->index].width; in gc08a3_enum_frame_size()
654 fse->min_height = gc08a3_modes[fse->index].height; in gc08a3_enum_frame_size()
655 fse->max_height = gc08a3_modes[fse->index].height; in gc08a3_enum_frame_size()
666 ret = __v4l2_ctrl_modify_range(gc08a3->vblank, in gc08a3_update_cur_mode_controls()
667 mode->vts_min - mode->height, in gc08a3_update_cur_mode_controls()
668 GC08A3_VTS_MAX - mode->height, 1, in gc08a3_update_cur_mode_controls()
669 mode->vts_def - mode->height); in gc08a3_update_cur_mode_controls()
671 dev_err(gc08a3->dev, "VB ctrl range update failed\n"); in gc08a3_update_cur_mode_controls()
675 h_blank = mode->hts - mode->width; in gc08a3_update_cur_mode_controls()
676 ret = __v4l2_ctrl_modify_range(gc08a3->hblank, h_blank, h_blank, 1, in gc08a3_update_cur_mode_controls()
679 dev_err(gc08a3->dev, "HB ctrl range update failed\n"); in gc08a3_update_cur_mode_controls()
683 exposure_max = mode->vts_def - GC08A3_EXP_MARGIN; in gc08a3_update_cur_mode_controls()
684 ret = __v4l2_ctrl_modify_range(gc08a3->exposure, GC08A3_EXP_MIN, in gc08a3_update_cur_mode_controls()
688 dev_err(gc08a3->dev, "exposure ctrl range update failed\n"); in gc08a3_update_cur_mode_controls()
699 fmt->width = mode->width; in gc08a3_update_pad_format()
700 fmt->height = mode->height; in gc08a3_update_pad_format()
701 fmt->code = GC08A3_MBUS_CODE; in gc08a3_update_pad_format()
702 fmt->field = V4L2_FIELD_NONE; in gc08a3_update_pad_format()
703 fmt->colorspace = V4L2_COLORSPACE_RAW; in gc08a3_update_pad_format()
704 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in gc08a3_update_pad_format()
705 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in gc08a3_update_pad_format()
706 fmt->xfer_func = V4L2_XFER_FUNC_NONE; in gc08a3_update_pad_format()
710 struct v4l2_subdev_state *state, in gc08a3_set_format() argument
719 width, height, fmt->format.width, in gc08a3_set_format()
720 fmt->format.height); in gc08a3_set_format()
722 /* update crop info to subdev state */ in gc08a3_set_format()
723 crop = v4l2_subdev_state_get_crop(state, 0); in gc08a3_set_format()
724 crop->width = mode->width; in gc08a3_set_format()
725 crop->height = mode->height; in gc08a3_set_format()
727 /* update fmt info to subdev state */ in gc08a3_set_format()
728 gc08a3_update_pad_format(gc08a3, mode, &fmt->format); in gc08a3_set_format()
729 mbus_fmt = v4l2_subdev_state_get_format(state, 0); in gc08a3_set_format()
730 *mbus_fmt = fmt->format; in gc08a3_set_format()
732 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) in gc08a3_set_format()
735 gc08a3->cur_mode = mode; in gc08a3_set_format()
742 struct v4l2_subdev_state *state, in gc08a3_get_selection() argument
745 switch (sel->target) { in gc08a3_get_selection()
748 sel->r = *v4l2_subdev_state_get_crop(state, 0); in gc08a3_get_selection()
751 sel->r.top = 0; in gc08a3_get_selection()
752 sel->r.left = 0; in gc08a3_get_selection()
753 sel->r.width = GC08A3_NATIVE_WIDTH; in gc08a3_get_selection()
754 sel->r.height = GC08A3_NATIVE_HEIGHT; in gc08a3_get_selection()
757 return -EINVAL; in gc08a3_get_selection()
764 struct v4l2_subdev_state *state) in gc08a3_init_state() argument
776 gc08a3_set_format(sd, state, &fmt); in gc08a3_init_state()
786 ret = cci_read(gc08a3->regmap, GC08A3_FLIP_REG, &val, NULL); in gc08a3_set_ctrl_hflip()
788 dev_err(gc08a3->dev, "read hflip register failed: %d\n", ret); in gc08a3_set_ctrl_hflip()
792 return cci_update_bits(gc08a3->regmap, GC08A3_FLIP_REG, in gc08a3_set_ctrl_hflip()
802 ret = cci_read(gc08a3->regmap, GC08A3_FLIP_REG, &val, NULL); in gc08a3_set_ctrl_vflip()
804 dev_err(gc08a3->dev, "read vflip register failed: %d\n", ret); in gc08a3_set_ctrl_vflip()
808 return cci_update_bits(gc08a3->regmap, GC08A3_FLIP_REG, in gc08a3_set_ctrl_vflip()
838 ret = cci_write(gc08a3->regmap, GC08A3_REG_TEST_PATTERN_IDX, in gc08a3_test_pattern()
843 return cci_write(gc08a3->regmap, GC08A3_REG_TEST_PATTERN_EN, in gc08a3_test_pattern()
846 return cci_write(gc08a3->regmap, GC08A3_REG_TEST_PATTERN_EN, in gc08a3_test_pattern()
854 container_of(ctrl->handler, struct gc08a3, ctrls); in gc08a3_set_ctrl()
857 struct v4l2_subdev_state *state; in gc08a3_set_ctrl() local
860 state = v4l2_subdev_get_locked_active_state(&gc08a3->sd); in gc08a3_set_ctrl()
861 format = v4l2_subdev_state_get_format(state, 0); in gc08a3_set_ctrl()
863 if (ctrl->id == V4L2_CID_VBLANK) { in gc08a3_set_ctrl()
865 exposure_max = format->height + ctrl->val - GC08A3_EXP_MARGIN; in gc08a3_set_ctrl()
866 __v4l2_ctrl_modify_range(gc08a3->exposure, in gc08a3_set_ctrl()
867 gc08a3->exposure->minimum, in gc08a3_set_ctrl()
868 exposure_max, gc08a3->exposure->step, in gc08a3_set_ctrl()
876 if (!pm_runtime_get_if_active(gc08a3->dev)) in gc08a3_set_ctrl()
879 switch (ctrl->id) { in gc08a3_set_ctrl()
881 ret = cci_write(gc08a3->regmap, GC08A3_EXP_REG, in gc08a3_set_ctrl()
882 ctrl->val, NULL); in gc08a3_set_ctrl()
886 ret = cci_write(gc08a3->regmap, GC08A3_AGAIN_REG, in gc08a3_set_ctrl()
887 ctrl->val, NULL); in gc08a3_set_ctrl()
891 ret = cci_write(gc08a3->regmap, GC08A3_FRAME_LENGTH_REG, in gc08a3_set_ctrl()
892 gc08a3->cur_mode->height + ctrl->val, NULL); in gc08a3_set_ctrl()
896 ret = gc08a3_set_ctrl_hflip(gc08a3, ctrl->val); in gc08a3_set_ctrl()
900 ret = gc08a3_set_ctrl_vflip(gc08a3, ctrl->val); in gc08a3_set_ctrl()
904 ret = gc08a3_test_pattern(gc08a3, ctrl->val); in gc08a3_set_ctrl()
911 pm_runtime_put(gc08a3->dev); in gc08a3_set_ctrl()
926 ret = pm_runtime_resume_and_get(gc08a3->dev); in gc08a3_start_streaming()
930 ret = cci_multi_reg_write(gc08a3->regmap, in gc08a3_start_streaming()
936 mode = gc08a3->cur_mode; in gc08a3_start_streaming()
937 reg_list = &mode->reg_list; in gc08a3_start_streaming()
938 ret = cci_multi_reg_write(gc08a3->regmap, in gc08a3_start_streaming()
939 reg_list->regs, reg_list->num_of_regs, NULL); in gc08a3_start_streaming()
943 ret = __v4l2_ctrl_handler_setup(&gc08a3->ctrls); in gc08a3_start_streaming()
945 dev_err(gc08a3->dev, "could not sync v4l2 controls\n"); in gc08a3_start_streaming()
949 ret = cci_write(gc08a3->regmap, GC08A3_STREAMING_REG, 1, NULL); in gc08a3_start_streaming()
951 dev_err(gc08a3->dev, "write STREAMING_REG failed: %d\n", ret); in gc08a3_start_streaming()
958 pm_runtime_put(gc08a3->dev); in gc08a3_start_streaming()
966 ret = cci_write(gc08a3->regmap, GC08A3_STREAMING_REG, 0, NULL); in gc08a3_stop_streaming()
968 dev_err(gc08a3->dev, "could not sent stop streaming %d\n", ret); in gc08a3_stop_streaming()
970 pm_runtime_put(gc08a3->dev); in gc08a3_stop_streaming()
977 struct v4l2_subdev_state *state; in gc08a3_s_stream() local
980 state = v4l2_subdev_lock_and_get_active_state(subdev); in gc08a3_s_stream()
987 v4l2_subdev_unlock_state(state); in gc08a3_s_stream()
1024 gc08a3->supplies[i].supply = gc08a3_supply_name[i]; in gc08a3_get_regulators()
1027 gc08a3->supplies); in gc08a3_get_regulators()
1037 struct device *dev = gc08a3->dev; in gc08a3_parse_fwnode()
1044 return -EINVAL; in gc08a3_parse_fwnode()
1057 &gc08a3->link_freq_bitmap); in gc08a3_parse_fwnode()
1077 struct i2c_client *client = v4l2_get_subdevdata(&gc08a3->sd); in gc08a3_init_controls()
1085 ctrl_hdlr = &gc08a3->ctrls; in gc08a3_init_controls()
1090 gc08a3->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1092 gc08a3->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1094 v4l2_ctrl_cluster(2, &gc08a3->hflip); in gc08a3_init_controls()
1096 gc08a3->link_freq = in gc08a3_init_controls()
1100 ARRAY_SIZE(gc08a3_link_freq_menu_items) - 1, in gc08a3_init_controls()
1103 if (gc08a3->link_freq) in gc08a3_init_controls()
1104 gc08a3->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc08a3_init_controls()
1106 gc08a3->pixel_rate = in gc08a3_init_controls()
1114 gc08a3->vblank = in gc08a3_init_controls()
1117 mode->vts_min - mode->height, in gc08a3_init_controls()
1118 GC08A3_VTS_MAX - mode->height, 1, in gc08a3_init_controls()
1119 mode->vts_def - mode->height); in gc08a3_init_controls()
1121 h_blank = mode->hts - mode->width; in gc08a3_init_controls()
1122 gc08a3->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1125 if (gc08a3->hblank) in gc08a3_init_controls()
1126 gc08a3->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in gc08a3_init_controls()
1133 exposure_max = mode->vts_def - GC08A3_EXP_MARGIN; in gc08a3_init_controls()
1134 gc08a3->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &gc08a3_ctrl_ops, in gc08a3_init_controls()
1141 ARRAY_SIZE(gc08a3_test_pattern_menu) - 1, in gc08a3_init_controls()
1145 ret = v4l2_fwnode_device_parse(&client->dev, &props); in gc08a3_init_controls()
1153 if (ctrl_hdlr->error) { in gc08a3_init_controls()
1154 ret = ctrl_hdlr->error; in gc08a3_init_controls()
1158 gc08a3->sd.ctrl_handler = ctrl_hdlr; in gc08a3_init_controls()
1173 ret = cci_read(gc08a3->regmap, GC08A3_REG_CHIP_ID, &val, NULL); in gc08a3_identify_module()
1175 dev_err(gc08a3->dev, "failed to read chip id"); in gc08a3_identify_module()
1180 dev_err(gc08a3->dev, "chip id mismatch: 0x%x!=0x%llx", in gc08a3_identify_module()
1182 return -ENXIO; in gc08a3_identify_module()
1190 struct device *dev = &client->dev; in gc08a3_probe()
1196 return -ENOMEM; in gc08a3_probe()
1198 gc08a3->dev = dev; in gc08a3_probe()
1204 gc08a3->regmap = devm_cci_regmap_init_i2c(client, 16); in gc08a3_probe()
1205 if (IS_ERR(gc08a3->regmap)) in gc08a3_probe()
1206 return dev_err_probe(dev, PTR_ERR(gc08a3->regmap), in gc08a3_probe()
1209 gc08a3->xclk = devm_clk_get(dev, NULL); in gc08a3_probe()
1210 if (IS_ERR(gc08a3->xclk)) in gc08a3_probe()
1211 return dev_err_probe(dev, PTR_ERR(gc08a3->xclk), in gc08a3_probe()
1214 ret = clk_set_rate(gc08a3->xclk, GC08A3_DEFAULT_CLK_FREQ); in gc08a3_probe()
1224 gc08a3->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in gc08a3_probe()
1225 if (IS_ERR(gc08a3->reset_gpio)) in gc08a3_probe()
1226 return dev_err_probe(dev, PTR_ERR(gc08a3->reset_gpio), in gc08a3_probe()
1229 v4l2_i2c_subdev_init(&gc08a3->sd, client, &gc08a3_subdev_ops); in gc08a3_probe()
1230 gc08a3->sd.internal_ops = &gc08a3_internal_ops; in gc08a3_probe()
1231 gc08a3->cur_mode = &gc08a3_modes[0]; in gc08a3_probe()
1233 ret = gc08a3_power_on(gc08a3->dev); in gc08a3_probe()
1240 dev_err(&client->dev, "failed to find sensor: %d\n", ret); in gc08a3_probe()
1246 dev_err(&client->dev, "failed to init controls: %d", ret); in gc08a3_probe()
1250 gc08a3->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in gc08a3_probe()
1252 gc08a3->pad.flags = MEDIA_PAD_FL_SOURCE; in gc08a3_probe()
1253 gc08a3->sd.dev = &client->dev; in gc08a3_probe()
1254 gc08a3->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in gc08a3_probe()
1256 ret = media_entity_pads_init(&gc08a3->sd.entity, 1, &gc08a3->pad); in gc08a3_probe()
1262 gc08a3->sd.state_lock = gc08a3->ctrls.lock; in gc08a3_probe()
1263 ret = v4l2_subdev_init_finalize(&gc08a3->sd); in gc08a3_probe()
1269 pm_runtime_set_active(gc08a3->dev); in gc08a3_probe()
1270 pm_runtime_enable(gc08a3->dev); in gc08a3_probe()
1271 pm_runtime_set_autosuspend_delay(gc08a3->dev, 1000); in gc08a3_probe()
1272 pm_runtime_use_autosuspend(gc08a3->dev); in gc08a3_probe()
1273 pm_runtime_idle(gc08a3->dev); in gc08a3_probe()
1275 ret = v4l2_async_register_subdev_sensor(&gc08a3->sd); in gc08a3_probe()
1284 pm_runtime_disable(gc08a3->dev); in gc08a3_probe()
1285 v4l2_subdev_cleanup(&gc08a3->sd); in gc08a3_probe()
1288 media_entity_cleanup(&gc08a3->sd.entity); in gc08a3_probe()
1291 v4l2_ctrl_handler_free(gc08a3->sd.ctrl_handler); in gc08a3_probe()
1294 gc08a3_power_off(gc08a3->dev); in gc08a3_probe()
1304 v4l2_async_unregister_subdev(&gc08a3->sd); in gc08a3_remove()
1306 media_entity_cleanup(&gc08a3->sd.entity); in gc08a3_remove()
1307 v4l2_ctrl_handler_free(&gc08a3->ctrls); in gc08a3_remove()
1309 pm_runtime_disable(&client->dev); in gc08a3_remove()
1310 if (!pm_runtime_status_suspended(&client->dev)) in gc08a3_remove()
1311 gc08a3_power_off(gc08a3->dev); in gc08a3_remove()
1312 pm_runtime_set_suspended(&client->dev); in gc08a3_remove()