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

1 // SPDX-License-Identifier: GPL-2.0-only
19 #include <media/v4l2-cci.h>
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-fwnode.h>
22 #include <media/v4l2-subdev.h>
100 * describe MIPI CSI-2 speed. This driver uses lane rates wherever possible
114 /* INCK Settings - includes all lane rate and INCK dependent registers */
448 /* all-pixel 2-lane 720 Mbps 15.74 Hz mode */
464 /* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */
480 /* all-pixel 4-lane 891 Mbps 30 Hz mode */
573 "solid black",
574 "solid white",
575 "solid dark gray",
576 "solid light gray",
613 /* use all-pixel readout mode, no flip */
617 /* use RAW 10-bit mode */
708 cci_write(sensor->regmap, IMX415_BLKLEVEL, 0x00, &ret); in imx415_set_testpattern()
709 cci_write(sensor->regmap, IMX415_TPG_EN_DUOUT, 0x01, &ret); in imx415_set_testpattern()
710 cci_write(sensor->regmap, IMX415_TPG_PATSEL_DUOUT, in imx415_set_testpattern()
711 val - 1, &ret); in imx415_set_testpattern()
712 cci_write(sensor->regmap, IMX415_TPG_COLORWIDTH, 0x01, &ret); in imx415_set_testpattern()
713 cci_write(sensor->regmap, IMX415_TESTCLKEN_MIPI, 0x20, &ret); in imx415_set_testpattern()
714 cci_write(sensor->regmap, IMX415_DIG_CLP_MODE, 0x00, &ret); in imx415_set_testpattern()
715 cci_write(sensor->regmap, IMX415_WRJ_OPEN, 0x00, &ret); in imx415_set_testpattern()
717 cci_write(sensor->regmap, IMX415_BLKLEVEL, in imx415_set_testpattern()
719 cci_write(sensor->regmap, IMX415_TPG_EN_DUOUT, 0x00, &ret); in imx415_set_testpattern()
720 cci_write(sensor->regmap, IMX415_TESTCLKEN_MIPI, 0x00, &ret); in imx415_set_testpattern()
721 cci_write(sensor->regmap, IMX415_DIG_CLP_MODE, 0x01, &ret); in imx415_set_testpattern()
722 cci_write(sensor->regmap, IMX415_WRJ_OPEN, 0x01, &ret); in imx415_set_testpattern()
729 struct imx415 *sensor = container_of(ctrl->handler, struct imx415, in imx415_s_ctrl()
732 struct v4l2_subdev_state *state; in imx415_s_ctrl() local
737 if (!pm_runtime_get_if_in_use(sensor->dev)) in imx415_s_ctrl()
740 state = v4l2_subdev_get_locked_active_state(&sensor->subdev); in imx415_s_ctrl()
741 format = v4l2_subdev_state_get_format(state, 0); in imx415_s_ctrl()
743 switch (ctrl->id) { in imx415_s_ctrl()
746 vmax = format->height + sensor->vblank->cur.val; in imx415_s_ctrl()
747 ctrl->val = min_t(int, ctrl->val, vmax); in imx415_s_ctrl()
748 ret = cci_write(sensor->regmap, IMX415_SHR0, in imx415_s_ctrl()
749 vmax - ctrl->val, NULL); in imx415_s_ctrl()
754 ret = cci_write(sensor->regmap, IMX415_GAIN_PCG_0, in imx415_s_ctrl()
755 ctrl->val, NULL); in imx415_s_ctrl()
760 flip = (sensor->hflip->val << IMX415_HREVERSE_SHIFT) | in imx415_s_ctrl()
761 (sensor->vflip->val << IMX415_VREVERSE_SHIFT); in imx415_s_ctrl()
762 ret = cci_write(sensor->regmap, IMX415_REVERSE, flip, NULL); in imx415_s_ctrl()
766 ret = imx415_set_testpattern(sensor, ctrl->val); in imx415_s_ctrl()
770 ret = -EINVAL; in imx415_s_ctrl()
774 pm_runtime_put(sensor->dev); in imx415_s_ctrl()
787 u64 pixel_rate = supported_modes[sensor->cur_mode].pixel_rate; in imx415_ctrls_init()
788 u64 lane_rate = supported_modes[sensor->cur_mode].lane_rate; in imx415_ctrls_init()
790 IMX415_PIXEL_ARRAY_VBLANK - 8; in imx415_ctrls_init()
795 ret = v4l2_fwnode_device_parse(sensor->dev, &props); in imx415_ctrls_init()
799 v4l2_ctrl_handler_init(&sensor->ctrls, 10); in imx415_ctrls_init()
806 return dev_err_probe(sensor->dev, -EINVAL, in imx415_ctrls_init()
811 ctrl = v4l2_ctrl_new_int_menu(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
813 ARRAY_SIZE(link_freq_menu_items) - 1, i, in imx415_ctrls_init()
817 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx415_ctrls_init()
819 v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_EXPOSURE, in imx415_ctrls_init()
822 v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
827 hblank = supported_modes[sensor->cur_mode].hmax_pix - in imx415_ctrls_init()
829 ctrl = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
832 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx415_ctrls_init()
834 sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
839 if (sensor->vblank) in imx415_ctrls_init()
840 sensor->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx415_ctrls_init()
847 v4l2_ctrl_new_std(&sensor->ctrls, NULL, V4L2_CID_PIXEL_RATE, pixel_rate, in imx415_ctrls_init()
850 sensor->hflip = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
852 sensor->vflip = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
855 v4l2_ctrl_new_std_menu_items(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
857 ARRAY_SIZE(imx415_test_pattern_menu) - 1, in imx415_ctrls_init()
860 v4l2_ctrl_new_fwnode_properties(&sensor->ctrls, &imx415_ctrl_ops, in imx415_ctrls_init()
863 if (sensor->ctrls.error) { in imx415_ctrls_init()
864 dev_err_probe(sensor->dev, sensor->ctrls.error, in imx415_ctrls_init()
866 v4l2_ctrl_handler_free(&sensor->ctrls); in imx415_ctrls_init()
867 return sensor->ctrls.error; in imx415_ctrls_init()
869 sensor->subdev.ctrl_handler = &sensor->ctrls; in imx415_ctrls_init()
879 dev_err(sensor->dev, "Mode %d not supported\n", mode); in imx415_set_mode()
880 return -EINVAL; in imx415_set_mode()
883 cci_multi_reg_write(sensor->regmap, in imx415_set_mode()
888 cci_multi_reg_write(sensor->regmap, in imx415_set_mode()
889 sensor->clk_params->regs, in imx415_set_mode()
896 static int imx415_setup(struct imx415 *sensor, struct v4l2_subdev_state *state) in imx415_setup() argument
900 ret = cci_multi_reg_write(sensor->regmap, in imx415_setup()
907 return imx415_set_mode(sensor, sensor->cur_mode); in imx415_setup()
914 ret = cci_write(sensor->regmap, IMX415_MODE, in imx415_wakeup()
934 return cci_write(sensor->regmap, IMX415_XMSTA, in imx415_stream_on()
942 ret = cci_write(sensor->regmap, IMX415_XMSTA, in imx415_stream_off()
944 return cci_write(sensor->regmap, IMX415_MODE, in imx415_stream_off()
951 struct v4l2_subdev_state *state; in imx415_s_stream() local
954 state = v4l2_subdev_lock_and_get_active_state(sd); in imx415_s_stream()
959 pm_runtime_mark_last_busy(sensor->dev); in imx415_s_stream()
960 pm_runtime_put_autosuspend(sensor->dev); in imx415_s_stream()
965 ret = pm_runtime_resume_and_get(sensor->dev); in imx415_s_stream()
969 ret = imx415_setup(sensor, state); in imx415_s_stream()
973 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls); in imx415_s_stream()
984 v4l2_subdev_unlock_state(state); in imx415_s_stream()
993 pm_runtime_put_sync(sensor->dev); in imx415_s_stream()
999 struct v4l2_subdev_state *state, in imx415_enum_mbus_code() argument
1002 if (code->index != 0) in imx415_enum_mbus_code()
1003 return -EINVAL; in imx415_enum_mbus_code()
1005 code->code = MEDIA_BUS_FMT_SGBRG10_1X10; in imx415_enum_mbus_code()
1011 struct v4l2_subdev_state *state, in imx415_enum_frame_size() argument
1016 format = v4l2_subdev_state_get_format(state, fse->pad); in imx415_enum_frame_size()
1018 if (fse->index > 0 || fse->code != format->code) in imx415_enum_frame_size()
1019 return -EINVAL; in imx415_enum_frame_size()
1021 fse->min_width = IMX415_PIXEL_ARRAY_WIDTH; in imx415_enum_frame_size()
1022 fse->max_width = fse->min_width; in imx415_enum_frame_size()
1023 fse->min_height = IMX415_PIXEL_ARRAY_HEIGHT; in imx415_enum_frame_size()
1024 fse->max_height = fse->min_height; in imx415_enum_frame_size()
1029 struct v4l2_subdev_state *state, in imx415_set_format() argument
1034 format = v4l2_subdev_state_get_format(state, fmt->pad); in imx415_set_format()
1036 format->width = fmt->format.width; in imx415_set_format()
1037 format->height = fmt->format.height; in imx415_set_format()
1038 format->code = MEDIA_BUS_FMT_SGBRG10_1X10; in imx415_set_format()
1039 format->field = V4L2_FIELD_NONE; in imx415_set_format()
1040 format->colorspace = V4L2_COLORSPACE_RAW; in imx415_set_format()
1041 format->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in imx415_set_format()
1042 format->quantization = V4L2_QUANTIZATION_DEFAULT; in imx415_set_format()
1043 format->xfer_func = V4L2_XFER_FUNC_NONE; in imx415_set_format()
1045 fmt->format = *format; in imx415_set_format()
1053 switch (sel->target) { in imx415_get_selection()
1057 sel->r.top = IMX415_PIXEL_ARRAY_TOP; in imx415_get_selection()
1058 sel->r.left = IMX415_PIXEL_ARRAY_LEFT; in imx415_get_selection()
1059 sel->r.width = IMX415_PIXEL_ARRAY_WIDTH; in imx415_get_selection()
1060 sel->r.height = IMX415_PIXEL_ARRAY_HEIGHT; in imx415_get_selection()
1065 return -EINVAL; in imx415_get_selection()
1069 struct v4l2_subdev_state *state) in imx415_init_state() argument
1078 imx415_set_format(sd, state, &format); in imx415_init_state()
1106 struct i2c_client *client = to_i2c_client(sensor->dev); in imx415_subdev_init()
1109 v4l2_i2c_subdev_init(&sensor->subdev, client, &imx415_subdev_ops); in imx415_subdev_init()
1110 sensor->subdev.internal_ops = &imx415_internal_ops; in imx415_subdev_init()
1116 sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in imx415_subdev_init()
1118 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in imx415_subdev_init()
1119 sensor->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx415_subdev_init()
1120 ret = media_entity_pads_init(&sensor->subdev.entity, 1, &sensor->pad); in imx415_subdev_init()
1122 v4l2_ctrl_handler_free(&sensor->ctrls); in imx415_subdev_init()
1126 sensor->subdev.state_lock = sensor->subdev.ctrl_handler->lock; in imx415_subdev_init()
1127 v4l2_subdev_init_finalize(&sensor->subdev); in imx415_subdev_init()
1134 media_entity_cleanup(&sensor->subdev.entity); in imx415_subdev_cleanup()
1135 v4l2_ctrl_handler_free(&sensor->ctrls); in imx415_subdev_cleanup()
1142 ret = regulator_bulk_enable(ARRAY_SIZE(sensor->supplies), in imx415_power_on()
1143 sensor->supplies); in imx415_power_on()
1147 gpiod_set_value_cansleep(sensor->reset, 0); in imx415_power_on()
1151 ret = clk_prepare_enable(sensor->clk); in imx415_power_on()
1165 gpiod_set_value_cansleep(sensor->reset, 1); in imx415_power_on()
1166 regulator_bulk_disable(ARRAY_SIZE(sensor->supplies), sensor->supplies); in imx415_power_on()
1172 clk_disable_unprepare(sensor->clk); in imx415_power_off()
1173 gpiod_set_value_cansleep(sensor->reset, 1); in imx415_power_off()
1174 regulator_bulk_disable(ARRAY_SIZE(sensor->supplies), sensor->supplies); in imx415_power_off()
1184 * is not the case of the sensor info register :-( in imx415_identify_model()
1188 return dev_err_probe(sensor->dev, ret, in imx415_identify_model()
1191 ret = cci_read(sensor->regmap, IMX415_SENSOR_INFO, &chip_id, NULL); in imx415_identify_model()
1193 dev_err_probe(sensor->dev, ret, in imx415_identify_model()
1202 dev_info(sensor->dev, "Detected IMX415 image sensor\n"); in imx415_identify_model()
1205 ret = dev_err_probe(sensor->dev, -ENODEV, in imx415_identify_model()
1213 cci_write(sensor->regmap, IMX415_MODE, IMX415_MODE_STANDBY, &ret); in imx415_identify_model()
1228 return -EINVAL; in imx415_check_inck()
1244 for (i = 0; i < ARRAY_SIZE(sensor->supplies); ++i) in imx415_parse_hw_config()
1245 sensor->supplies[i].supply = imx415_supply_names[i]; in imx415_parse_hw_config()
1247 ret = devm_regulator_bulk_get(sensor->dev, ARRAY_SIZE(sensor->supplies), in imx415_parse_hw_config()
1248 sensor->supplies); in imx415_parse_hw_config()
1250 return dev_err_probe(sensor->dev, ret, in imx415_parse_hw_config()
1253 sensor->reset = devm_gpiod_get_optional(sensor->dev, "reset", in imx415_parse_hw_config()
1255 if (IS_ERR(sensor->reset)) in imx415_parse_hw_config()
1256 return dev_err_probe(sensor->dev, PTR_ERR(sensor->reset), in imx415_parse_hw_config()
1259 sensor->clk = devm_clk_get(sensor->dev, "inck"); in imx415_parse_hw_config()
1260 if (IS_ERR(sensor->clk)) in imx415_parse_hw_config()
1261 return dev_err_probe(sensor->dev, PTR_ERR(sensor->clk), in imx415_parse_hw_config()
1264 ep = fwnode_graph_get_next_endpoint(dev_fwnode(sensor->dev), NULL); in imx415_parse_hw_config()
1266 return -ENXIO; in imx415_parse_hw_config()
1276 sensor->num_data_lanes = bus_cfg.bus.mipi_csi2.num_data_lanes; in imx415_parse_hw_config()
1279 ret = dev_err_probe(sensor->dev, -EINVAL, in imx415_parse_hw_config()
1286 ret = dev_err_probe(sensor->dev, -EINVAL, in imx415_parse_hw_config()
1295 inck = clk_get_rate(sensor->clk); in imx415_parse_hw_config()
1298 dev_dbg(sensor->dev, in imx415_parse_hw_config()
1305 if (sensor->num_data_lanes != supported_modes[j].lanes) in imx415_parse_hw_config()
1310 sensor->cur_mode = j; in imx415_parse_hw_config()
1317 ret = dev_err_probe(sensor->dev, -EINVAL, in imx415_parse_hw_config()
1322 lane_rate = supported_modes[sensor->cur_mode].lane_rate; in imx415_parse_hw_config()
1326 sensor->clk_params = &imx415_clk_params[i]; in imx415_parse_hw_config()
1331 ret = dev_err_probe(sensor->dev, -EINVAL, in imx415_parse_hw_config()
1333 sensor->cur_mode); in imx415_parse_hw_config()
1338 dev_dbg(sensor->dev, "clock: %lu Hz, lane_rate: %llu bps, lanes: %d\n", in imx415_parse_hw_config()
1339 inck, lane_rate, sensor->num_data_lanes); in imx415_parse_hw_config()
1352 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); in imx415_probe()
1354 return -ENOMEM; in imx415_probe()
1356 sensor->dev = &client->dev; in imx415_probe()
1362 sensor->regmap = devm_cci_regmap_init_i2c(client, 16); in imx415_probe()
1363 if (IS_ERR(sensor->regmap)) in imx415_probe()
1364 return PTR_ERR(sensor->regmap); in imx415_probe()
1387 pm_runtime_set_active(sensor->dev); in imx415_probe()
1388 pm_runtime_get_noresume(sensor->dev); in imx415_probe()
1389 pm_runtime_enable(sensor->dev); in imx415_probe()
1391 ret = v4l2_async_register_subdev_sensor(&sensor->subdev); in imx415_probe()
1400 pm_runtime_set_autosuspend_delay(sensor->dev, 1000); in imx415_probe()
1401 pm_runtime_use_autosuspend(sensor->dev); in imx415_probe()
1402 pm_runtime_put_autosuspend(sensor->dev); in imx415_probe()
1407 pm_runtime_disable(sensor->dev); in imx415_probe()
1408 pm_runtime_put_noidle(sensor->dev); in imx415_probe()
1428 pm_runtime_disable(sensor->dev); in imx415_remove()
1429 if (!pm_runtime_status_suspended(sensor->dev)) in imx415_remove()
1431 pm_runtime_set_suspended(sensor->dev); in imx415_remove()