diff options
Diffstat (limited to 'drivers/media/platform/rcar-vin/rcar-v4l2.c')
-rw-r--r-- | drivers/media/platform/rcar-vin/rcar-v4l2.c | 299 |
1 files changed, 187 insertions, 112 deletions
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index 10a5c107e8b9..2bbe6d495fa6 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -92,21 +92,84 @@ static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix) * V4L2 */ +static void rvin_reset_crop_compose(struct rvin_dev *vin) +{ + vin->crop.top = vin->crop.left = 0; + vin->crop.width = vin->source.width; + vin->crop.height = vin->source.height; + + vin->compose.top = vin->compose.left = 0; + vin->compose.width = vin->format.width; + vin->compose.height = vin->format.height; +} + +static int rvin_reset_format(struct rvin_dev *vin) +{ + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + struct v4l2_mbus_framefmt *mf = &fmt.format; + int ret; + + fmt.pad = vin->src_pad_idx; + + ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, &fmt); + if (ret) + return ret; + + vin->format.width = mf->width; + vin->format.height = mf->height; + vin->format.colorspace = mf->colorspace; + vin->format.field = mf->field; + + /* + * If the subdevice uses ALTERNATE field mode and G_STD is + * implemented use the VIN HW to combine the two fields to + * one INTERLACED frame. The ALTERNATE field mode can still + * be requested in S_FMT and be respected, this is just the + * default which is applied at probing or when S_STD is called. + */ + if (vin->format.field == V4L2_FIELD_ALTERNATE && + v4l2_subdev_has_op(vin_to_source(vin), video, g_std)) + vin->format.field = V4L2_FIELD_INTERLACED; + + switch (vin->format.field) { + case V4L2_FIELD_TOP: + case V4L2_FIELD_BOTTOM: + case V4L2_FIELD_ALTERNATE: + vin->format.height /= 2; + break; + case V4L2_FIELD_NONE: + case V4L2_FIELD_INTERLACED_TB: + case V4L2_FIELD_INTERLACED_BT: + case V4L2_FIELD_INTERLACED: + break; + default: + vin->format.field = V4L2_FIELD_NONE; + break; + } + + rvin_reset_crop_compose(vin); + + return 0; +} + static int __rvin_try_format_source(struct rvin_dev *vin, - u32 which, - struct v4l2_pix_format *pix, - struct rvin_source_fmt *source) + u32 which, + struct v4l2_pix_format *pix, + struct rvin_source_fmt *source) { struct v4l2_subdev *sd; struct v4l2_subdev_pad_config *pad_cfg; struct v4l2_subdev_format format = { .which = which, }; + enum v4l2_field field; int ret; sd = vin_to_source(vin); - v4l2_fill_mbus_format(&format.format, pix, vin->source.code); + v4l2_fill_mbus_format(&format.format, pix, vin->digital.code); pad_cfg = v4l2_subdev_alloc_pad_config(sd); if (pad_cfg == NULL) @@ -114,28 +177,31 @@ static int __rvin_try_format_source(struct rvin_dev *vin, format.pad = vin->src_pad_idx; - ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, pad, set_fmt, - pad_cfg, &format); - if (ret < 0) - goto cleanup; + field = pix->field; + + ret = v4l2_subdev_call(sd, pad, set_fmt, pad_cfg, &format); + if (ret < 0 && ret != -ENOIOCTLCMD) + goto done; v4l2_fill_pix_format(pix, &format.format); + pix->field = field; + source->width = pix->width; source->height = pix->height; vin_dbg(vin, "Source resolution: %ux%u\n", source->width, source->height); -cleanup: +done: v4l2_subdev_free_pad_config(pad_cfg); - return 0; + return ret; } static int __rvin_try_format(struct rvin_dev *vin, - u32 which, - struct v4l2_pix_format *pix, - struct rvin_source_fmt *source) + u32 which, + struct v4l2_pix_format *pix, + struct rvin_source_fmt *source) { const struct rvin_video_format *info; u32 rwidth, rheight, walign; @@ -144,6 +210,10 @@ static int __rvin_try_format(struct rvin_dev *vin, rwidth = pix->width; rheight = pix->height; + /* Keep current field if no specific one is asked for */ + if (pix->field == V4L2_FIELD_ANY) + pix->field = vin->format.field; + /* * Retrieve format information and select the current format if the * requested format isn't supported. @@ -164,21 +234,14 @@ static int __rvin_try_format(struct rvin_dev *vin, /* Limit to source capabilities */ __rvin_try_format_source(vin, which, pix, source); - /* If source can't match format try if VIN can scale */ - if (source->width != rwidth || source->height != rheight) - rvin_scale_try(vin, pix, rwidth, rheight); - - /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */ - walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1; - - /* Limit to VIN capabilities */ - v4l_bound_align_image(&pix->width, 2, RVIN_MAX_WIDTH, walign, - &pix->height, 4, RVIN_MAX_HEIGHT, 2, 0); - switch (pix->field) { - case V4L2_FIELD_NONE: case V4L2_FIELD_TOP: case V4L2_FIELD_BOTTOM: + case V4L2_FIELD_ALTERNATE: + pix->height /= 2; + source->height /= 2; + break; + case V4L2_FIELD_NONE: case V4L2_FIELD_INTERLACED_TB: case V4L2_FIELD_INTERLACED_BT: case V4L2_FIELD_INTERLACED: @@ -188,11 +251,27 @@ static int __rvin_try_format(struct rvin_dev *vin, break; } + /* If source can't match format try if VIN can scale */ + if (source->width != rwidth || source->height != rheight) + rvin_scale_try(vin, pix, rwidth, rheight); + + /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */ + walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1; + + /* Limit to VIN capabilities */ + v4l_bound_align_image(&pix->width, 2, RVIN_MAX_WIDTH, walign, + &pix->height, 4, RVIN_MAX_HEIGHT, 2, 0); + pix->bytesperline = max_t(u32, pix->bytesperline, rvin_format_bytesperline(pix)); pix->sizeimage = max_t(u32, pix->sizeimage, rvin_format_sizeimage(pix)); + if (vin->chip == RCAR_M1 && pix->pixelformat == V4L2_PIX_FMT_XBGR32) { + vin_err(vin, "pixel format XBGR32 not supported on M1\n"); + return -EINVAL; + } + vin_dbg(vin, "Requested %ux%u Got %ux%u bpl: %d size: %d\n", rwidth, rheight, pix->width, pix->height, pix->bytesperline, pix->sizeimage); @@ -219,7 +298,7 @@ static int rvin_try_fmt_vid_cap(struct file *file, void *priv, struct rvin_source_fmt source; return __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, - &source); + &source); } static int rvin_s_fmt_vid_cap(struct file *file, void *priv, @@ -233,7 +312,7 @@ static int rvin_s_fmt_vid_cap(struct file *file, void *priv, return -EBUSY; ret = __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix, - &source); + &source); if (ret) return ret; @@ -242,6 +321,8 @@ static int rvin_s_fmt_vid_cap(struct file *file, void *priv, vin->format = f->fmt.pix; + rvin_reset_crop_compose(vin); + return 0; } @@ -334,8 +415,8 @@ static int rvin_s_selection(struct file *file, void *fh, vin->crop = s->r = r; vin_dbg(vin, "Cropped %dx%d@%d:%d of %dx%d\n", - r.width, r.height, r.left, r.top, - vin->source.width, vin->source.height); + r.width, r.height, r.left, r.top, + vin->source.width, vin->source.height); break; case V4L2_SEL_TGT_COMPOSE: /* Make sure compose rect fits inside output format */ @@ -359,8 +440,8 @@ static int rvin_s_selection(struct file *file, void *fh, vin->compose = s->r = r; vin_dbg(vin, "Compose %dx%d@%d:%d in %dx%d\n", - r.width, r.height, r.left, r.top, - vin->format.width, vin->format.height); + r.width, r.height, r.left, r.top, + vin->format.width, vin->format.height); break; default: return -EINVAL; @@ -381,7 +462,7 @@ static int rvin_cropcap(struct file *file, void *priv, if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; - return v4l2_subdev_call(sd, video, cropcap, crop); + return v4l2_subdev_call(sd, video, g_pixelaspect, &crop->pixelaspect); } static int rvin_enum_input(struct file *file, void *priv, @@ -433,35 +514,14 @@ static int rvin_querystd(struct file *file, void *priv, v4l2_std_id *a) static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a) { struct rvin_dev *vin = video_drvdata(file); - struct v4l2_subdev *sd = vin_to_source(vin); - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_mbus_framefmt *mf = &fmt.format; - int ret = v4l2_subdev_call(sd, video, s_std, a); + int ret; + ret = v4l2_subdev_call(vin_to_source(vin), video, s_std, a); if (ret < 0) return ret; /* Changing the standard will change the width/height */ - ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt); - if (ret) { - vin_err(vin, "Failed to get initial format\n"); - return ret; - } - - vin->format.width = mf->width; - vin->format.height = mf->height; - - vin->crop.top = vin->crop.left = 0; - vin->crop.width = mf->width; - vin->crop.height = mf->height; - - vin->compose.top = vin->compose.left = 0; - vin->compose.width = mf->width; - vin->compose.height = mf->height; - - return 0; + return rvin_reset_format(vin); } static int rvin_g_std(struct file *file, void *priv, v4l2_std_id *a) @@ -483,14 +543,14 @@ static int rvin_subscribe_event(struct v4l2_fh *fh, } static int rvin_enum_dv_timings(struct file *file, void *priv_fh, - struct v4l2_enum_dv_timings *timings) + struct v4l2_enum_dv_timings *timings) { struct rvin_dev *vin = video_drvdata(file); struct v4l2_subdev *sd = vin_to_source(vin); int pad, ret; pad = timings->pad; - timings->pad = vin->src_pad_idx; + timings->pad = vin->sink_pad_idx; ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings); @@ -500,52 +560,51 @@ static int rvin_enum_dv_timings(struct file *file, void *priv_fh, } static int rvin_s_dv_timings(struct file *file, void *priv_fh, - struct v4l2_dv_timings *timings) + struct v4l2_dv_timings *timings) { struct rvin_dev *vin = video_drvdata(file); struct v4l2_subdev *sd = vin_to_source(vin); - int err; - - err = v4l2_subdev_call(sd, - video, s_dv_timings, timings); - if (!err) { - vin->source.width = timings->bt.width; - vin->source.height = timings->bt.height; - vin->format.width = timings->bt.width; - vin->format.height = timings->bt.height; - } - return err; + int ret; + + ret = v4l2_subdev_call(sd, video, s_dv_timings, timings); + if (ret) + return ret; + + vin->source.width = timings->bt.width; + vin->source.height = timings->bt.height; + vin->format.width = timings->bt.width; + vin->format.height = timings->bt.height; + + return 0; } static int rvin_g_dv_timings(struct file *file, void *priv_fh, - struct v4l2_dv_timings *timings) + struct v4l2_dv_timings *timings) { struct rvin_dev *vin = video_drvdata(file); struct v4l2_subdev *sd = vin_to_source(vin); - return v4l2_subdev_call(sd, - video, g_dv_timings, timings); + return v4l2_subdev_call(sd, video, g_dv_timings, timings); } static int rvin_query_dv_timings(struct file *file, void *priv_fh, - struct v4l2_dv_timings *timings) + struct v4l2_dv_timings *timings) { struct rvin_dev *vin = video_drvdata(file); struct v4l2_subdev *sd = vin_to_source(vin); - return v4l2_subdev_call(sd, - video, query_dv_timings, timings); + return v4l2_subdev_call(sd, video, query_dv_timings, timings); } static int rvin_dv_timings_cap(struct file *file, void *priv_fh, - struct v4l2_dv_timings_cap *cap) + struct v4l2_dv_timings_cap *cap) { struct rvin_dev *vin = video_drvdata(file); struct v4l2_subdev *sd = vin_to_source(vin); int pad, ret; pad = cap->pad; - cap->pad = vin->src_pad_idx; + cap->pad = vin->sink_pad_idx; ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap); @@ -554,6 +613,44 @@ static int rvin_dv_timings_cap(struct file *file, void *priv_fh, return ret; } +static int rvin_g_edid(struct file *file, void *fh, struct v4l2_edid *edid) +{ + struct rvin_dev *vin = video_drvdata(file); + struct v4l2_subdev *sd = vin_to_source(vin); + int input, ret; + + if (edid->pad) + return -EINVAL; + + input = edid->pad; + edid->pad = vin->sink_pad_idx; + + ret = v4l2_subdev_call(sd, pad, get_edid, edid); + + edid->pad = input; + + return ret; +} + +static int rvin_s_edid(struct file *file, void *fh, struct v4l2_edid *edid) +{ + struct rvin_dev *vin = video_drvdata(file); + struct v4l2_subdev *sd = vin_to_source(vin); + int input, ret; + + if (edid->pad) + return -EINVAL; + + input = edid->pad; + edid->pad = vin->sink_pad_idx; + + ret = v4l2_subdev_call(sd, pad, set_edid, edid); + + edid->pad = input; + + return ret; +} + static const struct v4l2_ioctl_ops rvin_ioctl_ops = { .vidioc_querycap = rvin_querycap, .vidioc_try_fmt_vid_cap = rvin_try_fmt_vid_cap, @@ -576,6 +673,9 @@ static const struct v4l2_ioctl_ops rvin_ioctl_ops = { .vidioc_s_dv_timings = rvin_s_dv_timings, .vidioc_query_dv_timings = rvin_query_dv_timings, + .vidioc_g_edid = rvin_g_edid, + .vidioc_s_edid = rvin_s_edid, + .vidioc_querystd = rvin_querystd, .vidioc_g_std = rvin_g_std, .vidioc_s_std = rvin_s_std, @@ -767,16 +867,9 @@ static void rvin_notify(struct v4l2_subdev *sd, int rvin_v4l2_probe(struct rvin_dev *vin) { - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_mbus_framefmt *mf = &fmt.format; struct video_device *vdev = &vin->vdev; struct v4l2_subdev *sd = vin_to_source(vin); -#if defined(CONFIG_MEDIA_CONTROLLER) - int pad_idx; -#endif - int ret; + int pad_idx, ret; v4l2_set_subdev_hostdata(sd, vin); @@ -823,41 +916,23 @@ int rvin_v4l2_probe(struct rvin_dev *vin) V4L2_CAP_READWRITE; vin->src_pad_idx = 0; -#if defined(CONFIG_MEDIA_CONTROLLER) for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++) - if (sd->entity.pads[pad_idx].flags - == MEDIA_PAD_FL_SOURCE) + if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SOURCE) break; if (pad_idx >= sd->entity.num_pads) return -EINVAL; vin->src_pad_idx = pad_idx; -#endif - fmt.pad = vin->src_pad_idx; - /* Try to improve our guess of a reasonable window format */ - ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt); - if (ret) { - vin_err(vin, "Failed to get initial format\n"); - return ret; - } + vin->sink_pad_idx = 0; + for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++) + if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SINK) { + vin->sink_pad_idx = pad_idx; + break; + } - /* Set default format */ - vin->format.width = mf->width; - vin->format.height = mf->height; - vin->format.colorspace = mf->colorspace; - vin->format.field = mf->field; vin->format.pixelformat = RVIN_DEFAULT_FORMAT; - - - /* Set initial crop and compose */ - vin->crop.top = vin->crop.left = 0; - vin->crop.width = mf->width; - vin->crop.height = mf->height; - - vin->compose.top = vin->compose.left = 0; - vin->compose.width = mf->width; - vin->compose.height = mf->height; + rvin_reset_format(vin); ret = video_register_device(&vin->vdev, VFL_TYPE_GRABBER, -1); if (ret) { |