Lines Matching full:sensor

3  * Driver for the Sony IMX415 CMOS Image Sensor.
703 static int imx415_set_testpattern(struct imx415 *sensor, int val) in imx415_set_testpattern() argument
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()
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() 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()
746 vmax = format->height + sensor->vblank->cur.val; in imx415_s_ctrl()
748 ret = cci_write(sensor->regmap, IMX415_SHR0, in imx415_s_ctrl()
754 ret = cci_write(sensor->regmap, IMX415_GAIN_PCG_0, 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()
774 pm_runtime_put(sensor->dev); in imx415_s_ctrl()
783 static int imx415_ctrls_init(struct imx415 *sensor) in imx415_ctrls_init() argument
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()
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()
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()
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()
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()
874 static int imx415_set_mode(struct imx415 *sensor, int mode) in imx415_set_mode() argument
879 dev_err(sensor->dev, "Mode %d not supported\n", mode); 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()
910 static int imx415_wakeup(struct imx415 *sensor) in imx415_wakeup() argument
914 ret = cci_write(sensor->regmap, IMX415_MODE, in imx415_wakeup()
929 static int imx415_stream_on(struct imx415 *sensor) in imx415_stream_on() argument
933 ret = imx415_wakeup(sensor); in imx415_stream_on()
934 return cci_write(sensor->regmap, IMX415_XMSTA, in imx415_stream_on()
938 static int imx415_stream_off(struct imx415 *sensor) in imx415_stream_off() argument
942 ret = cci_write(sensor->regmap, IMX415_XMSTA, in imx415_stream_off()
944 return cci_write(sensor->regmap, IMX415_MODE, in imx415_stream_off()
950 struct imx415 *sensor = to_imx415(sd); in imx415_s_stream() local
957 ret = imx415_stream_off(sensor); 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()
977 ret = imx415_stream_on(sensor); in imx415_s_stream()
993 pm_runtime_put_sync(sensor->dev); in imx415_s_stream()
1104 static int imx415_subdev_init(struct imx415 *sensor) in imx415_subdev_init() argument
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()
1112 ret = imx415_ctrls_init(sensor); 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()
1132 static void imx415_subdev_cleanup(struct imx415 *sensor) in imx415_subdev_cleanup() argument
1134 media_entity_cleanup(&sensor->subdev.entity); in imx415_subdev_cleanup()
1135 v4l2_ctrl_handler_free(&sensor->ctrls); in imx415_subdev_cleanup()
1138 static int imx415_power_on(struct imx415 *sensor) in imx415_power_on() argument
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()
1170 static void imx415_power_off(struct imx415 *sensor) in imx415_power_off() argument
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()
1177 static int imx415_identify_model(struct imx415 *sensor) in imx415_identify_model() argument
1183 * While most registers can be read when the sensor is in standby, this in imx415_identify_model()
1184 * is not the case of the sensor info register :-( in imx415_identify_model()
1186 ret = imx415_wakeup(sensor); in imx415_identify_model()
1188 return dev_err_probe(sensor->dev, ret, in imx415_identify_model()
1189 "failed to get sensor out of standby\n"); 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()
1194 "failed to read sensor information\n"); 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()
1233 static int imx415_parse_hw_config(struct imx415 *sensor) in imx415_parse_hw_config() argument
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()
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()
1292 * Check if there exists a sensor mode defined for current INCK, 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()
1318 "no valid sensor mode defined\n"); 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()
1349 struct imx415 *sensor; in imx415_probe() local
1352 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); in imx415_probe()
1353 if (!sensor) in imx415_probe()
1356 sensor->dev = &client->dev; in imx415_probe()
1358 ret = imx415_parse_hw_config(sensor); 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()
1369 * the sensor on manually here, identify it, and fully initialize it. in imx415_probe()
1371 ret = imx415_power_on(sensor); in imx415_probe()
1375 ret = imx415_identify_model(sensor); in imx415_probe()
1379 ret = imx415_subdev_init(sensor); 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()
1409 imx415_subdev_cleanup(sensor); in imx415_probe()
1411 imx415_power_off(sensor); in imx415_probe()
1418 struct imx415 *sensor = to_imx415(subdev); in imx415_remove() local
1422 imx415_subdev_cleanup(sensor); in imx415_remove()
1428 pm_runtime_disable(sensor->dev); in imx415_remove()
1429 if (!pm_runtime_status_suspended(sensor->dev)) in imx415_remove()
1430 imx415_power_off(sensor); in imx415_remove()
1431 pm_runtime_set_suspended(sensor->dev); in imx415_remove()
1438 struct imx415 *sensor = to_imx415(subdev); in imx415_runtime_resume() local
1440 return imx415_power_on(sensor); in imx415_runtime_resume()
1447 struct imx415 *sensor = to_imx415(subdev); in imx415_runtime_suspend() local
1449 imx415_power_off(sensor); in imx415_runtime_suspend()
1476 MODULE_DESCRIPTION("Sony IMX415 image sensor driver");