int __m10mo_try_mbus_fmt_fw_type2(struct v4l2_subdev *sd,
			struct v4l2_mbus_framefmt *fmt, bool update_fmt)
{
	struct m10mo_device *dev = to_m10mo_sensor(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct atomisp_input_stream_info *stream_info =
			(struct atomisp_input_stream_info *)fmt->reserved;
	const struct m10mo_resolution *res;
	int entries, idx;
//	int mode = M10MO_GET_RESOLUTION_MODE(dev->fw_type);

	/* Set mbus format to 0x8001(YUV420) */
	fmt->code = 0x8001;

	/* In ZSL case, capture table needs to be handled separately */
	if (stream_info->stream == ATOMISP_INPUT_STREAM_CAPTURE &&
			(dev->run_mode == CI_MODE_PREVIEW ||
			 dev->run_mode == CI_MODE_VIDEO ||
			 dev->run_mode == CI_MODE_CONTINUOUS)) {
		res = resolutions[M10MO_MODE_CAPTURE_INDEX];
		entries =
		     resolutions_sizes[M10MO_MODE_CAPTURE_INDEX];
	} else {
		res = dev->curr_res_table;
		entries = dev->entries_curr_table;
	}

	/* check if the given resolutions are spported */
	idx = get_resolution_index(res, entries, fmt->width, fmt->height);
	if (idx < 0) {
		dev_err(&client->dev, "%s unsupported resolution: %dx%d\n",
			__func__, fmt->width, fmt->height);
		return -EINVAL;
	}

	/* If the caller wants to get updated fmt values based on the search */
	if (update_fmt) {
		if (fmt->code == V4L2_MBUS_FMT_JPEG_1X8) {
			fmt->width = dev->mipi_params.jpeg_width;
			fmt->height = dev->mipi_params.jpeg_height;
		} else if (fmt->code == V4L2_MBUS_FMT_CUSTOM_M10MO_RAW) {
			fmt->width = dev->mipi_params.raw_width;
			fmt->height = dev->mipi_params.raw_height;
		} else {
			fmt->width = res[idx].width;
			fmt->height = res[idx].height;
		}
	}
	return idx;
}
static int m10mo_set_burst_capture(struct v4l2_subdev *sd)
{
	struct m10mo_device *dev = to_m10mo_sensor(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	const struct m10mo_resolution *capture_res;
//	int mode = M10MO_GET_RESOLUTION_MODE(dev->fw_type);
	int idx;
	int ret;

	dev_info(&client->dev, "%s mode: %d width: %d, height: %d, cmd: 0x%x\n",
		__func__, dev->cmd, dev->curr_res_table[dev->fmt_idx].width,
		dev->curr_res_table[dev->fmt_idx].height,
		dev->curr_res_table[dev->fmt_idx].command);

	/* Exit from normal monitor mode. */
	ret = m10mo_request_cmd_effect(sd, M10MO_PARAMETER_MODE_REQUEST_CMD, NULL);
	if (ret)
		return ret;
	ret = m10mo_wait_mode_change(sd, M10MO_PARAMETER_MODE_REQUEST_CMD, M10MO_INIT_TIMEOUT);
	if (ret)
		return ret;

	/* Configure burst capture resolution.
	 * Map burst capture size to monitor size. Burst capture uses
	 * monitor parameters.
	 */
	capture_res = resolutions[M10MO_MODE_CAPTURE_INDEX];
	idx = get_resolution_index(
		resolutions[M10MO_MODE_CAPTURE_INDEX],
		resolutions_sizes[M10MO_MODE_CAPTURE_INDEX],
		capture_res->width, capture_res->height);
	if (idx == -1) {
		dev_err(&client->dev, "Unsupported burst capture size %dx%d\n",
			capture_res->width, capture_res->height);
		return -EINVAL;
	}
	ret = m10mo_writeb(sd, CATEGORY_PARAM, PARAM_MON_SIZE,
		resolutions[M10MO_MODE_PREVIEW_INDEX][idx]
		.command);
	if (ret)
		return ret;

	/* Start burst capture. */
	ret = m10mo_request_cmd_effect(sd, M10MO_BURST_CAPTURE_MODE, NULL);

	return ret;
}
static int hm5040_s_mbus_fmt(struct v4l2_subdev *sd,
                             struct v4l2_mbus_framefmt *fmt)
{
    struct hm5040_device *dev = to_hm5040_sensor(sd);
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    struct camera_mipi_info *hm5040_info = NULL;
    int ret = 0;

    hm5040_info = v4l2_get_subdev_hostdata(sd);
    if (hm5040_info == NULL)
        return -EINVAL;

    pr_info("%s\n", __func__);
    mutex_lock(&dev->input_lock);
    ret = hm5040_try_mbus_fmt(sd, fmt);
    if (ret == -1) {
        dev_err(&client->dev, "try fmt fail\n");
        goto err;
    }

    dev->fmt_idx = get_resolution_index(fmt->width,
                                        fmt->height);
    if (dev->fmt_idx == -1) {
        dev_err(&client->dev, "get resolution fail\n");
        mutex_unlock(&dev->input_lock);
        return -EINVAL;
    }

    ret = startup(sd);
    if (ret)
        dev_err(&client->dev, "hm5040 startup err\n");

    ret = hm5040_get_intg_factor(client, hm5040_info,
                                 &hm5040_res[dev->fmt_idx]);
    if (ret) {
        dev_err(&client->dev, "failed to get integration_factor\n");
        goto err;
    }

err:
    mutex_unlock(&dev->input_lock);
    return ret;
}
static int ov5693_s_mbus_fmt(struct v4l2_subdev *sd,
			     struct v4l2_mbus_framefmt *fmt)
{
	struct ov5693_device *dev = to_ov5693_sensor(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct camera_mipi_info *ov5693_info = NULL;
	int ret = 0;

	ov5693_info = v4l2_get_subdev_hostdata(sd);
	if (ov5693_info == NULL)
		return -EINVAL;

	mutex_lock(&dev->input_lock);
	ret = __ov5693_try_mbus_fmt(sd, fmt);
	if (ret == -1) {
		dev_err(&client->dev, "try fmt fail\n");
		goto done;
	}

	dev->fmt_idx = get_resolution_index(sd, fmt->width, fmt->height);
	if (dev->fmt_idx == -1) {
		dev_err(&client->dev, "get resolution fail\n");
		goto done;
	}

	ret = ov5693_write_reg_array(client, dev->ov5693_res[dev->fmt_idx].regs);
	if (ret) {
		dev_err(&client->dev, "ov5693 write fmt register err.\n");
		goto done;
	}

	ret = ov5693_get_intg_factor(client, ov5693_info,
					&dev->ov5693_res[dev->fmt_idx]);
	if (ret)
		dev_err(&client->dev, "failed to get integration_factor\n");

done:
	mutex_unlock(&dev->input_lock);
	return ret;
}
示例#5
0
static int ov2680_set_fmt(struct v4l2_subdev *sd,
			  struct v4l2_subdev_pad_config *cfg,
			  struct v4l2_subdev_format *format)
{
	struct v4l2_mbus_framefmt *fmt = &format->format;
	struct ov2680_device *dev = to_ov2680_sensor(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct camera_mipi_info *ov2680_info = NULL;
	int ret = 0;
	int idx = 0;
	dev_dbg(&client->dev, "+++++ov2680_s_mbus_fmt+++++l\n");
	if (format->pad)
		return -EINVAL;

	if (!fmt)
		return -EINVAL;

	ov2680_info = v4l2_get_subdev_hostdata(sd);
	if (!ov2680_info)
		return -EINVAL;

	mutex_lock(&dev->input_lock);
	idx = nearest_resolution_index(fmt->width, fmt->height);
	if (idx == -1) {
		/* return the largest resolution */
		fmt->width = ov2680_res[N_RES - 1].width;
		fmt->height = ov2680_res[N_RES - 1].height;
	} else {
		fmt->width = ov2680_res[idx].width;
		fmt->height = ov2680_res[idx].height;
	}
	fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
		cfg->try_fmt = *fmt;
		mutex_unlock(&dev->input_lock);
		return 0;
		}
	dev->fmt_idx = get_resolution_index(fmt->width, fmt->height);
	dev_dbg(&client->dev, "+++++get_resolution_index=%d+++++l\n",
		     dev->fmt_idx);
	if (dev->fmt_idx == -1) {
		dev_err(&client->dev, "get resolution fail\n");
		mutex_unlock(&dev->input_lock);
		return -EINVAL;
	}
	v4l2_info(client, "__s_mbus_fmt i=%d, w=%d, h=%d\n", dev->fmt_idx,
		  fmt->width, fmt->height);
	dev_dbg(&client->dev, "__s_mbus_fmt i=%d, w=%d, h=%d\n",
		     dev->fmt_idx, fmt->width, fmt->height);

	ret = ov2680_write_reg_array(client, ov2680_res[dev->fmt_idx].regs);
	if (ret)
		dev_err(&client->dev, "ov2680 write resolution register err\n");

	ret = ov2680_get_intg_factor(client, ov2680_info,
				     &ov2680_res[dev->fmt_idx]);
	if (ret) {
		dev_err(&client->dev, "failed to get integration_factor\n");
		goto err;
	}

	/*recall flip functions to avoid flip registers
	 * were overridden by default setting
	 */
	if (h_flag)
		ov2680_h_flip(sd, h_flag);
	if (v_flag)
		ov2680_v_flip(sd, v_flag);

	v4l2_info(client, "\n%s idx %d \n", __func__, dev->fmt_idx);

	/*ret = startup(sd);
	 * if (ret)
	 * dev_err(&client->dev, "ov2680 startup err\n");
	 */
err:
	mutex_unlock(&dev->input_lock);
	return ret;
}