Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vsp1_video.c -- R-Car VSP1 Video Node |
| 3 | * |
Sei Fumizono | 139c928 | 2015-03-15 11:33:07 -0300 | [diff] [blame] | 4 | * Copyright (C) 2013-2015 Renesas Electronics Corporation |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 5 | * |
| 6 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/mutex.h> |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 17 | #include <linux/slab.h> |
| 18 | #include <linux/v4l2-mediabus.h> |
| 19 | #include <linux/videodev2.h> |
Laurent Pinchart | dba4a18 | 2015-08-02 14:15:23 -0300 | [diff] [blame] | 20 | #include <linux/wait.h> |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 21 | |
| 22 | #include <media/media-entity.h> |
| 23 | #include <media/v4l2-dev.h> |
| 24 | #include <media/v4l2-fh.h> |
| 25 | #include <media/v4l2-ioctl.h> |
| 26 | #include <media/v4l2-subdev.h> |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 27 | #include <media/videobuf2-v4l2.h> |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 28 | #include <media/videobuf2-dma-contig.h> |
| 29 | |
| 30 | #include "vsp1.h" |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 31 | #include "vsp1_bru.h" |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 32 | #include "vsp1_dl.h" |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 33 | #include "vsp1_entity.h" |
Laurent Pinchart | dba4a18 | 2015-08-02 14:15:23 -0300 | [diff] [blame] | 34 | #include "vsp1_pipe.h" |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 35 | #include "vsp1_rwpf.h" |
Laurent Pinchart | bdc2df6 | 2014-05-30 21:45:48 -0300 | [diff] [blame] | 36 | #include "vsp1_uds.h" |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 37 | #include "vsp1_video.h" |
| 38 | |
| 39 | #define VSP1_VIDEO_DEF_FORMAT V4L2_PIX_FMT_YUYV |
| 40 | #define VSP1_VIDEO_DEF_WIDTH 1024 |
| 41 | #define VSP1_VIDEO_DEF_HEIGHT 768 |
| 42 | |
| 43 | #define VSP1_VIDEO_MIN_WIDTH 2U |
| 44 | #define VSP1_VIDEO_MAX_WIDTH 8190U |
| 45 | #define VSP1_VIDEO_MIN_HEIGHT 2U |
| 46 | #define VSP1_VIDEO_MAX_HEIGHT 8190U |
| 47 | |
| 48 | /* ----------------------------------------------------------------------------- |
| 49 | * Helper functions |
| 50 | */ |
| 51 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 52 | static struct v4l2_subdev * |
| 53 | vsp1_video_remote_subdev(struct media_pad *local, u32 *pad) |
| 54 | { |
| 55 | struct media_pad *remote; |
| 56 | |
| 57 | remote = media_entity_remote_pad(local); |
Mauro Carvalho Chehab | 3efdf62 | 2015-05-07 22:12:32 -0300 | [diff] [blame] | 58 | if (!remote || !is_media_entity_v4l2_subdev(remote->entity)) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 59 | return NULL; |
| 60 | |
| 61 | if (pad) |
| 62 | *pad = remote->index; |
| 63 | |
| 64 | return media_entity_to_v4l2_subdev(remote->entity); |
| 65 | } |
| 66 | |
| 67 | static int vsp1_video_verify_format(struct vsp1_video *video) |
| 68 | { |
| 69 | struct v4l2_subdev_format fmt; |
| 70 | struct v4l2_subdev *subdev; |
| 71 | int ret; |
| 72 | |
| 73 | subdev = vsp1_video_remote_subdev(&video->pad, &fmt.pad); |
| 74 | if (subdev == NULL) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; |
| 78 | ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt); |
| 79 | if (ret < 0) |
| 80 | return ret == -ENOIOCTLCMD ? -EINVAL : ret; |
| 81 | |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 82 | if (video->rwpf->fmtinfo->mbus != fmt.format.code || |
| 83 | video->rwpf->format.height != fmt.format.height || |
| 84 | video->rwpf->format.width != fmt.format.width) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 85 | return -EINVAL; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static int __vsp1_video_try_format(struct vsp1_video *video, |
| 91 | struct v4l2_pix_format_mplane *pix, |
| 92 | const struct vsp1_format_info **fmtinfo) |
| 93 | { |
Laurent Pinchart | 56bfef3 | 2014-05-26 19:57:21 -0300 | [diff] [blame] | 94 | static const u32 xrgb_formats[][2] = { |
| 95 | { V4L2_PIX_FMT_RGB444, V4L2_PIX_FMT_XRGB444 }, |
| 96 | { V4L2_PIX_FMT_RGB555, V4L2_PIX_FMT_XRGB555 }, |
| 97 | { V4L2_PIX_FMT_BGR32, V4L2_PIX_FMT_XBGR32 }, |
| 98 | { V4L2_PIX_FMT_RGB32, V4L2_PIX_FMT_XRGB32 }, |
| 99 | }; |
| 100 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 101 | const struct vsp1_format_info *info; |
| 102 | unsigned int width = pix->width; |
| 103 | unsigned int height = pix->height; |
| 104 | unsigned int i; |
| 105 | |
Laurent Pinchart | 56bfef3 | 2014-05-26 19:57:21 -0300 | [diff] [blame] | 106 | /* Backward compatibility: replace deprecated RGB formats by their XRGB |
| 107 | * equivalent. This selects the format older userspace applications want |
| 108 | * while still exposing the new format. |
| 109 | */ |
| 110 | for (i = 0; i < ARRAY_SIZE(xrgb_formats); ++i) { |
| 111 | if (xrgb_formats[i][0] == pix->pixelformat) { |
| 112 | pix->pixelformat = xrgb_formats[i][1]; |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 117 | /* Retrieve format information and select the default format if the |
| 118 | * requested format isn't supported. |
| 119 | */ |
| 120 | info = vsp1_get_format_info(pix->pixelformat); |
| 121 | if (info == NULL) |
| 122 | info = vsp1_get_format_info(VSP1_VIDEO_DEF_FORMAT); |
| 123 | |
| 124 | pix->pixelformat = info->fourcc; |
| 125 | pix->colorspace = V4L2_COLORSPACE_SRGB; |
| 126 | pix->field = V4L2_FIELD_NONE; |
| 127 | memset(pix->reserved, 0, sizeof(pix->reserved)); |
| 128 | |
| 129 | /* Align the width and height for YUV 4:2:2 and 4:2:0 formats. */ |
| 130 | width = round_down(width, info->hsub); |
| 131 | height = round_down(height, info->vsub); |
| 132 | |
| 133 | /* Clamp the width and height. */ |
| 134 | pix->width = clamp(width, VSP1_VIDEO_MIN_WIDTH, VSP1_VIDEO_MAX_WIDTH); |
| 135 | pix->height = clamp(height, VSP1_VIDEO_MIN_HEIGHT, |
| 136 | VSP1_VIDEO_MAX_HEIGHT); |
| 137 | |
| 138 | /* Compute and clamp the stride and image size. While not documented in |
| 139 | * the datasheet, strides not aligned to a multiple of 128 bytes result |
| 140 | * in image corruption. |
| 141 | */ |
Laurent Pinchart | df5c3e7 | 2015-06-19 08:51:22 -0300 | [diff] [blame] | 142 | for (i = 0; i < min(info->planes, 2U); ++i) { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 143 | unsigned int hsub = i > 0 ? info->hsub : 1; |
| 144 | unsigned int vsub = i > 0 ? info->vsub : 1; |
| 145 | unsigned int align = 128; |
| 146 | unsigned int bpl; |
| 147 | |
| 148 | bpl = clamp_t(unsigned int, pix->plane_fmt[i].bytesperline, |
| 149 | pix->width / hsub * info->bpp[i] / 8, |
| 150 | round_down(65535U, align)); |
| 151 | |
| 152 | pix->plane_fmt[i].bytesperline = round_up(bpl, align); |
| 153 | pix->plane_fmt[i].sizeimage = pix->plane_fmt[i].bytesperline |
| 154 | * pix->height / vsub; |
| 155 | } |
| 156 | |
| 157 | if (info->planes == 3) { |
| 158 | /* The second and third planes must have the same stride. */ |
| 159 | pix->plane_fmt[2].bytesperline = pix->plane_fmt[1].bytesperline; |
| 160 | pix->plane_fmt[2].sizeimage = pix->plane_fmt[1].sizeimage; |
| 161 | } |
| 162 | |
| 163 | pix->num_planes = info->planes; |
| 164 | |
| 165 | if (fmtinfo) |
| 166 | *fmtinfo = info; |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 171 | /* ----------------------------------------------------------------------------- |
| 172 | * Pipeline Management |
| 173 | */ |
| 174 | |
Laurent Pinchart | 76c2975 | 2016-01-17 19:55:18 -0200 | [diff] [blame] | 175 | /* |
| 176 | * vsp1_video_complete_buffer - Complete the current buffer |
| 177 | * @video: the video node |
| 178 | * |
| 179 | * This function completes the current buffer by filling its sequence number, |
| 180 | * time stamp and payload size, and hands it back to the videobuf core. |
| 181 | * |
| 182 | * When operating in DU output mode (deep pipeline to the DU through the LIF), |
| 183 | * the VSP1 needs to constantly supply frames to the display. In that case, if |
| 184 | * no other buffer is queued, reuse the one that has just been processed instead |
| 185 | * of handing it back to the videobuf core. |
| 186 | * |
| 187 | * Return the next queued buffer or NULL if the queue is empty. |
| 188 | */ |
| 189 | static struct vsp1_vb2_buffer * |
| 190 | vsp1_video_complete_buffer(struct vsp1_video *video) |
| 191 | { |
| 192 | struct vsp1_pipeline *pipe = video->rwpf->pipe; |
| 193 | struct vsp1_vb2_buffer *next = NULL; |
| 194 | struct vsp1_vb2_buffer *done; |
| 195 | unsigned long flags; |
| 196 | unsigned int i; |
| 197 | |
| 198 | spin_lock_irqsave(&video->irqlock, flags); |
| 199 | |
| 200 | if (list_empty(&video->irqqueue)) { |
| 201 | spin_unlock_irqrestore(&video->irqlock, flags); |
| 202 | return NULL; |
| 203 | } |
| 204 | |
| 205 | done = list_first_entry(&video->irqqueue, |
| 206 | struct vsp1_vb2_buffer, queue); |
| 207 | |
| 208 | /* In DU output mode reuse the buffer if the list is singular. */ |
| 209 | if (pipe->lif && list_is_singular(&video->irqqueue)) { |
| 210 | spin_unlock_irqrestore(&video->irqlock, flags); |
| 211 | return done; |
| 212 | } |
| 213 | |
| 214 | list_del(&done->queue); |
| 215 | |
| 216 | if (!list_empty(&video->irqqueue)) |
| 217 | next = list_first_entry(&video->irqqueue, |
| 218 | struct vsp1_vb2_buffer, queue); |
| 219 | |
| 220 | spin_unlock_irqrestore(&video->irqlock, flags); |
| 221 | |
Laurent Pinchart | 0c1a41b | 2016-04-10 02:59:04 -0300 | [diff] [blame] | 222 | done->buf.sequence = pipe->sequence; |
Laurent Pinchart | 76c2975 | 2016-01-17 19:55:18 -0200 | [diff] [blame] | 223 | done->buf.vb2_buf.timestamp = ktime_get_ns(); |
| 224 | for (i = 0; i < done->buf.vb2_buf.num_planes; ++i) |
| 225 | vb2_set_plane_payload(&done->buf.vb2_buf, i, |
| 226 | vb2_plane_size(&done->buf.vb2_buf, i)); |
| 227 | vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE); |
| 228 | |
| 229 | return next; |
| 230 | } |
| 231 | |
| 232 | static void vsp1_video_frame_end(struct vsp1_pipeline *pipe, |
| 233 | struct vsp1_rwpf *rwpf) |
| 234 | { |
| 235 | struct vsp1_video *video = rwpf->video; |
| 236 | struct vsp1_vb2_buffer *buf; |
| 237 | unsigned long flags; |
| 238 | |
| 239 | buf = vsp1_video_complete_buffer(video); |
| 240 | if (buf == NULL) |
| 241 | return; |
| 242 | |
| 243 | spin_lock_irqsave(&pipe->irqlock, flags); |
| 244 | |
| 245 | video->rwpf->mem = buf->mem; |
| 246 | pipe->buffers_ready |= 1 << video->pipe_index; |
| 247 | |
| 248 | spin_unlock_irqrestore(&pipe->irqlock, flags); |
| 249 | } |
| 250 | |
| 251 | static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe) |
| 252 | { |
| 253 | struct vsp1_device *vsp1 = pipe->output->entity.vsp1; |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 254 | struct vsp1_entity *entity; |
Laurent Pinchart | 76c2975 | 2016-01-17 19:55:18 -0200 | [diff] [blame] | 255 | unsigned int i; |
| 256 | |
| 257 | if (!pipe->dl) |
| 258 | pipe->dl = vsp1_dl_list_get(pipe->output->dlm); |
| 259 | |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 260 | list_for_each_entry(entity, &pipe->entities, list_pipe) { |
| 261 | if (entity->ops->configure) |
| 262 | entity->ops->configure(entity, pipe, pipe->dl, false); |
| 263 | } |
| 264 | |
Laurent Pinchart | 76c2975 | 2016-01-17 19:55:18 -0200 | [diff] [blame] | 265 | for (i = 0; i < vsp1->info->rpf_count; ++i) { |
| 266 | struct vsp1_rwpf *rwpf = pipe->inputs[i]; |
| 267 | |
| 268 | if (rwpf) |
| 269 | vsp1_rwpf_set_memory(rwpf, pipe->dl); |
| 270 | } |
| 271 | |
| 272 | if (!pipe->lif) |
| 273 | vsp1_rwpf_set_memory(pipe->output, pipe->dl); |
| 274 | |
| 275 | vsp1_dl_list_commit(pipe->dl); |
| 276 | pipe->dl = NULL; |
| 277 | |
| 278 | vsp1_pipeline_run(pipe); |
| 279 | } |
| 280 | |
| 281 | static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe) |
| 282 | { |
| 283 | struct vsp1_device *vsp1 = pipe->output->entity.vsp1; |
| 284 | enum vsp1_pipeline_state state; |
| 285 | unsigned long flags; |
| 286 | unsigned int i; |
| 287 | |
| 288 | /* Complete buffers on all video nodes. */ |
| 289 | for (i = 0; i < vsp1->info->rpf_count; ++i) { |
| 290 | if (!pipe->inputs[i]) |
| 291 | continue; |
| 292 | |
| 293 | vsp1_video_frame_end(pipe, pipe->inputs[i]); |
| 294 | } |
| 295 | |
| 296 | vsp1_video_frame_end(pipe, pipe->output); |
| 297 | |
| 298 | spin_lock_irqsave(&pipe->irqlock, flags); |
| 299 | |
| 300 | state = pipe->state; |
| 301 | pipe->state = VSP1_PIPELINE_STOPPED; |
| 302 | |
| 303 | /* If a stop has been requested, mark the pipeline as stopped and |
| 304 | * return. Otherwise restart the pipeline if ready. |
| 305 | */ |
| 306 | if (state == VSP1_PIPELINE_STOPPING) |
| 307 | wake_up(&pipe->wq); |
| 308 | else if (vsp1_pipeline_ready(pipe)) |
| 309 | vsp1_video_pipeline_run(pipe); |
| 310 | |
| 311 | spin_unlock_irqrestore(&pipe->irqlock, flags); |
| 312 | } |
| 313 | |
Laurent Pinchart | d221982 | 2016-01-19 19:42:56 -0200 | [diff] [blame] | 314 | static int vsp1_video_pipeline_build_branch(struct vsp1_pipeline *pipe, |
| 315 | struct vsp1_rwpf *input, |
| 316 | struct vsp1_rwpf *output) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 317 | { |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 318 | struct media_entity_enum ent_enum; |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 319 | struct vsp1_entity *entity; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 320 | struct media_pad *pad; |
Laurent Pinchart | bdc2df6 | 2014-05-30 21:45:48 -0300 | [diff] [blame] | 321 | bool bru_found = false; |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 322 | int ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 323 | |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 324 | ret = media_entity_enum_init(&ent_enum, &input->entity.vsp1->media_dev); |
| 325 | if (ret < 0) |
| 326 | return ret; |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 327 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 328 | pad = media_entity_remote_pad(&input->entity.pads[RWPF_PAD_SOURCE]); |
| 329 | |
| 330 | while (1) { |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 331 | if (pad == NULL) { |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 332 | ret = -EPIPE; |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 333 | goto out; |
| 334 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 335 | |
| 336 | /* We've reached a video node, that shouldn't have happened. */ |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 337 | if (!is_media_entity_v4l2_subdev(pad->entity)) { |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 338 | ret = -EPIPE; |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 339 | goto out; |
| 340 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 341 | |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 342 | entity = to_vsp1_entity( |
| 343 | media_entity_to_v4l2_subdev(pad->entity)); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 344 | |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 345 | /* A BRU is present in the pipeline, store the BRU input pad |
| 346 | * number in the input RPF for use when configuring the RPF. |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 347 | */ |
| 348 | if (entity->type == VSP1_ENTITY_BRU) { |
| 349 | struct vsp1_bru *bru = to_bru(&entity->subdev); |
Laurent Pinchart | 6418b4d | 2014-05-27 20:35:36 -0300 | [diff] [blame] | 350 | |
| 351 | bru->inputs[pad->index].rpf = input; |
Laurent Pinchart | b7e5107 | 2015-11-15 19:14:22 -0200 | [diff] [blame] | 352 | input->bru_input = pad->index; |
Laurent Pinchart | bdc2df6 | 2014-05-30 21:45:48 -0300 | [diff] [blame] | 353 | |
| 354 | bru_found = true; |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 355 | } |
| 356 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 357 | /* We've reached the WPF, we're done. */ |
| 358 | if (entity->type == VSP1_ENTITY_WPF) |
| 359 | break; |
| 360 | |
| 361 | /* Ensure the branch has no loop. */ |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 362 | if (media_entity_enum_test_and_set(&ent_enum, |
| 363 | &entity->subdev.entity)) { |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 364 | ret = -EPIPE; |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 365 | goto out; |
| 366 | } |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 367 | |
| 368 | /* UDS can't be chained. */ |
| 369 | if (entity->type == VSP1_ENTITY_UDS) { |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 370 | if (pipe->uds) { |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 371 | ret = -EPIPE; |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 372 | goto out; |
| 373 | } |
Laurent Pinchart | bdc2df6 | 2014-05-30 21:45:48 -0300 | [diff] [blame] | 374 | |
| 375 | pipe->uds = entity; |
| 376 | pipe->uds_input = bru_found ? pipe->bru |
| 377 | : &input->entity; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /* Follow the source link. The link setup operations ensure |
| 381 | * that the output fan-out can't be more than one, there is thus |
| 382 | * no need to verify here that only a single source link is |
| 383 | * activated. |
| 384 | */ |
| 385 | pad = &entity->pads[entity->source_pad]; |
| 386 | pad = media_entity_remote_pad(pad); |
| 387 | } |
| 388 | |
| 389 | /* The last entity must be the output WPF. */ |
| 390 | if (entity != &output->entity) |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 391 | ret = -EPIPE; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 392 | |
Sakari Ailus | 54b5a74 | 2015-12-16 11:32:31 -0200 | [diff] [blame] | 393 | out: |
| 394 | media_entity_enum_cleanup(&ent_enum); |
| 395 | |
Laurent Pinchart | 6b1446b | 2016-02-28 23:28:38 -0300 | [diff] [blame] | 396 | return ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 397 | } |
| 398 | |
Laurent Pinchart | d221982 | 2016-01-19 19:42:56 -0200 | [diff] [blame] | 399 | static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe, |
| 400 | struct vsp1_video *video) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 401 | { |
| 402 | struct media_entity_graph graph; |
| 403 | struct media_entity *entity = &video->video.entity; |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 404 | struct media_device *mdev = entity->graph_obj.mdev; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 405 | unsigned int i; |
| 406 | int ret; |
| 407 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 408 | /* Walk the graph to locate the entities and video nodes. */ |
Sakari Ailus | c1a5f1b | 2015-12-16 15:32:27 +0200 | [diff] [blame] | 409 | ret = media_entity_graph_walk_init(&graph, mdev); |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 410 | if (ret) |
Sakari Ailus | c1a5f1b | 2015-12-16 15:32:27 +0200 | [diff] [blame] | 411 | return ret; |
Sakari Ailus | c1a5f1b | 2015-12-16 15:32:27 +0200 | [diff] [blame] | 412 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 413 | media_entity_graph_walk_start(&graph, entity); |
| 414 | |
| 415 | while ((entity = media_entity_graph_walk_next(&graph))) { |
| 416 | struct v4l2_subdev *subdev; |
| 417 | struct vsp1_rwpf *rwpf; |
| 418 | struct vsp1_entity *e; |
| 419 | |
Laurent Pinchart | 02650eb | 2016-03-01 06:27:10 -0300 | [diff] [blame] | 420 | if (!is_media_entity_v4l2_subdev(entity)) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 421 | continue; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 422 | |
| 423 | subdev = media_entity_to_v4l2_subdev(entity); |
| 424 | e = to_vsp1_entity(subdev); |
| 425 | list_add_tail(&e->list_pipe, &pipe->entities); |
| 426 | |
| 427 | if (e->type == VSP1_ENTITY_RPF) { |
| 428 | rwpf = to_rwpf(subdev); |
Laurent Pinchart | 96bfa6a | 2015-08-05 16:40:31 -0300 | [diff] [blame] | 429 | pipe->inputs[rwpf->entity.index] = rwpf; |
| 430 | rwpf->video->pipe_index = ++pipe->num_inputs; |
Laurent Pinchart | ff7e97c | 2016-01-19 19:16:36 -0200 | [diff] [blame] | 431 | rwpf->pipe = pipe; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 432 | } else if (e->type == VSP1_ENTITY_WPF) { |
| 433 | rwpf = to_rwpf(subdev); |
Laurent Pinchart | f8562f2 | 2015-08-02 17:43:36 -0300 | [diff] [blame] | 434 | pipe->output = rwpf; |
Laurent Pinchart | faf2644 | 2015-08-02 14:58:43 -0300 | [diff] [blame] | 435 | rwpf->video->pipe_index = 0; |
Laurent Pinchart | ff7e97c | 2016-01-19 19:16:36 -0200 | [diff] [blame] | 436 | rwpf->pipe = pipe; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 437 | } else if (e->type == VSP1_ENTITY_LIF) { |
| 438 | pipe->lif = e; |
Laurent Pinchart | 629bb6d | 2013-07-10 18:03:46 -0300 | [diff] [blame] | 439 | } else if (e->type == VSP1_ENTITY_BRU) { |
| 440 | pipe->bru = e; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Sakari Ailus | c1a5f1b | 2015-12-16 15:32:27 +0200 | [diff] [blame] | 444 | media_entity_graph_walk_cleanup(&graph); |
| 445 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 446 | /* We need one output and at least one input. */ |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 447 | if (pipe->num_inputs == 0 || !pipe->output) |
| 448 | return -EPIPE; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 449 | |
| 450 | /* Follow links downstream for each input and make sure the graph |
| 451 | * contains no loop and that all branches end at the output WPF. |
| 452 | */ |
Laurent Pinchart | 5aa2eb3 | 2015-12-05 20:17:10 -0200 | [diff] [blame] | 453 | for (i = 0; i < video->vsp1->info->rpf_count; ++i) { |
Laurent Pinchart | 96bfa6a | 2015-08-05 16:40:31 -0300 | [diff] [blame] | 454 | if (!pipe->inputs[i]) |
| 455 | continue; |
| 456 | |
Laurent Pinchart | d221982 | 2016-01-19 19:42:56 -0200 | [diff] [blame] | 457 | ret = vsp1_video_pipeline_build_branch(pipe, pipe->inputs[i], |
| 458 | pipe->output); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 459 | if (ret < 0) |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 460 | return ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 464 | } |
| 465 | |
Laurent Pinchart | 945f127 | 2015-08-02 17:29:03 -0300 | [diff] [blame] | 466 | static int vsp1_video_pipeline_init(struct vsp1_pipeline *pipe, |
| 467 | struct vsp1_video *video) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 468 | { |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 469 | vsp1_pipeline_init(pipe); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 470 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 471 | pipe->frame_end = vsp1_video_pipeline_frame_end; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 472 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 473 | return vsp1_video_pipeline_build(pipe, video); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 474 | } |
| 475 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 476 | static struct vsp1_pipeline *vsp1_video_pipeline_get(struct vsp1_video *video) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 477 | { |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 478 | struct vsp1_pipeline *pipe; |
| 479 | int ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 480 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 481 | /* Get a pipeline object for the video node. If a pipeline has already |
| 482 | * been allocated just increment its reference count and return it. |
| 483 | * Otherwise allocate a new pipeline and initialize it, it will be freed |
| 484 | * when the last reference is released. |
| 485 | */ |
| 486 | if (!video->rwpf->pipe) { |
| 487 | pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); |
| 488 | if (!pipe) |
| 489 | return ERR_PTR(-ENOMEM); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 490 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 491 | ret = vsp1_video_pipeline_init(pipe, video); |
| 492 | if (ret < 0) { |
| 493 | vsp1_pipeline_reset(pipe); |
| 494 | kfree(pipe); |
| 495 | return ERR_PTR(ret); |
| 496 | } |
| 497 | } else { |
| 498 | pipe = video->rwpf->pipe; |
| 499 | kref_get(&pipe->kref); |
| 500 | } |
| 501 | |
| 502 | return pipe; |
| 503 | } |
| 504 | |
| 505 | static void vsp1_video_pipeline_release(struct kref *kref) |
| 506 | { |
| 507 | struct vsp1_pipeline *pipe = container_of(kref, typeof(*pipe), kref); |
| 508 | |
| 509 | vsp1_pipeline_reset(pipe); |
| 510 | kfree(pipe); |
| 511 | } |
| 512 | |
| 513 | static void vsp1_video_pipeline_put(struct vsp1_pipeline *pipe) |
| 514 | { |
| 515 | struct media_device *mdev = &pipe->output->entity.vsp1->media_dev; |
| 516 | |
| 517 | mutex_lock(&mdev->graph_mutex); |
| 518 | kref_put(&pipe->kref, vsp1_video_pipeline_release); |
| 519 | mutex_unlock(&mdev->graph_mutex); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 520 | } |
| 521 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 522 | /* ----------------------------------------------------------------------------- |
| 523 | * videobuf2 Queue Operations |
| 524 | */ |
| 525 | |
| 526 | static int |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 527 | vsp1_video_queue_setup(struct vb2_queue *vq, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 528 | unsigned int *nbuffers, unsigned int *nplanes, |
| 529 | unsigned int sizes[], struct device *alloc_devs[]) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 530 | { |
| 531 | struct vsp1_video *video = vb2_get_drv_priv(vq); |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 532 | const struct v4l2_pix_format_mplane *format = &video->rwpf->format; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 533 | unsigned int i; |
| 534 | |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 535 | if (*nplanes) { |
| 536 | if (*nplanes != format->num_planes) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 537 | return -EINVAL; |
| 538 | |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 539 | for (i = 0; i < *nplanes; i++) |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 540 | if (sizes[i] < format->plane_fmt[i].sizeimage) |
| 541 | return -EINVAL; |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 542 | return 0; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | *nplanes = format->num_planes; |
| 546 | |
Hans Verkuil | dce5731 | 2016-02-15 13:24:11 -0200 | [diff] [blame] | 547 | for (i = 0; i < format->num_planes; ++i) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 548 | sizes[i] = format->plane_fmt[i].sizeimage; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | static int vsp1_video_buffer_prepare(struct vb2_buffer *vb) |
| 554 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 555 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 556 | struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue); |
Laurent Pinchart | f7ebf3c | 2015-07-28 14:17:07 -0300 | [diff] [blame] | 557 | struct vsp1_vb2_buffer *buf = to_vsp1_vb2_buffer(vbuf); |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 558 | const struct v4l2_pix_format_mplane *format = &video->rwpf->format; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 559 | unsigned int i; |
| 560 | |
| 561 | if (vb->num_planes < format->num_planes) |
| 562 | return -EINVAL; |
| 563 | |
Laurent Pinchart | b58faa9 | 2015-07-28 16:04:47 -0300 | [diff] [blame] | 564 | for (i = 0; i < vb->num_planes; ++i) { |
| 565 | buf->mem.addr[i] = vb2_dma_contig_plane_dma_addr(vb, i); |
Laurent Pinchart | b58faa9 | 2015-07-28 16:04:47 -0300 | [diff] [blame] | 566 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 567 | if (vb2_plane_size(vb, i) < format->plane_fmt[i].sizeimage) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 568 | return -EINVAL; |
| 569 | } |
| 570 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 571 | for ( ; i < 3; ++i) |
Laurent Pinchart | 4d346be5 | 2015-11-01 13:48:11 -0200 | [diff] [blame] | 572 | buf->mem.addr[i] = 0; |
Laurent Pinchart | 4d346be5 | 2015-11-01 13:48:11 -0200 | [diff] [blame] | 573 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static void vsp1_video_buffer_queue(struct vb2_buffer *vb) |
| 578 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 579 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 580 | struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue); |
Laurent Pinchart | ff7e97c | 2016-01-19 19:16:36 -0200 | [diff] [blame] | 581 | struct vsp1_pipeline *pipe = video->rwpf->pipe; |
Laurent Pinchart | f7ebf3c | 2015-07-28 14:17:07 -0300 | [diff] [blame] | 582 | struct vsp1_vb2_buffer *buf = to_vsp1_vb2_buffer(vbuf); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 583 | unsigned long flags; |
| 584 | bool empty; |
| 585 | |
| 586 | spin_lock_irqsave(&video->irqlock, flags); |
| 587 | empty = list_empty(&video->irqqueue); |
| 588 | list_add_tail(&buf->queue, &video->irqqueue); |
| 589 | spin_unlock_irqrestore(&video->irqlock, flags); |
| 590 | |
| 591 | if (!empty) |
| 592 | return; |
| 593 | |
| 594 | spin_lock_irqsave(&pipe->irqlock, flags); |
| 595 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 596 | video->rwpf->mem = buf->mem; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 597 | pipe->buffers_ready |= 1 << video->pipe_index; |
| 598 | |
| 599 | if (vb2_is_streaming(&video->queue) && |
| 600 | vsp1_pipeline_ready(pipe)) |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 601 | vsp1_video_pipeline_run(pipe); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 602 | |
| 603 | spin_unlock_irqrestore(&pipe->irqlock, flags); |
| 604 | } |
| 605 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 606 | static int vsp1_video_setup_pipeline(struct vsp1_pipeline *pipe) |
| 607 | { |
| 608 | struct vsp1_entity *entity; |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 609 | |
| 610 | /* Prepare the display list. */ |
| 611 | pipe->dl = vsp1_dl_list_get(pipe->output->dlm); |
| 612 | if (!pipe->dl) |
| 613 | return -ENOMEM; |
| 614 | |
| 615 | if (pipe->uds) { |
| 616 | struct vsp1_uds *uds = to_uds(&pipe->uds->subdev); |
| 617 | |
| 618 | /* If a BRU is present in the pipeline before the UDS, the alpha |
| 619 | * component doesn't need to be scaled as the BRU output alpha |
| 620 | * value is fixed to 255. Otherwise we need to scale the alpha |
| 621 | * component only when available at the input RPF. |
| 622 | */ |
| 623 | if (pipe->uds_input->type == VSP1_ENTITY_BRU) { |
| 624 | uds->scale_alpha = false; |
| 625 | } else { |
| 626 | struct vsp1_rwpf *rpf = |
| 627 | to_rwpf(&pipe->uds_input->subdev); |
| 628 | |
| 629 | uds->scale_alpha = rpf->fmtinfo->alpha; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | list_for_each_entry(entity, &pipe->entities, list_pipe) { |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 634 | vsp1_entity_route_setup(entity, pipe->dl); |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 635 | |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 636 | if (entity->ops->configure) |
Laurent Pinchart | fc845e5 | 2016-06-11 04:07:56 -0300 | [diff] [blame] | 637 | entity->ops->configure(entity, pipe, pipe->dl, true); |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | return 0; |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 641 | } |
| 642 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 643 | static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 644 | { |
| 645 | struct vsp1_video *video = vb2_get_drv_priv(vq); |
Laurent Pinchart | ff7e97c | 2016-01-19 19:16:36 -0200 | [diff] [blame] | 646 | struct vsp1_pipeline *pipe = video->rwpf->pipe; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 647 | unsigned long flags; |
| 648 | int ret; |
| 649 | |
| 650 | mutex_lock(&pipe->lock); |
Laurent Pinchart | 2f2db2f | 2015-08-02 17:17:15 -0300 | [diff] [blame] | 651 | if (pipe->stream_count == pipe->num_inputs) { |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 652 | ret = vsp1_video_setup_pipeline(pipe); |
| 653 | if (ret < 0) { |
| 654 | mutex_unlock(&pipe->lock); |
| 655 | return ret; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
| 659 | pipe->stream_count++; |
| 660 | mutex_unlock(&pipe->lock); |
| 661 | |
| 662 | spin_lock_irqsave(&pipe->irqlock, flags); |
| 663 | if (vsp1_pipeline_ready(pipe)) |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 664 | vsp1_video_pipeline_run(pipe); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 665 | spin_unlock_irqrestore(&pipe->irqlock, flags); |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 670 | static void vsp1_video_stop_streaming(struct vb2_queue *vq) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 671 | { |
| 672 | struct vsp1_video *video = vb2_get_drv_priv(vq); |
Laurent Pinchart | ff7e97c | 2016-01-19 19:16:36 -0200 | [diff] [blame] | 673 | struct vsp1_pipeline *pipe = video->rwpf->pipe; |
Laurent Pinchart | f7ebf3c | 2015-07-28 14:17:07 -0300 | [diff] [blame] | 674 | struct vsp1_vb2_buffer *buffer; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 675 | unsigned long flags; |
| 676 | int ret; |
| 677 | |
| 678 | mutex_lock(&pipe->lock); |
Laurent Pinchart | b4dfb9b | 2016-06-17 21:03:29 -0300 | [diff] [blame] | 679 | if (--pipe->stream_count == pipe->num_inputs) { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 680 | /* Stop the pipeline. */ |
| 681 | ret = vsp1_pipeline_stop(pipe); |
| 682 | if (ret == -ETIMEDOUT) |
| 683 | dev_err(video->vsp1->dev, "pipeline stop timeout\n"); |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 684 | |
| 685 | vsp1_dl_list_put(pipe->dl); |
| 686 | pipe->dl = NULL; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 687 | } |
| 688 | mutex_unlock(&pipe->lock); |
| 689 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 690 | media_entity_pipeline_stop(&video->video.entity); |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 691 | vsp1_video_pipeline_put(pipe); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 692 | |
| 693 | /* Remove all buffers from the IRQ queue. */ |
| 694 | spin_lock_irqsave(&video->irqlock, flags); |
Laurent Pinchart | 9df04e9 | 2014-06-23 16:57:22 -0300 | [diff] [blame] | 695 | list_for_each_entry(buffer, &video->irqqueue, queue) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 696 | vb2_buffer_done(&buffer->buf.vb2_buf, VB2_BUF_STATE_ERROR); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 697 | INIT_LIST_HEAD(&video->irqqueue); |
| 698 | spin_unlock_irqrestore(&video->irqlock, flags); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 699 | } |
| 700 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 701 | static const struct vb2_ops vsp1_video_queue_qops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 702 | .queue_setup = vsp1_video_queue_setup, |
| 703 | .buf_prepare = vsp1_video_buffer_prepare, |
| 704 | .buf_queue = vsp1_video_buffer_queue, |
| 705 | .wait_prepare = vb2_ops_wait_prepare, |
| 706 | .wait_finish = vb2_ops_wait_finish, |
| 707 | .start_streaming = vsp1_video_start_streaming, |
| 708 | .stop_streaming = vsp1_video_stop_streaming, |
| 709 | }; |
| 710 | |
| 711 | /* ----------------------------------------------------------------------------- |
| 712 | * V4L2 ioctls |
| 713 | */ |
| 714 | |
| 715 | static int |
| 716 | vsp1_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap) |
| 717 | { |
| 718 | struct v4l2_fh *vfh = file->private_data; |
| 719 | struct vsp1_video *video = to_vsp1_video(vfh->vdev); |
| 720 | |
| 721 | cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING |
| 722 | | V4L2_CAP_VIDEO_CAPTURE_MPLANE |
| 723 | | V4L2_CAP_VIDEO_OUTPUT_MPLANE; |
| 724 | |
| 725 | if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 726 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE |
| 727 | | V4L2_CAP_STREAMING; |
| 728 | else |
| 729 | cap->device_caps = V4L2_CAP_VIDEO_OUTPUT_MPLANE |
| 730 | | V4L2_CAP_STREAMING; |
| 731 | |
| 732 | strlcpy(cap->driver, "vsp1", sizeof(cap->driver)); |
| 733 | strlcpy(cap->card, video->video.name, sizeof(cap->card)); |
| 734 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
| 735 | dev_name(video->vsp1->dev)); |
| 736 | |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | static int |
| 741 | vsp1_video_get_format(struct file *file, void *fh, struct v4l2_format *format) |
| 742 | { |
| 743 | struct v4l2_fh *vfh = file->private_data; |
| 744 | struct vsp1_video *video = to_vsp1_video(vfh->vdev); |
| 745 | |
| 746 | if (format->type != video->queue.type) |
| 747 | return -EINVAL; |
| 748 | |
| 749 | mutex_lock(&video->lock); |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 750 | format->fmt.pix_mp = video->rwpf->format; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 751 | mutex_unlock(&video->lock); |
| 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | static int |
| 757 | vsp1_video_try_format(struct file *file, void *fh, struct v4l2_format *format) |
| 758 | { |
| 759 | struct v4l2_fh *vfh = file->private_data; |
| 760 | struct vsp1_video *video = to_vsp1_video(vfh->vdev); |
| 761 | |
| 762 | if (format->type != video->queue.type) |
| 763 | return -EINVAL; |
| 764 | |
| 765 | return __vsp1_video_try_format(video, &format->fmt.pix_mp, NULL); |
| 766 | } |
| 767 | |
| 768 | static int |
| 769 | vsp1_video_set_format(struct file *file, void *fh, struct v4l2_format *format) |
| 770 | { |
| 771 | struct v4l2_fh *vfh = file->private_data; |
| 772 | struct vsp1_video *video = to_vsp1_video(vfh->vdev); |
| 773 | const struct vsp1_format_info *info; |
| 774 | int ret; |
| 775 | |
| 776 | if (format->type != video->queue.type) |
| 777 | return -EINVAL; |
| 778 | |
| 779 | ret = __vsp1_video_try_format(video, &format->fmt.pix_mp, &info); |
| 780 | if (ret < 0) |
| 781 | return ret; |
| 782 | |
| 783 | mutex_lock(&video->lock); |
| 784 | |
| 785 | if (vb2_is_busy(&video->queue)) { |
| 786 | ret = -EBUSY; |
| 787 | goto done; |
| 788 | } |
| 789 | |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 790 | video->rwpf->format = format->fmt.pix_mp; |
| 791 | video->rwpf->fmtinfo = info; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 792 | |
| 793 | done: |
| 794 | mutex_unlock(&video->lock); |
| 795 | return ret; |
| 796 | } |
| 797 | |
| 798 | static int |
| 799 | vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) |
| 800 | { |
| 801 | struct v4l2_fh *vfh = file->private_data; |
| 802 | struct vsp1_video *video = to_vsp1_video(vfh->vdev); |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 803 | struct media_device *mdev = &video->vsp1->media_dev; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 804 | struct vsp1_pipeline *pipe; |
| 805 | int ret; |
| 806 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 807 | if (video->queue.owner && video->queue.owner != file->private_data) |
| 808 | return -EBUSY; |
| 809 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 810 | /* Get a pipeline for the video node and start streaming on it. No link |
| 811 | * touching an entity in the pipeline can be activated or deactivated |
| 812 | * once streaming is started. |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 813 | */ |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 814 | mutex_lock(&mdev->graph_mutex); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 815 | |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 816 | pipe = vsp1_video_pipeline_get(video); |
| 817 | if (IS_ERR(pipe)) { |
| 818 | mutex_unlock(&mdev->graph_mutex); |
| 819 | return PTR_ERR(pipe); |
| 820 | } |
| 821 | |
| 822 | ret = __media_entity_pipeline_start(&video->video.entity, &pipe->pipe); |
| 823 | if (ret < 0) { |
| 824 | mutex_unlock(&mdev->graph_mutex); |
| 825 | goto err_pipe; |
| 826 | } |
| 827 | |
| 828 | mutex_unlock(&mdev->graph_mutex); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 829 | |
| 830 | /* Verify that the configured format matches the output of the connected |
| 831 | * subdev. |
| 832 | */ |
| 833 | ret = vsp1_video_verify_format(video); |
| 834 | if (ret < 0) |
| 835 | goto err_stop; |
| 836 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 837 | /* Start the queue. */ |
| 838 | ret = vb2_streamon(&video->queue, type); |
| 839 | if (ret < 0) |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 840 | goto err_stop; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 841 | |
| 842 | return 0; |
| 843 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 844 | err_stop: |
| 845 | media_entity_pipeline_stop(&video->video.entity); |
Laurent Pinchart | a0cdac5 | 2016-01-17 19:53:56 -0200 | [diff] [blame] | 846 | err_pipe: |
| 847 | vsp1_video_pipeline_put(pipe); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | static const struct v4l2_ioctl_ops vsp1_video_ioctl_ops = { |
| 852 | .vidioc_querycap = vsp1_video_querycap, |
| 853 | .vidioc_g_fmt_vid_cap_mplane = vsp1_video_get_format, |
| 854 | .vidioc_s_fmt_vid_cap_mplane = vsp1_video_set_format, |
| 855 | .vidioc_try_fmt_vid_cap_mplane = vsp1_video_try_format, |
| 856 | .vidioc_g_fmt_vid_out_mplane = vsp1_video_get_format, |
| 857 | .vidioc_s_fmt_vid_out_mplane = vsp1_video_set_format, |
| 858 | .vidioc_try_fmt_vid_out_mplane = vsp1_video_try_format, |
| 859 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 860 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 861 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 862 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 863 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
| 864 | .vidioc_prepare_buf = vb2_ioctl_prepare_buf, |
| 865 | .vidioc_streamon = vsp1_video_streamon, |
| 866 | .vidioc_streamoff = vb2_ioctl_streamoff, |
| 867 | }; |
| 868 | |
| 869 | /* ----------------------------------------------------------------------------- |
| 870 | * V4L2 File Operations |
| 871 | */ |
| 872 | |
| 873 | static int vsp1_video_open(struct file *file) |
| 874 | { |
| 875 | struct vsp1_video *video = video_drvdata(file); |
| 876 | struct v4l2_fh *vfh; |
| 877 | int ret = 0; |
| 878 | |
| 879 | vfh = kzalloc(sizeof(*vfh), GFP_KERNEL); |
| 880 | if (vfh == NULL) |
| 881 | return -ENOMEM; |
| 882 | |
| 883 | v4l2_fh_init(vfh, &video->video); |
| 884 | v4l2_fh_add(vfh); |
| 885 | |
| 886 | file->private_data = vfh; |
| 887 | |
Laurent Pinchart | 4c16d6a | 2014-05-31 08:50:32 -0300 | [diff] [blame] | 888 | ret = vsp1_device_get(video->vsp1); |
| 889 | if (ret < 0) { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 890 | v4l2_fh_del(vfh); |
| 891 | kfree(vfh); |
| 892 | } |
| 893 | |
| 894 | return ret; |
| 895 | } |
| 896 | |
| 897 | static int vsp1_video_release(struct file *file) |
| 898 | { |
| 899 | struct vsp1_video *video = video_drvdata(file); |
| 900 | struct v4l2_fh *vfh = file->private_data; |
| 901 | |
| 902 | mutex_lock(&video->lock); |
| 903 | if (video->queue.owner == vfh) { |
| 904 | vb2_queue_release(&video->queue); |
| 905 | video->queue.owner = NULL; |
| 906 | } |
| 907 | mutex_unlock(&video->lock); |
| 908 | |
| 909 | vsp1_device_put(video->vsp1); |
| 910 | |
| 911 | v4l2_fh_release(file); |
| 912 | |
| 913 | file->private_data = NULL; |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 918 | static const struct v4l2_file_operations vsp1_video_fops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 919 | .owner = THIS_MODULE, |
| 920 | .unlocked_ioctl = video_ioctl2, |
| 921 | .open = vsp1_video_open, |
| 922 | .release = vsp1_video_release, |
| 923 | .poll = vb2_fop_poll, |
| 924 | .mmap = vb2_fop_mmap, |
| 925 | }; |
| 926 | |
| 927 | /* ----------------------------------------------------------------------------- |
| 928 | * Initialization and Cleanup |
| 929 | */ |
| 930 | |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 931 | struct vsp1_video *vsp1_video_create(struct vsp1_device *vsp1, |
| 932 | struct vsp1_rwpf *rwpf) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 933 | { |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 934 | struct vsp1_video *video; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 935 | const char *direction; |
| 936 | int ret; |
| 937 | |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 938 | video = devm_kzalloc(vsp1->dev, sizeof(*video), GFP_KERNEL); |
| 939 | if (!video) |
| 940 | return ERR_PTR(-ENOMEM); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 941 | |
Laurent Pinchart | faf2644 | 2015-08-02 14:58:43 -0300 | [diff] [blame] | 942 | rwpf->video = video; |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 943 | |
| 944 | video->vsp1 = vsp1; |
| 945 | video->rwpf = rwpf; |
| 946 | |
| 947 | if (rwpf->entity.type == VSP1_ENTITY_RPF) { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 948 | direction = "input"; |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 949 | video->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 950 | video->pad.flags = MEDIA_PAD_FL_SOURCE; |
| 951 | video->video.vfl_dir = VFL_DIR_TX; |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 952 | } else { |
| 953 | direction = "output"; |
| 954 | video->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 955 | video->pad.flags = MEDIA_PAD_FL_SINK; |
| 956 | video->video.vfl_dir = VFL_DIR_RX; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 957 | } |
| 958 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 959 | mutex_init(&video->lock); |
| 960 | spin_lock_init(&video->irqlock); |
| 961 | INIT_LIST_HEAD(&video->irqqueue); |
| 962 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 963 | /* Initialize the media entity... */ |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 964 | ret = media_entity_pads_init(&video->video.entity, 1, &video->pad); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 965 | if (ret < 0) |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 966 | return ERR_PTR(ret); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 967 | |
| 968 | /* ... and the format ... */ |
Laurent Pinchart | b911605 | 2015-11-22 14:08:18 -0200 | [diff] [blame] | 969 | rwpf->format.pixelformat = VSP1_VIDEO_DEF_FORMAT; |
Laurent Pinchart | 86960ee | 2015-07-28 14:00:43 -0300 | [diff] [blame] | 970 | rwpf->format.width = VSP1_VIDEO_DEF_WIDTH; |
| 971 | rwpf->format.height = VSP1_VIDEO_DEF_HEIGHT; |
Laurent Pinchart | b911605 | 2015-11-22 14:08:18 -0200 | [diff] [blame] | 972 | __vsp1_video_try_format(video, &rwpf->format, &rwpf->fmtinfo); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 973 | |
| 974 | /* ... and the video node... */ |
| 975 | video->video.v4l2_dev = &video->vsp1->v4l2_dev; |
| 976 | video->video.fops = &vsp1_video_fops; |
| 977 | snprintf(video->video.name, sizeof(video->video.name), "%s %s", |
Laurent Pinchart | 8b4a056 | 2015-07-28 13:54:03 -0300 | [diff] [blame] | 978 | rwpf->entity.subdev.name, direction); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 979 | video->video.vfl_type = VFL_TYPE_GRABBER; |
| 980 | video->video.release = video_device_release_empty; |
| 981 | video->video.ioctl_ops = &vsp1_video_ioctl_ops; |
| 982 | |
| 983 | video_set_drvdata(&video->video, video); |
| 984 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 985 | video->queue.type = video->type; |
| 986 | video->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
| 987 | video->queue.lock = &video->lock; |
| 988 | video->queue.drv_priv = video; |
Laurent Pinchart | f7ebf3c | 2015-07-28 14:17:07 -0300 | [diff] [blame] | 989 | video->queue.buf_struct_size = sizeof(struct vsp1_vb2_buffer); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 990 | video->queue.ops = &vsp1_video_queue_qops; |
| 991 | video->queue.mem_ops = &vb2_dma_contig_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 992 | video->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Hans Verkuil | dce5731 | 2016-02-15 13:24:11 -0200 | [diff] [blame] | 993 | video->queue.dev = video->vsp1->dev; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 994 | ret = vb2_queue_init(&video->queue); |
| 995 | if (ret < 0) { |
| 996 | dev_err(video->vsp1->dev, "failed to initialize vb2 queue\n"); |
| 997 | goto error; |
| 998 | } |
| 999 | |
| 1000 | /* ... and register the video device. */ |
| 1001 | video->video.queue = &video->queue; |
| 1002 | ret = video_register_device(&video->video, VFL_TYPE_GRABBER, -1); |
| 1003 | if (ret < 0) { |
| 1004 | dev_err(video->vsp1->dev, "failed to register video device\n"); |
| 1005 | goto error; |
| 1006 | } |
| 1007 | |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 1008 | return video; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1009 | |
| 1010 | error: |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1011 | vsp1_video_cleanup(video); |
Laurent Pinchart | 9d40637 | 2015-07-28 15:46:00 -0300 | [diff] [blame] | 1012 | return ERR_PTR(ret); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | void vsp1_video_cleanup(struct vsp1_video *video) |
| 1016 | { |
| 1017 | if (video_is_registered(&video->video)) |
| 1018 | video_unregister_device(&video->video); |
| 1019 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 1020 | media_entity_cleanup(&video->video.entity); |
| 1021 | } |