static int __ov5693_try_mbus_fmt(struct v4l2_subdev *sd,
				 struct v4l2_mbus_framefmt *fmt)
{
	struct ov5693_device *dev = to_ov5693_sensor(sd);
	int idx;

	if (!fmt)
		return -EINVAL;

	idx = nearest_resolution_index(sd, fmt->width, fmt->height);
	fmt->width = dev->ov5693_res[idx].width;
	fmt->height = dev->ov5693_res[idx].height;
	fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;

	return 0;
}
static int hm5040_try_mbus_fmt(struct v4l2_subdev *sd,
                               struct v4l2_mbus_framefmt *fmt)
{
    int idx;

    if (!fmt)
        return -EINVAL;
    idx = nearest_resolution_index(fmt->width,
                                   fmt->height);

    if (idx == -1) {
        /* return the largest resolution */
        fmt->width = hm5040_res[0].width;
        fmt->height = hm5040_res[0].height;
    } else {
        fmt->width = hm5040_res[idx].width;
        fmt->height = hm5040_res[idx].height;
    }

    fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;

    return 0;
}
Esempio n. 3
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;
}